Exemple #1
0
        private readonly Format16OpCode inverseOpCode; //should we wish to invert this operator, because (a<b)==!(a>=b), therefore BGE

        private CompareOp(IntExpression lhs, IntExpression rhs, Format16OpCode branchOpCode, Format16OpCode inverseOpCode)
        {
            this.lhs           = lhs;
            this.rhs           = rhs;
            this.branchOpCode  = branchOpCode;
            this.inverseOpCode = inverseOpCode;
        }
Exemple #2
0
 private CompareOp(IntExpression lhs, IntExpression rhs, Format16OpCode branchOpCode, Format16OpCode inverseOpCode)
 {
     this.lhs=lhs;
       this.rhs=rhs;
       this.branchOpCode=branchOpCode;
       this.inverseOpCode=inverseOpCode;
 }
Exemple #3
0
        public void Emit(Format16OpCode opCode, int target)
        {
            var offset = target - (CurrentAddress + 4);

            CheckRange(offset, -(1 << 8) + 1, (1 << 8) - 1, 1);
            var fluentComment = opCode.ToHumanReadable() + " " + ((short)target).ToHex();
            var offsetBits    = (offset >> 1) & 0xff;

            EmitHelper(null, 16, fluentComment, 13, 4, (int)opCode, 4, offsetBits, 8);
        }
Exemple #4
0
 // branchOpCode: the normal case: (a<b) therefore BLT
 // flipOpCode: the flipped case: (a<b)==(b>a), therefore BGT
 // inverseOpCode: the inverse case: (a<b)==!(a>=b), therefore BGE
 // flipInverseOpCode: the flipped inverse case: (a<b)==!(b<=a), therefore BLE
 private static CompareOp CreateHelper(IntExpression lhs, IntExpression rhs,
                                       Format16OpCode branchOpCode, Format16OpCode flipOpCode, Format16OpCode inverseOpCode, Format16OpCode flipInverseOpCode)
 {
     if (lhs.IsConstant())
     {
         if (rhs.IsConstant())
         {
             throw new Exception("ridiculous");
         }
         //flip the constant over to the right side, for better code generation
         return(new CompareOp(rhs, lhs, flipOpCode, flipInverseOpCode));
     }
     return(new CompareOp(lhs, rhs, branchOpCode, inverseOpCode));
 }
Exemple #5
0
 public void Emit(Format16OpCode opCode, int target)
 {
     var offset=target-(CurrentAddress+4);
       CheckRange(offset, -(1<<8)+1, (1<<8)-1, 1);
       var fluentComment=opCode.ToHumanReadable()+" "+((short)target).ToHex();
       var offsetBits=(offset>>1)&0xff;
       EmitHelper(null, 16, fluentComment, 13, 4, (int)opCode, 4, offsetBits, 8);
 }
Exemple #6
0
   // branchOpCode: the normal case: (a<b) therefore BLT
   // flipOpCode: the flipped case: (a<b)==(b>a), therefore BGT
   // inverseOpCode: the inverse case: (a<b)==!(a>=b), therefore BGE
   // flipInverseOpCode: the flipped inverse case: (a<b)==!(b<=a), therefore BLE
   private static CompareOp CreateHelper(IntExpression lhs, IntExpression rhs,
 Format16OpCode branchOpCode, Format16OpCode flipOpCode, Format16OpCode inverseOpCode, Format16OpCode flipInverseOpCode)
   {
       if(lhs.IsConstant()) {
       if(rhs.IsConstant()) {
         throw new Exception("ridiculous");
       }
       //flip the constant over to the right side, for better code generation
       return new CompareOp(rhs, lhs, flipOpCode, flipInverseOpCode);
         }
         return new CompareOp(lhs, rhs, branchOpCode, inverseOpCode);
   }
Exemple #7
0
 public static string ToHumanReadable(this Format16OpCode opCode)
 {
     return("BEQBNEBCSBCCBMIBPLBVSBVCBHIBLSBGEBLTBGTBLE".Substring((int)opCode * 3, 3));
 }