コード例 #1
0
 public void TestStringAsParameter()
 {
     MemoryStream stream = new MemoryStream();
     var writer = new StreamWriter(stream);
     var inst = new X86_64(writer);
     inst.visit(new StringAsParameter(".LC0", 0));
     string actual = Encoding.Default.GetString(stream.ToArray());
     Assert.AreEqual("leaq\t.LC0(%rip), %rcx", actual);
 }
コード例 #2
0
 public static string MakeAssembly(string origin, string dest, List<Module> modules, Global.InstructionSets targetInstructionSet)
 {
     using (file = new System.IO.StreamWriter(dest))
     {
         InstructionSetGenerator ISVisitor;
         switch (targetInstructionSet)
         {
             case Global.InstructionSets.X86_64: ISVisitor = new X86_64(file); break;
             default: ISVisitor = new X86_64(file); break;
         }
         ISVisitor.processModules(origin, modules);
         //foreach (Instruction instruction in intercode)
         //{
         //    instruction.accept(ISVisitor);
             /*pos = str.IndexOf(':');
             if (pos == -1)
                 opcode = str;
             else
             {
                 opcode = str.Substring(0, pos);
                 code = str.Substring(pos + 1);
             }
             switch (opcode)
             {
                 case "call":
                     if (code[0] == '%')
                     {
                         if (code == "%SETUP_C%")
                             w("call\t___main");
                         break;
                     }
                     pos = code.IndexOf(',');
                     switch (code.Substring(0, pos))
                     {
                         case "print":
                             code = code.Substring(pos + 1);
                             pos = code.IndexOf(',');
                             if (code.Substring(0, pos) == "constant")
                                 w("movl\t$A" + code.Substring(pos + 1) + ", (%esp)");
                             w("call\t_puts");
                             break;
                     }
                     break;
                 case "comment":
                     w(".ident\t" + code);
                     break;
                 case "define_constant_string":
                     pos = code.IndexOf(":");
                     wn("A" + code.Substring(0, pos) + ":");
                     code = code.Substring(pos + 1);
                     w(".asciz " + code);
                     break;
                 case "define_main_method":
                     w(".globl\t_main");
                     w(".def\t_main;\t.scl\t2;\t.type\t32;\t\t.endef");
                     wn("_main:");
                     break;
                 case "file":
                     w(".file\t" + code);
                     file_origin = code;
                     break;
                 case "get_base_pointer":
                     w("leave");
                     break;
                 case "reserve_stack":
                     w("andl\t$-16, %esp");
                     w("subl\t$16, %esp");
                     break;
                 case "return":
                     w("ret");
                     break;
                 case "section":
                     switch (code)
                     {
                         case "code": w(".text"); break;
                         case "constants": w(".section\t.rdata,\"dr\""); break;
                         case "var_initialised": w(".section\t.data"); break;
                         case "var_unitialised": w(".section\t.comm"); break;
                     }
                     break;
                 case "set_base_pointer":
                     w("pushl\t%ebp");
                     w("movl\t%esp, %ebp");
                     break;
             }*/
         //}
     }
     return "Compilation successful. The compilation of the source \"" + origin + "\" is contained in \"" + dest + "\"";
 }