IterationIR.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 Atan2;
  24. struct Pow;
  25. struct Cos;
  26. struct Sin;
  27. struct Exp;
  28. struct Ln;
  29. using Node = std::variant<
  30. Constant,
  31. Variable,
  32. Negation,
  33. Addition,
  34. Subtraction,
  35. Multiplication,
  36. Atan2,
  37. Pow,
  38. Cos,
  39. Sin,
  40. Exp,
  41. Ln
  42. >;
  43. struct Formula
  44. {
  45. util::Arena<Node> nodeArena;
  46. Node* newA;
  47. Node* newB;
  48. std::string toString(void) const;
  49. void constantPropagation(void);
  50. };
  51. }
  52. ir::Formula expand(const mnd::IterationFormula& fmla);
  53. }
  54. struct mnd::ir::NodeBase
  55. {
  56. std::any nodeData;
  57. };
  58. struct mnd::ir::Constant : NodeBase
  59. {
  60. mnd::Real value;
  61. inline Constant(double val) : value{ val } {}
  62. };
  63. struct mnd::ir::Variable : NodeBase
  64. {
  65. std::string name;
  66. inline Variable(const std::string name) : name{ name } {}
  67. };
  68. struct mnd::ir::UnaryOperation : NodeBase
  69. {
  70. Node* value;
  71. inline UnaryOperation(Node* value) : value{ value } {}
  72. };
  73. struct mnd::ir::Negation : mnd::ir::UnaryOperation
  74. {
  75. inline Negation(Node* value) : UnaryOperation{ value } {}
  76. };
  77. struct mnd::ir::BinaryOperation : NodeBase
  78. {
  79. Node* left;
  80. Node* right;
  81. inline BinaryOperation(Node* left, Node* right) :
  82. left{ left }, right{ right } {}
  83. };
  84. struct mnd::ir::Addition : mnd::ir::BinaryOperation
  85. {
  86. inline Addition(Node* left, Node* right) :
  87. BinaryOperation{ left, right } {}
  88. };
  89. struct mnd::ir::Subtraction : mnd::ir::BinaryOperation
  90. {
  91. inline Subtraction(Node* left, Node* right) :
  92. BinaryOperation{ left, right } {}
  93. };
  94. struct mnd::ir::Multiplication : mnd::ir::BinaryOperation
  95. {
  96. inline Multiplication(Node* left, Node* right) :
  97. BinaryOperation{ left, right } {}
  98. };
  99. struct mnd::ir::Atan2 : mnd::ir::BinaryOperation
  100. {
  101. inline Atan2(Node* left, Node* right) :
  102. BinaryOperation{ left, right } {}
  103. };
  104. struct mnd::ir::Pow : mnd::ir::BinaryOperation
  105. {
  106. inline Pow(Node* left, Node* right) :
  107. BinaryOperation{ left, right } {}
  108. };
  109. struct mnd::ir::Cos : mnd::ir::UnaryOperation
  110. {
  111. inline Cos(Node* value) : UnaryOperation{ value } {}
  112. };
  113. struct mnd::ir::Sin : mnd::ir::UnaryOperation
  114. {
  115. inline Sin(Node* value) : UnaryOperation{ value } {}
  116. };
  117. struct mnd::ir::Exp : mnd::ir::UnaryOperation
  118. {
  119. inline Exp(Node* value) : UnaryOperation{ value } {}
  120. };
  121. struct mnd::ir::Ln : mnd::ir::UnaryOperation
  122. {
  123. inline Ln(Node* value) : UnaryOperation{ value } {}
  124. };
  125. #endif // MANDEL_ITERATIONIR_H