OpCode.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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(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. return RegisterSize switch
  25. {
  26. RegisterSize.Int32 => 32,
  27. RegisterSize.Int64 => 64,
  28. RegisterSize.Simd64 => 64,
  29. RegisterSize.Simd128 => 128,
  30. _ => throw new InvalidOperationException(),
  31. };
  32. }
  33. public OperandType GetOperandType()
  34. {
  35. return RegisterSize == RegisterSize.Int32 ? OperandType.I32 : OperandType.I64;
  36. }
  37. }
  38. }