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