[cfe-commits] r138470 - in /cfe/trunk: lib/Basic/Targets.cpp test/Driver/le32-unknown-nacl.cpp
Ivan Krasin
krasin at chromium.org
Wed Aug 24 13:22:22 PDT 2011
Author: krasin
Date: Wed Aug 24 15:22:22 2011
New Revision: 138470
URL: http://llvm.org/viewvc/llvm-project?rev=138470&view=rev
Log:
Add PNaCl TargetInfo.
Added:
cfe/trunk/test/Driver/le32-unknown-nacl.cpp
Modified:
cfe/trunk/lib/Basic/Targets.cpp
Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=138470&r1=138469&r2=138470&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Aug 24 15:22:22 2011
@@ -2843,6 +2843,70 @@
}
} // end anonymous namespace.
+namespace {
+class PNaClTargetInfo : public TargetInfo {
+public:
+ PNaClTargetInfo(const std::string& triple) : TargetInfo(triple) {
+ this->UserLabelPrefix = "";
+ this->LongAlign = 32;
+ this->LongWidth = 32;
+ this->PointerAlign = 32;
+ this->PointerWidth = 32;
+ this->IntMaxType = TargetInfo::SignedLongLong;
+ this->UIntMaxType = TargetInfo::UnsignedLongLong;
+ this->Int64Type = TargetInfo::SignedLongLong;
+ this->SizeType = TargetInfo::UnsignedInt;
+ DescriptionString = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"
+ "f32:32:32-f64:64:64-p:32:32:32-v128:32:32";
+ }
+
+ void getDefaultFeatures(const std::string &CPU,
+ llvm::StringMap<bool> &Features) const {
+ }
+ virtual void getArchDefines(const LangOptions &Opts,
+ MacroBuilder &Builder) const {
+ Builder.defineMacro("__le32__");
+ Builder.defineMacro("__pnacl__");
+ }
+ virtual void getTargetDefines(const LangOptions &Opts,
+ MacroBuilder &Builder) const {
+ Builder.defineMacro("__native_client__");
+ getArchDefines(Opts, Builder);
+ }
+ virtual void getTargetBuiltins(const Builtin::Info *&Records,
+ unsigned &NumRecords) const {
+ }
+ virtual const char *getVAListDeclaration() const {
+ return "typedef void* __builtin_va_list;";
+ }
+ virtual void getGCCRegNames(const char * const *&Names,
+ unsigned &NumNames) const;
+ virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
+ unsigned &NumAliases) const;
+ virtual bool validateAsmConstraint(const char *&Name,
+ TargetInfo::ConstraintInfo &Info) const {
+ return false;
+ }
+
+ virtual const char *getClobbers() const {
+ return "";
+ }
+};
+
+void PNaClTargetInfo::getGCCRegNames(const char * const *&Names,
+ unsigned &NumNames) const {
+ Names = NULL;
+ NumNames = 0;
+}
+
+void PNaClTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
+ unsigned &NumAliases) const {
+ Aliases = NULL;
+ NumAliases = 0;
+}
+} // end anonymous namespace.
+
+
//===----------------------------------------------------------------------===//
// Driver code
//===----------------------------------------------------------------------===//
@@ -2913,6 +2977,14 @@
return new MipsTargetInfo(T);
}
+ case llvm::Triple::le32:
+ switch (os) {
+ case llvm::Triple::NativeClient:
+ return new PNaClTargetInfo(T);
+ default:
+ return NULL;
+ }
+
case llvm::Triple::ppc:
if (Triple.isOSDarwin())
return new DarwinPPC32TargetInfo(T);
Added: cfe/trunk/test/Driver/le32-unknown-nacl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/le32-unknown-nacl.cpp?rev=138470&view=auto
==============================================================================
--- cfe/trunk/test/Driver/le32-unknown-nacl.cpp (added)
+++ cfe/trunk/test/Driver/le32-unknown-nacl.cpp Wed Aug 24 15:22:22 2011
@@ -0,0 +1,86 @@
+// RUN: %clang -ccc-host-triple le32-unknown-nacl -ccc-echo %s -emit-llvm -c -o /tmp/OUTPUTNAME 2> %t.log
+
+// Make sure we used clang.
+// RUN: grep 'clang\(-[0-9.]\+\)\?\(\.[Ee][Xx][Ee]\)\?" -cc1 .*le32-unknown-nacl.c' %t.log
+
+// RUN: llvm-dis < /tmp/OUTPUTNAME | FileCheck %s
+
+// Check platform defines
+#include <stddef.h>
+
+extern "C" {
+
+#ifdef __native_client__
+void __native_client__defined() {
+ // CHECK: __native_client__defined
+}
+#endif
+
+#ifdef __le32__
+void __le32__defined() {
+ // CHECK: __le32__defined
+}
+#endif
+
+#ifdef __pnacl__
+void __pnacl__defined() {
+ // CHECK: __pnacl__defined
+}
+#endif
+
+// Check types
+
+// CHECK: signext i8 @check_char()
+char check_char() { return 0; }
+
+// CHECK: signext i16 @check_short()
+short check_short() { return 0; }
+
+// CHECK: i32 @check_int()
+int check_int() { return 0; }
+
+// CHECK: i32 @check_long()
+long check_long() { return 0; }
+
+// CHECK: i64 @check_longlong()
+long long check_longlong() { return 0; }
+
+// CHECK: zeroext i8 @check_uchar()
+unsigned char check_uchar() { return 0; }
+
+// CHECK: zeroext i16 @check_ushort()
+unsigned short check_ushort() { return 0; }
+
+// CHECK: i32 @check_uint()
+unsigned int check_uint() { return 0; }
+
+// CHECK: i32 @check_ulong()
+unsigned long check_ulong() { return 0; }
+
+// CHECK: i64 @check_ulonglong()
+unsigned long long check_ulonglong() { return 0; }
+
+// CHECK: i32 @check_size_t()
+size_t check_size_t() { return 0; }
+
+// CHECK: float @check_float()
+float check_float() { return 0; }
+
+// CHECK: double @check_double()
+double check_double() { return 0; }
+
+}
+
+// Check that pointers are 32-bit.
+
+template<int> void Switch();
+template<> void Switch<4>();
+template<> void Switch<8>();
+
+void check_pointer_size() {
+ // CHECK: SwitchILi4
+ Switch<sizeof(void*)>();
+
+ // CHECK: SwitchILi8
+ Switch<sizeof(long long)>();
+}
More information about the cfe-commits
mailing list