From 40182a6ad6ef9141fde6c589142abe8385bd2432 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Mon, 10 Apr 2023 00:08:44 +0200 Subject: [PATCH] #815 working on moving control flow graphs into procedure compilation. --- .../dk/camelot64/kickc/passes/utils/Unroller.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/dk/camelot64/kickc/passes/utils/Unroller.java b/src/main/java/dk/camelot64/kickc/passes/utils/Unroller.java index 268bf98df..ab32c78a1 100644 --- a/src/main/java/dk/camelot64/kickc/passes/utils/Unroller.java +++ b/src/main/java/dk/camelot64/kickc/passes/utils/Unroller.java @@ -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 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);