Merge pull request #5428 from kumpera/wasm-support-p2
[mono.git] / mcs / class / PEAPI / Metadata.cs
index d983c8a2a2c754365ecb6c3d626726079f4c8104..eca297380bcdc92386e6067a43e5b686447f67dd 100644 (file)
@@ -92,7 +92,14 @@ namespace PEAPI {
        /// </summary>
        public enum ImplAttr { IL, Native, Runtime = 0x03, Unmanaged = 0x04,
                ForwardRef = 0x10, PreserveSig = 0x0080, InternalCall = 0x1000, 
-               Synchronised = 0x0020, Synchronized = 0x0020, NoInLining = 0x0008, Optil = 0x0002}
+               Synchronised = 0x0020, Synchronized = 0x0020, NoInLining = 0x0008, NoOptimization = 0x0040, Optil = 0x0002,
+               AggressiveInlining = 0x0100
+       }
+
+       /// <summary>
+       /// Storage location for initial field data
+       /// </summary>
+       public enum DataSegment { Data, TLS, CIL }
 
        /// <summary>
        /// Modes for a parameter
@@ -1634,6 +1641,7 @@ namespace PEAPI {
        public class ClassDef : Class {
 
                Class superType;
+               bool setSuperType;
                ArrayList fields = new ArrayList();
                ArrayList methods = new ArrayList();
                ArrayList events;
@@ -1649,9 +1657,6 @@ namespace PEAPI {
                                MetaData md) : base(nsName, name, md) 
                {
                        metaData = md;
-                       if (! ((nsName == "" && name == "<Module>") || (nsName == "System" && name == "Object")) ) {
-                               superType = metaData.mscorlib.GetSpecialSystemClass(PrimitiveType.Object);
-                       }
                        flags = (uint)attrSet;
                        tabIx = MDTable.TypeDef;
                }
@@ -1659,6 +1664,7 @@ namespace PEAPI {
                internal void SetSuper(Class sClass) 
                {
                        superType = sClass;
+                       setSuperType = true;
                        if (! (sClass is GenericTypeInst))
                                typeIndexChecked = false;
                }
@@ -1670,12 +1676,13 @@ namespace PEAPI {
                        else  
                                superType = metaData.mscorlib.ValueType();
 
+                       setSuperType = true;
                        typeIndex = PrimitiveType.ValueType.GetTypeIndex ();
                }
 
                public void SpecialNoSuper() 
                {
-                       superType = null;
+                       setSuperType = true;
                }
 
                /// <summary>
@@ -1917,8 +1924,13 @@ namespace PEAPI {
 
                internal sealed override void BuildTables(MetaData md) 
                {
-                       if (done) return;
-                       if ((flags & (uint)TypeAttr.Interface) != 0) { superType = null; }
+                       if (done) 
+                               return;
+                       
+                       if ((flags & (uint)TypeAttr.Interface) != 0) {
+                               superType = null;
+                               setSuperType = true;
+                       }
                        // Console.WriteLine("Building tables for " + name);
                        if (layout != null) md.AddToTable(MDTable.ClassLayout,layout);
                        // Console.WriteLine("adding methods " + methods.Count);
@@ -1951,6 +1963,10 @@ namespace PEAPI {
                                                        ((Property)properties[0]).Row,MDTable.Property));
                        }
                        // Console.WriteLine("End of building tables");
+
+                       if (!setSuperType)
+                               superType = metaData.mscorlib.GetSpecialSystemClass(PrimitiveType.Object);
+
                        done = true;
                }
 
@@ -5045,7 +5061,7 @@ namespace PEAPI {
                private byte heapSizes = 0;
                MetaDataElement entryPoint;
                BinaryWriter output;
-               public MSCorLib mscorlib;
+               MSCorLib _mscorlib;
                private TypeSpec[] systemTypeSpecs = new TypeSpec[PrimitiveType.NumSystemTypes];
                long mdStart;
                private ArrayList cattr_list;
@@ -5070,9 +5086,15 @@ namespace PEAPI {
                        for (int i=0; i < lgeCIx.Length; i++) {
                                lgeCIx[i] = false;
                        }
-                       mscorlib = new MSCorLib(this);
                }
 
+               public MSCorLib mscorlib {
+                       get {
+                               return _mscorlib ?? (_mscorlib = new MSCorLib (this));
+                       }
+               }
+
+
                internal TypeSpec GetPrimitiveTypeSpec(int ix) 
                {
                        return systemTypeSpecs[ix];
@@ -5346,12 +5368,20 @@ namespace PEAPI {
 
                                MDTable tabIx = (MDTable)i;
                                if (count > max5BitSmlIx) {
+                                       if (tabIx == MDTable.Method || tabIx == MDTable.Field || tabIx == MDTable.TypeRef ||
+                                               tabIx == MDTable.TypeDef || tabIx == MDTable.Param || tabIx == MDTable.InterfaceImpl ||
+                                               tabIx == MDTable.MemberRef || tabIx == MDTable.Module || tabIx == MDTable.DeclSecurity ||
+                                               tabIx == MDTable.Property || tabIx == MDTable.Event || tabIx == MDTable.StandAloneSig ||
+                                               tabIx == MDTable.ModuleRef || tabIx == MDTable.TypeSpec || tabIx == MDTable.Assembly ||
+                                               tabIx == MDTable.AssemblyRef || tabIx == MDTable.File || tabIx == MDTable.ExportedType ||
+                                               tabIx == MDTable.ManifestResource || tabIx == MDTable.GenericParam)
                                        lgeCIx[(int)CIx.HasCustomAttr] = true;
                                }
                                if (count > max3BitSmlIx) {
-                                       if ((tabIx == MDTable.TypeRef) || (tabIx == MDTable.ModuleRef) || (tabIx == MDTable.Method) || (tabIx == MDTable.TypeSpec) || (tabIx == MDTable.Field)) 
+                                       if (tabIx == MDTable.Method || tabIx == MDTable.MemberRef)
                                                lgeCIx[(int)CIx.CustomAttributeType] = true;
-                                       if ((tabIx == MDTable.Method) || (tabIx == MDTable.MemberRef)) 
+                                       if (tabIx == MDTable.TypeDef || tabIx == MDTable.TypeRef || tabIx == MDTable.ModuleRef ||
+                                               tabIx == MDTable.Method || tabIx == MDTable.TypeSpec)
                                                lgeCIx[(int)CIx.MemberRefParent] = true;
                                }
                                if (count > max2BitSmlIx) {