summaryrefslogtreecommitdiff
path: root/scope.h
blob: 4d6cc7fa541f8c648e38cdf7fa039552329191e3 (plain)
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
#ifndef VARS_H
#define VARS_H

struct storage_location {
    enum {
        STO_REG,
        STO_LABEL,
        STO_STACK,
        STO_IMM,
        STO_FN,
    } type;
    union {
        const struct reg* reg;
        const char* label;
        long long bp_offset;
        unsigned long long value;
        struct fn_decl_node* decl;
    };
};

struct type_def {
    const char* name;
    unsigned long long sz;
};

struct var_def {
    const char* name;
    struct storage_location loc;
    unsigned long long sz;
};

struct scope {
    struct type_def** types;
    unsigned long long type_sz;
    unsigned long long type_cap;

    struct var_def** vars;
    unsigned long long var_sz;
    unsigned long long var_cap;

    struct scope* next_out;
    unsigned long long bp_offset;
};

void scope_push(struct scope** p_scope);
void scope_pop(struct scope** p_scope);
void scope_install_default_types(struct scope* scope);
bool scope_get_type(
    const struct scope* scope,
    struct type_def* p_entry,
    const char* name);
void scope_define_type(struct scope* scope, struct type_def type);
bool scope_get_var(
    const struct scope* scope,
    struct var_def* p_entry,
    const char* name);
void scope_define_var(struct scope* scope, struct var_def var);

#endif