public override void Write(ModuleWriter writer) { // The global namespace hasn't name. string name = GetName(); if (parentScope == null) { name = string.Empty; } // Write the header. MemberHeader header = new MemberHeader(); header.memberName = (uint)GetModule().RegisterString(name); header.memberType = (byte)MemberHeaderType.Namespace; header.memberFlags = (uint)GetFlags(); header.memberSize = (uint)(members.Count * 4); header.Write(writer); // Write the member ids. foreach (ScopeMember member in this.members.Values) { writer.Write((uint)member.GetSerialId()); } }
public override void Write(ModuleWriter writer) { // Get the module. ChelaModule module = GetModule(); // Create the member header. MemberHeader mheader = new MemberHeader(); mheader.memberType = (byte)MemberHeaderType.TypeInstance; mheader.memberFlags = (uint)GetFlags(); mheader.memberName = 0; mheader.memberSize = (uint)(8 + genericInstance.GetSize()); mheader.memberAttributes = 0; // Write the member header. mheader.Write(writer); // Write the template id. writer.Write(module.RegisterMember(template)); // Write the factory id. writer.Write(module.RegisterMember(factory)); // Write the template parameters. genericInstance.Write(writer, GetModule()); }
public override void Write(ModuleWriter writer) { // Write the header. MemberHeader header = new MemberHeader(); header.memberType = (byte)MemberHeaderType.TypeName; header.memberName = GetModule().RegisterString(GetName()); header.memberFlags = (uint)GetFlags(); header.memberSize = 4; header.Write(writer); // Write the type and accessors.. writer.Write((uint)GetModule().RegisterType(GetActualType())); }
public override void Write(ModuleWriter writer) { // Write the header. MemberHeader header = new MemberHeader(); header.memberName = GetModule().RegisterString(GetName()); header.memberType = (byte)MemberHeaderType.FunctionGroup; header.memberFlags = (uint)GetFlags(); header.memberSize = (uint)(functions.Count * 4); header.Write(writer); // Write the functions ids. foreach (FunctionGroupName gname in functions) { writer.Write((uint)gname.GetFunction().GetSerialId()); } }
public override void Write(ModuleWriter writer) { // Write the header. MemberHeader header = new MemberHeader(); header.memberType = (byte)MemberHeaderType.Property; header.memberName = GetModule().RegisterString(GetName()); header.memberFlags = (uint)GetFlags(); header.memberSize = (uint)(13 + 4 * GetIndexCount()); header.Write(writer); // Write the type. ChelaModule module = GetModule(); writer.Write((uint)module.RegisterType(GetVariableType())); // Write the indices. byte numIndices = (byte)GetIndexCount(); writer.Write(numIndices); for (int i = 0; i < numIndices; ++i) { writer.Write(module.RegisterType((IChelaType)indices[i])); } // Write the get accessor. if (getAccessor != null) { writer.Write((uint)getAccessor.GetSerialId()); } else { writer.Write((uint)0); } // Write the set accessor. if (setAccessor != null) { writer.Write((uint)setAccessor.GetSerialId()); } else { writer.Write((uint)0); } }
public override void Write(ModuleWriter writer) { if (mergedGroup) { throw new ModuleException("Cannot write temporal type group " + GetFullName()); } // Write the header. MemberHeader header = new MemberHeader(); header.memberName = GetModule().RegisterString(GetName()); header.memberType = (byte)MemberHeaderType.TypeGroup; header.memberFlags = (uint)GetFlags(); header.memberSize = (uint)(types.Count * 4); header.Write(writer); // Write the functions ids. foreach (TypeGroupName gname in types) { writer.Write((uint)gname.GetBuilding().GetSerialId()); } }
public override void Write(ModuleWriter writer) { // Write the header. MemberHeader header = new MemberHeader(); header.memberType = (byte) MemberHeaderType.TypeName; header.memberName = GetModule().RegisterString(GetName()); header.memberFlags = (uint) GetFlags(); header.memberSize = 4; header.Write(writer); // Write the type and accessors.. writer.Write((uint)GetModule().RegisterType(GetActualType())); }
public override void Write(ModuleWriter writer) { // Count the block size. int blockSize = 0; foreach(BasicBlock bb in basicBlocks) blockSize += bb.GetRawBlockSize(); // Count the argument size. int argSize = 0; for(int i = 0; i < arguments.Length; ++i) argSize += arguments[i].GetSize(); // Count the exceptions. int numexceptions = CountExceptionContexts(); int exceptionSize = 0; if(numexceptions > 0) exceptionSize = exceptionContext.GetFullSize(); // Create the member header. MemberHeader mheader = new MemberHeader(); mheader.memberType = (byte)MemberHeaderType.Function; mheader.memberFlags = (uint) GetFlags(); mheader.memberName = GetModule().RegisterString(GetName()); mheader.memberSize = (uint)(FunctionHeader.HeaderSize + blockSize + argSize + nextLocalId*LocalVariable.LocalDataSize + exceptionSize + genericPrototype.GetSize()); mheader.memberAttributes = GetAttributeCount(); // Write the member header. mheader.Write(writer); // Write the attributes. WriteAttributes(writer); // Create the header. FunctionHeader header = new FunctionHeader(); header.functionType = GetModule().RegisterType(GetFunctionType()); header.numargs = (ushort)arguments.Length; header.numlocals = (ushort)nextLocalId; header.numblocks = (ushort)basicBlocks.Count; header.numexceptions = (byte)numexceptions; if(IsMethod() && !IsStatic()) { Method method = (Method)this; if(method.IsAbstract() || method.IsContract() || method.IsOverride() || method.IsVirtual()) header.vslot = (short)method.GetVSlot(); } // Write the header. header.Write(writer); // Write the generic signature. genericPrototype.Write(writer, GetModule()); // Write the argument names. ChelaModule module = GetModule(); for(int i = 0; i < arguments.Length; ++i) arguments[i].Write(writer, module); // Write the locals. foreach(LocalVariable local in locals) { if(!local.IsPseudoLocal) local.Write(writer); } // Write the basic blocks. foreach(BasicBlock bb in basicBlocks) bb.Write(GetModule(), writer); // Write the exception contexts. if(exceptionContext != null) exceptionContext.Write(writer); }
public override void Write(ModuleWriter writer) { if(mergedGroup) throw new ModuleException("Cannot write temporal type group " + GetFullName()); // Write the header. MemberHeader header = new MemberHeader (); header.memberName = GetModule ().RegisterString (GetName ()); header.memberType = (byte)MemberHeaderType.TypeGroup; header.memberFlags = (uint)GetFlags (); header.memberSize = (uint)(types.Count * 4); header.Write (writer); // Write the functions ids. foreach (TypeGroupName gname in types) writer.Write ((uint)gname.GetBuilding().GetSerialId ()); }
public override void Write(ModuleWriter writer) { // Get the module. ChelaModule module = GetModule(); // Create the member header. MemberHeader mheader = new MemberHeader(); mheader.memberType = (byte)MemberHeaderType.TypeInstance; mheader.memberFlags = (uint) GetFlags(); mheader.memberName = 0; mheader.memberSize = (uint)(8 + genericInstance.GetSize()); mheader.memberAttributes = 0; // Write the member header. mheader.Write(writer); // Write the template id. writer.Write(module.RegisterMember(template)); // Write the factory id. writer.Write(module.RegisterMember(factory)); // Write the template parameters. genericInstance.Write(writer, GetModule()); }
public override void Write(ModuleWriter writer) { // Write the header. MemberHeader header = new MemberHeader(); header.memberType = (byte) MemberHeaderType.Property; header.memberName = GetModule().RegisterString(GetName()); header.memberFlags = (uint) GetFlags(); header.memberSize = (uint) (13 + 4*GetIndexCount()); header.Write(writer); // Write the type. ChelaModule module = GetModule(); writer.Write((uint)module.RegisterType(GetVariableType())); // Write the indices. byte numIndices = (byte)GetIndexCount(); writer.Write(numIndices); for(int i = 0; i < numIndices; ++i) writer.Write(module.RegisterType((IChelaType)indices[i])); // Write the get accessor. if(getAccessor != null) writer.Write((uint)getAccessor.GetSerialId()); else writer.Write((uint)0); // Write the set accessor. if(setAccessor != null) writer.Write((uint)setAccessor.GetSerialId()); else writer.Write((uint)0); }
public override void Write(ModuleWriter writer) { // Count the block size. int blockSize = 0; foreach (BasicBlock bb in basicBlocks) { blockSize += bb.GetRawBlockSize(); } // Count the argument size. int argSize = 0; for (int i = 0; i < arguments.Length; ++i) { argSize += arguments[i].GetSize(); } // Count the exceptions. int numexceptions = CountExceptionContexts(); int exceptionSize = 0; if (numexceptions > 0) { exceptionSize = exceptionContext.GetFullSize(); } // Create the member header. MemberHeader mheader = new MemberHeader(); mheader.memberType = (byte)MemberHeaderType.Function; mheader.memberFlags = (uint)GetFlags(); mheader.memberName = GetModule().RegisterString(GetName()); mheader.memberSize = (uint)(FunctionHeader.HeaderSize + blockSize + argSize + nextLocalId * LocalVariable.LocalDataSize + exceptionSize + genericPrototype.GetSize()); mheader.memberAttributes = GetAttributeCount(); // Write the member header. mheader.Write(writer); // Write the attributes. WriteAttributes(writer); // Create the header. FunctionHeader header = new FunctionHeader(); header.functionType = GetModule().RegisterType(GetFunctionType()); header.numargs = (ushort)arguments.Length; header.numlocals = (ushort)nextLocalId; header.numblocks = (ushort)basicBlocks.Count; header.numexceptions = (byte)numexceptions; if (IsMethod() && !IsStatic()) { Method method = (Method)this; if (method.IsAbstract() || method.IsContract() || method.IsOverride() || method.IsVirtual()) { header.vslot = (short)method.GetVSlot(); } } // Write the header. header.Write(writer); // Write the generic signature. genericPrototype.Write(writer, GetModule()); // Write the argument names. ChelaModule module = GetModule(); for (int i = 0; i < arguments.Length; ++i) { arguments[i].Write(writer, module); } // Write the locals. foreach (LocalVariable local in locals) { if (!local.IsPseudoLocal) { local.Write(writer); } } // Write the basic blocks. foreach (BasicBlock bb in basicBlocks) { bb.Write(GetModule(), writer); } // Write the exception contexts. if (exceptionContext != null) { exceptionContext.Write(writer); } }
public override void Write(ModuleWriter writer) { // The global namespace hasn't name. string name = GetName(); if(parentScope == null) name = string.Empty; // Write the header. MemberHeader header = new MemberHeader(); header.memberName = (uint)GetModule().RegisterString(name); header.memberType = (byte)MemberHeaderType.Namespace; header.memberFlags = (uint)GetFlags(); header.memberSize = (uint) (members.Count*4); header.Write(writer); // Write the member ids. foreach(ScopeMember member in this.members.Values) writer.Write((uint)member.GetSerialId()); }
public override void Write(ModuleWriter writer) { // Write the header. MemberHeader header = new MemberHeader(); header.memberName = GetModule().RegisterString(GetName()); header.memberType = (byte)MemberHeaderType.FunctionGroup; header.memberFlags = (uint)GetFlags(); header.memberSize = (uint)(functions.Count*4); header.Write(writer); // Write the functions ids. foreach(FunctionGroupName gname in functions) writer.Write((uint)gname.GetFunction().GetSerialId()); }
public void Write(ModuleWriter writer) { // Create the header. ModuleHeader header = new ModuleHeader(); // Populate it. // Store the module type. header.moduleType = (uint)moduleType; // Write the header. header.Write(writer); // Prepare the members. globalNamespace.PrepareSerialization(); foreach(ScopeMember instance in genericInstances) instance.PrepareSerialization(); // Prepare type referemnces. PrepareTypeReferences(); // Prepare resource writing. PrepareResources(); // Prepare debug information. DebugEmitter debugEmitter = null; if(debugBuild) { debugEmitter = new DebugEmitter(this); debugEmitter.Prepare(); globalNamespace.PrepareDebug(debugEmitter); } // Don't allow registering members. writingModule = true; // Write the members. header.memberTableOffset = writer.GetPosition(); foreach(ScopeMember member in memberTable) { // Write local members, and a pointer for the externals. ChelaModule memberModule = member.GetModule(); if(memberModule == this) { member.Write(writer); } else { // Don't write external generic instances. if(member.GetGenericInstance() != null) throw new ModuleException("Write external generic instance."); // Create the member reference header. MemberHeader mheader = new MemberHeader(); mheader.memberSize = 1; mheader.memberName = RegisterString(member.GetFullName()); // TODO: Use mangled name. mheader.memberType = (byte)MemberHeaderType.Reference; // Write the reference header and module id. mheader.Write(writer); writer.Write((byte)AddReference(memberModule)); } } header.memberTableSize = writer.GetPosition() - header.memberTableOffset; // Write module references. header.moduleRefTableOffset = writer.GetPosition(); header.moduleRefTableEntries = (uint) (referencedModules.Count + 1); // Write myself. ModuleReference modRef = new ModuleReference(); modRef.moduleName = RegisterString(GetName()); modRef.Write(writer); // Write module references. foreach(ChelaModule mod in referencedModules) { modRef.moduleName = RegisterString(mod.GetName()); modRef.Write(writer); } // Write the libraries table. header.libTableOffset = writer.GetPosition(); header.libTableEntries = (uint)nativeLibraries.Count; foreach(string libname in nativeLibraries) writer.Write(RegisterString(libname)); // Write the anonymous types. header.anonTypeTableOffset = writer.GetPosition(); WriteAnonType(writer); header.anonTypeTableSize = writer.GetPosition() - header.anonTypeTableOffset; // Write the type table. header.typeTableOffset = writer.GetPosition(); header.typeTableEntries = (uint)typeTable.Count; TypeReference typeRef = new TypeReference(); foreach(IChelaType type in typeTable) { // Write the type kind. if(type.IsTypeInstance()) typeRef.typeKind = (byte)TypeKind.Instance; else if(type.IsStructure()) typeRef.typeKind = (byte)TypeKind.Structure; else if(type.IsClass()) typeRef.typeKind = (byte)TypeKind.Class; else if(type.IsInterface()) typeRef.typeKind = (byte)TypeKind.Interface; else if(type.IsFunction()) typeRef.typeKind = (byte)TypeKind.Function; else if(type.IsReference()) typeRef.typeKind = (byte)TypeKind.Reference; else if(type.IsPointer()) typeRef.typeKind = (byte)TypeKind.Pointer; else if(type.IsConstant()) typeRef.typeKind = (byte)TypeKind.Constant; else if(type.IsArray()) typeRef.typeKind = (byte)TypeKind.Array; else if(type.IsVector()) typeRef.typeKind = (byte)TypeKind.Vector; else if(type.IsMatrix()) typeRef.typeKind = (byte)TypeKind.Matrix; else if(type.IsPlaceHolderType()) typeRef.typeKind = (byte)TypeKind.PlaceHolder; if(!type.IsStructure() && !type.IsClass() && !type.IsInterface() && !type.IsTypeInstance()) { // Write a reference into the anonymous types. typeRef.memberId = (uint)anonymousTypeMap[type]; typeRef.typeName = 0;//RegisterString(type.GetName()); } else { // Write the type member reference. ScopeMember member = (ScopeMember)type; typeRef.memberId = RegisterMember(member); typeRef.typeName = 0;//RegisterString(type.GetName()); } // Write the type reference. typeRef.Write(writer); } // Write the string table. header.stringTableOffset = writer.GetPosition(); header.stringTableEntries = (uint)stringTable.Count; foreach(string s in stringTable) writer.Write(s); // Write the debug info if(debugBuild) { header.debugInfoOffset = writer.GetPosition(); debugEmitter.Write(writer); header.debugInfoSize = writer.GetPosition() - header.debugInfoOffset; } // Write the resources. header.resourceDataOffset = writer.GetPosition(); WriteResources(writer); header.resourceDataSize = writer.GetPosition() - header.resourceDataOffset; // Store the module size. header.moduleSize = writer.GetPosition(); // Store the entry point. if(mainFunction != null) header.entryPoint = mainFunction.GetSerialId(); // Write the header again. writer.MoveBegin(); header.Write(writer); // Allow more modifications from here. writingModule = false; }