add operation tree printing, fix wrong data linking during selective assembly
This commit is contained in:
+1
-1
@@ -9,6 +9,6 @@ namespace Syntax
|
||||
int prepare_token_vector(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);
|
||||
void print_op_tree(const std::vector<Expression::Token>& tv, const std::vector<Expression::Operation>& ov);
|
||||
void print_op_tree(const Expression::TreeNode &node);
|
||||
|
||||
}
|
||||
|
||||
+25
-4
@@ -90,13 +90,29 @@ void assemble(
|
||||
|
||||
program.reserve(commands.size());
|
||||
|
||||
std::vector<bool> command_used;
|
||||
for (int i = 0, l = commands.size(); i < l; i++)
|
||||
{
|
||||
command_used.emplace_back(false);
|
||||
}
|
||||
|
||||
for (int i = 0, l = commands.size(); i < l; i++)
|
||||
{
|
||||
int lowest_weight_idx = 0;
|
||||
|
||||
for (int j = 0, k = commands.size(); j < k; j++)
|
||||
for (int j = 0; j < l; j++)
|
||||
{
|
||||
if (commands[j].node->weight() < commands[lowest_weight_idx].node->weight())
|
||||
if (!command_used[j])
|
||||
{
|
||||
pr_debug("Starting from " << j);
|
||||
lowest_weight_idx = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = lowest_weight_idx + 1; j < l; j++)
|
||||
{
|
||||
if (!command_used[j] && commands[j].node->weight() < commands[lowest_weight_idx].node->weight())
|
||||
{
|
||||
lowest_weight_idx = j;
|
||||
}
|
||||
@@ -104,9 +120,14 @@ void assemble(
|
||||
|
||||
Command &cmd = commands[lowest_weight_idx];
|
||||
pr_debug("Selecting command idx=" << lowest_weight_idx << " with weight=" << cmd.node->weight());
|
||||
program.emplace_back(cmd.opcode, cmd.left_src * preload_mem + cmd.left_index, cmd.right_src * preload_mem + cmd.right_index, preload_mem + i);
|
||||
pr_debug(cmd.opcode << " "
|
||||
<< cmd.left_src << " " << cmd.left_index << " "
|
||||
<< cmd.right_src << " " << cmd.right_index << " "
|
||||
<< preload_mem + lowest_weight_idx);
|
||||
|
||||
commands.erase(commands.begin() + lowest_weight_idx);
|
||||
program.emplace_back(cmd.opcode, cmd.left_src * preload_mem + cmd.left_index, cmd.right_src * preload_mem + cmd.right_index, preload_mem + lowest_weight_idx);
|
||||
|
||||
command_used[lowest_weight_idx] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ int main(int argc, char **argv)
|
||||
std::vector<Expression::Operation> ov = Syntax::build_op_vector(tv);
|
||||
|
||||
Expression::TreeNode root = Syntax::ov_to_tree(tv, ov);
|
||||
Syntax::print_op_tree(root);
|
||||
|
||||
std::vector<DynamicPipeline::Command> program;
|
||||
std::array<double, DYN_PIPELINE_MEM_SIZE> memory;
|
||||
|
||||
+42
-3
@@ -1432,11 +1432,50 @@ Expression::TreeNode ov_to_tree(const std::vector<Expression::Token>& tv, const
|
||||
return root;
|
||||
}
|
||||
|
||||
static void descend_print_tree_node(const Expression::TreeNode& this_node, const int depth, const int leftnesses)
|
||||
{
|
||||
prs_info("");
|
||||
|
||||
for (int i = 0; i < depth - 1; i++)
|
||||
{
|
||||
if (leftnesses & (1 << i))
|
||||
{
|
||||
pri_info("│ ");
|
||||
}
|
||||
else
|
||||
{
|
||||
pri_info(" ");
|
||||
}
|
||||
}
|
||||
|
||||
if (depth > 0)
|
||||
{
|
||||
if (leftnesses & (1 << (depth - 1)))
|
||||
{
|
||||
pri_info("├─");
|
||||
}
|
||||
else
|
||||
{
|
||||
pri_info("└─");
|
||||
}
|
||||
}
|
||||
|
||||
pri_info(*this_node.o.to_math_str() << "\n");
|
||||
|
||||
if (this_node.l != nullptr)
|
||||
{
|
||||
descend_print_tree_node(*this_node.l, depth + 1, leftnesses | 1 << depth);
|
||||
}
|
||||
|
||||
if (this_node.r != nullptr)
|
||||
{
|
||||
descend_print_tree_node(*this_node.r, depth + 1, leftnesses);
|
||||
}
|
||||
}
|
||||
|
||||
void print_op_tree(const Expression::TreeNode& root)
|
||||
{
|
||||
(void) root;
|
||||
|
||||
std::vector<std::pair<Expression::TreeNode *, int>> items_to_display;
|
||||
descend_print_tree_node(root, 0, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user