15
15
using namespace llvm ::jitlink;
16
16
namespace llvm {
17
17
18
- JITLinkTestCommon::TestResources::TestResources (StringRef AsmSrc,
19
- StringRef TripleStr, bool PIC,
20
- bool LargeCodeModel,
21
- MCTargetOptions Options)
22
- : ObjStream(ObjBuffer), Options(std::move(Options)) {
23
- Triple TT (Triple::normalize (TripleStr));
24
- initializeTripleSpecifics (TT);
25
- initializeTestSpecifics (AsmSrc, TT, PIC, LargeCodeModel);
18
+ Expected<std::unique_ptr<JITLinkTestCommon::TestResources>>
19
+ JITLinkTestCommon::TestResources::Create (StringRef AsmSrc, StringRef TripleStr,
20
+ bool PIC, bool LargeCodeModel,
21
+ MCTargetOptions Options) {
22
+ Error Err = Error::success ();
23
+ auto R = std::unique_ptr<TestResources>(new TestResources (
24
+ AsmSrc, TripleStr, PIC, LargeCodeModel, std::move (Options), Err));
25
+ if (Err)
26
+ return std::move (Err);
27
+ return std::move (R);
26
28
}
27
29
28
30
MemoryBufferRef
@@ -31,12 +33,27 @@ JITLinkTestCommon::TestResources::getTestObjectBufferRef() const {
31
33
" Test object" );
32
34
}
33
35
34
- void JITLinkTestCommon::TestResources::initializeTripleSpecifics (Triple &TT) {
35
- std::string Error;
36
- TheTarget = TargetRegistry::lookupTarget (" " , TT, Error);
36
+ JITLinkTestCommon::TestResources::TestResources (StringRef AsmSrc,
37
+ StringRef TripleStr, bool PIC,
38
+ bool LargeCodeModel,
39
+ MCTargetOptions Options,
40
+ Error &Err)
41
+ : ObjStream(ObjBuffer), Options(std::move(Options)) {
42
+ ErrorAsOutParameter _ (&Err);
43
+ Triple TT (Triple::normalize (TripleStr));
44
+ if (auto Err2 = initializeTripleSpecifics (TT)) {
45
+ Err = std::move (Err2);
46
+ return ;
47
+ }
48
+ initializeTestSpecifics (AsmSrc, TT, PIC, LargeCodeModel);
49
+ }
50
+
51
+ Error JITLinkTestCommon::TestResources::initializeTripleSpecifics (Triple &TT) {
52
+ std::string ErrorMsg;
53
+ TheTarget = TargetRegistry::lookupTarget (" " , TT, ErrorMsg);
37
54
38
55
if (!TheTarget)
39
- report_fatal_error (Error );
56
+ return make_error<StringError>(ErrorMsg, inconvertibleErrorCode () );
40
57
41
58
MRI.reset (TheTarget->createMCRegInfo (TT.getTriple ()));
42
59
if (!MRI)
@@ -59,6 +76,8 @@ void JITLinkTestCommon::TestResources::initializeTripleSpecifics(Triple &TT) {
59
76
60
77
if (!Dis)
61
78
report_fatal_error (" Could not build MCDisassembler" );
79
+
80
+ return Error::success ();
62
81
}
63
82
64
83
void JITLinkTestCommon::TestResources::initializeTestSpecifics (
0 commit comments