Exemple #1
0
        public void Write(ModuleWriter writer, ChelaModule module)
        {
            // Write the type count.
            writer.Write((byte)parameters.Length);

            // Write the types.
            for (int i = 0; i < parameters.Length; ++i)
            {
                writer.Write((uint)module.RegisterType(parameters[i]));
            }
        }
Exemple #2
0
        public void Write(ModuleWriter writer, ChelaModule module)
        {
            // Write the placeholder count.
            writer.Write((byte)placeHolders.Length);

            // Write the placeholders.
            for (int i = 0; i < placeHolders.Length; ++i)
            {
                PlaceHolderType placeHolder = placeHolders[i];
                writer.Write((uint)module.RegisterType(placeHolder));
            }
        }
Exemple #3
0
        public void Write(ChelaModule module, ModuleWriter writer)
        {
            // Write the number of instructions.
            writer.Write((ushort)rawInstructionSize);
            writer.Write((ushort)instructions.Count);
            writer.Write((byte)(isUnsafe ? 1 : 0));

            // Write the instructions.
            foreach (Instruction inst in instructions)
            {
                inst.Write(module, writer);
            }
        }
Exemple #4
0
        private void EmitDebugStringTable(ModuleWriter writer)
        {
            // Write the debug string table records.
            uint numRecords = (uint)stringTable.Count;

            writer.Write(numRecords);

            // Write the string table entries.
            foreach (string s in stringTable)
            {
                writer.Write(s);
            }
        }
Exemple #5
0
        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()));
        }
Exemple #6
0
        public void WriteAttributes(ModuleWriter writer)
        {
            // Ignore the case without attributes.
            if (attributes == null)
            {
                return;
            }

            // Write each one of the attributes.
            foreach (AttributeConstant attrConst in attributes)
            {
                attrConst.Write(writer, GetModule());
            }
        }
Exemple #7
0
        private void EmitStructureDebugInfo(ModuleWriter writer, Structure building)
        {
            // Emit the structure id.
            uint buildingId = building.GetSerialId();

            writer.Write(buildingId);

            // Emit the structure position.
            TokenPosition position = building.Position;

            if (position == null)
            {
                position = NullPosition;
            }
            EmitPosition(writer, position);
        }
Exemple #8
0
        private void EmitFieldDebugInfo(ModuleWriter writer, FieldVariable field)
        {
            // Emit the field id.
            uint fieldId = field.GetSerialId();

            writer.Write(fieldId);

            // Emit the field position.
            TokenPosition position = field.Position;

            if (position == null)
            {
                position = NullPosition;
            }
            EmitPosition(writer, position);
        }
Exemple #9
0
        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());
            }
        }
Exemple #10
0
        private void EmitPosition(ModuleWriter writer, TokenPosition position)
        {
            // Use the null position if unknown.
            if (position == null)
            {
                position = NullPosition;
            }

            // Emit the filename, line and column.
            uint filename = AddFileName(position.GetFileName());
            int  line     = position.GetLine();
            int  column   = position.GetColumn();

            writer.Write(filename);
            writer.Write(line);
            writer.Write(column);
        }
Exemple #11
0
        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);
            }
        }
Exemple #12
0
        private int Write(ModuleWriter writer, int parentId, int nextIndex)
        {
            // Write the parent id.
            int myindex = nextIndex;

            writer.Write((sbyte)parentId);

            // Write the number of blocks.
            writer.Write((ushort)blocks.Count);

            // Write the number of catches.
            writer.Write((byte)handlers.Count);

            // Write the cleanup.
            if (cleanup != null)
            {
                writer.Write((int)cleanup.GetIndex());
            }
            else
            {
                writer.Write((int)-1);
            }

            // Write the blocks.
            foreach (BasicBlock block in blocks)
            {
                writer.Write((ushort)block.GetIndex());
            }

            // Write the handlers.
            foreach (Handler handler in handlers)
            {
                writer.Write((uint)module.RegisterType(handler.exception));
                writer.Write((ushort)handler.handler.GetIndex());
            }

            // Write the children.
            foreach (ExceptionContext child in children)
            {
                nextIndex = child.Write(writer, myindex, nextIndex);
            }

            // Return the next index.
            return(nextIndex);
        }
Exemple #13
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());
            }
        }
Exemple #14
0
        public void Write(ModuleWriter writer)
        {
            // Emit the debug string table.
            EmitDebugStringTable(writer);

            // Emit the module name and working directory.
            writer.Write(AddString(module.GetFileName()));
            writer.Write(AddString(module.GetWorkDirectory()));

            // Emit each function debug information.
            uint numFunctions = (uint)functions.Count;

            writer.Write(numFunctions);
            foreach (Function function in functions)
            {
                EmitFunctionDebugInfo(writer, function);
            }

            // Emit each structure debug information.
            uint numStructures = (uint)structures.Count;

            writer.Write(numStructures);
            foreach (Structure building in structures)
            {
                EmitStructureDebugInfo(writer, building);
            }

            // Emit each field debug information.
            uint numFields = (uint)fields.Count;

            writer.Write(numFields);
            foreach (FieldVariable field in fields)
            {
                EmitFieldDebugInfo(writer, field);
            }
        }
Exemple #15
0
        private void EmitFunctionDebugInfo(ModuleWriter writer, Function function)
        {
            // Emit the function id.
            uint functionId = function.GetSerialId();

            writer.Write(functionId);

            // Emit the function position.
            EmitPosition(writer, function.Position);

            // Emit the lexical scopes.
            byte numscopes = (byte)function.GetLexicalScopeCount();

            writer.Write(numscopes);
            for (int i = 0; i < numscopes; ++i)
            {
                // Get the lexical scope.
                LexicalScope scope = function.GetLexicalScope(i);

                // Find the parent index.
                byte         parentIndex = 0;
                LexicalScope parentScope = scope.GetParentScope() as LexicalScope;
                if (parentScope != null)
                {
                    parentIndex = (byte)parentScope.Index;
                }

                // Emit the parent scope.
                writer.Write(parentIndex);

                // Write the scope position.
                EmitPosition(writer, scope.Position);
            }

            // Emit the local data and positions.
            ushort localCount = (ushort)function.GetLocalCount();

            writer.Write(localCount);
            foreach (LocalVariable local in function.GetLocals())
            {
                // Get the local scope.
                byte         localScope = 0;
                LexicalScope scope      = local.GetParentScope() as LexicalScope;
                if (scope != null)
                {
                    localScope = (byte)scope.Index;
                }

                // Write the variable data.
                writer.Write(AddString(local.GetName()));
                writer.Write(localScope);
                writer.Write((byte)local.Type);
                writer.Write((byte)local.ArgumentIndex);
                EmitPosition(writer, local.Position);
            }

            // Emit each basic block position information.
            ushort blockCount = (ushort)function.GetBasicBlockCount();

            writer.Write(blockCount);
            foreach (BasicBlock bb in function.GetBasicBlocks())
            {
                EmitBasicBlockDebugInfo(writer, bb);
            }
        }
Exemple #16
0
        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());
        }
Exemple #17
0
        private void EmitFunctionDebugInfo(ModuleWriter writer, Function function)
        {
            // Emit the function id.
            uint functionId = function.GetSerialId();
            writer.Write(functionId);

            // Emit the function position.
            EmitPosition(writer, function.Position);

            // Emit the lexical scopes.
            byte numscopes = (byte)function.GetLexicalScopeCount();
            writer.Write(numscopes);
            for(int i = 0; i < numscopes; ++i)
            {
                // Get the lexical scope.
                LexicalScope scope = function.GetLexicalScope(i);

                // Find the parent index.
                byte parentIndex = 0;
                LexicalScope parentScope = scope.GetParentScope() as LexicalScope;
                if(parentScope != null)
                    parentIndex = (byte)parentScope.Index;

                // Emit the parent scope.
                writer.Write(parentIndex);

                // Write the scope position.
                EmitPosition(writer, scope.Position);
            }

            // Emit the local data and positions.
            ushort localCount = (ushort)function.GetLocalCount();
            writer.Write(localCount);
            foreach(LocalVariable local in function.GetLocals())
            {
                // Get the local scope.
                byte localScope = 0;
                LexicalScope scope = local.GetParentScope() as LexicalScope;
                if(scope != null)
                    localScope = (byte)scope.Index;

                // Write the variable data.
                writer.Write(AddString(local.GetName()));
                writer.Write(localScope);
                writer.Write((byte)local.Type);
                writer.Write((byte)local.ArgumentIndex);
                EmitPosition(writer, local.Position);
            }

            // Emit each basic block position information.
            ushort blockCount = (ushort)function.GetBasicBlockCount();
            writer.Write(blockCount);
            foreach(BasicBlock bb in function.GetBasicBlocks())
                EmitBasicBlockDebugInfo(writer, bb);
        }
Exemple #18
0
        public void Write(ChelaModule module, ModuleWriter writer)
        {
            // Write the opcode.
            writer.Write((byte)opcode);

            // Write the instruction arguments.
            InstructionDescription desc = InstructionDescription.GetInstructionTable()[(int)opcode];

            InstructionArgumentType[] args = desc.GetArguments();
            byte n;

            for (int i = 0, k = 0; i < arguments.Length; i++, k++)
            {
                object arg = arguments[i];
                switch (args[k])
                {
                case InstructionArgumentType.UInt8:
                    writer.Write((byte)arg);
                    break;

                case InstructionArgumentType.UInt8V:
                {
                    n = (byte)arg;
                    writer.Write(n); i++;
                    for (int j = 0; j < n; j++)
                    {
                        writer.Write((byte)arguments[i++]);
                    }
                }
                break;

                case InstructionArgumentType.Int8:
                    writer.Write((sbyte)arg);
                    break;

                case InstructionArgumentType.Int8V:
                {
                    n = (byte)arg;
                    writer.Write(n); i++;
                    for (int j = 0; j < n; j++)
                    {
                        writer.Write((sbyte)arguments[i++]);
                    }
                }
                break;

                case InstructionArgumentType.UInt16:
                    writer.Write((ushort)arg);
                    break;

                case InstructionArgumentType.UInt16V:
                {
                    n = (byte)arg;
                    writer.Write(n); i++;
                    for (int j = 0; j < n; j++)
                    {
                        writer.Write((ushort)arguments[i++]);
                    }
                }
                break;

                case InstructionArgumentType.Int16:
                    writer.Write((short)arg);
                    break;

                case InstructionArgumentType.Int16V:
                {
                    n = (byte)arg;
                    writer.Write(n); i++;
                    for (int j = 0; j < n; j++)
                    {
                        writer.Write((short)arguments[i++]);
                    }
                }
                break;

                case InstructionArgumentType.UInt32:
                    writer.Write((uint)arg);
                    break;

                case InstructionArgumentType.UInt32V:
                {
                    n = (byte)arg;
                    writer.Write(n); i++;
                    for (int j = 0; j < n; j++)
                    {
                        writer.Write((uint)arguments[i++]);
                    }
                }
                break;

                case InstructionArgumentType.Int32:
                    writer.Write((int)arg);
                    break;

                case InstructionArgumentType.Int32V:
                {
                    n = (byte)arg;
                    writer.Write(n); i++;
                    for (int j = 0; j < n; j++)
                    {
                        writer.Write((int)arguments[i++]);
                    }
                }
                break;

                case InstructionArgumentType.UInt64:
                    writer.Write((ulong)arg);
                    break;

                case InstructionArgumentType.UInt64V:
                {
                    n = (byte)arg;
                    writer.Write(n); i++;
                    for (int j = 0; j < n; j++)
                    {
                        writer.Write((ulong)arguments[i++]);
                    }
                }
                break;

                case InstructionArgumentType.Int64:
                    writer.Write((long)arg);
                    break;

                case InstructionArgumentType.Int64V:
                {
                    n = (byte)arg;
                    writer.Write(n); i++;
                    for (int j = 0; j < n; j++)
                    {
                        writer.Write((long)arguments[i++]);
                    }
                }
                break;

                case InstructionArgumentType.Fp32:
                    writer.Write((float)arg);
                    break;

                case InstructionArgumentType.Fp32V:
                {
                    n = (byte)arg;
                    writer.Write(n); i++;
                    for (int j = 0; j < n; j++)
                    {
                        writer.Write((float)arguments[i++]);
                    }
                }
                break;

                case InstructionArgumentType.Fp64:
                    writer.Write((double)arg);
                    break;

                case InstructionArgumentType.Fp64V:
                {
                    n = (byte)arg;
                    writer.Write(n); i++;
                    for (int j = 0; j < n; j++)
                    {
                        writer.Write((double)arguments[i++]);
                    }
                }
                break;

                case InstructionArgumentType.TypeID:
                {
                    uint tyid = module.RegisterType((IChelaType)arg);
                    writer.Write(tyid);
                }
                break;

                case InstructionArgumentType.GlobalID:
                case InstructionArgumentType.FieldID:
                case InstructionArgumentType.FunctionID:
                {
                    ScopeMember member = (ScopeMember)arg;
                    uint        id     = member != null?module.RegisterMember(member) : 0u;

                    writer.Write(id);
                }
                break;

                case InstructionArgumentType.StringID:
                {
                    uint sid = module.RegisterString((string)arg);
                    writer.Write(sid);
                }
                break;

                case InstructionArgumentType.BasicBlockID:
                {
                    BasicBlock bb = (BasicBlock)arg;
                    writer.Write((ushort)bb.GetIndex());
                }
                break;

                case InstructionArgumentType.JumpTable:
                {
                    ushort tableLen = (ushort)arg;
                    writer.Write(tableLen); ++i;
                    for (int j = 0; j < tableLen; j++)
                    {
                        int constant = (int)arguments[i++];
                        writer.Write((int)constant);
                        BasicBlock bb = (BasicBlock)arguments[i++];
                        writer.Write((ushort)bb.GetIndex());
                    }
                }
                break;
                }
            }
        }
Exemple #19
0
 public void Write(ModuleWriter writer)
 {
     Write(writer, -1, 0);
 }
Exemple #20
0
        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);
        }
Exemple #21
0
        public void WriteOutput(string outputFile)
        {
            // Set the module filename data used by debugging.
            ChelaModule module = moduleNode.GetModule();
            module.SetFileName(outputFile);
            module.SetWorkDirectory(System.Environment.CurrentDirectory);

            // Create the output file.
            FileStream output = new FileStream(outputFile, FileMode.Create);

            // Write the module.
            ModuleWriter writer = new ModuleWriter(output);
            Benchmark.Begin();
            module.Write(writer);

            // Close the output file.
            output.Flush();
            output.Close();
            Benchmark.End("Write module");
        }
Exemple #22
0
        private void EmitBasicBlockDebugInfo(ModuleWriter writer, BasicBlock block)
        {
            // Compute instructions subblocks.
            List<SubBlock> subBlocks = new List<SubBlock> ();
            TokenPosition position = NullPosition;
            int start = 0;
            int index = 0;
            foreach(Instruction inst in block.GetInstructions())
            {
                // Get the instruction position.
                TokenPosition instPos = inst.GetPosition();
                if(instPos == null)
                    instPos = NullPosition;

                if(instPos != position)
                {
                    // Create a sub block for the previous set.
                    if(index != 0)
                    {
                        SubBlock subBlock = new SubBlock();
                        subBlock.Position = position;
                        subBlock.Start = (ushort)start;
                        subBlock.End = (ushort)(index - 1);

                        // Store the sub block.
                        subBlocks.Add(subBlock);
                    }

                    // Store the start of the next subblock.
                    start = index;
                    position = instPos;
                }

                // Increase the index.
                ++index;
            }

            // Create the last sub block.
            SubBlock lastSubBlock = new SubBlock();
            lastSubBlock.Position = position;
            lastSubBlock.Start = (ushort)(start);
            lastSubBlock.End = (ushort)(index - 1);

            // Store the sub block.
            subBlocks.Add(lastSubBlock);

            // Emit all of the sub blocks.
            ushort numSubs = (ushort)subBlocks.Count;
            writer.Write(numSubs);
            foreach(SubBlock subBlock in subBlocks)
            {
                writer.Write(subBlock.Start);
                writer.Write(subBlock.End);
                EmitPosition(writer, subBlock.Position);
            }
        }
Exemple #23
0
        private void EmitDebugStringTable(ModuleWriter writer)
        {
            // Write the debug string table records.
            uint numRecords = (uint)stringTable.Count;
            writer.Write(numRecords);

            // Write the string table entries.
            foreach(string s in stringTable)
                writer.Write(s);
        }
Exemple #24
0
        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());
        }
Exemple #25
0
        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;
        }
Exemple #26
0
        public void Write(ChelaModule module, ModuleWriter writer)
        {
            // Write the opcode.
            writer.Write((byte)opcode);

            // Write the instruction arguments.
            InstructionDescription desc = InstructionDescription.GetInstructionTable()[(int)opcode];
            InstructionArgumentType[] args = desc.GetArguments();
            byte n;
            for(int i = 0, k = 0; i < arguments.Length; i++, k++)
            {
                object arg = arguments[i];
                switch(args[k])
                {
                case InstructionArgumentType.UInt8:
                    writer.Write((byte)arg);
                    break;
                case InstructionArgumentType.UInt8V:
                    {
                        n = (byte)arg;
                        writer.Write(n); i++;
                        for(int j = 0; j < n; j++)
                            writer.Write((byte)arguments[i++]);
                    }
                    break;
                case InstructionArgumentType.Int8:
                    writer.Write((sbyte)arg);
                    break;
                case InstructionArgumentType.Int8V:
                    {
                        n = (byte)arg;
                        writer.Write(n); i++;
                        for(int j = 0; j < n; j++)
                            writer.Write((sbyte)arguments[i++]);
                    }
                    break;
                case InstructionArgumentType.UInt16:
                    writer.Write((ushort)arg);
                    break;
                case InstructionArgumentType.UInt16V:
                    {
                        n = (byte)arg;
                        writer.Write(n); i++;
                        for(int j = 0; j < n; j++)
                            writer.Write((ushort)arguments[i++]);
                    }
                    break;
                case InstructionArgumentType.Int16:
                    writer.Write((short)arg);
                    break;
                case InstructionArgumentType.Int16V:
                    {
                        n = (byte)arg;
                        writer.Write(n); i++;
                        for(int j = 0; j < n; j++)
                            writer.Write((short)arguments[i++]);
                    }
                    break;
                case InstructionArgumentType.UInt32:
                    writer.Write((uint)arg);
                    break;
                case InstructionArgumentType.UInt32V:
                    {
                        n = (byte)arg;
                        writer.Write(n); i++;
                        for(int j = 0; j < n; j++)
                            writer.Write((uint)arguments[i++]);
                    }
                    break;
                case InstructionArgumentType.Int32:
                    writer.Write((int)arg);
                    break;
                case InstructionArgumentType.Int32V:
                    {
                        n = (byte)arg;
                        writer.Write(n); i++;
                        for(int j = 0; j < n; j++)
                            writer.Write((int)arguments[i++]);
                    }
                    break;
                case InstructionArgumentType.UInt64:
                    writer.Write((ulong)arg);
                    break;
                case InstructionArgumentType.UInt64V:
                    {
                        n = (byte)arg;
                        writer.Write(n); i++;
                        for(int j = 0; j < n; j++)
                            writer.Write((ulong)arguments[i++]);
                    }
                    break;
                case InstructionArgumentType.Int64:
                    writer.Write((long)arg);
                    break;
                case InstructionArgumentType.Int64V:
                    {
                        n = (byte)arg;
                        writer.Write(n); i++;
                        for(int j = 0; j < n; j++)
                            writer.Write((long)arguments[i++]);
                    }
                    break;
                case InstructionArgumentType.Fp32:
                    writer.Write((float)arg);
                    break;
                case InstructionArgumentType.Fp32V:
                    {
                        n = (byte)arg;
                        writer.Write(n); i++;
                        for(int j = 0; j < n; j++)
                            writer.Write((float)arguments[i++]);
                    }
                    break;
                case InstructionArgumentType.Fp64:
                    writer.Write((double)arg);
                    break;
                case InstructionArgumentType.Fp64V:
                    {
                        n = (byte)arg;
                        writer.Write(n); i++;
                        for(int j = 0; j < n; j++)
                            writer.Write((double)arguments[i++]);
                    }
                    break;
                case InstructionArgumentType.TypeID:
                    {
                        uint tyid = module.RegisterType((IChelaType)arg);
                        writer.Write(tyid);
                    }
                    break;
                case InstructionArgumentType.GlobalID:
                case InstructionArgumentType.FieldID:
                case InstructionArgumentType.FunctionID:
                    {
                        ScopeMember member = (ScopeMember) arg;
                        uint id = member != null ? module.RegisterMember(member) : 0u;
                        writer.Write(id);
                    }
                    break;
                case InstructionArgumentType.StringID:
                    {
                        uint sid = module.RegisterString((string)arg);
                        writer.Write(sid);
                    }
                    break;
                case InstructionArgumentType.BasicBlockID:
                    {
                        BasicBlock bb = (BasicBlock) arg;
                        writer.Write((ushort)bb.GetIndex());
                    }
                    break;
                case InstructionArgumentType.JumpTable:
                    {
                        ushort tableLen = (ushort) arg;
                        writer.Write(tableLen); ++i;
                        for(int j = 0; j < tableLen; j++)
                        {
                            int constant = (int)arguments[i++];
                            writer.Write((int)constant);
                            BasicBlock bb = (BasicBlock) arguments[i++];
                            writer.Write((ushort)bb.GetIndex());
                        }
                    }
                    break;
                }
            }
        }
Exemple #27
0
        private void EmitStructureDebugInfo(ModuleWriter writer, Structure building)
        {
            // Emit the structure id.
            uint buildingId = building.GetSerialId();
            writer.Write(buildingId);

            // Emit the structure position.
            TokenPosition position = building.Position;
            if(position == null)
                position = NullPosition;
            EmitPosition(writer, position);
        }
Exemple #28
0
        private void EmitPosition(ModuleWriter writer, TokenPosition position)
        {
            // Use the null position if unknown.
            if(position == null)
                position = NullPosition;

            // Emit the filename, line and column.
            uint filename = AddFileName(position.GetFileName());
            int line = position.GetLine();
            int column = position.GetColumn();
            writer.Write(filename);
            writer.Write(line);
            writer.Write(column);
        }
Exemple #29
0
 public void Write(ModuleWriter writer)
 {
     Write(writer, -1, 0);
 }
Exemple #30
0
        private int Write(ModuleWriter writer, int parentId, int nextIndex)
        {
            // Write the parent id.
            int myindex = nextIndex;
            writer.Write((sbyte)parentId);

            // Write the number of blocks.
            writer.Write((ushort)blocks.Count);

            // Write the number of catches.
            writer.Write((byte)handlers.Count);

            // Write the cleanup.
            if(cleanup != null)
                writer.Write((int)cleanup.GetIndex());
            else
                writer.Write((int)-1);

            // Write the blocks.
            foreach(BasicBlock block in blocks)
            {
                writer.Write((ushort) block.GetIndex());
            }

            // Write the handlers.
            foreach(Handler handler in handlers)
            {
                writer.Write((uint)module.RegisterType(handler.exception));
                writer.Write((ushort)handler.handler.GetIndex());
            }

            // Write the children.
            foreach(ExceptionContext child in children)
                nextIndex = child.Write(writer, myindex, nextIndex);

            // Return the next index.
            return nextIndex;
        }
Exemple #31
0
        public void Write(ChelaModule module, ModuleWriter writer)
        {
            // Write the number of instructions.
            writer.Write((ushort)rawInstructionSize);
            writer.Write((ushort)instructions.Count);
            writer.Write((byte)(isUnsafe ? 1 : 0));

            // Write the instructions.
            foreach(Instruction inst in instructions)
                inst.Write(module, writer);
        }
Exemple #32
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);
            }
        }
Exemple #33
0
        public void Write(ModuleWriter writer)
        {
            // Emit the debug string table.
            EmitDebugStringTable(writer);

            // Emit the module name and working directory.
            writer.Write(AddString(module.GetFileName()));
            writer.Write(AddString(module.GetWorkDirectory()));

            // Emit each function debug information.
            uint numFunctions = (uint)functions.Count;
            writer.Write(numFunctions);
            foreach(Function function in functions)
                EmitFunctionDebugInfo(writer, function);

            // Emit each structure debug information.
            uint numStructures = (uint)structures.Count;
            writer.Write(numStructures);
            foreach(Structure building in structures)
                EmitStructureDebugInfo(writer, building);

            // Emit each field debug information.
            uint numFields = (uint)fields.Count;
            writer.Write(numFields);
            foreach(FieldVariable field in fields)
                EmitFieldDebugInfo(writer, field);
        }
Exemple #34
0
        private void EmitBasicBlockDebugInfo(ModuleWriter writer, BasicBlock block)
        {
            // Compute instructions subblocks.
            List <SubBlock> subBlocks = new List <SubBlock> ();
            TokenPosition   position  = NullPosition;
            int             start     = 0;
            int             index     = 0;

            foreach (Instruction inst in block.GetInstructions())
            {
                // Get the instruction position.
                TokenPosition instPos = inst.GetPosition();
                if (instPos == null)
                {
                    instPos = NullPosition;
                }

                if (instPos != position)
                {
                    // Create a sub block for the previous set.
                    if (index != 0)
                    {
                        SubBlock subBlock = new SubBlock();
                        subBlock.Position = position;
                        subBlock.Start    = (ushort)start;
                        subBlock.End      = (ushort)(index - 1);

                        // Store the sub block.
                        subBlocks.Add(subBlock);
                    }

                    // Store the start of the next subblock.
                    start    = index;
                    position = instPos;
                }

                // Increase the index.
                ++index;
            }

            // Create the last sub block.
            SubBlock lastSubBlock = new SubBlock();

            lastSubBlock.Position = position;
            lastSubBlock.Start    = (ushort)(start);
            lastSubBlock.End      = (ushort)(index - 1);

            // Store the sub block.
            subBlocks.Add(lastSubBlock);

            // Emit all of the sub blocks.
            ushort numSubs = (ushort)subBlocks.Count;

            writer.Write(numSubs);
            foreach (SubBlock subBlock in subBlocks)
            {
                writer.Write(subBlock.Start);
                writer.Write(subBlock.End);
                EmitPosition(writer, subBlock.Position);
            }
        }
Exemple #35
0
        public void WriteAttributes(ModuleWriter writer)
        {
            // Ignore the case without attributes.
            if(attributes == null)
                return;

            // Write each one of the attributes.
            foreach(AttributeConstant attrConst in attributes)
                attrConst.Write(writer, GetModule());
        }
Exemple #36
0
        /// <summary>
        /// Writes the attribute constant into the module file.
        /// </summary>
        /// <param name="writer">
        /// A <see cref="ModuleWriter"/>
        /// </param>
        public void Write(ModuleWriter writer, ChelaModule module)
        {
            // Write the attribute class id.
            uint attributeClassId = module.RegisterMember(attributeClass);
            writer.Write(attributeClassId);

            // Write the attribute constructor id.
            uint attributeCtorId = module.RegisterMember(attributeCtor);
            writer.Write(attributeCtorId);

            // Write the arguments.
            byte numargs = (byte)ctorArguments.Count;
            writer.Write(numargs);
            for(int i = 0; i < numargs; ++i)
            {
                ConstantValue arg = ctorArguments[i];
                arg.WriteQualified(module, writer);
            }

            // Write the properties.
            byte numprops = (byte)propertyValues.Count;
            writer.Write(numprops);
            for(int i = 0; i < numprops; ++i)
            {
                PropertyValue propVal = propertyValues[i];
                uint propId = module.RegisterMember(propVal.Property);
                writer.Write(propId);
                propVal.Value.WriteQualified(module, writer);
            }
        }
Exemple #37
0
        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());
        }
Exemple #38
0
        private void WriteAnonType(ModuleWriter writer)
        {
            AnonTypeHeader header = new AnonTypeHeader();

            foreach(IChelaType anonType in anonymousTypes)
            {
                if(anonType.IsReference())
                {
                    // Write the header.
                    ReferenceType refType = (ReferenceType) anonType;
                    header.typeKind = (byte) TypeKind.Reference;
                    header.recordSize = 6;
                    header.Write(writer);

                    // Write the referenced type.
                    writer.Write((uint)RegisterType(refType.GetReferencedType()));
                    writer.Write((byte)refType.GetReferenceFlow());
                    writer.Write((byte)(refType.IsStreamReference() ? 1 : 0));
                }
                else if(anonType.IsPointer())
                {
                    // Write the header.
                    PointerType pointerType = (PointerType) anonType;
                    header.typeKind = (byte) TypeKind.Pointer;
                    header.recordSize = 4;
                    header.Write(writer);

                    // Write the referenced type.
                    writer.Write((uint)RegisterType(pointerType.GetPointedType()));

                }
                else if(anonType.IsConstant())
                {
                    // Write the header.
                    ConstantType constantType = (ConstantType) anonType;
                    header.typeKind = (byte) TypeKind.Constant;
                    header.recordSize = 4;
                    header.Write(writer);

                    // Write the value type.
                    writer.Write((uint)RegisterType(constantType.GetValueType()));
                }
                else if(anonType.IsArray())
                {
                    // Write the header.
                    ArrayType arrayType = (ArrayType) anonType;
                    header.typeKind = (byte) TypeKind.Array;
                    header.recordSize = 6;
                    header.Write(writer);

                    // Write the value type.
                    writer.Write((uint)RegisterType(arrayType.GetValueType()));
                    writer.Write((byte)arrayType.GetDimensions());
                    writer.Write((byte)(arrayType.IsReadOnly() ? 1 : 0));
                }
                else if(anonType.IsVector())
                {
                    // Write the header.
                    VectorType vectorType = (VectorType)anonType;
                    header.typeKind = (byte)TypeKind.Vector;
                    header.recordSize = 5;
                    header.Write(writer);

                    // Write the primitive type.
                    writer.Write((uint)RegisterType(vectorType.GetPrimitiveType()));

                    // Write the number of components.
                    writer.Write((byte)vectorType.GetNumComponents());
                }
                else if(anonType.IsMatrix())
                {
                    // Write the header.
                    MatrixType matrixType = (MatrixType)anonType;
                    header.typeKind = (byte)TypeKind.Matrix;
                    header.recordSize = 6;
                    header.Write(writer);

                    // Write the primitive type.
                    writer.Write((uint)RegisterType(matrixType.GetPrimitiveType()));

                    // Write the number of rows and columns.
                    writer.Write((byte)matrixType.GetNumRows());
                    writer.Write((byte)matrixType.GetNumColumns());
                }
                else if(anonType.IsFunction())
                {
                    // Get the type.
                    FunctionType functionType = (FunctionType) anonType;

                    // Write the header.
                    header.typeKind =(byte) TypeKind.Function;
                    header.recordSize = (uint)(functionType.GetArgumentCount()*4 + 8);
                    header.Write(writer);

                    // Write the flags.
                    int flags = (int)functionType.GetFunctionFlags();
                    flags |= functionType.HasVariableArgument() ? 1 : 0;
                    writer.Write((uint)flags);

                    // Write the return type.
                    writer.Write((uint)RegisterType(functionType.GetReturnType()));

                    // Write the arguments.
                    foreach(IChelaType arg in functionType.GetArguments())
                        writer.Write((uint)RegisterType(arg));
                }
                else if(anonType.IsPlaceHolderType())
                {
                    // Cast the type.
                    PlaceHolderType placeholder = (PlaceHolderType)anonType;

                    // Write the header.
                    header.typeKind =(byte) TypeKind.PlaceHolder;
                    header.recordSize = (uint)(placeholder.GetBaseCount()*4 + 10);
                    header.Write(writer);

                    // Write the name.
                    writer.Write((uint)RegisterString(placeholder.GetName()));

                    // Write the id.
                    writer.Write((uint)placeholder.GetPlaceHolderId());

                    // Write the value type flag.
                    writer.Write((byte) (placeholder.IsValueType() ? 1 : 0));

                    // Write the number of bases.
                    writer.Write((byte) placeholder.GetBaseCount());

                    // Write the bases.
                    for(int i = 0; i < placeholder.GetBaseCount(); ++i)
                        writer.Write((uint) RegisterMember(placeholder.GetBase(i)));
                }
                else
                {
                    throw new ModuleException("Trying to write an invalid anon type.");
                }
            }
        }
Exemple #39
0
        private void EmitFieldDebugInfo(ModuleWriter writer, FieldVariable field)
        {
            // Emit the field id.
            uint fieldId = field.GetSerialId();
            writer.Write(fieldId);

            // Emit the field position.
            TokenPosition position = field.Position;
            if(position == null)
                position = NullPosition;
            EmitPosition(writer, position);
        }
Exemple #40
0
 public virtual void Write(ModuleWriter writer)
 {
 }
Exemple #41
0
        private void WriteResources(ModuleWriter writer)
        {
            // Compute the initial offsets.
            int numresources = resources.Count;
            int headerSize = numresources*12;
            int nextOffset = (int)writer.GetPosition() + headerSize + /*numresources*/4;

            // Sort the resources by name.
            resources.Sort(delegate(ResourceData r1, ResourceData r2) {
                return string.Compare(r1.Name, r2.Name);
            });

            // Write the number of resources.
            writer.Write(numresources);

            // Write the resource headers.
            foreach(ResourceData resource in resources)
            {
                // Writer the resource metadata.
                uint name = RegisterString(resource.Name);
                int offset = nextOffset;
                int length = resource.Length;
                writer.Write(name);
                writer.Write(offset);
                writer.Write(length);

                // Increase the next offset.
                nextOffset += length;
            }

            // Write the resource data.
            foreach(ResourceData resource in resources)
                writer.Write(resource.File);
        }
Exemple #42
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 ());
        }
Exemple #43
0
 public void Write(ModuleWriter writer)
 {
     writer.Write(typeKind);
     writer.Write(recordSize);
 }
Exemple #44
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);
        }
Exemple #45
0
 public void Write(ModuleWriter writer)
 {
     writer.Write(Signature, 8);
     writer.Write(moduleSize);
     writer.Write(formatVersionMajor);
     writer.Write(formatVersionMinor);
     writer.Write(moduleType);
     writer.Write(entryPoint);
     writer.Write(moduleRefTableEntries);
     writer.Write(moduleRefTableOffset);
     writer.Write(memberTableOffset);
     writer.Write(memberTableSize);
     writer.Write(anonTypeTableOffset);
     writer.Write(anonTypeTableSize);
     writer.Write(typeTableEntries);
     writer.Write(typeTableOffset);
     writer.Write(stringTableEntries);
     writer.Write(stringTableOffset);
     writer.Write(libTableOffset);
     writer.Write(libTableEntries);
     writer.Write(debugInfoSize);
     writer.Write(debugInfoOffset);
     writer.Write(resourceDataSize);
     writer.Write(resourceDataOffset);
 }
Exemple #46
0
 public void Write(ModuleWriter writer)
 {
     writer.Write(moduleName);
     writer.Write(versionMajor);
     writer.Write(versionMinor);
     writer.Write(versionMicro);
 }
Exemple #47
0
 public void Write(ModuleWriter writer)
 {
     writer.Write(typeName);
     writer.Write(typeKind);
     writer.Write(memberId);
 }
Exemple #48
0
        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()));
        }
Exemple #49
0
 public virtual void Write(ModuleWriter writer)
 {
 }