1
0

IterationIR.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #ifndef MANDEL_ITERATIONIR_H
  2. #define MANDEL_ITERATIONIR_H
  3. #include <string>
  4. #include <vector>
  5. #include <variant>
  6. #include <any>
  7. #include "IterationFormula.h"
  8. #include "Types.h"
  9. #include "Arena.h"
  10. namespace mnd
  11. {
  12. namespace ir
  13. {
  14. struct NodeBase;
  15. struct Constant;
  16. struct Variable;
  17. struct UnaryOperation;
  18. struct Negation;
  19. struct BinaryOperation;
  20. struct Addition;
  21. struct Subtraction;
  22. struct Multiplication;
  23. struct Division;
  24. // struct CPow;
  25. // struct RPow;
  26. struct Atan2;
  27. struct Pow;
  28. struct Cos;
  29. struct Sin;
  30. struct Exp;
  31. struct Ln;
  32. using Node = std::variant<
  33. Constant,
  34. Variable,
  35. Negation,
  36. Addition,
  37. Subtraction,
  38. Multiplication,
  39. Division,
  40. // CPow,
  41. // RPow,
  42. Atan2,
  43. Pow,
  44. Cos,
  45. Sin,
  46. Exp,
  47. Ln
  48. >;
  49. struct Formula
  50. {
  51. util::Arena<Node> nodeArena;
  52. Node* newA;
  53. Node* newB;
  54. std::string toString(void) const;
  55. void constantPropagation(void);
  56. };
  57. }
  58. ir::Formula expand(const mnd::IterationFormula& fmla);
  59. }
  60. struct mnd::ir::NodeBase
  61. {
  62. std::any nodeData;
  63. };
  64. struct mnd::ir::Constant : NodeBase
  65. {
  66. mnd::Real value;
  67. inline Constant(const mnd::Real& val) : value{ val } {}
  68. };
  69. struct mnd::ir::Variable : NodeBase
  70. {
  71. std::string name;
  72. inline Variable(const std::string name) : name{ name } {}
  73. };
  74. struct mnd::ir::UnaryOperation : NodeBase
  75. {
  76. Node* value;
  77. inline UnaryOperation(Node* value) : value{ value } {}
  78. };
  79. struct mnd::ir::Negation : mnd::ir::UnaryOperation
  80. {
  81. inline Negation(Node* value) : UnaryOperation{ value } {}
  82. };
  83. struct mnd::ir::BinaryOperation : NodeBase
  84. {
  85. Node* left;
  86. Node* right;
  87. inline BinaryOperation(Node* left, Node* right) :
  88. left{ left }, right{ right } {}
  89. };
  90. struct mnd::ir::Addition : mnd::ir::BinaryOperation
  91. {
  92. inline Addition(Node* left, Node* right) :
  93. BinaryOperation{ left, right } {}
  94. };
  95. struct mnd::ir::Subtraction : mnd::ir::BinaryOperation
  96. {
  97. inline Subtraction(Node* left, Node* right) :
  98. BinaryOperation{ left, right } {}
  99. };
  100. struct mnd::ir::Multiplication : mnd::ir::BinaryOperation
  101. {
  102. inline Multiplication(Node* left, Node* right) :
  103. BinaryOperation{ left, right } {}
  104. };
  105. struct mnd::ir::Division : mnd::ir::BinaryOperation
  106. {
  107. inline Division(Node* left, Node* right) :
  108. BinaryOperation{ left, right } {}
  109. };
  110. /*
  111. struct mnd::ir::CPow : mnd::ir::NodeBase
  112. {
  113. Node* re;
  114. Node* im;
  115. Node* ere;
  116. Node* eim;
  117. inline CPow(Node* re, Node* im, Node* ere, Node* eim) :
  118. re{ re }, im{ im }, ere{ ere }, eim{ eim }
  119. {}
  120. };
  121. struct mnd::ir::RPow : mnd::ir::NodeBase
  122. {
  123. Node* re;
  124. Node* im;
  125. Node* exponent;
  126. inline RPow(Node* re, Node* im, Node* exponent) :
  127. re{ re }, im{ im }, exponent{ exponent }
  128. {}
  129. };*/
  130. struct mnd::ir::Atan2 : mnd::ir::BinaryOperation
  131. {
  132. inline Atan2(Node* left, Node* right) :
  133. BinaryOperation{ left, right } {}
  134. };
  135. struct mnd::ir::Pow : mnd::ir::BinaryOperation
  136. {
  137. inline Pow(Node* left, Node* right) :
  138. BinaryOperation{ left, right } {}
  139. };
  140. struct mnd::ir::Cos : mnd::ir::UnaryOperation
  141. {
  142. inline Cos(Node* value) : UnaryOperation{ value } {}
  143. };
  144. struct mnd::ir::Sin : mnd::ir::UnaryOperation
  145. {
  146. inline Sin(Node* value) : UnaryOperation{ value } {}
  147. };
  148. struct mnd::ir::Exp : mnd::ir::UnaryOperation
  149. {
  150. inline Exp(Node* value) : UnaryOperation{ value } {}
  151. };
  152. struct mnd::ir::Ln : mnd::ir::UnaryOperation
  153. {
  154. inline Ln(Node* value) : UnaryOperation{ value } {}
  155. };
  156. #endif // MANDEL_ITERATIONIR_H