fucked shit up

This commit is contained in:
anon
2024-07-22 18:35:21 +02:00
parent 4cbec3ec8a
commit b0a54971b3
11 changed files with 390 additions and 238 deletions

View File

@ -6,12 +6,14 @@
#include <stdarg.h>
#include "eaxhla.h"
__attribute__((unused))
static
void breakpoint(void) { ; }
# define debug_puts(msg) do { puts(msg); } while (0)
static // this is less horid than macro varargs
__attribute__((unused))
static
void debug_printf(const char * const fmt, ...) {
va_list args;
va_start(args, fmt);
@ -19,19 +21,22 @@ void debug_printf(const char * const fmt, ...) {
va_end(args);
}
__attribute__((unused))
static
void dump_variable(void * data) {
symbol_t * variable = (symbol_t*)data;
if (variable->symbol_type != VARIABLE) { return; }
if (variable->symbol_type != VARIABLE_SYMBOL) { return; }
if (variable->elements == 1) {
printf("{ .name = '%s', .value = '%ld' }\n",
printf("{ .name = '%s', .id = %d, .value = '%ld' }\n",
variable->name,
variable->_id,
variable->value
);
} else {
printf("{ .name = '%s', .elements = '%llu', .array_value = \"%.*s\" }\n",
printf("{ .name = '%s', .id = %d, .elements = '%lu', .array_value = \"%.*s\" }\n",
variable->name,
variable->_id,
variable->elements,
(int)variable->elements,
(char*)variable->array_value
@ -39,28 +44,33 @@ void dump_variable(void * data) {
}
}
__attribute__((unused))
static
void debug_dump_variables(void) {
puts("# Variables:");
tommy_hashtable_foreach(&symbol_table, dump_variable);
}
__attribute__((unused))
static
void dump_function(void * data) {
symbol_t * function = (symbol_t*)data;
if (function->symbol_type != FUNCTION) { return; }
if (function->symbol_type != LABEL_SYMBOL) { return; }
printf("{ .name = '%s' }\n",
function->name
printf("{ .name = '%s', .id = %d }\n",
function->name,
function->_id
);
}
__attribute__((unused))
static
void debug_dump_functions(void) {
puts("# Functions:");
tommy_hashtable_foreach(&symbol_table, dump_function);
}
__attribute__((unused))
static
void debug_dump_symbols(void) {
debug_dump_variables();
@ -68,6 +78,7 @@ void debug_dump_symbols(void) {
printf("# Total variable size: '%d'\n", variable_size_sum());
}
__attribute__((unused))
static
void debug_token_dump(void) {
extern unsigned int * token_array;