scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 162486162929c82a4c92763e7ad488c064d4142c
parent f48bd7ea099100ae505a090271379e47953f0c54
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
Date:   Fri, 15 Apr 2016 15:24:20 +0200

[cc2-qbe] Small stetic changes to the output of qbe

After this commit we have a beatitul output for something like

$ cc1 | cc2
int
func(int a, int b)
{
	int c;

	c = a + c;
}
^D
export function h $func(h %a,h %b)
	%c h=	alloc2	2
	$.1 w=	load	%a
	$.2 w=	load	%c
	$.3 w=	add	$.1,$.2
		storew	$.3,%c
}

Diffstat:
cc2/arch/qbe/code.c | 15+++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c @@ -191,19 +191,22 @@ writeout(void) { Symbol *p; Type *tp; + char *sep; if (curfun->kind == GLOB) fputs("export ", stdout); - printf("function %s %s(\n", size2asm(&curfun->rtype), symname(curfun)); + printf("function %s %s(", size2asm(&curfun->rtype), symname(curfun)); - for (p = locals; p && p->type.flags & PARF; p = p->next) - printf("\t%s %s,\n", size2asm(&p->type), symname(p)); - - puts(")\n{"); + for (sep = "", p = locals; p; p = p->next, sep = ",") { + if ((p->type.flags & PARF) == 0) + break; + printf("%s%s %s", sep, size2asm(&p->type), symname(p)); + } + puts(")"); for ( ; p && p->id != TMPSYM; p = p->next) { tp = &p->type; - printf("\t%s %s= alloc%lld %lld\n", + printf("\t%s %s=\talloc%lld\t%lld\n", symname(p), size2asm(tp), (long long) tp->size, (long long) tp->align); }