locident.h 5.0 KB

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