Ejemplo n.º 1
0
        private string buildCall(DCall call)
        {
            string args = "";

            for (int i = 0; i < call.numOperands; i++)
            {
                DNode  input = call.getOperand(i);
                string arg   = buildExpression(input);
                args += arg;
                if (i != call.numOperands - 1)
                {
                    args += ", ";
                }
            }

            return(call.function.name + "(" + args + ")");
        }
Ejemplo n.º 2
0
        public override void visit(DCall call)
        {
            // Operators can be overloaded for floats, and we want these to print
            // normally, so here is some gross peephole stuff. Maybe we should be
            // looking for bytecode patterns instead or something, but that would
            // need a whole-program analysis.
            if (call.function.name.Length < 8)
                return;
            if (call.function.name.Substring(0, 8) != "operator")
                return;

            string op = "";
            for (int i = 8; i < call.function.name.Length; i++)
            {
                if (call.function.name[i] == '(')
                    break;
                op += call.function.name[i];
            }

            SPOpcode spop;
            switch (op)
            {
                case ">":
                    spop = SPOpcode.sgrtr;
                    break;
                case ">=":
                    spop = SPOpcode.sgeq;
                    break;
                case "<":
                    spop = SPOpcode.sless;
                    break;
                case "<=":
                    spop = SPOpcode.sleq;
                    break;
                case "*":
                    spop = SPOpcode.smul;
                    break;
                case "/":
                    spop = SPOpcode.sdiv;
                    break;
                case "!=":
                    spop = SPOpcode.neq;
                    break;
                case "+":
                    spop = SPOpcode.add;
                    break;
                case "-":
                    spop = SPOpcode.sub;
                    break;
                default:
                    throw new Exception(String.Format("unknown operator ({0})", op.ToString()));
            }

            switch (spop)
            {
                case SPOpcode.sgeq:
                case SPOpcode.sleq:
                case SPOpcode.sgrtr:
                case SPOpcode.sless:
                case SPOpcode.smul:
                case SPOpcode.sdiv:
                case SPOpcode.neq:
                case SPOpcode.add:
                case SPOpcode.sub:
                {
                    if (call.numOperands != 2)
                        return;
                    DBinary binary = new DBinary(spop, call.getOperand(0), call.getOperand(1));
                    call.replaceAllUsesWith(binary);
                    call.removeFromUseChains();
                    current_.replace(iterator_, binary);
                    break;
                }
                default:
                    throw new Exception("unknown spop");
            }
        }
Ejemplo n.º 3
0
        public override void visit(DCall call)
        {
            // Operators can be overloaded for floats, and we want these to print
            // normally, so here is some gross peephole stuff. Maybe we should be
            // looking for bytecode patterns instead or something, but that would
            // need a whole-program analysis.
            if (call.function.name.Length < 8)
            {
                return;
            }

            if (call.function.name.Substring(0, 8) != "operator")
            {
                return;
            }

            var op = "";

            for (var i = 8; i < call.function.name.Length; i++)
            {
                if (call.function.name[i] == '(')
                {
                    break;
                }

                op += call.function.name[i];
            }

            SPOpcode spop;

            switch (op)
            {
            case ">":
                spop = SPOpcode.sgrtr;
                break;

            case ">=":
                spop = SPOpcode.sgeq;
                break;

            case "<":
                spop = SPOpcode.sless;
                break;

            case "<=":
                spop = SPOpcode.sleq;
                break;

            case "*":
                spop = SPOpcode.smul;
                break;

            case "/":
                spop = SPOpcode.sdiv;
                break;

            case "!=":
                spop = SPOpcode.neq;
                break;

            case "+":
                spop = SPOpcode.add;
                break;

            case "-":
                spop = SPOpcode.sub;
                break;

            default:
                throw new Exception(string.Format("unknown operator ({0})", op.ToString()));
            }

            switch (spop)
            {
            case SPOpcode.sgeq:
            case SPOpcode.sleq:
            case SPOpcode.sgrtr:
            case SPOpcode.sless:
            case SPOpcode.smul:
            case SPOpcode.sdiv:
            case SPOpcode.neq:
            case SPOpcode.add:
            case SPOpcode.sub:
            {
                if (call.numOperands != 2)
                {
                    return;
                }

                var binary = new DBinary(spop, call.getOperand(0), call.getOperand(1));
                call.replaceAllUsesWith(binary);
                call.removeFromUseChains();
                current_.replace(iterator_, binary);
                break;
            }

            default:
                throw new Exception("unknown spop");
            }
        }
Ejemplo n.º 4
0
        private string buildCall(DCall call)
        {
            string args = "";
            for (int i = 0; i < call.numOperands; i++)
            {
                DNode input = call.getOperand(i);
                string arg = buildExpression(input);
                args += arg;
                if (i != call.numOperands - 1)
                    args += ", ";
            }

            return call.function.name + "(" + args + ")";
        }