1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-23 08:32:39 +00:00

Optimized fragments in test (still needs proper handling of CPU aspects). Added error when encountering unsupported const parameters. Closes #331

This commit is contained in:
jespergravgaard 2019-10-03 10:29:58 +02:00
parent ec6139de54
commit f4206a2e84
5 changed files with 84 additions and 10 deletions

View File

@ -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");

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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<width-1; i++)
for( word j=0;j<width-1; j++)
*s++ = *m++;
}