コード例 #1
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());
        }
コード例 #2
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);
            }
        }
コード例 #3
0
ファイル: FieldInstance.cs プロジェクト: MilkTool/chela
        internal override void PrepareSerialization()
        {
            base.PrepareSerialization();

            // Register the template and the factory.
            ChelaModule module = GetModule();

            module.RegisterMember(template);
            module.RegisterMember(factory);
        }
コード例 #4
0
        internal override void PrepareSerialization()
        {
            //base.PrepareSerialization ();
            PrepareSerializationNoBase();

            // Register the template.
            ChelaModule module = GetModule();

            module.RegisterMember(template);
            module.RegisterMember(factory);

            // Register the types used.
            genericInstance.PrepareSerialization(module);
        }
コード例 #5
0
        public void PrepareSerialization(ChelaModule module)
        {
            // Register the attribute class.
            module.RegisterType(attributeClass);

            // Register the attribute ctor.
            if (attributeCtor != null)
            {
                module.RegisterMember(attributeCtor);
            }

            // Register the properties.
            foreach (PropertyValue prop in propertyValues)
            {
                module.RegisterMember(prop.Property);
                module.RegisterType(prop.Property.GetVariableType());
            }
        }
コード例 #6
0
        internal static new void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal structure instance.
            StructureInstance instance = new StructureInstance(module);

            module.RegisterMember(instance);

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
コード例 #7
0
ファイル: FunctionInstance.cs プロジェクト: MilkTool/chela
        public override void Write(ModuleWriter writer)
        {
            // Create the member header.
            MemberHeader mheader = new MemberHeader();

            mheader.memberFlags      = (uint)GetFlags();
            mheader.memberName       = 0;
            mheader.memberAttributes = 0;

            ChelaModule module = GetModule();

            if (factory != null)
            {
                // This is a member instance.
                mheader.memberType = (byte)MemberHeaderType.MemberInstance;
                mheader.memberSize = (uint)8;

                // Write the member header.
                mheader.Write(writer);

                // Write the template.
                writer.Write(module.RegisterMember(template));

                // Write the factory id.
                writer.Write(module.RegisterMember(factory));
            }
            else
            {
                // This is a function instance
                mheader.memberType = (byte)MemberHeaderType.FunctionInstance;
                mheader.memberSize = (uint)(4 + genericInstance.GetSize());

                // Write the member header.
                mheader.Write(writer);

                // Write the template id.
                writer.Write(module.RegisterMember(template));

                // Write the template parameters.
                genericInstance.Write(writer, GetModule());
            }
        }
コード例 #8
0
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal namespace and register it.
            Namespace space = new Namespace(module);

            module.RegisterMember(space);

            // Read the name.
            space.name = module.GetString(header.memberName);

            // Skip the namespace elements.
            reader.Skip(header.memberSize);
        }
コード例 #9
0
ファイル: TypeGroup.cs プロジェクト: MilkTool/chela
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal event and register it.
            TypeGroup tgroup = new TypeGroup(module);

            module.RegisterMember(tgroup);

            // Read the name.
            tgroup.name = module.GetString(header.memberName);

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
コード例 #10
0
ファイル: FieldInstance.cs プロジェクト: MilkTool/chela
        public override void Write(ModuleWriter writer)
        {
            // Create the member header.
            MemberHeader mheader = new MemberHeader();

            mheader.memberType       = (byte)MemberHeaderType.MemberInstance;
            mheader.memberFlags      = (uint)GetFlags();
            mheader.memberName       = 0;
            mheader.memberSize       = 8;
            mheader.memberAttributes = 0;

            // Write the header.
            mheader.Write(writer);

            // Write the template.
            ChelaModule module = GetModule();

            writer.Write(module.RegisterMember(template));

            // Write the factory.
            writer.Write(module.RegisterMember(factory));
        }
コード例 #11
0
ファイル: Interface.cs プロジェクト: ronsaldo/chela
        internal static new void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal interface and register it.
            Interface iface = new Interface(module);
            module.RegisterMember(iface);

            // Read the name.
            iface.name = module.GetString(header.memberName);
            iface.flags = (MemberFlags)header.memberFlags;

            // Skip the class elements.
            reader.Skip(header.memberSize);
        }
コード例 #12
0
ファイル: EventVariable.cs プロジェクト: MilkTool/chela
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal event and register it.
            EventVariable ev = new EventVariable(module);

            module.RegisterMember(ev);

            // Read the name and flags.
            ev.SetName(module.GetString(header.memberName));
            ev.flags = (MemberFlags)header.memberFlags;

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
コード例 #13
0
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal type name and register it.
            TypeNameMember typeName = new TypeNameMember(module);

            module.RegisterMember(typeName);

            // Read the name and flags.
            typeName.name  = module.GetString(header.memberName);
            typeName.flags = (MemberFlags)header.memberFlags;

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
コード例 #14
0
ファイル: Class.cs プロジェクト: MilkTool/chela
        internal new static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal structure and register it.
            Class clazz = new Class(module);

            module.RegisterMember(clazz);

            // Read the name.
            clazz.name  = module.GetString(header.memberName);
            clazz.flags = (MemberFlags)header.memberFlags;

            // Skip the class elements.
            reader.Skip(header.memberSize);
        }
コード例 #15
0
        internal new static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal interface and register it.
            Interface iface = new Interface(module);

            module.RegisterMember(iface);

            // Read the name.
            iface.name  = module.GetString(header.memberName);
            iface.flags = (MemberFlags)header.memberFlags;

            // Skip the class elements.
            reader.Skip(header.memberSize);
        }
コード例 #16
0
ファイル: FieldVariable.cs プロジェクト: MilkTool/chela
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal field and register it.
            FieldVariable field = new FieldVariable(module);

            module.RegisterMember(field);

            // Read the name and flags.
            field.SetName(module.GetString(header.memberName));
            field.flags = (MemberFlags)header.memberFlags;

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
コード例 #17
0
ファイル: Function.cs プロジェクト: MilkTool/chela
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Check if the function is a method.
            MemberFlags instanceFlags = (MemberFlags)header.memberFlags & MemberFlags.InstanceMask;
            bool        method        = instanceFlags != MemberFlags.Static &&
                                        instanceFlags != MemberFlags.StaticConstructor;

            // Create the temporal function and register it.
            Function function = method ? new Method(module) : new Function(module);

            module.RegisterMember(function);

            // Read the name and flags.
            function.name  = module.GetString(header.memberName);
            function.flags = (MemberFlags)header.memberFlags;

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
コード例 #18
0
ファイル: Instruction.cs プロジェクト: MilkTool/chela
        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;
                }
            }
        }
コード例 #19
0
ファイル: FieldVariable.cs プロジェクト: ronsaldo/chela
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal field and register it.
            FieldVariable field = new FieldVariable(module);
            module.RegisterMember(field);

            // Read the name and flags.
            field.SetName(module.GetString(header.memberName));
            field.flags = (MemberFlags)header.memberFlags;

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
コード例 #20
0
ファイル: EventVariable.cs プロジェクト: ronsaldo/chela
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal event and register it.
            EventVariable ev = new EventVariable(module);
            module.RegisterMember(ev);

            // Read the name and flags.
            ev.SetName(module.GetString(header.memberName));
            ev.flags = (MemberFlags)header.memberFlags;

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
コード例 #21
0
ファイル: Instruction.cs プロジェクト: MilkTool/chela
        internal void PrepareSerialization(ChelaModule module)
        {
            // Register types and external members used.
            InstructionDescription desc = InstructionDescription.GetInstructionTable()[(int)opcode];

            InstructionArgumentType[] args = desc.GetArguments();
            for (int i = 0, k = 0; i < arguments.Length; i++, k++)
            {
                object arg = arguments[i];
                switch (args[k])
                {
                case InstructionArgumentType.UInt8V:
                case InstructionArgumentType.Int8V:
                case InstructionArgumentType.UInt16V:
                case InstructionArgumentType.Int16V:
                case InstructionArgumentType.UInt32V:
                case InstructionArgumentType.Int32V:
                case InstructionArgumentType.UInt64V:
                case InstructionArgumentType.Int64V:
                case InstructionArgumentType.Fp32V:
                case InstructionArgumentType.Fp64V:
                {
                    // Ignore the vector arguments.
                    byte n = (byte)arg;
                    i += n;
                }
                break;

                case InstructionArgumentType.TypeID:
                {
                    // Prepare serialization of generic instances.
                    IChelaType argType = (IChelaType)arg;
                    if (argType.IsGenericInstance() &&
                        (argType.IsStructure() || argType.IsClass() || argType.IsInterface()))
                    {
                        ScopeMember member = (ScopeMember)argType;
                        member.PrepareSerialization();
                    }

                    // Register types.
                    module.RegisterType(argType);
                }
                break;

                case InstructionArgumentType.GlobalID:
                case InstructionArgumentType.FieldID:
                case InstructionArgumentType.FunctionID:
                {
                    // Register external members.
                    ScopeMember member = (ScopeMember)arg;
                    if (member != null)
                    {
                        if (member.IsGenericInstance())
                        {
                            member.PrepareSerialization();
                        }
                        module.RegisterMember(member);
                    }
                }
                break;

                case InstructionArgumentType.JumpTable:
                {
                    // Ignore the jump table
                    ushort tableLen = (ushort)arg;
                    i += tableLen * 2;
                }
                break;

                default:
                    // Do nothing.
                    break;
                }
            }
        }