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

Method PrintFor

Source/SpireCore/SpirVCodeGen.cpp:4450–4496  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4448 }
4449
4450 void PrintFor(ForInstruction * instr)
4451 {
4452 int HeaderBlockLabel = ++ctx.CurrentID;
4453 int ConditionBlockLabel = ++ctx.CurrentID;
4454 int BodyBlockLabel = ++ctx.CurrentID;
4455 int UpdateBlockLabel = ++ctx.CurrentID;
4456 int MergeBlockLabel = ++ctx.CurrentID;
4457
4458 ctx.AddInstrBranch(HeaderBlockLabel);
4459
4460 ctx.AddInstrLabel_AtFunctionBody(HeaderBlockLabel);
4461 ctx.AddInstrLoopMerge(MergeBlockLabel, UpdateBlockLabel);
4462 ctx.AddInstrBranch(ConditionBlockLabel);
4463
4464 // condition block
4465 ctx.PushScope();
4466 ctx.AddInstrLabel_AtFunctionBody(ConditionBlockLabel);
4467 GenerateCode(instr->ConditionCode.Ptr(), ConditionBlockLabel);
4468 int conditionID = GetOperandValue(instr->ConditionCode->GetLastInstruction());
4469 conditionID = ctx.ConvertBasicType(
4470 conditionID,
4471 ctx.IDInfos[conditionID]().GetILType(),
4472 GetTypeFromString("bool"));
4473 ctx.AddInstrBranchConditional(conditionID, BodyBlockLabel, MergeBlockLabel);
4474 ctx.PopScope();
4475
4476 // body block
4477 ctx.PushScope();
4478 ctx.AddInstrLabel_AtFunctionBody(BodyBlockLabel);
4479 ctx.StackMergeBlock.Add(MergeBlockLabel);
4480 ctx.StackContinueBlock.Add(UpdateBlockLabel);
4481 GenerateCode(instr->BodyCode.Ptr(), BodyBlockLabel);
4482 ctx.StackMergeBlock.RemoveAt(ctx.StackMergeBlock.Count() - 1);
4483 ctx.StackContinueBlock.RemoveAt(ctx.StackContinueBlock.Count() - 1);
4484 ctx.AddInstrBranch(UpdateBlockLabel);
4485 ctx.PopScope();
4486
4487 // update block
4488 ctx.PushScope();
4489 ctx.AddInstrLabel_AtFunctionBody(UpdateBlockLabel);
4490 GenerateCode(instr->SideEffectCode.Ptr(), UpdateBlockLabel);
4491 ctx.AddInstrBranch(HeaderBlockLabel);
4492 ctx.PopScope();
4493
4494 // merge block
4495 ctx.AddInstrLabel_AtFunctionBody(MergeBlockLabel);
4496 }
4497
4498 void PrintWhileDo(WhileInstruction * instr)
4499 {

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