mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-18 14:21:36 +00:00
importing initial ftepp.c; -E option now executes the preprocessor
This commit is contained in:
parent
9d57cf2774
commit
07ca2e6407
4 changed files with 111 additions and 18 deletions
3
Makefile
3
Makefile
|
@ -24,7 +24,8 @@ OBJ = \
|
|||
code.o \
|
||||
ast.o \
|
||||
ir.o \
|
||||
con.o
|
||||
con.o \
|
||||
ftepp.o
|
||||
OBJ_C = main.o lexer.o parser.o
|
||||
OBJ_X = exec-standalone.o util.o con.o
|
||||
|
||||
|
|
81
ftepp.c
Normal file
81
ftepp.c
Normal file
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (C) 2012
|
||||
* Wolfgang Bumiller
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#include "gmqcc.h"
|
||||
#include "lexer.h"
|
||||
|
||||
typedef struct {
|
||||
lex_file *lex;
|
||||
} ftepp_t;
|
||||
|
||||
#define ftepp_tokval(f) ((f)->lex->tok.value)
|
||||
|
||||
ftepp_t* ftepp_init()
|
||||
{
|
||||
ftepp_t *ftepp;
|
||||
|
||||
ftepp = (ftepp_t*)mem_a(sizeof(*ftepp));
|
||||
memset(ftepp, 0, sizeof(*ftepp));
|
||||
|
||||
return ftepp;
|
||||
}
|
||||
|
||||
static bool ftepp_preprocess(ftepp_t *ftepp)
|
||||
{
|
||||
int token;
|
||||
|
||||
ftepp->lex->flags.preprocessing = true;
|
||||
|
||||
for (token = lex_do(ftepp->lex); token < TOKEN_EOF; token = lex_do(ftepp->lex))
|
||||
{
|
||||
switch (token) {
|
||||
case TOKEN_EOL: printf("\n"); break;
|
||||
default:
|
||||
printf("%s", ftepp_tokval(ftepp));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (token == TOKEN_EOF);
|
||||
}
|
||||
|
||||
bool ftepp_preprocess_file(const char *filename)
|
||||
{
|
||||
ftepp_t *ftepp = ftepp_init();
|
||||
ftepp->lex = lex_open(filename);
|
||||
if (!ftepp->lex) {
|
||||
con_out("failed to open file \"%s\"\n", filename);
|
||||
return false;
|
||||
}
|
||||
return ftepp_preprocess(ftepp);
|
||||
}
|
||||
|
||||
bool ftepp_preprocess_string(const char *name, const char *str)
|
||||
{
|
||||
ftepp_t *ftepp = ftepp_init();
|
||||
ftepp->lex = lex_open_string(str, strlen(str), name);
|
||||
if (!ftepp->lex) {
|
||||
con_out("failed to create lexer for string \"%s\"\n", name);
|
||||
return false;
|
||||
}
|
||||
return ftepp_preprocess(ftepp);
|
||||
}
|
6
gmqcc.h
6
gmqcc.h
|
@ -752,6 +752,12 @@ bool parser_compile_string(const char *name, const char *str);
|
|||
bool parser_finish (const char *output);
|
||||
void parser_cleanup ();
|
||||
|
||||
/*===================================================================*/
|
||||
/*====================== ftepp.c commandline ========================*/
|
||||
/*===================================================================*/
|
||||
bool ftepp_preprocess_file (const char *filename);
|
||||
bool ftepp_preprocess_string(const char *name, const char *str);
|
||||
|
||||
/*===================================================================*/
|
||||
/*======================= main.c commandline ========================*/
|
||||
/*===================================================================*/
|
||||
|
|
39
main.c
39
main.c
|
@ -57,28 +57,28 @@ static const char *app_name;
|
|||
static int usage() {
|
||||
con_out("usage: %s [options] [files...]", app_name);
|
||||
con_out("options:\n"
|
||||
" -h, --help show this help message\n"
|
||||
" -debug turns on compiler debug messages\n"
|
||||
" -memchk turns on compiler memory leak check\n");
|
||||
" -h, --help show this help message\n"
|
||||
" -debug turns on compiler debug messages\n"
|
||||
" -memchk turns on compiler memory leak check\n");
|
||||
con_out(" -o, --output=file output file, defaults to progs.dat\n"
|
||||
" -a filename add an asm file to be assembled\n"
|
||||
" -s filename add a progs.src file to be used\n");
|
||||
" -a filename add an asm file to be assembled\n"
|
||||
" -s filename add a progs.src file to be used\n");
|
||||
con_out(" -E stop after preprocessing\n");
|
||||
con_out(" -f<flag> enable a flag\n"
|
||||
" -fno-<flag> disable a flag\n"
|
||||
" -std standard select one of the following standards\n"
|
||||
" -std=qcc original QuakeC\n"
|
||||
" -std=fteqcc fteqcc QuakeC\n"
|
||||
" -std=gmqcc this compiler (default)\n");
|
||||
" -fno-<flag> disable a flag\n"
|
||||
" -std standard select one of the following standards\n"
|
||||
" -std=qcc original QuakeC\n"
|
||||
" -std=fteqcc fteqcc QuakeC\n"
|
||||
" -std=gmqcc this compiler (default)\n");
|
||||
con_out(" -W<warning> enable a warning\n"
|
||||
" -Wno-<warning> disable a warning\n"
|
||||
" -Wall enable all warnings\n"
|
||||
" -Werror treat warnings as errors\n");
|
||||
" -Wno-<warning> disable a warning\n"
|
||||
" -Wall enable all warnings\n"
|
||||
" -Werror treat warnings as errors\n");
|
||||
con_out(" -force-crc=num force a specific checksum into the header\n");
|
||||
con_out("\n");
|
||||
con_out("flags:\n"
|
||||
" -fadjust-vector-fields\n"
|
||||
" when assigning a vector field, its _y and _z fields also get assigned\n"
|
||||
" -fadjust-vector-fields\n"
|
||||
" when assigning a vector field, its _y and _z fields also get assigned\n"
|
||||
);
|
||||
return -1;
|
||||
}
|
||||
|
@ -482,10 +482,15 @@ int main(int argc, char **argv) {
|
|||
(items[itr].type == TYPE_SRC ? "progs.src" :
|
||||
("unknown"))))));
|
||||
|
||||
if (!parser_compile_file(items[itr].filename))
|
||||
{
|
||||
if (opts_pp_only) {
|
||||
if (!ftepp_preprocess_file(items[itr].filename)) {
|
||||
retval = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
else if (!parser_compile_file(items[itr].filename)) {
|
||||
retval = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue