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