forked from JonathanMeans/EvilC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.cpp
31 lines (27 loc) · 888 Bytes
/
backend.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 "backend.h"
#include "file_utils.h"
#include "platform.h"
void generateExecutableFromBytecode(const Platform& platform,
std::filesystem::path llvmIrPath,
std::filesystem::path outputPath)
{
try
{
Platform().runProgram("clang", {"-m32", llvmIrPath.string()});
}
catch (...)
{
std::cerr << "Exception occurred calling hello\n";
}
std::filesystem::path compiledExePath(Platform().defaultOutputFilename);
if (!std::filesystem::exists(compiledExePath))
{
throw std::runtime_error(
std::string("Clang failed to create expected file ") +
compiledExePath.string());
}
deleteFile(llvmIrPath);
deleteFile(outputPath);
std::filesystem::copy(compiledExePath, outputPath);
deleteFile(compiledExePath);
}