[hackers] [scc] [cc1] Print information about size, aligment and offset in structs || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 26 Jan 2016 10:57:43 +0100 (CET)

commit 1b4f88745ddce9a4870c4cf1c9c2877486c2c4bb
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Mon Jan 25 17:08:44 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Mon Jan 25 17:55:41 2016 +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.

diff --git a/cc1/code.c b/cc1/code.c
index 661ffb5..88d45af 100644
--- a/cc1/code.c
+++ b/cc1/code.c
_AT_@ -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);
_AT_@ -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
index ad03e80..336a72f 100644
--- a/cc1/tests/test002.c
+++ b/cc1/tests/test002.c
_AT_@ -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
index 54655bd..9bab063 100644
--- a/cc1/tests/test015.c
+++ b/cc1/tests/test015.c
_AT_@ -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
index c781b1a..77c19b9 100644
--- a/cc1/tests/test017.c
+++ b/cc1/tests/test017.c
_AT_@ -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 _AT_S2 M3 .I #I1 :I
diff --git a/cc1/tests/test030.c b/cc1/tests/test030.c
index bfd989b..7842baa 100644
--- a/cc1/tests/test030.c
+++ b/cc1/tests/test030.c
_AT_@ -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
index c6968b5..f0ecc69 100644
--- a/cc1/tests/test040.c
+++ b/cc1/tests/test040.c
_AT_@ -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
index 1a56414..1f34502 100644
--- a/cc1/tests/test041.c
+++ b/cc1/tests/test041.c
_AT_@ -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
index 59a6fee..14c9bf0 100644
--- a/cc1/tests/test043.c
+++ b/cc1/tests/test043.c
_AT_@ -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
index 2802ad8..948a018 100644
--- a/cc1/tests/test047.c
+++ b/cc1/tests/test047.c
_AT_@ -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
index 232495d..16f4d97 100644
--- a/cc1/tests/test048.c
+++ b/cc1/tests/test048.c
_AT_@ -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
index ce7da75..164d43b 100644
--- a/cc1/tests/test052.c
+++ b/cc1/tests/test052.c
_AT_@ -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
index 629860f..bd3e1af 100644
--- a/cc1/tests/test053.c
+++ b/cc1/tests/test053.c
_AT_@ -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
index ee3f9cc..3b62cc1 100644
--- a/cc1/tests/test056.c
+++ b/cc1/tests/test056.c
_AT_@ -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
Received on Tue Jan 26 2016 - 10:57:43 CET

This archive was generated by hypermail 2.3.0 : Tue Jan 26 2016 - 11:00:31 CET