MCJITTestAPICommon.h [plain text]
#ifndef MCJIT_TEST_API_COMMON_H
#define MCJIT_TEST_API_COMMON_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/TargetSelect.h"
#define SKIP_UNSUPPORTED_PLATFORM \
do \
if (!ArchSupportsMCJIT() || !OSSupportsMCJIT()) \
return; \
while(0)
namespace llvm {
class MCJITTestAPICommon {
protected:
MCJITTestAPICommon()
: HostTriple(sys::getProcessTriple())
{
InitializeNativeTarget();
InitializeNativeTargetAsmPrinter();
#ifdef LLVM_ON_WIN32
HostTriple += "-elf";
#endif // LLVM_ON_WIN32
HostTriple = Triple::normalize(HostTriple);
}
bool ArchSupportsMCJIT() {
Triple Host(HostTriple);
if (std::find(SupportedArchs.begin(), SupportedArchs.end(), Host.getArch())
== SupportedArchs.end())
return false;
if (std::find(HasSubArchs.begin(), HasSubArchs.end(), Host.getArch())
== HasSubArchs.end())
return true;
SmallVectorImpl<std::string>::const_iterator I = SupportedSubArchs.begin();
for(; I != SupportedSubArchs.end(); ++I)
if (Host.getArchName().startswith(I->c_str()))
return true;
return false;
}
bool OSSupportsMCJIT() {
Triple Host(HostTriple);
if (std::find(UnsupportedOSs.begin(), UnsupportedOSs.end(), Host.getOS())
== UnsupportedOSs.end()) {
return true;
}
return false;
}
std::string HostTriple;
SmallVector<Triple::ArchType, 4> SupportedArchs;
SmallVector<Triple::ArchType, 1> HasSubArchs;
SmallVector<std::string, 2> SupportedSubArchs; SmallVector<Triple::OSType, 4> UnsupportedOSs;
};
}
#endif // MCJIT_TEST_API_COMMON_H