IterationIR.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. };
  50. }
  51. ir::Formula expand(const mnd::IterationFormula& fmla);
  52. }
  53. struct mnd::ir::NodeBase
  54. {
  55. std::any nodeData;
  56. };
  57. struct mnd::ir::Constant : NodeBase
  58. {
  59. mnd::Real value;
  60. inline Constant(double val) : value{ val } {}
  61. };
  62. struct mnd::ir::Variable : NodeBase
  63. {
  64. std::string name;
  65. inline Variable(const std::string name) : name{ name } {}
  66. };
  67. struct mnd::ir::UnaryOperation : NodeBase
  68. {
  69. Node* value;
  70. inline UnaryOperation(Node* value) : value{ value } {}
  71. };
  72. struct mnd::ir::Negation : mnd::ir::UnaryOperation
  73. {
  74. inline Negation(Node* value) : UnaryOperation{ value } {}
  75. };
  76. struct mnd::ir::BinaryOperation : NodeBase
  77. {
  78. Node* left;
  79. Node* right;
  80. inline BinaryOperation(Node* left, Node* right) :
  81. left{ left }, right{ right } {}
  82. };
  83. struct mnd::ir::Addition : mnd::ir::BinaryOperation
  84. {
  85. inline Addition(Node* left, Node* right) :
  86. BinaryOperation{ left, right } {}
  87. };
  88. struct mnd::ir::Subtraction : mnd::ir::BinaryOperation
  89. {
  90. inline Subtraction(Node* left, Node* right) :
  91. BinaryOperation{ left, right } {}
  92. };
  93. struct mnd::ir::Multiplication : mnd::ir::BinaryOperation
  94. {
  95. inline Multiplication(Node* left, Node* right) :
  96. BinaryOperation{ left, right } {}
  97. };
  98. struct mnd::ir::Atan2 : mnd::ir::BinaryOperation
  99. {
  100. inline Atan2(Node* left, Node* right) :
  101. BinaryOperation{ left, right } {}
  102. };
  103. struct mnd::ir::Pow : mnd::ir::BinaryOperation
  104. {
  105. inline Pow(Node* left, Node* right) :
  106. BinaryOperation{ left, right } {}
  107. };
  108. struct mnd::ir::Cos : mnd::ir::UnaryOperation
  109. {
  110. inline Cos(Node* value) : UnaryOperation{ value } {}
  111. };
  112. struct mnd::ir::Sin : mnd::ir::UnaryOperation
  113. {
  114. inline Sin(Node* value) : UnaryOperation{ value } {}
  115. };
  116. struct mnd::ir::Exp : mnd::ir::UnaryOperation
  117. {
  118. inline Exp(Node* value) : UnaryOperation{ value } {}
  119. };
  120. struct mnd::ir::Ln : mnd::ir::UnaryOperation
  121. {
  122. inline Ln(Node* value) : UnaryOperation{ value } {}
  123. };
  124. #endif // MANDEL_ITERATIONIR_H