RegisterNode.cpp 3.1 KB

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