From 93f1fb0995a987cfe5f82195fc95b5b5be3cf6f0 Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Mon, 19 Aug 2024 15:13:36 +0200 Subject: [PATCH] Fix compilation for Not-Windows --- Sources/backends/metal.c | 95 ---------------------------------------- Sources/backends/util.c | 14 +++--- Sources/backends/wgsl.c | 95 ---------------------------------------- 3 files changed, 7 insertions(+), 197 deletions(-) diff --git a/Sources/backends/metal.c b/Sources/backends/metal.c index 10f8808..303cf2d 100644 --- a/Sources/backends/metal.c +++ b/Sources/backends/metal.c @@ -48,101 +48,6 @@ static void write_code(char *metal, char *directory, const char *filename) { fclose(file); } -static void find_referenced_functions(function *f, function **functions, size_t *functions_size) { - if (f->block == NULL) { - // built-in - return; - } - - uint8_t *data = f->code.o; - size_t size = f->code.size; - - size_t index = 0; - while (index < size) { - opcode *o = (opcode *)&data[index]; - switch (o->type) { - case OPCODE_CALL: { - for (function_id i = 0; get_function(i) != NULL; ++i) { - function *f = get_function(i); - if (f->name == o->op_call.func) { - if (f->block == NULL) { - // built-in - break; - } - - bool found = false; - for (size_t j = 0; j < *functions_size; ++j) { - if (functions[j]->name == o->op_call.func) { - found = true; - break; - } - } - if (!found) { - functions[*functions_size] = f; - *functions_size += 1; - find_referenced_functions(f, functions, functions_size); - } - break; - } - } - break; - } - } - - index += o->size; - } -} - -static void add_found_type(type_id t, type_id *types, size_t *types_size) { - for (size_t i = 0; i < *types_size; ++i) { - if (types[i] == t) { - return; - } - } - - types[*types_size] = t; - *types_size += 1; -} - -static void find_referenced_types(function *f, type_id *types, size_t *types_size) { - if (f->block == NULL) { - // built-in - return; - } - - function *functions[256]; - size_t functions_size = 0; - - functions[functions_size] = f; - functions_size += 1; - - find_referenced_functions(f, functions, &functions_size); - - for (size_t l = 0; l < functions_size; ++l) { - function *func = functions[l]; - debug_context context = {0}; - check(func->parameter_type.type != NO_TYPE, context, "Function parameter type missing"); - add_found_type(func->parameter_type.type, types, types_size); - check(func->return_type.type != NO_TYPE, context, "Function return type missing"); - add_found_type(func->return_type.type, types, types_size); - - uint8_t *data = functions[l]->code.o; - size_t size = functions[l]->code.size; - - size_t index = 0; - while (index < size) { - opcode *o = (opcode *)&data[index]; - switch (o->type) { - case OPCODE_VAR: - add_found_type(o->op_var.var.type.type, types, types_size); - break; - } - - index += o->size; - } - } -} - static void find_referenced_global_for_var(variable v, global_id *globals, size_t *globals_size) { for (global_id j = 0; get_global(j).type != NO_TYPE; ++j) { global g = get_global(j); diff --git a/Sources/backends/util.c b/Sources/backends/util.c index f172a8c..7d7181f 100644 --- a/Sources/backends/util.c +++ b/Sources/backends/util.c @@ -6,10 +6,10 @@ void indent(char *code, size_t *offset, int indentation) { indentation = indentation < 15 ? indentation : 15; - char indent[16]; - memset(indent, '\t', sizeof(indent)); - indent[indentation] = 0; - *offset += sprintf(&code[*offset], indent); + char str[16]; + memset(str, '\t', sizeof(str)); + str[indentation] = 0; + *offset += sprintf(&code[*offset], str); } void find_referenced_functions(function *f, function **functions, size_t *functions_size) { @@ -85,9 +85,9 @@ void find_referenced_types(function *f, type_id *types, size_t *types_size) { for (size_t l = 0; l < functions_size; ++l) { function *func = functions[l]; debug_context context = {0}; - check(func->parameter_type.type != NO_TYPE, context, "Parameter type missing"); + check(func->parameter_type.type != NO_TYPE, context, "Function parameter type not found"); add_found_type(func->parameter_type.type, types, types_size); - check(func->return_type.type != NO_TYPE, context, "Return type missing"); + check(func->return_type.type != NO_TYPE, context, "Function return type missing"); add_found_type(func->return_type.type, types, types_size); uint8_t *data = functions[l]->code.o; @@ -105,4 +105,4 @@ void find_referenced_types(function *f, type_id *types, size_t *types_size) { index += o->size; } } -} \ No newline at end of file +} diff --git a/Sources/backends/wgsl.c b/Sources/backends/wgsl.c index 785b420..496507e 100644 --- a/Sources/backends/wgsl.c +++ b/Sources/backends/wgsl.c @@ -90,101 +90,6 @@ static void write_code(char *wgsl, char *directory, const char *filename) { } } -static void find_referenced_functions(function *f, function **functions, size_t *functions_size) { - if (f->block == NULL) { - // built-in - return; - } - - uint8_t *data = f->code.o; - size_t size = f->code.size; - - size_t index = 0; - while (index < size) { - opcode *o = (opcode *)&data[index]; - switch (o->type) { - case OPCODE_CALL: { - for (function_id i = 0; get_function(i) != NULL; ++i) { - function *f = get_function(i); - if (f->name == o->op_call.func) { - if (f->block == NULL) { - // built-in - break; - } - - bool found = false; - for (size_t j = 0; j < *functions_size; ++j) { - if (functions[j]->name == o->op_call.func) { - found = true; - break; - } - } - if (!found) { - functions[*functions_size] = f; - *functions_size += 1; - find_referenced_functions(f, functions, functions_size); - } - break; - } - } - break; - } - } - - index += o->size; - } -} - -static void add_found_type(type_id t, type_id *types, size_t *types_size) { - for (size_t i = 0; i < *types_size; ++i) { - if (types[i] == t) { - return; - } - } - - types[*types_size] = t; - *types_size += 1; -} - -static void find_referenced_types(function *f, type_id *types, size_t *types_size) { - if (f->block == NULL) { - // built-in - return; - } - - function *functions[256]; - size_t functions_size = 0; - - functions[functions_size] = f; - functions_size += 1; - - find_referenced_functions(f, functions, &functions_size); - - for (size_t l = 0; l < functions_size; ++l) { - function *func = functions[l]; - debug_context context = {0}; - check(func->parameter_type.type != NO_TYPE, context, "Function parameter has no type"); - add_found_type(func->parameter_type.type, types, types_size); - check(func->return_type.type != NO_TYPE, context, "Function return type missing"); - add_found_type(func->return_type.type, types, types_size); - - uint8_t *data = functions[l]->code.o; - size_t size = functions[l]->code.size; - - size_t index = 0; - while (index < size) { - opcode *o = (opcode *)&data[index]; - switch (o->type) { - case OPCODE_VAR: - add_found_type(o->op_var.var.type.type, types, types_size); - break; - } - - index += o->size; - } - } -} - static void find_referenced_global_for_var(variable v, global_id *globals, size_t *globals_size) { for (global_id j = 0; get_global(j).type != NO_TYPE; ++j) { global g = get_global(j);