From a22d2a9526c5ea95a63f9f9b919dc9284d96e229 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 26 Oct 2024 23:30:37 +0900 Subject: [PATCH] [qfcc] Move guts of emit_function to per-target code Ruamoko and v6(p) have their own copies despite being (currently) the same, and spir-v's is currently empty, but now targeting spir-v doesn't try to emit ruamoko code. --- tools/qfcc/include/target.h | 3 +++ tools/qfcc/source/function.c | 10 +--------- tools/qfcc/source/target_rua.c | 21 +++++++++++++++++++++ tools/qfcc/source/target_spirv.c | 10 ++++++++++ tools/qfcc/source/target_v6.c | 23 +++++++++++++++++++++++ 5 files changed, 58 insertions(+), 9 deletions(-) diff --git a/tools/qfcc/include/target.h b/tools/qfcc/include/target.h index 2963d8a62..a8bf20dfe 100644 --- a/tools/qfcc/include/target.h +++ b/tools/qfcc/include/target.h @@ -30,10 +30,13 @@ typedef struct symbol_s symbol_t; typedef struct type_s type_t; +typedef struct function_s function_t; +typedef struct expr_s expr_t; typedef struct { bool (*value_too_large) (const type_t *val_type); void (*build_scope) (symbol_t *fsym); + void (*emit_function) (function_t *f, const expr_t *e); } target_t; extern target_t current_target; diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c index 307064485..d6db815a9 100644 --- a/tools/qfcc/source/function.c +++ b/tools/qfcc/source/function.c @@ -1330,15 +1330,7 @@ emit_function (function_t *f, expr_t *e) { if (pr.error_count) return; - f->code = pr.code->size; - lineno_base = f->def->loc.line; - f->sblock = make_statements (e); - if (options.code.optimize) { - flow_data_flow (f); - } else { - statements_count_temps (f->sblock); - } - emit_statements (f->sblock); + current_target.emit_function (f, e); } void diff --git a/tools/qfcc/source/target_rua.c b/tools/qfcc/source/target_rua.c index 92616f63b..526b9349a 100644 --- a/tools/qfcc/source/target_rua.c +++ b/tools/qfcc/source/target_rua.c @@ -31,10 +31,16 @@ #include "QF/va.h" #include "QF/progs/pr_comp.h" +#include "tools/qfcc/include/codespace.h" +#include "tools/qfcc/include/debug.h" #include "tools/qfcc/include/defspace.h" #include "tools/qfcc/include/diagnostic.h" +#include "tools/qfcc/include/emit.h" +#include "tools/qfcc/include/flow.h" #include "tools/qfcc/include/function.h" #include "tools/qfcc/include/options.h" +#include "tools/qfcc/include/qfcc.h" +#include "tools/qfcc/include/statements.h" #include "tools/qfcc/include/strpool.h" #include "tools/qfcc/include/symtab.h" #include "tools/qfcc/include/target.h" @@ -109,7 +115,22 @@ ruamoko_build_scope (symbol_t *fsym) } } +static void +ruamoko_emit_function (function_t *f, const expr_t *e) +{ + f->code = pr.code->size; + lineno_base = f->def->loc.line; + f->sblock = make_statements (e); + if (options.code.optimize) { + flow_data_flow (f); + } else { + statements_count_temps (f->sblock); + } + emit_statements (f->sblock); +} + target_t ruamoko_target = { .value_too_large = ruamoko_value_too_large, .build_scope = ruamoko_build_scope, + .emit_function = ruamoko_emit_function, }; diff --git a/tools/qfcc/source/target_spirv.c b/tools/qfcc/source/target_spirv.c index c0adfb4ef..64b12ced8 100644 --- a/tools/qfcc/source/target_spirv.c +++ b/tools/qfcc/source/target_spirv.c @@ -162,6 +162,9 @@ spirv_Source (unsigned lang, unsigned version, unsigned srcid, static void spirv_Name (unsigned id, const char *name, spirvctx_t *ctx) { + if (!name) { + name = ""; + } int len = strlen (name) + 1; auto def = spirv_new_insn (SpvOpName, 2 + RUP(len, 4) / 4, ctx->names); D_var_o(int, def, 1) = id; @@ -324,6 +327,7 @@ spirv_TypeFunction (symbol_t *fsym, spirvctx_t *ctx) static unsigned type_id (const type_t *type, spirvctx_t *ctx) { + type = unalias_type (type); if (spirv_type_id (type, ctx)) { return spirv_type_id (type, ctx); } @@ -909,7 +913,13 @@ spirv_build_scope (symbol_t *fsym) } } +static void +spirv_emit_function (function_t *f, const expr_t *e) +{ +} + target_t spirv_target = { .value_too_large = spirv_value_too_large, .build_scope = spirv_build_scope, + .emit_function = spirv_emit_function, }; diff --git a/tools/qfcc/source/target_v6.c b/tools/qfcc/source/target_v6.c index 4db44bd7c..4f0cc9ec1 100644 --- a/tools/qfcc/source/target_v6.c +++ b/tools/qfcc/source/target_v6.c @@ -31,8 +31,15 @@ #include "QF/va.h" #include "QF/progs/pr_comp.h" +#include "tools/qfcc/include/codespace.h" +#include "tools/qfcc/include/debug.h" #include "tools/qfcc/include/diagnostic.h" +#include "tools/qfcc/include/emit.h" +#include "tools/qfcc/include/flow.h" #include "tools/qfcc/include/function.h" +#include "tools/qfcc/include/options.h" +#include "tools/qfcc/include/qfcc.h" +#include "tools/qfcc/include/statements.h" #include "tools/qfcc/include/strpool.h" #include "tools/qfcc/include/symtab.h" #include "tools/qfcc/include/target.h" @@ -91,12 +98,28 @@ v6_value_too_large (const type_t *val_type) return type_size (val_type) > type_size (&type_param); } +static void +v6p_emit_function (function_t *f, const expr_t *e) +{ + f->code = pr.code->size; + lineno_base = f->def->loc.line; + f->sblock = make_statements (e); + if (options.code.optimize) { + flow_data_flow (f); + } else { + statements_count_temps (f->sblock); + } + emit_statements (f->sblock); +} + target_t v6_target = { .value_too_large = v6_value_too_large, .build_scope = v6p_build_scope, + .emit_function = v6p_emit_function, }; target_t v6p_target = { .value_too_large = v6_value_too_large, .build_scope = v6p_build_scope, + .emit_function = v6p_emit_function, };