scc

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

commit 1b4f88745ddce9a4870c4cf1c9c2877486c2c4bb
parent 60a0cff60f2c11945afc0026c2f6ed532dc60e87
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 25 Jan 2016 17:08:44 +0100

[cc1] Print information about size, aligment and offset in structs

This informatio mut be calculated in the frontend (sizeof and _Alignof),
and it is a bit stupid that the backend must recalculate it again, so
the best option is to print it to the IR.

Diffstat:
cc1/code.c | 12+++++++++---
cc1/tests/test002.c | 6+++---
cc1/tests/test015.c | 14+++++++-------
cc1/tests/test017.c | 10+++++-----
cc1/tests/test030.c | 12++++++------
cc1/tests/test040.c | 8++++----
cc1/tests/test041.c | 4++--
cc1/tests/test043.c | 6+++---
cc1/tests/test047.c | 8++++----
cc1/tests/test048.c | 6+++---
cc1/tests/test052.c | 6+++---
cc1/tests/test053.c | 6+++---
cc1/tests/test056.c | 12++++++------
13 files changed, 58 insertions(+), 52 deletions(-)

diff --git a/cc1/code.c b/cc1/code.c @@ -264,9 +264,13 @@ emittype(Type *tp) for (sp = tp->p.fields; n-- > 0; ++sp) emittype((*sp)->type); emitletter(tp); - if ((tag = tp->tag->name) != NULL) - printf("\t%s", tag); - putchar('\n'); + tag = tp->tag->name; + printf("\t\"%s\t#%c%llX\t#%c%llX\n", + (tag) ? tag : "", + sizettype->letter, + (unsigned long long) tp->size, + sizettype->letter, + (unsigned long long) tp->align); n = tp->n.elem; for (sp = tp->p.fields; n-- > 0; ++sp) emit(ODECL, *sp); @@ -378,6 +382,8 @@ emitdcl(unsigned op, void *arg) putchar('\t'); emitletter(sym->type); printf("\t\"%s", (sym->name) ? sym->name : ""); + if (sym->flags & ISFIELD) + printf("\t#%c%llX", sizettype->letter, sym->u.i); putchar('\n'); sym->flags |= ISEMITTED; } diff --git a/cc1/tests/test002.c b/cc1/tests/test002.c @@ -7,9 +7,9 @@ G4 P "x G8 F "main { \ -S2 S -M5 I "i -M6 P "next +S2 "S #NC #N2 +M5 I "i #N0 +M6 P "next #N2 A9 S2 "y A10 P "p A11 N "n diff --git a/cc1/tests/test015.c b/cc1/tests/test015.c @@ -4,13 +4,13 @@ description: Stress namespace mechanism error: test015.c:52: error: label 's' already defined output: -S8 s2 -M9 I "s -S5 s1 -M6 I "s -M10 S8 "s1 -S2 s -M11 S5 "s +S8 "s2 #N2 #N1 +M9 I "s #N0 +S5 "s1 #N4 #N1 +M6 I "s #N0 +M10 S8 "s1 #N2 +S2 "s #N4 #N1 +M11 S5 "s #N0 G12 S2 "s2 G14 F "main { diff --git a/cc1/tests/test017.c b/cc1/tests/test017.c @@ -6,12 +6,12 @@ output: G10 F "main { \ -S2 s1 -M3 I "y -M4 I "z +S2 "s1 #N4 #N1 +M3 I "y #N0 +M4 I "z #N2 A11 S2 "nested -S6 s2 -M8 P "p +S6 "s2 #N4 #N2 +M8 P "p #N0 A12 S6 "v A12 M8 .P A11 'P :P A12 M8 .P @S2 M3 .I #I1 :I diff --git a/cc1/tests/test030.c b/cc1/tests/test030.c @@ -6,12 +6,12 @@ error: output: G14 F "f1 { -S2 foo -M3 I "i -M4 I "j -M5 I "k -M7 P "p -M8 J "v +S2 "foo #N24 #N2 +M3 I "i #N0 +M4 I "j #N2 +M5 I "k #N4 +M7 P "p #N6 +M8 J "v #NE A9 S2 "f A11 P "p A12 I "n diff --git a/cc1/tests/test040.c b/cc1/tests/test040.c @@ -6,10 +6,10 @@ output: G9 F "main { \ -S2 List -M4 I "len -M6 P "head -M7 P "back +S2 "List #N1C #N2 +M4 I "len #N0 +M6 P "head #N2 +M7 P "back #N6 A10 S2 "List r A10 M4 .I } diff --git a/cc1/tests/test041.c b/cc1/tests/test041.c @@ -16,8 +16,8 @@ A3 I "i A5 P "q A7 P "s A8 P "p -S10 foo -M11 I "i +S10 "foo #N2 #N1 +M11 I "i #N0 A12 S10 "foo A3 A3 #I0 !I #W0 #W0 ?W gI :I A8 A3 #I0 !I #P0 #P0 ?P :P diff --git a/cc1/tests/test043.c b/cc1/tests/test043.c @@ -3,9 +3,9 @@ name: TEST043 description: Test for double typedef (taken from plan9 kernel) error: output: -S2 Clock0link -M6 P "clock -M8 P "link +S2 "Clock0link #NC #N2 +M6 P "clock #N0 +M8 P "link #N2 G9 S2 "cl0 G11 F "main { diff --git a/cc1/tests/test047.c b/cc1/tests/test047.c @@ -3,10 +3,10 @@ name: TEST047 description: Basic test for initializer error: output: -S2 S -M3 I "a -M4 I "b -M5 I "c +S2 "S #N6 #N1 +M3 I "a #N0 +M4 I "b #N2 +M5 I "c #N4 G6 S2 "x ( #I1 diff --git a/cc1/tests/test048.c b/cc1/tests/test048.c @@ -3,9 +3,9 @@ name: TEST048 description: Basic test for initializer error: output: -S2 S -M3 I "a -M4 I "b +S2 "S #N4 #N1 +M3 I "a #N0 +M4 I "b #N2 V5 S2 #N1 G6 V5 "x ( diff --git a/cc1/tests/test052.c b/cc1/tests/test052.c @@ -3,9 +3,9 @@ name: TEST052 description: Basic test for initializer error: output: -S2 S -M3 I "a -M4 I "b +S2 "S #N4 #N1 +M3 I "a #N0 +M4 I "b #N2 V5 S2 #N2 G6 V5 "arr ( diff --git a/cc1/tests/test053.c b/cc1/tests/test053.c @@ -3,9 +3,9 @@ name: TEST053 description: Basic test for initializer error: output: -S2 S -M3 I "a -M4 I "b +S2 "S #N4 #N1 +M3 I "a #N0 +M4 I "b #N2 G5 S2 "s ( #I1 diff --git a/cc1/tests/test056.c b/cc1/tests/test056.c @@ -4,12 +4,12 @@ desciption: Test of overlaying designators error: output: V6 K #N3 -S2 S -M3 I "a -M4 I "b -M5 I "c -M7 V6 "d -M8 I "e +S2 "S #NB #N1 +M3 I "a #N0 +M4 I "b #N2 +M5 I "c #N4 +M7 V6 "d #N6 +M8 I "e #N9 G9 S2 "s ( #I1