Ejemplo n.º 1
0
        private static void BuildVTableFunctionLookup()
        {
            List <LLParameter> parametersFunction = new List <LLParameter>();

            parametersFunction.Add(LLParameter.Create(LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 1), "this"));
            parametersFunction.Add(LLParameter.Create(LLModule.GetOrCreateSignedType(32), "index"));
            sVTableFunctionLookup = LLModule.GetOrCreateFunction("VTableFunctionLookup", true, true, false, LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 1), parametersFunction);
        }
Ejemplo n.º 2
0
        private static void BuildRuntimeDataStringTable(HLStringTable pStringTable)
        {
            byte[]   bufferRuntimeDataStringTable   = pStringTable.ToASCIIBytes();
            string[] literalsRuntimeDataStringTable = Array.ConvertAll(bufferRuntimeDataStringTable, b => b.ToString());
            LLType   typeRuntimeDataStringTable     = LLModule.GetOrCreateArrayType(LLModule.GetOrCreateSignedType(8), literalsRuntimeDataStringTable.Length);
            LLGlobal globalRuntimeDataStringTable   = LLModule.CreateGlobal(typeRuntimeDataStringTable.PointerDepthPlusOne, "RuntimeDataStringTable");

            globalRuntimeDataStringTable.InitialValue = typeRuntimeDataStringTable.ToLiteral(literalsRuntimeDataStringTable);
        }
Ejemplo n.º 3
0
        private static void BuildGCAllocate()
        {
            List <LLParameter> parametersFunction = new List <LLParameter>();

            parametersFunction.Add(LLParameter.Create(LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 2), "this"));
            parametersFunction.Add(LLParameter.Create(LLModule.GetOrCreateUnsignedType(32), "size"));
            parametersFunction.Add(LLParameter.Create(LLModule.GetOrCreateSignedType(32), "handle"));
            sGCAllocate = LLModule.GetOrCreateFunction("GCAllocate", true, true, false, LLModule.VoidType, parametersFunction);
        }
Ejemplo n.º 4
0
        private static void BuildRuntimeMethodData(HLStringTable pStringTable)
        {
            List <LLType>     fieldsRuntimeMethodData                 = sSystemRuntimeMethodData.Fields.Where(f => !f.IsStatic).ToList().ConvertAll(f => f.Type.LLType);
            LLType            typePointer                             = LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 1);
            LLType            typeRuntimeMethodData                   = LLModule.GetOrCreateStructureType("RuntimeMethodData", true, fieldsRuntimeMethodData);
            LLType            typeRuntimeMethodDataTable              = LLModule.GetOrCreateArrayType(typeRuntimeMethodData, sMethods.Values.Count);
            LLGlobal          globalRuntimeMethodDataTable            = LLModule.CreateGlobal(typeRuntimeMethodDataTable.PointerDepthPlusOne, "RuntimeMethodDataTable");
            List <LLLiteral>  literalsRuntimeMethodDataTable          = new List <LLLiteral>();
            List <LLFunction> functionsRuntimeMethodDataFunctionTable = new List <LLFunction>();
            List <LLLiteral>  literalsRuntimeMethodDataFunctionTable  = new List <LLLiteral>();

            foreach (HLMethod method in sMethods.Values.OrderBy(m => m.RuntimeMethodHandle))
            {
                int flags = 0;
                if (method.IsStatic)
                {
                    flags |= 1 << 0;
                }

                string definitionName = method.Definition.Name.Value;
                int    offsetName     = pStringTable.Include(definitionName);

                literalsRuntimeMethodDataTable.Add(typeRuntimeMethodData.ToLiteral(method.RuntimeMethodHandle.ToString(), flags.ToString(), offsetName.ToString()));

                LLFunction function = method.LLFunction;
                functionsRuntimeMethodDataFunctionTable.Add(function);
                string literalAddress = null;
                if (method.LLFunction.Abstract)
                {
                    literalAddress = "null";
                }
                else
                {
                    literalAddress = string.Format("bitcast({0} {1} to {2})", LLModule.GetOrCreatePointerType(function.FunctionType, 1), function, typePointer);
                }
                literalsRuntimeMethodDataFunctionTable.Add(LLLiteral.Create(typePointer, literalAddress));
            }
            globalRuntimeMethodDataTable.InitialValue = typeRuntimeMethodDataTable.ToLiteral(literalsRuntimeMethodDataTable.ConvertAll(l => l.Value).ToArray());
            LLGlobal globalRuntimeMethodDataTableCount = LLModule.CreateGlobal(LLModule.GetOrCreateSignedType(32), "RuntimeMethodDataTableCount");

            globalRuntimeMethodDataTableCount.InitialValue = LLLiteral.Create(LLModule.GetOrCreateSignedType(32), sMethods.Values.Count.ToString());

            LLType   typeRuntimeMethodDataFunctionTable   = LLModule.GetOrCreateArrayType(typePointer, functionsRuntimeMethodDataFunctionTable.Count);
            LLGlobal globalRuntimeMethodDataFunctionTable = LLModule.CreateGlobal(typeRuntimeMethodDataFunctionTable.PointerDepthPlusOne, "RuntimeMethodDataFunctionTable");

            globalRuntimeMethodDataFunctionTable.InitialValue = typeRuntimeMethodDataFunctionTable.ToLiteral(literalsRuntimeMethodDataFunctionTable.ConvertAll(l => l.Value).ToArray());
            LLGlobal globalRuntimeMethodDataFunctionTableCount = LLModule.CreateGlobal(LLModule.GetOrCreateSignedType(32), "RuntimeMethodDataFunctionTableCount");

            globalRuntimeMethodDataFunctionTableCount.InitialValue = LLLiteral.Create(LLModule.GetOrCreateSignedType(32), functionsRuntimeMethodDataFunctionTable.Count.ToString());

            sRuntimeMethodDataFunctionTable = globalRuntimeMethodDataFunctionTable;
        }
Ejemplo n.º 5
0
 private static void BuildRuntimeTypeHandles()
 {
     foreach (HLType type in sTypes.Values.OrderBy(t => t.RuntimeTypeHandle).Where(t => t.Definition.TypeCode != PrimitiveTypeCode.Pointer && t.Definition.TypeCode != PrimitiveTypeCode.Reference && !(t.Definition is IArrayType)))
     {
         string globalName = "RuntimeTypeHandle_" + type.ToString().Replace(".", "");
         //int startOfPtrOrRef = globalName.IndexOfAny(new char[] { '*', '&' });
         //if (startOfPtrOrRef > 0) globalName = globalName.Insert(startOfPtrOrRef, "_");
         //globalName = globalName.Replace("*", "Ptr");
         //globalName = globalName.Replace("&", "Ref");
         LLGlobal globalHandle = LLModule.CreateGlobal(LLModule.GetOrCreateSignedType(32), globalName);
         globalHandle.InitialValue = LLLiteral.Create(LLModule.GetOrCreateSignedType(32), type.RuntimeTypeHandle.ToString());
     }
 }
Ejemplo n.º 6
0
        internal override LLLocation Load(LLFunction pFunction)
        {
            List <LLLocation> parameters = new List <LLLocation>();

            LLLocation locationStringReference = LLTemporaryLocation.Create(pFunction.CreateTemporary(HLDomain.SystemStringCtorWithCharPointer.Parameters[0].Type.LLType.PointerDepthPlusOne));

            pFunction.CurrentBlock.EmitAllocate(locationStringReference);
            pFunction.CurrentBlock.EmitStore(locationStringReference, LLLiteralLocation.Create(LLLiteral.Create(locationStringReference.Type.PointerDepthMinusOne, "zeroinitializer")));

            parameters.Add(locationStringReference);
            parameters.Add(LLLiteralLocation.Create(LLLiteral.Create(HLDomain.GCRoot.Parameters[1].Type, "null")));
            pFunction.CurrentBlock.EmitCall(null, LLFunctionLocation.Create(HLDomain.GCRoot), parameters);

            parameters.Clear();
            parameters.Add(locationStringReference);

            char[] data = Literal.ToCharArray();
            Array.Resize(ref data, data.Length + 1);

            LLType     typeChar            = LLModule.GetOrCreateSignedType(16);
            LLType     typeLiteralData     = LLModule.GetOrCreateArrayType(typeChar, data.Length);
            LLLocation locationLiteralData = LLTemporaryLocation.Create(pFunction.CreateTemporary(typeLiteralData.PointerDepthPlusOne));

            pFunction.CurrentBlock.EmitAllocate(locationLiteralData);
            StringBuilder sb = new StringBuilder();

            sb.Append("[ ");
            for (int index = 0; index < data.Length; ++index)
            {
                if (index > 0)
                {
                    sb.Append(", ");
                }
                sb.AppendFormat("{0} {1}", typeChar, (int)data[index]);
            }
            sb.Append(" ]");
            pFunction.CurrentBlock.EmitStore(locationLiteralData, LLLiteralLocation.Create(LLLiteral.Create(typeLiteralData, sb.ToString())));
            parameters.Add(locationLiteralData);

            for (int index = 1; index < parameters.Count; ++index)
            {
                parameters[index] = pFunction.CurrentBlock.EmitConversion(parameters[index], HLDomain.SystemStringCtorWithCharPointer.Parameters[index].Type.LLType);
            }

            pFunction.CurrentBlock.EmitCall(null, LLFunctionLocation.Create(HLDomain.SystemStringCtorWithCharPointer.LLFunction), parameters);

            LLLocation locationString = LLTemporaryLocation.Create(pFunction.CreateTemporary(Type.LLType));

            pFunction.CurrentBlock.EmitLoad(locationString, locationStringReference);
            return(locationString);
        }
        internal static LLLocation LoadArrayElementPointer(LLFunction pFunction, HLLocation pInstance, HLLocation pIndex, HLType pElementType)
        {
            LLLocation locationIndex         = pIndex.Load(pFunction);
            LLLocation locationElementOffset = locationIndex;
            long?      literalElementOffset  = null;

            if (locationIndex is LLLiteralLocation)
            {
                literalElementOffset = Convert.ToInt64(((LLLiteralLocation)locationIndex).Literal.Value) * pElementType.VariableSize;
            }
            else if (pElementType.VariableSize > 1)
            {
                locationElementOffset = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationIndex.Type));
                pFunction.CurrentBlock.EmitMultiply(locationElementOffset, locationIndex, LLLiteralLocation.Create(LLLiteral.Create(locationElementOffset.Type, pElementType.VariableSize.ToString())));
            }

            LLLocation locationArrayPointer = pInstance.Load(pFunction);

            locationArrayPointer = pFunction.CurrentBlock.EmitConversion(locationArrayPointer, LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 1));

            LLLocation locationElementPointer = null;

            if (literalElementOffset.HasValue)
            {
                locationElementOffset  = LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(64), (literalElementOffset.Value + HLDomain.SystemArray.CalculatedSize).ToString()));
                locationElementPointer = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationArrayPointer.Type));
                pFunction.CurrentBlock.EmitGetElementPointer(locationElementPointer, locationArrayPointer, locationElementOffset);
            }
            else
            {
                LLLocation locationTemporary = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationArrayPointer.Type));
                pFunction.CurrentBlock.EmitGetElementPointer(locationTemporary, locationArrayPointer, LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), (HLDomain.SystemArray.CalculatedSize).ToString())));
                locationElementPointer = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationArrayPointer.Type));
                pFunction.CurrentBlock.EmitGetElementPointer(locationElementPointer, locationTemporary, locationElementOffset);
            }
            return(pFunction.CurrentBlock.EmitConversion(locationElementPointer, pElementType.LLType.PointerDepthPlusOne));
        }
Ejemplo n.º 8
0
        private static void BuildRuntimeTypeData(HLStringTable pStringTable)
        {
            List <LLType>    fieldsRuntimeTypeData                   = sSystemRuntimeTypeData.Fields.Where(f => !f.IsStatic).ToList().ConvertAll(f => f.Type.LLType);
            LLType           typePointer                             = LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 1);
            LLType           typeRuntimeTypeData                     = LLModule.GetOrCreateStructureType("RuntimeTypeData", true, fieldsRuntimeTypeData);
            LLType           typeRuntimeTypeDataTable                = LLModule.GetOrCreateArrayType(typeRuntimeTypeData, sTypes.Values.Count);
            LLGlobal         globalRuntimeTypeDataTable              = LLModule.CreateGlobal(typeRuntimeTypeDataTable.PointerDepthPlusOne, "RuntimeTypeDataTable");
            List <LLLiteral> literalsRuntimeTypeDataTable            = new List <LLLiteral>();
            List <LLLiteral> literalsRuntimeTypeDataEnum8ValueTable  = new List <LLLiteral>();
            List <LLLiteral> literalsRuntimeTypeDataEnum16ValueTable = new List <LLLiteral>();
            List <LLLiteral> literalsRuntimeTypeDataEnum32ValueTable = new List <LLLiteral>();
            List <LLLiteral> literalsRuntimeTypeDataEnum64ValueTable = new List <LLLiteral>();
            List <LLLiteral> literalsRuntimeTypeDataEnum8NameTable   = new List <LLLiteral>();
            List <LLLiteral> literalsRuntimeTypeDataEnum16NameTable  = new List <LLLiteral>();
            List <LLLiteral> literalsRuntimeTypeDataEnum32NameTable  = new List <LLLiteral>();
            List <LLLiteral> literalsRuntimeTypeDataEnum64NameTable  = new List <LLLiteral>();
            List <int>       handlesRuntimeTypeDataVirtualTable      = new List <int>();
            List <LLLiteral> literalsRuntimeTypeDataVirtualTable     = new List <LLLiteral>();

            foreach (HLType type in sTypes.Values.OrderBy(t => t.RuntimeTypeHandle))
            {
                int flags = 0;
                if (type.Definition.IsValueType)
                {
                    flags |= 1 << 0;
                }
                if (type.Definition.IsEnum)
                {
                    flags |= 1 << 1;
                }

                string definitionName  = TypeHelper.GetTypeName(type.Definition, NameFormattingOptions.OmitContainingNamespace);
                int    offsetName      = pStringTable.Include(definitionName);
                int    offsetNamespace = 0;
                if (type.Definition is INamespaceTypeDefinition)
                {
                    string definitionNamespace = TypeHelper.GetNamespaceName(((INamespaceTypeDefinition)type.Definition).ContainingUnitNamespace, NameFormattingOptions.None);
                    offsetNamespace = pStringTable.Include(definitionNamespace);
                }

                int offsetEnum = 0;
                int countEnum  = 0;
                if (type.Definition.IsEnum)
                {
                    countEnum = type.StaticFields.Count;
                    switch (type.MemberFields[0].Type.VariableSize)
                    {
                    case 1:
                        offsetEnum = literalsRuntimeTypeDataEnum8ValueTable.Count;
                        for (int index = 0; index < type.StaticFields.Count; ++index)
                        {
                            int offsetEnumName = pStringTable.Include(type.StaticFields[index].Name);
                            literalsRuntimeTypeDataEnum8ValueTable.Add(LLLiteral.Create(LLModule.GetOrCreateUnsignedType(8), type.StaticFields[index].CompileTimeConstant.ToString()));
                            literalsRuntimeTypeDataEnum8NameTable.Add(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), offsetEnumName.ToString()));
                        }
                        break;

                    case 2:
                        offsetEnum = literalsRuntimeTypeDataEnum16ValueTable.Count;
                        for (int index = 0; index < type.StaticFields.Count; ++index)
                        {
                            int offsetEnumName = pStringTable.Include(type.StaticFields[index].Name);
                            literalsRuntimeTypeDataEnum16ValueTable.Add(LLLiteral.Create(LLModule.GetOrCreateUnsignedType(16), type.StaticFields[index].CompileTimeConstant.ToString()));
                            literalsRuntimeTypeDataEnum16NameTable.Add(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), offsetEnumName.ToString()));
                        }
                        break;

                    case 4:
                        offsetEnum = literalsRuntimeTypeDataEnum32ValueTable.Count;
                        for (int index = 0; index < type.StaticFields.Count; ++index)
                        {
                            int offsetEnumName = pStringTable.Include(type.StaticFields[index].Name);
                            literalsRuntimeTypeDataEnum32ValueTable.Add(LLLiteral.Create(LLModule.GetOrCreateUnsignedType(32), type.StaticFields[index].CompileTimeConstant.ToString()));
                            literalsRuntimeTypeDataEnum32NameTable.Add(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), offsetEnumName.ToString()));
                        }
                        break;

                    case 8:
                        offsetEnum = literalsRuntimeTypeDataEnum64ValueTable.Count;
                        for (int index = 0; index < type.StaticFields.Count; ++index)
                        {
                            int offsetEnumName = pStringTable.Include(type.StaticFields[index].Name);
                            literalsRuntimeTypeDataEnum64ValueTable.Add(LLLiteral.Create(LLModule.GetOrCreateUnsignedType(64), type.StaticFields[index].CompileTimeConstant.ToString()));
                            literalsRuntimeTypeDataEnum64NameTable.Add(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), offsetEnumName.ToString()));
                        }
                        break;

                    default: throw new NotSupportedException();
                    }
                }

                literalsRuntimeTypeDataTable.Add(typeRuntimeTypeData.ToLiteral(type.RuntimeTypeHandle.ToString(),
                                                                               flags.ToString(),
                                                                               type.CalculatedSize.ToString(),
                                                                               offsetName.ToString(),
                                                                               offsetNamespace.ToString(),
                                                                               handlesRuntimeTypeDataVirtualTable.Count.ToString(),
                                                                               offsetEnum.ToString(),
                                                                               countEnum.ToString()));

                //List<LLFunction> functions = type.VirtualTable.ConvertAll(m => m.LLFunction);
                foreach (HLMethod method in type.VirtualTable)
                {
                    handlesRuntimeTypeDataVirtualTable.Add(method.RuntimeMethodHandle);
                    literalsRuntimeTypeDataVirtualTable.Add(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), method.RuntimeMethodHandle.ToString()));
                }
                //foreach (LLFunction function in functions)
                //{
                //    handlesRuntimeTypeDataVirtualTable.Add(function);
                //    string literalAddress = null;
                //    if (function.Abstract) literalAddress = "null";
                //    else literalAddress = string.Format("bitcast({0} {1} to {2})", LLModule.GetOrCreatePointerType(function.FunctionType, 1), function, typePointer);
                //    literalsRuntimeTypeDataVirtualTable.Add(LLLiteral.Create(typePointer, literalAddress));
                //}
            }
            globalRuntimeTypeDataTable.InitialValue = typeRuntimeTypeDataTable.ToLiteral(literalsRuntimeTypeDataTable.ConvertAll(l => l.Value).ToArray());
            LLGlobal globalRuntimeTypeDataTableCount = LLModule.CreateGlobal(LLModule.GetOrCreateSignedType(32), "RuntimeTypeDataTableCount");

            globalRuntimeTypeDataTableCount.InitialValue = LLLiteral.Create(LLModule.GetOrCreateSignedType(32), sTypes.Values.Count.ToString());

            LLType   typeRuntimeTypeDataEnum8ValueTable   = LLModule.GetOrCreateArrayType(LLModule.GetOrCreateUnsignedType(8), literalsRuntimeTypeDataEnum8ValueTable.Count);
            LLGlobal globalRuntimeTypeDataEnum8ValueTable = LLModule.CreateGlobal(typeRuntimeTypeDataEnum8ValueTable.PointerDepthPlusOne, "RuntimeTypeDataEnum8ValueTable");

            globalRuntimeTypeDataEnum8ValueTable.InitialValue = typeRuntimeTypeDataEnum8ValueTable.ToLiteral(literalsRuntimeTypeDataEnum8ValueTable.ConvertAll(l => l.Value).ToArray());

            LLType   typeRuntimeTypeDataEnum8NameTable   = LLModule.GetOrCreateArrayType(LLModule.GetOrCreateSignedType(32), literalsRuntimeTypeDataEnum8NameTable.Count);
            LLGlobal globalRuntimeTypeDataEnum8NameTable = LLModule.CreateGlobal(typeRuntimeTypeDataEnum8NameTable.PointerDepthPlusOne, "RuntimeTypeDataEnum8NameTable");

            globalRuntimeTypeDataEnum8NameTable.InitialValue = typeRuntimeTypeDataEnum8NameTable.ToLiteral(literalsRuntimeTypeDataEnum8NameTable.ConvertAll(l => l.Value).ToArray());

            LLType   typeRuntimeTypeDataEnum16ValueTable   = LLModule.GetOrCreateArrayType(LLModule.GetOrCreateUnsignedType(16), literalsRuntimeTypeDataEnum16ValueTable.Count);
            LLGlobal globalRuntimeTypeDataEnum16ValueTable = LLModule.CreateGlobal(typeRuntimeTypeDataEnum16ValueTable.PointerDepthPlusOne, "RuntimeTypeDataEnum16ValueTable");

            globalRuntimeTypeDataEnum16ValueTable.InitialValue = typeRuntimeTypeDataEnum16ValueTable.ToLiteral(literalsRuntimeTypeDataEnum16ValueTable.ConvertAll(l => l.Value).ToArray());

            LLType   typeRuntimeTypeDataEnum16NameTable   = LLModule.GetOrCreateArrayType(LLModule.GetOrCreateSignedType(32), literalsRuntimeTypeDataEnum16NameTable.Count);
            LLGlobal globalRuntimeTypeDataEnum16NameTable = LLModule.CreateGlobal(typeRuntimeTypeDataEnum16NameTable.PointerDepthPlusOne, "RuntimeTypeDataEnum16NameTable");

            globalRuntimeTypeDataEnum16NameTable.InitialValue = typeRuntimeTypeDataEnum16NameTable.ToLiteral(literalsRuntimeTypeDataEnum16NameTable.ConvertAll(l => l.Value).ToArray());

            LLType   typeRuntimeTypeDataEnum32ValueTable   = LLModule.GetOrCreateArrayType(LLModule.GetOrCreateUnsignedType(32), literalsRuntimeTypeDataEnum32ValueTable.Count);
            LLGlobal globalRuntimeTypeDataEnum32ValueTable = LLModule.CreateGlobal(typeRuntimeTypeDataEnum32ValueTable.PointerDepthPlusOne, "RuntimeTypeDataEnum32ValueTable");

            globalRuntimeTypeDataEnum32ValueTable.InitialValue = typeRuntimeTypeDataEnum32ValueTable.ToLiteral(literalsRuntimeTypeDataEnum32ValueTable.ConvertAll(l => l.Value).ToArray());

            LLType   typeRuntimeTypeDataEnum32NameTable   = LLModule.GetOrCreateArrayType(LLModule.GetOrCreateSignedType(32), literalsRuntimeTypeDataEnum32NameTable.Count);
            LLGlobal globalRuntimeTypeDataEnum32NameTable = LLModule.CreateGlobal(typeRuntimeTypeDataEnum32NameTable.PointerDepthPlusOne, "RuntimeTypeDataEnum32NameTable");

            globalRuntimeTypeDataEnum32NameTable.InitialValue = typeRuntimeTypeDataEnum32NameTable.ToLiteral(literalsRuntimeTypeDataEnum32NameTable.ConvertAll(l => l.Value).ToArray());

            LLType   typeRuntimeTypeDataEnum64ValueTable   = LLModule.GetOrCreateArrayType(LLModule.GetOrCreateUnsignedType(64), literalsRuntimeTypeDataEnum64ValueTable.Count);
            LLGlobal globalRuntimeTypeDataEnum64ValueTable = LLModule.CreateGlobal(typeRuntimeTypeDataEnum64ValueTable.PointerDepthPlusOne, "RuntimeTypeDataEnum64ValueTable");

            globalRuntimeTypeDataEnum64ValueTable.InitialValue = typeRuntimeTypeDataEnum64ValueTable.ToLiteral(literalsRuntimeTypeDataEnum64ValueTable.ConvertAll(l => l.Value).ToArray());

            LLType   typeRuntimeTypeDataEnum64NameTable   = LLModule.GetOrCreateArrayType(LLModule.GetOrCreateSignedType(32), literalsRuntimeTypeDataEnum64NameTable.Count);
            LLGlobal globalRuntimeTypeDataEnum64NameTable = LLModule.CreateGlobal(typeRuntimeTypeDataEnum64NameTable.PointerDepthPlusOne, "RuntimeTypeDataEnum64NameTable");

            globalRuntimeTypeDataEnum64NameTable.InitialValue = typeRuntimeTypeDataEnum64NameTable.ToLiteral(literalsRuntimeTypeDataEnum64NameTable.ConvertAll(l => l.Value).ToArray());

            LLType   typeRuntimeTypeDataVirtualTable   = LLModule.GetOrCreateArrayType(LLModule.GetOrCreateSignedType(32), handlesRuntimeTypeDataVirtualTable.Count);
            LLGlobal globalRuntimeTypeDataVirtualTable = LLModule.CreateGlobal(typeRuntimeTypeDataVirtualTable.PointerDepthPlusOne, "RuntimeTypeDataVirtualTable");

            globalRuntimeTypeDataVirtualTable.InitialValue = typeRuntimeTypeDataVirtualTable.ToLiteral(literalsRuntimeTypeDataVirtualTable.ConvertAll(l => l.Value).ToArray());
            LLGlobal globalRuntimeTypeDataVirtualTableCount = LLModule.CreateGlobal(LLModule.GetOrCreateSignedType(32), "RuntimeTypeDataVirtualTableCount");

            globalRuntimeTypeDataVirtualTableCount.InitialValue = LLLiteral.Create(LLModule.GetOrCreateSignedType(32), handlesRuntimeTypeDataVirtualTable.Count.ToString());
        }
Ejemplo n.º 9
0
        internal override void Transform(LLFunction pFunction)
        {
            List <LLLocation> parameters = new List <LLLocation>();
            LLLocation        locationDelegateReference = mDestinationSource.Load(pFunction);

            pFunction.CurrentBlock.EmitStore(locationDelegateReference, LLLiteralLocation.Create(LLLiteral.Create(locationDelegateReference.Type.PointerDepthMinusOne, "zeroinitializer")));

            parameters.Add(locationDelegateReference);
            parameters.Add(LLLiteralLocation.Create(LLLiteral.Create(HLDomain.GCRoot.Parameters[1].Type, "null")));
            pFunction.CurrentBlock.EmitCall(null, LLFunctionLocation.Create(HLDomain.GCRoot), parameters);

            LLLocation locationTotalSize = LLLiteralLocation.Create(LLLiteral.Create(HLDomain.GCAllocate.Parameters[1].Type, mNewDelegateType.CalculatedSize.ToString()));

            LLLocation locationHandle = LLLiteralLocation.Create(LLLiteral.Create(HLDomain.GCAllocate.Parameters[2].Type, mNewDelegateType.RuntimeTypeHandle.ToString()));

            parameters.Clear();
            parameters.Add(locationDelegateReference);
            parameters.Add(locationTotalSize);
            parameters.Add(locationHandle);
            pFunction.CurrentBlock.EmitCall(null, LLFunctionLocation.Create(HLDomain.GCAllocate), parameters);

            LLLocation locationDelegate = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationDelegateReference.Type.PointerDepthMinusOne));

            pFunction.CurrentBlock.EmitLoad(locationDelegate, locationDelegateReference);

            LLLocation locationTargetObj = null;

            if (mInstanceSource != null)
            {
                LLLocation locationTargetObjPointer = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationDelegate.Type));
                pFunction.CurrentBlock.EmitGetElementPointer(locationTargetObjPointer, locationDelegate, LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), mNewDelegateType.Fields["mTargetObj"].Offset.ToString())));
                locationTargetObjPointer = pFunction.CurrentBlock.EmitConversion(locationTargetObjPointer, mInstanceSource.Type.LLType.PointerDepthPlusOne);
                locationTargetObj        = mInstanceSource.Load(pFunction);
                pFunction.CurrentBlock.EmitStore(locationTargetObjPointer, locationTargetObj);
            }

            LLLocation locationTargetMethodPointer = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationDelegate.Type));

            pFunction.CurrentBlock.EmitGetElementPointer(locationTargetMethodPointer, locationDelegate, LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), mNewDelegateType.Fields["mTargetMethod"].Offset.ToString())));
            locationTargetMethodPointer = pFunction.CurrentBlock.EmitConversion(locationTargetMethodPointer, LLModule.GetOrCreatePointerType(LLModule.GetOrCreateSignedType(32), 1));
            LLLocation locationTargetMethod = null;

            if (!mVirtual)
            {
                locationTargetMethod = LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), mMethodCalled.RuntimeMethodHandle.ToString()));
            }
            else
            {
                LLType typeFunction = LLModule.GetOrCreateFunctionType(mMethodCalled.ReturnType == null ? null : mMethodCalled.ReturnType.LLType, mMethodCalled.Parameters.ConvertAll(p => p.Type.LLType));
                int    virtualIndex = mMethodCalled.Container.VirtualLookup[mMethodCalled];

                parameters.Clear();
                parameters.Add(locationTargetObj);
                parameters.Add(LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), virtualIndex.ToString())));
                for (int index = 0; index < parameters.Count; ++index)
                {
                    parameters[index] = pFunction.CurrentBlock.EmitConversion(parameters[index], HLDomain.VTableHandleLookup.Parameters[index].Type);
                }
                locationTargetMethod = LLTemporaryLocation.Create(pFunction.CreateTemporary(HLDomain.VTableHandleLookup.ReturnType));
                pFunction.CurrentBlock.EmitCall(locationTargetMethod, LLFunctionLocation.Create(HLDomain.VTableHandleLookup), parameters);
                locationTargetMethod = pFunction.CurrentBlock.EmitConversion(locationTargetMethod, LLModule.GetOrCreateSignedType(32));
            }
            pFunction.CurrentBlock.EmitStore(locationTargetMethodPointer, locationTargetMethod);
        }
Ejemplo n.º 10
0
        internal override LLLocation Load(LLFunction pFunction)
        {
            LLLocation locationArrayPointer = Instance.Load(pFunction);

            locationArrayPointer = pFunction.CurrentBlock.EmitConversion(locationArrayPointer, LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 1));
            LLLocation locationArraySizePointer = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationArrayPointer.Type));

            pFunction.CurrentBlock.EmitGetElementPointer(locationArraySizePointer, locationArrayPointer, LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), HLDomain.SystemArray.Fields["mLength"].Offset.ToString())));
            locationArraySizePointer = pFunction.CurrentBlock.EmitConversion(locationArraySizePointer, LLModule.GetOrCreatePointerType(LLModule.GetOrCreateSignedType(32), 1));
            LLLocation locationTemporary = LLTemporaryLocation.Create(pFunction.CreateTemporary(LLModule.GetOrCreateSignedType(32)));

            pFunction.CurrentBlock.EmitLoad(locationTemporary, locationArraySizePointer);
            return(pFunction.CurrentBlock.EmitConversion(locationTemporary, Type.LLType));
        }
Ejemplo n.º 11
0
        internal override void Transform(LLFunction pFunction)
        {
            List <LLLocation> parameters              = new List <LLLocation>();
            LLLocation        locationReturn          = null;
            LLLocation        locationFunction        = null;
            LLLocation        locationAlternativeThis = null;

            if (!mVirtual)
            {
                locationFunction = LLFunctionLocation.Create(mCalledMethod.LLFunction);
            }
            else if (mCalledMethod.Container.Definition.IsDelegate && mCalledMethod.Name == "Invoke")
            {
                parameters.Add(mParameterSources[0].Load(pFunction));

                locationFunction = LLTemporaryLocation.Create(pFunction.CreateTemporary(HLDomain.DelegateLookup.ReturnType));
                pFunction.CurrentBlock.EmitCall(locationFunction, LLFunctionLocation.Create(HLDomain.DelegateLookup), parameters);

                LLType typeFunction = LLModule.GetOrCreateFunctionType(mCalledMethod.ReturnType == null ? null : mCalledMethod.ReturnType.LLType, mParameterSources.ConvertAll(l => l.Type.LLType));
                locationFunction = pFunction.CurrentBlock.EmitConversion(locationFunction, LLModule.GetOrCreatePointerType(typeFunction, 1));

                locationAlternativeThis = LLTemporaryLocation.Create(pFunction.CreateTemporary(HLDomain.DelegateInstance.ReturnType));
                pFunction.CurrentBlock.EmitCall(locationAlternativeThis, LLFunctionLocation.Create(HLDomain.DelegateInstance), parameters);
            }
            else
            {
                LLType typeFunction = LLModule.GetOrCreateFunctionType(mCalledMethod.ReturnType == null ? null : mCalledMethod.ReturnType.LLType, mParameterSources.ConvertAll(l => l.Type.LLType));
                int    virtualIndex = mCalledMethod.Container.VirtualLookup[mCalledMethod];
                parameters.Add(mParameterSources[0].Load(pFunction));
                parameters.Add(LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), virtualIndex.ToString())));
                for (int index = 0; index < parameters.Count; ++index)
                {
                    parameters[index] = pFunction.CurrentBlock.EmitConversion(parameters[index], HLDomain.VTableFunctionLookup.Parameters[index].Type);
                }
                locationReturn = LLTemporaryLocation.Create(pFunction.CreateTemporary(HLDomain.VTableFunctionLookup.ReturnType));
                pFunction.CurrentBlock.EmitCall(locationReturn, LLFunctionLocation.Create(HLDomain.VTableFunctionLookup), parameters);
                locationFunction = pFunction.CurrentBlock.EmitConversion(locationReturn, typeFunction.PointerDepthPlusOne);
            }

            parameters.Clear();
            if (locationAlternativeThis == null)
            {
                mParameterSources.ForEach(l => parameters.Add(l.Load(pFunction)));
            }
            else
            {
                parameters.Add(locationAlternativeThis);
                for (int index = 1; index < mParameterSources.Count; ++index)
                {
                    parameters.Add(mParameterSources[index].Load(pFunction));
                }
            }

            for (int index = 0; index < parameters.Count; ++index)
            {
                parameters[index] = pFunction.CurrentBlock.EmitConversion(parameters[index], mCalledMethod.LLFunction.Parameters[index].Type);
            }

            locationReturn = null;
            if (mReturnDestination != null)
            {
                locationReturn = LLTemporaryLocation.Create(pFunction.CreateTemporary(mReturnDestination.Type.LLType));
            }

            pFunction.CurrentBlock.EmitCall(locationReturn, locationFunction, parameters);
            if (mReturnDestination != null)
            {
                mReturnDestination.Store(pFunction, locationReturn);
            }
        }
Ejemplo n.º 12
0
        internal override void Transform(LLFunction pFunction)
        {
            List <LLLocation> parameters             = new List <LLLocation>();
            LLLocation        locationArrayReference = mDestinationSource.Load(pFunction);

            pFunction.CurrentBlock.EmitStore(locationArrayReference, LLLiteralLocation.Create(LLLiteral.Create(locationArrayReference.Type.PointerDepthMinusOne, "zeroinitializer")));

            parameters.Add(locationArrayReference);
            parameters.Add(LLLiteralLocation.Create(LLLiteral.Create(HLDomain.GCRoot.Parameters[1].Type, "null")));
            pFunction.CurrentBlock.EmitCall(null, LLFunctionLocation.Create(HLDomain.GCRoot), parameters);

            LLLocation locationSize         = mSizeSource.Load(pFunction);
            LLLocation locationElementsSize = locationSize;

            if (mElementType.VariableSize > 1)
            {
                locationElementsSize = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationSize.Type));
                pFunction.CurrentBlock.EmitMultiply(locationElementsSize, locationSize, LLLiteralLocation.Create(LLLiteral.Create(locationSize.Type, mElementType.VariableSize.ToString())));
            }
            LLLocation locationTotalSize = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationSize.Type));

            pFunction.CurrentBlock.EmitAdd(locationTotalSize, locationElementsSize, LLLiteralLocation.Create(LLLiteral.Create(locationSize.Type, (HLDomain.SystemArray.CalculatedSize).ToString())));
            locationTotalSize = pFunction.CurrentBlock.EmitConversion(locationTotalSize, HLDomain.GCAllocate.Parameters[1].Type);

            LLLocation locationHandle = LLLiteralLocation.Create(LLLiteral.Create(HLDomain.GCAllocate.Parameters[2].Type, mArrayType.RuntimeTypeHandle.ToString()));

            parameters.Clear();
            parameters.Add(locationArrayReference);
            parameters.Add(locationTotalSize);
            parameters.Add(locationHandle);
            pFunction.CurrentBlock.EmitCall(null, LLFunctionLocation.Create(HLDomain.GCAllocate), parameters);

            LLLocation locationArrayPointer = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationArrayReference.Type.PointerDepthMinusOne));

            pFunction.CurrentBlock.EmitLoad(locationArrayPointer, locationArrayReference);
            locationArrayPointer = pFunction.CurrentBlock.EmitConversion(locationArrayPointer, LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 1));

            LLLocation locationArraySizePointer = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationArrayPointer.Type));

            pFunction.CurrentBlock.EmitGetElementPointer(locationArraySizePointer, locationArrayPointer, LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), HLDomain.SystemObject.CalculatedSize.ToString())));
            locationArraySizePointer = pFunction.CurrentBlock.EmitConversion(locationArraySizePointer, locationSize.Type.PointerDepthPlusOne);
            pFunction.CurrentBlock.EmitStore(locationArraySizePointer, locationSize);
        }
Ejemplo n.º 13
0
        internal override void Transform(LLFunction pFunction)
        {
            LLLocation locationSource = mSource.Load(pFunction);

            if (mSource.Type.Definition.IsValueType && mDestination.Type == HLDomain.SystemObject)
            {
                // Boxing
                List <LLLocation> parameters = new List <LLLocation>();
                LLLocation        locationObjectReference = LLTemporaryLocation.Create(pFunction.CreateTemporary(HLDomain.SystemObject.LLType.PointerDepthPlusOne));
                pFunction.CurrentBlock.EmitAllocate(locationObjectReference);
                pFunction.CurrentBlock.EmitStore(locationObjectReference, LLLiteralLocation.Create(LLLiteral.Create(locationObjectReference.Type.PointerDepthMinusOne, "zeroinitializer")));

                parameters.Add(locationObjectReference);
                parameters.Add(LLLiteralLocation.Create(LLLiteral.Create(HLDomain.GCRoot.Parameters[1].Type, "null")));
                pFunction.CurrentBlock.EmitCall(null, LLFunctionLocation.Create(HLDomain.GCRoot), parameters);

                LLLocation locationTotalSize = LLLiteralLocation.Create(LLLiteral.Create(HLDomain.GCAllocate.Parameters[1].Type, (HLDomain.SystemObject.CalculatedSize + mSource.Type.CalculatedSize).ToString()));
                LLLocation locationHandle    = LLLiteralLocation.Create(LLLiteral.Create(HLDomain.GCAllocate.Parameters[2].Type, mSource.Type.RuntimeTypeHandle.ToString()));

                parameters.Clear();
                parameters.Add(locationObjectReference);
                parameters.Add(locationTotalSize);
                parameters.Add(locationHandle);
                pFunction.CurrentBlock.EmitCall(null, LLFunctionLocation.Create(HLDomain.GCAllocate), parameters);

                LLLocation locationObject = LLTemporaryLocation.Create(pFunction.CreateTemporary(HLDomain.SystemObject.LLType));
                pFunction.CurrentBlock.EmitLoad(locationObject, locationObjectReference);

                LLLocation locationObjectValue = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationObject.Type));
                pFunction.CurrentBlock.EmitGetElementPointer(locationObjectValue, locationObject, LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), HLDomain.SystemObject.CalculatedSize.ToString())));
                locationObjectValue = pFunction.CurrentBlock.EmitConversion(locationObjectValue, mSource.Type.LLType.PointerDepthPlusOne);

                pFunction.CurrentBlock.EmitStore(locationObjectValue, locationSource);
                locationSource = locationObject;
            }
            else if (mSource.Type == HLDomain.SystemObject && mDestination.Type.Definition.IsValueType)
            {
                // Unboxing

                // TODO: Branch on destination type handle not matching object handle, and throw exception
                LLLocation locationObjectValue = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationSource.Type));
                pFunction.CurrentBlock.EmitGetElementPointer(locationObjectValue, locationSource, LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), HLDomain.SystemObject.CalculatedSize.ToString())));
                locationObjectValue = pFunction.CurrentBlock.EmitConversion(locationObjectValue, mDestination.Type.LLType.PointerDepthPlusOne);

                LLLocation locationValue = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationObjectValue.Type.PointerDepthMinusOne));
                pFunction.CurrentBlock.EmitLoad(locationValue, locationObjectValue);
                locationSource = locationValue;
            }
            mDestination.Store(pFunction, locationSource);
        }