1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-29 02:50:11 +00:00

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

This commit is contained in:
jespergravgaard 2023-04-10 10:23:00 +02:00
parent 40182a6ad6
commit c78b8c59b1
4 changed files with 21 additions and 21 deletions

View File

@ -18,6 +18,10 @@ public interface Graph {
void addBlock(Graph.Block block); void addBlock(Graph.Block block);
default List<Statement> getAllStatements() {
return getAllBlocks().stream().map(Block::getStatements).flatMap(Collection::stream).toList();
}
default List<Graph.Block> getPredecessors(Graph.Block block) { default List<Graph.Block> getPredecessors(Graph.Block block) {
ArrayList<Block> predecessorBlocks = new ArrayList<>(); ArrayList<Block> predecessorBlocks = new ArrayList<>();
for(Graph.Block other : getAllBlocks()) { for(Graph.Block other : getAllBlocks()) {

View File

@ -1,6 +1,5 @@
package dk.camelot64.kickc.model; package dk.camelot64.kickc.model;
import dk.camelot64.kickc.model.statements.Statement;
import dk.camelot64.kickc.model.values.ProcedureRef; import dk.camelot64.kickc.model.values.ProcedureRef;
/** /**

View File

@ -14,7 +14,6 @@ import dk.camelot64.kickc.passes.utils.ProcedureUtils;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** A KickC Intermediate Compiler Language (ICL) Program */ /** A KickC Intermediate Compiler Language (ICL) Program */
public class Program { public class Program {

View File

@ -19,27 +19,25 @@ public class Pass1AssertInterrupts extends Pass1Base {
@Override @Override
public boolean step() { public boolean step() {
for(var block : getGraph().getAllBlocks()) { for(Statement statement : getGraph().getAllStatements()) {
for(Statement statement : block.getStatements()) { if(statement instanceof StatementCalling) {
if(statement instanceof StatementCalling) { ProcedureRef procedureRef = ((StatementCalling) statement).getProcedure();
ProcedureRef procedureRef = ((StatementCalling) statement).getProcedure(); Procedure procedure = getProgramScope().getProcedure(procedureRef);
Procedure procedure = getProgramScope().getProcedure(procedureRef); if(procedure.getInterruptType() != null) {
if(procedure.getInterruptType()!=null) { throw new CompileError("Interrupts cannot be called.", statement.getSource());
throw new CompileError("Interrupts cannot be called.", statement.getSource());
}
} }
} }
for(Procedure procedure : getProgramScope().getAllProcedures(true)) { }
if(procedure.getInterruptType()!=null) { for(Procedure procedure : getProgramScope().getAllProcedures(true)) {
if(procedure.isDeclaredInline()) { if(procedure.getInterruptType()!=null) {
throw new CompileError("Interrupts cannot be inlined. " + procedure.toString()); 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(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()); if(!SymbolType.VOID.equals(procedure.getReturnType())) {
} throw new CompileError("Interrupts cannot return anything. " + procedure.toString());
} }
} }
} }