-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnumericcond.cpp
More file actions
41 lines (34 loc) · 1.08 KB
/
numericcond.cpp
File metadata and controls
41 lines (34 loc) · 1.08 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
#include "numericcond.hpp"
NumericCond::NumericCond(Expr *l, char o, Expr *r) : left(l), op(o), right(r) {}
NumericCond::~NumericCond() { delete left; delete right; }
void NumericCond::printAST(std::ostream &out) const {
out << op << "(" << *left << ", " << *right << ")";
}
void NumericCond::sem()
{
if (check_assignable_operands(left, right)) expr_type = typeBoolean;
else semError("Type mismatch (numeric cond)");
}
llvm::Value* NumericCond::compile() {
llvm::Value *L = left->compile();
llvm::Value *R = right->compile();
if (!L || !R)
return nullptr;
switch (op) {
case '<':
return Builder.CreateICmpSLT(L, R, "cmplttmp");
case '>':
return Builder.CreateICmpSGT(L, R, "cmpgttmp");
case '#':
return Builder.CreateICmpNE(L, R, "cmpnetmp");
case '=':
return Builder.CreateICmpEQ(L, R, "cmpeqtmp");
case 'l':
return Builder.CreateICmpSLE(L, R, "cmpletmp");
case 'g':
return Builder.CreateICmpSGE(L, R, "cmpgetmp");
default:
return nullptr;
return nullptr;
}
}