LLDB mainline
LanguageOpts.h
Go to the documentation of this file.
1//===-- LanguageOpts.h ----------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_TYPESYSTEM_CLIKE_LANGUAGEOPTS_H
10#define LLDB_SOURCE_PLUGINS_TYPESYSTEM_CLIKE_LANGUAGEOPTS_H
11
12#include "clang/Basic/TargetInfo.h"
13
14#include "llvm/Support/Error.h"
15#include "llvm/TargetParser/Triple.h"
16
18
19#include <cstdint>
20#include <memory>
21#include <optional>
22
23namespace llvm {
24struct fltSemantics;
25} // namespace llvm
26
27namespace lldb_private {
28namespace clike {
29
30/// Describes the target/language configuration that determines properties of
31/// the type system, such as builtin type sizes and encodings.
33public:
34 /// Sizes (in bytes) of the target-dependent builtin types.
35 struct BuiltinSizes {
36 uint32_t bool_size = 0;
37 uint32_t short_size = 0;
38 uint32_t int_size = 0;
39 uint32_t long_size = 0;
40 uint32_t long_long_size = 0;
41 uint32_t wchar_size = 0;
42 uint32_t char16_size = 0;
43 uint32_t char32_size = 0;
44 uint32_t float_size = 0;
45 uint32_t double_size = 0;
46 uint32_t long_double_size = 0;
47 uint32_t pointer_size = 0;
48 };
49
50 /// The language options for \p triple, or an error if Clang cannot describe
51 /// the triple.
52 static llvm::Expected<LanguageOpts> Create(llvm::Triple triple);
53
54 const llvm::Triple &GetTriple() const { return m_triple; }
55 const BuiltinSizes &GetBuiltinSizes() const { return m_builtin_sizes; }
56
57 /// The floating point semantics for a float of the given storage size.
58 const llvm::fltSemantics &
59 GetFloatTypeSemantics(const size_t byte_size,
60 const lldb::Format format) const;
61
62 /// The storage size (in bytes) of a `_BitInt(bits)` on this target.
63 ///
64 /// Returns std::nullopt if the bit width is invalid for the target.
65 std::optional<uint64_t> GetBitIntByteSize(unsigned bits) const;
66
67private:
68 /// The target's float formats.
70 const llvm::fltSemantics *half = nullptr;
71 const llvm::fltSemantics *single = nullptr;
72 const llvm::fltSemantics *double_ = nullptr;
73 const llvm::fltSemantics *long_double = nullptr;
74 const llvm::fltSemantics *float128 = nullptr;
75 };
76
77 LanguageOpts(llvm::Triple triple, std::unique_ptr<clang::TargetInfo> target,
78 BuiltinSizes sizes, FloatSemantics semantics);
79
80 llvm::Triple m_triple;
81 std::unique_ptr<clang::TargetInfo> m_target;
84};
85
86} // namespace clike
87} // namespace lldb_private
88
89#endif // LLDB_SOURCE_PLUGINS_TYPESYSTEM_CLIKE_LANGUAGEOPTS_H
std::optional< uint64_t > GetBitIntByteSize(unsigned bits) const
The storage size (in bytes) of a _BitInt(bits) on this target.
const llvm::Triple & GetTriple() const
static llvm::Expected< LanguageOpts > Create(llvm::Triple triple)
The language options for triple, or an error if Clang cannot describe the triple.
const BuiltinSizes & GetBuiltinSizes() const
LanguageOpts(llvm::Triple triple, std::unique_ptr< clang::TargetInfo > target, BuiltinSizes sizes, FloatSemantics semantics)
std::unique_ptr< clang::TargetInfo > m_target
const llvm::fltSemantics & GetFloatTypeSemantics(const size_t byte_size, const lldb::Format format) const
The floating point semantics for a float of the given storage size.
A class that represents a running process on the host machine.
static uint32_t bits(const uint32_t val, const uint32_t msbit, const uint32_t lsbit)
Definition ARMUtils.h:265
Format
Display format definitions.
Sizes (in bytes) of the target-dependent builtin types.