1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-02-28 23:29:38 +00:00

Upgraded to Picocli 4.2.0. Added support for -Dname command-line option for defining a macro on the command line.

This commit is contained in:
jespergravgaard 2020-05-10 00:07:12 +02:00
parent 16d19d69a4
commit f2ece49ded
6 changed files with 58 additions and 32 deletions

View File

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

View File

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

View File

@ -23,6 +23,6 @@
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: cml.kickass:kickassembler:5.14" level="project" />
<orderEntry type="library" name="Maven: info.picocli:picocli:3.6.0" level="project" />
<orderEntry type="library" name="Maven: info.picocli:picocli:4.2.0" level="project" />
</component>
</module>

View File

@ -49,7 +49,7 @@
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>3.6.0</version>
<version>4.2.0</version>
</dependency>
</dependencies>

View File

@ -15,10 +15,7 @@ import java.nio.file.FileAlreadyExistsException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
@ -36,7 +33,7 @@ import java.util.stream.Collectors;
optionListHeading = "%nOptions:%n",
version = "KickC 0.8.1 BETA"
)
public class KickC implements Callable<Void> {
public class KickC implements Callable<Integer> {
@CommandLine.Parameters(index = "0", arity = "0..n", description = "The C source files to compile.")
private List<Path> cFiles = null;
@ -59,7 +56,7 @@ public class KickC implements Callable<Void> {
@CommandLine.Option(names = {"-d"}, description = "Debug the assembled prg file using C64Debugger. Implicitly assembles the output.")
private boolean debug = false;
@CommandLine.Option(names = {"-D"}, description = "Define a macro to have a specific value.")
@CommandLine.Option(names = {"-D"}, parameterConsumer = DefineConsumer.class, description = "Define macro to value (1 if no value given).")
private Map<String, String> defines = null;
@CommandLine.Option(names = {"-E"}, description = "Only run the preprocessor. Output is sent to standard out.")
@ -171,14 +168,16 @@ public class KickC implements Callable<Void> {
private String calling = null;
/** Program Exit Code signaling a compile error. */
public static final int COMPILE_ERROR = 1;
public static final int COMPILE_ERROR = CommandLine.ExitCode.SOFTWARE;
public static void main(String[] args) {
CommandLine.call(new KickC(), args);
final CommandLine commandLine = new CommandLine(new KickC());
final int exitCode = commandLine.execute(args);
System.exit(exitCode);
}
@Override
public Void call() throws Exception {
public Integer call() throws Exception {
System.out.println("//--------------------------------------------------");
System.out.println("// " + getVersion() + " by Jesper Gravgaard ");
System.out.println("//--------------------------------------------------");
@ -195,7 +194,7 @@ public class KickC implements Callable<Void> {
supported.append(value.getName()).append(" ");
}
System.err.println(supported);
System.exit(COMPILE_ERROR);
return COMPILE_ERROR;
}
compiler.setTargetPlatform(targetPlatform);
}
@ -210,7 +209,7 @@ public class KickC implements Callable<Void> {
supported.append(value.getName()).append(" ");
}
System.err.println(supported);
System.exit(COMPILE_ERROR);
return COMPILE_ERROR;
}
compiler.setTargetCpu(targetCpu);
}
@ -325,7 +324,7 @@ public class KickC implements Callable<Void> {
compiler.setVariableBuilderConfig(config);
} catch(CompileError e) {
System.err.println(e.getMessage());
System.exit(COMPILE_ERROR);
return COMPILE_ERROR;
}
}
@ -339,7 +338,7 @@ public class KickC implements Callable<Void> {
supported.append(value.getName()).append(" ");
}
System.err.println(supported);
System.exit(COMPILE_ERROR);
return COMPILE_ERROR;
}
compiler.setCallingConvention(callingConvention);
}
@ -354,7 +353,7 @@ public class KickC implements Callable<Void> {
} catch(CompileError e) {
// Print the error and exit with compile error
System.err.println(e.getMessage());
System.exit(COMPILE_ERROR);
return COMPILE_ERROR;
}
return null;
}
@ -366,7 +365,7 @@ public class KickC implements Callable<Void> {
} catch(CompileError e) {
// Print the error and exit with compile error
System.err.println(e.getMessage());
System.exit(COMPILE_ERROR);
return COMPILE_ERROR;
}
String asmFileName = outputFileNameBase + ".asm";
@ -463,7 +462,7 @@ public class KickC implements Callable<Void> {
}
}
return null;
return CommandLine.ExitCode.OK;
}
private void configVerbosity(Compiler compiler) {
@ -545,4 +544,32 @@ public class KickC implements Callable<Void> {
return i > 0 ? name.substring(i + 1) : "";
}
/**
* Picocli Parameter Consumer for -D defines that allow both -Dname and -Dname=Value
*/
static class DefineConsumer implements CommandLine.IParameterConsumer {
@Override
public void consumeParameters(
Stack<String> args,
CommandLine.Model.ArgSpec argSpec,
CommandLine.Model.CommandSpec commandSpec) {
if(args.isEmpty()) {
throw new CommandLine.ParameterException(commandSpec.commandLine(),
"Missing required parameter");
}
String parameter = args.pop();
String[] keyValue = parameter.split("=", 2);
String key = keyValue[0];
String value = keyValue.length > 1
? keyValue[1]
: "1";
Map<String, String> map = argSpec.getValue();
if(map==null) {
map = new LinkedHashMap<>();
argSpec.setValue(map);
}
map.put(key, value);
}
}
}

View File

@ -23,7 +23,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import static junit.framework.TestCase.fail;
import static org.junit.Assert.assertTrue;