コード例 #1
0
ファイル: Function.cs プロジェクト: MilkTool/chela
        internal override void Read(ModuleReader reader, MemberHeader header)
        {
            // Read the function header.
            FunctionHeader fheader = new FunctionHeader();

            fheader.Read(reader);

            // Read the function type.
            type = (FunctionType)GetModule().GetType(fheader.functionType);

            // Read the generic prototype.
            genericPrototype = GenericPrototype.Read(reader, GetModule());

            // Read the vslot.
            if (IsMethod())
            {
                Method method = (Method)this;
                method.vslot = fheader.vslot;
            }

            // Skip the elements.
            reader.Skip(header.memberSize - FunctionHeader.HeaderSize - genericPrototype.GetSize());
        }
コード例 #2
0
ファイル: Function.cs プロジェクト: ronsaldo/chela
        internal override void Read(ModuleReader reader, MemberHeader header)
        {
            // Read the function header.
            FunctionHeader fheader = new FunctionHeader();
            fheader.Read(reader);

            // Read the function type.
            type = (FunctionType)GetModule().GetType(fheader.functionType);

            // Read the generic prototype.
            genericPrototype = GenericPrototype.Read(reader, GetModule());

            // Read the vslot.
            if(IsMethod())
            {
                Method method = (Method)this;
                method.vslot = fheader.vslot;
            }

            // Skip the elements.
            reader.Skip(header.memberSize - FunctionHeader.HeaderSize - genericPrototype.GetSize());
        }
コード例 #3
0
ファイル: Function.cs プロジェクト: ronsaldo/chela
        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);
        }
コード例 #4
0
ファイル: Function.cs プロジェクト: MilkTool/chela
        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);
            }
        }