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