Exemple #1
0
        public void Decompile(string file)
        {
            file = string.Concat(_testPaths[Environment.MachineName], file);

            var objData = Compile(file);
            var reader = new CodeReader(objData);
            var writer = new InstructionTextWriter(Console.Out);
            foreach  (var instruction in reader)
            {
                writer.Write(instruction);
            }
        }
Exemple #2
0
        public void AssembleSimple()
        {
            var x = new[]
            {
                new Instruction(OpCode.Mov, "Put 1 into r1").Destination(Register.A).Source(1),
                new Instruction(OpCode.Exit, "Exit with r1").Source(Register.A),
            };

            var grammer = new AsmStructuralGrammar();
            var p = new ParserState(TestPrograms.ReallySimpleProgram);

            bool parseResult = grammer.program.Match(p);
            Assert.That(parseResult, Is.True);

            var assembler = new Assembler(p);
            var code = assembler.Assemble().ToList();

            using (var w = new InstructionTextWriter(Console.Out))
                code.ForEach(w.Write);

            Assert.That(code, Is.EquivalentTo(x).Using(new InstructionComparer()));
        }
Exemple #3
0
        public void OpenFile(string file)
        {
            var grammar = new AsmStructuralGrammar();
            file = string.Concat(_testPaths[Environment.MachineName], file);

            var outputFile = Path.ChangeExtension(file, ".asm");
            using (var stringWriter = File.CreateText(outputFile))
            using (var writer = new InstructionTextWriter(stringWriter))
            {
                string source = File.ReadAllText(file);
                var parser = new ParserState(source);
                var result = grammar.program.Match(parser);
                Assert.That(result, Is.True);

                var printer = new CppStructuralOutputAsXml();
                printer.Print(parser.GetRoot());
                Console.WriteLine(printer.AsXml());

                var assembler = new Assembler(parser);
                assembler.Assemble().ToList().ForEach(writer.Write);
            }
        }
Exemple #4
0
        public void WriteMissingParameter()
        {
            var badInstruction = new Instruction(OpCode.Mov).Source(10);
            Assert.That(badInstruction.ToString(), Is.StringMatching(@"^Mov"));

            var ms = new StringWriter();
            using (var writer = new InstructionTextWriter(ms))
            {
                writer.Write(badInstruction);
            }
        }
Exemple #5
0
        public void WriteExtraParameter()
        {
            var badInstruction = new Instruction(OpCode.Ret).Source(10);
            Assert.That(badInstruction.ToString(), Is.StringMatching(@"^Ret\s+\$10"));

            var ms = new StringWriter();
            using (var writer = new InstructionTextWriter(ms))
                writer.Write(badInstruction);
        }
Exemple #6
0
        public void WriteBadOpCode()
        {
            var badInstruction = new Instruction((OpCode) 254);
            Assert.That(badInstruction.ToString(), Is.StringMatching(@"^254\s+;.*"));

            var ms = new StringWriter();
            using (var writer = new InstructionTextWriter(ms))
                writer.Write(badInstruction);
        }