#include #include #include #include #include #include "aisa/aisa.h" #include "aisa/async.h" #include "aisa/simple-models.h" #include "fib/fib.h" #include "git-tag.h" const unsigned int max_steps = 300; const bool show_mem_fetch = false; const bool show_mem_store = true; const bool show_regs = false; const bool show_steps = false; const bool show_tasks = false; int main(int argc, const char *argv[]) { std::cout << "Version " << GIT_TAG << "\n"; struct Eval : public aisa::AsyncEval, aisa::PagedMem<>, aisa::TaskStack, aisa::VectorRF { bool fetch_mem(aisa::byte_t *bytes, aisa::addr_t addr, aisa::addr_t size) { if (aisa::PagedMem<>::fetch_mem(bytes, addr, size)) { if (show_mem_fetch) { fmt::print("\t\t\t"); for (; size; --size) fmt::print("{:02x} ", *bytes++); fmt::print("= [{:x}]\n", addr); } return true; } return false; } bool store_mem(aisa::addr_t addr, const aisa::byte_t *bytes, aisa::addr_t size) { if (aisa::PagedMem<>::store_mem(addr, bytes, size)) { if (show_mem_store) { fmt::print("\t\t\t[{:x}] =", addr); for (; size; --size) fmt::print(" {:02x}", *bytes++); fmt::print("\n"); } return true; } return false; } bool store_reg(aisa::regnum_t rn, aisa::regval_t rv) { if (aisa::VectorRF::store_reg(rn, rv)) { if (show_regs) fmt::print(".{} = {}\n", fib::Reg::disasm(rn), rv); return true; } return false; } bool push_task(std::unique_ptr &&task) { auto d = task->disasm(); if (aisa::TaskStack::push_task(std::move(task))) { if (show_tasks) fmt::print("\t\t*** ENTER {} ***\n", d); return true; } return false; } bool pop_task() { if (aisa::TaskStack::pop_task()) { if (show_tasks) fmt::print("\t\t *** LEAVE ***\n"); return true; } return false; } } eval; fib::Fib<3> fib; if (!eval.async_setup_initial_task(fib)()) { fmt::print("Failed to complete initial setup.\n"); return 1; } for (unsigned int i = 0; i < max_steps; ++i) { auto res = eval.async_fetch_and_run_step()(); if (res.has_value()) { auto &es = *res; if (es.first) { auto &step = *es.first; auto &w = es.second; if (show_steps) fmt::print("\t{}\n", step.disasm(&w)); } else { break; } } else { fmt::print("Failed to complete step.\n"); return 2; } } fmt::print("Functional model exited.\n"); return 0; }