public void Add(Macro macro) { macros[macro.Name] = macro; }
public override void EndNode(ParserContext context) { expressionResolver.EndNode(context); switch (context.NodeKind) { case SyntaxNodeKind.Label: labelName = context.Span.Text; break; case SyntaxNodeKind.MacroName: currentMacroName = context.Span.Text; break; case SyntaxNodeKind.Macro: currentMacro = new Macro(currentMacroName); break; case SyntaxNodeKind.DirectiveName: directiveName = context.Span.Text; if (labelName != null && directiveName != "=") { AddLabel(new Label(labelName, currentChunkStartAddress + opcodes.Count)); labelName = null; } break; case SyntaxNodeKind.Directive: ProcessDriective(); break; case SyntaxNodeKind.Instruction: ProcessInstruction(); break; case SyntaxNodeKind.ImpliedOperand: operandKind = OperandKind.Implied; break; case SyntaxNodeKind.AbsoluteOperand: ProcessAbsoluteOperand(); break; case SyntaxNodeKind.ImmediateOperand: operandValue = (byte) expressionResolver.Evaluate(); operandKind = OperandKind.Immediate; break; case SyntaxNodeKind.IndirectOperand: ProcessIndirectOperand(); break; case SyntaxNodeKind.OperandIndexer: ProcessOperandIndexer(context.Span.Text); break; case SyntaxNodeKind.Mnemonic: mnemonic = context.Span.Text; break; case SyntaxNodeKind.DirectiveOperands: directiveOperands.Enqueue(expressionResolver.Evaluate()); break; case SyntaxNodeKind.Literal: foreach (var b in AtasciiEncoding.Instance.GetBytes(context.Span.Text)) { directiveOperands.Enqueue(b); } break; case SyntaxNodeKind.Line: if (labelName != null) { AddLabel(new Label(labelName, currentChunkStartAddress + opcodes.Count)); labelName = null; } break; } }
public bool TryGetMacro(string name, out Macro macro) { return macros.TryGetValue(name, out macro); }
private void ProcessDriective() { switch (directiveName) { case ".BYTE": while (directiveOperands.Count > 0) { var directiveOperand = directiveOperands.Dequeue(); AddOpCode((byte) (directiveOperand & 0xFF)); } break; case ".WORD": while (directiveOperands.Count > 0) { var directiveOperand = directiveOperands.Dequeue(); AddOpCode((byte)( directiveOperand & 0xFF )); AddOpCode((byte)( ( directiveOperand & 0xFF00 ) >> 8 )); } break; case ".DBYTE": while (directiveOperands.Count > 0) { var directiveOperand = directiveOperands.Dequeue(); AddOpCode((byte)( ( directiveOperand & 0xFF00 ) >> 8 )); AddOpCode((byte)( directiveOperand & 0xFF )); } break; case ".IF": var conditionValue = directiveOperands.Dequeue(); ifConditionValues.Push(conditionValue); if (conditionValue == 0) { skippingIfsCount++; } break; case ".ELSE": var conditionValue2 = ifConditionValues.Pop(); if (conditionValue2 == 0) { ifConditionValues.Push(1); skippingIfsCount--; } else { ifConditionValues.Push(0); skippingIfsCount++; } break; case ".ENDIF": if (ifConditionValues.Pop() == 0) skippingIfsCount--; if (skippingIfsCount < 0) throw new InvalidOperationException("unpaired .ENDIF"); break; case ".ENDM": macroStore.Add(currentMacro); currentMacro = null; currentMacroName = null; break; case ".DS": var dsLength = directiveOperands.Dequeue(); SetCurrentOrigin(opcodes.Count + currentChunkStartAddress + dsLength); break; case "*=": SetCurrentOrigin(directiveOperands.Dequeue()); break; case "=": AddLabel(new Label(labelName, directiveOperands.Dequeue())); labelName = null; break; } if (directiveOperands.Count > 0) { throw new InvalidOperationException("Unprocessed directive operands"); } }