-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathprogram.cpp
47 lines (43 loc) · 1.22 KB
/
program.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Implementation of the \ref Program class
*/
#include <llvm/Support/raw_ostream.h>
#include "program.h"
/**
* Constructor for the class
* @param name name of the decaf class
* @param fields field Declarations of the class
* @param methods method declarations of the class
*/
Program::Program(string name, class fieldDeclarations *fields, class methodDeclarations *methods) {
this->methods = methods;
this->name = std::move(name);
this->fields = fields;
this->compilerConstructs = new Constructs();
}
/**
* Generate the IR for the program
*/
Value *Program::generateCode() {
Value *V;
// Generate code for field Declarations
V = fields->generateCode(this->compilerConstructs);
if (V == nullptr) {
reportError("Invalid field Declarations");
return nullptr;
}
//Generate the code for method Declarations
V = methods->generateCode(this->compilerConstructs);
if (V == nullptr) {
reportError("Invalid method Declarations");
return nullptr;
}
return V;
}
/**
* Dump the IR generated onto stdout
*/
void Program::generateCodeDump() {
cerr << "Generating LLVM IR Code\n";
this->compilerConstructs->TheModule->print(llvm::outs(), nullptr);
}