|
@@ -38,6 +38,7 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
import de.mcs.tools.IntelHex;
|
|
|
import de.mcs.tools.sps.exceptions.SyntaxError;
|
|
|
+import de.mcs.tools.sps.mnemonic.HARDWARE;
|
|
|
import de.mcs.tools.sps.mnemonic.JMP;
|
|
|
import de.mcs.tools.sps.mnemonic.Mnemonic;
|
|
|
import de.mcs.tools.sps.mnemonic.MnemonicFactory;
|
|
@@ -55,12 +56,13 @@ import de.mcs.utils.jsap.SwitchOption;
|
|
|
public class SPSAssembler {
|
|
|
|
|
|
private static File source;
|
|
|
- private static File destination;
|
|
|
+ private static HARDWARE destination;
|
|
|
private static int lineNumber;
|
|
|
private static int srcLineNumber;
|
|
|
private static Map<String, Integer> labels = new HashMap<>();
|
|
|
private static boolean inBlockComment;
|
|
|
private static List<Mnemonic> mnemonics = new ArrayList<>();
|
|
|
+ private static File destinationFile;
|
|
|
|
|
|
/**
|
|
|
*
|
|
@@ -78,13 +80,20 @@ public class SPSAssembler {
|
|
|
}
|
|
|
|
|
|
@StringOption(shortKey = 'd', longKey = "destination", name = "destination system", defaultValue = "HOLTEK", help = "the destination system to compile to.", required = false)
|
|
|
- public static void setDestinationSystemFile(String destination) {
|
|
|
- System.out.printf("set destination %s\r\n", destination);
|
|
|
+ public static void setDestinationSystem(String value) {
|
|
|
+ destination = HARDWARE.valueOf((value.toUpperCase()));
|
|
|
}
|
|
|
|
|
|
- @FileOption(index = 1, name = "source file", help = "source file to compile", required = false)
|
|
|
- public static void setSourceFile(File sourceFile) {
|
|
|
- System.out.printf("set source to: %s\r\n", sourceFile);
|
|
|
+ @FileOption(index = 1, name = "source file", help = "source file to compile", required = true, mustExists = true)
|
|
|
+ public static void setSourceFile(File file) {
|
|
|
+ source = file;
|
|
|
+ }
|
|
|
+
|
|
|
+ @FileOption(index = 2, name = "destination file", help = "destination file to compile to", required = false)
|
|
|
+ public static void setDestinationFile(File file) {
|
|
|
+ if (file != null) {
|
|
|
+ destinationFile = file;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -94,22 +103,16 @@ public class SPSAssembler {
|
|
|
public static void main(String[] args) throws IOException, SyntaxError {
|
|
|
CommandlineProcessor.processCommandline(SPSAssembler.class, args);
|
|
|
|
|
|
- if (args.length == 0) {
|
|
|
- showHelp();
|
|
|
- }
|
|
|
- source = new File(args[0]);
|
|
|
if (!source.exists()) {
|
|
|
throw new FileNotFoundException(String.format("source file not found. %s", source.getAbsolutePath()));
|
|
|
}
|
|
|
System.out.printf("source file: %s \r\n", source.getName());
|
|
|
- if (args.length > 1) {
|
|
|
- destination = new File(args[1]);
|
|
|
- } else {
|
|
|
+ if (destinationFile == null) {
|
|
|
String name = source.getName();
|
|
|
name = name.substring(0, source.getName().lastIndexOf("."));
|
|
|
- destination = new File(source.getParentFile(), name + ".hex");
|
|
|
+ destinationFile = new File(source.getParentFile(), name + ".hex");
|
|
|
}
|
|
|
- System.out.printf("destination file: %s \r\n", destination.getName());
|
|
|
+ System.out.printf("destination file: %s \r\n", destinationFile.getName());
|
|
|
System.out.println();
|
|
|
|
|
|
try {
|
|
@@ -152,7 +155,7 @@ public class SPSAssembler {
|
|
|
data[i] = (byte) mnemonic.getByte();
|
|
|
i++;
|
|
|
}
|
|
|
- FileOutputStream output = new FileOutputStream(destination);
|
|
|
+ FileOutputStream output = new FileOutputStream(destinationFile);
|
|
|
intelHex.writeHexStream(output, data);
|
|
|
output.close();
|
|
|
}
|