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

Method GenerateCode

Source/SpireCore/SpirVCodeGen.cpp:4588–4647  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4586 }
4587
4588 void GenerateCode(CFGNode * code, int givenLabel = -1, bool LoopReturn = false)
4589 {
4590 if (givenLabel == -1)
4591 {
4592 ++ctx.CurrentID; //label ID
4593 ctx.AddInstrLabel_AtFunctionBody(ctx.CurrentID);
4594 }
4595
4596 List<int> usedID;
4597 for (auto & instr : *code)
4598 {
4599
4600 if (auto ifInstr = instr.As<IfInstruction>())
4601 {
4602 PrintIf(ifInstr);
4603 }
4604 else if (auto forInstr = instr.As<ForInstruction>())
4605 {
4606 PrintFor(forInstr);
4607 }
4608 else if (auto doInstr = instr.As<DoInstruction>())
4609 {
4610 PrintDoWhile(doInstr);
4611 }
4612 else if (auto whileInstr = instr.As<WhileInstruction>())
4613 {
4614 PrintWhileDo(whileInstr);
4615 }
4616 else if (auto ret = instr.As<ReturnInstruction>())
4617 {
4618 if (!LoopReturn)
4619 {
4620 if (ret->Operand)
4621 ctx.AddInstrReturnValue(GetOperandValue(ret->Operand.Ptr()));
4622 else
4623 ctx.AddInstrReturn();
4624 ctx.AddInstrLabel_AtFunctionBody(++ctx.CurrentID);
4625 }
4626 }
4627 else if (instr.Is<BreakInstruction>())
4628 {
4629 ctx.AddInstrBranch(ctx.StackMergeBlock.Last());
4630 ctx.AddInstrLabel_AtFunctionBody(++ctx.CurrentID);
4631 }
4632 else if (instr.Is<ContinueInstruction>())
4633 {
4634 ctx.AddInstrBranch(ctx.StackContinueBlock.Last());
4635 ctx.AddInstrLabel_AtFunctionBody(++ctx.CurrentID);
4636 }
4637 else if (instr.Is<DiscardInstruction>())
4638 {
4639 ctx.AddInstrKill();
4640 ctx.AddInstrLabel_AtFunctionBody(++ctx.CurrentID);
4641 }
4642 else
4643 {
4644 PrintInstr(instr);
4645 }

Callers

nothing calls this directly

Calls 6

AddInstrReturnValueMethod · 0.80
AddInstrReturnMethod · 0.80
AddInstrBranchMethod · 0.80
AddInstrKillMethod · 0.80
PtrMethod · 0.45

Tested by

no test coverage detected