]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/ArchSpec.h
Merge ^/head r275118 through r275209.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / ArchSpec.h
1 //===-- ArchSpec.h ----------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_ArchSpec_h_
11 #define liblldb_ArchSpec_h_
12
13 #if defined(__cplusplus)
14
15 #include "lldb/lldb-private.h"
16 #include "lldb/Core/ConstString.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/ADT/Triple.h"
19
20 namespace lldb_private {
21
22 struct CoreDefinition;    
23
24 //----------------------------------------------------------------------
25 /// @class ArchSpec ArchSpec.h "lldb/Core/ArchSpec.h"
26 /// @brief An architecture specification class.
27 ///
28 /// A class designed to be created from a cpu type and subtype, a
29 /// string representation, or an llvm::Triple.  Keeping all of the
30 /// conversions of strings to architecture enumeration values confined
31 /// to this class allows new architecture support to be added easily.
32 //----------------------------------------------------------------------
33 class ArchSpec
34 {
35 public:
36     enum Core
37     {
38         eCore_arm_generic,
39         eCore_arm_armv4,
40         eCore_arm_armv4t,
41         eCore_arm_armv5,
42         eCore_arm_armv5e,
43         eCore_arm_armv5t,
44         eCore_arm_armv6,
45         eCore_arm_armv6m,
46         eCore_arm_armv7,
47         eCore_arm_armv7f,
48         eCore_arm_armv7s,
49         eCore_arm_armv7k,
50         eCore_arm_armv7m,
51         eCore_arm_armv7em,
52         eCore_arm_xscale,  
53
54         eCore_thumb,
55         eCore_thumbv4t,
56         eCore_thumbv5,
57         eCore_thumbv5e,
58         eCore_thumbv6,
59         eCore_thumbv6m,
60         eCore_thumbv7,
61         eCore_thumbv7s,
62         eCore_thumbv7k,
63         eCore_thumbv7f,
64         eCore_thumbv7m,
65         eCore_thumbv7em,
66         eCore_arm_arm64,
67         eCore_arm_armv8,
68         eCore_arm_aarch64,
69         
70         eCore_mips64,
71
72         eCore_ppc_generic,
73         eCore_ppc_ppc601,
74         eCore_ppc_ppc602,
75         eCore_ppc_ppc603,
76         eCore_ppc_ppc603e,
77         eCore_ppc_ppc603ev,
78         eCore_ppc_ppc604,
79         eCore_ppc_ppc604e,
80         eCore_ppc_ppc620,
81         eCore_ppc_ppc750,
82         eCore_ppc_ppc7400,
83         eCore_ppc_ppc7450,
84         eCore_ppc_ppc970,
85         
86         eCore_ppc64_generic,
87         eCore_ppc64_ppc970_64,
88         
89         eCore_sparc_generic,
90         
91         eCore_sparc9_generic,
92         
93         eCore_x86_32_i386,
94         eCore_x86_32_i486,
95         eCore_x86_32_i486sx,
96         eCore_x86_32_i686,
97         
98         eCore_x86_64_x86_64,
99         eCore_x86_64_x86_64h, // Haswell enabled x86_64
100         eCore_hexagon_generic,
101         eCore_hexagon_hexagonv4,
102         eCore_hexagon_hexagonv5,
103
104         eCore_uknownMach32,
105         eCore_uknownMach64,
106
107         eCore_kalimba,
108         eCore_kalimba3,
109         eCore_kalimba4,
110         eCore_kalimba5,
111
112         kNumCores,
113
114         kCore_invalid,
115         // The following constants are used for wildcard matching only
116         kCore_any,
117         kCore_arm_any,
118         kCore_ppc_any,
119         kCore_ppc64_any,
120         kCore_x86_32_any,
121         kCore_x86_64_any,
122         kCore_hexagon_any,
123
124         kCore_arm_first     = eCore_arm_generic,
125         kCore_arm_last      = eCore_arm_xscale,
126
127         kCore_thumb_first   = eCore_thumb,
128         kCore_thumb_last    = eCore_thumbv7em,
129
130         kCore_ppc_first     = eCore_ppc_generic,
131         kCore_ppc_last      = eCore_ppc_ppc970,
132
133         kCore_ppc64_first   = eCore_ppc64_generic,
134         kCore_ppc64_last    = eCore_ppc64_ppc970_64,
135
136         kCore_x86_32_first  = eCore_x86_32_i386,
137         kCore_x86_32_last   = eCore_x86_32_i686,
138
139         kCore_x86_64_first  = eCore_x86_64_x86_64,
140         kCore_x86_64_last   = eCore_x86_64_x86_64h,
141
142         kCore_hexagon_first  = eCore_hexagon_generic,
143         kCore_hexagon_last   = eCore_hexagon_hexagonv5,
144
145         kCore_kalimba_first = eCore_kalimba,
146         kCore_kalimba_last = eCore_kalimba5
147     };
148
149     //------------------------------------------------------------------
150     /// Default constructor.
151     ///
152     /// Default constructor that initializes the object with invalid
153     /// cpu type and subtype values.
154     //------------------------------------------------------------------
155     ArchSpec ();
156
157     //------------------------------------------------------------------
158     /// Constructor over triple.
159     ///
160     /// Constructs an ArchSpec with properties consistent with the given
161     /// Triple.
162     //------------------------------------------------------------------
163     explicit 
164     ArchSpec (const llvm::Triple &triple);
165     explicit 
166     ArchSpec (const char *triple_cstr);
167     explicit 
168     ArchSpec (const char *triple_cstr, Platform *platform);
169     //------------------------------------------------------------------
170     /// Constructor over architecture name.
171     ///
172     /// Constructs an ArchSpec with properties consistent with the given
173     /// object type and architecture name.
174     //------------------------------------------------------------------
175     explicit 
176     ArchSpec (ArchitectureType arch_type,
177               uint32_t cpu_type,
178               uint32_t cpu_subtype);
179
180     //------------------------------------------------------------------
181     /// Destructor.
182     //------------------------------------------------------------------
183     ~ArchSpec ();
184
185     //------------------------------------------------------------------
186     /// Assignment operator.
187     ///
188     /// @param[in] rhs another ArchSpec object to copy.
189     ///
190     /// @return A const reference to this object.
191     //------------------------------------------------------------------
192     const ArchSpec&
193     operator= (const ArchSpec& rhs);
194
195     static size_t
196     AutoComplete (const char *name, 
197                   StringList &matches);
198
199     //------------------------------------------------------------------
200     /// Returns a static string representing the current architecture.
201     ///
202     /// @return A static string correcponding to the current
203     ///         architecture.
204     //------------------------------------------------------------------
205     const char *
206     GetArchitectureName () const;
207
208     //------------------------------------------------------------------
209     /// Clears the object state.
210     ///
211     /// Clears the object state back to a default invalid state.
212     //------------------------------------------------------------------
213     void
214     Clear ();
215
216     //------------------------------------------------------------------
217     /// Returns the size in bytes of an address of the current
218     /// architecture.
219     ///
220     /// @return The byte size of an address of the current architecture.
221     //------------------------------------------------------------------
222     uint32_t
223     GetAddressByteSize () const;
224
225     //------------------------------------------------------------------
226     /// Returns a machine family for the current architecture.
227     ///
228     /// @return An LLVM arch type.
229     //------------------------------------------------------------------
230     llvm::Triple::ArchType
231     GetMachine () const;
232
233     //------------------------------------------------------------------
234     /// Returns the distribution id of the architecture.
235     ///
236     /// This will be something like "ubuntu", "fedora", etc. on Linux.
237     ///
238     /// @return A ConstString ref containing the distribution id,
239     ///         potentially empty.
240     //------------------------------------------------------------------
241     const ConstString&
242     GetDistributionId () const;
243
244     //------------------------------------------------------------------
245     /// Set the distribution id of the architecture.
246     ///
247     /// This will be something like "ubuntu", "fedora", etc. on Linux.
248     /// This should be the same value returned by
249     /// HostInfo::GetDistributionId ().
250     ///------------------------------------------------------------------
251     void
252     SetDistributionId (const char* distribution_id);
253
254     //------------------------------------------------------------------
255     /// Tests if this ArchSpec is valid.
256     ///
257     /// @return True if the current architecture is valid, false
258     ///         otherwise.
259     //------------------------------------------------------------------
260     bool
261     IsValid () const
262     {
263         return m_core >= eCore_arm_generic && m_core < kNumCores;
264     }
265
266     bool
267     TripleVendorWasSpecified() const
268     {
269         return !m_triple.getVendorName().empty();
270     }
271
272     bool
273     TripleOSWasSpecified() const
274     {
275         return !m_triple.getOSName().empty();
276     }
277
278     //------------------------------------------------------------------
279     /// Sets this ArchSpec according to the given architecture name.
280     ///
281     /// The architecture name can be one of the generic system default
282     /// values:
283     ///
284     /// @li \c LLDB_ARCH_DEFAULT - The arch the current system defaults
285     ///        to when a program is launched without any extra
286     ///        attributes or settings.
287     /// @li \c LLDB_ARCH_DEFAULT_32BIT - The default host architecture
288     ///        for 32 bit (if any).
289     /// @li \c LLDB_ARCH_DEFAULT_64BIT - The default host architecture
290     ///        for 64 bit (if any).
291     ///
292     /// Alternatively, if the object type of this ArchSpec has been
293     /// configured,  a concrete architecture can be specified to set
294     /// the CPU type ("x86_64" for example).
295     ///
296     /// Finally, an encoded object and archetecture format is accepted.
297     /// The format contains an object type (like "macho" or "elf"),
298     /// followed by a platform dependent encoding of CPU type and
299     /// subtype.  For example:
300     ///
301     ///     "macho"        : Specifies an object type of MachO.
302     ///     "macho-16-6"   : MachO specific encoding for ARMv6.
303     ///     "elf-43        : ELF specific encoding for Sparc V9.
304     ///
305     /// @param[in] arch_name The name of an architecture.
306     ///
307     /// @return True if @p arch_name was successfully translated, false
308     ///         otherwise.
309     //------------------------------------------------------------------
310 //    bool
311 //    SetArchitecture (const llvm::StringRef& arch_name);
312 //
313 //    bool
314 //    SetArchitecture (const char *arch_name);
315     
316     //------------------------------------------------------------------
317     /// Change the architecture object type and CPU type.
318     ///
319     /// @param[in] arch_type The object type of this ArchSpec.
320     ///
321     /// @param[in] cpu The required CPU type.
322     ///
323     /// @return True if the object and CPU type were successfully set.
324     //------------------------------------------------------------------
325     bool
326     SetArchitecture (ArchitectureType arch_type, 
327                      uint32_t cpu,
328                      uint32_t sub);
329
330     //------------------------------------------------------------------
331     /// Returns the byte order for the architecture specification.
332     ///
333     /// @return The endian enumeration for the current endianness of
334     ///     the architecture specification
335     //------------------------------------------------------------------
336     lldb::ByteOrder
337     GetByteOrder () const;
338
339     //------------------------------------------------------------------
340     /// Sets this ArchSpec's byte order.
341     ///
342     /// In the common case there is no need to call this method as the
343     /// byte order can almost always be determined by the architecture.
344     /// However, many CPU's are bi-endian (ARM, Alpha, PowerPC, etc)
345     /// and the default/assumed byte order may be incorrect.
346     //------------------------------------------------------------------
347     void
348     SetByteOrder (lldb::ByteOrder byte_order)
349     {
350         m_byte_order = byte_order;
351     }
352
353     uint32_t
354     GetMinimumOpcodeByteSize() const;
355
356     uint32_t
357     GetMaximumOpcodeByteSize() const;
358
359     Core
360     GetCore () const
361     {
362         return m_core;
363     }
364
365     uint32_t
366     GetMachOCPUType () const;
367
368     uint32_t
369     GetMachOCPUSubType () const;
370
371     //------------------------------------------------------------------
372     /// Architecture data byte width accessor
373     ///
374     /// @return the size in 8-bit (host) bytes of a minimum addressable
375     /// unit from the Architecture's data bus
376     //------------------------------------------------------------------
377     uint32_t
378     GetDataByteSize() const;
379
380     //------------------------------------------------------------------
381     /// Architecture code byte width accessor
382     ///
383     /// @return the size in 8-bit (host) bytes of a minimum addressable
384     /// unit from the Architecture's code bus
385     //------------------------------------------------------------------
386     uint32_t
387     GetCodeByteSize() const;
388  
389     //------------------------------------------------------------------
390     /// Architecture tripple accessor.
391     ///
392     /// @return A triple describing this ArchSpec.
393     //------------------------------------------------------------------
394     llvm::Triple &
395     GetTriple ()
396     {
397         return m_triple;
398     }
399
400     //------------------------------------------------------------------
401     /// Architecture tripple accessor.
402     ///
403     /// @return A triple describing this ArchSpec.
404     //------------------------------------------------------------------
405     const llvm::Triple &
406     GetTriple () const
407     {
408         return m_triple;
409     }
410
411     //------------------------------------------------------------------
412     /// Architecture tripple setter.
413     ///
414     /// Configures this ArchSpec according to the given triple.  If the 
415     /// triple has unknown components in all of the vendor, OS, and 
416     /// the optional environment field (i.e. "i386-unknown-unknown")
417     /// then default values are taken from the host.  Architecture and
418     /// environment components are used to further resolve the CPU type
419     /// and subtype, endian characteristics, etc.
420     ///
421     /// @return A triple describing this ArchSpec.
422     //------------------------------------------------------------------
423     bool
424     SetTriple (const llvm::Triple &triple);
425
426     bool
427     SetTriple (const char *triple_cstr);
428
429     bool
430     SetTriple (const char *triple_cstr,
431                Platform *platform);
432     
433     //------------------------------------------------------------------
434     /// Returns the default endianness of the architecture.
435     ///
436     /// @return The endian enumeration for the default endianness of
437     ///         the architecture.
438     //------------------------------------------------------------------
439     lldb::ByteOrder
440     GetDefaultEndian () const;
441
442     //------------------------------------------------------------------
443     /// Compare an ArchSpec to another ArchSpec, requiring an exact cpu 
444     /// type match between them.  
445     /// e.g. armv7s is not an exact match with armv7 - this would return false
446     ///
447     /// @return true if the two ArchSpecs match.
448     //------------------------------------------------------------------
449     bool
450     IsExactMatch (const ArchSpec& rhs) const;
451
452     //------------------------------------------------------------------
453     /// Compare an ArchSpec to another ArchSpec, requiring a compatible
454     /// cpu type match between them.  
455     /// e.g. armv7s is compatible with armv7 - this method would return true
456     ///
457     /// @return true if the two ArchSpecs are compatible
458     //------------------------------------------------------------------
459     bool
460     IsCompatibleMatch (const ArchSpec& rhs) const;
461
462 protected:
463     bool
464     IsEqualTo (const ArchSpec& rhs, bool exact_match) const;
465
466     llvm::Triple m_triple;
467     Core m_core;
468     lldb::ByteOrder m_byte_order;
469
470     ConstString m_distribution_id;
471
472     // Called when m_def or m_entry are changed.  Fills in all remaining
473     // members with default values.
474     void
475     CoreUpdated (bool update_triple);
476 };
477
478 //------------------------------------------------------------------
479 /// @fn bool operator< (const ArchSpec& lhs, const ArchSpec& rhs)
480 /// @brief Less than operator.
481 ///
482 /// Tests two ArchSpec objects to see if \a lhs is less than \a
483 /// rhs.
484 ///
485 /// @param[in] lhs The Left Hand Side ArchSpec object to compare.
486 /// @param[in] rhs The Left Hand Side ArchSpec object to compare.
487 ///
488 /// @return true if \a lhs is less than \a rhs
489 //------------------------------------------------------------------
490 bool operator< (const ArchSpec& lhs, const ArchSpec& rhs);
491
492 } // namespace lldb_private
493
494 #endif  // #if defined(__cplusplus)
495 #endif  // #ifndef liblldb_ArchSpec_h_