Ejemplo n.º 1
0
        public static string BinaryToLLVM(int depth, string keyword, IOperation a, IOperation b, ValueType returnType)
        {
            //int curNumber = MISC.LLVMtmpNumber + 1;
            MISC.LLVMtmpNumber++;
            int    num  = MISC.LLVMtmpNumber;
            string kids = String.Format("{0}, {1}\n", a.ToLLVM(depth), b.ToLLVM(depth)); MISC.LLVMtmpNumber++;
            string add  = String.Format("{3}%tmp{0} = {4} {1} {2}", num, returnType.ToLLVM(), kids, MISC.tabsLLVM(depth), keyword);

            LLVM.CurrentCode += add;
            return("%tmp" + (num));
        }
Ejemplo n.º 2
0
        public static string ParamToLLVM(int depth, string keyword, ValueType returnType, params IOperation[] ops)
        {
            MISC.LLVMtmpNumber++;
            int    num  = MISC.LLVMtmpNumber;
            string kids = "";//first.ToLLVM(depth)+((ops.Length > 0)?", " : "");// = String.Format("{0}, {1}\n", a.ToLLVM(depth), b.ToLLVM(depth));

            for (int i = 0; i < ops.Length; i++, kids += ((i < ops.Length) ? ", " : ""))
            {
                kids += ops[i].returnTypes().ToLLVM() + " " + ops[i].ToLLVM(depth);
            }

            return(String.Format("{2}{0}{3}{5} {4}\n", (keyword.Length > 0)? " " :"", num, keyword, returnType.ToLLVM(), kids, (keyword.Length > 0)? "," :""));
        }
Ejemplo n.º 3
0
        public static string TypeConvertLLVM(int depth, string keyword, IOperation what, ValueType ty2)
        {
            MISC.LLVMtmpNumber++;
            int    num = MISC.LLVMtmpNumber;
            string boy = what.returnTypes().ToLLVM() + " " + what.ToLLVM(depth);

            LLVM.AddToCode(String.Format("{0}%tmp{1} = {2} {3} to {4}\n", MISC.tabsLLVM(depth), num, keyword, boy, ty2.ToLLVM()));
            return("%tmp" + num);
        }
Ejemplo n.º 4
0
        public virtual string ToLLVM(int depth)
        {
            string param      = "";
            int    funcNumber = depth;

            depth = 0;
            for (int i = 0; i < input.Count; i++)
            {
                param += input[i].returnTypes().ToLLVM() + ((!declareOnly) ? " " + MISC.RemoveCall(input[i].var.ToLLVM()) : "") + ((i < input.Count - 1) ? ", " : "");
            }
            if (infiniteParamsAfter >= 0)
            {
                param += ", ...";
            }
            LLVM.AddToCode(String.Format("; {0} {1}\n", getName, getArgsString));
            if (!declareOnly)
            {
                LLVM.AddToCode(String.Format("{0}define {1} @{2}({3}) #{4} ", MISC.tabsLLVM(depth), retType.ToLLVM(), getNameLLVM, param, funcNumber) + "{\n" /*+ MISC.tabsLLVM(depth) + "entry:\n"*/);//  + code + "}";
                // add used global variables
                List <ASTvariable> addVars = new List <ASTvariable>();
                //for (int i = 0; i < input.Count; i++)
                //    addVars.Add(input[i].var);
                // add param variables
                addVars.AddRange(ASTTree.GlobalVarsVars);
                foreach (ASTvariable vari in addVars)
                {
                    vari.reloadedTimes++;
                    LLVM.AddToCode(String.Format("{0}{1} = load {2}, {3} {4}\n", MISC.tabsLLVM(depth + 1), vari.ToLLVM(), vari.returnTypes().ToLLVM(), vari.returnTypes().TypeOfPointerToThis().ToLLVM(),
                                                 (vari.adress.typ == VAT.Global) ? "@" + MISC.RemoveCall(vari.ToLLVM()).Substring(1) : MISC.RemoveCall(vari.ToLLVM())));
                }
                LLVM.AddToCode(actions.ToLLVM(depth + 1));
                return(MISC.tabsLLVM(depth) + "}");
            }
            return(String.Format("{0}declare {1} @{2}({3}) #{4}", MISC.tabsLLVM(depth), retType.ToLLVM(), getNameLLVM, param, funcNumber));
        }