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 | 373feca7a02a75e5ab4788ac77fd061883c23ff6 (patch) | |
tree | 3084ab3da63e267bd5a108207712bd64fa0f3291 /clang/lib | |
parent | fbd7c2d3b2ae2447c933c55a9bdb07d4f01bd95e (diff) | |
download | bcm5719-llvm-373feca7a02a75e5ab4788ac77fd061883c23ff6.tar.gz bcm5719-llvm-373feca7a02a75e5ab4788ac77fd061883c23ff6.zip |
First step in implementation of mips16 and nomips16 attributes.
Waiting for new llvm attribute code for the next step.
llvm-svn: 172626
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/TargetInfo.cpp | 7 | ||||
-rw-r--r-- | clang/lib/Sema/TargetAttributesSema.cpp | 51 |
2 files changed, 58 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index 1b44352b389..9811143c8d6 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -3884,6 +3884,13 @@ public: return 29; } + void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV, + CodeGen::CodeGenModule &CGM) const { + // + // can fill this in when new attribute work in llvm is done. + // attributes mips16 and nomips16 need to be handled here. + // + } bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF, llvm::Value *Address) const; diff --git a/clang/lib/Sema/TargetAttributesSema.cpp b/clang/lib/Sema/TargetAttributesSema.cpp index 94f240c49ae..1b8889de822 100644 --- a/clang/lib/Sema/TargetAttributesSema.cpp +++ b/clang/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); } |