public void GetRegister(OperandType operandType, RegisterIndex registerIndex, out Number4[] register, out int index)
		{
			switch (operandType)
			{
				case OperandType.ConstantBuffer:
					register = _virtualMachine.ConstantBuffers[registerIndex.Index2D_0];
					index = registerIndex.Index2D_1;
					return;
				case OperandType.Input:
					// Only GS requires 2-dimensional inputs, but for simplicity we always use a 2-dimensional input array.
					register = Inputs[registerIndex.Index2D_0];
					index = registerIndex.Index2D_1;
					return;
				case OperandType.Output:
					register = Outputs;
					index = registerIndex.Index1D;
					return;
				case OperandType.Temp:
					register = Temps;
					index = registerIndex.Index1D;
					return;
				case OperandType.IndexableTemp:
					register = IndexableTemps[registerIndex.Index2D_0];
					index = registerIndex.Index2D_1;
					return;
				default:
					throw new ArgumentException("Unsupported operand type: " + operandType);
			}
		}
Example #2
0
 internal MSILOpCode(string name, byte[] bytes, OperandType operandType, StackBehaviour stackBehaviour)
 {
     Name = name;
     Bytes = bytes;
     OperandType = operandType;
     StackBehaviour = stackBehaviour;
 }
Example #3
0
 public RegData(OperandType type, int size, int id, int code)
 {
     _op = checked((byte)type);
     _size = checked((byte)size);
     _id = id;
     _code = code;
 }
 public void Decode(byte[] code, ref int offset, OperandType operand, IState state)
 {
     this.Unknown1 = BitConverter.ToInt16(code, offset + 2).BigEndian();
     this.Unknown2 = BitConverter.ToInt16(code, offset + 4).BigEndian();
     this.Unknown3 = BitConverter.ToInt16(code, offset + 6).BigEndian();
     offset += 8;
 }
Example #5
0
 public Instruction(ushort pos, InstrCode code, OperandType operandType, ulong operand)
 {
     Pos = pos;
     Code = code;
     OperandType = operandType;
     Operand = operand;
 }
 public void Encode(byte[] code, ref int offset, out OperandType operand, IState state)
 {
     operand = OperandType.None;
     Array.Copy(BitConverter.GetBytes(this.Routine.LittleEndian()), 0, code, offset + 2, 2);
     code[offset + 4] = this.ArgumentCount;
     offset += 5;
 }
Example #7
0
        public void Decode(byte[] code, ref int offset, OperandType operand, IState state)
        {
            if (operand != OperandType.None)
            {
                throw new InvalidOperationException();
            }

            offset += 2;
        }
Example #8
0
 protected AutoSizedOperand(OperandType type,
                            OperandValueType valueType = OperandValueType.Dword,
                            bool isPointer = false,
                            bool isOffset = false,
                            Register offsetRegister = Register.R0,
                            int payload = 0)
     : base(type, valueType, isPointer, isOffset, offsetRegister, payload)
 {
 }
        public void Decode(byte[] code, ref int offset, OperandType operand, IState state)
        {
            if (operand != OperandType.None)
            {
                throw new InvalidOperationException();
            }

            this.Value = BitConverter.ToInt32(code, offset + 2).BigEndian();
            offset += 6;
        }
        public void Decode(byte[] code, ref int offset, OperandType operand, IState state)
        {
            if (operand != OperandType.IntegerInteger &&
                operand != OperandType.FloatFloat)
            {
                throw new InvalidOperationException();
            }

            this.Operand = operand;
            offset += 2;
        }
        public void Decode(byte[] code, ref int offset, OperandType operand, IState state)
        {
            if (operand != OperandType.None)
            {
                throw new InvalidOperationException();
            }

            this.Routine = BitConverter.ToInt16(code, offset + 2).BigEndian();
            this.ArgumentCount = code[offset + 4];
            offset += 5;
        }
Example #12
0
 public Operand(Processor cpu, OperandType optype)
 {
     Type = optype;
     switch (Type)
     {
         case OperandType.AddressBlock:
             Address = new AddressBlock(cpu, cpu.ReadULong());
             break;
         case OperandType.Register:
             // add
             break;
         case OperandType.StackIndex:
             // add
             break;
         case OperandType.NumericByte:
             Value = new ByteBlock(cpu.ReadByte());
             break;
         case OperandType.NumericSByte:
             Value = new ByteBlock(cpu.ReadSByte());
             break;
         case OperandType.NumericShort:
             Value = new ByteBlock(cpu.ReadShort());
             break;
         case OperandType.NumericUShort:
             Value = new ByteBlock(cpu.ReadUShort());
             break;
         case OperandType.NumericInt:
             Value = new ByteBlock(cpu.ReadInt());
             break;
         case OperandType.NumericUInt:
             Value = new ByteBlock(cpu.ReadUInt());
             break;
         case OperandType.NumericLong:
             Value = new ByteBlock(cpu.ReadLong());
             break;
         case OperandType.NumericULong:
             Value = new ByteBlock(cpu.ReadULong());
             break;
         case OperandType.NumericFloat:
             Value = new ByteBlock(cpu.ReadFloat());
             break;
         case OperandType.NumericDouble:
             Value = new ByteBlock(cpu.ReadDouble());
             break;
         case OperandType.LPString:
             uint length = cpu.ReadUInt();
             ByteBlock bytes = cpu.Read(length);
             Value = new ByteBlock(System.Text.Encoding.UTF8.GetString(bytes.ToByteArray()));
             break;
         default:
             break;
     }
 }
Example #13
0
 public void Decode(byte[] code, ref int offset, OperandType operand, IState state)
 {
     this.Operand = operand;
     if (operand == Script.OperandType.StructureStructure)
     {
         this.StructureSize = BitConverter.ToInt16(code, offset + 2).BigEndian();
         offset += 4;
     }
     else
     {
         offset += 2;
     }
 }
Example #14
0
		internal OpCode(string name, Code code, OperandType operandType, FlowControl flowControl, OpCodeType opCodeType, StackBehaviour push, StackBehaviour pop) {
			this.Name = name;
			this.Code = code;
			this.OperandType = operandType;
			this.FlowControl = flowControl;
			this.OpCodeType = opCodeType;
			this.StackBehaviourPush = push;
			this.StackBehaviourPop = pop;
			if (((ushort)code >> 8) == 0)
				OpCodes.OneByteOpCodes[(byte)code] = this;
			else if (((ushort)code >> 8) == 0xFE)
				OpCodes.TwoByteOpCodes[(byte)code] = this;
		}
Example #15
0
 protected Operand(OperandType type,
                   OperandValueType valueType = OperandValueType.Dword,
                   bool isPointer = false,
                   bool isOffset = false,
                   Register offsetRegister = Register.R0,
                   int payload = 0)
 {
     Type = type;
     ValueType = valueType;
     IsPointer = isPointer;
     IsOffset = isOffset;
     OffsetRegister = offsetRegister;
     Payload = payload;
 }
Example #16
0
 internal OpCode(string name, byte op1, byte op2, int size, FlowControl flowControl,
     OpCodeType opCodeType, OperandType operandType,
     StackBehaviour pop, StackBehaviour push)
 {
     m_name = name;
     m_op1 = op1;
     m_op2 = op2;
     m_size = size;
     m_flowControl = flowControl;
     m_opCodeType = opCodeType;
     m_operandType = operandType;
     m_stackBehaviourPop = pop;
     m_stackBehaviourPush = push;
 }
Example #17
0
        internal OpCode(int x, int y)
        {
            m_op1 = (byte)((x >> 0) & 0xff);
            m_op2 = (byte)((x >> 8) & 0xff);
            m_code = (Code)((x >> 16) & 0xff);
            m_flowControl = (FlowControl)((x >> 24) & 0xff);
            m_size = 0;
            m_name = "";

            m_opCodeType = (OpCodeType)((y >> 0) & 0xff);
            m_operandType = (OperandType)((y >> 8) & 0xff);
            m_stackBehaviourPop = (StackBehaviour)((y >> 16) & 0xff);
            m_stackBehaviourPush = (StackBehaviour)((y >> 24) & 0xff);
        }
Example #18
0
	internal OpCode(String stringname, StackBehaviour pop, StackBehaviour push, OperandType operand, OpCodeType type, int size, byte s1, byte s2, FlowControl ctrl, bool endsjmpblk, int stack)
	{
		m_stringname = stringname;
		m_pop = pop;
		m_push = push;
		m_operand = operand;
		m_type = type;
		m_size = size;
		m_s1 = s1;
		m_s2 = s2;
		m_ctrl = ctrl;
		m_endsUncondJmpBlk = endsjmpblk;
		m_stackChange = stack;

	}
Example #19
0
    private bool VerifyOpCodeType(OpCode op1, OperandType ot, string errNum)
    {
        bool retVal = true;

        try
        {
            if (op1.OperandType != ot)
            {
                TestLibrary.TestFramework.LogError(errNum, "Result is not the value as expected,OperandType is: " + op1.OperandType + ",Expected is: " + ot);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError(errNum, "Unexpected exception: " + e);
            retVal = false;
        }
        return retVal;
    }
Example #20
0
 public Opcode(ZMachine zm, OpcodeCompiler compiler, OpcodeAttribute attribute,
     int pc, int zCodeLength,
     int argc, OperandType[] operandTypes, short[] operandValues,
     string operandText, int resultStorage, bool branchIfTrue, int branchOffset)
 {
     this.zm = zm;
     this.compiler = compiler;
     this.attribute = attribute;
     this.PC = pc;
     this.ZCodeLength = zCodeLength;
     this.argc = argc;
     this.operandTypes = new OperandType[argc];
     Array.Copy(operandTypes, this.operandTypes, argc);
     this.operandValues = new short[argc];
     Array.Copy(operandValues, this.operandValues, argc);
     this.operandText = operandText;
     this.resultStorage = resultStorage;
     this.branchIfTrue = branchIfTrue;
     this.branchOffset = branchOffset;
 }
Example #21
0
	// Construct a new opcode.
	internal OpCode(String name, int value, FlowControl flowControl,
					OpCodeType opcodeType, OperandType operandType,
					StackBehaviour stackPop, StackBehaviour stackPush)
			{
				this.name = name;
				this.value = (short)value;
				this.flowControl = (byte)flowControl;
				this.opcodeType = (byte)opcodeType;
				this.operandType = (byte)operandType;
				if(value < 0x0100)
				{
					this.size = (byte)1;
				}
				else
				{
					this.size = (byte)2;
				}
				this.stackPop = (byte)stackPop;
				this.stackPush = (byte)stackPush;
			}
Example #22
0
        internal OpCode(string name, byte op1, byte op2, int size,
			Code code, FlowControl flowControl,
			OpCodeType opCodeType, OperandType operandType,
			StackBehaviour pop, StackBehaviour push)
        {
            m_name = name;
            m_op1 = op1;
            m_op2 = op2;
            m_size = size;
            m_code = code;
            m_flowControl = flowControl;
            m_opCodeType = opCodeType;
            m_operandType = operandType;
            m_stackBehaviourPop = pop;
            m_stackBehaviourPush = push;

            if (op1 == 0xff)
                OpCodes.OneByteOpCode [op2] = this;
            else
                OpCodes.TwoBytesOpCode [op2] = this;
        }
Example #23
0
 //verify the opcode fields
 //if not equal,retun the field name which contains error. 
 private CompareResult CompareOpCode(
     OpCode opcode,
     String stringname,
     StackBehaviour pop,
     StackBehaviour push,
     OperandType operand,
     OpCodeType type,
     int size,
     byte s1,
     byte s2,
     FlowControl ctrl)
 {
     CompareResult returnValue = CompareResult.Equal;
     if (opcode.Name != stringname) returnValue = returnValue | CompareResult.Name;
     if (opcode.StackBehaviourPop != pop) returnValue = returnValue | CompareResult.Pop;
     if (opcode.StackBehaviourPush != push) returnValue = returnValue | CompareResult.Push;
     if (opcode.OperandType != operand) returnValue = returnValue | CompareResult.OpenrandType;
     if (opcode.OpCodeType != type) returnValue = returnValue | CompareResult.OpCodeType;
     if (opcode.Size != size) returnValue = returnValue | CompareResult.Size;
     if (size == 2)
     {
         if (opcode.Value != ((short)(s1 << 8 | s2)))
         {
             returnValue = returnValue | CompareResult.Value;
         }
     }
     else
     {
         if (opcode.Value != ((short)s2))
         {
             returnValue = returnValue | CompareResult.Value;
         }
     }
     if (opcode.FlowControl != ctrl)
     {
         returnValue = returnValue | CompareResult.FlowControl;
     }
     return returnValue;
 }
Example #24
0
        public void Decode(byte[] code, ref int offset, OperandType operand, IState state)
        {
            this.Operand = operand;
            switch (operand)
            {
                case OperandType.Integer:
                {
                    this.Value = BitConverter.ToInt32(code, offset + 2).BigEndian();
                    offset += 6;
                    return;
                }

                case OperandType.Float:
                {
                    this.Value = BitConverter.ToSingle(code, offset + 2).BigEndian();
                    offset += 6;
                    return;
                }

                case OperandType.String:
                case OperandType.Resource:
                {
                    var length = BitConverter.ToInt16(code, offset + 2).BigEndian();
                    this.Value = Encoding.UTF8.GetString(code, offset + 4, length);
                    offset += 4 + length;
                    return;
                }

                case OperandType.Object:
                {
                    this.Value = BitConverter.ToInt32(code, offset + 2).BigEndian();
                    offset += 6;
                    return;
                }
            }

            throw new NotSupportedException();
        }
Example #25
0
 public Operand(OperandType type, Register register)
 {
     this.Type     = type;
     this.Register = register;
 }
Example #26
0
    private bool VerifyAllTheFileds(OpCode opCode, 
                                    String opCodeName, 
                                    StackBehaviour pop, 
                                    StackBehaviour push, 
                                    OperandType operandType, 
                                    OpCodeType type, 
                                    int size, 
                                    byte s1, byte s2, 
                                    FlowControl ctrl, 
                                    string errorNum)
    {
        bool retVal = true;
        string errorDesc;

        string actualName = opCode.Name;
        if (actualName != opCodeName)
        {
            errorDesc = "Actual name of the specified MSIL instruction: \"" + actualName +
                        "\" does not equal expected name: \"" + opCodeName + "\"";
            TestLibrary.TestFramework.LogError( errorNum + ".1", errorDesc);
            retVal = false;
        }

        StackBehaviour actualStackBehaviourPop = opCode.StackBehaviourPop;
        if (actualStackBehaviourPop != pop)
        {
            errorDesc = "Actual pop statck behaviour of the specified MSIL instruction: (" + actualStackBehaviourPop +
                        ") does not equal expected pop stack behaviour: (" + pop + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".2", errorDesc);
            retVal = false;
        }

        StackBehaviour actualStackBehaviourPush = opCode.StackBehaviourPush;
        if (actualStackBehaviourPush != push)
        {
            errorDesc = "Actual push statck behaviour of the specified MSIL instruction: (" + actualStackBehaviourPush +
                        ") does not equal expected push stack behaviour: (" + push + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".3", errorDesc);
            retVal = false;
        }


        OperandType actualOperandType = opCode.OperandType;
        if (actualOperandType != operandType)
        {
            errorDesc = "Actual operand type of the specified MSIL instruction: (" + actualOperandType +
                        ") does not equal expected operand type: (" + operandType + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".4", errorDesc);
            retVal = false;
        }

        OpCodeType actualOpCodeType = opCode.OpCodeType;
        if (actualOpCodeType != type)
        {
            errorDesc = "Actual OpCode type of the specified MSIL instruction: (" + actualOpCodeType +
                        ") does not equal expected OpCode type: (" + type + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".5", errorDesc);
            retVal = false;
        }

        int actualSize = opCode.Size;
        if (actualSize != size)
        {
            errorDesc = "Actual size of the specified MSIL instruction: (" + actualSize +
                        ") does not equal expected size: (" + size + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".6", errorDesc);
            retVal = false;
        }

        short actualValue = opCode.Value;
        short expectedValue = (2 == size) ? (short)(s1 << 8 | s2) : s2;
        if (actualValue != expectedValue)
        {
            errorDesc = "Actual immediate operand value of the specified MSIL instruction: (" + actualValue +
                        ") does not equal expected immediate operand value: (" + expectedValue + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".7", errorDesc);
            retVal = false;
        }

        FlowControl actualCtrl = opCode.FlowControl;
        if (actualCtrl != ctrl)
        {
            errorDesc = "Actual flow control of the specified MSIL instruction: (" + actualCtrl +
                        ") does not equal expected flow control: (" + ctrl + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".8", errorDesc);
            retVal = false;
        }

        return retVal;
    }
Example #27
0
 public Operand(float immediate)
 {
     this.Type           = OperandType.ImmediateFloat;
     this.ImmediateFloat = immediate;
 }
Example #28
0
 public Operand(OperandType type, int immediate)
 {
     this.Type      = type;
     this.Immediate = immediate;
 }
Example #29
0
 public Operand(object operandValue, OperandType type)
 {
     this.m_operandValue = operandValue;
     this.m_type         = type;
 }
Example #30
0
    private bool VerifyAllTheFileds(OpCode opCode,
                                    String opCodeName,
                                    StackBehaviour pop,
                                    StackBehaviour push,
                                    OperandType operandType,
                                    OpCodeType type,
                                    int size,
                                    byte s1, byte s2,
                                    FlowControl ctrl,
                                    string errorNum)
    {
        bool   retVal = true;
        string errorDesc;

        string actualName = opCode.Name;

        if (actualName != opCodeName)
        {
            errorDesc = "Actual name of the specified MSIL instruction: \"" + actualName +
                        "\" does not equal expected name: \"" + opCodeName + "\"";
            TestLibrary.TestFramework.LogError(errorNum + ".1", errorDesc);
            retVal = false;
        }

        StackBehaviour actualStackBehaviourPop = opCode.StackBehaviourPop;

        if (actualStackBehaviourPop != pop)
        {
            errorDesc = "Actual pop statck behaviour of the specified MSIL instruction: (" + actualStackBehaviourPop +
                        ") does not equal expected pop stack behaviour: (" + pop + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".2", errorDesc);
            retVal = false;
        }

        StackBehaviour actualStackBehaviourPush = opCode.StackBehaviourPush;

        if (actualStackBehaviourPush != push)
        {
            errorDesc = "Actual push statck behaviour of the specified MSIL instruction: (" + actualStackBehaviourPush +
                        ") does not equal expected push stack behaviour: (" + push + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".3", errorDesc);
            retVal = false;
        }


        OperandType actualOperandType = opCode.OperandType;

        if (actualOperandType != operandType)
        {
            errorDesc = "Actual operand type of the specified MSIL instruction: (" + actualOperandType +
                        ") does not equal expected operand type: (" + operandType + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".4", errorDesc);
            retVal = false;
        }

        OpCodeType actualOpCodeType = opCode.OpCodeType;

        if (actualOpCodeType != type)
        {
            errorDesc = "Actual OpCode type of the specified MSIL instruction: (" + actualOpCodeType +
                        ") does not equal expected OpCode type: (" + type + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".5", errorDesc);
            retVal = false;
        }

        int actualSize = opCode.Size;

        if (actualSize != size)
        {
            errorDesc = "Actual size of the specified MSIL instruction: (" + actualSize +
                        ") does not equal expected size: (" + size + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".6", errorDesc);
            retVal = false;
        }

        short actualValue   = opCode.Value;
        short expectedValue = (2 == size) ? (short)(s1 << 8 | s2) : s2;

        if (actualValue != expectedValue)
        {
            errorDesc = "Actual immediate operand value of the specified MSIL instruction: (" + actualValue +
                        ") does not equal expected immediate operand value: (" + expectedValue + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".7", errorDesc);
            retVal = false;
        }

        FlowControl actualCtrl = opCode.FlowControl;

        if (actualCtrl != ctrl)
        {
            errorDesc = "Actual flow control of the specified MSIL instruction: (" + actualCtrl +
                        ") does not equal expected flow control: (" + ctrl + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".8", errorDesc);
            retVal = false;
        }

        return(retVal);
    }
Example #31
0
    private bool VerificationHelper(OpCode code,
        string name,
        StackBehaviour pop,
        StackBehaviour push,
        OperandType oprandType,
        OpCodeType type,
        int size,
        byte s1,
        byte s2,
        FlowControl ctrl,
        string errorno,
        string errordesp)
    {
        bool retVal = true;

        string actualName = code.Name;
        if (actualName != name)
        {
            TestLibrary.TestFramework.LogError(errorno + ".0", "Name returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualName = " + actualName + ", name = " + name);
            retVal = false;
        }

        StackBehaviour actualPop = code.StackBehaviourPop;
        if (actualPop != pop)
        {
            TestLibrary.TestFramework.LogError(errorno + ".1", "StackBehaviourPop returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualPop = " + actualPop + ", pop = " + pop);
            retVal = false;
        }

        StackBehaviour actualPush = code.StackBehaviourPush;
        if (actualPush != push)
        {
            TestLibrary.TestFramework.LogError(errorno + ".2", "StackBehaviourPush returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualPush = " + actualPush + ", push = " + push);
            retVal = false;
        }

        OperandType actualOperandType = code.OperandType;
        if (actualOperandType != oprandType)
        {
            TestLibrary.TestFramework.LogError(errorno + ".3", "OperandType returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualOperandType = " + actualOperandType + ", oprandType = " + oprandType);
            retVal = false;
        }

        OpCodeType actualOpCodeType = code.OpCodeType;
        if (actualOpCodeType != type)
        {
            TestLibrary.TestFramework.LogError(errorno + ".4", "OpCodeType returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualOpCodeType = " + actualOpCodeType + ", type = " + type);
            retVal = false;
        }

        int actualSize = code.Size;
        if (actualSize != size)
        {
            TestLibrary.TestFramework.LogError(errorno + ".5", "Size returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualSize = " + actualSize + ", size = " + size);
            retVal = false;
        }

        short expectedValue = 0;
        if (size == 2)
            expectedValue = (short)(s1 << 8 | s2);
        else
            expectedValue = (short)s2;

        short actualValue = code.Value;
        if (actualValue != expectedValue)
        {
            TestLibrary.TestFramework.LogError(errorno + ".6", "Value returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualValue = " + actualValue + ", s1 = " + s1 + ", s2 = " + s2 + ", expectedValue = " + expectedValue);
            retVal = false;
        }

        FlowControl actualCtrl = code.FlowControl;
        if (actualCtrl != ctrl)
        {
            TestLibrary.TestFramework.LogError(errorno + ".7", "FlowControl returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualCtrl = " + actualCtrl + ", ctrl = " + ctrl);
            retVal = false;
        }
        return retVal;
    }
Example #32
0
 public Operand SignExtend32(OperandType type, Operand op1)
 {
     return(Add(Instruction.SignExtend32, Local(type), op1));
 }
Example #33
0
 public Operand VectorExtract(OperandType type, Operand vector, int index)
 {
     return(Add(Instruction.VectorExtract, Local(type), vector, Const(index)));
 }
Example #34
0
 public Operand LoadArgument(OperandType type, int index)
 {
     return(Add(Instruction.LoadArgument, Local(type), Const(index)));
 }
Example #35
0
 public Operand Load(OperandType type, Operand address)
 {
     return(Add(Instruction.Load, Local(type), address));
 }
Example #36
0
 public Operand ConvertToFPUI(OperandType type, Operand op1)
 {
     return(Add(Instruction.ConvertToFPUI, Local(type), op1));
 }
Example #37
0
 public void Encode(byte[] code, ref int offset, out OperandType operand, IState state)
 {
     throw new NotImplementedException();
 }
 public void Encode(byte[] code, ref int offset, out OperandType operand, IState state)
 {
     throw new NotImplementedException();
 }
Example #39
0
 public void Encode(byte[] code, ref int offset, out OperandType operand, IState state)
 {
     operand = OperandType.None;
     offset += 2;
 }
 public void Decode(byte[] code, ref int offset, OperandType operand, IState state)
 {
     this.Operand = operand;
     offset      += 2;
 }
 public void RegisterDelegate(OperandType left, OperandType right, DoubleOperandDelegate func)
 {
     _delegateMatrix[(int)left, (int)right] = func;
 }
Example #42
0
 public Operand(string lexem, OperandType operandType)
 {
     Lexem  = lexem;
     TypeOp = operandType;
 }
Example #43
0
 public static Operand Local(OperandType type)
 {
     return(Operand().With(OperandKind.LocalVariable, type));
 }
Example #44
0
    private bool VerificationHelper(OpCode code,
                                    string name,
                                    StackBehaviour pop,
                                    StackBehaviour push,
                                    OperandType oprandType,
                                    OpCodeType type,
                                    int size,
                                    byte s1,
                                    byte s2,
                                    FlowControl ctrl,
                                    string errorno,
                                    string errordesp)
    {
        bool retVal = true;

        string actualName = code.Name;

        if (actualName != name)
        {
            TestLibrary.TestFramework.LogError(errorno + ".0", "Name returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualName = " + actualName + ", name = " + name);
            retVal = false;
        }

        StackBehaviour actualPop = code.StackBehaviourPop;

        if (actualPop != pop)
        {
            TestLibrary.TestFramework.LogError(errorno + ".1", "StackBehaviourPop returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualPop = " + actualPop + ", pop = " + pop);
            retVal = false;
        }

        StackBehaviour actualPush = code.StackBehaviourPush;

        if (actualPush != push)
        {
            TestLibrary.TestFramework.LogError(errorno + ".2", "StackBehaviourPush returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualPush = " + actualPush + ", push = " + push);
            retVal = false;
        }

        OperandType actualOperandType = code.OperandType;

        if (actualOperandType != oprandType)
        {
            TestLibrary.TestFramework.LogError(errorno + ".3", "OperandType returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualOperandType = " + actualOperandType + ", oprandType = " + oprandType);
            retVal = false;
        }

        OpCodeType actualOpCodeType = code.OpCodeType;

        if (actualOpCodeType != type)
        {
            TestLibrary.TestFramework.LogError(errorno + ".4", "OpCodeType returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualOpCodeType = " + actualOpCodeType + ", type = " + type);
            retVal = false;
        }

        int actualSize = code.Size;

        if (actualSize != size)
        {
            TestLibrary.TestFramework.LogError(errorno + ".5", "Size returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualSize = " + actualSize + ", size = " + size);
            retVal = false;
        }

        short expectedValue = 0;

        if (size == 2)
        {
            expectedValue = (short)(s1 << 8 | s2);
        }
        else
        {
            expectedValue = (short)s2;
        }

        short actualValue = code.Value;

        if (actualValue != expectedValue)
        {
            TestLibrary.TestFramework.LogError(errorno + ".6", "Value returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualValue = " + actualValue + ", s1 = " + s1 + ", s2 = " + s2 + ", expectedValue = " + expectedValue);
            retVal = false;
        }

        FlowControl actualCtrl = code.FlowControl;

        if (actualCtrl != ctrl)
        {
            TestLibrary.TestFramework.LogError(errorno + ".7", "FlowControl returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualCtrl = " + actualCtrl + ", ctrl = " + ctrl);
            retVal = false;
        }
        return(retVal);
    }
Example #45
0
        private Expression <Func <IFigure, bool> > CaseConditioner(FilterTerm fc, Expression <Func <IFigure, bool> > ex)
        {
            if (fc.Value != null)
            {
                object      Value   = fc.Value;
                OperandType Operand = fc.Operand;
                if (Operand != OperandType.Like && Operand != OperandType.NotLike)
                {
                    switch (Operand)
                    {
                    case OperandType.Equal:

                        ex = (r => r[fc.FilterRubric.FieldId] != null ?
                              fc.FilterRubric.RubricType == typeof(IUnique) ||
                              fc.FilterRubric.RubricType == typeof(string) ||
                              fc.FilterRubric.RubricType == typeof(DateTime) ?
                              r[fc.FilterRubric.FieldId].ComparableUInt64(fc.FilterRubric.RubricType)
                              .Equals(Value.ComparableUInt64(fc.FilterRubric.RubricType)) :
                              r[fc.FilterRubric.FieldId].ComparableDouble(fc.FilterRubric.RubricType)
                              .Equals(Value.ComparableDouble(fc.FilterRubric.RubricType)) :
                              false);
                        break;

                    case OperandType.EqualOrMore:

                        ex = (r => r[fc.FilterRubric.FieldId] != null ?
                              fc.FilterRubric.RubricType == typeof(IUnique) ||
                              fc.FilterRubric.RubricType == typeof(string) ||
                              fc.FilterRubric.RubricType == typeof(DateTime) ?
                              r[fc.FilterRubric.FieldId].ComparableUInt64(fc.FilterRubric.RubricType)
                              >=
                              (Value.ComparableUInt64(fc.FilterRubric.RubricType)) :
                              r[fc.FilterRubric.FieldId].ComparableDouble(fc.FilterRubric.RubricType)
                              >=
                              (Value.ComparableDouble(fc.FilterRubric.RubricType)) : false);
                        break;

                    case OperandType.More:

                        ex = (r => r[fc.FilterRubric.FieldId] != null ?
                              fc.FilterRubric.RubricType == typeof(IUnique) ||
                              fc.FilterRubric.RubricType == typeof(string) ||
                              fc.FilterRubric.RubricType == typeof(DateTime) ?
                              r[fc.FilterRubric.FieldId].ComparableUInt64(fc.FilterRubric.RubricType)
                              >
                              (Value.ComparableUInt64(fc.FilterRubric.RubricType)) :
                              r[fc.FilterRubric.FieldId].ComparableDouble(fc.FilterRubric.RubricType)
                              >
                              (Value.ComparableDouble(fc.FilterRubric.RubricType)) : false);
                        break;

                    case OperandType.EqualOrLess:

                        ex = (r => r[fc.FilterRubric.FieldId] != null ?
                              fc.FilterRubric.RubricType == typeof(IUnique) ||
                              fc.FilterRubric.RubricType == typeof(string) ||
                              fc.FilterRubric.RubricType == typeof(DateTime) ?
                              r[fc.FilterRubric.FieldId].ComparableUInt64(fc.FilterRubric.RubricType)
                              <=
                              (Value.ComparableUInt64(fc.FilterRubric.RubricType)) :
                              r[fc.FilterRubric.FieldId].ComparableDouble(fc.FilterRubric.RubricType)
                              <=
                              (Value.ComparableDouble(fc.FilterRubric.RubricType)) : false);
                        break;

                    case OperandType.Less:

                        ex = (r => r[fc.FilterRubric.FieldId] != null ?
                              fc.FilterRubric.RubricType == typeof(IUnique) ||
                              fc.FilterRubric.RubricType == typeof(string) ||
                              fc.FilterRubric.RubricType == typeof(DateTime) ?
                              r[fc.FilterRubric.FieldId].ComparableUInt64(fc.FilterRubric.RubricType)
                              <
                              (Value.ComparableUInt64(fc.FilterRubric.RubricType)) :
                              r[fc.FilterRubric.FieldId].ComparableDouble(fc.FilterRubric.RubricType)
                              <
                              (Value.ComparableDouble(fc.FilterRubric.RubricType)) : false);
                        break;

                    default:
                        break;
                    }
                }
                else if (Operand != OperandType.NotLike)
                {
                    ex = (r => r[fc.FilterRubric.FieldId] != null ?
                          Convert.ChangeType(r[fc.FilterRubric.FieldId], fc.FilterRubric.RubricType).ToString()
                          .Contains(Convert.ChangeType(Value, fc.FilterRubric.RubricType).ToString()) :
                          false);
                }
                else
                {
                    ex = (r => r[fc.FilterRubric.FieldId] != null ?
                          !Convert.ChangeType(r[fc.FilterRubric.FieldId], fc.FilterRubric.RubricType).ToString()
                          .Contains(Convert.ChangeType(Value, fc.FilterRubric.RubricType).ToString()) :
                          false);
                }
            }
            return(ex);
        }
Example #46
0
 public Variable CreateVariable(string name, OperandType type, object defaultValue, object state)
 {
     // state object can be used by non-default factories, e.g. a factory that manufactures serializable variables where the object holds a serialization key.
     return(new Variable(name, type, defaultValue, state));
 }
Example #47
0
 public Operand(int immediate, int size)
 {
     this.Type      = OperandType.Immediate;
     this.Immediate = immediate;
     this.Size      = size;
 }
Example #48
0
        static internal TypeSymbol TypeSymbol(this OperandType OpType)
        {
            switch (OpType)
            {
            case OperandType.Object:
                return(Compilation.Get(NativeType.Object));

            case OperandType.String:
                return(Compilation.Get(NativeType.String));

            case OperandType.ObjectAndString:
                return(Compilation.Get(NativeType.String));

            case OperandType.StringAndObject:
                return(Compilation.Get(NativeType.String));

            case OperandType.Int:
                return(Compilation.Get(NativeType.Int32));

            case OperandType.UInt:
                return(Compilation.Get(NativeType.UInt32));

            case OperandType.Long:
                return(Compilation.Get(NativeType.Int64));

            case OperandType.ULong:
                return(Compilation.Get(NativeType.UInt64));

            case OperandType.Float:
                return(Compilation.Get(NativeType.Single));

            case OperandType.Double:
                return(Compilation.Get(NativeType.Double));

            case OperandType.Decimal:
                return(Compilation.Get(NativeType.Decimal));

            case OperandType.Bool:
                return(Compilation.Get(NativeType.Boolean));

            case OperandType.NullableInt:
                return(Binder.NullableType(Compilation.Get(NativeType.Int32)));

            case OperandType.NullableUInt:
                return(Binder.NullableType(Compilation.Get(NativeType.UInt32)));

            case OperandType.NullableLong:
                return(Binder.NullableType(Compilation.Get(NativeType.Int64)));

            case OperandType.NullableULong:
                return(Binder.NullableType(Compilation.Get(NativeType.UInt64)));

            case OperandType.NullableFloat:
                return(Binder.NullableType(Compilation.Get(NativeType.Single)));

            case OperandType.NullableDouble:
                return(Binder.NullableType(Compilation.Get(NativeType.Double)));

            case OperandType.NullableDecimal:
                return(Binder.NullableType(Compilation.Get(NativeType.Decimal)));

            case OperandType.NullableBool:
                return(Binder.NullableType(Compilation.Get(NativeType.Boolean)));

            default:
                return(null);
            }
        }
Example #49
0
 /// <summary>
 /// Initializes a new instance of <see cref="Operand"/>.
 /// </summary>
 /// <param name="type">The type of the operand.</param>
 private Operand(SigType type, OperandType operandType)
 {
     this.sigType = type;
     this.operandType = operandType;
     definitions = new List<int>();
     uses = new List<int>();
 }
Example #50
0
 internal static bool IsNullable(OperandType type)
 {
     return(s_nullable[(int)type]);
 }
Example #51
0
 public Operand(OperandType type, Register register, int offset)
 {
     this.Type      = type;
     this.Register  = register;
     this.Immediate = offset;
 }
        private void Load(ShaderModel shader)
        {
            ConstantDeclarations = shader.ParseConstantTable();
            foreach (var constantDeclaration in ConstantDeclarations)
            {
                RegisterType registerType;
                switch (constantDeclaration.RegisterSet)
                {
                case RegisterSet.Bool:
                    registerType = RegisterType.ConstBool;
                    break;

                case RegisterSet.Float4:
                    registerType = RegisterType.Const;
                    break;

                case RegisterSet.Int4:
                    registerType = RegisterType.Input;
                    break;

                case RegisterSet.Sampler:
                    registerType = RegisterType.Sampler;
                    break;

                default:
                    throw new InvalidOperationException();
                }
                if (registerType == RegisterType.Sampler)
                {
                    // Use declaration from declaration instruction instead
                    continue;
                }
                for (int r = 0; r < constantDeclaration.RegisterCount; r++)
                {
                    var registerKey         = new RegisterKey(registerType, constantDeclaration.RegisterIndex + r);
                    var registerDeclaration = new RegisterDeclaration(registerKey);
                    _registerDeclarations.Add(registerKey, registerDeclaration);
                }
            }

            if (shader.MajorVersion <= 3)
            {
                foreach (D3D9Instruction instruction in shader.Instructions)
                {
                    if (!instruction.HasDestination)
                    {
                        if (instruction.Opcode == Opcode.Loop)
                        {
                            RegisterKey registerKey = new RegisterKey(RegisterType.Loop, 0);
                            if (!_registerDeclarations.TryGetValue(registerKey, out _))
                            {
                                var registerDeclaration = new RegisterDeclaration(registerKey);
                                _registerDeclarations.Add(registerKey, registerDeclaration);
                            }
                        }
                        continue;
                    }

                    if (instruction.Opcode == Opcode.Dcl)
                    {
                        var         registerDeclaration = new RegisterDeclaration(instruction);
                        RegisterKey registerKey         = registerDeclaration.RegisterKey;

                        _registerDeclarations.Add(registerKey, registerDeclaration);

                        switch (registerKey.Type)
                        {
                        case RegisterType.Input:
                        case RegisterType.MiscType:
                            MethodInputRegisters.Add(registerKey, registerDeclaration);
                            break;

                        case RegisterType.Output:
                        case RegisterType.ColorOut:
                            MethodOutputRegisters.Add(registerKey, registerDeclaration);
                            break;
                        }
                        switch (registerKey.OperandType)
                        {
                        case OperandType.Output:
                            MethodOutputRegisters.Add(registerKey, registerDeclaration);
                            break;
                        }
                    }
                    else if (instruction.Opcode == Opcode.Def)
                    {
                        var constant = new ConstantRegister(
                            instruction.GetParamRegisterNumber(0),
                            instruction.GetParamSingle(1),
                            instruction.GetParamSingle(2),
                            instruction.GetParamSingle(3),
                            instruction.GetParamSingle(4));
                        _constantDefinitions.Add(constant);
                    }
                    else if (instruction.Opcode == Opcode.DefI)
                    {
                        var constantInt = new ConstantIntRegister(instruction.GetParamRegisterNumber(0),
                                                                  instruction.Params[1],
                                                                  instruction.Params[2],
                                                                  instruction.Params[3],
                                                                  instruction.Params[4]);
                        _constantIntDefinitions.Add(constantInt);
                    }
                    else
                    {
                        int          destIndex    = instruction.GetDestinationParamIndex();
                        RegisterType registerType = instruction.GetParamRegisterType(destIndex);
                        // Find assignments to color outputs, since pixel shader outputs are not pre-declared
                        if (registerType == RegisterType.ColorOut)
                        {
                            if (shader.Type == ShaderType.Pixel)
                            {
                                int registerNumber = instruction.GetParamRegisterNumber(destIndex);
                                var registerKey    = new RegisterKey(registerType, registerNumber);
                                if (MethodOutputRegisters.ContainsKey(registerKey) == false)
                                {
                                    var reg = new RegisterDeclaration(registerKey);
                                    MethodOutputRegisters[registerKey] = reg;

                                    if (!_registerDeclarations.TryGetValue(registerKey, out _))
                                    {
                                        var registerDeclaration = new RegisterDeclaration(registerKey);
                                        _registerDeclarations.Add(registerKey, registerDeclaration);
                                    }
                                }
                            }
                        }
                        // Find assignments to temporary registers, since they are not pre-declared
                        else if (registerType == RegisterType.Temp)
                        {
                            int         registerNumber = instruction.GetParamRegisterNumber(destIndex);
                            RegisterKey registerKey    = new RegisterKey(registerType, registerNumber);
                            if (!_registerDeclarations.TryGetValue(registerKey, out _))
                            {
                                var registerDeclaration = new RegisterDeclaration(registerKey);
                                _registerDeclarations.Add(registerKey, registerDeclaration);
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (D3D10Instruction instruction in shader.Instructions)
                {
                    if (!instruction.HasDestination)
                    {
                        if (instruction.Opcode == D3D10Opcode.Loop)
                        {
                            RegisterKey registerKey = new RegisterKey(RegisterType.Loop, 0);
                            if (!_registerDeclarations.TryGetValue(registerKey, out _))
                            {
                                var registerDeclaration = new RegisterDeclaration(registerKey);
                                _registerDeclarations.Add(registerKey, registerDeclaration);
                            }
                        }
                        continue;
                    }

                    if (instruction.Opcode == D3D10Opcode.DclOutput)
                    {
                        var         registerDeclaration = new RegisterDeclaration(instruction);
                        RegisterKey registerKey         = registerDeclaration.RegisterKey;

                        _registerDeclarations.Add(registerKey, registerDeclaration);

                        switch (registerKey.OperandType)
                        {
                        case OperandType.Output:
                            MethodOutputRegisters.Add(registerKey, registerDeclaration);
                            break;
                        }
                    }
                    else if (instruction.Opcode == D3D10Opcode.DclInputPS)
                    {
                        var         registerDeclaration = new RegisterDeclaration(instruction);
                        RegisterKey registerKey         = registerDeclaration.RegisterKey;

                        _registerDeclarations.Add(registerKey, registerDeclaration);

                        switch (registerKey.OperandType)
                        {
                        case OperandType.Input:
                            MethodInputRegisters.Add(registerKey, registerDeclaration);
                            break;
                        }
                    }
                    else
                    {
                        int         destIndex   = instruction.GetDestinationParamIndex();
                        OperandType operandType = instruction.GetOperandType(destIndex);
                        // Find assignments to color outputs, since pixel shader outputs are not pre-declared
                        if (operandType == OperandType.Output)
                        {
                            if (shader.Type == ShaderType.Pixel)
                            {
                                int registerNumber = instruction.GetParamRegisterNumber(destIndex);
                                var registerKey    = new RegisterKey(operandType, registerNumber);
                                if (MethodOutputRegisters.ContainsKey(registerKey) == false)
                                {
                                    var reg = new RegisterDeclaration(registerKey);
                                    MethodOutputRegisters[registerKey] = reg;

                                    if (!_registerDeclarations.TryGetValue(registerKey, out _))
                                    {
                                        var registerDeclaration = new RegisterDeclaration(registerKey);
                                        _registerDeclarations.Add(registerKey, registerDeclaration);
                                    }
                                }
                            }
                        }
                        // Find assignments to temporary registers, since they are not pre-declared
                        else if (operandType == OperandType.Temp)
                        {
                            int         registerNumber = instruction.GetParamRegisterNumber(destIndex);
                            RegisterKey registerKey    = new RegisterKey(operandType, registerNumber);
                            if (!_registerDeclarations.TryGetValue(registerKey, out _))
                            {
                                var registerDeclaration = new RegisterDeclaration(registerKey);
                                _registerDeclarations.Add(registerKey, registerDeclaration);
                            }
                        }
                    }
                }
            }
        }
Example #53
0
 public void Decode(byte[] code, ref int offset, OperandType operand, IState state)
 {
     this.Operand = operand;
     offset += 2;
 }
Example #54
0
 internal void setOperand(OperandType operand)
 {
     operands.Add(new Operand(lexem, operand));
     lexem = "";
 }
Example #55
0
 public Operand(Register register)
 {
     this.Type     = OperandType.Register;
     this.Register = register;
 }
Example #56
0
 public static Operand Const(OperandType type, long value)
 {
     return(type == OperandType.I32 ? Operand().With((int)value) : Operand().With(value));
 }
Example #57
0
        //public Reference Reference;

        public Operand(string annotation)
        {
            this.Type       = OperandType.Annotation;
            this.Annotation = annotation;
        }
Example #58
0
 public static Operand Register(int index, RegisterType regType, OperandType type)
 {
     return(Operand().With(index, regType, type));
 }
Example #59
0
 public Operand ZeroExtend8(OperandType type, Operand op1)
 {
     return(Add(Instruction.ZeroExtend8, Local(type), op1));
 }
        public DoubleOperandFunctionMatrix()
        {
            var numOperandTypes = OperandType.GetNames(typeof(OperandType)).Length;

            _delegateMatrix = new DoubleOperandDelegate[numOperandTypes, numOperandTypes];
        }