-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefs.cpp
More file actions
76 lines (65 loc) · 2.33 KB
/
Copy pathdefs.cpp
File metadata and controls
76 lines (65 loc) · 2.33 KB
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
#ifndef defs_hpp
#include "defs.hpp"
#define defs_hpp
#endif
using namespace std;
VarManager *varManager = new VarManager();
FuncManager *funcManager = new FuncManager();
RegManager *regManager = new RegManager();
vector<sysyAST *> globalInitList{};
sysyAST *sysyRoot;
eeyoreAST *eeyoreRoot;
tiggerAST *tiggerRoot;
vector<eeyoreAST *> eeyoreList{};
vector<eeyoreAST *> eeyoreDeclList{};
vector<eeyoreAST *> eeyoreStmtList{};
vector<tiggerAST *> tiggerList{};
vector<tiggerAST *> tiggerStmtList{};
int STK = 0;
string t0 = "s8";
int flatten(vector<int> &shape) {
/* return flattened size */
int ret = 1; for (auto x: shape) ret *= x; return ret;
}
void eeyoreStmt(eeyoreAST *x) { eeyoreStmtList.push_back(x); }
void eeyoreDecl(eeyoreAST *x) { eeyoreDeclList.push_back(x); }
void tiggerStmt(tiggerAST *x) { tiggerStmtList.push_back(x); }
void tiggerDecl(tiggerAST *x) { tiggerList.push_back(x); }
void print(string x) { cout << x << endl; }
void printTab(string x) { cout << "\t" + x << endl; }
bool isreg(string x) { return x[0] == 's' || x[0] == 't' || x[0] == 'a' || x == "x0"; }
bool islogicop(string x) { return x == "!=" || x == "==" || x == "<" || x == ">" || x == "<=" || x == ">="; }
bool isint10(int x) { return x >= -512 && x < 512; }
bool isint12(int x) { return x >= -2048 && x < 2048; }
bool is2power(int x) {return x > 0 && (x & -x) == x;}
int get2log(int x) {return x > 1 ? get2log(x >> 1) + 1 : 0 ;}
int binary_result(int a, string op, int b) {
if (op == "+") return a + b;
if (op == "-") return a - b;
if (op == "*") return a * b;
if (op == "/") return a / b;
if (op == "\%") return a % b;
if (op == "<") return a < b;
if (op == "<=") return a <= b;
if (op == ">") return a > b;
if (op == ">=") return a >= b;
if (op == "||") return a || b;
if (op == "&&") return a && b;
if (op == "==") return a == b;
if (op == "!=") return a != b;
assert(false);
}
int unary_result(string op, int b) {
if (op == "!") return !b;
if (op == "-") return -b;
assert(false);
}
string neg_logicop(string op) {
if (op == "==") return "!=";
if (op == "!=") return "==";
if (op == "<") return ">=";
if (op == ">") return "<=";
if (op == "<=") return ">";
if (op == ">=") return "<";
assert(false);
}