X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=isl_printer.c;h=e0821f2a2b4ef5d57ee6927d9e436b9f6b587a72;hb=48a8be3c1b335873ee455b4d911b4101892bbf25;hp=15da2094b1347894541e523f8c5b87543ffefab9;hpb=e6471054a536dfe234a91665e2e715660188d867;p=platform%2Fupstream%2Fisl.git diff --git a/isl_printer.c b/isl_printer.c index 15da209..e0821f2 100644 --- a/isl_printer.c +++ b/isl_printer.c @@ -26,6 +26,13 @@ static __isl_give isl_printer *file_print_str(__isl_take isl_printer *p, return p; } +static __isl_give isl_printer *file_print_double(__isl_take isl_printer *p, + double d) +{ + fprintf(p->file, "%g", d); + return p; +} + static __isl_give isl_printer *file_print_int(__isl_take isl_printer *p, int i) { fprintf(p->file, "%d", i); @@ -116,6 +123,24 @@ static __isl_give isl_printer *str_print_str(__isl_take isl_printer *p, return str_print(p, s, strlen(s)); } +static __isl_give isl_printer *str_print_double(__isl_take isl_printer *p, + double d) +{ + int left = p->buf_size - p->buf_n; + int need = snprintf(p->buf + p->buf_n, left, "%g", d); + if (need >= left) { + if (grow_buf(p, need)) + goto error; + left = p->buf_size - p->buf_n; + need = snprintf(p->buf + p->buf_n, left, "%g", d); + } + p->buf_n += need; + return p; +error: + isl_printer_free(p); + return NULL; +} + static __isl_give isl_printer *str_print_int(__isl_take isl_printer *p, int i) { int left = p->buf_size - p->buf_n; @@ -138,21 +163,21 @@ static __isl_give isl_printer *str_print_isl_int(__isl_take isl_printer *p, { char *s; int len; - isl_int_print_gmp_free_t gmp_free; s = isl_int_get_str(i); len = strlen(s); if (len < p->width) p = str_print_indent(p, p->width - len); p = str_print(p, s, len); - mp_get_memory_functions(NULL, NULL, &gmp_free); - (*gmp_free)(s, len + 1); + isl_int_free_str(s); return p; } struct isl_printer_ops { __isl_give isl_printer *(*start_line)(__isl_take isl_printer *p); __isl_give isl_printer *(*end_line)(__isl_take isl_printer *p); + __isl_give isl_printer *(*print_double)(__isl_take isl_printer *p, + double d); __isl_give isl_printer *(*print_int)(__isl_take isl_printer *p, int i); __isl_give isl_printer *(*print_isl_int)(__isl_take isl_printer *p, isl_int i); @@ -164,6 +189,7 @@ struct isl_printer_ops { static struct isl_printer_ops file_ops = { file_start_line, file_end_line, + file_print_double, file_print_int, file_print_isl_int, file_print_str, @@ -173,6 +199,7 @@ static struct isl_printer_ops file_ops = { static struct isl_printer_ops str_ops = { str_start_line, str_end_line, + str_print_double, str_print_int, str_print_isl_int, str_print_str, @@ -213,6 +240,7 @@ __isl_give isl_printer *isl_printer_to_str(isl_ctx *ctx) if (!p->buf) goto error; p->buf_n = 0; + p->buf[0] = '\0'; p->buf_size = 256; p->indent = 0; p->output_format = ISL_FORMAT_ISL; @@ -226,13 +254,30 @@ error: return NULL; } -void isl_printer_free(__isl_take isl_printer *p) +void *isl_printer_free(__isl_take isl_printer *p) { if (!p) - return; + return NULL; free(p->buf); isl_ctx_deref(p->ctx); free(p); + + return NULL; +} + +isl_ctx *isl_printer_get_ctx(__isl_keep isl_printer *printer) +{ + return printer ? printer->ctx : NULL; +} + +FILE *isl_printer_get_file(__isl_keep isl_printer *printer) +{ + if (!printer) + return NULL; + if (!printer->file) + isl_die(isl_printer_get_ctx(printer), isl_error_invalid, + "not a file printer", return NULL); + return printer->file; } __isl_give isl_printer *isl_printer_set_isl_int_width(__isl_take isl_printer *p, @@ -303,15 +348,33 @@ __isl_give isl_printer *isl_printer_set_output_format(__isl_take isl_printer *p, return p; } +int isl_printer_get_output_format(__isl_keep isl_printer *p) +{ + if (!p) + return -1; + return p->output_format; +} + __isl_give isl_printer *isl_printer_print_str(__isl_take isl_printer *p, const char *s) { if (!p) return NULL; + if (!s) + return isl_printer_free(p); return p->ops->print_str(p, s); } +__isl_give isl_printer *isl_printer_print_double(__isl_take isl_printer *p, + double d) +{ + if (!p) + return NULL; + + return p->ops->print_double(p, d); +} + __isl_give isl_printer *isl_printer_print_int(__isl_take isl_printer *p, int i) { if (!p)