Advertisement
Guest User

Untitled

a guest
May 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. //instructionselection.cpp
  2. #include "Registers.h"
  3. #include "Instruction.h"
  4. #include "Tree.h"
  5. #include "Munch.h"
  6.  
  7. #include <iostream>
  8. #include <list>
  9.  
  10. using namespace std;
  11.  
  12.  
  13. int main()
  14. {
  15. Reg reg1 = 1;
  16. Reg reg2 = 2;
  17. Reg reg3 = 3;
  18.  
  19. Statement* root;
  20.  
  21. cout << "*******************************************************************" << endl;
  22. cout << "*******************************************************************" << endl;
  23. cout << "**************** INSTRUCTION SELECTION START... *****************" << endl;
  24. cout << "*******************************************************************" << endl << endl;
  25.  
  26. // Note: uncomment the desired tree for instruction selection
  27.  
  28. // PLUS
  29. Statement* instruction11 = new S_Exp(new E_Binop(E_Binop::PLUS_OP, new E_Reg(reg1), new E_Const(20)));
  30. Statement* instruction12 = new S_Exp(new E_Binop(E_Binop::PLUS_OP, new E_Const(20), new E_Reg(reg1)));
  31. Statement* instruction13 = new S_Exp(new E_Binop(E_Binop::PLUS_OP, new E_Reg(reg1), new E_Reg(reg2)));
  32. root = new S_Seq(instruction11, new S_Seq(instruction12, instruction13));
  33.  
  34. // MINUS
  35. //Statement* instruction21 = new S_Exp(new E_Binop(E_Binop::MINUS_OP, new E_Reg(reg1), new E_Reg(reg2)));
  36. //root = instruction21;
  37.  
  38. // LW
  39. Statement* instruction31 = new S_Exp(new E_Mem(new E_Binop(E_Binop::PLUS_OP, new E_Const(15), new E_Reg(reg2))));
  40. Statement* instruction32 = new S_Exp(new E_Mem(new E_Binop(E_Binop::PLUS_OP, new E_Reg(reg2), new E_Const(20))));
  41. Statement* instruction33 = new S_Exp(new E_Mem(new E_Const(0x10010000)));
  42. Statement* instruction34 = new S_Exp(new E_Mem(new E_Reg(reg2)));
  43. root = new S_Seq(instruction31, new S_Seq(instruction32, new S_Seq(instruction33, instruction34)));
  44.  
  45. // SW
  46. //Statement* instruction41 = new S_Move(
  47. // new E_Mem(new E_Binop(E_Binop::PLUS_OP, new E_Const(0), new E_Const(0x10010000))), // dst
  48. // new E_Const(4) // src
  49. //);
  50. //Statement* instruction42 = new S_Move(
  51. // new E_Mem(new E_Binop(E_Binop::PLUS_OP, new E_Const(0), new E_Reg(reg2))), // dst
  52. // new E_Const(4) // src
  53. //);
  54. //Statement* instruction43 = new S_Move(
  55. // new E_Mem(new E_Binop(E_Binop::PLUS_OP, new E_Reg(reg2), new E_Const(0))), // dst
  56. // new E_Const(4) // src
  57. //);
  58. //Statement* instruction44 = new S_Move(
  59. // new E_Mem(new E_Const(0x10010000)), // dst
  60. // new E_Const(4) // src
  61. //);
  62. //Statement* instruction45 = new S_Move(
  63. // new E_Mem(new E_Reg(reg2)), // dst
  64. // new E_Const(4) // src
  65. //);
  66. //root = new S_Seq(instruction41, new S_Seq(instruction42, new S_Seq(instruction43, new S_Seq(instruction44, instruction45))));
  67.  
  68. // MOVE
  69. //Statement* instruction51 = new S_Move(
  70. // new E_Mem(new E_Reg(reg2)), // dst
  71. // new E_Mem(new E_Reg(reg1)) // src
  72. //);
  73. //root = instruction51;
  74.  
  75. // PROGRAM (from pdf)
  76. //Statement* program = new S_Move(
  77. // new E_Mem(new E_Binop(E_Binop::PLUS_OP,
  78. // new E_Mem(new E_Binop(E_Binop::PLUS_OP, new E_Const(20), new E_Reg(reg1))),
  79. // new E_Binop(E_Binop::MINUS_OP, new E_Const(15), new E_Reg(reg2))
  80. // )
  81. // ),
  82. // new E_Mem(new E_Binop(E_Binop::PLUS_OP, new E_Const(10), new E_Reg(reg3)))
  83. // );
  84. //root = program;
  85.  
  86. munchStm(root);
  87.  
  88. InstructionList instructionList = getInstructionList();
  89. for (auto inst : instructionList)
  90. {
  91. cout << inst->toString() << endl;
  92. }
  93.  
  94. cout << "*******************************************************************" << endl;
  95. cout << "************ INSTRUCTION SELECTION END SUCESSFULL! ***************" << endl;
  96. cout << "********************** press any key ...***************************" << endl;
  97. cout << "*******************************************************************" << endl;
  98.  
  99. getchar();
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement