Ran clang-format on src/rustllvm with llvm as the coding style.
This commit is contained in:
parent
7f2d2afa91
commit
c72d859e4f
4 changed files with 1324 additions and 1590 deletions
|
@ -21,17 +21,18 @@ struct RustArchiveMember {
|
||||||
const char *name;
|
const char *name;
|
||||||
Archive::Child child;
|
Archive::Child child;
|
||||||
|
|
||||||
RustArchiveMember(): filename(NULL), name(NULL),
|
RustArchiveMember()
|
||||||
|
: filename(NULL), name(NULL),
|
||||||
#if LLVM_VERSION_GE(3, 8)
|
#if LLVM_VERSION_GE(3, 8)
|
||||||
child(NULL, NULL, NULL)
|
child(NULL, NULL, NULL)
|
||||||
#else
|
#else
|
||||||
child(NULL, NULL)
|
child(NULL, NULL)
|
||||||
#endif
|
#endif
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
~RustArchiveMember() {}
|
~RustArchiveMember() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct RustArchiveIterator {
|
struct RustArchiveIterator {
|
||||||
bool first;
|
bool first;
|
||||||
Archive::child_iterator cur;
|
Archive::child_iterator cur;
|
||||||
|
@ -39,9 +40,9 @@ struct RustArchiveIterator {
|
||||||
#if LLVM_VERSION_GE(3, 9)
|
#if LLVM_VERSION_GE(3, 9)
|
||||||
Error err;
|
Error err;
|
||||||
|
|
||||||
RustArchiveIterator() : first(true), err(Error::success()) { }
|
RustArchiveIterator() : first(true), err(Error::success()) {}
|
||||||
#else
|
#else
|
||||||
RustArchiveIterator() : first(true) { }
|
RustArchiveIterator() : first(true) {}
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -53,9 +54,7 @@ enum class LLVMRustArchiveKind {
|
||||||
COFF,
|
COFF,
|
||||||
};
|
};
|
||||||
|
|
||||||
static Archive::Kind
|
static Archive::Kind from_rust(LLVMRustArchiveKind kind) {
|
||||||
from_rust(LLVMRustArchiveKind kind)
|
|
||||||
{
|
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case LLVMRustArchiveKind::GNU:
|
case LLVMRustArchiveKind::GNU:
|
||||||
return Archive::K_GNU;
|
return Archive::K_GNU;
|
||||||
|
@ -76,11 +75,9 @@ typedef Archive::Child *LLVMRustArchiveChildRef;
|
||||||
typedef Archive::Child const *LLVMRustArchiveChildConstRef;
|
typedef Archive::Child const *LLVMRustArchiveChildConstRef;
|
||||||
typedef RustArchiveIterator *LLVMRustArchiveIteratorRef;
|
typedef RustArchiveIterator *LLVMRustArchiveIteratorRef;
|
||||||
|
|
||||||
extern "C" LLVMRustArchiveRef
|
extern "C" LLVMRustArchiveRef LLVMRustOpenArchive(char *path) {
|
||||||
LLVMRustOpenArchive(char *path) {
|
ErrorOr<std::unique_ptr<MemoryBuffer>> buf_or =
|
||||||
ErrorOr<std::unique_ptr<MemoryBuffer>> buf_or = MemoryBuffer::getFile(path,
|
MemoryBuffer::getFile(path, -1, false);
|
||||||
-1,
|
|
||||||
false);
|
|
||||||
if (!buf_or) {
|
if (!buf_or) {
|
||||||
LLVMRustSetLastError(buf_or.getError().message().c_str());
|
LLVMRustSetLastError(buf_or.getError().message().c_str());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -108,10 +105,7 @@ LLVMRustOpenArchive(char *path) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMRustDestroyArchive(LLVMRustArchiveRef ar) { delete ar; }
|
||||||
LLVMRustDestroyArchive(LLVMRustArchiveRef ar) {
|
|
||||||
delete ar;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" LLVMRustArchiveIteratorRef
|
extern "C" LLVMRustArchiveIteratorRef
|
||||||
LLVMRustArchiveIteratorNew(LLVMRustArchiveRef ra) {
|
LLVMRustArchiveIteratorNew(LLVMRustArchiveRef ra) {
|
||||||
|
@ -133,7 +127,8 @@ LLVMRustArchiveIteratorNew(LLVMRustArchiveRef ra) {
|
||||||
|
|
||||||
extern "C" LLVMRustArchiveChildConstRef
|
extern "C" LLVMRustArchiveChildConstRef
|
||||||
LLVMRustArchiveIteratorNext(LLVMRustArchiveIteratorRef rai) {
|
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
|
// Advancing the iterator validates the next child, and this can
|
||||||
// uncover an error. LLVM requires that we check all Errors,
|
// uncover an error. LLVM requires that we check all Errors,
|
||||||
|
@ -153,10 +148,11 @@ LLVMRustArchiveIteratorNext(LLVMRustArchiveIteratorRef rai) {
|
||||||
rai->first = false;
|
rai->first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rai->cur == rai->end) return nullptr;
|
if (rai->cur == rai->end)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
#if LLVM_VERSION_EQ(3, 8)
|
#if LLVM_VERSION_EQ(3, 8)
|
||||||
const ErrorOr<Archive::Child>* cur = rai->cur.operator->();
|
const ErrorOr<Archive::Child> *cur = rai->cur.operator->();
|
||||||
if (!*cur) {
|
if (!*cur) {
|
||||||
LLVMRustSetLastError(cur->getError().message().c_str());
|
LLVMRustSetLastError(cur->getError().message().c_str());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -170,17 +166,15 @@ LLVMRustArchiveIteratorNext(LLVMRustArchiveIteratorRef rai) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMRustArchiveChildFree(LLVMRustArchiveChildRef child) {
|
||||||
LLVMRustArchiveChildFree(LLVMRustArchiveChildRef child) {
|
|
||||||
delete child;
|
delete child;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMRustArchiveIteratorFree(LLVMRustArchiveIteratorRef rai) {
|
||||||
LLVMRustArchiveIteratorFree(LLVMRustArchiveIteratorRef rai) {
|
|
||||||
delete rai;
|
delete rai;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" const char*
|
extern "C" const char *
|
||||||
LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef child, size_t *size) {
|
LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef child, size_t *size) {
|
||||||
#if LLVM_VERSION_GE(4, 0)
|
#if LLVM_VERSION_GE(4, 0)
|
||||||
Expected<StringRef> name_or_err = child->getName();
|
Expected<StringRef> name_or_err = child->getName();
|
||||||
|
@ -201,8 +195,8 @@ LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef child, size_t *size) {
|
||||||
return name.data();
|
return name.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" const char*
|
extern "C" const char *LLVMRustArchiveChildData(LLVMRustArchiveChildRef child,
|
||||||
LLVMRustArchiveChildData(LLVMRustArchiveChildRef child, size_t *size) {
|
size_t *size) {
|
||||||
StringRef buf;
|
StringRef buf;
|
||||||
#if LLVM_VERSION_GE(4, 0)
|
#if LLVM_VERSION_GE(4, 0)
|
||||||
Expected<StringRef> buf_or_err = child->getBuffer();
|
Expected<StringRef> buf_or_err = child->getBuffer();
|
||||||
|
@ -233,17 +227,14 @@ LLVMRustArchiveMemberNew(char *Filename, char *Name,
|
||||||
return Member;
|
return Member;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMRustArchiveMemberFree(LLVMRustArchiveMemberRef Member) {
|
||||||
LLVMRustArchiveMemberFree(LLVMRustArchiveMemberRef Member) {
|
|
||||||
delete Member;
|
delete Member;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" LLVMRustResult
|
extern "C" LLVMRustResult
|
||||||
LLVMRustWriteArchive(char *Dst,
|
LLVMRustWriteArchive(char *Dst, size_t NumMembers,
|
||||||
size_t NumMembers,
|
|
||||||
const LLVMRustArchiveMemberRef *NewMembers,
|
const LLVMRustArchiveMemberRef *NewMembers,
|
||||||
bool WriteSymbtab,
|
bool WriteSymbtab, LLVMRustArchiveKind rust_kind) {
|
||||||
LLVMRustArchiveKind rust_kind) {
|
|
||||||
|
|
||||||
#if LLVM_VERSION_LE(3, 8)
|
#if LLVM_VERSION_LE(3, 8)
|
||||||
std::vector<NewArchiveIterator> Members;
|
std::vector<NewArchiveIterator> Members;
|
||||||
|
@ -257,7 +248,8 @@ LLVMRustWriteArchive(char *Dst,
|
||||||
assert(Member->name);
|
assert(Member->name);
|
||||||
if (Member->filename) {
|
if (Member->filename) {
|
||||||
#if LLVM_VERSION_GE(3, 9)
|
#if LLVM_VERSION_GE(3, 9)
|
||||||
Expected<NewArchiveMember> MOrErr = NewArchiveMember::getFile(Member->filename, true);
|
Expected<NewArchiveMember> MOrErr =
|
||||||
|
NewArchiveMember::getFile(Member->filename, true);
|
||||||
if (!MOrErr) {
|
if (!MOrErr) {
|
||||||
LLVMRustSetLastError(toString(MOrErr.takeError()).c_str());
|
LLVMRustSetLastError(toString(MOrErr.takeError()).c_str());
|
||||||
return LLVMRustResult::Failure;
|
return LLVMRustResult::Failure;
|
||||||
|
@ -272,7 +264,8 @@ LLVMRustWriteArchive(char *Dst,
|
||||||
#if LLVM_VERSION_LE(3, 8)
|
#if LLVM_VERSION_LE(3, 8)
|
||||||
Members.push_back(NewArchiveIterator(Member->child, Member->name));
|
Members.push_back(NewArchiveIterator(Member->child, Member->name));
|
||||||
#else
|
#else
|
||||||
Expected<NewArchiveMember> MOrErr = NewArchiveMember::getOldMember(Member->child, true);
|
Expected<NewArchiveMember> MOrErr =
|
||||||
|
NewArchiveMember::getOldMember(Member->child, true);
|
||||||
if (!MOrErr) {
|
if (!MOrErr) {
|
||||||
LLVMRustSetLastError(toString(MOrErr.takeError()).c_str());
|
LLVMRustSetLastError(toString(MOrErr.takeError()).c_str());
|
||||||
return LLVMRustResult::Failure;
|
return LLVMRustResult::Failure;
|
||||||
|
|
|
@ -12,12 +12,12 @@
|
||||||
|
|
||||||
#include "rustllvm.h"
|
#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/TargetLibraryInfo.h"
|
||||||
#include "llvm/Analysis/TargetTransformInfo.h"
|
#include "llvm/Analysis/TargetTransformInfo.h"
|
||||||
#include "llvm/IR/AutoUpgrade.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/TargetMachine.h"
|
||||||
#include "llvm/Target/TargetSubtargetInfo.h"
|
#include "llvm/Target/TargetSubtargetInfo.h"
|
||||||
#include "llvm/Transforms/IPO/PassManagerBuilder.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(Pass, LLVMPassRef)
|
||||||
DEFINE_STDCXX_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef)
|
DEFINE_STDCXX_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef)
|
||||||
DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBuilder, LLVMPassManagerBuilderRef)
|
DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBuilder,
|
||||||
|
LLVMPassManagerBuilderRef)
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMInitializePasses() {
|
||||||
LLVMInitializePasses() {
|
|
||||||
PassRegistry &Registry = *PassRegistry::getPassRegistry();
|
PassRegistry &Registry = *PassRegistry::getPassRegistry();
|
||||||
initializeCore(Registry);
|
initializeCore(Registry);
|
||||||
initializeCodeGen(Registry);
|
initializeCodeGen(Registry);
|
||||||
|
@ -64,9 +64,7 @@ enum class LLVMRustPassKind {
|
||||||
Module,
|
Module,
|
||||||
};
|
};
|
||||||
|
|
||||||
static LLVMRustPassKind
|
static LLVMRustPassKind to_rust(PassKind kind) {
|
||||||
to_rust(PassKind kind)
|
|
||||||
{
|
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case PT_Function:
|
case PT_Function:
|
||||||
return LLVMRustPassKind::Function;
|
return LLVMRustPassKind::Function;
|
||||||
|
@ -77,8 +75,7 @@ to_rust(PassKind kind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" LLVMPassRef
|
extern "C" LLVMPassRef LLVMRustFindAndCreatePass(const char *PassName) {
|
||||||
LLVMRustFindAndCreatePass(const char *PassName) {
|
|
||||||
StringRef SR(PassName);
|
StringRef SR(PassName);
|
||||||
PassRegistry *PR = PassRegistry::getPassRegistry();
|
PassRegistry *PR = PassRegistry::getPassRegistry();
|
||||||
|
|
||||||
|
@ -89,15 +86,13 @@ LLVMRustFindAndCreatePass(const char *PassName) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" LLVMRustPassKind
|
extern "C" LLVMRustPassKind LLVMRustPassKind(LLVMPassRef rust_pass) {
|
||||||
LLVMRustPassKind(LLVMPassRef rust_pass) {
|
|
||||||
assert(rust_pass);
|
assert(rust_pass);
|
||||||
Pass *pass = unwrap(rust_pass);
|
Pass *pass = unwrap(rust_pass);
|
||||||
return to_rust(pass->getPassKind());
|
return to_rust(pass->getPassKind());
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMRustAddPass(LLVMPassManagerRef PM, LLVMPassRef rust_pass) {
|
||||||
LLVMRustAddPass(LLVMPassManagerRef PM, LLVMPassRef rust_pass) {
|
|
||||||
assert(rust_pass);
|
assert(rust_pass);
|
||||||
Pass *pass = unwrap(rust_pass);
|
Pass *pass = unwrap(rust_pass);
|
||||||
PassManagerBase *pm = unwrap(PM);
|
PassManagerBase *pm = unwrap(PM);
|
||||||
|
@ -155,7 +150,8 @@ LLVMRustAddPass(LLVMPassManagerRef PM, LLVMPassRef rust_pass) {
|
||||||
SUBTARGET_SYSTEMZ \
|
SUBTARGET_SYSTEMZ \
|
||||||
SUBTARGET_MSP430
|
SUBTARGET_MSP430
|
||||||
|
|
||||||
#define SUBTARGET(x) namespace llvm { \
|
#define SUBTARGET(x) \
|
||||||
|
namespace llvm { \
|
||||||
extern const SubtargetFeatureKV x##FeatureKV[]; \
|
extern const SubtargetFeatureKV x##FeatureKV[]; \
|
||||||
extern const SubtargetFeatureKV x##SubTypeKV[]; \
|
extern const SubtargetFeatureKV x##SubTypeKV[]; \
|
||||||
}
|
}
|
||||||
|
@ -163,8 +159,7 @@ LLVMRustAddPass(LLVMPassManagerRef PM, LLVMPassRef rust_pass) {
|
||||||
GEN_SUBTARGETS
|
GEN_SUBTARGETS
|
||||||
#undef SUBTARGET
|
#undef SUBTARGET
|
||||||
|
|
||||||
extern "C" bool
|
extern "C" bool LLVMRustHasFeature(LLVMTargetMachineRef TM,
|
||||||
LLVMRustHasFeature(LLVMTargetMachineRef TM,
|
|
||||||
const char *feature) {
|
const char *feature) {
|
||||||
TargetMachine *Target = unwrap(TM);
|
TargetMachine *Target = unwrap(TM);
|
||||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||||
|
@ -176,9 +171,7 @@ LLVMRustHasFeature(LLVMTargetMachineRef TM,
|
||||||
FeatureEntry = x##FeatureKV; \
|
FeatureEntry = x##FeatureKV; \
|
||||||
} else
|
} else
|
||||||
|
|
||||||
GEN_SUBTARGETS {
|
GEN_SUBTARGETS { return false; }
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#undef SUBTARGET
|
#undef SUBTARGET
|
||||||
|
|
||||||
while (strcmp(feature, FeatureEntry->Key) != 0)
|
while (strcmp(feature, FeatureEntry->Key) != 0)
|
||||||
|
@ -197,9 +190,7 @@ enum class LLVMRustCodeModel {
|
||||||
Large,
|
Large,
|
||||||
};
|
};
|
||||||
|
|
||||||
static CodeModel::Model
|
static CodeModel::Model from_rust(LLVMRustCodeModel model) {
|
||||||
from_rust(LLVMRustCodeModel model)
|
|
||||||
{
|
|
||||||
switch (model) {
|
switch (model) {
|
||||||
case LLVMRustCodeModel::Default:
|
case LLVMRustCodeModel::Default:
|
||||||
return CodeModel::Default;
|
return CodeModel::Default;
|
||||||
|
@ -226,9 +217,7 @@ enum class LLVMRustCodeGenOptLevel {
|
||||||
Aggressive,
|
Aggressive,
|
||||||
};
|
};
|
||||||
|
|
||||||
static CodeGenOpt::Level
|
static CodeGenOpt::Level from_rust(LLVMRustCodeGenOptLevel level) {
|
||||||
from_rust(LLVMRustCodeGenOptLevel level)
|
|
||||||
{
|
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case LLVMRustCodeGenOptLevel::None:
|
case LLVMRustCodeGenOptLevel::None:
|
||||||
return CodeGenOpt::None;
|
return CodeGenOpt::None;
|
||||||
|
@ -253,8 +242,7 @@ static size_t getLongestEntryLength(ArrayRef<SubtargetFeatureKV> Table) {
|
||||||
return MaxLen;
|
return MaxLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM) {
|
||||||
LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM) {
|
|
||||||
const TargetMachine *Target = unwrap(TM);
|
const TargetMachine *Target = unwrap(TM);
|
||||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||||
const ArrayRef<SubtargetFeatureKV> CPUTable = MCInfo->getCPUTable();
|
const ArrayRef<SubtargetFeatureKV> CPUTable = MCInfo->getCPUTable();
|
||||||
|
@ -266,8 +254,7 @@ LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMRustPrintTargetFeatures(LLVMTargetMachineRef TM) {
|
||||||
LLVMRustPrintTargetFeatures(LLVMTargetMachineRef TM) {
|
|
||||||
const TargetMachine *Target = unwrap(TM);
|
const TargetMachine *Target = unwrap(TM);
|
||||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||||
const ArrayRef<SubtargetFeatureKV> FeatTable = MCInfo->getFeatureTable();
|
const ArrayRef<SubtargetFeatureKV> FeatTable = MCInfo->getFeatureTable();
|
||||||
|
@ -279,32 +266,26 @@ LLVMRustPrintTargetFeatures(LLVMTargetMachineRef TM) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
printf("Use +feature to enable a feature, or -feature to disable it.\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");
|
"For example, rustc -C -target-cpu=mycpu -C "
|
||||||
|
"target-feature=+feature1,-feature2\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef) {
|
||||||
LLVMRustPrintTargetCPUs(LLVMTargetMachineRef) {
|
|
||||||
printf("Target CPU help is not supported by this LLVM version.\n\n");
|
printf("Target CPU help is not supported by this LLVM version.\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMRustPrintTargetFeatures(LLVMTargetMachineRef) {
|
||||||
LLVMRustPrintTargetFeatures(LLVMTargetMachineRef) {
|
|
||||||
printf("Target features help is not supported by this LLVM version.\n\n");
|
printf("Target features help is not supported by this LLVM version.\n\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern "C" LLVMTargetMachineRef
|
extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
|
||||||
LLVMRustCreateTargetMachine(const char *triple,
|
const char *triple, const char *cpu, const char *feature,
|
||||||
const char *cpu,
|
LLVMRustCodeModel rust_CM, LLVMRelocMode Reloc,
|
||||||
const char *feature,
|
LLVMRustCodeGenOptLevel rust_OptLevel, bool UseSoftFloat,
|
||||||
LLVMRustCodeModel rust_CM,
|
bool PositionIndependentExecutable, bool FunctionSections,
|
||||||
LLVMRelocMode Reloc,
|
|
||||||
LLVMRustCodeGenOptLevel rust_OptLevel,
|
|
||||||
bool UseSoftFloat,
|
|
||||||
bool PositionIndependentExecutable,
|
|
||||||
bool FunctionSections,
|
|
||||||
bool DataSections) {
|
bool DataSections) {
|
||||||
|
|
||||||
#if LLVM_VERSION_LE(3, 8)
|
#if LLVM_VERSION_LE(3, 8)
|
||||||
|
@ -315,7 +296,7 @@ LLVMRustCreateTargetMachine(const char *triple,
|
||||||
auto CM = from_rust(rust_CM);
|
auto CM = from_rust(rust_CM);
|
||||||
auto OptLevel = from_rust(rust_OptLevel);
|
auto OptLevel = from_rust(rust_OptLevel);
|
||||||
|
|
||||||
switch (Reloc){
|
switch (Reloc) {
|
||||||
case LLVMRelocStatic:
|
case LLVMRelocStatic:
|
||||||
RM = Reloc::Static;
|
RM = Reloc::Static;
|
||||||
break;
|
break;
|
||||||
|
@ -334,8 +315,8 @@ LLVMRustCreateTargetMachine(const char *triple,
|
||||||
|
|
||||||
std::string Error;
|
std::string Error;
|
||||||
Triple Trip(Triple::normalize(triple));
|
Triple Trip(Triple::normalize(triple));
|
||||||
const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Trip.getTriple(),
|
const llvm::Target *TheTarget =
|
||||||
Error);
|
TargetRegistry::lookupTarget(Trip.getTriple(), Error);
|
||||||
if (TheTarget == NULL) {
|
if (TheTarget == NULL) {
|
||||||
LLVMRustSetLastError(Error.c_str());
|
LLVMRustSetLastError(Error.c_str());
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -358,41 +339,31 @@ LLVMRustCreateTargetMachine(const char *triple,
|
||||||
Options.DataSections = DataSections;
|
Options.DataSections = DataSections;
|
||||||
Options.FunctionSections = FunctionSections;
|
Options.FunctionSections = FunctionSections;
|
||||||
|
|
||||||
TargetMachine *TM = TheTarget->createTargetMachine(Trip.getTriple(),
|
TargetMachine *TM = TheTarget->createTargetMachine(
|
||||||
real_cpu,
|
Trip.getTriple(), real_cpu, feature, Options, RM, CM, OptLevel);
|
||||||
feature,
|
|
||||||
Options,
|
|
||||||
RM,
|
|
||||||
CM,
|
|
||||||
OptLevel);
|
|
||||||
return wrap(TM);
|
return wrap(TM);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) {
|
||||||
LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) {
|
|
||||||
delete unwrap(TM);
|
delete unwrap(TM);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unfortunately, LLVM doesn't expose a C API to add the corresponding analysis
|
// 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
|
// passes for a target to a pass manager. We export that functionality through
|
||||||
// this function.
|
// this function.
|
||||||
extern "C" void
|
extern "C" void LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM,
|
||||||
LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM,
|
|
||||||
LLVMPassManagerRef PMR,
|
LLVMPassManagerRef PMR,
|
||||||
LLVMModuleRef M) {
|
LLVMModuleRef M) {
|
||||||
PassManagerBase *PM = unwrap(PMR);
|
PassManagerBase *PM = unwrap(PMR);
|
||||||
PM->add(createTargetTransformInfoWrapperPass(
|
PM->add(
|
||||||
unwrap(TM)->getTargetIRAnalysis()));
|
createTargetTransformInfoWrapperPass(unwrap(TM)->getTargetIRAnalysis()));
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMRustConfigurePassManagerBuilder(
|
||||||
LLVMRustConfigurePassManagerBuilder(LLVMPassManagerBuilderRef PMB,
|
LLVMPassManagerBuilderRef PMB, LLVMRustCodeGenOptLevel OptLevel,
|
||||||
LLVMRustCodeGenOptLevel OptLevel,
|
bool MergeFunctions, bool SLPVectorize, bool LoopVectorize) {
|
||||||
bool MergeFunctions,
|
|
||||||
bool SLPVectorize,
|
|
||||||
bool LoopVectorize) {
|
|
||||||
// Ignore mergefunc for now as enabling it causes crashes.
|
// Ignore mergefunc for now as enabling it causes crashes.
|
||||||
//unwrap(PMB)->MergeFunctions = MergeFunctions;
|
// unwrap(PMB)->MergeFunctions = MergeFunctions;
|
||||||
unwrap(PMB)->SLPVectorize = SLPVectorize;
|
unwrap(PMB)->SLPVectorize = SLPVectorize;
|
||||||
unwrap(PMB)->OptLevel = from_rust(OptLevel);
|
unwrap(PMB)->OptLevel = from_rust(OptLevel);
|
||||||
unwrap(PMB)->LoopVectorize = LoopVectorize;
|
unwrap(PMB)->LoopVectorize = LoopVectorize;
|
||||||
|
@ -400,8 +371,7 @@ LLVMRustConfigurePassManagerBuilder(LLVMPassManagerBuilderRef PMB,
|
||||||
|
|
||||||
// Unfortunately, the LLVM C API doesn't provide a way to set the `LibraryInfo`
|
// 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.
|
// field of a PassManagerBuilder, we expose our own method of doing so.
|
||||||
extern "C" void
|
extern "C" void LLVMRustAddBuilderLibraryInfo(LLVMPassManagerBuilderRef PMB,
|
||||||
LLVMRustAddBuilderLibraryInfo(LLVMPassManagerBuilderRef PMB,
|
|
||||||
LLVMModuleRef M,
|
LLVMModuleRef M,
|
||||||
bool DisableSimplifyLibCalls) {
|
bool DisableSimplifyLibCalls) {
|
||||||
Triple TargetTriple(unwrap(M)->getTargetTriple());
|
Triple TargetTriple(unwrap(M)->getTargetTriple());
|
||||||
|
@ -413,9 +383,7 @@ LLVMRustAddBuilderLibraryInfo(LLVMPassManagerBuilderRef PMB,
|
||||||
|
|
||||||
// Unfortunately, the LLVM C API doesn't provide a way to create the
|
// Unfortunately, the LLVM C API doesn't provide a way to create the
|
||||||
// TargetLibraryInfo pass, so we use this method to do so.
|
// TargetLibraryInfo pass, so we use this method to do so.
|
||||||
extern "C" void
|
extern "C" void LLVMRustAddLibraryInfo(LLVMPassManagerRef PMB, LLVMModuleRef M,
|
||||||
LLVMRustAddLibraryInfo(LLVMPassManagerRef PMB,
|
|
||||||
LLVMModuleRef M,
|
|
||||||
bool DisableSimplifyLibCalls) {
|
bool DisableSimplifyLibCalls) {
|
||||||
Triple TargetTriple(unwrap(M)->getTargetTriple());
|
Triple TargetTriple(unwrap(M)->getTargetTriple());
|
||||||
TargetLibraryInfoImpl TLII(TargetTriple);
|
TargetLibraryInfoImpl TLII(TargetTriple);
|
||||||
|
@ -427,32 +395,32 @@ LLVMRustAddLibraryInfo(LLVMPassManagerRef PMB,
|
||||||
// Unfortunately, the LLVM C API doesn't provide an easy way of iterating over
|
// 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
|
// all the functions in a module, so we do that manually here. You'll find
|
||||||
// similar code in clang's BackendUtil.cpp file.
|
// similar code in clang's BackendUtil.cpp file.
|
||||||
extern "C" void
|
extern "C" void LLVMRustRunFunctionPassManager(LLVMPassManagerRef PM,
|
||||||
LLVMRustRunFunctionPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) {
|
LLVMModuleRef M) {
|
||||||
llvm::legacy::FunctionPassManager *P = unwrap<llvm::legacy::FunctionPassManager>(PM);
|
llvm::legacy::FunctionPassManager *P =
|
||||||
|
unwrap<llvm::legacy::FunctionPassManager>(PM);
|
||||||
P->doInitialization();
|
P->doInitialization();
|
||||||
|
|
||||||
// Upgrade all calls to old intrinsics first.
|
// Upgrade all calls to old intrinsics first.
|
||||||
for (Module::iterator I = unwrap(M)->begin(),
|
for (Module::iterator I = unwrap(M)->begin(), E = unwrap(M)->end(); I != E;)
|
||||||
E = unwrap(M)->end(); I != E;)
|
|
||||||
UpgradeCallsToIntrinsic(&*I++); // must be post-increment, as we remove
|
UpgradeCallsToIntrinsic(&*I++); // must be post-increment, as we remove
|
||||||
|
|
||||||
for (Module::iterator I = unwrap(M)->begin(),
|
for (Module::iterator I = unwrap(M)->begin(), E = unwrap(M)->end(); I != E;
|
||||||
E = unwrap(M)->end(); I != E; ++I)
|
++I)
|
||||||
if (!I->isDeclaration())
|
if (!I->isDeclaration())
|
||||||
P->run(*I);
|
P->run(*I);
|
||||||
|
|
||||||
P->doFinalization();
|
P->doFinalization();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMRustSetLLVMOptions(int Argc, char **Argv) {
|
||||||
LLVMRustSetLLVMOptions(int Argc, char **Argv) {
|
|
||||||
// Initializing the command-line options more than once is not allowed. So,
|
// 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
|
// check if they've already been initialized. (This could happen if we're
|
||||||
// being called from rustpkg, for example). If the arguments change, then
|
// being called from rustpkg, for example). If the arguments change, then
|
||||||
// that's just kinda unfortunate.
|
// that's just kinda unfortunate.
|
||||||
static bool initialized = false;
|
static bool initialized = false;
|
||||||
if (initialized) return;
|
if (initialized)
|
||||||
|
return;
|
||||||
initialized = true;
|
initialized = true;
|
||||||
cl::ParseCommandLineOptions(Argc, Argv);
|
cl::ParseCommandLineOptions(Argc, Argv);
|
||||||
}
|
}
|
||||||
|
@ -463,9 +431,7 @@ enum class LLVMRustFileType {
|
||||||
ObjectFile,
|
ObjectFile,
|
||||||
};
|
};
|
||||||
|
|
||||||
static TargetMachine::CodeGenFileType
|
static TargetMachine::CodeGenFileType from_rust(LLVMRustFileType type) {
|
||||||
from_rust(LLVMRustFileType type)
|
|
||||||
{
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case LLVMRustFileType::AssemblyFile:
|
case LLVMRustFileType::AssemblyFile:
|
||||||
return TargetMachine::CGFT_AssemblyFile;
|
return TargetMachine::CGFT_AssemblyFile;
|
||||||
|
@ -477,10 +443,8 @@ from_rust(LLVMRustFileType type)
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" LLVMRustResult
|
extern "C" LLVMRustResult
|
||||||
LLVMRustWriteOutputFile(LLVMTargetMachineRef Target,
|
LLVMRustWriteOutputFile(LLVMTargetMachineRef Target, LLVMPassManagerRef PMR,
|
||||||
LLVMPassManagerRef PMR,
|
LLVMModuleRef M, const char *path,
|
||||||
LLVMModuleRef M,
|
|
||||||
const char *path,
|
|
||||||
LLVMRustFileType rust_FileType) {
|
LLVMRustFileType rust_FileType) {
|
||||||
llvm::legacy::PassManager *PM = unwrap<llvm::legacy::PassManager>(PMR);
|
llvm::legacy::PassManager *PM = unwrap<llvm::legacy::PassManager>(PMR);
|
||||||
auto FileType = from_rust(rust_FileType);
|
auto FileType = from_rust(rust_FileType);
|
||||||
|
@ -505,10 +469,8 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target,
|
||||||
return LLVMRustResult::Success;
|
return LLVMRustResult::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMRustPrintModule(LLVMPassManagerRef PMR, LLVMModuleRef M,
|
||||||
LLVMRustPrintModule(LLVMPassManagerRef PMR,
|
const char *path) {
|
||||||
LLVMModuleRef M,
|
|
||||||
const char* path) {
|
|
||||||
llvm::legacy::PassManager *PM = unwrap<llvm::legacy::PassManager>(PMR);
|
llvm::legacy::PassManager *PM = unwrap<llvm::legacy::PassManager>(PMR);
|
||||||
std::string ErrorInfo;
|
std::string ErrorInfo;
|
||||||
|
|
||||||
|
@ -524,8 +486,7 @@ LLVMRustPrintModule(LLVMPassManagerRef PMR,
|
||||||
PM->run(*unwrap(M));
|
PM->run(*unwrap(M));
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMRustPrintPasses() {
|
||||||
LLVMRustPrintPasses() {
|
|
||||||
LLVMInitializePasses();
|
LLVMInitializePasses();
|
||||||
struct MyListener : PassRegistrationListener {
|
struct MyListener : PassRegistrationListener {
|
||||||
void passEnumerate(const PassInfo *info) {
|
void passEnumerate(const PassInfo *info) {
|
||||||
|
@ -541,8 +502,7 @@ LLVMRustPrintPasses() {
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (info->getPassArgument() && *info->getPassArgument()) {
|
if (info->getPassArgument() && *info->getPassArgument()) {
|
||||||
printf("%15s - %s\n", info->getPassArgument(),
|
printf("%15s - %s\n", info->getPassArgument(), info->getPassName());
|
||||||
info->getPassName());
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -552,8 +512,8 @@ LLVMRustPrintPasses() {
|
||||||
PR->enumerateWith(&listener);
|
PR->enumerateWith(&listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMRustAddAlwaysInlinePass(LLVMPassManagerBuilderRef PMB,
|
||||||
LLVMRustAddAlwaysInlinePass(LLVMPassManagerBuilderRef PMB, bool AddLifetimes) {
|
bool AddLifetimes) {
|
||||||
#if LLVM_VERSION_GE(4, 0)
|
#if LLVM_VERSION_GE(4, 0)
|
||||||
unwrap(PMB)->Inliner = llvm::createAlwaysInlinerLegacyPass(AddLifetimes);
|
unwrap(PMB)->Inliner = llvm::createAlwaysInlinerLegacyPass(AddLifetimes);
|
||||||
#else
|
#else
|
||||||
|
@ -561,16 +521,16 @@ LLVMRustAddAlwaysInlinePass(LLVMPassManagerBuilderRef PMB, bool AddLifetimes) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **symbols,
|
||||||
LLVMRustRunRestrictionPass(LLVMModuleRef M, char **symbols, size_t len) {
|
size_t len) {
|
||||||
llvm::legacy::PassManager passes;
|
llvm::legacy::PassManager passes;
|
||||||
|
|
||||||
#if LLVM_VERSION_LE(3, 8)
|
#if LLVM_VERSION_LE(3, 8)
|
||||||
ArrayRef<const char*> ref(symbols, len);
|
ArrayRef<const char *> ref(symbols, len);
|
||||||
passes.add(llvm::createInternalizePass(ref));
|
passes.add(llvm::createInternalizePass(ref));
|
||||||
#else
|
#else
|
||||||
auto PreserveFunctions = [=](const GlobalValue &GV) {
|
auto PreserveFunctions = [=](const GlobalValue &GV) {
|
||||||
for (size_t i=0; i<len; i++) {
|
for (size_t i = 0; i < len; i++) {
|
||||||
if (GV.getName() == symbols[i]) {
|
if (GV.getName() == symbols[i]) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -584,18 +544,16 @@ LLVMRustRunRestrictionPass(LLVMModuleRef M, char **symbols, size_t len) {
|
||||||
passes.run(*unwrap(M));
|
passes.run(*unwrap(M));
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMRustMarkAllFunctionsNounwind(LLVMModuleRef M) {
|
||||||
LLVMRustMarkAllFunctionsNounwind(LLVMModuleRef M) {
|
for (Module::iterator GV = unwrap(M)->begin(), E = unwrap(M)->end(); GV != E;
|
||||||
for (Module::iterator GV = unwrap(M)->begin(),
|
++GV) {
|
||||||
E = unwrap(M)->end(); GV != E; ++GV) {
|
|
||||||
GV->setDoesNotThrow();
|
GV->setDoesNotThrow();
|
||||||
Function *F = dyn_cast<Function>(GV);
|
Function *F = dyn_cast<Function>(GV);
|
||||||
if (F == NULL)
|
if (F == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (Function::iterator B = F->begin(), BE = F->end(); B != BE; ++B) {
|
for (Function::iterator B = F->begin(), BE = F->end(); B != BE; ++B) {
|
||||||
for (BasicBlock::iterator I = B->begin(), IE = B->end();
|
for (BasicBlock::iterator I = B->begin(), IE = B->end(); I != IE; ++I) {
|
||||||
I != IE; ++I) {
|
|
||||||
if (isa<InvokeInst>(I)) {
|
if (isa<InvokeInst>(I)) {
|
||||||
InvokeInst *CI = cast<InvokeInst>(I);
|
InvokeInst *CI = cast<InvokeInst>(I);
|
||||||
CI->setDoesNotThrow();
|
CI->setDoesNotThrow();
|
||||||
|
@ -612,13 +570,11 @@ LLVMRustSetDataLayoutFromTargetMachine(LLVMModuleRef Module,
|
||||||
unwrap(Module)->setDataLayout(Target->createDataLayout());
|
unwrap(Module)->setDataLayout(Target->createDataLayout());
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" LLVMTargetDataRef
|
extern "C" LLVMTargetDataRef LLVMRustGetModuleDataLayout(LLVMModuleRef M) {
|
||||||
LLVMRustGetModuleDataLayout(LLVMModuleRef M) {
|
|
||||||
return wrap(&unwrap(M)->getDataLayout());
|
return wrap(&unwrap(M)->getDataLayout());
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void LLVMRustSetModulePIELevel(LLVMModuleRef M) {
|
||||||
LLVMRustSetModulePIELevel(LLVMModuleRef M) {
|
|
||||||
#if LLVM_VERSION_GE(3, 9)
|
#if LLVM_VERSION_GE(3, 9)
|
||||||
unwrap(M)->setPIELevel(PIELevel::Level::Large);
|
unwrap(M)->setPIELevel(PIELevel::Level::Large);
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -8,50 +8,52 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// 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/BitReader.h"
|
||||||
|
#include "llvm-c/Core.h"
|
||||||
#include "llvm-c/ExecutionEngine.h"
|
#include "llvm-c/ExecutionEngine.h"
|
||||||
#include "llvm-c/Object.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) \
|
#define LLVM_VERSION_GE(major, minor) \
|
||||||
(LLVM_VERSION_MAJOR > (major) || LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR >= (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))
|
(LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR == (minor))
|
||||||
|
|
||||||
#define LLVM_VERSION_LE(major, minor) \
|
#define LLVM_VERSION_LE(major, minor) \
|
||||||
(LLVM_VERSION_MAJOR < (major) || LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))
|
(LLVM_VERSION_MAJOR < (major) || \
|
||||||
|
LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))
|
||||||
|
|
||||||
#if LLVM_VERSION_GE(3, 7)
|
#if LLVM_VERSION_GE(3, 7)
|
||||||
#include "llvm/IR/LegacyPassManager.h"
|
#include "llvm/IR/LegacyPassManager.h"
|
||||||
|
@ -66,17 +68,14 @@
|
||||||
#include "llvm/Bitcode/ReaderWriter.h"
|
#include "llvm/Bitcode/ReaderWriter.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "llvm/IR/IRPrintingPasses.h"
|
|
||||||
#include "llvm/IR/DebugInfo.h"
|
|
||||||
#include "llvm/IR/DIBuilder.h"
|
#include "llvm/IR/DIBuilder.h"
|
||||||
|
#include "llvm/IR/DebugInfo.h"
|
||||||
|
#include "llvm/IR/IRPrintingPasses.h"
|
||||||
#include "llvm/Linker/Linker.h"
|
#include "llvm/Linker/Linker.h"
|
||||||
|
|
||||||
void LLVMRustSetLastError(const char*);
|
void LLVMRustSetLastError(const char *);
|
||||||
|
|
||||||
enum class LLVMRustResult {
|
enum class LLVMRustResult { Success, Failure };
|
||||||
Success,
|
|
||||||
Failure
|
|
||||||
};
|
|
||||||
|
|
||||||
enum LLVMRustAttribute {
|
enum LLVMRustAttribute {
|
||||||
AlwaysInline = 0,
|
AlwaysInline = 0,
|
||||||
|
@ -107,8 +106,8 @@ typedef struct LLVMOpaqueDebugLoc *LLVMDebugLocRef;
|
||||||
typedef struct LLVMOpaqueSMDiagnostic *LLVMSMDiagnosticRef;
|
typedef struct LLVMOpaqueSMDiagnostic *LLVMSMDiagnosticRef;
|
||||||
typedef struct LLVMOpaqueRustJITMemoryManager *LLVMRustJITMemoryManagerRef;
|
typedef struct LLVMOpaqueRustJITMemoryManager *LLVMRustJITMemoryManagerRef;
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void rust_llvm_string_write_impl(RustStringRef str, const char *ptr,
|
||||||
rust_llvm_string_write_impl(RustStringRef str, const char *ptr, size_t size);
|
size_t size);
|
||||||
|
|
||||||
class raw_rust_string_ostream : public llvm::raw_ostream {
|
class raw_rust_string_ostream : public llvm::raw_ostream {
|
||||||
RustStringRef str;
|
RustStringRef str;
|
||||||
|
@ -119,13 +118,10 @@ class raw_rust_string_ostream : public llvm::raw_ostream {
|
||||||
pos += size;
|
pos += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t current_pos() const override {
|
uint64_t current_pos() const override { return pos; }
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit raw_rust_string_ostream(RustStringRef str)
|
explicit raw_rust_string_ostream(RustStringRef str) : str(str), pos(0) {}
|
||||||
: str(str), pos(0) { }
|
|
||||||
|
|
||||||
~raw_rust_string_ostream() {
|
~raw_rust_string_ostream() {
|
||||||
// LLVM requires this.
|
// LLVM requires this.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue