Пример #1
0
        public override void Emit(MethodDefinition md, Instruction c, AssemblyWriter writer)
        {
            int num = 0;

            if (c.OpCode == OpCodes.Ldarg)
            {
                num = (int)c.Operand;
            }
            else
            {
                num = int.Parse(c.OpCode.Name.Split('.').Last());
            }

            var offset = md.Body.Variables.Count * 4;

            writer.Mov("eax", $"[ebp+{offset + 4}]");
            writer.Push("eax");
        }
Пример #2
0
        public void CompileMethod(MethodDefinition md)
        {
            if (md.IsConstructor)
            {
                return;
            }

            Writer.Label(NormaliseName(md.FullName));
            Writer.Comment("");
            Writer.Comment("");

            Writer.Push("ebp");
            Writer.Mov("ebp", "esp");
            Writer.Sub("esp", md.Body.MaxStackSize * 4);


            foreach (var bodyInstruction in md.Body.Instructions)
            {
                bool found = false;
                foreach (var opcode in Opcodes)
                {
                    if (opcode.IsMe(bodyInstruction))
                    {
                        if (md.HasBody)
                        {
                            opcode.Emit(md, bodyInstruction, Writer);
                        }
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    Writer.Comment(bodyInstruction.ToString());
                    Console.WriteLine($"Found Missing Opcode: {bodyInstruction.ToString()}");
                }
            }

            Writer.Label(NormaliseName(md.FullName) + "_ret");

            Writer.Ret();
        }