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