]> git.xonotic.org Git - xonotic/gmqcc.git/blob - doc/gmqcc.1
Implement support for indirect macro expansions in the preprocessor. This closes #36
[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 used-uninitialized
190 Generate a warning if it is possible that a variable can be used
191 without prior initialization. Note that this warning is not
192 necessarily reliable if the initialization happens only under certain
193 conditions. The other way is
194 .Em not
195 possible: that the warning is
196 .Em not
197 generated when uninitialized use
198 .Em is
199 possible.
200 .It Fl W Ns Cm unknown-control-sequence
201 Generate an error when an unrecognized control sequence in a string is
202 used. Meaning: when there's a character after a backslash in a string
203 which has no known meaning.
204 .It Fl W Ns Cm extensions
205 Warn when using special extensions which are not part of the selected
206 standard.
207 .It Fl W Ns Cm field-redeclared
208 Generally QC compilers ignore redeclaration of fields. Here you can
209 optionally enable a warning.
210 .It Fl W Ns Cm missing-return-values
211 Functions which aren't of type
212 .Ft void
213 will warn if it possible to
214 reach the end without returning an actual value.
215 .It Fl W Ns Cm invalid-parameter-count
216 Warn about a function call with an invalid number of parameters.
217 .It Fl W Ns Cm local-shadows
218 Warn when a locally declared variable shadows variable.
219 .It Fl W Ns Cm local-constants
220 Warn when the initialization of a local variable turns the variable
221 into a constant. This is default behaviour unless
222 .Fl f Ns Cm initialized-nonconstants
223 is used.
224 .It Fl W Ns Cm void-variables
225 There are only 2 known global variables of type void:
226 .Ql end_sys_globals
227 and
228 .Ql end_sys_fields Ns .
229 Any other void-variable will warn.
230 .It Fl W Ns Cm implicit-function-pointer
231 A global function which is not declared with the
232 .Ql var
233 keyword is
234 expected to have an implementing body, or be a builtin. If neither is
235 the case, it implicitly becomes a function pointer, and a warning is
236 generated.
237 .It Fl W Ns Cm variadic-function
238 Currently there's no way for an in QC implemented function to access
239 variadic parameters. If a function with variadic parameters has an
240 implementing body, a warning will be generated.
241 .It Fl W Ns Cm frame-macros
242 Generate warnings about
243 .Ql $frame
244 commands, for instance about
245 duplicate frame definitions.
246 .It Fl W Ns Cm effectless-statement
247 Warn about statements which have no effect. Any expression which does
248 not call a function or assigns a variable.
249 .It Fl W Ns Cm end-sys-fields
250 The
251 .Ql end_sys_fields
252 variable is supposed to be a global variable
253 of type
254 .Ft void Ns .
255 It is also recognized as a \fIfield\fR but this
256 will generate a warning.
257 .It Fl W Ns Cm assign-function-types
258 Warn when assigning to a function pointer with an unmatching
259 signature. This usually happens in cases like assigning the null
260 function to an entity's .think function pointer.
261 .It Fl W Ns Cm cpp
262 Show warnings created using the preprocessor's '#warning' directive.
263 .It Fl W Ns Cm multifile-if
264 Warn if there's a preprocessor \fI#if\fR spanning across several
265 files.
266 .It Fl W Ns Cm double-declaration
267 Warn about multiple declarations of globals. This seems pretty common
268 in QC code so you probably do not want this unless you want to clean
269 up your code.
270 .It Fl W Ns Cm const-var
271 The combination of \fIconst\fR and \fIvar\fR is not illegal, however
272 different compilers may handle them differently. We were told, the
273 intention is to create a function-pointer which is not assignable.
274 This is exactly how we interpret it. However for this interpretation
275 the
276 .Ql var
277 keyword is considered superfluous (and philosophically
278 wrong), so it is possible to generate a warning about this.
279 .It Fl W Ns Cm multibyte-character
280 Warn about multibyte character constants, they do not work right now.
281 .It Fl W Ns Cm ternary-precedence
282 Warn if a ternary expression which contains a comma operator is used
283 without enclosing parenthesis, since this is most likely not what you
284 actually want. We recommend the
285 .Fl f Ns Cm correct-ternary
286 option.
287 .It Fl W Ns Cm unknown-pragmas
288 Warn when encountering an unrecognized
289 .Ql #pragma
290 line.
291 .It Fl W Ns Cm unreachable-code
292 Warn about unreachable code. That is: code after a return statement,
293 or code after a call to a function marked as 'noreturn'.
294 .It Fl W Ns Cm debug
295 Enable some warnings added in order to help debugging in the compiler.
296 You won't need this.
297 .It Fl W Ns Cm unknown-attribute
298 Warn on an unknown attribute. The warning will inlclude only the first
299 token inside the enclosing attribute-brackets. This may change when
300 the actual attribute syntax is better defined.
301 .It Fl W Ns Cm reserved-names
302 Warn when using reserved names such as
303 .Ql nil Ns .
304 .It Fl W Ns Cm uninitialized-constant
305 Warn about global constants (using the
306 .Ql const
307 keyword) with no
308 assigned value.
309 .It Fl W Ns Cm uninitialized-global
310 Warn about global variables with no initializing value. This is off by
311 default, and is added mostly to help find null-values which are
312 supposed to be replaced by the untyped 'nil' constant.
313 .It Fl W Ns Cm different-qualifiers
314 Warn when a variables is redeclared with a different qualifier. For
315 example when redeclaring a variable as \'var\' which was previously
316 marked \'const\'.
317 .It Fl W Ns Cm different-attributes
318 Similar to the above but for attributes like
319 .Ql [[noreturn]] Ns .
320 .It Fl W Ns Cm deprecated
321 Warn when a function is marked with the attribute
322 "[[deprecated]]". This flag enables a warning on calls to functions
323 marked as such.
324 .It Fl W Ns Cm parenthesis
325 Warn about possible mistakes caused by missing or wrong parenthesis,
326 like an assignment in an 'if' condition when there's no additional set
327 of parens around the assignment.
328 .It Fl W Ns Cm unsafe-types
329 When passing variadic parameters via
330 .Li ...(N)
331 it can happen that incompatible types are passed to functions. This
332 enables several warnings when static typechecking cannot guarantee
333 consistent behavior.
334 .It Fl W Ns Cm breakdef
335 When compiling original id1 QC there is a definition for `break`
336 which conflicts with the 'break' keyword in GMQCC. Enabling this
337 will print a warning when the definition occurs. The definition is
338 ignored for both cases.
339 .It Fl W Ns Cm const-overwrite
340 When compiling original QuakeWorld QC there are instances where
341 code overwrites constants. This is considered an error, however
342 for QuakeWorld to compile it needs to be treated as a warning
343 instead, as such this warning only works when \-std=qcc.
344 .It Fl W Ns Cm directive-inmacro
345 Warn about the use of preprocessor directives inside macros.
346 .It Fl W Ns Cm builtins
347 When using a function that is not explicitly defined, the compiler
348 will search its intrinsics table for something that matches that
349 function name by appending "__builtin_" to it. This behaviour may
350 be unexpected, so enabling this will produce a diagnostic when
351 such a function is resolved to a builtin.
352 .It Fl W Ns Cm inexact-compares
353 When comparing an inexact value such as `1.0/3.0' the result is
354 pathologically wrong. Enabling this will trigger a compiler warning
355 on such expressions.
356 .El
357 .Sh COMPILE FLAGS
358 .Bl -tag -width Ds
359 .It Fl f Ns Cm darkplaces-string-table-bug
360 Add some additional characters to the string table in order to
361 compensate for a wrong boundcheck in some specific version of the
362 darkplaces engine.
363 .It Fl f Ns Cm adjust-vector-fields
364 When assigning to field pointers of type \fI.vector\fR the common
365 behaviour in compilers like \fIfteqcc\fR is to only assign the
366 x-component of the pointer. This means that you can use the vector as
367 such, but you cannot use its y and z components directly. This flag
368 fixes this behaviour. Before using it make sure your code does not
369 depend on the buggy behaviour.
370 .It Fl f Ns Cm ftepp
371 Enable a partially fteqcc-compatible preprocessor. It supports all the
372 features used in the Xonotic codebase. If you need more, write a
373 ticket.
374 .It Fl f Ns Cm ftepp-predefs
375 Enable some predefined macros. This only works in combination with
376 \'\-fftepp' and is currently not included by '\-std=fteqcc'. The
377 following macros will be added:
378 .Bd -literal -offset indent
379 __LINE__
380 __FILE__
381 __COUNTER__
382 __COUNTER_LAST__
383 __RANDOM__
384 __RANDOM_LAST__
385 __DATE__
386 __TIME__
387 __FUNC__
388 .Ed
389 .Pp
390 Note that
391 .Li __FUNC__
392 is not actually a preprocessor macro, but is recognized by the parser
393 even with the preprocessor disabled.
394 .Pp
395 Note that fteqcc also defines
396 .Li __NULL__
397 which becomes the first global. Assigning it to a vector does not
398 yield the same result as in gmqcc where
399 .Li __NULL__
400 is defined to
401 .Li nil
402 (See
403 .Fl f Ns Cm untyped-nil
404 ), which will cause the vector to be zero in all components. With fteqcc
405 only the first component will be 0, while the other two will become
406 the first to of the global return value. This behavior is odd and
407 relying on it should be discouraged, and thus is not supported by
408 gmqcc.
409 .It Fl f Ns Cm ftepp-mathdefs
410 Enable math constant definitions. This only works in combination
411 with \'\-fftepp' and is currently not included by '\-std=fteqcc'.
412 The following macros will be added:
413 .Bd -literal -offset indent
414 M_E
415 M_LOG2E
416 M_LOG10E
417 M_LN2
418 M_LN10
419 M_PI
420 M_PI_2
421 M_PI_4
422 M_1_PI
423 M_2_PI
424 M_2_SQRTPI
425 M_SQRT2
426 M_SQRT1_2
427 M_TAU
428 .Ed
429 .It Fl f Ns Cm ftepp-indirect-expansion
430 Enable indirect macro expansion. This only works in combination
431 with '-fftepp' and is currently not included by '-std=fteqcc'.
432 Enabling this behavior will allow the preprocessor to operate more
433 like the standard C preprocessor in that it will allow arguments
434 of macros which are macro-expanded to be substituted into the
435 definition of the macro.
436 .Pp
437 As an example:
438 .Bd -literal -offset indent
439 #define STR1(x) #x
440 #define STR2(x) STR1(x)
441 #define THE_ANSWER 42
442 #define THE_ANSWER_STR STR2(THE_ANSWER) /* "42" */
443
444 .Ed
445 With this enabled, an expansion of THE_ANSWER_STR will yield
446 the string "42". With this disabled an expansion of THE_ANSWER_STR
447 will yield "THE_ANSWER"
448 .It Fl f Ns Cm relaxed-switch
449 Allow switch cases to use non constant variables.
450 .It Fl f Ns Cm short-logic
451 Perform early out in logical AND and OR expressions. The final result
452 will be either a 0 or a 1, see the next flag for more possibilities.
453 .It Fl f Ns Cm perl-logic
454 In many languages, logical expressions perform early out in a special
455 way: If the left operand of an AND yeilds true, or the one of an OR
456 yields false, the complete expression evaluates to the right side.
457 Thus
458 .Ql true && 5
459 evaluates to 5 rather than 1.
460 .It Fl f Ns Cm translatable-strings
461 Enable the underscore intrinsic: Using
462 .Ql _("A string constant")
463 will cause the string immediate to get a name with a "dotranslate_"
464 prefix. The darkplaces engine recognizes these and translates them in
465 a way similar to how gettext works.
466 .It Fl f Ns Cm initialized-nonconstants
467 Don't implicitly convert initialized variables to constants. With this
468 flag, the \fIconst\fR keyword is required to make a constant.
469 .It Fl f Ns Cm assign-function-types
470 If this flag is not set, (and it is set by default in the qcc and
471 fteqcc standards), assigning function pointers of mismatching
472 signatures will result in an error rather than a warning.
473 .It Fl f Ns Cm lno
474 Produce a linenumber file along with the output .dat file.
475 .It Fl f Ns Cm correct-ternary
476 Use C's operator precedence for ternary expressions. Unless your code
477 depends on fteqcc-compatible behaviour, you'll want to use thi
478 soption.
479 .It Fl f Ns Cm single-vector-defs
480 Normally vectors generate 4 defs, once for the vector, and once for
481 its components with _x, _y, _z suffixes. This option
482 prevents components from being listed.
483 .It Fl f Ns Cm correct-logic
484 Most QC compilers translate
485 .Ql if(a_vector)
486 directly as an IF on the
487 vector, which means only the x-component is checked. This option causes
488 vectors to be cast to actual booleans via a NOT_V and, if necessary, a
489 NOT_F chained to it.
490 .Bd -literal -offset indent
491 if (a_vector) // becomes
492 if not(!a_vector)
493 // likewise
494 a = a_vector && a_float // becomes
495 a = !!a_vector && a_float
496 .Ed
497 .It Fl f Ns Cm true-empty-strings
498 An empty string is considered to be true everywhere. The NOT_S
499 instruction usually considers an empty string to be false, this option
500 effectively causes the unary not in strings to use NOT_F instead.
501 .It Fl f Ns Cm false-empty-strings
502 An empty string is considered to be false everywhere. This means loops
503 and if statements which depend on a string will perform a NOT_S
504 instruction on the string before using it.
505 .It Fl f Ns Cm utf8
506 Enable utf8 characters. This allows utf-8 encoded character constants,
507 and escape sequence codepoints in the valid utf-8 range. Effectively
508 enabling escape sequences like '\\{x2211}'.
509 .It Fl f Ns Cm bail-on-werror
510 When a warning is treated as an error, and this option is set (which
511 it is by default), it is like any other error and will cause
512 compilation to stop. When disabling this flag by using
513 \-fno-bail-on-werror, compilation will continue until the end, but no
514 output is generated. Instead the first such error message's context is
515 shown.
516 .It Fl f Ns Cm loop-labels
517 Allow loops to be labeled, and allow 'break' and 'continue' to take an
518 optional label to decide which loop to actually jump out of or
519 continue.
520 .Bd -literal -offset indent
521 for :outer (i = 0; i < n; ++i) {
522     while (inner) {
523         ...;
524         if (something)
525             continue outer;
526     }
527 }
528 .Ed
529 .It Fl f Ns Cm untyped-nil
530 Adds a global named 'nil' which is of no type and can be assigned to
531 anything. No typechecking will be performed on assignments. Assigning
532 to it is forbidden, using it in any other kind of expression is also
533 not allowed.
534 .sp
535 Note that this is different from fteqcc's __NULL__: In fteqcc,
536 __NULL__ maps to the integer written as '0i'. It's can be assigned to
537 function pointers and integers, but it'll error about invalid
538 instructions when assigning it to floats without enabling the FTE
539 instruction set. There's also a bug which allows it to be assigned to
540 vectors, for which the source will be the global at offset 0, meaning
541 the vector's y and z components will contain the OFS_RETURN x and y
542 components.
543 .sp
544 In that gmqcc the nil global is an actual global filled with zeroes,
545 and can be assigned to anything including fields, vectors or function
546 pointers, and they end up becoming zeroed.
547 .It Fl f Ns Cm permissive
548 Various effects, usually to weaken some conditions.
549 .Bl -tag -width indent -offset indent
550 .It with Fl f Ns Cm untyped-nil
551 Allow local variables named
552 .Ql nil Ns .
553 (This will not allow declaring a global of that name.)
554 .El
555 .It Fl f Ns Cm variadic-args
556 Allow variadic parameters to be accessed by QC code. This can be
557 achieved via the '...' function, which takes a parameter index and a
558 typename.
559 .Pp
560 Example:
561 .Bd -literal -offset indent
562 void vafunc(string...count) {
563     float i;
564     for (i = 0; i < count; ++i)
565         print(...(i, string), "\\n");
566 }
567 .Ed
568 .It Fl f Ns Cm legacy-vector-maths
569 Most Quake VMs, including the one from FTEQW or up till recently
570 Darkplaces, do not cope well with vector instructions with overlapping
571 input and output. This option will avoid producing such code.
572 .It Fl f Ns Cm expressions-for-builtins
573 Usually builtin-numbers are just immediate constants. With this flag
574 expressions can be used, as long as they are compile-time constant.
575 .Pp
576 Example:
577 .Bd -literal -offset indent
578 void printA() = #1; // the usual way
579 void printB() = #2-1; // with a constant expression
580 .Ed
581 .It Fl f Ns Cm return-assignments
582 Enabiling this option will allow assigning values or expressions to the
583 return keyword as if it were a local variable of the same type as the
584 function's signature's return type.
585 .Pp
586 Example:
587 .Bd -literal -offset indent
588 float bar() { return 1024; }
589 float fun() {
590     return = bar();
591     return; // returns value of bar
592 }
593 .Ed
594 .It Fl f Ns Cm unsafe-varargs
595 When passing on varargs to a different functions, this turns some
596 static error cases into warnings. Like when the caller's varargs are
597 restricted to a different type than the callee's parameter. Or a list
598 of unrestricted varargs is passed into restricted varargs.
599 .It Fl f Ns Cm typeless-stores
600 Always use STORE_F, LOAD_F, STOREP_F when accessing scalar variables.
601 This is somewhat incorrect assembly instruction use, but in all engines
602 they do exactly the same. This makes disassembly output harder to read,
603 breaks decompilers, but causes the output file to be better compressible.
604 .It Fl f Ns Cm sort-operands
605 In commutative instructions, always put the lower-numbered operand first.
606 This shaves off 1 byte of entropy from all these instructions, reducing
607 compressed size of the output file.
608 .It Fl f Ns Cm emulate-state
609 Emulate OP_STATE operations in code rather than using the instruction.
610 The desired fps can be set via -state-fps=NUM, defaults to 10.
611 Specifying \-state-fps implicitly sets this flag. Defaults to off in all
612 standards.
613 .It Fl f Ns Cm arithmetic-exceptions
614 Turn on arithmetic exception tests in the compiler. In constant expressions
615 which trigger exceptions like division by zero, overflow, underflow, etc,
616 the following flag will produce diagnostics for what triggered that
617 exception.
618 .El
619 .Sh OPTIMIZATIONS
620 .Bl -tag -width Ds
621 .It Fl O Ns Cm peephole
622 Some general peephole optimizations. For instance the code `a = b + c`
623 typically generates 2 instructions, an ADD and a STORE. This
624 optimization removes the STORE and lets the ADD write directly into A.
625 .It Fl O Ns Cm tail-recursion
626 Tail recursive function calls will be turned into loops to avoid the
627 overhead of the CALL and RETURN instructions.
628 .It Fl O Ns Cm overlap-locals
629 Make all functions which use neither local arrays nor have locals
630 which are seen as possibly uninitialized use the same local section.
631 This should be pretty safe compared to other compilers which do not
632 check for uninitialized values properly. The problem is that there's
633 QC code out there which really doesn't initialize some values. This is
634 fine as long as this kind of optimization isn't used, but also, only
635 as long as the functions cannot be called in a recursive manner. Since
636 it's hard to know whether or not an array is actually fully
637 initialized, especially when initializing it via a loop, we assume
638 functions with arrays to be too dangerous for this optimization.
639 .It Fl O Ns Cm local-temps
640 This promotes locally declared variables to "temps". Meaning when a
641 temporary result of an operation has to be stored somewhere, a local
642 variable which is not 'alive' at that point can be used to keep the
643 result. This can reduce the size of the global section.
644 This will not have declared variables overlap, even if it was
645 possible.
646 .It Fl O Ns Cm global-temps
647 Causes temporary values which do not need to be backed up on a CALL to
648 not be stored in the function's locals-area. With this, a CALL to a
649 function may need to back up fewer values and thus execute faster.
650 .It Fl O Ns Cm strip-constant-names
651 Don't generate defs for immediate values or even declared constants.
652 Meaning variables which are implicitly constant or qualified as such
653 using the 'const' keyword.
654 .It Fl O Ns Cm overlap-strings
655 Aggressively reuse strings in the string section. When a string should
656 be added which is the trailing substring of an already existing
657 string, the existing string's tail will be returned instead of the new
658 string being added.
659 .Pp
660 For example the following code will only generate 1 string:
661 .Bd -literal -offset indent
662 print("Hello you!\\n");
663 print("you!\\n"); // trailing substring of "Hello you!\\n"
664 .Ed
665 .Pp
666 There's however one limitation. Strings are still processed in order,
667 so if the above print statements were reversed, this optimization
668 would not happen.
669 .It Fl O Ns Cm call-stores
670 By default, all parameters of a CALL are copied into the
671 parameter-globals right before the CALL instructions. This is the
672 easiest and safest way to translate calls, but also adds a lot of
673 unnecessary copying and unnecessary temporary values. This
674 optimization makes operations which are used as a parameter evaluate
675 directly into the parameter-global if that is possible, which is when
676 there's no other CALL instruction in between.
677 .It Fl O Ns Cm void-return
678 Usually an empty RETURN instruction is added to the end of a void
679 typed function. However, additionally after every function a DONE
680 instruction is added for several reasons. (For example the qcvm's
681 disassemble switch uses it to know when the function ends.). This
682 optimization replaces that last RETURN with DONE rather than adding
683 the DONE additionally.
684 .It Fl O Ns Cm vector-components
685 Because traditional QC code doesn't allow you to access individual
686 vector components of a computed vector without storing it in a local
687 first, sometimes people multiply it by a constant like
688 .Ql '0 1 0'
689 to get,
690 in this case, the y component of a vector. This optimization will turn
691 such a multiplication into a direct component access. If the factor is
692 anything other than 1, a float-multiplication will be added, which is
693 still faster than a vector multiplication.
694 .It Fl O Ns Cm const-fold-dce
695 For constant expressions that result in dead code (such as a branch whos
696 condition can be evaluated at compile-time), this will eliminate the branch
697 and else body (if present) to produce more optimal code.
698 .El
699 .Sh CONFIG
700 The configuration file is similar to regular .ini files. Comments
701 start with hashtags or semicolons, sections are written in square
702 brackets and in each section there can be arbitrary many key-value
703 pairs.
704 .Pp
705 There are 3 sections currently:
706 .Ql flags Ns ,
707 .Ql warnings Ns ,
708 .Ql optimizations Ns .
709 They contain a list of boolean values of the form
710 .Ql VARNAME = true
711 or
712 .Ql VARNAME = false Ns .
713 The variable names are the same as for the
714 corresponding
715 .Fl W , Fl f
716 or
717 .Fl O
718 flag written with only capital letters and
719 dashes replaced by underscores.
720 .Pp
721 Here's an example:
722 .Bd -literal -offset indent
723 # a GMQCC configuration file
724 [flags]
725     FTEPP = true
726     ADJUST_VECTOR_FIELDS = false
727     LNO = true
728
729 [warnings]
730     UNUSED_VARIABLE = false
731     USED_UNINITIALIZED = true
732
733 [optimizations]
734     PEEPHOLE = true
735     TAIL_RECURSION = true
736 .Ed
737 .Sh FILES
738 .Bl -tag -width Ds
739 .It gmqcc.ini.example
740 A documented example for a gmqcc.ini file.
741 .El
742 .Sh SEE ALSO
743 .Xr qcvm 1
744 .Sh AUTHOR
745 See <http://graphitemaster.github.com/gmqcc>.
746 .Sh BUGS
747 Currently the '\-fftepp-predefs' flag is not included by '\-std=fteqcc',
748 partially because it is not entirely conformant to fteqcc.
749 .Pp
750 Please report bugs on <http://github.com/graphitemaster/gmqcc/issues>,
751 or see <http://graphitemaster.github.com/gmqcc> on how to contact us.