private void assembleAction() { String line; messages = new Vector(); mainFrame.resetExecWindow(); save(); assembleFailed = false; haveAssemblyErrors = false; if (Assembler.version()) { while ((line = Assembler.output()) != null) { messages.addElement(line); } Assembler.setPaths(baseName, sourcePath); if (Assembler.assemble()) { while ((line = Assembler.output()) != null) { System.out.println(line); messages.addElement(line); if (line.startsWith(" [ERROR:")) { haveAssemblyErrors = true; } } messageList.setListData(messages); messageList.ensureIndexIsVisible(0); mainFrame.showExecWindow(baseName); } else { assembleFailed = true; } } else { assembleFailed = true; } if (assembleFailed) { String message = String.format( "Autocoder failed!\nVerify the correctness of autocoder path\n%s", AssemblerOptions.assemblerPath); System.out.println(message); JOptionPane.showMessageDialog(this, message, "ROPE", JOptionPane.ERROR_MESSAGE); } }
private void verifyAssembly(String templateName) throws Exception { StringWriter output = new StringWriter(); assembler.assemble( createClassPathUrl("templates/" + templateName + ".xhtml"), namespace, output); String expectedOutput = loadText(createClassPathUrl("solutions/" + templateName + ".html")); assertEquals(expectedOutput, output.toString()); }
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()); } }
@Test public void testMinimalTemplate() throws Exception { final String INPUT = "<html xmlns=\"http://www.w3.org/1999/xhtml\"/>"; final String EXPECTED_OUTPUT = "<!DOCTYPE html>\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\"/>"; StringWriter output = new StringWriter(); assembler.assemble(createLiteralUrl(INPUT), output); assertEquals(EXPECTED_OUTPUT, output.toString()); }
@Test public void testMissingDocumentElement() throws Exception { final String INPUT = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; Throwable error = null; try { assembler.assemble(createLiteralUrl(INPUT), new StringWriter()); } catch (AssemblerException e) { error = e.getCause(); } assertNotNull(error); }
@Test public void testBadInputPath() throws Exception { final String BAD_PATH = "no-such"; Throwable error = null; try { assembler.assemble(createClassPathUrl(BAD_PATH), new StringWriter()); } catch (AssemblerException e) { error = e.getCause(); } assertEquals(BAD_PATH, error.getMessage()); }
private void assemble() { Assembler assembler = new Assembler(); assembler.genMap = true; try { binary = new char[] {}; binary = assembler.assemble(sourceTextarea.getText()); cpu.upload(binary); memoryModel.fireUpdate(0, binary.length); asmMap = assembler.asmmap; for (Character addr : debugger.getBreakpoints()) { debugger.setBreakpoint(addr, false); } for (Integer breakpoint : srcBreakpoints) { Character addr = asmMap.src2bin(breakpoint); if (addr != null) { // TODO if null, mark breakpoint somehow debugger.setBreakpoint(addr, true); } } } catch (Exception ex) { JOptionPane.showMessageDialog( frame, "Compilation error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); ex.printStackTrace(); } }
private void execute() { if (sourceFile == null) { printError("-i : No source file specified"); } if (assembler == null || computer == null) { printError("-f : No format specified"); } if (assembler.hasErrors()) { printError("Unable to execute file due to errors"); } print("...preparing to execute program"); if (trace) { print("...opening computer trace files"); addTraceListeners(); } computer.setExecutionSpeed(ExecutionSpeed.FULL); computer.setInstructions(assembler.getInstructions()); computer.addComputerListener( new ComputerAdapter() { public void computerStarted(Computer computer) { print("...Execution started"); } public void computerStopped(Computer computer) { print("...Execution complete"); } }); computer.execute(); }
@Test public void testConflictingIncludeAndContent() throws Exception { final String INPUT = "<html xmlns=\"http://www.w3.org/1999/xhtml\"" + " xmlns:dwc=\"http://shopximity.com/schema/dwc\"" + " dwc:content=\"\"" + " dwc:include=\"\"/>"; Throwable error = null; try { assembler.assemble(createLiteralUrl(INPUT), new StringWriter()); } catch (AssemblerException e) { error = e.getCause(); } // TODO: assert that the error message contains meaningful information. assertNotNull(error); }