lab5: improve weighting during compilation, fix assembly operator translation bug
This commit is contained in:
@@ -43,7 +43,7 @@ class System
|
|||||||
private:
|
private:
|
||||||
std::vector<Command> *program_memory;
|
std::vector<Command> *program_memory;
|
||||||
std::array<MemCell, DYN_PIPELINE_MEM_SIZE> data_memory;
|
std::array<MemCell, DYN_PIPELINE_MEM_SIZE> data_memory;
|
||||||
std::array<int, CMD_COUNT> delays {2, 2, 5, 5, 9};
|
std::array<int, CMD_COUNT> delays;
|
||||||
std::array<int, DYN_PIPELINE_LAYERS> layer_cmd {-1};
|
std::array<int, DYN_PIPELINE_LAYERS> layer_cmd {-1};
|
||||||
unsigned int pc {0};
|
unsigned int pc {0};
|
||||||
unsigned int system_time;
|
unsigned int system_time;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "expression.hpp"
|
#include "expression.hpp"
|
||||||
|
#include "dyn-pipeline.hpp"
|
||||||
|
|
||||||
namespace Syntax
|
namespace Syntax
|
||||||
{
|
{
|
||||||
@@ -10,5 +11,6 @@ int prepare_token_vector(std::vector<Expression::Token>& tv);
|
|||||||
std::vector<Expression::Operation> build_op_vector(const std::vector<Expression::Token>& tv);
|
std::vector<Expression::Operation> build_op_vector(const std::vector<Expression::Token>& tv);
|
||||||
Expression::TreeNode ov_to_tree(const std::vector<Expression::Token>& tv, const std::vector<Expression::Operation>& ov);
|
Expression::TreeNode ov_to_tree(const std::vector<Expression::Token>& tv, const std::vector<Expression::Operation>& ov);
|
||||||
void print_op_tree(const std::vector<Expression::Token>& tv, const std::vector<Expression::Operation>& ov);
|
void print_op_tree(const std::vector<Expression::Token>& tv, const std::vector<Expression::Operation>& ov);
|
||||||
|
int op_weight(DynamicPipeline::CommandType o);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -60,7 +60,7 @@ int descend_operator(const Expression::TreeNode& node, int& preload_mem, std::ve
|
|||||||
ro = PRELOAD;
|
ro = PRELOAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
commands.emplace_back((DynamicPipeline::CommandType) (node.o.t - 2), lo, ro, left, right);
|
commands.emplace_back((DynamicPipeline::CommandType) (node.o.v.o - 2), lo, ro, left, right);
|
||||||
|
|
||||||
return commands.size() - 1; // this index in dynamic memory
|
return commands.size() - 1; // this index in dynamic memory
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,13 @@ void System::init(const std::vector<Command> * const prg, const std::array<doubl
|
|||||||
layer_cmd[i] = -1;
|
layer_cmd[i] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int d[5] = {1, 1, 2, 2, 3};
|
||||||
|
|
||||||
|
for (int i = 0; i < CMD_COUNT; i++)
|
||||||
|
{
|
||||||
|
delays[i] = d[i];
|
||||||
|
}
|
||||||
|
|
||||||
pc = 0;
|
pc = 0;
|
||||||
system_time = 0;
|
system_time = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-1
@@ -248,6 +248,37 @@ static int get_max_index(const std::vector<int>& v)
|
|||||||
return idx;
|
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(
|
static int write_operation(
|
||||||
std::vector<Expression::Operation>& ov,
|
std::vector<Expression::Operation>& ov,
|
||||||
std::vector<Expression::Token>& cv,
|
std::vector<Expression::Token>& cv,
|
||||||
@@ -322,7 +353,7 @@ static int write_operation(
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
int this_op_weight = get_operator_weight(mv, location) + 1;
|
int this_op_weight = get_operator_weight(mv, location) + op_weight(o.v.o);
|
||||||
|
|
||||||
int il = l.t == Expression::Token::CV ? l.v.cv.i : left_location;
|
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;
|
int ir = r.t == Expression::Token::CV ? r.v.cv.i : right_location;
|
||||||
|
|||||||
Reference in New Issue
Block a user