-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModule.cpp
31 lines (26 loc) · 876 Bytes
/
Module.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
#include "Module.h"
#include <iostream>
#include <fstream>
using namespace std;
/*
Define functions for Module class, this is the entrance of code generation
*/
//Add global definitions to a module
void Module::Add(GlobalDefinition *definition) {
definitions.push_back(definition);
}
//Emit every global definiton, also prepare the I/O
void Module::Emit(ofstream& os) {
os << "@.str = private unnamed_addr constant [3 x i8] c\"%d\\00\", align 1" << endl;
os << "@.str1 = private unnamed_addr constant [4 x i8] c\"%d\\0A\\00\", align 1" << endl;
for(int i = 0; i < definitions.size(); ++i) {
definitions[i]->Emit(os);
}
os << "declare i32 @scanf(i8*, ...)" << endl;
os << "declare i32 @printf(i8*, ...)" << endl;
}
void Module::Optimize() {
for(int i = 0; i < definitions.size(); ++i) {
definitions[i]->Optimize();
}
}