locident.h 4.3 KB

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