locident.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * File: locIdent.h
  3. * Purpose: High-level local identifier definitions
  4. * Date: October 1993
  5. * (C) Cristina Cifuentes
  6. */
  7. #pragma once
  8. #include <vector>
  9. #include <algorithm>
  10. /* Type definition */
  11. struct IDX_ARRAY : public std::vector<int>
  12. {
  13. bool inList(int idx)
  14. {
  15. return std::find(begin(),end(),idx)!=end();
  16. }
  17. };
  18. /* Type definitions used in the decompiled program */
  19. typedef enum {
  20. TYPE_UNKNOWN = 0, /* unknown so far */
  21. TYPE_BYTE_SIGN, /* signed byte (8 bits) */
  22. TYPE_BYTE_UNSIGN, /* unsigned byte */
  23. TYPE_WORD_SIGN, /* signed word (16 bits) */
  24. TYPE_WORD_UNSIGN, /* unsigned word (16 bits) */
  25. TYPE_LONG_SIGN, /* signed long (32 bits) */
  26. TYPE_LONG_UNSIGN, /* unsigned long (32 bits) */
  27. TYPE_RECORD, /* record structure */
  28. TYPE_PTR, /* pointer (32 bit ptr) */
  29. TYPE_STR, /* string */
  30. TYPE_CONST, /* constant (any type) */
  31. TYPE_FLOAT, /* floating point */
  32. TYPE_DOUBLE /* double precision float */
  33. } hlType;
  34. static const char *hlTypes[13] = {"", "char", "unsigned char", "int", "unsigned int",
  35. "long", "unsigned long", "record", "int *", "char *",
  36. "", "float", "double"};
  37. typedef enum
  38. {
  39. STK_FRAME, /* For stack vars */
  40. REG_FRAME, /* For register variables */
  41. GLB_FRAME /* For globals */
  42. } frameType;
  43. typedef struct
  44. {
  45. int16 seg; /* segment value */
  46. int16 off; /* offset */
  47. byte regi; /* optional indexed register */
  48. } BWGLB_TYPE;
  49. typedef struct
  50. { /* For TYPE_LONG_(UN)SIGN on the stack */
  51. Int offH; /* high offset from BP */
  52. Int offL; /* low offset from BP */
  53. } LONG_STKID_TYPE;
  54. typedef struct
  55. { /* For TYPE_LONG_(UN)SIGN registers */
  56. byte h; /* high register */
  57. byte l; /* low register */
  58. } LONGID_TYPE;
  59. /* ID, LOCAL_ID */
  60. struct ID
  61. {
  62. hlType type; /* Probable type */
  63. boolT illegal;/* Boolean: not a valid field any more */
  64. IDX_ARRAY idx; /* Index into icode array (REG_FRAME only) */
  65. frameType loc; /* Frame location */
  66. boolT hasMacro;/* Identifier requires a macro */
  67. char macro[10];/* Macro for this identifier */
  68. char name[20];/* Identifier's name */
  69. union { /* Different types of identifiers */
  70. byte regi; /* For TYPE_BYTE(WORD)_(UN)SIGN registers */
  71. struct { /* For TYPE_BYTE(WORD)_(UN)SIGN on the stack */
  72. byte regOff; /* register offset (if any) */
  73. Int off; /* offset from BP */
  74. } bwId;
  75. BWGLB_TYPE bwGlb; /* For TYPE_BYTE(WORD)_(UN)SIGN globals */
  76. LONGID_TYPE longId; /* For TYPE_LONG_(UN)SIGN registers */
  77. LONG_STKID_TYPE longStkId;/* For TYPE_LONG_(UN)SIGN on the stack */
  78. struct { /* For TYPE_LONG_(UN)SIGN globals */
  79. int16 seg; /* segment value */
  80. int16 offH; /* offset high */
  81. int16 offL; /* offset low */
  82. byte regi; /* optional indexed register */
  83. } longGlb;
  84. struct { /* For TYPE_LONG_(UN)SIGN constants */
  85. dword h; /* high word */
  86. dword l; /* low word */
  87. } longKte;
  88. } id;
  89. ID()
  90. {
  91. memset(this,0,sizeof(ID));
  92. }
  93. ID(hlType t, frameType f)
  94. {
  95. memset(this,0,sizeof(ID));
  96. type=t;
  97. loc=f;
  98. }
  99. };
  100. struct LOCAL_ID
  101. {
  102. std::vector<ID> id_arr;
  103. public:
  104. LOCAL_ID()
  105. {}
  106. Int newByteWordReg(hlType t, byte regi);
  107. Int newByteWordStk(hlType t, Int off, byte regOff);
  108. Int newIntIdx(int16 seg, int16 off, byte regi, Int ix, hlType t);
  109. Int newLongReg(hlType t, byte regH, byte regL, Int ix);
  110. Int newLong(opLoc sd, ICODE *pIcode, hlFirst f, Int ix, operDu du, Int off);
  111. void newIdent(hlType t, frameType f);
  112. void flagByteWordId(Int off);
  113. void propLongId(byte regL, byte regH, const char *name);
  114. size_t csym() const {return id_arr.size();}
  115. protected:
  116. Int newLongIdx(int16 seg, int16 offH, int16 offL, byte regi, Int ix, hlType t);
  117. Int newLongGlb(int16 seg, int16 offH, int16 offL, Int ix, hlType t);
  118. Int newLongStk(hlType t, Int offH, Int offL);
  119. };