llvm.org GIT mirror llvm / 9ed9e5d
Fix it so llvm-objdump -arch does accept x86 and x86-64 as valid arch names. PR12731. Patch by Meador Inge! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156444 91177308-0d34-0410-b5e6-96231b3b80d8 Kevin Enderby 8 years ago
5 changed file(s) with 87 addition(s) and 79 deletion(s). Raw diff Collapse all Expand all
509509 static const Target *lookupTarget(const std::string &Triple,
510510 std::string &Error);
511511
512 /// lookupTarget - Lookup a target based on an architecture name
513 /// and a target triple. If the architecture name is non-empty,
514 /// then the lookup is done by architecture. Otherwise, the target
515 /// triple is used.
516 ///
517 /// \param ArchName - The architecture to use for finding a target.
518 /// \param TheTriple - The triple to use for finding a target. The
519 /// triple is updated with canonical architecture name if a lookup
520 /// by architecture is done.
521 /// \param Error - On failure, an error string describing why no target was
522 /// found.
523 static const Target *lookupTarget(const std::string &ArchName,
524 Triple &TheTriple,
525 std::string &Error);
526
512527 /// getClosestTargetForJIT - Pick the best target that is compatible with
513528 /// the current host. If no close target can be found, this returns null
514529 /// and sets the Error string to a reason.
2020
2121 TargetRegistry::iterator TargetRegistry::begin() {
2222 return iterator(FirstTarget);
23 }
24
25 const Target *TargetRegistry::lookupTarget(const std::string &ArchName,
26 Triple &TheTriple,
27 std::string &Error) {
28 // Allocate target machine. First, check whether the user has explicitly
29 // specified an architecture to compile for. If so we have to look it up by
30 // name, because it might be a backend that has no mapping to a target triple.
31 const Target *TheTarget = 0;
32 if (!ArchName.empty()) {
33 for (TargetRegistry::iterator it = TargetRegistry::begin(),
34 ie = TargetRegistry::end(); it != ie; ++it) {
35 if (ArchName == it->getName()) {
36 TheTarget = &*it;
37 break;
38 }
39 }
40
41 if (!TheTarget) {
42 Error = "error: invalid target '" + ArchName + "'.\n";
43 return 0;
44 }
45
46 // Adjust the triple to match (if known), otherwise stick with the
47 // given triple.
48 Triple::ArchType Type = Triple::getArchTypeForLLVMName(ArchName);
49 if (Type != Triple::UnknownArch)
50 TheTriple.setArch(Type);
51 } else {
52 // Get the target specific parser.
53 std::string TempError;
54 TheTarget = TargetRegistry::lookupTarget(TheTriple.getTriple(), TempError);
55 if (TheTarget == 0) {
56 Error = ": error: unable to get target for '"
57 + TheTriple.getTriple()
58 + "', see --version and --triple.\n";
59 return 0;
60 }
61 }
62
63 return TheTarget;
2364 }
2465
2566 const Target *TargetRegistry::lookupTarget(const std::string &TT,
365365 if (!TargetTriple.empty())
366366 mod.setTargetTriple(Triple::normalize(TargetTriple));
367367
368 // Figure out the target triple.
368369 Triple TheTriple(mod.getTargetTriple());
369370 if (TheTriple.getTriple().empty())
370371 TheTriple.setTriple(sys::getDefaultTargetTriple());
371372
372 // Allocate target machine. First, check whether the user has explicitly
373 // specified an architecture to compile for. If so we have to look it up by
374 // name, because it might be a backend that has no mapping to a target triple.
375 const Target *TheTarget = 0;
376 if (!MArch.empty()) {
377 for (TargetRegistry::iterator it = TargetRegistry::begin(),
378 ie = TargetRegistry::end(); it != ie; ++it) {
379 if (MArch == it->getName()) {
380 TheTarget = &*it;
381 break;
382 }
383 }
384
385 if (!TheTarget) {
386 errs() << argv[0] << ": error: invalid target '" << MArch << "'.\n";
387 return 1;
388 }
389
390 // Adjust the triple to match (if known), otherwise stick with the
391 // module/host triple.
392 Triple::ArchType Type = Triple::getArchTypeForLLVMName(MArch);
393 if (Type != Triple::UnknownArch)
394 TheTriple.setArch(Type);
395 } else {
396 std::string Err;
397 TheTarget = TargetRegistry::lookupTarget(TheTriple.getTriple(), Err);
398 if (TheTarget == 0) {
399 errs() << argv[0] << ": error auto-selecting target for module '"
400 << Err << "'. Please use the -march option to explicitly "
401 << "pick a target.\n";
402 return 1;
403 }
373 // Get the target specific parser.
374 std::string Error;
375 const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple,
376 Error);
377 if (!TheTarget) {
378 errs() << argv[0] << ": " << Error;
379 return 1;
404380 }
405381
406382 // Package up features to be passed to target/subtarget
179179 TripleName = sys::getDefaultTargetTriple();
180180 Triple TheTriple(Triple::normalize(TripleName));
181181
182 const Target *TheTarget = 0;
183 if (!ArchName.empty()) {
184 for (TargetRegistry::iterator it = TargetRegistry::begin(),
185 ie = TargetRegistry::end(); it != ie; ++it) {
186 if (ArchName == it->getName()) {
187 TheTarget = &*it;
188 break;
189 }
190 }
191
192 if (!TheTarget) {
193 errs() << ProgName << ": error: invalid target '" << ArchName << "'.\n";
194 return 0;
195 }
196
197 // Adjust the triple to match (if known), otherwise stick with the
198 // module/host triple.
199 Triple::ArchType Type = Triple::getArchTypeForLLVMName(ArchName);
200 if (Type != Triple::UnknownArch)
201 TheTriple.setArch(Type);
202 } else {
203 // Get the target specific parser.
204 std::string Error;
205 TheTarget = TargetRegistry::lookupTarget(TheTriple.getTriple(), Error);
206 if (TheTarget == 0) {
207 errs() << ProgName << ": error: unable to get target for '"
208 << TheTriple.getTriple()
209 << "', see --version and --triple.\n";
210 return 0;
211 }
212 }
213
182 // Get the target specific parser.
183 std::string Error;
184 const Target *TheTarget = TargetRegistry::lookupTarget(ArchName, TheTriple,
185 Error);
186 if (!TheTarget) {
187 errs() << ProgName << ": " << Error;
188 return 0;
189 }
190
191 // Update the triple name and return the found target.
214192 TripleName = TheTriple.getTriple();
215193 return TheTarget;
216194 }
105105
106106 static const Target *GetTarget(const ObjectFile *Obj = NULL) {
107107 // Figure out the target triple.
108 llvm::Triple TT("unknown-unknown-unknown");
108 llvm::Triple TheTriple("unknown-unknown-unknown");
109109 if (TripleName.empty()) {
110110 if (Obj)
111 TT.setArch(Triple::ArchType(Obj->getArch()));
111 TheTriple.setArch(Triple::ArchType(Obj->getArch()));
112112 } else
113 TT.setTriple(Triple::normalize(TripleName));
114
115 if (!ArchName.empty())
116 TT.setArchName(ArchName);
117
118 TripleName = TT.str();
113 TheTriple.setTriple(Triple::normalize(TripleName));
119114
120115 // Get the target specific parser.
121116 std::string Error;
122 const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
123 if (TheTarget)
124 return TheTarget;
125
126 errs() << ToolName << ": error: unable to get target for '" << TripleName
127 << "', see --version and --triple.\n";
128 return 0;
117 const Target *TheTarget = TargetRegistry::lookupTarget(ArchName, TheTriple,
118 Error);
119 if (!TheTarget) {
120 errs() << ToolName << ": " << Error;
121 return 0;
122 }
123
124 // Update the triple name and return the found target.
125 TripleName = TheTriple.getTriple();
126 return TheTarget;
129127 }
130128
131129 void llvm::StringRefMemoryObject::anchor() { }