Skip to content

Commit

Permalink
Merge pull request riscv#528 from Alasdair/step_delimit_trace
Browse files Browse the repository at this point in the history
Add an option to delimit instructions in the trace
  • Loading branch information
billmcspadden-riscv authored Sep 3, 2024
2 parents e199a2e + 461c275 commit d518013
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions c_emulator/riscv_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdbool.h>

extern bool config_print_instr;
extern bool config_print_step;
extern bool config_print_reg;
extern bool config_print_mem_access;
extern bool config_print_platform;
7 changes: 7 additions & 0 deletions c_emulator/riscv_prelude.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ unit print_instr(sail_string s)
return UNIT;
}

unit print_step(unit u)
{
if (config_print_step)
fprintf(trace_log, "\n");
return UNIT;
}

unit print_reg(sail_string s)
{
if (config_print_reg)
Expand Down
1 change: 1 addition & 0 deletions c_emulator/riscv_prelude.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
unit print_string(sail_string prefix, sail_string msg);

unit print_instr(sail_string s);
unit print_step(unit u);
unit print_reg(sail_string s);
unit print_mem_access(sail_string s);
unit print_platform(sail_string s);
Expand Down
10 changes: 8 additions & 2 deletions c_emulator/riscv_sim.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ bool config_print_reg = true;
bool config_print_mem_access = true;
bool config_print_platform = true;
bool config_print_rvfi = false;
bool config_print_step = false;

void set_config_print(char *var, bool val)
{
Expand All @@ -111,9 +112,11 @@ void set_config_print(char *var, bool val)
config_print_rvfi = val;
} else if (strcmp("platform", var) == 0) {
config_print_platform = val;
} else if (strcmp("step", var) == 0) {
config_print_step = val;
} else {
fprintf(stderr, "Unknown trace category: '%s' (should be %s)\n",
"instr|reg|mem|platform|all", var);
fprintf(stderr, "Unknown trace category: '%s' (should be %s)\n", var,
"instr|reg|mem|rvfi|platform|step|all");
exit(1);
}
}
Expand Down Expand Up @@ -1027,6 +1030,9 @@ void run_sail(void)
KILL(sail_int)(&sail_step);
}
if (stepped) {
if (config_print_step) {
fprintf(trace_log, "\n");
}
step_no++;
insn_cnt++;
total_insns++;
Expand Down
4 changes: 4 additions & 0 deletions model/prelude.sail
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ val print_reg = {ocaml: "Platform.print_reg", interpreter: "print_endline",
val print_mem = {ocaml: "Platform.print_mem_access", interpreter: "print_endline", c: "print_mem_access", lem: "print_dbg", _: "print_endline"} : string -> unit
val print_platform = {ocaml: "Platform.print_platform", interpreter: "print_endline", c: "print_platform", lem: "print_dbg", _: "print_endline"} : string -> unit

val print_step = {ocaml: "Platform.print_step", c: "print_step"} : unit -> unit

function print_step() = ()

val get_config_print_instr = {ocaml: "Platform.get_config_print_instr", c:"get_config_print_instr"} : unit -> bool
val get_config_print_reg = {ocaml: "Platform.get_config_print_reg", c:"get_config_print_reg"} : unit -> bool
val get_config_print_mem = {ocaml: "Platform.get_config_print_mem", c:"get_config_print_mem"} : unit -> bool
Expand Down
3 changes: 3 additions & 0 deletions model/riscv_step.sail
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ function loop () : unit -> unit = {
let stepped = step(step_no);
if stepped then {
step_no = step_no + 1;
if get_config_print_instr() then {
print_step()
};
sail_end_cycle()
};

Expand Down
6 changes: 6 additions & 0 deletions ocaml_emulator/platform.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ let platform_arch = ref P.RV64
(* logging *)

let config_print_instr = ref true
let config_print_step = ref false
let config_print_reg = ref true
let config_print_mem_access = ref true
let config_print_platform = ref true
Expand All @@ -37,6 +38,11 @@ let print_instr s =
then print_endline s
else ()

let print_step () =
if !config_print_step
then print_endline ""
else ()

let print_reg s =
if !config_print_reg
then print_endline s
Expand Down
3 changes: 3 additions & 0 deletions ocaml_emulator/riscv_ocaml_sim.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ let options = Arg.align ([("-dump-dts",
("-signature-granularity",
Arg.Int set_signature_granularity,
" test signature granularity (in bytes)");
("-trace-delimit-step",
Arg.Set P.config_print_step,
" delimit instructions in the trace output");
("-isa",
Arg.String (fun s -> opt_isa := Some s),
" requested isa");
Expand Down

0 comments on commit d518013

Please sign in to comment.