diff --git a/src/main/java/dk/camelot64/kickc/Compiler.java b/src/main/java/dk/camelot64/kickc/Compiler.java index df45f2520..95629f117 100644 --- a/src/main/java/dk/camelot64/kickc/Compiler.java +++ b/src/main/java/dk/camelot64/kickc/Compiler.java @@ -93,6 +93,10 @@ public class Compiler { program.initAsmFragmentSynthesizer(); } + public void initAsmFragmentSynthesizer(AsmFragmentTemplateSynthesizer synthesizer) { + program.initAsmFragmentSynthesizer(synthesizer); + } + public AsmFragmentTemplateSynthesizer getAsmFragmentSynthesizer() { return program.getAsmFragmentSynthesizer(); } @@ -115,7 +119,6 @@ public class Compiler { } program.setFileName(fileName); - initAsmFragmentSynthesizer(); try { Path currentPath = new File(".").toPath(); if(this.linkScriptFileName != null) { @@ -167,6 +170,7 @@ public class Compiler { new Pass1StructTypeSizeFix(program).execute(); new Pass1AssertReturn(program).execute(); new Pass1AssertUsedVars(program).execute(); + new Pass1AssertNoConstParams(program).execute(); if(getLog().isVerbosePass1CreateSsa()) { getLog().append("SYMBOLS"); diff --git a/src/main/java/dk/camelot64/kickc/model/Program.java b/src/main/java/dk/camelot64/kickc/model/Program.java index a5092fe29..af4015512 100644 --- a/src/main/java/dk/camelot64/kickc/model/Program.java +++ b/src/main/java/dk/camelot64/kickc/model/Program.java @@ -203,6 +203,9 @@ public class Program { this.asmFragmentSynthesizer = new AsmFragmentTemplateSynthesizer(asmFragmentBaseFolder, targetCpu, asmFragmentCacheFolder, getLog()); } + public void initAsmFragmentSynthesizer(AsmFragmentTemplateSynthesizer synthesizer) { + this.asmFragmentSynthesizer = synthesizer; + } public TargetCpu getTargetCpu() { return targetCpu; } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1AssertNoConstParams.java b/src/main/java/dk/camelot64/kickc/passes/Pass1AssertNoConstParams.java new file mode 100644 index 000000000..27a9df8e7 --- /dev/null +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1AssertNoConstParams.java @@ -0,0 +1,30 @@ +package dk.camelot64.kickc.passes; + +import dk.camelot64.kickc.model.CompileError; +import dk.camelot64.kickc.model.Program; +import dk.camelot64.kickc.model.symbols.Procedure; +import dk.camelot64.kickc.model.symbols.Variable; + +/** + * Check that no parameters are declared const + */ +public class Pass1AssertNoConstParams extends Pass1Base { + + public Pass1AssertNoConstParams(Program program) { + super(program); + } + + @Override + public boolean step() { + for(Procedure procedure : getScope().getAllProcedures(true)) { + for(Variable parameter : procedure.getParameters()) { + if(parameter.isDeclaredConstant()) { + throw new CompileError("Error! Const parameters not supported "+parameter.getName()+" in "+ procedure.getFullName()+"()"); + } + } + } + return false; + } + +} + diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index eef8703e2..d1eea69e8 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -3,8 +3,10 @@ package dk.camelot64.kickc.test; import dk.camelot64.kickc.CompileLog; import dk.camelot64.kickc.Compiler; import dk.camelot64.kickc.asm.AsmProgram; +import dk.camelot64.kickc.fragment.AsmFragmentTemplateSynthesizer; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.Program; +import dk.camelot64.kickc.model.TargetCpu; import kickass.KickAssembler; import kickass.nonasm.c64.CharToPetsciiConverter; import org.junit.AfterClass; @@ -127,15 +129,22 @@ public class TestPrograms { compileAndCompare("string-pointer-problem"); } - //@Test - //public void testOs52() throws IOException, URISyntaxException { - // compileAndCompare("complex/unit5/os5.2"); - //} +/* + @Test + public void testMaze() throws IOException, URISyntaxException { + compileAndCompare("complex/maze/maze", log().verboseSSAOptimize()); + } - //@Test - //public void testOs51() throws IOException, URISyntaxException { - // compileAndCompare("complex/unit5/os5.1", log().verboseSSAOptimize()); - //} + @Test + public void testOs52() throws IOException, URISyntaxException { + compileAndCompare("complex/unit5/os5.2"); + } + + @Test + public void testOs51() throws IOException, URISyntaxException { + compileAndCompare("complex/unit5/os5.1"); + } +*/ @Test public void testCpu6502() throws IOException, URISyntaxException { @@ -2406,6 +2415,11 @@ public class TestPrograms { compileAndCompare("const-word-pointer"); } + @Test + public void testConstParam1() throws IOException, URISyntaxException { + assertError("const-param-1", "Error! Const parameters not supported", true); + } + @Test public void testConstParam() throws IOException, URISyntaxException { compileAndCompare("const-param"); @@ -3242,8 +3256,13 @@ public class TestPrograms { compileAndCompare("condition-type-mismatch"); } + static AsmFragmentTemplateSynthesizer asmFragmentSynthesizer; + @BeforeClass public static void setUp() { + Path asmFragmentBaseFolder = new File("src/main/fragment/").toPath(); + Path asmFragmentCacheFolder = null; + asmFragmentSynthesizer = new AsmFragmentTemplateSynthesizer(asmFragmentBaseFolder, TargetCpu.MOS6502X, asmFragmentCacheFolder, new CompileLog()); } @AfterClass @@ -3332,7 +3351,7 @@ public class TestPrograms { tester.testFile(filename, upliftCombinations, log); } - private void testFile(String fileName, Integer upliftCombinations, CompileLog compileLog) throws IOException, URISyntaxException { + private void testFile(String fileName, Integer upliftCombinations, CompileLog compileLog) throws IOException { System.out.println("Testing output for " + fileName); Compiler compiler = new Compiler(); //compiler.setWarnFragmentMissing(true); @@ -3343,6 +3362,7 @@ public class TestPrograms { } compiler.addImportPath(stdlibPath); compiler.addImportPath(testPath); + compiler.initAsmFragmentSynthesizer(asmFragmentSynthesizer); if(upliftCombinations != null) { compiler.setUpliftCombinations(upliftCombinations); } diff --git a/src/test/kc/const-param-1.kc b/src/test/kc/const-param-1.kc new file mode 100644 index 000000000..d59d33421 --- /dev/null +++ b/src/test/kc/const-param-1.kc @@ -0,0 +1,17 @@ + +void main() { + char *maze = 0xa000; + word width=40; + word height=25; + ShowMaze(maze, width, height); +} + +const char* SCREEN = 0x0400; + +void ShowMaze(const char *maze, word width, word height) { + char* s = SCREEN; + char* m = maze; + for( word i=0;i