using namespace llvm::jitlink;
namespace llvm {
-JITLinkTestCommon::TestResources::TestResources(StringRef AsmSrc,
- StringRef TripleStr, bool PIC,
- bool LargeCodeModel,
- MCTargetOptions Options)
- : ObjStream(ObjBuffer), Options(std::move(Options)) {
- Triple TT(Triple::normalize(TripleStr));
- initializeTripleSpecifics(TT);
- initializeTestSpecifics(AsmSrc, TT, PIC, LargeCodeModel);
+Expected<std::unique_ptr<JITLinkTestCommon::TestResources>>
+JITLinkTestCommon::TestResources::Create(StringRef AsmSrc, StringRef TripleStr,
+ bool PIC, bool LargeCodeModel,
+ MCTargetOptions Options) {
+ Error Err = Error::success();
+ auto R = std::unique_ptr<TestResources>(new TestResources(
+ AsmSrc, TripleStr, PIC, LargeCodeModel, std::move(Options), Err));
+ if (Err)
+ return std::move(Err);
+ return std::move(R);
}
MemoryBufferRef
"Test object");
}
-void JITLinkTestCommon::TestResources::initializeTripleSpecifics(Triple &TT) {
- std::string Error;
- TheTarget = TargetRegistry::lookupTarget("", TT, Error);
+JITLinkTestCommon::TestResources::TestResources(StringRef AsmSrc,
+ StringRef TripleStr, bool PIC,
+ bool LargeCodeModel,
+ MCTargetOptions Options,
+ Error &Err)
+ : ObjStream(ObjBuffer), Options(std::move(Options)) {
+ ErrorAsOutParameter _(&Err);
+ Triple TT(Triple::normalize(TripleStr));
+ if (auto Err2 = initializeTripleSpecifics(TT)) {
+ Err = std::move(Err2);
+ return;
+ }
+ initializeTestSpecifics(AsmSrc, TT, PIC, LargeCodeModel);
+}
+
+Error JITLinkTestCommon::TestResources::initializeTripleSpecifics(Triple &TT) {
+ std::string ErrorMsg;
+ TheTarget = TargetRegistry::lookupTarget("", TT, ErrorMsg);
if (!TheTarget)
- report_fatal_error(Error);
+ return make_error<StringError>(ErrorMsg, inconvertibleErrorCode());
MRI.reset(TheTarget->createMCRegInfo(TT.getTriple()));
if (!MRI)
if (!Dis)
report_fatal_error("Could not build MCDisassembler");
+
+ return Error::success();
}
void JITLinkTestCommon::TestResources::initializeTestSpecifics(
class TestResources {
public:
- TestResources(StringRef AsmSrc, StringRef TripleStr, bool PIC,
- bool LargeCodeModel, MCTargetOptions Options);
+ static Expected<std::unique_ptr<TestResources>>
+ Create(StringRef AsmSrc, StringRef TripleStr, bool PIC, bool LargeCodeModel,
+ MCTargetOptions Options);
MemoryBufferRef getTestObjectBufferRef() const;
const MCDisassembler &getDisassembler() const { return *Dis; }
private:
- void initializeTripleSpecifics(Triple &TT);
+ TestResources(StringRef AsmSrc, StringRef TripleStr, bool PIC,
+ bool LargeCodeModel, MCTargetOptions Options, Error &Err);
+
+ Error initializeTripleSpecifics(Triple &TT);
void initializeTestSpecifics(StringRef AsmSource, const Triple &TT,
bool PIC, bool LargeCodeModel);
JITLinkTestCommon();
- std::unique_ptr<TestResources>
+ /// Get TestResources for this target/test.
+ ///
+ /// If this method fails it is likely because the target is not supported in
+ /// this build. The test should bail out without failing (possibly logging a
+ /// diagnostic).
+ Expected<std::unique_ptr<TestResources>>
getTestResources(StringRef AsmSrc, StringRef Triple, bool PIC,
bool LargeCodeModel, MCTargetOptions Options) const {
- return llvm::make_unique<TestResources>(AsmSrc, Triple, PIC, LargeCodeModel,
- std::move(Options));
+ return TestResources::Create(AsmSrc, Triple, PIC, LargeCodeModel,
+ std::move(Options));
}
template <typename T>
BasicVerifyGraphFunction RunGraphTest) {
auto TR = getTestResources(AsmSrc, Triple, PIC, LargeCodeModel,
std::move(Options));
+ if (!TR) {
+ dbgs() << "Skipping JITLInk unit test: " << toString(TR.takeError())
+ << "\n";
+ return;
+ }
auto JTCtx = llvm::make_unique<TestJITLinkContext>(
- *TR, [&](AtomGraph &G) { RunGraphTest(G, TR->getDisassembler()); });
+ **TR, [&](AtomGraph &G) { RunGraphTest(G, (*TR)->getDisassembler()); });
JTCtx->externals() = std::move(Externals);