forked from bhargavkulk/CSF363-baseline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathast.hh
94 lines (76 loc) · 1.74 KB
/
ast.hh
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
#ifndef AST_HH
#define AST_HH
#include <llvm/IR/Value.h>
#include <string>
#include <vector>
struct LLVMCompiler;
/**
Base node class. Defined as `abstract`.
*/
struct Node {
enum NodeType {
BIN_OP, INT_LIT, STMTS, ASSN, DBG, IDENT
} type;
virtual std::string to_string() = 0;
virtual llvm::Value *llvm_codegen(LLVMCompiler *compiler) = 0;
};
/**
Node for list of statements
*/
struct NodeStmts : public Node {
std::vector<Node*> list;
NodeStmts();
void push_back(Node *node);
std::string to_string();
llvm::Value *llvm_codegen(LLVMCompiler *compiler);
};
/**
Node for binary operations
*/
struct NodeBinOp : public Node {
enum Op {
PLUS, MINUS, MULT, DIV
} op;
Node *left, *right;
NodeBinOp(Op op, Node *leftptr, Node *rightptr);
std::string to_string();
llvm::Value *llvm_codegen(LLVMCompiler *compiler);
};
/**
Node for integer literals
*/
struct NodeInt : public Node {
int value;
NodeInt(int val);
std::string to_string();
llvm::Value *llvm_codegen(LLVMCompiler *compiler);
};
/**
Node for variable assignments
*/
struct NodeAssn : public Node {
std::string identifier;
Node *expression;
NodeAssn(std::string id, Node *expr);
std::string to_string();
llvm::Value *llvm_codegen(LLVMCompiler *compiler);
};
/**
Node for `dbg` statements
*/
struct NodeDebug : public Node {
Node *expression;
NodeDebug(Node *expr);
std::string to_string();
llvm::Value *llvm_codegen(LLVMCompiler *compiler);
};
/**
Node for idnetifiers
*/
struct NodeIdent : public Node {
std::string identifier;
NodeIdent(std::string ident);
std::string to_string();
llvm::Value *llvm_codegen(LLVMCompiler *compiler);
};
#endif