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