From: Dale Weiler Date: Wed, 29 May 2013 03:29:04 +0000 (+0000) Subject: Major export cleanup. Anything that was exported but wasn't used outside where it... X-Git-Tag: v0.3.0~151^2~44 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f892b323351eb110dc97b8cf4e15d03dddc6fb78;p=xonotic%2Fgmqcc.git Major export cleanup. Anything that was exported but wasn't used outside where it was implemented has been turned into static, and their exports have been removed. This actually makes the compiler compile slightly faster. --- diff --git a/Makefile b/Makefile index 2ab06dd..fea3356 100644 --- a/Makefile +++ b/Makefile @@ -135,7 +135,6 @@ SPLINTFLAGS = \ -onlytrans \ -predboolint \ -boolops \ - -exportlocal \ -incondefs \ -macroredef \ -retvalint \ diff --git a/ast.c b/ast.c index 1e2836f..96f768f 100644 --- a/ast.c +++ b/ast.c @@ -36,6 +36,43 @@ ast_node_init((ast_node*)self, ctx, TYPE_##T); \ ( (ast_node*)self )->node.destroy = (ast_node_delete*)destroyfn +/* + * forward declarations, these need not be in ast.h for obvious + * static reasons. + */ +static bool ast_member_codegen(ast_member*, ast_function*, bool lvalue, ir_value**); +static void ast_array_index_delete(ast_array_index*); +static bool ast_array_index_codegen(ast_array_index*, ast_function*, bool lvalue, ir_value**); +static void ast_store_delete(ast_store*); +static bool ast_store_codegen(ast_store*, ast_function*, bool lvalue, ir_value**); +static void ast_ifthen_delete(ast_ifthen*); +static bool ast_ifthen_codegen(ast_ifthen*, ast_function*, bool lvalue, ir_value**); +static void ast_ternary_delete(ast_ternary*); +static bool ast_ternary_codegen(ast_ternary*, ast_function*, bool lvalue, ir_value**); +static void ast_loop_delete(ast_loop*); +static bool ast_loop_codegen(ast_loop*, ast_function*, bool lvalue, ir_value**); +static void ast_breakcont_delete(ast_breakcont*); +static bool ast_breakcont_codegen(ast_breakcont*, ast_function*, bool lvalue, ir_value**); +static void ast_switch_delete(ast_switch*); +static bool ast_switch_codegen(ast_switch*, ast_function*, bool lvalue, ir_value**); +static void ast_label_delete(ast_label*); +static void ast_label_register_goto(ast_label*, ast_goto*); +static bool ast_label_codegen(ast_label*, ast_function*, bool lvalue, ir_value**); +static bool ast_goto_codegen(ast_goto*, ast_function*, bool lvalue, ir_value**); +static void ast_goto_delete(ast_goto*); +static void ast_call_delete(ast_call*); +static bool ast_call_codegen(ast_call*, ast_function*, bool lvalue, ir_value**); +static bool ast_block_codegen(ast_block*, ast_function*, bool lvalue, ir_value**); +static void ast_unary_delete(ast_unary*); +static bool ast_unary_codegen(ast_unary*, ast_function*, bool lvalue, ir_value**); +static void ast_entfield_delete(ast_entfield*); +static bool ast_entfield_codegen(ast_entfield*, ast_function*, bool lvalue, ir_value**); +static void ast_return_delete(ast_return*); +static bool ast_return_codegen(ast_return*, ast_function*, bool lvalue, ir_value**); +static void ast_binstore_delete(ast_binstore*); +static bool ast_binstore_codegen(ast_binstore*, ast_function*, bool lvalue, ir_value**); +static void ast_binary_delete(ast_binary*); +static bool ast_binary_codegen(ast_binary*, ast_function*, bool lvalue, ir_value**); /* It must not be possible to get here. */ static GMQCC_NORETURN void _ast_node_destroy(ast_node *self) @@ -303,6 +340,7 @@ void ast_type_to_string(ast_expression *e, char *buf, size_t bufsize) buf[pos] = 0; } +static bool ast_value_codegen(ast_value *self, ast_function *func, bool lvalue, ir_value **out); ast_value* ast_value_new(lex_ctx ctx, const char *name, int t) { ast_instantiate(ast_value, ctx, ast_value_delete); @@ -845,7 +883,7 @@ void ast_label_delete(ast_label *self) mem_d(self); } -void ast_label_register_goto(ast_label *self, ast_goto *g) +static void ast_label_register_goto(ast_label *self, ast_goto *g) { vec_push(self->gotos, g); } @@ -1098,7 +1136,7 @@ void ast_function_delete(ast_function *self) mem_d(self); } -const char* ast_function_label(ast_function *self, const char *prefix) +static const char* ast_function_label(ast_function *self, const char *prefix) { size_t id; size_t len; @@ -1132,7 +1170,7 @@ const char* ast_function_label(ast_function *self, const char *prefix) * But I can't imagine a pituation where the output is truly unnecessary. */ -void _ast_codegen_output_type(ast_expression_common *self, ir_value *out) +static void _ast_codegen_output_type(ast_expression_common *self, ir_value *out) { if (out->vtype == TYPE_FIELD) out->fieldtype = self->next->expression.vtype; @@ -1381,7 +1419,7 @@ error: /* clean up */ return false; } -bool ast_local_codegen(ast_value *self, ir_function *func, bool param) +static bool ast_local_codegen(ast_value *self, ir_function *func, bool param) { ir_value *v = NULL; diff --git a/ast.h b/ast.h index f18c73e..f130fb4 100644 --- a/ast.h +++ b/ast.h @@ -1,6 +1,7 @@ /* * Copyright (C) 2012, 2013 * Wolfgang Bumiller + * Dale Weiler * * 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 @@ -214,8 +215,11 @@ void ast_value_delete(ast_value*); bool ast_value_set_name(ast_value*, const char *name); +/* bool ast_value_codegen(ast_value*, ast_function*, bool lvalue, ir_value**); bool ast_local_codegen(ast_value *self, ir_function *func, bool isparam); +*/ + bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield); void ast_value_params_add(ast_value*, ast_value*); @@ -251,9 +255,6 @@ ast_binary* ast_binary_new(lex_ctx ctx, int op, ast_expression *left, ast_expression *right); -void ast_binary_delete(ast_binary*); - -bool ast_binary_codegen(ast_binary*, ast_function*, bool lvalue, ir_value**); /* Binstore * @@ -276,9 +277,6 @@ ast_binstore* ast_binstore_new(lex_ctx ctx, int op, ast_expression *left, ast_expression *right); -void ast_binstore_delete(ast_binstore*); - -bool ast_binstore_codegen(ast_binstore*, ast_function*, bool lvalue, ir_value**); /* Unary * @@ -294,9 +292,6 @@ struct ast_unary_s ast_unary* ast_unary_new(lex_ctx ctx, int op, ast_expression *expr); -void ast_unary_delete(ast_unary*); - -bool ast_unary_codegen(ast_unary*, ast_function*, bool lvalue, ir_value**); /* Return * @@ -311,9 +306,6 @@ struct ast_return_s }; ast_return* ast_return_new(lex_ctx ctx, ast_expression *expr); -void ast_return_delete(ast_return*); - -bool ast_return_codegen(ast_return*, ast_function*, bool lvalue, ir_value**); /* Entity-field * @@ -338,9 +330,6 @@ struct ast_entfield_s }; ast_entfield* ast_entfield_new(lex_ctx ctx, ast_expression *entity, ast_expression *field); ast_entfield* ast_entfield_new_force(lex_ctx ctx, ast_expression *entity, ast_expression *field, const ast_expression *outtype); -void ast_entfield_delete(ast_entfield*); - -bool ast_entfield_codegen(ast_entfield*, ast_function*, bool lvalue, ir_value**); /* Member access: * @@ -359,7 +348,6 @@ ast_member* ast_member_new(lex_ctx ctx, ast_expression *owner, unsigned int fiel void ast_member_delete(ast_member*); bool ast_member_set_name(ast_member*, const char *name); -bool ast_member_codegen(ast_member*, ast_function*, bool lvalue, ir_value**); /* Array index access: * @@ -378,9 +366,6 @@ struct ast_array_index_s ast_expression *index; }; ast_array_index* ast_array_index_new(lex_ctx ctx, ast_expression *array, ast_expression *index); -void ast_array_index_delete(ast_array_index*); - -bool ast_array_index_codegen(ast_array_index*, ast_function*, bool lvalue, ir_value**); /* Store * @@ -396,9 +381,6 @@ struct ast_store_s }; ast_store* ast_store_new(lex_ctx ctx, int op, ast_expression *d, ast_expression *s); -void ast_store_delete(ast_store*); - -bool ast_store_codegen(ast_store*, ast_function*, bool lvalue, ir_value**); /* If * @@ -420,9 +402,6 @@ struct ast_ifthen_s ast_expression *on_false; }; ast_ifthen* ast_ifthen_new(lex_ctx ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse); -void ast_ifthen_delete(ast_ifthen*); - -bool ast_ifthen_codegen(ast_ifthen*, ast_function*, bool lvalue, ir_value**); /* Ternary expressions... * @@ -446,9 +425,6 @@ struct ast_ternary_s ast_expression *on_false; }; ast_ternary* ast_ternary_new(lex_ctx ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse); -void ast_ternary_delete(ast_ternary*); - -bool ast_ternary_codegen(ast_ternary*, ast_function*, bool lvalue, ir_value**); /* A general loop node * @@ -496,9 +472,6 @@ ast_loop* ast_loop_new(lex_ctx ctx, ast_expression *postcond, bool post_not, ast_expression *increment, ast_expression *body); -void ast_loop_delete(ast_loop*); - -bool ast_loop_codegen(ast_loop*, ast_function*, bool lvalue, ir_value**); /* Break/Continue */ @@ -509,9 +482,6 @@ struct ast_breakcont_s unsigned int levels; }; ast_breakcont* ast_breakcont_new(lex_ctx ctx, bool iscont, unsigned int levels); -void ast_breakcont_delete(ast_breakcont*); - -bool ast_breakcont_codegen(ast_breakcont*, ast_function*, bool lvalue, ir_value**); /* Switch Statements * @@ -536,9 +506,6 @@ struct ast_switch_s }; ast_switch* ast_switch_new(lex_ctx ctx, ast_expression *op); -void ast_switch_delete(ast_switch*); - -bool ast_switch_codegen(ast_switch*, ast_function*, bool lvalue, ir_value**); /* Label nodes * @@ -555,10 +522,6 @@ struct ast_label_s }; ast_label* ast_label_new(lex_ctx ctx, const char *name, bool undefined); -void ast_label_delete(ast_label*); -void ast_label_register_goto(ast_label*, ast_goto*); - -bool ast_label_codegen(ast_label*, ast_function*, bool lvalue, ir_value**); /* GOTO nodes * @@ -573,11 +536,8 @@ struct ast_goto_s }; ast_goto* ast_goto_new(lex_ctx ctx, const char *name); -void ast_goto_delete(ast_goto*); void ast_goto_set_label(ast_goto*, ast_label*); -bool ast_goto_codegen(ast_goto*, ast_function*, bool lvalue, ir_value**); - /* CALL node * * Contains an ast_expression as target, rather than an ast_function/value. @@ -597,8 +557,6 @@ struct ast_call_s }; ast_call* ast_call_new(lex_ctx ctx, ast_expression *funcexpr); -void ast_call_delete(ast_call*); -bool ast_call_codegen(ast_call*, ast_function*, bool lvalue, ir_value**); bool ast_call_check_types(ast_call*); /* Blocks @@ -615,8 +573,6 @@ struct ast_block_s ast_block* ast_block_new(lex_ctx ctx); void ast_block_delete(ast_block*); void ast_block_set_type(ast_block*, ast_expression *from); - -bool ast_block_codegen(ast_block*, ast_function*, bool lvalue, ir_value**); void ast_block_collect(ast_block*, ast_expression*); bool GMQCC_WARN ast_block_add_expr(ast_block*, ast_expression*); @@ -673,7 +629,7 @@ void ast_function_delete(ast_function*); /* For "optimized" builds this can just keep returning "foo"... * or whatever... */ -const char* ast_function_label(ast_function*, const char *prefix); +/*const char* ast_function_label(ast_function*, const char *prefix);*/ bool ast_function_codegen(ast_function *self, ir_builder *builder); bool ast_generate_accessors(ast_value *asvalue, ir_builder *ir); diff --git a/conout.c b/conout.c index dd4dca3..2f72076 100644 --- a/conout.c +++ b/conout.c @@ -333,7 +333,7 @@ int con_out(const char *fmt, ...) { * for reporting of file:line based on lexer context, These are used * heavily in the parser/ir/ast. */ -void con_vprintmsg_c(int level, const char *name, size_t line, const char *msgtype, const char *msg, va_list ap, const char *condname) { +static void con_vprintmsg_c(int level, const char *name, size_t line, const char *msgtype, const char *msg, va_list ap, const char *condname) { /* color selection table */ static int sel[] = { CON_WHITE, diff --git a/ftepp.c b/ftepp.c index 9fc0025..f8d41d9 100644 --- a/ftepp.c +++ b/ftepp.c @@ -81,7 +81,7 @@ static uint32_t ftepp_predef_countval = 0; static uint32_t ftepp_predef_randval = 0; /* __DATE__ */ -char *ftepp_predef_date(lex_file *context) { +static char *ftepp_predef_date(lex_file *context) { struct tm *itime = NULL; time_t rtime; char *value = (char*)mem_a(82); @@ -104,7 +104,7 @@ char *ftepp_predef_date(lex_file *context) { } /* __TIME__ */ -char *ftepp_predef_time(lex_file *context) { +static char *ftepp_predef_time(lex_file *context) { struct tm *itime = NULL; time_t rtime; char *value = (char*)mem_a(82); @@ -127,13 +127,13 @@ char *ftepp_predef_time(lex_file *context) { } /* __LINE__ */ -char *ftepp_predef_line(lex_file *context) { +static char *ftepp_predef_line(lex_file *context) { char *value; util_asprintf(&value, "%d", (int)context->line); return value; } /* __FILE__ */ -char *ftepp_predef_file(lex_file *context) { +static char *ftepp_predef_file(lex_file *context) { size_t length = strlen(context->name) + 3; /* two quotes and a terminator */ char *value = (char*)mem_a(length); util_snprintf(value, length, "\"%s\"", context->name); @@ -141,7 +141,7 @@ char *ftepp_predef_file(lex_file *context) { return value; } /* __COUNTER_LAST__ */ -char *ftepp_predef_counterlast(lex_file *context) { +static char *ftepp_predef_counterlast(lex_file *context) { char *value; util_asprintf(&value, "%u", ftepp_predef_countval); @@ -149,7 +149,7 @@ char *ftepp_predef_counterlast(lex_file *context) { return value; } /* __COUNTER__ */ -char *ftepp_predef_counter(lex_file *context) { +static char *ftepp_predef_counter(lex_file *context) { char *value; ftepp_predef_countval ++; util_asprintf(&value, "%u", ftepp_predef_countval); @@ -158,7 +158,7 @@ char *ftepp_predef_counter(lex_file *context) { return value; } /* __RANDOM__ */ -char *ftepp_predef_random(lex_file *context) { +static char *ftepp_predef_random(lex_file *context) { char *value; ftepp_predef_randval = (util_rand() % 0xFF) + 1; util_asprintf(&value, "%u", ftepp_predef_randval); @@ -167,7 +167,7 @@ char *ftepp_predef_random(lex_file *context) { return value; } /* __RANDOM_LAST__ */ -char *ftepp_predef_randomlast(lex_file *context) { +static char *ftepp_predef_randomlast(lex_file *context) { char *value; util_asprintf(&value, "%u", ftepp_predef_randval); @@ -175,7 +175,7 @@ char *ftepp_predef_randomlast(lex_file *context) { return value; } /* __TIMESTAMP__ */ -char *ftepp_predef_timestamp(lex_file *context) { +static char *ftepp_predef_timestamp(lex_file *context) { struct stat finfo; char *find; char *value; diff --git a/intrin.h b/intrin.h index 4f672dd..81af620 100644 --- a/intrin.h +++ b/intrin.h @@ -36,7 +36,7 @@ typedef struct { const char *alias; } intrin_t; -ht intrin_intrinsics() { +static ht intrin_intrinsics() { static ht intrinsics = NULL; if (!intrinsics) intrinsics = util_htnew(PARSER_HT_SIZE); @@ -69,12 +69,10 @@ ht intrin_intrinsics() { vec_push(parser->globals, (ast_expression*)(VALUE)); \ } while (0) - -ast_expression *intrin_func (parser_t *parser, const char *name); - #define QC_M_E 2.71828182845905 -ast_expression *intrin_pow(parser_t *parser) { +static ast_expression *intrin_func(parser_t *parser, const char *name); +static ast_expression *intrin_pow (parser_t *parser) { /* * float pow(float x, float y) { * float local = 1.0f; @@ -221,7 +219,7 @@ ast_expression *intrin_pow(parser_t *parser) { return (ast_expression*)value; } -ast_expression *intrin_mod(parser_t *parser) { +static ast_expression *intrin_mod(parser_t *parser) { /* * float mod(float x, float y) { * return x - y * floor(x / y); @@ -276,7 +274,7 @@ ast_expression *intrin_mod(parser_t *parser) { return (ast_expression*)value; } -ast_expression *intrin_exp(parser_t *parser) { +static ast_expression *intrin_exp(parser_t *parser) { /* * float exp(float x) { * return pow(QC_M_E, x); @@ -314,7 +312,7 @@ ast_expression *intrin_exp(parser_t *parser) { return (ast_expression*)value; } -ast_expression *intrin_isnan(parser_t *parser) { +static ast_expression *intrin_isnan(parser_t *parser) { /* * float isnan(float x) { * float local; @@ -383,7 +381,7 @@ void intrin_intrinsics_destroy(parser_t *parser) { } -ast_expression *intrin_func(parser_t *parser, const char *name) { +static ast_expression *intrin_func(parser_t *parser, const char *name) { static bool init = false; size_t i = 0; void *find; diff --git a/ir.c b/ir.c index b67a37c..5dae734 100644 --- a/ir.c +++ b/ir.c @@ -1,6 +1,7 @@ /* * Copyright (C) 2012, 2013 * Wolfgang Bumiller + * Dale Weiler * * 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 @@ -211,9 +212,31 @@ const uint16_t type_not_instr[TYPE_COUNT] = { }; /* protos */ -static ir_value* ir_gen_extparam_proto(ir_builder *ir); -static void ir_gen_extparam (code_t *, ir_builder *ir); - +static ir_value* ir_value_var(const char *name, int st, int vtype); +static bool ir_value_set_name(ir_value*, const char *name); +static void ir_value_dump(ir_value*, int (*oprintf)(const char*,...)); + +static ir_value* ir_gen_extparam_proto(ir_builder *ir); +static void ir_gen_extparam (code_t *, ir_builder *ir); + +static bool ir_builder_set_name(ir_builder *self, const char *name); + +static ir_function* ir_function_new(struct ir_builder_s *owner, int returntype); +static bool ir_function_set_name(ir_function*, const char *name); +static void ir_function_delete(ir_function*); +static void ir_function_dump(ir_function*, char *ind, int (*oprintf)(const char*,...)); + +static ir_value* ir_block_create_general_instr(ir_block *self, lex_ctx, const char *label, + int op, ir_value *a, ir_value *b, int outype); +static void ir_block_delete(ir_block*); +static ir_block* ir_block_new(struct ir_function_s *owner, const char *label); +static bool GMQCC_WARN ir_block_create_store(ir_block*, lex_ctx, ir_value *target, ir_value *what); +static bool ir_block_set_label(ir_block*, const char *label); +static void ir_block_dump(ir_block*, char *ind, int (*oprintf)(const char*,...)); + +static bool ir_instr_op(ir_instr*, int op, ir_value *value, bool writing); +static void ir_instr_delete(ir_instr*); +static void ir_instr_dump(ir_instr* in, char *ind, int (*oprintf)(const char*,...)); /* error functions */ static void irerror(lex_ctx ctx, const char *msg, ...) @@ -238,7 +261,7 @@ static bool irwarning(lex_ctx ctx, int warntype, const char *fmt, ...) * Vector utility functions */ -bool GMQCC_WARN vec_ir_value_find(ir_value **vec, const ir_value *what, size_t *idx) +static bool GMQCC_WARN vec_ir_value_find(ir_value **vec, const ir_value *what, size_t *idx) { size_t i; size_t len = vec_size(vec); @@ -251,7 +274,7 @@ bool GMQCC_WARN vec_ir_value_find(ir_value **vec, const ir_value *what, size_t * return false; } -bool GMQCC_WARN vec_ir_block_find(ir_block **vec, ir_block *what, size_t *idx) +static bool GMQCC_WARN vec_ir_block_find(ir_block **vec, ir_block *what, size_t *idx) { size_t i; size_t len = vec_size(vec); @@ -264,7 +287,7 @@ bool GMQCC_WARN vec_ir_block_find(ir_block **vec, ir_block *what, size_t *idx) return false; } -bool GMQCC_WARN vec_ir_instr_find(ir_instr **vec, ir_instr *what, size_t *idx) +static bool GMQCC_WARN vec_ir_instr_find(ir_instr **vec, ir_instr *what, size_t *idx) { size_t i; size_t len = vec_size(vec); @@ -363,7 +386,7 @@ bool ir_builder_set_name(ir_builder *self, const char *name) return !!self->name; } -ir_function* ir_builder_get_function(ir_builder *self, const char *name) +static ir_function* ir_builder_get_function(ir_builder *self, const char *name) { return (ir_function*)util_htget(self->htfunctions, name); } @@ -398,7 +421,7 @@ ir_function* ir_builder_create_function(ir_builder *self, const char *name, int return fn; } -ir_value* ir_builder_get_global(ir_builder *self, const char *name) +static ir_value* ir_builder_get_global(ir_builder *self, const char *name) { return (ir_value*)util_htget(self->htglobals, name); } @@ -428,7 +451,7 @@ ir_value* ir_builder_get_va_count(ir_builder *self) return (self->reserved_va_count = ir_builder_create_global(self, "reserved:va_count", TYPE_FLOAT)); } -ir_value* ir_builder_get_field(ir_builder *self, const char *name) +static ir_value* ir_builder_get_field(ir_builder *self, const char *name) { return (ir_value*)util_htget(self->htfields, name); } @@ -452,10 +475,10 @@ ir_value* ir_builder_create_field(ir_builder *self, const char *name, int vtype) *IR Function */ -bool ir_function_naive_phi(ir_function*); -void ir_function_enumerate(ir_function*); -bool ir_function_calculate_liferanges(ir_function*); -bool ir_function_allocate_locals(ir_function*); +static bool ir_function_naive_phi(ir_function*); +static void ir_function_enumerate(ir_function*); +static bool ir_function_calculate_liferanges(ir_function*); +static bool ir_function_allocate_locals(ir_function*); ir_function* ir_function_new(ir_builder* owner, int outtype) { @@ -552,7 +575,7 @@ void ir_function_delete(ir_function *self) mem_d(self); } -void ir_function_collect_value(ir_function *self, ir_value *v) +static void ir_function_collect_value(ir_function *self, ir_value *v) { vec_push(self->values, v); } @@ -575,7 +598,7 @@ static bool instr_is_operation(uint16_t op) (op >= INSTR_CALL0 && op <= INSTR_CALL8) ); } -bool ir_function_pass_peephole(ir_function *self) +static bool ir_function_pass_peephole(ir_function *self) { size_t b; @@ -691,7 +714,7 @@ bool ir_function_pass_peephole(ir_function *self) return true; } -bool ir_function_pass_tailrecursion(ir_function *self) +static bool ir_function_pass_tailrecursion(ir_function *self) { size_t b, p; @@ -927,7 +950,7 @@ bool ir_block_set_label(ir_block *self, const char *name) *IR Instructions */ -ir_instr* ir_instr_new(lex_ctx ctx, ir_block* owner, int op) +static ir_instr* ir_instr_new(lex_ctx ctx, ir_block* owner, int op) { ir_instr *self; self = (ir_instr*)mem_a(sizeof(*self)); @@ -959,7 +982,7 @@ static void ir_instr_delete_quick(ir_instr *self) mem_d(self); } -void ir_instr_delete(ir_instr *self) +static void ir_instr_delete(ir_instr *self) { size_t i; /* The following calls can only delete from @@ -990,7 +1013,7 @@ void ir_instr_delete(ir_instr *self) mem_d(self); } -bool ir_instr_op(ir_instr *self, int op, ir_value *v, bool writing) +static bool ir_instr_op(ir_instr *self, int op, ir_value *v, bool writing) { if (self->_ops[op]) { size_t idx; @@ -1013,7 +1036,7 @@ bool ir_instr_op(ir_instr *self, int op, ir_value *v, bool writing) *IR Value */ -void ir_value_code_setaddr(ir_value *self, int32_t gaddr) +static void ir_value_code_setaddr(ir_value *self, int32_t gaddr) { self->code.globaladdr = gaddr; if (self->members[0]) self->members[0]->code.globaladdr = gaddr; @@ -1021,7 +1044,7 @@ void ir_value_code_setaddr(ir_value *self, int32_t gaddr) if (self->members[2]) self->members[2]->code.globaladdr = gaddr; } -int32_t ir_value_code_addr(const ir_value *self) +static int32_t ir_value_code_addr(const ir_value *self) { if (self->store == store_return) return OFS_RETURN + self->code.addroffset; @@ -1134,7 +1157,7 @@ static GMQCC_INLINE size_t ir_value_sizeof(const ir_value *self) return type_sizeof_[self->vtype]; } -ir_value* ir_value_out(ir_function *owner, const char *name, int storetype, int vtype) +static ir_value* ir_value_out(ir_function *owner, const char *name, int storetype, int vtype) { ir_value *v = ir_value_var(name, storetype, vtype); if (!v) @@ -1241,7 +1264,7 @@ bool ir_value_lives(ir_value *self, size_t at) return false; } -bool ir_value_life_insert(ir_value *self, size_t idx, ir_life_entry_t e) +static bool ir_value_life_insert(ir_value *self, size_t idx, ir_life_entry_t e) { size_t k; vec_push(self->life, e); @@ -1251,7 +1274,7 @@ bool ir_value_life_insert(ir_value *self, size_t idx, ir_life_entry_t e) return true; } -bool ir_value_life_merge(ir_value *self, size_t s) +static bool ir_value_life_merge(ir_value *self, size_t s) { size_t i; const size_t vs = vec_size(self->life); @@ -1314,7 +1337,7 @@ bool ir_value_life_merge(ir_value *self, size_t s) return ir_value_life_insert(self, i, new_entry); } -bool ir_value_life_merge_into(ir_value *self, const ir_value *other) +static bool ir_value_life_merge_into(ir_value *self, const ir_value *other) { size_t i, myi; @@ -1388,7 +1411,7 @@ bool ir_value_life_merge_into(ir_value *self, const ir_value *other) return true; } -bool ir_values_overlap(const ir_value *a, const ir_value *b) +static bool ir_values_overlap(const ir_value *a, const ir_value *b) { /* For any life entry in A see if it overlaps with * any life entry in B. @@ -1484,7 +1507,7 @@ bool ir_block_create_store_op(ir_block *self, lex_ctx ctx, int op, ir_value *tar return true; } -bool ir_block_create_store(ir_block *self, lex_ctx ctx, ir_value *target, ir_value *what) +static bool ir_block_create_store(ir_block *self, lex_ctx ctx, ir_value *target, ir_value *what) { int op = 0; int vtype; @@ -1827,7 +1850,7 @@ ir_value* ir_block_create_unary(ir_block *self, lex_ctx ctx, return ir_block_create_general_instr(self, ctx, label, opcode, operand, NULL, ot); } -ir_value* ir_block_create_general_instr(ir_block *self, lex_ctx ctx, const char *label, +static ir_value* ir_block_create_general_instr(ir_block *self, lex_ctx ctx, const char *label, int op, ir_value *a, ir_value *b, int outype) { ir_instr *instr; @@ -3686,7 +3709,7 @@ bool ir_builder_generate(code_t *code, ir_builder *self, const char *filename) # define strncat(dst, src, sz) strncat_s(dst, sz, src, _TRUNCATE) #endif -const char *qc_opname(int op) +static const char *qc_opname(int op) { if (op < 0) return ""; if (op < (int)( sizeof(asm_instr) / sizeof(asm_instr[0]) )) @@ -3838,7 +3861,7 @@ void ir_block_dump(ir_block* b, char *ind, ind[strlen(ind)-1] = 0; } -void dump_phi(ir_instr *in, int (*oprintf)(const char*, ...)) +static void dump_phi(ir_instr *in, int (*oprintf)(const char*, ...)) { size_t i; oprintf("%s <- phi ", in->_ops[0]->name); @@ -3908,7 +3931,7 @@ void ir_instr_dump(ir_instr *in, char *ind, ind[strlen(ind)-1] = 0; } -void ir_value_dump_string(const char *str, int (*oprintf)(const char*, ...)) +static void ir_value_dump_string(const char *str, int (*oprintf)(const char*, ...)) { oprintf("\""); for (; *str; ++str) { diff --git a/ir.h b/ir.h index dac16a3..cd38295 100644 --- a/ir.h +++ b/ir.h @@ -23,7 +23,6 @@ #ifndef GMQCC_IR_HDR #define GMQCC_IR_HDR #include "gmqcc.h" -/* ir_value */ typedef struct { @@ -86,42 +85,19 @@ typedef struct ir_value_s { ir_life_entry_t *life; } ir_value; -int32_t ir_value_code_addr(const ir_value*); - /* ir_value can be a variable, or created by an operation */ -ir_value* ir_value_var(const char *name, int st, int vtype); /* if a result of an operation: the function should store * it to remember to delete it / garbage collect it */ -ir_value* ir_value_out(struct ir_function_s *owner, const char *name, int st, int vtype); -void ir_value_delete(ir_value*); -bool ir_value_set_name(ir_value*, const char *name); -ir_value* ir_value_vector_member(ir_value*, unsigned int member); - -bool GMQCC_WARN vec_ir_value_find(ir_value **vec, const ir_value *what, size_t *idx); - +void ir_value_delete(ir_value*); +ir_value* ir_value_vector_member(ir_value*, unsigned int member); bool GMQCC_WARN ir_value_set_float(ir_value*, float f); bool GMQCC_WARN ir_value_set_func(ir_value*, int f); -#if 0 -bool GMQCC_WARN ir_value_set_int(ir_value*, int i); -#endif bool GMQCC_WARN ir_value_set_string(ir_value*, const char *s); bool GMQCC_WARN ir_value_set_vector(ir_value*, vector v); bool GMQCC_WARN ir_value_set_field(ir_value*, ir_value *fld); -/*bool ir_value_set_pointer_v(ir_value*, ir_value* p); */ -/*bool ir_value_set_pointer_i(ir_value*, int i); */ - -/* merge an instruction into the life-range */ -/* returns false if the lifepoint was already known */ -bool ir_value_life_merge(ir_value*, size_t); -bool ir_value_life_merge_into(ir_value*, const ir_value*); -/* check if a value lives at a specific point */ -bool ir_value_lives(ir_value*, size_t); -/* check if the life-range of 2 values overlaps */ -bool ir_values_overlap(const ir_value*, const ir_value*); - -void ir_value_dump(ir_value*, int (*oprintf)(const char*,...)); -void ir_value_dump_life(const ir_value *self, int (*oprintf)(const char*,...)); +bool ir_value_lives(ir_value*, size_t); +void ir_value_dump_life(const ir_value *self, int (*oprintf)(const char*,...)); /* PHI data */ typedef struct ir_phi_entry_s @@ -150,15 +126,6 @@ typedef struct ir_instr_s struct ir_block_s *owner; } ir_instr; -ir_instr* ir_instr_new(lex_ctx ctx, struct ir_block_s *owner, int opcode); -void ir_instr_delete(ir_instr*); - -bool GMQCC_WARN vec_ir_instr_find(ir_instr **vec, ir_instr *what, size_t *idx); - -bool ir_instr_op(ir_instr*, int op, ir_value *value, bool writing); - -void ir_instr_dump(ir_instr* in, char *ind, int (*oprintf)(const char*,...)); - /* block */ typedef struct ir_block_s { @@ -182,30 +149,16 @@ typedef struct ir_block_s size_t code_start; } ir_block; -ir_block* ir_block_new(struct ir_function_s *owner, const char *label); -void ir_block_delete(ir_block*); - -bool ir_block_set_label(ir_block*, const char *label); - -ir_value* ir_block_create_binop(ir_block*, lex_ctx, const char *label, int op, - ir_value *left, ir_value *right); -ir_value* ir_block_create_unary(ir_block*, lex_ctx, const char *label, int op, - ir_value *operand); +ir_value* ir_block_create_binop(ir_block*, lex_ctx, const char *label, int op, ir_value *left, ir_value *right); +ir_value* ir_block_create_unary(ir_block*, lex_ctx, const char *label, int op, ir_value *operand); bool GMQCC_WARN ir_block_create_store_op(ir_block*, lex_ctx, int op, ir_value *target, ir_value *what); -bool GMQCC_WARN ir_block_create_store(ir_block*, lex_ctx, ir_value *target, ir_value *what); bool GMQCC_WARN ir_block_create_storep(ir_block*, lex_ctx, ir_value *target, ir_value *what); - -/* field must be of TYPE_FIELD */ -ir_value* ir_block_create_load_from_ent(ir_block*, lex_ctx, const char *label, ir_value *ent, ir_value *field, int outype); - -ir_value* ir_block_create_fieldaddress(ir_block*, lex_ctx, const char *label, ir_value *entity, ir_value *field); +ir_value* ir_block_create_load_from_ent(ir_block*, lex_ctx, const char *label, ir_value *ent, ir_value *field, int outype); +ir_value* ir_block_create_fieldaddress(ir_block*, lex_ctx, const char *label, ir_value *entity, ir_value *field); /* This is to create an instruction of the form * %label := opcode a, b */ -ir_value* ir_block_create_general_instr(ir_block *self, lex_ctx, const char *label, - int op, ir_value *a, ir_value *b, int outype); - ir_instr* ir_block_create_phi(ir_block*, lex_ctx, const char *label, int vtype); ir_value* ir_phi_value(ir_instr*); void ir_phi_add(ir_instr*, ir_block *b, ir_value *v); @@ -226,10 +179,7 @@ bool GMQCC_WARN ir_block_create_if(ir_block*, lex_ctx, ir_value *cond, bool GMQCC_WARN ir_block_create_jump(ir_block*, lex_ctx, ir_block *to); bool GMQCC_WARN ir_block_create_goto(ir_block*, lex_ctx, ir_block *to); -void ir_block_dump(ir_block*, char *ind, int (*oprintf)(const char*,...)); - /* function */ - typedef struct ir_function_s { char *name; @@ -276,6 +226,7 @@ typedef struct ir_function_s /* vararg support: */ size_t max_varargs; } ir_function; + #define IR_FLAG_HAS_ARRAYS (1<<1) #define IR_FLAG_HAS_UNINITIALIZED (1<<2) #define IR_FLAG_HAS_GOTO (1<<3) @@ -283,25 +234,9 @@ typedef struct ir_function_s #define IR_FLAG_MASK_NO_OVERLAP (IR_FLAG_HAS_ARRAYS | IR_FLAG_HAS_UNINITIALIZED) #define IR_FLAG_MASK_NO_LOCAL_TEMPS (IR_FLAG_HAS_ARRAYS | IR_FLAG_HAS_UNINITIALIZED) -ir_function* ir_function_new(struct ir_builder_s *owner, int returntype); -void ir_function_delete(ir_function*); - -void ir_function_collect_value(ir_function*, ir_value *value); - -bool ir_function_set_name(ir_function*, const char *name); - -ir_value* ir_function_create_local(ir_function *self, const char *name, int vtype, bool param); - +ir_value* ir_function_create_local(ir_function *self, const char *name, int vtype, bool param); bool GMQCC_WARN ir_function_finalize(ir_function*); -/* -bool ir_function_naive_phi(ir_function*); -bool ir_function_enumerate(ir_function*); -bool ir_function_calculate_liferanges(ir_function*); -*/ - -ir_block* ir_function_create_block(lex_ctx ctx, ir_function*, const char *label); - -void ir_function_dump(ir_function*, char *ind, int (*oprintf)(const char*,...)); +ir_block* ir_function_create_block(lex_ctx ctx, ir_function*, const char *label); /* builder */ #define IR_HT_SIZE 1024 @@ -334,25 +269,14 @@ typedef struct ir_builder_s ir_value *reserved_va_count; } ir_builder; -ir_builder* ir_builder_new(const char *modulename); -void ir_builder_delete(ir_builder*); - -bool ir_builder_set_name(ir_builder *self, const char *name); - -ir_function* ir_builder_get_function(ir_builder*, const char *fun); +ir_builder* ir_builder_new(const char *modulename); +void ir_builder_delete(ir_builder*); ir_function* ir_builder_create_function(ir_builder*, const char *name, int outtype); - -ir_value* ir_builder_get_global(ir_builder*, const char *fun); -ir_value* ir_builder_create_global(ir_builder*, const char *name, int vtype); -ir_value* ir_builder_get_field(ir_builder*, const char *fun); -ir_value* ir_builder_create_field(ir_builder*, const char *name, int vtype); - -ir_value* ir_builder_get_va_count(ir_builder*); - -bool ir_builder_generate(code_t *, ir_builder *self, const char *filename); - -void ir_builder_dump(ir_builder*, int (*oprintf)(const char*, ...)); - +ir_value* ir_builder_create_global(ir_builder*, const char *name, int vtype); +ir_value* ir_builder_create_field(ir_builder*, const char *name, int vtype); +ir_value* ir_builder_get_va_count(ir_builder*); +bool ir_builder_generate(code_t *, ir_builder *self, const char *filename); +void ir_builder_dump(ir_builder*, int (*oprintf)(const char*, ...)); /* * This code assumes 32 bit floats while generating binary diff --git a/lexer.c b/lexer.c index 7722f4f..035dc1b 100644 --- a/lexer.c +++ b/lexer.c @@ -60,7 +60,7 @@ static size_t num_keywords_fg = sizeof(keywords_fg) / sizeof(keywords_fg[0]); static char* *lex_filenames; -void lexerror(lex_file *lex, const char *fmt, ...) +static void lexerror(lex_file *lex, const char *fmt, ...) { va_list ap; @@ -72,7 +72,7 @@ void lexerror(lex_file *lex, const char *fmt, ...) va_end(ap); } -bool lexwarn(lex_file *lex, int warntype, const char *fmt, ...) +static bool lexwarn(lex_file *lex, int warntype, const char *fmt, ...) { bool r; lex_ctx ctx; diff --git a/lexer.h b/lexer.h index 2573fb2..5f0bb63 100644 --- a/lexer.h +++ b/lexer.h @@ -340,6 +340,6 @@ static const size_t qcc_operator_count = (sizeof(qcc_operators) / sizeof(qcc_ope extern const oper_info *operators; extern size_t operator_count; -void lexerror(lex_file*, const char *fmt, ...); +/*void lexerror(lex_file*, const char *fmt, ...);*/ #endif diff --git a/pak.c b/pak.c index 048469b..9ff7e78 100644 --- a/pak.c +++ b/pak.c @@ -222,7 +222,7 @@ static pak_file_t *pak_open_write(const char *file) { return pak; } -pak_file_t *pak_open(const char *file, const char *mode) { +static pak_file_t *pak_open(const char *file, const char *mode) { if (!file || !mode) return NULL; @@ -234,7 +234,7 @@ pak_file_t *pak_open(const char *file, const char *mode) { return NULL; } -bool pak_exists(pak_file_t *pak, const char *file, pak_directory_t **dir) { +static bool pak_exists(pak_file_t *pak, const char *file, pak_directory_t **dir) { size_t itr; if (!pak || !file) @@ -259,7 +259,7 @@ bool pak_exists(pak_file_t *pak, const char *file, pak_directory_t **dir) { /* * Extraction abilities. These work as you expect them to. */ -bool pak_extract_one(pak_file_t *pak, const char *file, const char *outdir) { +static bool pak_extract_one(pak_file_t *pak, const char *file, const char *outdir) { pak_directory_t *dir = NULL; unsigned char *dat = NULL; char *local = NULL; @@ -310,7 +310,7 @@ bool pak_extract_one(pak_file_t *pak, const char *file, const char *outdir) { return true; } -bool pak_extract_all(pak_file_t *pak, const char *dir) { +static bool pak_extract_all(pak_file_t *pak, const char *dir) { size_t itr; if (!fs_dir_make(dir)) @@ -328,7 +328,7 @@ bool pak_extract_all(pak_file_t *pak, const char *dir) { * Insertion functions (the opposite of extraction). Yes for generating * PAKs. */ -bool pak_insert_one(pak_file_t *pak, const char *file) { +static bool pak_insert_one(pak_file_t *pak, const char *file) { pak_directory_t dir; unsigned char *dat; FILE *fp; @@ -413,7 +413,7 @@ bool pak_insert_all(pak_file_t *pak, const char *dir) { return true; } -bool pak_close(pak_file_t *pak) { +static bool pak_close(pak_file_t *pak) { size_t itr; if (!pak) diff --git a/parser.c b/parser.c index da9d33a..6d0c010 100644 --- a/parser.c +++ b/parser.c @@ -185,7 +185,7 @@ vector vec3_mulvf(vector a, float b) * parsing */ -bool parser_next(parser_t *parser) +static bool parser_next(parser_t *parser) { /* lex_do kills the previous token */ parser->tok = lex_do(parser->lex); @@ -6069,7 +6069,7 @@ parser_t *parser_create() return parser; } -bool parser_compile(parser_t *parser) +static bool parser_compile(parser_t *parser) { /* initial lexer/parser state */ parser->lex->flags.noops = true; diff --git a/test.c b/test.c index 7722af2..2febbff 100644 --- a/test.c +++ b/test.c @@ -60,7 +60,7 @@ typedef struct { int pid; } popen_t; -FILE ** task_popen(const char *command, const char *mode) { +static FILE ** task_popen(const char *command, const char *mode) { int inhandle [2]; int outhandle [2]; int errhandle [2]; @@ -137,7 +137,7 @@ task_popen_error_0: return NULL; } -int task_pclose(FILE **handles) { +static int task_pclose(FILE **handles) { popen_t *data = (popen_t*)handles; int status = 0; @@ -158,7 +158,7 @@ int task_pclose(FILE **handles) { char name_out[L_tmpnam]; } popen_t; - FILE **task_popen(const char *command, const char *mode) { + static FILE **task_popen(const char *command, const char *mode) { char *cmd = NULL; popen_t *open = (popen_t*)mem_a(sizeof(popen_t)); @@ -179,7 +179,7 @@ int task_pclose(FILE **handles) { return open->handles; } - void task_pclose(FILE **files) { + static void task_pclose(FILE **files) { popen_t *open = ((popen_t*)files); fs_file_close(files[1]); fs_file_close(files[2]); @@ -281,7 +281,7 @@ typedef struct { * This is very much like a compiler code generator :-). This generates * a value from some data observed from the compiler. */ -bool task_template_generate(task_template_t *tmpl, char tag, const char *file, size_t line, char *value, size_t *pad) { +static bool task_template_generate(task_template_t *tmpl, char tag, const char *file, size_t line, char *value, size_t *pad) { size_t desclen = 0; size_t filelen = 0; char **destval = NULL; @@ -354,7 +354,7 @@ bool task_template_generate(task_template_t *tmpl, char tag, const char *file, s return true; } -bool task_template_parse(const char *file, task_template_t *tmpl, FILE *fp, size_t *pad) { +static bool task_template_parse(const char *file, task_template_t *tmpl, FILE *fp, size_t *pad) { char *data = NULL; char *back = NULL; size_t size = 0; @@ -480,7 +480,7 @@ failure: * Nullifies the template data: used during initialization of a new * template and free. */ -void task_template_nullify(task_template_t *tmpl) { +static void task_template_nullify(task_template_t *tmpl) { if (!tmpl) return; @@ -495,7 +495,7 @@ void task_template_nullify(task_template_t *tmpl) { tmpl->testflags = NULL; } -task_template_t *task_template_compile(const char *file, const char *dir, size_t *pad) { +static task_template_t *task_template_compile(const char *file, const char *dir, size_t *pad) { /* a page should be enough */ char fullfile[4096]; size_t filepadd = 0; @@ -609,7 +609,7 @@ failure: return NULL; } -void task_template_destroy(task_template_t **tmpl) { +static void task_template_destroy(task_template_t **tmpl) { if (!tmpl) return; @@ -660,7 +660,7 @@ static task_t *task_tasks = NULL; * Read a directory and searches for all template files in it * which is later used to run all tests. */ -bool task_propagate(const char *curdir, size_t *pad, const char *defs) { +static bool task_propagate(const char *curdir, size_t *pad, const char *defs) { bool success = true; DIR *dir; struct dirent *files; @@ -840,7 +840,7 @@ bool task_propagate(const char *curdir, size_t *pad, const char *defs) { * Task precleanup removes any existing temporary files or log files * left behind from a previous invoke of the test-suite. */ -void task_precleanup(const char *curdir) { +static void task_precleanup(const char *curdir) { DIR *dir; struct dirent *files; char buffer[4096]; @@ -863,7 +863,7 @@ void task_precleanup(const char *curdir) { fs_dir_close(dir); } -void task_destroy(void) { +static void task_destroy(void) { /* * Free all the data in the task list and finally the list itself * then proceed to cleanup anything else outside the program like @@ -912,7 +912,7 @@ void task_destroy(void) { * messages IF the procedure type is -execute, otherwise it matches * the preprocessor output. */ -bool task_trymatch(task_template_t *tmpl, char ***line) { +static bool task_trymatch(task_template_t *tmpl, char ***line) { bool success = true; bool preprocessing = false; FILE *execute; @@ -1020,7 +1020,7 @@ bool task_trymatch(task_template_t *tmpl, char ***line) { return success; } -const char *task_type(task_template_t *tmpl) { +static const char *task_type(task_template_t *tmpl) { if (!strcmp(tmpl->proceduretype, "-pp")) return "type: preprocessor"; if (!strcmp(tmpl->proceduretype, "-execute")) @@ -1037,7 +1037,7 @@ const char *task_type(task_template_t *tmpl) { * from thin air and executed INLINE. */ #include -void task_schedualize(size_t *pad) { +static void task_schedualize(size_t *pad) { char space[2][64]; bool execute = false; char *data = NULL; @@ -1210,7 +1210,7 @@ void task_schedualize(size_t *pad) { * * It expects con_init() was called before hand. */ -GMQCC_WARN bool test_perform(const char *curdir, const char *defs) { +static GMQCC_WARN bool test_perform(const char *curdir, const char *defs) { static const char *default_defs = "defs.qh"; size_t pad[] = { diff --git a/util.c b/util.c index c8d50f5..d695ae6 100644 --- a/util.c +++ b/util.c @@ -491,7 +491,7 @@ GMQCC_INLINE size_t util_hthash(hash_table_t *ht, const char *key) { return (size_t) (hash % ht->size); } -hash_node_t *_util_htnewpair(const char *key, void *value) { +static hash_node_t *_util_htnewpair(const char *key, void *value) { hash_node_t *node; if (!(node = (hash_node_t*)mem_a(sizeof(hash_node_t)))) return NULL;