private static void EmitTest(Instruction instruction, string assembler) { var actual = new List <byte>(); Assert.Null(InstructionEmitter.Emit(instruction, actual)); var expected = TestHelpers.NasmBuildBinFromString($"bits 64\r\n{assembler}"); TestHelpers.AssertByteArrays(expected, actual, $"Assembling `{assembler}`:\r\n"); }
public string Assemble(AstNode node) { switch (node) { case AssemblyListing listing: foreach (var directive in listing.Directives) { var err = Assemble(directive); if (err != null) { return(err); } } return(null); case ExternDeclaration externDeclaration: _symbolTable.Import(externDeclaration.Name); return(null); case GlobalDeclaration globalDeclaration: _symbolTable.Export(globalDeclaration.Name); return(null); case SectionDeclaration sectionDeclaration: foreach (var entry in sectionDeclaration.SectionEntries) { var error = Assemble(entry); if (error != null) { return(error); } } return(null); case Instruction instruction: return(InstructionEmitter.Emit(instruction, _data)); case Data data: case SectionLabel label: return(null); default: return($"unsupported AstNode: {node.GetType()}"); } }