diff options
Diffstat (limited to 'clang/lib/Basic')
-rw-r--r-- | clang/lib/Basic/CMakeLists.txt | 1 | ||||
-rw-r--r-- | clang/lib/Basic/Targets.cpp | 9 | ||||
-rw-r--r-- | clang/lib/Basic/Targets/M88k.cpp | 152 | ||||
-rw-r--r-- | clang/lib/Basic/Targets/M88k.h | 49 |
4 files changed, 211 insertions, 0 deletions
diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt index f0f3839..78158ca 100644 --- a/clang/lib/Basic/CMakeLists.txt +++ b/clang/lib/Basic/CMakeLists.txt @@ -84,6 +84,7 @@ add_clang_library(clangBasic Targets/Le64.cpp Targets/LoongArch.cpp Targets/M68k.cpp + Targets/M88k.cpp Targets/MSP430.cpp Targets/Mips.cpp Targets/NVPTX.cpp diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 8400774..93ccf80 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -26,6 +26,7 @@ #include "Targets/Le64.h" #include "Targets/LoongArch.h" #include "Targets/M68k.h" +#include "Targets/M88k.h" #include "Targets/MSP430.h" #include "Targets/Mips.h" #include "Targets/NVPTX.h" @@ -318,6 +319,14 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple, return new M68kTargetInfo(Triple, Opts); } + case llvm::Triple::m88k: + switch (os) { + case llvm::Triple::OpenBSD: + return new OpenBSDTargetInfo<M88kTargetInfo>(Triple, Opts); + default: + return new M88kTargetInfo(Triple, Opts); + } + case llvm::Triple::le32: switch (os) { case llvm::Triple::NaCl: diff --git a/clang/lib/Basic/Targets/M88k.cpp b/clang/lib/Basic/Targets/M88k.cpp new file mode 100644 index 0000000..e60f75c --- /dev/null +++ b/clang/lib/Basic/Targets/M88k.cpp @@ -0,0 +1,152 @@ +//===--- M88k.cpp - Implement M88k targets feature support ----------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements M88k TargetInfo objects. +// +//===----------------------------------------------------------------------===// + +#include "M88k.h" +#include "clang/Basic/Builtins.h" +#include "clang/Basic/Diagnostic.h" +#include "clang/Basic/TargetBuiltins.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/StringSwitch.h" +#include "llvm/Support/TargetParser.h" +#include <cstring> + +namespace clang { +namespace targets { + +M88kTargetInfo::M88kTargetInfo(const llvm::Triple &Triple, + const TargetOptions &) + : TargetInfo(Triple) { + + std::string Layout = ""; + + // M68k is Big Endian + Layout += "E"; + + // FIXME how to wire it with the used object format? + Layout += "-m:e"; + + // Pointers are 32 bit. + Layout += "-p:32:8:32"; + + // Make sure that global data has at least 16 bits of alignment by + // default, so that we can refer to it using LARL. We don't have any + // special requirements for stack variables though. + Layout += "-i1:8:16-i8:8:16"; + + // 64-bit integers are naturally aligned. + Layout += "-i64:64"; + + // 128-bit floats are aligned only to 64 bits. + Layout += "-f128:64"; + + // We prefer 16 bits of aligned for all globals; see above. + Layout += "-a:8:16"; + + // Integer registers are 32bits. + Layout += "-n32"; + + resetDataLayout(Layout); + + SizeType = UnsignedInt; + PtrDiffType = SignedInt; + IntPtrType = SignedInt; +} + +bool M88kTargetInfo::setCPU(const std::string &Name) { + StringRef N = Name; + CPU = llvm::StringSwitch<CPUKind>(N) + .Case("generic", CK_88000) + .Case("M88000", CK_88000) + .Case("M88100", CK_88100) + .Case("M88110", CK_88110) + .Default(CK_Unknown); + return CPU != CK_Unknown; +} + +void M88kTargetInfo::getTargetDefines(const LangOptions &Opts, + MacroBuilder &Builder) const { + using llvm::Twine; + + Builder.defineMacro("__m88k__"); + Builder.defineMacro("__m88k"); + + // For sub-architecture + switch (CPU) { + case CK_88000: + Builder.defineMacro("__mc88000__"); + break; + case CK_88100: + Builder.defineMacro("__mc88100__"); + break; + case CK_88110: + Builder.defineMacro("__mc88110__"); + break; + default: + break; + } +} + +ArrayRef<Builtin::Info> M88kTargetInfo::getTargetBuiltins() const { + // TODO Implement. + return None; +} + +bool M88kTargetInfo::hasFeature(StringRef Feature) const { + // TODO Implement. + return Feature == "M88000"; +} + +const char *const M88kTargetInfo::GCCRegNames[] = { + // TODO Extended registers, control registers. + "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", + "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20", "r21", + "r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", "r39", "r31"}; + +ArrayRef<const char *> M88kTargetInfo::getGCCRegNames() const { + return llvm::makeArrayRef(GCCRegNames); +} + +ArrayRef<TargetInfo::GCCRegAlias> M88kTargetInfo::getGCCRegAliases() const { + // No aliases. + return None; +} + +bool M88kTargetInfo::validateAsmConstraint( + const char *&Name, TargetInfo::ConstraintInfo &info) const { + // TODO Implement. + switch (*Name) { + case 'a': // address register + case 'd': // data register + case 'f': // floating point register + info.setAllowsRegister(); + return true; + case 'K': // the constant 1 + case 'L': // constant -1^20 .. 1^19 + case 'M': // constant 1-4: + return true; + } + return false; +} + +const char *M88kTargetInfo::getClobbers() const { + // TODO Implement. + return ""; +} + +M88kTargetInfo::BuiltinVaListKind M88kTargetInfo::getBuiltinVaListKind() const { + // TODO Check. + return TargetInfo::VoidPtrBuiltinVaList; +} + +} // namespace targets +} // namespace clang diff --git a/clang/lib/Basic/Targets/M88k.h b/clang/lib/Basic/Targets/M88k.h new file mode 100644 index 0000000..f959668 --- /dev/null +++ b/clang/lib/Basic/Targets/M88k.h @@ -0,0 +1,49 @@ +//===--- M88k.h - Declare M88k target feature support ---------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file declares M88k TargetInfo objects. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_M88K_H +#define LLVM_CLANG_LIB_BASIC_TARGETS_M88K_H + +#include "OSTargets.h" +#include "clang/Basic/TargetInfo.h" +#include "clang/Basic/TargetOptions.h" +#include "llvm/ADT/Triple.h" +#include "llvm/Support/Compiler.h" + +namespace clang { +namespace targets { + +class LLVM_LIBRARY_VISIBILITY M88kTargetInfo : public TargetInfo { + static const char *const GCCRegNames[]; + + enum CPUKind { CK_Unknown, CK_88000, CK_88100, CK_88110 } CPU = CK_Unknown; + +public: + M88kTargetInfo(const llvm::Triple &Triple, const TargetOptions &); + + void getTargetDefines(const LangOptions &Opts, + MacroBuilder &Builder) const override; + ArrayRef<Builtin::Info> getTargetBuiltins() const override; + bool hasFeature(StringRef Feature) const override; + ArrayRef<const char *> getGCCRegNames() const override; + ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override; + bool validateAsmConstraint(const char *&Name, + TargetInfo::ConstraintInfo &info) const override; + const char *getClobbers() const override; + BuiltinVaListKind getBuiltinVaListKind() const override; + bool setCPU(const std::string &Name) override; +}; + +} // namespace targets +} // namespace clang + +#endif // LLVM_CLANG_LIB_BASIC_TARGETS_M88K_H |