Plug new bitcode generator in main.
This commit is contained in:
parent
a8fa0a1bff
commit
becafb4cd5
|
@ -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(
|
||||||
|
|
36
main.cpp
36
main.cpp
|
@ -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() {
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
for (int i = 1; i < argc; ++i) {
|
||||||
|
std::string inputname(argv[i]);
|
||||||
|
std::ifstream instream(inputname);
|
||||||
|
|
||||||
Program program;
|
Program program;
|
||||||
Scanner scanner(&std::cin);
|
Scanner scanner(&instream);
|
||||||
Parser parser(scanner, program);
|
Parser parser(scanner, program);
|
||||||
|
BitcodeEmitter emitter;
|
||||||
|
|
||||||
# if YYDEBUG
|
# if YYDEBUG
|
||||||
parser.set_debug_level(1);
|
parser.set_debug_level(1);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
parser.parse();
|
parser.parse();
|
||||||
CppEmitter emitter(&std::cout);
|
|
||||||
|
|
||||||
program.emit(&emitter);
|
boost::regex namere("^(.+)\\.mc$");
|
||||||
|
std::string outputname;
|
||||||
|
|
||||||
return 0;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user