public override CompilerResult VisitFuncDef(DesignScriptParser.FuncDefContext context)
        {
            //var parentBlock = LLVM.GetInsertBlock(builder);

            // TODO: This assumes namedValues only contains identifiers for function args right now.
            namedValues.Clear();

            var typedIdent = context.typedIdent();
            var funcSig    = VisitTypedIdent(typedIdent) as TypedIdentCompilerResult;

            functionName = funcSig.Name;
            returnType   = (LLVMTypeRef)funcSig.Type;

            VisitFuncDefArgList(context.funcDefArgList());

            function = valueStack.Pop();

            // Create a new basic block to start insertion into.
            LLVMBasicBlockRef entry = LLVM.AppendBasicBlock(function, "entry");

            LLVM.PositionBuilderAtEnd(this.builder, entry);

            var stmts = context.coreStmt();

            foreach (var stmt in stmts)
            {
                VisitCoreStmt(stmt);
            }

            // Validate the generated code, checking for consistency.
            LLVM.VerifyFunction(function, LLVMVerifierFailureAction.LLVMPrintMessageAction);

            LLVM.RunFunctionPassManager(this.passManager, function);

            this.valueStack.Push(function);

            //LLVM.PositionBuilderAtEnd(this.builder, parentBlock);

            return(new NullCompilerResult());
        }
Example #2
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="DesignScriptParser.funcDef"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitFuncDef([NotNull] DesignScriptParser.FuncDefContext context)
 {
     return(VisitChildren(context));
 }