clang 23.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(StringRef Name) {
39 CPU = llvm::StringSwitch<CPUKind>(Name)
40 .Case("generic", CK_68000)
41 .Case("M68000", CK_68000)
42 .Case("M68010", CK_68010)
43 .Case("M68020", CK_68020)
44 .Case("M68030", CK_68030)
45 .Case("M68040", CK_68040)
46 .Case("M68060", CK_68060)
47 .Default(CK_Unknown);
48 return CPU != CK_Unknown;
49}
50
52 MacroBuilder &Builder) const {
53 using llvm::Twine;
54
55 Builder.defineMacro("__m68k__");
56
57 DefineStd(Builder, "mc68000", Opts);
58
59 // For sub-architecture
60 switch (CPU) {
61 case CK_68010:
62 DefineStd(Builder, "mc68010", Opts);
63 break;
64 case CK_68020:
65 DefineStd(Builder, "mc68020", Opts);
66 break;
67 case CK_68030:
68 DefineStd(Builder, "mc68030", Opts);
69 break;
70 case CK_68040:
71 DefineStd(Builder, "mc68040", Opts);
72 break;
73 case CK_68060:
74 DefineStd(Builder, "mc68060", Opts);
75 break;
76 default:
77 break;
78 }
79
80 if (CPU >= CK_68020) {
81 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
82 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
83 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
84 }
85
86 // Floating point
87 if (TargetOpts.FeatureMap.lookup("isa-68881") ||
88 TargetOpts.FeatureMap.lookup("isa-68882"))
89 Builder.defineMacro("__HAVE_68881__");
90}
91
94 // FIXME: Implement.
95 return {};
96}
97
98bool M68kTargetInfo::hasFeature(StringRef Feature) const {
99 // FIXME elaborate moar
100 return Feature == "M68000";
101}
102
103const char *const M68kTargetInfo::GCCRegNames[] = {
104 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
105 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp",
106 "pc"};
107
111
112const TargetInfo::GCCRegAlias M68kTargetInfo::GCCRegAliases[] = {
113 {{"bp"}, "a5"},
114 {{"fp"}, "a6"},
115 {{"usp", "ssp", "isp", "a7"}, "sp"},
116};
117
121
123 const char *&Name, TargetInfo::ConstraintInfo &info) const {
124 switch (*Name) {
125 case 'a': // address register
126 case 'd': // data register
127 info.setAllowsRegister();
128 return true;
129 case 'I': // constant integer in the range [1,8]
130 info.setRequiresImmediate(1, 8);
131 return true;
132 case 'J': // constant signed 16-bit integer
133 info.setRequiresImmediate(std::numeric_limits<int16_t>::min(),
134 std::numeric_limits<int16_t>::max());
135 return true;
136 case 'K': // constant that is NOT in the range of [-0x80, 0x80)
138 return true;
139 case 'L': // constant integer in the range [-8,-1]
140 info.setRequiresImmediate(-8, -1);
141 return true;
142 case 'M': // constant that is NOT in the range of [-0x100, 0x100]
144 return true;
145 case 'N': // constant integer in the range [24,31]
146 info.setRequiresImmediate(24, 31);
147 return true;
148 case 'O': // constant integer 16
149 info.setRequiresImmediate(16);
150 return true;
151 case 'P': // constant integer in the range [8,15]
152 info.setRequiresImmediate(8, 15);
153 return true;
154 case 'C':
155 ++Name;
156 switch (*Name) {
157 case '0': // constant integer 0
158 info.setRequiresImmediate(0);
159 return true;
160 case 'i': // constant integer
161 case 'j': // integer constant that doesn't fit in 16 bits
163 return true;
164 default:
165 break;
166 }
167 break;
168 case 'Q': // address register indirect addressing
169 case 'U': // address register indirect w/ constant offset addressing
170 // TODO: Handle 'S' (basically 'm' when pc-rel is enforced) when
171 // '-mpcrel' flag is properly handled by the driver.
172 info.setAllowsMemory();
173 return true;
174 default:
175 break;
176 }
177 return false;
178}
179
180std::optional<std::string>
182 char C;
183 switch (EscChar) {
184 case '.':
185 case '#':
186 C = EscChar;
187 break;
188 case '/':
189 C = '%';
190 break;
191 case '$':
192 C = 's';
193 break;
194 case '&':
195 C = 'd';
196 break;
197 default:
198 return std::nullopt;
199 }
200
201 return std::string(1, C);
202}
203
204std::string M68kTargetInfo::convertConstraint(const char *&Constraint) const {
205 if (*Constraint == 'C')
206 // Two-character constraint; add "^" hint for later parsing
207 return std::string("^") + std::string(Constraint++, 2);
208
209 return std::string(1, *Constraint);
210}
211
212std::string_view M68kTargetInfo::getClobbers() const {
213 // FIXME: Is this really right?
214 return "";
215}
216
220
223 switch (CC) {
224 case CC_C:
225 case CC_M68kRTD:
226 return CCCR_OK;
227 default:
229 }
230}
231} // namespace targets
232} // 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:334
@ VoidPtrBuiltinVaList
typedef void* __builtin_va_list;
Definition TargetInfo.h:339
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:204
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
Definition M68k.cpp:98
std::optional< std::string > handleAsmEscapedChar(char EscChar) const override
Replace some escaped characters with another string based on target-specific rules.
Definition M68k.cpp:181
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition M68k.cpp:217
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:222
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition M68k.cpp:51
bool setCPU(StringRef Name) override
Target the specified CPU.
Definition M68k.cpp:38
std::string_view getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition M68k.cpp:212
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition M68k.cpp:118
ArrayRef< const char * > getGCCRegNames() const override
Definition M68k.cpp:108
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const override
Definition M68k.cpp:122
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:93
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:279
@ CC_M68kRTD
Definition Specifiers.h:300
void setRequiresImmediate(int Min, int Max)