public void SetIRSensor(IR direction) { toSend[2] = 0; currentIr = direction; switch (direction) { case IR.Front: toSend[2] = 62; break; case IR.Rear: toSend[2] = 26; break; case IR.Left: toSend[2] = 44; break; case IR.Right: toSend[2] = 8; break; case IR.None: toSend[2] = 0; break; } send(); send(); send(); send(); send(); send(); }
static void Main(string[] args) { Console.WriteLine("Digite salario: "); double salario = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); double IR; if (salario >= 0.00 && salario <= 2000.00) { IR = 0.00; Console.WriteLine("Isento de impostos"); } else if (salario > 2000.00 && salario <= 3000.00) { IR = (salario - 2000.00) * 0.08; Console.WriteLine(IR); } else if (salario > 3000.00 && salario <= 4500.00) { IR = (salario - 3000.00) * 0.18 + 1000 * 0.08; Console.WriteLine("R$: " + IR); } else if (salario > 4500.00) { IR = (salario - 4500.00) * 0.28 + 1500.00 * 0.18 + 1000.00 * 0.08; Console.WriteLine("R$" + IR.ToString("F2", CultureInfo.InvariantCulture)); } }
public Vector(int length) { for (int i = 0; i < length; i++) { V.Add(IR.New(0)); } }
public void Other() { RemindersTX.color = new Color32(26, 28, 46, 255); ImportantTX.color = new Color32(148, 148, 148, 255); UpcomingTX.color = new Color32(148, 148, 148, 255); foreach (GameObject IR in ImportantReminders) { if (IR.activeSelf == false) { IR.SetActive(true); } } foreach (GameObject UR in UpcomingReminders) { if (UR.activeSelf == false) { UR.SetActive(true); } } foreach (GameObject OR in OtherReminders) { if (OR.activeSelf == false) { OR.SetActive(true); } } }
/// <summary> /// Constructor. /// </summary> /// <param name="mem">The memory device to display.</param> public MemoryForm(MemoryDevice mem) { InitializeComponent(); this.Text = mem.Name; this.mDevice = mem; this.mIr = new IR(); this.mShadow = new uint[mem.Size]; this.mVirtualItems = new ListViewItem[mem.Size]; memoryListView.VirtualListSize = (int)mem.Size; mBreakpoints = new List <uint>(); //Populate view buffer for (uint i = 0; i < mDevice.Size; i++) { uint address = i + mDevice.BaseAddress; uint value = 0xffffffff; //Note: this should come from memory, but the default value zero is immediately set to 0xffffffff by WRAMPmon, resulting in a complete (slow) redraw. mIr.Instruction = value; mShadow[i] = value; string addressStr = address.ToString("X8"); string valueStr = value.ToString("X8"); string disassembly = mIr.ToString(); mVirtualItems[i] = new ListViewItem(new string[] { "", addressStr, valueStr, disassembly }); } updateTimer.Start(); }
public IrSym(IR d, Location arg, int l) { dir = d; arg1 = arg; arg2 = null; linenum = l; checkInstr(d, 1); }
public IrSym(IR d, Location arga, Location argb, int l) { dir = d; arg1 = arga; arg2 = argb; linenum = l; checkInstr(d, 2); }
public IrSym(IR d, int l) { dir = d; arg1 = null; arg2 = null; linenum = l; checkInstr(d, 0); }
public override void OnLoad() { Ir = PhidgetManager.Get <IR>(throwIfNotAttached: false); Ir.Code += ir_Code; Ir.Attach += ir_Attach; Ir.Detach += ir_Detach; CheckCanSave(); }
private ImmutableList <Tuple <FhirDateTime, FhirDecimal> > Convert_R( IR value) { return(value.Value .Select( i => new Tuple <FhirDateTime, FhirDecimal>( i.t_IndexElement, i.Value)) .ToImmutableList()); }
private void SetInterrupt(IR interrupt) { _interruptRegisters[0] |= (byte)interrupt; if ((_interruptRegisters[1] & (byte)interrupt) != 0 && (_interruptRegisters[0] & (byte)IR.REQ) == 0) { _interruptRegisters[0] |= (byte)IR.REQ; _irqLine.Raise(); } }
public List<int> AllocateRegisters(Stack<int> registers, IR.MethodEntry method) { List<int> used = new List<int>(); Dictionary<int, int> usageCount = new Dictionary<int, int>(); foreach (IR.InstructionElement i in method.Childnodes) AllocateRegistersRecursive(i, registers, method, used, usageCount); return used; }
//detach event handler...clear all the fields, display the attached status, and disable the checkboxes. void ir_Detach(object sender, DetachEventArgs e) { IR detached = (IR)sender; attachedTxt.Text = detached.Attached.ToString(); nameTxt.Text = ""; serialTxt.Text = ""; versionTxt.Text = ""; retransmitButton.Enabled = false; }
private void SetWiimoteInputs(Wiimote wm) { wm.irSensor.Normalize(); holder.SetValue(Inputs.Wiimote.A, wm.buttons.A); holder.SetValue(Inputs.Wiimote.B, wm.buttons.B); holder.SetValue(Inputs.Wiimote.ONE, wm.buttons.One); holder.SetValue(Inputs.Wiimote.TWO, wm.buttons.Two); holder.SetValue(Inputs.Wiimote.UP, wm.buttons.Up); holder.SetValue(Inputs.Wiimote.DOWN, wm.buttons.Down); holder.SetValue(Inputs.Wiimote.LEFT, wm.buttons.Left); holder.SetValue(Inputs.Wiimote.RIGHT, wm.buttons.Right); holder.SetValue(Inputs.Wiimote.MINUS, wm.buttons.Minus); holder.SetValue(Inputs.Wiimote.PLUS, wm.buttons.Plus); holder.SetValue(Inputs.Wiimote.HOME, wm.buttons.Home); holder.SetValue(Inputs.Wiimote.TILT_RIGHT, wm.accelerometer.X > 0 ? wm.accelerometer.X : 0); holder.SetValue(Inputs.Wiimote.TILT_LEFT, wm.accelerometer.X < 0 ? wm.accelerometer.X : 0); holder.SetValue(Inputs.Wiimote.TILT_UP, wm.accelerometer.Y > 0 ? wm.accelerometer.Y : 0); holder.SetValue(Inputs.Wiimote.TILT_DOWN, wm.accelerometer.Y < 0 ? wm.accelerometer.Y : 0); holder.SetValue(Inputs.Wiimote.ACC_SHAKE_X, wm.accelerometer.X > 1.15); holder.SetValue(Inputs.Wiimote.ACC_SHAKE_Y, wm.accelerometer.Y > 1.15); holder.SetValue(Inputs.Wiimote.ACC_SHAKE_Z, wm.accelerometer.Z > 1.15); if (wm.buttons.Up || wm.buttons.Down || wm.buttons.Left || wm.buttons.Right || wm.buttons.A || wm.buttons.B || wm.buttons.One || wm.buttons.Two || wm.buttons.Minus || wm.buttons.Plus || wm.buttons.Home) { disconnectTimer.Change(disconnectTime, -1); } if (snapIRpointer && !wm.irSensor.point1.visible && !wm.irSensor.point2.visible) { if (properties.pointerMode == Property.PointerOffScreenMode.SnapX || properties.pointerMode == Property.PointerOffScreenMode.SnapXY) { wm.irSensor.X = previousIR.X; } if (properties.pointerMode == Property.PointerOffScreenMode.SnapY || properties.pointerMode == Property.PointerOffScreenMode.SnapXY) { wm.irSensor.Y = previousIR.Y; } } holder.SetValue(Inputs.Wiimote.IR_RIGHT, wm.irSensor.X > 0 ? wm.irSensor.X : 0); holder.SetValue(Inputs.Wiimote.IR_LEFT, wm.irSensor.X < 0 ? wm.irSensor.X : 0); holder.SetValue(Inputs.Wiimote.IR_UP, wm.irSensor.Y > 0 ? wm.irSensor.Y : 0); holder.SetValue(Inputs.Wiimote.IR_DOWN, wm.irSensor.Y < 0 ? wm.irSensor.Y : 0); previousIR = wm.irSensor; }
/// <summary> /// Given three of the four current channels, calculates the /// missing channel based on the relationship IR = IA + IB + IC. /// </summary> private void CalculateMissingCurrentChannel() { Meter meter; DataSeries missingSeries; // If the data group does not have exactly 3 channels, // then there is no missing channel or there is not // enough data to calculate the missing channel if (DefinedCurrents != 3) { return; } // Get the meter associated with the channels in this data group meter = (IA ?? IB).SeriesInfo.Channel.Meter; if (m_iaIndex == -1) { // Calculate IA = IR - IB - IC missingSeries = IR.Add(IB.Negate()).Add(IC.Negate()); missingSeries.SeriesInfo = GetSeriesInfo(meter, m_dataGroup, "Current", "AN", IR.SeriesInfo.Channel.AssetID); missingSeries.Calculated = true; m_iaIndex = m_dataGroup.DataSeries.Count; m_dataGroup.Add(missingSeries); } else if (m_ibIndex == -1) { // Calculate IB = IR - IA - IC missingSeries = IR.Add(IA.Negate()).Add(IC.Negate()); missingSeries.SeriesInfo = GetSeriesInfo(meter, m_dataGroup, "Current", "BN", IR.SeriesInfo.Channel.AssetID); missingSeries.Calculated = true; m_ibIndex = m_dataGroup.DataSeries.Count; m_dataGroup.Add(missingSeries); } else if (m_icIndex == -1) { // Calculate IC = IR - IA - IB missingSeries = IR.Add(IA.Negate()).Add(IB.Negate()); missingSeries.SeriesInfo = GetSeriesInfo(meter, m_dataGroup, "Current", "CN", IR.SeriesInfo.Channel.AssetID); missingSeries.Calculated = true; m_icIndex = m_dataGroup.DataSeries.Count; m_dataGroup.Add(missingSeries); } else { // Calculate IR = IA + IB + IC missingSeries = IA.Add(IB).Add(IC); missingSeries.SeriesInfo = GetSeriesInfo(meter, m_dataGroup, "Current", "RES", IA.SeriesInfo.Channel.AssetID); missingSeries.Calculated = true; m_irIndex = m_dataGroup.DataSeries.Count; m_dataGroup.Add(missingSeries); } }
private void ClearInterrupt(IR flag) { _interruptFlagRegister &= (byte)~flag; if ((_interruptFlagRegister & (_interruptEnabledRegister | (byte)IR.IRQ)) == (byte)IR.IRQ) { byte clear = (byte)IR.IRQ; _interruptFlagRegister &= (byte)~clear; _irqLine.Lower(); } }
public TParam GetParam <TParam>(TParamName name) { object result; if (IR.TryGetValue(name, out result)) { return((TParam)result); } else { return(default(TParam)); } }
/// <summary> /// Given three of the four current channels, calculates the /// missing channel based on the relationship IR = IA + IB + IC. /// </summary> /// <param name="meterInfo">Data context for accessing configuration tables in the database.</param> public DataSeries CalculateMissingCurrentChannel() { Meter meter; DataSeries missingSeries; // If the data group does not have exactly 3 channels, // then there is no missing channel or there is not // enough data to calculate the missing channel if (DefinedCurrents != 3) { return(null); } // Get the meter associated with the channels in this data group meter = (I1 ?? I2).SeriesInfo.Channel.Meter; if (m_i1Index == -1) { // Calculate I1 = IR - I2 - I3 missingSeries = IR.Add(I2.Negate()).Add(I3.Negate()); missingSeries.SeriesInfo = GetSeriesInfo(meter, m_dataGroup, "Current", "General1"); m_i1Index = m_dataGroup.DataSeries.Count; m_dataGroup.Add(missingSeries); } else if (m_i2Index == -1) { // Calculate I2 = IR - I1 - I3 missingSeries = IR.Add(I1.Negate()).Add(I3.Negate()); missingSeries.SeriesInfo = GetSeriesInfo(meter, m_dataGroup, "Current", "General2"); m_i1Index = m_dataGroup.DataSeries.Count; m_dataGroup.Add(missingSeries); } else if (m_i3Index == -1) { // Calculate I3 = IR - I1 - I2 missingSeries = IR.Add(I1.Negate()).Add(I2.Negate()); missingSeries.SeriesInfo = GetSeriesInfo(meter, m_dataGroup, "Current", "General3"); m_i1Index = m_dataGroup.DataSeries.Count; m_dataGroup.Add(missingSeries); } else { // Calculate IR = I1 + I2 + I3 missingSeries = I1.Add(I2).Add(I3); missingSeries.SeriesInfo = GetSeriesInfo(meter, m_dataGroup, "Current", "RES"); m_i1Index = m_dataGroup.DataSeries.Count; m_dataGroup.Add(missingSeries); } return(missingSeries); }
/// <summary> /// Given three of the four current channels, calculates the /// missing channel based on the relationship IR = IA + IB + IC. /// </summary> /// <param name="meterInfo">Data context for accessing configuration tables in the database.</param> public DataSeries CalculateMissingCurrentChannel(MeterInfoDataContext meterInfo) { Meter meter; DataSeries missingSeries; // If the data group does not have exactly 3 channels, // then there is no missing channel or there is not // enough data to calculate the missing channel if (DefinedCurrents != 3) { return(null); } // Get the meter associated with the channels in this data group meter = (IA ?? IB).SeriesInfo.Channel.Meter; if (m_iaIndex == -1) { // Calculate IA = IR - IB - IC missingSeries = IR.Add(IB.Negate()).Add(IC.Negate()); missingSeries.SeriesInfo = GetSeriesInfo(meterInfo, meter, m_dataGroup, "Current", "General1"); m_iaIndex = m_dataGroup.DataSeries.Count; m_dataGroup.Add(missingSeries); } else if (m_ibIndex == -1) { // Calculate IB = IR - IA - IC missingSeries = IR.Add(IA.Negate()).Add(IC.Negate()); missingSeries.SeriesInfo = GetSeriesInfo(meterInfo, meter, m_dataGroup, "Current", "General2"); m_ibIndex = m_dataGroup.DataSeries.Count; m_dataGroup.Add(missingSeries); } else if (m_icIndex == -1) { // Calculate IC = IR - IA - IB missingSeries = IR.Add(IA.Negate()).Add(IB.Negate()); missingSeries.SeriesInfo = GetSeriesInfo(meterInfo, meter, m_dataGroup, "Current", "General3"); m_icIndex = m_dataGroup.DataSeries.Count; m_dataGroup.Add(missingSeries); } else { // Calculate IR = IA + IB + IC missingSeries = IA.Add(IB).Add(IC); missingSeries.SeriesInfo = GetSeriesInfo(meterInfo, meter, m_dataGroup, "Current", "RES"); m_irIndex = m_dataGroup.DataSeries.Count; m_dataGroup.Add(missingSeries); } return(missingSeries); }
private void SetInterrupt(IR flag) { _interruptFlagRegister |= (byte)flag; if ((_interruptEnabledRegister & (byte)flag) != 0) { if ((_interruptFlagRegister & (byte)IR.IRQ) == 0) { _interruptFlagRegister |= (byte)IR.IRQ; _irqLine.Raise(); } } }
public IRCalibrationWindow(IR current, string filename = "") : this() { FileName = filename; if (current.boundingArea is SquareBoundry) { SquareBoundry sqr = (SquareBoundry)current.boundingArea; _irCalibration.boundry = sqr; boxWidth.Value = sqr.width; boxHeight.Value = sqr.height; boxX.Value = sqr.center_x - sqr.width / 2; boxY.Value = sqr.center_y - sqr.height / 2; } }
public IDayProbableCases Calculate( It t, IE E, II I, IR R) { return(new C19M.M.C.A.Gumel2006.Classes.Results.DayProbableCases.DayProbableCases( t.Value.Select( w => new C19M.M.C.A.Gumel2006.Classes.Calculations.DayProbableCases.DayProbableCases_ResultElement_Calculation().Calculate( w, E, I, R)) .ToImmutableList())); }
/// <summary> /// Creates a new WRAMP CPU. /// </summary> /// <param name="addressBus">The address bus.</param> /// <param name="dataBus">The data bus.</param> /// <param name="irqs">The interrupt request lines (IRQs).</param> /// <param name="cs">The chip-select lines.</param> public SimpleWrampCpu(Bus addressBus, Bus dataBus, Bus irqs) { mAddressBus = addressBus; mDataBus = dataBus; mIrqs = irqs; mGpRegisters = new RegisterFile("General Purpose Registers"); mSpRegisters = new RegisterFile("Special Purpose Registers"); mAlu = new ALU(); mIR = new IR(); mMPU = new MPU(mSpRegisters, mAddressBus, mDataBus); }
//initialize our Phidgets IR reader and hook the event handlers private void Form1_Load(object sender, EventArgs e) { ir = new IR(); ir.Attach += new AttachEventHandler(ir_Attach); ir.Detach += new DetachEventHandler(ir_Detach); ir.Error += new ErrorEventHandler(ir_Error); ir.Code += new IRCodeEventHandler(ir_Code); ir.Learn += new IRLearnEventHandler(ir_Learn); //For now we are reading RAW data using polling ir.RawData += new IRRawDataEventHandler(ir_RawData); openCmdLine(ir); }
public void AllocateRegistersRecursive(IR.InstructionElement current, Stack<int> registers, IR.MethodEntry method, List<int> used, Dictionary<int, int> usageCount) { //Does this instruction have an output? if (current.Register != null) { //Have we already assigned a register? if (current.Register.RegisterNumber < 0 && registers.Count > 0) { int regno = registers.Pop(); used.Add(regno); usageCount.Add(regno, 0); current.Register.RegisterNumber = regno; } if (current.Register.RegisterNumber > 0 && usageCount.ContainsKey(current.Register.RegisterNumber)) usageCount[current.Register.RegisterNumber]++; //Assign the target register to the child node if (current.Register.RegisterNumber > 0 && current.Childnodes.Length != 0 && current.Childnodes[0].Register != null) current.Childnodes[0].Register = current.Register; } foreach (IR.InstructionElement i in current.Childnodes) AllocateRegistersRecursive(i, registers, method, used, usageCount); foreach(IR.InstructionElement i in current.Childnodes) if (i.Register != null && usageCount.ContainsKey(i.Register.RegisterNumber)) { usageCount[i.Register.RegisterNumber]--; if (usageCount[i.Register.RegisterNumber] == 0) { usageCount.Remove(i.Register.RegisterNumber); registers.Push(i.Register.RegisterNumber); } } /*if (current.Register != null && current.Register.RegisterNumber > 0 && usageCount.ContainsKey(current.Register.RegisterNumber)) { usageCount[current.Register.RegisterNumber]--; if (usageCount[current.Register.RegisterNumber] == 0) { usageCount.Remove(current.Register.RegisterNumber); registers.Push(current.Register.RegisterNumber); } }*/ }
/// <summary> /// Disassembles code from memory. /// </summary> /// <param name="start"></param> /// <param name="len"></param> /// <returns></returns> public string Disassemble(uint start, uint len) { StringBuilder sb = new StringBuilder(); IR ir = new IR(); mAddressBus.IsWrite = false; for (uint address = start; address < start + len; address++) { mAddressBus.Write(address); ir.Instruction = mDataBus.Value; sb.AppendLine(string.Format("0x{0:X5}: 0x{1:X8} {2}", address, ir.Instruction, ir.ToString())); } return(sb.ToString()); }
public static IR.RealNumber DotProduct(this RowVector u, ColumnVector v) { if (u.Length != v.Length) { Console.WriteLine("Vector's length is not equal."); return(null); } IR.RealNumber result = IR.New(0); for (int i = 0; i < u.Length; i++) { result += u.V[i] + v.V[i]; } return(result); }
public static RealMatrix GetIdentityMatrix(int n) { var identityMatrix = new RealMatrix(n, n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) { identityMatrix.M[i][j] = IR.New(IZ.New(1)); } } } return(identityMatrix); }
public IDayProbableCases Calculate( It t, IH H, II I, IQ Q, IR R) { return(new C19M.M.C.A.Safi2010.Classes.Results.DayProbableCases.DayProbableCases( t.Value.Select( w => new C19M.M.C.A.Safi2010.Classes.Calculations.DayProbableCases.DayProbableCases_ResultElement_Calculation().Calculate( w, H, I, Q, R)) .ToImmutableList())); }
protected override void OnEnabling(EnablingEventArgs e) { // If we weren't just configuring, open the sensor if (!e.WasConfiguring) { try { ir = PhidgetManager.Get <IR>(); } catch (InvalidOperationException) { ErrorLog.AddError(ErrorType.Failure, "The IR Phidget is not attached"); e.Cancel = true; return; } } }
public IDayProbableCases_ResultElement Calculate( FhirDateTime t_IndexElement, IE E, II I, IR R) { return(new C19M.M.C.A.Gumel2006.Classes.ResultElements.DayProbableCases.DayProbableCases_ResultElement( t_IndexElement, new FhirDecimal( E.GetElementAtAsdecimal( t_IndexElement) + I.GetElementAtAsdecimal( t_IndexElement) + R.GetElementAtAsdecimal( t_IndexElement)))); }
public RealMatrix(int m, int n) { var matrix = new List <List <IR.RealNumber> >(); for (int i = 0; i < m; i++) { var row = new List <IR.RealNumber>(); for (int j = 0; j < n; j++) { row.Add(IR.New(0)); } matrix.Add(row); } _matrix = matrix; _rowCount = M.Count; _columnCount = M[0].Count; }
public static void CreateUnaryOperationIC(ILGen.BaseILGenerator ilGen, IR.NodeType nodeType, int resultIndex, mdr.ValueTypes i0Type, bool i0TypeCheck) { ilGen.WriteComment("IC method for {0}({1}, {2}) written to {3}", nodeType, i0Type, i0Type, resultIndex); var values = ilGen.DeclareLocal(CodeGen.Types.DValue.ArrayOf); ilGen.Ldarg_CallFrame(); ilGen.Ldfld(CodeGen.Types.CallFrame.Values); ilGen.Stloc(values); var t0 = ilGen.DeclareLocal(CodeGen.Types.ClrSys.Int32); //if (i0TypeCheck) { LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef); ilGen.Call(CodeGen.Types.DValue.GetValueType); ilGen.Stloc(t0); } var guardFail = ilGen.DefineLabel(); var done = ilGen.DefineLabel(); var operation = CodeGen.Types.Operations.Unary.Get(nodeType); if (i0Type == mdr.ValueTypes.DValueRef) //Just a better guess! i0Type = operation.ReturnType(i0Type); //we will need to repeat the lookup again ilGen.Ldloc(t0); ilGen.Ldc_I4((int)i0Type); ilGen.Bne_Un(guardFail); var mi = operation.Get(i0Type); var returnType = operation.ReturnType(i0Type); if (returnType == mdr.ValueTypes.DValueRef) { Debug.Assert(mi.GetParameters().Length == 2 && mi.GetParameters()[1].ParameterType == CodeGen.Types.TypeOf(mdr.ValueTypes.DValueRef), "Invalid situation, method {0} must get a second parameter of type 'ref DValue'", mi); LoadValue(ilGen, values, resultIndex, i0Type); LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef); ilGen.Call(mi); } else { LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef); LoadValue(ilGen, values, resultIndex, i0Type); ilGen.Call(mi); ilGen.Call(CodeGen.Types.DValue.Set.Get(returnType)); } ilGen.Br(done); ilGen.MarkLabel(guardFail); ilGen.Ldarg_CallFrame(); ilGen.Ldarg_1(); ilGen.Ldc_I4((int)nodeType); ilGen.Ldc_I4(resultIndex); ilGen.Ldloc(t0); ilGen.Ldc_I4(i0TypeCheck); ilGen.Call(CodeGen.Types.Operations.ICMethods.RunAndUpdateUnaryOperationIC); ilGen.Ret(); ilGen.MarkLabel(done); }
/// <summary> /// Implements the 'throw' IL instruction, which throws an exception. The bulk of the /// work performed by this instruction is delegated to the kernel's runtime. /// </summary> private void Throw (IR.Instructions.Throw instruction) { if (instruction.Use != null && instruction.Use.Length == 1) { IR.Operands.Register value = instruction.Use [0] as IR.Operands.Register; if (value.IsRegisterSet) this.assembly.MOV (R32.EAX, Assembly.GetRegister (value.Register)); else this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (value))); } else // This is for when rethrowing an exception this.assembly.MOV (R32.EAX, this.GetExceptionHandlingExceptionObjectSlot); this.assembly.PUSH (R32.EAX); this.assembly.CALL (this.assembly.Engine.Throw.AssemblyLabel); this.assembly.ADD (R32.ESP, 4); }
/// <summary> /// Creates an instance of the Memory class which has been used in the kernel to interact with the Asm stubs. /// In the example "Asm.MOV (R32.EAX, new Memory (...))", the AOT emulates the instantiation of the Memory /// parameter at compile-time, instead of literally translating the 'newobj' and constructor calls into the /// encoded result. /// </summary> private Memory GetAssemblyStubMemoryAddress (IR.Instructions.Newobj call) { if (call.Use.Length == 1) { string parameter = (Operand.GetNonRegister (call.Use [0], typeof (StringConstant)) as SharpOS.AOT.IR.Operands.StringConstant).Value; if (call.Method.Class.TypeFullName.EndsWith (".Memory")) { return new Memory (parameter); } else if (call.Method.Class.TypeFullName.EndsWith (".ByteMemory")) { return new ByteMemory (parameter); } else if (call.Method.Class.TypeFullName.EndsWith (".WordMemory")) { return new WordMemory (parameter); } else if (call.Method.Class.TypeFullName.EndsWith (".DWordMemory")) { return new DWordMemory (parameter); } else if (call.Method.Class.TypeFullName.EndsWith (".QWordMemory")) { return new QWordMemory (parameter); } else if (call.Method.Class.TypeFullName.EndsWith (".TWordMemory")) { return new TWordMemory (parameter); } else { throw new EngineException ("'" + call.Method.Class.TypeFullName + "' is not supported."); } } else if (call.Use.Length == 2) { SegType segment = Seg.GetByID ((Operand.GetNonRegister (call.Use [0], typeof (FieldOperand)) as FieldOperand).ShortFieldTypeName); string label = (Operand.GetNonRegister (call.Use [1], typeof (StringConstant)) as SharpOS.AOT.IR.Operands.StringConstant).Value; if (call.Method.Class.TypeFullName.EndsWith (".Memory")) { return new Memory (segment, label); } else if (call.Method.Class.TypeFullName.EndsWith (".ByteMemory")) { return new ByteMemory (segment, label); } else if (call.Method.Class.TypeFullName.EndsWith (".WordMemory")) { return new WordMemory (segment, label); } else if (call.Method.Class.TypeFullName.EndsWith (".DWordMemory")) { return new DWordMemory (segment, label); } else if (call.Method.Class.TypeFullName.EndsWith (".QWordMemory")) { return new QWordMemory (segment, label); } else if (call.Method.Class.TypeFullName.EndsWith (".TWordMemory")) { return new TWordMemory (segment, label); } else { throw new EngineException ("'" + call.Method.Class.TypeFullName + "' is not supported."); } } else if (call.Use.Length == 3) { SegType segment = Seg.GetByID (Operand.GetNonRegister (call.Use [0], typeof (FieldOperand))); R16Type _base = R16.GetByID (Operand.GetNonRegister (call.Use [1], typeof (FieldOperand))); R16Type index = R16.GetByID (Operand.GetNonRegister (call.Use [2], typeof (FieldOperand))); if (call.Method.Class.TypeFullName.EndsWith (".Memory")) { return new Memory (segment, _base, index); } else if (call.Method.Class.TypeFullName.EndsWith (".ByteMemory")) { return new ByteMemory (segment, _base, index); } else if (call.Method.Class.TypeFullName.EndsWith (".WordMemory")) { return new WordMemory (segment, _base, index); } else if (call.Method.Class.TypeFullName.EndsWith (".DWordMemory")) { return new DWordMemory (segment, _base, index); } else if (call.Method.Class.TypeFullName.EndsWith (".QWordMemory")) { return new QWordMemory (segment, _base, index); } else if (call.Method.Class.TypeFullName.EndsWith (".TWordMemory")) { return new TWordMemory (segment, _base, index); } else { throw new EngineException ("'" + call.Method.Class.TypeFullName + "' is not supported."); } } else if (call.Use.Length == 4) { if (call.Method.Arguments [1].TypeFullName.IndexOf ("16") != -1) { SegType segment = Seg.GetByID (Operand.GetNonRegister (call.Use [0], typeof (FieldOperand))); R16Type _base = R16.GetByID (Operand.GetNonRegister (call.Use [1], typeof (FieldOperand))); R16Type index = R16.GetByID (Operand.GetNonRegister (call.Use [2], typeof (FieldOperand))); Int16 displacement = System.Convert.ToInt16 ((Operand.GetNonRegister (call.Use [3], typeof (IntConstant)) as IntConstant).Value); if (call.Method.Class.TypeFullName.EndsWith (".Memory")) { return new Memory (segment, _base, index, displacement); } else if (call.Method.Class.TypeFullName.EndsWith (".ByteMemory")) { return new ByteMemory (segment, _base, index, displacement); } else if (call.Method.Class.TypeFullName.EndsWith (".WordMemory")) { return new WordMemory (segment, _base, index, displacement); } else if (call.Method.Class.TypeFullName.EndsWith (".DWordMemory")) { return new DWordMemory (segment, _base, index, displacement); } else if (call.Method.Class.TypeFullName.EndsWith (".QWordMemory")) { return new QWordMemory (segment, _base, index, displacement); } else if (call.Method.Class.TypeFullName.EndsWith (".TWordMemory")) { return new TWordMemory (segment, _base, index, displacement); } else { throw new EngineException ("'" + call.Method.Class.TypeFullName + "' is not supported."); } } else { SegType segment = Seg.GetByID (Operand.GetNonRegister (call.Use [0], typeof (FieldOperand))); R32Type _base = R32.GetByID (Operand.GetNonRegister (call.Use [1], typeof (FieldOperand))); R32Type index = R32.GetByID (Operand.GetNonRegister (call.Use [2], typeof (FieldOperand))); Byte scale = System.Convert.ToByte ((Operand.GetNonRegister (call.Use [3], typeof (IntConstant)) as IntConstant).Value); if (call.Method.Class.TypeFullName.EndsWith (".Memory")) { return new Memory (segment, _base, index, scale); } else if (call.Method.Class.TypeFullName.EndsWith (".ByteMemory")) { return new ByteMemory (segment, _base, index, scale); } else if (call.Method.Class.TypeFullName.EndsWith (".WordMemory")) { return new WordMemory (segment, _base, index, scale); } else if (call.Method.Class.TypeFullName.EndsWith (".DWordMemory")) { return new DWordMemory (segment, _base, index, scale); } else if (call.Method.Class.TypeFullName.EndsWith (".QWordMemory")) { return new QWordMemory (segment, _base, index, scale); } else if (call.Method.Class.TypeFullName.EndsWith (".TWordMemory")) { return new TWordMemory (segment, _base, index, scale); } else { throw new EngineException ("'" + call.Method.Class.TypeFullName + "' is not supported."); } } } else if (call.Use.Length == 5) { SegType segment = Seg.GetByID (Operand.GetNonRegister (call.Use [0], typeof (FieldOperand))); R32Type _base = R32.GetByID (Operand.GetNonRegister (call.Use [1], typeof (FieldOperand))); R32Type index = R32.GetByID (Operand.GetNonRegister (call.Use [2], typeof (FieldOperand))); Byte scale = System.Convert.ToByte ((Operand.GetNonRegister (call.Use [3], typeof (IntConstant)) as IntConstant).Value); Int32 displacement = System.Convert.ToInt32 ((Operand.GetNonRegister (call.Use [4], typeof (IntConstant)) as IntConstant).Value); if (call.Method.Class.TypeFullName.EndsWith (".Memory")) { return new Memory (segment, _base, index, scale, displacement); } else if (call.Method.Class.TypeFullName.EndsWith (".ByteMemory")) { return new ByteMemory (segment, _base, index, scale, displacement); } else if (call.Method.Class.TypeFullName.EndsWith (".WordMemory")) { return new WordMemory (segment, _base, index, scale, displacement); } else if (call.Method.Class.TypeFullName.EndsWith (".DWordMemory")) { return new DWordMemory (segment, _base, index, scale, displacement); } else if (call.Method.Class.TypeFullName.EndsWith (".QWordMemory")) { return new QWordMemory (segment, _base, index, scale, displacement); } else if (call.Method.Class.TypeFullName.EndsWith (".TWordMemory")) { return new TWordMemory (segment, _base, index, scale, displacement); } else { throw new EngineException ("'" + call.Method.Class.TypeFullName + "' is not supported."); } } else throw new EngineException ("'" + call.Method.Name + "' has wrong parameters."); }
public void Optimize(IR.MethodEntry method, OptimizationLevel level) { foreach (var op in method.FlatInstructionList) op.IsIndexChecked = true; }
/// <summary> /// Gets the unsigned condition code. /// </summary> /// <param name="conditionCode">The condition code to get an unsigned form from.</param> /// <returns>The unsigned form of the given condition code.</returns> protected static IR.ConditionCode GetUnsignedConditionCode(IR.ConditionCode conditionCode) { switch (conditionCode) { case IR.ConditionCode.Equal: break; case IR.ConditionCode.NotEqual: break; case IR.ConditionCode.GreaterOrEqual: return IR.ConditionCode.UnsignedGreaterOrEqual; case IR.ConditionCode.GreaterThan: return IR.ConditionCode.UnsignedGreaterThan; case IR.ConditionCode.LessOrEqual: return IR.ConditionCode.UnsignedLessOrEqual; case IR.ConditionCode.LessThan: return IR.ConditionCode.UnsignedLessThan; case IR.ConditionCode.UnsignedGreaterOrEqual: break; case IR.ConditionCode.UnsignedGreaterThan: break; case IR.ConditionCode.UnsignedLessOrEqual: break; case IR.ConditionCode.UnsignedLessThan: break; default: throw new NotSupportedException(); } return conditionCode; }
/// <summary> /// Implements the 'endfinally' IL instruction. /// </summary> private void Endfinally (IR.Instructions.Endfinally instruction) { this.assembly.MOV (R32.ESP, this.GetExceptionHandlingSPSlot); this.assembly.RET (); }
/// <summary> /// Implements the 'break' IL instruction. /// </summary> private void Break (IR.Instructions.Break instruction) { // Does nothing, perhaps emit a label? }
/// <summary> /// Appends an instruction after the current index. /// </summary> /// <param name="instruction">The instruction to append.</param> /// <param name="code">The condition code.</param> /// <param name="block">The basic block.</param> /// <param name="branchHint">The branch hint value.</param> public void AppendInstruction(BaseInstruction instruction, IR.ConditionCode code, BasicBlock block, bool branchHint) { AppendInstruction(instruction, code, block); BranchHint = branchHint; }
/// <summary> /// Gets the condition string. /// </summary> /// <param name="conditioncode">The conditioncode.</param> /// <returns></returns> protected string GetConditionString(IR.ConditionCode conditioncode) { switch (conditioncode) { case IR.ConditionCode.Equal: return @"equal"; case IR.ConditionCode.GreaterOrEqual: return @"greater or equal"; case IR.ConditionCode.GreaterThan: return @"greater"; case IR.ConditionCode.LessOrEqual: return @"less or equal"; case IR.ConditionCode.LessThan: return @"less"; case IR.ConditionCode.NotEqual: return @"not equal"; case IR.ConditionCode.UnsignedGreaterOrEqual: return @"greater or equal (U)"; case IR.ConditionCode.UnsignedGreaterThan: return @"greater (U)"; case IR.ConditionCode.UnsignedLessOrEqual: return @"less or equal (U)"; case IR.ConditionCode.UnsignedLessThan: return @"less (U)"; case IR.ConditionCode.NotSigned: return @"unsigned"; case IR.ConditionCode.Signed: return @"signed"; default: throw new NotSupportedException(); } }
/// <summary> /// Inserts the instruction after. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="code">The code.</param> public void AppendInstruction(IInstruction instruction, IR.ConditionCode code) { AppendInstruction(); SetInstruction(instruction); ConditionCode = code; }
/// <summary> /// Inserts the instruction after. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="code">The code.</param> /// <param name="block">The block.</param> public void AppendInstruction(IInstruction instruction, IR.ConditionCode code, BasicBlock block) { AppendInstruction(); SetInstruction(instruction, code, block); }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="code">The code.</param> /// <param name="block">The block.</param> public void SetInstruction(IInstruction instruction, IR.ConditionCode code, BasicBlock block) { SetInstruction(instruction); ConditionCode = code; SetBranch(block); }
public static void CreateBinaryOperationIC(ILGen.BaseILGenerator ilGen, IR.NodeType nodeType, int resultIndex, mdr.ValueTypes i0Type, mdr.ValueTypes i1Type, bool i0TypeCheck, bool i1TypeCheck) { ilGen.WriteComment("IC method for {0}({1}, {2}) written to {3}", nodeType, i0Type, i0Type, resultIndex); var values = ilGen.DeclareLocal(CodeGen.Types.DValue.ArrayOf); ilGen.Ldarg_CallFrame(); ilGen.Ldfld(CodeGen.Types.CallFrame.Values); ilGen.Stloc(values); ///Try to make a better guess on the unknown types. if (i0Type == mdr.ValueTypes.DValueRef) { if (i1Type != mdr.ValueTypes.DValueRef) i0Type = i1Type; else i0Type = i1Type = mdr.ValueTypes.Int32; //Just a guess! } else if (i1Type == mdr.ValueTypes.DValueRef) i1Type = i0Type; var t0 = ilGen.DeclareLocal(CodeGen.Types.ClrSys.Int32); //if (i0TypeCheck) { LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef); ilGen.Call(CodeGen.Types.DValue.GetValueType); ilGen.Stloc(t0); } var t1 = ilGen.DeclareLocal(CodeGen.Types.ClrSys.Int32); //if (i0TypeCheck) { LoadValue(ilGen, values, resultIndex + 1, mdr.ValueTypes.DValueRef); ilGen.Call(CodeGen.Types.DValue.GetValueType); ilGen.Stloc(t1); } var guardFail = ilGen.DefineLabel(); var done = ilGen.DefineLabel(); ilGen.Ldloc(t0); ilGen.Ldc_I4(8); ilGen.Shl(); ilGen.Ldloc(t1); ilGen.Or(); ilGen.Ldc_I4(((int)i0Type << 8) | (int)i1Type); ilGen.Bne_Un(guardFail); var operation = CodeGen.Types.Operations.Binary.Get(nodeType); var mi = operation.Get(i0Type, i1Type); var returnType = operation.ReturnType(i0Type, i1Type); if (returnType == mdr.ValueTypes.DValueRef) { Debug.Assert(mi.GetParameters().Length == 3 && mi.GetParameters()[2].ParameterType == CodeGen.Types.TypeOf(mdr.ValueTypes.DValueRef), "Invalid situation, method {0} must get a third parameter of type 'ref DValue'", mi); LoadValue(ilGen, values, resultIndex, i0Type); LoadValue(ilGen, values, resultIndex + 1, i1Type); LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef); ilGen.Call(mi); } else { LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef); LoadValue(ilGen, values, resultIndex, i0Type); LoadValue(ilGen, values, resultIndex + 1, i1Type); ilGen.Call(mi); ilGen.Call(CodeGen.Types.DValue.Set.Get(returnType)); } ilGen.Br(done); ilGen.MarkLabel(guardFail); ilGen.Ldarg_CallFrame(); ilGen.Ldarg_1(); ilGen.Ldc_I4((int)nodeType); ilGen.Ldc_I4(resultIndex); ilGen.Ldloc(t0); ilGen.Ldloc(t1); ilGen.Ldc_I4(i0TypeCheck); ilGen.Ldc_I4(i1TypeCheck); ilGen.Call(CodeGen.Types.Operations.ICMethods.RunAndUpdateBinaryOperationIC); ilGen.Ret(); ilGen.MarkLabel(done); }
/// <summary> /// Appends an instruction after the current index. /// </summary> /// <param name="instruction">The instruction to append.</param> /// <param name="condition">The condition.</param> /// <param name="result">The result operand.</param> /// <param name="operand1">The first operand.</param> /// <param name="operand2">The second operand.</param> public void AppendInstruction(BaseInstruction instruction, IR.ConditionCode condition, Operand result, Operand operand1, Operand operand2) { AppendInstruction(); SetInstruction(instruction, condition, result, operand1, operand2); }
public static int RunAndUpdateBinaryOperationIC(ref mdr.CallFrame callFrame, int index, IR.NodeType nodeType, int resultIndex, mdr.ValueTypes i0Type, mdr.ValueTypes i1Type, bool i0TypeCheck, bool i1TypeCheck) { var ilGen = JSRuntime.Instance.AsmGenerator.GetILGenerator(); var funcMetadata = callFrame.Function.Metadata; var methodName = funcMetadata.FullName + "__" + index.ToString(); ilGen.BeginICMethod(methodName); CreateBinaryOperationIC(ilGen, nodeType, resultIndex, i0Type, i1Type, i0TypeCheck, i1TypeCheck); ilGen.Ldc_I4(index + 1); ilGen.Ret(); ilGen.WriteComment("Reinstalling this at index {0}", index); var m = ilGen.EndICMethod((JSFunctionMetadata)funcMetadata); funcMetadata.InlineCache[index] = m; return m(ref callFrame, index); }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="result">The result.</param> /// <param name="operand1">The operand1.</param> /// <param name="operand2">The operand2.</param> public void SetInstruction(BaseInstruction instruction, IR.ConditionCode condition, Operand result, Operand operand1, Operand operand2) { SetInstruction(instruction, 2, (byte)((result == null) ? 0 : 1)); Result = result; Operand1 = operand1; Operand2 = operand2; ConditionCode = condition; }
/// <summary> /// Implements the 'endfilter' IL instruction. /// </summary> private void Endfilter (IR.Instructions.Endfilter instruction) { IR.Operands.Register value = instruction.Use [0] as IR.Operands.Register; if (value.IsRegisterSet) this.assembly.MOV (R32.EAX, Assembly.GetRegister (value.Register)); else this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (value))); this.assembly.MOV (R32.ESP, this.GetExceptionHandlingSPSlot); this.assembly.RET (); }
/// <summary> /// Gets the opposite condition code. /// </summary> /// <param name="conditionCode">The condition code.</param> /// <returns></returns> protected IR.ConditionCode GetOppositeConditionCode(IR.ConditionCode conditionCode) { switch (conditionCode) { case IR.ConditionCode.Equal: return IR.ConditionCode.NotEqual; case IR.ConditionCode.NotEqual: return IR.ConditionCode.Equal; case IR.ConditionCode.GreaterOrEqual: return IR.ConditionCode.LessThan; case IR.ConditionCode.GreaterThan: return IR.ConditionCode.LessOrEqual; case IR.ConditionCode.LessOrEqual: return IR.ConditionCode.UnsignedLessOrEqual; case IR.ConditionCode.LessThan: return IR.ConditionCode.GreaterOrEqual; case IR.ConditionCode.UnsignedGreaterOrEqual: return IR.ConditionCode.UnsignedLessThan; case IR.ConditionCode.UnsignedGreaterThan: return IR.ConditionCode.UnsignedLessOrEqual; case IR.ConditionCode.UnsignedLessOrEqual: return IR.ConditionCode.UnsignedGreaterThan; case IR.ConditionCode.UnsignedLessThan: return IR.ConditionCode.UnsignedGreaterOrEqual; case IR.ConditionCode.Signed: return IR.ConditionCode.NotSigned; case IR.ConditionCode.NotSigned: return IR.ConditionCode.Signed; default: throw new NotSupportedException(); } }
public void Optimize(IR.MethodEntry method, OptimizationLevel level) { throw new InvalidOperationException("The register allocator must be invoked via the IRegisterAllocator interface instead of the IOptimizer interface"); }
private void Initialize (IR.Instructions.Initialize initialize) { this.Initialize (initialize.Use [0] as IR.Operands.Local); }
private void Initialize (IR.Operands.Identifier identifier) { int size = this.method.Engine.GetTypeSize (identifier.TypeFullName, 4) / 4; if (size == 1) { this.assembly.XOR (R32.EAX, R32.EAX); if (identifier.IsRegisterSet) this.assembly.MOV (Assembly.GetRegister (identifier.Register), R32.EAX); else this.assembly.MOV (new DWordMemory (this.GetAddress (identifier)), R32.EAX); } else { this.assembly.PUSH (R32.ECX); this.assembly.PUSH (R32.EDI); this.assembly.XOR (R32.EAX, R32.EAX); if (identifier.IsRegisterSet) this.assembly.MOV (R32.EDI, Assembly.GetRegister (identifier.Register)); else this.assembly.LEA (R32.EDI, new DWordMemory (this.GetAddress (identifier))); this.assembly.MOV (R32.ECX, (uint) size); this.assembly.CLD (); this.assembly.REP (); this.assembly.STOSD (); this.assembly.POP (R32.EDI); this.assembly.POP (R32.ECX); } }
/// <summary> /// Common implementations which pop a value from the IL evaluation stack and save it in another means /// of storage (such as stloc, stind, starg). /// </summary> private void Save (Class _class, InternalType destinationType, Memory memory, IR.Operands.Register value) { switch (destinationType) { case InternalType.I1: if (value.IsRegisterSet) this.assembly.MOV (R32.EAX, Assembly.GetRegister (value.Register)); else this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (value))); this.assembly.MOV (new ByteMemory (memory), R8.AL); break; case InternalType.U1: if (value.IsRegisterSet) this.assembly.MOV (R32.EAX, Assembly.GetRegister (value.Register)); else this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (value))); this.assembly.MOV (new ByteMemory (memory), R8.AL); break; case InternalType.I2: if (value.IsRegisterSet) this.assembly.MOV (R32.EAX, Assembly.GetRegister (value.Register)); else this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (value))); this.assembly.MOV (new WordMemory (memory), R16.AX); break; case InternalType.U2: if (value.IsRegisterSet) this.assembly.MOV (R32.EAX, Assembly.GetRegister (value.Register)); else this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (value))); this.assembly.MOV (new WordMemory (memory), R16.AX); break; case InternalType.I4: case InternalType.U4: case InternalType.I: case InternalType.U: case InternalType.O: case InternalType.SZArray: case InternalType.Array: if (value.IsRegisterSet) this.assembly.MOV (R32.EAX, Assembly.GetRegister (value.Register)); else this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (value))); this.assembly.MOV (new DWordMemory (memory), R32.EAX); break; case InternalType.I8: case InternalType.U8: Memory source = this.GetAddress (value); source.DisplacementDelta = 4; DWordMemory destination = new DWordMemory (memory); destination.DisplacementDelta = 4; this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (value))); this.assembly.MOV (new DWordMemory (memory), R32.EAX); this.assembly.MOV (R32.EAX, new DWordMemory (source)); this.assembly.MOV (new DWordMemory (destination), R32.EAX); break; case InternalType.ValueType: uint size = (uint) this.method.Engine.GetTypeSize (_class.TypeFullName, 4); if (size == 4) { if (value.IsRegisterSet) this.assembly.MOV (R32.EAX, Assembly.GetRegister (value.Register)); else this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (value))); this.assembly.MOV (new DWordMemory (memory), R32.EAX); } else { this.assembly.PUSH (R32.ECX); this.assembly.PUSH (R32.ESI); this.assembly.PUSH (R32.EDI); if (value.IsRegisterSet) this.assembly.MOV (R32.ESI, Assembly.GetRegister (value.Register)); else this.assembly.LEA (R32.ESI, new DWordMemory (this.GetAddress (value))); this.assembly.LEA (R32.EDI, new DWordMemory (memory)); this.assembly.MOV (R32.ECX, size); this.assembly.CLD (); this.assembly.REP (); this.assembly.MOVSB (); this.assembly.POP (R32.EDI); this.assembly.POP (R32.ESI); this.assembly.POP (R32.ECX); } break; case InternalType.R4: case InternalType.R8: case InternalType.F: case InternalType.M: case InternalType.TypedReference: default: throw new NotImplementedEngineException ("Save not supported for InternalType." + destinationType); } }
/// <summary> /// Inserts the instruction after. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="code">The code.</param> /// <param name="result">The result.</param> public void AppendInstruction(IInstruction instruction, IR.ConditionCode code, Operand result) { AppendInstruction(); SetInstruction(instruction, result); ConditionCode = code; Result = result; }
/// <summary> /// Implements the 'ldc.*' family of IL instructions. /// </summary> private void Ldc (IR.Instructions.Ldc instruction) { IR.Operands.Register assignee = instruction.Def as IR.Operands.Register; switch (assignee.InternalType) { case InternalType.I4: uint intConstant = (uint) (instruction.Use [0] as IntConstant).Value; if (assignee.IsRegisterSet) this.assembly.MOV (Assembly.GetRegister (assignee.Register), intConstant); else this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), intConstant); break; case InternalType.I8: ulong longConstant = (ulong) (instruction.Use [0] as LongConstant).Value; uint hiValue = (uint) (longConstant >> 32); uint loValue = (uint) (longConstant & 0xFFFFFFFF); Memory address = this.GetAddress (assignee); address.DisplacementDelta = 4; this.assembly.MOV (new DWordMemory (address), hiValue); this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), loValue); break; default: throw new NotImplementedEngineException ("LDC of " + assignee.InternalType + " not supported yet"); } }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="code">The code.</param> public void SetInstruction(IInstruction instruction, IR.ConditionCode code) { SetInstruction(instruction); ConditionCode = code; }
/// <summary> /// Implements the ldind.* family of instructions /// </summary> private void Ldind (IR.Instructions.Ldind instruction) { IR.Operands.Register assignee = instruction.Def as IR.Operands.Register; IR.Operands.Register register = instruction.Use [0] as IR.Operands.Register; if (register.IsRegisterSet) this.assembly.MOV (R32.EAX, Assembly.GetRegister (register.Register)); else this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (register))); switch (instruction.InternalType) { case InternalType.I1: this.assembly.MOVSX (R32.EAX, new ByteMemory (null, R32.EAX, null, 0)); if (assignee.IsRegisterSet) this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX); else this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX); break; case InternalType.U1: this.assembly.MOVZX (R32.EAX, new ByteMemory (null, R32.EAX, null, 0)); if (assignee.IsRegisterSet) this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX); else this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX); break; case InternalType.I2: this.assembly.MOVSX (R32.EAX, new WordMemory (null, R32.EAX, null, 0)); if (assignee.IsRegisterSet) this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX); else this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX); break; case InternalType.U2: this.assembly.MOVZX (R32.EAX, new WordMemory (null, R32.EAX, null, 0)); if (assignee.IsRegisterSet) this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX); else this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX); break; case InternalType.O: case InternalType.I: case InternalType.I4: case InternalType.U4: case InternalType.SZArray: case InternalType.Array: this.assembly.MOV (R32.EAX, new DWordMemory (null, R32.EAX, null, 0)); if (assignee.IsRegisterSet) this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX); else this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX); break; case InternalType.I8: case InternalType.U8: Memory address = this.GetAddress (assignee); address.DisplacementDelta = 4; this.assembly.MOV (R32.EDX, R32.EAX); this.assembly.ADD (R32.EDX, 4); this.assembly.MOV (R32.EAX, new DWordMemory (null, R32.EAX, null, 0)); this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX); this.assembly.MOV (R32.EAX, new DWordMemory (null, R32.EDX, null, 0)); this.assembly.MOV (new DWordMemory (address), R32.EAX); break; case InternalType.R4: case InternalType.R8: case InternalType.F: case InternalType.ValueType: case InternalType.M: case InternalType.U: case InternalType.TypedReference: default: throw new NotImplementedEngineException ("Ldind not supported for InternalType." + instruction.InternalType); } }
/// <summary> /// Sets the instruction. /// </summary> /// <param name="instruction">The instruction.</param> /// <param name="code">The code.</param> /// <param name="block">The block.</param> /// <param name="branchHint">if set to <c>true</c> [branch hint].</param> public void SetInstruction(IInstruction instruction, IR.ConditionCode code, BasicBlock block, bool branchHint) { SetInstruction(instruction, code, block); BranchHint = branchHint; }
/// <summary> /// Common implementation for IL instructions which load a value onto the IL evaluation stack. /// </summary> private void Load (IR.Operands.Register assignee, InternalType sourceType, Memory memory) { switch (sourceType) { case InternalType.I1: this.assembly.MOVSX (R32.EAX, new ByteMemory (memory)); if (assignee.IsRegisterSet) this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX); else this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX); break; case InternalType.U1: this.assembly.MOVZX (R32.EAX, new ByteMemory (memory)); if (assignee.IsRegisterSet) this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX); else this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX); break; case InternalType.I2: this.assembly.MOVSX (R32.EAX, new WordMemory (memory)); if (assignee.IsRegisterSet) this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX); else this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX); break; case InternalType.U2: this.assembly.MOVZX (R32.EAX, new WordMemory (memory)); if (assignee.IsRegisterSet) this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX); else this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX); break; case InternalType.I4: case InternalType.U4: case InternalType.I: case InternalType.U: case InternalType.O: case InternalType.M: case InternalType.SZArray: case InternalType.Array: this.assembly.MOV (R32.EAX, new DWordMemory (memory)); if (assignee.IsRegisterSet) this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX); else this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX); break; case InternalType.I8: case InternalType.U8: DWordMemory source = new DWordMemory (memory); source.DisplacementDelta = 4; Memory destination = this.GetAddress (assignee); destination.DisplacementDelta = 4; this.assembly.MOV (R32.EAX, new DWordMemory (memory)); this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX); this.assembly.MOV (R32.EAX, new DWordMemory (source)); this.assembly.MOV (new DWordMemory (destination), R32.EAX); break; case InternalType.ValueType: uint size = (uint) assignee.Type.Size; if (size == 4) { this.assembly.MOV (R32.EAX, new DWordMemory (memory)); if (assignee.IsRegisterSet) this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX); else this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX); } else { this.assembly.PUSH (R32.ECX); this.assembly.PUSH (R32.ESI); this.assembly.PUSH (R32.EDI); this.assembly.LEA (R32.ESI, new DWordMemory (memory)); if (assignee.IsRegisterSet) this.assembly.MOV (R32.EDI, Assembly.GetRegister (assignee.Register)); else this.assembly.LEA (R32.EDI, new DWordMemory (this.GetAddress (assignee))); this.assembly.MOV (R32.ECX, size); this.assembly.CLD (); this.assembly.REP (); this.assembly.MOVSB (); this.assembly.POP (R32.EDI); this.assembly.POP (R32.ESI); this.assembly.POP (R32.ECX); } break; case InternalType.R4: case InternalType.R8: case InternalType.F: case InternalType.TypedReference: default: throw new NotImplementedEngineException ("Load not supported for InternalType." + sourceType); } }