From 72244b6e4f711566b749e018af4b18feb4c45108 Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Thu, 5 Jul 2012 16:06:06 +0000 Subject: [PATCH] MIPS: Define __mips16 macro if -mips16 option is provided. llvm-svn: 159753 --- clang/lib/Basic/Targets.cpp | 8 ++++++++ clang/test/Preprocessor/init.c | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 713396c3abc1..3eaa65177c73 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -3599,6 +3599,7 @@ namespace { class MipsTargetInfoBase : public TargetInfo { static const Builtin::Info BuiltinInfo[]; std::string CPU; + bool IsMips16; enum MipsFloatABI { HardFloat, SingleFloat, SoftFloat } FloatABI; @@ -3612,6 +3613,7 @@ public: const std::string& CPUStr) : TargetInfo(triple), CPU(CPUStr), + IsMips16(false), FloatABI(HardFloat), ABI(ABIStr) {} @@ -3643,6 +3645,9 @@ public: break; } + if (IsMips16) + Builder.defineMacro("__mips16", Twine(1)); + Builder.defineMacro("_MIPS_SZPTR", Twine(getPointerWidth(0))); Builder.defineMacro("_MIPS_SZINT", Twine(getIntWidth())); Builder.defineMacro("_MIPS_SZLONG", Twine(getLongWidth())); @@ -3722,6 +3727,7 @@ public: } virtual void HandleTargetFeatures(std::vector &Features) { + IsMips16 = false; FloatABI = HardFloat; for (std::vector::iterator it = Features.begin(), @@ -3730,6 +3736,8 @@ public: FloatABI = SingleFloat; else if (*it == "+soft-float") FloatABI = SoftFloat; + else if (*it == "+mips16") + IsMips16 = true; } // Remove front-end specific option. diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 9694aad3f341..29ad682827d3 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -876,6 +876,18 @@ // MIPS-FABI-SINGLE:#define __mips_hard_float 1 // MIPS-FABI-SINGLE:#define __mips_single_float 1 // +// Check MIPS features macros +// +// RUN: %clang_cc1 -target-feature +mips16 \ +// RUN: -E -dM -triple=mips-none-none < /dev/null \ +// RUN: | FileCheck -check-prefix MIPS16 %s +// MIPS16:#define __mips16 1 +// +// RUN: %clang_cc1 -target-feature -mips16 \ +// RUN: -E -dM -triple=mips-none-none < /dev/null \ +// RUN: | FileCheck -check-prefix NOMIPS16 %s +// NOMIPS16-NOT:#define __mips16 1 +// // RUN: %clang_cc1 -E -dM -ffreestanding -triple=msp430-none-none < /dev/null | FileCheck -check-prefix MSP430 %s // // MSP430:#define MSP430 1