[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.
This commit is contained in:
Bill Currie 2024-10-26 23:30:37 +09:00
parent 95eaa4c65e
commit a22d2a9526
5 changed files with 58 additions and 9 deletions

View file

@ -30,10 +30,13 @@
typedef struct symbol_s symbol_t; typedef struct symbol_s symbol_t;
typedef struct type_s type_t; typedef struct type_s type_t;
typedef struct function_s function_t;
typedef struct expr_s expr_t;
typedef struct { typedef struct {
bool (*value_too_large) (const type_t *val_type); bool (*value_too_large) (const type_t *val_type);
void (*build_scope) (symbol_t *fsym); void (*build_scope) (symbol_t *fsym);
void (*emit_function) (function_t *f, const expr_t *e);
} target_t; } target_t;
extern target_t current_target; extern target_t current_target;

View file

@ -1330,15 +1330,7 @@ emit_function (function_t *f, expr_t *e)
{ {
if (pr.error_count) if (pr.error_count)
return; return;
f->code = pr.code->size; current_target.emit_function (f, e);
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);
} }
void void

View file

@ -31,10 +31,16 @@
#include "QF/va.h" #include "QF/va.h"
#include "QF/progs/pr_comp.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/defspace.h"
#include "tools/qfcc/include/diagnostic.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/function.h"
#include "tools/qfcc/include/options.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/strpool.h"
#include "tools/qfcc/include/symtab.h" #include "tools/qfcc/include/symtab.h"
#include "tools/qfcc/include/target.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 = { target_t ruamoko_target = {
.value_too_large = ruamoko_value_too_large, .value_too_large = ruamoko_value_too_large,
.build_scope = ruamoko_build_scope, .build_scope = ruamoko_build_scope,
.emit_function = ruamoko_emit_function,
}; };

View file

@ -162,6 +162,9 @@ spirv_Source (unsigned lang, unsigned version, unsigned srcid,
static void static void
spirv_Name (unsigned id, const char *name, spirvctx_t *ctx) spirv_Name (unsigned id, const char *name, spirvctx_t *ctx)
{ {
if (!name) {
name = "";
}
int len = strlen (name) + 1; int len = strlen (name) + 1;
auto def = spirv_new_insn (SpvOpName, 2 + RUP(len, 4) / 4, ctx->names); auto def = spirv_new_insn (SpvOpName, 2 + RUP(len, 4) / 4, ctx->names);
D_var_o(int, def, 1) = id; D_var_o(int, def, 1) = id;
@ -324,6 +327,7 @@ spirv_TypeFunction (symbol_t *fsym, spirvctx_t *ctx)
static unsigned static unsigned
type_id (const type_t *type, spirvctx_t *ctx) type_id (const type_t *type, spirvctx_t *ctx)
{ {
type = unalias_type (type);
if (spirv_type_id (type, ctx)) { if (spirv_type_id (type, ctx)) {
return 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 = { target_t spirv_target = {
.value_too_large = spirv_value_too_large, .value_too_large = spirv_value_too_large,
.build_scope = spirv_build_scope, .build_scope = spirv_build_scope,
.emit_function = spirv_emit_function,
}; };

View file

@ -31,8 +31,15 @@
#include "QF/va.h" #include "QF/va.h"
#include "QF/progs/pr_comp.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/diagnostic.h"
#include "tools/qfcc/include/emit.h"
#include "tools/qfcc/include/flow.h"
#include "tools/qfcc/include/function.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/strpool.h"
#include "tools/qfcc/include/symtab.h" #include "tools/qfcc/include/symtab.h"
#include "tools/qfcc/include/target.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); 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 = { target_t v6_target = {
.value_too_large = v6_value_too_large, .value_too_large = v6_value_too_large,
.build_scope = v6p_build_scope, .build_scope = v6p_build_scope,
.emit_function = v6p_emit_function,
}; };
target_t v6p_target = { target_t v6p_target = {
.value_too_large = v6_value_too_large, .value_too_large = v6_value_too_large,
.build_scope = v6p_build_scope, .build_scope = v6p_build_scope,
.emit_function = v6p_emit_function,
}; };