aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/prc1/fn.c2
-rw-r--r--src/prc1/sym.c7
-rw-r--r--src/prc1/td.c8
-rw-r--r--src/prc1/triplet.c27
-rw-r--r--src/prc1/triplet.h1
-rw-r--r--src/prc1/triplet/prv.h12
-rw-r--r--src/prc1/triplet/x86_64-linux-gnu.c31
7 files changed, 59 insertions, 29 deletions
diff --git a/src/prc1/fn.c b/src/prc1/fn.c
index affa4be..7b3343c 100644
--- a/src/prc1/fn.c
+++ b/src/prc1/fn.c
@@ -2,7 +2,6 @@
#include "dbg.h"
#include "div.h"
#include "errloc.h"
-#include "gl.h"
#include "im.h"
#include "parse.h"
#include "prv.h"
@@ -11,7 +10,6 @@
#include "storage.h"
#include "sym.h"
#include "td.h"
-#include "ws.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
diff --git a/src/prc1/sym.c b/src/prc1/sym.c
index 69d3bca..3ba2937 100644
--- a/src/prc1/sym.c
+++ b/src/prc1/sym.c
@@ -364,7 +364,7 @@ static const struct type *genlittype(struct prv *p)
{
const struct fn *fn = fn_cur(p);
const char *tr = triplet(p);
- const struct type *byte = type_find(fn, tr, "char");
+ const struct type *byte = type_find(fn, tr, "char"), *ret;
struct type *bytedup = NULL, *t = NULL;
if (!byte)
@@ -384,7 +384,10 @@ static const struct type *genlittype(struct prv *p)
.child = bytedup
};
- return p->ast->littype = type_insert(p, t);
+ if (!(ret = type_insert(p, t)))
+ goto failure;
+
+ return p->ast->littype = ret;
failure:
free(t);
diff --git a/src/prc1/td.c b/src/prc1/td.c
index 4f894af..a1212b4 100644
--- a/src/prc1/td.c
+++ b/src/prc1/td.c
@@ -27,8 +27,12 @@ static int p(const struct lex *, struct prv *);
static const struct seq seqs[] =
{
{(struct step[]){{ID, "end"}, {0}}, .fn = end},
- {(struct step[]){{ID}, {ID, "constant"}, {ID, "to"}, {ID}, {0}}, .fn = cid},
- {(struct step[]){{ID}, {ID, "constant"}, {ID, "to"}, {NUM}, {0}}, .fn = cnum},
+ {(struct step[]){
+ {ID}, {ID, "constant"}, {ID, "set"}, {ID, "to"}, {ID}, {0}}, .fn = cid},
+ {(struct step[]){
+ {ID}, {ID, "constant"}, {ID, "set"}, {ID, "to"}, {NUM}, {0}},
+ .fn = cnum
+ },
{(struct step[]){{ID}, {ID, "alias"}, {0}}, .fn = a},
{(struct step[]){{ID}, {ID, "union"}, {0}}, .fn = u},
{(struct step[]){{ID}, {ID, "struct"}, {0}}, .fn = s},
diff --git a/src/prc1/triplet.c b/src/prc1/triplet.c
index 37d6e10..6325555 100644
--- a/src/prc1/triplet.c
+++ b/src/prc1/triplet.c
@@ -5,6 +5,15 @@
#include <stddef.h>
#include <string.h>
+static const struct
+{
+ const char *s;
+ const struct triplet *t;
+} m[] =
+{
+ {"x86_64-linux-gnu", &x86_64_linux_gnu}
+};
+
const char *triplet(const struct prv *p)
{
const struct args *args = p->ast->args;
@@ -23,18 +32,18 @@ static const struct type *find(const char *s, const struct type (*v)[12])
const struct type *triplet_type(const char *tr, const char *s)
{
- static const struct
- {
- const char *s;
- const struct type (*v)[12];
- } m[] =
- {
- {"x86_64-linux-gnu", &x86_64_linux_gnu}
- };
+ for (size_t i = 0; i < sizeof m / sizeof *m; i++)
+ if (!strcmp(tr, m[i].s))
+ return find(s, &m[i].t->builtins);
+ return NULL;
+}
+
+const struct type *triplet_ptr(const char *tr)
+{
for (size_t i = 0; i < sizeof m / sizeof *m; i++)
if (!strcmp(tr, m[i].s))
- return find(s, m[i].v);
+ return &m[i].t->ptr;
return NULL;
}
diff --git a/src/prc1/triplet.h b/src/prc1/triplet.h
index cccca0c..416db9c 100644
--- a/src/prc1/triplet.h
+++ b/src/prc1/triplet.h
@@ -5,5 +5,6 @@
const char *triplet(const struct prv *p);
const struct type *triplet_type(const char *tr, const char *s);
+const struct type *triplet_ptr(const char *tr);
#endif
diff --git a/src/prc1/triplet/prv.h b/src/prc1/triplet/prv.h
index 342036c..6445ebf 100644
--- a/src/prc1/triplet/prv.h
+++ b/src/prc1/triplet/prv.h
@@ -1,3 +1,13 @@
+#ifndef TRIPLET_PRV_H
+#define TRIPLET_PRV_H
+
#include "parse.h"
-extern const struct type x86_64_linux_gnu[12];
+struct triplet
+{
+ struct type builtins[12], ptr;
+};
+
+extern const struct triplet x86_64_linux_gnu;
+
+#endif
diff --git a/src/prc1/triplet/x86_64-linux-gnu.c b/src/prc1/triplet/x86_64-linux-gnu.c
index c22bc93..a0f8687 100644
--- a/src/prc1/triplet/x86_64-linux-gnu.c
+++ b/src/prc1/triplet/x86_64-linux-gnu.c
@@ -1,18 +1,23 @@
#include "triplet/prv.h"
#include "parse.h"
-const struct type x86_64_linux_gnu[] =
+const struct triplet x86_64_linux_gnu =
{
- {.type = BUILTIN, .u.b = {"void"}},
- {.type = BUILTIN, .u.b = {"char"}, .sz = 1, .sign = 1, .align = 1},
- {.type = BUILTIN, .u.b = {"schar"}, .sz = 1, .sign = 1, .align = 1},
- {.type = BUILTIN, .u.b = {"short"}, .sz = 2, .sign = 1, .align = 2},
- {.type = BUILTIN, .u.b = {"int"}, .sz = 4, .sign = 1, .align = 4},
- {.type = BUILTIN, .u.b = {"long"}, .sz = 8, .sign = 1, .align = 8},
- {.type = BUILTIN, .u.b = {"longlong"}, .sz = 8, .sign = 1, .align = 8},
- {.type = BUILTIN, .u.b = {"uchar"}, .sz = 1, .align = 1},
- {.type = BUILTIN, .u.b = {"ushort"}, .sz = 2, .align = 2},
- {.type = BUILTIN, .u.b = {"uint"}, .sz = 4, .align = 4},
- {.type = BUILTIN, .u.b = {"ulong"}, .sz = 8, .align = 8},
- {.type = BUILTIN, .u.b = {"ulonglong"}, .sz = 8, .align = 8}
+ .builtins =
+ {
+ {.type = BUILTIN, .u.b = {"void"}},
+ {.type = BUILTIN, .u.b = {"char"}, .sz = 1, .sign = 1, .align = 1},
+ {.type = BUILTIN, .u.b = {"schar"}, .sz = 1, .sign = 1, .align = 1},
+ {.type = BUILTIN, .u.b = {"short"}, .sz = 2, .sign = 1, .align = 2},
+ {.type = BUILTIN, .u.b = {"int"}, .sz = 4, .sign = 1, .align = 4},
+ {.type = BUILTIN, .u.b = {"long"}, .sz = 8, .sign = 1, .align = 8},
+ {.type = BUILTIN, .u.b = {"longlong"}, .sz = 8, .sign = 1, .align = 8},
+ {.type = BUILTIN, .u.b = {"uchar"}, .sz = 1, .align = 1},
+ {.type = BUILTIN, .u.b = {"ushort"}, .sz = 2, .align = 2},
+ {.type = BUILTIN, .u.b = {"uint"}, .sz = 4, .align = 4},
+ {.type = BUILTIN, .u.b = {"ulong"}, .sz = 8, .align = 8},
+ {.type = BUILTIN, .u.b = {"ulonglong"}, .sz = 8, .align = 8}
+ },
+
+ .ptr = {.type = P, .sz = 8, .align = 8}
};