cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 31c2d5aa28eed34dc6949db828c1ae9a81203740
parent c1d079fae39e20ea695f575a221e2251727d07aa
Author: Michael Forney <mforney@mforney.org>
Date:   Wed, 29 May 2019 16:37:49 -0700

Temporarily avoid %a when printing floating constants

This is C99, but is not supported by fscanf in OpenBSD, so floating
constants can't be read back in by QBE.

Diffstat:
Mqbe.c | 5+++--
Mtest/float-const-leading-dot.qbe | 2+-
Mtest/float-promote.qbe | 6+++---
Mtest/float-to-uint64.qbe | 4++--
Mtest/union.qbe | 2+-
5 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/qbe.c b/qbe.c @@ -1,6 +1,7 @@ #include <assert.h> #include <ctype.h> #include <errno.h> +#include <float.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> @@ -1035,7 +1036,7 @@ emitvalue(struct value *v) switch (v->kind) { case VALCONST: if (v->repr->base == 's' || v->repr->base == 'd') - printf("%c_%a", v->repr->base, v->f); + printf("%c_%.*g", v->repr->base, DECIMAL_DIG, v->f); else printf("%" PRIu64, v->i); break; @@ -1243,7 +1244,7 @@ dataitem(struct expr *expr, uint64_t size) break; case EXPRCONST: if (expr->type->prop & PROPFLOAT) - printf("%c_%a", expr->type->size == 4 ? 's' : 'd', expr->constant.f); + printf("%c_%.*g", expr->type->size == 4 ? 's' : 'd', DECIMAL_DIG, expr->constant.f); else printf("%" PRIu64, expr->constant.i); break; diff --git a/test/float-const-leading-dot.qbe b/test/float-const-leading-dot.qbe @@ -1 +1 @@ -export data $x = align 4 { s s_0x1p-1, } +export data $x = align 4 { s s_0.5, } diff --git a/test/float-promote.qbe b/test/float-promote.qbe @@ -2,10 +2,10 @@ export function $f() { @start.1 @body.2 - %.1 =d exts s_0x1p+0 + %.1 =d exts s_1 call $g1(d %.1) - %.2 =d exts s_0x1p+0 + %.2 =d exts s_1 call $g2(w 0, d %.2, ...) - call $g3(s s_0x1p+0) + call $g3(s s_1) ret } diff --git a/test/float-to-uint64.qbe b/test/float-to-uint64.qbe @@ -3,13 +3,13 @@ function l $f() { @start.1 @body.2 %.1 =s call $g() - %.2 =w cges %.1, s_0x1p+63 + %.2 =w cges %.1, s_9223372036854775808 jnz %.2, @ftou_big.4, @ftou_small.3 @ftou_small.3 %.3 =l stosi %.1 jmp @ftou_join.5 @ftou_big.4 - %.4 =s sub %.1, s_0x1p+63 + %.4 =s sub %.1, s_9223372036854775808 %.5 =l stosi %.4 %.6 =l xor %.5, 9223372036854775808 @ftou_join.5 diff --git a/test/union.qbe b/test/union.qbe @@ -1,2 +1,2 @@ export data $a = align 8 { w 5, z 4 } -export data $b = align 8 { d d_0x1.ep+2, } +export data $b = align 8 { d d_7.5, }