IterationIR.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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* startA;
  53. Node* startB;
  54. Node* newA;
  55. Node* newB;
  56. std::string toString(void) const;
  57. void constantPropagation(void);
  58. void optimize(void);
  59. };
  60. }
  61. ir::Formula expand(const mnd::IterationFormula& z0, const mnd::IterationFormula& zi);
  62. }
  63. struct mnd::ir::NodeBase
  64. {
  65. std::any nodeData;
  66. };
  67. struct mnd::ir::Constant : NodeBase
  68. {
  69. mnd::Real value;
  70. inline Constant(const mnd::Real& val) : value{ val } {}
  71. };
  72. struct mnd::ir::Variable : NodeBase
  73. {
  74. std::string name;
  75. inline Variable(const std::string name) : name{ name } {}
  76. };
  77. struct mnd::ir::UnaryOperation : NodeBase
  78. {
  79. Node* value;
  80. inline UnaryOperation(Node* value) : value{ value } {}
  81. };
  82. struct mnd::ir::Negation : mnd::ir::UnaryOperation
  83. {
  84. inline Negation(Node* value) : UnaryOperation{ value } {}
  85. };
  86. struct mnd::ir::BinaryOperation : NodeBase
  87. {
  88. Node* left;
  89. Node* right;
  90. inline BinaryOperation(Node* left, Node* right) :
  91. left{ left }, right{ right } {}
  92. };
  93. struct mnd::ir::Addition : mnd::ir::BinaryOperation
  94. {
  95. inline Addition(Node* left, Node* right) :
  96. BinaryOperation{ left, right } {}
  97. };
  98. struct mnd::ir::Subtraction : mnd::ir::BinaryOperation
  99. {
  100. inline Subtraction(Node* left, Node* right) :
  101. BinaryOperation{ left, right } {}
  102. };
  103. struct mnd::ir::Multiplication : mnd::ir::BinaryOperation
  104. {
  105. inline Multiplication(Node* left, Node* right) :
  106. BinaryOperation{ left, right } {}
  107. };
  108. struct mnd::ir::Division : mnd::ir::BinaryOperation
  109. {
  110. inline Division(Node* left, Node* right) :
  111. BinaryOperation{ left, right } {}
  112. };
  113. /*
  114. struct mnd::ir::CPow : mnd::ir::NodeBase
  115. {
  116. Node* re;
  117. Node* im;
  118. Node* ere;
  119. Node* eim;
  120. inline CPow(Node* re, Node* im, Node* ere, Node* eim) :
  121. re{ re }, im{ im }, ere{ ere }, eim{ eim }
  122. {}
  123. };
  124. struct mnd::ir::RPow : mnd::ir::NodeBase
  125. {
  126. Node* re;
  127. Node* im;
  128. Node* exponent;
  129. inline RPow(Node* re, Node* im, Node* exponent) :
  130. re{ re }, im{ im }, exponent{ exponent }
  131. {}
  132. };*/
  133. struct mnd::ir::Atan2 : mnd::ir::BinaryOperation
  134. {
  135. inline Atan2(Node* left, Node* right) :
  136. BinaryOperation{ left, right } {}
  137. };
  138. struct mnd::ir::Pow : mnd::ir::BinaryOperation
  139. {
  140. inline Pow(Node* left, Node* right) :
  141. BinaryOperation{ left, right } {}
  142. };
  143. struct mnd::ir::Cos : mnd::ir::UnaryOperation
  144. {
  145. inline Cos(Node* value) : UnaryOperation{ value } {}
  146. };
  147. struct mnd::ir::Sin : mnd::ir::UnaryOperation
  148. {
  149. inline Sin(Node* value) : UnaryOperation{ value } {}
  150. };
  151. struct mnd::ir::Exp : mnd::ir::UnaryOperation
  152. {
  153. inline Exp(Node* value) : UnaryOperation{ value } {}
  154. };
  155. struct mnd::ir::Ln : mnd::ir::UnaryOperation
  156. {
  157. inline Ln(Node* value) : UnaryOperation{ value } {}
  158. };
  159. #endif // MANDEL_ITERATIONIR_H