aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2024-03-24 01:13:15 -0700
committerMichael Forney <mforney@mforney.org>2024-03-24 02:41:29 -0700
commit7c4217eaaf28ebf52106a4b2e8b03e992fef5da0 (patch)
tree97814601b137322e00fa9fc91825cde43898ed5c
parent591853a8ddd01258a5dbf9484a3fd2114e5e87e7 (diff)
attr: Parse some GNU attributes
Implements: https://todo.sr.ht/~mcf/cproc/68
-rw-r--r--attr.c23
-rw-r--r--cc.h6
2 files changed, 28 insertions, 1 deletions
diff --git a/attr.c b/attr.c
index 8b06d46..31d16f7 100644
--- a/attr.c
+++ b/attr.c
@@ -1,3 +1,4 @@
+#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
@@ -48,6 +49,28 @@ parseattr(struct attr *a, enum attrkind allowed, enum attrprefix prefix)
switch (prefix) {
case PREFIXGNU:
prefixname = "GNU ";
+ if (strcmp(name, "aligned") == 0) {
+ kind = ATTRALIGNED;
+ if (consume(TLPAREN)) {
+ unsigned long long i;
+
+ i = intconstexpr(&filescope, false);
+ if (!i || i & i - 1 || i > INT_MAX)
+ error(&tok.loc, "invalid alignment %llu", i);
+ if (a)
+ a->align = i;
+ expect(TRPAREN, "after alignment");
+ } else {
+ if (a)
+ a->align = 16;
+ }
+ } else if (strcmp(name, "constructor") == 0) {
+ kind = ATTRCONSTRUCTOR;
+ } else if (strcmp(name, "destructor") == 0) {
+ kind = ATTRDESTRUCTOR;
+ } else if (strcmp(name, "packed") == 0) {
+ kind = ATTRPACKED;
+ }
break;
}
if (kind) {
diff --git a/cc.h b/cc.h
index e07273f..974e1ef 100644
--- a/cc.h
+++ b/cc.h
@@ -473,11 +473,15 @@ void targinit(const char *);
/* attr */
enum attrkind {
- ATTRNONE,
+ ATTRALIGNED = 1<<0,
+ ATTRCONSTRUCTOR = 1<<1,
+ ATTRDESTRUCTOR = 1<<2,
+ ATTRPACKED = 1<<3,
};
struct attr {
enum attrkind kind;
+ int align;
};
_Bool attr(struct attr *, enum attrkind);