22#include "riscv_config.h"
33#include "riscv_platform_impl.h"
44
5+ /* Attempt to keep track of whether output is at the start of a line so that we
6+ * can produce nicer output if trace output interrupts terminal output. */
7+ bool have_newline = true;
8+
9+ void ensure_newline ()
10+ {
11+ if (!have_newline )
12+ fputc ('\n' , trace_log );
13+ }
14+
515unit print_string (sail_string prefix , sail_string msg )
616{
7- printf ("%s%s\n" , prefix , msg );
17+ ensure_newline ();
18+ fprintf (trace_log , "%s%s\n" , prefix , msg );
19+ have_newline = true;
820 return UNIT ;
921}
1022
1123unit print_instr (sail_string s )
1224{
25+ ensure_newline ();
1326 if (config_print_instr )
1427 fprintf (trace_log , "%s\n" , s );
28+ have_newline = true;
1529 return UNIT ;
1630}
1731
1832unit print_reg (sail_string s )
1933{
34+ ensure_newline ();
2035 if (config_print_reg )
2136 fprintf (trace_log , "%s\n" , s );
37+ have_newline = true;
2238 return UNIT ;
2339}
2440
2541unit print_mem_access (sail_string s )
2642{
43+ ensure_newline ();
2744 if (config_print_mem_access )
2845 fprintf (trace_log , "%s\n" , s );
46+ have_newline = true;
2947 return UNIT ;
3048}
3149
3250unit print_platform (sail_string s )
3351{
52+ ensure_newline ();
3453 if (config_print_platform )
3554 fprintf (trace_log , "%s\n" , s );
55+ have_newline = true;
3656 return UNIT ;
3757}
3858
@@ -59,4 +79,4 @@ bool get_config_print_platform(unit u)
5979bool get_config_print_exception (unit u )
6080{
6181 return (config_print_exception ) ? true : false;
62- }
82+ }
0 commit comments