From: Matthias Braun Date: Sat, 2 Jan 2010 13:57:38 +0000 (+0000) Subject: cleanup dbginfo public API: no dbg_snprint anymore X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=bf3972bf795dc4ff83de4f14a96e520c6533427b;p=libfirm cleanup dbginfo public API: no dbg_snprint anymore (there is retrieve_dbginfo stuff already there! And don't tell me about possible future extensions where sets of locations are merged and someone generates usefull debug info from that. Noone uses this currently!) [r26878] --- diff --git a/include/libfirm/dbginfo.h b/include/libfirm/dbginfo.h index b6c538c1d..fde55fcd1 100644 --- a/include/libfirm/dbginfo.h +++ b/include/libfirm/dbginfo.h @@ -119,26 +119,9 @@ typedef void merge_pair_func(ir_node *new_node, ir_node *old_node, dbg_action ac */ typedef void merge_sets_func(ir_node **new_node_array, int new_num_entries, ir_node **old_node_array, int old_num_entries, dbg_action action); -/** - * The type of the debug info to human readable string function. - * - * @param buf pointer to a buffer that will hold the info - * @param len length of the buffer - * @param dbg the debug info - * - * @return Number of written characters to the buffer. - * - * @see dbg_init() - */ -typedef unsigned snprint_dbg_func(char *buf, unsigned len, const dbg_info *dbg); - /** * Initializes the debug support. * - * @param dbg_info_merge_pair see function description - * @param dbg_info_merge_sets see function description - * @param snprint_dbg see function description - * * This function takes pointers to two functions that merge the * debug information when a * transformation of a Firm graph is performed. @@ -158,43 +141,18 @@ typedef unsigned snprint_dbg_func(char *buf, unsigned len, const dbg_info *dbg); * * Further both functions pass an enumeration indicating the action * performed by the transformation, e.g. the kind of optimization performed. - * - * The third argument snprint_dbg is called to convert a debug info into a human readable string. - * This string is the dumped in the dumper functions. - * - * Note that if NULL is passed for dbg_info_merge_pair or dbg_info_merge_sets, the default - * implementations default_dbg_info_merge_pair() and default_dbg_info_merge_sets() are used. - * NULL passed for snprint_dbg means no output. */ -void dbg_init(merge_pair_func *dbg_info_merge_pair, merge_sets_func *dbg_info_merge_sets, snprint_dbg_func *snprint_dbg); +void dbg_init(merge_pair_func *dbg_info_merge_pair, + merge_sets_func *dbg_info_merge_sets); -/** - * The default merge_pair_func implementation, simply copies the debug info - * from the old Firm node to the new one if the new one does not have debug info yet. - * - * @param nw The new Firm node. - * @param old The old Firm node. - * @param info The action that cause old node to be replaced by new one. - */ -void default_dbg_info_merge_pair(ir_node *nw, ir_node *old, dbg_action info); +/** @} */ /** - * The default merge_sets_func implementation. If n_old_nodes is equal 1, copies - * the debug info from the old node to all new ones (if they do not have one), else does nothing. - * - * @param new_nodes An array of new Firm nodes. - * @param n_new_nodes The length of the new_nodes array. - * @param old_nodes An array of old (replaced) Firm nodes. - * @param n_old_nodes The length of the old_nodes array. - * @param info The action that cause old node to be replaced by new one. + * The type of the debug info retriever function. + * When given a dbg_info returns the name (usually the filename) of the + * compilation unit defining it. @p line is set to the line number of the + * definition. */ -void default_dbg_info_merge_sets(ir_node **new_nodes, int n_new_nodes, - ir_node **old_nodes, int n_old_nodes, - dbg_action info); - -/** @} */ - -/** The type of the debug info retriever function. */ typedef const char *(*retrieve_dbg_func)(const dbg_info *dbg, unsigned *line); /** diff --git a/ir/debug/dbginfo.c b/ir/debug/dbginfo.c index c4fea3055..9941700a6 100644 --- a/ir/debug/dbginfo.c +++ b/ir/debug/dbginfo.c @@ -32,22 +32,19 @@ #include "entity_t.h" merge_pair_func *__dbg_info_merge_pair = default_dbg_info_merge_pair; - merge_sets_func *__dbg_info_merge_sets = default_dbg_info_merge_sets; -snprint_dbg_func *__dbg_info_snprint = (snprint_dbg_func *)0; - -void dbg_init( merge_pair_func *mpf, merge_sets_func *msf, snprint_dbg_func *snprint_dbg ) +void dbg_init(merge_pair_func *mpf, merge_sets_func *msf) { __dbg_info_merge_pair = mpf ? mpf : default_dbg_info_merge_pair; __dbg_info_merge_sets = msf ? msf : default_dbg_info_merge_sets; - __dbg_info_snprint = snprint_dbg; -} /* dbg_init */ +} /* * Converts a debug_action into a string. */ -const char *dbg_action_2_str(dbg_action a) { +const char *dbg_action_2_str(dbg_action a) +{ #define CASE(a) case a: return #a switch (a) { @@ -79,19 +76,20 @@ const char *dbg_action_2_str(dbg_action a) { return NULL; } #undef CASE -} /* dbg_action_2_str */ - +} -void default_dbg_info_merge_pair(ir_node *nw, ir_node *old, dbg_action info) { +void default_dbg_info_merge_pair(ir_node *nw, ir_node *old, dbg_action info) +{ dbg_info *new_db = get_irn_dbg_info(nw); (void) info; if (new_db == NULL) set_irn_dbg_info(nw, get_irn_dbg_info(old)); -} /* default_dbg_info_merge_pair */ +} void default_dbg_info_merge_sets(ir_node **new_nodes, int n_new_nodes, ir_node **old_nodes, int n_old_nodes, - dbg_action info) { + dbg_action info) +{ (void) info; if (n_old_nodes == 1) { dbg_info *old_db = get_irn_dbg_info(old_nodes[0]); @@ -101,21 +99,36 @@ void default_dbg_info_merge_sets(ir_node **new_nodes, int n_new_nodes, if (get_irn_dbg_info(new_nodes[i]) == NULL) set_irn_dbg_info(new_nodes[i], old_db); } -} /* default_dbg_info_merge_sets */ +} /** The debug info retriever function. */ static retrieve_dbg_func retrieve_dbg = NULL; /* Sets a debug info retriever. */ -void ir_set_debug_retrieve(retrieve_dbg_func func) { +void ir_set_debug_retrieve(retrieve_dbg_func func) +{ retrieve_dbg = func; } /* Retrieve the debug info. */ -const char *ir_retrieve_dbg_info(const dbg_info *dbg, unsigned *line) { +const char *ir_retrieve_dbg_info(const dbg_info *dbg, unsigned *line) +{ if (retrieve_dbg) return retrieve_dbg(dbg, line); *line = 0; return NULL; } + +void ir_dbg_info_snprint(char *buf, size_t bufsize, const dbg_info *dbg) +{ + unsigned line; + const char *source = ir_retrieve_dbg_info(dbg, &line); + + if (source == NULL) { + assert(bufsize > 0); + buf[0] = 0; + return; + } + snprintf(buf, bufsize, "%s:%u", source, line); +} diff --git a/ir/debug/dbginfo_t.h b/ir/debug/dbginfo_t.h index b836f2cdc..271e09bd7 100644 --- a/ir/debug/dbginfo_t.h +++ b/ir/debug/dbginfo_t.h @@ -31,8 +31,34 @@ #ifndef FIRM_DEBUG_DBGINFO_T_H #define FIRM_DEBUG_DBGINFO_T_H +#include #include "dbginfo.h" +/** + * The default merge_pair_func implementation, simply copies the debug info + * from the old Firm node to the new one if the new one does not have debug info yet. + * + * @param nw The new Firm node. + * @param old The old Firm node. + * @param info The action that cause old node to be replaced by new one. + */ +void default_dbg_info_merge_pair(ir_node *nw, ir_node *old, dbg_action info); + +/** + * The default merge_sets_func implementation. If n_old_nodes is equal 1, + * copies the debug info from the old node to all new ones (if they do not have + * one), else does nothing. + * + * @param new_nodes An array of new Firm nodes. + * @param n_new_nodes The length of the new_nodes array. + * @param old_nodes An array of old (replaced) Firm nodes. + * @param n_old_nodes The length of the old_nodes array. + * @param info The action that cause old node to be replaced by new one. + */ +void default_dbg_info_merge_sets(ir_node **new_nodes, int n_new_nodes, + ir_node **old_nodes, int n_old_nodes, + dbg_action info); + /** * The current merge_pair_func(), access only from inside firm. */ @@ -43,9 +69,6 @@ extern merge_pair_func *__dbg_info_merge_pair; */ extern merge_sets_func *__dbg_info_merge_sets; -/** - * The current snprint_dbg_func(), access only from inside firm. - */ -extern snprint_dbg_func *__dbg_info_snprint; +void ir_dbg_info_snprint(char *buf, size_t buf_size, const dbg_info *dbg); #endif diff --git a/ir/ir/irargs.c b/ir/ir/irargs.c index 22ea1be36..4713de40d 100644 --- a/ir/ir/irargs.c +++ b/ir/ir/irargs.c @@ -90,11 +90,7 @@ static int firm_emit_dbg(lc_appendable_t *app, ir_node *irn = arg->v_ptr; dbg_info *dbg = get_irn_dbg_info(irn); - buf[0] = '\0'; - if (dbg && __dbg_info_snprint) { - if (__dbg_info_snprint(buf, sizeof(buf), dbg) <= 0) - buf[0] = '\0'; - } + ir_dbg_info_snprint(buf, sizeof(buf), dbg); return lc_arg_append(app, occ, buf, strlen(buf)); } diff --git a/ir/ir/irdump.c b/ir/ir/irdump.c index e9f431e8d..ade9ba5cc 100644 --- a/ir/ir/irdump.c +++ b/ir/ir/irdump.c @@ -1430,10 +1430,9 @@ static void print_dbg_info(FILE *F, dbg_info *dbg) { char buf[1024]; - if (__dbg_info_snprint) { - buf[0] = '\0'; - if (__dbg_info_snprint(buf, sizeof(buf), dbg) > 0) - fprintf(F, " info3: \"%s\"\n", buf); + ir_dbg_info_snprint(buf, sizeof(buf), dbg); + if (buf[0] != 0) { + fprintf(F, " info3: \"%s\"\n", buf); } }