diff --git a/inc/dyn-pipeline.hpp b/inc/dyn-pipeline.hpp index a531e67..ba6267c 100644 --- a/inc/dyn-pipeline.hpp +++ b/inc/dyn-pipeline.hpp @@ -43,7 +43,6 @@ class System private: std::vector *program_memory; std::array data_memory; - std::array delays; std::array layer_cmd {-1}; unsigned int pc {0}; unsigned int system_time; diff --git a/inc/expression.hpp b/inc/expression.hpp index 0ca3afe..7aa7e60 100644 --- a/inc/expression.hpp +++ b/inc/expression.hpp @@ -5,6 +5,8 @@ #include #include +#include "print.h" + namespace Expression { class Token { @@ -28,6 +30,31 @@ public: NOP // not an operator }; + static int weight_op(Operator o) + { + switch (o) + { + case Expression::Token::OPA: + case Expression::Token::CPA: + case Expression::Token::NOP: + pr_warn("Unweightable operator - this is probably a bug!"); + return 0; + case Expression::Token::ADD: + return 1; + case Expression::Token::SUB: + return 1; + case Expression::Token::MUL: + return 2; + case Expression::Token::DIV: + return 2; + case Expression::Token::POW: + return 3; + default: + pr_warn("Impossible operator - this is a bug!"); + return 0; + } + } + union TokenValue { std::shared_ptr s; double d; @@ -380,6 +407,28 @@ public: delete r; } } + + int weight() + { + int w = 0; + + if (l != nullptr) + { + w += l->weight(); + } + + if (r != nullptr) + { + w += r->weight(); + } + + if (o.t == Token::OPERATOR) + { + Token::weight_op(o.v.o); + } + + return w; + } }; } diff --git a/inc/syntaxer.hpp b/inc/syntaxer.hpp index f741673..ba53b10 100644 --- a/inc/syntaxer.hpp +++ b/inc/syntaxer.hpp @@ -2,7 +2,6 @@ #include #include "expression.hpp" -#include "dyn-pipeline.hpp" namespace Syntax { @@ -11,6 +10,5 @@ int prepare_token_vector(std::vector& tv); std::vector build_op_vector(const std::vector& tv); Expression::TreeNode ov_to_tree(const std::vector& tv, const std::vector& ov); void print_op_tree(const std::vector& tv, const std::vector& ov); -int op_weight(DynamicPipeline::CommandType o); } diff --git a/src/dyn-pipeline.cpp b/src/dyn-pipeline.cpp index 7927f9c..c32b9f7 100644 --- a/src/dyn-pipeline.cpp +++ b/src/dyn-pipeline.cpp @@ -1,8 +1,14 @@ #include "dyn-pipeline.hpp" #include "print.h" +#include "expression.hpp" namespace DynamicPipeline { +int weight_op(DynamicPipeline::CommandType o) +{ + return Expression::Token::weight_op(static_cast(o + 2)); +} + void System::init(const std::vector * const prg, const std::array& mem, const int init_mem_size) { pr_info("Dynamic Pipeline System initialized with:\n" @@ -22,13 +28,6 @@ void System::init(const std::vector * const prg, const std::array time_taken) + if (const int d = weight_op((*program_memory)[layer_cmd[i]].t); d > time_taken) { time_taken = d; } @@ -156,8 +155,6 @@ void System::run(void) while (next_instruction() || !pipeline_empty()) { print_pipeline(); - pri_info("\n"); - step(); pri_info("\n"); } diff --git a/src/syntaxer.cpp b/src/syntaxer.cpp index 5fa5c59..0538e63 100644 --- a/src/syntaxer.cpp +++ b/src/syntaxer.cpp @@ -248,37 +248,6 @@ static int get_max_index(const std::vector& v) return idx; } - -static int op_weight(enum Expression::Token::Operator o) -{ - switch (o) - { - case Expression::Token::OPA: - case Expression::Token::CPA: - case Expression::Token::NOP: - pr_warn("Unweightable operator - this is probably a bug!"); - return 0; - case Expression::Token::ADD: - return 1; - case Expression::Token::SUB: - return 1; - case Expression::Token::MUL: - return 2; - case Expression::Token::DIV: - return 2; - case Expression::Token::POW: - return 3; - default: - pr_warn("Impossible operator - this is a bug!"); - return 0; - } -} - -int op_weight(DynamicPipeline::CommandType o) -{ - return op_weight((enum Expression::Token::Operator) (o + 2)); -} - static int write_operation( std::vector& ov, std::vector& cv, @@ -353,7 +322,7 @@ static int write_operation( return 1; } #endif - int this_op_weight = get_operator_weight(mv, location) + op_weight(o.v.o); + int this_op_weight = get_operator_weight(mv, location) + Expression::Token::weight_op(o.v.o); int il = l.t == Expression::Token::CV ? l.v.cv.i : left_location; int ir = r.t == Expression::Token::CV ? r.v.cv.i : right_location;