summaryrefslogtreecommitdiff
path: root/node/DeclNode.cc
blob: 63dc848525a32c16c2a80277314fe6e2ad88b2ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "DeclNode.hh"

#include <llvm/IR/IRBuilder.h>

namespace pcc {
VarDeclNode::VarDeclNode(Context* context, VariableList* scope,
                         std::list<Declaration> decls)
    : BaseNode(context)
    , scope_(scope)
    , decls_(decls) {}

void VarDeclNode::SetScope(VariableList* scope) { scope_ = scope; }

Value VarDeclNode::CodeGen() {
    llvm::IRBuilder<>* builder = context_->GetBuilder();
    for (auto& decl : decls_) {
        Value value = builder->CreateAlloca(std::get<1>(decl)->GetLLVMType());
        scope_->Add(std::get<0>(decl), {std::get<1>(decl), value});
    }
    return nullptr;
}

} // namespace pcc