mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-26 12:49:21 +00:00
Working on static initialization rewrite _init(). #257
This commit is contained in:
parent
ea52aa7f2b
commit
57d5d4500b
@ -217,8 +217,11 @@ public class Compiler {
|
||||
getLog().append(procedureCompilation.getStatementSequence().toString(program));
|
||||
}
|
||||
}
|
||||
|
||||
new Pass1GenerateControlFlowGraph(program).execute();
|
||||
if(getLog().isVerbosePass1CreateSsa()) {
|
||||
getLog().append("FIRST CONTROL FLOW GRAPH");
|
||||
getLog().append(program.getGraph().toString(program));
|
||||
}
|
||||
new Pass1ResolveForwardReferences(program).execute();
|
||||
new Pass1AssertProcedureDefined(program).execute();
|
||||
new Pass1AssertVariableDefined(program).execute();
|
||||
|
@ -35,6 +35,13 @@ public class Pass1GenerateControlFlowGraph extends Pass1Base {
|
||||
ControlFlowBlock procBlock = getOrCreateBlock(procedure.getLabel().getRef(), procedure.getRef());
|
||||
currentBlock = procBlock;
|
||||
for(Statement statement : sequence.getStatements()) {
|
||||
Symbol currentBlockLabel = getProgram().getScope().getSymbol(currentBlock.getLabel());
|
||||
Scope currentBlockScope;
|
||||
if(currentBlockLabel instanceof Procedure) {
|
||||
currentBlockScope = (Scope) currentBlockLabel;
|
||||
} else {
|
||||
currentBlockScope = currentBlockLabel.getScope();
|
||||
}
|
||||
if(statement instanceof StatementProcedureBegin) {
|
||||
// Do nothing
|
||||
} else if(statement instanceof StatementProcedureEnd) {
|
||||
@ -42,7 +49,7 @@ public class Pass1GenerateControlFlowGraph extends Pass1Base {
|
||||
currentBlock.setDefaultSuccessor(new Label(SymbolRef.PROCEXIT_BLOCK_NAME, programScope, false).getRef());
|
||||
} else if(statement instanceof StatementLabel) {
|
||||
StatementLabel statementLabel = (StatementLabel) statement;
|
||||
ControlFlowBlock nextBlock = getOrCreateBlock(statementLabel.getLabel(), procedure.getRef());
|
||||
ControlFlowBlock nextBlock = getOrCreateBlock(statementLabel.getLabel(), currentBlock.getScope());
|
||||
nextBlock.setComments(statementLabel.getComments());
|
||||
currentBlock.setDefaultSuccessor(nextBlock.getLabel());
|
||||
currentBlock = nextBlock;
|
||||
@ -50,13 +57,13 @@ public class Pass1GenerateControlFlowGraph extends Pass1Base {
|
||||
StatementJump statementJump = (StatementJump) statement;
|
||||
ControlFlowBlock jmpBlock = getOrCreateBlock(statementJump.getDestination(), currentBlock.getScope());
|
||||
currentBlock.setDefaultSuccessor(jmpBlock.getLabel());
|
||||
ControlFlowBlock nextBlock = getOrCreateBlock(procedure.addLabelIntermediate().getRef(), currentBlock.getScope());
|
||||
ControlFlowBlock nextBlock = getOrCreateBlock(currentBlockScope.addLabelIntermediate().getRef(), currentBlock.getScope());
|
||||
currentBlock = nextBlock;
|
||||
} else if(statement instanceof StatementConditionalJump) {
|
||||
currentBlock.addStatement(statement);
|
||||
StatementConditionalJump statementConditionalJump = (StatementConditionalJump) statement;
|
||||
ControlFlowBlock jmpBlock = getOrCreateBlock(statementConditionalJump.getDestination(), currentBlock.getScope());
|
||||
ControlFlowBlock nextBlock = getOrCreateBlock(procedure.addLabelIntermediate().getRef(), currentBlock.getScope());
|
||||
ControlFlowBlock nextBlock = getOrCreateBlock(currentBlockScope.addLabelIntermediate().getRef(), currentBlock.getScope());
|
||||
currentBlock.setDefaultSuccessor(nextBlock.getLabel());
|
||||
currentBlock.setConditionalSuccessor(jmpBlock.getLabel());
|
||||
currentBlock = nextBlock;
|
||||
|
Loading…
Reference in New Issue
Block a user