diff options
author | Reed Kotler <rkotler@mips.com> | 2013-01-16 17:10:28 +0000 |
---|---|---|
committer | Reed Kotler <rkotler@mips.com> | 2013-01-16 17:10:28 +0000 |
commit | 7dfd18275259df609f8574a25302fc73a000aa64 (patch) | |
tree | e2b9b36fdaeaff541a3fc653d0cea0905c9556b8 /lib/Sema/TargetAttributesSema.cpp | |
parent | 93cf969df9afb22028aa8b4d575fa55681d1ec56 (diff) |
First step in implementation of mips16 and nomips16 attributes.
Waiting for new llvm attribute code for the next step.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172626 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/TargetAttributesSema.cpp')
-rw-r--r-- | lib/Sema/TargetAttributesSema.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/Sema/TargetAttributesSema.cpp b/lib/Sema/TargetAttributesSema.cpp index 94f240c49a..1b8889de82 100644 --- a/lib/Sema/TargetAttributesSema.cpp +++ b/lib/Sema/TargetAttributesSema.cpp @@ -262,6 +262,54 @@ namespace { }; } +static void HandleMips16Attr(Decl *D, const AttributeList &Attr, Sema &S) { + // check the attribute arguments. + if (Attr.hasParameterOrArguments()) { + S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0; + return; + } + // Attribute can only be applied to function types. + if (!isa<FunctionDecl>(D)) { + S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type) + << Attr.getName() << /* function */0; + return; + } + D->addAttr(::new (S.Context) Mips16Attr(Attr.getRange(), S.Context)); +} + +static void HandleNoMips16Attr(Decl *D, const AttributeList &Attr, Sema &S) { + // check the attribute arguments. + if (Attr.hasParameterOrArguments()) { + S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0; + return; + } + // Attribute can only be applied to function types. + if (!isa<FunctionDecl>(D)) { + S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type) + << Attr.getName() << /* function */0; + return; + } + D->addAttr(::new (S.Context) NoMips16Attr(Attr.getRange(), S.Context)); +} + +namespace { + class MipsAttributesSema : public TargetAttributesSema { + public: + MipsAttributesSema() { } + bool ProcessDeclAttribute(Scope *scope, Decl *D, const AttributeList &Attr, + Sema &S) const { + if (Attr.getName()->getName() == "mips16") { + HandleMips16Attr(D, Attr, S); + return true; + } else if (Attr.getName()->getName() == "nomips16") { + HandleNoMips16Attr(D, Attr, S); + return true; + } + return false; + } + }; +} + const TargetAttributesSema &Sema::getTargetAttributesSema() const { if (TheTargetAttributesSema) return *TheTargetAttributesSema; @@ -275,6 +323,9 @@ const TargetAttributesSema &Sema::getTargetAttributesSema() const { case llvm::Triple::x86: case llvm::Triple::x86_64: return *(TheTargetAttributesSema = new X86AttributesSema); + case llvm::Triple::mips: + case llvm::Triple::mipsel: + return *(TheTargetAttributesSema = new MipsAttributesSema); default: return *(TheTargetAttributesSema = new TargetAttributesSema); } |