icode.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. }