clang 22.0.0git
M68k.cpp
Go to the documentation of this file.
1//===--- M68k.cpp - Implement M68k targets feature support-------------===//
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// This file implements M68k TargetInfo objects.
10//
11//===----------------------------------------------------------------------===//
12
13#include "M68k.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/ADT/StringSwitch.h"
18#include "llvm/TargetParser/TargetParser.h"
19#include <cstdint>
20#include <cstring>
21#include <limits>
22#include <optional>
23
24namespace clang {
25namespace targets {
26
27M68kTargetInfo::M68kTargetInfo(const llvm::Triple &Triple,
28 const TargetOptions &Opts)
29 : TargetInfo(Triple), TargetOpts(Opts) {
31
36}
37
38bool M68kTargetInfo::setCPU(const std::string &Name) {
39 StringRef N = Name;
40 CPU = llvm::StringSwitch<CPUKind>(N)
41 .Case("generic", CK_68000)
42 .Case("M68000", CK_68000)
43 .Case("M68010", CK_68010)
44 .Case("M68020", CK_68020)
45 .Case("M68030", CK_68030)
46 .Case("M68040", CK_68040)
47 .Case("M68060", CK_68060)
48 .Default(CK_Unknown);
49 return CPU != CK_Unknown;
50}
51
53 MacroBuilder &Builder) const {
54 using llvm::Twine;
55
56 Builder.defineMacro("__m68k__");
57
58 DefineStd(Builder, "mc68000", Opts);
59
60 // For sub-architecture
61 switch (CPU) {
62 case CK_68010:
63 DefineStd(Builder, "mc68010", Opts);
64 break;
65 case CK_68020:
66 DefineStd(Builder, "mc68020", Opts);
67 break;
68 case CK_68030:
69 DefineStd(Builder, "mc68030", Opts);
70 break;
71 case CK_68040:
72 DefineStd(Builder, "mc68040", Opts);
73 break;
74 case CK_68060:
75 DefineStd(Builder, "mc68060", Opts);
76 break;
77 default:
78 break;
79 }
80
81 if (CPU >= CK_68020) {
82 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
83 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
84 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
85 }
86
87 // Floating point
88 if (TargetOpts.FeatureMap.lookup("isa-68881") ||
89 TargetOpts.FeatureMap.lookup("isa-68882"))
90 Builder.defineMacro("__HAVE_68881__");
91}
92
95 // FIXME: Implement.
96 return {};
97}
98
99bool M68kTargetInfo::hasFeature(StringRef Feature) const {
100 // FIXME elaborate moar
101 return Feature == "M68000";
102}
103
104const char *const M68kTargetInfo::GCCRegNames[] = {
105 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
106 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp",
107 "pc"};
108
112
113const TargetInfo::GCCRegAlias M68kTargetInfo::GCCRegAliases[] = {
114 {{"bp"}, "a5"},
115 {{"fp"}, "a6"},
116 {{"usp", "ssp", "isp", "a7"}, "sp"},
117};
118
122
124 const char *&Name, TargetInfo::ConstraintInfo &info) const {
125 switch (*Name) {
126 case 'a': // address register
127 case 'd': // data register
128 info.setAllowsRegister();
129 return true;
130 case 'I': // constant integer in the range [1,8]
131 info.setRequiresImmediate(1, 8);
132 return true;
133 case 'J': // constant signed 16-bit integer
134 info.setRequiresImmediate(std::numeric_limits<int16_t>::min(),
135 std::numeric_limits<int16_t>::max());
136 return true;
137 case 'K': // constant that is NOT in the range of [-0x80, 0x80)
139 return true;
140 case 'L': // constant integer in the range [-8,-1]
141 info.setRequiresImmediate(-8, -1);
142 return true;
143 case 'M': // constant that is NOT in the range of [-0x100, 0x100]
145 return true;
146 case 'N': // constant integer in the range [24,31]
147 info.setRequiresImmediate(24, 31);
148 return true;
149 case 'O': // constant integer 16
150 info.setRequiresImmediate(16);
151 return true;
152 case 'P': // constant integer in the range [8,15]
153 info.setRequiresImmediate(8, 15);
154 return true;
155 case 'C':
156 ++Name;
157 switch (*Name) {
158 case '0': // constant integer 0
159 info.setRequiresImmediate(0);
160 return true;
161 case 'i': // constant integer
162 case 'j': // integer constant that doesn't fit in 16 bits
164 return true;
165 default:
166 break;
167 }
168 break;
169 case 'Q': // address register indirect addressing
170 case 'U': // address register indirect w/ constant offset addressing
171 // TODO: Handle 'S' (basically 'm' when pc-rel is enforced) when
172 // '-mpcrel' flag is properly handled by the driver.
173 info.setAllowsMemory();
174 return true;
175 default:
176 break;
177 }
178 return false;
179}
180
181std::optional<std::string>
183 char C;
184 switch (EscChar) {
185 case '.':
186 case '#':
187 C = EscChar;
188 break;
189 case '/':
190 C = '%';
191 break;
192 case '$':
193 C = 's';
194 break;
195 case '&':
196 C = 'd';
197 break;
198 default:
199 return std::nullopt;
200 }
201
202 return std::string(1, C);
203}
204
205std::string M68kTargetInfo::convertConstraint(const char *&Constraint) const {
206 if (*Constraint == 'C')
207 // Two-character constraint; add "^" hint for later parsing
208 return std::string("^") + std::string(Constraint++, 2);
209
210 return std::string(1, *Constraint);
211}
212
213std::string_view M68kTargetInfo::getClobbers() const {
214 // FIXME: Is this really right?
215 return "";
216}
217
221
224 switch (CC) {
225 case CC_C:
226 case CC_M68kRTD:
227 return CCCR_OK;
228 default:
230 }
231}
232} // namespace targets
233} // namespace clang
Defines the Diagnostic-related interfaces.
Defines enum values for all the target-independent builtin functions.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
TargetInfo(const llvm::Triple &T)
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition TargetInfo.h:333
@ VoidPtrBuiltinVaList
typedef void* __builtin_va_list;
Definition TargetInfo.h:338
virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const
Determines whether a given calling convention is valid for the target.
void resetDataLayout()
Set the data layout based on current triple and ABI.
Options for controlling the target.
std::string convertConstraint(const char *&Constraint) const override
Definition M68k.cpp:205
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
Definition M68k.cpp:99
std::optional< std::string > handleAsmEscapedChar(char EscChar) const override
Replace some escaped characters with another string based on target-specific rules.
Definition M68k.cpp:182
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition M68k.cpp:218
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition M68k.cpp:38
M68kTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition M68k.cpp:27
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition M68k.cpp:223
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition M68k.cpp:52
std::string_view getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition M68k.cpp:213
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition M68k.cpp:119
ArrayRef< const char * > getGCCRegNames() const override
Definition M68k.cpp:109
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const override
Definition M68k.cpp:123
llvm::SmallVector< Builtin::InfosShard > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition M68k.cpp:94
LLVM_LIBRARY_VISIBILITY void DefineStd(clang::MacroBuilder &Builder, llvm::StringRef MacroName, const clang::LangOptions &Opts)
Define a macro name and standard variants.
The JSON file list parser is used to communicate input to InstallAPI.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition Specifiers.h:278
@ CC_M68kRTD
Definition Specifiers.h:299
void setRequiresImmediate(int Min, int Max)