-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9cc.h
95 lines (79 loc) · 1.22 KB
/
9cc.h
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
#ifndef _9CC_H
#define _9CC_H
enum {
TK_NUM = 256,
TK_IDENT,
TK_EOF,
};
typedef struct {
char *data;
int capacity;
int len;
} String;
typedef struct {
int ty;
int val;
char *input;
String *name;
} Token;
enum {
ND_NUM = 256, // 整数のノードの型
ND_EQ,
ND_NEQ,
ND_LTE,
ND_LT,
ND_GTE,
ND_GT,
ND_LOGICAL_AND,
ND_LOGICAL_OR,
ND_IDENT,
ND_FUNC_CALL,
ND_IF,
ND_ELSE,
ND_WHILE,
ND_RET,
};
typedef struct {
void **data;
int capacity;
int len;
} Vector;
typedef struct {
Vector *keys;
Vector *vals;
} Map;
typedef struct Node {
int ty;
// binop
struct Node* lhs;
struct Node* rhs;
// if stmt
struct Node* cond;
Vector* stmts;
struct Node* els;
struct Node* expr;
// number
int val;
// fn_call or ident
String *name;
Vector* args;
} Node;
typedef struct {
Map* vars;
int var_cnt;
} Scope;
Vector* tokens;
Vector* code;
Scope* global_scope;
String *new_string();
void str_push(String *str, char c);
void tokenize(char *p);
void gen(Node *node);
void parse();
Vector *new_vector();
void vec_push(Vector *vec, void* elem);
Map *new_map();
void map_put(Map *map, char *key, void *val);
void *map_get(Map *map, char *key);
void runtest();
#endif