locident.h 4.6 KB

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