1 .\" Process with groff -man -Tascii file.3
2 .TH GMQCC 1 2012-07-12 "" "gmqcc Manual"
4 gmqcc \- A Quake C compiler built from the NIH realm of sarcastic wit
7 [\fIOPTIONS\fR] [\fIfiles...\fR]
9 Traditionally, a QC compiler reads the file \fIprogs.src\fR which
10 in its first line contains the output filename, and the rest is a
11 list of QC source files that are to be compiled in order.
12 \fBgmqcc\fR optionally takes options to specify the output and
13 input files on the commandline, and also accepts assembly files.
15 \fBgmqcc\fR mostly tries to mimic gcc's commandline handling, though
16 there are also traditional long-options available.
19 Show a usage message and exit.
22 Turn on some compiler debugging mechanisms.
25 Turn on compiler mem-check. (Shows allocations and checks for leaks.)
27 .BI "-o, --output=" filename
28 Specify the output filename. Defaults to progs.dat. This will overwrite
29 the output file listed in a \fIprogs.src\fR file in case such a file is used.
32 Specify the optimization level
35 Highest optimization level
37 Default optimization level
39 Minimal optimization level
41 Disable optimization entirely
44 .BI "-O" name "\fR, " "" -Ono- name
45 Enable or disable a specific optimization. Note that these options
46 must be used after setting the optimization level, otherwise they'll
50 List all possible optimizations and the optimization level they're
54 Be less verbose. In particular removes the messages about which files
55 are being processed, and which compilation mode is being used, and
56 some others. Warnings and errors will of course still be displayed.
58 .BI -W warning "\fR, " "" -Wno- warning
59 Enable or disable a warning.
62 Enable almost all warnings. Overrides preceding -W parameters.
64 The following warnings will \fBnot\fR be anbled:
67 -Wuninitialized-global
71 .BR -Werror ", " -Wno-error
72 Controls whether or not all warnings should be treated as errors.
74 .BI -Werror- warning "\fR, " "" -Wno-error- warning
75 Controls whether a specific warning should be an error.
78 List all possible warn flags.
80 .BI -f flag "\fR, " "" -fno- flag
81 Enable or disable a specific compile flag. See the list of flags
85 List all possible compile flags.
88 Disables colored output
91 Use an ini file to read all the -O, -W and -f flag from. See the
92 CONFIG section about the file format.
95 Redirects standard output to a \fIfile\fR
98 Redirects standard error to a \fIfile\fR
101 Use the specified standard for parsing QC code. The following standards
103 .IR gmqcc , qcc , fteqcc
104 Selecting a standard also implies some -f options and behaves as if
105 those options have been written right after the -std option, meaning
106 if you changed them before the -std option, you're now overwriting
109 .BR -std=gmqcc " includes:"
112 -fadjust-vector-fields
116 -finitialized-nonconstants
117 -ftranslatable-strings
118 -f\fIno-\fRfalse-empty-strings
119 -Winvalid-parameter-count
120 -Wmissing-returnvalues
121 -fcorrect-ternary (cannot be turned off)
125 .BR -std=qcc " includes:"
128 -fassign-function-types
129 -f\fIno-\fRadjust-vector-fields
133 .BR -std=fteqcc " includes:"
137 -ftranslatable-strings
138 -fassign-function-types
140 -f\fIno-\fRadjust-vector-fields
141 -f\fIno-\fRcorrect-ternary
146 Adds compiler information to the generated binary file. Currently
147 this includes the following globals:
149 .IP "reserved:version"
150 String containing the compiler version as printed by the --version
154 .BR "--correct" ", " "--no-correct"
155 When enabled, errors about undefined values try to suggest an existing
156 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
164 DEBUG OPTION. Print the code's intermediate representation after the
165 optimization and finalization passes to stdout before generating the
166 binary. The instructions will be enumerated, and values will contain a
171 Generate a warning about variables which are declared but never used.
172 This can be avoided by adding the \fInoref\fR keyword in front of the
173 variable declaration. Additionally a complete section of unreferenced
174 variables can be opened using \fI#pragma noref 1\fR, and closed via
175 \fI#pragma noref 0\fR.
177 .B -Wused-uninitialized
178 Generate a warning if it is possible that a variable can be used
179 without prior initialization. Note that this warning is not
180 necessarily reliable if the initialization happens only under certain
181 conditions. The other way is \fInot\fR possible: that the warning is
182 \fInot\fR generated when uninitialized use \fIis possible\fR.
184 .B -Wunknown-control-sequence
185 Generate an error when an unrecognized control sequence in a string is
186 used. Meaning: when there's a character after a backslash in a string
187 which has no known meaning.
190 Warn when using special extensions which are not part of the selected
193 .B -Wfield-redeclared
194 Generally QC compilers ignore redeclaration of fields. Here you can
195 optionally enable a warning.
197 .B -Wmissing-return-values
198 Functions which aren't of type \fIvoid\fR will warn if it possible to
199 reach the end without returning an actual value.
201 .B -Winvalid-parameter-count
202 Warn about a function call with an invalid number of parameters.
205 Warn when a locally declared variable shadows variable.
208 Warn when the initialization of a local variable turns the variable
209 into a constant. This is default behaviour unless
210 \fI-finitialized-nonconstants\fR is used.
213 There are only 2 known global variables of type void: end_sys_globals
214 and end_sys_fields. Any other void-variable will warn.
216 .B -Wimplicit-function-pointer
217 A global function which is not declared with the \fIvar\fR keyword is
218 expected to have an implementing body, or be a builtin. If neither is
219 the case, it implicitly becomes a function pointer, and a warning is
222 .B -Wvariadic-function
223 Currently there's no way for an in QC implemented function to access
224 variadic parameters. If a function with variadic parameters has an
225 implementing body, a warning will be generated.
228 Generate warnings about \fI$frame\fR commands, for instance about
229 duplicate frame definitions.
231 .B -Weffectless-statement
232 Warn about statements which have no effect. Any expression which does
233 not call a function or assigns a variable.
236 The \fIend_sys_fields\fR variable is supposed to be a global variable
237 of type \fIvoid\fR. It is also recognized as a \fIfield\fR but this
238 will generate a warning.
240 .B -Wassign-function-types
241 Warn when assigning to a function pointer with an unmatching
242 signature. This usually happens in cases like assigning the null
243 function to an entity's .think function pointer.
246 Enable warnings coming from the preprocessor. Like duplicate macro
247 declarations. This warning triggers when there's a problem with the
248 way the preprocessor has been used, it will \fBnot\fR affect warnings
249 generated with the '#warning' directive. See -Wcpp.
252 Show warnings created using the preprocessor's '#warning' directive.
255 Warn if there's a preprocessor \fI#if\fR spanning across several
258 .B -Wdouble-declaration
259 Warn about multiple declarations of globals. This seems pretty common
260 in QC code so you probably do not want this unless you want to clean
264 The combination of \fIconst\fR and \fIvar\fR is not illegal, however
265 different compilers may handle them differently. We were told, the
266 intention is to create a function-pointer which is not assignable.
267 This is exactly how we interpret it. However for this interpretation
268 the \fIvar\fR keyword is considered superfluous (and philosophically
269 wrong), so it is possible to generate a warning about this.
271 .B -Wmultibyte-character
272 Warn about multibyte character constants, they do not work right now.
274 .B -Wternary-precedence
275 Warn if a ternary expression which contains a comma operator is used
276 without enclosing parenthesis, since this is most likely not what you
277 actually want. We recommend the \fI-fcorrect-ternary\fR option.
280 Warn when encountering an unrecognized \fI#pragma\fR line.
282 .B -Wunreachable-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'.
287 Enable some warnings added in order to help debugging in the compiler.
289 .B -Wunknown-attribute
290 Warn on an unknown attribute. The warning will inlclude only the first
291 token inside the enclosing attribute-brackets. This may change when
292 the actual attribute syntax is better defined.
295 Warn when using reserved names such as 'nil'.
297 .B -Wuninitialized-constant
298 Warn about global constants (using the 'const' keyword) with no
301 .B -Wuninitialized-global
302 Warn about global variables with no initializing value. This is off by
303 default, and is added mostly to help find null-values which are
304 supposed to be replaced by the untyped 'nil' constant.
306 .B -Wdifferent-qualifiers
307 Warn when a variables is redeclared with a different qualifier. For
308 example when redeclaring a variable as \'var\' which was previously
311 .B -Wdifferent-attributes
312 Similar to the above but for attributes like "[[noreturn]]".
315 Warn when a function is marked with the attribute
316 "[[deprecated]]". This flag enables a warning on calls to functions
320 Warn about possible mistakes caused by missing or wrong parenthesis,
321 like an assignment in an 'if' condition when there's no additional set
322 of parens around the assignment.
325 .B -fdarkplaces-string-table-bug
326 Add some additional characters to the string table in order to
327 compensate for a wrong boundcheck in some specific version of the
330 .B -fadjust-vector-fields
331 When assigning to field pointers of type \fI.vector\fR the common
332 behaviour in compilers like \fIfteqcc\fR is to only assign the
333 x-component of the pointer. This means that you can use the vector as
334 such, but you cannot use its y and z components directly. This flag
335 fixes this behaviour. Before using it make sure your code does not
336 depend on the buggy behaviour.
339 Enable a partially fteqcc-compatible preprocessor. It supports all the
340 features used in the Xonotic codebase. If you need more, write a
344 Enable some predefined macros. This only works in combination with
345 \'-fftepp' and is currently not included by '-std=fteqcc'. The
346 following macros will be added:
359 Note that fteqcc also defines __NULL__ which is not implemented yet.
360 (See -funtyped-nil about gmqcc's alternative to __NULL__).
363 Allow switch cases to use non constant variables.
366 Perform early out in logical AND and OR expressions. The final result
367 will be either a 0 or a 1, see the next flag for more possibilities.
370 In many languages, logical expressions perform early out in a special
371 way: If the left operand of an AND yeilds true, or the one of an OR
372 yields false, the complete expression evaluates to the right side.
373 Thus \fItrue && 5\fI evaluates to 5 rather than 1.
375 .B -ftranslatable-strings
376 Enable the underscore intrinsic: Using \fI_("A string constant")\fR
377 will cause the string immediate to get a name with a "dotranslate_"
378 prefix. The darkplaces engine recognizes these and translates them in
379 a way similar to how gettext works.
381 .B -finitialized-nonconstants
382 Don't implicitly convert initialized variables to constants. With this
383 flag, the \fIconst\fR keyword is required to make a constant.
385 .B -fassign-function-types
386 If this flag is not set, (and it is set by default in the qcc and
387 fteqcc standards), assigning function pointers of mismatching
388 signatures will result in an error rather than a warning.
391 Produce a linenumber file along with the output .dat file.
394 Use C's operator precedence for ternary expressions. Unless your code
395 depends on fteqcc-compatible behaviour, you'll want to use thi
398 .B -fsingle-vector-defs
399 Normally vectors generate 4 defs, once for the vector, and once for
400 its components with _x, _y, _z suffixes. This option
401 prevents components from being listed.
404 Most QC compilers translate if(a_vector) directly as an IF on the
405 vector, which means only the x-component is checked. This causes
406 vectors to be cast to actual booleans via a NOT_V and, if necessary, a
410 if (a_vector) // becomes
413 a = a_vector && a_float // becomes
414 a = !!a_vector && a_float
418 .B -ftrue-empty-strings
419 An empty string is considered to be true everywhere. The NOT_S
420 instruction usually considers an empty string to be false, this option
421 effectively causes the unary not in strings to use NOT_F instead.
423 .B -ffalse-empty-strings
424 An empty string is considered to be false everywhere. This means loops
425 and if statements which depend on a string will perform a NOT_S
426 instruction on the string before using it.
429 Enable utf8 characters. This allows utf-8 encoded character constants,
430 and escape sequence codepoints in the valid utf-8 range. Effectively
431 enabling escape sequences like '\\{x2211}'.
434 When a warning is treated as an error, and this option is set (which
435 it is by default), it is like any other error and will cause
436 compilation to stop. When disabling this flag by using
437 \-fno-bail-on-werror, compilation will continue until the end, but no
438 output is generated. Instead the first such error message's context is
442 Allow loops to be labeled, and allow 'break' and 'continue' to take an
443 optional label to decide which loop to actually jump out of or
448 for :outer (i = 0; i < n; ++i) {
459 Adds a global named 'nil' which is of no type and can be assigned to
460 anything. No typechecking will be performed on assignments. Assigning
461 to it is forbidden, using it in any other kind of expression is also
464 Note that this is different from fteqcc's __NULL__: In fteqcc,
465 __NULL__ maps to the integer written as '0i'. It's can be assigned to
466 function pointers and integers, but it'll error about invalid
467 instructions when assigning it to floats without enabling the FTE
468 instruction set. There's also a bug which allows it to be assigned to
469 vectors, for which the source will be the global at offset 0, meaning
470 the vector's y and z components will contain the OFS_RETURN x and y
473 In that gmqcc the nil global is an actual global filled with zeroes,
474 and can be assigned to anything including fields, vectors or function
475 pointers, and they end up becoming zeroed.
478 Various effects, usually to weaken some conditions.
480 .IP "with -funtyped-nil"
481 Allow local variables named 'nil'. (This will not allow declaring a
482 global of that name.)
486 Allow variadic parameters to be accessed by QC code. This can be
487 achieved via the '...' function, which takes a parameter index and a
494 void vafunc(string...count) {
496 for (i = 0; i < count; ++i)
497 print(...(i, string), "\\n");
504 Some general peephole optimizations. For instance the code `a = b + c`
505 typically generates 2 instructions, an ADD and a STORE. This
506 optimization removes the STORE and lets the ADD write directly into A.
509 Tail recursive function calls will be turned into loops to avoid the
510 overhead of the CALL and RETURN instructions.
513 Make all functions which use neither local arrays nor have locals
514 which are seen as possibly uninitialized use the same local section.
515 This should be pretty safe compared to other compilers which do not
516 check for uninitialized values properly. The problem is that there's
517 QC code out there which really doesn't initialize some values. This is
518 fine as long as this kind of optimization isn't used, but also, only
519 as long as the functions cannot be called in a recursive manner. Since
520 it's hard to know whether or not an array is actually fully
521 initialized, especially when initializing it via a loop, we assume
522 functions with arrays to be too dangerous for this optimization.
525 This promotes locally declared variables to "temps". Meaning when a
526 temporary result of an operation has to be stored somewhere, a local
527 variable which is not 'alive' at that point can be used to keep the
528 result. This can reduce the size of the global section.
529 This will not have declared variables overlap, even if it was
533 Causes temporary values which do not need to be backed up on a CALL to
534 not be stored in the function's locals-area. With this, a CALL to a
535 function may need to back up fewer values and thus execute faster.
537 .B -Ostrip-constant-names
538 Don't generate defs for immediate values or even declared constants.
539 Meaning variables which are implicitly constant or qualified as such
540 using the 'const' keyword.
543 Aggressively reuse strings in the string section. When a string should
544 be added which is the trailing substring of an already existing
545 string, the existing string's tail will be returned instead of the new
548 For example the following code will only generate 1 string:
552 print("Hell you!\\n");
553 print("you!\\n"); // trailing substring of "Hello you!\\n"
556 There's however one limitation. Strings are still processed in order,
557 so if the above print statements were reversed, this optimization
561 By default, all parameters of a CALL are copied into the
562 parameter-globals right before the CALL instructions. This is the
563 easiest and safest way to translate calls, but also adds a lot of
564 unnecessary copying and unnecessary temporary values. This
565 optimization makes operations which are used as a parameter evaluate
566 directly into the parameter-global if that is possible, which is when
567 there's no other CALL instruction in between.
570 Usually an empty RETURN instruction is added to the end of a void
571 typed function. However, additionally after every function a DONE
572 instruction is added for several reasons. (For example the qcvm's
573 disassemble switch uses it to know when the function ends.). This
574 optimization replaces that last RETURN with DONE rather than adding
575 the DONE additionally.
577 .B -Ovector-components
578 Because traditional QC code doesn't allow you to access individual
579 vector components of a computed vector without storing it in a local
580 first, sometimes people multiply it by a constant like '0 1 0' to get,
581 in this case, the y component of a vector. This optimization will turn
582 such a multiplication into a direct component access. If the factor is
583 anything other than 1, a float-multiplication will be added, which is
584 still faster than a vector multiplication.
586 The configuration file is similar to regular .ini files. Comments
587 start with hashtags or semicolons, sections are written in square
588 brackets and in each section there can be arbitrary many key-value
591 There are 3 sections currently:
592 .IR flags ", " warnings ", and " optimizations .
593 They contain a list of boolean values of the form `VARNAME = true` or
594 `VARNAME = false`. The variable names are the same as for the
595 corresponding -W, -f or -O flag written with only capital letters and
596 dashes replaced by underscores.
601 # a GMQCC configuration file
604 ADJUST_VECTOR_FIELDS = false
608 UNUSED_VARIABLE = false
609 USED_UNINITIALIZED = true
613 TAIL_RECURSION = true
617 Currently the '-fftepp-predefs' flag is not included by '-std=fteqcc',
618 partially because it is not entirely conformant to fteqcc.
621 Please report bugs on <http://github.com/graphitemaster/gmqcc/issues>,
622 or see <http://graphitemaster.github.com/gmqcc> on how to contact us.
626 A documented example for a gmqcc.ini file.
630 See <http://graphitemaster.github.com/gmqcc>.