IterationIR.h 3.8 KB

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