memgraph/src/query_engine/code_compiler.hpp

43 lines
1.4 KiB
C++
Raw Normal View History

#pragma once
#include <string>
2016-07-18 01:32:35 +08:00
#include "exceptions/query_engine_exception.hpp"
#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>
class CodeCompiler
{
public:
void compile(const std::string &in_file, const std::string &out_file)
{
2016-07-18 01:32:35 +08:00
// generate compile command
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",
"-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) {
throw QueryEngineException("Code compilation error");
}
// TODO: use logger
std::cout << fmt::format("SUCCESS: Query Code Compilation: {} -> {}",
in_file, out_file) << std::endl;
}
};