clang  14.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"
14 #include "clang/Basic/Builtins.h"
15 #include "clang/Basic/Diagnostic.h"
17 #include "llvm/ADT/StringExtras.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ADT/StringSwitch.h"
20 #include "llvm/Support/TargetParser.h"
21 #include <cstdint>
22 #include <cstring>
23 #include <limits>
24 
25 namespace clang {
26 namespace targets {
27 
28 M68kTargetInfo::M68kTargetInfo(const llvm::Triple &Triple,
29  const TargetOptions &)
30  : TargetInfo(Triple) {
31 
32  std::string Layout = "";
33 
34  // M68k is Big Endian
35  Layout += "E";
36 
37  // FIXME how to wire it with the used object format?
38  Layout += "-m:e";
39 
40  // M68k pointers are always 32 bit wide even for 16-bit CPUs
41  Layout += "-p:32:16:32";
42 
43  // M68k integer data types
44  Layout += "-i8:8:8-i16:16:16-i32:16:32";
45 
46  // FIXME no floats at the moment
47 
48  // The registers can hold 8, 16, 32 bits
49  Layout += "-n8:16:32";
50 
51  // 16 bit alignment for both stack and aggregate
52  // in order to conform to ABI used by GCC
53  Layout += "-a:0:16-S16";
54 
55  resetDataLayout(Layout);
56 
60 }
61 
63  StringRef N = Name;
64  CPU = llvm::StringSwitch<CPUKind>(N)
65  .Case("generic", CK_68000)
66  .Case("M68000", CK_68000)
67  .Case("M68010", CK_68010)
68  .Case("M68020", CK_68020)
69  .Case("M68030", CK_68030)
70  .Case("M68040", CK_68040)
71  .Case("M68060", CK_68060)
72  .Default(CK_Unknown);
73  return CPU != CK_Unknown;
74 }
75 
77  MacroBuilder &Builder) const {
78  using llvm::Twine;
79 
80  Builder.defineMacro("__m68k__");
81 
82  Builder.defineMacro("mc68000");
83  Builder.defineMacro("__mc68000");
84  Builder.defineMacro("__mc68000__");
85 
86  // For sub-architecture
87  switch (CPU) {
88  case CK_68010:
89  Builder.defineMacro("mc68010");
90  Builder.defineMacro("__mc68010");
91  Builder.defineMacro("__mc68010__");
92  break;
93  case CK_68020:
94  Builder.defineMacro("mc68020");
95  Builder.defineMacro("__mc68020");
96  Builder.defineMacro("__mc68020__");
97  break;
98  case CK_68030:
99  Builder.defineMacro("mc68030");
100  Builder.defineMacro("__mc68030");
101  Builder.defineMacro("__mc68030__");
102  break;
103  case CK_68040:
104  Builder.defineMacro("mc68040");
105  Builder.defineMacro("__mc68040");
106  Builder.defineMacro("__mc68040__");
107  break;
108  case CK_68060:
109  Builder.defineMacro("mc68060");
110  Builder.defineMacro("__mc68060");
111  Builder.defineMacro("__mc68060__");
112  break;
113  default:
114  break;
115  }
116 }
117 
119  // FIXME: Implement.
120  return None;
121 }
122 
123 bool M68kTargetInfo::hasFeature(StringRef Feature) const {
124  // FIXME elaborate moar
125  return Feature == "M68000";
126 }
127 
128 const char *const M68kTargetInfo::GCCRegNames[] = {
129  "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
130  "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
131  "pc"};
132 
134  return llvm::makeArrayRef(GCCRegNames);
135 }
136 
138  // No aliases.
139  return None;
140 }
141 
143  const char *&Name, TargetInfo::ConstraintInfo &info) const {
144  switch (*Name) {
145  case 'a': // address register
146  case 'd': // data register
147  info.setAllowsRegister();
148  return true;
149  case 'I': // constant integer in the range [1,8]
150  info.setRequiresImmediate(1, 8);
151  return true;
152  case 'J': // constant signed 16-bit integer
155  return true;
156  case 'K': // constant that is NOT in the range of [-0x80, 0x80)
157  info.setRequiresImmediate();
158  return true;
159  case 'L': // constant integer in the range [-8,-1]
160  info.setRequiresImmediate(-8, -1);
161  return true;
162  case 'M': // constant that is NOT in the range of [-0x100, 0x100]
163  info.setRequiresImmediate();
164  return true;
165  case 'N': // constant integer in the range [24,31]
166  info.setRequiresImmediate(24, 31);
167  return true;
168  case 'O': // constant integer 16
169  info.setRequiresImmediate(16);
170  return true;
171  case 'P': // constant integer in the range [8,15]
172  info.setRequiresImmediate(8, 15);
173  return true;
174  case 'C':
175  ++Name;
176  switch (*Name) {
177  case '0': // constant integer 0
178  info.setRequiresImmediate(0);
179  return true;
180  case 'i': // constant integer
181  case 'j': // integer constant that doesn't fit in 16 bits
182  info.setRequiresImmediate();
183  return true;
184  default:
185  break;
186  }
187  break;
188  default:
189  break;
190  }
191  return false;
192 }
193 
196  char C;
197  switch (EscChar) {
198  case '.':
199  case '#':
200  C = EscChar;
201  break;
202  case '/':
203  C = '%';
204  break;
205  case '$':
206  C = 's';
207  break;
208  case '&':
209  C = 'd';
210  break;
211  default:
212  return llvm::None;
213  }
214 
215  return std::string(1, C);
216 }
217 
218 std::string M68kTargetInfo::convertConstraint(const char *&Constraint) const {
219  if (*Constraint == 'C')
220  // Two-character constraint; add "^" hint for later parsing
221  return std::string("^") + std::string(Constraint++, 2);
222 
223  return std::string(1, *Constraint);
224 }
225 
226 const char *M68kTargetInfo::getClobbers() const {
227  // FIXME: Is this really right?
228  return "";
229 }
230 
233 }
234 
235 } // namespace targets
236 } // namespace clang
Builtins.h
max
__DEVICE__ int max(int __a, int __b)
Definition: __clang_cuda_math.h:196
clang::TransferrableTargetInfo::IntPtrType
IntType IntPtrType
Definition: TargetInfo.h:134
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::targets::M68kTargetInfo::getTargetDefines
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition: M68k.cpp:76
clang::targets::M68kTargetInfo::M68kTargetInfo
M68kTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition: M68k.cpp:28
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:189
clang::TargetInfo::VoidPtrBuiltinVaList
@ VoidPtrBuiltinVaList
typedef void* __builtin_va_list;
Definition: TargetInfo.h:270
llvm::Optional< std::string >
clang::targets::M68kTargetInfo::convertConstraint
std::string convertConstraint(const char *&Constraint) const override
Definition: M68k.cpp:218
clang::TargetInfo::BuiltinVaListKind
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:265
clang::TargetInfo::ConstraintInfo::setAllowsRegister
void setAllowsRegister()
Definition: TargetInfo.h:1025
clang::targets::M68kTargetInfo::getGCCRegAliases
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: M68k.cpp:137
clang::targets::M68kTargetInfo::getClobbers
const char * getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: M68k.cpp:226
min
__DEVICE__ int min(int __a, int __b)
Definition: __clang_cuda_math.h:197
clang::TargetInfo::ConstraintInfo::setRequiresImmediate
void setRequiresImmediate(int Min, int Max)
Definition: TargetInfo.h:1027
clang::targets::M68kTargetInfo::getGCCRegNames
ArrayRef< const char * > getGCCRegNames() const override
Definition: M68k.cpp:133
Diagnostic.h
clang::targets::M68kTargetInfo::hasFeature
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
Definition: M68k.cpp:123
clang::TargetInfo::resetDataLayout
void resetDataLayout(StringRef DL, const char *UserLabelPrefix="")
Definition: TargetInfo.cpp:156
clang::targets::M68kTargetInfo::setCPU
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: M68k.cpp:62
clang::targets::M68kTargetInfo::getTargetBuiltins
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition: M68k.cpp:118
clang::TransferrableTargetInfo::PtrDiffType
IntType PtrDiffType
Definition: TargetInfo.h:134
clang::targets::M68kTargetInfo::getBuiltinVaListKind
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: M68k.cpp:231
llvm::ArrayRef
Definition: LLVM.h:34
TargetBuiltins.h
clang::TargetInfo::ConstraintInfo
Definition: TargetInfo.h:960
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:58
clang::targets::M68kTargetInfo::handleAsmEscapedChar
llvm::Optional< std::string > handleAsmEscapedChar(char EscChar) const override
Replace some escaped characters with another string based on target-specific rules.
Definition: M68k.cpp:195
clang
Definition: CalledOnceCheck.h:17
M68k.h
clang::TransferrableTargetInfo::SignedInt
@ SignedInt
Definition: TargetInfo.h:125
clang::TargetOptions
Options for controlling the target.
Definition: TargetOptions.h:26
clang::MacroBuilder
Definition: MacroBuilder.h:23
clang::targets::M68kTargetInfo::validateAsmConstraint
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const override
Definition: M68k.cpp:142
clang::TransferrableTargetInfo::UnsignedInt
@ UnsignedInt
Definition: TargetInfo.h:126
clang::TransferrableTargetInfo::SizeType
IntType SizeType
Definition: TargetInfo.h:134