Esempio n. 1
0
        public void ExitHandleExtern(Expr.Prototype data)
        {
            var value = this._visitor.Visit(data);

            if (value == null)
            {
                return;
            }
            this._visitor.FunctionProtos[data.Name] = data;
        }
Esempio n. 2
0
        /// toplevelexpr ::= expression
        private Expr.Function ParseTopLevelExpr()
        {
            //Console.WriteLine($"ParseTopLevelExpr: {this._scanner.CurrentToken}");
            var e = this.ParseExpression();

            if (e == null)
            {
                return(null);
            }

            // Make an anonymous proto.
            var proto = new Expr.Prototype("__anon_expr", new string[0], false, 0);

            return(new Expr.Function(proto, e));
        }
Esempio n. 3
0
        private IrFunction GetOrDeclareFunction(Expr.Prototype prototype)
        {
            var function = this.Module.GetFunction(prototype.Name);

            if (function != null)
            {
                return(function);
            }

            var llvmSignature = this._ctx.GetFunctionType(this._ctx.DoubleType, prototype.Arguments.Select(_ => this._ctx.DoubleType));
            var retVal        = this.Module.AddFunction(prototype.Name, llvmSignature);

            retVal.Linkage = Linkage.External;

            int index = 0;

            foreach (var argId in prototype.Arguments)
            {
                retVal.Parameters[index].Name = argId;
                ++index;
            }

            return(retVal);
        }
Esempio n. 4
0
 public Value Visit(Expr.Prototype stmt)
 {
     return(this.GetOrDeclareFunction(stmt));
 }
Esempio n. 5
0
 public void EnterHandleExtern(Expr.Prototype data)
 {
 }
Esempio n. 6
0
 public void ExitHandleExtern(Expr.Prototype data)
 {
     //Console.WriteLine($"ExitHandleExtern {data.Name}");
     this._visitor.NextIsExtern = true;
     this._visitor.Visit(data);
 }