mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-30 04:56:25 +03:00
Auto merge of #38701 - karpinski:rustllvm-style, r=brson
Making code style consistent for src/rustllvm (#38688) Part of #38688 r? @brson
This commit is contained in:
+137
-144
@@ -21,52 +21,51 @@ struct RustArchiveMember {
|
||||
const char *name;
|
||||
Archive::Child child;
|
||||
|
||||
RustArchiveMember(): filename(NULL), name(NULL),
|
||||
RustArchiveMember()
|
||||
: filename(nullptr), name(nullptr),
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
child(NULL, NULL, NULL)
|
||||
child(nullptr, nullptr, nullptr)
|
||||
#else
|
||||
child(NULL, NULL)
|
||||
child(nullptr, nullptr)
|
||||
#endif
|
||||
{}
|
||||
{
|
||||
}
|
||||
~RustArchiveMember() {}
|
||||
};
|
||||
|
||||
|
||||
struct RustArchiveIterator {
|
||||
bool first;
|
||||
Archive::child_iterator cur;
|
||||
Archive::child_iterator end;
|
||||
bool first;
|
||||
Archive::child_iterator cur;
|
||||
Archive::child_iterator end;
|
||||
#if LLVM_VERSION_GE(3, 9)
|
||||
Error err;
|
||||
Error err;
|
||||
|
||||
RustArchiveIterator() : first(true), err(Error::success()) { }
|
||||
RustArchiveIterator() : first(true), err(Error::success()) {}
|
||||
#else
|
||||
RustArchiveIterator() : first(true) { }
|
||||
RustArchiveIterator() : first(true) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
enum class LLVMRustArchiveKind {
|
||||
Other,
|
||||
GNU,
|
||||
MIPS64,
|
||||
BSD,
|
||||
COFF,
|
||||
Other,
|
||||
GNU,
|
||||
MIPS64,
|
||||
BSD,
|
||||
COFF,
|
||||
};
|
||||
|
||||
static Archive::Kind
|
||||
from_rust(LLVMRustArchiveKind kind)
|
||||
{
|
||||
switch (kind) {
|
||||
case LLVMRustArchiveKind::GNU:
|
||||
return Archive::K_GNU;
|
||||
case LLVMRustArchiveKind::MIPS64:
|
||||
return Archive::K_MIPS64;
|
||||
case LLVMRustArchiveKind::BSD:
|
||||
return Archive::K_BSD;
|
||||
case LLVMRustArchiveKind::COFF:
|
||||
return Archive::K_COFF;
|
||||
default:
|
||||
llvm_unreachable("Bad ArchiveKind.");
|
||||
static Archive::Kind from_rust(LLVMRustArchiveKind kind) {
|
||||
switch (kind) {
|
||||
case LLVMRustArchiveKind::GNU:
|
||||
return Archive::K_GNU;
|
||||
case LLVMRustArchiveKind::MIPS64:
|
||||
return Archive::K_MIPS64;
|
||||
case LLVMRustArchiveKind::BSD:
|
||||
return Archive::K_BSD;
|
||||
case LLVMRustArchiveKind::COFF:
|
||||
return Archive::K_COFF;
|
||||
default:
|
||||
llvm_unreachable("Bad ArchiveKind.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,174 +75,166 @@ typedef Archive::Child *LLVMRustArchiveChildRef;
|
||||
typedef Archive::Child const *LLVMRustArchiveChildConstRef;
|
||||
typedef RustArchiveIterator *LLVMRustArchiveIteratorRef;
|
||||
|
||||
extern "C" LLVMRustArchiveRef
|
||||
LLVMRustOpenArchive(char *path) {
|
||||
ErrorOr<std::unique_ptr<MemoryBuffer>> buf_or = MemoryBuffer::getFile(path,
|
||||
-1,
|
||||
false);
|
||||
if (!buf_or) {
|
||||
LLVMRustSetLastError(buf_or.getError().message().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
extern "C" LLVMRustArchiveRef LLVMRustOpenArchive(char *path) {
|
||||
ErrorOr<std::unique_ptr<MemoryBuffer>> buf_or =
|
||||
MemoryBuffer::getFile(path, -1, false);
|
||||
if (!buf_or) {
|
||||
LLVMRustSetLastError(buf_or.getError().message().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
ErrorOr<std::unique_ptr<Archive>> archive_or =
|
||||
ErrorOr<std::unique_ptr<Archive>> archive_or =
|
||||
#else
|
||||
Expected<std::unique_ptr<Archive>> archive_or =
|
||||
Expected<std::unique_ptr<Archive>> archive_or =
|
||||
#endif
|
||||
Archive::create(buf_or.get()->getMemBufferRef());
|
||||
Archive::create(buf_or.get()->getMemBufferRef());
|
||||
|
||||
if (!archive_or) {
|
||||
if (!archive_or) {
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
LLVMRustSetLastError(archive_or.getError().message().c_str());
|
||||
LLVMRustSetLastError(archive_or.getError().message().c_str());
|
||||
#else
|
||||
LLVMRustSetLastError(toString(archive_or.takeError()).c_str());
|
||||
LLVMRustSetLastError(toString(archive_or.takeError()).c_str());
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
OwningBinary<Archive> *ret = new OwningBinary<Archive>(
|
||||
std::move(archive_or.get()), std::move(buf_or.get()));
|
||||
OwningBinary<Archive> *ret = new OwningBinary<Archive>(
|
||||
std::move(archive_or.get()), std::move(buf_or.get()));
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustDestroyArchive(LLVMRustArchiveRef ar) {
|
||||
delete ar;
|
||||
}
|
||||
extern "C" void LLVMRustDestroyArchive(LLVMRustArchiveRef ar) { delete ar; }
|
||||
|
||||
extern "C" LLVMRustArchiveIteratorRef
|
||||
LLVMRustArchiveIteratorNew(LLVMRustArchiveRef ra) {
|
||||
Archive *ar = ra->getBinary();
|
||||
RustArchiveIterator *rai = new RustArchiveIterator();
|
||||
Archive *ar = ra->getBinary();
|
||||
RustArchiveIterator *rai = new RustArchiveIterator();
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
rai->cur = ar->child_begin();
|
||||
rai->cur = ar->child_begin();
|
||||
#else
|
||||
rai->cur = ar->child_begin(rai->err);
|
||||
if (rai->err) {
|
||||
LLVMRustSetLastError(toString(std::move(rai->err)).c_str());
|
||||
delete rai;
|
||||
return NULL;
|
||||
}
|
||||
rai->cur = ar->child_begin(rai->err);
|
||||
if (rai->err) {
|
||||
LLVMRustSetLastError(toString(std::move(rai->err)).c_str());
|
||||
delete rai;
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
rai->end = ar->child_end();
|
||||
return rai;
|
||||
rai->end = ar->child_end();
|
||||
return rai;
|
||||
}
|
||||
|
||||
extern "C" LLVMRustArchiveChildConstRef
|
||||
LLVMRustArchiveIteratorNext(LLVMRustArchiveIteratorRef rai) {
|
||||
if (rai->cur == rai->end) return nullptr;
|
||||
if (rai->cur == rai->end)
|
||||
return nullptr;
|
||||
|
||||
// Advancing the iterator validates the next child, and this can
|
||||
// uncover an error. LLVM requires that we check all Errors,
|
||||
// so we only advance the iterator if we actually need to fetch
|
||||
// the next child.
|
||||
// This means we must not advance the iterator in the *first* call,
|
||||
// but instead advance it *before* fetching the child in all later calls.
|
||||
if (!rai->first) {
|
||||
++rai->cur;
|
||||
// Advancing the iterator validates the next child, and this can
|
||||
// uncover an error. LLVM requires that we check all Errors,
|
||||
// so we only advance the iterator if we actually need to fetch
|
||||
// the next child.
|
||||
// This means we must not advance the iterator in the *first* call,
|
||||
// but instead advance it *before* fetching the child in all later calls.
|
||||
if (!rai->first) {
|
||||
++rai->cur;
|
||||
#if LLVM_VERSION_GE(3, 9)
|
||||
if (rai->err) {
|
||||
LLVMRustSetLastError(toString(std::move(rai->err)).c_str());
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
rai->first = false;
|
||||
if (rai->err) {
|
||||
LLVMRustSetLastError(toString(std::move(rai->err)).c_str());
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
rai->first = false;
|
||||
}
|
||||
|
||||
if (rai->cur == rai->end) return nullptr;
|
||||
if (rai->cur == rai->end)
|
||||
return nullptr;
|
||||
|
||||
#if LLVM_VERSION_EQ(3, 8)
|
||||
const ErrorOr<Archive::Child>* cur = rai->cur.operator->();
|
||||
if (!*cur) {
|
||||
LLVMRustSetLastError(cur->getError().message().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
const Archive::Child &child = cur->get();
|
||||
const ErrorOr<Archive::Child> *cur = rai->cur.operator->();
|
||||
if (!*cur) {
|
||||
LLVMRustSetLastError(cur->getError().message().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
const Archive::Child &child = cur->get();
|
||||
#else
|
||||
const Archive::Child &child = *rai->cur.operator->();
|
||||
const Archive::Child &child = *rai->cur.operator->();
|
||||
#endif
|
||||
Archive::Child *ret = new Archive::Child(child);
|
||||
Archive::Child *ret = new Archive::Child(child);
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustArchiveChildFree(LLVMRustArchiveChildRef child) {
|
||||
delete child;
|
||||
extern "C" void LLVMRustArchiveChildFree(LLVMRustArchiveChildRef child) {
|
||||
delete child;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustArchiveIteratorFree(LLVMRustArchiveIteratorRef rai) {
|
||||
delete rai;
|
||||
extern "C" void LLVMRustArchiveIteratorFree(LLVMRustArchiveIteratorRef rai) {
|
||||
delete rai;
|
||||
}
|
||||
|
||||
extern "C" const char*
|
||||
extern "C" const char *
|
||||
LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef child, size_t *size) {
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
Expected<StringRef> name_or_err = child->getName();
|
||||
if (!name_or_err) {
|
||||
// rustc_llvm currently doesn't use this error string, but it might be useful
|
||||
// in the future, and in the mean time this tells LLVM that the error was
|
||||
// not ignored and that it shouldn't abort the process.
|
||||
LLVMRustSetLastError(toString(name_or_err.takeError()).c_str());
|
||||
return NULL;
|
||||
}
|
||||
Expected<StringRef> name_or_err = child->getName();
|
||||
if (!name_or_err) {
|
||||
// rustc_llvm currently doesn't use this error string, but it might be useful
|
||||
// in the future, and in the mean time this tells LLVM that the error was
|
||||
// not ignored and that it shouldn't abort the process.
|
||||
LLVMRustSetLastError(toString(name_or_err.takeError()).c_str());
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
ErrorOr<StringRef> name_or_err = child->getName();
|
||||
if (name_or_err.getError())
|
||||
return NULL;
|
||||
ErrorOr<StringRef> name_or_err = child->getName();
|
||||
if (name_or_err.getError())
|
||||
return nullptr;
|
||||
#endif
|
||||
StringRef name = name_or_err.get();
|
||||
*size = name.size();
|
||||
return name.data();
|
||||
StringRef name = name_or_err.get();
|
||||
*size = name.size();
|
||||
return name.data();
|
||||
}
|
||||
|
||||
extern "C" const char*
|
||||
LLVMRustArchiveChildData(LLVMRustArchiveChildRef child, size_t *size) {
|
||||
StringRef buf;
|
||||
extern "C" const char *LLVMRustArchiveChildData(LLVMRustArchiveChildRef child,
|
||||
size_t *size) {
|
||||
StringRef buf;
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
Expected<StringRef> buf_or_err = child->getBuffer();
|
||||
if (!buf_or_err) {
|
||||
LLVMRustSetLastError(toString(buf_or_err.takeError()).c_str());
|
||||
return NULL;
|
||||
}
|
||||
Expected<StringRef> buf_or_err = child->getBuffer();
|
||||
if (!buf_or_err) {
|
||||
LLVMRustSetLastError(toString(buf_or_err.takeError()).c_str());
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
ErrorOr<StringRef> buf_or_err = child->getBuffer();
|
||||
if (buf_or_err.getError()) {
|
||||
LLVMRustSetLastError(buf_or_err.getError().message().c_str());
|
||||
return NULL;
|
||||
}
|
||||
ErrorOr<StringRef> buf_or_err = child->getBuffer();
|
||||
if (buf_or_err.getError()) {
|
||||
LLVMRustSetLastError(buf_or_err.getError().message().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
buf = buf_or_err.get();
|
||||
*size = buf.size();
|
||||
return buf.data();
|
||||
buf = buf_or_err.get();
|
||||
*size = buf.size();
|
||||
return buf.data();
|
||||
}
|
||||
|
||||
extern "C" LLVMRustArchiveMemberRef
|
||||
LLVMRustArchiveMemberNew(char *Filename, char *Name,
|
||||
LLVMRustArchiveChildRef child) {
|
||||
RustArchiveMember *Member = new RustArchiveMember;
|
||||
Member->filename = Filename;
|
||||
Member->name = Name;
|
||||
if (child)
|
||||
Member->child = *child;
|
||||
return Member;
|
||||
LLVMRustArchiveChildRef child) {
|
||||
RustArchiveMember *Member = new RustArchiveMember;
|
||||
Member->filename = Filename;
|
||||
Member->name = Name;
|
||||
if (child)
|
||||
Member->child = *child;
|
||||
return Member;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustArchiveMemberFree(LLVMRustArchiveMemberRef Member) {
|
||||
delete Member;
|
||||
extern "C" void LLVMRustArchiveMemberFree(LLVMRustArchiveMemberRef Member) {
|
||||
delete Member;
|
||||
}
|
||||
|
||||
extern "C" LLVMRustResult
|
||||
LLVMRustWriteArchive(char *Dst,
|
||||
size_t NumMembers,
|
||||
LLVMRustWriteArchive(char *Dst, size_t NumMembers,
|
||||
const LLVMRustArchiveMemberRef *NewMembers,
|
||||
bool WriteSymbtab,
|
||||
LLVMRustArchiveKind rust_kind) {
|
||||
bool WriteSymbtab, LLVMRustArchiveKind rust_kind) {
|
||||
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
std::vector<NewArchiveIterator> Members;
|
||||
@@ -257,7 +248,8 @@ LLVMRustWriteArchive(char *Dst,
|
||||
assert(Member->name);
|
||||
if (Member->filename) {
|
||||
#if LLVM_VERSION_GE(3, 9)
|
||||
Expected<NewArchiveMember> MOrErr = NewArchiveMember::getFile(Member->filename, true);
|
||||
Expected<NewArchiveMember> MOrErr =
|
||||
NewArchiveMember::getFile(Member->filename, true);
|
||||
if (!MOrErr) {
|
||||
LLVMRustSetLastError(toString(MOrErr.takeError()).c_str());
|
||||
return LLVMRustResult::Failure;
|
||||
@@ -272,7 +264,8 @@ LLVMRustWriteArchive(char *Dst,
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
Members.push_back(NewArchiveIterator(Member->child, Member->name));
|
||||
#else
|
||||
Expected<NewArchiveMember> MOrErr = NewArchiveMember::getOldMember(Member->child, true);
|
||||
Expected<NewArchiveMember> MOrErr =
|
||||
NewArchiveMember::getOldMember(Member->child, true);
|
||||
if (!MOrErr) {
|
||||
LLVMRustSetLastError(toString(MOrErr.takeError()).c_str());
|
||||
return LLVMRustResult::Failure;
|
||||
|
||||
+293
-337
@@ -12,12 +12,12 @@
|
||||
|
||||
#include "rustllvm.h"
|
||||
|
||||
#include "llvm/Support/CBindingWrapping.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
#include "llvm/Analysis/TargetLibraryInfo.h"
|
||||
#include "llvm/Analysis/TargetTransformInfo.h"
|
||||
#include "llvm/IR/AutoUpgrade.h"
|
||||
#include "llvm/Support/CBindingWrapping.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Target/TargetSubtargetInfo.h"
|
||||
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
||||
@@ -38,10 +38,10 @@ typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
|
||||
|
||||
DEFINE_STDCXX_CONVERSION_FUNCTIONS(Pass, LLVMPassRef)
|
||||
DEFINE_STDCXX_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef)
|
||||
DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBuilder, LLVMPassManagerBuilderRef)
|
||||
DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBuilder,
|
||||
LLVMPassManagerBuilderRef)
|
||||
|
||||
extern "C" void
|
||||
LLVMInitializePasses() {
|
||||
extern "C" void LLVMInitializePasses() {
|
||||
PassRegistry &Registry = *PassRegistry::getPassRegistry();
|
||||
initializeCore(Registry);
|
||||
initializeCodeGen(Registry);
|
||||
@@ -64,44 +64,39 @@ enum class LLVMRustPassKind {
|
||||
Module,
|
||||
};
|
||||
|
||||
static LLVMRustPassKind
|
||||
to_rust(PassKind kind)
|
||||
{
|
||||
static LLVMRustPassKind to_rust(PassKind kind) {
|
||||
switch (kind) {
|
||||
case PT_Function:
|
||||
return LLVMRustPassKind::Function;
|
||||
return LLVMRustPassKind::Function;
|
||||
case PT_Module:
|
||||
return LLVMRustPassKind::Module;
|
||||
return LLVMRustPassKind::Module;
|
||||
default:
|
||||
return LLVMRustPassKind::Other;
|
||||
return LLVMRustPassKind::Other;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" LLVMPassRef
|
||||
LLVMRustFindAndCreatePass(const char *PassName) {
|
||||
StringRef SR(PassName);
|
||||
PassRegistry *PR = PassRegistry::getPassRegistry();
|
||||
extern "C" LLVMPassRef LLVMRustFindAndCreatePass(const char *PassName) {
|
||||
StringRef SR(PassName);
|
||||
PassRegistry *PR = PassRegistry::getPassRegistry();
|
||||
|
||||
const PassInfo *PI = PR->getPassInfo(SR);
|
||||
if (PI) {
|
||||
return wrap(PI->createPass());
|
||||
}
|
||||
return NULL;
|
||||
const PassInfo *PI = PR->getPassInfo(SR);
|
||||
if (PI) {
|
||||
return wrap(PI->createPass());
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
extern "C" LLVMRustPassKind
|
||||
LLVMRustPassKind(LLVMPassRef rust_pass) {
|
||||
assert(rust_pass);
|
||||
Pass *pass = unwrap(rust_pass);
|
||||
return to_rust(pass->getPassKind());
|
||||
extern "C" LLVMRustPassKind LLVMRustPassKind(LLVMPassRef rust_pass) {
|
||||
assert(rust_pass);
|
||||
Pass *pass = unwrap(rust_pass);
|
||||
return to_rust(pass->getPassKind());
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustAddPass(LLVMPassManagerRef PM, LLVMPassRef rust_pass) {
|
||||
assert(rust_pass);
|
||||
Pass *pass = unwrap(rust_pass);
|
||||
PassManagerBase *pm = unwrap(PM);
|
||||
pm->add(pass);
|
||||
extern "C" void LLVMRustAddPass(LLVMPassManagerRef PM, LLVMPassRef rust_pass) {
|
||||
assert(rust_pass);
|
||||
Pass *pass = unwrap(rust_pass);
|
||||
PassManagerBase *pm = unwrap(PM);
|
||||
pm->add(pass);
|
||||
}
|
||||
|
||||
#ifdef LLVM_COMPONENT_X86
|
||||
@@ -146,100 +141,94 @@ LLVMRustAddPass(LLVMPassManagerRef PM, LLVMPassRef rust_pass) {
|
||||
#define SUBTARGET_MSP430
|
||||
#endif
|
||||
|
||||
#define GEN_SUBTARGETS \
|
||||
SUBTARGET_X86 \
|
||||
SUBTARGET_ARM \
|
||||
SUBTARGET_AARCH64 \
|
||||
SUBTARGET_MIPS \
|
||||
SUBTARGET_PPC \
|
||||
SUBTARGET_SYSTEMZ \
|
||||
SUBTARGET_MSP430
|
||||
#define GEN_SUBTARGETS \
|
||||
SUBTARGET_X86 \
|
||||
SUBTARGET_ARM \
|
||||
SUBTARGET_AARCH64 \
|
||||
SUBTARGET_MIPS \
|
||||
SUBTARGET_PPC \
|
||||
SUBTARGET_SYSTEMZ \
|
||||
SUBTARGET_MSP430
|
||||
|
||||
#define SUBTARGET(x) namespace llvm { \
|
||||
extern const SubtargetFeatureKV x##FeatureKV[]; \
|
||||
extern const SubtargetFeatureKV x##SubTypeKV[]; \
|
||||
#define SUBTARGET(x) \
|
||||
namespace llvm { \
|
||||
extern const SubtargetFeatureKV x##FeatureKV[]; \
|
||||
extern const SubtargetFeatureKV x##SubTypeKV[]; \
|
||||
}
|
||||
|
||||
GEN_SUBTARGETS
|
||||
#undef SUBTARGET
|
||||
|
||||
extern "C" bool
|
||||
LLVMRustHasFeature(LLVMTargetMachineRef TM,
|
||||
const char *feature) {
|
||||
TargetMachine *Target = unwrap(TM);
|
||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||
const FeatureBitset &Bits = MCInfo->getFeatureBits();
|
||||
const llvm::SubtargetFeatureKV *FeatureEntry;
|
||||
extern "C" bool LLVMRustHasFeature(LLVMTargetMachineRef TM,
|
||||
const char *feature) {
|
||||
TargetMachine *Target = unwrap(TM);
|
||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||
const FeatureBitset &Bits = MCInfo->getFeatureBits();
|
||||
const llvm::SubtargetFeatureKV *FeatureEntry;
|
||||
|
||||
#define SUBTARGET(x) \
|
||||
if (MCInfo->isCPUStringValid(x##SubTypeKV[0].Key)) { \
|
||||
FeatureEntry = x##FeatureKV; \
|
||||
} else
|
||||
#define SUBTARGET(x) \
|
||||
if (MCInfo->isCPUStringValid(x##SubTypeKV[0].Key)) { \
|
||||
FeatureEntry = x##FeatureKV; \
|
||||
} else
|
||||
|
||||
GEN_SUBTARGETS {
|
||||
return false;
|
||||
}
|
||||
GEN_SUBTARGETS { return false; }
|
||||
#undef SUBTARGET
|
||||
|
||||
while (strcmp(feature, FeatureEntry->Key) != 0)
|
||||
FeatureEntry++;
|
||||
while (strcmp(feature, FeatureEntry->Key) != 0)
|
||||
FeatureEntry++;
|
||||
|
||||
return (Bits & FeatureEntry->Value) == FeatureEntry->Value;
|
||||
return (Bits & FeatureEntry->Value) == FeatureEntry->Value;
|
||||
}
|
||||
|
||||
enum class LLVMRustCodeModel {
|
||||
Other,
|
||||
Default,
|
||||
JITDefault,
|
||||
Small,
|
||||
Kernel,
|
||||
Medium,
|
||||
Large,
|
||||
Other,
|
||||
Default,
|
||||
JITDefault,
|
||||
Small,
|
||||
Kernel,
|
||||
Medium,
|
||||
Large,
|
||||
};
|
||||
|
||||
static CodeModel::Model
|
||||
from_rust(LLVMRustCodeModel model)
|
||||
{
|
||||
switch (model) {
|
||||
case LLVMRustCodeModel::Default:
|
||||
return CodeModel::Default;
|
||||
case LLVMRustCodeModel::JITDefault:
|
||||
return CodeModel::JITDefault;
|
||||
case LLVMRustCodeModel::Small:
|
||||
return CodeModel::Small;
|
||||
case LLVMRustCodeModel::Kernel:
|
||||
return CodeModel::Kernel;
|
||||
case LLVMRustCodeModel::Medium:
|
||||
return CodeModel::Medium;
|
||||
case LLVMRustCodeModel::Large:
|
||||
return CodeModel::Large;
|
||||
default:
|
||||
llvm_unreachable("Bad CodeModel.");
|
||||
static CodeModel::Model from_rust(LLVMRustCodeModel model) {
|
||||
switch (model) {
|
||||
case LLVMRustCodeModel::Default:
|
||||
return CodeModel::Default;
|
||||
case LLVMRustCodeModel::JITDefault:
|
||||
return CodeModel::JITDefault;
|
||||
case LLVMRustCodeModel::Small:
|
||||
return CodeModel::Small;
|
||||
case LLVMRustCodeModel::Kernel:
|
||||
return CodeModel::Kernel;
|
||||
case LLVMRustCodeModel::Medium:
|
||||
return CodeModel::Medium;
|
||||
case LLVMRustCodeModel::Large:
|
||||
return CodeModel::Large;
|
||||
default:
|
||||
llvm_unreachable("Bad CodeModel.");
|
||||
}
|
||||
}
|
||||
|
||||
enum class LLVMRustCodeGenOptLevel {
|
||||
Other,
|
||||
None,
|
||||
Less,
|
||||
Default,
|
||||
Aggressive,
|
||||
Other,
|
||||
None,
|
||||
Less,
|
||||
Default,
|
||||
Aggressive,
|
||||
};
|
||||
|
||||
static CodeGenOpt::Level
|
||||
from_rust(LLVMRustCodeGenOptLevel level)
|
||||
{
|
||||
switch (level) {
|
||||
case LLVMRustCodeGenOptLevel::None:
|
||||
return CodeGenOpt::None;
|
||||
case LLVMRustCodeGenOptLevel::Less:
|
||||
return CodeGenOpt::Less;
|
||||
case LLVMRustCodeGenOptLevel::Default:
|
||||
return CodeGenOpt::Default;
|
||||
case LLVMRustCodeGenOptLevel::Aggressive:
|
||||
return CodeGenOpt::Aggressive;
|
||||
default:
|
||||
llvm_unreachable("Bad CodeGenOptLevel.");
|
||||
static CodeGenOpt::Level from_rust(LLVMRustCodeGenOptLevel level) {
|
||||
switch (level) {
|
||||
case LLVMRustCodeGenOptLevel::None:
|
||||
return CodeGenOpt::None;
|
||||
case LLVMRustCodeGenOptLevel::Less:
|
||||
return CodeGenOpt::Less;
|
||||
case LLVMRustCodeGenOptLevel::Default:
|
||||
return CodeGenOpt::Default;
|
||||
case LLVMRustCodeGenOptLevel::Aggressive:
|
||||
return CodeGenOpt::Aggressive;
|
||||
default:
|
||||
llvm_unreachable("Bad CodeGenOptLevel.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,234 +242,209 @@ static size_t getLongestEntryLength(ArrayRef<SubtargetFeatureKV> Table) {
|
||||
return MaxLen;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM) {
|
||||
const TargetMachine *Target = unwrap(TM);
|
||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||
const ArrayRef<SubtargetFeatureKV> CPUTable = MCInfo->getCPUTable();
|
||||
unsigned MaxCPULen = getLongestEntryLength(CPUTable);
|
||||
extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM) {
|
||||
const TargetMachine *Target = unwrap(TM);
|
||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||
const ArrayRef<SubtargetFeatureKV> CPUTable = MCInfo->getCPUTable();
|
||||
unsigned MaxCPULen = getLongestEntryLength(CPUTable);
|
||||
|
||||
printf("Available CPUs for this target:\n");
|
||||
for (auto &CPU : CPUTable)
|
||||
printf(" %-*s - %s.\n", MaxCPULen, CPU.Key, CPU.Desc);
|
||||
printf("\n");
|
||||
printf("Available CPUs for this target:\n");
|
||||
for (auto &CPU : CPUTable)
|
||||
printf(" %-*s - %s.\n", MaxCPULen, CPU.Key, CPU.Desc);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustPrintTargetFeatures(LLVMTargetMachineRef TM) {
|
||||
const TargetMachine *Target = unwrap(TM);
|
||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||
const ArrayRef<SubtargetFeatureKV> FeatTable = MCInfo->getFeatureTable();
|
||||
unsigned MaxFeatLen = getLongestEntryLength(FeatTable);
|
||||
extern "C" void LLVMRustPrintTargetFeatures(LLVMTargetMachineRef TM) {
|
||||
const TargetMachine *Target = unwrap(TM);
|
||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||
const ArrayRef<SubtargetFeatureKV> FeatTable = MCInfo->getFeatureTable();
|
||||
unsigned MaxFeatLen = getLongestEntryLength(FeatTable);
|
||||
|
||||
printf("Available features for this target:\n");
|
||||
for (auto &Feature : FeatTable)
|
||||
printf(" %-*s - %s.\n", MaxFeatLen, Feature.Key, Feature.Desc);
|
||||
printf("\n");
|
||||
printf("Available features for this target:\n");
|
||||
for (auto &Feature : FeatTable)
|
||||
printf(" %-*s - %s.\n", MaxFeatLen, Feature.Key, Feature.Desc);
|
||||
printf("\n");
|
||||
|
||||
printf("Use +feature to enable a feature, or -feature to disable it.\n"
|
||||
"For example, rustc -C -target-cpu=mycpu -C target-feature=+feature1,-feature2\n\n");
|
||||
printf("Use +feature to enable a feature, or -feature to disable it.\n"
|
||||
"For example, rustc -C -target-cpu=mycpu -C "
|
||||
"target-feature=+feature1,-feature2\n\n");
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
extern "C" void
|
||||
LLVMRustPrintTargetCPUs(LLVMTargetMachineRef) {
|
||||
printf("Target CPU help is not supported by this LLVM version.\n\n");
|
||||
extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef) {
|
||||
printf("Target CPU help is not supported by this LLVM version.\n\n");
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustPrintTargetFeatures(LLVMTargetMachineRef) {
|
||||
printf("Target features help is not supported by this LLVM version.\n\n");
|
||||
extern "C" void LLVMRustPrintTargetFeatures(LLVMTargetMachineRef) {
|
||||
printf("Target features help is not supported by this LLVM version.\n\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
extern "C" LLVMTargetMachineRef
|
||||
LLVMRustCreateTargetMachine(const char *triple,
|
||||
const char *cpu,
|
||||
const char *feature,
|
||||
LLVMRustCodeModel rust_CM,
|
||||
LLVMRelocMode Reloc,
|
||||
LLVMRustCodeGenOptLevel rust_OptLevel,
|
||||
bool UseSoftFloat,
|
||||
bool PositionIndependentExecutable,
|
||||
bool FunctionSections,
|
||||
bool DataSections) {
|
||||
extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
|
||||
const char *triple, const char *cpu, const char *feature,
|
||||
LLVMRustCodeModel rust_CM, LLVMRelocMode Reloc,
|
||||
LLVMRustCodeGenOptLevel rust_OptLevel, bool UseSoftFloat,
|
||||
bool PositionIndependentExecutable, bool FunctionSections,
|
||||
bool DataSections) {
|
||||
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
Reloc::Model RM;
|
||||
Reloc::Model RM;
|
||||
#else
|
||||
Optional<Reloc::Model> RM;
|
||||
Optional<Reloc::Model> RM;
|
||||
#endif
|
||||
auto CM = from_rust(rust_CM);
|
||||
auto OptLevel = from_rust(rust_OptLevel);
|
||||
auto CM = from_rust(rust_CM);
|
||||
auto OptLevel = from_rust(rust_OptLevel);
|
||||
|
||||
switch (Reloc){
|
||||
case LLVMRelocStatic:
|
||||
RM = Reloc::Static;
|
||||
break;
|
||||
case LLVMRelocPIC:
|
||||
RM = Reloc::PIC_;
|
||||
break;
|
||||
case LLVMRelocDynamicNoPic:
|
||||
RM = Reloc::DynamicNoPIC;
|
||||
break;
|
||||
default:
|
||||
switch (Reloc) {
|
||||
case LLVMRelocStatic:
|
||||
RM = Reloc::Static;
|
||||
break;
|
||||
case LLVMRelocPIC:
|
||||
RM = Reloc::PIC_;
|
||||
break;
|
||||
case LLVMRelocDynamicNoPic:
|
||||
RM = Reloc::DynamicNoPIC;
|
||||
break;
|
||||
default:
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
RM = Reloc::Default;
|
||||
RM = Reloc::Default;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
std::string Error;
|
||||
Triple Trip(Triple::normalize(triple));
|
||||
const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Trip.getTriple(),
|
||||
Error);
|
||||
if (TheTarget == NULL) {
|
||||
LLVMRustSetLastError(Error.c_str());
|
||||
return NULL;
|
||||
}
|
||||
std::string Error;
|
||||
Triple Trip(Triple::normalize(triple));
|
||||
const llvm::Target *TheTarget =
|
||||
TargetRegistry::lookupTarget(Trip.getTriple(), Error);
|
||||
if (TheTarget == nullptr) {
|
||||
LLVMRustSetLastError(Error.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
StringRef real_cpu = cpu;
|
||||
if (real_cpu == "native") {
|
||||
real_cpu = sys::getHostCPUName();
|
||||
}
|
||||
StringRef real_cpu = cpu;
|
||||
if (real_cpu == "native") {
|
||||
real_cpu = sys::getHostCPUName();
|
||||
}
|
||||
|
||||
TargetOptions Options;
|
||||
TargetOptions Options;
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
Options.PositionIndependentExecutable = PositionIndependentExecutable;
|
||||
Options.PositionIndependentExecutable = PositionIndependentExecutable;
|
||||
#endif
|
||||
|
||||
Options.FloatABIType = FloatABI::Default;
|
||||
if (UseSoftFloat) {
|
||||
Options.FloatABIType = FloatABI::Soft;
|
||||
}
|
||||
Options.DataSections = DataSections;
|
||||
Options.FunctionSections = FunctionSections;
|
||||
Options.FloatABIType = FloatABI::Default;
|
||||
if (UseSoftFloat) {
|
||||
Options.FloatABIType = FloatABI::Soft;
|
||||
}
|
||||
Options.DataSections = DataSections;
|
||||
Options.FunctionSections = FunctionSections;
|
||||
|
||||
TargetMachine *TM = TheTarget->createTargetMachine(Trip.getTriple(),
|
||||
real_cpu,
|
||||
feature,
|
||||
Options,
|
||||
RM,
|
||||
CM,
|
||||
OptLevel);
|
||||
return wrap(TM);
|
||||
TargetMachine *TM = TheTarget->createTargetMachine(
|
||||
Trip.getTriple(), real_cpu, feature, Options, RM, CM, OptLevel);
|
||||
return wrap(TM);
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) {
|
||||
delete unwrap(TM);
|
||||
extern "C" void LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) {
|
||||
delete unwrap(TM);
|
||||
}
|
||||
|
||||
// Unfortunately, LLVM doesn't expose a C API to add the corresponding analysis
|
||||
// passes for a target to a pass manager. We export that functionality through
|
||||
// this function.
|
||||
extern "C" void
|
||||
LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM,
|
||||
LLVMPassManagerRef PMR,
|
||||
LLVMModuleRef M) {
|
||||
PassManagerBase *PM = unwrap(PMR);
|
||||
PM->add(createTargetTransformInfoWrapperPass(
|
||||
unwrap(TM)->getTargetIRAnalysis()));
|
||||
extern "C" void LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM,
|
||||
LLVMPassManagerRef PMR,
|
||||
LLVMModuleRef M) {
|
||||
PassManagerBase *PM = unwrap(PMR);
|
||||
PM->add(
|
||||
createTargetTransformInfoWrapperPass(unwrap(TM)->getTargetIRAnalysis()));
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustConfigurePassManagerBuilder(LLVMPassManagerBuilderRef PMB,
|
||||
LLVMRustCodeGenOptLevel OptLevel,
|
||||
bool MergeFunctions,
|
||||
bool SLPVectorize,
|
||||
bool LoopVectorize) {
|
||||
// Ignore mergefunc for now as enabling it causes crashes.
|
||||
//unwrap(PMB)->MergeFunctions = MergeFunctions;
|
||||
unwrap(PMB)->SLPVectorize = SLPVectorize;
|
||||
unwrap(PMB)->OptLevel = from_rust(OptLevel);
|
||||
unwrap(PMB)->LoopVectorize = LoopVectorize;
|
||||
extern "C" void LLVMRustConfigurePassManagerBuilder(
|
||||
LLVMPassManagerBuilderRef PMB, LLVMRustCodeGenOptLevel OptLevel,
|
||||
bool MergeFunctions, bool SLPVectorize, bool LoopVectorize) {
|
||||
// Ignore mergefunc for now as enabling it causes crashes.
|
||||
// unwrap(PMB)->MergeFunctions = MergeFunctions;
|
||||
unwrap(PMB)->SLPVectorize = SLPVectorize;
|
||||
unwrap(PMB)->OptLevel = from_rust(OptLevel);
|
||||
unwrap(PMB)->LoopVectorize = LoopVectorize;
|
||||
}
|
||||
|
||||
// Unfortunately, the LLVM C API doesn't provide a way to set the `LibraryInfo`
|
||||
// field of a PassManagerBuilder, we expose our own method of doing so.
|
||||
extern "C" void
|
||||
LLVMRustAddBuilderLibraryInfo(LLVMPassManagerBuilderRef PMB,
|
||||
LLVMModuleRef M,
|
||||
bool DisableSimplifyLibCalls) {
|
||||
Triple TargetTriple(unwrap(M)->getTargetTriple());
|
||||
TargetLibraryInfoImpl *TLI = new TargetLibraryInfoImpl(TargetTriple);
|
||||
if (DisableSimplifyLibCalls)
|
||||
TLI->disableAllFunctions();
|
||||
unwrap(PMB)->LibraryInfo = TLI;
|
||||
extern "C" void LLVMRustAddBuilderLibraryInfo(LLVMPassManagerBuilderRef PMB,
|
||||
LLVMModuleRef M,
|
||||
bool DisableSimplifyLibCalls) {
|
||||
Triple TargetTriple(unwrap(M)->getTargetTriple());
|
||||
TargetLibraryInfoImpl *TLI = new TargetLibraryInfoImpl(TargetTriple);
|
||||
if (DisableSimplifyLibCalls)
|
||||
TLI->disableAllFunctions();
|
||||
unwrap(PMB)->LibraryInfo = TLI;
|
||||
}
|
||||
|
||||
// Unfortunately, the LLVM C API doesn't provide a way to create the
|
||||
// TargetLibraryInfo pass, so we use this method to do so.
|
||||
extern "C" void
|
||||
LLVMRustAddLibraryInfo(LLVMPassManagerRef PMB,
|
||||
LLVMModuleRef M,
|
||||
bool DisableSimplifyLibCalls) {
|
||||
Triple TargetTriple(unwrap(M)->getTargetTriple());
|
||||
TargetLibraryInfoImpl TLII(TargetTriple);
|
||||
if (DisableSimplifyLibCalls)
|
||||
TLII.disableAllFunctions();
|
||||
unwrap(PMB)->add(new TargetLibraryInfoWrapperPass(TLII));
|
||||
extern "C" void LLVMRustAddLibraryInfo(LLVMPassManagerRef PMB, LLVMModuleRef M,
|
||||
bool DisableSimplifyLibCalls) {
|
||||
Triple TargetTriple(unwrap(M)->getTargetTriple());
|
||||
TargetLibraryInfoImpl TLII(TargetTriple);
|
||||
if (DisableSimplifyLibCalls)
|
||||
TLII.disableAllFunctions();
|
||||
unwrap(PMB)->add(new TargetLibraryInfoWrapperPass(TLII));
|
||||
}
|
||||
|
||||
// Unfortunately, the LLVM C API doesn't provide an easy way of iterating over
|
||||
// all the functions in a module, so we do that manually here. You'll find
|
||||
// similar code in clang's BackendUtil.cpp file.
|
||||
extern "C" void
|
||||
LLVMRustRunFunctionPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) {
|
||||
llvm::legacy::FunctionPassManager *P = unwrap<llvm::legacy::FunctionPassManager>(PM);
|
||||
P->doInitialization();
|
||||
extern "C" void LLVMRustRunFunctionPassManager(LLVMPassManagerRef PM,
|
||||
LLVMModuleRef M) {
|
||||
llvm::legacy::FunctionPassManager *P =
|
||||
unwrap<llvm::legacy::FunctionPassManager>(PM);
|
||||
P->doInitialization();
|
||||
|
||||
// Upgrade all calls to old intrinsics first.
|
||||
for (Module::iterator I = unwrap(M)->begin(),
|
||||
E = unwrap(M)->end(); I != E;)
|
||||
UpgradeCallsToIntrinsic(&*I++); // must be post-increment, as we remove
|
||||
// Upgrade all calls to old intrinsics first.
|
||||
for (Module::iterator I = unwrap(M)->begin(), E = unwrap(M)->end(); I != E;)
|
||||
UpgradeCallsToIntrinsic(&*I++); // must be post-increment, as we remove
|
||||
|
||||
for (Module::iterator I = unwrap(M)->begin(),
|
||||
E = unwrap(M)->end(); I != E; ++I)
|
||||
if (!I->isDeclaration())
|
||||
P->run(*I);
|
||||
for (Module::iterator I = unwrap(M)->begin(), E = unwrap(M)->end(); I != E;
|
||||
++I)
|
||||
if (!I->isDeclaration())
|
||||
P->run(*I);
|
||||
|
||||
P->doFinalization();
|
||||
P->doFinalization();
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustSetLLVMOptions(int Argc, char **Argv) {
|
||||
// Initializing the command-line options more than once is not allowed. So,
|
||||
// check if they've already been initialized. (This could happen if we're
|
||||
// being called from rustpkg, for example). If the arguments change, then
|
||||
// that's just kinda unfortunate.
|
||||
static bool initialized = false;
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
cl::ParseCommandLineOptions(Argc, Argv);
|
||||
extern "C" void LLVMRustSetLLVMOptions(int Argc, char **Argv) {
|
||||
// Initializing the command-line options more than once is not allowed. So,
|
||||
// check if they've already been initialized. (This could happen if we're
|
||||
// being called from rustpkg, for example). If the arguments change, then
|
||||
// that's just kinda unfortunate.
|
||||
static bool initialized = false;
|
||||
if (initialized)
|
||||
return;
|
||||
initialized = true;
|
||||
cl::ParseCommandLineOptions(Argc, Argv);
|
||||
}
|
||||
|
||||
enum class LLVMRustFileType {
|
||||
Other,
|
||||
AssemblyFile,
|
||||
ObjectFile,
|
||||
Other,
|
||||
AssemblyFile,
|
||||
ObjectFile,
|
||||
};
|
||||
|
||||
static TargetMachine::CodeGenFileType
|
||||
from_rust(LLVMRustFileType type)
|
||||
{
|
||||
switch (type) {
|
||||
case LLVMRustFileType::AssemblyFile:
|
||||
return TargetMachine::CGFT_AssemblyFile;
|
||||
case LLVMRustFileType::ObjectFile:
|
||||
return TargetMachine::CGFT_ObjectFile;
|
||||
default:
|
||||
llvm_unreachable("Bad FileType.");
|
||||
static TargetMachine::CodeGenFileType from_rust(LLVMRustFileType type) {
|
||||
switch (type) {
|
||||
case LLVMRustFileType::AssemblyFile:
|
||||
return TargetMachine::CGFT_AssemblyFile;
|
||||
case LLVMRustFileType::ObjectFile:
|
||||
return TargetMachine::CGFT_ObjectFile;
|
||||
default:
|
||||
llvm_unreachable("Bad FileType.");
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" LLVMRustResult
|
||||
LLVMRustWriteOutputFile(LLVMTargetMachineRef Target,
|
||||
LLVMPassManagerRef PMR,
|
||||
LLVMModuleRef M,
|
||||
const char *path,
|
||||
LLVMRustWriteOutputFile(LLVMTargetMachineRef Target, LLVMPassManagerRef PMR,
|
||||
LLVMModuleRef M, const char *path,
|
||||
LLVMRustFileType rust_FileType) {
|
||||
llvm::legacy::PassManager *PM = unwrap<llvm::legacy::PassManager>(PMR);
|
||||
auto FileType = from_rust(rust_FileType);
|
||||
@@ -505,10 +469,8 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target,
|
||||
return LLVMRustResult::Success;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustPrintModule(LLVMPassManagerRef PMR,
|
||||
LLVMModuleRef M,
|
||||
const char* path) {
|
||||
extern "C" void LLVMRustPrintModule(LLVMPassManagerRef PMR, LLVMModuleRef M,
|
||||
const char *path) {
|
||||
llvm::legacy::PassManager *PM = unwrap<llvm::legacy::PassManager>(PMR);
|
||||
std::string ErrorInfo;
|
||||
|
||||
@@ -524,102 +486,96 @@ LLVMRustPrintModule(LLVMPassManagerRef PMR,
|
||||
PM->run(*unwrap(M));
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustPrintPasses() {
|
||||
LLVMInitializePasses();
|
||||
struct MyListener : PassRegistrationListener {
|
||||
void passEnumerate(const PassInfo *info) {
|
||||
extern "C" void LLVMRustPrintPasses() {
|
||||
LLVMInitializePasses();
|
||||
struct MyListener : PassRegistrationListener {
|
||||
void passEnumerate(const PassInfo *info) {
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
StringRef PassArg = info->getPassArgument();
|
||||
StringRef PassName = info->getPassName();
|
||||
if (!PassArg.empty()) {
|
||||
// These unsigned->signed casts could theoretically overflow, but
|
||||
// realistically never will (and even if, the result is implementation
|
||||
// defined rather plain UB).
|
||||
printf("%15.*s - %.*s\n", (int)PassArg.size(), PassArg.data(),
|
||||
(int)PassName.size(), PassName.data());
|
||||
}
|
||||
StringRef PassArg = info->getPassArgument();
|
||||
StringRef PassName = info->getPassName();
|
||||
if (!PassArg.empty()) {
|
||||
// These unsigned->signed casts could theoretically overflow, but
|
||||
// realistically never will (and even if, the result is implementation
|
||||
// defined rather plain UB).
|
||||
printf("%15.*s - %.*s\n", (int)PassArg.size(), PassArg.data(),
|
||||
(int)PassName.size(), PassName.data());
|
||||
}
|
||||
#else
|
||||
if (info->getPassArgument() && *info->getPassArgument()) {
|
||||
printf("%15s - %s\n", info->getPassArgument(),
|
||||
info->getPassName());
|
||||
}
|
||||
if (info->getPassArgument() && *info->getPassArgument()) {
|
||||
printf("%15s - %s\n", info->getPassArgument(), info->getPassName());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} listener;
|
||||
}
|
||||
} listener;
|
||||
|
||||
PassRegistry *PR = PassRegistry::getPassRegistry();
|
||||
PR->enumerateWith(&listener);
|
||||
PassRegistry *PR = PassRegistry::getPassRegistry();
|
||||
PR->enumerateWith(&listener);
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustAddAlwaysInlinePass(LLVMPassManagerBuilderRef PMB, bool AddLifetimes) {
|
||||
extern "C" void LLVMRustAddAlwaysInlinePass(LLVMPassManagerBuilderRef PMB,
|
||||
bool AddLifetimes) {
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
unwrap(PMB)->Inliner = llvm::createAlwaysInlinerLegacyPass(AddLifetimes);
|
||||
unwrap(PMB)->Inliner = llvm::createAlwaysInlinerLegacyPass(AddLifetimes);
|
||||
#else
|
||||
unwrap(PMB)->Inliner = createAlwaysInlinerPass(AddLifetimes);
|
||||
unwrap(PMB)->Inliner = createAlwaysInlinerPass(AddLifetimes);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustRunRestrictionPass(LLVMModuleRef M, char **symbols, size_t len) {
|
||||
llvm::legacy::PassManager passes;
|
||||
extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **symbols,
|
||||
size_t len) {
|
||||
llvm::legacy::PassManager passes;
|
||||
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
ArrayRef<const char*> ref(symbols, len);
|
||||
passes.add(llvm::createInternalizePass(ref));
|
||||
ArrayRef<const char *> ref(symbols, len);
|
||||
passes.add(llvm::createInternalizePass(ref));
|
||||
#else
|
||||
auto PreserveFunctions = [=](const GlobalValue &GV) {
|
||||
for (size_t i=0; i<len; i++) {
|
||||
if (GV.getName() == symbols[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
auto PreserveFunctions = [=](const GlobalValue &GV) {
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (GV.getName() == symbols[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
passes.add(llvm::createInternalizePass(PreserveFunctions));
|
||||
passes.add(llvm::createInternalizePass(PreserveFunctions));
|
||||
#endif
|
||||
|
||||
passes.run(*unwrap(M));
|
||||
passes.run(*unwrap(M));
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustMarkAllFunctionsNounwind(LLVMModuleRef M) {
|
||||
for (Module::iterator GV = unwrap(M)->begin(),
|
||||
E = unwrap(M)->end(); GV != E; ++GV) {
|
||||
GV->setDoesNotThrow();
|
||||
Function *F = dyn_cast<Function>(GV);
|
||||
if (F == NULL)
|
||||
continue;
|
||||
extern "C" void LLVMRustMarkAllFunctionsNounwind(LLVMModuleRef M) {
|
||||
for (Module::iterator GV = unwrap(M)->begin(), E = unwrap(M)->end(); GV != E;
|
||||
++GV) {
|
||||
GV->setDoesNotThrow();
|
||||
Function *F = dyn_cast<Function>(GV);
|
||||
if (F == nullptr)
|
||||
continue;
|
||||
|
||||
for (Function::iterator B = F->begin(), BE = F->end(); B != BE; ++B) {
|
||||
for (BasicBlock::iterator I = B->begin(), IE = B->end();
|
||||
I != IE; ++I) {
|
||||
if (isa<InvokeInst>(I)) {
|
||||
InvokeInst *CI = cast<InvokeInst>(I);
|
||||
CI->setDoesNotThrow();
|
||||
}
|
||||
}
|
||||
for (Function::iterator B = F->begin(), BE = F->end(); B != BE; ++B) {
|
||||
for (BasicBlock::iterator I = B->begin(), IE = B->end(); I != IE; ++I) {
|
||||
if (isa<InvokeInst>(I)) {
|
||||
InvokeInst *CI = cast<InvokeInst>(I);
|
||||
CI->setDoesNotThrow();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustSetDataLayoutFromTargetMachine(LLVMModuleRef Module,
|
||||
LLVMTargetMachineRef TMR) {
|
||||
TargetMachine *Target = unwrap(TMR);
|
||||
unwrap(Module)->setDataLayout(Target->createDataLayout());
|
||||
TargetMachine *Target = unwrap(TMR);
|
||||
unwrap(Module)->setDataLayout(Target->createDataLayout());
|
||||
}
|
||||
|
||||
extern "C" LLVMTargetDataRef
|
||||
LLVMRustGetModuleDataLayout(LLVMModuleRef M) {
|
||||
return wrap(&unwrap(M)->getDataLayout());
|
||||
extern "C" LLVMTargetDataRef LLVMRustGetModuleDataLayout(LLVMModuleRef M) {
|
||||
return wrap(&unwrap(M)->getDataLayout());
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustSetModulePIELevel(LLVMModuleRef M) {
|
||||
extern "C" void LLVMRustSetModulePIELevel(LLVMModuleRef M) {
|
||||
#if LLVM_VERSION_GE(3, 9)
|
||||
unwrap(M)->setPIELevel(PIELevel::Level::Large);
|
||||
unwrap(M)->setPIELevel(PIELevel::Level::Large);
|
||||
#endif
|
||||
}
|
||||
|
||||
+818
-1029
@@ -9,11 +9,11 @@
|
||||
// except according to those terms.
|
||||
|
||||
#include "rustllvm.h"
|
||||
#include "llvm/Object/Archive.h"
|
||||
#include "llvm/Object/ObjectFile.h"
|
||||
#include "llvm/IR/DiagnosticInfo.h"
|
||||
#include "llvm/IR/DiagnosticPrinter.h"
|
||||
#include "llvm/IR/Instructions.h"
|
||||
#include "llvm/Object/Archive.h"
|
||||
#include "llvm/Object/ObjectFile.h"
|
||||
|
||||
#include "llvm/IR/CallSite.h"
|
||||
|
||||
@@ -32,76 +32,73 @@ using namespace llvm::object;
|
||||
// one.
|
||||
static AtomicOrdering from_rust(LLVMAtomicOrdering Ordering) {
|
||||
switch (Ordering) {
|
||||
case LLVMAtomicOrderingNotAtomic:
|
||||
return AtomicOrdering::NotAtomic;
|
||||
case LLVMAtomicOrderingUnordered:
|
||||
return AtomicOrdering::Unordered;
|
||||
case LLVMAtomicOrderingMonotonic:
|
||||
return AtomicOrdering::Monotonic;
|
||||
case LLVMAtomicOrderingAcquire:
|
||||
return AtomicOrdering::Acquire;
|
||||
case LLVMAtomicOrderingRelease:
|
||||
return AtomicOrdering::Release;
|
||||
case LLVMAtomicOrderingAcquireRelease:
|
||||
return AtomicOrdering::AcquireRelease;
|
||||
case LLVMAtomicOrderingSequentiallyConsistent:
|
||||
return AtomicOrdering::SequentiallyConsistent;
|
||||
case LLVMAtomicOrderingNotAtomic:
|
||||
return AtomicOrdering::NotAtomic;
|
||||
case LLVMAtomicOrderingUnordered:
|
||||
return AtomicOrdering::Unordered;
|
||||
case LLVMAtomicOrderingMonotonic:
|
||||
return AtomicOrdering::Monotonic;
|
||||
case LLVMAtomicOrderingAcquire:
|
||||
return AtomicOrdering::Acquire;
|
||||
case LLVMAtomicOrderingRelease:
|
||||
return AtomicOrdering::Release;
|
||||
case LLVMAtomicOrderingAcquireRelease:
|
||||
return AtomicOrdering::AcquireRelease;
|
||||
case LLVMAtomicOrderingSequentiallyConsistent:
|
||||
return AtomicOrdering::SequentiallyConsistent;
|
||||
}
|
||||
|
||||
llvm_unreachable("Invalid LLVMAtomicOrdering value!");
|
||||
}
|
||||
|
||||
|
||||
static char *LastError;
|
||||
|
||||
extern "C" LLVMMemoryBufferRef
|
||||
LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) {
|
||||
ErrorOr<std::unique_ptr<MemoryBuffer>> buf_or = MemoryBuffer::getFile(Path,
|
||||
-1,
|
||||
false);
|
||||
ErrorOr<std::unique_ptr<MemoryBuffer>> buf_or =
|
||||
MemoryBuffer::getFile(Path, -1, false);
|
||||
if (!buf_or) {
|
||||
LLVMRustSetLastError(buf_or.getError().message().c_str());
|
||||
return nullptr;
|
||||
LLVMRustSetLastError(buf_or.getError().message().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
return wrap(buf_or.get().release());
|
||||
}
|
||||
|
||||
extern "C" char *LLVMRustGetLastError(void) {
|
||||
char *ret = LastError;
|
||||
LastError = NULL;
|
||||
LastError = nullptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void LLVMRustSetLastError(const char *err) {
|
||||
free((void*) LastError);
|
||||
free((void *)LastError);
|
||||
LastError = strdup(err);
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustSetNormalizedTarget(LLVMModuleRef M, const char *triple) {
|
||||
unwrap(M)->setTargetTriple(Triple::normalize(triple));
|
||||
extern "C" void LLVMRustSetNormalizedTarget(LLVMModuleRef M,
|
||||
const char *triple) {
|
||||
unwrap(M)->setTargetTriple(Triple::normalize(triple));
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustPrintPassTimings() {
|
||||
raw_fd_ostream OS (2, false); // stderr.
|
||||
raw_fd_ostream OS(2, false); // stderr.
|
||||
TimerGroup::printAll(OS);
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef LLVMRustGetNamedValue(LLVMModuleRef M,
|
||||
const char* Name) {
|
||||
return wrap(unwrap(M)->getNamedValue(Name));
|
||||
const char *Name) {
|
||||
return wrap(unwrap(M)->getNamedValue(Name));
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef LLVMRustGetOrInsertFunction(LLVMModuleRef M,
|
||||
const char* Name,
|
||||
LLVMTypeRef FunctionTy) {
|
||||
return wrap(unwrap(M)->getOrInsertFunction(Name,
|
||||
unwrap<FunctionType>(FunctionTy)));
|
||||
const char *Name,
|
||||
LLVMTypeRef FunctionTy) {
|
||||
return wrap(
|
||||
unwrap(M)->getOrInsertFunction(Name, unwrap<FunctionType>(FunctionTy)));
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef LLVMRustGetOrInsertGlobal(LLVMModuleRef M,
|
||||
const char* Name,
|
||||
LLVMTypeRef Ty) {
|
||||
extern "C" LLVMValueRef
|
||||
LLVMRustGetOrInsertGlobal(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty) {
|
||||
return wrap(unwrap(M)->getOrInsertGlobal(Name, unwrap(Ty)));
|
||||
}
|
||||
|
||||
@@ -109,91 +106,84 @@ extern "C" LLVMTypeRef LLVMRustMetadataTypeInContext(LLVMContextRef C) {
|
||||
return wrap(Type::getMetadataTy(*unwrap(C)));
|
||||
}
|
||||
|
||||
static Attribute::AttrKind
|
||||
from_rust(LLVMRustAttribute kind) {
|
||||
static Attribute::AttrKind from_rust(LLVMRustAttribute kind) {
|
||||
switch (kind) {
|
||||
case AlwaysInline:
|
||||
return Attribute::AlwaysInline;
|
||||
case ByVal:
|
||||
return Attribute::ByVal;
|
||||
case Cold:
|
||||
return Attribute::Cold;
|
||||
case InlineHint:
|
||||
return Attribute::InlineHint;
|
||||
case MinSize:
|
||||
return Attribute::MinSize;
|
||||
case Naked:
|
||||
return Attribute::Naked;
|
||||
case NoAlias:
|
||||
return Attribute::NoAlias;
|
||||
case NoCapture:
|
||||
return Attribute::NoCapture;
|
||||
case NoInline:
|
||||
return Attribute::NoInline;
|
||||
case NonNull:
|
||||
return Attribute::NonNull;
|
||||
case NoRedZone:
|
||||
return Attribute::NoRedZone;
|
||||
case NoReturn:
|
||||
return Attribute::NoReturn;
|
||||
case NoUnwind:
|
||||
return Attribute::NoUnwind;
|
||||
case OptimizeForSize:
|
||||
return Attribute::OptimizeForSize;
|
||||
case ReadOnly:
|
||||
return Attribute::ReadOnly;
|
||||
case SExt:
|
||||
return Attribute::SExt;
|
||||
case StructRet:
|
||||
return Attribute::StructRet;
|
||||
case UWTable:
|
||||
return Attribute::UWTable;
|
||||
case ZExt:
|
||||
return Attribute::ZExt;
|
||||
case InReg:
|
||||
return Attribute::InReg;
|
||||
default:
|
||||
llvm_unreachable("bad AttributeKind");
|
||||
case AlwaysInline:
|
||||
return Attribute::AlwaysInline;
|
||||
case ByVal:
|
||||
return Attribute::ByVal;
|
||||
case Cold:
|
||||
return Attribute::Cold;
|
||||
case InlineHint:
|
||||
return Attribute::InlineHint;
|
||||
case MinSize:
|
||||
return Attribute::MinSize;
|
||||
case Naked:
|
||||
return Attribute::Naked;
|
||||
case NoAlias:
|
||||
return Attribute::NoAlias;
|
||||
case NoCapture:
|
||||
return Attribute::NoCapture;
|
||||
case NoInline:
|
||||
return Attribute::NoInline;
|
||||
case NonNull:
|
||||
return Attribute::NonNull;
|
||||
case NoRedZone:
|
||||
return Attribute::NoRedZone;
|
||||
case NoReturn:
|
||||
return Attribute::NoReturn;
|
||||
case NoUnwind:
|
||||
return Attribute::NoUnwind;
|
||||
case OptimizeForSize:
|
||||
return Attribute::OptimizeForSize;
|
||||
case ReadOnly:
|
||||
return Attribute::ReadOnly;
|
||||
case SExt:
|
||||
return Attribute::SExt;
|
||||
case StructRet:
|
||||
return Attribute::StructRet;
|
||||
case UWTable:
|
||||
return Attribute::UWTable;
|
||||
case ZExt:
|
||||
return Attribute::ZExt;
|
||||
case InReg:
|
||||
return Attribute::InReg;
|
||||
default:
|
||||
llvm_unreachable("bad AttributeKind");
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned index, LLVMRustAttribute attr) {
|
||||
extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned index,
|
||||
LLVMRustAttribute attr) {
|
||||
CallSite Call = CallSite(unwrap<Instruction>(Instr));
|
||||
Attribute Attr = Attribute::get(Call->getContext(), from_rust(attr));
|
||||
AttrBuilder B(Attr);
|
||||
Call.setAttributes(
|
||||
Call.getAttributes().addAttributes(Call->getContext(), index,
|
||||
AttributeSet::get(Call->getContext(),
|
||||
index, B)));
|
||||
Call.setAttributes(Call.getAttributes().addAttributes(
|
||||
Call->getContext(), index,
|
||||
AttributeSet::get(Call->getContext(), index, B)));
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr,
|
||||
unsigned index,
|
||||
uint64_t bytes)
|
||||
{
|
||||
unsigned index,
|
||||
uint64_t bytes) {
|
||||
CallSite Call = CallSite(unwrap<Instruction>(Instr));
|
||||
AttrBuilder B;
|
||||
B.addDereferenceableAttr(bytes);
|
||||
Call.setAttributes(
|
||||
Call.getAttributes().addAttributes(Call->getContext(), index,
|
||||
AttributeSet::get(Call->getContext(),
|
||||
index, B)));
|
||||
Call.setAttributes(Call.getAttributes().addAttributes(
|
||||
Call->getContext(), index,
|
||||
AttributeSet::get(Call->getContext(), index, B)));
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn,
|
||||
unsigned index,
|
||||
LLVMRustAttribute attr)
|
||||
{
|
||||
extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned index,
|
||||
LLVMRustAttribute attr) {
|
||||
Function *A = unwrap<Function>(Fn);
|
||||
Attribute Attr = Attribute::get(A->getContext(), from_rust(attr));
|
||||
AttrBuilder B(Attr);
|
||||
A->addAttributes(index, AttributeSet::get(A->getContext(), index, B));
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn,
|
||||
unsigned index,
|
||||
uint64_t bytes)
|
||||
{
|
||||
extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned index,
|
||||
uint64_t bytes) {
|
||||
Function *A = unwrap<Function>(Fn);
|
||||
AttrBuilder B;
|
||||
B.addDereferenceableAttr(bytes);
|
||||
@@ -201,9 +191,9 @@ extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn,
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
|
||||
unsigned index,
|
||||
const char *Name,
|
||||
const char *Value) {
|
||||
unsigned index,
|
||||
const char *Name,
|
||||
const char *Value) {
|
||||
Function *F = unwrap<Function>(Fn);
|
||||
AttrBuilder B;
|
||||
B.addAttribute(Name, Value);
|
||||
@@ -211,90 +201,77 @@ extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,
|
||||
unsigned index,
|
||||
LLVMRustAttribute attr)
|
||||
{
|
||||
unsigned index,
|
||||
LLVMRustAttribute attr) {
|
||||
Function *F = unwrap<Function>(Fn);
|
||||
const AttributeSet PAL = F->getAttributes();
|
||||
Attribute Attr = Attribute::get(F->getContext(), from_rust(attr));
|
||||
AttrBuilder B(Attr);
|
||||
const AttributeSet PALnew =
|
||||
PAL.removeAttributes(F->getContext(), index,
|
||||
AttributeSet::get(F->getContext(), index, B));
|
||||
const AttributeSet PALnew = PAL.removeAttributes(
|
||||
F->getContext(), index, AttributeSet::get(F->getContext(), index, B));
|
||||
F->setAttributes(PALnew);
|
||||
}
|
||||
|
||||
// enable fpmath flag UnsafeAlgebra
|
||||
extern "C" void LLVMRustSetHasUnsafeAlgebra(LLVMValueRef V) {
|
||||
if (auto I = dyn_cast<Instruction>(unwrap<Value>(V))) {
|
||||
I->setHasUnsafeAlgebra(true);
|
||||
}
|
||||
if (auto I = dyn_cast<Instruction>(unwrap<Value>(V))) {
|
||||
I->setHasUnsafeAlgebra(true);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef LLVMRustBuildAtomicLoad(LLVMBuilderRef B,
|
||||
LLVMValueRef source,
|
||||
const char* Name,
|
||||
LLVMAtomicOrdering order,
|
||||
unsigned alignment) {
|
||||
LoadInst* li = new LoadInst(unwrap(source),0);
|
||||
li->setAtomic(from_rust(order));
|
||||
li->setAlignment(alignment);
|
||||
return wrap(unwrap(B)->Insert(li, Name));
|
||||
extern "C" LLVMValueRef
|
||||
LLVMRustBuildAtomicLoad(LLVMBuilderRef B, LLVMValueRef source, const char *Name,
|
||||
LLVMAtomicOrdering order, unsigned alignment) {
|
||||
LoadInst *li = new LoadInst(unwrap(source), 0);
|
||||
li->setAtomic(from_rust(order));
|
||||
li->setAlignment(alignment);
|
||||
return wrap(unwrap(B)->Insert(li, Name));
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef LLVMRustBuildAtomicStore(LLVMBuilderRef B,
|
||||
LLVMValueRef val,
|
||||
LLVMValueRef target,
|
||||
LLVMAtomicOrdering order,
|
||||
unsigned alignment) {
|
||||
StoreInst* si = new StoreInst(unwrap(val),unwrap(target));
|
||||
si->setAtomic(from_rust(order));
|
||||
si->setAlignment(alignment);
|
||||
return wrap(unwrap(B)->Insert(si));
|
||||
LLVMValueRef val,
|
||||
LLVMValueRef target,
|
||||
LLVMAtomicOrdering order,
|
||||
unsigned alignment) {
|
||||
StoreInst *si = new StoreInst(unwrap(val), unwrap(target));
|
||||
si->setAtomic(from_rust(order));
|
||||
si->setAlignment(alignment);
|
||||
return wrap(unwrap(B)->Insert(si));
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef LLVMRustBuildAtomicCmpXchg(LLVMBuilderRef B,
|
||||
LLVMValueRef target,
|
||||
LLVMValueRef old,
|
||||
LLVMValueRef source,
|
||||
LLVMAtomicOrdering order,
|
||||
LLVMAtomicOrdering failure_order,
|
||||
LLVMBool weak) {
|
||||
AtomicCmpXchgInst* acxi = unwrap(B)->CreateAtomicCmpXchg(
|
||||
unwrap(target),
|
||||
unwrap(old),
|
||||
unwrap(source),
|
||||
from_rust(order),
|
||||
from_rust(failure_order));
|
||||
acxi->setWeak(weak);
|
||||
return wrap(acxi);
|
||||
extern "C" LLVMValueRef
|
||||
LLVMRustBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef target,
|
||||
LLVMValueRef old, LLVMValueRef source,
|
||||
LLVMAtomicOrdering order,
|
||||
LLVMAtomicOrdering failure_order, LLVMBool weak) {
|
||||
AtomicCmpXchgInst *acxi = unwrap(B)->CreateAtomicCmpXchg(
|
||||
unwrap(target), unwrap(old), unwrap(source), from_rust(order),
|
||||
from_rust(failure_order));
|
||||
acxi->setWeak(weak);
|
||||
return wrap(acxi);
|
||||
}
|
||||
|
||||
enum class LLVMRustSynchronizationScope {
|
||||
Other,
|
||||
SingleThread,
|
||||
CrossThread,
|
||||
Other,
|
||||
SingleThread,
|
||||
CrossThread,
|
||||
};
|
||||
|
||||
static SynchronizationScope
|
||||
from_rust(LLVMRustSynchronizationScope scope)
|
||||
{
|
||||
switch (scope) {
|
||||
case LLVMRustSynchronizationScope::SingleThread:
|
||||
return SingleThread;
|
||||
case LLVMRustSynchronizationScope::CrossThread:
|
||||
return CrossThread;
|
||||
default:
|
||||
llvm_unreachable("bad SynchronizationScope.");
|
||||
}
|
||||
static SynchronizationScope from_rust(LLVMRustSynchronizationScope scope) {
|
||||
switch (scope) {
|
||||
case LLVMRustSynchronizationScope::SingleThread:
|
||||
return SingleThread;
|
||||
case LLVMRustSynchronizationScope::CrossThread:
|
||||
return CrossThread;
|
||||
default:
|
||||
llvm_unreachable("bad SynchronizationScope.");
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef LLVMRustBuildAtomicFence(
|
||||
LLVMBuilderRef B,
|
||||
LLVMAtomicOrdering order,
|
||||
LLVMRustSynchronizationScope scope)
|
||||
{
|
||||
return wrap(unwrap(B)->CreateFence(from_rust(order), from_rust(scope)));
|
||||
extern "C" LLVMValueRef
|
||||
LLVMRustBuildAtomicFence(LLVMBuilderRef B, LLVMAtomicOrdering order,
|
||||
LLVMRustSynchronizationScope scope) {
|
||||
return wrap(unwrap(B)->CreateFence(from_rust(order), from_rust(scope)));
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustSetDebug(int Enabled) {
|
||||
@@ -304,36 +281,32 @@ extern "C" void LLVMRustSetDebug(int Enabled) {
|
||||
}
|
||||
|
||||
enum class LLVMRustAsmDialect {
|
||||
Other,
|
||||
Att,
|
||||
Intel,
|
||||
Other,
|
||||
Att,
|
||||
Intel,
|
||||
};
|
||||
|
||||
static InlineAsm::AsmDialect
|
||||
from_rust(LLVMRustAsmDialect dialect)
|
||||
{
|
||||
switch (dialect) {
|
||||
case LLVMRustAsmDialect::Att:
|
||||
return InlineAsm::AD_ATT;
|
||||
case LLVMRustAsmDialect::Intel:
|
||||
return InlineAsm::AD_Intel;
|
||||
default:
|
||||
llvm_unreachable("bad AsmDialect.");
|
||||
}
|
||||
static InlineAsm::AsmDialect from_rust(LLVMRustAsmDialect dialect) {
|
||||
switch (dialect) {
|
||||
case LLVMRustAsmDialect::Att:
|
||||
return InlineAsm::AD_ATT;
|
||||
case LLVMRustAsmDialect::Intel:
|
||||
return InlineAsm::AD_Intel;
|
||||
default:
|
||||
llvm_unreachable("bad AsmDialect.");
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef LLVMRustInlineAsm(LLVMTypeRef Ty,
|
||||
char *AsmString,
|
||||
char *Constraints,
|
||||
LLVMBool HasSideEffects,
|
||||
LLVMBool IsAlignStack,
|
||||
LLVMRustAsmDialect Dialect) {
|
||||
return wrap(InlineAsm::get(unwrap<FunctionType>(Ty), AsmString,
|
||||
Constraints, HasSideEffects,
|
||||
IsAlignStack, from_rust(Dialect)));
|
||||
extern "C" LLVMValueRef LLVMRustInlineAsm(LLVMTypeRef Ty, char *AsmString,
|
||||
char *Constraints,
|
||||
LLVMBool HasSideEffects,
|
||||
LLVMBool IsAlignStack,
|
||||
LLVMRustAsmDialect Dialect) {
|
||||
return wrap(InlineAsm::get(unwrap<FunctionType>(Ty), AsmString, Constraints,
|
||||
HasSideEffects, IsAlignStack, from_rust(Dialect)));
|
||||
}
|
||||
|
||||
typedef DIBuilder* LLVMRustDIBuilderRef;
|
||||
typedef DIBuilder *LLVMRustDIBuilderRef;
|
||||
|
||||
typedef struct LLVMOpaqueMetadata *LLVMRustMetadataRef;
|
||||
|
||||
@@ -341,13 +314,12 @@ namespace llvm {
|
||||
DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMRustMetadataRef)
|
||||
|
||||
inline Metadata **unwrap(LLVMRustMetadataRef *Vals) {
|
||||
return reinterpret_cast<Metadata**>(Vals);
|
||||
return reinterpret_cast<Metadata **>(Vals);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename DIT>
|
||||
DIT* unwrapDIptr(LLVMRustMetadataRef ref) {
|
||||
return (DIT*) (ref ? unwrap<MDNode>(ref) : NULL);
|
||||
template <typename DIT> DIT *unwrapDIptr(LLVMRustMetadataRef ref) {
|
||||
return (DIT *)(ref ? unwrap<MDNode>(ref) : nullptr);
|
||||
}
|
||||
|
||||
#define DIDescriptor DIScope
|
||||
@@ -358,614 +330,482 @@ DIT* unwrapDIptr(LLVMRustMetadataRef ref) {
|
||||
// to match LLVM, but that isn't required as we do giant sets of
|
||||
// matching below. The value shouldn't be directly passed to LLVM.
|
||||
enum class LLVMRustDIFlags : uint32_t {
|
||||
FlagZero = 0,
|
||||
FlagPrivate = 1,
|
||||
FlagProtected = 2,
|
||||
FlagPublic = 3,
|
||||
FlagFwdDecl = (1 << 2),
|
||||
FlagAppleBlock = (1 << 3),
|
||||
FlagBlockByrefStruct = (1 << 4),
|
||||
FlagVirtual = (1 << 5),
|
||||
FlagArtificial = (1 << 6),
|
||||
FlagExplicit = (1 << 7),
|
||||
FlagPrototyped = (1 << 8),
|
||||
FlagObjcClassComplete = (1 << 9),
|
||||
FlagObjectPointer = (1 << 10),
|
||||
FlagVector = (1 << 11),
|
||||
FlagStaticMember = (1 << 12),
|
||||
FlagLValueReference = (1 << 13),
|
||||
FlagRValueReference = (1 << 14),
|
||||
// Do not add values that are not supported by the minimum LLVM
|
||||
// version we support!
|
||||
FlagZero = 0,
|
||||
FlagPrivate = 1,
|
||||
FlagProtected = 2,
|
||||
FlagPublic = 3,
|
||||
FlagFwdDecl = (1 << 2),
|
||||
FlagAppleBlock = (1 << 3),
|
||||
FlagBlockByrefStruct = (1 << 4),
|
||||
FlagVirtual = (1 << 5),
|
||||
FlagArtificial = (1 << 6),
|
||||
FlagExplicit = (1 << 7),
|
||||
FlagPrototyped = (1 << 8),
|
||||
FlagObjcClassComplete = (1 << 9),
|
||||
FlagObjectPointer = (1 << 10),
|
||||
FlagVector = (1 << 11),
|
||||
FlagStaticMember = (1 << 12),
|
||||
FlagLValueReference = (1 << 13),
|
||||
FlagRValueReference = (1 << 14),
|
||||
// Do not add values that are not supported by the minimum LLVM
|
||||
// version we support!
|
||||
};
|
||||
|
||||
inline LLVMRustDIFlags operator& (LLVMRustDIFlags a, LLVMRustDIFlags b) {
|
||||
return static_cast<LLVMRustDIFlags>(static_cast<uint32_t>(a) & static_cast<uint32_t>(b));
|
||||
inline LLVMRustDIFlags operator&(LLVMRustDIFlags a, LLVMRustDIFlags b) {
|
||||
return static_cast<LLVMRustDIFlags>(static_cast<uint32_t>(a) &
|
||||
static_cast<uint32_t>(b));
|
||||
}
|
||||
|
||||
inline LLVMRustDIFlags operator| (LLVMRustDIFlags a, LLVMRustDIFlags b) {
|
||||
return static_cast<LLVMRustDIFlags>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
|
||||
inline LLVMRustDIFlags operator|(LLVMRustDIFlags a, LLVMRustDIFlags b) {
|
||||
return static_cast<LLVMRustDIFlags>(static_cast<uint32_t>(a) |
|
||||
static_cast<uint32_t>(b));
|
||||
}
|
||||
|
||||
inline LLVMRustDIFlags& operator|= (LLVMRustDIFlags& a, LLVMRustDIFlags b) {
|
||||
return a = a | b;
|
||||
inline LLVMRustDIFlags &operator|=(LLVMRustDIFlags &a, LLVMRustDIFlags b) {
|
||||
return a = a | b;
|
||||
}
|
||||
|
||||
inline bool is_set(LLVMRustDIFlags f) {
|
||||
return f != LLVMRustDIFlags::FlagZero;
|
||||
}
|
||||
inline bool is_set(LLVMRustDIFlags f) { return f != LLVMRustDIFlags::FlagZero; }
|
||||
|
||||
inline LLVMRustDIFlags visibility(LLVMRustDIFlags f) {
|
||||
return static_cast<LLVMRustDIFlags>(static_cast<uint32_t>(f) & 0x3);
|
||||
return static_cast<LLVMRustDIFlags>(static_cast<uint32_t>(f) & 0x3);
|
||||
}
|
||||
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
static DINode::DIFlags from_rust(LLVMRustDIFlags flags) {
|
||||
DINode::DIFlags result = DINode::DIFlags::FlagZero;
|
||||
DINode::DIFlags result = DINode::DIFlags::FlagZero;
|
||||
#else
|
||||
static unsigned from_rust(LLVMRustDIFlags flags) {
|
||||
unsigned result = 0;
|
||||
unsigned result = 0;
|
||||
#endif
|
||||
|
||||
switch (visibility(flags)) {
|
||||
case LLVMRustDIFlags::FlagPrivate:
|
||||
result |= DINode::DIFlags::FlagPrivate;
|
||||
break;
|
||||
case LLVMRustDIFlags::FlagProtected:
|
||||
result |= DINode::DIFlags::FlagProtected;
|
||||
break;
|
||||
case LLVMRustDIFlags::FlagPublic:
|
||||
result |= DINode::DIFlags::FlagPublic;
|
||||
break;
|
||||
default:
|
||||
// The rest are handled below
|
||||
break;
|
||||
}
|
||||
switch (visibility(flags)) {
|
||||
case LLVMRustDIFlags::FlagPrivate:
|
||||
result |= DINode::DIFlags::FlagPrivate;
|
||||
break;
|
||||
case LLVMRustDIFlags::FlagProtected:
|
||||
result |= DINode::DIFlags::FlagProtected;
|
||||
break;
|
||||
case LLVMRustDIFlags::FlagPublic:
|
||||
result |= DINode::DIFlags::FlagPublic;
|
||||
break;
|
||||
default:
|
||||
// The rest are handled below
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagFwdDecl)) { result |= DINode::DIFlags::FlagFwdDecl; }
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagAppleBlock)) { result |= DINode::DIFlags::FlagAppleBlock; }
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagBlockByrefStruct)) { result |= DINode::DIFlags::FlagBlockByrefStruct; }
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagVirtual)) { result |= DINode::DIFlags::FlagVirtual; }
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagArtificial)) { result |= DINode::DIFlags::FlagArtificial; }
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagExplicit)) { result |= DINode::DIFlags::FlagExplicit; }
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagPrototyped)) { result |= DINode::DIFlags::FlagPrototyped; }
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagObjcClassComplete)) { result |= DINode::DIFlags::FlagObjcClassComplete; }
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagObjectPointer)) { result |= DINode::DIFlags::FlagObjectPointer; }
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagVector)) { result |= DINode::DIFlags::FlagVector; }
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagStaticMember)) { result |= DINode::DIFlags::FlagStaticMember; }
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagLValueReference)) { result |= DINode::DIFlags::FlagLValueReference; }
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagRValueReference)) { result |= DINode::DIFlags::FlagRValueReference; }
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagFwdDecl)) {
|
||||
result |= DINode::DIFlags::FlagFwdDecl;
|
||||
}
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagAppleBlock)) {
|
||||
result |= DINode::DIFlags::FlagAppleBlock;
|
||||
}
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagBlockByrefStruct)) {
|
||||
result |= DINode::DIFlags::FlagBlockByrefStruct;
|
||||
}
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagVirtual)) {
|
||||
result |= DINode::DIFlags::FlagVirtual;
|
||||
}
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagArtificial)) {
|
||||
result |= DINode::DIFlags::FlagArtificial;
|
||||
}
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagExplicit)) {
|
||||
result |= DINode::DIFlags::FlagExplicit;
|
||||
}
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagPrototyped)) {
|
||||
result |= DINode::DIFlags::FlagPrototyped;
|
||||
}
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagObjcClassComplete)) {
|
||||
result |= DINode::DIFlags::FlagObjcClassComplete;
|
||||
}
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagObjectPointer)) {
|
||||
result |= DINode::DIFlags::FlagObjectPointer;
|
||||
}
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagVector)) {
|
||||
result |= DINode::DIFlags::FlagVector;
|
||||
}
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagStaticMember)) {
|
||||
result |= DINode::DIFlags::FlagStaticMember;
|
||||
}
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagLValueReference)) {
|
||||
result |= DINode::DIFlags::FlagLValueReference;
|
||||
}
|
||||
if (is_set(flags & LLVMRustDIFlags::FlagRValueReference)) {
|
||||
result |= DINode::DIFlags::FlagRValueReference;
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
extern "C" uint32_t LLVMRustDebugMetadataVersion() {
|
||||
return DEBUG_METADATA_VERSION;
|
||||
return DEBUG_METADATA_VERSION;
|
||||
}
|
||||
|
||||
extern "C" uint32_t LLVMRustVersionMinor() {
|
||||
return LLVM_VERSION_MINOR;
|
||||
}
|
||||
extern "C" uint32_t LLVMRustVersionMinor() { return LLVM_VERSION_MINOR; }
|
||||
|
||||
extern "C" uint32_t LLVMRustVersionMajor() {
|
||||
return LLVM_VERSION_MAJOR;
|
||||
}
|
||||
extern "C" uint32_t LLVMRustVersionMajor() { return LLVM_VERSION_MAJOR; }
|
||||
|
||||
extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M,
|
||||
const char *name,
|
||||
extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M, const char *name,
|
||||
uint32_t value) {
|
||||
unwrap(M)->addModuleFlag(Module::Warning, name, value);
|
||||
unwrap(M)->addModuleFlag(Module::Warning, name, value);
|
||||
}
|
||||
|
||||
extern "C" LLVMRustDIBuilderRef LLVMRustDIBuilderCreate(LLVMModuleRef M) {
|
||||
return new DIBuilder(*unwrap(M));
|
||||
return new DIBuilder(*unwrap(M));
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustDIBuilderDispose(LLVMRustDIBuilderRef Builder) {
|
||||
delete Builder;
|
||||
delete Builder;
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustDIBuilderFinalize(LLVMRustDIBuilderRef Builder) {
|
||||
Builder->finalize();
|
||||
Builder->finalize();
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateCompileUnit(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
unsigned Lang,
|
||||
const char* File,
|
||||
const char* Dir,
|
||||
const char* Producer,
|
||||
bool isOptimized,
|
||||
const char* Flags,
|
||||
unsigned RuntimeVer,
|
||||
const char* SplitName) {
|
||||
return wrap(Builder->createCompileUnit(Lang,
|
||||
File,
|
||||
Dir,
|
||||
Producer,
|
||||
isOptimized,
|
||||
Flags,
|
||||
RuntimeVer,
|
||||
SplitName));
|
||||
LLVMRustDIBuilderRef Builder, unsigned Lang, const char *File,
|
||||
const char *Dir, const char *Producer, bool isOptimized, const char *Flags,
|
||||
unsigned RuntimeVer, const char *SplitName) {
|
||||
return wrap(Builder->createCompileUnit(Lang, File, Dir, Producer, isOptimized,
|
||||
Flags, RuntimeVer, SplitName));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateFile(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
const char* Filename,
|
||||
const char* Directory) {
|
||||
return wrap(Builder->createFile(Filename, Directory));
|
||||
extern "C" LLVMRustMetadataRef
|
||||
LLVMRustDIBuilderCreateFile(LLVMRustDIBuilderRef Builder, const char *Filename,
|
||||
const char *Directory) {
|
||||
return wrap(Builder->createFile(Filename, Directory));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateSubroutineType(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef File,
|
||||
LLVMRustMetadataRef ParameterTypes) {
|
||||
return wrap(Builder->createSubroutineType(
|
||||
extern "C" LLVMRustMetadataRef
|
||||
LLVMRustDIBuilderCreateSubroutineType(LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef File,
|
||||
LLVMRustMetadataRef ParameterTypes) {
|
||||
return wrap(Builder->createSubroutineType(
|
||||
#if LLVM_VERSION_EQ(3, 7)
|
||||
unwrapDI<DIFile>(File),
|
||||
unwrapDI<DIFile>(File),
|
||||
#endif
|
||||
DITypeRefArray(unwrap<MDTuple>(ParameterTypes))));
|
||||
DITypeRefArray(unwrap<MDTuple>(ParameterTypes))));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateFunction(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef Scope,
|
||||
const char* Name,
|
||||
const char* LinkageName,
|
||||
LLVMRustMetadataRef File,
|
||||
unsigned LineNo,
|
||||
LLVMRustMetadataRef Ty,
|
||||
bool isLocalToUnit,
|
||||
bool isDefinition,
|
||||
unsigned ScopeLine,
|
||||
LLVMRustDIFlags Flags,
|
||||
bool isOptimized,
|
||||
LLVMValueRef Fn,
|
||||
LLVMRustMetadataRef TParam,
|
||||
LLVMRustMetadataRef Decl) {
|
||||
LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, const char *Name,
|
||||
const char *LinkageName, LLVMRustMetadataRef File, unsigned LineNo,
|
||||
LLVMRustMetadataRef Ty, bool isLocalToUnit, bool isDefinition,
|
||||
unsigned ScopeLine, LLVMRustDIFlags Flags, bool isOptimized,
|
||||
LLVMValueRef Fn, LLVMRustMetadataRef TParam, LLVMRustMetadataRef Decl) {
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
DITemplateParameterArray TParams =
|
||||
DITemplateParameterArray(unwrap<MDTuple>(TParam));
|
||||
DISubprogram *Sub = Builder->createFunction(
|
||||
unwrapDI<DIScope>(Scope), Name, LinkageName,
|
||||
unwrapDI<DIFile>(File), LineNo,
|
||||
unwrapDI<DISubroutineType>(Ty), isLocalToUnit, isDefinition, ScopeLine,
|
||||
from_rust(Flags), isOptimized,
|
||||
TParams,
|
||||
unwrapDIptr<DISubprogram>(Decl));
|
||||
unwrap<Function>(Fn)->setSubprogram(Sub);
|
||||
return wrap(Sub);
|
||||
DITemplateParameterArray TParams =
|
||||
DITemplateParameterArray(unwrap<MDTuple>(TParam));
|
||||
DISubprogram *Sub = Builder->createFunction(
|
||||
unwrapDI<DIScope>(Scope), Name, LinkageName, unwrapDI<DIFile>(File),
|
||||
LineNo, unwrapDI<DISubroutineType>(Ty), isLocalToUnit, isDefinition,
|
||||
ScopeLine, from_rust(Flags), isOptimized, TParams,
|
||||
unwrapDIptr<DISubprogram>(Decl));
|
||||
unwrap<Function>(Fn)->setSubprogram(Sub);
|
||||
return wrap(Sub);
|
||||
#else
|
||||
return wrap(Builder->createFunction(
|
||||
unwrapDI<DIScope>(Scope), Name, LinkageName,
|
||||
unwrapDI<DIFile>(File), LineNo,
|
||||
unwrapDI<DISubroutineType>(Ty), isLocalToUnit, isDefinition, ScopeLine,
|
||||
from_rust(Flags), isOptimized,
|
||||
unwrap<Function>(Fn),
|
||||
unwrapDIptr<MDNode>(TParam),
|
||||
unwrapDIptr<MDNode>(Decl)));
|
||||
return wrap(Builder->createFunction(
|
||||
unwrapDI<DIScope>(Scope), Name, LinkageName, unwrapDI<DIFile>(File),
|
||||
LineNo, unwrapDI<DISubroutineType>(Ty), isLocalToUnit, isDefinition,
|
||||
ScopeLine, from_rust(Flags), isOptimized, unwrap<Function>(Fn),
|
||||
unwrapDIptr<MDNode>(TParam), unwrapDIptr<MDNode>(Decl)));
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateBasicType(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
const char* Name,
|
||||
uint64_t SizeInBits,
|
||||
uint64_t AlignInBits,
|
||||
unsigned Encoding) {
|
||||
return wrap(Builder->createBasicType(
|
||||
Name,
|
||||
SizeInBits,
|
||||
extern "C" LLVMRustMetadataRef
|
||||
LLVMRustDIBuilderCreateBasicType(LLVMRustDIBuilderRef Builder, const char *Name,
|
||||
uint64_t SizeInBits, uint64_t AlignInBits,
|
||||
unsigned Encoding) {
|
||||
return wrap(Builder->createBasicType(Name, SizeInBits,
|
||||
#if LLVM_VERSION_LE(3, 9)
|
||||
AlignInBits,
|
||||
AlignInBits,
|
||||
#endif
|
||||
Encoding
|
||||
));
|
||||
Encoding));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreatePointerType(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef PointeeTy,
|
||||
uint64_t SizeInBits,
|
||||
uint64_t AlignInBits,
|
||||
const char* Name) {
|
||||
return wrap(Builder->createPointerType(
|
||||
unwrapDI<DIType>(PointeeTy), SizeInBits, AlignInBits, Name));
|
||||
LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef PointeeTy,
|
||||
uint64_t SizeInBits, uint64_t AlignInBits, const char *Name) {
|
||||
return wrap(Builder->createPointerType(unwrapDI<DIType>(PointeeTy),
|
||||
SizeInBits, AlignInBits, Name));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStructType(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef Scope,
|
||||
const char* Name,
|
||||
LLVMRustMetadataRef File,
|
||||
unsigned LineNumber,
|
||||
uint64_t SizeInBits,
|
||||
uint64_t AlignInBits,
|
||||
LLVMRustDIFlags Flags,
|
||||
LLVMRustMetadataRef DerivedFrom,
|
||||
LLVMRustMetadataRef Elements,
|
||||
unsigned RunTimeLang,
|
||||
LLVMRustMetadataRef VTableHolder,
|
||||
LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, const char *Name,
|
||||
LLVMRustMetadataRef File, unsigned LineNumber, uint64_t SizeInBits,
|
||||
uint64_t AlignInBits, LLVMRustDIFlags Flags,
|
||||
LLVMRustMetadataRef DerivedFrom, LLVMRustMetadataRef Elements,
|
||||
unsigned RunTimeLang, LLVMRustMetadataRef VTableHolder,
|
||||
const char *UniqueId) {
|
||||
return wrap(Builder->createStructType(
|
||||
unwrapDI<DIDescriptor>(Scope),
|
||||
Name,
|
||||
unwrapDI<DIFile>(File),
|
||||
LineNumber,
|
||||
SizeInBits,
|
||||
AlignInBits,
|
||||
from_rust(Flags),
|
||||
unwrapDI<DIType>(DerivedFrom),
|
||||
DINodeArray(unwrapDI<MDTuple>(Elements)),
|
||||
RunTimeLang,
|
||||
unwrapDI<DIType>(VTableHolder),
|
||||
UniqueId
|
||||
));
|
||||
return wrap(Builder->createStructType(
|
||||
unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber,
|
||||
SizeInBits, AlignInBits, from_rust(Flags), unwrapDI<DIType>(DerivedFrom),
|
||||
DINodeArray(unwrapDI<MDTuple>(Elements)), RunTimeLang,
|
||||
unwrapDI<DIType>(VTableHolder), UniqueId));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateMemberType(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef Scope,
|
||||
const char* Name,
|
||||
LLVMRustMetadataRef File,
|
||||
unsigned LineNo,
|
||||
uint64_t SizeInBits,
|
||||
uint64_t AlignInBits,
|
||||
uint64_t OffsetInBits,
|
||||
LLVMRustDIFlags Flags,
|
||||
LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, const char *Name,
|
||||
LLVMRustMetadataRef File, unsigned LineNo, uint64_t SizeInBits,
|
||||
uint64_t AlignInBits, uint64_t OffsetInBits, LLVMRustDIFlags Flags,
|
||||
LLVMRustMetadataRef Ty) {
|
||||
return wrap(Builder->createMemberType(
|
||||
unwrapDI<DIDescriptor>(Scope), Name,
|
||||
unwrapDI<DIFile>(File), LineNo,
|
||||
SizeInBits, AlignInBits, OffsetInBits, from_rust(Flags),
|
||||
unwrapDI<DIType>(Ty)));
|
||||
return wrap(Builder->createMemberType(
|
||||
unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNo,
|
||||
SizeInBits, AlignInBits, OffsetInBits, from_rust(Flags),
|
||||
unwrapDI<DIType>(Ty)));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateLexicalBlock(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef Scope,
|
||||
LLVMRustMetadataRef File,
|
||||
unsigned Line,
|
||||
unsigned Col) {
|
||||
return wrap(Builder->createLexicalBlock(
|
||||
unwrapDI<DIDescriptor>(Scope),
|
||||
unwrapDI<DIFile>(File), Line, Col
|
||||
));
|
||||
LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope,
|
||||
LLVMRustMetadataRef File, unsigned Line, unsigned Col) {
|
||||
return wrap(Builder->createLexicalBlock(unwrapDI<DIDescriptor>(Scope),
|
||||
unwrapDI<DIFile>(File), Line, Col));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateLexicalBlockFile(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef Scope,
|
||||
LLVMRustMetadataRef File) {
|
||||
return wrap(Builder->createLexicalBlockFile(
|
||||
unwrapDI<DIDescriptor>(Scope),
|
||||
unwrapDI<DIFile>(File)));
|
||||
extern "C" LLVMRustMetadataRef
|
||||
LLVMRustDIBuilderCreateLexicalBlockFile(LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef Scope,
|
||||
LLVMRustMetadataRef File) {
|
||||
return wrap(Builder->createLexicalBlockFile(unwrapDI<DIDescriptor>(Scope),
|
||||
unwrapDI<DIFile>(File)));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef Context,
|
||||
const char* Name,
|
||||
const char* LinkageName,
|
||||
LLVMRustMetadataRef File,
|
||||
unsigned LineNo,
|
||||
LLVMRustMetadataRef Ty,
|
||||
bool isLocalToUnit,
|
||||
LLVMValueRef Val,
|
||||
LLVMRustMetadataRef Decl = NULL,
|
||||
uint64_t AlignInBits = 0) {
|
||||
Constant *InitVal = cast<Constant>(unwrap(Val));
|
||||
LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Context, const char *Name,
|
||||
const char *LinkageName, LLVMRustMetadataRef File, unsigned LineNo,
|
||||
LLVMRustMetadataRef Ty, bool isLocalToUnit, LLVMValueRef Val,
|
||||
LLVMRustMetadataRef Decl = nullptr, uint64_t AlignInBits = 0) {
|
||||
Constant *InitVal = cast<Constant>(unwrap(Val));
|
||||
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
llvm::DIExpression *InitExpr = nullptr;
|
||||
if (llvm::ConstantInt *IntVal = llvm::dyn_cast<llvm::ConstantInt>(InitVal)) {
|
||||
InitExpr = Builder->createConstantValueExpression(
|
||||
IntVal->getValue().getSExtValue());
|
||||
} else if (llvm::ConstantFP *FPVal = llvm::dyn_cast<llvm::ConstantFP>(InitVal)) {
|
||||
InitExpr = Builder->createConstantValueExpression(
|
||||
FPVal->getValueAPF().bitcastToAPInt().getZExtValue());
|
||||
}
|
||||
llvm::DIExpression *InitExpr = nullptr;
|
||||
if (llvm::ConstantInt *IntVal = llvm::dyn_cast<llvm::ConstantInt>(InitVal)) {
|
||||
InitExpr = Builder->createConstantValueExpression(
|
||||
IntVal->getValue().getSExtValue());
|
||||
} else if (llvm::ConstantFP *FPVal =
|
||||
llvm::dyn_cast<llvm::ConstantFP>(InitVal)) {
|
||||
InitExpr = Builder->createConstantValueExpression(
|
||||
FPVal->getValueAPF().bitcastToAPInt().getZExtValue());
|
||||
}
|
||||
#endif
|
||||
|
||||
return wrap(Builder->createGlobalVariable(unwrapDI<DIDescriptor>(Context),
|
||||
Name,
|
||||
LinkageName,
|
||||
unwrapDI<DIFile>(File),
|
||||
LineNo,
|
||||
unwrapDI<DIType>(Ty),
|
||||
isLocalToUnit,
|
||||
return wrap(Builder->createGlobalVariable(
|
||||
unwrapDI<DIDescriptor>(Context), Name, LinkageName,
|
||||
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), isLocalToUnit,
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
InitExpr,
|
||||
InitExpr,
|
||||
#else
|
||||
InitVal,
|
||||
InitVal,
|
||||
#endif
|
||||
unwrapDIptr<MDNode>(Decl)
|
||||
unwrapDIptr<MDNode>(Decl)
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
, AlignInBits
|
||||
,
|
||||
AlignInBits
|
||||
#endif
|
||||
));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateVariable(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
unsigned Tag,
|
||||
LLVMRustMetadataRef Scope,
|
||||
const char* Name,
|
||||
LLVMRustMetadataRef File,
|
||||
unsigned LineNo,
|
||||
LLVMRustMetadataRef Ty,
|
||||
bool AlwaysPreserve,
|
||||
LLVMRustDIFlags Flags,
|
||||
unsigned ArgNo,
|
||||
uint64_t AlignInBits)
|
||||
{
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
if (Tag == 0x100) { // DW_TAG_auto_variable
|
||||
return wrap(Builder->createAutoVariable(
|
||||
unwrapDI<DIDescriptor>(Scope),
|
||||
Name,
|
||||
unwrapDI<DIFile>(File),
|
||||
LineNo,
|
||||
unwrapDI<DIType>(Ty),
|
||||
AlwaysPreserve,
|
||||
from_rust(Flags)
|
||||
#if LLVM_VERSION_GE(4,0)
|
||||
, AlignInBits
|
||||
#endif
|
||||
));
|
||||
} else {
|
||||
return wrap(Builder->createParameterVariable(
|
||||
unwrapDI<DIDescriptor>(Scope), Name, ArgNo,
|
||||
unwrapDI<DIFile>(File),
|
||||
LineNo,
|
||||
unwrapDI<DIType>(Ty), AlwaysPreserve, from_rust(Flags)));
|
||||
}
|
||||
#else
|
||||
return wrap(Builder->createLocalVariable(Tag,
|
||||
unwrapDI<DIDescriptor>(Scope), Name,
|
||||
unwrapDI<DIFile>(File),
|
||||
LineNo,
|
||||
unwrapDI<DIType>(Ty), AlwaysPreserve, from_rust(Flags), ArgNo));
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateArrayType(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
uint64_t Size,
|
||||
uint64_t AlignInBits,
|
||||
LLVMRustMetadataRef Ty,
|
||||
LLVMRustMetadataRef Subscripts) {
|
||||
return wrap(Builder->createArrayType(Size, AlignInBits,
|
||||
unwrapDI<DIType>(Ty),
|
||||
DINodeArray(unwrapDI<MDTuple>(Subscripts))
|
||||
));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateVectorType(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
uint64_t Size,
|
||||
uint64_t AlignInBits,
|
||||
LLVMRustMetadataRef Ty,
|
||||
LLVMRustMetadataRef Subscripts) {
|
||||
return wrap(Builder->createVectorType(Size, AlignInBits,
|
||||
unwrapDI<DIType>(Ty),
|
||||
DINodeArray(unwrapDI<MDTuple>(Subscripts))
|
||||
));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderGetOrCreateSubrange(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
int64_t Lo,
|
||||
int64_t Count) {
|
||||
return wrap(Builder->getOrCreateSubrange(Lo, Count));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderGetOrCreateArray(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef* Ptr,
|
||||
unsigned Count) {
|
||||
Metadata **DataValue = unwrap(Ptr);
|
||||
return wrap(Builder->getOrCreateArray(
|
||||
ArrayRef<Metadata*>(DataValue, Count)).get());
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
LLVMValueRef Val,
|
||||
LLVMRustMetadataRef VarInfo,
|
||||
int64_t* AddrOps,
|
||||
unsigned AddrOpsCount,
|
||||
LLVMValueRef DL,
|
||||
LLVMBasicBlockRef InsertAtEnd) {
|
||||
return wrap(Builder->insertDeclare(
|
||||
unwrap(Val),
|
||||
unwrap<DILocalVariable>(VarInfo),
|
||||
Builder->createExpression(
|
||||
llvm::ArrayRef<int64_t>(AddrOps, AddrOpsCount)),
|
||||
DebugLoc(cast<MDNode>(unwrap<MetadataAsValue>(DL)->getMetadata())),
|
||||
unwrap(InsertAtEnd)));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateEnumerator(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
const char* Name,
|
||||
uint64_t Val)
|
||||
{
|
||||
return wrap(Builder->createEnumerator(Name, Val));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateEnumerationType(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef Scope,
|
||||
const char* Name,
|
||||
LLVMRustMetadataRef File,
|
||||
unsigned LineNumber,
|
||||
uint64_t SizeInBits,
|
||||
uint64_t AlignInBits,
|
||||
LLVMRustMetadataRef Elements,
|
||||
LLVMRustMetadataRef ClassType)
|
||||
{
|
||||
return wrap(Builder->createEnumerationType(
|
||||
unwrapDI<DIDescriptor>(Scope),
|
||||
Name,
|
||||
unwrapDI<DIFile>(File),
|
||||
LineNumber,
|
||||
SizeInBits,
|
||||
AlignInBits,
|
||||
DINodeArray(unwrapDI<MDTuple>(Elements)),
|
||||
unwrapDI<DIType>(ClassType)));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateUnionType(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef Scope,
|
||||
const char* Name,
|
||||
LLVMRustMetadataRef File,
|
||||
unsigned LineNumber,
|
||||
uint64_t SizeInBits,
|
||||
uint64_t AlignInBits,
|
||||
LLVMRustDIFlags Flags,
|
||||
LLVMRustMetadataRef Elements,
|
||||
unsigned RunTimeLang,
|
||||
const char* UniqueId)
|
||||
{
|
||||
return wrap(Builder->createUnionType(
|
||||
unwrapDI<DIDescriptor>(Scope),
|
||||
Name,
|
||||
unwrapDI<DIFile>(File),
|
||||
LineNumber,
|
||||
SizeInBits,
|
||||
AlignInBits,
|
||||
from_rust(Flags),
|
||||
DINodeArray(unwrapDI<MDTuple>(Elements)),
|
||||
RunTimeLang,
|
||||
UniqueId
|
||||
));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateTemplateTypeParameter(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef Scope,
|
||||
const char* Name,
|
||||
LLVMRustMetadataRef Ty,
|
||||
LLVMRustMetadataRef File,
|
||||
unsigned LineNo,
|
||||
unsigned ColumnNo)
|
||||
{
|
||||
return wrap(Builder->createTemplateTypeParameter(
|
||||
unwrapDI<DIDescriptor>(Scope),
|
||||
Name,
|
||||
unwrapDI<DIType>(Ty)
|
||||
));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateNameSpace(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef Scope,
|
||||
const char* Name,
|
||||
LLVMRustMetadataRef File,
|
||||
unsigned LineNo)
|
||||
{
|
||||
return wrap(Builder->createNameSpace(
|
||||
unwrapDI<DIDescriptor>(Scope),
|
||||
Name,
|
||||
unwrapDI<DIFile>(File),
|
||||
LineNo
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateVariable(
|
||||
LLVMRustDIBuilderRef Builder, unsigned Tag, LLVMRustMetadataRef Scope,
|
||||
const char *Name, LLVMRustMetadataRef File, unsigned LineNo,
|
||||
LLVMRustMetadataRef Ty, bool AlwaysPreserve, LLVMRustDIFlags Flags,
|
||||
unsigned ArgNo, uint64_t AlignInBits) {
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
if (Tag == 0x100) { // DW_TAG_auto_variable
|
||||
return wrap(Builder->createAutoVariable(
|
||||
unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNo,
|
||||
unwrapDI<DIType>(Ty), AlwaysPreserve, from_rust(Flags)
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
, false // ExportSymbols (only relevant for C++ anonymous namespaces)
|
||||
,
|
||||
AlignInBits
|
||||
#endif
|
||||
));
|
||||
} else {
|
||||
return wrap(Builder->createParameterVariable(
|
||||
unwrapDI<DIDescriptor>(Scope), Name, ArgNo, unwrapDI<DIFile>(File),
|
||||
LineNo, unwrapDI<DIType>(Ty), AlwaysPreserve, from_rust(Flags)));
|
||||
}
|
||||
#else
|
||||
return wrap(Builder->createLocalVariable(
|
||||
Tag, unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNo,
|
||||
unwrapDI<DIType>(Ty), AlwaysPreserve, from_rust(Flags), ArgNo));
|
||||
#endif
|
||||
));
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustDICompositeTypeSetTypeArray(
|
||||
LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef CompositeType,
|
||||
LLVMRustMetadataRef TypeArray)
|
||||
{
|
||||
DICompositeType *tmp = unwrapDI<DICompositeType>(CompositeType);
|
||||
Builder->replaceArrays(tmp, DINodeArray(unwrap<MDTuple>(TypeArray)));
|
||||
extern "C" LLVMRustMetadataRef
|
||||
LLVMRustDIBuilderCreateArrayType(LLVMRustDIBuilderRef Builder, uint64_t Size,
|
||||
uint64_t AlignInBits, LLVMRustMetadataRef Ty,
|
||||
LLVMRustMetadataRef Subscripts) {
|
||||
return wrap(
|
||||
Builder->createArrayType(Size, AlignInBits, unwrapDI<DIType>(Ty),
|
||||
DINodeArray(unwrapDI<MDTuple>(Subscripts))));
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef LLVMRustDIBuilderCreateDebugLocation(
|
||||
LLVMContextRef Context,
|
||||
unsigned Line,
|
||||
unsigned Column,
|
||||
LLVMRustMetadataRef Scope,
|
||||
LLVMRustMetadataRef InlinedAt)
|
||||
{
|
||||
LLVMContext& context = *unwrap(Context);
|
||||
|
||||
DebugLoc debug_loc = DebugLoc::get(Line,
|
||||
Column,
|
||||
unwrapDIptr<MDNode>(Scope),
|
||||
unwrapDIptr<MDNode>(InlinedAt));
|
||||
|
||||
return wrap(MetadataAsValue::get(context, debug_loc.getAsMDNode()));
|
||||
extern "C" LLVMRustMetadataRef
|
||||
LLVMRustDIBuilderCreateVectorType(LLVMRustDIBuilderRef Builder, uint64_t Size,
|
||||
uint64_t AlignInBits, LLVMRustMetadataRef Ty,
|
||||
LLVMRustMetadataRef Subscripts) {
|
||||
return wrap(
|
||||
Builder->createVectorType(Size, AlignInBits, unwrapDI<DIType>(Ty),
|
||||
DINodeArray(unwrapDI<MDTuple>(Subscripts))));
|
||||
}
|
||||
|
||||
extern "C" int64_t LLVMRustDIBuilderCreateOpDeref()
|
||||
{
|
||||
return dwarf::DW_OP_deref;
|
||||
extern "C" LLVMRustMetadataRef
|
||||
LLVMRustDIBuilderGetOrCreateSubrange(LLVMRustDIBuilderRef Builder, int64_t Lo,
|
||||
int64_t Count) {
|
||||
return wrap(Builder->getOrCreateSubrange(Lo, Count));
|
||||
}
|
||||
|
||||
extern "C" int64_t LLVMRustDIBuilderCreateOpPlus()
|
||||
{
|
||||
return dwarf::DW_OP_plus;
|
||||
extern "C" LLVMRustMetadataRef
|
||||
LLVMRustDIBuilderGetOrCreateArray(LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef *Ptr, unsigned Count) {
|
||||
Metadata **DataValue = unwrap(Ptr);
|
||||
return wrap(
|
||||
Builder->getOrCreateArray(ArrayRef<Metadata *>(DataValue, Count)).get());
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd(
|
||||
LLVMRustDIBuilderRef Builder, LLVMValueRef Val, LLVMRustMetadataRef VarInfo,
|
||||
int64_t *AddrOps, unsigned AddrOpsCount, LLVMValueRef DL,
|
||||
LLVMBasicBlockRef InsertAtEnd) {
|
||||
return wrap(Builder->insertDeclare(
|
||||
unwrap(Val), unwrap<DILocalVariable>(VarInfo),
|
||||
Builder->createExpression(llvm::ArrayRef<int64_t>(AddrOps, AddrOpsCount)),
|
||||
DebugLoc(cast<MDNode>(unwrap<MetadataAsValue>(DL)->getMetadata())),
|
||||
unwrap(InsertAtEnd)));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef
|
||||
LLVMRustDIBuilderCreateEnumerator(LLVMRustDIBuilderRef Builder,
|
||||
const char *Name, uint64_t Val) {
|
||||
return wrap(Builder->createEnumerator(Name, Val));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateEnumerationType(
|
||||
LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, const char *Name,
|
||||
LLVMRustMetadataRef File, unsigned LineNumber, uint64_t SizeInBits,
|
||||
uint64_t AlignInBits, LLVMRustMetadataRef Elements,
|
||||
LLVMRustMetadataRef ClassType) {
|
||||
return wrap(Builder->createEnumerationType(
|
||||
unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber,
|
||||
SizeInBits, AlignInBits, DINodeArray(unwrapDI<MDTuple>(Elements)),
|
||||
unwrapDI<DIType>(ClassType)));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateUnionType(
|
||||
LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, const char *Name,
|
||||
LLVMRustMetadataRef File, unsigned LineNumber, uint64_t SizeInBits,
|
||||
uint64_t AlignInBits, LLVMRustDIFlags Flags, LLVMRustMetadataRef Elements,
|
||||
unsigned RunTimeLang, const char *UniqueId) {
|
||||
return wrap(Builder->createUnionType(
|
||||
unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber,
|
||||
SizeInBits, AlignInBits, from_rust(Flags),
|
||||
DINodeArray(unwrapDI<MDTuple>(Elements)), RunTimeLang, UniqueId));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateTemplateTypeParameter(
|
||||
LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, const char *Name,
|
||||
LLVMRustMetadataRef Ty, LLVMRustMetadataRef File, unsigned LineNo,
|
||||
unsigned ColumnNo) {
|
||||
return wrap(Builder->createTemplateTypeParameter(
|
||||
unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIType>(Ty)));
|
||||
}
|
||||
|
||||
extern "C" LLVMRustMetadataRef
|
||||
LLVMRustDIBuilderCreateNameSpace(LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef Scope, const char *Name,
|
||||
LLVMRustMetadataRef File, unsigned LineNo) {
|
||||
return wrap(Builder->createNameSpace(
|
||||
unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNo
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
,
|
||||
false // ExportSymbols (only relevant for C++ anonymous namespaces)
|
||||
#endif
|
||||
));
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustDICompositeTypeSetTypeArray(LLVMRustDIBuilderRef Builder,
|
||||
LLVMRustMetadataRef CompositeType,
|
||||
LLVMRustMetadataRef TypeArray) {
|
||||
DICompositeType *tmp = unwrapDI<DICompositeType>(CompositeType);
|
||||
Builder->replaceArrays(tmp, DINodeArray(unwrap<MDTuple>(TypeArray)));
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef
|
||||
LLVMRustDIBuilderCreateDebugLocation(LLVMContextRef Context, unsigned Line,
|
||||
unsigned Column, LLVMRustMetadataRef Scope,
|
||||
LLVMRustMetadataRef InlinedAt) {
|
||||
LLVMContext &context = *unwrap(Context);
|
||||
|
||||
DebugLoc debug_loc = DebugLoc::get(Line, Column, unwrapDIptr<MDNode>(Scope),
|
||||
unwrapDIptr<MDNode>(InlinedAt));
|
||||
|
||||
return wrap(MetadataAsValue::get(context, debug_loc.getAsMDNode()));
|
||||
}
|
||||
|
||||
extern "C" int64_t LLVMRustDIBuilderCreateOpDeref() {
|
||||
return dwarf::DW_OP_deref;
|
||||
}
|
||||
|
||||
extern "C" int64_t LLVMRustDIBuilderCreateOpPlus() { return dwarf::DW_OP_plus; }
|
||||
|
||||
extern "C" void LLVMRustWriteTypeToString(LLVMTypeRef Type, RustStringRef str) {
|
||||
raw_rust_string_ostream os(str);
|
||||
unwrap<llvm::Type>(Type)->print(os);
|
||||
raw_rust_string_ostream os(str);
|
||||
unwrap<llvm::Type>(Type)->print(os);
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustWriteValueToString(LLVMValueRef Value, RustStringRef str) {
|
||||
raw_rust_string_ostream os(str);
|
||||
os << "(";
|
||||
unwrap<llvm::Value>(Value)->getType()->print(os);
|
||||
os << ":";
|
||||
unwrap<llvm::Value>(Value)->print(os);
|
||||
os << ")";
|
||||
extern "C" void LLVMRustWriteValueToString(LLVMValueRef Value,
|
||||
RustStringRef str) {
|
||||
raw_rust_string_ostream os(str);
|
||||
os << "(";
|
||||
unwrap<llvm::Value>(Value)->getType()->print(os);
|
||||
os << ":";
|
||||
unwrap<llvm::Value>(Value)->print(os);
|
||||
os << ")";
|
||||
}
|
||||
|
||||
extern "C" bool
|
||||
LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
|
||||
Module *Dst = unwrap(dst);
|
||||
extern "C" bool LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc,
|
||||
size_t len) {
|
||||
Module *Dst = unwrap(dst);
|
||||
|
||||
std::unique_ptr<MemoryBuffer> buf = MemoryBuffer::getMemBufferCopy(StringRef(bc, len));
|
||||
std::unique_ptr<MemoryBuffer> buf =
|
||||
MemoryBuffer::getMemBufferCopy(StringRef(bc, len));
|
||||
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
Expected<std::unique_ptr<Module>> SrcOrError =
|
||||
llvm::getLazyBitcodeModule(buf->getMemBufferRef(), Dst->getContext());
|
||||
if (!SrcOrError) {
|
||||
LLVMRustSetLastError(toString(SrcOrError.takeError()).c_str());
|
||||
return false;
|
||||
}
|
||||
Expected<std::unique_ptr<Module>> SrcOrError =
|
||||
llvm::getLazyBitcodeModule(buf->getMemBufferRef(), Dst->getContext());
|
||||
if (!SrcOrError) {
|
||||
LLVMRustSetLastError(toString(SrcOrError.takeError()).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto Src = std::move(*SrcOrError);
|
||||
auto Src = std::move(*SrcOrError);
|
||||
#else
|
||||
ErrorOr<std::unique_ptr<Module>> Src =
|
||||
llvm::getLazyBitcodeModule(std::move(buf), Dst->getContext());
|
||||
if (!Src) {
|
||||
LLVMRustSetLastError(Src.getError().message().c_str());
|
||||
return false;
|
||||
}
|
||||
ErrorOr<std::unique_ptr<Module>> Src =
|
||||
llvm::getLazyBitcodeModule(std::move(buf), Dst->getContext());
|
||||
if (!Src) {
|
||||
LLVMRustSetLastError(Src.getError().message().c_str());
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string Err;
|
||||
std::string Err;
|
||||
|
||||
raw_string_ostream Stream(Err);
|
||||
DiagnosticPrinterRawOStream DP(Stream);
|
||||
raw_string_ostream Stream(Err);
|
||||
DiagnosticPrinterRawOStream DP(Stream);
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
if (Linker::linkModules(*Dst, std::move(Src))) {
|
||||
if (Linker::linkModules(*Dst, std::move(Src))) {
|
||||
#elif LLVM_VERSION_GE(3, 8)
|
||||
if (Linker::linkModules(*Dst, std::move(Src.get()))) {
|
||||
if (Linker::linkModules(*Dst, std::move(Src.get()))) {
|
||||
#else
|
||||
if (Linker::LinkModules(Dst, Src->get(), [&](const DiagnosticInfo &DI) { DI.print(DP); })) {
|
||||
if (Linker::LinkModules(Dst, Src->get(),
|
||||
[&](const DiagnosticInfo &DI) { DI.print(DP); })) {
|
||||
#endif
|
||||
LLVMRustSetLastError(Err.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
LLVMRustSetLastError(Err.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Note that the two following functions look quite similar to the
|
||||
@@ -980,127 +820,118 @@ LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
|
||||
// that's returned.
|
||||
|
||||
inline section_iterator *unwrap(LLVMSectionIteratorRef SI) {
|
||||
return reinterpret_cast<section_iterator*>(SI);
|
||||
return reinterpret_cast<section_iterator *>(SI);
|
||||
}
|
||||
|
||||
extern "C" size_t
|
||||
LLVMRustGetSectionName(LLVMSectionIteratorRef SI, const char **ptr) {
|
||||
StringRef ret;
|
||||
if (std::error_code ec = (*unwrap(SI))->getName(ret))
|
||||
report_fatal_error(ec.message());
|
||||
*ptr = ret.data();
|
||||
return ret.size();
|
||||
extern "C" size_t LLVMRustGetSectionName(LLVMSectionIteratorRef SI,
|
||||
const char **ptr) {
|
||||
StringRef ret;
|
||||
if (std::error_code ec = (*unwrap(SI))->getName(ret))
|
||||
report_fatal_error(ec.message());
|
||||
*ptr = ret.data();
|
||||
return ret.size();
|
||||
}
|
||||
|
||||
// LLVMArrayType function does not support 64-bit ElementCount
|
||||
extern "C" LLVMTypeRef
|
||||
LLVMRustArrayType(LLVMTypeRef ElementType, uint64_t ElementCount) {
|
||||
return wrap(ArrayType::get(unwrap(ElementType), ElementCount));
|
||||
extern "C" LLVMTypeRef LLVMRustArrayType(LLVMTypeRef ElementType,
|
||||
uint64_t ElementCount) {
|
||||
return wrap(ArrayType::get(unwrap(ElementType), ElementCount));
|
||||
}
|
||||
|
||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Twine, LLVMTwineRef)
|
||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DebugLoc, LLVMDebugLocRef)
|
||||
|
||||
extern "C" void
|
||||
LLVMRustWriteTwineToString(LLVMTwineRef T, RustStringRef str) {
|
||||
raw_rust_string_ostream os(str);
|
||||
unwrap(T)->print(os);
|
||||
extern "C" void LLVMRustWriteTwineToString(LLVMTwineRef T, RustStringRef str) {
|
||||
raw_rust_string_ostream os(str);
|
||||
unwrap(T)->print(os);
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustUnpackOptimizationDiagnostic(
|
||||
LLVMDiagnosticInfoRef di,
|
||||
RustStringRef pass_name_out,
|
||||
LLVMValueRef *function_out,
|
||||
LLVMDebugLocRef *debugloc_out,
|
||||
RustStringRef message_out)
|
||||
{
|
||||
// Undefined to call this not on an optimization diagnostic!
|
||||
llvm::DiagnosticInfoOptimizationBase *opt
|
||||
= static_cast<llvm::DiagnosticInfoOptimizationBase*>(unwrap(di));
|
||||
extern "C" void LLVMRustUnpackOptimizationDiagnostic(
|
||||
LLVMDiagnosticInfoRef di, RustStringRef pass_name_out,
|
||||
LLVMValueRef *function_out, LLVMDebugLocRef *debugloc_out,
|
||||
RustStringRef message_out) {
|
||||
// Undefined to call this not on an optimization diagnostic!
|
||||
llvm::DiagnosticInfoOptimizationBase *opt =
|
||||
static_cast<llvm::DiagnosticInfoOptimizationBase *>(unwrap(di));
|
||||
|
||||
raw_rust_string_ostream pass_name_os(pass_name_out);
|
||||
pass_name_os << opt->getPassName();
|
||||
*function_out = wrap(&opt->getFunction());
|
||||
*debugloc_out = wrap(&opt->getDebugLoc());
|
||||
raw_rust_string_ostream message_os(message_out);
|
||||
message_os << opt->getMsg();
|
||||
raw_rust_string_ostream pass_name_os(pass_name_out);
|
||||
pass_name_os << opt->getPassName();
|
||||
*function_out = wrap(&opt->getFunction());
|
||||
*debugloc_out = wrap(&opt->getDebugLoc());
|
||||
raw_rust_string_ostream message_os(message_out);
|
||||
message_os << opt->getMsg();
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustUnpackInlineAsmDiagnostic(
|
||||
LLVMDiagnosticInfoRef di,
|
||||
unsigned *cookie_out,
|
||||
LLVMTwineRef *message_out,
|
||||
LLVMValueRef *instruction_out)
|
||||
{
|
||||
// Undefined to call this not on an inline assembly diagnostic!
|
||||
llvm::DiagnosticInfoInlineAsm *ia
|
||||
= static_cast<llvm::DiagnosticInfoInlineAsm*>(unwrap(di));
|
||||
extern "C" void LLVMRustUnpackInlineAsmDiagnostic(
|
||||
LLVMDiagnosticInfoRef di, unsigned *cookie_out, LLVMTwineRef *message_out,
|
||||
LLVMValueRef *instruction_out) {
|
||||
// Undefined to call this not on an inline assembly diagnostic!
|
||||
llvm::DiagnosticInfoInlineAsm *ia =
|
||||
static_cast<llvm::DiagnosticInfoInlineAsm *>(unwrap(di));
|
||||
|
||||
*cookie_out = ia->getLocCookie();
|
||||
*message_out = wrap(&ia->getMsgStr());
|
||||
*instruction_out = wrap(ia->getInstruction());
|
||||
*cookie_out = ia->getLocCookie();
|
||||
*message_out = wrap(&ia->getMsgStr());
|
||||
*instruction_out = wrap(ia->getInstruction());
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustWriteDiagnosticInfoToString(LLVMDiagnosticInfoRef di, RustStringRef str) {
|
||||
raw_rust_string_ostream os(str);
|
||||
DiagnosticPrinterRawOStream dp(os);
|
||||
unwrap(di)->print(dp);
|
||||
extern "C" void LLVMRustWriteDiagnosticInfoToString(LLVMDiagnosticInfoRef di,
|
||||
RustStringRef str) {
|
||||
raw_rust_string_ostream os(str);
|
||||
DiagnosticPrinterRawOStream dp(os);
|
||||
unwrap(di)->print(dp);
|
||||
}
|
||||
|
||||
enum class LLVMRustDiagnosticKind {
|
||||
Other,
|
||||
InlineAsm,
|
||||
StackSize,
|
||||
DebugMetadataVersion,
|
||||
SampleProfile,
|
||||
OptimizationRemark,
|
||||
OptimizationRemarkMissed,
|
||||
OptimizationRemarkAnalysis,
|
||||
OptimizationRemarkAnalysisFPCommute,
|
||||
OptimizationRemarkAnalysisAliasing,
|
||||
OptimizationRemarkOther,
|
||||
OptimizationFailure,
|
||||
Other,
|
||||
InlineAsm,
|
||||
StackSize,
|
||||
DebugMetadataVersion,
|
||||
SampleProfile,
|
||||
OptimizationRemark,
|
||||
OptimizationRemarkMissed,
|
||||
OptimizationRemarkAnalysis,
|
||||
OptimizationRemarkAnalysisFPCommute,
|
||||
OptimizationRemarkAnalysisAliasing,
|
||||
OptimizationRemarkOther,
|
||||
OptimizationFailure,
|
||||
};
|
||||
|
||||
static LLVMRustDiagnosticKind
|
||||
to_rust(DiagnosticKind kind)
|
||||
{
|
||||
switch (kind) {
|
||||
case DK_InlineAsm:
|
||||
return LLVMRustDiagnosticKind::InlineAsm;
|
||||
case DK_StackSize:
|
||||
return LLVMRustDiagnosticKind::StackSize;
|
||||
case DK_DebugMetadataVersion:
|
||||
return LLVMRustDiagnosticKind::DebugMetadataVersion;
|
||||
case DK_SampleProfile:
|
||||
return LLVMRustDiagnosticKind::SampleProfile;
|
||||
case DK_OptimizationRemark:
|
||||
return LLVMRustDiagnosticKind::OptimizationRemark;
|
||||
case DK_OptimizationRemarkMissed:
|
||||
return LLVMRustDiagnosticKind::OptimizationRemarkMissed;
|
||||
case DK_OptimizationRemarkAnalysis:
|
||||
return LLVMRustDiagnosticKind::OptimizationRemarkAnalysis;
|
||||
static LLVMRustDiagnosticKind to_rust(DiagnosticKind kind) {
|
||||
switch (kind) {
|
||||
case DK_InlineAsm:
|
||||
return LLVMRustDiagnosticKind::InlineAsm;
|
||||
case DK_StackSize:
|
||||
return LLVMRustDiagnosticKind::StackSize;
|
||||
case DK_DebugMetadataVersion:
|
||||
return LLVMRustDiagnosticKind::DebugMetadataVersion;
|
||||
case DK_SampleProfile:
|
||||
return LLVMRustDiagnosticKind::SampleProfile;
|
||||
case DK_OptimizationRemark:
|
||||
return LLVMRustDiagnosticKind::OptimizationRemark;
|
||||
case DK_OptimizationRemarkMissed:
|
||||
return LLVMRustDiagnosticKind::OptimizationRemarkMissed;
|
||||
case DK_OptimizationRemarkAnalysis:
|
||||
return LLVMRustDiagnosticKind::OptimizationRemarkAnalysis;
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
case DK_OptimizationRemarkAnalysisFPCommute:
|
||||
return LLVMRustDiagnosticKind::OptimizationRemarkAnalysisFPCommute;
|
||||
case DK_OptimizationRemarkAnalysisAliasing:
|
||||
return LLVMRustDiagnosticKind::OptimizationRemarkAnalysisAliasing;
|
||||
case DK_OptimizationRemarkAnalysisFPCommute:
|
||||
return LLVMRustDiagnosticKind::OptimizationRemarkAnalysisFPCommute;
|
||||
case DK_OptimizationRemarkAnalysisAliasing:
|
||||
return LLVMRustDiagnosticKind::OptimizationRemarkAnalysisAliasing;
|
||||
#endif
|
||||
default:
|
||||
default:
|
||||
#if LLVM_VERSION_GE(3, 9)
|
||||
return (kind >= DK_FirstRemark && kind <= DK_LastRemark) ?
|
||||
LLVMRustDiagnosticKind::OptimizationRemarkOther :
|
||||
LLVMRustDiagnosticKind::Other;
|
||||
return (kind >= DK_FirstRemark && kind <= DK_LastRemark)
|
||||
? LLVMRustDiagnosticKind::OptimizationRemarkOther
|
||||
: LLVMRustDiagnosticKind::Other;
|
||||
#else
|
||||
return LLVMRustDiagnosticKind::Other;
|
||||
return LLVMRustDiagnosticKind::Other;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" LLVMRustDiagnosticKind LLVMRustGetDiagInfoKind(LLVMDiagnosticInfoRef di) {
|
||||
return to_rust((DiagnosticKind) unwrap(di)->getKind());
|
||||
extern "C" LLVMRustDiagnosticKind
|
||||
LLVMRustGetDiagInfoKind(LLVMDiagnosticInfoRef di) {
|
||||
return to_rust((DiagnosticKind)unwrap(di)->getKind());
|
||||
}
|
||||
// This is kept distinct from LLVMGetTypeKind, because when
|
||||
// a new type kind is added, the Rust-side enum must be
|
||||
@@ -1147,359 +978,317 @@ extern "C" LLVMTypeKind LLVMRustGetTypeKind(LLVMTypeRef Ty) {
|
||||
llvm_unreachable("Unhandled TypeID.");
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustWriteDebugLocToString(
|
||||
LLVMContextRef C,
|
||||
LLVMDebugLocRef dl,
|
||||
RustStringRef str)
|
||||
{
|
||||
raw_rust_string_ostream os(str);
|
||||
unwrap(dl)->print(os);
|
||||
extern "C" void LLVMRustWriteDebugLocToString(LLVMContextRef C,
|
||||
LLVMDebugLocRef dl,
|
||||
RustStringRef str) {
|
||||
raw_rust_string_ostream os(str);
|
||||
unwrap(dl)->print(os);
|
||||
}
|
||||
|
||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(SMDiagnostic, LLVMSMDiagnosticRef)
|
||||
|
||||
extern "C" void LLVMRustSetInlineAsmDiagnosticHandler(
|
||||
LLVMContextRef C,
|
||||
LLVMContext::InlineAsmDiagHandlerTy H,
|
||||
void *CX)
|
||||
{
|
||||
unwrap(C)->setInlineAsmDiagnosticHandler(H, CX);
|
||||
LLVMContextRef C, LLVMContext::InlineAsmDiagHandlerTy H, void *CX) {
|
||||
unwrap(C)->setInlineAsmDiagnosticHandler(H, CX);
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustWriteSMDiagnosticToString(LLVMSMDiagnosticRef d,
|
||||
RustStringRef str) {
|
||||
raw_rust_string_ostream os(str);
|
||||
unwrap(d)->print("", os);
|
||||
RustStringRef str) {
|
||||
raw_rust_string_ostream os(str);
|
||||
unwrap(d)->print("", os);
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef
|
||||
LLVMRustBuildLandingPad(LLVMBuilderRef Builder,
|
||||
LLVMTypeRef Ty,
|
||||
LLVMValueRef PersFn,
|
||||
unsigned NumClauses,
|
||||
const char* Name,
|
||||
LLVMValueRef F) {
|
||||
return LLVMBuildLandingPad(Builder, Ty, PersFn, NumClauses, Name);
|
||||
LLVMRustBuildLandingPad(LLVMBuilderRef Builder, LLVMTypeRef Ty,
|
||||
LLVMValueRef PersFn, unsigned NumClauses,
|
||||
const char *Name, LLVMValueRef F) {
|
||||
return LLVMBuildLandingPad(Builder, Ty, PersFn, NumClauses, Name);
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef
|
||||
LLVMRustBuildCleanupPad(LLVMBuilderRef Builder,
|
||||
LLVMValueRef ParentPad,
|
||||
unsigned ArgCnt,
|
||||
LLVMValueRef *LLArgs,
|
||||
const char *Name) {
|
||||
extern "C" LLVMValueRef LLVMRustBuildCleanupPad(LLVMBuilderRef Builder,
|
||||
LLVMValueRef ParentPad,
|
||||
unsigned ArgCnt,
|
||||
LLVMValueRef *LLArgs,
|
||||
const char *Name) {
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
Value **Args = unwrap(LLArgs);
|
||||
if (ParentPad == NULL) {
|
||||
Type *Ty = Type::getTokenTy(unwrap(Builder)->getContext());
|
||||
ParentPad = wrap(Constant::getNullValue(Ty));
|
||||
}
|
||||
return wrap(unwrap(Builder)->CreateCleanupPad(unwrap(ParentPad),
|
||||
ArrayRef<Value*>(Args, ArgCnt),
|
||||
Name));
|
||||
Value **Args = unwrap(LLArgs);
|
||||
if (ParentPad == nullptr) {
|
||||
Type *Ty = Type::getTokenTy(unwrap(Builder)->getContext());
|
||||
ParentPad = wrap(Constant::getNullValue(Ty));
|
||||
}
|
||||
return wrap(unwrap(Builder)->CreateCleanupPad(
|
||||
unwrap(ParentPad), ArrayRef<Value *>(Args, ArgCnt), Name));
|
||||
#else
|
||||
return NULL;
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef LLVMRustBuildCleanupRet(LLVMBuilderRef Builder,
|
||||
LLVMValueRef CleanupPad,
|
||||
LLVMBasicBlockRef UnwindBB) {
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
CleanupPadInst *Inst = cast<CleanupPadInst>(unwrap(CleanupPad));
|
||||
return wrap(unwrap(Builder)->CreateCleanupRet(Inst, unwrap(UnwindBB)));
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef
|
||||
LLVMRustBuildCleanupRet(LLVMBuilderRef Builder,
|
||||
LLVMValueRef CleanupPad,
|
||||
LLVMBasicBlockRef UnwindBB) {
|
||||
LLVMRustBuildCatchPad(LLVMBuilderRef Builder, LLVMValueRef ParentPad,
|
||||
unsigned ArgCnt, LLVMValueRef *LLArgs, const char *Name) {
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
CleanupPadInst *Inst = cast<CleanupPadInst>(unwrap(CleanupPad));
|
||||
return wrap(unwrap(Builder)->CreateCleanupRet(Inst, unwrap(UnwindBB)));
|
||||
Value **Args = unwrap(LLArgs);
|
||||
return wrap(unwrap(Builder)->CreateCatchPad(
|
||||
unwrap(ParentPad), ArrayRef<Value *>(Args, ArgCnt), Name));
|
||||
#else
|
||||
return NULL;
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef
|
||||
LLVMRustBuildCatchPad(LLVMBuilderRef Builder,
|
||||
LLVMValueRef ParentPad,
|
||||
unsigned ArgCnt,
|
||||
LLVMValueRef *LLArgs,
|
||||
const char *Name) {
|
||||
extern "C" LLVMValueRef LLVMRustBuildCatchRet(LLVMBuilderRef Builder,
|
||||
LLVMValueRef Pad,
|
||||
LLVMBasicBlockRef BB) {
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
Value **Args = unwrap(LLArgs);
|
||||
return wrap(unwrap(Builder)->CreateCatchPad(unwrap(ParentPad),
|
||||
ArrayRef<Value*>(Args, ArgCnt),
|
||||
Name));
|
||||
return wrap(unwrap(Builder)->CreateCatchRet(cast<CatchPadInst>(unwrap(Pad)),
|
||||
unwrap(BB)));
|
||||
#else
|
||||
return NULL;
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef
|
||||
LLVMRustBuildCatchRet(LLVMBuilderRef Builder,
|
||||
LLVMValueRef Pad,
|
||||
LLVMBasicBlockRef BB) {
|
||||
extern "C" LLVMValueRef LLVMRustBuildCatchSwitch(LLVMBuilderRef Builder,
|
||||
LLVMValueRef ParentPad,
|
||||
LLVMBasicBlockRef BB,
|
||||
unsigned NumHandlers,
|
||||
const char *Name) {
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
return wrap(unwrap(Builder)->CreateCatchRet(cast<CatchPadInst>(unwrap(Pad)),
|
||||
unwrap(BB)));
|
||||
if (ParentPad == nullptr) {
|
||||
Type *Ty = Type::getTokenTy(unwrap(Builder)->getContext());
|
||||
ParentPad = wrap(Constant::getNullValue(Ty));
|
||||
}
|
||||
return wrap(unwrap(Builder)->CreateCatchSwitch(unwrap(ParentPad), unwrap(BB),
|
||||
NumHandlers, Name));
|
||||
#else
|
||||
return NULL;
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef
|
||||
LLVMRustBuildCatchSwitch(LLVMBuilderRef Builder,
|
||||
LLVMValueRef ParentPad,
|
||||
LLVMBasicBlockRef BB,
|
||||
unsigned NumHandlers,
|
||||
const char *Name) {
|
||||
extern "C" void LLVMRustAddHandler(LLVMValueRef CatchSwitchRef,
|
||||
LLVMBasicBlockRef Handler) {
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
if (ParentPad == NULL) {
|
||||
Type *Ty = Type::getTokenTy(unwrap(Builder)->getContext());
|
||||
ParentPad = wrap(Constant::getNullValue(Ty));
|
||||
}
|
||||
return wrap(unwrap(Builder)->CreateCatchSwitch(unwrap(ParentPad),
|
||||
unwrap(BB),
|
||||
NumHandlers,
|
||||
Name));
|
||||
#else
|
||||
return NULL;
|
||||
Value *CatchSwitch = unwrap(CatchSwitchRef);
|
||||
cast<CatchSwitchInst>(CatchSwitch)->addHandler(unwrap(Handler));
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustAddHandler(LLVMValueRef CatchSwitchRef,
|
||||
LLVMBasicBlockRef Handler) {
|
||||
extern "C" void LLVMRustSetPersonalityFn(LLVMBuilderRef B,
|
||||
LLVMValueRef Personality) {
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
Value *CatchSwitch = unwrap(CatchSwitchRef);
|
||||
cast<CatchSwitchInst>(CatchSwitch)->addHandler(unwrap(Handler));
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustSetPersonalityFn(LLVMBuilderRef B,
|
||||
LLVMValueRef Personality) {
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
unwrap(B)->GetInsertBlock()
|
||||
->getParent()
|
||||
->setPersonalityFn(cast<Function>(unwrap(Personality)));
|
||||
unwrap(B)->GetInsertBlock()->getParent()->setPersonalityFn(
|
||||
cast<Function>(unwrap(Personality)));
|
||||
#endif
|
||||
}
|
||||
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
extern "C" OperandBundleDef*
|
||||
LLVMRustBuildOperandBundleDef(const char *Name,
|
||||
LLVMValueRef *Inputs,
|
||||
unsigned NumInputs) {
|
||||
extern "C" OperandBundleDef *LLVMRustBuildOperandBundleDef(const char *Name,
|
||||
LLVMValueRef *Inputs,
|
||||
unsigned NumInputs) {
|
||||
return new OperandBundleDef(Name, makeArrayRef(unwrap(Inputs), NumInputs));
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustFreeOperandBundleDef(OperandBundleDef* Bundle) {
|
||||
extern "C" void LLVMRustFreeOperandBundleDef(OperandBundleDef *Bundle) {
|
||||
delete Bundle;
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef
|
||||
LLVMRustBuildCall(LLVMBuilderRef B,
|
||||
LLVMValueRef Fn,
|
||||
LLVMValueRef *Args,
|
||||
unsigned NumArgs,
|
||||
OperandBundleDef *Bundle,
|
||||
const char *Name) {
|
||||
unsigned len = Bundle ? 1 : 0;
|
||||
ArrayRef<OperandBundleDef> Bundles = makeArrayRef(Bundle, len);
|
||||
return wrap(unwrap(B)->CreateCall(unwrap(Fn),
|
||||
makeArrayRef(unwrap(Args), NumArgs),
|
||||
Bundles,
|
||||
Name));
|
||||
extern "C" LLVMValueRef LLVMRustBuildCall(LLVMBuilderRef B, LLVMValueRef Fn,
|
||||
LLVMValueRef *Args, unsigned NumArgs,
|
||||
OperandBundleDef *Bundle,
|
||||
const char *Name) {
|
||||
unsigned len = Bundle ? 1 : 0;
|
||||
ArrayRef<OperandBundleDef> Bundles = makeArrayRef(Bundle, len);
|
||||
return wrap(unwrap(B)->CreateCall(
|
||||
unwrap(Fn), makeArrayRef(unwrap(Args), NumArgs), Bundles, Name));
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef
|
||||
LLVMRustBuildInvoke(LLVMBuilderRef B,
|
||||
LLVMValueRef Fn,
|
||||
LLVMValueRef *Args,
|
||||
unsigned NumArgs,
|
||||
LLVMBasicBlockRef Then,
|
||||
LLVMBasicBlockRef Catch,
|
||||
OperandBundleDef *Bundle,
|
||||
LLVMRustBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args,
|
||||
unsigned NumArgs, LLVMBasicBlockRef Then,
|
||||
LLVMBasicBlockRef Catch, OperandBundleDef *Bundle,
|
||||
const char *Name) {
|
||||
unsigned len = Bundle ? 1 : 0;
|
||||
ArrayRef<OperandBundleDef> Bundles = makeArrayRef(Bundle, len);
|
||||
return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch),
|
||||
makeArrayRef(unwrap(Args), NumArgs),
|
||||
Bundles,
|
||||
Name));
|
||||
unsigned len = Bundle ? 1 : 0;
|
||||
ArrayRef<OperandBundleDef> Bundles = makeArrayRef(Bundle, len);
|
||||
return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch),
|
||||
makeArrayRef(unwrap(Args), NumArgs),
|
||||
Bundles, Name));
|
||||
}
|
||||
#else
|
||||
extern "C" void*
|
||||
LLVMRustBuildOperandBundleDef(const char *Name,
|
||||
LLVMValueRef *Inputs,
|
||||
unsigned NumInputs) {
|
||||
return NULL;
|
||||
extern "C" void *LLVMRustBuildOperandBundleDef(const char *Name,
|
||||
LLVMValueRef *Inputs,
|
||||
unsigned NumInputs) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustFreeOperandBundleDef(void* Bundle) {
|
||||
extern "C" void LLVMRustFreeOperandBundleDef(void *Bundle) {}
|
||||
|
||||
extern "C" LLVMValueRef LLVMRustBuildCall(LLVMBuilderRef B, LLVMValueRef Fn,
|
||||
LLVMValueRef *Args, unsigned NumArgs,
|
||||
void *Bundle, const char *Name) {
|
||||
return LLVMBuildCall(B, Fn, Args, NumArgs, Name);
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef
|
||||
LLVMRustBuildCall(LLVMBuilderRef B,
|
||||
LLVMValueRef Fn,
|
||||
LLVMValueRef *Args,
|
||||
unsigned NumArgs,
|
||||
void *Bundle,
|
||||
const char *Name) {
|
||||
return LLVMBuildCall(B, Fn, Args, NumArgs, Name);
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef
|
||||
LLVMRustBuildInvoke(LLVMBuilderRef B,
|
||||
LLVMValueRef Fn,
|
||||
LLVMValueRef *Args,
|
||||
unsigned NumArgs,
|
||||
LLVMBasicBlockRef Then,
|
||||
LLVMBasicBlockRef Catch,
|
||||
void *Bundle,
|
||||
const char *Name) {
|
||||
return LLVMBuildInvoke(B, Fn, Args, NumArgs, Then, Catch, Name);
|
||||
LLVMRustBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args,
|
||||
unsigned NumArgs, LLVMBasicBlockRef Then,
|
||||
LLVMBasicBlockRef Catch, void *Bundle, const char *Name) {
|
||||
return LLVMBuildInvoke(B, Fn, Args, NumArgs, Then, Catch, Name);
|
||||
}
|
||||
#endif
|
||||
|
||||
extern "C" void LLVMRustPositionBuilderAtStart(LLVMBuilderRef B, LLVMBasicBlockRef BB) {
|
||||
auto point = unwrap(BB)->getFirstInsertionPt();
|
||||
unwrap(B)->SetInsertPoint(unwrap(BB), point);
|
||||
extern "C" void LLVMRustPositionBuilderAtStart(LLVMBuilderRef B,
|
||||
LLVMBasicBlockRef BB) {
|
||||
auto point = unwrap(BB)->getFirstInsertionPt();
|
||||
unwrap(B)->SetInsertPoint(unwrap(BB), point);
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustSetComdat(LLVMModuleRef M, LLVMValueRef V, const char *Name) {
|
||||
Triple TargetTriple(unwrap(M)->getTargetTriple());
|
||||
GlobalObject *GV = unwrap<GlobalObject>(V);
|
||||
if (!TargetTriple.isOSBinFormatMachO()) {
|
||||
GV->setComdat(unwrap(M)->getOrInsertComdat(Name));
|
||||
}
|
||||
extern "C" void LLVMRustSetComdat(LLVMModuleRef M, LLVMValueRef V,
|
||||
const char *Name) {
|
||||
Triple TargetTriple(unwrap(M)->getTargetTriple());
|
||||
GlobalObject *GV = unwrap<GlobalObject>(V);
|
||||
if (!TargetTriple.isOSBinFormatMachO()) {
|
||||
GV->setComdat(unwrap(M)->getOrInsertComdat(Name));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustUnsetComdat(LLVMValueRef V) {
|
||||
GlobalObject *GV = unwrap<GlobalObject>(V);
|
||||
GV->setComdat(nullptr);
|
||||
GlobalObject *GV = unwrap<GlobalObject>(V);
|
||||
GV->setComdat(nullptr);
|
||||
}
|
||||
|
||||
enum class LLVMRustLinkage {
|
||||
ExternalLinkage = 0,
|
||||
AvailableExternallyLinkage = 1,
|
||||
LinkOnceAnyLinkage = 2,
|
||||
LinkOnceODRLinkage = 3,
|
||||
WeakAnyLinkage = 4,
|
||||
WeakODRLinkage = 5,
|
||||
AppendingLinkage = 6,
|
||||
InternalLinkage = 7,
|
||||
PrivateLinkage = 8,
|
||||
ExternalWeakLinkage = 9,
|
||||
CommonLinkage = 10,
|
||||
ExternalLinkage = 0,
|
||||
AvailableExternallyLinkage = 1,
|
||||
LinkOnceAnyLinkage = 2,
|
||||
LinkOnceODRLinkage = 3,
|
||||
WeakAnyLinkage = 4,
|
||||
WeakODRLinkage = 5,
|
||||
AppendingLinkage = 6,
|
||||
InternalLinkage = 7,
|
||||
PrivateLinkage = 8,
|
||||
ExternalWeakLinkage = 9,
|
||||
CommonLinkage = 10,
|
||||
};
|
||||
|
||||
static LLVMRustLinkage to_rust(LLVMLinkage linkage) {
|
||||
switch (linkage) {
|
||||
case LLVMExternalLinkage:
|
||||
return LLVMRustLinkage::ExternalLinkage;
|
||||
case LLVMAvailableExternallyLinkage:
|
||||
return LLVMRustLinkage::AvailableExternallyLinkage;
|
||||
case LLVMLinkOnceAnyLinkage:
|
||||
return LLVMRustLinkage::LinkOnceAnyLinkage;
|
||||
case LLVMLinkOnceODRLinkage:
|
||||
return LLVMRustLinkage::LinkOnceODRLinkage;
|
||||
case LLVMWeakAnyLinkage:
|
||||
return LLVMRustLinkage::WeakAnyLinkage;
|
||||
case LLVMWeakODRLinkage:
|
||||
return LLVMRustLinkage::WeakODRLinkage;
|
||||
case LLVMAppendingLinkage:
|
||||
return LLVMRustLinkage::AppendingLinkage;
|
||||
case LLVMInternalLinkage:
|
||||
return LLVMRustLinkage::InternalLinkage;
|
||||
case LLVMPrivateLinkage:
|
||||
return LLVMRustLinkage::PrivateLinkage;
|
||||
case LLVMExternalWeakLinkage:
|
||||
return LLVMRustLinkage::ExternalWeakLinkage;
|
||||
case LLVMCommonLinkage:
|
||||
return LLVMRustLinkage::CommonLinkage;
|
||||
default:
|
||||
llvm_unreachable("Invalid LLVMRustLinkage value!");
|
||||
}
|
||||
switch (linkage) {
|
||||
case LLVMExternalLinkage:
|
||||
return LLVMRustLinkage::ExternalLinkage;
|
||||
case LLVMAvailableExternallyLinkage:
|
||||
return LLVMRustLinkage::AvailableExternallyLinkage;
|
||||
case LLVMLinkOnceAnyLinkage:
|
||||
return LLVMRustLinkage::LinkOnceAnyLinkage;
|
||||
case LLVMLinkOnceODRLinkage:
|
||||
return LLVMRustLinkage::LinkOnceODRLinkage;
|
||||
case LLVMWeakAnyLinkage:
|
||||
return LLVMRustLinkage::WeakAnyLinkage;
|
||||
case LLVMWeakODRLinkage:
|
||||
return LLVMRustLinkage::WeakODRLinkage;
|
||||
case LLVMAppendingLinkage:
|
||||
return LLVMRustLinkage::AppendingLinkage;
|
||||
case LLVMInternalLinkage:
|
||||
return LLVMRustLinkage::InternalLinkage;
|
||||
case LLVMPrivateLinkage:
|
||||
return LLVMRustLinkage::PrivateLinkage;
|
||||
case LLVMExternalWeakLinkage:
|
||||
return LLVMRustLinkage::ExternalWeakLinkage;
|
||||
case LLVMCommonLinkage:
|
||||
return LLVMRustLinkage::CommonLinkage;
|
||||
default:
|
||||
llvm_unreachable("Invalid LLVMRustLinkage value!");
|
||||
}
|
||||
}
|
||||
|
||||
static LLVMLinkage from_rust(LLVMRustLinkage linkage) {
|
||||
switch (linkage) {
|
||||
case LLVMRustLinkage::ExternalLinkage:
|
||||
return LLVMExternalLinkage;
|
||||
case LLVMRustLinkage::AvailableExternallyLinkage:
|
||||
return LLVMAvailableExternallyLinkage;
|
||||
case LLVMRustLinkage::LinkOnceAnyLinkage:
|
||||
return LLVMLinkOnceAnyLinkage;
|
||||
case LLVMRustLinkage::LinkOnceODRLinkage:
|
||||
return LLVMLinkOnceODRLinkage;
|
||||
case LLVMRustLinkage::WeakAnyLinkage:
|
||||
return LLVMWeakAnyLinkage;
|
||||
case LLVMRustLinkage::WeakODRLinkage:
|
||||
return LLVMWeakODRLinkage;
|
||||
case LLVMRustLinkage::AppendingLinkage:
|
||||
return LLVMAppendingLinkage;
|
||||
case LLVMRustLinkage::InternalLinkage:
|
||||
return LLVMInternalLinkage;
|
||||
case LLVMRustLinkage::PrivateLinkage:
|
||||
return LLVMPrivateLinkage;
|
||||
case LLVMRustLinkage::ExternalWeakLinkage:
|
||||
return LLVMExternalWeakLinkage;
|
||||
case LLVMRustLinkage::CommonLinkage:
|
||||
return LLVMCommonLinkage;
|
||||
default:
|
||||
llvm_unreachable("Invalid LLVMRustLinkage value!");
|
||||
}
|
||||
switch (linkage) {
|
||||
case LLVMRustLinkage::ExternalLinkage:
|
||||
return LLVMExternalLinkage;
|
||||
case LLVMRustLinkage::AvailableExternallyLinkage:
|
||||
return LLVMAvailableExternallyLinkage;
|
||||
case LLVMRustLinkage::LinkOnceAnyLinkage:
|
||||
return LLVMLinkOnceAnyLinkage;
|
||||
case LLVMRustLinkage::LinkOnceODRLinkage:
|
||||
return LLVMLinkOnceODRLinkage;
|
||||
case LLVMRustLinkage::WeakAnyLinkage:
|
||||
return LLVMWeakAnyLinkage;
|
||||
case LLVMRustLinkage::WeakODRLinkage:
|
||||
return LLVMWeakODRLinkage;
|
||||
case LLVMRustLinkage::AppendingLinkage:
|
||||
return LLVMAppendingLinkage;
|
||||
case LLVMRustLinkage::InternalLinkage:
|
||||
return LLVMInternalLinkage;
|
||||
case LLVMRustLinkage::PrivateLinkage:
|
||||
return LLVMPrivateLinkage;
|
||||
case LLVMRustLinkage::ExternalWeakLinkage:
|
||||
return LLVMExternalWeakLinkage;
|
||||
case LLVMRustLinkage::CommonLinkage:
|
||||
return LLVMCommonLinkage;
|
||||
default:
|
||||
llvm_unreachable("Invalid LLVMRustLinkage value!");
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" LLVMRustLinkage LLVMRustGetLinkage(LLVMValueRef V) {
|
||||
return to_rust(LLVMGetLinkage(V));
|
||||
return to_rust(LLVMGetLinkage(V));
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustSetLinkage(LLVMValueRef V, LLVMRustLinkage RustLinkage) {
|
||||
LLVMSetLinkage(V, from_rust(RustLinkage));
|
||||
extern "C" void LLVMRustSetLinkage(LLVMValueRef V,
|
||||
LLVMRustLinkage RustLinkage) {
|
||||
LLVMSetLinkage(V, from_rust(RustLinkage));
|
||||
}
|
||||
|
||||
extern "C" LLVMContextRef LLVMRustGetValueContext(LLVMValueRef V) {
|
||||
return wrap(&unwrap(V)->getContext());
|
||||
return wrap(&unwrap(V)->getContext());
|
||||
}
|
||||
|
||||
enum class LLVMRustVisibility {
|
||||
Default = 0,
|
||||
Hidden = 1,
|
||||
Protected = 2,
|
||||
Default = 0,
|
||||
Hidden = 1,
|
||||
Protected = 2,
|
||||
};
|
||||
|
||||
static LLVMRustVisibility to_rust(LLVMVisibility vis) {
|
||||
switch (vis) {
|
||||
case LLVMDefaultVisibility:
|
||||
return LLVMRustVisibility::Default;
|
||||
case LLVMHiddenVisibility:
|
||||
return LLVMRustVisibility::Hidden;
|
||||
case LLVMProtectedVisibility:
|
||||
return LLVMRustVisibility::Protected;
|
||||
switch (vis) {
|
||||
case LLVMDefaultVisibility:
|
||||
return LLVMRustVisibility::Default;
|
||||
case LLVMHiddenVisibility:
|
||||
return LLVMRustVisibility::Hidden;
|
||||
case LLVMProtectedVisibility:
|
||||
return LLVMRustVisibility::Protected;
|
||||
|
||||
default:
|
||||
llvm_unreachable("Invalid LLVMRustVisibility value!");
|
||||
}
|
||||
default:
|
||||
llvm_unreachable("Invalid LLVMRustVisibility value!");
|
||||
}
|
||||
}
|
||||
|
||||
static LLVMVisibility from_rust(LLVMRustVisibility vis) {
|
||||
switch (vis) {
|
||||
case LLVMRustVisibility::Default:
|
||||
return LLVMDefaultVisibility;
|
||||
case LLVMRustVisibility::Hidden:
|
||||
return LLVMHiddenVisibility;
|
||||
case LLVMRustVisibility::Protected:
|
||||
return LLVMProtectedVisibility;
|
||||
switch (vis) {
|
||||
case LLVMRustVisibility::Default:
|
||||
return LLVMDefaultVisibility;
|
||||
case LLVMRustVisibility::Hidden:
|
||||
return LLVMHiddenVisibility;
|
||||
case LLVMRustVisibility::Protected:
|
||||
return LLVMProtectedVisibility;
|
||||
|
||||
default:
|
||||
llvm_unreachable("Invalid LLVMRustVisibility value!");
|
||||
}
|
||||
default:
|
||||
llvm_unreachable("Invalid LLVMRustVisibility value!");
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" LLVMRustVisibility LLVMRustGetVisibility(LLVMValueRef V) {
|
||||
return to_rust(LLVMGetVisibility(V));
|
||||
return to_rust(LLVMGetVisibility(V));
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustSetVisibility(LLVMValueRef V, LLVMRustVisibility RustVisibility) {
|
||||
LLVMSetVisibility(V, from_rust(RustVisibility));
|
||||
extern "C" void LLVMRustSetVisibility(LLVMValueRef V,
|
||||
LLVMRustVisibility RustVisibility) {
|
||||
LLVMSetVisibility(V, from_rust(RustVisibility));
|
||||
}
|
||||
|
||||
+78
-82
@@ -8,50 +8,52 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#include "llvm/IR/IRBuilder.h"
|
||||
#include "llvm/IR/InlineAsm.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/IR/InlineAsm.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/Analysis/Passes.h"
|
||||
#include "llvm/Analysis/Lint.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include "llvm/ADT/DenseSet.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/FormattedStream.h"
|
||||
#include "llvm/Support/Timer.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
#include "llvm/Support/TargetRegistry.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/DynamicLibrary.h"
|
||||
#include "llvm/Support/Memory.h"
|
||||
#include "llvm/ExecutionEngine/ExecutionEngine.h"
|
||||
#include "llvm/ExecutionEngine/MCJIT.h"
|
||||
#include "llvm/ExecutionEngine/Interpreter.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Target/TargetOptions.h"
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
#include "llvm/Transforms/IPO.h"
|
||||
#include "llvm/Transforms/Instrumentation.h"
|
||||
#include "llvm/Transforms/Vectorize.h"
|
||||
#include "llvm-c/Core.h"
|
||||
#include "llvm-c/BitReader.h"
|
||||
#include "llvm-c/Core.h"
|
||||
#include "llvm-c/ExecutionEngine.h"
|
||||
#include "llvm-c/Object.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/DenseSet.h"
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include "llvm/Analysis/Lint.h"
|
||||
#include "llvm/Analysis/Passes.h"
|
||||
#include "llvm/ExecutionEngine/ExecutionEngine.h"
|
||||
#include "llvm/ExecutionEngine/Interpreter.h"
|
||||
#include "llvm/ExecutionEngine/MCJIT.h"
|
||||
#include "llvm/IR/IRBuilder.h"
|
||||
#include "llvm/IR/InlineAsm.h"
|
||||
#include "llvm/IR/InlineAsm.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/DynamicLibrary.h"
|
||||
#include "llvm/Support/FormattedStream.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
#include "llvm/Support/Memory.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "llvm/Support/TargetRegistry.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
#include "llvm/Support/Timer.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Target/TargetOptions.h"
|
||||
#include "llvm/Transforms/IPO.h"
|
||||
#include "llvm/Transforms/Instrumentation.h"
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
#include "llvm/Transforms/Vectorize.h"
|
||||
|
||||
#define LLVM_VERSION_GE(major, minor) \
|
||||
(LLVM_VERSION_MAJOR > (major) || LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR >= (minor))
|
||||
#define LLVM_VERSION_GE(major, minor) \
|
||||
(LLVM_VERSION_MAJOR > (major) || \
|
||||
LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR >= (minor))
|
||||
|
||||
#define LLVM_VERSION_EQ(major, minor) \
|
||||
#define LLVM_VERSION_EQ(major, minor) \
|
||||
(LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR == (minor))
|
||||
|
||||
#define LLVM_VERSION_LE(major, minor) \
|
||||
(LLVM_VERSION_MAJOR < (major) || LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))
|
||||
#define LLVM_VERSION_LE(major, minor) \
|
||||
(LLVM_VERSION_MAJOR < (major) || \
|
||||
LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))
|
||||
|
||||
#if LLVM_VERSION_GE(3, 7)
|
||||
#include "llvm/IR/LegacyPassManager.h"
|
||||
@@ -66,39 +68,36 @@
|
||||
#include "llvm/Bitcode/ReaderWriter.h"
|
||||
#endif
|
||||
|
||||
#include "llvm/IR/IRPrintingPasses.h"
|
||||
#include "llvm/IR/DebugInfo.h"
|
||||
#include "llvm/IR/DIBuilder.h"
|
||||
#include "llvm/IR/DebugInfo.h"
|
||||
#include "llvm/IR/IRPrintingPasses.h"
|
||||
#include "llvm/Linker/Linker.h"
|
||||
|
||||
void LLVMRustSetLastError(const char*);
|
||||
void LLVMRustSetLastError(const char *);
|
||||
|
||||
enum class LLVMRustResult {
|
||||
Success,
|
||||
Failure
|
||||
};
|
||||
enum class LLVMRustResult { Success, Failure };
|
||||
|
||||
enum LLVMRustAttribute {
|
||||
AlwaysInline = 0,
|
||||
ByVal = 1,
|
||||
Cold = 2,
|
||||
InlineHint = 3,
|
||||
MinSize = 4,
|
||||
Naked = 5,
|
||||
NoAlias = 6,
|
||||
NoCapture = 7,
|
||||
NoInline = 8,
|
||||
NonNull = 9,
|
||||
NoRedZone = 10,
|
||||
NoReturn = 11,
|
||||
NoUnwind = 12,
|
||||
OptimizeForSize = 13,
|
||||
ReadOnly = 14,
|
||||
SExt = 15,
|
||||
StructRet = 16,
|
||||
UWTable = 17,
|
||||
ZExt = 18,
|
||||
InReg = 19,
|
||||
AlwaysInline = 0,
|
||||
ByVal = 1,
|
||||
Cold = 2,
|
||||
InlineHint = 3,
|
||||
MinSize = 4,
|
||||
Naked = 5,
|
||||
NoAlias = 6,
|
||||
NoCapture = 7,
|
||||
NoInline = 8,
|
||||
NonNull = 9,
|
||||
NoRedZone = 10,
|
||||
NoReturn = 11,
|
||||
NoUnwind = 12,
|
||||
OptimizeForSize = 13,
|
||||
ReadOnly = 14,
|
||||
SExt = 15,
|
||||
StructRet = 16,
|
||||
UWTable = 17,
|
||||
ZExt = 18,
|
||||
InReg = 19,
|
||||
};
|
||||
|
||||
typedef struct OpaqueRustString *RustStringRef;
|
||||
@@ -107,28 +106,25 @@ typedef struct LLVMOpaqueDebugLoc *LLVMDebugLocRef;
|
||||
typedef struct LLVMOpaqueSMDiagnostic *LLVMSMDiagnosticRef;
|
||||
typedef struct LLVMOpaqueRustJITMemoryManager *LLVMRustJITMemoryManagerRef;
|
||||
|
||||
extern "C" void
|
||||
rust_llvm_string_write_impl(RustStringRef str, const char *ptr, size_t size);
|
||||
extern "C" void rust_llvm_string_write_impl(RustStringRef str, const char *ptr,
|
||||
size_t size);
|
||||
|
||||
class raw_rust_string_ostream : public llvm::raw_ostream {
|
||||
RustStringRef str;
|
||||
uint64_t pos;
|
||||
class raw_rust_string_ostream : public llvm::raw_ostream {
|
||||
RustStringRef str;
|
||||
uint64_t pos;
|
||||
|
||||
void write_impl(const char *ptr, size_t size) override {
|
||||
rust_llvm_string_write_impl(str, ptr, size);
|
||||
pos += size;
|
||||
}
|
||||
void write_impl(const char *ptr, size_t size) override {
|
||||
rust_llvm_string_write_impl(str, ptr, size);
|
||||
pos += size;
|
||||
}
|
||||
|
||||
uint64_t current_pos() const override {
|
||||
return pos;
|
||||
}
|
||||
uint64_t current_pos() const override { return pos; }
|
||||
|
||||
public:
|
||||
explicit raw_rust_string_ostream(RustStringRef str)
|
||||
: str(str), pos(0) { }
|
||||
explicit raw_rust_string_ostream(RustStringRef str) : str(str), pos(0) {}
|
||||
|
||||
~raw_rust_string_ostream() {
|
||||
// LLVM requires this.
|
||||
flush();
|
||||
}
|
||||
~raw_rust_string_ostream() {
|
||||
// LLVM requires this.
|
||||
flush();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user