-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathassign.cpp
More file actions
31 lines (24 loc) · 752 Bytes
/
assign.cpp
File metadata and controls
31 lines (24 loc) · 752 Bytes
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
#include "assign.hpp"
Assign::Assign(AbstractLvalue *l, Expr *e) : lval(l), expr(e) {}
Assign::~Assign() { delete lval; delete expr; }
void Assign::printAST(std::ostream &out) const {
out << *lval << " <- " << *expr;
}
void Assign::sem()
{
/* We check that lval is not a function inside lval->sem() */
if (!check_assignable_operands(lval, expr)) semError("Bad types (assign)");
}
llvm::Value* Assign::compile()
{
/* Compile expr to assign */
llvm::Value *val = expr->compile();
if (!val)
return nullptr;
/* Find the llvmAddr that corresponds to the variable we want to change */
llvmAddr var_addr = lval->findLLVMAddr();
if (var_addr == nullptr)
return nullptr;
Builder.CreateStore(val, var_addr);
return nullptr;
}