mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-02-17 09:02:25 +00:00
Updated readme
This commit is contained in:
parent
fc1844e2a2
commit
4a1f67bb97
4 changed files with 135 additions and 56 deletions
182
README
182
README
|
@ -1,58 +1,140 @@
|
||||||
This is my work in progress Quake C compiler. There are very few _good_ QC
|
This is a work in progress Quake C compiler. There are very few good QC
|
||||||
compilers out there on the internet that can be used in the opensource
|
compilers out there on the internet that can be used in the opensource
|
||||||
community. There are a lot of mediocre compilers, but no one wants those.
|
community. There are a lot of mediocre compilers, but no one wants those.
|
||||||
This is the solution for that, for once a proper Quake C compiler that is
|
This is the solution for that, for once a proper Quake C compiler that is
|
||||||
capable of doing proper optimization. The design so far of this compiler
|
capable of doing proper optimization.
|
||||||
is basic, because it doesn't actually compile code yet.
|
|
||||||
|
|
||||||
gmqcc.h
|
The compiler is intended to implement modern day compiler design princibles
|
||||||
This is the common header with all definitions, structures, and
|
and support modifications through extensions that are provided for the
|
||||||
constants for everything.
|
user through a low-level syntax specific-language inside the language itself
|
||||||
|
to implement language functionality.
|
||||||
|
|
||||||
error.c
|
The design goals of the compiler are very large, it's intended the compiler
|
||||||
This is the error subsystem, this handles the output of good detailed
|
supports a multitude of things, these things along with the status of
|
||||||
error messages (not currently, but will), with colors and such.
|
completeness is represented below in a table.
|
||||||
|
|
||||||
|
+-------------------+-----------------------------+------------------+
|
||||||
|
| Feature | What's it for? | Complete Factor |
|
||||||
|
+-------------------+-----------------------------+------------------+
|
||||||
|
. Lexical analysis . Tokenization . 90% .
|
||||||
|
.-------------------.-----------------------------.------------------.
|
||||||
|
. Tokenization . Parsing . 90% .
|
||||||
|
.-------------------.-----------------------------.------------------.
|
||||||
|
. Parsing / SYA . AST Generation . 09% .
|
||||||
|
.-------------------.-----------------------------.------------------.
|
||||||
|
. AST Generation . IR Generation . ??% .
|
||||||
|
.-------------------.-----------------------------.------------------.
|
||||||
|
. IR Generation . Code Generation . ??% .
|
||||||
|
.-------------------.-----------------------------.------------------.
|
||||||
|
. Code Generation . Binary Generation . ??% .
|
||||||
|
.-------------------.-----------------------------.------------------.
|
||||||
|
. Binary Generation . Binary . 100% .
|
||||||
|
+-------------------+-----------------------------+------------------+
|
||||||
|
|
||||||
|
Design tree:
|
||||||
|
The compiler is intended to work in the following order:
|
||||||
|
Lexical analysis ->
|
||||||
|
Tokenization ->
|
||||||
|
Parsing:
|
||||||
|
Operator precedence:
|
||||||
|
Shynting yard algorithm
|
||||||
|
Inline assembly:
|
||||||
|
Usage of the assembler subsystem:
|
||||||
|
top-down parsing and assemblation no optimization
|
||||||
|
Other parsing:
|
||||||
|
recrusive decent
|
||||||
|
->
|
||||||
|
Abstract syntax tree generation ->
|
||||||
|
Immediate representation (SSA):
|
||||||
|
Optimizations:
|
||||||
|
Constant propagation
|
||||||
|
Value range propogation
|
||||||
|
Sparse conditional constant propagation (possibly?)
|
||||||
|
Dead code elimination
|
||||||
|
Constant folding
|
||||||
|
Global value numbering
|
||||||
|
Partial redundancy elimination
|
||||||
|
Strength reduction
|
||||||
|
Common subexpression elimination
|
||||||
|
Peephole optimizations
|
||||||
|
Loop-invariant code motion
|
||||||
|
Inline expansion
|
||||||
|
Constant folding
|
||||||
|
Induction variable recognition and elimination
|
||||||
|
Dead store elimination
|
||||||
|
Jump threading
|
||||||
|
->
|
||||||
|
Code Generation:
|
||||||
|
Optimizations:
|
||||||
|
Rematerialization
|
||||||
|
Code Factoring
|
||||||
|
Recrusion Elimination
|
||||||
|
Loop unrolling
|
||||||
|
Deforestation
|
||||||
|
->
|
||||||
|
Binary Generation
|
||||||
|
|
||||||
|
File tree and explination:
|
||||||
|
gmqcc.h
|
||||||
|
This is the common header with all definitions, structures, and
|
||||||
|
constants for everything.
|
||||||
|
|
||||||
|
error.c
|
||||||
|
This is the error subsystem, this handles the output of good detailed
|
||||||
|
error messages (not currently, but will), with colors and such.
|
||||||
|
|
||||||
lex.c
|
lex.c
|
||||||
This is the lexer, a very small basic step-seek lexer that can be easily
|
This is the lexer, a very small basic step-seek lexer that can be easily
|
||||||
changed to add new tokens, very retargetable.
|
changed to add new tokens, very retargetable.
|
||||||
|
|
||||||
main.c
|
main.c
|
||||||
This is the core compiler entry, handles switches (will) to toggle on
|
This is the core compiler entry, handles switches (will) to toggle on
|
||||||
and off certian compiler features.
|
and off certian compiler features.
|
||||||
|
|
||||||
parse.c
|
parse.c
|
||||||
This is the parser which goes over all tokens and generates a parse tree
|
This is the parser which goes over all tokens and generates a parse tree
|
||||||
and check for syntax correctness.
|
and check for syntax correctness.
|
||||||
|
|
||||||
typedef.c
|
typedef.c
|
||||||
This is the typedef system, this is a seperate file because it's a lot more
|
This is the typedef system, this is a seperate file because it's a lot more
|
||||||
complicated than it sounds. This handles all typedefs, and even recrusive
|
complicated than it sounds. This handles all typedefs, and even recrusive
|
||||||
typedefs.
|
typedefs.
|
||||||
|
|
||||||
util.c
|
util.c
|
||||||
These are utilities for the compiler, some things in here include a
|
These are utilities for the compiler, some things in here include a
|
||||||
allocator used for debugging, and some string functions.
|
allocator used for debugging, and some string functions.
|
||||||
|
|
||||||
assembler.c
|
assembler.c
|
||||||
This implements support for assembling Quake assembler (which doesn't
|
This implements support for assembling Quake assembler (which doesn't
|
||||||
actually exist untill now: documentation of the Quake assembler is below.
|
actually exist untill now: documentation of the Quake assembler is below.
|
||||||
This also implements (will) inline assembly for the C compiler.
|
This also implements (will) inline assembly for the C compiler.
|
||||||
|
|
||||||
README
|
README
|
||||||
This is the file you're currently reading
|
This is the file you're currently reading
|
||||||
|
|
||||||
Makefile
|
Makefile
|
||||||
The makefile, when sources are added you should add them to the SRC=
|
The makefile, when sources are added you should add them to the SRC=
|
||||||
line otherwise the build will not pick it up. Trivial stuff, small
|
line otherwise the build will not pick it up. Trivial stuff, small
|
||||||
easy to manage makefile, no need to complicate it.
|
easy to manage makefile, no need to complicate it.
|
||||||
Some targets:
|
Some targets:
|
||||||
#make gmqcc
|
#make gmqcc
|
||||||
Builds gmqcc, creating a gmqcc binary file in the current
|
Builds gmqcc, creating a `gmqcc` binary file in the current
|
||||||
directory as the makefile.
|
directory as the makefile.
|
||||||
|
#make test
|
||||||
#make clean
|
Builds the ir and ast tests, creating a `test_ir` and `test_ast`
|
||||||
Cleans the build files left behind by a previous build
|
binary file in the current directory as the makefile.
|
||||||
|
#make test_ir
|
||||||
|
Builds the ir test, creating a `test_ir` binary file in the
|
||||||
|
current directory as the makefile.
|
||||||
|
#make test_ast
|
||||||
|
Builds the asr test, creating a `test_ast` binary file in the
|
||||||
|
current directory as the makefile.
|
||||||
|
#make clean
|
||||||
|
Cleans the build files left behind by a previous build, as
|
||||||
|
well as all the binary files.
|
||||||
|
#make all
|
||||||
|
Builds the tests and the compiler binary all in the current
|
||||||
|
directory of the makefile.
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
///////////////////// Quake Assembler Documentation ////////////////////
|
///////////////////// Quake Assembler Documentation ////////////////////
|
||||||
|
@ -135,7 +217,7 @@ Misc:
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
AUTHOR: "Dale Weiler"
|
AUTHOR: "Dale Weiler"
|
||||||
AUTHOR: "John Doe"
|
AUTHOR: "Wolfgang Bumiller"
|
||||||
|
|
||||||
Colons exist for the sole reason of not having to use spaces after
|
Colons exist for the sole reason of not having to use spaces after
|
||||||
keyword usage (however spaces are allowed). To understand the
|
keyword usage (however spaces are allowed). To understand the
|
||||||
|
|
1
gmqcc.h
1
gmqcc.h
|
@ -28,6 +28,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
|
||||||
#define GMQCC_VERSION_MAJOR 0
|
#define GMQCC_VERSION_MAJOR 0
|
||||||
#define GMQCC_VERSION_MINOR 1
|
#define GMQCC_VERSION_MINOR 1
|
||||||
#define GMQCC_VERSION_PATCH 0
|
#define GMQCC_VERSION_PATCH 0
|
||||||
|
|
2
main.c
2
main.c
|
@ -130,7 +130,7 @@ int main(int argc, char **argv) {
|
||||||
opts_omit_nullcode = true;
|
opts_omit_nullcode = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return printf("invalid command line argument: %s\n", argv[1]);
|
return printf("invalid command line argument: %s\n",argv[1]);
|
||||||
|
|
||||||
}
|
}
|
||||||
++argv;
|
++argv;
|
||||||
|
|
6
util.c
6
util.c
|
@ -164,11 +164,7 @@ bool util_strdigit(const char *str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool util_strncmpexact(const char *src, const char *ned, size_t len) {
|
bool util_strncmpexact(const char *src, const char *ned, size_t len) {
|
||||||
if (!strncmp(src, ned, len)) {
|
return (!strncmp(src, ned, len) && !src[len]);
|
||||||
if (!src[len])
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void util_debug(const char *area, const char *ms, ...) {
|
void util_debug(const char *area, const char *ms, ...) {
|
||||||
|
|
Loading…
Reference in a new issue