mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-14 23:04:57 +00:00
Added another 2 word fragments. Added compiler commandline option to show fragment -fragment <signature>. Closes #145
This commit is contained in:
parent
ea98c9e2eb
commit
ad6a1910c8
@ -0,0 +1,8 @@
|
|||||||
|
sta $ff
|
||||||
|
sec
|
||||||
|
lda {c1},y
|
||||||
|
sbc $ff
|
||||||
|
sta {c1},y
|
||||||
|
lda {c1}+1,y
|
||||||
|
sbc #0
|
||||||
|
sta {c1},y
|
@ -0,0 +1,8 @@
|
|||||||
|
stx $ff
|
||||||
|
sec
|
||||||
|
lda {c1},y
|
||||||
|
sbc $ff
|
||||||
|
sta {c1},y
|
||||||
|
lda {c1}+1,y
|
||||||
|
sbc #0
|
||||||
|
sta {c1},y
|
@ -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,6 +117,17 @@ 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();
|
||||||
@ -228,6 +245,8 @@ public class KickC implements Callable<Void> {
|
|||||||
process.waitFor();
|
process.waitFor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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+" "));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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,8 +157,12 @@ 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, "");
|
||||||
|
}
|
||||||
|
log.append("");
|
||||||
}
|
}
|
||||||
assertTrue("Fragment cannot be synthesized " + signature, templates.size() > 0);
|
assertTrue("Fragment cannot be synthesized " + signature, templates.size() > 0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user