Skip to content

Commit

Permalink
Fix compilation for Not-Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Aug 19, 2024
1 parent 1d795a5 commit 93f1fb0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 197 deletions.
95 changes: 0 additions & 95 deletions Sources/backends/metal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions Sources/backends/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -105,4 +105,4 @@ void find_referenced_types(function *f, type_id *types, size_t *types_size) {
index += o->size;
}
}
}
}
95 changes: 0 additions & 95 deletions Sources/backends/wgsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 93f1fb0

Please sign in to comment.