diff --git a/src/main/java/dk/camelot64/kickc/model/VariableBuilder.java b/src/main/java/dk/camelot64/kickc/model/VariableBuilder.java index 519613359..d9777f941 100644 --- a/src/main/java/dk/camelot64/kickc/model/VariableBuilder.java +++ b/src/main/java/dk/camelot64/kickc/model/VariableBuilder.java @@ -319,7 +319,7 @@ public class VariableBuilder { return Variable.MemoryArea.ZEROPAGE_MEMORY; else if(hasDirective(Directive.MemMain.class)) return Variable.MemoryArea.MAIN_MEMORY; - Directive.Address addressDirective = findDirective(Directive.Address.class); + Directive.Address addressDirective = findDirective(Directive.Address.class, directives); if(addressDirective != null) return (addressDirective.address < 0x100) ? Variable.MemoryArea.ZEROPAGE_MEMORY : Variable.MemoryArea.MAIN_MEMORY; else if(!isConstant() && isOptimize()) @@ -341,7 +341,7 @@ public class VariableBuilder { * @return The memory alignment */ public Integer getAlignment() { - Directive.Align alignDirective = findDirective(Directive.Align.class); + Directive.Align alignDirective = findDirective(Directive.Align.class, directives); if(alignDirective != null) { if(isArray()) { return alignDirective.alignment; @@ -359,7 +359,7 @@ public class VariableBuilder { * @return Hard-coded register allocation. Null if not hard-coded. */ public Registers.Register getRegister() { - Directive.Address addressDirective = findDirective(Directive.Address.class); + Directive.Address addressDirective = findDirective(Directive.Address.class, directives); if(addressDirective != null) { Variable.MemoryArea memoryArea = (addressDirective.address < 0x100) ? Variable.MemoryArea.ZEROPAGE_MEMORY : Variable.MemoryArea.MAIN_MEMORY; if(Variable.MemoryArea.ZEROPAGE_MEMORY.equals(memoryArea)) { @@ -370,7 +370,7 @@ public class VariableBuilder { } } - Directive.NamedRegister registerDirective = findDirective(Directive.NamedRegister.class); + Directive.NamedRegister registerDirective = findDirective(Directive.NamedRegister.class, directives); if(registerDirective != null) { Registers.Register register = Registers.getRegister(registerDirective.name); if(register == null) { @@ -391,8 +391,18 @@ public class VariableBuilder { * @param The class of the type to look for * @return true if the directive if found. false otherwise. */ - public boolean hasDirective(Class directiveClass) { - return findDirective(directiveClass) != null; + private boolean hasDirective(Class directiveClass) { + return findDirective(directiveClass, directives) != null; + } + /** + * Examines whether a specific directive is present in the source + * + * @param directiveClass The class of the type to look for + * @param The class of the type to look for + * @return true if the directive if found. false otherwise. + */ + public static boolean hasDirective(Class directiveClass, List directives) { + return findDirective(directiveClass, directives) != null; } /** @@ -402,7 +412,7 @@ public class VariableBuilder { * @param The class of the type to look for * @return The directive if found. null if not found. */ - private DirectiveClass findDirective(Class directiveClass) { + private static DirectiveClass findDirective(Class directiveClass, List directives) { if(directives == null) return null; for(Directive directive : directives) { if(directiveClass.isInstance(directive)) { diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java index 2d070edd8..9a0b37ecf 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java @@ -261,12 +261,15 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor@1] +__b1_from___bbegin: + jmp __b1 + // @1 +__b1: + // [2] call main + // [4] phi from @1 to main [phi:@1->main] +main_from___b1: + jsr main + // [3] phi from @1 to @end [phi:@1->@end] +__bend_from___b1: + jmp __bend + // @end +__bend: + // main +// Definition of main() +main: { + jmp __breturn + // main::@return + __breturn: + // [5] return + rts +} + // File Data + +REGISTER UPLIFT POTENTIAL REGISTERS + +REGISTER UPLIFT SCOPES +Uplift Scope [main] +Uplift Scope [] + +Uplifting [main] best 48 combination +Uplifting [] best 48 combination + +ASSEMBLER BEFORE OPTIMIZATION + // File Comments +// Test declaration of intrinsic without body + // Upstart +.pc = $801 "Basic" +:BasicUpstart(__bbegin) +.pc = $80d "Program" + // Global Constants & labels + // @begin +__bbegin: + // [1] phi from @begin to @1 [phi:@begin->@1] +__b1_from___bbegin: + jmp __b1 + // @1 +__b1: + // [2] call main + // [4] phi from @1 to main [phi:@1->main] +main_from___b1: + jsr main + // [3] phi from @1 to @end [phi:@1->@end] +__bend_from___b1: + jmp __bend + // @end +__bend: + // main +// Definition of main() +main: { + jmp __breturn + // main::@return + __breturn: + // [5] return + rts +} + // File Data + +ASSEMBLER OPTIMIZATIONS +Removing instruction jmp __b1 +Removing instruction jmp __bend +Removing instruction jmp __breturn +Succesful ASM optimization Pass5NextJumpElimination +Removing instruction __b1_from___bbegin: +Removing instruction __b1: +Removing instruction main_from___b1: +Removing instruction __bend_from___b1: +Succesful ASM optimization Pass5RedundantLabelElimination +Removing instruction __bend: +Removing instruction __breturn: +Succesful ASM optimization Pass5UnusedLabelElimination +Updating BasicUpstart to call main directly +Removing instruction jsr main +Succesful ASM optimization Pass5SkipBegin +Removing instruction __bbegin: +Succesful ASM optimization Pass5UnusedLabelElimination + +FINAL SYMBOL TABLE +(label) @1 +(label) @begin +(label) @end +(void()) main() +(label) main::@return + + + +FINAL ASSEMBLER +Score: 6 + + // File Comments +// Test declaration of intrinsic without body + // Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + // Global Constants & labels + // @begin + // [1] phi from @begin to @1 [phi:@begin->@1] + // @1 + // [2] call main + // [4] phi from @1 to main [phi:@1->main] + // [3] phi from @1 to @end [phi:@1->@end] + // @end + // main +// Definition of main() +main: { + // main::@return + // } + // [5] return + rts +} + // File Data + diff --git a/src/test/ref/cstyle-decl-function-intrinsic.sym b/src/test/ref/cstyle-decl-function-intrinsic.sym new file mode 100644 index 000000000..5b1ee8133 --- /dev/null +++ b/src/test/ref/cstyle-decl-function-intrinsic.sym @@ -0,0 +1,6 @@ +(label) @1 +(label) @begin +(label) @end +(void()) main() +(label) main::@return +