1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-06-03 07:29:37 +00:00

Created initial simple commandline using picocli.

This commit is contained in:
jespergravgaard 2018-08-23 23:54:39 +02:00
parent 8efb7f9f2f
commit c05b04ff3c
4 changed files with 89 additions and 1 deletions

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: info.picocli:picocli:3.5.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/info/picocli/picocli/3.5.2/picocli-3.5.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/info/picocli/picocli/3.5.2/picocli-3.5.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/info/picocli/picocli/3.5.2/picocli-3.5.2-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
@ -21,5 +21,6 @@
<orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: cml.kickass:kickassembler:4.19" level="project" />
<orderEntry type="library" name="Maven: info.picocli:picocli:3.5.2" level="project" />
</component>
</module>

View File

@ -38,6 +38,11 @@
<artifactId>kickassembler</artifactId>
<version>4.19</version>
</dependency>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>3.5.2</version>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,69 @@
package dk.camelot64.kickc;
import dk.camelot64.kickc.model.Program;
import picocli.CommandLine;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.concurrent.Callable;
/** KickC Commandline */
@CommandLine.Command(description = "Compiles KickC source files to KickAssembler.",
name = "kickc", mixinStandardHelpOptions = true, version = "KickC 0.7")
public class KickC implements Callable<Void> {
@CommandLine.Parameters(index = "0", description = "The KickC file to compile.")
private File file = null;
@CommandLine.Option(names = {"-libdir", "-I"}, description = "Path to a library folder, where the compiler looks for included files.")
private File libdir = null;
@CommandLine.Option(names = {"-o"}, description = "Name of the output file. By default it is the same as the input file with extension .asm")
private String outname = null;
public static void main(String[] args) throws Exception {
CommandLine.call(new KickC(), args);
}
@Override
public Void call() throws Exception {
System.out.println("//------------------------------------");
System.out.println("// KickC v0.7 by Jesper Gravgaard ");
System.out.println("//------------------------------------");
Compiler compiler = new Compiler();
if(libdir != null) {
compiler.addImportPath(libdir.getPath());
}
if(outname == null) {
outname = getFileBaseName(file) + ".asm";
}
System.out.println("Compiling "+file.getPath());
Program program = compiler.compile(file.getName());
System.out.println("Writing asm file "+outname);
FileOutputStream outputStream = new FileOutputStream(outname);
OutputStreamWriter writer = new OutputStreamWriter(outputStream);
String assembler = program.getAsm().toString(false);
writer.write(assembler);
writer.close();
outputStream.close();
return null;
}
String getFileBaseName(File file) {
String name = file.getName();
int i = name.lastIndexOf('.');
return i > 0 ? name.substring(0, i) : name;
}
String getFileExtension(File file) {
if(file == null) {
return "";
}
String name = file.getName();
int i = name.lastIndexOf('.');
return i > 0 ? name.substring(i + 1) : "";
}
}