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