Esempio n. 1
0
 private static void EmitArrayInit(Stream hmsw, Stream cmsw, List <string> header_funcs,
                                   Target ass, MetadataStream m)
 {
     EmitArrayInit(m.SystemObject, "Ref", hmsw, cmsw, header_funcs, ass);
     EmitArrayInit(m.SystemChar, "Char", hmsw, cmsw, header_funcs, ass);
     EmitArrayInit(m.SystemIntPtr, "I", hmsw, cmsw, header_funcs, ass);
     EmitArrayInit(m.SystemInt8, "I1", hmsw, cmsw, header_funcs, ass);
     EmitArrayInit(m.SystemInt16, "I2", hmsw, cmsw, header_funcs, ass);
     EmitArrayInit(m.SystemInt32, "I4", hmsw, cmsw, header_funcs, ass);
     EmitArrayInit(m.SystemInt64, "I8", hmsw, cmsw, header_funcs, ass);
     EmitArrayInit(m.GetSimpleTypeSpec(0x19), "U", hmsw, cmsw, header_funcs, ass);
     EmitArrayInit(m.GetSimpleTypeSpec(0x05), "U1", hmsw, cmsw, header_funcs, ass);
     EmitArrayInit(m.GetSimpleTypeSpec(0x07), "U2", hmsw, cmsw, header_funcs, ass);
     EmitArrayInit(m.GetSimpleTypeSpec(0x09), "U4", hmsw, cmsw, header_funcs, ass);
     EmitArrayInit(m.GetSimpleTypeSpec(0x0b), "U8", hmsw, cmsw, header_funcs, ass);
 }
Esempio n. 2
0
        private static void LayoutString(Code c)
        {
            corlib = c.ms.m.al.GetAssembly("mscorlib");

            var ts = corlib.GetSimpleTypeSpec(0x0e);

            length = GetFieldOffset(ts, "length", c.t, out var is_tls);
            sc     = GetFieldOffset(ts, "start_char", c.t, out is_tls);
        }
Esempio n. 3
0
        internal static void WriteHeader(MetadataStream m, Target ass, string output_header,
                                         string output_cinit)
        {
            FileStream fs = new FileStream(output_header, FileMode.Create, FileAccess.Write);
            var        sw = fs;

            var hmsw = new MemoryStream();
            var cmsw = new MemoryStream();

            FileStream oci = null;

            System.IO.FileInfo header_fi = new FileInfo(output_header);
            if (output_cinit != null)
            {
                oci = new FileStream(output_cinit, FileMode.Create, FileAccess.Write);

                HexFile.writeStr(oci, "#include \"" + header_fi.Name + "\"", true);
                HexFile.writeStr(oci, "#include <string.h>", true);
                HexFile.writeStr(oci, "#include <stdlib.h>", true);
                HexFile.writeStr(oci, "#include <stdint.h>", true);
                HexFile.writeStr(oci, "#include <stddef.h>", true);
                HexFile.writeStr(oci, "", true);
                HexFile.writeStr(oci, "INTPTR Get_Symbol_Addr(const char *name);", true);
                HexFile.writeStr(oci, "", true);
            }

            List <string> advance_defines  = new List <string>();
            List <string> external_defines = new List <string>();
            List <string> func_headers     = new List <string>();

            EmitType(m.GetSimpleTypeSpec(0x1c), hmsw, cmsw, advance_defines,
                     external_defines, func_headers, ass);
            EmitType(m.GetSimpleTypeSpec(0xe), hmsw, cmsw, advance_defines,
                     external_defines, func_headers, ass);
            EmitArrayInit(hmsw, cmsw, func_headers, ass, m);

            for (int i = 1; i <= m.table_rows[MetadataStream.tid_CustomAttribute]; i++)
            {
                int type_tid, type_row;
                m.GetCodedIndexEntry(MetadataStream.tid_CustomAttribute,
                                     i, 1, m.CustomAttributeType, out type_tid,
                                     out type_row);

                MethodSpec ca_ms;
                m.GetMethodDefRow(type_tid, type_row, out ca_ms);
                var ca_ms_name = ca_ms.MangleMethod();

                if (ca_ms_name == "_ZN14libsupcs#2Edll8libsupcs22OutputCHeaderAttribute_7#2Ector_Rv_P1u1t")
                {
                    int parent_tid, parent_row;
                    m.GetCodedIndexEntry(MetadataStream.tid_CustomAttribute,
                                         i, 0, m.HasCustomAttribute, out parent_tid,
                                         out parent_row);

                    if (parent_tid == MetadataStream.tid_TypeDef)
                    {
                        var ts = m.GetTypeSpec(parent_tid, parent_row);

                        EmitType(ts, hmsw, cmsw, advance_defines,
                                 external_defines, func_headers, ass);
                    }
                }
            }

            HexFile.writeStr(sw, "");
            HexFile.writeStr(sw, "#include <stdint.h>");
            HexFile.writeStr(sw, "");
            HexFile.writeStr(sw, "#ifdef INTPTR");
            HexFile.writeStr(sw, "#undef INTPTR");
            HexFile.writeStr(sw, "#endif");
            HexFile.writeStr(sw, "#ifdef UINTPTR");
            HexFile.writeStr(sw, "#undef UINTPTR");
            HexFile.writeStr(sw, "#endif");
            HexFile.writeStr(sw, "");
            HexFile.writeStr(sw, "#define INTPTR " + ((ass.GetPointerSize() == 4) ? ass.GetCType(m.SystemInt32) : ass.GetCType(m.SystemInt64)));
            HexFile.writeStr(sw, "#define UINTPTR " + ((ass.GetPointerSize() == 4) ? ass.GetCType(m.GetSimpleTypeSpec(0x09)) : ass.GetCType(m.GetSimpleTypeSpec(0x0b))));
            HexFile.writeStr(sw, "");
            EmitArrayType(sw, ass, m);
            foreach (string s in advance_defines)
            {
                HexFile.writeStr(sw, s);
            }
            HexFile.writeStr(sw, "");
            if (oci != null)
            {
                foreach (string s2 in func_headers)
                {
                    HexFile.writeStr(sw, s2);
                }
                HexFile.writeStr(sw, "");
            }
            hmsw.Flush();
            StreamReader hmsr = new StreamReader(hmsw);

            hmsr.BaseStream.Seek(0, SeekOrigin.Begin);
            string hs = hmsr.ReadLine();

            while (hs != null)
            {
                HexFile.writeStr(sw, hs);
                hs = hmsr.ReadLine();
            }

            sw.Close();

            if (oci != null)
            {
                foreach (string s in external_defines)
                {
                    HexFile.writeStr(oci, s);
                }
                HexFile.writeStr(oci, "");

                cmsw.Flush();
                StreamReader cmsr = new StreamReader(cmsw);
                cmsr.BaseStream.Seek(0, SeekOrigin.Begin);
                string cs = cmsr.ReadLine();
                while (cs != null)
                {
                    HexFile.writeStr(oci, cs);
                    cs = cmsr.ReadLine();
                }
                oci.Close();
            }
        }
Esempio n. 4
0
        public SpecialMethods(metadata.MetadataStream m)
        {
            corlib = m.al.GetAssembly("mscorlib");
            var i  = corlib.GetTypeSpec("System", "Int32");
            var u  = corlib.GetTypeSpec("System", "UInt32");
            var I  = corlib.GetTypeSpec("System", "IntPtr");
            var o  = corlib.GetSimpleTypeSpec(0x1c);
            var s  = corlib.GetSimpleTypeSpec(0x0e);
            var a  = corlib.GetSimpleTypeSpec(0x04);
            var Pa = a.Pointer;
            var c  = corlib.GetSimpleTypeSpec(0x03);
            var Pc = c.Pointer;
            var Zc = c.SzArray;
            var Zo = o.SzArray;
            var Pv = m.SystemVoid.Type.Pointer;
            var d  = corlib.GetSimpleTypeSpec(0xd);

            gcmalloc = CreateMethodSignature(b, I,
                                             new metadata.TypeSpec[] { i });
            castclassex = CreateMethodSignature(b, o,
                                                new TypeSpec[] { I, I, i });
            throw_ = CreateMethodSignature(b, null,
                                           new TypeSpec[] { o });
            try_enter = CreateMethodSignature(b, null,
                                              new TypeSpec[] { I, I });
            catch_enter = CreateMethodSignature(b, null,
                                                new TypeSpec[] { I, I });
            leave = CreateMethodSignature(b, null,
                                          new TypeSpec[] { I });
            rethrow = CreateMethodSignature(b, null,
                                            new TypeSpec[] { });
            strlen = CreateMethodSignature(b, I,
                                           new TypeSpec[] { Pa });
            wcslen = CreateMethodSignature(b, I,
                                           new TypeSpec[] { Pc });
            memcpy = CreateMethodSignature(I,
                                           new TypeSpec[] { I, I, i });
            memset = CreateMethodSignature(I,
                                           new TypeSpec[] { I, i, i });
            invoke = CreateMethodSignature(o,
                                           new TypeSpec[] { Pv, Zo, Pv, u });

            inst_Rv_s = CreateMethodSignature(b, null,
                                              new TypeSpec[] { s }, true);
            inst_Rv_P0 = CreateMethodSignature(b, null,
                                               new TypeSpec[] { }, true);
            static_Rv_P0 = CreateMethodSignature(b, null,
                                                 new TypeSpec[] { }, false);
            static_Rv_P1Pv = CreateMethodSignature(b, null,
                                                   new TypeSpec[] { Pv }, false);

            string_ci = CreateMethodSignature(null,
                                              new TypeSpec[] { c, i }, true);
            string_Zc = CreateMethodSignature(null,
                                              new TypeSpec[] { Zc }, true);
            string_Pcii = CreateMethodSignature(null,
                                                new TypeSpec[] { Pc, i, i }, true);
            string_Pa = CreateMethodSignature(null,
                                              new TypeSpec[] { Pa }, true);
            string_Zcii = CreateMethodSignature(null,
                                                new TypeSpec[] { Zc, i, i }, true);
            string_Pc = CreateMethodSignature(null,
                                              new TypeSpec[] { Pc }, true);
            string_PaiiEncoding = CreateMethodSignature(null,
                                                        new TypeSpec[] { Pa, i, i, corlib.GetTypeSpec("System.Text", "Encoding") }, true);
            string_Paii = CreateMethodSignature(null,
                                                new TypeSpec[] { Pa, i, i }, true);

            type_from_vtbl = CreateMethodSignature(o, new TypeSpec[] { I });

            array_copyToManaged = CreateMethodSignature(null,
                                                        new TypeSpec[] { Pv, Pv, i, i }, false);

            debugger_Log = CreateMethodSignature(null,
                                                 new TypeSpec[] { i, s, s });

            rint = CreateMethodSignature(d, new TypeSpec[] { d });

            sh_blob = new BlobStream(b);

            al = m.al;

            SystemArray               = m.SystemArray;
            SystemByte                = m.SystemByte;
            SystemChar                = m.SystemChar;
            SystemDelegate            = m.SystemDelegate;
            SystemEnum                = m.SystemEnum;
            SystemInt16               = m.SystemInt16;
            SystemInt32               = m.SystemInt32;
            SystemInt64               = m.SystemInt64;
            SystemInt8                = m.SystemInt8;
            SystemIntPtr              = m.SystemIntPtr;
            SystemObject              = m.SystemObject;
            SystemRuntimeFieldHandle  = m.SystemRuntimeFieldHandle;
            SystemRuntimeMethodHandle = m.SystemRuntimeMethodHandle;
            SystemRuntimeTypeHandle   = m.SystemRuntimeTypeHandle;
            SystemString              = m.SystemString;
            SystemUInt16              = m.SystemUInt16;
            SystemUInt32              = m.SystemUInt32;
            SystemUInt64              = m.SystemUInt64;
            SystemValueType           = m.SystemValueType;
            SystemVoid                = m.SystemVoid;
        }