Example #1
0
        void BuildStub()
        {
            var entryType = LLVM.FunctionType(
                ReturnType: LLVM.Int32Type(),
                ParamTypes: new LLVMTypeRef [0],
                IsVarArg: false
                );
            var entryFunc = LLVM.AddFunction(LLVMModule, "__lore_entrypoint__", entryType);

            LLVM.SetLinkage(entryFunc, LLVMLinkage.LLVMExternalLinkage);
            PrototypeCompiler.Analyze(this, Root);
            var entryBlock = LLVM.AppendBasicBlock(entryFunc, "entry");

            LLVM.PositionBuilderAtEnd(Builder, entryBlock);
            var mainFunc = LLVM.GetNamedFunction(LLVMModule, "main");

            if (mainFunc.Pointer == IntPtr.Zero)
            {
                Console.WriteLine("No main function found!");
                LLVM.BuildRet(Builder, LLVM.ConstInt(LLVM.Int32Type(), 0, LLVMFalse));
            }
            else
            {
                Console.WriteLine("Main function found!");
                var callResult = LLVM.BuildCall(Builder, mainFunc, new LLVMValueRef [0], "callmain");
                if (Helper.CompareType(callResult, LLVM.Int32Type()))
                {
                    LLVM.BuildRet(Builder, callResult);
                }
                else
                {
                    LLVM.BuildRet(Builder, LLVM.ConstInt(LLVM.Int32Type(), 0, LLVMFalse));
                }
            }
        }
Example #2
0
        /// <summary>
        /// Analyze the specified compiler and root.
        /// </summary>
        /// <param name="compiler">Compiler.</param>
        /// <param name="root">Root.</param>
        public static void Analyze(LoreLLVMCompiler compiler, AstRoot root)
        {
            var visitor = new PrototypeCompiler(compiler);

            visitor.Analyze(root);
        }