@@ -1390,6 +1390,8 @@ CompilerValue *LLVMCodeBuilder::addFunctionCall(const std::string &functionName,
13901390 for (size_t i = 0 ; i < args.size (); i++)
13911391 ins->args .push_back ({ argTypes[i], dynamic_cast <LLVMRegister *>(args[i]) });
13921392
1393+ m_instructions.addInstruction (ins);
1394+
13931395 if (returnType != Compiler::StaticType::Void) {
13941396 auto reg = std::make_shared<LLVMRegister>(returnType);
13951397 reg->isRawValue = true ;
@@ -1456,6 +1458,7 @@ CompilerValue *LLVMCodeBuilder::addVariableValue(Variable *variable)
14561458 ret->isRawValue = false ;
14571459 ins->functionReturnReg = ret.get ();
14581460
1461+ m_instructions.addInstruction (ins);
14591462 m_instructionList.push_back (ins);
14601463 m_variableInstructions.push_back (m_instructionList.back ());
14611464 return addReg (ret, ins);
@@ -1486,6 +1489,7 @@ CompilerValue *LLVMCodeBuilder::addListItem(List *list, CompilerValue *index)
14861489 ret->isRawValue = false ;
14871490 ins->functionReturnReg = ret.get ();
14881491
1492+ m_instructions.addInstruction (ins);
14891493 m_instructionList.push_back (ins);
14901494 m_listInstructions.push_back (m_instructionList.back ());
14911495 return addReg (ret, ins);
@@ -1549,6 +1553,7 @@ CompilerValue *LLVMCodeBuilder::addProcedureArgument(const std::string &name)
15491553 ins->functionReturnReg = ret.get ();
15501554 ins->procedureArgIndex = index;
15511555
1556+ m_instructions.addInstruction (ins);
15521557 m_instructionList.push_back (ins);
15531558 return addReg (ret, ins);
15541559}
@@ -1818,17 +1823,22 @@ void LLVMCodeBuilder::beginIfStatement(CompilerValue *cond)
18181823{
18191824 auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginIf, currentLoopScope (), m_loopCondition);
18201825 ins->args .push_back ({ Compiler::StaticType::Bool, dynamic_cast <LLVMRegister *>(cond) });
1826+ m_instructions.addInstruction (ins);
18211827 m_instructionList.push_back (ins);
18221828}
18231829
18241830void LLVMCodeBuilder::beginElseBranch ()
18251831{
1826- m_instructionList.push_back (std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginElse, currentLoopScope (), m_loopCondition));
1832+ auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginElse, currentLoopScope (), m_loopCondition);
1833+ m_instructions.addInstruction (ins);
1834+ m_instructionList.push_back (ins);
18271835}
18281836
18291837void LLVMCodeBuilder::endIf ()
18301838{
1831- m_instructionList.push_back (std::make_shared<LLVMInstruction>(LLVMInstruction::Type::EndIf, currentLoopScope (), m_loopCondition));
1839+ auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::EndIf, currentLoopScope (), m_loopCondition);
1840+ m_instructions.addInstruction (ins);
1841+ m_instructionList.push_back (ins);
18321842}
18331843
18341844void LLVMCodeBuilder::beginRepeatLoop (CompilerValue *count)
@@ -1837,6 +1847,7 @@ void LLVMCodeBuilder::beginRepeatLoop(CompilerValue *count)
18371847
18381848 auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginRepeatLoop, currentLoopScope (), m_loopCondition);
18391849 ins->args .push_back ({ Compiler::StaticType::Number, dynamic_cast <LLVMRegister *>(count) });
1850+ m_instructions.addInstruction (ins);
18401851 m_instructionList.push_back (ins);
18411852 pushLoopScope (false );
18421853}
@@ -1848,6 +1859,7 @@ void LLVMCodeBuilder::beginWhileLoop(CompilerValue *cond)
18481859
18491860 auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginWhileLoop, currentLoopScope (), m_loopCondition);
18501861 ins->args .push_back ({ Compiler::StaticType::Bool, dynamic_cast <LLVMRegister *>(cond) });
1862+ m_instructions.addInstruction (ins);
18511863 m_instructionList.push_back (ins);
18521864 pushLoopScope (false );
18531865}
@@ -1859,37 +1871,50 @@ void LLVMCodeBuilder::beginRepeatUntilLoop(CompilerValue *cond)
18591871
18601872 auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginRepeatUntilLoop, currentLoopScope (), m_loopCondition);
18611873 ins->args .push_back ({ Compiler::StaticType::Bool, dynamic_cast <LLVMRegister *>(cond) });
1874+ m_instructions.addInstruction (ins);
18621875 m_instructionList.push_back (ins);
18631876 pushLoopScope (false );
18641877}
18651878
18661879void LLVMCodeBuilder::beginLoopCondition ()
18671880{
18681881 assert (!m_loopCondition);
1869- m_instructionList.push_back (std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginLoopCondition, currentLoopScope (), m_loopCondition));
1882+
1883+ auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginLoopCondition, currentLoopScope (), m_loopCondition);
1884+ m_instructions.addInstruction (ins);
1885+ m_instructionList.push_back (ins);
18701886 m_loopCondition = true ;
18711887}
18721888
18731889void LLVMCodeBuilder::endLoop ()
18741890{
1875- if (!m_warp)
1876- m_instructionList.push_back (std::make_shared<LLVMInstruction>(LLVMInstruction::Type::Yield, currentLoopScope (), m_loopCondition));
1891+ if (!m_warp) {
1892+ auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::Yield, currentLoopScope (), m_loopCondition);
1893+ m_instructions.addInstruction (ins);
1894+ m_instructionList.push_back (ins);
1895+ }
18771896
1878- m_instructionList.push_back (std::make_shared<LLVMInstruction>(LLVMInstruction::Type::EndLoop, currentLoopScope (), m_loopCondition));
1897+ auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::EndLoop, currentLoopScope (), m_loopCondition);
1898+ m_instructions.addInstruction (ins);
1899+ m_instructionList.push_back (ins);
18791900 popLoopScope ();
18801901}
18811902
18821903void LLVMCodeBuilder::yield ()
18831904{
1884- m_instructionList.push_back (std::make_shared<LLVMInstruction>(LLVMInstruction::Type::Yield, currentLoopScope (), m_loopCondition));
1905+ auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::Yield, currentLoopScope (), m_loopCondition);
1906+ m_instructions.addInstruction (ins);
1907+ m_instructionList.push_back (ins);
18851908
18861909 if (m_loopScope >= 0 )
18871910 m_loopScopes[m_loopScope]->containsYield = true ;
18881911}
18891912
18901913void LLVMCodeBuilder::createStop ()
18911914{
1892- m_instructionList.push_back (std::make_shared<LLVMInstruction>(LLVMInstruction::Type::Stop, currentLoopScope (), m_loopCondition));
1915+ auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::Stop, currentLoopScope (), m_loopCondition);
1916+ m_instructions.addInstruction (ins);
1917+ m_instructionList.push_back (ins);
18931918}
18941919
18951920void LLVMCodeBuilder::createProcedureCall (BlockPrototype *prototype, const Compiler::Args &args)
@@ -2715,6 +2740,7 @@ LLVMRegister *LLVMCodeBuilder::createOp(const LLVMInstruction &ins, Compiler::St
27152740LLVMRegister *LLVMCodeBuilder::createOp (const LLVMInstruction &ins, Compiler::StaticType retType, const Compiler::ArgTypes &argTypes, const Compiler::Args &args)
27162741{
27172742 auto createdIns = std::make_shared<LLVMInstruction>(ins);
2743+ m_instructions.addInstruction (createdIns);
27182744 m_instructionList.push_back (createdIns);
27192745
27202746 for (size_t i = 0 ; i < args.size (); i++)
0 commit comments