Skip to content

Commit

Permalink
Fix Xcode warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Feb 2, 2025
1 parent 0cea11b commit 500463c
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 114 deletions.
11 changes: 7 additions & 4 deletions Sources/backends/cstyle.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include <stdio.h>
#include <string.h>

static char *function_string(name_id func) {
return get_name(func);
}
//static char *function_string(name_id func) {
// return get_name(func);
//}

// HLSL for now
static char *member_string(type *parent_type, name_id member_name) {
Expand Down Expand Up @@ -84,7 +84,7 @@ void cstyle_write_opcode(char *code, size_t *offset, opcode *o, type_string_func
for (size_t i = 0; i < o->op_store_member.member_indices_size; ++i) {
if (is_array) {
if (o->op_store_member.dynamic_member[i]) {
*offset += sprintf(&code[*offset], "[_% " PRIu64 "]", o->op_store_member.dynamic_member_indices[i].index);
*offset += sprintf(&code[*offset], "[_%" PRIu64 "]", o->op_store_member.dynamic_member_indices[i].index);
}
else {
*offset += sprintf(&code[*offset], "[%i]", o->op_store_member.static_member_indices[i]);
Expand Down Expand Up @@ -116,6 +116,9 @@ void cstyle_write_opcode(char *code, size_t *offset, opcode *o, type_string_func
case OPCODE_MULTIPLY_AND_STORE_MEMBER:
*offset += sprintf(&code[*offset], " *= _%" PRIu64 ";\n", o->op_store_member.from.index);
break;
default:
assert(false);
break;
}
break;
case OPCODE_LOAD_FLOAT_CONSTANT:
Expand Down
12 changes: 8 additions & 4 deletions Sources/backends/d3d11.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stdint.h>
#endif

#ifdef _WIN32
static const char *shaderString(shader_stage stage, int version) {
if (version == 4) {
switch (stage) {
Expand All @@ -26,6 +27,9 @@ static const char *shaderString(shader_stage stage, int version) {
return "ps_4_0";
case SHADER_STAGE_COMPUTE:
return "cs_4_0";
default:
assert(false);
return "";
}
}
else if (version == 5) {
Expand All @@ -36,17 +40,17 @@ static const char *shaderString(shader_stage stage, int version) {
return "ps_5_0";
case SHADER_STAGE_COMPUTE:
return "cs_5_0";
default:
assert(false);
return "";
}
}

debug_context context = {0};
error(context, "Unsupported shader stage/version combination");
return "unsupported";
}

struct map {
int nothing;
};
#endif

int compile_hlsl_to_d3d11(const char *source, uint8_t **output, size_t *outputlength, shader_stage stage, bool debug) {
#ifdef _WIN32
Expand Down
2 changes: 2 additions & 0 deletions Sources/backends/d3d12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#endif

#ifdef _WIN32
static const wchar_t *shader_string(shader_stage stage) {
switch (stage) {
case SHADER_STAGE_VERTEX:
Expand All @@ -36,6 +37,7 @@ static const wchar_t *shader_string(shader_stage stage) {
}
}
}
#endif

int compile_hlsl_to_d3d12(const char *source, uint8_t **output, size_t *outputlength, shader_stage stage, bool debug) {
#ifdef _WIN32
Expand Down
2 changes: 1 addition & 1 deletion Sources/backends/glsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static void write_globals(char *glsl, size_t *offset, function *main) {

for (size_t i = 0; i < globals_size; ++i) {
global *g = get_global(globals[i]);
int register_index = global_register_indices[globals[i]];
//int register_index = global_register_indices[globals[i]];

if (g->type == sampler_type_id) {
}
Expand Down
18 changes: 18 additions & 0 deletions Sources/backends/hlsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ static void write_root_signature(char *hlsl, size_t *offset) {
case DEFINITION_SAMPLER:
has_sampler = true;
break;
default:
assert(false);
break;
}
}

Expand Down Expand Up @@ -475,6 +478,9 @@ static void write_root_signature(char *hlsl, size_t *offset) {
srv_index += 1;
}
break;
default:
assert(false);
break;
}
}

Expand All @@ -501,6 +507,9 @@ static void write_root_signature(char *hlsl, size_t *offset) {
cbv_index += 1;
}
break;
default:
assert(false);
break;
}
}

Expand All @@ -525,6 +534,9 @@ static void write_root_signature(char *hlsl, size_t *offset) {

break;
}
default:
assert(false);
break;
}
}
}
Expand All @@ -547,6 +559,9 @@ static void write_root_signature(char *hlsl, size_t *offset) {
*offset += sprintf(&hlsl[*offset], "Sampler(s%i)", sampler_index);
sampler_index += 1;
break;
default:
assert(false);
break;
}
}

Expand Down Expand Up @@ -618,6 +633,9 @@ static void write_functions(char *hlsl, size_t *offset, shader_stage stage, func
}
}
}
default:
assert(false);
break;
}
index += o->size;
}
Expand Down
38 changes: 19 additions & 19 deletions Sources/backends/spirv.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,13 @@ static spirv_id write_type_float(instructions_buffer *instructions, uint32_t wid
return float_type;
}

static spirv_id write_type_vector(instructions_buffer *instructions, spirv_id component_type, uint32_t component_count) {
spirv_id vector_type = allocate_index();

uint32_t operands[] = {vector_type.id, component_type.id, component_count};
write_instruction(instructions, WORD_COUNT(operands), SPIRV_OPCODE_TYPE_VECTOR, operands);
return vector_type;
}
//static spirv_id write_type_vector(instructions_buffer *instructions, spirv_id component_type, uint32_t component_count) {
// spirv_id vector_type = allocate_index();
//
// uint32_t operands[] = {vector_type.id, component_type.id, component_count};
// write_instruction(instructions, WORD_COUNT(operands), SPIRV_OPCODE_TYPE_VECTOR, operands);
// return vector_type;
//}

static spirv_id write_type_vector_preallocated(instructions_buffer *instructions, spirv_id component_type, uint32_t component_count, spirv_id vector_type) {
uint32_t operands[] = {vector_type.id, component_type.id, component_count};
Expand Down Expand Up @@ -569,11 +569,11 @@ static spirv_id write_op_function_preallocated(instructions_buffer *instructions
return result;
}

static spirv_id write_op_function(instructions_buffer *instructions, spirv_id result_type, function_control control, spirv_id function_type) {
spirv_id result = allocate_index();
write_op_function_preallocated(instructions, result_type, control, function_type, result);
return result;
}
//static spirv_id write_op_function(instructions_buffer *instructions, spirv_id result_type, function_control control, spirv_id function_type) {
// spirv_id result = allocate_index();
// write_op_function_preallocated(instructions, result_type, control, function_type, result);
// return result;
//}

static spirv_id write_op_label(instructions_buffer *instructions) {
spirv_id result = allocate_index();
Expand Down Expand Up @@ -721,13 +721,13 @@ static spirv_id write_op_variable_preallocated(instructions_buffer *instructions
return result;
}

static spirv_id write_op_variable_with_initializer(instructions_buffer *instructions, uint32_t result_type, storage_class storage, uint32_t initializer) {
spirv_id result = allocate_index();

uint32_t operands[] = {result_type, result.id, (uint32_t)storage, initializer};
write_instruction(instructions, WORD_COUNT(operands), SPIRV_OPCODE_VARIABLE, operands);
return result;
}
//static spirv_id write_op_variable_with_initializer(instructions_buffer *instructions, uint32_t result_type, storage_class storage, uint32_t initializer) {
// spirv_id result = allocate_index();
//
// uint32_t operands[] = {result_type, result.id, (uint32_t)storage, initializer};
// write_instruction(instructions, WORD_COUNT(operands), SPIRV_OPCODE_VARIABLE, operands);
// return result;
//}

static struct {
uint64_t key;
Expand Down
9 changes: 9 additions & 0 deletions Sources/backends/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ void find_referenced_globals(function *f, global_id *globals, size_t *globals_si
}
break;
}
default:
assert(false);
break;
}

index += o->size;
Expand Down Expand Up @@ -132,6 +135,9 @@ void find_referenced_functions(function *f, function **functions, size_t *functi
}
break;
}
default:
assert(false);
break;
}

index += o->size;
Expand Down Expand Up @@ -183,6 +189,9 @@ void find_referenced_types(function *f, type_id *types, size_t *types_size) {
case OPCODE_VAR:
add_found_type(o->op_var.var.type.type, types, types_size);
break;
default:
assert(false);
break;
}

index += o->size;
Expand Down
6 changes: 3 additions & 3 deletions Sources/backends/wgsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ static char *type_string(type_id type) {
return get_name(get_type(type)->name);
}

static char *function_string(name_id func) {
return get_name(func);
}
//static char *function_string(name_id func) {
// return get_name(func);
//}

static void write_code(char *wgsl, char *directory, const char *filename) {
char full_filename[512];
Expand Down
16 changes: 10 additions & 6 deletions Sources/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ variable emit_expression(opcodes *code, block *parent, expression *e) {
o.type = OPCODE_XOR;
break;
default: {
debug_context context = {0};
error(context, "Unexpected operator");
}
}
Expand Down Expand Up @@ -200,7 +199,6 @@ variable emit_expression(opcodes *code, block *parent, expression *e) {
o.type = OPCODE_MOD;
break;
default: {
debug_context context = {0};
error(context, "Unexpected operator");
}
}
Expand All @@ -213,7 +211,6 @@ variable emit_expression(opcodes *code, block *parent, expression *e) {
return result_var;
}
case OPERATOR_NOT: {
debug_context context = {0};
error(context, "! is not a binary operator");
}
case OPERATOR_ASSIGN:
Expand Down Expand Up @@ -243,7 +240,6 @@ variable emit_expression(opcodes *code, block *parent, expression *e) {
o.type = OPCODE_MULTIPLY_AND_STORE_VARIABLE;
break;
default: {
debug_context context = {0};
error(context, "Unexpected operator");
}
}
Expand Down Expand Up @@ -275,7 +271,6 @@ variable emit_expression(opcodes *code, block *parent, expression *e) {
o.type = OPCODE_MULTIPLY_AND_STORE_MEMBER;
break;
default: {
debug_context context = {0};
error(context, "Unexpected operator");
}
}
Expand Down Expand Up @@ -414,6 +409,11 @@ variable emit_expression(opcodes *code, block *parent, expression *e) {
error(context, "not implemented");
case OPERATOR_ASSIGN:
error(context, "not implemented");
case OPERATOR_PLUS_ASSIGN:
case OPERATOR_MINUS_ASSIGN:
case OPERATOR_MULTIPLY_ASSIGN:
case OPERATOR_DIVIDE_ASSIGN:
error(context, "not implemented");
}
}
case EXPRESSION_BOOLEAN: {
Expand Down Expand Up @@ -592,6 +592,10 @@ variable emit_expression(opcodes *code, block *parent, expression *e) {
debug_context context = {0};
error(context, "not implemented");
}
default: {
debug_context context = {0};
error(context, "not implemented");
}
}

{
Expand Down Expand Up @@ -863,7 +867,7 @@ static block_ids emit_statement(opcodes *code, block *parent, statement *stateme
o.type = OPCODE_VAR;
o.size = OP_SIZE(o, op_var);

variable init_var;
variable init_var = {0};
if (statement->local_variable.init != NULL) {
init_var = emit_expression(code, parent, statement->local_variable.init);
}
Expand Down
Loading

0 comments on commit 500463c

Please sign in to comment.