From 81deb637c07d0e1782ad5ffc57a103aff29d479a Mon Sep 17 00:00:00 2001 From: hasslesstech Date: Sat, 7 Nov 2026 22:10:11 +0200 Subject: [PATCH] improve emulator output --- src/dyn-pipeline.cpp | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/dyn-pipeline.cpp b/src/dyn-pipeline.cpp index c32b9f7..3ed98b7 100644 --- a/src/dyn-pipeline.cpp +++ b/src/dyn-pipeline.cpp @@ -4,11 +4,31 @@ namespace DynamicPipeline { -int weight_op(DynamicPipeline::CommandType o) +static int weight_op(DynamicPipeline::CommandType o) { return Expression::Token::weight_op(static_cast(o + 2)); } +static const char *op_to_str(DynamicPipeline::CommandType o) +{ + switch (o) + { + case ADD: + return "ADD"; + case SUB: + return "SUB"; + case MUL: + return "MUL"; + case DIV: + return "DIV"; + case POW: + return "POW"; + default: + pr_warn("Impossible token - this is a bug!"); + return "Impossible token"; + } +} + 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" @@ -40,21 +60,22 @@ void System::print_pipeline(void) const { if (layer_cmd[i] != -1) { - pri_info(std::setw(3) << layer_cmd[i] << " | "); + pri_info(std::setw(3) << layer_cmd[i] << " (" << op_to_str((*program_memory)[layer_cmd[i]].t) << ") | "); } else { - pri_info("IDL | "); + pri_info("--- (---) | "); } } if (layer_cmd[DYN_PIPELINE_LAYERS - 1] != -1) { - pri_info(std::setw(3) << layer_cmd[DYN_PIPELINE_LAYERS - 1] << "\n"); + int addr = layer_cmd[DYN_PIPELINE_LAYERS - 1]; + pri_info(std::setw(3) << addr << " (" << op_to_str((*program_memory)[addr].t) << ")\n"); } else { - pri_info("IDL\n"); + pri_info("--- (---)\n"); } } @@ -123,7 +144,7 @@ void System::step(void) if (int prg_mem_addr = layer_cmd[DYN_PIPELINE_LAYERS - 1]; prg_mem_addr != -1) { Command &cmd = (*program_memory)[prg_mem_addr]; - pr_info("Instruction " << prg_mem_addr << " completes, writes output to " << cmd.res); + pr_info("Instruction " << prg_mem_addr << " (" << op_to_str(cmd.t) << ") completes, writes output to " << cmd.res); data_memory[cmd.res].ready = 1; } @@ -140,14 +161,14 @@ void System::step(void) if (instruction_ready()) { Command &cmd = (*program_memory)[pc]; - pr_info("Instruction " << pc << " reads " << cmd.op1 << " and " << cmd.op2 << " and enters the pipeline"); + pr_info("Instruction " << pc << " (" << op_to_str(cmd.t) << ") reads " << cmd.op1 << " and " << cmd.op2 << " and enters the pipeline"); layer_cmd[0] = pc; pc++; } - pr_info("Pipeline step took " << time_taken << " ticks"); + pr_info("Step took " << time_taken << " ticks"); } void System::run(void) @@ -155,6 +176,8 @@ void System::run(void) while (next_instruction() || !pipeline_empty()) { print_pipeline(); + pri_info("\n"); + step(); pri_info("\n"); }