Add fastcall/stdcall attribute support
Generate CallingConv::Fast when fastcall attribute is present llvm-svn: 48017
This commit is contained in:
parent
47d774b2c8
commit
0a6192cfb8
|
@ -15,6 +15,7 @@
|
||||||
#include "CodeGenModule.h"
|
#include "CodeGenModule.h"
|
||||||
#include "clang/Basic/TargetInfo.h"
|
#include "clang/Basic/TargetInfo.h"
|
||||||
#include "clang/AST/AST.h"
|
#include "clang/AST/AST.h"
|
||||||
|
#include "llvm/CallingConv.h"
|
||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/Function.h"
|
#include "llvm/Function.h"
|
||||||
|
@ -76,6 +77,9 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD) {
|
||||||
else if (FD->getStorageClass() == FunctionDecl::Static)
|
else if (FD->getStorageClass() == FunctionDecl::Static)
|
||||||
CurFn->setLinkage(llvm::Function::InternalLinkage);
|
CurFn->setLinkage(llvm::Function::InternalLinkage);
|
||||||
|
|
||||||
|
if (FD->getAttr<FastCallAttr>())
|
||||||
|
CurFn->setCallingConv(llvm::CallingConv::Fast);
|
||||||
|
|
||||||
if (const VisibilityAttr *attr = FD->getAttr<VisibilityAttr>())
|
if (const VisibilityAttr *attr = FD->getAttr<VisibilityAttr>())
|
||||||
CurFn->setVisibility(attr->getVisibility());
|
CurFn->setVisibility(attr->getVisibility());
|
||||||
// FIXME: else handle -fvisibility
|
// FIXME: else handle -fvisibility
|
||||||
|
|
|
@ -65,11 +65,13 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
|
||||||
if (!memcmp(Str, "aligned", 7)) return AT_aligned;
|
if (!memcmp(Str, "aligned", 7)) return AT_aligned;
|
||||||
if (!memcmp(Str, "nothrow", 7)) return AT_nothrow;
|
if (!memcmp(Str, "nothrow", 7)) return AT_nothrow;
|
||||||
if (!memcmp(Str, "nonnull", 7)) return AT_nonnull;
|
if (!memcmp(Str, "nonnull", 7)) return AT_nonnull;
|
||||||
|
if (!memcmp(Str, "stdcall", 7)) return AT_stdcall;
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
if (!memcmp(Str, "annotate", 8)) return AT_annotate;
|
if (!memcmp(Str, "annotate", 8)) return AT_annotate;
|
||||||
if (!memcmp(Str, "noreturn", 8)) return AT_noreturn;
|
if (!memcmp(Str, "noreturn", 8)) return AT_noreturn;
|
||||||
if (!memcmp(Str, "noinline", 8)) return AT_noinline;
|
if (!memcmp(Str, "noinline", 8)) return AT_noinline;
|
||||||
|
if (!memcmp(Str, "fastcall", 8)) return AT_fastcall;
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
if (!memcmp(Str, "dllimport", 9)) return AT_dllimport;
|
if (!memcmp(Str, "dllimport", 9)) return AT_dllimport;
|
||||||
|
|
|
@ -280,6 +280,8 @@ private:
|
||||||
void HandleVisibilityAttribute(Decl *d, AttributeList *rawAttr);
|
void HandleVisibilityAttribute(Decl *d, AttributeList *rawAttr);
|
||||||
void HandleNothrowAttribute(Decl *d, AttributeList *rawAttr);
|
void HandleNothrowAttribute(Decl *d, AttributeList *rawAttr);
|
||||||
void HandleFormatAttribute(Decl *d, AttributeList *rawAttr);
|
void HandleFormatAttribute(Decl *d, AttributeList *rawAttr);
|
||||||
|
void HandleStdCallAttribute(Decl *d, AttributeList *rawAttr);
|
||||||
|
void HandleFastCallAttribute(Decl *d, AttributeList *rawAttr);
|
||||||
|
|
||||||
void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
|
void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
|
||||||
bool &IncompleteImpl);
|
bool &IncompleteImpl);
|
||||||
|
@ -501,7 +503,7 @@ public:
|
||||||
SourceLocation *CommaLocs,
|
SourceLocation *CommaLocs,
|
||||||
SourceLocation BuiltinLoc,
|
SourceLocation BuiltinLoc,
|
||||||
SourceLocation RParenLoc);
|
SourceLocation RParenLoc);
|
||||||
|
|
||||||
// __builtin_va_arg(expr, type)
|
// __builtin_va_arg(expr, type)
|
||||||
virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
|
virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
|
||||||
ExprTy *expr, TypeTy *type,
|
ExprTy *expr, TypeTy *type,
|
||||||
|
|
|
@ -1811,6 +1811,12 @@ void Sema::HandleDeclAttribute(Decl *New, AttributeList *Attr) {
|
||||||
case AttributeList::AT_nothrow:
|
case AttributeList::AT_nothrow:
|
||||||
HandleNothrowAttribute(New, Attr);
|
HandleNothrowAttribute(New, Attr);
|
||||||
break;
|
break;
|
||||||
|
case AttributeList::AT_stdcall:
|
||||||
|
HandleStdCallAttribute(New, Attr);
|
||||||
|
break;
|
||||||
|
case AttributeList::AT_fastcall:
|
||||||
|
HandleFastCallAttribute(New, Attr);
|
||||||
|
break;
|
||||||
case AttributeList::AT_aligned:
|
case AttributeList::AT_aligned:
|
||||||
HandleAlignedAttribute(New, Attr);
|
HandleAlignedAttribute(New, Attr);
|
||||||
break;
|
break;
|
||||||
|
@ -2073,6 +2079,28 @@ void Sema::HandleDLLExportAttribute(Decl *d, AttributeList *rawAttr) {
|
||||||
d->addAttr(new DLLExportAttr());
|
d->addAttr(new DLLExportAttr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Sema::HandleStdCallAttribute(Decl *d, AttributeList *rawAttr) {
|
||||||
|
// check the attribute arguments.
|
||||||
|
if (rawAttr->getNumArgs() != 0) {
|
||||||
|
Diag(rawAttr->getLoc(), diag::err_attribute_wrong_number_arguments,
|
||||||
|
std::string("0"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->addAttr(new StdCallAttr());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sema::HandleFastCallAttribute(Decl *d, AttributeList *rawAttr) {
|
||||||
|
// check the attribute arguments.
|
||||||
|
if (rawAttr->getNumArgs() != 0) {
|
||||||
|
Diag(rawAttr->getLoc(), diag::err_attribute_wrong_number_arguments,
|
||||||
|
std::string("0"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->addAttr(new FastCallAttr());
|
||||||
|
}
|
||||||
|
|
||||||
void Sema::HandleNothrowAttribute(Decl *d, AttributeList *rawAttr) {
|
void Sema::HandleNothrowAttribute(Decl *d, AttributeList *rawAttr) {
|
||||||
// check the attribute arguments.
|
// check the attribute arguments.
|
||||||
if (rawAttr->getNumArgs() != 0) {
|
if (rawAttr->getNumArgs() != 0) {
|
||||||
|
|
|
@ -34,7 +34,9 @@ public:
|
||||||
DLLExport,
|
DLLExport,
|
||||||
NoThrow,
|
NoThrow,
|
||||||
Format,
|
Format,
|
||||||
Visibility
|
Visibility,
|
||||||
|
FastCall,
|
||||||
|
StdCall
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -196,6 +198,26 @@ public:
|
||||||
static bool classof(const DLLExportAttr *A) { return true; }
|
static bool classof(const DLLExportAttr *A) { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class FastCallAttr : public Attr {
|
||||||
|
public:
|
||||||
|
FastCallAttr() : Attr(FastCall) {}
|
||||||
|
|
||||||
|
// Implement isa/cast/dyncast/etc.
|
||||||
|
|
||||||
|
static bool classof(const Attr *A) { return A->getKind() == FastCall; }
|
||||||
|
static bool classof(const FastCallAttr *A) { return true; }
|
||||||
|
};
|
||||||
|
|
||||||
|
class StdCallAttr : public Attr {
|
||||||
|
public:
|
||||||
|
StdCallAttr() : Attr(StdCall) {}
|
||||||
|
|
||||||
|
// Implement isa/cast/dyncast/etc.
|
||||||
|
|
||||||
|
static bool classof(const Attr *A) { return A->getKind() == StdCall; }
|
||||||
|
static bool classof(const StdCallAttr *A) { return true; }
|
||||||
|
};
|
||||||
|
|
||||||
} // end namespace clang
|
} // end namespace clang
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -60,6 +60,8 @@ public:
|
||||||
AT_dllimport,
|
AT_dllimport,
|
||||||
AT_dllexport,
|
AT_dllexport,
|
||||||
AT_visibility,
|
AT_visibility,
|
||||||
|
AT_fastcall,
|
||||||
|
AT_stdcall,
|
||||||
AT_nothrow,
|
AT_nothrow,
|
||||||
AT_noinline,
|
AT_noinline,
|
||||||
AT_warn_unused_result
|
AT_warn_unused_result
|
||||||
|
|
Loading…
Reference in New Issue