From 72ae59f882b2a25a4196f85a6971ee25c975a6a8 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 22 Oct 2003 08:27:38 +0000 Subject: [PATCH] short circuit logic can now be controlled (see man page) --- tools/qfcc/doc/man/qfcc.1 | 7 +++++++ tools/qfcc/include/options.h | 1 + tools/qfcc/source/expr.c | 3 +++ tools/qfcc/source/options.c | 10 ++++++++++ 4 files changed, 21 insertions(+) diff --git a/tools/qfcc/doc/man/qfcc.1 b/tools/qfcc/doc/man/qfcc.1 index 8df67f2a8..ee4f37dde 100644 --- a/tools/qfcc/doc/man/qfcc.1 +++ b/tools/qfcc/doc/man/qfcc.1 @@ -148,6 +148,13 @@ diagnosing progs crashes. This option tells \fBqfcc\fP to generate this information. It is written to a secondary file with the extension "sym" \(em if your output file is "progs.dat", the symbol file will be "progs.sym". .TP +.B short\-circuit +Generate short circuit code for logical operators (\fB&&\fP and \fB||\fP). For +\fBA && B\fP, if \fBA\fP is false, the expression is known to be false and the +code for \fBB\fP will not be executed. Similar for \fBA || B\fP, but if \fBA\fP +true, the expression is known to be true and the code for \fBB\fP will not be +executed. Defaults to off for traditional and on for advanced. +.TP .B v6only Restrict the compiler to only version 6 progs (original Quake/QuakeWorld) features. This means that the compiled data file should be able to run on diff --git a/tools/qfcc/include/options.h b/tools/qfcc/include/options.h index e5920143e..1f94dd74a 100644 --- a/tools/qfcc/include/options.h +++ b/tools/qfcc/include/options.h @@ -37,6 +37,7 @@ typedef struct { qboolean cow; // Turn constants into variables if written to qboolean debug; // Generate debug info for the engine + qboolean short_circuit; // short circuit logic for && and || unsigned int progsversion; // Progs version to generate code for } code_options_t; diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index 23f4e6b63..39fbab750 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -1542,6 +1542,9 @@ bool_expr (int op, expr_t *label, expr_t *e1, expr_t *e2) { expr_t *block; + if (!options.code.short_circuit) + return binary_expr (op, e1, e2); + e1 = convert_bool (e1, 0); e2 = convert_bool (e2, 0); diff --git a/tools/qfcc/source/options.c b/tools/qfcc/source/options.c index b4d93b361..339782016 100644 --- a/tools/qfcc/source/options.c +++ b/tools/qfcc/source/options.c @@ -170,6 +170,7 @@ DecodeArgs (int argc, char **argv) add_cpp_def ("-D__QUAKEC__=1"); options.code.progsversion = PROG_VERSION; + options.code.short_circuit = -1; options.warnings.uninited_variable = true; options.save_temps = false; @@ -262,6 +263,10 @@ DecodeArgs (int argc, char **argv) options.code.debug = true; } else if (!(strcasecmp (temp, "no-debug"))) { options.code.debug = false; + } else if (!(strcasecmp (temp, "short-circuit"))) { + options.code.short_circuit = true; + } else if (!(strcasecmp (temp, "no-short-circuit"))) { + options.code.short_circuit = false; } else if (!(strcasecmp (temp, "v6only"))) { options.code.progsversion = PROG_ID_VERSION; } else if (!(strcasecmp (temp, "no-v6only"))) { @@ -398,10 +403,15 @@ DecodeArgs (int argc, char **argv) options.traditional = true; options.advanced = false; options.code.progsversion = PROG_ID_VERSION; + if (options.code.short_circuit == -1) + options.code.short_circuit = false; } if (!options.traditional) { + options.advanced = true; add_cpp_def ("-D__RUAMOKO__=1"); add_cpp_def ("-D__RAUMOKO__=1"); + if (options.code.short_circuit == -1) + options.code.short_circuit = true; } if (options.code.progsversion == PROG_ID_VERSION) add_cpp_def ("-D__VERSION6__=1");