(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]
*/
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.
*
* 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);
/**
#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) {
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]);
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);
+}
#ifndef FIRM_DEBUG_DBGINFO_T_H
#define FIRM_DEBUG_DBGINFO_T_H
+#include <stdlib.h>
#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.
*/
*/
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
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));
}
{
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);
}
}