Exemple #1
0
    public bool WriteAsm(StreamWriter sw, MethodData md)
    {
        bool   ok   = true;
        string name = md.FullName;

        sw.WriteLine("; {0}", name);
        sw.WriteLine("{0}:", Util.MangleFunction(md));
        ArrayList list = new ArrayList();

        if (md.LocalVars != null || md.ParamCount > 0)
        {
            list.Add(new X86Code("push", "bp"));
            list.Add(new X86Code("mov", "bp", "sp"));
            if (md.LocalVars != null)
            {
                list.Add(new X86Code("sub", "sp", (md.LocalVars.Count * 2).ToString()));
            }
        }
        foreach (object obj in ConvertNative(md))
        {
            X86Codes codes = obj as X86Codes;
            if (codes == null)
            {
                ILCode il = obj as ILCode;
                codes = ConvertIL(md, il);
                if (codes == null)
                {
                    ok = false;
                    Console.WriteLine("ERROR PE_{0:X8}: {1} in {2}", il.Address, il.OpCode, md.FullName);
                    continue;
                }
            }
            codes.Output(list);
        }
        switch (this.optimize)
        {
        case 1:
            X86Code.Optimize(list);
            break;

        case 2:
            this.Optimize(list, md);
            break;
        }
        foreach (object obj in list)
        {
            X86Code x = obj as X86Code;
            x.Write(sw);
        }
        return(ok);
    }