icode.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Object oriented icode code for dcc
  2. // (C) 1997 Mike Van Emmerik
  3. #include <stdlib.h>
  4. #include "dcc.h"
  5. #include "types.h" // Common types like uint8_t, etc
  6. #include "ast.h" // Some icode types depend on these
  7. #include "icode.h"
  8. ICODE::TypeFilter<HIGH_LEVEL> ICODE::select_high_level;
  9. ICODE::TypeAndValidFilter<HIGH_LEVEL> ICODE::select_valid_high_level;
  10. CIcodeRec::CIcodeRec()
  11. {
  12. }
  13. /* Copies the icode that is pointed to by pIcode to the icode array.
  14. * If there is need to allocate extra memory, it is done so, and
  15. * the alloc variable is adjusted. */
  16. ICODE * CIcodeRec::addIcode(ICODE *pIcode)
  17. {
  18. push_back(*pIcode);
  19. back().loc_ip = size()-1;
  20. return &back();
  21. }
  22. void CIcodeRec::SetInBB(rCODE &rang, BB *pnewBB)
  23. {
  24. for(ICODE &ic : rang)
  25. ic.setParent(pnewBB);
  26. }
  27. /* labelSrchRepl - Searches the icodes for instruction with label = target, and
  28. replaces *pIndex with an icode index */
  29. bool CIcodeRec::labelSrch(uint32_t target, uint32_t &pIndex)
  30. {
  31. iICODE location=labelSrch(target);
  32. if(end()==location)
  33. return false;
  34. pIndex=location->loc_ip;
  35. return true;
  36. }
  37. bool CIcodeRec::alreadyDecoded(uint32_t target)
  38. {
  39. iICODE location=labelSrch(target);
  40. if(end()==location)
  41. return false;
  42. return true;
  43. }
  44. CIcodeRec::iterator CIcodeRec::labelSrch(uint32_t target)
  45. {
  46. return find_if(begin(),end(),[target](ICODE &l) -> bool {return l.ll()->label==target;});
  47. }
  48. ICODE * CIcodeRec::GetIcode(size_t ip)
  49. {
  50. assert(ip<size());
  51. iICODE res=begin();
  52. advance(res,ip);
  53. return &(*res);
  54. }
  55. extern int getNextLabel();
  56. extern bundle cCode;
  57. /* Checks the given icode to determine whether it has a label associated
  58. * to it. If so, a goto is emitted to this label; otherwise, a new label
  59. * is created and a goto is also emitted.
  60. * Note: this procedure is to be used when the label is to be backpatched
  61. * onto code in cCode.code */
  62. void LLInst::emitGotoLabel (int indLevel)
  63. {
  64. if ( not testFlags(HLL_LABEL) ) /* node hasn't got a lab */
  65. {
  66. /* Generate new label */
  67. hllLabNum = getNextLabel();
  68. setFlags(HLL_LABEL);
  69. /* Node has been traversed already, so backpatch this label into
  70. * the code */
  71. cCode.code.addLabelBundle (codeIdx, hllLabNum);
  72. }
  73. cCode.appendCode( "%sgoto L%ld;\n", indentStr(indLevel), hllLabNum);
  74. stats.numHLIcode++;
  75. }
  76. bool LLOperand::isReg() const
  77. {
  78. return (regi>=rAX) && (regi<=rTMP);
  79. }
  80. void LLOperand::addProcInformation(int param_count, uint32_t call_conv)
  81. {
  82. proc.proc->cbParam = (int16_t)param_count;
  83. proc.cb = param_count;
  84. proc.proc->flg |= call_conv;
  85. }
  86. void HLTYPE::setCall(Function *proc)
  87. {
  88. opcode = HLI_CALL;
  89. call.proc = proc;
  90. call.args = new STKFRAME;
  91. }
  92. bool AssignType::removeRegFromLong(eReg regi, LOCAL_ID *locId)
  93. {
  94. m_lhs=lhs()->performLongRemoval(regi,locId);
  95. return true;
  96. }
  97. void AssignType::lhs(Expr *l)
  98. {
  99. assert(dynamic_cast<UnaryOperator *>(l));
  100. m_lhs=l;
  101. }