示例#1
0
        public static IReadable Invoke(string scopeName, IReference storage, IntExpression lhs, IntExpression rhs,
                                       ActionOnThreeLowRegisters registerAction, ActionOnTwoLowRegistersAndAByte byteAction)
        {
            var f = FuncBuilder.Instance;

            using (f.OpenScope(scopeName)) {
                var sm        = new StorageManager(storage);
                var lhsResult = lhs.EvaluateTo(sm.ForLhs(rhs));
                var rhsResult = rhs.EvaluateTo(sm.ForRhs(lhsResult));

                var storageReg   = storage.ProposeRegisterOrScratch0();
                var lhsReg       = lhsResult.ToRegister(f.Scratch0);
                var rhsRegOrByte = rhsResult.ToRegisterOrByte(f.Scratch1);
                if (rhsRegOrByte.IsRegister)
                {
                    registerAction(storageReg, lhsReg, rhsRegOrByte.Register);
                }
                else
                {
                    byteAction(storageReg, lhsReg, rhsRegOrByte.Byte);
                }
                storage.FromRegister(storageReg);
                return(storage);
            }
        }
示例#2
0
文件: Add.cs 项目: meikeric/DotCopter
 private static Add CreateHelper(IntExpression lhs, IntExpression rhs)
 {
     //turn a+(-b) into a-(+b)
     return(rhs.IsNegated
 ? new Add(lhs, -rhs, false)
 : new Add(lhs, rhs, true));
 }
示例#3
0
 private static Add CreateHelper(IntExpression lhs, IntExpression rhs)
 {
     //turn a+(-b) into a-(+b)
       return rhs.IsNegated
     ? new Add(lhs, -rhs, false)
     : new Add(lhs, rhs, true);
 }
示例#4
0
 private CompareOp(IntExpression lhs, IntExpression rhs, Format16OpCode branchOpCode, Format16OpCode inverseOpCode)
 {
     this.lhs=lhs;
       this.rhs=rhs;
       this.branchOpCode=branchOpCode;
       this.inverseOpCode=inverseOpCode;
 }
示例#5
0
 public static IntExpression Create(IntExpression lhs, IntExpression rhs, bool shiftLeft)
 {
     int lhsValue, rhsValue;
       if(lhs.TryGetConstant(out lhsValue) && rhs.TryGetConstant(out rhsValue)) {
     return shiftLeft ? lhsValue<<rhsValue : lhsValue>>rhsValue;
       }
       return new Shift(lhs, rhs, shiftLeft);
 }
示例#6
0
 public static IntExpression Create(IntExpression lhs, IntExpression rhs)
 {
     //item 1: move constants to the right hand side
       //item 2: move negated items to the right hand side, except where this conflicts with item 1
       if(lhs.IsConstant() || (lhs.IsNegated && !rhs.IsConstant())) {
     return CreateHelper(rhs, lhs);
       }
       return CreateHelper(lhs, rhs);
 }
示例#7
0
文件: Add.cs 项目: meikeric/DotCopter
 public static IntExpression Create(IntExpression lhs, IntExpression rhs)
 {
     //item 1: move constants to the right hand side
     //item 2: move negated items to the right hand side, except where this conflicts with item 1
     if (lhs.IsConstant() || (lhs.IsNegated && !rhs.IsConstant()))
     {
         return(CreateHelper(rhs, lhs));
     }
     return(CreateHelper(lhs, rhs));
 }
 public void GetPIOReference(ref PIOReferenceVariable pio, IntExpression port)
 {
     //ugh.. fix this type system disaster
       var f=FuncBuilder.Instance;
       using(f.OpenScope("GetPIORef")) {
     var temp=f.Declare.Int("temp");
     InvokeResult(19, temp, port);
     Assignment.AssignAny(pio, temp); //escape from the type system
       }
 }
示例#9
0
        public static IntExpression Create(IntExpression lhs, IntExpression rhs, bool shiftLeft)
        {
            int lhsValue, rhsValue;

            if (lhs.TryGetConstant(out lhsValue) && rhs.TryGetConstant(out rhsValue))
            {
                return(shiftLeft ? lhsValue << rhsValue : lhsValue >> rhsValue);
            }
            return(new Shift(lhs, rhs, shiftLeft));
        }
        public void GetPIOReference(ref PIOReferenceVariable pio, IntExpression port)
        {
            //ugh.. fix this type system disaster
            var f = FuncBuilder.Instance;

            using (f.OpenScope("GetPIORef")) {
                var temp = f.Declare.Int("temp");
                InvokeResult(19, temp, port);
                Assignment.AssignAny(pio, temp); //escape from the type system
            }
        }
示例#11
0
 public static IntExpression Create(IntExpression expr)
 {
     int value;
       if(expr.TryGetConstant(out value)) {
     return new IntConstant(-value);
       }
       var alreadyNegatedExpression=expr as UnaryMinus;
       return ReferenceEquals(alreadyNegatedExpression, null)
     ? new UnaryMinus(expr)
     : alreadyNegatedExpression.expr;
 }
示例#12
0
 public void Invoke(IntExpression intParam0    = null, IntExpression intParam1    = null, IntExpression intParam2    = null, IntExpression intParam3    = null,
                    BytePointer bytePtrParam4  = null, BytePointer bytePtrParam5  = null, BytePointer bytePtrParam6  = null, BytePointer bytePtrParam7  = null,
                    IntPointer intPtrParam8    = null, IntPointer intPtrParam9    = null, IntPointer intPtrParam10   = null, IntPointer intPtrParam11   = null,
                    FuncPointer funcPtrParam12 = null, FuncPointer funcPtrParam13 = null, FuncPointer funcPtrParam14 = null, FuncPointer funcPtrParam15 = null,
                    MethodDispatchTablePointer firmwareParam16 = null)
 {
     this.Invoke(new Expression[] {
         intParam0, intParam1, intParam2, intParam3,
         bytePtrParam4, bytePtrParam5, bytePtrParam6, bytePtrParam7,
         intPtrParam8, intPtrParam9, intPtrParam10, intPtrParam11,
         funcPtrParam12, funcPtrParam13, funcPtrParam14, funcPtrParam15
     });
 }
示例#13
0
 public void Invoke(IntExpression intParam0=null, IntExpression intParam1=null, IntExpression intParam2=null, IntExpression intParam3=null,
     BytePointer bytePtrParam4=null, BytePointer bytePtrParam5=null, BytePointer bytePtrParam6=null, BytePointer bytePtrParam7=null,
     IntPointer intPtrParam8=null, IntPointer intPtrParam9=null, IntPointer intPtrParam10=null, IntPointer intPtrParam11=null,
     FuncPointer funcPtrParam12=null, FuncPointer funcPtrParam13=null, FuncPointer funcPtrParam14=null, FuncPointer funcPtrParam15=null,
     MethodDispatchTablePointer firmwareParam16=null)
 {
     this.Invoke(new Expression[] {
     intParam0, intParam1, intParam2, intParam3,
     bytePtrParam4, bytePtrParam5, bytePtrParam6, bytePtrParam7,
     intPtrParam8, intPtrParam9, intPtrParam10, intPtrParam11,
     funcPtrParam12, funcPtrParam13, funcPtrParam14, funcPtrParam15
       });
 }
示例#14
0
        public static IntExpression Create(IntExpression expr)
        {
            int value;

            if (expr.TryGetConstant(out value))
            {
                return(new IntConstant(-value));
            }
            var alreadyNegatedExpression = expr as UnaryMinus;

            return(ReferenceEquals(alreadyNegatedExpression, null)
        ? new UnaryMinus(expr)
        : alreadyNegatedExpression.expr);
        }
        public static void Return(this FuncBuilder f, IntExpression expr)
        {
            using(f.OpenScope("return")) {
            var emitter=CodeGenerator.Emitter;
            var resultStorage=f.Declare.Int("result");
            var exprResult=expr.EvaluateTo(resultStorage);

            var exprRegOrByte=exprResult.ToRegisterOrByte(f.Scratch0);
            if(exprRegOrByte.IsRegister) {
              emitter.EmitRegisterMoveIfDifferent(Register.R0, exprRegOrByte.Register);
            } else {
              emitter.Emit(Format3OpCode.MOV, Register.R0, exprRegOrByte.Byte);
            }
            BranchLogic.UnconditionalBranchTo(f.TheExitLabel);
              }
        }
示例#16
0
        protected void AssignFromHelper(IntExpression value, ActionOnThreeLowRegisters regAction, ActionOnTwoLowRegistersAndAByte byteAction)
        {
            var f = FuncBuilder.Instance;

            using (f.OpenScope("indirectReferenceAssign")) {
                var declarer   = f.Declare;
                var valueTemp  = declarer.Int("value");
                var baseTemp   = declarer.Int("baseAddress");
                var offsetTemp = declarer.Int("offset");

                var valueResult  = value.EvaluateTo(valueTemp);
                var baseResult   = baseAddress.EvaluateTo(baseTemp);
                var offsetResult = offset.EvaluateTo(offsetTemp);

                //Oh crap. I need three readable registers to accomplish this instruction.
                //The other instructions only need two registers.
                //If indeed I do need three scratch registers, I'm going to do the super hack job from hell
                //(namely, swapping some other register with LR)
                var baseReg         = baseResult.ToRegister(f.Scratch0);
                var offsetRegOrByte = offsetResult.ToRegisterOrUnsignedConstant(exclusiveUpperBoundForConstantOffset, f.Scratch1);
                if (offsetRegOrByte.IsRegister)
                {
                    var         offsetReg    = offsetRegOrByte.Register;
                    var         valuePropReg = ProposeRegisterForValue(valueResult, baseReg, offsetReg);
                    LowRegister valueReg;
                    if (valuePropReg != null)
                    {
                        valueReg = valueResult.ToRegister(valuePropReg);
                    }
                    else
                    {
                        //out of scratch registers.  Burn another instruction to do base+=offset so that you can free up offset
                        CodeGenerator.Emitter.Emit(Format2OpCode.ADD, baseReg, offsetReg, 0);
                        //now the register in offsetReg, which is known to be scratch, can be used to hold the value
                        valueReg = valueResult.ToRegister(offsetReg);
                    }
                    regAction(valueReg, baseReg, offsetReg);
                }
                else
                {
                    var valueReg = valueResult.ToRegister(f.Scratch1);
                    byteAction(valueReg, baseReg, offsetRegOrByte.Byte);
                }
            }
        }
示例#17
0
        protected void AssignFromHelper(IntExpression value, ActionOnThreeLowRegisters regAction, ActionOnTwoLowRegistersAndAByte byteAction)
        {
            var f=FuncBuilder.Instance;

              using(f.OpenScope("indirectReferenceAssign")) {
            var declarer=f.Declare;
            var valueTemp=declarer.Int("value");
            var baseTemp=declarer.Int("baseAddress");
            var offsetTemp=declarer.Int("offset");

            var valueResult=value.EvaluateTo(valueTemp);
            var baseResult=baseAddress.EvaluateTo(baseTemp);
            var offsetResult=offset.EvaluateTo(offsetTemp);

            //Oh crap. I need three readable registers to accomplish this instruction.
            //The other instructions only need two registers.
            //If indeed I do need three scratch registers, I'm going to do the super hack job from hell
            //(namely, swapping some other register with LR)
            var baseReg=baseResult.ToRegister(f.Scratch0);
            var offsetRegOrByte=offsetResult.ToRegisterOrUnsignedConstant(exclusiveUpperBoundForConstantOffset, f.Scratch1);
            if(offsetRegOrByte.IsRegister) {
              var offsetReg=offsetRegOrByte.Register;
              var valuePropReg=ProposeRegisterForValue(valueResult, baseReg, offsetReg);
              LowRegister valueReg;
              if(valuePropReg!=null) {
            valueReg=valueResult.ToRegister(valuePropReg);
              } else {
            //out of scratch registers.  Burn another instruction to do base+=offset so that you can free up offset
            CodeGenerator.Emitter.Emit(Format2OpCode.ADD, baseReg, offsetReg, 0);
            //now the register in offsetReg, which is known to be scratch, can be used to hold the value
            valueReg=valueResult.ToRegister(offsetReg);
              }
              regAction(valueReg, baseReg, offsetReg);
            } else {
              var valueReg=valueResult.ToRegister(f.Scratch1);
              byteAction(valueReg, baseReg, offsetRegOrByte.Byte);
            }
              }
        }
示例#18
0
        public static IReadable Invoke(string scopeName, IReference storage, IntExpression lhs, IntExpression rhs,
      ActionOnThreeLowRegisters registerAction, ActionOnTwoLowRegistersAndAByte byteAction)
        {
            var f=FuncBuilder.Instance;

              using(f.OpenScope(scopeName)) {
            var sm=new StorageManager(storage);
            var lhsResult=lhs.EvaluateTo(sm.ForLhs(rhs));
            var rhsResult=rhs.EvaluateTo(sm.ForRhs(lhsResult));

            var storageReg=storage.ProposeRegisterOrScratch0();
            var lhsReg=lhsResult.ToRegister(f.Scratch0);
            var rhsRegOrByte=rhsResult.ToRegisterOrByte(f.Scratch1);
            if(rhsRegOrByte.IsRegister) {
              registerAction(storageReg, lhsReg, rhsRegOrByte.Register);
            } else {
              byteAction(storageReg, lhsReg, rhsRegOrByte.Byte);
            }
            storage.FromRegister(storageReg);
            return storage;
              }
        }
        public static void ForEachBit(this FuncBuilder f, IntExpression expr, int offset, int count, bool bigEndian, ActionOnIntExpr action)
        {
            int inclusiveStart;
              int exclusiveEnd;
              int increment;
              if(!bigEndian) {
            inclusiveStart=offset;
            exclusiveEnd=offset+count;
            increment=1;
              } else {
            inclusiveStart=offset+count-1;
            exclusiveEnd=offset-1;
            increment=-1;
              }

              f.For(i => i.Value=inclusiveStart, i => i<exclusiveEnd, i => i.Value=i+increment)
            .Do(i => {
              var mask=((IntExpression)1).ShiftLeft(i);
              var bitInPosition=f.Declare.Int("bitInPosition");
              bitInPosition.Value=expr&mask;
              action(bitInPosition);
            });
        }
 public void EnableOutputPin(IntExpression pin, IntExpression initialState)
 {
     InvokeVoid(4, pin, initialState);
 }
 public void IntegerDivide(ref IntVariable result, IntExpression numerator, IntExpression denominator)
 {
     InvokeResult(18, result, numerator, denominator);
 }
 public void GetPinState(ref IntVariable result, IntExpression pin)
 {
     InvokeResult(7, result, pin);
 }
示例#23
0
 public IntExpression ShiftRight(IntExpression rhs)
 {
     return Shift.Create(this, rhs, false);
 }
   public void EnableInputPin(IntExpression pin, IntExpression glitchFilterEnable,
 FuncPointer pinIsr, IntExpression intEdge, IntExpression resistorState)
   {
       InvokeVoid(5, pin, glitchFilterEnable, pinIsr, intEdge, resistorState);
   }
 public IndirectByteReference(BytePointer baseAddress, IntExpression offset)
     : base(baseAddress, offset, 32)
 {
 }
示例#26
0
 protected IndirectReference(Pointer baseAddress, IntExpression offset, int exclusiveUpperBoundForConstantOffset)
 {
     this.baseAddress=baseAddress;
       this.offset=offset;
       this.exclusiveUpperBoundForConstantOffset=exclusiveUpperBoundForConstantOffset;
 }
 public IndirectIntReference(IntPointer baseAddress, IntExpression offset)
     : base(baseAddress, offset.ShiftLeft(2), 31*4+1)
 {
 }
 public static void GetPIOAndBitmask(this MethodDispatchTablePointer md, IntExpression pin, ref PIOReferenceVariable pio, ref IntVariable bitmask)
 {
     md.GetPIOReference(ref pio, pin.ShiftRight(5)); // pin/32
       bitmask.Value=((IntExpression)1).ShiftLeft(pin&0x1f); // 1<<(pin%32)
 }
示例#29
0
 public IndirectByteReference(BytePointer baseAddress, IntExpression offset) : base(baseAddress, offset, 32)
 {
 }
示例#30
0
 public UnaryMinus(IntExpression expr)
 {
     this.expr=expr;
 }
示例#31
0
 protected BinaryIntExpression(IntExpression lhs, IntExpression rhs)
 {
     this.lhs = lhs;
     this.rhs = rhs;
 }
示例#32
0
文件: Add.cs 项目: meikeric/DotCopter
 private Add(IntExpression lhs, IntExpression rhs, bool isAdd) : base(lhs, rhs)
 {
     this.isAdd = isAdd;
 }
示例#33
0
 public IntExpression ShiftRight(IntExpression rhs)
 {
     return(Shift.Create(this, rhs, false));
 }
示例#34
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);
   }
 public void SetPinState(IntExpression pin, IntExpression value)
 {
     InvokeVoid(8, pin, value);
 }
示例#36
0
 private Add(IntExpression lhs, IntExpression rhs, bool isAdd)
     : base(lhs, rhs)
 {
     this.isAdd=isAdd;
 }
示例#37
0
 public UnaryMinus(IntExpression expr)
 {
     this.expr = expr;
 }
示例#38
0
 protected IndirectReference(Pointer baseAddress, IntExpression offset, int exclusiveUpperBoundForConstantOffset)
 {
     this.baseAddress = baseAddress;
     this.offset      = offset;
     this.exclusiveUpperBoundForConstantOffset = exclusiveUpperBoundForConstantOffset;
 }
 public void EnableInputPin2(IntExpression pin, IntExpression glitchFilterEnable,
                             FuncPointer pinIsr, IntExpression payload, IntExpression intEdge, IntExpression resistorState)
 {
     InvokeVoid(6, pin, glitchFilterEnable, pinIsr, payload, intEdge, resistorState);
 }
示例#40
0
 public static CompareOp CreateNotEqual(IntExpression lhs, IntExpression rhs)
 {
     return CreateHelper(lhs, rhs, Format16OpCode.BNE, Format16OpCode.BNE, Format16OpCode.BEQ, Format16OpCode.BEQ);
 }
 public void SetPinState(IntExpression pin, IntExpression value)
 {
     InvokeVoid(8, pin, value);
 }
示例#42
0
 public static CompareOp CreateLessThanOrEqual(IntExpression lhs, IntExpression rhs)
 {
     return CreateHelper(lhs, rhs, Format16OpCode.BLE, Format16OpCode.BGE, Format16OpCode.BGT, Format16OpCode.BLT);
 }
示例#43
0
 private Shift(IntExpression lhs, IntExpression rhs, bool shiftLeft) : base(lhs, rhs)
 {
     this.shiftLeft = shiftLeft;
 }
 public void EnableOutputPin(IntExpression pin, IntExpression initialState)
 {
     InvokeVoid(4, pin, initialState);
 }
 public void HAL_EnqueueDelta(IntPointer address, IntExpression delayInMicroseconds)
 {
     InvokeVoid(21, address, delayInMicroseconds);
 }
 public void GetPinState(ref IntVariable result, IntExpression pin)
 {
     InvokeResult(7, result, pin);
 }
示例#47
0
 public AluOperation(IntExpression lhs, IntExpression rhs, Format4OpCode opCode) : base(lhs, rhs)
 {
     this.opCode = opCode;
 }
示例#48
0
 protected BinaryIntExpression(IntExpression lhs, IntExpression rhs)
 {
     this.lhs=lhs;
       this.rhs=rhs;
 }
示例#49
0
 private Shift(IntExpression lhs, IntExpression rhs, bool shiftLeft)
     : base(lhs, rhs)
 {
     this.shiftLeft=shiftLeft;
 }
 public void HAL_EnqueueDelta(IntPointer address, IntExpression delayInMicroseconds)
 {
     InvokeVoid(21, address, delayInMicroseconds);
 }
示例#51
0
 /// <summary>
 /// operator&lt;&lt; not overridable in the way I would like
 /// </summary>
 public IntExpression ShiftLeft(IntExpression rhs)
 {
     return(Shift.Create(this, rhs, true));
 }
 public void IntegerDivide(ref IntVariable result, IntExpression numerator, IntExpression denominator)
 {
     InvokeResult(18, result, numerator, denominator);
 }
示例#53
0
 public IndirectIntReference(IntPointer baseAddress, IntExpression offset) : base(baseAddress, offset.ShiftLeft(2), 31 * 4 + 1)
 {
 }
示例#54
0
 public AluOperation(IntExpression lhs, IntExpression rhs, Format4OpCode opCode)
     : base(lhs, rhs)
 {
     this.opCode=opCode;
 }