1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-28 11:51:09 +00:00

#815 working on moving control flow graphs into procedure compilation.

This commit is contained in:
jespergravgaard 2023-04-10 00:08:44 +02:00
parent dfbeba7805
commit 40182a6ad6

View File

@ -5,6 +5,7 @@ import dk.camelot64.kickc.model.iterator.ProgramValue;
import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
import dk.camelot64.kickc.model.statements.*;
import dk.camelot64.kickc.model.symbols.Label;
import dk.camelot64.kickc.model.symbols.Procedure;
import dk.camelot64.kickc.model.symbols.Scope;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.values.*;
@ -285,7 +286,15 @@ public class Unroller {
// Create the new block
LabelRef newBlockLabel = blocksOriginalToCopied.get(origBlock.getLabel());
ControlFlowBlock newBlock = new ControlFlowBlock(newBlockLabel, origBlock.getScope());
program.getGraph().addBlock(newBlock);
// Add the new graph to the appropriate procedure
final Procedure containingProcedure = program.getScope().getSymbol(origBlock.getLabel()).getContainingProcedure();
final ProcedureCompilation procedureCompilation = program.getProcedureCompilation(containingProcedure.getRef());
final List<Graph.Block> procedureBlocks = new ArrayList<>(procedureCompilation.getGraph().getAllBlocks());
procedureBlocks.add(newBlock);
procedureCompilation.setGraph(new ControlFlowGraph(procedureBlocks));
for(Statement origStatement : origBlock.getStatements()) {
Statement newStatement = unrollStatement(origStatement, origBlock.getLabel());
newBlock.addStatement(newStatement);