private void assemble() { if (sourceFile == null) { printError("-i : No source file specified"); } if (assembler == null) { printError("-f : No format specified"); } print("...Assembling " + sourceFile.getName()); assembler.assemble(sourceFile); print("..." + assembler.getErrors().length + " error(s) found"); try { PrintWriter output = null; if (!assembler.hasErrors()) { if (!machineCode) { print("...saving .pco file"); output = new PrintWriter(new FileWriter(baseFileName + ".pco")); for (Instruction instruction : assembler.getInstructions()) { output.print(instruction.getInstruction()); output.println(" ;" + instruction.getSourceCode()); } } else { print("Machine code file varified"); } } else { print("...saving .err file"); output = new PrintWriter(new FileWriter(baseFileName + ".err")); for (AssemblyError error : assembler.getErrors()) { output.println(error.toString()); } } if (output != null) { output.close(); } } catch (IOException e) { printError(e.getMessage()); } }
private void doInput(String[] arguments) { if (arguments.length < 2) { printError("-i : No filename specified"); } if (arguments[1].endsWith(".pco")) { machineCode = true; assembler = new MachineCodeAssembler(); } else { if (!new File(arguments[1]).exists()) { print("...no file extension specified. Guessing .pca"); arguments[1] = arguments[1] + ".pca"; } } try { sourceFile = SourceFile.load(arguments[1]); baseFileName = arguments[1].substring(0, arguments[1].lastIndexOf(".")); } catch (IOException e) { printError(e.getMessage()); } }