CFLAGS += -DNOTRACK
endif
-OBJ_D = util.o code.o ast.o ir.o conout.o ftepp.o opts.o
-OBJ_T = test.o util.o conout.o
-OBJ_C = main.o lexer.o parser.o
-OBJ_X = exec-standalone.o util.o conout.o
+OBJ_D = util.o code.o ast.o ir.o conout.o ftepp.o opts.o file.o
+OBJ_T = test.o util.o conout.o file.o
+OBJ_C = main.o lexer.o parser.o file.o
+OBJ_X = exec-standalone.o util.o conout.o file.o
ifneq ("$(CYGWIN)", "")
#nullify the common variables that
$(OBJ_D) $(OBJ_C) $(OBJ_X): gmqcc.h opts.def
main.o: lexer.h
parser.o: ast.h lexer.h
+ lexer.o: lexer.h
ast.o: ast.h ir.h
ir.o: ir.h
qc_program* prog_load(const char *filename)
{
- qc_program *prog;
- prog_header header;
- FILE *file;
+ qc_program *prog;
+ prog_header header;
+ FILE *file = file_open(filename, "rb");
- file = util_fopen(filename, "rb");
if (!file)
return NULL;
- if (fread(&header, sizeof(header), 1, file) != 1) {
+ if (file_read(&header, sizeof(header), 1, file) != 1) {
loaderror("failed to read header from '%s'", filename);
- fclose(file);
+ file_close(file);
return NULL;
}
if (header.version != 6) {
loaderror("header says this is a version %i progs, we need version 6\n", header.version);
- fclose(file);
+ file_close(file);
return NULL;
}
prog = (qc_program*)mem_a(sizeof(qc_program));
if (!prog) {
- fclose(file);
+ file_close(file);
printf("failed to allocate program data\n");
return NULL;
}
}
#define read_data(hdrvar, progvar, reserved) \
- if (fseek(file, header.hdrvar.offset, SEEK_SET) != 0) { \
+ if (file_seek(file, header.hdrvar.offset, SEEK_SET) != 0) { \
loaderror("seek failed"); \
goto error; \
} \
- if (fread(vec_add(prog->progvar, header.hdrvar.length + reserved), \
- sizeof(*prog->progvar), \
- header.hdrvar.length, file) \
- != header.hdrvar.length) \
- { \
+ if (file_read ( \
+ vec_add(prog->progvar, header.hdrvar.length + reserved), \
+ sizeof(*prog->progvar), \
+ header.hdrvar.length, \
+ file \
+ )!= header.hdrvar.length \
+ ) { \
loaderror("read failed"); \
goto error; \
}
read_data1(strings);
read_data2(globals, 2); /* reserve more in case a RETURN using with the global at "the end" exists */
- fclose(file);
+ file_close(file);
/* profile counters */
memset(vec_add(prog->profile, vec_size(prog->code)), 0, sizeof(prog->profile[0]) * vec_size(prog->code));
printf("Program's system-checksum = 0x%04x\n", (unsigned int)prog->crc16);
printf("Entity field space: %u\n", (unsigned int)prog->entityfields);
printf("Globals: %u\n", (unsigned int)vec_size(prog->globals));
+ printf("Counts:\n"
+ " code: %lu\n"
+ " defs: %lu\n"
+ " fields: %lu\n"
+ " functions: %lu\n"
+ " strings: %lu\n",
+ (unsigned long)vec_size(prog->code),
+ (unsigned long)vec_size(prog->defs),
+ (unsigned long)vec_size(prog->fields),
+ (unsigned long)vec_size(prog->functions),
+ (unsigned long)vec_size(prog->strings));
}
if (opts_info) {
"typedef",
"goto",
- "noreturn",
-
"__builtin_debug_printtype"
};
static size_t num_keywords_fg = sizeof(keywords_fg) / sizeof(keywords_fg[0]);
lex_file* lex_open(const char *file)
{
lex_file *lex;
- FILE *in = util_fopen(file, "rb");
+ FILE *in = file_open(file, "rb");
if (!in) {
lexerror(NULL, "open failed: '%s'\n", file);
lex = (lex_file*)mem_a(sizeof(*lex));
if (!lex) {
- fclose(in);
+ file_close(in);
lexerror(NULL, "out of memory\n");
return NULL;
}
vec_free(lex->modelname);
if (lex->file)
- fclose(lex->file);
+ file_close(lex->file);
#if 0
if (lex->tok)
token_delete(lex->tok);
switch (ch)
{
case '[':
+ nextch = lex_getch(lex);
+ if (nextch == '[') {
+ lex_tokench(lex, ch);
+ lex_tokench(lex, nextch);
+ lex_endtoken(lex);
+ return (lex->tok.ttype = TOKEN_ATTRIBUTE_OPEN);
+ }
+ lex_ungetch(lex, nextch);
+ /* FALL THROUGH */
case '(':
case ':':
case '?':
return (lex->tok.ttype = ch);
else
return (lex->tok.ttype = TOKEN_OPERATOR);
+
+ case ']':
+ if (lex->flags.noops) {
+ nextch = lex_getch(lex);
+ if (nextch == ']') {
+ lex_tokench(lex, ch);
+ lex_tokench(lex, nextch);
+ lex_endtoken(lex);
+ return (lex->tok.ttype = TOKEN_ATTRIBUTE_CLOSE);
+ }
+ lex_ungetch(lex, nextch);
+ }
+ /* FALL THROUGH */
case ')':
case ';':
case '{':
case '}':
- case ']':
case '#':
lex_tokench(lex, ch);
bool argend = false;
size_t itr;
char buffer[1024];
- char *redirout = (char*)stdout;
- char *redirerr = (char*)stderr;
+ char *redirout = NULL;
+ char *redirerr = NULL;
char *config = NULL;
while (!argend && argc > 1) {
char *end;
line = *out;
- len = util_getline(&line, alen, src);
+ len = file_getline(&line, alen, src);
if (len == -1)
return false;
return usage();
}
+ if (OPTS_FLAG(TRUE_EMPTY_STRINGS) && OPTS_FLAG(FALSE_EMPTY_STRINGS)) {
+ con_err("-ftrue-empty-strings and -ffalse-empty-strings are mutually exclusive");
+ exit(1);
+ }
+
/* the standard decides which set of operators to use */
if (opts.standard == COMPILER_GMQCC) {
operators = c_operators;
if (opts.pp_only) {
if (opts_output_wasset) {
- outfile = util_fopen(opts.output, "wb");
+ outfile = file_open(opts.output, "wb");
if (!outfile) {
con_err("failed to open `%s` for writing\n", opts.output);
retval = 1;
goto cleanup;
}
}
- else
- outfile = stdout;
+ else {
+ /* TODO: stdout without stdout .. */
+ }
}
if (!opts.pp_only) {
progs_src = true;
- src = util_fopen("progs.src", "rb");
+ src = file_open("progs.src", "rb");
if (!src) {
con_err("failed to open `progs.src` for reading\n");
retval = 1;
}
srcdone:
- fclose(src);
+ file_close(src);
mem_d(line);
}
}
out = ftepp_get();
if (out)
- fprintf(outfile, "%s", out);
+ file_printf(outfile, "%s", out);
ftepp_flush();
}
else {
opts_set(opts.warn, WARN_UNKNOWN_PRAGMAS, true);
opts_set(opts.warn, WARN_UNREACHABLE_CODE, true);
opts_set(opts.warn, WARN_CPP, true);
+ opts_set(opts.warn, WARN_UNKNOWN_ATTRIBUTE, true);
/* flags */
opts_set(opts.flags, ADJUST_VECTOR_FIELDS, true);
opts_set(opts.flags, FTEPP, false);
char *read_name;
char *read_value;
- while (util_getline(&line, &linesize, filehandle) != EOF) {
+ while (file_getline(&line, &linesize, filehandle) != EOF) {
parse_beg = line;
/* handle BOM */
if (!file) {
/* try ini */
- if (!(ini = fopen((file = "gmqcc.ini"), "r")))
+ if (!(ini = file_open((file = "gmqcc.ini"), "r")))
/* try cfg */
- if (!(ini = fopen((file = "gmqcc.cfg"), "r")))
+ if (!(ini = file_open((file = "gmqcc.cfg"), "r")))
return;
- } else if (!(ini = fopen(file, "r")))
+ } else if (!(ini = file_open(file, "r")))
return;
con_out("found ini file `%s`\n", file);
vec_free(error);
}
- fclose(ini);
+ file_close(ini);
}