X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftv%2Fstrcalc.c;h=b012b7479694ae7b1460d1bc604b68212786d884;hb=2d09549421b49587d4680a94dab277646e9fef44;hp=2d55f58f33ead809a4a16030545deb056d90fa7f;hpb=6dddb06ad1e8611f083f7bcb432dd4b116e58a0e;p=libfirm diff --git a/ir/tv/strcalc.c b/ir/tv/strcalc.c index 2d55f58f3..b012b7479 100644 --- a/ir/tv/strcalc.c +++ b/ir/tv/strcalc.c @@ -22,6 +22,9 @@ #ifdef HAVE_ALLOCA_H # include #endif +#ifdef HAVE_MALLOC_H +# include +#endif #include /* assertions */ #include /* memset/memcmp */ #include /* output for error messages */ @@ -517,6 +520,7 @@ static void _add(const char *val1, const char *val2, char *buffer) buffer[counter] = add2[0]; carry = add_table[_val(add1[1])][_val(add2[1])][0]; } + carry_flag = carry != SC_0; } static void _mul(const char *val1, const char *val2, char *buffer) @@ -1506,17 +1510,16 @@ void init_strcalc(int precision) if (precision <= 0) precision = SC_DEFAULT_PRECISION; /* round up to multiple of 4 */ - if (precision & 0x3) precision += 4 - (precision&0x3); + precision = (precision + 3) & ~3; BIT_PATTERN_SIZE = (precision); CALC_BUFFER_SIZE = (precision / 2); MAX_VALUE_SIZE = (precision / 4); - calc_buffer = malloc(CALC_BUFFER_SIZE+1 * sizeof(char)); + calc_buffer = malloc(CALC_BUFFER_SIZE+1 * sizeof(char)); output_buffer = malloc(BIT_PATTERN_SIZE+1 * sizeof(char)); - if (calc_buffer == NULL || output_buffer == NULL) - { + if (calc_buffer == NULL || output_buffer == NULL) { assert(0 && "malloc failed"); exit(-1); } @@ -1524,6 +1527,13 @@ void init_strcalc(int precision) DEBUGPRINTF(("init strcalc: \n\tPRECISION: %d\n\tCALC_BUFFER_SIZE = %d\n\tMAX_VALUE_SIZE = %d\n\tbuffer pointer: %p\n", precision, CALC_BUFFER_SIZE, MAX_VALUE_SIZE, calc_buffer)); } } + + +void finish_strcalc() { + free(calc_buffer); calc_buffer = NULL; + free(output_buffer); output_buffer = NULL; +} + int sc_get_precision(void) { return BIT_PATTERN_SIZE;