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