Exemplo n.º 1
0
Arquivo: SSA.cs Projeto: AxFab/amy
        internal SSA(Operand operand, bool ignoreConst)
        {
            if ((ignoreConst && operand.IsConst) ||
            (operand.Operator == Operator.Operand && (operand.Parent == null ||
            (operand.Parent != null && operand == operand.Parent.Left)))) {
            this.Operator = Operator.Assign;
            this.Name = operand.Code;
            this.Version = 0;
            this.Operand1 = operand;
            operand.Version = 0;

              } else if (operand.OperandCount == 1) {
            this.Operator = operand.Operator;
            this.Name = operand.Right.Code;
            this.Version = operand.Right.Version + 1;

              } else if (operand.OperandCount == 2) {
            this.Operator = operand.Operator;
            this.Name = operand.Left.Code;
            this.Version = operand.Left.Version + 1;
            this.Operand1 = operand.Right;

              }

              operand.Code = this.Name;
              operand.Version = this.Version;
        }
Exemplo n.º 2
0
 public void Div(Operand result, Operand left, Operand right)
 {
     Primitive type = (Primitive)Math.Max((int)left.PType, (int)right.PType);
       if (!right.AsBoolean)
     result.Set(Primitive.Error, false, right.IsConst);
       else
     result.Set(type, left.AsSigned / right.AsSigned, left.IsConst && right.IsConst);
 }
Exemplo n.º 3
0
Arquivo: Operand.cs Projeto: AxFab/amy
        public bool Resolve(Operand left, Operand right)
        {
            this.Left = left;
              this.Right = right;
              left.Parent = this;
              right.Parent = this;

              OperatorImplem action = OperatorAction.Get(this.Operator, left.PType, right.PType);
              if (action == null) {
            this.PType = Primitive.Error;
            this.IsConst = true;
            // Push an error or what !?
              } else
            action(this, left, right);

              return false;
        }
Exemplo n.º 4
0
 public void Sub(Operand result, Operand left, Operand right)
 {
     result.Set(Primitive.Error, false, left.IsConst && right.IsConst);
 }
Exemplo n.º 5
0
 public void Equals(Operand result, Operand left, Operand right)
 {
     result.Set(Primitive.Boolean, left.AsBoolean == right.AsBoolean, left.IsConst && right.IsConst);
 }
Exemplo n.º 6
0
 public void Mul(Operand result, Operand left, Operand right)
 {
     Primitive type = (Primitive)Math.Max((int)left.PType, (int)right.PType);
       result.Set(type, left.AsDecimal * right.AsDecimal, left.IsConst && right.IsConst);
 }
Exemplo n.º 7
0
 private static void isError(Operand result, Operand left, Operand right)
 {
     result.Set(Primitive.Error, false, left.IsConst && right.IsConst);
 }
Exemplo n.º 8
0
 public void NotEquals(Operand result, Operand left, Operand right)
 {
     result.Set(Primitive.Boolean, left.AsSigned != right.AsSigned, left.IsConst && right.IsConst);
 }
Exemplo n.º 9
0
 /// <summary>Push an operand on the post-fix stack.</summary>
 /// <param name="node">An operand object without operator.</param>
 private void addPostFixOperand(Operand node)
 {
     System.Diagnostics.Debug.Assert(node.Operator == Operator.Operand);
       postFixStack_.Push(node);
 }
Exemplo n.º 10
0
        public bool Push(object token, Operator opcode)
        {
            if (!setLast(token, opcode))
            return false;

              Operand node = new Operand(token, opcode);
              while (inFixStack_.Count > 0 && inFixStack_.Peek().Priority <= node.Priority) {
            Operand nd = inFixStack_.Pop();
            addPostFixOperator(nd);
              }

              inFixStack_.Push(node);
              return true;
        }
Exemplo n.º 11
0
        public bool Push(object token, Primitive type, decimal value)
        {
            if (!setLast(token, Operator.Operand))
            return false;

              Operand node = new Operand(token, type, value);
              addPostFixOperand(node);
              return true;
        }
Exemplo n.º 12
0
        public bool OpenParenthese(object token)
        {
            if (!setLast(token, Operator.Parenthese))
            return false;

              Operand node = new Operand(token, Operator.Parenthese);
              inFixStack_.Push(node);
              return true;
        }
Exemplo n.º 13
0
 public void LessEq(Operand result, Operand left, Operand right)
 {
     result.Set(Primitive.Boolean, left.AsUnsigned <= right.AsUnsigned, left.IsConst && right.IsConst);
 }
Exemplo n.º 14
0
 public void MoreEq(Operand result, Operand left, Operand right)
 {
     result.Set(Primitive.Boolean, left.AsSigned >= right.AsSigned, left.IsConst && right.IsConst);
 }
Exemplo n.º 15
0
        /// <summary>Resolve an operator and push it pack on the post-fix stack.</summary>
        /// <param name="node">An operand object with an operator.</param>
        private void addPostFixOperator(Operand node)
        {
            Operand opRg;
              Operand opLf;
              System.Diagnostics.Debug.Assert(node.Operator != Operator.Operand);
              System.Diagnostics.Debug.Assert(node.Operator != Operator.Parenthese);

              if (node.Priority == 0)
            throw new Exception("Internal error, the definition for this operator can't be found: " + node.Operator);

              if (node.OperandCount == 1) {
            if (postFixStack_.Count < 1)
              throw new Exception("Missing operand for the operator: " + node.Operator);
            opRg = postFixStack_.Pop();
            opLf = new Operand(null, Primitive.Error, false);

              } else if (node.OperandCount == 2) {
            if (postFixStack_.Count < 2)
              throw new Exception("Missing operands for the operator: " + node.Operator);
            opRg = postFixStack_.Pop();
            opLf = postFixStack_.Pop();

              } else {
            // TODO Parenthesis can be there if the expression is incorrect
            throw new Exception("Invalid operator: " + node.Operator);
              }

              node.Resolve(opLf, opRg);
              postFixStack_.Push(node);
        }
Exemplo n.º 16
0
 public void Not(Operand result, Operand left, Operand right)
 {
     result.Set(Primitive.Boolean, !right.AsBoolean, right.IsConst);
 }
Exemplo n.º 17
0
        private SSAFlow SSA(Operand op, SSAFlow flow, bool removeConst)
        {
            if (flow == null)
            flow = new SSAFlow();
              Operand origin = op;
              while (op.Left != null && (!removeConst || !op.Left.IsConst))
            op = op.Left;
              for (; ; ) {
            if (op.Operator == Operator.Operand || (op.IsConst && removeConst))
              op.Code = ssaNameArr[ssaNameIdx++].ToString();
            flow.Push(new SSA(op, removeConst));
            //Console.WriteLine(op.SSA()); // TODO
            op = op.Parent;
            if (op == null || op == origin.Parent)
              break;
            if (op != null && op.Right != null && op.Right.Operator != Operator.Operand)
              SSA(op.Right, flow, removeConst);
              }

              return flow;
        }
Exemplo n.º 18
0
 public void Sub(Operand result, Operand left, Operand right)
 {
     Primitive type = (Primitive)Math.Max((int)left.PType, (int)right.PType);
       result.Set(type, left.AsSigned - right.AsSigned, left.IsConst && right.IsConst);
 }
Exemplo n.º 19
0
 public void Add(Operand result, Operand left, Operand right)
 {
     // TODO IsConst -> likely to be const type so const.
       result.Set(Primitive.Error, false, left.IsConst && right.IsConst);
 }
Exemplo n.º 20
0
 private static void orLogic(Operand result, Operand left, Operand right)
 {
     if (left.PType == Primitive.Error)
     result.Set(Primitive.Error, false, left.IsConst);
       else if (left.AsBoolean)
     result.Set(Primitive.Boolean, true, left.IsConst);
       else if (right.PType == Primitive.Error)
     result.Set(Primitive.Error, false, left.IsConst && right.IsConst);
       else
     result.Set(Primitive.Boolean, right.AsBoolean, left.IsConst && right.IsConst);
 }
Exemplo n.º 21
0
 public void More(Operand result, Operand left, Operand right)
 {
     result.Set(Primitive.Boolean, left.AsDecimal > right.AsDecimal, left.IsConst && right.IsConst);
 }