IterationIR.h 2.7 KB

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