From c78b8c59b12d730b776d596dc8cfad4100684342 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Mon, 10 Apr 2023 10:23:00 +0200 Subject: [PATCH] #815 working on moving control flow graphs into procedure compilation. --- .../java/dk/camelot64/kickc/model/Graph.java | 4 +++ .../kickc/model/ProcedureCompilation.java | 1 - .../dk/camelot64/kickc/model/Program.java | 1 - .../kickc/passes/Pass1AssertInterrupts.java | 36 +++++++++---------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/dk/camelot64/kickc/model/Graph.java b/src/main/java/dk/camelot64/kickc/model/Graph.java index fd1c2e603..a1252ff76 100644 --- a/src/main/java/dk/camelot64/kickc/model/Graph.java +++ b/src/main/java/dk/camelot64/kickc/model/Graph.java @@ -18,6 +18,10 @@ public interface Graph { void addBlock(Graph.Block block); + default List getAllStatements() { + return getAllBlocks().stream().map(Block::getStatements).flatMap(Collection::stream).toList(); + } + default List getPredecessors(Graph.Block block) { ArrayList predecessorBlocks = new ArrayList<>(); for(Graph.Block other : getAllBlocks()) { diff --git a/src/main/java/dk/camelot64/kickc/model/ProcedureCompilation.java b/src/main/java/dk/camelot64/kickc/model/ProcedureCompilation.java index d9b499c3b..f6a56416c 100644 --- a/src/main/java/dk/camelot64/kickc/model/ProcedureCompilation.java +++ b/src/main/java/dk/camelot64/kickc/model/ProcedureCompilation.java @@ -1,6 +1,5 @@ package dk.camelot64.kickc.model; -import dk.camelot64.kickc.model.statements.Statement; import dk.camelot64.kickc.model.values.ProcedureRef; /** diff --git a/src/main/java/dk/camelot64/kickc/model/Program.java b/src/main/java/dk/camelot64/kickc/model/Program.java index 9f03fd0cc..bc29b3a79 100644 --- a/src/main/java/dk/camelot64/kickc/model/Program.java +++ b/src/main/java/dk/camelot64/kickc/model/Program.java @@ -14,7 +14,6 @@ import dk.camelot64.kickc.passes.utils.ProcedureUtils; import java.nio.file.Path; import java.util.*; -import java.util.stream.Collectors; /** A KickC Intermediate Compiler Language (ICL) Program */ public class Program { diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1AssertInterrupts.java b/src/main/java/dk/camelot64/kickc/passes/Pass1AssertInterrupts.java index b182aee68..fa0025f22 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass1AssertInterrupts.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1AssertInterrupts.java @@ -19,27 +19,25 @@ public class Pass1AssertInterrupts extends Pass1Base { @Override public boolean step() { - for(var block : getGraph().getAllBlocks()) { - for(Statement statement : block.getStatements()) { - if(statement instanceof StatementCalling) { - ProcedureRef procedureRef = ((StatementCalling) statement).getProcedure(); - Procedure procedure = getProgramScope().getProcedure(procedureRef); - if(procedure.getInterruptType()!=null) { - throw new CompileError("Interrupts cannot be called.", statement.getSource()); - } + for(Statement statement : getGraph().getAllStatements()) { + if(statement instanceof StatementCalling) { + ProcedureRef procedureRef = ((StatementCalling) statement).getProcedure(); + Procedure procedure = getProgramScope().getProcedure(procedureRef); + if(procedure.getInterruptType() != null) { + throw new CompileError("Interrupts cannot be called.", statement.getSource()); } } - for(Procedure procedure : getProgramScope().getAllProcedures(true)) { - if(procedure.getInterruptType()!=null) { - if(procedure.isDeclaredInline()) { - throw new CompileError("Interrupts cannot be inlined. " + procedure.toString()); - } - if(procedure.getParameters().size()>0) { - throw new CompileError("Interrupts cannot have parameters. " + procedure.toString()); - } - if(!SymbolType.VOID.equals(procedure.getReturnType())) { - throw new CompileError("Interrupts cannot return anything. " + procedure.toString()); - } + } + for(Procedure procedure : getProgramScope().getAllProcedures(true)) { + if(procedure.getInterruptType()!=null) { + if(procedure.isDeclaredInline()) { + throw new CompileError("Interrupts cannot be inlined. " + procedure.toString()); + } + if(procedure.getParameters().size()>0) { + throw new CompileError("Interrupts cannot have parameters. " + procedure.toString()); + } + if(!SymbolType.VOID.equals(procedure.getReturnType())) { + throw new CompileError("Interrupts cannot return anything. " + procedure.toString()); } } }