2016-01-27 06:40:11 +08:00
|
|
|
#pragma once
|
|
|
|
|
2016-02-08 05:56:52 +08:00
|
|
|
#include <string>
|
|
|
|
|
2016-07-24 10:47:48 +08:00
|
|
|
#include "exceptions/exceptions.hpp"
|
2016-02-08 05:56:52 +08:00
|
|
|
#include "utils/string/join.hpp"
|
|
|
|
|
2016-07-18 01:32:35 +08:00
|
|
|
// TODO:
|
|
|
|
// * all libraries have to be compiled in the server compile time
|
|
|
|
// * compile command has to be generated
|
|
|
|
#include <iostream>
|
|
|
|
|
2016-01-27 06:40:11 +08:00
|
|
|
class CodeCompiler
|
|
|
|
{
|
2016-02-08 05:56:52 +08:00
|
|
|
public:
|
2016-06-06 17:29:52 +08:00
|
|
|
void compile(const std::string &in_file, const std::string &out_file)
|
2016-02-08 05:56:52 +08:00
|
|
|
{
|
2016-07-18 01:32:35 +08:00
|
|
|
// generate compile command
|
2016-06-06 17:29:52 +08:00
|
|
|
auto compile_command =
|
|
|
|
utils::prints("clang++",
|
|
|
|
// "-std=c++1y -O2 -DNDEBUG", // compile flags
|
2016-07-18 01:32:35 +08:00
|
|
|
"-std=c++1y -DDEBUG", // compile flags
|
|
|
|
in_file, // input file
|
|
|
|
"-o", out_file, // ouput file
|
|
|
|
"-I./include", // include paths (TODO: parameter)
|
|
|
|
"-I./src", "-I../../libs/fmt",
|
2016-06-06 17:29:52 +08:00
|
|
|
"-shared -fPIC" // shared library flags
|
|
|
|
);
|
2016-02-11 06:34:49 +08:00
|
|
|
|
|
|
|
// synchronous call
|
2016-07-18 01:32:35 +08:00
|
|
|
auto compile_status = system(compile_command.c_str());
|
|
|
|
|
|
|
|
// if compilation has failed throw exception
|
|
|
|
if (compile_status == -1) {
|
2016-07-24 10:47:48 +08:00
|
|
|
throw QueryEngineException("Code compilation error. Generated code "
|
|
|
|
"is not compilable or compilation "
|
|
|
|
"settings are wrong");
|
2016-07-18 01:32:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: use logger
|
|
|
|
std::cout << fmt::format("SUCCESS: Query Code Compilation: {} -> {}",
|
2016-07-24 10:47:48 +08:00
|
|
|
in_file, out_file)
|
|
|
|
<< std::endl;
|
2016-02-08 05:56:52 +08:00
|
|
|
}
|
2016-01-27 06:40:11 +08:00
|
|
|
};
|