+ va_start(args, fmt);
+ ir_common_vprintf(app, object, limit, fmt, args);
+ va_end(args);
+}
+
+#if 0
+static int is_std_fmt(const char *fmt)
+{
+ static const char *fmt_re_str =
+ "^[0 -+#']?[1-9]*(\\.[1-9]*)?[hlLqjzt]?[diouxXeEfFgGaAc]";
+
+ static regex_t fmt_re;
+ static int preapred_re = 0;
+
+ regmatch_t match[1];
+ int res;
+
+ if(!preapred_re) {
+ int res = regcomp(&fmt_re, fmt_re_str, REG_EXTENDED);
+ assert(res == 0 && "Could not prepare regex");
+ preapred_re = 1;
+ }
+
+ res = regexec(&fmt_re, fmt, 1, &match[0], 0);
+
+#if 0
+ if(res != 0) {
+ char buf[256];
+ regerror(res, &fmt_re, buf, sizeof(buf));
+ printf("%s ", buf);
+ }
+
+ printf("res: %d, start: %d, end: %d\n",
+ res, match[0].rm_so, match[0].rm_eo);
+#endif
+
+ return res == 0 ? match[0].rm_eo : -1;
+}
+#endif
+
+struct settings {
+ char flag_zero;
+ int width;
+ int flag_minus;
+ int flag_plus;
+ int flag_hash;
+};
+
+/* Length specifiers. */
+enum {
+ len_char,
+ len_short,
+ len_int,
+ len_long,
+ len_long_long
+};
+
+
+#define MIN(x,y) ((x) < (y) ? (x) : (y))
+#define MAX(x,y) ((x) > (y) ? (x) : (y))
+
+static void dump_with_settings(const appender_t *app, void *object, size_t limit,
+ const struct settings *settings, const char *str)
+{
+ if (settings->width >= 0) {
+ int i;
+ size_t n = strlen(str);
+ int lim = MIN(settings->width, (int)limit);
+ int to_print = MIN(lim, (int)n);
+ int to_pad = to_print - lim;
+
+ if (!settings->flag_minus)
+ for(i = 0; i < to_pad; ++i)
+ app->append_char(object, lim, settings->flag_zero);
+
+ app->append_str(object, to_print, str);
+
+ if (!settings->flag_minus)
+ for(i = 0; i < to_pad; ++i)
+ app->append_char(object, lim, settings->flag_zero);
+ }
+
+ else
+ app->append_str(object, limit, str);
+}
+
+/**
+ * Beware: do not set the entity ld_name
+ */
+static const char *get_entity_ld_name_ex(ir_entity *ent) {
+ if (ent->ld_name)
+ return get_entity_ld_name(ent);
+ return get_entity_name(ent);
+}
+
+/**
+ * emit a Firm object. Backported from irargs.
+ */
+static void firm_emit(char *buf, int buflen, char conversion,
+ const struct settings *occ, void *X)
+{
+#define A(s) occ->flag_hash ? s " ": ""
+
+ firm_kind *obj = X;
+ int i, n;
+ ir_node *block;
+ char add[64];
+ char tv_buf[256];
+ ir_entity *ent;
+
+ buf[0] = '\0';
+ add[0] = '\0';
+
+ if (! X)
+ strncpy(buf, "(null)", buflen);
+ else {
+ switch (*obj) {
+ case k_BAD:
+ snprintf(buf, buflen, "BAD");
+ snprintf(add, sizeof(add), "[%p]", X);
+ break;
+ case k_entity:
+ snprintf(buf, buflen, "%s%s", A("ent"),
+ isupper(conversion) ? get_entity_ld_name_ex(X): get_entity_name(X));
+ snprintf(add, sizeof(add), "[%ld]", get_entity_nr(X));
+ break;
+ case k_type:
+ snprintf(buf, buflen, "%s%s:%s", A("type"), get_type_tpop_name(X), get_type_name(X));
+ snprintf(add, sizeof(add), "[%ld]", get_type_nr(X));
+ break;
+ case k_ir_graph:
+ if (X == get_const_code_irg())
+ snprintf(buf, buflen, "const_code_irg ");
+ else
+ snprintf(buf, buflen, "%s%s", A("irg"), get_entity_name(get_irg_entity(X)));
+ snprintf(add, sizeof(add), "[%ld]", get_irg_graph_nr(X));
+ break;
+ case k_ir_node:
+ switch (conversion) {
+ case 'B':
+ block = is_no_Block(X) ? get_nodes_block(X) : X;
+ snprintf(buf, buflen, "%s%s%s", A("irn"), get_irn_opname(block),
+ get_mode_name(get_irn_mode(block)));
+ snprintf(add, sizeof(add), "[%ld]", get_irn_node_nr(block));
+ break;
+ case 'N':
+ snprintf(buf, buflen, "%ld", get_irn_node_nr(X));
+ break;
+ default:
+ if (is_Const(X)) {
+ tarval *tv = get_Const_tarval(X);
+
+ if (tv)
+ tarval_snprintf(tv_buf, sizeof(tv_buf), tv);
+ snprintf(buf, buflen, "%s%s%s<%s>", A("irn"), get_irn_opname(X),
+ get_mode_name(get_irn_mode(X)), tv ? tv_buf : ">NULL<");
+ }
+ else if (get_irn_op(X) == op_SymConst) {
+ switch (get_SymConst_kind(X)) {
+ case symconst_type_tag: /* type tag */
+ snprintf(tv_buf, sizeof(tv_buf), "<ID:%s>", get_type_name(get_SymConst_type(X)));
+ break;
+ case symconst_type_size: /* type size */
+ snprintf(tv_buf, sizeof(tv_buf), "<SIZE:%s>", get_type_name(get_SymConst_type(X)));
+ break;
+ case symconst_type_align: /* type alignment */
+ snprintf(tv_buf, sizeof(tv_buf), "<ALIGN:%s>", get_type_name(get_SymConst_type(X)));
+ break;
+ case symconst_addr_name: /* linker name */
+ snprintf(tv_buf, sizeof(tv_buf), "<EXT:%s>", get_id_str(get_SymConst_name(X)));
+ break;
+ case symconst_addr_ent: /* entity name */
+ snprintf(tv_buf, sizeof(tv_buf), "<%s>", get_entity_name(get_SymConst_entity(X)));
+ break;
+ case symconst_enum_const: /* enumeration constant */
+ snprintf(tv_buf, sizeof(tv_buf), "<ENUM:%s>", get_enumeration_name(get_SymConst_enum(X)));
+ break;
+ case symconst_label: /* label */
+ snprintf(tv_buf, sizeof(tv_buf), "<LABEL:%lu>", get_SymConst_label(X));
+ break;
+ default:
+ tv_buf[0] = '\0';
+ }
+ snprintf(buf, buflen, "%s%s%s%s", A("irn"), get_irn_opname(X),
+ get_mode_name(get_irn_mode(X)), tv_buf);
+ }
+ else
+ snprintf(buf, buflen, "%s%s%s", A("irn"), get_irn_opname(X),
+ get_mode_name(get_irn_mode(X)));
+ snprintf(add, sizeof(add), "[%ld:%d]", get_irn_node_nr(X), get_irn_idx(X));
+ }
+ break;
+ case k_ir_mode:
+ snprintf(buf, buflen, "%s%s", A("mode"), get_mode_name(X));
+ break;
+ case k_tarval:
+ tarval_snprintf(tv_buf, sizeof(tv_buf), X);
+ snprintf(buf, buflen, "%s%s", A("tv"), tv_buf);
+ break;
+ case k_ir_loop:
+ snprintf(buf, sizeof(buf), "loop[%d:%d]", get_loop_loop_nr(X), get_loop_depth(X));
+ break;
+ case k_ir_op:
+ snprintf(buf, buflen, "%s%s", A("op"), get_op_name(X));
+ break;
+ case k_ir_compound_graph_path:
+ n = get_compound_graph_path_length(X);
+
+ for (i = 0; i < n; ++i) {
+ ent = get_compound_graph_path_node(X, i);
+
+ strncat(buf, ".", buflen);
+ strncat(buf, get_entity_name(ent), buflen);
+ if (is_Array_type(get_entity_owner(ent))) {
+ snprintf(add, sizeof(add), "[%d]",
+ get_compound_graph_path_array_index(X, i));
+ strncat(buf, add, buflen);
+ }
+ }
+ add[0] = '\0';
+ break;
+
+ default:
+ snprintf(buf, buflen, "UNKWN");
+ snprintf(add, sizeof(add), "[%p]", X);
+ }
+ }
+
+ if (occ->flag_plus)
+ strncat(buf, add, buflen);
+
+#undef A