public void WhenParserCalledWithCommentOnlyDoesNotGenerateInstructionSet() { Parser parser = new Parser (); ushort[] instructionSet = parser.Parse (new string[]{"; Try some basic stuff"}); Assert.IsNull (instructionSet); }
public void WhenParserCalledWithEmptySourceDoesNotGenerateInstructionSet() { Parser parser = new Parser (); ushort[] instructionSet = parser.Parse (new string[]{""}); Assert.IsNull (instructionSet); }
public void WhenParserCalledWithSetRegisterWithHexLiteralGenertesCorrectInstructionSet() { Parser parser = new Parser (); ushort[] instructionSet = parser.Parse (new string[]{"SET A 0x2000"}); string convertedInstructionSet = ConvertInstructionSetToString (instructionSet); Assert.AreEqual ("7c01 2000".ToUpper (), convertedInstructionSet.ToUpper()); }
public void WhenParserCalledWithSetMemoryAddressWithLiteralGenertesCorrectInstructionSet() { Parser parser = new Parser (); ushort[] instructionSet = parser.Parse (new string[]{"SET [0x1000], 0x20"}); string convertedInstructionSet = ConvertInstructionSetToString (instructionSet); Assert.AreEqual ("7de1 1000 0020".ToUpper (), convertedInstructionSet.ToUpper ()); }
public void WhenParserCalledWithNotchSampleGenertesCorrectInstructionSet() { Parser parser = new Parser (); string source = @" ; Try some basic stuff SET A, 0x30 ; 7c01 0030 SET [0x1000], 0x20 ; 7de1 1000 0020 SUB A, [0x1000] ; 7803 1000 IFN A, 0x10 ; c00d SET PC, crash ; 7dc1 001a [*] ; Do a loopy thing SET I, 10 ; a861 SET A, 0x2000 ; 7c01 2000 :loop SET [0x2000+I], [A] ; 2161 2000 SUB I, 1 ; 8463 IFN I, 0 ; 806d SET PC, loop ; 7dc1 000d [*] ; Call a subroutine SET X, 0x4 ; 9031 JSR testsub ; 7c10 0018 [*] SET PC, crash ; 7dc1 001a [*] :testsub SHL X, 4 ; 9037 SET PC, POP ; 61c1 ; Hang forever. X should now be 0x40 if everything went right. :crash SET PC, crash ; 7dc1 001a [*]"; string[] lines = source.Split('\n'); ushort[] instructionSet = parser.Parse(lines); string convertedInstructionSet = ConvertInstructionSetToString(instructionSet); string memoryDump = ""; memoryDump += "7c01 0030 7de1 1000 0020 7803 1000 c00d "; memoryDump += "7dc1 001a a861 7c01 2000 2161 2000 8463 "; memoryDump += "806d 7dc1 000d 9031 7c10 0018 7dc1 001a "; memoryDump += "9037 61c1 7dc1 001a"; Assert.AreEqual (memoryDump.ToUpper (), convertedInstructionSet.ToUpper()); }
/// <summary> /// Compile Source code. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button3_Click(object sender, EventArgs e) { if (ColorCodeTextBox.Text.Trim() == "") { MessageBox.Show("Nothing to compile", Globals.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } /*CDCPULexer lexer = new CDCPULexer(); string Error = ""; List<CDCPULexerToken> tokens = lexer.TokenizeFileString(ColorCodeTextBox.Text, out Error); textBox1.Text = Error; return; */ var assemble = new Parser(); var lines = ColorCodeTextBox.Text.Split('\n'); ushort[] machineCode = assemble.Parse(lines); if (machineCode == null) { textBox1.Text = assemble.MessageOuput; MessageBox.Show("Issue compiling code, check the 'Messages' box", Globals.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } var generator = new Generator(); var output = generator.Generate(machineCode, this.m_fileName); if (output == string.Empty) { textBox1.Text = generator.MessageOuput; MessageBox.Show("Issue compiling code, check the 'Messages' box", Globals.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } textBox1.Text = assemble.MessageOuput; MessageBox.Show(string.Format("Code successfully compiled to\n\n'{0}'", output), Globals.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.None); }