#include #include "hruby_sim.h" /** * The HDLRuby simulation visualization engine, to be used with C code * generated by hruby_low2c. **/ /* The print function pointers. */ PrinterS printer; /** Initializes the visualization printer engine. * @param print_time the time printer * @param print_name the name printer * @param print_value the value printer * @param print_signal the signal state printer * @param print_string the string printer. */ void init_visualizer(void (*print_time)(unsigned long long), void (*print_name)(Object), void (*print_value)(Value), void (*print_signal)(SignalI), void (*print_string)(const char*), void (*print_string_name)(Object), void (*print_string_value)(Value)) { printer.print_time = print_time; printer.print_name = print_name; printer.print_value = print_value; printer.print_signal = print_signal; printer.print_string = print_string; printer.print_string_name = print_string_name; printer.print_string_value = print_string_value; } /* The default printing functions. */ /** Prints the time. * @param time the time to show. */ void default_print_time(unsigned long long time) { printf("# %llups",time); } /** Prints the time and goes to the next line. * @par1am time the time to show. */ static void default_println_time(unsigned long long time) { default_print_time(time); printf("\n"); } /** Prints the name of an object. * @param object the object to print the name. */ void default_print_name(Object object) { /* Recurse on the owner if any. */ // printf("owner=%p\n",object->owner); if (object->owner != NULL) { default_print_name(object->owner); printf("::"); } /* Depending on the kind of object. */ switch(object->kind) { case SIGNALI: /* Print the name if name. */ /* Trick: SystemT, SignalI, Scope and SystemI have the * field name at the same place. */ if (((SignalI)object)->name != NULL) { printf("%s",((SignalI)object)->name); } break; case SYSTEMT: case SCOPE: case SYSTEMI: /* Print the name if name. */ /* Trick: SystemT, SignalI, Scope and SystemI have the * field name at the same place. */ if (((SystemI)object)->name != NULL) { printf("%s",((SystemI)object)->name); } break; default: /* Nothing to do */ break; } } /** Prints a value. * @param value the value to print */ void default_print_value(Value value) { if (value->numeric) { unsigned long long width = type_width(value->type); unsigned long long mask = 1ULL << (width-1); for(; mask > 0; mask >>= 1) { printf("%d",(value->data_int & mask) != 0); } } else { /* Display a bitstring value. */ unsigned long long i; unsigned long long width = type_width(value->type); char* data = value->data_str; if (value->capacity == 0) { /* The value is empty, therefore undefined. */ for(i=width; i>0; --i) { printf("u"); } } else { /* The value is not empty. */ for(i=width; i>0; --i) { printf("%c",data[i-1]); } } } } /** Prints a string. * @param str the string to print. */ void default_print_string(const char* str) { printf("%s", str); } /** Prints a signal. * @param signal the signal to show */ static void default_print_signal(SignalI signal) { default_print_name((Object)signal); printf(": "); default_print_value(signal->f_value); } /** Prints a signal and goes to the next line. * @param signal the signal to show */ static void default_println_signal(SignalI signal) { default_print_signal(signal); printf("\n"); } /* Set up the visualizer. */ /** Set up the default vizualization engine. * @param name the name of the vizualization. */ void init_default_visualizer(char* name) { /* Initialize the vizualizer printer engine. */ init_visualizer(&default_println_time, &default_print_name, &default_print_value, &default_println_signal, &default_print_string, &default_print_name, &default_print_value); }