[qfcc] Add option to promote of float through ...

The server code is not yet ready for doubles, especially in its varargs
builtins: they expect only floats. When float promotion is enabled
(default for advanced code, disabled for traditional or v6only),
"@float_promoted@" is written to the prog's strings.
This commit is contained in:
Bill Currie 2020-03-08 19:13:57 +09:00
parent bcf75b541a
commit 89ec86f77f
4 changed files with 30 additions and 3 deletions

View file

@ -295,6 +295,12 @@ This can be a problem because instructions can access addresses up to 32767 in
older servers or 65535 in most modern servers.
Defaults to off for traditional mode, and on for advanced mode.
.TP
.B promote\-float
Promote float when passed to a function that takes a variable number of
arguements. Defaults to enabled for advanced code, is forced off for
traditional or v6only code (mostly because such code does not have doubles).
.TP
.B short\-circuit
Generate short circuit code for logical operators (\fB&&\fP and \fB||\fP).

View file

@ -1718,9 +1718,20 @@ build_function_call (expr_t *fexpr, const type_t *ftype, expr_t *params)
if (is_integer_val (e)
&& options.code.progsversion == PROG_ID_VERSION)
convert_int (e);
if (is_float (get_type (e))
&& options.code.progsversion != PROG_ID_VERSION) {
t = &type_double;
if (options.code.promote_float) {
if (is_float (get_type (e))) {
t = &type_double;
}
} else {
if (is_double (get_type (e))) {
if (!e->implicit) {
warning (e, "passing double into ... function");
}
if (is_constant (e)) {
// don't auto-demote non-constant doubles
t = &type_float;
}
}
}
if (is_integer_val (e) && options.warnings.vararg_integer)
warning (e, "passing integer constant into ... function");

View file

@ -203,6 +203,7 @@ code_usage (void)
" help Display this text.\n"
" [no-]local-merging Merge the local variable blocks into one.\n"
" [no-]optimize Perform various optimizations on the code.\n"
" [no-]promote-float Promote float when passed through ...\n"
" [no-]short-circuit Generate short circuit code for logical\n"
" operators.\n"
" [no-]single-cpp Convert progs.src to cpp input file.\n"
@ -310,6 +311,7 @@ DecodeArgs (int argc, char **argv)
options.code.vector_components = -1;
options.code.crc = -1;
options.code.fast_float = true;
options.code.promote_float = true;
options.warnings.uninited_variable = true;
options.warnings.unused = true;
options.warnings.executable = true;
@ -489,6 +491,8 @@ DecodeArgs (int argc, char **argv)
options.code.debug = flag;
} else if (!(strcasecmp (temp, "fast-float"))) {
options.code.fast_float = flag;
} else if (!(strcasecmp (temp, "promote-float"))) {
options.code.promote_float = flag;
} else if (!strcasecmp (temp, "help")) {
code_usage ();
} else if (!(strcasecmp (temp, "local-merging"))) {
@ -716,8 +720,11 @@ DecodeArgs (int argc, char **argv)
options.code.local_merging = true;
if (options.code.vector_components == (qboolean) -1)
options.code.vector_components = false;
} else {
options.code.promote_float = 0;
}
if (options.code.progsversion == PROG_ID_VERSION) {
options.code.promote_float = 0;
add_cpp_def ("-D__VERSION6__=1");
if (options.code.crc == (qboolean) -1)
options.code.crc = true;

View file

@ -148,6 +148,9 @@ InitData (void)
pr.code = codespace_new ();
memset (codespace_newstatement (pr.code), 0, sizeof (dstatement_t));
pr.strings = strpool_new ();
if (options.code.promote_float) {
ReuseString ("@float_promoted@");
}
pr.num_functions = 1;
pr.num_linenos = 0;