IterationIR.h 3.9 KB

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