Ejemplo n.º 1
0
        public StructDefinition ProcessForStruct(TypeDefinition type)
        {
            Context.CLRLogger.Debug($"\tProcessing {type.FullName} type for LLVM");
            var processed = ResolveAllFields(type.Resolve());

            foreach (var field in processed)
            {
                if (field.FieldType.IsNested && !Context.FullSymbolToTypeRef.ContainsKey(field.FieldType.FullName))
                {
                    Context.FullSymbolToTypeRef.Add(field.FieldType.FullName,
                                                    ProcessForStruct(field.FieldType.Resolve()));
                }
            }

            var structDef = new StructDefinition
            {
                CS_StructName    = type.FullName,
                LL_StructName    = type.FullName,
                CS_FieldDefs     = processed,
                LL_FieldTypeRefs = processed.Select(I => ResolveType(I.FieldType)).ToArray()
            };

            structDef.StructTypeRef = LLVM.StructTypeInContext(Context.ContextRef, structDef.LL_FieldTypeRefs.Select(
                                                                   f =>
            {
                Context.CLRLogger.Debug($"\t\t{f.StackType.FullName} - {f.FieldTypeRef}");
                return(f.FieldTypeRef);
            }).ToArray(), true);
            return(structDef);
        }
Ejemplo n.º 2
0
        private void AddBCLObjects()
        {
            var structDef = new StructDefinition();

            if (_options.MetadataTypeHandlingModeOption == MetadataTypeHandlingMode.Full_Fixed)
            {
                // C# Fields are going to be seen as Int32, but it may not necessarily be 32 bit integer,
                // What is important is the specified type information in LLVM.
                // This is intended to allow a more flexible optimization feature.
                structDef.CS_FieldDefs = new[]
                {
                    new FieldDefinition("___INTERNAL__DO_NOT_TOUCH__CLR__TYPEHANDLE",
                                        FieldAttributes.SpecialName | FieldAttributes.Private | FieldAttributes.CompilerControlled,
                                        MiniBCL.Int32Type),
                    new FieldDefinition("___INTERNAL__DO_NOT_TOUCH__CLR__SYNC",
                                        FieldAttributes.SpecialName | FieldAttributes.Private | FieldAttributes.CompilerControlled,
                                        MiniBCL.Int32Type)
                };

                structDef.CS_StructName = "Object";
                structDef.LL_StructName = "Object";

                structDef.LL_FieldTypeRefs = new[]
                {
                    new LLVMFieldDefAndRef(MiniBCL.Int32Type, LLVM.IntType(_options.MetadataFixedLength)),
                    new LLVMFieldDefAndRef(MiniBCL.Int32Type, LLVM.IntType(_options.MetadataFixedLength))
                };

                structDef.StructTypeRef =
                    LLVM.StructType(structDef.LL_FieldTypeRefs.Select(I => I.FieldTypeRef).ToArray(), true);

                _context.FullSymbolToTypeRef.Add("System.Object", structDef);

                // TODO: Add actual Type retrieval for objects
                _context.SymbolToCallableFunction.Add("System.Object::GetType", default(LLVMValueRef));
            }
            else
            {
                // TODO: Implement support for Full_Native and None.
                throw new NotImplementedException();
            }
        }