Move LLVM interface code out of bootstrap
This commit is contained in:
parent
f2edc8f42d
commit
0875459581
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,3 @@
|
|||||||
zig-cache/
|
zig-cache/
|
||||||
zig-out/
|
zig-out/
|
||||||
nat/
|
nat/
|
||||||
llvm*/
|
|
||||||
|
@ -102,10 +102,11 @@ pub fn build(b: *std.Build) !void {
|
|||||||
const llvm_lib_dir = try std.mem.concat(b.allocator, u8, &.{ llvm_path, "/lib" });
|
const llvm_lib_dir = try std.mem.concat(b.allocator, u8, &.{ llvm_path, "/lib" });
|
||||||
compiler.addIncludePath(std.Build.LazyPath.relative(llvm_include_dir));
|
compiler.addIncludePath(std.Build.LazyPath.relative(llvm_include_dir));
|
||||||
const cpp_files = .{
|
const cpp_files = .{
|
||||||
"bootstrap/backend/llvm.cpp",
|
"src/llvm/llvm.cpp",
|
||||||
"bootstrap/frontend/clang/main.cpp",
|
"src/llvm/lld.cpp",
|
||||||
"bootstrap/frontend/clang/cc1.cpp",
|
"src/llvm/clang_main.cpp",
|
||||||
"bootstrap/frontend/clang/cc1as.cpp",
|
"src/llvm/clang_cc1.cpp",
|
||||||
|
"src/llvm/clang_cc1as.cpp",
|
||||||
};
|
};
|
||||||
compiler.addCSourceFiles(.{
|
compiler.addCSourceFiles(.{
|
||||||
.files = &cpp_files,
|
.files = &cpp_files,
|
||||||
|
58
src/llvm/lld.cpp
Normal file
58
src/llvm/lld.cpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#include "lld/Common/CommonLinkerContext.h"
|
||||||
|
using namespace llvm;
|
||||||
|
|
||||||
|
enum class Format {
|
||||||
|
elf = 0,
|
||||||
|
macho = 1,
|
||||||
|
coff = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace lld {
|
||||||
|
namespace coff {
|
||||||
|
bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
|
||||||
|
llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput);
|
||||||
|
}
|
||||||
|
namespace elf {
|
||||||
|
bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
|
||||||
|
llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput);
|
||||||
|
}
|
||||||
|
namespace wasm {
|
||||||
|
bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
|
||||||
|
llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput);
|
||||||
|
}
|
||||||
|
namespace macho {
|
||||||
|
bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
|
||||||
|
llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void stream_to_string(raw_string_ostream& stream, const char** message_ptr, size_t* message_len);
|
||||||
|
|
||||||
|
extern "C" bool NativityLLDLink(Format format, const char** argument_ptr, size_t argument_count, const char** stdout_ptr, size_t* stdout_len, const char** stderr_ptr, size_t* stderr_len)
|
||||||
|
{
|
||||||
|
auto arguments = ArrayRef<const char*>(argument_ptr, argument_count);
|
||||||
|
std::string stdout_string;
|
||||||
|
raw_string_ostream stdout_stream(stdout_string);
|
||||||
|
|
||||||
|
std::string stderr_string;
|
||||||
|
raw_string_ostream stderr_stream(stderr_string);
|
||||||
|
|
||||||
|
bool success = false;
|
||||||
|
switch (format) {
|
||||||
|
case Format::elf:
|
||||||
|
success = lld::elf::link(arguments, stdout_stream, stderr_stream, true, false);
|
||||||
|
break;
|
||||||
|
case Format::coff:
|
||||||
|
success = lld::coff::link(arguments, stdout_stream, stderr_stream, true, false);
|
||||||
|
case Format::macho:
|
||||||
|
success = lld::macho::link(arguments, stdout_stream, stderr_stream, true, false);
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream_to_string(stdout_stream, stdout_ptr, stdout_len);
|
||||||
|
stream_to_string(stderr_stream, stderr_ptr, stderr_len);
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,6 @@
|
|||||||
#include "llvm/Support/TargetSelect.h"
|
#include "llvm/Support/TargetSelect.h"
|
||||||
#include "llvm/Support/FileSystem.h"
|
#include "llvm/Support/FileSystem.h"
|
||||||
|
|
||||||
#include "lld/Common/CommonLinkerContext.h"
|
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
@ -667,7 +666,7 @@ extern "C" Constant* NativityLLVMBuilderCreateGlobalStringPointer(IRBuilder<>& b
|
|||||||
return constant;
|
return constant;
|
||||||
}
|
}
|
||||||
|
|
||||||
void stream_to_string(raw_string_ostream& stream, const char** message_ptr, size_t* message_len)
|
extern "C" void stream_to_string(raw_string_ostream& stream, const char** message_ptr, size_t* message_len)
|
||||||
{
|
{
|
||||||
stream.flush();
|
stream.flush();
|
||||||
|
|
||||||
@ -850,25 +849,6 @@ extern "C" void NativityLLVMCallSetCallingConvention(CallBase& call_instruction,
|
|||||||
call_instruction.setCallingConv(calling_convention);
|
call_instruction.setCallingConv(calling_convention);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace lld {
|
|
||||||
namespace coff {
|
|
||||||
bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
|
|
||||||
llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput);
|
|
||||||
}
|
|
||||||
namespace elf {
|
|
||||||
bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
|
|
||||||
llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput);
|
|
||||||
}
|
|
||||||
namespace wasm {
|
|
||||||
bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
|
|
||||||
llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput);
|
|
||||||
}
|
|
||||||
namespace macho {
|
|
||||||
bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
|
|
||||||
llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void NativityLLVMInitializeCodeGeneration()
|
extern "C" void NativityLLVMInitializeCodeGeneration()
|
||||||
{
|
{
|
||||||
InitializeAllTargetInfos();
|
InitializeAllTargetInfos();
|
||||||
@ -942,40 +922,6 @@ extern "C" bool NativityLLVMModuleAddPassesToEmitFile(Module& module, TargetMach
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class Format {
|
|
||||||
elf = 0,
|
|
||||||
macho = 1,
|
|
||||||
coff = 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
extern "C" bool NativityLLDLink(Format format, const char** argument_ptr, size_t argument_count, const char** stdout_ptr, size_t* stdout_len, const char** stderr_ptr, size_t* stderr_len)
|
|
||||||
{
|
|
||||||
auto arguments = ArrayRef<const char*>(argument_ptr, argument_count);
|
|
||||||
std::string stdout_string;
|
|
||||||
raw_string_ostream stdout_stream(stdout_string);
|
|
||||||
|
|
||||||
std::string stderr_string;
|
|
||||||
raw_string_ostream stderr_stream(stderr_string);
|
|
||||||
|
|
||||||
bool success = false;
|
|
||||||
switch (format) {
|
|
||||||
case Format::elf:
|
|
||||||
success = lld::elf::link(arguments, stdout_stream, stderr_stream, true, false);
|
|
||||||
break;
|
|
||||||
case Format::coff:
|
|
||||||
success = lld::coff::link(arguments, stdout_stream, stderr_stream, true, false);
|
|
||||||
case Format::macho:
|
|
||||||
success = lld::macho::link(arguments, stdout_stream, stderr_stream, true, false);
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
stream_to_string(stdout_stream, stdout_ptr, stdout_len);
|
|
||||||
stream_to_string(stderr_stream, stderr_ptr, stderr_len);
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" bool NativityLLVMCompareTypes(Type* a, Type* b)
|
extern "C" bool NativityLLVMCompareTypes(Type* a, Type* b)
|
||||||
{
|
{
|
||||||
if (auto* int_a = dyn_cast<IntegerType>(a)) {
|
if (auto* int_a = dyn_cast<IntegerType>(a)) {
|
Loading…
x
Reference in New Issue
Block a user