OpCode.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using ARMeilleure.IntermediateRepresentation;
  2. using System;
  3. namespace ARMeilleure.Decoders
  4. {
  5. class OpCode : IOpCode
  6. {
  7. public ulong Address { get; }
  8. public int RawOpCode { get; }
  9. public int OpCodeSizeInBytes { get; protected set; } = 4;
  10. public InstDescriptor Instruction { get; protected set; }
  11. public RegisterSize RegisterSize { get; protected set; }
  12. public static OpCode Create(InstDescriptor inst, ulong address, int opCode) => new OpCode(inst, address, opCode);
  13. public OpCode(InstDescriptor inst, ulong address, int opCode)
  14. {
  15. Instruction = inst;
  16. Address = address;
  17. RawOpCode = opCode;
  18. RegisterSize = RegisterSize.Int64;
  19. }
  20. public int GetPairsCount() => GetBitsCount() / 16;
  21. public int GetBytesCount() => GetBitsCount() / 8;
  22. public int GetBitsCount()
  23. {
  24. switch (RegisterSize)
  25. {
  26. case RegisterSize.Int32: return 32;
  27. case RegisterSize.Int64: return 64;
  28. case RegisterSize.Simd64: return 64;
  29. case RegisterSize.Simd128: return 128;
  30. }
  31. throw new InvalidOperationException();
  32. }
  33. public OperandType GetOperandType()
  34. {
  35. return RegisterSize == RegisterSize.Int32 ? OperandType.I32 : OperandType.I64;
  36. }
  37. }
  38. }