icode.cpp 3.0 KB

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