operand.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef OPERAND_H
  2. #define OPERAND_H
  3. #include "fixed_types.h"
  4. #include <sstream>
  5. #include <iostream>
  6. #include <vector>
  7. class Operand
  8. {
  9. public:
  10. enum Type
  11. {
  12. REG,
  13. MEMORY,
  14. IMMEDIATE
  15. };
  16. enum Direction
  17. {
  18. READ,
  19. WRITE
  20. };
  21. typedef UInt64 Value;
  22. Operand(const Operand &src)
  23. : m_type(src.m_type), m_value(src.m_value), m_direction(src.m_direction), m_value_name(src.m_value_name), m_mem_operand(src.m_mem_operand) {}
  24. Operand(Type type, Value value = 0, Direction direction = READ, const String& value_name = String(), bool mem_operand = false)
  25. : m_type(type), m_value(value), m_direction(direction), m_value_name(value_name), m_mem_operand(mem_operand) {}
  26. String toString (void) const
  27. {
  28. std::ostringstream o;
  29. o << "Operand: ";
  30. if (m_type == REG)
  31. o << "REG";
  32. if (m_type == MEMORY)
  33. o << "MEMORY";
  34. if (m_type == IMMEDIATE)
  35. o << "IMMEDIATE";
  36. o << " ";
  37. if (m_direction == READ)
  38. o << "READ";
  39. if (m_direction == WRITE)
  40. o << "WRITE";
  41. o << " ";
  42. if (m_type == REG)
  43. o << m_value_name << "[Operand:" << m_mem_operand << "] (" << m_value << ")";
  44. else
  45. o << m_value;
  46. return String(o.str().c_str());
  47. }
  48. Type m_type;
  49. Value m_value;
  50. Direction m_direction;
  51. String m_value_name; // for m_type == REG
  52. bool m_mem_operand; // for m_type == REG
  53. };
  54. typedef std::vector<Operand> OperandList;
  55. #endif /* OPERAND_H */