Handle ret not being in last basic block

This commit is contained in:
baldurk
2020-06-19 17:02:59 +01:00
parent 5b5cd18283
commit 4d156f0904
2 changed files with 17 additions and 3 deletions
@@ -1406,6 +1406,8 @@ Program::Program(const byte *bytes, size_t length)
m_Symbols.push_back({SymbolType::Instruction, f.instructions.size()});
}
curBlock++;
f.instructions.push_back(inst);
}
else if(op.type == FunctionRecord::INST_BINOP)
@@ -2256,6 +2258,8 @@ Program::Program(const byte *bytes, size_t length)
}
}
RDCASSERT(curBlock == f.blocks.size());
size_t resultID = 0;
if(f.blocks[0].name.empty())
@@ -2277,9 +2281,13 @@ Program::Program(const byte *bytes, size_t length)
if(f.instructions[i].op == Instruction::Branch ||
f.instructions[i].op == Instruction::Unreachable ||
f.instructions[i].op == Instruction::Switch)
f.instructions[i].op == Instruction::Switch || f.instructions[i].op == Instruction::Ret)
{
curBlock++;
if(i == f.instructions.size() - 1)
break;
if(f.blocks[curBlock].name.empty())
f.blocks[curBlock].resultID = (uint32_t)resultID++;
continue;
@@ -595,8 +595,10 @@ void Program::MakeDisassemblyString()
instructionLine++;
}
for(Instruction &inst : func.instructions)
for(size_t funcIdx = 0; funcIdx < func.instructions.size(); funcIdx++)
{
Instruction &inst = func.instructions[funcIdx];
inst.disassemblyLine = instructionLine;
m_Disassembly += " ";
if(!inst.name.empty())
@@ -1326,8 +1328,12 @@ void Program::MakeDisassemblyString()
m_Disassembly += "\n";
instructionLine++;
// if this is the last instruction don't print the next block's label
if(funcIdx == func.instructions.size() - 1)
break;
if(inst.op == Instruction::Branch || inst.op == Instruction::Unreachable ||
inst.op == Instruction::Switch)
inst.op == Instruction::Switch || inst.op == Instruction::Ret)
{
m_Disassembly += "\n";
instructionLine++;