Example #1
0
 public void Initialize()
 {
     this.codeGenerator = new LLVMCodeGenerator(this);
     ParentMethod       = GetParentMethod(this);
     if (ParentMethod == this &&
         this.GetIsVirtual() &&
         !DeclaringType.GetIsInterface())
     {
         ParentType.RelativeVTable.CreateRelativeSlot(this);
     }
 }
Example #2
0
        /// <summary>
        /// Writes this method definitions to the given module.
        /// </summary>
        /// <param name="Module">The module to populate.</param>
        public void Emit(LLVMModuleBuilder Module)
        {
            if (this.GetRecursiveGenericParameters().Any <IType>())
            {
                throw new NotSupportedException("LLVM methods do not support generic parameters");
            }

            if (!DeclaringType.GetIsInterface() &&
                !this.GetIsAbstract())
            {
                var func = Module.Declare(this);
                func.SetLinkage(Linkage);

                var methodBody = this.body;

                if (methodBody == null &&
                    this.HasAttribute(
                        PrimitiveAttributes.Instance.RuntimeImplementedAttribute.AttributeType))
                {
                    // Auto-implement runtime-implemented methods here.
                    methodBody = (CodeBlock)AutoImplement().Emit(codeGenerator);
                }

                if (methodBody != null)
                {
                    // Generate the method body.
                    var bodyBuilder       = new FunctionBodyBuilder(Module, func);
                    var entryPointBuilder = bodyBuilder.AppendBasicBlock("entry");
                    entryPointBuilder = codeGenerator.Prologue.Emit(entryPointBuilder);
                    var codeGen = methodBody.Emit(entryPointBuilder);
                    BuildUnreachable(codeGen.BasicBlock.Builder);
                }
            }

            foreach (var iface in allInterfaceImpls.Value)
            {
                Module.GetInterfaceStub(iface).Implement(ParentType, this);
            }
        }