From: Sebastian Hack Date: Thu, 16 Dec 2004 09:43:09 +0000 (+0000) Subject: Added obstack dumping and vprintf... functions. X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=3197973335859d2a385f0b1a4c431b7baa5b201e;p=libfirm Added obstack dumping and vprintf... functions. [r4669] --- diff --git a/ir/ir/irprintf.c b/ir/ir/irprintf.c index 0ba4b01c0..06dcd09d9 100644 --- a/ir/ir/irprintf.c +++ b/ir/ir/irprintf.c @@ -35,8 +35,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 +97,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 +141,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); @@ -373,6 +410,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 +422,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 +546,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); +} diff --git a/ir/ir/irprintf.h b/ir/ir/irprintf.h index 60464f13f..20280a2ed 100644 --- a/ir/ir/irprintf.h +++ b/ir/ir/irprintf.h @@ -21,7 +21,9 @@ #define _IRPRINTF_H #include +#include #include +#include /** * Something that can append strings and chars to something. @@ -50,15 +52,16 @@ typedef void (ir_printf_cb_t)(const appender_t *app, void *object, size_t limit, * - @%p A pointer. * - @%s A string. * - @%I An ident. + * - @%t A type name. * - @%e An entity name. - * - @%E An entity ld_name. + * - @%E An entity ld name. * - @%n A full description of a node. * - @%O The opcode name of an ir node. * - @%m The mode name of an ir mode. * - @%N The node number of an ir node. * - @%B The block node number of the nodes block. * - @%b A bitset. - * - @%t A tarval. + * - @%T A tarval. * * Each of these can be prepended by a '+' which means, that the given * pointer is a collection of items specified by the format. In this @@ -68,7 +71,7 @@ typedef void (ir_printf_cb_t)(const appender_t *app, void *object, size_t limit, * @code * pset *nodes; * ... - * ir_printf("Some nodes: %+n\n", it_pset, nodes); + * ir_printf("Some nodes: %*n\n", it_pset, nodes); * @endcode * The @c it_pset is an iterator interface (of type * @c iterator_t that allows the dumper to traverse the set. @@ -89,7 +92,7 @@ typedef void (ir_printf_cb_t)(const appender_t *app, void *object, size_t limit, * ... * pset *xyzs; * - * ir_printf("A set of xyz\'s: %+C\n", it_pset, xyzs, xyz_dump); + * ir_printf("A set of xyz\'s: %*C\n", it_pset, xyzs, xyz_dump); * @endcode * * @param fmt The format string. @@ -106,5 +109,24 @@ void ir_fprintf(FILE *f, const char *fmt, ...); */ void ir_snprintf(char *buf, size_t n, const char *fmt, ...); +/** + * @see irn_printf. + */ +void ir_vprintf(const char *fmt, va_list args); + +/** + * @see irn_printf. + */ +void ir_vfprintf(FILE *f, const char *fmt, va_list args); + +/** + * @see irn_printf. + */ +void ir_vsnprintf(char *buf, size_t len, const char *fmt, va_list args); + +/** + * @see irn_printf. + */ +void ir_obst_vprintf(struct obstack *obst, const char *fmt, va_list args); #endif