-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.h
64 lines (59 loc) · 1.12 KB
/
node.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
#include<stdlib.h>
#include <ctype.h>
#include <string.h>
#include "container.h"
enum {
ND_NUM = 256,
ND_EQUAL,
ND_NEQUAL,
ND_IF,
ND_FOR,
ND_WHILE,
ND_RETURN, //262
ND_IDENT, //263
ND_BLOCK,
ND_GEQUAL,
ND_LEQUAL,
ND_FUNCTION,
ND_FUNCTION_DEF,
ND_ARGUMENT,
ND_ADDR,
ND_DEREF
};
typedef struct Node {
int ty;
struct Node *lhs;
struct Node *rhs;
struct Node *definition;
struct Node *condition;
struct Node *statement;
struct Node *initialize;
struct Node *control;
Vector *block_contents;
Vector *arguments;
Map *local_variable_map;
int *local_variable_count;
int val;
char *name;
int arg_count;
} Node;
Node *new_node(int ty, Node *lhs, Node *rhs);
Node *new_node_ident(char *name);
Node *new_node_num(int val);
Node *new_node_function(char *name);
//Node *new_node_function(char *name, int ty);
Node *new_node_argument(int val, int arg_count);
//int consume(int ty);
int consume(int ty);
Node *add();
Node *mul();
Node *term();
Node *assign();
Node *stmt();
Node *unary();
Node *comp();
Node *block_items();
void program();
void gen_lval(Node *node);
void gen(Node *node);
void gen_definition(Node *node);