MCPcopy Create free account
hub / github.com/csyonghe/Spire / PrintWhileDo

Method PrintWhileDo

Source/SpireCore/SpirVCodeGen.cpp:4498–4543  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4496 }
4497
4498 void PrintWhileDo(WhileInstruction * instr)
4499 {
4500 int HeaderBlockLabel = ++ctx.CurrentID;
4501 int ConditionBlockLabel = ++ctx.CurrentID;
4502 int BodyBlockLabel = ++ctx.CurrentID;
4503 int UpdateBlockLabel = ++ctx.CurrentID;
4504 int MergeBlockLabel = ++ctx.CurrentID;
4505
4506 ctx.AddInstrBranch(HeaderBlockLabel);
4507
4508 // header block
4509 ctx.AddInstrLabel_AtFunctionBody(HeaderBlockLabel);
4510 ctx.AddInstrLoopMerge(MergeBlockLabel, UpdateBlockLabel);
4511 ctx.AddInstrBranch(ConditionBlockLabel);
4512
4513 // condition block
4514 ctx.PushScope();
4515 ctx.AddInstrLabel_AtFunctionBody(ConditionBlockLabel);
4516 GenerateCode(instr->ConditionCode.Ptr(), ConditionBlockLabel, true);
4517 int conditionID = GetOperandValue(instr->ConditionCode->GetLastInstruction()->As<ReturnInstruction>()->Operand.Ptr());
4518 conditionID = ctx.ConvertBasicType(
4519 conditionID,
4520 ctx.IDInfos[conditionID]().GetILType(),
4521 GetTypeFromString("bool")
4522 );
4523 ctx.AddInstrBranchConditional(conditionID, BodyBlockLabel, MergeBlockLabel);
4524 ctx.PopScope();
4525
4526 // body block
4527 ctx.PushScope();
4528 ctx.AddInstrLabel_AtFunctionBody(BodyBlockLabel);
4529 ctx.StackMergeBlock.Add(MergeBlockLabel);
4530 ctx.StackContinueBlock.Add(UpdateBlockLabel);
4531 GenerateCode(instr->BodyCode.Ptr(), BodyBlockLabel);
4532 ctx.StackMergeBlock.RemoveAt(ctx.StackMergeBlock.Count() - 1);
4533 ctx.StackContinueBlock.RemoveAt(ctx.StackContinueBlock.Count() - 1);
4534 ctx.AddInstrBranch(UpdateBlockLabel);
4535 ctx.PopScope();
4536
4537 // update block (empty)
4538 ctx.AddInstrLabel_AtFunctionBody(UpdateBlockLabel);
4539 ctx.AddInstrBranch(HeaderBlockLabel);
4540
4541 // merge block
4542 ctx.AddInstrLabel_AtFunctionBody(MergeBlockLabel);
4543 }
4544
4545 void PrintDoWhile(DoInstruction * instr)
4546 {

Callers

nothing calls this directly

Calls 14

GetTypeFromStringFunction · 0.85
AddInstrBranchMethod · 0.80
AddInstrLoopMergeMethod · 0.80
GetLastInstructionMethod · 0.80
ConvertBasicTypeMethod · 0.80
GetILTypeMethod · 0.80
RemoveAtMethod · 0.80
PushScopeMethod · 0.45
PtrMethod · 0.45
PopScopeMethod · 0.45

Tested by

no test coverage detected