1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-08 17:54:40 +00:00

Added another 2 word fragments. Added compiler commandline option to show fragment -fragment <signature>. Closes #145

This commit is contained in:
jespergravgaard 2019-03-12 17:53:33 +01:00
parent ea98c9e2eb
commit ad6a1910c8
5 changed files with 151 additions and 107 deletions

View File

@ -0,0 +1,8 @@
sta $ff
sec
lda {c1},y
sbc $ff
sta {c1},y
lda {c1}+1,y
sbc #0
sta {c1},y

View File

@ -0,0 +1,8 @@
stx $ff
sec
lda {c1},y
sbc $ff
sta {c1},y
lda {c1}+1,y
sbc #0
sta {c1},y

View File

@ -1,6 +1,8 @@
package dk.camelot64.kickc; package dk.camelot64.kickc;
import dk.camelot64.kickc.fragment.AsmFragmentTemplate;
import dk.camelot64.kickc.fragment.AsmFragmentTemplateSynthesizer; import dk.camelot64.kickc.fragment.AsmFragmentTemplateSynthesizer;
import dk.camelot64.kickc.fragment.AsmFragmentTemplateUsages;
import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.Program; import dk.camelot64.kickc.model.Program;
import kickass.KickAssembler; import kickass.KickAssembler;
@ -8,6 +10,7 @@ import picocli.CommandLine;
import java.io.*; import java.io.*;
import java.nio.file.*; import java.nio.file.*;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -27,7 +30,7 @@ import java.util.concurrent.Callable;
) )
public class KickC implements Callable<Void> { public class KickC implements Callable<Void> {
@CommandLine.Parameters(index = "0", description = "The KickC source file to compile.") @CommandLine.Parameters(index = "0", arity="0..1", description = "The KickC source file to compile.")
private Path kcFile = null; private Path kcFile = null;
@CommandLine.Option(names = {"-I", "-libdir" }, description = "Path to a library folder, where the compiler looks for included files. This option can be repeated to add multiple library folders.") @CommandLine.Option(names = {"-I", "-libdir" }, description = "Path to a library folder, where the compiler looks for included files. This option can be repeated to add multiple library folders.")
@ -87,6 +90,9 @@ public class KickC implements Callable<Void> {
@CommandLine.Option(names = {"-vasmoptimize" }, description = "Verbosity Option. Assembler optimization.") @CommandLine.Option(names = {"-vasmoptimize" }, description = "Verbosity Option. Assembler optimization.")
private boolean verboseAsmOptimize = false; private boolean verboseAsmOptimize = false;
@CommandLine.Option(names = {"-fragment" }, description = "Print the ASM code for a named fragment. The fragment is loaded/synthesized and the ASM variations are written to the output.")
private String fragment = null;
public static void main(String[] args) { public static void main(String[] args) {
CommandLine.call(new KickC(), args); CommandLine.call(new KickC(), args);
} }
@ -111,14 +117,25 @@ public class KickC implements Callable<Void> {
AsmFragmentTemplateSynthesizer.initialize("fragment/"); AsmFragmentTemplateSynthesizer.initialize("fragment/");
} }
if(fragment!=null) {
compiler.getLog().setSysOut(true);
Collection<AsmFragmentTemplate> fragmentTemplates = AsmFragmentTemplateSynthesizer.getFragmentTemplates(fragment, compiler.getLog());
for(AsmFragmentTemplate fragmentTemplate : fragmentTemplates) {
AsmFragmentTemplateUsages.logTemplate(compiler.getLog(), fragmentTemplate, "");
}
compiler.getLog().setSysOut(false);
}
if(kcFile!=null) {
String fileBaseName = getFileBaseName(kcFile); String fileBaseName = getFileBaseName(kcFile);
Path kcFileDir = kcFile.getParent(); Path kcFileDir = kcFile.getParent();
if(kcFileDir==null) { if(kcFileDir == null) {
kcFileDir = FileSystems.getDefault().getPath("."); kcFileDir = FileSystems.getDefault().getPath(".");
} }
if(outputDir==null) { if(outputDir == null) {
outputDir = kcFileDir; outputDir = kcFileDir;
} }
if(!Files.exists(outputDir)) { if(!Files.exists(outputDir)) {
@ -129,7 +146,7 @@ public class KickC implements Callable<Void> {
asmFileName = fileBaseName + ".asm"; asmFileName = fileBaseName + ".asm";
} }
if(optimizeUpliftCombinations!=null) { if(optimizeUpliftCombinations != null) {
compiler.setUpliftCombinations(optimizeUpliftCombinations); compiler.setUpliftCombinations(optimizeUpliftCombinations);
} }
@ -210,7 +227,7 @@ public class KickC implements Callable<Void> {
// Assemble the asm-file if instructed // Assemble the asm-file if instructed
Path prgPath = outputDir.resolve(fileBaseName + ".prg"); Path prgPath = outputDir.resolve(fileBaseName + ".prg");
if(assemble || execute) { if(assemble || execute) {
Path kasmLogPath = outputDir.resolve(fileBaseName+".klog"); Path kasmLogPath = outputDir.resolve(fileBaseName + ".klog");
System.out.println("Assembling to " + prgPath.toString()); System.out.println("Assembling to " + prgPath.toString());
ByteArrayOutputStream kasmLogOutputStream = new ByteArrayOutputStream(); ByteArrayOutputStream kasmLogOutputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(kasmLogOutputStream)); System.setOut(new PrintStream(kasmLogOutputStream));
@ -224,10 +241,12 @@ public class KickC implements Callable<Void> {
// Execute the prg-file if instructed // Execute the prg-file if instructed
if(execute) { if(execute) {
System.out.println("Executing " + prgPath); System.out.println("Executing " + prgPath);
Process process = Runtime.getRuntime().exec("x64 " + prgPath.toString() ); Process process = Runtime.getRuntime().exec("x64 " + prgPath.toString());
process.waitFor(); process.waitFor();
} }
}
return null; return null;
} }

View File

@ -179,13 +179,17 @@ public class AsmFragmentTemplateUsages {
log.append(String.format("%8d", usage) + " " + template.getSignature()+" - templates: " + bestTemplates.size()); log.append(String.format("%8d", usage) + " " + template.getSignature()+" - templates: " + bestTemplates.size());
if(logBody) { if(logBody) {
for(AsmFragmentTemplate bestTemplate : bestTemplates) { for(AsmFragmentTemplate bestTemplate : bestTemplates) {
log.append(" " + (bestTemplate.isFile() ? "*" : "") + bestTemplate.getName() + " - clobber:" + bestTemplate.getClobber().toString() + " cycles:" + bestTemplate.getCycles()); logTemplate(log, bestTemplate, " ");
log.append(" " + bestTemplate.getBody().replace("\n", "\n "));
} }
} }
} }
} }
public static void logTemplate(CompileLog log, AsmFragmentTemplate template, String indent) {
log.append(indent + (template.isFile() ? "*" : "") + template.getName() + " - clobber:" + template.getClobber().toString() + " cycles:" + template.getCycles());
log.append(indent+ " " + template.getBody().replace("\n", "\n"+indent+" "));
}
} }

View File

@ -147,6 +147,7 @@ public class TestFragments {
/** /**
* Test that a specific fragment can be succesfully loaded/synthesized * Test that a specific fragment can be succesfully loaded/synthesized
*
* @param signature The fragment signature * @param signature The fragment signature
*/ */
private void testFragmentExists(String signature) { private void testFragmentExists(String signature) {
@ -156,10 +157,14 @@ public class TestFragments {
log.setVerboseFragmentLog(true); log.setVerboseFragmentLog(true);
List<AsmFragmentTemplate> templates = List<AsmFragmentTemplate> templates =
new ArrayList<>(AsmFragmentTemplateSynthesizer.getFragmentTemplates(signature, log)); new ArrayList<>(AsmFragmentTemplateSynthesizer.getFragmentTemplates(signature, log));
if(templates.size()==0) { if(templates.size() > 0) {
System.out.println(log.toString()); log.append("");
for(AsmFragmentTemplate template : templates) {
AsmFragmentTemplateUsages.logTemplate(log, template, "");
} }
assertTrue("Fragment cannot be synthesized "+signature, templates.size() > 0); log.append("");
}
assertTrue("Fragment cannot be synthesized " + signature, templates.size() > 0);
} }