Ejemplo n.º 1
0
 private LLVMBasicBlockRef WriteReturnBlock(
     LLVMType Type,
     LLVMMethod Implementation,
     LLVMModuleBuilder Module)
 {
     return(WriteReturnBlock(Type.Name.ToString(), Module.DeclareVirtual(Implementation)));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a relative vtable slot for the given method.
        /// </summary>
        /// <param name="Method">The method to create a vtable slot for.</param>
        /// <returns>A vtable slot.</returns>
        public int CreateRelativeSlot(LLVMMethod Method)
        {
            int slot = contents.Count;

            contents.Add(Method);
            slots.Add(Method, slot);
            return(slot);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the absolute vtable slot for the given method.
        /// </summary>
        /// <param name="Method">The method to get the absolute vtable slot for.</param>
        /// <returns>An absolute vtable slot.</returns>
        public int GetAbsoluteSlot(LLVMMethod Method)
        {
            int slot;

            if (!absSlots.TryGetValue(Method, out slot))
            {
                slot             = GetAbsoluteSlot(Method.ParentMethod);
                absSlots[Method] = slot;
            }
            return(slot);
        }
Ejemplo n.º 4
0
        public IMethodBuilder DeclareMethod(IMethodSignatureTemplate Template)
        {
            var methodDef = new LLVMMethod(this, Template);

            declaredMethods.Add(methodDef);
            if (methodDef.IsStatic && methodDef.IsConstructor)
            {
                declaredStaticCtors.Add(methodDef);
            }
            return(methodDef);
        }
Ejemplo n.º 5
0
 public void Initialize()
 {
     this.codeGenerator = new LLVMCodeGenerator(this);
     ParentMethod       = GetParentMethod(this);
     if (ParentMethod == this &&
         this.GetIsVirtual() &&
         !DeclaringType.GetIsInterface())
     {
         ParentType.RelativeVTable.CreateRelativeSlot(this);
     }
 }
Ejemplo n.º 6
0
        private static LLVMMethod GetParentMethod(LLVMMethod Method)
        {
            var result = Method;

            foreach (var baseMethod in Method.BaseMethods)
            {
                if (baseMethod is LLVMMethod && !baseMethod.DeclaringType.GetIsInterface())
                {
                    result = (LLVMMethod)baseMethod;
                    break;
                }
            }
            return(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the interface stub for the given method.
        /// </summary>
        /// <param name="Method">The method to get the interface stub of.</param>
        /// <returns>An interface stub.</returns>
        public InterfaceStub GetInterfaceStub(LLVMMethod Method)
        {
            InterfaceStub stub;

            if (!interfaceStubs.TryGetValue(Method, out stub))
            {
                var retType    = PointerType(DeclarePrototype(Method), 0);
                var paramTypes = new LLVMTypeRef[] { Int64Type() };
                var stubFunc   = AddFunction(
                    module,
                    Method.Abi.Mangler.Mangle(Method, true) + "_stub",
                    FunctionType(retType, paramTypes, false));
                stubFunc.SetLinkage(LLVMLinkage.LLVMInternalLinkage);

                stub = new InterfaceStub(stubFunc);
                interfaceStubs[Method] = stub;
            }
            return(stub);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Gets the relative vtable slot for the given method.
 /// </summary>
 /// <param name="Method">The method to get a vtable slot for.</param>
 /// <returns>A vtable slot.</returns>
 public int GetRelativeSlot(LLVMMethod Method)
 {
     return(slots[Method]);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Registers the given method as the implementation for the given type.
 /// </summary>
 /// <param name="Type">The type that implements the method.</param>
 /// <param name="Method">The implementation method.</param>
 public void Implement(LLVMType Type, LLVMMethod Method)
 {
     impls.Add(Type, Method);
 }