X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firprintf.c;h=2d8e1238c10bea784d4b2dbc9c0bf2eeb5507fd8;hb=8399216d8aebc713bbda04b6e3e250a1d52b20bf;hp=0ba4b01c03af7735fcd438777bb8dca63c2b1a1a;hpb=5d4a38a9efb9a6ed19e592fce8fcf73d1332d1b4;p=libfirm diff --git a/ir/ir/irprintf.c b/ir/ir/irprintf.c index 0ba4b01c0..2d8e1238c 100644 --- a/ir/ir/irprintf.c +++ b/ir/ir/irprintf.c @@ -24,6 +24,9 @@ #ifdef HAVE_STRING_H #include #endif +#ifdef HAVE_INTTYPES_H +#include +#endif #include #include @@ -35,8 +38,10 @@ #include "irmode_t.h" #include "irnode_t.h" #include "entity_t.h" +#include "type_t.h" #include "tv.h" #include "irprintf.h" +#include "obst.h" #include "pset.h" #include "iterator.h" #include "bitset.h" @@ -95,6 +100,32 @@ static void file_append_str(void *object, size_t n, const char *str) fputs(str, object); } +/** + * Init the obstack. i.e. do nothing. + */ +static void obst_init(void *object, size_t n) +{ +} + +/** + * append a char to a obstack. + */ +static void obst_append_char(void *object, size_t n, char ch) +{ + struct obstack *obst = object; + obstack_1grow(obst, ch); +} + +/** + * append a string to a obstack. + */ +static void obst_append_str(void *object, size_t n, const char *str) +{ + struct obstack *obst = object; + obstack_grow(obst, str, strlen(str)); +} + + /** * the file appender */ @@ -113,6 +144,15 @@ static const appender_t str_appender = { str_append_str }; +/** + * the obstack appender. + */ +static const appender_t obst_appender = { + obst_init, + obst_append_char, + obst_append_str +}; + static void ir_common_vprintf(const appender_t *app, void *object, size_t limit, const char *fmt, va_list args); @@ -188,8 +228,8 @@ static void dump_with_settings(const appender_t *app, void *object, size_t limit if(settings->width >= 0) { int i; size_t n = strlen(str); - int lim = MIN(settings->width, limit); - int to_print = MIN(lim, n); + int lim = MIN(settings->width, (int)limit); + int to_print = MIN(lim, (int)n); int to_pad = to_print - lim; if(!settings->left_just) @@ -361,7 +401,7 @@ static void ir_common_vprintf(const appender_t *app, void *object, case len_long_long: { - long long arg = va_arg(args, long long); + int64_t arg = va_arg(args, int64_t); snprintf(buf, sizeof(buf), fmt_str, arg); } break; @@ -373,6 +413,10 @@ static void ir_common_vprintf(const appender_t *app, void *object, str = get_id_str(va_arg(args, ident *)); break; + case 't': + str = get_type_name(va_arg(args, type *)); + break; + case 'e': str = get_entity_name(va_arg(args, entity *)); break; @@ -381,7 +425,7 @@ static void ir_common_vprintf(const appender_t *app, void *object, str = get_entity_ld_name(va_arg(args, entity *)); break; - case 't': + case 'T': tarval_snprintf(buf, sizeof(buf), va_arg(args, tarval *)); break; @@ -505,3 +549,34 @@ void ir_snprintf(char *buf, size_t len, const char *fmt, ...) ir_common_vprintf(&str_appender, buf, len, fmt, args); va_end(args); } + +/** + * Convencience for string dumping. + */ +void ir_obst_printf(struct obstack *obst, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + ir_common_vprintf(&obst_appender, obst, 0, fmt, args); + va_end(args); +} + +void ir_vprintf(const char *fmt, va_list args) +{ + ir_common_vprintf(&file_appender, stdout, 0, fmt, args); +} + +void ir_vfprintf(FILE *f, const char *fmt, va_list args) +{ + ir_common_vprintf(&file_appender, f, 0, fmt, args); +} + +void ir_vsnprintf(char *buf, size_t len, const char *fmt, va_list args) +{ + ir_common_vprintf(&str_appender, buf, len, fmt, args); +} + +void ir_obst_vprintf(struct obstack *obst, const char *fmt, va_list args) +{ + ir_common_vprintf(&obst_appender, obst, 0, fmt, args); +}