From 4e59245e506055e4e355c419de638cdc8a485c42 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Tue, 2 Nov 2021 17:28:09 +0100 Subject: Add a function to generate labels --- src/compiler.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/compiler.h b/src/compiler.h index b703a99..441b665 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -20,6 +20,19 @@ void compile_fixnum(Object *obj); void compile_proc_call(Object *obj); void compile(Root *roots); +char * +generate_label(void) { + // Generate a unique label allocated on the heap. The caller is responsible + // for freeing the memory. + static size_t label_counter = 0; + char buf[32]; + memset(buf, 0, 32); + sprintf(buf, ".BDLL%ld", label_counter++); + char * ret = malloc(strlen(buf)); + memcpy(ret, buf, strlen(buf)); + return ret; +} + void emit_file(char *file_name) { FILE *file = fopen(file_name, "r"); -- cgit v1.2.1