From 8b0a8c84da2030ee8f4440d5b60a8033de691222 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Wed, 25 Apr 2007 14:27:10 +0000 Subject: Implement aliases. This fixes PR1017 and it's dependent bugs. CFE part will follow. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36435 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AsmParser/Lexer.l | 1 + lib/AsmParser/llvmAsmParser.y | 52 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 7 deletions(-) (limited to 'lib/AsmParser') diff --git a/lib/AsmParser/Lexer.l b/lib/AsmParser/Lexer.l index d75d070..382ce24 100644 --- a/lib/AsmParser/Lexer.l +++ b/lib/AsmParser/Lexer.l @@ -222,6 +222,7 @@ datalayout { return DATALAYOUT; } volatile { return VOLATILE; } align { return ALIGN; } section { return SECTION; } +alias { return ALIAS; } module { return MODULE; } asm { return ASM_TOK; } sideeffect { return SIDEEFFECT; } diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 2b08d3a..17ca06f 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -1004,6 +1004,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) { %type OptSideEffect // 'sideeffect' or not. %type GVInternalLinkage GVExternalLinkage %type FunctionDefineLinkage FunctionDeclareLinkage +%type AliasLinkage %type GVVisibilityStyle // ValueRef - Unresolved reference to a definition or BB @@ -1035,12 +1036,12 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) { %token LOCALVAR GLOBALVAR LABELSTR STRINGCONSTANT ATSTRINGCONSTANT %type LocalName OptLocalName OptLocalAssign -%type GlobalName OptGlobalAssign +%type GlobalName OptGlobalAssign GlobalAssign %type OptAlign OptCAlign %type OptSection SectionString %token ZEROINITIALIZER TRUETOK FALSETOK BEGINTOK ENDTOK -%token DECLARE DEFINE GLOBAL CONSTANT SECTION VOLATILE THREAD_LOCAL +%token DECLARE DEFINE GLOBAL CONSTANT SECTION ALIAS VOLATILE THREAD_LOCAL %token TO DOTDOTDOT NULL_TOK UNDEF INTERNAL LINKONCE WEAK APPENDING %token DLLIMPORT DLLEXPORT EXTERN_WEAK %token OPAQUE EXTERNAL TARGET TRIPLE ALIGN @@ -1136,15 +1137,17 @@ OptLocalAssign : LocalName '=' { GlobalName : GLOBALVAR | ATSTRINGCONSTANT; -OptGlobalAssign : GlobalName '=' { - $$ = $1; - CHECK_FOR_ERROR - } +OptGlobalAssign : GlobalAssign | /*empty*/ { $$ = 0; CHECK_FOR_ERROR }; +GlobalAssign : GlobalName '=' { + $$ = $1; + CHECK_FOR_ERROR + } + GVInternalLinkage : INTERNAL { $$ = GlobalValue::InternalLinkage; } | WEAK { $$ = GlobalValue::WeakLinkage; } @@ -1161,6 +1164,7 @@ GVExternalLinkage GVVisibilityStyle : /*empty*/ { $$ = GlobalValue::DefaultVisibility; } + | DEFAULT { $$ = GlobalValue::DefaultVisibility; } | HIDDEN { $$ = GlobalValue::HiddenVisibility; } ; @@ -1170,7 +1174,7 @@ FunctionDeclareLinkage | EXTERN_WEAK { $$ = GlobalValue::ExternalWeakLinkage; } ; -FunctionDefineLinkage +FunctionDefineLinkage : /*empty*/ { $$ = GlobalValue::ExternalLinkage; } | INTERNAL { $$ = GlobalValue::InternalLinkage; } | LINKONCE { $$ = GlobalValue::LinkOnceLinkage; } @@ -1178,6 +1182,12 @@ FunctionDefineLinkage | DLLEXPORT { $$ = GlobalValue::DLLExportLinkage; } ; +AliasLinkage + : /*empty*/ { $$ = GlobalValue::ExternalLinkage; } + | WEAK { $$ = GlobalValue::WeakLinkage; } + | INTERNAL { $$ = GlobalValue::InternalLinkage; } + ; + OptCallingConv : /*empty*/ { $$ = CallingConv::C; } | CCC_TOK { $$ = CallingConv::C; } | FASTCC_TOK { $$ = CallingConv::Fast; } | @@ -2031,6 +2041,34 @@ Definition CurGV = 0; CHECK_FOR_ERROR } + | OptGlobalAssign GVVisibilityStyle ALIAS AliasLinkage ResultTypes SymbolicValueRef { + std::string Name($1); + if (Name.empty()) + GEN_ERROR("Alias name cannot be empty") + const PointerType *PFTy = 0; + const FunctionType *Ty = 0; + Value* V = 0; + const Type* VTy = 0; + if (!(PFTy = dyn_cast($5->get())) || + !(Ty = dyn_cast(PFTy->getElementType()))) { + VTy = $5->get(); + V = getExistingVal(VTy, $6); + } else { + VTy = PFTy; + V = getExistingVal(PFTy, $6); + } + if (V == 0) + GEN_ERROR(std::string("Invalid aliasee for alias: ") + $1); + GlobalValue* Aliasee; + if (Aliasee = dyn_cast(V)) { + GlobalAlias* GA = new GlobalAlias(VTy, $4, Name, Aliasee, CurModule.CurrentModule); + GA->setVisibility($2); + InsertValue(GA, CurModule.Values); + } else + GEN_ERROR("Aliases can be created only to global values"); + CHECK_FOR_ERROR + delete $5; + } | TARGET TargetDefinition { CHECK_FOR_ERROR } -- cgit v1.1