diff options
author | Anton Korobeynikov <asl@math.spbu.ru> | 2007-04-25 14:27:10 +0000 |
---|---|---|
committer | Anton Korobeynikov <asl@math.spbu.ru> | 2007-04-25 14:27:10 +0000 |
commit | 8b0a8c84da2030ee8f4440d5b60a8033de691222 (patch) | |
tree | 7b780ed0cf12403faeac0e65fb16bca29fda5dbf /lib/AsmParser | |
parent | 24a3cc4c83e5edb25fadf7b8979a26b4451795c6 (diff) | |
download | external_llvm-8b0a8c84da2030ee8f4440d5b60a8033de691222.zip external_llvm-8b0a8c84da2030ee8f4440d5b60a8033de691222.tar.gz external_llvm-8b0a8c84da2030ee8f4440d5b60a8033de691222.tar.bz2 |
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
Diffstat (limited to 'lib/AsmParser')
-rw-r--r-- | lib/AsmParser/Lexer.l | 1 | ||||
-rw-r--r-- | lib/AsmParser/llvmAsmParser.y | 52 |
2 files changed, 46 insertions, 7 deletions
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 <BoolVal> OptSideEffect // 'sideeffect' or not. %type <Linkage> GVInternalLinkage GVExternalLinkage %type <Linkage> FunctionDefineLinkage FunctionDeclareLinkage +%type <Linkage> AliasLinkage %type <Visibility> GVVisibilityStyle // ValueRef - Unresolved reference to a definition or BB @@ -1035,12 +1036,12 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) { %token<StrVal> LOCALVAR GLOBALVAR LABELSTR STRINGCONSTANT ATSTRINGCONSTANT %type <StrVal> LocalName OptLocalName OptLocalAssign -%type <StrVal> GlobalName OptGlobalAssign +%type <StrVal> GlobalName OptGlobalAssign GlobalAssign %type <UIntVal> OptAlign OptCAlign %type <StrVal> 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<PointerType>($5->get())) || + !(Ty = dyn_cast<FunctionType>(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<GlobalValue>(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 } |