OpCode.cs 1.3 KB

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