Plug new bitcode generator in main.

This commit is contained in:
Stefano Sanfilippo 2015-03-07 19:43:53 +01:00
parent a8fa0a1bff
commit becafb4cd5
2 changed files with 38 additions and 12 deletions

View File

@ -65,7 +65,7 @@ elseif(BISON_VERSION VERSION_LESS 3.0)
endif() endif()
## 3. External components ## 3. External components
find_package(Boost 1.54 REQUIRED) find_package(Boost 1.48 REQUIRED regex)
find_package(LLVM REQUIRED CONFIG) find_package(LLVM REQUIRED CONFIG)
add_definitions( add_definitions(

View File

@ -20,26 +20,52 @@
#include "Scanner.hpp" #include "Scanner.hpp"
#include "Parser.hpp" #include "Parser.hpp"
#include "CppEmitter.hpp" #include "CppEmitter.hpp"
#include "BitcodeEmitter.hpp"
#include <llvm/Bitcode/ReaderWriter.h>
#include <llvm/Support/FileSystem.h>
#include <llvm/Support/raw_os_ostream.h>
#include <boost/regex.hpp>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <string>
#include <regex>
using namespace monicelli; using namespace monicelli;
int main() {
Program program;
Scanner scanner(&std::cin);
Parser parser(scanner, program);
#if YYDEBUG int main(int argc, char **argv) {
parser.set_debug_level(1); for (int i = 1; i < argc; ++i) {
#endif std::string inputname(argv[i]);
std::ifstream instream(inputname);
parser.parse(); Program program;
CppEmitter emitter(&std::cout); Scanner scanner(&instream);
Parser parser(scanner, program);
BitcodeEmitter emitter;
program.emit(&emitter); # if YYDEBUG
parser.set_debug_level(1);
# endif
return 0; parser.parse();
boost::regex namere("^(.+)\\.mc$");
std::string outputname;
if (boost::regex_match(inputname, namere)) {
outputname = boost::regex_replace(inputname, namere, "$1.bc");
} else {
outputname = inputname + ".bc";
}
if (!program.emit(&emitter)) return 1;
std::ofstream outstream(outputname);
llvm::raw_os_ostream stream(outstream);
llvm::WriteBitcodeToFile(&emitter.getModule(), stream);
}
} }