Assembler { public static List<Instruction> insertIOConfiguration(List<Instruction> instructions, AssemblerConfig config) { List<Instruction> updatedInstructions = new ArrayList<>(); for (Instruction instruction : instructions) { if ("init".equals(instruction.label)) { updatedInstructions.add(new Instruction(InstructionType.INSTRUCTION, "init", null, null, null, null, null, instruction.originalLine)); for (IOPin pin : config.getProcessor().getIopins()) { updatedInstructions.add(new Instruction(InstructionType.INSTRUCTION, null, opcodes.get("ldc"), (long) pin.getAddr(), null, null, null, instruction.originalLine)); updatedInstructions.add(new Instruction(InstructionType.INSTRUCTION, null, opcodes.get("ldc"), (long) pin.getConfig(), null, null, null, instruction.originalLine)); updatedInstructions.add(new Instruction(InstructionType.INSTRUCTION, null, opcodes.get("confio"), null, null, null, null, instruction.originalLine)); } updatedInstructions.add(new Instruction(InstructionType.INSTRUCTION, "postconfig", instruction.opcode, instruction.constantOperand, instruction.labelOperand, instruction.comment, instruction.directive, instruction.originalLine)); } else { updatedInstructions.add(instruction); } } return updatedInstructions; } private  Assembler(); @Nullable static AssemblerConfig loadConfig(@Nullable Reader configReader); static List<String> assemble(@Nonnull String input, @Nullable AssemblerConfig config, @Nonnull PrintStream logger, boolean insertIOConfiguration); @Nonnull static List<Instruction> parseAssembly(@Nonnull String input); static List<Instruction> insertIOConfiguration(List<Instruction> instructions, AssemblerConfig config); static List<Instruction> processDollarLabelOperands(List<Instruction> instructions); static List<Instruction> processChanDirectives(List<Instruction> instructions, AssemblerConfig config); static List<Instruction> processDataDirectives(List<Instruction> instructions); static Assembly makeLabelMap(List<Instruction> instructions); static Map<String, Long> getConfigLabels(@Nonnull AssemblerConfig config); static Assembly patchLabels(Assembly assembly); static List<Byte> processIndirectInstruction(Instruction instruction); static List<Byte> processDirectInstructionWithLabelOperand(Instruction instruction, Map<String, Long> labelMap); static byte processDirectInstructionWithConstantOperand(Instruction instruction); static List<Instruction> prefix(Instruction instruction); static ParseTree parseExpression(String expression, Function<AssemblerExpressionParser, ParseTree> startRule); final static long maxInt; final static long minInt; final static Pattern inputComment; final static Pattern instructionPattern; final static Pattern directivePattern; final static Pattern dollarPattern; static Map<String, Opcode> opcodes; }
@Test public void testInsertIOConfiguration() { String assembly = "init: ldc 10\najw -11\n"; List<Instruction> instructions = Assembler.parseAssembly(assembly); AssemblerConfig config = getSampleConfig(); List<Instruction> configuredInstructions = Assembler.insertIOConfiguration(instructions, config); checkInstructionEquality( new Instruction(InstructionType.INSTRUCTION, "init", null, null, null, null, null, 1), configuredInstructions.get(0)); checkInstructionEquality( new Instruction(InstructionType.INSTRUCTION, null, Assembler.opcodes.get("ldc"), 70L, null, null, null, 1), configuredInstructions.get(1)); checkInstructionEquality( new Instruction(InstructionType.INSTRUCTION, null, Assembler.opcodes.get("ldc"), 0L, null, null, null, 1), configuredInstructions.get(2)); checkInstructionEquality( new Instruction(InstructionType.INSTRUCTION, null, Assembler.opcodes.get("confio"), null, null, null, null, 1), configuredInstructions.get(3)); checkInstructionEquality( new Instruction(InstructionType.INSTRUCTION, "postconfig", Assembler.opcodes.get("ldc"), 10L, null, null, null, 1), configuredInstructions.get(4)); checkInstructionEquality( new Instruction(InstructionType.INSTRUCTION, null, Assembler.opcodes.get("ajw"), -11L, null, null, null, 2), configuredInstructions.get(5)); }