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