-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathunaryExpression.cpp
31 lines (27 loc) · 936 Bytes
/
unaryExpression.cpp
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
/**
* Implementation of \ref unaryExpression class */
#include "unaryExpression.h"
using namespace std;
/**
* Constructor to the class
* @param opr operator in the unary expression
* @param expr body of the expression
*/
unaryExpression::unaryExpression(string opr, class Expression *expr) {
this->opr = std::move(opr);
this->body = expr;
this->etype = exprType::unExpr;
}
Value *unaryExpression::generateCode(Constructs *compilerConstructs) {
/// Generate IR for body of the expression
Value *v = body->generateCode(compilerConstructs);
if (body->getEtype() == exprType::location) {
v = compilerConstructs->Builder->CreateLoad(v);
}
/// Generate the code for operation based on the operator
if (opr == "-") {
return compilerConstructs->Builder->CreateNeg(v, "negtmp");
} else if (opr == "!") {
return compilerConstructs->Builder->CreateNot(v, "nottmp");
}
}