icode.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Object oriented icode code for dcc
  2. // (C) 1997 Mike Van Emmerik
  3. #include <stdlib.h>
  4. #include <malloc.h>
  5. #include <memory.h>
  6. #include "types.h" // Common types like byte, etc
  7. #include "ast.h" // Some icode types depend on these
  8. #include "icode.h"
  9. #define ICODE_DELTA 25 // Amount to allocate for new chunk
  10. CIcodeRec::CIcodeRec()
  11. {
  12. }
  13. CIcodeRec::~CIcodeRec()
  14. {
  15. }
  16. /* Copies the icode that is pointed to by pIcode to the icode array.
  17. * If there is need to allocate extra memory, it is done so, and
  18. * the alloc variable is adjusted. */
  19. ICODE * CIcodeRec::addIcode(ICODE *pIcode)
  20. {
  21. push_back(*pIcode);
  22. return &back();
  23. }
  24. ICODE * CIcodeRec::GetFirstIcode()
  25. {
  26. return &front();
  27. }
  28. /* Don't need this; just pIcode++ since array is guaranteed to be contiguous
  29. ICODE * CIcodeRec::GetNextIcode(ICODE * pCurIcode)
  30. {
  31. int idx = pCurIcode - icode; // Current index
  32. ASSERT(idx+1 < numIcode);
  33. return &icode[idx+1];
  34. }
  35. */
  36. boolT CIcodeRec::IsValid(ICODE *pCurIcode)
  37. {
  38. ptrdiff_t idx = pCurIcode - &this->front(); // Current index
  39. return (idx>=0) && (idx < size());
  40. }
  41. int CIcodeRec::GetNumIcodes()
  42. {
  43. return size();
  44. }
  45. void CIcodeRec::SetInBB(int start, int end, BB *pnewBB)
  46. {
  47. for (int i = start; i <= end; i++)
  48. at(i).inBB = pnewBB;
  49. }
  50. void CIcodeRec::SetImmediateOp(int ip, dword dw)
  51. {
  52. at(ip).ic.ll.immed.op = dw;
  53. }
  54. void CIcodeRec::SetLlFlag(int ip, dword flag)
  55. {
  56. at(ip).ic.ll.flg |= flag;
  57. }
  58. dword CIcodeRec::GetLlFlag(int ip)
  59. {
  60. return at(ip).ic.ll.flg;
  61. }
  62. void CIcodeRec::ClearLlFlag(int ip, dword flag)
  63. {
  64. at(ip).ic.ll.flg &= (~flag);
  65. }
  66. void CIcodeRec::SetLlInvalid(int ip, boolT fInv)
  67. {
  68. at(ip).invalid = fInv;
  69. }
  70. dword CIcodeRec::GetLlLabel(int ip)
  71. {
  72. return at(ip).ic.ll.label;
  73. }
  74. llIcode CIcodeRec::GetLlOpcode(int ip)
  75. {
  76. return at(ip).ic.ll.opcode;
  77. }
  78. /* labelSrchRepl - Searches the icodes for instruction with label = target, and
  79. replaces *pIndex with an icode index */
  80. boolT CIcodeRec::labelSrch(dword target, Int *pIndex)
  81. {
  82. Int i;
  83. for (i = 0; i < size(); i++)
  84. {
  85. if (at(i).ic.ll.label == target)
  86. {
  87. *pIndex = i;
  88. return TRUE;
  89. }
  90. }
  91. return FALSE;
  92. }
  93. ICODE * CIcodeRec::GetIcode(int ip)
  94. {
  95. return &at(ip);
  96. }