From 128ce1ee2115b54d43db1334e12410b1cc216f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Mon, 1 Jan 2018 20:43:42 +0100 Subject: cli: extend tracer and implement reporter --- qtmips_cli/reporter.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 qtmips_cli/reporter.cpp (limited to 'qtmips_cli/reporter.cpp') diff --git a/qtmips_cli/reporter.cpp b/qtmips_cli/reporter.cpp new file mode 100644 index 0000000..70d1d27 --- /dev/null +++ b/qtmips_cli/reporter.cpp @@ -0,0 +1,59 @@ +#include "reporter.h" +#include +#include +#include + +using namespace machine; +using namespace std; + +Reporter::Reporter(QCoreApplication *app, QtMipsMachine *machine) : QObject() { + this->app = app; + this->machine = machine; + + connect(machine, SIGNAL(program_exit()), this, SLOT(machine_exit())); + connect(machine, SIGNAL(program_trap(machine::QtMipsException&)), this, SLOT(machine_trap(machine::QtMipsException&))); + + e_regs = false; + e_fail = (enum FailReason)0; +} + +void Reporter::regs() { + e_regs = true; +} + +void Reporter::expect_fail(enum FailReason reason) { + e_fail = (enum FailReason)(e_fail | reason); +} + +void Reporter::machine_exit() { + report(); + if (e_fail != 0) { + cout << "Machine was expected to fail but it didn't." << endl; + app->exit(1); + } else + app->exit(); +} + +void Reporter::machine_trap(QtMipsException &e) { + report(); + + bool expected = false; + auto& etype = typeid(e); + if (etype == typeid(QtMipsExceptionUnsupportedInstruction)) + expected = e_fail & FR_I; + else if (etype == typeid(QtMipsExceptionUnsupportedAluOperation)) + expected = e_fail & FR_A; + else if (etype == typeid(QtMipsExceptionOverflow)) + expected = e_fail & FR_O; + else if (etype == typeid(QtMipsExceptionUnalignedJump)) + expected = e_fail & FR_J; + + cout << "Machine trapped: " << e.what() << endl; + app->exit(expected ? 0 : 1); +} + +void Reporter::report() { + if (e_regs) { + // TODO + } +} -- cgit v1.2.3