public virtual Expr BVSUB(Expr lhs, Expr rhs)
 {
     return(UB.BVSUB(lhs, rhs));
 }
Example #2
0
        protected Expr HandleBvBuiltIns(FunctionCall fc, string builtin, List <Expr> newArgs)
        {
            Debug.Assert(builtin.Length > 0);

            // We grab for first word because the bvbuiltin
            // might be "zeroextend 16", we don't care about the number
            string firstWord = builtin.Split(' ')[0];

            Debug.Assert(firstWord.Length > 0);

            // Handle `(_ zero_extend x)` and `(_ sign_extend x)` style builtins
            if (firstWord.StartsWith("(_"))
            {
                var words = builtin.Split(' ');
                if (words.Length < 2)
                {
                    throw new ArgumentException("Malformed bvbuiltin name \"" + builtin + "\"");
                }
                firstWord = words[1];
            }

            int retWidth = 0;

            switch (firstWord)
            {
            // arithmetic
            case "bvadd":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVADD(newArgs[0], newArgs[1]));

            case "bvsub":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVSUB(newArgs[0], newArgs[1]));

            case "bvmul":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVMUL(newArgs[0], newArgs[1]));

            case "bvudiv":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVUDIV(newArgs[0], newArgs[1]));

            case "bvurem":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVUREM(newArgs[0], newArgs[1]));

            case "bvsdiv":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVSDIV(newArgs[0], newArgs[1]));

            case "bvsrem":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVSREM(newArgs[0], newArgs[1]));

            case "bvsmod":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVSMOD(newArgs[0], newArgs[1]));

            case "sign_extend":
                Debug.Assert(newArgs.Count == 1);
                Debug.Assert(fc.Func.OutParams.Count == 1);
                retWidth = fc.Func.OutParams[0].TypedIdent.Type.BvBits;
                return(Builder.BVSEXT(newArgs[0], retWidth));

            case "zero_extend":
                Debug.Assert(newArgs.Count == 1);
                Debug.Assert(fc.Func.OutParams.Count == 1);
                retWidth = fc.Func.OutParams[0].TypedIdent.Type.BvBits;
                return(Builder.BVZEXT(newArgs[0], retWidth));

            case "bvneg":
                Debug.Assert(newArgs.Count == 1);
                return(Builder.BVNEG(newArgs[0]));

            // bitwise logical
            case "bvand":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVAND(newArgs[0], newArgs[1]));

            case "bvor":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVOR(newArgs[0], newArgs[1]));

            case "bvnot":
                Debug.Assert(newArgs.Count == 1);
                return(Builder.BVNOT(newArgs[0]));

            case "bvxor":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVXOR(newArgs[0], newArgs[1]));

            // shift
            case "bvshl":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVSHL(newArgs[0], newArgs[1]));

            case "bvlshr":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVLSHR(newArgs[0], newArgs[1]));

            case "bvashr":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVASHR(newArgs[0], newArgs[1]));

            // Comparison
            case "bvult":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVULT(newArgs[0], newArgs[1]));

            case "bvule":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVULE(newArgs[0], newArgs[1]));

            case "bvugt":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVUGT(newArgs[0], newArgs[1]));

            case "bvuge":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVUGE(newArgs[0], newArgs[1]));

            case "bvslt":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVSLT(newArgs[0], newArgs[1]));

            case "bvsle":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVSLE(newArgs[0], newArgs[1]));

            case "bvsgt":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVSGT(newArgs[0], newArgs[1]));

            case "bvsge":
                Debug.Assert(newArgs.Count == 2);
                return(Builder.BVSGE(newArgs[0], newArgs[1]));

            default:
                throw new NotImplementedException("\"" + firstWord + "\" bvbuiltin not supported!");
            }
        }