public override void EnterInstructionStatement([NotNull] ZealCpuParser.InstructionStatementContext context) { _currentInstruction = new CpuInstructionStatement(); _currentInstruction.Line = context.Start.Line; _currentInstruction.Column = context.Start.Column; CpuInstructions opcode; if (Enum.TryParse <CpuInstructions>(context.opcode().GetText(), out opcode)) { _currentInstruction.Opcode = opcode; } }
public override void ExitInstructionStatement([NotNull] ZealCpuParser.InstructionStatementContext context) { if (_currentInstruction.Arguments.Count == 0) { _currentInstruction.AddressingMode = CpuAddressingMode.Implied; } var assumeAddressingAttribute = _currentInstruction.Opcode.GetAttribute <CpuAssumeAddressingAttribute>(); if (assumeAddressingAttribute != null) { _currentInstruction.AddressingMode = assumeAddressingAttribute.Addressing; } var labelContext = context.label(); if (labelContext != null) { _currentInstruction.AssociatedLabel = labelContext.IDENTIFIER().GetText(); } var opcodeAttributes = EnumHelper.GetAttributes <OpcodeAttribute>(_currentInstruction.Opcode).Where(x => x.AddressingMode == _currentInstruction.AddressingMode).ToArray(); if (opcodeAttributes == null || (opcodeAttributes != null && opcodeAttributes.Length == 0)) { string descriptionAddressingMode = EnumHelper.GetAttribute <DescriptionAttribute>(_currentInstruction.AddressingMode).Description; addErrorMesage(String.Format("opcode '{0}' does not support {1} addressing mode.", _currentInstruction.Opcode, descriptionAddressingMode), context.opcode().Start); } _currentScope.Statements.Add(_currentInstruction); _currentInstruction = null; }