summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlastair Reid2018-06-27 22:06:10 +0100
committerAlastair Reid2018-06-27 22:06:18 +0100
commitd0c42e9526fe3b116afccb1e8f7864c8115f05e7 (patch)
tree1c073a566f45b7453707d055d38038c4a9c195d1 /lib
parent028c67766b0bcbd453dbdeab609267bdce56b290 (diff)
RTS/Main: tweaking cycle counter handling
Diffstat (limited to 'lib')
-rw-r--r--lib/rts.c11
-rw-r--r--lib/rts.h5
2 files changed, 13 insertions, 3 deletions
diff --git a/lib/rts.c b/lib/rts.c
index 51c99af0..d42eebe3 100644
--- a/lib/rts.c
+++ b/lib/rts.c
@@ -7,6 +7,8 @@
#include"elf.h"
static uint64_t g_elf_entry;
+static uint64_t g_cycle_count = 0;
+static uint64_t g_cycle_limit;
void sail_match_failure(sail_string msg)
{
@@ -23,6 +25,7 @@ unit sail_assert(bool b, sail_string msg)
unit sail_exit(unit u)
{
+ fprintf(stderr, "[Sail] Exiting after %lld cycles\n", g_cycle_count);
exit(EXIT_SUCCESS);
return UNIT;
}
@@ -344,9 +347,6 @@ void elf_tohost(mpz_t *rop, const unit u)
/* ***** Cycle limit ***** */
-static uint64_t g_cycle_count = 0;
-static uint64_t g_cycle_limit;
-
/* NB Also increments cycle_count */
bool cycle_limit_reached(const unit u)
{
@@ -362,6 +362,11 @@ unit cycle_count(const unit u)
return UNIT;
}
+void get_cycle_count(sail_int *rop, const unit u)
+{
+ mpz_init_set_ui(*rop, g_cycle_count);
+}
+
/* ***** Argument Parsing ***** */
static struct option options[] = {
diff --git a/lib/rts.h b/lib/rts.h
index 032d48b8..b4f0d695 100644
--- a/lib/rts.h
+++ b/lib/rts.h
@@ -109,10 +109,15 @@ void trace_end(void);
* Functions for counting and limiting cycles
*/
+// increment cycle count and test if over limit
bool cycle_limit_reached(const unit);
+// increment cycle count and abort if over
unit cycle_count(const unit);
+// read cycle count
+void get_cycle_count(sail_int *rop, const unit);
+
/*
* Functions to get info from ELF files.
*/