Skip to content

Commit 97ccf93

Browse files
abhina-sreehubert-reinterpretcast
authored andcommitted
[SystemZ][z/OS] Add z/OS Target and define macros
This patch adds the z/OS target and defines macros as a stepping stone towards enabling a native build on z/OS. Reviewed By: hubert.reinterpretcast Differential Revision: https://reviews.llvm.org/D85324
1 parent f753f5b commit 97ccf93

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

clang/lib/Basic/Targets.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple,
452452
switch (os) {
453453
case llvm::Triple::Linux:
454454
return new LinuxTargetInfo<SystemZTargetInfo>(Triple, Opts);
455+
case llvm::Triple::ZOS:
456+
return new ZOSTargetInfo<SystemZTargetInfo>(Triple, Opts);
455457
default:
456458
return new SystemZTargetInfo(Triple, Opts);
457459
}

clang/lib/Basic/Targets/OSTargets.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,55 @@ class AIXTargetInfo : public OSTargetInfo<Target> {
728728
bool defaultsToAIXPowerAlignment() const override { return true; }
729729
};
730730

731+
// z/OS target
732+
template <typename Target>
733+
class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo<Target> {
734+
protected:
735+
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
736+
MacroBuilder &Builder) const override {
737+
// FIXME: _LONG_LONG should not be defined under -std=c89.
738+
Builder.defineMacro("_LONG_LONG");
739+
Builder.defineMacro("_OPEN_DEFAULT");
740+
// _UNIX03_WITHDRAWN is required to build libcxx.
741+
Builder.defineMacro("_UNIX03_WITHDRAWN");
742+
Builder.defineMacro("__370__");
743+
Builder.defineMacro("__BFP__");
744+
// FIXME: __BOOL__ should not be defined under -std=c89.
745+
Builder.defineMacro("__BOOL__");
746+
Builder.defineMacro("__LONGNAME__");
747+
Builder.defineMacro("__MVS__");
748+
Builder.defineMacro("__THW_370__");
749+
Builder.defineMacro("__THW_BIG_ENDIAN__");
750+
Builder.defineMacro("__TOS_390__");
751+
Builder.defineMacro("__TOS_MVS__");
752+
Builder.defineMacro("__XPLINK__");
753+
754+
if (this->PointerWidth == 64)
755+
Builder.defineMacro("__64BIT__");
756+
757+
if (Opts.CPlusPlus) {
758+
Builder.defineMacro("__DLL__");
759+
// _XOPEN_SOURCE=600 is required to build libcxx.
760+
Builder.defineMacro("_XOPEN_SOURCE", "600");
761+
}
762+
763+
if (Opts.GNUMode) {
764+
Builder.defineMacro("_MI_BUILTIN");
765+
Builder.defineMacro("_EXT");
766+
}
767+
768+
if (Opts.CPlusPlus && Opts.WChar) {
769+
// Macro __wchar_t is defined so that the wchar_t data
770+
// type is not declared as a typedef in system headers.
771+
Builder.defineMacro("__wchar_t");
772+
}
773+
}
774+
775+
public:
776+
ZOSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
777+
: OSTargetInfo<Target>(Triple, Opts) {}
778+
};
779+
731780
void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
732781
MacroBuilder &Builder);
733782

clang/test/Preprocessor/init-zos.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS %s
2+
// RUN: %clang_cc1 -x c++ -std=gnu++14 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS -check-prefix S390X-ZOS-GNUXX %s
3+
4+
// S390X-ZOS-GNUXX:#define _EXT 1
5+
// S390X-ZOS:#define _LONG_LONG 1
6+
// S390X-ZOS-GNUXX:#define _MI_BUILTIN 1
7+
// S390X-ZOS:#define _OPEN_DEFAULT 1
8+
// S390X-ZOS:#define _UNIX03_WITHDRAWN 1
9+
// S390X-ZOS-GNUXX:#define _XOPEN_SOURCE 600
10+
// S390X-ZOS:#define __370__ 1
11+
// S390X-ZOS:#define __64BIT__ 1
12+
// S390X-ZOS:#define __BFP__ 1
13+
// S390X-ZOS:#define __BOOL__ 1
14+
// S390X-ZOS-GNUXX:#define __DLL__ 1
15+
// S390X-ZOS:#define __LONGNAME__ 1
16+
// S390X-ZOS:#define __MVS__ 1
17+
// S390X-ZOS:#define __THW_370__ 1
18+
// S390X-ZOS:#define __THW_BIG_ENDIAN__ 1
19+
// S390X-ZOS:#define __TOS_390__ 1
20+
// S390X-ZOS:#define __TOS_MVS__ 1
21+
// S390X-ZOS:#define __XPLINK__ 1
22+
// S390X-ZOS-GNUXX:#define __wchar_t 1

0 commit comments

Comments
 (0)