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