]> git.xonotic.org Git - xonotic/gmqcc.git/blob - doc/gmqcc.1
manpage: -E was missing all that time in there
[xonotic/gmqcc.git] / doc / gmqcc.1
1 .\" Process with groff -man -Tascii file.3
2 .TH GMQCC 1 2012-07-12 "" "gmqcc Manual"
3 .SH NAME
4 gmqcc \- A Quake C compiler built from the NIH realm of sarcastic wit
5 .SH SYNOPSIS
6 .B gmqcc
7 [\fIOPTIONS\fR] [\fIfiles...\fR]
8 .SH DESCRIPTION
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.
14 .SH OPTIONS
15 \fBgmqcc\fR mostly tries to mimic gcc's commandline handling, though
16 there are also traditional long-options available.
17 .TP
18 .B "-h, --help"
19 Show a usage message and exit.
20 .TP
21 .B "-debug"
22 Turn on some compiler debugging mechanisms.
23 .TP
24 .B "-memchk"
25 Turn on compiler mem-check. (Shows allocations and checks for leaks.)
26 .TP
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.
30 .TP
31 .BI "-O" number
32 Specify the optimization level
33 .RS
34 .IP 3
35 Highest optimization level
36 .IP 2
37 Default optimization level
38 .IP 1
39 Minimal optimization level
40 .IP 0
41 Disable optimization entirely
42 .RE
43 .TP
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
47 be overwritten.
48 .TP
49 .B -Ohelp
50 List all possible optimizations and the optimization level they're
51 activated at.
52 .TP
53 .BR -q ", " --quiet
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.
57 .TP
58 .B "-E"
59 Run only the preprocessor as if -fftepp was used and print the
60 preprocessed code to stdout.
61 .TP
62 .BI -W warning "\fR, " "" -Wno- warning
63 Enable or disable a warning.
64 .TP
65 .B -Wall
66 Enable almost all warnings. Overrides preceding -W parameters.
67 .sp
68 The following warnings will \fBnot\fR be anbled:
69 .in +4
70 .nf
71 -Wuninitialized-global
72 .fi
73 .in
74 .TP
75 .BR -Werror ", " -Wno-error
76 Controls whether or not all warnings should be treated as errors.
77 .TP
78 .BI -Werror- warning "\fR, " "" -Wno-error- warning
79 Controls whether a specific warning should be an error.
80 .TP
81 .B -Whelp
82 List all possible warn flags.
83 .TP
84 .BI -f flag "\fR, " "" -fno- flag
85 Enable or disable a specific compile flag. See the list of flags
86 below.
87 .TP
88 .B -fhelp
89 List all possible compile flags.
90 .TP
91 .B -nocolor
92 Disables colored output
93 .TP
94 .BI -config= file
95 Use an ini file to read all the -O, -W and -f flag from. See the
96 CONFIG section about the file format.
97 .TP
98 .BI "-redirout=" file
99 Redirects standard output to a \fIfile\fR
100 .TP
101 .BI "-redirerr=" file
102 Redirects standard error to a \fIfile\fR
103 .TP
104 .BI "-std=" standard
105 Use the specified standard for parsing QC code. The following standards
106 are available:
107 .IR gmqcc , qcc , fteqcc
108 Selecting a standard also implies some -f options and behaves as if
109 those options have been written right after the -std option, meaning
110 if you changed them before the -std option, you're now overwriting
111 them.
112 .sp
113 .BR -std=gmqcc " includes:"
114 .in +4
115 .nf
116 -fadjust-vector-fields
117 -fcorrect-logic
118 -ftrue-empty-strings
119 -floop-labels
120 -finitialized-nonconstants
121 -ftranslatable-strings
122 -f\fIno-\fRfalse-empty-strings
123 -Winvalid-parameter-count
124 -Wmissing-returnvalues
125 -fcorrect-ternary (cannot be turned off)
126 .fi
127 .in
128 .sp
129 .BR -std=qcc " includes:"
130 .in +4
131 .nf
132 -fassign-function-types
133 -f\fIno-\fRadjust-vector-fields
134 .fi
135 .in
136 .sp
137 .BR -std=fteqcc " includes:"
138 .in +4
139 .nf
140 -fftepp
141 -ftranslatable-strings
142 -fassign-function-types
143 -Wternary-precedence
144 -f\fIno-\fRadjust-vector-fields
145 -f\fIno-\fRcorrect-ternary
146 .fi
147 .in
148 .TP
149 .B "--add-info"
150 Adds compiler information to the generated binary file. Currently
151 this includes the following globals:
152 .RS
153 .IP "reserved:version"
154 String containing the compiler version as printed by the --version
155 parameter.
156 .RE
157 .TP
158 .BR "--correct" ", " "--no-correct"
159 When enabled, errors about undefined values try to suggest an existing
160 value via spell checking.
161 .TP
162 .B "-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 .TP
167 .B "-dumpfin"
168 DEBUG OPTION. Print the code's intermediate representation after the
169 optimization and finalization passes to stdout before generating the
170 binary. The instructions will be enumerated, and values will contain a
171 list of liferanges.
172 .SH COMPILE WARNINGS
173 .TP
174 .B -Wunused-variable
175 Generate a warning about variables which are declared but never used.
176 This can be avoided by adding the \fInoref\fR keyword in front of the
177 variable declaration. Additionally a complete section of unreferenced
178 variables can be opened using \fI#pragma noref 1\fR, and closed via
179 \fI#pragma noref 0\fR.
180 .TP
181 .B -Wused-uninitialized
182 Generate a warning if it is possible that a variable can be used
183 without prior initialization. Note that this warning is not
184 necessarily reliable if the initialization happens only under certain
185 conditions. The other way is \fInot\fR possible: that the warning is
186 \fInot\fR generated when uninitialized use \fIis possible\fR.
187 .TP
188 .B -Wunknown-control-sequence
189 Generate an error when an unrecognized control sequence in a string is
190 used. Meaning: when there's a character after a backslash in a string
191 which has no known meaning.
192 .TP
193 .B -Wextensions
194 Warn when using special extensions which are not part of the selected
195 standard.
196 .TP
197 .B -Wfield-redeclared
198 Generally QC compilers ignore redeclaration of fields. Here you can
199 optionally enable a warning.
200 .TP
201 .B -Wmissing-return-values
202 Functions which aren't of type \fIvoid\fR will warn if it possible to
203 reach the end without returning an actual value.
204 .TP
205 .B -Winvalid-parameter-count
206 Warn about a function call with an invalid number of parameters.
207 .TP
208 .B -Wlocal-shadows
209 Warn when a locally declared variable shadows variable.
210 .TP
211 .B -Wlocal-constants
212 Warn when the initialization of a local variable turns the variable
213 into a constant. This is default behaviour unless
214 \fI-finitialized-nonconstants\fR is used.
215 .TP
216 .B -Wvoid-variables
217 There are only 2 known global variables of type void: end_sys_globals
218 and end_sys_fields. Any other void-variable will warn.
219 .TP
220 .B -Wimplicit-function-pointer
221 A global function which is not declared with the \fIvar\fR keyword is
222 expected to have an implementing body, or be a builtin. If neither is
223 the case, it implicitly becomes a function pointer, and a warning is
224 generated.
225 .TP
226 .B -Wvariadic-function
227 Currently there's no way for an in QC implemented function to access
228 variadic parameters. If a function with variadic parameters has an
229 implementing body, a warning will be generated.
230 .TP
231 .B -Wframe-macros
232 Generate warnings about \fI$frame\fR commands, for instance about
233 duplicate frame definitions.
234 .TP
235 .B -Weffectless-statement
236 Warn about statements which have no effect. Any expression which does
237 not call a function or assigns a variable.
238 .TP
239 .B -Wend-sys-fields
240 The \fIend_sys_fields\fR variable is supposed to be a global variable
241 of type \fIvoid\fR. It is also recognized as a \fIfield\fR but this
242 will generate a warning.
243 .TP
244 .B -Wassign-function-types
245 Warn when assigning to a function pointer with an unmatching
246 signature. This usually happens in cases like assigning the null
247 function to an entity's .think function pointer.
248 .TP
249 .B -Wpreprocessor
250 Enable warnings coming from the preprocessor. Like duplicate macro
251 declarations. This warning triggers when there's a problem with the
252 way the preprocessor has been used, it will \fBnot\fR affect warnings
253 generated with the '#warning' directive. See -Wcpp.
254 .TP
255 .B -Wcpp
256 Show warnings created using the preprocessor's '#warning' directive.
257 .TP
258 .B -Wmultifile-if
259 Warn if there's a preprocessor \fI#if\fR spanning across several
260 files.
261 .TP
262 .B -Wdouble-declaration
263 Warn about multiple declarations of globals. This seems pretty common
264 in QC code so you probably do not want this unless you want to clean
265 up your code.
266 .TP
267 .B -Wconst-var
268 The combination of \fIconst\fR and \fIvar\fR is not illegal, however
269 different compilers may handle them differently. We were told, the
270 intention is to create a function-pointer which is not assignable.
271 This is exactly how we interpret it. However for this interpretation
272 the \fIvar\fR keyword is considered superfluous (and philosophically
273 wrong), so it is possible to generate a warning about this.
274 .TP
275 .B -Wmultibyte-character
276 Warn about multibyte character constants, they do not work right now.
277 .TP
278 .B -Wternary-precedence
279 Warn if a ternary expression which contains a comma operator is used
280 without enclosing parenthesis, since this is most likely not what you
281 actually want. We recommend the \fI-fcorrect-ternary\fR option.
282 .TP
283 .B -Wunknown-pragmas
284 Warn when encountering an unrecognized \fI#pragma\fR line.
285 .TP
286 .B -Wunreachable-code
287 Warn about unreachable code. That is: code after a return statement,
288 or code after a call to a function marked as 'noreturn'.
289 .TP
290 .B -Wdebug
291 Enable some warnings added in order to help debugging in the compiler.
292 You won't need this.
293 .B -Wunknown-attribute
294 Warn on an unknown attribute. The warning will inlclude only the first
295 token inside the enclosing attribute-brackets. This may change when
296 the actual attribute syntax is better defined.
297 .TP
298 .B -Wreserved-names
299 Warn when using reserved names such as 'nil'.
300 .TP
301 .B -Wuninitialized-constant
302 Warn about global constants (using the 'const' keyword) with no
303 assigned value.
304 .TP
305 .B -Wuninitialized-global
306 Warn about global variables with no initializing value. This is off by
307 default, and is added mostly to help find null-values which are
308 supposed to be replaced by the untyped 'nil' constant.
309 .TP
310 .B -Wdifferent-qualifiers
311 Warn when a variables is redeclared with a different qualifier. For
312 example when redeclaring a variable as \'var\' which was previously
313 marked \'const\'.
314 .TP
315 .B -Wdifferent-attributes
316 Similar to the above but for attributes like "[[noreturn]]".
317 .TP
318 .B -Wdeprecated
319 Warn when a function is marked with the attribute
320 "[[deprecated]]". This flag enables a warning on calls to functions
321 marked as such.
322 .TP
323 .B -Wparenthesis
324 Warn about possible mistakes caused by missing or wrong parenthesis,
325 like an assignment in an 'if' condition when there's no additional set
326 of parens around the assignment.
327 .SH COMPILE FLAGS
328 .TP
329 .B -fdarkplaces-string-table-bug
330 Add some additional characters to the string table in order to
331 compensate for a wrong boundcheck in some specific version of the
332 darkplaces engine.
333 .TP
334 .B -fadjust-vector-fields
335 When assigning to field pointers of type \fI.vector\fR the common
336 behaviour in compilers like \fIfteqcc\fR is to only assign the
337 x-component of the pointer. This means that you can use the vector as
338 such, but you cannot use its y and z components directly. This flag
339 fixes this behaviour. Before using it make sure your code does not
340 depend on the buggy behaviour.
341 .TP
342 .B -fftepp
343 Enable a partially fteqcc-compatible preprocessor. It supports all the
344 features used in the Xonotic codebase. If you need more, write a
345 ticket.
346 .TP
347 .B -fftepp-predefs
348 Enable some predefined macros. This only works in combination with
349 \'-fftepp' and is currently not included by '-std=fteqcc'. The
350 following macros will be added:
351 .in +4
352 .nf
353 __LINE__
354 __FILE__
355 __COUNTER__
356 __COUNTER_LAST__
357 __RANDOM__
358 __RANDOM_LAST__
359 __DATE__
360 __TIME__
361 .fi
362 .in
363 Note that fteqcc also defines __NULL__ which is not implemented yet.
364 (See -funtyped-nil about gmqcc's alternative to __NULL__).
365 .TP
366 .B -frelaxed-switch
367 Allow switch cases to use non constant variables.
368 .TP
369 .B -fshort-logic
370 Perform early out in logical AND and OR expressions. The final result
371 will be either a 0 or a 1, see the next flag for more possibilities.
372 .TP
373 .B -fperl-logic
374 In many languages, logical expressions perform early out in a special
375 way: If the left operand of an AND yeilds true, or the one of an OR
376 yields false, the complete expression evaluates to the right side.
377 Thus \fItrue && 5\fI evaluates to 5 rather than 1.
378 .TP
379 .B -ftranslatable-strings
380 Enable the underscore intrinsic: Using \fI_("A string constant")\fR
381 will cause the string immediate to get a name with a "dotranslate_"
382 prefix. The darkplaces engine recognizes these and translates them in
383 a way similar to how gettext works.
384 .TP
385 .B -finitialized-nonconstants
386 Don't implicitly convert initialized variables to constants. With this
387 flag, the \fIconst\fR keyword is required to make a constant.
388 .TP
389 .B -fassign-function-types
390 If this flag is not set, (and it is set by default in the qcc and
391 fteqcc standards), assigning function pointers of mismatching
392 signatures will result in an error rather than a warning.
393 .TP
394 .B -flno
395 Produce a linenumber file along with the output .dat file.
396 .TP
397 .B -fcorrect-ternary
398 Use C's operator precedence for ternary expressions. Unless your code
399 depends on fteqcc-compatible behaviour, you'll want to use thi
400 soption.
401 .TP
402 .B -fsingle-vector-defs
403 Normally vectors generate 4 defs, once for the vector, and once for
404 its components with _x, _y, _z suffixes. This option
405 prevents components from being listed.
406 .TP
407 .B -fcorrect-logic
408 Most QC compilers translate if(a_vector) directly as an IF on the
409 vector, which means only the x-component is checked. This causes
410 vectors to be cast to actual booleans via a NOT_V and, if necessary, a
411 NOT_F chained to it.
412 .in +4
413 .nf
414 if (a_vector) // becomes
415 if not(!a_vector)
416 // likewise
417 a = a_vector && a_float // becomes
418 a = !!a_vector && a_float
419 .fi
420 .in
421 .TP
422 .B -ftrue-empty-strings
423 An empty string is considered to be true everywhere. The NOT_S
424 instruction usually considers an empty string to be false, this option
425 effectively causes the unary not in strings to use NOT_F instead.
426 .TP
427 .B -ffalse-empty-strings
428 An empty string is considered to be false everywhere. This means loops
429 and if statements which depend on a string will perform a NOT_S
430 instruction on the string before using it.
431 .TP
432 .B -futf8
433 Enable utf8 characters. This allows utf-8 encoded character constants,
434 and escape sequence codepoints in the valid utf-8 range. Effectively
435 enabling escape sequences like '\\{x2211}'.
436 .TP
437 .B -fbail-on-werror
438 When a warning is treated as an error, and this option is set (which
439 it is by default), it is like any other error and will cause
440 compilation to stop. When disabling this flag by using
441 \-fno-bail-on-werror, compilation will continue until the end, but no
442 output is generated. Instead the first such error message's context is
443 shown.
444 .TP
445 .B -floop-labels
446 Allow loops to be labeled, and allow 'break' and 'continue' to take an
447 optional label to decide which loop to actually jump out of or
448 continue.
449 .sp
450 .in +4
451 .nf
452 for :outer (i = 0; i < n; ++i) {
453     while (inner) {
454         ...;
455         if (something)
456             continue outer;
457     }
458 }
459 .fi
460 .in
461 .TP
462 .B -funtyped-nil
463 Adds a global named 'nil' which is of no type and can be assigned to
464 anything. No typechecking will be performed on assignments. Assigning
465 to it is forbidden, using it in any other kind of expression is also
466 not allowed.
467 .sp
468 Note that this is different from fteqcc's __NULL__: In fteqcc,
469 __NULL__ maps to the integer written as '0i'. It's can be assigned to
470 function pointers and integers, but it'll error about invalid
471 instructions when assigning it to floats without enabling the FTE
472 instruction set. There's also a bug which allows it to be assigned to
473 vectors, for which the source will be the global at offset 0, meaning
474 the vector's y and z components will contain the OFS_RETURN x and y
475 components.
476 .sp
477 In that gmqcc the nil global is an actual global filled with zeroes,
478 and can be assigned to anything including fields, vectors or function
479 pointers, and they end up becoming zeroed.
480 .TP
481 .B -fpermissive
482 Various effects, usually to weaken some conditions.
483 .RS
484 .IP "with -funtyped-nil"
485 Allow local variables named 'nil'. (This will not allow declaring a
486 global of that name.)
487 .RE
488 .TP
489 .B -fvariadic-args
490 Allow variadic parameters to be accessed by QC code. This can be
491 achieved via the '...' function, which takes a parameter index and a
492 typename.
493
494 Example:
495 .sp
496 .in +4
497 .nf
498 void vafunc(string...count) {
499     float i;
500     for (i = 0; i < count; ++i)
501         print(...(i, string), "\\n");
502 }
503 .fi
504 .in
505 .TP -flegacy-vector-maths
506 Most Quake VMs, including the one from FTEQW or up till recently
507 Darkplaces, do not cope well with vector instructions with overlapping
508 input and output. This option will avoid producing such code.
509 .SH OPTIMIZATIONS
510 .TP
511 .B -Opeephole
512 Some general peephole optimizations. For instance the code `a = b + c`
513 typically generates 2 instructions, an ADD and a STORE. This
514 optimization removes the STORE and lets the ADD write directly into A.
515 .TP
516 .B -Otail-recursion
517 Tail recursive function calls will be turned into loops to avoid the
518 overhead of the CALL and RETURN instructions.
519 .TP
520 .B -Ooverlap-locals
521 Make all functions which use neither local arrays nor have locals
522 which are seen as possibly uninitialized use the same local section.
523 This should be pretty safe compared to other compilers which do not
524 check for uninitialized values properly. The problem is that there's
525 QC code out there which really doesn't initialize some values. This is
526 fine as long as this kind of optimization isn't used, but also, only
527 as long as the functions cannot be called in a recursive manner. Since
528 it's hard to know whether or not an array is actually fully
529 initialized, especially when initializing it via a loop, we assume
530 functions with arrays to be too dangerous for this optimization.
531 .TP
532 .B -Olocal-temps
533 This promotes locally declared variables to "temps". Meaning when a
534 temporary result of an operation has to be stored somewhere, a local
535 variable which is not 'alive' at that point can be used to keep the
536 result. This can reduce the size of the global section.
537 This will not have declared variables overlap, even if it was
538 possible.
539 .TP
540 .B -Oglobal-temps
541 Causes temporary values which do not need to be backed up on a CALL to
542 not be stored in the function's locals-area. With this, a CALL to a
543 function may need to back up fewer values and thus execute faster.
544 .TP
545 .B -Ostrip-constant-names
546 Don't generate defs for immediate values or even declared constants.
547 Meaning variables which are implicitly constant or qualified as such
548 using the 'const' keyword.
549 .TP
550 .B -Ooverlap-strings
551 Aggressively reuse strings in the string section. When a string should
552 be added which is the trailing substring of an already existing
553 string, the existing string's tail will be returned instead of the new
554 string being added.
555
556 For example the following code will only generate 1 string:
557
558 .in +4
559 .nf
560 print("Hell you!\\n");
561 print("you!\\n"); // trailing substring of "Hello you!\\n"
562 .fi
563 .in
564 There's however one limitation. Strings are still processed in order,
565 so if the above print statements were reversed, this optimization
566 would not happen.
567 .TP
568 .B -Ocall-stores
569 By default, all parameters of a CALL are copied into the
570 parameter-globals right before the CALL instructions. This is the
571 easiest and safest way to translate calls, but also adds a lot of
572 unnecessary copying and unnecessary temporary values. This
573 optimization makes operations which are used as a parameter evaluate
574 directly into the parameter-global if that is possible, which is when
575 there's no other CALL instruction in between.
576 .TP
577 .B -Ovoid-return
578 Usually an empty RETURN instruction is added to the end of a void
579 typed function. However, additionally after every function a DONE
580 instruction is added for several reasons. (For example the qcvm's
581 disassemble switch uses it to know when the function ends.). This
582 optimization replaces that last RETURN with DONE rather than adding
583 the DONE additionally.
584 .TP
585 .B -Ovector-components
586 Because traditional QC code doesn't allow you to access individual
587 vector components of a computed vector without storing it in a local
588 first, sometimes people multiply it by a constant like '0 1 0' to get,
589 in this case, the y component of a vector. This optimization will turn
590 such a multiplication into a direct component access. If the factor is
591 anything other than 1, a float-multiplication will be added, which is
592 still faster than a vector multiplication.
593 .SH CONFIG
594 The configuration file is similar to regular .ini files. Comments
595 start with hashtags or semicolons, sections are written in square
596 brackets and in each section there can be arbitrary many key-value
597 pairs.
598 .sp
599 There are 3 sections currently:
600 .IR flags ", " warnings ", and " optimizations .
601 They contain a list of boolean values of the form `VARNAME = true` or
602 `VARNAME = false`. The variable names are the same as for the
603 corresponding -W, -f or -O flag written with only capital letters and
604 dashes replaced by underscores.
605 .sp
606 Here's an example:
607 .in +4
608 .nf
609 # a GMQCC configuration file
610 [flags]
611     FTEPP = true
612     ADJUST_VECTOR_FIELDS = false
613     LNO = true
614
615 [warnings]
616     UNUSED_VARIABLE = false
617     USED_UNINITIALIZED = true
618
619 [optimizations]
620     PEEPHOLE = true
621     TAIL_RECURSION = true
622 .fi
623 .in
624 .SH BUGS
625 Currently the '-fftepp-predefs' flag is not included by '-std=fteqcc',
626 partially because it is not entirely conformant to fteqcc.
627 .sp
628
629 Please report bugs on <http://github.com/graphitemaster/gmqcc/issues>,
630 or see <http://graphitemaster.github.com/gmqcc> on how to contact us.
631 .SH FILES
632 .TP 20
633 .B gmqcc.ini.example
634 A documented example for a gmqcc.ini file.
635 .SH SEE ALSO
636 .IR qcvm (1)
637 .SH AUTHOR
638 See <http://graphitemaster.github.com/gmqcc>.