RegisterNode.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include <stdint.h>
  2. #include <string>
  3. #include <sstream>
  4. #include <iostream>
  5. #include <cassert>
  6. #include <boost/range.hpp>
  7. #include <boost/range/adaptors.hpp>
  8. //#include <boost/range/algorithm.hpp>
  9. //#include <boost/assign.hpp>
  10. #include "types.h"
  11. #include "ast.h"
  12. #include "bundle.h"
  13. #include "machine_x86.h"
  14. #include "project.h"
  15. using namespace std;
  16. using namespace boost::adaptors;
  17. RegisterNode::RegisterNode(const LLOperand &op, LOCAL_ID *locsym)
  18. {
  19. m_syms = locsym;
  20. ident.type(REGISTER);
  21. hlType type_sel;
  22. regType reg_type;
  23. if (op.byteWidth()==1)
  24. {
  25. type_sel = TYPE_BYTE_SIGN;
  26. reg_type = BYTE_REG;
  27. }
  28. else /* uint16_t */
  29. {
  30. type_sel = TYPE_WORD_SIGN;
  31. reg_type = WORD_REG;
  32. }
  33. regiIdx = locsym->newByteWordReg(type_sel, op.regi);
  34. regiType = reg_type;
  35. }
  36. //RegisterNode::RegisterNode(eReg regi, uint32_t icodeFlg, LOCAL_ID *locsym)
  37. //{
  38. // ident.type(REGISTER);
  39. // hlType type_sel;
  40. // regType reg_type;
  41. // if ((icodeFlg & B) || (icodeFlg & SRC_B))
  42. // {
  43. // type_sel = TYPE_BYTE_SIGN;
  44. // reg_type = BYTE_REG;
  45. // }
  46. // else /* uint16_t */
  47. // {
  48. // type_sel = TYPE_WORD_SIGN;
  49. // reg_type = WORD_REG;
  50. // }
  51. // regiIdx = locsym->newByteWordReg(type_sel, regi);
  52. // regiType = reg_type;
  53. //}
  54. string RegisterNode::walkCondExpr(Function *pProc, int *numLoc) const
  55. {
  56. std::ostringstream codeOut;
  57. std::ostringstream o;
  58. assert(&pProc->localId==m_syms);
  59. ID *id = &pProc->localId.id_arr[regiIdx];
  60. if (id->name[0] == '\0') /* no name */
  61. {
  62. id->setLocalName(++(*numLoc));
  63. codeOut <<TypeContainer::typeName(id->type)<< " "<<id->name<<"; ";
  64. codeOut <<"/* "<<Machine_X86::regName(id->id.regi)<<" */\n";
  65. }
  66. if (id->hasMacro)
  67. o << id->macro << "("<<id->name<<")";
  68. else
  69. o << id->name;
  70. cCode.appendDecl(codeOut.str());
  71. return o.str();
  72. }
  73. int RegisterNode::hlTypeSize(Function *) const
  74. {
  75. if (regiType == BYTE_REG)
  76. return (1);
  77. else
  78. return (2);
  79. }
  80. hlType RegisterNode::expType(Function *pproc) const
  81. {
  82. if (regiType == BYTE_REG)
  83. return (TYPE_BYTE_SIGN);
  84. else
  85. return (TYPE_WORD_SIGN);
  86. }
  87. Expr *RegisterNode::insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym)
  88. {
  89. assert(locsym==m_syms);
  90. eReg treeReg = locsym->id_arr[regiIdx].id.regi;
  91. if (treeReg == regi) /* uint16_t reg */
  92. {
  93. return _expr;
  94. }
  95. else if(Machine_X86::isSubRegisterOf(treeReg,regi)) /* uint16_t/uint8_t reg */
  96. {
  97. return _expr;
  98. }
  99. return nullptr;
  100. }
  101. bool RegisterNode::xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locId)
  102. {
  103. uint8_t regi = locId.id_arr[regiIdx].id.regi;
  104. range_to_check.advance_begin(1);
  105. auto all_valid_and_high_level_after_start = range_to_check | filtered(ICODE::select_valid_high_level);
  106. for (ICODE &i : all_valid_and_high_level_after_start)
  107. if (i.du.def.testRegAndSubregs(regi))
  108. return false;
  109. if (all_valid_and_high_level_after_start.end().base() != lastBBinst)
  110. return true;
  111. return false;
  112. }