5 <meta http-equiv="X-UA-Compatible" content="chrome=1">
8 <link rel="stylesheet" href="stylesheets/styles.css">
9 <link rel="stylesheet" href="stylesheets/pygment_trac.css">
10 <script src="javascripts/scale.fix.js"></script>
11 <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
13 <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
17 <a href="https://github.com/graphitemaster/gmqcc"><div class="fork"></div></a>
20 <h1 class="header">GMQCC</h1>
21 <p class="header">An Improved Quake C Compiler</p>
23 <li class="buttons"><a href=index.html>Index</a></li>
24 <li class="download"><a href="https://github.com/graphitemaster/gmqcc/archive/0.2.2.zip">Download v0.2.2</a></li>
25 <li class="buttons"><a href="https://github.com/graphitemaster/gmqcc/issues">Issues</a></li>
26 <li class="buttons"><a href="doc.html">Documentation</a></li>
27 <li class="buttons"><a href="https://github.com/graphitemaster/gmqcc">View On GitHub</a></li>
32 <li class="wiki"><a class="wiki" href="#cdoc">Compiler Documentation</a></li>
33 <li class="wiki"><a class="wiki" href="#bdoc">Building Documentation</a></li>
34 <li class="wiki"><a class="wiki" href="#tdoc">Testsuite Documentation</a></li>
35 <li class="wiki"><a class="wiki" href="#vdoc">Virtual Machine Documentation</a></li>
37 <h1><a name="cdoc">Compiler Documentation</a></h1>
38 <h3>Defaults Flag</h3>
40 The <i>-show-defaults</i> flag instructs the compiler to print out the defaults used related to
41 the standard, optimization, and code generation. When this flag is specified, the compiler
42 will just print the defaults and quit. No compilation is performed.
44 <pre>$ gmqcc -show-defaults</pre>
45 <h3>Compiling for an alternitive standard</h3>
46 To compile with a different dialect of the QuakeC programming language the <i>-std</i>
47 flag can be instructed to select one of the following options:
51 <td>default standard</td>
55 <td>fteqcc standard</td>
59 <td>vanila QuakeC standard</td>
62 <h2>Common compiler options</h2>
69 <td>-l<path></td>
70 <td>Adds <path> to the directories searched by the preprocessor for include file resolution.</td>
73 <td>-o <file></td>
74 <td>Generates the named executable (progs.src) file (when not specified default is progs.src).</td>
78 <td>-O<level></td>
79 <td>Specfies the optimization level: highest being 3, lowest being 0 (no optimization).</td>
83 <td>Enables generation of debug info for engine backtraces (turns on -flno)</td>
87 <td>Instructs the compiler to only preprocess the input, writing the preprocessed output to stdout</td>
92 "define" a macro. Optionally you may supply
93 a value to the macro with "=". Implicitally turns on -fftepp
98 <td>Enables all compiled warnings for the selcted standard</td>
102 <td>Instruct the compiler to treat all warnings as errors</td>
105 <td>-std=<standard></td>
106 <td>Selects the standard dialect</td>
109 <h3>Predefined Macros</h3>
113 <td>What it represents</td>
116 <td>__STD_GMQCC__</td>
117 <td>Specifies the current selected standard is gmqcc.</td>
120 <td>__STD_FTEQCC__</td>
121 <td>Specifies the current selected standard is fteqcc.</td>
125 <td>Specifies the current selected standard is qcc.</td>
129 <td>Defined always regardless of the selected standard</td>
132 <td>__STD_VERSION_MINOR__</td>
133 <td>Specifies the current selected stanadards minor version number.</td>
136 <td>__STD_VERSION_MAJOR__</td>
137 <td>Specifies the current selected stanadards major version number.</td>
141 <td>Expands to a const string literal of the current file (requires -fftepp-predef)</td>
145 <td>Expands to the current line number (requires -fftepp-predef)</td>
149 <td>Expands to a random number between [0, 256) (requires -fftepp-predef)</td>
153 <td>Expands to a unique number, each expansion causes it to increment (requires -fftepp-predef) </td>
156 <td>__RANDOM_LAST__</td>
157 <td>Expands to the last random number (requires -fftepp-predef)</td>
160 <td>__COUNTER_LAST__</td>
161 <td>Expands to the last counter number (requires -fftepp-predef)</td>
164 <h3>Unsupported compatability options</h3>
166 GMQCC strives hard for compatability with standard dialects, but not all
167 features of those standards might be implemented. The unsupported features
175 <td>Inline Assembly</td>
179 <td>Macro expansion in strings</td>
184 <h2>Less common compiler options</h2>
185 <h3>Code generation options</h3>
189 <td>What it does</td>
192 <td>-foverlap-locals</td>
193 <td>Reduces codesize by overlapping locals where possible</td>
196 <td>-fdarkplaces-string-table-bug</td>
197 <td>Works around a bug in older Darkplaces engine builds where the stringtable size is computed wrong</td>
200 <td>-fadjust-vector-fields</td>
201 <td>corrects assignment of vector field pointers (STORE_V instead of STORE_FLD)</td>
205 <td>Enables FTEQ preprocessor</td>
208 <td>-fftepp-predef</td>
209 <td>Enables additional predefined macros for the FTEQ preprocessor</td>
212 <td>-frelaxted-switch</td>
213 <td>Relaxes switch statement semantics</td>
216 <td>-fshort-logic</td>
217 <td>Enables short circut evaluation/logic</td>
220 <td>-fperl-logic</td>
221 <td>Enables perl evalutaion/logic</td>
224 <td>-ftranslatable-strings</td>
225 <td>Enables translatable strings via .po file</td>
228 <td>-finitialized-nonconstants</td>
229 <td>Prevents initializations from becoming constant unless 'const' is specified as a qualifer</td>
232 <td>-fassign-function-types</td>
233 <td>Allows function types to be assignable even if their signature is invariant</td>
237 <td>Enables generation of progs.lno for engine VM backtraces (enabled with -g as well)</td>
240 <td>-fcorrect-ternary</td>
241 <td>Enabling this corrects the ternary percedecce bugs present in fteqcc</td>
244 <td>-fsingle-vector-defs</td>
245 <td>Prevents the creation of progdefs for vectors</td>
248 <td>-fcorrect-logic</td>
249 <td>Use cast vector to real booleans when used in logic expressions</td>
252 <td>-ftrue-empty-strings</td>
253 <td>Always treat empty strings as true</td>
256 <td>-ffalse-empty-strings</td>
257 <td>Opposite of above, empty strings always false</td>
261 <td>Recognize utf-8 characters in character constants, and encode codepoint escape sequences in strings as utf-8</td>
264 <td>-fbail-on-werror</td>
265 <td>When a warning is printed and it is set to be treated as error via -Werror, compilation will be stopped.</td>
268 <td>-floop-labels</td>
269 <td>Allow loops and switches to be labeled and break and continue to take optional label to target it.</td>
272 <td>-funtyped-nil</td>
273 <td>Enable the 'nil' null constant, which has no type. It can be used as the right hand of any assignment.</td>
276 <td>-fpermissive</td>
277 <td>Be "permissive", e.g with -funtyped-nil, this will allow local variables with the name 'nil'</td>
280 <h3>Warning options</h3>
284 <td>What it does</td>
287 <td>-Wunused-uninitialized</td>
288 <td>Enables warnings about unused or uninitialized variables</td>
291 <td>-Wunknwon-control-sequence</td>
292 <td>Enables warnings about unknown control sequences</td>
296 <td>Enables warnings about the use of (an) extension(s)</td>
299 <td>-Wfield-redeclared</td>
300 <td>Enables warnings about redeclared fields</td>
303 <td>-Wmissing-return-values</td>
304 <td>Enables warnings about missing return values</td>
307 <td>-Wtoo-few-paramaters</td>
308 <td>Enables warnings about missing paramaters for function calls</td>
311 <td>-Wlocal-shadows</td>
312 <td>Enables warnings about locals shadowing paramaters or other locals</td>
315 <td>-Wlocal-constants</td>
316 <td>Enables warnings about constants specified as locals</td>
319 <td>-Wvoid-variables</td>
320 <td>Enables warnings about variables declared as type void</td>
323 <td>-Wimplicit-function-pointer</td>
324 <td>Enables warnings about implicitly declared function pointers</td>
327 <td>-Wvariadic-function</td>
328 <td>Enables warnings for use of varadics for non-builtin functions</td>
331 <td>-Wframe-macros</td>
332 <td>Enables warnings about duplicated frame macros</td>
335 <td>-Weffectless-statement</td>
336 <td>Enables warnings about effectiveless statements</td>
339 <td>-Wend-sys-field</td>
340 <td>Enables warnings of end_sys_fields being declared a field</td>
343 <td>-Wassign-function-types</td>
344 <td>Enables warnings for incompatible function pointer signatures used in assignment</td>
347 <td>-Wpreprocessor</td>
348 <td>Enables warnings about redefined macros</td>
351 <td>-Wmultifile-if</td>
352 <td>Enables warnings about multifile if statements</td>
355 <td>-Wdouble-declaration</td>
356 <td>Enables warnings about double declarations</td>
360 <td>Enables warnings about 'const var' and 'var const'</td>
363 <td>-Wmultibyte-character</td>
364 <td>Enables warnings about use of multibyte characters</td>
367 <td>-Wternary-precedence</td>
368 <td>Enables warnings about ternary expressions whos precedence may be not what expected</td>
371 <td>-Wunknown-pragmas</td>
372 <td>Enables warnings about unknown pragmas</td>
375 <td>-Wunreachable-code</td>
376 <td>Enables warnings about unreachable code</td>
380 <td>Enables warnings about the preprocessor</td>
383 <td>Wunknown-attribute</td>
384 <td>Enables warnings for when an unknown attribute is encountered.</td>
387 <td>-Wreserved-names</td>
388 <td>Enables warnings for variables or fields that are named with a reserved name</td>
391 <td>-Wuninitialized-constant</td>
392 <td>Enables warnings about const global variables with no initializing value</td>
395 <td>-Wuninitialized-global</td>
396 <td>Enables warnings about non-const gloal variable with no initializing value</td>
400 <tr><td>Options</td><td>What it does</td></tr>
403 <td>Enables peephole optimizations</td>
406 <td>-Olocal-temps</td>
407 <td>Enables local-temp omission optimizations</td>
410 <td>-Oglobal-temps</td>
411 <td>Enables global-temp omission optimizations</td>
414 <td>-Otail-recursion</td>
415 <td>Enables tail recursion optimization</td>
418 <td>-Otail-calls</td>
419 <td>Enables tail-call optimizations</td>
422 <td>-Ooverlap-locals</td>
424 Every function where it's safe to do so will share its local
425 section with others. The critera being that the function must
426 have any possibly uninitialized locals, or local arrays regardless
427 of how they are initialized.
431 <td>-Ostrip-constant-names</td>
432 <td>Strip the names of constants</td>
435 <td>-Ooverlap-strings</td>
436 <td>Agressivly reuse strings in the string-section.</td>
439 <td>-Ocall-stores</td>
441 Have expressions which are used as function parameters evaluate directly
442 into the parameter-globals if possible. This avoids copying.
446 <td>-Ovoid-return</td>
447 <td>Do not create a return instruction at the end of return-type void functions</td>
451 Individual warnings may be disabled with -Wno-<warning>
452 <pre>$ gmqcc -Wno-frame-macros # disables frame duplication warning</pre>
454 <h3>Miscellaneous options</h3>
458 <td>What it does</td>
461 <td>-force-crc=<num></td>
462 <td>Forces a specific checsum into the header</td>
466 <td>Turns on compiler debug messages</td>
470 <td>Turns on compiler memory leak checker</td>
474 <td>Dump IR before optimizing and finalizing</td>
478 <td>Dump IR after optimizing and finalizing</td>
481 <td>-Whelp or -W?</td>
482 <td>Lists all warning options</td>
485 <td>-fhelp or -f?</td>
486 <td>Lists all code generation options</td>
489 <td>-redirout=<file></td>
490 <td>Redirect stdout to any file.</td>
493 <td>-redirerr=<file></td>
494 <td>Redirect stderr to any file.</td>
498 <td>Turn off colored stdout/stderr.</td>
501 <td>-config=<file></td>
503 Supply a configuration file to set options.
504 Note: If a file named <b>gmqcc.ini</b> or
505 <b>gmqcc.cfg</b> is found it will be loaded
511 <h1><a name="bdoc">Building Documentation</a></h1>
512 <h2>Building on BSD/NIX</h2>
514 To compile GMQCC on BSD/NIX the following things are
520 <li>Any C90+ C compiler</li>
523 Once obtained you may checkout the development repository
524 with the following shell commands
526 <pre>$ git clone git://github.com/graphitemaster/gmqcc.git
530 The Makefile contains a few rules, depending on what you
531 want to compile, the following rules are:
536 <td>What it does</td>
540 <td>Builds the gmqcc compiler</td>
544 <td>Builds a standable QuakeC VM</td>
548 <td>Builds the testsuite for GMQCC</td>
552 <td>Builds gmqcc, qcvm, and testsuite</td>
556 <td>Installs gmqcc to /usr/local/</td>
560 <td>Runs the testsuite to verify correctness</td>
564 <h2>Building on Windows</h2>
566 To compile GMQCC on windows the following things are
570 <li><a href="http://msysgit.googlecode.com/files/Git-1.8.0-preview20121022.exe">msysGit</a></li>
571 <li><a href="http://www.microsoft.com/visualstudio/eng/downloads">Visual Studio</a></li>
574 Once obtained you may checkout the development repository
575 with the following msysGit commands from a msysGit shell.
576 <pre>$ git clone git://github.com/graphitemaster/gmqcc.git</pre>
577 Included is a VS project file.
580 <h1><a name="tdoc">Testsuite Documentation</a></h1>
581 <h2>Running The Testsuite</h2>
583 To run the testsuite you can either use
584 <pre>$ make check</pre>
585 Or if you're on windows or have already compiled the
586 testsuite from source:
587 <pre>$ ./testsuite </pre>
589 Optionally you may provide the testsuite with additional
595 <td>What it does</td>
598 <td>-redirout=<file></td>
599 <td>Redirect stdout to any file.</td>
602 <td>-redirerr=<file></td>
603 <td>Redirect stderr to any file.</td>
607 <td>Turn on testsuite debug messages.</td>
611 <td>Turn on testsuite memleak checker.</td>
615 <td>Turn off colored stdout/stderr.</td>
619 <h2>Writing Tests</h2>
621 GMQCC comes with a complete testsuite for verifying semantics
622 and syntatics. The testsuite executes files from the test/
623 directory, by reading task template files.
626 templates are rules for a specific test, used to create a "task" that
627 is executed with those set of rules (arguments, and what not). Tests
628 that don't have a template with them cannot become tasks, since without
629 the information for that test there is no way to properly "test" them.
630 Rules for these templates are described in a template file, using a
631 task template language.
634 The languge is composed entierly of "tags" which describe a string of
635 text for a task. Think of it much like a configuration file. Except
636 it's been designed to allow flexibility and future support for prodecual
640 The following "tags" are suported by the language:
645 <td>Description of what the tag does</td>
649 <td>Used to set a description of the current test, this must be
650 provided, this tag is NOT optional.</td>
654 <td>Used to set a failure message, this message will be displayed
655 if the test fails, this tag is optional.</td>
659 <td>Used to set a success message, this message will be displayed
660 if the test succeeds, this tag is optional.
665 <td>Used to set the procedure for the given task, there are two
669 This simply performs compilation only</li>
671 This will perform compilation and execution</li>
673 This will perform compilation on the requirement it fails, otherwise
677 This tag must be provided, this tag is NOT optional.
682 <td>Used to set the compilation flags for the given task, this
683 must be provided, this tag is NOT optional.</td>
687 <td>Used to set the execution flags for the given task. This tag
688 must be provided if T == -execute, otherwise it's erroneous
689 as compilation only takes place.</td>
693 <td>Used to describe a string of text that should be matched from
694 the output of executing the task. If this doesn't match the
695 task fails. This tag must be provided at least once if
696 T == -execute, otherwise it's erroneous as compilation only
697 takes place. Multiple M tags are required for multi-line comparision
702 <td>Used to specify the INPUT source file to operate on, this must be
703 provided, this tag is NOT optional</td>
708 These tags (with exception to M) have one-time use, using them more
709 than once will result in template compilation errors,
712 Lines beginning with # or // in the template file are comments and
713 are ignored by the template parser.
714 Whitespace is optional, with exception to the colon ':' between the
715 tag and it's assignment value.
717 The template compiler will detect erronrous tags (optional tags
718 that need not be set), as well as missing tags, and error accordingly
719 which will result in that task failing.
721 <h1><a name="vdoc">Quake C Virtual Machine Documentation</a></h1>
723 Included with GMQCC is a minimal implementation of the QCVM used in many game
724 engines. It's primarly used for the testsuite, but you may also use it as a
725 standalone runtime, or even embed it with existing appliciations.
727 <h2>Running The Standalone VM</h2>
729 To run the standalone application you need to have a compiled progs.dat, with an
730 entry function named main The main function can have any amount of arguments
731 as the standalone executor allows main to be invoked with your choice of arguments.
732 An example of invoking the VM:
733 <pre>$ ./qcvm progs.dat -float 200 #execute passing in 200 as a float to main</pre>
734 If main doesn't require arguments:
735 <pre>$ ./qcvm progs.dat #call main with no arguments</pre>
737 The standalone executor supports the following arguments for passing arguments to main 
742 <td>What it does</td>
746 <td>Passes in a string to main</td>
750 <td>Passes in a float to main</td>
754 <td>Passes in a vector to main</td>
758 The order in which the arguments are expected for main, must be preserved, for
759 example if main 's signature is the following:
760 <pre>void main(float a, vector b)</pre>
762 Then to pass the arguments you'd use the same order:
763 <pre>$ ./qcvm -float 200 -vector '1 2 3'</pre>
765 <h3>Additional Arguments</h3>
766 The standalone virtual machine has the following optional command line arguments:
770 <td>What it does</td>
774 <td>Trace the execution call hierarchy.</td>
778 <td>Profile the bytecode to find hotspots.</td>
782 <td>Get info of the running bytecode.</td>
786 <td>Dissasemble the bytecode into assembly.</td>
790 <td>Prints all definitions for the bytecode running.</td>
793 <td>-printfields</td>
794 <td>Prints all fields for the bytecode running.</td>
799 The standalone virtual machine includes the following builtins.
805 <tr><td>print</td><td>1</td></tr>
806 <tr><td>ftos</td><td>2</td></tr>
807 <tr><td>spawn</td><td>3</td></tr>
808 <tr><td>kill</td><td>4</td></tr>
809 <tr><td>vtos</td><td>5</td></tr>
810 <tr><td>error</td><td>6</td></tr>
811 <tr><td>vlen</td><td>7</td></tr>
812 <tr><td>etos</td><td>8</td></tr>
813 <tr><td>stof</td><td>9</td></tr>
816 <h3>Support or Contact</h3>
817 <p>Having trouble with GMQCC? Join our IRC channel at #kf-engine on irc.freenode.net or contact <a href="mailto:cube2killfild@gmail.com">Us</a>
820 <script type="text/javascript" src="http://www.ohloh.net/p/602517/widgets/project_partner_badge.js"></script>
823 <!--[if !IE]><script>fixScale(document);</script><![endif]-->