コード例 #1
0
  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());
    }
  }
コード例 #2
0
  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();
  }