Ejemplo n.º 1
0
        public void SimpleFunctionType_ParseCheck() {
            var returnVal = new LValueRef(LType.F32Type(), "");
            var parameter = new LPointerRef(new LValueRef(LType.F32Type(), ""), "");
            LFunctionType fnType = new LFunctionType(returnVal, parameter);

            Assert.AreEqual("float (float*)", fnType.Parse());
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initialize with function metadata
 /// </summary>
 /// <param name="meta"></param>
 public SymbolFunction(FunctionMetaData meta)
 {
     Name     = meta.Name;
     Meta     = meta;
     Category = SymbolCategory.Func;
     DataType = new LFunctionType(meta.Name);
 }
Ejemplo n.º 3
0
        public void SimpleFunctionType_ArrayAsReturnVal_Expected_Exception() {
            var returnVal = new LArrayRef("", new LValueRef(LType.F32Type(), ""), 5);
            LFunctionType fnType;

            Assert.Throws<Exception>(() =>
                fnType = new LFunctionType(returnVal)
            );
        }
Ejemplo n.º 4
0
        public void VarargFunctionType_ParseCheck() {
            var returnVal = new LValueRef(LType.F32Type(), "");
            var parameter = new LPointerRef(new LValueRef(LType.F32Type(), ""), "");
            LFunctionType fnType = new LFunctionType(returnVal, parameter) {
                HasVararg = true
            };

            Assert.AreEqual("float (float*, ...)", fnType.Parse());
        }
Ejemplo n.º 5
0
        public object VisitLambda(LambdaExpr expr)
        {
            var funcType = new LFunctionType();

            funcType.Name     = expr.Expr.Meta.Name;
            funcType.FullName = funcType.Name;
            var func = new LFunction(expr.Expr);

            func.Type = funcType;
            return(func);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            string valueIdentifier = "@value";
            string value           = "c\"Hello World!\\00\"";

            var module = new LModule("LLVMHelloWorld");
            var func   = LFunction.Create("@main", new LValueRef(LType.Int32Type(), ""));

            var arrayRef = new LArrayRef(valueIdentifier, new LValueRef(LType.Int8Type(), ""), 13);
            // Create char array constant.
            var global = new LGlobal(arrayRef, value)
            {
                IsConstant = true
            };

            var fnType = new LFunctionType(new LValueRef(LType.Int32Type(), "%printf"), new LPointerRef(new LValueRef(LType.Int8Type(), ""), "%result"))
            {
                HasVararg = true
            };
            var external = new LExternal(fnType, "@printf");

            var result = new LPointerRef(new LValueRef(LType.Int8Type(), ""), "%result");
            var gep    = new LGetelementptr(result, global.GetPointerRef());

            gep.Indexes.Add((LType.Int32Type(), 0));
            gep.Indexes.Add((LType.Int32Type(), 0));

            var call = new LCall(fnType, external.FnIdentifier);

            var ret = new LRet(new LValueRef(LType.Int32Type(), "0"));

            // Create and register entry label
            func.Register(new LLabelType("entry"));
            // Register function and char array constant to module.
            module.Register(global);
            module.Register(func);
            module.Register(external);
            // Register instructions.
            func.Register(gep);
            func.Register(call);
            func.Register(ret);

            Console.WriteLine(module.Parse());
        }
Ejemplo n.º 7
0
 public LExternal(LFunctionType fnType, string fnIdentifier)
 {
     FnType       = fnType;
     FnIdentifier = fnIdentifier;
 }