mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
Refactor duplicated code. NFC.
Linkage is always followed by visibility and dll storage. llvm-svn: 269286
This commit is contained in:
parent
135b316516
commit
f75c98257e
@ -454,11 +454,8 @@ bool LLParser::ParseUnnamedGlobal() {
|
||||
unsigned Linkage, Visibility, DLLStorageClass;
|
||||
GlobalVariable::ThreadLocalMode TLM;
|
||||
bool UnnamedAddr;
|
||||
if (ParseOptionalLinkage(Linkage, HasLinkage) ||
|
||||
ParseOptionalVisibility(Visibility) ||
|
||||
ParseOptionalDLLStorageClass(DLLStorageClass) ||
|
||||
ParseOptionalThreadLocal(TLM) ||
|
||||
parseOptionalUnnamedAddr(UnnamedAddr))
|
||||
if (ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass) ||
|
||||
ParseOptionalThreadLocal(TLM) || parseOptionalUnnamedAddr(UnnamedAddr))
|
||||
return true;
|
||||
|
||||
if (Lex.getKind() != lltok::kw_alias && Lex.getKind() != lltok::kw_ifunc)
|
||||
@ -484,11 +481,8 @@ bool LLParser::ParseNamedGlobal() {
|
||||
GlobalVariable::ThreadLocalMode TLM;
|
||||
bool UnnamedAddr;
|
||||
if (ParseToken(lltok::equal, "expected '=' in global variable") ||
|
||||
ParseOptionalLinkage(Linkage, HasLinkage) ||
|
||||
ParseOptionalVisibility(Visibility) ||
|
||||
ParseOptionalDLLStorageClass(DLLStorageClass) ||
|
||||
ParseOptionalThreadLocal(TLM) ||
|
||||
parseOptionalUnnamedAddr(UnnamedAddr))
|
||||
ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass) ||
|
||||
ParseOptionalThreadLocal(TLM) || parseOptionalUnnamedAddr(UnnamedAddr))
|
||||
return true;
|
||||
|
||||
if (Lex.getKind() != lltok::kw_alias && Lex.getKind() != lltok::kw_ifunc)
|
||||
@ -1535,10 +1529,14 @@ static unsigned parseOptionalLinkageAux(lltok::Kind Kind, bool &HasLinkage) {
|
||||
/// ::= 'common'
|
||||
/// ::= 'extern_weak'
|
||||
/// ::= 'external'
|
||||
bool LLParser::ParseOptionalLinkage(unsigned &Res, bool &HasLinkage) {
|
||||
bool LLParser::ParseOptionalLinkage(unsigned &Res, bool &HasLinkage,
|
||||
unsigned &Visibility,
|
||||
unsigned &DLLStorageClass) {
|
||||
Res = parseOptionalLinkageAux(Lex.getKind(), HasLinkage);
|
||||
if (HasLinkage)
|
||||
Lex.Lex();
|
||||
ParseOptionalVisibility(Visibility);
|
||||
ParseOptionalDLLStorageClass(DLLStorageClass);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1548,15 +1546,22 @@ bool LLParser::ParseOptionalLinkage(unsigned &Res, bool &HasLinkage) {
|
||||
/// ::= 'hidden'
|
||||
/// ::= 'protected'
|
||||
///
|
||||
bool LLParser::ParseOptionalVisibility(unsigned &Res) {
|
||||
void LLParser::ParseOptionalVisibility(unsigned &Res) {
|
||||
switch (Lex.getKind()) {
|
||||
default: Res = GlobalValue::DefaultVisibility; return false;
|
||||
case lltok::kw_default: Res = GlobalValue::DefaultVisibility; break;
|
||||
case lltok::kw_hidden: Res = GlobalValue::HiddenVisibility; break;
|
||||
case lltok::kw_protected: Res = GlobalValue::ProtectedVisibility; break;
|
||||
default:
|
||||
Res = GlobalValue::DefaultVisibility;
|
||||
return;
|
||||
case lltok::kw_default:
|
||||
Res = GlobalValue::DefaultVisibility;
|
||||
break;
|
||||
case lltok::kw_hidden:
|
||||
Res = GlobalValue::HiddenVisibility;
|
||||
break;
|
||||
case lltok::kw_protected:
|
||||
Res = GlobalValue::ProtectedVisibility;
|
||||
break;
|
||||
}
|
||||
Lex.Lex();
|
||||
return false;
|
||||
}
|
||||
|
||||
/// ParseOptionalDLLStorageClass
|
||||
@ -1564,14 +1569,19 @@ bool LLParser::ParseOptionalVisibility(unsigned &Res) {
|
||||
/// ::= 'dllimport'
|
||||
/// ::= 'dllexport'
|
||||
///
|
||||
bool LLParser::ParseOptionalDLLStorageClass(unsigned &Res) {
|
||||
void LLParser::ParseOptionalDLLStorageClass(unsigned &Res) {
|
||||
switch (Lex.getKind()) {
|
||||
default: Res = GlobalValue::DefaultStorageClass; return false;
|
||||
case lltok::kw_dllimport: Res = GlobalValue::DLLImportStorageClass; break;
|
||||
case lltok::kw_dllexport: Res = GlobalValue::DLLExportStorageClass; break;
|
||||
default:
|
||||
Res = GlobalValue::DefaultStorageClass;
|
||||
return;
|
||||
case lltok::kw_dllimport:
|
||||
Res = GlobalValue::DLLImportStorageClass;
|
||||
break;
|
||||
case lltok::kw_dllexport:
|
||||
Res = GlobalValue::DLLExportStorageClass;
|
||||
break;
|
||||
}
|
||||
Lex.Lex();
|
||||
return false;
|
||||
}
|
||||
|
||||
/// ParseOptionalCallingConv
|
||||
@ -4469,13 +4479,11 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
|
||||
unsigned DLLStorageClass;
|
||||
AttrBuilder RetAttrs;
|
||||
unsigned CC;
|
||||
bool HasLinkage;
|
||||
Type *RetType = nullptr;
|
||||
LocTy RetTypeLoc = Lex.getLoc();
|
||||
if (ParseOptionalLinkage(Linkage) ||
|
||||
ParseOptionalVisibility(Visibility) ||
|
||||
ParseOptionalDLLStorageClass(DLLStorageClass) ||
|
||||
ParseOptionalCallingConv(CC) ||
|
||||
ParseOptionalReturnAttrs(RetAttrs) ||
|
||||
if (ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass) ||
|
||||
ParseOptionalCallingConv(CC) || ParseOptionalReturnAttrs(RetAttrs) ||
|
||||
ParseType(RetType, RetTypeLoc, true /*void allowed*/))
|
||||
return true;
|
||||
|
||||
|
@ -232,12 +232,10 @@ namespace llvm {
|
||||
bool ParseOptionalAddrSpace(unsigned &AddrSpace);
|
||||
bool ParseOptionalParamAttrs(AttrBuilder &B);
|
||||
bool ParseOptionalReturnAttrs(AttrBuilder &B);
|
||||
bool ParseOptionalLinkage(unsigned &Linkage, bool &HasLinkage);
|
||||
bool ParseOptionalLinkage(unsigned &Linkage) {
|
||||
bool HasLinkage; return ParseOptionalLinkage(Linkage, HasLinkage);
|
||||
}
|
||||
bool ParseOptionalVisibility(unsigned &Visibility);
|
||||
bool ParseOptionalDLLStorageClass(unsigned &DLLStorageClass);
|
||||
bool ParseOptionalLinkage(unsigned &Linkage, bool &HasLinkage,
|
||||
unsigned &Visibility, unsigned &DLLStorageClass);
|
||||
void ParseOptionalVisibility(unsigned &Visibility);
|
||||
void ParseOptionalDLLStorageClass(unsigned &DLLStorageClass);
|
||||
bool ParseOptionalCallingConv(unsigned &CC);
|
||||
bool ParseOptionalAlignment(unsigned &Alignment);
|
||||
bool ParseOptionalDerefAttrBytes(lltok::Kind AttrKind, uint64_t &Bytes);
|
||||
|
Loading…
x
Reference in New Issue
Block a user