ref: 53f14a7c00755ff7aea5e8115de6e9fd3fe1518f
parent: b18a5a9dbc408cc4d30865dfc6d4a6f1329e142d
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Apr 20 00:31:40 EDT 2016
[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().
--- 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 @@
static char *
addr2txt(Addr *a)
{
- static char buff[40];
-
switch (a->kind) {
case SAUTO:
case SLABEL:
@@ -245,13 +246,12 @@
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