locident.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 <stdint.h>
  9. #include <vector>
  10. #include <list>
  11. #include <set>
  12. #include <algorithm>
  13. #include "types.h"
  14. #include "Enums.h"
  15. #include "machine_x86.h"
  16. /* Type definition */
  17. // this array has to stay in-order of addition i.e. not std::set<iICODE,std::less<iICODE> >
  18. // TODO: why ?
  19. struct COND_EXPR;
  20. struct ICODE;
  21. typedef std::list<ICODE>::iterator iICODE;
  22. struct IDX_ARRAY : public std::vector<iICODE>
  23. {
  24. bool inList(iICODE idx)
  25. {
  26. return std::find(begin(),end(),idx)!=end();
  27. }
  28. };
  29. typedef enum
  30. {
  31. STK_FRAME, /* For stack vars */
  32. REG_FRAME, /* For register variables */
  33. GLB_FRAME /* For globals */
  34. } frameType;
  35. typedef struct
  36. {
  37. int16_t seg; /* segment value */
  38. int16_t off; /* offset */
  39. eReg regi; /* optional indexed register */
  40. } BWGLB_TYPE;
  41. typedef struct
  42. { /* For TYPE_LONG_(UN)SIGN on the stack */
  43. int offH; /* high offset from BP */
  44. int offL; /* low offset from BP */
  45. } LONG_STKID_TYPE;
  46. typedef struct
  47. { /* For TYPE_LONG_(UN)SIGN registers */
  48. eReg h; /* high register */
  49. eReg l; /* low register */
  50. } LONGID_TYPE;
  51. /* ID, LOCAL_ID */
  52. struct ID
  53. {
  54. hlType type; /* Probable type */
  55. bool illegal; /* Boolean: not a valid field any more */
  56. //std::vector<iICODE> idx;
  57. IDX_ARRAY idx; /* Index into icode array (REG_FRAME only) */
  58. frameType loc; /* Frame location */
  59. bool hasMacro; /* Identifier requires a macro */
  60. char macro[10]; /* Macro for this identifier */
  61. std::string name; /* Identifier's name */
  62. union { /* Different types of identifiers */
  63. eReg regi; /* For TYPE_BYTE(uint16_t)_(UN)SIGN registers */
  64. struct { /* For TYPE_BYTE(uint16_t)_(UN)SIGN on the stack */
  65. uint8_t regOff; /* register offset (if any) */
  66. int off; /* offset from BP */
  67. } bwId;
  68. BWGLB_TYPE bwGlb; /* For TYPE_BYTE(uint16_t)_(UN)SIGN globals */
  69. LONGID_TYPE longId; /* For TYPE_LONG_(UN)SIGN registers */
  70. LONG_STKID_TYPE longStkId; /* For TYPE_LONG_(UN)SIGN on the stack */
  71. struct { /* For TYPE_LONG_(UN)SIGN globals */
  72. int16_t seg; /* segment value */
  73. int16_t offH; /* offset high */
  74. int16_t offL; /* offset low */
  75. uint8_t regi; /* optional indexed register */
  76. } longGlb;
  77. struct { /* For TYPE_LONG_(UN)SIGN constants */
  78. uint32_t h; /* high uint16_t */
  79. uint32_t l; /* low uint16_t */
  80. } longKte;
  81. } id;
  82. ID();
  83. ID(hlType t, frameType f);
  84. bool isSigned() const { return (type==TYPE_BYTE_SIGN)||(type==TYPE_WORD_SIGN)||(type==TYPE_LONG_SIGN);}
  85. uint16_t typeBitsize() const
  86. {
  87. return TypeContainer::typeSize(type)*8;
  88. }
  89. void setLocalName(int i)
  90. {
  91. char buf[32];
  92. sprintf (buf, "loc%ld", i);
  93. name=buf;
  94. }
  95. };
  96. struct LOCAL_ID
  97. {
  98. std::vector<ID> id_arr;
  99. protected:
  100. int newLongIdx(int16_t seg, int16_t offH, int16_t offL, uint8_t regi, hlType t);
  101. int newLongGlb(int16_t seg, int16_t offH, int16_t offL, hlType t);
  102. int newLongStk(hlType t, int offH, int offL);
  103. public:
  104. LOCAL_ID()
  105. {
  106. id_arr.reserve(256);
  107. }
  108. // interface to allow range based iteration
  109. std::vector<ID>::iterator begin() {return id_arr.begin();}
  110. std::vector<ID>::iterator end() {return id_arr.end();}
  111. int newByteWordReg(hlType t, eReg regi);
  112. int newByteWordStk(hlType t, int off, uint8_t regOff);
  113. int newIntIdx(int16_t seg, int16_t off, eReg regi, int ix, hlType t);
  114. int newLongReg(hlType t, eReg regH, eReg regL, iICODE ix_);
  115. int newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, int off);
  116. int newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, iICODE atOffset);
  117. void newIdent(hlType t, frameType f);
  118. void flagByteWordId(int off);
  119. void propLongId(uint8_t regL, uint8_t regH, const char *name);
  120. size_t csym() const {return id_arr.size();}
  121. void newRegArg(iICODE picode, iICODE ticode) const;
  122. void processTargetIcode(iICODE picode, int &numHlIcodes, iICODE ticode, bool isLong) const;
  123. void forwardSubs(COND_EXPR *lhs, COND_EXPR *rhs, iICODE picode, iICODE ticode, int &numHlIcodes) const;
  124. COND_EXPR *createId(const ID *retVal, iICODE ix_);
  125. };