mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-11 20:30:08 +00:00
Constructor procedures are not marked by boolean instead of a magic comment.
This commit is contained in:
parent
7d82543566
commit
a31600f740
@ -14,9 +14,6 @@ public class Comment implements Serializable {
|
||||
/** Empty comments collection. */
|
||||
public static final ArrayList<Comment> NO_COMMENTS = new ArrayList<>();
|
||||
|
||||
/** Special comment used for constructor calls in __init(). */
|
||||
public static final Comment CONSTRUCTOR = new Comment("#pragma constructor");
|
||||
|
||||
/** The comment. */
|
||||
private String comment;
|
||||
|
||||
|
@ -32,6 +32,8 @@ public class Procedure extends Scope {
|
||||
private final String codeSegment;
|
||||
/** The list of constructor procedures for this procedure. The constructor procedures are called during program initialization. */
|
||||
private final List<ProcedureRef> constructorRefs;
|
||||
/** Is this procedure declared as a constructor procedure. */
|
||||
private boolean isConstructor;
|
||||
|
||||
/** The names of all legal intrinsic procedures. */
|
||||
final public static List<String> INTRINSIC_PROCEDURES = Collections.singletonList(Pass1PrintfIntrinsicRewrite.INTRINSIC_PRINTF_NAME);
|
||||
@ -76,6 +78,7 @@ public class Procedure extends Scope {
|
||||
this.codeSegment = codeSegment;
|
||||
this.callingConvention = callingConvention;
|
||||
this.constructorRefs = new ArrayList<>();
|
||||
this.isConstructor = false;
|
||||
}
|
||||
|
||||
public CallingConvention getCallingConvention() {
|
||||
@ -205,6 +208,13 @@ public class Procedure extends Scope {
|
||||
return constructorRefs;
|
||||
}
|
||||
|
||||
public boolean isConstructor() {
|
||||
return isConstructor;
|
||||
}
|
||||
|
||||
public void setConstructor(boolean constructor) {
|
||||
isConstructor = constructor;
|
||||
}
|
||||
|
||||
/** The different types of supported interrupts. */
|
||||
public enum InterruptType {
|
||||
|
@ -150,7 +150,9 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
if(!constructorProcs.contains(constructorProc.getRef())) {
|
||||
constructorProcs.add(constructorProc.getRef());
|
||||
// Add call to constructor procedure to the __init() procedure
|
||||
addStatement(new StatementCall(null, constructorProc.getLocalName(), new ArrayList<>(), new StatementSource(pragmaConstructorFor), Collections.singletonList(Comment.CONSTRUCTOR)));
|
||||
addStatement(new StatementCall(null, constructorProc.getLocalName(), new ArrayList<>(), new StatementSource(pragmaConstructorFor), Comment.NO_COMMENTS));
|
||||
// Mark the constructor procedure
|
||||
constructorProc.setConstructor(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package dk.camelot64.kickc.passes;
|
||||
|
||||
import dk.camelot64.kickc.model.Comment;
|
||||
import dk.camelot64.kickc.model.ControlFlowBlock;
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
@ -36,11 +35,14 @@ public class PassNEliminateUnusedConstructors extends Pass2SsaOptimization {
|
||||
final List<ControlFlowBlock> startProcBlocks = getGraph().getScopeBlocks(startProc.getRef());
|
||||
for(ControlFlowBlock block : startProcBlocks) {
|
||||
for(Statement statement : block.getStatements()) {
|
||||
if(statement instanceof StatementCalling && statement.getComments().size() == 1 && statement.getComments().get(0).equals(Comment.CONSTRUCTOR)) {
|
||||
// This is a constructor call!
|
||||
final ProcedureRef constructorRef = ((StatementCalling) statement).getProcedure();
|
||||
if(!allConstructors.contains(constructorRef)) {
|
||||
unusedConstructors.add(constructorRef);
|
||||
if(statement instanceof StatementCalling) {
|
||||
final ProcedureRef procedureRef = ((StatementCalling) statement).getProcedure();
|
||||
final Procedure procedure = getScope().getProcedure(procedureRef);
|
||||
if(procedure.isConstructor()) {
|
||||
// This is a constructor call!
|
||||
if(!allConstructors.contains(procedureRef)) {
|
||||
unusedConstructors.add(procedureRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -48,6 +50,7 @@ public class PassNEliminateUnusedConstructors extends Pass2SsaOptimization {
|
||||
// Remove all calls to unused constructors
|
||||
for(ProcedureRef unusedConstructor : unusedConstructors) {
|
||||
removeAllCalls(unusedConstructor, startProcBlocks);
|
||||
optimized = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,13 +58,13 @@ public class TestPrograms {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLibraryConstructor2() throws IOException, URISyntaxException {
|
||||
compileAndCompare("library-constructor-2.c");
|
||||
public void testLibraryConstructor3() throws IOException, URISyntaxException {
|
||||
compileAndCompare("library-constructor-3.c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLibraryConstructor3() throws IOException, URISyntaxException {
|
||||
compileAndCompare("library-constructor-3.c", log());
|
||||
public void testLibraryConstructor2() throws IOException, URISyntaxException {
|
||||
compileAndCompare("library-constructor-2.c");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -10,7 +10,6 @@ __start: {
|
||||
lda #0
|
||||
sta.z my_value
|
||||
// #pragma constructor_for(my_init, print)
|
||||
//#pragma constructor
|
||||
jsr my_init
|
||||
jsr main
|
||||
rts
|
||||
|
@ -162,7 +162,6 @@ __start: {
|
||||
lda #0
|
||||
sta.z my_value
|
||||
// [2] call my_init
|
||||
//#pragma constructor
|
||||
jsr my_init
|
||||
// [3] phi from __start::__init1 to __start::@1 [phi:__start::__init1->__start::@1]
|
||||
__b1_from___init1:
|
||||
@ -254,7 +253,6 @@ __start: {
|
||||
lda #0
|
||||
sta.z my_value
|
||||
// [2] call my_init
|
||||
//#pragma constructor
|
||||
jsr my_init
|
||||
// [3] phi from __start::__init1 to __start::@1 [phi:__start::__init1->__start::@1]
|
||||
__b1_from___init1:
|
||||
@ -363,7 +361,6 @@ __start: {
|
||||
sta.z my_value
|
||||
// #pragma constructor_for(my_init, print)
|
||||
// [2] call my_init
|
||||
//#pragma constructor
|
||||
jsr my_init
|
||||
// [3] phi from __start::__init1 to __start::@1 [phi:__start::__init1->__start::@1]
|
||||
// __start::@1
|
||||
|
@ -62,6 +62,7 @@ Successful SSA optimization PassNFinalizeNumberTypeConversions
|
||||
Simplifying expression containing zero SCREEN in [0] *((const nomodify byte*) SCREEN + (byte) 0) ← (byte) '*'
|
||||
Successful SSA optimization PassNSimplifyExpressionWithZero
|
||||
Removing call to constructor procedure [4] call my_init
|
||||
Successful SSA optimization PassNEliminateUnusedConstructors
|
||||
Removing unused procedure my_init
|
||||
Removing unused procedure block my_init
|
||||
Removing unused procedure block my_init::@return
|
||||
|
@ -13,10 +13,8 @@ __start: {
|
||||
sta.z SCREEN
|
||||
sta.z SCREEN+1
|
||||
// #pragma constructor_for(init_1, print)
|
||||
//#pragma constructor
|
||||
jsr init_1
|
||||
// #pragma constructor_for(init_2, print)
|
||||
//#pragma constructor
|
||||
jsr init_2
|
||||
jsr main
|
||||
rts
|
||||
|
@ -204,7 +204,6 @@ __start: {
|
||||
lda #>0
|
||||
sta.z SCREEN+1
|
||||
// [3] call init_1
|
||||
//#pragma constructor
|
||||
jsr init_1
|
||||
// [4] phi from __start::__init1 to __start::@2 [phi:__start::__init1->__start::@2]
|
||||
__b2_from___init1:
|
||||
@ -212,7 +211,6 @@ __start: {
|
||||
// __start::@2
|
||||
__b2:
|
||||
// [5] call init_2
|
||||
//#pragma constructor
|
||||
jsr init_2
|
||||
// [6] phi from __start::@2 to __start::@1 [phi:__start::@2->__start::@1]
|
||||
__b1_from___b2:
|
||||
@ -328,7 +326,6 @@ __start: {
|
||||
lda #>0
|
||||
sta.z SCREEN+1
|
||||
// [3] call init_1
|
||||
//#pragma constructor
|
||||
jsr init_1
|
||||
// [4] phi from __start::__init1 to __start::@2 [phi:__start::__init1->__start::@2]
|
||||
__b2_from___init1:
|
||||
@ -336,7 +333,6 @@ __start: {
|
||||
// __start::@2
|
||||
__b2:
|
||||
// [5] call init_2
|
||||
//#pragma constructor
|
||||
jsr init_2
|
||||
// [6] phi from __start::@2 to __start::@1 [phi:__start::@2->__start::@1]
|
||||
__b1_from___b2:
|
||||
@ -475,13 +471,11 @@ __start: {
|
||||
sta.z SCREEN+1
|
||||
// #pragma constructor_for(init_1, print)
|
||||
// [3] call init_1
|
||||
//#pragma constructor
|
||||
jsr init_1
|
||||
// [4] phi from __start::__init1 to __start::@2 [phi:__start::__init1->__start::@2]
|
||||
// __start::@2
|
||||
// #pragma constructor_for(init_2, print)
|
||||
// [5] call init_2
|
||||
//#pragma constructor
|
||||
jsr init_2
|
||||
// [6] phi from __start::@2 to __start::@1 [phi:__start::@2->__start::@1]
|
||||
// __start::@1
|
||||
|
Loading…
x
Reference in New Issue
Block a user