From 1ff268ab13dd299c4cdc1e379df5397bd6a394e3 Mon Sep 17 00:00:00 2001 From: Alex AUVOLAT Date: Fri, 3 Jan 2014 19:05:10 +0100 Subject: Added simulator monitor tool. --- csim/Makefile | 2 +- csim/main.c | 17 +++++++++-------- csim/sim.c | 11 +++++++++++ csim/sim.h | 1 + 4 files changed, 22 insertions(+), 9 deletions(-) (limited to 'csim') diff --git a/csim/Makefile b/csim/Makefile index 6827579..ae4cc4e 100644 --- a/csim/Makefile +++ b/csim/Makefile @@ -1,5 +1,5 @@ csim: main.o load.o sim.o util.o - gcc -o csim $^ + gcc -o $@ $^ %.o: %.c gcc -c $< -o $@ -O2 -g diff --git a/csim/main.c b/csim/main.c index 5689cb4..2a88fbc 100644 --- a/csim/main.c +++ b/csim/main.c @@ -14,18 +14,18 @@ void usage() { - printf ("\nUsage:\n\tcsim [options] \n\n"); - printf("Available options:\n"); - printf("\n -rom \n\tLoad a filename as a ROM file for the machine\n"); - printf("\tA given ROM file is used for all ROM chips with variable name having given prefix\n"); - printf("\n -n \n\tOnly run #steps steps of simulation (0 = infinity)\n"); - printf("\n -in \n\tRead inputs from given file (eg. named pipe). Defaults to STDIN.\n"); - printf("\n -out \n\tWrite outputs to given file (eg. named pipe). Defaults to STDOut.\n"); + fprintf(stderr, "\nUsage:\n\tcsim [options] \n\n"); + fprintf(stderr, "Available options:\n"); + fprintf(stderr, "\n -rom \n\tLoad a filename as a ROM file for the machine\n"); + fprintf(stderr, "\tA given ROM file is used for all ROM chips with variable name having given prefix\n"); + fprintf(stderr, "\n -n \n\tOnly run #steps steps of simulation (0 = infinity)\n"); + fprintf(stderr, "\n -in \n\tRead inputs from given file (eg. named pipe). Defaults to STDIN.\n"); + fprintf(stderr, "\n -out \n\tWrite outputs to given file (eg. named pipe). Defaults to STDOUT.\n"); exit(1); } // Arguments to be parsed -int steps = 12; +int steps = 0; char *filename = NULL; char *infile = NULL; char *outfile = NULL; @@ -88,6 +88,7 @@ int main(int argc, char **argv) { // Run t_machine *machine = init_machine(program); + machine_banner(machine, output); i = 0; while (i < steps || steps == 0) { read_inputs(machine, input); diff --git a/csim/sim.c b/csim/sim.c index 04cad15..f91ac75 100644 --- a/csim/sim.c +++ b/csim/sim.c @@ -52,6 +52,17 @@ t_machine *init_machine (t_program *p) { return m; } +void machine_banner(t_machine *m, FILE *stream) { + int i; + fprintf(stream, "%d %d\n", m->prog->n_inputs, m->prog->n_outputs); + for (i = 0; i < m->prog->n_inputs; i++) { + fprintf(stream, "%d %s\n", + m->prog->vars[m->prog->inputs[i]].size, + m->prog->vars[m->prog->inputs[i]].name); + } + fprintf(stream, "\n"); +} + void read_inputs(t_machine *m, FILE *stream) { /* FORMAT : For each input in the list, *in the order specified*, diff --git a/csim/sim.h b/csim/sim.h index 0265f53..b06399f 100644 --- a/csim/sim.h +++ b/csim/sim.h @@ -124,6 +124,7 @@ void add_rom(const char *prefix, FILE *file); // Implemented in sim.c t_machine *init_machine(t_program *p); +void machine_banner(t_machine *m, FILE *stream); void read_inputs(t_machine *m, FILE *stream); void machine_step(t_machine *m); void write_outputs(t_machine *m, FILE *stream); -- cgit v1.2.3