]> git.xonotic.org Git - xonotic/gmqcc.git/blob - doc.html
update documentation
[xonotic/gmqcc.git] / doc.html
1 <!doctype html>
2 <html>
3     <head>
4         <meta charset="utf-8">
5         <meta http-equiv="X-UA-Compatible" content="chrome=1">
6         <title>GMQCC</title>
7
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">
12         <!--[if lt IE 9]>
13         <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
14         <![endif]-->
15     </head>
16     <body>
17         <a href="https://github.com/graphitemaster/gmqcc"><div class="fork"></div></a>
18         <div class="wrapper">
19             <header>
20                 <h1 class="header">GMQCC</h1>
21                 <p class="header">An Improved Quake C Compiler</p>
22                 <ul>
23                     <li class="buttons"><a href=index.html>Index</a></li>
24                     <li class="download"><a href="https://github.com/graphitemaster/gmqcc/archive/0.1.zip">Download v0.1</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>
28                 </ul>
29             </header>
30             <section>
31                 <ul class="wiki">
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>
36                 </ul>
37                 <h1><a name="cdoc">Compiler Documentation</a></h1>
38                 <h3>Defaults Flag</h3>
39                 <p>
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.
43                 </p>
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:
48                 <table border="0">
49                     <tr>
50                         <td>gmqcc</td>
51                         <td>default standard</td>
52                     </tr>
53                     <tr>
54                         <td>fteqcc</td>
55                         <td>fteqcc standard</td>
56                     </tr>
57                     <tr>
58                         <td>qcc</td>
59                         <td>vanila QuakeC standard</td>
60                     </tr>
61                 </table>
62                 <h2>Common compiler options</h2>
63                 <table border="0">
64                     <tr>
65                         <td>Options</td>
66                         <td>What it does</td>
67                     </tr>
68                     <tr>
69                         <td>-l&lt;path&gt;</td>
70                         <td>Adds &lt;path&gt; to the directories searched by the preprocessor for include file resolution.</td>
71                     </tr>
72                     <tr>
73                         <td>-o &lt;file&gt;</td>
74                         <td>Generates the named executable (progs.src) file (when not specified default is progs.src).</td>
75                     </tr>
76                     
77                     <tr>
78                         <td>-O&lt;level&gt;</td>
79                         <td>Specfies the optimization level: highest being 3, lowest being 0 (no optimization).</td>
80                     </tr>
81                     <tr>
82                         <td>-E</td>
83                         <td>Instructs the compiler to only preprocess the input, writing the preprocessed output to stdout</td>
84                     </tr>
85                     <tr>
86                         <td>-Wall</td>
87                         <td>Enables all compiled warnings for the selcted standard</td>
88                     </tr>
89                     <tr>
90                         <td>-Werror</td>
91                         <td>Instruct the compiler to treat all warnings as errors</td>
92                     </tr>
93                     <tr>
94                         <td>-std=&lt;standard&gt;</td>
95                         <td>Selects the standard dialect</td>
96                     </tr>
97                 </table>
98                 <h3>Predefined Macros</h3>
99                 <table border="0">
100                     <tr>
101                         <td>Macro</td>
102                         <td>What it represents</td>
103                     </tr>
104                     <tr>
105                         <td>GMQCC</td>
106                         <td>Specifies the current selected standard is gmqcc.</td>
107                     </tr>
108                     <tr>
109                         <td>FTEQCC</td>
110                         <td>Specifies the current selected standard is fteqcc.</td>
111                     </tr>
112                     <tr>
113                         <td>QCC</td>
114                         <td>Specifies the current selected standard is qcc.</td>
115                     </tr>
116                     
117                     <tr>
118                         <td>__STD_VERSION_MINOR__</td>
119                         <td>Specifies the current selected stanadards minor version number.</td>
120                     </tr>
121                     <tr>
122                         <td>__STD_VERSION_MAJOR__</td>
123                         <td>Specifies the current selected stanadards major version number.</td>
124                     </tr>
125                 </table>
126                 <h3>Unsupported compatability options</h3>
127                 <p>
128                     GMQCC strives hard for compatability with standard dialects, but not all
129                     features of those standards might be implemented. The unsupported features
130                     are presented below:
131                     <table border="0">
132                         <tr>
133                             <td>Feature</td>
134                             <td>Standard</td>
135                         </tr>
136                         <tr>
137                             <td>Inline Assembly</td>
138                             <td>FTEQCC</td>
139                         </tr>
140                         <tr>
141                             <td>Macro expansion in strings</td>
142                             <td>FTEQCC</td>
143                         </tr>
144                     </table>
145                 </p>
146                 <h2>Less common compiler options</h2>
147                 <h3>Code generation options</h3>
148                 <table border="0">
149                     <tr>
150                         <td>Option</td>
151                         <td>What it does</td>
152                     </tr>
153                     <tr>
154                         <td>-foverlap-locals</td>
155                         <td>Reduces codesize by overlapping locals where possible</td>
156                     </tr>
157                     <tr>
158                         <td>-fdarkplaces-string-table-bug</td>
159                         <td>Works around a bug in older Darkplaces engine builds where the stringtable size is computed wrong</td>
160                     </tr>
161                     <tr>
162                         <td>-fadjust-vector-fields</td>
163                         <td>corrects assignment of vector field pointers (STORE_V instead of STORE_FLD)</td>
164                     </tr>
165                     <tr>
166                         <td>-fftepp</td>
167                         <td>Enables FTEQ preprocessor</td>
168                     </tr>
169                     <tr>
170                         <td>-frelaxted-switch</td>
171                         <td>Relaxes switch statement semantics</td>
172                     </tr>
173                     <tr>
174                         <td>-fshort-logic</td>
175                         <td>Enables short circut evaluation/logic</td>
176                     </tr>
177                     <tr>
178                         <td>-fperl-logic</td>
179                         <td>Enables perl evalutaion/logic</td>
180                     </tr>
181                     <tr>
182                         <td>-ftranslatable-strings</td>
183                         <td>Enables translatable strings via .po file</td>
184                     </tr>
185                     <tr>
186                         <td>-finitialized-nonconstants</td>
187                         <td>Prevents initializations from becoming constant unless 'const' is specified as a qualifer</td>
188                     </tr>
189                     <tr>
190                         <td>-fassign-function-types</td>
191                         <td>Allows function types to be assignable even if their signature is invariant</td>
192                     </tr>
193                     <tr>
194                         <td>-flno</td>
195                         <td>Enables generation of progs.lno for engine VM backtraces</td>
196                     </tr>
197                 </table>
198                 <h3>Warning options</h3>
199                 <table border="0">
200                     <tr>
201                         <td>Option</td>
202                         <td>What it does</td>
203                     </tr>
204                     <tr>
205                         <td>-Wunused-uninitialized</td>
206                         <td>Enables warnings about unused or uninitialized variables</td>
207                     </tr>
208                     <tr>
209                         <td>-Wunknwon-control-sequence</td>
210                         <td>Enables warnings about unknown control sequences</td>
211                     </tr>
212                     <tr>
213                         <td>-Wextension</td>
214                         <td>Enables warnings about the use of (an) extension(s)</td>
215                     </tr>
216                     <tr>
217                         <td>-Wfield-redeclared</td>
218                         <td>Enables warnings about redeclared fields</td>
219                     </tr>
220                     <tr>
221                         <td>-Wmissing-return-values</td>
222                         <td>Enables warnings about missing return values</td>
223                     </tr>
224                     <tr>
225                         <td>-Wtoo-few-paramaters</td>
226                         <td>Enables warnings about missing paramaters for function calls</td>
227                     </tr>
228                     <tr>
229                         <td>-Wlocal-shadows</td>
230                         <td>Enables warnings about locals shadowing paramaters or other locals</td>
231                     </tr>
232                     <tr>
233                         <td>-Wlocal-constants</td>
234                         <td>Enables warnings about constants specified as locals</td>
235                     </tr>
236                     <tr>
237                         <td>-Wvoid-variables</td>
238                         <td>Enables warnings about variables declared as type void</td>
239                     </tr>
240                     <tr>
241                         <td>-Wimplicit-function-pointer</td>
242                         <td>Enables warnings about implicitly declared function pointers</td>
243                     </tr>
244                     <tr>
245                         <td>-Wvariadic-function</td>
246                         <td>Enables warnings for use of varadics for non-builtin functions</td>
247                     </tr>
248                     <tr>
249                         <td>-Wframe-macros</td>
250                         <td>Enables warnings about duplicated frame macros</td>
251                     </tr>
252                     <tr>
253                         <td>-Weffectless-statement</td>
254                         <td>Enables warnings about effectiveless statements</td>
255                     </tr>
256                     <tr>
257                         <td>-Wend-sys-field</td>
258                         <td>Enables warnings of end_sys_fields being declared a field</td>
259                     </tr>
260                     <tr>
261                         <td>-Wassign-function-types</td>
262                         <td>Enables warnings for incompatible function pointer signatures used in assignment</td>
263                     </tr>
264                     <tr>
265                         <td>-Wpreprocessor</td>
266                         <td>Enables warnings about redefined macros</td>
267                     </tr>
268                     <tr>
269                         <td>-Wmultifile-if</td>
270                         <td>Enables warnings about multifile if statements</td>
271                     </tr>
272                     <tr>
273                         <td>-Wdouble-declaration</td>
274                         <td>Enables warnings about double declarations</td>
275                     </tr>
276                     <tr>
277                         <td>-Wconst-var</td>
278                         <td>Enables warnings about 'const var' and 'var const'</td>
279                     </tr>
280                     <tr>
281                         <td>-Wmultibyte-character</td>
282                         <td>Enables warnings about use of multibyte characters</td>
283                     </tr>
284                     <tr>
285                         <td>-Wternary-precedence</td>
286                         <td>Enables warnings about ternary expressions whos precedence may be not what expected</td>
287                     </tr>
288                 </table>
289                 <table border="0">
290                     <tr><td>Options</td><td>What it does</td></tr>
291                     <tr>
292                         <td>-Otail-recursion</td>
293                         <td>Enables tail recursion optimization</td>
294                     </tr>
295                 </table>
296                 <p>
297                     Individual warnings may be disabled with &nbsp;-Wno-&lt;warning&gt;
298                     <pre>$ gmqcc -Wno-frame-macros # disables frame duplication warning</pre>
299                 </p>
300                 <h3>Miscellaneous options</h3>
301                 <table border="0">
302                     <tr>
303                         <td>Option</td>
304                         <td>What it does</td>
305                     </tr>
306                     <tr>
307                         <td>-force-crc=&lt;num&gt;</td>
308                         <td>Forces a specific checsum into the header</td>
309                     </tr>
310                     <tr>
311                         <td>-debug</td>
312                         <td>Turns on compiler debug messages</td>
313                     </tr>
314                     <tr>
315                         <td>-memchk</td>
316                         <td>Turns on compiler memory leak checker</td>
317                     </tr>
318                     <tr>
319                         <td>-Whelp or -W?</td>
320                         <td>Lists all warning options</td>
321                     </tr>
322                     <tr>
323                         <td>-fhelp or -f?</td>
324                         <td>Lists all code generation options</td>
325                     </tr>
326                     <tr>
327                         <td>-redirout=&lt;file&gt;</td>
328                         <td>Redirect stdout to any file.</td>
329                     </tr>
330                     <tr>
331                         <td>-redirerr=&lt;file&gt;</td>
332                         <td>Redirect stderr to any file.</td>
333                     </tr>
334                     <tr>
335                         <td>-nocolor</td>
336                         <td>Turn off colored stdout/stderr.</td>
337                     </tr>
338                 </table>
339                 
340                 <h1><a name="bdoc">Building Documentation</a></h1>
341                 <h2>Building on BSD/NIX</h2>
342                 <p>
343                     To compile GMQCC on BSD/NIX the following things are
344                     required:
345                     
346                     <ul>
347                         <li>GIT</li>
348                         <li>Make</li>
349                         <li>Any C90+ C compiler</li>
350                     </ul>
351                     
352                     Once obtained you may checkout the development repository
353                     with the following shell commands
354                     
355 <pre>$ git clone git://github.com/graphitemaster/gmqcc.git
356 $ cd gmqcc
357 </pre>
358
359                     The Makefile contains a few rules, depending on what you
360                     want to compile, the following rules are:
361                     
362                     <table border="0">
363                         <tr>
364                             <td>Rule</td>
365                             <td>What it does</td>
366                         </tr>
367                         <tr>
368                             <td>gmqcc</td>
369                             <td>Builds the gmqcc compiler</td>
370                         </tr>
371                         <tr>
372                             <td>qcvm</td>
373                             <td>Builds a standable QuakeC VM</td>
374                         </tr>
375                         <tr>
376                             <td>testsuite</td>
377                             <td>Builds the testsuite for GMQCC</td>
378                         </tr>
379                         <tr>
380                             <td>all</td>
381                             <td>Builds gmqcc, qcvm, and testsuite</td>
382                         </tr>
383                         <tr>
384                             <td>install</td>
385                             <td>Installs gmqcc to /usr/local/</td>
386                         </tr>
387                         <tr>
388                             <td>check</td>
389                             <td>Runs the testsuite to verify correctness</td>
390                         </tr>
391                     </table>
392                 </p>
393                 <h2>Building on Windows</h2>
394                 <p>
395                     To compile GMQCC on windows the following things are
396                     required:
397                     
398                     <ul>
399                         <li><a href="http://msysgit.googlecode.com/files/Git-1.8.0-preview20121022.exe">msysGit</a></li>
400                         <li><a href="http://www.microsoft.com/visualstudio/eng/downloads">Visual Studio</a></li>
401                     </ul>
402                     
403                     Once obtained you may checkout the development repository
404                     with the following msysGit commands from a msysGit shell.
405                     <pre>$ git clone git://github.com/graphitemaster/gmqcc.git</pre>
406                     Included is a VS project file.
407                 </p>
408                 
409                 <h1><a name="tdoc">Testsuite Documentation</a></h1>
410                 <h2>Running The Testsuite</h2>
411                 <p>
412                     To run the testsuite you can either use
413                     <pre>$ make check</pre>
414                     Or if you're on windows or have already compiled the
415                     testsuite from source:
416                     <pre>$ ./testsuite </pre>
417                     
418                     Optionally you may provide the testsuite with additional
419                     arguments:
420                     
421                     <table border="0">
422                         <tr>
423                             <td>Argument</td>
424                             <td>What it does</td>
425                         </tr>
426                         <tr>
427                             <td>-redirout=&lt;file&gt;</td>
428                             <td>Redirect stdout to any file.</td>
429                         </tr>
430                         <tr>
431                             <td>-redirerr=&lt;file&gt;</td>
432                             <td>Redirect stderr to any file.</td>
433                         </tr>
434                         <tr>
435                             <td>-debug</td>
436                             <td>Turn on testsuite debug messages.</td>
437                         </tr>
438                         <tr>
439                             <td>-memchk</td>
440                             <td>Turn on testsuite memleak checker.</td>
441                         </tr>
442                         <tr>
443                             <td>-nocolor</td>
444                             <td>Turn off colored stdout/stderr.</td>
445                         </tr>
446                     </table>
447                 </p>
448                 <h2>Writing Tests</h2>
449                 <p>
450                     GMQCC comes with a complete testsuite for verifying semantics
451                     and syntatics.  The testsuite executes files from the test/
452                     directory, by reading task template files.
453                 </p>
454                 <p>
455                    templates are rules for a specific test, used to create a "task" that
456                    is executed with those set of rules (arguments, and what not). Tests
457                    that don't have a template with them cannot become tasks, since without
458                    the information for that test there is no way to properly "test" them.
459                    Rules for these templates are described in a template file, using a
460                    task template language.
461                 </p>
462                 <p>
463                    The languge is composed entierly of "tags" which describe a string of
464                    text for a task.  Think of it much like a configuration file.  Except
465                    it's been designed to allow flexibility and future support for prodecual
466                    semantics.
467                 <p>
468                 <p>
469                    The following "tags" are suported by the language:
470                 </p>
471                 <table border="0">
472                     <tr>
473                         <td>Tag</td>
474                         <td>Description of what the tag does</td>
475                     </tr>
476                     <tr>
477                        <td>D:</td>
478                          <td>Used to set a description of the current test, this must be
479                            provided, this tag is NOT optional.</td>
480                     </tr>
481                     <tr>
482                         <td>F:</td>
483                          <td>Used to set a failure message, this message will be displayed
484                            if the test fails, this tag is optional.</td>
485                     </tr>
486                     <tr>
487                         <td>S:</td>
488                             <td>Used to set a success message, this message will be displayed
489                            if the test succeeds, this tag is optional.
490                            </td>
491                     </tr>
492                     <tr>
493                        <td>T:</td>
494                             <td>Used to set the procedure for the given task, there are two
495                            options for this:
496                            <ul>
497                                <li>-compile&nbsp;
498                                    This simply performs compilation only</li>
499                                <li>-execute&nbsp;
500                                    This will perform compilation and execution</li>
501                             </ul>
502                   
503                            This tag must be provided, this tag is NOT optional.
504                            </td>
505                     </tr>
506                     <tr>
507                        <td>C:</td>
508                         <td>Used to set the compilation flags for the given task, this
509                            must be provided, this tag is NOT optional.</td>
510                     </tr>
511                     <tr>
512                        <td>E:</td>
513                         <td>Used to set the execution flags for the given task. This tag
514                            must be provided if T == -execute, otherwise it's erroneous
515                            as compilation only takes place.</td>
516                     </tr>
517                     <tr>
518                        <td>M:</td>
519                         <td>Used to describe a string of text that should be matched from
520                            the output of executing the task.  If this doesn't match the
521                            task fails.  This tag must be provided at least once if
522                            T == -execute, otherwise it's erroneous as compilation only
523                            takes place. Multiple M tags are required for multi-line comparision
524                         </td>
525                     </tr>
526                     <tr>
527                        <td>I:</td>
528                        <td>Used to specify the INPUT source file to operate on, this must be
529                        provided, this tag is NOT optional</td>
530                     </tr>
531                  </table>
532                 <h3>Notes</h3>
533                 <p>
534                    These tags (with exception to M) have one-time use, using them more
535                    than once will result in template compilation errors,
536                 </p>
537                 <p>
538                    Lines beginning with # or // in the template file are comments and
539                    are ignored by the template parser.
540                    Whitespace is optional, with exception to the colon ':' between the
541                    tag and it's assignment value.
542                 </p>
543                    The template compiler will detect erronrous tags (optional tags
544                    that need not be set), as well as missing tags, and error accordingly
545                    which will result in that task failing.
546                 </p>
547                 <h1><a name="vdoc">Quake C Virtual Machine Documentation</a></h1>
548                 <p>
549                     Included with GMQCC is a minimal implementation of the QCVM used in many game
550                     engines.  It's primarly used for the testsuite, but you may also use it as a
551                     standalone runtime, or even embed it with existing appliciations.
552                 </p>
553                 <h2>Running The Standalone VM</h2>
554                 <p>
555                     To run the standalone application you need to have a compiled progs.dat, with an
556                     entry function named &nbsp;main&nbsp;  The main function can have any amount of arguments
557                     as the standalone executor allows main to be invoked with your choice of arguments.
558                     An example of invoking the VM:
559                     <pre>$ ./qcvm progs.dat -float 200 #execute passing in 200 as a float to main</pre>
560                     If &nbsp;main&nbsp; doesn't require arguments:
561                     <pre>$ ./qcvm progs.dat #call main with no arguments</pre>
562                     
563                     The standalone executor supports the following arguments for passing arguments to &nbsp;main&nbsp
564                     
565                     <table border="0">
566                         <tr>
567                             <td>Argument</td>
568                             <td>What it does</td>
569                         </tr>
570                         <tr>
571                             <td>-string</td>
572                             <td>Passes in a string to main</td>
573                         </tr>
574                         <tr>
575                             <td>-float</td>
576                             <td>Passes in a float to main</td>
577                         </tr>
578                         <tr>
579                             <td>-vector</td>
580                             <td>Passes in a vector to main</td>
581                         </tr>
582                     </table>
583                     
584                     The order in which the arguments are expected for main, must be preserved, for
585                     example if &nbsp;main&nbsp;'s signature is the following:
586                     <pre>void main(float a, vector b)</pre>
587                     
588                     Then to pass the arguments you'd use the same order:
589                     <pre>$ ./qcvm -float 200 -vector '1 2 3'</pre>
590                     
591                     <h3>Additional Arguments</h3>
592                     The standalone virtual machine has the following optional command line arguments:
593                     <table border="0">
594                         <tr>
595                             <td>Argument</td>
596                             <td>What it does</td>
597                         </tr>
598                         <tr>
599                             <td>-trace</td>
600                             <td>Trace the execution call hierarchy.</td>
601                         </tr>
602                         <tr>
603                             <td>-profile</td>
604                             <td>Profile the bytecode to find hotspots.</td>
605                         </tr>
606                         <tr>
607                             <td>-info</td>
608                             <td>Get info of the running bytecode.</td>
609                         </tr>
610                         <tr>
611                             <td>-disasm</td>
612                             <td>Dissasemble the bytecode into assembly.</td>
613                         </tr>
614                         <tr>
615                             <td>-printdefs</td>
616                             <td>Prints all definitions for the bytecode running.</td>
617                         </tr>
618                         <tr>
619                             <td>-printfields</td>
620                             <td>Prints all fields for the bytecode running.</td>
621                         </tr>
622                     </table>
623                     
624                     <h3>Builtins</h3>
625                     The standalone virtual machine includes the following builtins.
626                     <table border="0">
627                         <tr>
628                             <td>Builtin</td>
629                             <td>Number</td>
630                         </tr>
631                             <tr><td>print</td><td>1</td></tr>
632                             <tr><td>ftos</td><td>2</td></tr>
633                             <tr><td>spawn</td><td>3</td></tr>
634                             <tr><td>kill</td><td>4</td></tr>
635                             <tr><td>vtos</td><td>5</td></tr>
636                             <tr><td>error</td><td>6</td></tr>
637                             <tr><td>vlen</td><td>7</td></tr>
638                             <tr><td>etos</td><td>8</td></tr>
639                     </table>
640                 </p>
641                 <h3>Support or Contact</h3>
642                 <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> 
643             </section>
644             <footer>
645                 <script type="text/javascript" src="http://www.ohloh.net/p/602517/widgets/project_partner_badge.js"></script>
646             </footer>
647         </div>
648         <!--[if !IE]><script>fixScale(document);</script><![endif]-->
649     </body>
650 </html>