From 4ad9a0aefb83cc34a4cd05907f934d1e50de780a Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Wed, 2 Apr 2008 22:01:24 +0000 Subject: [PATCH] helper function for creating unique identifiers [r19078] --- include/libfirm/ident.h | 6 ++++++ ir/ident/ident.c | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/libfirm/ident.h b/include/libfirm/ident.h index 9b877b912..b2a0f6e6b 100644 --- a/include/libfirm/ident.h +++ b/include/libfirm/ident.h @@ -215,6 +215,12 @@ int id_is_suffix (ident *suffix, ident *id); */ int id_contains_char (ident *id, char c); +/** + * helper function for creating unique idents. It contains an internal counter + * and replaces a "%u" inside the tag with the counter. + */ +ident *id_unique(const char *tag); + #ifdef FIRM_ENABLE_WCHAR /** * Store a wide character string and create an ident. diff --git a/ir/ident/ident.c b/ir/ident/ident.c index af6bc04b1..d239034ef 100644 --- a/ir/ident/ident.c +++ b/ir/ident/ident.c @@ -337,6 +337,16 @@ int id_contains_char(ident *id, char c) return strchr(get_id_str(id), c) != NULL; } +ident *id_unique(const char *tag) +{ + static unsigned unique_id = 0; + char buf[256]; + + snprintf(buf, sizeof(buf), tag, unique_id); + unique_id++; + return new_id_from_str(buf); +} + #ifdef FIRM_ENABLE_WCHAR ident *new_id_from_wcs (const wchar_t *str) -- 2.20.1