aboutsummaryrefslogtreecommitdiff
path: root/src/prc1/parse.h
blob: 74380ed2cf713573ca14066fc4e91b76b5ab8f85 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#ifndef PARSE_H
#define PARSE_H

#include "arg.h"
#include "lex.h"
#include "storage.h"

struct u
{
    struct storage *storage;
};

struct s
{
    struct storage *storage;
};

union c
{
    unsigned long long uv;
    long long v;
};

struct p
{
    struct fn *fn;
};

struct t
{
    const struct type *alias;
};

struct ptr
{
    const struct type *t;
};

struct ary
{
    unsigned long long n;
    int etc;
};

struct builtin
{
    const char *name;
};

struct type
{
    enum ttype {U, S, C, P, T, PTR, ARY, BUILTIN} type;
    const struct tk *tk;
    size_t sz, align;
    int sign;
    struct type *child, *next;

    union
    {
        struct u u;
        struct s s;
        union c c;
        struct p p;
        struct t t;
        struct ptr ptr;
        struct ary ary;
        struct builtin b;
    } u;
};

struct sym
{
    enum symtype
    {
        SYM_ID,
        SYM_TMP,
        SYM_LIT,
        SYM_CAST,
        SYM_NUM,
        SYM_ADDR,
        SYM_SZ,
        SYM_CNT,
        SYM_OFF
    } type;

    struct sym *child, *next, *parent;
    const struct tk *tk;

    union
    {
        const struct tmp *tmp;
        const struct type *t;

        struct
        {
            int sign;
            union c c;
        } num;
    } u;
};

struct param
{
    const struct tk *tk;
    const struct stentry *entry;
};

struct pr
{
    const struct tk *tk, *using, *returning;
    struct param *params, *ret;
    size_t nparams;
    int variadic;
};

struct td
{
    const struct tk *tk;
    struct type *types;
};

struct tmp
{
    struct tk tk;
    struct stentry e;
    struct tmp *next;
};

struct fn
{
    const struct tk *tk, *im;
    const struct fn *parent;
    enum linkage {EXTERNAL, STATIC} linkage;
    struct storage *lk, *ws, *gl;
    struct stmt *stmts;
    struct sym *syms;
    struct tmp *tmps;
    struct im *imps;
    struct pr *pr;
    struct td *td;
    size_t nstmts, nimps, nblocks, ntmps, *blocks;
};

struct lit
{
    char *name;
    const struct tk *tk;
    const struct fn *fn;
    struct lit *next;
};

struct ast
{
    const struct args *args;
    const struct type *littype;
    struct fn *fns;
    struct lit *lits, *lastlit;
    struct type *types;
    size_t nfns, litcnt;
};

struct im
{
    struct lex l;
    struct ast ast;
};

int parse(const struct lex *l, struct ast *ast);
int parse_im(const struct lex *l, struct ast *ast);
void ast_free(struct ast *ast);

#endif