scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 599f8df9655f84d78e6383f546caf23c7dccae98
parent 6b9a0f241f50fce7e358ac90508d5be9a8a4cb61
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
Date:   Wed, 20 Apr 2016 04:31:40 +0200

[cc2-qbe] Improve cc2/arch/qbe/code.c:/^binary/

It is better to have an unique format string, even if we have to
do a double copy to an internal buffer instead of using the buffer
supplied by addr2txt().

Diffstat:
Mcc2/arch/qbe/code.c | 16++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c @@ -1,11 +1,14 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include "arch.h" #include "../../cc2.h" #include "../../../inc/sizes.h" +#define ADDR_LEN (IDENTSIZ+2) + static void binary(void), load(void), store(void); static struct opdata { @@ -229,8 +232,6 @@ writeout(void) static char * addr2txt(Addr *a) { - static char buff[40]; - switch (a->kind) { case SAUTO: case SLABEL: @@ -245,13 +246,12 @@ static void binary(void) { struct opdata *p = &optbl[pc->op]; + char to[ADDR_LEN], from1[ADDR_LEN], from2[ADDR_LEN]; - printf("\t%s %c=\t%s\t", - addr2txt(&pc->to), p->letter, p->txt); - fputs(addr2txt(&pc->from1), stdout); - putchar(','); - fputs(addr2txt(&pc->from2), stdout); - putchar('\n'); + strcpy(to, addr2txt(&pc->to)); + strcpy(from1, addr2txt(&pc->from1)); + strcpy(from2, addr2txt(&pc->from2)); + printf("\t%s %c=\t%s\t%s,%s\n", to, p->letter, p->txt, from1, from2); } static void