예제 #1
0
        static void Main(string[] args)
        {
            string assname = "x86_64s-elf64-tysos";

            libtysila.Assembler.Architecture arch = libtysila.Assembler.ParseArchitectureString(assname);

            frontend_lib.FileSystemFileLoader floader = new frontend_lib.FileSystemFileLoader();
            floader.DirectoryDelimiter = "\\";
            floader.SearchDirs.Add(".");
            floader.SearchDirs.Add("..\\mono\\corlib");


            libtysila.Assembler ass = libtysila.Assembler.CreateAssembler(arch, floader, null, null);

            System.IO.FileStream f = new System.IO.FileStream("test.tir", System.IO.FileMode.Open);
            TIRParse.Parser      p = new TIRParse.Parser(new TIRParse.Scanner(f), ass);
            bool res = p.Parse();

            /* Generate tybel code */
            libtysila.timple.Optimizer.OptimizeReturn opt = libtysila.timple.Optimizer.Optimize(p.tacs["test2"]);
            //libtysila.tybel.Tybel tybel = libtysila.tybel.Tybel.GenerateTybel(opt, ass, new List<libasm.hardware_location>());
            libtysila.tybel.Tybel tybel = null;

            /* Generate code */
            List <byte> code = new List <byte>();
            List <libasm.ExportedSymbol>  syms   = new List <libasm.ExportedSymbol>();
            List <libasm.RelocationBlock> relocs = new List <libasm.RelocationBlock>();

            //tybel.Assemble(code, syms, relocs, ass);

            /* Dump dissassembly */
            tydisasm.tydisasm d  = tydisasm.tydisasm.GetDisassembler(ass.Arch.InstructionSet);
            CodeStream        cs = new CodeStream {
                code = code
            };

            if (d != null)
            {
                while (cs.MoreToRead)
                {
                    ulong offset = (ulong)cs.Offset;

                    tydisasm.line disasm = d.GetNextLine(cs);

                    Console.WriteLine("{0} {1,-30} {2}", offset.ToString("x16"), disasm.OpcodeString, disasm.ToString());
                    if (disasm.opcodes == null)
                    {
                        break;
                    }
                }
            }

            Console.ReadKey();
        }
예제 #2
0
 internal Parser(Scanner s, libtysila.Assembler assembler) : base(s)
 {
     ass = assembler;
 }