public void AddsSymbol() { var instr = new Label("test", SymbolType.Public); Assert.AreEqual("test", instr.DefinedSymbol.Identifier); Assert.AreEqual(LabelType.Public, instr.DefinedSymbol.SymbolType); Context.Address = 5; Assert.IsEmpty(instr.Construct(Context).ToList()); Assert.AreEqual(SymbolType.Public, Context.SymbolTable["test"].SymbolType); Assert.AreEqual((Int128)5, Context.SymbolTable["test"].Value); }
/// <inheritdoc /> public override void VisitLabel(Label label) { int commentstart = 0; string commentstring = null; if (label.Comment != null) commentstring = label.Comment.Text; int linelength = 0; indentationlevel--; if (indentationlevel < 0) indentationlevel = 0; string identifier; SymbolType type; if (label.DefinedSymbol != null) { identifier = label.DefinedSymbol.Identifier; if (identifier == null) throw new NotSupportedException("Symbols without identifiers are not supported."); type = label.DefinedSymbol.SymbolType; if (label.DefinedSymbol.SymbolType == SymbolType.Private) { // Single line, with comments. Writer.Write("{0}:", identifier); linelength = identifier.Length + 1; WriteCommentOf(label, linelength); } else { // Two lines, with comments. switch (label.DefinedSymbol.SymbolType) { case SymbolType.Public: Writer.Write("global {0}", identifier); linelength = 7 + identifier.Length; break; case SymbolType.Weak: Writer.Write("weak {0}", identifier); linelength = 5 + identifier.Length; break; case SymbolType.Private: default: break; } // Write the first part of the comment. if (commentstring != null) commentstart = WriteCommentString(commentstring, linelength, 0, 1); else Writer.WriteLine(); linelength = 0; Writer.Write("{0}:", identifier); linelength = identifier.Length + 1; // Write the rest of the comment. if (commentstring != null) WriteCommentString(commentstring, linelength, commentstart, -1); else Writer.WriteLine(); } } else { linelength = WriteCommentString("label <unkown>", -1, 0, -1); WriteCommentOf(label, linelength); } indentationlevel++; }