コード例 #1
0
ファイル: CodeParserTests.cs プロジェクト: andy-uq/TinyOS
        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);
            }
        }
コード例 #2
0
ファイル: AssemblerTests.cs プロジェクト: andy-uq/TinyOS
        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()));
        }
コード例 #3
0
ファイル: CodeParserTests.cs プロジェクト: andy-uq/TinyOS
        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);
            }
        }
コード例 #4
0
ファイル: CodeParserTests.cs プロジェクト: andy-uq/TinyOS
        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);
            }
        }
コード例 #5
0
ファイル: CodeParserTests.cs プロジェクト: andy-uq/TinyOS
        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);
        }
コード例 #6
0
ファイル: CodeParserTests.cs プロジェクト: andy-uq/TinyOS
        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);
        }