| 
														
															@@ -21,13 +21,10 @@ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  */
 
														 | 
														
														 | 
														
															  */
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 package de.mcs.tools.sps;
 
														 | 
														
														 | 
														
															 package de.mcs.tools.sps;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-import java.io.BufferedWriter;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import java.io.File;
 
														 | 
														
														 | 
														
															 import java.io.File;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import java.io.FileNotFoundException;
 
														 | 
														
														 | 
														
															 import java.io.FileNotFoundException;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import java.io.FileOutputStream;
 
														 | 
														
														 | 
														
															 import java.io.FileOutputStream;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-import java.io.FileWriter;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import java.io.IOException;
 
														 | 
														
														 | 
														
															 import java.io.IOException;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-import java.io.Writer;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import java.nio.charset.Charset;
 
														 | 
														
														 | 
														
															 import java.nio.charset.Charset;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import java.nio.file.Files;
 
														 | 
														
														 | 
														
															 import java.nio.file.Files;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import java.util.ArrayList;
 
														 | 
														
														 | 
														
															 import java.util.ArrayList;
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -40,7 +37,7 @@ import java.util.Map.Entry; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import org.apache.commons.lang3.StringUtils;
 
														 | 
														
														 | 
														
															 import org.apache.commons.lang3.StringUtils;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-import de.mcs.tools.IntelHex;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+import de.mcs.tools.sps.exceptions.IllegalArgument;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import de.mcs.tools.sps.exceptions.SyntaxError;
 
														 | 
														
														 | 
														
															 import de.mcs.tools.sps.exceptions.SyntaxError;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import de.mcs.tools.sps.mnemonic.CALL;
 
														 | 
														
														 | 
														
															 import de.mcs.tools.sps.mnemonic.CALL;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import de.mcs.tools.sps.mnemonic.HARDWARE;
 
														 | 
														
														 | 
														
															 import de.mcs.tools.sps.mnemonic.HARDWARE;
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -69,24 +66,18 @@ public class SPSAssembler { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   private static final String START_MACRO_DEFINITION = ".macro";
 
														 | 
														
														 | 
														
															   private static final String START_MACRO_DEFINITION = ".macro";
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   private static File source;
 
														 | 
														
														 | 
														
															   private static File source;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   private static HARDWARE 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;
 
														 | 
														
														 | 
														
															   private static File destinationFile;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   private static FORMAT outputFormat;
 
														 | 
														
														 | 
														
															   private static FORMAT outputFormat;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  private static File include;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  private static boolean inMacro;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  private static Macro actualMacro;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  private static Map<String, Macro> macros = new HashMap<>();
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private static File includes;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  /**
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-   * 
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-   */
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  public SPSAssembler() {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    // TODO Auto-generated constructor stub
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  }
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private int lineNumber;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  // private int srcLineNumber;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private Map<String, Integer> labels;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private boolean inBlockComment;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private List<Mnemonic> mnemonics;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private boolean inMacro;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private Macro actualMacro;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private Map<String, Macro> macros;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   @SwitchOption(shortKey = 'h', longKey = "help", name = "help", help = "show this help page", required = false, defaultValue = false)
 
														 | 
														
														 | 
														
															   @SwitchOption(shortKey = 'h', longKey = "help", name = "help", help = "show this help page", required = false, defaultValue = false)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   public static void doHelp(boolean value) {
 
														 | 
														
														 | 
														
															   public static void doHelp(boolean value) {
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -106,10 +97,10 @@ public class SPSAssembler { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     destination = HARDWARE.valueOf((value.toUpperCase()));
 
														 | 
														
														 | 
														
															     destination = HARDWARE.valueOf((value.toUpperCase()));
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   }
 
														 | 
														
														 | 
														
															   }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  @FileOption(shortKey = 'i', longKey = "include", name = "include", defaultValue = "", help = "where to find the include files.", required = false)
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  @FileOption(shortKey = 'i', longKey = "includes", name = "includes", defaultValue = "", help = "where to find the includes files.", required = false)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   public static void setDestinationSystem(File file) {
 
														 | 
														
														 | 
														
															   public static void setDestinationSystem(File file) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if ((file != null) && !file.getName().equals("")) {
 
														 | 
														
														 | 
														
															     if ((file != null) && !file.getName().equals("")) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      include = file;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      includes = file;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     }
 
														 | 
														
														 | 
														
															     }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   }
 
														 | 
														
														 | 
														
															   }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -152,137 +143,162 @@ public class SPSAssembler { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         destinationFile = new File(source.getParentFile(), name + ext);
 
														 | 
														
														 | 
														
															         destinationFile = new File(source.getParentFile(), name + ext);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       }
 
														 | 
														
														 | 
														
															       }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       System.out.printf("destination file: %s \r\n", destinationFile.getName());
 
														 | 
														
														 | 
														
															       System.out.printf("destination file: %s \r\n", destinationFile.getName());
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      System.out.printf("output format: %s \r\n", outputFormat.name());
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       System.out.println();
 
														 | 
														
														 | 
														
															       System.out.println();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       try {
 
														 | 
														
														 | 
														
															       try {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        List<String> sourceFile = Files.readAllLines(source.toPath(), Charset.forName("UTF-8"));
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        for (String line : sourceFile) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-          srcLineNumber++;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-          parseLine(srcLineNumber, line);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        }
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        SPSAssembler spsAssembler = new SPSAssembler();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        spsAssembler.doWork(source);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        List<Mnemonic> mnemonics = spsAssembler.getMnemonics();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        outputMnemonics(mnemonics);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        outputLabels(spsAssembler);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        outputMacros(spsAssembler);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        outputFile(mnemonics);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       } catch (SyntaxError e) {
 
														 | 
														
														 | 
														
															       } catch (SyntaxError e) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         e.printStackTrace();
 
														 | 
														
														 | 
														
															         e.printStackTrace();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         System.err.println(e.getMessage());
 
														 | 
														
														 | 
														
															         System.err.println(e.getMessage());
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         System.exit(-1);
 
														 | 
														
														 | 
														
															         System.exit(-1);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       }
 
														 | 
														
														 | 
														
															       }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      // Checking destination
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      for (Iterator<Mnemonic> iterator = mnemonics.iterator(); iterator.hasNext();) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        Mnemonic mnemonic = iterator.next();
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        if (!mnemonic.allowedHardware().contains(destination)) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-          throw new SyntaxError(mnemonic.getLineNumber(), String.format(
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-              "the mnemonic \"%s\" with the argument \"%s\" is not availble on the choosen hardware \"%s\"",
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-              mnemonic.getName(), mnemonic.getArgument() == null ? "" : mnemonic.getArgument(), destination.name()));
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        }
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      }
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      System.out.println("parsing line numbers");
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      int address = 0;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      Mnemonic predecessor = null;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      for (Iterator<Mnemonic> iterator = mnemonics.iterator(); iterator.hasNext();) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        Mnemonic mnemonic = iterator.next();
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        if ((mnemonic instanceof JMP) || (mnemonic instanceof LOOPC) || (mnemonic instanceof LOOPD)
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            || (mnemonic instanceof CALL)) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-          if (mnemonic.isLabel()) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            processJMP(mnemonic, predecessor);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-          }
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        }
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        if (mnemonic instanceof RJMP) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-          if (mnemonic.isLabel()) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            processRJMP(address, mnemonic);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-          }
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        }
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        address++;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        predecessor = mnemonic;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      }
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      System.out.println("Mnemonics");
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      int pos = 0;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      for (Iterator<Mnemonic> iterator = mnemonics.iterator(); iterator.hasNext();) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        Mnemonic mnemonic = iterator.next();
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        System.out.printf("0x%03x: %s\r\n", pos, mnemonic.toString());
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        pos++;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      }
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      if ((labels != null) && (labels.size() > 0)) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        System.out.println();
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        System.out.println("labels");
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        for (Entry<String, Integer> entry : labels.entrySet()) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-          System.out.printf("%s: 0x%03x\r\n", entry.getKey(), entry.getValue());
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        }
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      }
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    } catch (Exception e) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      e.printStackTrace();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  /**
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   * @param mnemonics
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   * @throws IOException
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   * @throws FileNotFoundException
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   */
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private static void outputFile(List<Mnemonic> mnemonics) throws IOException, FileNotFoundException {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    try (FileOutputStream output = new FileOutputStream(destinationFile)) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       if (outputFormat.equals(FORMAT.HEX)) {
 
														 | 
														
														 | 
														
															       if (outputFormat.equals(FORMAT.HEX)) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        outputHEX();
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        new IntelHEXOutputter().output(mnemonics, output);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       } else if (outputFormat.equals(FORMAT.TPSTXT)) {
 
														 | 
														
														 | 
														
															       } else if (outputFormat.equals(FORMAT.TPSTXT)) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        outputTPSTXT();
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        new TPSTextOutputter().output(mnemonics, output);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       } else if (outputFormat.equals(FORMAT.HEXTXT)) {
 
														 | 
														
														 | 
														
															       } else if (outputFormat.equals(FORMAT.HEXTXT)) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        outputHEXTXT();
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        new HEXTextOutputter().output(mnemonics, output);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       }
 
														 | 
														
														 | 
														
															       }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    } catch (Exception e) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      e.printStackTrace();
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    } finally {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     }
 
														 | 
														
														 | 
														
															     }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   }
 
														 | 
														
														 | 
														
															   }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  private static void outputHEXTXT() {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    try (Writer writer = new BufferedWriter(new FileWriter(destinationFile))) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      int address = 0;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      for (Mnemonic mnemonic : mnemonics) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        writer.write(String.format("%02x", mnemonic.getByte()));
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        address++;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        if ((address % 8) == 0) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-          writer.write("\r\n");
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        } else {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-          writer.write(" ");
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        }
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  /**
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   * @param spsAssembler
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   */
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private static void outputMacros(SPSAssembler spsAssembler) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    Map<String, Macro> macros = spsAssembler.getMacros();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    if ((macros != null) && (macros.size() > 0)) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      System.out.println();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      System.out.println("macros");
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      for (Macro macro : macros.values()) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        System.out.printf("%s: %s\r\n", macro.getName(), macro.toString());
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       }
 
														 | 
														
														 | 
														
															       }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    } catch (IOException e) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      e.printStackTrace();
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    } finally {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     }
 
														 | 
														
														 | 
														
															     }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   }
 
														 | 
														
														 | 
														
															   }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  private static void outputTPSTXT() {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    try (Writer writer = new BufferedWriter(new FileWriter(destinationFile))) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      writer.write("Addr   BD   Befehl   Daten     Kommentar\r\n");
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      int address = 0;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      for (Mnemonic mnemonic : mnemonics) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        byte lowNibble = (byte) (mnemonic.getByte() & 0x0f);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        byte highNibble = (byte) ((mnemonic.getByte() >> 4) & 0x0f);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        writer.write(String.format("0x%03x  %02x   %4s     %4s      %s %s\r\n", address, mnemonic.getByte(),
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            nibbleToString(highNibble), nibbleToString(lowNibble), mnemonic.getName(),
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            StringUtils.isEmpty(mnemonic.getArgument()) ? "" : mnemonic.getArgument()));
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        address++;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  /**
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   * @param spsAssembler
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   */
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private static void outputLabels(SPSAssembler spsAssembler) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    Map<String, Integer> labels = spsAssembler.getLabels();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    if ((labels != null) && (labels.size() > 0)) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      System.out.println();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      System.out.println("labels");
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      for (Entry<String, Integer> entry : labels.entrySet()) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        System.out.printf("%s: 0x%03x\r\n", entry.getKey(), entry.getValue());
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       }
 
														 | 
														
														 | 
														
															       }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    } catch (IOException e) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      e.printStackTrace();
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    } finally {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     }
 
														 | 
														
														 | 
														
															     }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   }
 
														 | 
														
														 | 
														
															   }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  private static String nibbleToString(byte lowNibble) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    StringBuilder b = new StringBuilder();
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    b.append((lowNibble & 0x08) > 0 ? "X" : "0");
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    b.append((lowNibble & 0x04) > 0 ? "X" : "0");
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    b.append((lowNibble & 0x02) > 0 ? "X" : "0");
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    b.append((lowNibble & 0x01) > 0 ? "X" : "0");
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    return b.toString();
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  /**
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   * @param mnemonics
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   */
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private static void outputMnemonics(List<Mnemonic> mnemonics) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    System.out.println("Mnemonics");
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    int pos = 0;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    for (Iterator<Mnemonic> iterator = mnemonics.iterator(); iterator.hasNext();) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      Mnemonic mnemonic = iterator.next();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      System.out.printf("0x%03x: %s\r\n", pos, mnemonic.toString());
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      pos++;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  /**
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   * 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   */
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  public SPSAssembler() {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    lineNumber = 0;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    // srcLineNumber = 0;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    labels = new HashMap<>();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    inBlockComment = false;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    mnemonics = new ArrayList<>();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    inMacro = false;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    actualMacro = null;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    macros = new HashMap<>();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   }
 
														 | 
														
														 | 
														
															   }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  private static void outputHEX() throws FileNotFoundException, IOException {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    IntelHex intelHex = new IntelHex();
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    byte[] data = new byte[mnemonics.size()];
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    int i = 0;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    for (Mnemonic mnemonic : mnemonics) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      data[i] = (byte) mnemonic.getByte();
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      i++;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private void doWork(File source) throws IOException, SyntaxError {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    List<String> sourceFile = Files.readAllLines(source.toPath(), Charset.forName("UTF-8"));
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    for (int i = 0; i < sourceFile.size(); i++) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      String line = sourceFile.get(i);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      List<String> linesToAdd;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      do {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        linesToAdd = parseLine(i, line);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        if (linesToAdd != null) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          sourceFile.remove(i);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          sourceFile.addAll(i, linesToAdd);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          line = sourceFile.get(i);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          linesToAdd = parseLine(i, line);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      } while (linesToAdd != null);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    // Checking destination
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    checkingHardware();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    System.out.printf("start parsing file: %s\r\n", source.getName());
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    int address = 0;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    Mnemonic predecessor = null;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    for (Iterator<Mnemonic> iterator = mnemonics.iterator(); iterator.hasNext();) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      Mnemonic mnemonic = iterator.next();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      if ((mnemonic instanceof JMP) || (mnemonic instanceof LOOPC) || (mnemonic instanceof LOOPD)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          || (mnemonic instanceof CALL)) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        if (mnemonic.isLabel()) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          processJMP(mnemonic, predecessor);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      if (mnemonic instanceof RJMP) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        if (mnemonic.isLabel()) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          processRJMP(address, mnemonic);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      address++;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      predecessor = mnemonic;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     }
 
														 | 
														
														 | 
														
															     }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    FileOutputStream output = new FileOutputStream(destinationFile);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    intelHex.writeHexStream(output, data);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    output.close();
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   }
 
														 | 
														
														 | 
														
															   }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  private static void processJMP(Mnemonic mnemonic, Mnemonic predecessor) throws SyntaxError {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  /**
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   * @throws SyntaxError
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   */
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private void checkingHardware() throws SyntaxError {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    for (Iterator<Mnemonic> iterator = mnemonics.iterator(); iterator.hasNext();) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      Mnemonic mnemonic = iterator.next();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      if (!mnemonic.allowedHardware().contains(destination)) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        throw new SyntaxError(mnemonic.getLineNumber(),
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            String.format("the mnemonic \"%s\" with the argument \"%s\" is not availble on the choosen hardware \"%s\"",
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                mnemonic.getName(), mnemonic.getArgument() == null ? "" : mnemonic.getArgument(), destination.name()));
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private void processJMP(Mnemonic mnemonic, Mnemonic predecessor) throws SyntaxError {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     String label = mnemonic.getArgument();
 
														 | 
														
														 | 
														
															     String label = mnemonic.getArgument();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (!labels.containsKey(label)) {
 
														 | 
														
														 | 
														
															     if (!labels.containsKey(label)) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       throw new SyntaxError(mnemonic.getLineNumber(),
 
														 | 
														
														 | 
														
															       throw new SyntaxError(mnemonic.getLineNumber(),
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -302,7 +318,7 @@ public class SPSAssembler { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     }
 
														 | 
														
														 | 
														
															     }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   }
 
														 | 
														
														 | 
														
															   }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  private static void processRJMP(int address, Mnemonic mnemonic) throws SyntaxError {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private void processRJMP(int address, Mnemonic mnemonic) throws SyntaxError {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     String label = mnemonic.getArgument();
 
														 | 
														
														 | 
														
															     String label = mnemonic.getArgument();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (!labels.containsKey(label)) {
 
														 | 
														
														 | 
														
															     if (!labels.containsKey(label)) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       throw new SyntaxError(mnemonic.getLineNumber(),
 
														 | 
														
														 | 
														
															       throw new SyntaxError(mnemonic.getLineNumber(),
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -318,49 +334,45 @@ public class SPSAssembler { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     mnemonic.checkArgument();
 
														 | 
														
														 | 
														
															     mnemonic.checkArgument();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   }
 
														 | 
														
														 | 
														
															   }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  private static void parseLine(int srcLineNumber, String srcLine) throws SyntaxError {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private List<String> parseLine(int srcLineNumber, String srcLine) throws SyntaxError, IOException {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     String line = srcLine.trim();
 
														 | 
														
														 | 
														
															     String line = srcLine.trim();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    if (inMacro) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      actualMacro.addLine(line);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    if (line.startsWith(".")) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      // process pre compiler part
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      String label = getLabel(line);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      return precompiler(srcLineNumber, label);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } else {
 
														 | 
														
														 | 
														
															     } else {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      if (line.startsWith(":")) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        String label = getLabel(line);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        if (labels.containsKey(label)) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-          throw new SyntaxError(srcLineNumber,
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-              String.format("Label \"%s\" already definied in line %d.", label, labels.get(label)));
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        }
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        labels.put(label, lineNumber);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      } else if (line.startsWith(".")) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        // process pre compiler part
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        String label = getLabel(line);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        precompiler(srcLineNumber, label);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      if (inMacro) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        actualMacro.addLine(line);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       } else {
 
														 | 
														
														 | 
														
															       } else {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        Mnemonic mnemonic = getMnemonic(line);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        if (mnemonic != null) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-          lineNumber++;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-          mnemonics.add(mnemonic);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        if (line.startsWith(":")) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          String label = getLabel(line);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          if (labels.containsKey(label)) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            throw new SyntaxError(srcLineNumber,
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                String.format("Label \"%s\" already definied in line %d.", label, labels.get(label)));
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          labels.put(label, lineNumber);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        } else {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          Mnemonic mnemonic = getMnemonic(line, srcLineNumber);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          if (mnemonic != null) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            lineNumber++;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            mnemonics.add(mnemonic);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         }
 
														 | 
														
														 | 
														
															         }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       }
 
														 | 
														
														 | 
														
															       }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     }
 
														 | 
														
														 | 
														
															     }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    return null;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   }
 
														 | 
														
														 | 
														
															   }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  private static void precompiler(int srcLineNumber, String value) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private List<String> precompiler(int srcLineNumber, String value) throws IOException, SyntaxError {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     String label = value.trim().toLowerCase();
 
														 | 
														
														 | 
														
															     String label = value.trim().toLowerCase();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     String name = label;
 
														 | 
														
														 | 
														
															     String name = label;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (label.indexOf(" ") > 0) {
 
														 | 
														
														 | 
														
															     if (label.indexOf(" ") > 0) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       name = label.substring(0, label.indexOf(" "));
 
														 | 
														
														 | 
														
															       name = label.substring(0, label.indexOf(" "));
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     }
 
														 | 
														
														 | 
														
															     }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (INCLUDE_FILE.equals(name)) {
 
														 | 
														
														 | 
														
															     if (INCLUDE_FILE.equals(name)) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      // proccess include file
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      includeFile(srcLineNumber, label);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } else if (START_MACRO_DEFINITION.equals(name)) {
 
														 | 
														
														 | 
														
															     } else if (START_MACRO_DEFINITION.equals(name)) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      // macro definition
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      String[] arguments = label.split(" ");
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      String macroName = arguments[1];
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      String[] args = null;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      if (arguments.length > 2) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        args = Arrays.copyOfRange(arguments, 2, arguments.length);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      }
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      actualMacro = new Macro(macroName, args);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      startMacroDefinition(srcLineNumber, label);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       inMacro = true;
 
														 | 
														
														 | 
														
															       inMacro = true;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } else if (END_MACRO_DEFINITION.equalsIgnoreCase(label)) {
 
														 | 
														
														 | 
														
															     } else if (END_MACRO_DEFINITION.equalsIgnoreCase(label)) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       // end of macro definition
 
														 | 
														
														 | 
														
															       // end of macro definition
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -368,10 +380,71 @@ public class SPSAssembler { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       macros.put(actualMacro.getName(), actualMacro);
 
														 | 
														
														 | 
														
															       macros.put(actualMacro.getName(), actualMacro);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } else {
 
														 | 
														
														 | 
														
															     } else {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       // seems to be a macro usage
 
														 | 
														
														 | 
														
															       // seems to be a macro usage
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      name = name.substring(1);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      String[] arguments = label.split(" ");
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      if (arguments.length < 2) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        throw new IllegalArgument(srcLineNumber, "Need at least one argument for the macro name.");
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      String[] args = null;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      if (arguments.length > 1) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        args = Arrays.copyOfRange(arguments, 1, arguments.length);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      Macro macro = macros.get(name);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      if (macro == null) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        throw new SyntaxError(srcLineNumber, String.format("macro with name %s not define.", name));
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      List<String> macroMnemonics = macro.processMacro(args, srcLineNumber);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      return macroMnemonics;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    return null;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  /**
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   * @param srcLineNumber
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   * @param label
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   * @throws IllegalArgument
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   */
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private void startMacroDefinition(int srcLineNumber, String label) throws IllegalArgument {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    // macro definition
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    String[] arguments = label.split(" ");
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    if (arguments.length < 2) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      throw new IllegalArgument(srcLineNumber, "Need at least one argument for the macro name.");
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    String macroName = arguments[1];
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    String[] args = null;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    if (arguments.length > 2) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      args = Arrays.copyOfRange(arguments, 2, arguments.length);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    actualMacro = new Macro(macroName, args);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  /**
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   * @param srcLineNumber
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   * @param label
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   * @throws IllegalArgument
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   * @throws IOException
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   * @throws SyntaxError
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+   */
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private void includeFile(int srcLineNumber, String label) throws IllegalArgument, IOException, SyntaxError {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    String[] arguments = label.split(" ");
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    if (arguments.length < 2) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      throw new IllegalArgument(srcLineNumber, "Need at least one argument for the filename to include.");
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    File includeFile = new File(includes, String.format("%s.tps", arguments[1]));
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    if (!includeFile.exists()) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      throw new IllegalArgument(srcLineNumber, String.format("include file not found: %s", includeFile.getName()));
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     }
 
														 | 
														
														 | 
														
															     }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    System.out.println("=====");
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    System.out.printf("include file: %s \r\n", includeFile.getName());
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    SPSAssembler spsAssembler = new SPSAssembler();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    spsAssembler.doWork(includeFile);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    outputMnemonics(spsAssembler.getMnemonics());
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    outputLabels(spsAssembler);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    outputMacros(spsAssembler);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    System.out.println("=====");
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   }
 
														 | 
														
														 | 
														
															   }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  private static Mnemonic getMnemonic(String line) throws SyntaxError {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private Mnemonic getMnemonic(String line, int srcLineNumber) throws SyntaxError {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     String newLine = stripComments(line);
 
														 | 
														
														 | 
														
															     String newLine = stripComments(line);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (StringUtils.isNotEmpty(newLine)) {
 
														 | 
														
														 | 
														
															     if (StringUtils.isNotEmpty(newLine)) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       Mnemonic mnemonic = MnemonicFactory.getMnemonic(newLine, srcLineNumber);
 
														 | 
														
														 | 
														
															       Mnemonic mnemonic = MnemonicFactory.getMnemonic(newLine, srcLineNumber);
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -380,7 +453,7 @@ public class SPSAssembler { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     return null;
 
														 | 
														
														 | 
														
															     return null;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   }
 
														 | 
														
														 | 
														
															   }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  private static String stripComments(String line) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private String stripComments(String line) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (line.indexOf("*/") >= 0) {
 
														 | 
														
														 | 
														
															     if (line.indexOf("*/") >= 0) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       inBlockComment = false;
 
														 | 
														
														 | 
														
															       inBlockComment = false;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       return null;
 
														 | 
														
														 | 
														
															       return null;
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -399,14 +472,20 @@ public class SPSAssembler { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     return line.trim();
 
														 | 
														
														 | 
														
															     return line.trim();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   }
 
														 | 
														
														 | 
														
															   }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  private static String getLabel(String line) {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private String getLabel(String line) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     line = stripComments(line);
 
														 | 
														
														 | 
														
															     line = stripComments(line);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     return line;
 
														 | 
														
														 | 
														
															     return line;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   }
 
														 | 
														
														 | 
														
															   }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  private static void showHelp() {
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    System.out.println("usage SPSAssembler <sorucefile> [<destination>]");
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    System.exit(0);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private List<Mnemonic> getMnemonics() {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    return mnemonics;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   }
 
														 | 
														
														 | 
														
															   }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private Map<String, Macro> getMacros() {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    return macros;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  private Map<String, Integer> getLabels() {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    return labels;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 }
 
														 | 
														
														 | 
														
															 }
 
														 |