]> git.xonotic.org Git - xonotic/gmqcc.git/blob - doc/gmqcc.1
ir: fix generation of multi-op vinstrs
[xonotic/gmqcc.git] / doc / gmqcc.1
1 .\"mdoc
2 .Dd January 24, 2013
3 .Dt GMQCC 1 PRM
4 .Os
5 .Sh NAME
6 .Nm gmqcc
7 .Nd A Quake C compiler built from the NIH realm of sarcastic wit
8 .Sh SYNOPSIS
9 .Nm gmqcc
10 .Op Cm options
11 .Op Ar files...
12 .Sh DESCRIPTION
13 Traditionally, a QC compiler reads the file
14 .Pa progs.src
15 which in its first line contains the output filename, and the rest is a
16 list of QC source files that are to be compiled in order.
17 .Nm gmqcc
18 optionally takes options to specify the output and
19 input files on the commandline, and also accepts assembly files.
20 .Sh OPTIONS
21 .Nm gmqcc
22 mostly tries to mimic gcc's commandline handling, though
23 there are also traditional long-options available.
24 .Bl -tag -width Ds
25 .It Fl h , Fl -help
26 Show a usage message and exit.
27 .It Fl o , Fl -output= Ns Ar filename
28 Specify the output filename. Defaults to progs.dat. This will overwrite
29 the output file listed in a
30 .Pa progs.src
31 file in case such a file is used.
32 .Bl -tag -width indent
33 .It Fl O Ns Ar number
34 Specify the optimization level
35 .It Ar 3
36 Highest optimization level
37 .It Ar 2
38 Default optimization level
39 .It Ar 1
40 Minimal optimization level
41 .It Ar 0
42 Disable optimization entirely
43 .El
44 .Pp
45 .It Fl O Ns Ar name , Fl Ono- Ns Ar name
46 Enable or disable a specific optimization. Note that these options
47 must be used after setting the optimization level, otherwise they'll
48 be overwritten.
49 .It Fl O Ns Cm help
50 List all possible optimizations and the optimization level they're
51 activated at.
52 .It Fl q , Fl -quiet
53 Be less verbose. In particular removes the messages about which files
54 are being processed, and which compilation mode is being used, and
55 some others. Warnings and errors will of course still be displayed.
56 .It Fl D Ns Ar macroname , Fl D Ns Ar macroname Ns = Ns Ar value
57 Predefine a macro, optionally with a optional value.
58 .It Fl E
59 Run only the preprocessor as if
60 .Fl f Ns Cm ftepp
61 was used and print the preprocessed code to stdout.
62 .It Fl W Ns Ar warning , Fl Wno- Ns Ar warning
63 Enable or disable a warning.
64 .It Fl W Ns Cm all
65 Enable almost all warnings. Overrides preceding
66 .Fl W
67 parameters.
68 .Pp
69 The following warnings will
70 .Em not
71 be enabled:
72 .Bl -tag -width indent -offset indent
73 .It Fl W Ns Cm uninitialized-global
74 .El
75 .It Fl W Ns Cm error , Fl Wno- Ns Cm error
76 Controls whether or not all warnings should be treated as errors.
77 .It Fl Werror- Ns Ar warning , Fl Wno-error- Ns Ar warning
78 Controls whether a specific warning should be an error.
79 .It Fl W Ns Cm help
80 List all possible warn flags.
81 .It Fl f Ns Ar flag , Fl fno- Ns Ar flag
82 Enable or disable a specific compile flag. See the list of flags
83 below.
84 .It Fl f Ns Cm help
85 List all possible compile flags.
86 .It Fl nocolor
87 Disables colored output
88 .It Fl config= Ns Ar file
89 Use an ini file to read all the
90 .Fl O , Fl W
91 and
92 .Fl f
93 flag from. See the
94 .It Fl "debug"
95 Turn on some compiler debugging mechanisms.
96 .It Fl memchk
97 Turn on compiler mem-check. (Shows allocations and checks for leaks.)
98 .It Fl -memdumpcols Ns Ar columns
99 Changes the number of columns to use for the debug memory dump, defaults to 16.
100 .Sx CONFIG
101 section about the file format.
102 .It Fl redirout= Ns Ar file
103 Redirects standard output to a
104 .Ar file
105 .It Fl redirerr= Ns Ar file
106 Redirects standard error to a
107 .Ar file
108 .It Fl std= Ns Ar standard
109 Use the specified standard for parsing QC code. The following standards
110 are available:
111 .Ar gmqcc , Ar qcc , Ar fteqcc
112 Selecting a standard also implies some
113 .Fl f
114 options and behaves as if
115 those options have been written right after the
116 .Fl std
117 option, meaning
118 if you changed them before the
119 .Fl -std
120 option, you're now overwriting them.
121 .Pp
122 .Fl std= Ns Cm gmqcc No includes:
123 .Bl -tag -width indent -compact -offset Ds
124 .It Fl f Ns Cm adjust-vector-fields
125 .It Fl f Ns Cm correct-logic
126 .It Fl f Ns Cm true-empty-strings
127 .It Fl f Ns Cm loop-labels
128 .It Fl f Ns Cm initialized-nonconstants
129 .It Fl f Ns Cm translatable-strings
130 .It Fl fno- Ns Cm false-empty-strings
131 .It Fl W Ns Cm invalid-parameter-count
132 .It Fl W Ns Cm missing-returnvalues
133 .It Fl f Ns Cm correct-ternary Li (cannot be turned off)
134 .El
135 .Pp
136 .Fl std= Ns Cm qcc No includes:
137 .Bl -tag -width indent -compact -offset Ds
138 .It Fl f Ns Cm assign-function-types
139 .It Fl fIno- Ns Cm adjust-vector-fields
140 .El
141 .Pp
142 .Fl std= Ns Cm fteqcc No includes:
143 .Bl -tag -width indent -compact -offset Ds
144 .It Fl f Ns Cm ftepp
145 .It Fl f Ns Cm translatable-strings
146 .It Fl f Ns Cm assign-function-types
147 .It Fl W Ns Cm ternary-precedence
148 .It Fl fno- Ns Cm adjust-vector-fields
149 .It Fl fno- Ns Cm correct-ternary
150 .El
151 .It Fl -add-info
152 Adds compiler information to the generated binary file. Currently
153 this includes the following globals:
154 .Bl -tag -width indent -compact
155 .It Li reserved:version
156 String containing the compiler version as printed by the \-\-version
157 parameter.
158 .El
159 .It Fl -correct , Fl -no-correct
160 When enabled, errors about undefined values try to suggest an existing
161 value via spell checking.
162 .It Fl dump
163 DEBUG OPTION. Print the code's intermediate representation before the
164 optimization and finalization passes to stdout before generating the
165 binary.
166 .It Fl dumpfin
167 DEBUG OPTION. Print the code's intermediate representation after the
168 optimization and finalization passes to stdout before generating the
169 binary. The instructions will be enumerated, and values will contain a
170 list of liferanges.
171 .It Fl force-crc= Ns Ar CRC
172 Force the produced progs file to use the specified CRC.
173 .It Fl state-fps= Ns Ar NUM
174 Activate \-femulate-state and set the emulated FPS to
175 .Ar NUM Ns .
176 .El
177 .Sh COMPILE WARNINGS
178 .Bl -tag -width Ds
179 .It Fl W Ns Cm unused-variable
180 Generate a warning about variables which are declared but never used.
181 This can be avoided by adding the
182 .Ql noref
183 keyword in front of the
184 variable declaration. Additionally a complete section of unreferenced
185 variables can be opened using
186 .Ql #pragma noref 1
187 and closed via
188 .Ql #pragma noref 0 Ns .
189 .It Fl W Ns Cm unused-component
190 Generate a warning about vector variables which are declared but not all their
191 components are used.
192 .It Fl W Ns Cm used-uninitialized
193 Generate a warning if it is possible that a variable can be used
194 without prior initialization. Note that this warning is not
195 necessarily reliable if the initialization happens only under certain
196 conditions. The other way is
197 .Em not
198 possible: that the warning is
199 .Em not
200 generated when uninitialized use
201 .Em is
202 possible.
203 .It Fl W Ns Cm unknown-control-sequence
204 Generate an error when an unrecognized control sequence in a string is
205 used. Meaning: when there's a character after a backslash in a string
206 which has no known meaning.
207 .It Fl W Ns Cm extensions
208 Warn when using special extensions which are not part of the selected
209 standard.
210 .It Fl W Ns Cm field-redeclared
211 Generally QC compilers ignore redeclaration of fields. Here you can
212 optionally enable a warning.
213 .It Fl W Ns Cm missing-return-values
214 Functions which aren't of type
215 .Ft void
216 will warn if it possible to
217 reach the end without returning an actual value.
218 .It Fl W Ns Cm invalid-parameter-count
219 Warn about a function call with an invalid number of parameters.
220 .It Fl W Ns Cm local-shadows
221 Warn when a locally declared variable shadows variable.
222 .It Fl W Ns Cm local-constants
223 Warn when the initialization of a local variable turns the variable
224 into a constant. This is default behaviour unless
225 .Fl f Ns Cm initialized-nonconstants
226 is used.
227 .It Fl W Ns Cm void-variables
228 There are only 2 known global variables of type void:
229 .Ql end_sys_globals
230 and
231 .Ql end_sys_fields Ns .
232 Any other void-variable will warn.
233 .It Fl W Ns Cm implicit-function-pointer
234 A global function which is not declared with the
235 .Ql var
236 keyword is
237 expected to have an implementing body, or be a builtin. If neither is
238 the case, it implicitly becomes a function pointer, and a warning is
239 generated.
240 .It Fl W Ns Cm variadic-function
241 Currently there's no way for an in QC implemented function to access
242 variadic parameters. If a function with variadic parameters has an
243 implementing body, a warning will be generated.
244 .It Fl W Ns Cm frame-macros
245 Generate warnings about
246 .Ql $frame
247 commands, for instance about
248 duplicate frame definitions.
249 .It Fl W Ns Cm effectless-statement
250 Warn about statements which have no effect. Any expression which does
251 not call a function or assigns a variable.
252 .It Fl W Ns Cm end-sys-fields
253 The
254 .Ql end_sys_fields
255 variable is supposed to be a global variable
256 of type
257 .Ft void Ns .
258 It is also recognized as a \fIfield\fR but this
259 will generate a warning.
260 .It Fl W Ns Cm assign-function-types
261 Warn when assigning to a function pointer with an unmatching
262 signature. This usually happens in cases like assigning the null
263 function to an entity's .think function pointer.
264 .It Fl W Ns Cm cpp
265 Show warnings created using the preprocessor's '#warning' directive.
266 .It Fl W Ns Cm multifile-if
267 Warn if there's a preprocessor \fI#if\fR spanning across several
268 files.
269 .It Fl W Ns Cm double-declaration
270 Warn about multiple declarations of globals. This seems pretty common
271 in QC code so you probably do not want this unless you want to clean
272 up your code.
273 .It Fl W Ns Cm const-var
274 The combination of \fIconst\fR and \fIvar\fR is not illegal, however
275 different compilers may handle them differently. We were told, the
276 intention is to create a function-pointer which is not assignable.
277 This is exactly how we interpret it. However for this interpretation
278 the
279 .Ql var
280 keyword is considered superfluous (and philosophically
281 wrong), so it is possible to generate a warning about this.
282 .It Fl W Ns Cm multibyte-character
283 Warn about multibyte character constants, they do not work right now.
284 .It Fl W Ns Cm ternary-precedence
285 Warn if a ternary expression which contains a comma operator is used
286 without enclosing parenthesis, since this is most likely not what you
287 actually want. We recommend the
288 .Fl f Ns Cm correct-ternary
289 option.
290 .It Fl W Ns Cm unknown-pragmas
291 Warn when encountering an unrecognized
292 .Ql #pragma
293 line.
294 .It Fl W Ns Cm unreachable-code
295 Warn about unreachable code. That is: code after a return statement,
296 or code after a call to a function marked as 'noreturn'.
297 .It Fl W Ns Cm debug
298 Enable some warnings added in order to help debugging in the compiler.
299 You won't need this.
300 .It Fl W Ns Cm unknown-attribute
301 Warn on an unknown attribute. The warning will inlclude only the first
302 token inside the enclosing attribute-brackets. This may change when
303 the actual attribute syntax is better defined.
304 .It Fl W Ns Cm reserved-names
305 Warn when using reserved names such as
306 .Ql nil Ns .
307 .It Fl W Ns Cm uninitialized-constant
308 Warn about global constants (using the
309 .Ql const
310 keyword) with no
311 assigned value.
312 .It Fl W Ns Cm uninitialized-global
313 Warn about global variables with no initializing value. This is off by
314 default, and is added mostly to help find null-values which are
315 supposed to be replaced by the untyped 'nil' constant.
316 .It Fl W Ns Cm different-qualifiers
317 Warn when a variables is redeclared with a different qualifier. For
318 example when redeclaring a variable as \'var\' which was previously
319 marked \'const\'.
320 .It Fl W Ns Cm different-attributes
321 Similar to the above but for attributes like
322 .Ql [[noreturn]] Ns .
323 .It Fl W Ns Cm deprecated
324 Warn when a function is marked with the attribute
325 "[[deprecated]]". This flag enables a warning on calls to functions
326 marked as such.
327 .It Fl W Ns Cm parenthesis
328 Warn about possible mistakes caused by missing or wrong parenthesis,
329 like an assignment in an 'if' condition when there's no additional set
330 of parens around the assignment.
331 .It Fl W Ns Cm unsafe-types
332 When passing variadic parameters via
333 .Li ...(N)
334 it can happen that incompatible types are passed to functions. This
335 enables several warnings when static typechecking cannot guarantee
336 consistent behavior.
337 .It Fl W Ns Cm breakdef
338 When compiling original id1 QC there is a definition for `break`
339 which conflicts with the 'break' keyword in GMQCC. Enabling this
340 will print a warning when the definition occurs. The definition is
341 ignored for both cases.
342 .It Fl W Ns Cm const-overwrite
343 When compiling original QuakeWorld QC there are instances where
344 code overwrites constants. This is considered an error, however
345 for QuakeWorld to compile it needs to be treated as a warning
346 instead, as such this warning only works when \-std=qcc.
347 .It Fl W Ns Cm directive-inmacro
348 Warn about the use of preprocessor directives inside macros.
349 .It Fl W Ns Cm builtins
350 When using a function that is not explicitly defined, the compiler
351 will search its intrinsics table for something that matches that
352 function name by appending "__builtin_" to it. This behaviour may
353 be unexpected, so enabling this will produce a diagnostic when
354 such a function is resolved to a builtin.
355 .It Fl W Ns Cm inexact-compares
356 When comparing an inexact value such as `1.0/3.0' the result is
357 pathologically wrong. Enabling this will trigger a compiler warning
358 on such expressions.
359 .El
360 .Sh COMPILE FLAGS
361 .Bl -tag -width Ds
362 .It Fl f Ns Cm darkplaces-string-table-bug
363 Add some additional characters to the string table in order to
364 compensate for a wrong boundcheck in some specific version of the
365 darkplaces engine.
366 .It Fl f Ns Cm adjust-vector-fields
367 When assigning to field pointers of type \fI.vector\fR the common
368 behaviour in compilers like \fIfteqcc\fR is to only assign the
369 x-component of the pointer. This means that you can use the vector as
370 such, but you cannot use its y and z components directly. This flag
371 fixes this behaviour. Before using it make sure your code does not
372 depend on the buggy behaviour.
373 .It Fl f Ns Cm ftepp
374 Enable a partially fteqcc-compatible preprocessor. It supports all the
375 features used in the Xonotic codebase. If you need more, write a
376 ticket.
377 .It Fl f Ns Cm ftepp-predefs
378 Enable some predefined macros. This only works in combination with
379 \'\-fftepp' and is currently not included by '\-std=fteqcc'. The
380 following macros will be added:
381 .Bd -literal -offset indent
382 __LINE__
383 __FILE__
384 __COUNTER__
385 __COUNTER_LAST__
386 __RANDOM__
387 __RANDOM_LAST__
388 __DATE__
389 __TIME__
390 __FUNC__
391 .Ed
392 .Pp
393 Note that
394 .Li __FUNC__
395 is not actually a preprocessor macro, but is recognized by the parser
396 even with the preprocessor disabled.
397 .Pp
398 Note that fteqcc also defines
399 .Li __NULL__
400 which becomes the first global. Assigning it to a vector does not
401 yield the same result as in gmqcc where
402 .Li __NULL__
403 is defined to
404 .Li nil
405 (See
406 .Fl f Ns Cm untyped-nil
407 ), which will cause the vector to be zero in all components. With fteqcc
408 only the first component will be 0, while the other two will become
409 the first to of the global return value. This behavior is odd and
410 relying on it should be discouraged, and thus is not supported by
411 gmqcc.
412 .It Fl f Ns Cm ftepp-mathdefs
413 Enable math constant definitions. This only works in combination
414 with \'\-fftepp' and is currently not included by '\-std=fteqcc'.
415 The following macros will be added:
416 .Bd -literal -offset indent
417 M_E
418 M_LOG2E
419 M_LOG10E
420 M_LN2
421 M_LN10
422 M_PI
423 M_PI_2
424 M_PI_4
425 M_1_PI
426 M_2_PI
427 M_2_SQRTPI
428 M_SQRT2
429 M_SQRT1_2
430 M_TAU
431 .Ed
432 .It Fl f Ns Cm ftepp-indirect-expansion
433 Enable indirect macro expansion. This only works in combination
434 with '-fftepp' and is currently not included by '-std=fteqcc'.
435 Enabling this behavior will allow the preprocessor to operate more
436 like the standard C preprocessor in that it will allow arguments
437 of macros which are macro-expanded to be substituted into the
438 definition of the macro.
439 .Pp
440 As an example:
441 .Bd -literal -offset indent
442 #define STR1(x) #x
443 #define STR2(x) STR1(x)
444 #define THE_ANSWER 42
445 #define THE_ANSWER_STR STR2(THE_ANSWER) /* "42" */
446
447 .Ed
448 With this enabled, an expansion of THE_ANSWER_STR will yield
449 the string "42". With this disabled an expansion of THE_ANSWER_STR
450 will yield "THE_ANSWER"
451 .It Fl f Ns Cm relaxed-switch
452 Allow switch cases to use non constant variables.
453 .It Fl f Ns Cm short-logic
454 Perform early out in logical AND and OR expressions. The final result
455 will be either a 0 or a 1, see the next flag for more possibilities.
456 .It Fl f Ns Cm perl-logic
457 In many languages, logical expressions perform early out in a special
458 way: If the left operand of an AND yeilds true, or the one of an OR
459 yields false, the complete expression evaluates to the right side.
460 Thus
461 .Ql true && 5
462 evaluates to 5 rather than 1.
463 .It Fl f Ns Cm translatable-strings
464 Enable the underscore intrinsic: Using
465 .Ql _("A string constant")
466 will cause the string immediate to get a name with a "dotranslate_"
467 prefix. The darkplaces engine recognizes these and translates them in
468 a way similar to how gettext works.
469 .It Fl f Ns Cm initialized-nonconstants
470 Don't implicitly convert initialized variables to constants. With this
471 flag, the \fIconst\fR keyword is required to make a constant.
472 .It Fl f Ns Cm assign-function-types
473 If this flag is not set, (and it is set by default in the qcc and
474 fteqcc standards), assigning function pointers of mismatching
475 signatures will result in an error rather than a warning.
476 .It Fl f Ns Cm lno
477 Produce a linenumber file along with the output .dat file.
478 .It Fl f Ns Cm correct-ternary
479 Use C's operator precedence for ternary expressions. Unless your code
480 depends on fteqcc-compatible behaviour, you'll want to use thi
481 soption.
482 .It Fl f Ns Cm single-vector-defs
483 Normally vectors generate 4 defs, once for the vector, and once for
484 its components with _x, _y, _z suffixes. This option
485 prevents components from being listed.
486 .It Fl f Ns Cm correct-logic
487 Most QC compilers translate
488 .Ql if(a_vector)
489 directly as an IF on the
490 vector, which means only the x-component is checked. This option causes
491 vectors to be cast to actual booleans via a NOT_V and, if necessary, a
492 NOT_F chained to it.
493 .Bd -literal -offset indent
494 if (a_vector) // becomes
495 if not(!a_vector)
496 // likewise
497 a = a_vector && a_float // becomes
498 a = !!a_vector && a_float
499 .Ed
500 .It Fl f Ns Cm true-empty-strings
501 An empty string is considered to be true everywhere. The NOT_S
502 instruction usually considers an empty string to be false, this option
503 effectively causes the unary not in strings to use NOT_F instead.
504 .It Fl f Ns Cm false-empty-strings
505 An empty string is considered to be false everywhere. This means loops
506 and if statements which depend on a string will perform a NOT_S
507 instruction on the string before using it.
508 .It Fl f Ns Cm utf8
509 Enable utf8 characters. This allows utf-8 encoded character constants,
510 and escape sequence codepoints in the valid utf-8 range. Effectively
511 enabling escape sequences like '\\{x2211}'.
512 .It Fl f Ns Cm bail-on-werror
513 When a warning is treated as an error, and this option is set (which
514 it is by default), it is like any other error and will cause
515 compilation to stop. When disabling this flag by using
516 \-fno-bail-on-werror, compilation will continue until the end, but no
517 output is generated. Instead the first such error message's context is
518 shown.
519 .It Fl f Ns Cm loop-labels
520 Allow loops to be labeled, and allow 'break' and 'continue' to take an
521 optional label to decide which loop to actually jump out of or
522 continue.
523 .Bd -literal -offset indent
524 for :outer (i = 0; i < n; ++i) {
525     while (inner) {
526         ...;
527         if (something)
528             continue outer;
529     }
530 }
531 .Ed
532 .It Fl f Ns Cm untyped-nil
533 Adds a global named 'nil' which is of no type and can be assigned to
534 anything. No typechecking will be performed on assignments. Assigning
535 to it is forbidden, using it in any other kind of expression is also
536 not allowed.
537 .sp
538 Note that this is different from fteqcc's __NULL__: In fteqcc,
539 __NULL__ maps to the integer written as '0i'. It's can be assigned to
540 function pointers and integers, but it'll error about invalid
541 instructions when assigning it to floats without enabling the FTE
542 instruction set. There's also a bug which allows it to be assigned to
543 vectors, for which the source will be the global at offset 0, meaning
544 the vector's y and z components will contain the OFS_RETURN x and y
545 components.
546 .sp
547 In that gmqcc the nil global is an actual global filled with zeroes,
548 and can be assigned to anything including fields, vectors or function
549 pointers, and they end up becoming zeroed.
550 .It Fl f Ns Cm permissive
551 Various effects, usually to weaken some conditions.
552 .Bl -tag -width indent -offset indent
553 .It with Fl f Ns Cm untyped-nil
554 Allow local variables named
555 .Ql nil Ns .
556 (This will not allow declaring a global of that name.)
557 .El
558 .It Fl f Ns Cm variadic-args
559 Allow variadic parameters to be accessed by QC code. This can be
560 achieved via the '...' function, which takes a parameter index and a
561 typename.
562 .Pp
563 Example:
564 .Bd -literal -offset indent
565 void vafunc(string...count) {
566     float i;
567     for (i = 0; i < count; ++i)
568         print(...(i, string), "\\n");
569 }
570 .Ed
571 .It Fl f Ns Cm legacy-vector-maths
572 Most Quake VMs, including the one from FTEQW or up till recently
573 Darkplaces, do not cope well with vector instructions with overlapping
574 input and output. This option will avoid producing such code.
575 .It Fl f Ns Cm expressions-for-builtins
576 Usually builtin-numbers are just immediate constants. With this flag
577 expressions can be used, as long as they are compile-time constant.
578 .Pp
579 Example:
580 .Bd -literal -offset indent
581 void printA() = #1; // the usual way
582 void printB() = #2-1; // with a constant expression
583 .Ed
584 .It Fl f Ns Cm return-assignments
585 Enabiling this option will allow assigning values or expressions to the
586 return keyword as if it were a local variable of the same type as the
587 function's signature's return type.
588 .Pp
589 Example:
590 .Bd -literal -offset indent
591 float bar() { return 1024; }
592 float fun() {
593     return = bar();
594     return; // returns value of bar
595 }
596 .Ed
597 .It Fl f Ns Cm unsafe-varargs
598 When passing on varargs to a different functions, this turns some
599 static error cases into warnings. Like when the caller's varargs are
600 restricted to a different type than the callee's parameter. Or a list
601 of unrestricted varargs is passed into restricted varargs.
602 .It Fl f Ns Cm typeless-stores
603 Always use STORE_F, LOAD_F, STOREP_F when accessing scalar variables.
604 This is somewhat incorrect assembly instruction use, but in all engines
605 they do exactly the same. This makes disassembly output harder to read,
606 breaks decompilers, but causes the output file to be better compressible.
607 .It Fl f Ns Cm sort-operands
608 In commutative instructions, always put the lower-numbered operand first.
609 This shaves off 1 byte of entropy from all these instructions, reducing
610 compressed size of the output file.
611 .It Fl f Ns Cm emulate-state
612 Emulate OP_STATE operations in code rather than using the instruction.
613 The desired fps can be set via -state-fps=NUM, defaults to 10.
614 Specifying \-state-fps implicitly sets this flag. Defaults to off in all
615 standards.
616 .It Fl f Ns Cm arithmetic-exceptions
617 Turn on arithmetic exception tests in the compiler. In constant expressions
618 which trigger exceptions like division by zero, overflow, underflow, etc,
619 the following flag will produce diagnostics for what triggered that
620 exception.
621 .It Fl f Ns Cm split-vector-parameters
622 With this flag immediate vector literals which only ever appear as function
623 parameters won't be stored as vector immediates. Instead, the 3 floats making
624 up the vector will be copied separately. Essentially this turns a vector-store
625 instruction into 3 float-store instructions for such cases. This increases
626 code size but can dramatically reduce the amount of vector globals, which is
627 after all limited to 64k. There's at least one known codebase where this
628 lowers the number of globals from over 80k down to around 3k. In other code
629 bases it doesn't reduce the globals at all but only increases code size.
630 Just try it and see whether it helps you.
631 .It Fl f Ns Cm default-eraseable
632 Force all expressions to be "eraseable" which permits the compiler to
633 remove unused functions, variables and statements. This is equivlant to
634 putting [[eraseable]] on all definitions. This is dangerous as it breaks
635 auto cvars, definitions for functions the engine may be looking for and
636 translatable strings. Instead, you can mark a definition with [[noerase]]
637 to prevent this from happening.
638 .El
639 .Sh OPTIMIZATIONS
640 .Bl -tag -width Ds
641 .It Fl O Ns Cm peephole
642 Some general peephole optimizations. For instance the code `a = b + c`
643 typically generates 2 instructions, an ADD and a STORE. This
644 optimization removes the STORE and lets the ADD write directly into A.
645 .It Fl O Ns Cm tail-recursion
646 Tail recursive function calls will be turned into loops to avoid the
647 overhead of the CALL and RETURN instructions.
648 .It Fl O Ns Cm overlap-locals
649 Make all functions which use neither local arrays nor have locals
650 which are seen as possibly uninitialized use the same local section.
651 This should be pretty safe compared to other compilers which do not
652 check for uninitialized values properly. The problem is that there's
653 QC code out there which really doesn't initialize some values. This is
654 fine as long as this kind of optimization isn't used, but also, only
655 as long as the functions cannot be called in a recursive manner. Since
656 it's hard to know whether or not an array is actually fully
657 initialized, especially when initializing it via a loop, we assume
658 functions with arrays to be too dangerous for this optimization.
659 .It Fl O Ns Cm local-temps
660 This promotes locally declared variables to "temps". Meaning when a
661 temporary result of an operation has to be stored somewhere, a local
662 variable which is not 'alive' at that point can be used to keep the
663 result. This can reduce the size of the global section.
664 This will not have declared variables overlap, even if it was
665 possible.
666 .It Fl O Ns Cm global-temps
667 Causes temporary values which do not need to be backed up on a CALL to
668 not be stored in the function's locals-area. With this, a CALL to a
669 function may need to back up fewer values and thus execute faster.
670 .It Fl O Ns Cm strip-constant-names
671 Don't generate defs for immediate values or even declared constants.
672 Meaning variables which are implicitly constant or qualified as such
673 using the 'const' keyword.
674 .It Fl O Ns Cm overlap-strings
675 Aggressively reuse strings in the string section. When a string should
676 be added which is the trailing substring of an already existing
677 string, the existing string's tail will be returned instead of the new
678 string being added.
679 .Pp
680 For example the following code will only generate 1 string:
681 .Bd -literal -offset indent
682 print("Hello you!\\n");
683 print("you!\\n"); // trailing substring of "Hello you!\\n"
684 .Ed
685 .Pp
686 There's however one limitation. Strings are still processed in order,
687 so if the above print statements were reversed, this optimization
688 would not happen.
689 .It Fl O Ns Cm call-stores
690 By default, all parameters of a CALL are copied into the
691 parameter-globals right before the CALL instructions. This is the
692 easiest and safest way to translate calls, but also adds a lot of
693 unnecessary copying and unnecessary temporary values. This
694 optimization makes operations which are used as a parameter evaluate
695 directly into the parameter-global if that is possible, which is when
696 there's no other CALL instruction in between.
697 .It Fl O Ns Cm void-return
698 Usually an empty RETURN instruction is added to the end of a void
699 typed function. However, additionally after every function a DONE
700 instruction is added for several reasons. (For example the qcvm's
701 disassemble switch uses it to know when the function ends.). This
702 optimization replaces that last RETURN with DONE rather than adding
703 the DONE additionally.
704 .It Fl O Ns Cm vector-components
705 Because traditional QC code doesn't allow you to access individual
706 vector components of a computed vector without storing it in a local
707 first, sometimes people multiply it by a constant like
708 .Ql '0 1 0'
709 to get,
710 in this case, the y component of a vector. This optimization will turn
711 such a multiplication into a direct component access. If the factor is
712 anything other than 1, a float-multiplication will be added, which is
713 still faster than a vector multiplication.
714 .It Fl O Ns Cm const-fold-dce
715 For constant expressions that result in dead code (such as a branch whos
716 condition can be evaluated at compile-time), this will eliminate the branch
717 and else body (if present) to produce more optimal code.
718 .El
719 .Sh CONFIG
720 The configuration file is similar to regular .ini files. Comments
721 start with hashtags or semicolons, sections are written in square
722 brackets and in each section there can be arbitrary many key-value
723 pairs.
724 .Pp
725 There are 3 sections currently:
726 .Ql flags Ns ,
727 .Ql warnings Ns ,
728 .Ql optimizations Ns .
729 They contain a list of boolean values of the form
730 .Ql VARNAME = true
731 or
732 .Ql VARNAME = false Ns .
733 The variable names are the same as for the
734 corresponding
735 .Fl W , Fl f
736 or
737 .Fl O
738 flag written with only capital letters and
739 dashes replaced by underscores.
740 .Pp
741 Here's an example:
742 .Bd -literal -offset indent
743 # a GMQCC configuration file
744 [flags]
745     FTEPP = true
746     ADJUST_VECTOR_FIELDS = false
747     LNO = true
748
749 [warnings]
750     UNUSED_VARIABLE = false
751     USED_UNINITIALIZED = true
752
753 [optimizations]
754     PEEPHOLE = true
755     TAIL_RECURSION = true
756 .Ed
757 .Sh FILES
758 .Bl -tag -width Ds
759 .It gmqcc.ini.example
760 A documented example for a gmqcc.ini file.
761 .El
762 .Sh SEE ALSO
763 .Xr qcvm 1
764 .Sh AUTHOR
765 See <http://graphitemaster.github.com/gmqcc>.
766 .Sh BUGS
767 Currently the '\-fftepp-predefs' flag is not included by '\-std=fteqcc',
768 partially because it is not entirely conformant to fteqcc.
769 .Pp
770 Please report bugs on <http://github.com/graphitemaster/gmqcc/issues>,
771 or see <http://graphitemaster.github.com/gmqcc> on how to contact us.