aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-11-02 17:28:09 +0100
committerBad Diode <bd@badd10de.dev>2021-11-02 17:28:09 +0100
commit4e59245e506055e4e355c419de638cdc8a485c42 (patch)
tree246f0437f13d57b9f08bd6cf794ebe3ab039de4d
parent58ffe8a7dbf57d5637e091083175028eb9614636 (diff)
downloadbdl-4e59245e506055e4e355c419de638cdc8a485c42.tar.gz
bdl-4e59245e506055e4e355c419de638cdc8a485c42.zip
Add a function to generate labels
-rw-r--r--src/compiler.h13
1 files changed, 13 insertions, 0 deletions
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);
20void compile_proc_call(Object *obj); 20void compile_proc_call(Object *obj);
21void compile(Root *roots); 21void compile(Root *roots);
22 22
23char *
24generate_label(void) {
25 // Generate a unique label allocated on the heap. The caller is responsible
26 // for freeing the memory.
27 static size_t label_counter = 0;
28 char buf[32];
29 memset(buf, 0, 32);
30 sprintf(buf, ".BDLL%ld", label_counter++);
31 char * ret = malloc(strlen(buf));
32 memcpy(ret, buf, strlen(buf));
33 return ret;
34}
35
23void 36void
24emit_file(char *file_name) { 37emit_file(char *file_name) {
25 FILE *file = fopen(file_name, "r"); 38 FILE *file = fopen(file_name, "r");