]> git.xonotic.org Git - xonotic/gmqcc.git/blob - opts.def
Added documentation to all options inside the binary itself. These will be used...
[xonotic/gmqcc.git] / opts.def
1 /*
2  * Copyright (C) 2012, 2013
3  *     Wolfgang Bumiller
4  *     Dale Weiler
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy of
7  * this software and associated documentation files (the "Software"), to deal in
8  * the Software without restriction, including without limitation the rights to
9  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10  * of the Software, and to permit persons to whom the Software is furnished to do
11  * so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #ifndef GMQCC_DEFINE_FLAG
25 #   ifdef GMQCC_TYPE_OPTIMIZATIONS
26 #       define GMQCC_DEFINE_FLAG(X, Y, Z)
27 #   else
28 #       define GMQCC_DEFINE_FLAG(X, Y)
29 #   endif /* !GMQCC_TYPE_OPTIMIZATIONS */
30 #endif
31
32 /* codegen flags */
33 #ifdef GMQCC_TYPE_FLAGS
34     GMQCC_DEFINE_FLAG (
35         DARKPLACES_STRING_TABLE_BUG,
36
37         "Add some additional characters to the string table in order to\n"
38         "compensate for a wrong boundcheck in some specific version of the\n"
39         "darkplaces engine."
40     )
41
42     GMQCC_DEFINE_FLAG (
43         ADJUST_VECTOR_FIELDS,
44
45         "When assigning to field pointers of type .vector the common be\n"
46         "haviour in compilers like fteqcc is to only assign the x-compo-\n"
47         "nent of the pointer. This means that you can use the vector as\n"
48         "such, but you cannot use its y and z components directly. This\n"
49         "flag fixes this behaviour. Before using it make sure your code\n"
50         "does not depend on the buggy behaviour."
51     )
52
53     GMQCC_DEFINE_FLAG (
54         FTEPP,
55
56         "Enable a partially fteqcc-compatible preprocessor. It supports\n"
57         "all the features used in the Xonotic codebase. If you need more,\n"
58         "write a ticket."
59     )
60
61     GMQCC_DEFINE_FLAG (
62         FTEPP_PREDEFS,
63
64         "Enable some predefined macros. This only works in combination\n"
65         "with '-fftepp' and is currently not included by '-std=fteqcc'.\n"
66         "The following macros will be added:\n"
67         "    __LINE__\n"
68         "    __FILE__\n"
69         "    __COUNTER__\n"
70         "    __COUNTER_LAST__\n"
71         "    __RANDOM__\n"
72         "    __RANDOM_LAST__\n"
73         "    __DATE__\n"
74         "    __TIME__\n"
75         "Note that fteqcc also defines __NULL__ which is not implemented\n"
76         "yet.  (See -funtyped-nil about gmqcc's alternative to __NULL__)."
77     )
78
79
80     GMQCC_DEFINE_FLAG (
81         RELAXED_SWITCH,
82
83         "Allow switch cases to use non constant variables."
84     )
85
86     GMQCC_DEFINE_FLAG (
87         SHORT_LOGIC,
88
89         "Perform early out in logical AND and OR expressions. The final\n"
90         "result will be either a 0 or a 1, see the next flag for more pos-\n"
91         "sibilities."
92     )
93
94     GMQCC_DEFINE_FLAG (
95         PERL_LOGIC,
96
97         "In many languages, logical expressions perform early out in a\n"
98         "special way: If the left operand of an AND yeilds true, or the\n"
99         "one of an OR yields false, the complete expression evaluates to\n"
100         "the right side.  Thus ‘true && 5’ evaluates to 5 rather than 1."
101     )
102
103     GMQCC_DEFINE_FLAG (
104         TRANSLATABLE_STRINGS,
105
106         "Enable the underscore intrinsic: Using ‘_(\"A string constant\")’\n"
107         "will cause the string immediate to get a name with a \"dotrans-\n"
108         "late_\" prefix. The darkplaces engine recognizes these and trans-\n"
109         "lates them in a way similar to how gettext works."
110     )
111
112     GMQCC_DEFINE_FLAG (
113         INITIALIZED_NONCONSTANTS,
114
115         "Don't implicitly convert initialized variables to constants. With\n"
116         "this flag, the const keyword is required to make a constant."
117     )
118
119     GMQCC_DEFINE_FLAG (
120         ASSIGN_FUNCTION_TYPES,
121
122         "If this flag is not set, (and it is set by default in the qcc and\n"
123         "fteqcc standards), assigning function pointers of mismatching\n"
124         "signatures will result in an error rather than a warning."
125     )
126
127     GMQCC_DEFINE_FLAG (
128         LNO,
129
130         "Produce a linenumber file along with the output .dat file."
131     )
132
133     GMQCC_DEFINE_FLAG (
134         CORRECT_TERNARY,
135
136         "Use C's operator precedence for ternary expressions. Unless\n"
137         "code depends on fteqcc-compatible behaviour, you'll want to use\n"
138         "this option."
139     )
140
141     GMQCC_DEFINE_FLAG (
142         SINGLE_VECTOR_DEFS,
143
144         "Normally vectors generate 4 defs, once for the vector, and once\n"
145         "for its components with _x, _y, _z suffixes. This option prevents\n"
146         "components from being listed."
147     )
148
149     GMQCC_DEFINE_FLAG (
150         CORRECT_LOGIC,
151
152         "Most QC compilers translate ‘if(a_vector)’ directly as an IF on\n"
153         "the vector, which means only the x-component is checked. This\n"
154         "option causes vectors to be cast to actual booleans via a NOT_V\n"
155         "and, if necessary, a NOT_F chained to it."
156     )
157
158     GMQCC_DEFINE_FLAG (
159         TRUE_EMPTY_STRINGS,
160
161         "An empty string is considered to be true everywhere. The NOT_S\n"
162         "instruction usually considers an empty string to be false, this\n"
163         "option effectively causes the unary not in strings to use NOT_F\n"
164         "instead."
165     )
166
167     GMQCC_DEFINE_FLAG (
168         FALSE_EMPTY_STRINGS,
169
170         "An empty string is considered to be false everywhere. This means\n"
171         "loops and if statements which depend on a string will perform a\n"
172         "NOT_S instruction on the string before using it."
173     )
174
175     GMQCC_DEFINE_FLAG (
176         UTF8,
177
178         "Enable utf8 characters. This allows utf-8 encoded character con-\n"
179         "stants, and escape sequence codepoints in the valid utf-8 range.\n"
180         "Effectively enabling escape sequences like '\\{x2211}'."
181     )
182
183     GMQCC_DEFINE_FLAG (
184         BAIL_ON_WERROR,
185
186         "When a warning is treated as an error, and this option is set\n"
187         "(which it is by default), it is like any other error and will\n"
188         "cause compilation to stop. When disabling this flag by using\n"
189         "-fno-bail-on-werror, compilation will continue until the end, but\n"
190         "no output is generated. Instead the first such error message's\n"
191         "context is shown."
192     )
193
194     GMQCC_DEFINE_FLAG (
195         LOOP_LABELS,
196
197         "Allow loops to be labeled, and allow 'break' and 'continue' to\n"
198         "take an optional label to decide which loop to actually jump out\n"
199         "of or continue.\n\n"
200         "   for :outer (i = 0; i < n; ++i) {\n"
201         "       while (inner) {\n"
202         "           ...;\n"
203         "           if (something)\n"
204         "               continue outer;\n"
205         "       }\n"
206         "   }"
207     )
208
209     GMQCC_DEFINE_FLAG (
210         UNTYPED_NIL,
211
212         "Adds a global named 'nil' which is of no type and can be assigned\n"
213         "to anything. No typechecking will be performed on assignments.\n"
214         "Assigning to it is forbidden, using it in any other kind of\n"
215         "expression is also not allowed.\n\n"
216         "Note that this is different from fteqcc's __NULL__: In fteqcc,\n"
217         "__NULL__ maps to the integer written as '0i'. It's can be\n"
218         "assigned to function pointers and integers, but it'll error about\n"
219         "invalid instructions when assigning it to floats without enabling\n"
220         "the FTE instruction set. There's also a bug which allows it to be\n"
221         "assigned to vectors, for which the source will be the global at\n"
222         "offset 0, meaning the vector's y and z components will contain\n"
223         "the OFS_RETURN x and y components.\n\n"
224         "In that gmqcc the nil global is an actual global filled with\n"
225         "zeroes, and can be assigned to anything including fields, vectors\n"
226         "or function pointers, and they end up becoming zeroed."
227     )
228
229     GMQCC_DEFINE_FLAG (
230         PERMISSIVE,
231
232         "Various effects, usually to weaken some conditions.\n\n"
233         "   with -funtyped-nil\n"
234         "       Allow local variables named ‘nil’.  (This will not\n"
235         "       allow declaring a global of that name.)"
236     )
237
238     GMQCC_DEFINE_FLAG (
239         VARIADIC_ARGS,
240
241         "Allow variadic parameters to be accessed by QC code. This can be\n"
242         "achieved via the '...' function, which takes a parameter index\n"
243         "and a typename.\n\n"
244         "Example:\n"
245         "   void vafunc(string...count) {\n"
246         "       float i;\n"
247         "       for (i = 0; i < count; ++i)\n"
248         "           print(...(i, string), \"\n\");\n"
249         "   }"
250     )
251
252     GMQCC_DEFINE_FLAG (
253         LEGACY_VECTOR_MATHS,
254
255         "Most Quake VMs, including the one from FTEQW or up till recently\n"
256         "Darkplaces, do not cope well with vector instructions with over‐\n"
257         "lapping input and output. This option will avoid producing such\n"
258         "code."
259     )
260 #endif
261
262 /* warning flags */
263 #ifdef GMQCC_TYPE_WARNS
264     GMQCC_DEFINE_FLAG (
265         UNUSED_VARIABLE,
266         
267         "Generate a warning about variables which are declared but never"
268         "used.  This can be avoided by adding the ‘noref’ keyword in front"
269         "of the variable declaration. Additionally a complete section of"
270         "unreferenced variables can be opened using ‘#pragma noref 1’ and"
271         "closed via ‘#pragma noref 0’."
272     )
273
274     GMQCC_DEFINE_FLAG (
275         USED_UNINITIALIZED,
276
277         "Generate a warning if it is possible that a variable can be used"
278          "without prior initialization. Note that this warning is not nec"
279          "essarily reliable if the initialization happens only under cer"
280          "tain conditions. The other way is not possible: that the warning"
281          "is not generated when uninitialized use is possible."
282     )
283
284     GMQCC_DEFINE_FLAG (
285         UNKNOWN_CONTROL_SEQUENCE,
286
287          "Generate an error when an unrecognized control sequence in a"
288          "string is used. Meaning: when there's a character after a back-"
289          "slash in a string which has no known meaning."
290     )
291
292     GMQCC_DEFINE_FLAG (
293         EXTENSIONS,
294
295         "Warn when using special extensions which are not part of the"
296         "selected standard."
297     )
298
299     GMQCC_DEFINE_FLAG (
300         FIELD_REDECLARED,
301
302         "Generally QC compilers ignore redeclaration of fields. Here you"
303         "can optionally enable a warning."
304     )
305
306     GMQCC_DEFINE_FLAG (
307         MISSING_RETURN_VALUES,
308
309         "Functions which aren't of type void will warn if it possible to"
310         "reach the end without returning an actual value."
311     )
312
313     GMQCC_DEFINE_FLAG (
314         INVALID_PARAMETER_COUNT,
315
316         "Warn about a function call with an invalid number of parameters."
317     )
318
319     GMQCC_DEFINE_FLAG (
320         LOCAL_SHADOWS,
321
322         "Warn when a locally declared variable shadows variable."
323     )
324
325     GMQCC_DEFINE_FLAG (
326         LOCAL_CONSTANTS,
327
328         " Warn when the initialization of a local variable turns the vari"
329         "able into a constant. This is default behaviour unless"
330         "-finitialized-nonconstants is used."
331     )
332
333     GMQCC_DEFINE_FLAG (
334         VOID_VARIABLES,
335
336         "There are only 2 known global variables of type void:"
337         "‘end_sys_globals’ and ‘end_sys_fields’.  Any other void-variable"
338         "will warn."
339     )
340
341     GMQCC_DEFINE_FLAG (
342         IMPLICIT_FUNCTION_POINTER,
343
344         "A global function which is not declared with the ‘var’ keyword is"
345         "expected to have an implementing body, or be a builtin. If nei"
346         "ther is the case, it implicitly becomes a function pointer, and a"
347         "warning is generated."
348     )
349
350     GMQCC_DEFINE_FLAG (
351         VARIADIC_FUNCTION,
352
353         "Currently there's no way for an in QC implemented function to"
354         "access variadic parameters. If a function with variadic parame"
355         "ters has an implementing body, a warning will be generated."
356     )
357
358     GMQCC_DEFINE_FLAG (
359         FRAME_MACROS,
360
361         "Generate warnings about ‘$frame’ commands, for instance about"
362         "duplicate frame definitions."
363     )
364
365     GMQCC_DEFINE_FLAG (
366         EFFECTLESS_STATEMENT,
367
368         "Warn about statements which have no effect. Any expression which"
369         "does not call a function or assigns a variable."
370     )
371
372     GMQCC_DEFINE_FLAG (
373         END_SYS_FIELDS,
374
375         "The ‘end_sys_fields’ variable is supposed to be a global variable"
376         "of type void.  It is also recognized as a field but this will"
377         "generate a warning."
378     )
379
380     GMQCC_DEFINE_FLAG (
381         ASSIGN_FUNCTION_TYPES,
382
383         "Warn when assigning to a function pointer with an unmatching sig"
384         "nature. This usually happens in cases like assigning the null"
385         "function to an entity's .think function pointer."
386     )
387
388     GMQCC_DEFINE_FLAG (
389         CPP,
390
391         "Enable warnings coming from the preprocessor. Like duplicate"
392         "macro declarations. This warning triggers when there's a problem"
393         "with the way the preprocessor has been used."
394     )
395
396     GMQCC_DEFINE_FLAG (
397         MULTIFILE_IF,
398
399         "Warn if there's a preprocessor #if spanning across several files."
400     )
401
402     GMQCC_DEFINE_FLAG (
403         DOUBLE_DECLARATION,
404
405         "Warn about multiple declarations of globals. This seems pretty"
406         "common in QC code so you probably do not want this unless you"
407         "want to clean up your code."
408     )
409     GMQCC_DEFINE_FLAG (
410         CONST_VAR,
411
412         "The combination of const and var is not illegal, however differ"
413         "ent compilers may handle them differently. We were told, the"
414         "intention is to create a function-pointer which is not assigna"
415         "ble.  This is exactly how we interpret it. However for this"
416         "interpretation the ‘var’ keyword is considered superfluous (and"
417         "philosophically wrong), so it is possible to generate a warning"
418         "about this."
419     )
420
421     GMQCC_DEFINE_FLAG (
422         MULTIBYTE_CHARACTER,
423
424         "Warn about multibyte character constants, they do not work right"
425         "now."
426     )
427
428     GMQCC_DEFINE_FLAG (
429         TERNARY_PRECEDENCE,
430
431         "Warn if a ternary expression which contains a comma operator is"
432         "used without enclosing parenthesis, since this is most likely not"
433         "what you actually want. We recommend the -fcorrect-ternary"
434         "option."
435     )
436
437     GMQCC_DEFINE_FLAG (
438         UNKNOWN_PRAGMAS,
439
440         "Warn when encountering an unrecognized ‘#pragma’ line."
441     )
442
443     GMQCC_DEFINE_FLAG (
444         UNREACHABLE_CODE,
445
446         "Warn about unreachable code. That is: code after a return state"
447         "ment, or code after a call to a function marked as 'noreturn'."
448     )
449
450     GMQCC_DEFINE_FLAG (
451         DEBUG,
452
453         "Enable some warnings added in order to help debugging in the com"
454         "piler.  You won't need this."
455     )
456
457     GMQCC_DEFINE_FLAG (
458         UNKNOWN_ATTRIBUTE,
459
460         "Warn on an unknown attribute. The warning will inlclude only the"
461         "first token inside the enclosing attribute-brackets. This may"
462         "change when the actual attribute syntax is better defined."
463     )
464
465     GMQCC_DEFINE_FLAG (
466         RESERVED_NAMES,
467
468         "Warn when using reserved names such as ‘nil’."
469     )
470
471     GMQCC_DEFINE_FLAG (
472         UNINITIALIZED_CONSTANT,
473
474         "Warn about global constants (using the ‘const’ keyword) with no"
475         "assigned value."
476     )
477
478     GMQCC_DEFINE_FLAG (
479         UNINITIALIZED_GLOBAL,
480
481         "Warn about global variables with no initializing value. This is"
482         "off by default, and is added mostly to help find null-values"
483         "which are supposed to be replaced by the untyped 'nil' constant."
484     )
485
486     GMQCC_DEFINE_FLAG (
487         DIFFERENT_QUALIFIERS,
488
489         "Warn when a variables is redeclared with a different qualifier."
490         "For example when redeclaring a variable as 'var' which was previ"
491         "ously marked 'const'."
492     )
493
494     GMQCC_DEFINE_FLAG (
495         DIFFERENT_ATTRIBUTES,
496
497         "Similar to qualifiers but for attributes like ‘[[noreturn]]’."
498     )
499
500     GMQCC_DEFINE_FLAG (
501         DEPRECATED,
502
503         "Warn when a function is marked with the attribute \"[[depre"
504         "cated]]\". This flag enables a warning on calls to functions"
505         "marked as such."
506     )
507
508     GMQCC_DEFINE_FLAG (
509         PARENTHESIS,
510
511         "Warn about possible mistakes caused by missing or wrong parenthe"
512         "sis, like an assignment in an 'if' condition when there's no"
513         "additional set of parens around the assignment."
514     )
515 #endif
516
517 #ifdef GMQCC_TYPE_OPTIMIZATIONS
518     GMQCC_DEFINE_FLAG (
519         PEEPHOLE,             1,
520
521         "Some general peephole optimizations. For instance the code `a = b\n"
522         "+ c` typically generates 2 instructions, an ADD and a STORE. This\n"
523         "optimization removes the STORE and lets the ADD write directly\n"
524         "into A."
525     )
526
527     GMQCC_DEFINE_FLAG (
528         TAIL_RECURSION,       1,
529
530         "Tail recursive function calls will be turned into loops to avoid\n"
531         "the overhead of the CALL and RETURN instructions."
532     )
533
534     GMQCC_DEFINE_FLAG (
535         OVERLAP_LOCALS,       3,
536
537         "Make all functions which use neither local arrays nor have locals\n"
538         "which are seen as possibly uninitialized use the same local sec‐\n"
539         "tion.  This should be pretty safe compared to other compilers\n"
540         "which do not check for uninitialized values properly. The problem\n"
541         "is that there's QC code out there which really doesn't initialize\n"
542         "some values. This is fine as long as this kind of optimization\n"
543         "isn't used, but also, only as long as the functions cannot be\n"
544         "called in a recursive manner. Since it's hard to know whether or\n"
545         "not an array is actually fully initialized, especially when ini‐\n"
546         "tializing it via a loop, we assume functions with arrays to be\n"
547         "too dangerous for this optimization."
548     )
549
550
551     GMQCC_DEFINE_FLAG (
552         LOCAL_TEMPS,          3,
553
554         "This promotes locally declared variables to \"temps\". Meaning when\n"
555         "a temporary result of an operation has to be stored somewhere, a\n"
556         "local variable which is not 'alive' at that point can be used to\n"
557         "keep the result. This can reduce the size of the global section.\n"
558         "This will not have declared variables overlap, even if it was\n"
559         "possible."
560     )
561
562     GMQCC_DEFINE_FLAG (
563         GLOBAL_TEMPS,         3,
564
565         "Causes temporary values which do not need to be backed up on a\n"
566         "CALL to not be stored in the function's locals-area. With this, a\n"
567         "CALL to a function may need to back up fewer values and thus exe‐\n"
568         "cute faster."
569     )
570
571
572     GMQCC_DEFINE_FLAG (
573         STRIP_CONSTANT_NAMES, 1,
574
575         "Don't generate defs for immediate values or even declared con‐\n"
576         "stants.  Meaning variables which are implicitly constant or qual‐\n"
577         "ified as such using the 'const' keyword."
578     )
579
580     GMQCC_DEFINE_FLAG (
581         OVERLAP_STRINGS,      2,
582
583         "Aggressively reuse strings in the string section. When a string\n"
584         "should be added which is the trailing substring of an already\n"
585         "existing string, the existing string's tail will be returned\n"
586         "instead of the new string being added.\n\n"
587         "For example the following code will only generate 1 string:\n\n"
588         "   print(\"Hell you!\\n\");\n"
589         "   print(\"you!\n\"); // trailing substring of \"Hello you!\\n\"\n\n"
590         "There's however one limitation. Strings are still processed in\n"
591         "order, so if the above print statements were reversed, this opti‐\n"
592         "mization would not happen."
593     )
594
595     GMQCC_DEFINE_FLAG (
596         CALL_STORES,          3,
597
598         "By default, all parameters of a CALL are copied into the parame‐\n"
599         "ter-globals right before the CALL instructions. This is the easi‐\n"
600         "est and safest way to translate calls, but also adds a lot of\n"
601         "unnecessary copying and unnecessary temporary values. This opti‐\n"
602         "mization makes operations which are used as a parameter evaluate\n"
603         "directly into the parameter-global if that is possible, which is\n"
604         "when there's no other CALL instruction in between."
605     )
606
607     GMQCC_DEFINE_FLAG (
608         VOID_RETURN,          1,
609
610         "Usually an empty RETURN instruction is added to the end of a void\n"
611         "typed function. However, additionally after every function a DONE\n"
612         "instruction is added for several reasons. (For example the qcvm's\n"
613         "disassemble switch uses it to know when the function ends.). This\n"
614         "optimization replaces that last RETURN with DONE rather than\n"
615         "adding the DONE additionally."
616     )
617
618     GMQCC_DEFINE_FLAG (
619         VECTOR_COMPONENTS,    1,
620
621         "Because traditional QC code doesn't allow you to access individ‐\n"
622         "ual vector components of a computed vector without storing it in\n"
623         "a local first, sometimes people multiply it by a constant like\n"
624         "‘'0 1 0'’ to get, in this case, the y component of a vector. This\n"
625         "optimization will turn such a multiplication into a direct compo‐\n"
626         "nent access. If the factor is anything other than 1, a float-mul‐\n"
627         "tiplication will be added, which is still faster than a vector"
628         "multiplication."
629     )
630 #endif
631
632 /* some cleanup so we don't have to */
633 #undef GMQCC_TYPE_FLAGS
634 #undef GMQCC_TYPE_WARNS
635 #undef GMQCC_TYPE_OPTIMIZATIONS
636 #undef GMQCC_DEFINE_FLAG