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:
parent
40182a6ad6
commit
c78b8c59b1
@ -18,6 +18,10 @@ public interface Graph {
|
||||
|
||||
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) {
|
||||
ArrayList<Block> predecessorBlocks = new ArrayList<>();
|
||||
for(Graph.Block other : getAllBlocks()) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
import dk.camelot64.kickc.model.values.ProcedureRef;
|
||||
|
||||
/**
|
||||
|
@ -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 {
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user