From 6db1942bb102b8805a9e1551caf550c9151faa42 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 11 Oct 2024 10:01:45 +0900 Subject: [PATCH] [qfcc] Make max_params a code option Rather than relying on progsversion (I think this also fixes a bug with max params when targeting ruamoko). --- tools/qfcc/include/options.h | 1 + tools/qfcc/source/expr.c | 9 +++++---- tools/qfcc/source/function.c | 3 ++- tools/qfcc/source/target.c | 4 ++++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/qfcc/include/options.h b/tools/qfcc/include/options.h index 13154649f..049b77341 100644 --- a/tools/qfcc/include/options.h +++ b/tools/qfcc/include/options.h @@ -43,6 +43,7 @@ typedef struct { bool vector_calls; // use floats instead of vectors for constant function args bool local_merging; // merge function locals into one block unsigned progsversion; // Progs version to generate code for + int max_params; // maximum param count (-1 = unlimited) bool spirv; // Target spir-v instead of Quake bool vector_components; // add *_[xyz] symbols for vectors bool ifstring; // expand if (str) to if (str != "") diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index a3e2a6932..2ea6f6171 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -2010,12 +2010,13 @@ build_function_call (const expr_t *fexpr, const type_t *ftype, const expr_t *par } } - if (options.code.progsversion < PROG_VERSION - && arg_count > PR_MAX_PARAMS) { - return error (fexpr, "more than %d parameters", PR_MAX_PARAMS); - } if (ftype->func.num_params < -1) { + if (options.code.max_params >= 0 + && arg_count > options.code.max_params) { + return error (fexpr, "more than %d parameters", + options.code.max_params); + } if (-arg_count > ftype->func.num_params + 1) { if (!options.traditional) return error (fexpr, "too few arguments"); diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c index d7d883e0b..307064485 100644 --- a/tools/qfcc/source/function.c +++ b/tools/qfcc/source/function.c @@ -1137,7 +1137,8 @@ static void build_function (symbol_t *fsym) { const type_t *func_type = fsym->metafunc->func->type; - if (func_type->func.num_params > PR_MAX_PARAMS) { + if (options.code.max_params >= 0 + && func_type->func.num_params > options.code.max_params) { error (0, "too many params"); } } diff --git a/tools/qfcc/source/target.c b/tools/qfcc/source/target.c index 4e44605cd..dad3fd4ea 100644 --- a/tools/qfcc/source/target.c +++ b/tools/qfcc/source/target.c @@ -44,15 +44,19 @@ target_set_backend (const char *tgt) if (!strcasecmp (tgt, "v6")) { current_target = v6_target; options.code.progsversion = PROG_ID_VERSION; + options.code.max_params = PR_MAX_PARAMS; } else if (!strcasecmp (tgt, "v6p")) { current_target = v6p_target; options.code.progsversion = PROG_V6P_VERSION; + options.code.max_params = PR_MAX_PARAMS; } else if (!strcasecmp (tgt, "ruamoko")) { current_target = ruamoko_target; options.code.progsversion = PROG_VERSION; + options.code.max_params = -1; } else if (!strcasecmp (tgt, "spir-v")) { current_target = spirv_target; options.code.progsversion = PROG_VERSION; + options.code.max_params = -1; options.code.spirv = true; options.code.no_vararg = true; } else {