7 .Nd A Quake C compiler built from the NIH realm of sarcastic wit
13 Traditionally, a QC compiler reads the file
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.
18 optionally takes options to specify the output and
19 input files on the commandline, and also accepts assembly files.
22 mostly tries to mimic gcc's commandline handling, though
23 there are also traditional long-options available.
26 Show a usage message and exit.
28 Turn on some compiler debugging mechanisms.
30 Turn on compiler mem-check. (Shows allocations and checks for leaks.)
31 .It Fl o , Fl -output= Ns Ar filename
32 Specify the output filename. Defaults to progs.dat. This will overwrite
33 the output file listed in a
35 file in case such a file is used.
36 .Bl -tag -width indent
38 Specify the optimization level
40 Highest optimization level
42 Default optimization level
44 Minimal optimization level
46 Disable optimization entirely
49 .It Fl O Ns Ar name Fl Ono- Ns Ar name
50 Enable or disable a specific optimization. Note that these options
51 must be used after setting the optimization level, otherwise they'll
54 List all possible optimizations and the optimization level they're
57 Be less verbose. In particular removes the messages about which files
58 are being processed, and which compilation mode is being used, and
59 some others. Warnings and errors will of course still be displayed.
61 Run only the preprocessor as if
63 was used and print the preprocessed code to stdout.
64 .It Fl W Ns Ar warning , Fl Wno- Ns Ar warning
65 Enable or disable a warning.
67 Enable almost all warnings. Overrides preceding
71 The following warnings will
74 .Bl -tag -width indent -offset indent
75 .It Fl W Ns Cm uninitialized-global
77 .It Fl W Ns Cm error , Fl Wno- Ns Cm error
78 Controls whether or not all warnings should be treated as errors.
79 .It Fl Werror- Ns Ar warning , Fl Wno-error- Ns Ar warning
80 Controls whether a specific warning should be an error.
82 List all possible warn flags.
83 .It Fl f Ns Ar flag , Fl fno- Ns Ar flag
84 Enable or disable a specific compile flag. See the list of flags
87 List all possible compile flags.
89 Disables colored output
90 .It Fl config= Ns Ar file
91 Use an ini file to read all the
97 section about the file format.
98 .It Fl redirout= Ns Ar file
99 Redirects standard output to a
101 .It Fl redirerr= Ns Ar file
102 Redirects standard error to a
104 .It Fl std= Ns Ar standard
105 Use the specified standard for parsing QC code. The following standards
107 .Ar gmqcc , Ar qcc , Ar fteqcc
108 Selecting a standard also implies some
110 options and behaves as if
111 those options have been written right after the
114 if you changed them before the
116 option, you're now overwriting them.
118 .Fl std= Ns Cm gmqcc No includes:
119 .Bl -tag -width indent -compact -offset Ds
120 .It Fl f Ns Cm adjust-vector-fields
121 .It Fl f Ns Cm correct-logic
122 .It Fl f Ns Cm true-empty-strings
123 .It Fl f Ns Cm loop-labels
124 .It Fl f Ns Cm initialized-nonconstants
125 .It Fl f Ns Cm translatable-strings
126 .It Fl fno- Ns Cm false-empty-strings
127 .It Fl W Ns Cm invalid-parameter-count
128 .It Fl W Ns Cm missing-returnvalues
129 .It Fl f Ns Cm correct-ternary Li (cannot be turned off)
132 .Fl std= Ns Cm qcc No includes:
133 .Bl -tag -width indent -compact -offset Ds
134 .It Fl f Ns Cm assign-function-types
135 .It Fl fIno- Ns Cm adjust-vector-fields
138 .Fl std= Ns Cm fteqcc No includes:
139 .Bl -tag -width indent -compact -offset Ds
141 .It Fl f Ns Cm translatable-strings
142 .It Fl f Ns Cm assign-function-types
143 .It Fl W Ns Cm ternary-precedence
144 .It Fl fno- Ns Cm adjust-vector-fields
145 .It Fl fno- Ns Cm correct-ternary
148 Adds compiler information to the generated binary file. Currently
149 this includes the following globals:
150 .Bl -tag -width indent -compact
151 .It Li reserved:version
152 String containing the compiler version as printed by the --version
155 .It Fl -correct , Fl -no-correct
156 When enabled, errors about undefined values try to suggest an existing
157 value via spell checking.
159 DEBUG OPTION. Print the code's intermediate representation before the
160 optimization and finalization passes to stdout before generating the
163 DEBUG OPTION. Print the code's intermediate representation after the
164 optimization and finalization passes to stdout before generating the
165 binary. The instructions will be enumerated, and values will contain a
170 .It Fl W Ns Cm unused-variable
171 Generate a warning about variables which are declared but never used.
172 This can be avoided by adding the
174 keyword in front of the
175 variable declaration. Additionally a complete section of unreferenced
176 variables can be opened using
179 .Ql #pragma noref 0 Ns .
180 .It Fl W Ns Cm used-uninitialized
181 Generate a warning if it is possible that a variable can be used
182 without prior initialization. Note that this warning is not
183 necessarily reliable if the initialization happens only under certain
184 conditions. The other way is
186 possible: that the warning is
188 generated when uninitialized use
191 .It Fl W Ns Cm unknown-control-sequence
192 Generate an error when an unrecognized control sequence in a string is
193 used. Meaning: when there's a character after a backslash in a string
194 which has no known meaning.
195 .It Fl W Ns Cm extensions
196 Warn when using special extensions which are not part of the selected
198 .It Fl W Ns Cm field-redeclared
199 Generally QC compilers ignore redeclaration of fields. Here you can
200 optionally enable a warning.
201 .It Fl W Ns Cm missing-return-values
202 Functions which aren't of type
204 will warn if it possible to
205 reach the end without returning an actual value.
206 .It Fl W Ns Cm invalid-parameter-count
207 Warn about a function call with an invalid number of parameters.
208 .It Fl W Ns Cm local-shadows
209 Warn when a locally declared variable shadows variable.
210 .It Fl W Ns Cm local-constants
211 Warn when the initialization of a local variable turns the variable
212 into a constant. This is default behaviour unless
213 .Fl f Ns Cm initialized-nonconstants
215 .It Fl W Ns Cm void-variables
216 There are only 2 known global variables of type void:
219 .Ql end_sys_fields Ns .
220 Any other void-variable will warn.
221 .It Fl W Ns Cm implicit-function-pointer
222 A global function which is not declared with the
225 expected to have an implementing body, or be a builtin. If neither is
226 the case, it implicitly becomes a function pointer, and a warning is
228 .It Fl W Ns Cm variadic-function
229 Currently there's no way for an in QC implemented function to access
230 variadic parameters. If a function with variadic parameters has an
231 implementing body, a warning will be generated.
232 .It Fl W Ns Cm frame-macros
233 Generate warnings about
235 commands, for instance about
236 duplicate frame definitions.
237 .It Fl W Ns Cm effectless-statement
238 Warn about statements which have no effect. Any expression which does
239 not call a function or assigns a variable.
240 .It Fl W Ns Cm end-sys-fields
243 variable is supposed to be a global variable
246 It is also recognized as a \fIfield\fR but this
247 will generate a warning.
248 .It Fl W Ns Cm assign-function-types
249 Warn when assigning to a function pointer with an unmatching
250 signature. This usually happens in cases like assigning the null
251 function to an entity's .think function pointer.
253 Show warnings created using the preprocessor's '#warning' directive.
254 .It Fl W Ns Cm multifile-if
255 Warn if there's a preprocessor \fI#if\fR spanning across several
257 .It Fl W Ns Cm double-declaration
258 Warn about multiple declarations of globals. This seems pretty common
259 in QC code so you probably do not want this unless you want to clean
261 .It Fl W Ns Cm const-var
262 The combination of \fIconst\fR and \fIvar\fR is not illegal, however
263 different compilers may handle them differently. We were told, the
264 intention is to create a function-pointer which is not assignable.
265 This is exactly how we interpret it. However for this interpretation
268 keyword is considered superfluous (and philosophically
269 wrong), so it is possible to generate a warning about this.
270 .It Fl W Ns Cm multibyte-character
271 Warn about multibyte character constants, they do not work right now.
272 .It Fl W Ns Cm ternary-precedence
273 Warn if a ternary expression which contains a comma operator is used
274 without enclosing parenthesis, since this is most likely not what you
275 actually want. We recommend the
276 .Fl f Ns Cm correct-ternary
278 .It Fl W Ns Cm unknown-pragmas
279 Warn when encountering an unrecognized
282 .It Fl W Ns Cm unreachable-code
283 Warn about unreachable code. That is: code after a return statement,
284 or code after a call to a function marked as 'noreturn'.
286 Enable some warnings added in order to help debugging in the compiler.
288 .It Fl W Ns Cm unknown-attribute
289 Warn on an unknown attribute. The warning will inlclude only the first
290 token inside the enclosing attribute-brackets. This may change when
291 the actual attribute syntax is better defined.
292 .It Fl W Ns Cm reserved-names
293 Warn when using reserved names such as
295 .It Fl W Ns Cm uninitialized-constant
296 Warn about global constants (using the
300 .It Fl W Ns Cm uninitialized-global
301 Warn about global variables with no initializing value. This is off by
302 default, and is added mostly to help find null-values which are
303 supposed to be replaced by the untyped 'nil' constant.
304 .It Fl W Ns Cm different-qualifiers
305 Warn when a variables is redeclared with a different qualifier. For
306 example when redeclaring a variable as \'var\' which was previously
308 .It Fl W Ns Cm different-attributes
309 Similar to the above but for attributes like
310 .Ql [[noreturn]] Ns .
311 .It Fl W Ns Cm deprecated
312 Warn when a function is marked with the attribute
313 "[[deprecated]]". This flag enables a warning on calls to functions
315 .It Fl W Ns Cm parenthesis
316 Warn about possible mistakes caused by missing or wrong parenthesis,
317 like an assignment in an 'if' condition when there's no additional set
318 of parens around the assignment.
322 .It Fl f Ns Cm darkplaces-string-table-bug
323 Add some additional characters to the string table in order to
324 compensate for a wrong boundcheck in some specific version of the
326 .It Fl f Ns Cm adjust-vector-fields
327 When assigning to field pointers of type \fI.vector\fR the common
328 behaviour in compilers like \fIfteqcc\fR is to only assign the
329 x-component of the pointer. This means that you can use the vector as
330 such, but you cannot use its y and z components directly. This flag
331 fixes this behaviour. Before using it make sure your code does not
332 depend on the buggy behaviour.
334 Enable a partially fteqcc-compatible preprocessor. It supports all the
335 features used in the Xonotic codebase. If you need more, write a
337 .It Fl f Ns Cm ftepp-predefs
338 Enable some predefined macros. This only works in combination with
339 \'-fftepp' and is currently not included by '-std=fteqcc'. The
340 following macros will be added:
341 .Bd -literal -offset indent
352 Note that fteqcc also defines
354 which is not implemented yet.
356 .Fl f Ns Cm untyped-nil
357 about gmqcc's alternative to
359 .It Fl f Ns Cm relaxed-switch
360 Allow switch cases to use non constant variables.
361 .It Fl f Ns Cm short-logic
362 Perform early out in logical AND and OR expressions. The final result
363 will be either a 0 or a 1, see the next flag for more possibilities.
364 .It Fl f Ns Cm perl-logic
365 In many languages, logical expressions perform early out in a special
366 way: If the left operand of an AND yeilds true, or the one of an OR
367 yields false, the complete expression evaluates to the right side.
370 evaluates to 5 rather than 1.
371 .It Fl f Ns Cm translatable-strings
372 Enable the underscore intrinsic: Using
373 .Ql _("A string constant")
374 will cause the string immediate to get a name with a "dotranslate_"
375 prefix. The darkplaces engine recognizes these and translates them in
376 a way similar to how gettext works.
377 .It Fl f Ns Cm initialized-nonconstants
378 Don't implicitly convert initialized variables to constants. With this
379 flag, the \fIconst\fR keyword is required to make a constant.
380 .It Fl f Ns Cm assign-function-types
381 If this flag is not set, (and it is set by default in the qcc and
382 fteqcc standards), assigning function pointers of mismatching
383 signatures will result in an error rather than a warning.
385 Produce a linenumber file along with the output .dat file.
386 .It Fl f Ns Cm correct-ternary
387 Use C's operator precedence for ternary expressions. Unless your code
388 depends on fteqcc-compatible behaviour, you'll want to use thi
390 .It Fl f Ns Cm single-vector-defs
391 Normally vectors generate 4 defs, once for the vector, and once for
392 its components with _x, _y, _z suffixes. This option
393 prevents components from being listed.
394 .It Fl f Ns Cm correct-logic
395 Most QC compilers translate
397 directly as an IF on the
398 vector, which means only the x-component is checked. This option causes
399 vectors to be cast to actual booleans via a NOT_V and, if necessary, a
401 .Bd -literal -offset indent
402 if (a_vector) // becomes
405 a = a_vector && a_float // becomes
406 a = !!a_vector && a_float
408 .It Fl f Ns Cm true-empty-strings
409 An empty string is considered to be true everywhere. The NOT_S
410 instruction usually considers an empty string to be false, this option
411 effectively causes the unary not in strings to use NOT_F instead.
412 .It Fl f Ns Cm false-empty-strings
413 An empty string is considered to be false everywhere. This means loops
414 and if statements which depend on a string will perform a NOT_S
415 instruction on the string before using it.
417 Enable utf8 characters. This allows utf-8 encoded character constants,
418 and escape sequence codepoints in the valid utf-8 range. Effectively
419 enabling escape sequences like '\\{x2211}'.
420 .It Fl f Ns Cm bail-on-werror
421 When a warning is treated as an error, and this option is set (which
422 it is by default), it is like any other error and will cause
423 compilation to stop. When disabling this flag by using
424 \-fno-bail-on-werror, compilation will continue until the end, but no
425 output is generated. Instead the first such error message's context is
427 .It Fl f Ns Cm loop-labels
428 Allow loops to be labeled, and allow 'break' and 'continue' to take an
429 optional label to decide which loop to actually jump out of or
431 .Bd -literal -offset indent
432 for :outer (i = 0; i < n; ++i) {
440 .It Fl f Ns Cm untyped-nil
441 Adds a global named 'nil' which is of no type and can be assigned to
442 anything. No typechecking will be performed on assignments. Assigning
443 to it is forbidden, using it in any other kind of expression is also
446 Note that this is different from fteqcc's __NULL__: In fteqcc,
447 __NULL__ maps to the integer written as '0i'. It's can be assigned to
448 function pointers and integers, but it'll error about invalid
449 instructions when assigning it to floats without enabling the FTE
450 instruction set. There's also a bug which allows it to be assigned to
451 vectors, for which the source will be the global at offset 0, meaning
452 the vector's y and z components will contain the OFS_RETURN x and y
455 In that gmqcc the nil global is an actual global filled with zeroes,
456 and can be assigned to anything including fields, vectors or function
457 pointers, and they end up becoming zeroed.
458 .It Fl f Ns Cm permissive
459 Various effects, usually to weaken some conditions.
460 .Bl -tag -width indent -offset indent
461 .It with Fl f Ns Cm untyped-nil
462 Allow local variables named
464 (This will not allow declaring a global of that name.)
466 .It Fl f Ns Cm variadic-args
467 Allow variadic parameters to be accessed by QC code. This can be
468 achieved via the '...' function, which takes a parameter index and a
472 .Bd -literal -offset indent
473 void vafunc(string...count) {
475 for (i = 0; i < count; ++i)
476 print(...(i, string), "\\n");
479 .It Fl f Ns Cm legacy-vector-maths
480 Most Quake VMs, including the one from FTEQW or up till recently
481 Darkplaces, do not cope well with vector instructions with overlapping
482 input and output. This option will avoid producing such code.
486 .It Fl O Ns Cm peephole
487 Some general peephole optimizations. For instance the code `a = b + c`
488 typically generates 2 instructions, an ADD and a STORE. This
489 optimization removes the STORE and lets the ADD write directly into A.
490 .It Fl O Ns Cm tail-recursion
491 Tail recursive function calls will be turned into loops to avoid the
492 overhead of the CALL and RETURN instructions.
493 .It Fl O Ns Cm overlap-locals
494 Make all functions which use neither local arrays nor have locals
495 which are seen as possibly uninitialized use the same local section.
496 This should be pretty safe compared to other compilers which do not
497 check for uninitialized values properly. The problem is that there's
498 QC code out there which really doesn't initialize some values. This is
499 fine as long as this kind of optimization isn't used, but also, only
500 as long as the functions cannot be called in a recursive manner. Since
501 it's hard to know whether or not an array is actually fully
502 initialized, especially when initializing it via a loop, we assume
503 functions with arrays to be too dangerous for this optimization.
504 .It Fl O Ns Cm local-temps
505 This promotes locally declared variables to "temps". Meaning when a
506 temporary result of an operation has to be stored somewhere, a local
507 variable which is not 'alive' at that point can be used to keep the
508 result. This can reduce the size of the global section.
509 This will not have declared variables overlap, even if it was
511 .It Fl O Ns Cm global-temps
512 Causes temporary values which do not need to be backed up on a CALL to
513 not be stored in the function's locals-area. With this, a CALL to a
514 function may need to back up fewer values and thus execute faster.
515 .It Fl O Ns Cm strip-constant-names
516 Don't generate defs for immediate values or even declared constants.
517 Meaning variables which are implicitly constant or qualified as such
518 using the 'const' keyword.
519 .It Fl O Ns Cm overlap-strings
520 Aggressively reuse strings in the string section. When a string should
521 be added which is the trailing substring of an already existing
522 string, the existing string's tail will be returned instead of the new
525 For example the following code will only generate 1 string:
526 .Bd -literal -offset indent
527 print("Hell you!\\n");
528 print("you!\\n"); // trailing substring of "Hello you!\\n"
531 There's however one limitation. Strings are still processed in order,
532 so if the above print statements were reversed, this optimization
534 .It Fl O Ns Cm call-stores
535 By default, all parameters of a CALL are copied into the
536 parameter-globals right before the CALL instructions. This is the
537 easiest and safest way to translate calls, but also adds a lot of
538 unnecessary copying and unnecessary temporary values. This
539 optimization makes operations which are used as a parameter evaluate
540 directly into the parameter-global if that is possible, which is when
541 there's no other CALL instruction in between.
542 .It Fl O Ns Cm void-return
543 Usually an empty RETURN instruction is added to the end of a void
544 typed function. However, additionally after every function a DONE
545 instruction is added for several reasons. (For example the qcvm's
546 disassemble switch uses it to know when the function ends.). This
547 optimization replaces that last RETURN with DONE rather than adding
548 the DONE additionally.
549 .It Fl O Ns Cm vector-components
550 Because traditional QC code doesn't allow you to access individual
551 vector components of a computed vector without storing it in a local
552 first, sometimes people multiply it by a constant like
555 in this case, the y component of a vector. This optimization will turn
556 such a multiplication into a direct component access. If the factor is
557 anything other than 1, a float-multiplication will be added, which is
558 still faster than a vector multiplication.
561 The configuration file is similar to regular .ini files. Comments
562 start with hashtags or semicolons, sections are written in square
563 brackets and in each section there can be arbitrary many key-value
566 There are 3 sections currently:
569 .Ql optimizations Ns .
570 They contain a list of boolean values of the form
573 .Ql VARNAME = false Ns .
574 The variable names are the same as for the
579 flag written with only capital letters and
580 dashes replaced by underscores.
583 .Bd -literal -offset indent
584 # a GMQCC configuration file
587 ADJUST_VECTOR_FIELDS = false
591 UNUSED_VARIABLE = false
592 USED_UNINITIALIZED = true
596 TAIL_RECURSION = true
600 .It gmqcc.ini.example
601 A documented example for a gmqcc.ini file.
606 See <http://graphitemaster.github.com/gmqcc>.
608 Currently the '-fftepp-predefs' flag is not included by '-std=fteqcc',
609 partially because it is not entirely conformant to fteqcc.
611 Please report bugs on <http://github.com/graphitemaster/gmqcc/issues>,
612 or see <http://graphitemaster.github.com/gmqcc> on how to contact us.