X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=parser.c;h=1c453f3d577763f51974d6882379a8deeb4b5d66;hb=3ece4a964f7fd04424ff7c619fc43c1056fa98c1;hp=e8760bb08344a5e07f2333f3e6eba5fe83f9c360;hpb=960cb7034af7240036a969a59f21e28e63a86df2;p=xonotic%2Fgmqcc.git diff --git a/parser.c b/parser.c index e8760bb..1c453f3 100644 --- a/parser.c +++ b/parser.c @@ -29,8 +29,6 @@ #define PARSER_HT_SIZE 512 #define TYPEDEF_HT_SIZE 512 -static ast_expression * const intrinsic_debug_typestring = (ast_expression*)0x1; - static void parser_enterblock(parser_t *parser); static bool parser_leaveblock(parser_t *parser); static void parser_addlocal(parser_t *parser, const char *name, ast_expression *e); @@ -111,7 +109,7 @@ static ast_expression* parser_find_label(parser_t *parser, const char *name) return NULL; } -static ast_expression* parser_find_global(parser_t *parser, const char *name) +ast_expression* parser_find_global(parser_t *parser, const char *name) { ast_expression *var = (ast_expression*)util_htget(parser->aliases, parser_tokval(parser)); if (var) @@ -173,9 +171,6 @@ static ast_value* parser_find_typedef(parser_t *parser, const char *name, size_t return NULL; } -/* include intrinsics */ -#include "intrin.h" - typedef struct { size_t etype; /* 0 = expression, others are operators */ @@ -353,11 +348,6 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) #define NotSameType(T) \ (exprs[0]->vtype != exprs[1]->vtype || \ exprs[0]->vtype != T) - - /* preform any constant folding on operator usage first */ - /*if ((out = fold_op(parser->fold, op, exprs)))*/ - /*goto complete;*/ - switch (op->id) { default: @@ -506,11 +496,9 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) if (exprs[0]->vtype != exprs[1]->vtype || (exprs[0]->vtype != TYPE_VECTOR && exprs[0]->vtype != TYPE_FLOAT) ) { - compile_error(ctx, "invalid types used in expression: cannot add type %s and %s (%s %s)", + compile_error(ctx, "invalid types used in expression: cannot add type %s and %s", type_name[exprs[0]->vtype], - type_name[exprs[1]->vtype], - asvalue[0]->name, - asvalue[1]->name); + type_name[exprs[1]->vtype]); return false; } if (!(out = fold_op(parser->fold, op, exprs))) { @@ -617,7 +605,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) return false; } else if (!(out = fold_op(parser->fold, op, exprs))) { /* generate a call to __builtin_mod */ - ast_expression *mod = intrin_func(parser, "mod"); + ast_expression *mod = intrin_func(parser->intrin, "mod"); ast_call *call = NULL; if (!mod) return false; /* can return null for missing floor */ @@ -753,6 +741,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) compile_error(ast_ctx(exprs[0]), "Not Yet Implemented: bit-shifts"); return false; } + break; case opid2('|','|'): generated_op += 1; /* INSTR_OR */ @@ -819,7 +808,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) } if (!(out = fold_op(parser->fold, op, exprs))) { - ast_call *gencall = ast_call_new(parser_ctx(parser), intrin_func(parser, "pow")); + ast_call *gencall = ast_call_new(parser_ctx(parser), intrin_func(parser->intrin, "pow")); vec_push(gencall->params, exprs[0]); vec_push(gencall->params, exprs[1]); out = (ast_expression*)gencall; @@ -1163,7 +1152,6 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) break; } #undef NotSameType -/*complete:*/ if (!out) { compile_error(ctx, "failed to apply operator %s", op->op); return false; @@ -1205,9 +1193,11 @@ static bool parser_close_call(parser_t *parser, shunt *sy) return false; } - fun = sy->out[fid].out; - - if (fun == intrinsic_debug_typestring) { + /* + * TODO handle this at the intrinsic level with an ast_intrinsic + * node and codegen. + */ + if ((fun = sy->out[fid].out) == intrin_debug_typestring(parser->intrin)) { char ty[1024]; if (fid+2 != vec_size(sy->out) || vec_last(sy->out).block) @@ -1222,8 +1212,8 @@ static bool parser_close_call(parser_t *parser, shunt *sy) vec_shrinkby(sy->out, 1); return true; } - call = ast_call_new(sy->ops[vec_size(sy->ops)].ctx, fun); + if (!call) return false; @@ -1539,9 +1529,7 @@ static bool parse_sya_operand(parser_t *parser, shunt *sy, bool with_labels) /* a_vector.{x,y,z} */ if (!vec_size(sy->ops) || !vec_last(sy->ops).etype || - operators[vec_last(sy->ops).etype-1].id != opid1('.') || - (prev >= intrinsic_debug_typestring && - prev <= intrinsic_debug_typestring)) + operators[vec_last(sy->ops).etype-1].id != opid1('.')) { /* When adding more intrinsics, fix the above condition */ prev = NULL; @@ -1565,16 +1553,13 @@ static bool parse_sya_operand(parser_t *parser, shunt *sy, bool with_labels) if (!var && !strcmp(parser_tokval(parser), "__FUNC__")) var = (ast_expression*)fold_constgen_string(parser->fold, parser->function->name, false); if (!var) { - /* intrinsics */ - if (!strcmp(parser_tokval(parser), "__builtin_debug_typestring")) { - var = (ast_expression*)intrinsic_debug_typestring; - } - /* now we try for the real intrinsic hashtable. If the string + /* + * now we try for the real intrinsic hashtable. If the string * begins with __builtin, we simply skip past it, otherwise we * use the identifier as is. */ - else if (!strncmp(parser_tokval(parser), "__builtin_", 10)) { - var = intrin_func(parser, parser_tokval(parser) + 10 /* skip __builtin */); + if (!strncmp(parser_tokval(parser), "__builtin_", 10)) { + var = intrin_func(parser->intrin, parser_tokval(parser)); } if (!var) { @@ -5881,7 +5866,8 @@ parser_t *parser_create() parser->reserved_version = NULL; } - parser->fold = fold_init(parser); + parser->fold = fold_init (parser); + parser->intrin = intrin_init(parser); return parser; } @@ -5999,9 +5985,9 @@ static void parser_remove_ast(parser_t *parser) if (parser->reserved_version) ast_value_delete(parser->reserved_version); - util_htdel(parser->aliases); - intrin_intrinsics_destroy(parser); + util_htdel(parser->aliases); fold_cleanup(parser->fold); + intrin_cleanup(parser->intrin); } void parser_cleanup(parser_t *parser)