diff options
31 files changed, 597 insertions, 168 deletions
diff --git a/docs/BytecodeFormat.html b/docs/BytecodeFormat.html index cc0ae7ca5f..e65ee0cba4 100644 --- a/docs/BytecodeFormat.html +++ b/docs/BytecodeFormat.html @@ -743,7 +743,6 @@ describes the latest version, 1.3):</p> <li>#3: LLVM 1.3</li> <li>#4: LLVM 1.3.x (not released)</li> <li>#5: LLVM 1.4 and newer</li> - </li> </ul> <p>Note that we plan to eventually expand the target description capabilities @@ -1082,7 +1081,11 @@ and can includes more information:</p> <td class="td_left">If this bit is set, a SectionID follows this vbr.</td> </tr> <tr> - <td><a href="#bit">bit(10-31)</a></td> + <td><a href="#bit">bit(10-12)</a></td> + <td class="td_left">Visibility style: 0=Default, 1=Hidden.</td> + </tr> + <tr> + <td><a href="#bit">bit(13-31)</a></td> <td class="td_left">Currently unassigned.</td> </tr> </tbody> @@ -1337,7 +1340,7 @@ field values of the structure.</li> </div> <!-- _______________________________________________________________________ --> -<div class="doc_subsubsection">Undef Entries</a></div> +<div class="doc_subsubsection">Undef Entries</div> <div class="doc_text"> <p>When the number of operands to the constant is one, we have an 'undef' value @@ -1345,7 +1348,7 @@ of the specified type.</p> </div> <!-- _______________________________________________________________________ --> -<div class="doc_subsubsection">Inline Assembler Entries</a></div> +<div class="doc_subsubsection">Inline Assembler Entries</div> <div class="doc_text"> <p>Inline Assembler entries are stored in the constant pool, though they are not @@ -1369,7 +1372,7 @@ of the specified type.</p> </tr> <tr> <td><a href="#uint32_vbr">uint32_vbr</a></td> - <td class="td_left">Flags</sup></td> + <td class="td_left">Flags</td> </tr> </tbody> </table> @@ -1380,7 +1383,7 @@ of the specified type.</p> </div> <!-- _______________________________________________________________________ --> -<div class="doc_subsubsection">Constant Expression Entries</a></div> +<div class="doc_subsubsection">Constant Expression Entries</div> <div class="doc_text"> @@ -1436,8 +1439,8 @@ size<br> </tr> <tr> <td><a href="#uint32_vbr">uint32_vbr</a></td> - <td class="td_left">The linkage type of the function: 0=External, 1=Weak, -2=Appending, 3=Internal, 4=LinkOnce, 5=DllImport, 6=DllExport<sup>1</sup></td> + <td class="td_left"><a href="#funclinkage_and_visibility">The linkage and + visibility</a> style field</td> </tr> <tr> <td><a href="#block">block</a></td> @@ -1470,7 +1473,34 @@ other fields will be present as the function is defined elsewhere.</li> be written. Compaction tables are only written if they will actually save bytecode space. If not, then a regular constant pool is written.</li> </ol> + +<!-- _______________________________________________________________________ --> +<div class="doc_subsubsection"><a name="funclinkage_and_visibility">Linkage and + visibility word</a> +</div> +<div class="doc_text"> + +<table> + <tbody> + <tr> + <th><b>Type</b></th> + <th class="td_left"><b>Field Description</b></th> + </tr> + <tr> + <td><a href="#bit">bit(0-15)</a></td> + <td class="td_left">The linkage type of the function: 0=External, 1=Weak, +2=Appending, 3=Internal, 4=LinkOnce, 5=DllImport, 6=DllExport<sup>1</sup></td> + </tr> + <tr> + <td><a href="#bit">bit(16-31)</a></td> + <td class="td_left">Visibility style: 0=Default, 1=Hidden.</td> + </tr> + </tbody> +</table> + +</div> </div> + <!-- _______________________________________________________________________ --> <div class="doc_subsection"><a name="compactiontable">Compaction Table</a> </div> diff --git a/docs/LangRef.html b/docs/LangRef.html index e9daca07e5..2e40842dfb 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -275,7 +275,7 @@ purposes:</p> For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'. Identifiers which require other characters in their names can be surrounded - with quotes. In this way, anything except a <tt>"</tt> character can be used + with quotes. In this way, anything except a <tt>"</tt> character can be used in a name.</li> <li>Unnamed values are represented as an unsigned numeric value with a '%' @@ -452,6 +452,13 @@ All Global Variables and Functions have one of the following types of linkage: "sections" with identical names when .o files are linked. </dd> + <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt> + <dd>The semantics of this linkage follow the ELF model: the symbol is weak + until linked, if not linked, the symbol becomes null instead of being an + undefined reference. + </dd> +</dl> + <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt> <dd>If none of the above identifiers are used, the global is externally @@ -459,17 +466,13 @@ All Global Variables and Functions have one of the following types of linkage: external symbol references. </dd> - <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt> - - <dd>"<tt>extern_weak</tt>" TBD - </dd> - <p> The next two types of linkage are targeted for Microsoft Windows platform only. They are designed to support importing (exporting) symbols from (to) DLLs. </p> + <dl> <dt><tt><b><a name="linkage_dllimport">dllimport</a></b></tt>: </dt> <dd>"<tt>dllimport</tt>" linkage causes the compiler to reference a function @@ -489,7 +492,7 @@ All Global Variables and Functions have one of the following types of linkage: </dl> -<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>" +<p><a name="linkage_external"></a>For example, since the "<tt>.LC0</tt>" variable is defined to be internal, if another module defined a "<tt>.LC0</tt>" variable and was linked with this one, one of the two would be renamed, preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are @@ -497,7 +500,7 @@ external (i.e., lacking any linkage declarations), they are accessible outside of the current module.</p> <p>It is illegal for a function <i>declaration</i> to have any linkage type other than "externally visible", <tt>dllimport</tt>, -or <tt>extern_weak</tt>.</a></p> +or <tt>extern_weak</tt>.</p> </div> @@ -676,13 +679,13 @@ a power of 2.</p> <p>Parameter attributes consist of an at sign (@) followed by either a single keyword or a comma separate list of keywords enclosed in parentheses. For - example:<pre> + example:</p><pre> %someFunc = i16 @zext (i8 @(sext) %someParam) %someFunc = i16 @zext (i8 @zext %someParam)</pre> - Note that the two function types above are unique because the parameter - has a different attribute (@sext in the first one, @zext in the second).</p> + <p>Note that the two function types above are unique because the parameter has + a different attribute (@sext in the first one, @zext in the second).</p> - <p>Currently, only the following parameter attributes are defined: + <p>Currently, only the following parameter attributes are defined:</p> <dl> <dt><tt>@zext</tt></dt> <dd>This indicates that the parameter should be zero extended just before @@ -690,7 +693,7 @@ a power of 2.</p> <dt><tt>@sext</tt></dt> <dd>This indicates that the parameter should be sign extended just before a call to this function.</dd> - </dl></p> + </dl> <p>The current motivation for parameter attributes is to enable the sign and zero extend information necessary for the C calling convention to be passed @@ -3053,7 +3056,7 @@ a pointer type, <tt>ty2</tt>.</p> <h5>Arguments:</h5> <p>The '<tt>inttoptr</tt>' instruction takes an <a href="i_integer">integer</a> value to cast, and a type to cast it to, which must be a -<a href="#t_pointer">pointer</a> type. </tt> +<a href="#t_pointer">pointer</a> type. <h5>Semantics:</h5> <p>The '<tt>inttoptr</tt>' instruction converts <tt>value</tt> to type @@ -3172,7 +3175,6 @@ yields a <a href="#t_primitive">i1</a> result, as follows: <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li> <li><tt>sle</tt>: interprets the operands as signed values and yields <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li> - </li> </ol> <p>If the operands are <a href="#t_pointer">pointer</a> typed, the pointer values are treated as integers and then compared.</p> diff --git a/include/llvm/Bytecode/BytecodeHandler.h b/include/llvm/Bytecode/BytecodeHandler.h index c693380e1d..1d95db5daf 100644 --- a/include/llvm/Bytecode/BytecodeHandler.h +++ b/include/llvm/Bytecode/BytecodeHandler.h @@ -112,6 +112,7 @@ public: const Type* ElemType, ///< The type of the global variable bool isConstant, ///< Whether the GV is constant or not GlobalValue::LinkageTypes,///< The linkage type of the GV + GlobalValue::VisibilityTypes,///< The visibility style of the GV unsigned SlotNum, ///< Slot number of GV unsigned initSlot ///< Slot number of GV's initializer (0 if none) ) {} diff --git a/include/llvm/GlobalValue.h b/include/llvm/GlobalValue.h index c3b96f2ea7..2fbbbc0437 100644 --- a/include/llvm/GlobalValue.h +++ b/include/llvm/GlobalValue.h @@ -38,14 +38,19 @@ public: ExternalWeakLinkage, /// ExternalWeak linkage description GhostLinkage /// Stand-in functions for streaming fns from BC files }; + enum VisibilityTypes { + DefaultVisibility, + HiddenVisibility + }; protected: GlobalValue(const Type *Ty, ValueTy vty, Use *Ops, unsigned NumOps, LinkageTypes linkage, const std::string &name = "") - : Constant(Ty, vty, Ops, NumOps, name), - Parent(0), Linkage(linkage), Alignment(0) { } + : Constant(Ty, vty, Ops, NumOps, name), Parent(0), + Linkage(linkage), Visibility(DefaultVisibility), Alignment(0) { } Module *Parent; LinkageTypes Linkage; // The linkage of this global + VisibilityTypes Visibility; // The visibility style of this global unsigned Alignment; // Alignment of this symbol, must be power of two std::string Section; // Section to emit this into, empty mean default public: @@ -58,6 +63,10 @@ public: assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!"); Alignment = Align; } + + VisibilityTypes getVisibility() const { return Visibility; } + bool hasHiddenVisibility() const { return Visibility == HiddenVisibility; } + void setVisibility(VisibilityTypes V) { Visibility = V; } bool hasSection() const { return !Section.empty(); } const std::string &getSection() const { return Section; } diff --git a/lib/AsmParser/Lexer.l b/lib/AsmParser/Lexer.l index 5300b3dabe..22fe64bf0d 100644 --- a/lib/AsmParser/Lexer.l +++ b/lib/AsmParser/Lexer.l @@ -203,6 +203,7 @@ weak { return WEAK; } appending { return APPENDING; } dllimport { return DLLIMPORT; } dllexport { return DLLEXPORT; } +hidden { return HIDDEN; } extern_weak { return EXTERN_WEAK; } external { return EXTERNAL; } implementation { return IMPLEMENTATION; } diff --git a/lib/AsmParser/Lexer.l.cvs b/lib/AsmParser/Lexer.l.cvs index 5300b3dabe..22fe64bf0d 100644 --- a/lib/AsmParser/Lexer.l.cvs +++ b/lib/AsmParser/Lexer.l.cvs @@ -203,6 +203,7 @@ weak { return WEAK; } appending { return APPENDING; } dllimport { return DLLIMPORT; } dllexport { return DLLEXPORT; } +hidden { return HIDDEN; } extern_weak { return EXTERN_WEAK; } external { return EXTERNAL; } implementation { return IMPLEMENTATION; } diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index b84cf25150..52d8847d32 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -210,6 +210,7 @@ static struct PerFunctionInfo { std::map<const Type*, ValueList> LateResolveValues; bool isDeclare; // Is this function a forward declararation? GlobalValue::LinkageTypes Linkage; // Linkage for forward declaration. + GlobalValue::VisibilityTypes Visibility; /// BBForwardRefs - When we see forward references to basic blocks, keep /// track of them here. @@ -220,7 +221,8 @@ static struct PerFunctionInfo { inline PerFunctionInfo() { CurrentFunction = 0; isDeclare = false; - Linkage = GlobalValue::ExternalLinkage; + Linkage = GlobalValue::ExternalLinkage; + Visibility = GlobalValue::DefaultVisibility; } inline void FunctionStart(Function *M) { @@ -245,6 +247,7 @@ static struct PerFunctionInfo { CurrentFunction = 0; isDeclare = false; Linkage = GlobalValue::ExternalLinkage; + Visibility = GlobalValue::DefaultVisibility; } } CurFun; // Info for the current function... @@ -648,7 +651,9 @@ static void setValueName(Value *V, char *NameStr) { /// ParseGlobalVariable - Handle parsing of a global. If Initializer is null, /// this is a declaration, otherwise it is a definition. static GlobalVariable * -ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage, +ParseGlobalVariable(char *NameStr, + GlobalValue::LinkageTypes Linkage, + GlobalValue::VisibilityTypes Visibility, bool isConstantGlobal, const Type *Ty, Constant *Initializer) { if (isa<FunctionType>(Ty)) { @@ -681,6 +686,7 @@ ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage, CurModule.CurrentModule->getGlobalList().push_back(GV); GV->setInitializer(Initializer); GV->setLinkage(Linkage); + GV->setVisibility(Visibility); GV->setConstant(isConstantGlobal); InsertValue(GV, CurModule.Values); return GV; @@ -702,6 +708,7 @@ ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage, GlobalVariable *GV = new GlobalVariable(Ty, isConstantGlobal, Linkage, Initializer, Name, CurModule.CurrentModule); + GV->setVisibility(Visibility); InsertValue(GV, CurModule.Values); return GV; } @@ -898,6 +905,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) { std::vector<llvm::Constant*> *ConstVector; llvm::GlobalValue::LinkageTypes Linkage; + llvm::GlobalValue::VisibilityTypes Visibility; llvm::FunctionType::ParameterAttributes ParamAttrs; int64_t SInt64Val; uint64_t UInt64Val; @@ -940,6 +948,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) { %type <BoolVal> OptSideEffect // 'sideeffect' or not. %type <Linkage> GVInternalLinkage GVExternalLinkage %type <Linkage> FunctionDefineLinkage FunctionDeclareLinkage +%type <Visibility> GVVisibilityStyle %type <Endianness> BigOrLittle // ValueRef - Unresolved reference to a definition or BB @@ -1011,6 +1020,9 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) { // Function Attributes %token NORETURN +// Visibility Styles +%token DEFAULT HIDDEN + %start Module %% @@ -1081,6 +1093,11 @@ GVExternalLinkage | EXTERNAL { $$ = GlobalValue::ExternalLinkage; } ; +GVVisibilityStyle + : /*empty*/ { $$ = GlobalValue::DefaultVisibility; } + | HIDDEN { $$ = GlobalValue::HiddenVisibility; } + ; + FunctionDeclareLinkage : /*empty*/ { $$ = GlobalValue::ExternalLinkage; } | DLLIMPORT { $$ = GlobalValue::DLLImportLinkage; } @@ -1225,7 +1242,7 @@ Types if (isVarArg) Params.pop_back(); FunctionType *FT = FunctionType::get(*$1, Params, isVarArg, Attrs); - delete $3; // Delete the argument list + delete $3; // Delete the argument list delete $1; // Delete the return type handle $$ = new PATypeHolder(HandleUpRefs(FT)); CHECK_FOR_ERROR @@ -1883,29 +1900,29 @@ Definition } CHECK_FOR_ERROR } - | OptAssign GlobalType ConstVal { /* "Externally Visible" Linkage */ - if ($3 == 0) + | OptAssign GVVisibilityStyle GlobalType ConstVal { /* "Externally Visible" Linkage */ + if ($4 == 0) GEN_ERROR("Global value initializer is not a constant!"); - CurGV = ParseGlobalVariable($1, GlobalValue::ExternalLinkage, $2, - $3->getType(), $3); + CurGV = ParseGlobalVariable($1, GlobalValue::ExternalLinkage, + $2, $3, $4->getType(), $4); CHECK_FOR_ERROR } GlobalVarAttributes { CurGV = 0; } - | OptAssign GVInternalLinkage GlobalType ConstVal { - if ($4 == 0) + | OptAssign GVInternalLinkage GVVisibilityStyle GlobalType ConstVal { + if ($5 == 0) GEN_ERROR("Global value initializer is not a constant!"); - CurGV = ParseGlobalVariable($1, $2, $3, $4->getType(), $4); + CurGV = ParseGlobalVariable($1, $2, $3, $4, $5->getType(), $5); CHECK_FOR_ERROR } GlobalVarAttributes { CurGV = 0; } - | OptAssign GVExternalLinkage GlobalType Types { + | OptAssign GVExternalLinkage GVVisibilityStyle GlobalType Types { if (!UpRefs.empty()) - GEN_ERROR("Invalid upreference in type: " + (*$4)->getDescription()); - CurGV = ParseGlobalVariable($1, $2, $3, *$4, 0); + GEN_ERROR("Invalid upreference in type: " + (*$5)->getDescription()); + CurGV = ParseGlobalVariable($1, $2, $3, $4, *$5, 0); CHECK_FOR_ERROR - delete $4; + delete $5; } GlobalVarAttributes { CurGV = 0; CHECK_FOR_ERROR @@ -2103,6 +2120,7 @@ FunctionHeaderH : OptCallingConv ResultTypes Name '(' ArgList ')' // correctly handle cases, when pointer to function is passed as argument to // another function. Fn->setLinkage(CurFun.Linkage); + Fn->setVisibility(CurFun.Visibility); } Fn->setCallingConv($1); Fn->setAlignment($9); @@ -2136,12 +2154,13 @@ FunctionHeaderH : OptCallingConv ResultTypes Name '(' ArgList ')' BEGIN : BEGINTOK | '{'; // Allow BEGIN or '{' to start a function -FunctionHeader : FunctionDefineLinkage FunctionHeaderH BEGIN { +FunctionHeader : FunctionDefineLinkage GVVisibilityStyle FunctionHeaderH BEGIN { $$ = CurFun.CurrentFunction; // Make sure that we keep track of the linkage type even if there was a // previous "declare". $$->setLinkage($1); + $$->setVisibility($2); }; END : ENDTOK | '}'; // Allow end of '}' to end a function @@ -2151,8 +2170,9 @@ Function : BasicBlockList END { CHECK_FOR_ERROR }; -FunctionProto : FunctionDeclareLinkage FunctionHeaderH { +FunctionProto : FunctionDeclareLinkage GVVisibilityStyle FunctionHeaderH { CurFun.CurrentFunction->setLinkage($1); + CurFun.CurrentFunction->setVisibility($2); $$ = CurFun.CurrentFunction; CurFun.FunctionDone(); CHECK_FOR_ERROR diff --git a/lib/AsmParser/llvmAsmParser.y.cvs b/lib/AsmParser/llvmAsmParser.y.cvs index b84cf25150..52d8847d32 100644 --- a/lib/AsmParser/llvmAsmParser.y.cvs +++ b/lib/AsmParser/llvmAsmParser.y.cvs @@ -210,6 +210,7 @@ static struct PerFunctionInfo { std::map<const Type*, ValueList> LateResolveValues; bool isDeclare; // Is this function a forward declararation? GlobalValue::LinkageTypes Linkage; // Linkage for forward declaration. + GlobalValue::VisibilityTypes Visibility; /// BBForwardRefs - When we see forward references to basic blocks, keep /// track of them here. @@ -220,7 +221,8 @@ static struct PerFunctionInfo { inline PerFunctionInfo() { CurrentFunction = 0; isDeclare = false; - Linkage = GlobalValue::ExternalLinkage; + Linkage = GlobalValue::ExternalLinkage; + Visibility = GlobalValue::DefaultVisibility; } inline void FunctionStart(Function *M) { @@ -245,6 +247,7 @@ static struct PerFunctionInfo { CurrentFunction = 0; isDeclare = false; Linkage = GlobalValue::ExternalLinkage; + Visibility = GlobalValue::DefaultVisibility; } } CurFun; // Info for the current function... @@ -648,7 +651,9 @@ static void setValueName(Value *V, char *NameStr) { /// ParseGlobalVariable - Handle parsing of a global. If Initializer is null, /// this is a declaration, otherwise it is a definition. static GlobalVariable * -ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage, +ParseGlobalVariable(char *NameStr, + GlobalValue::LinkageTypes Linkage, + GlobalValue::VisibilityTypes Visibility, bool isConstantGlobal, const Type *Ty, Constant *Initializer) { if (isa<FunctionType>(Ty)) { @@ -681,6 +686,7 @@ ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage, CurModule.CurrentModule->getGlobalList().push_back(GV); GV->setInitializer(Initializer); GV->setLinkage(Linkage); + GV->setVisibility(Visibility); GV->setConstant(isConstantGlobal); InsertValue(GV, CurModule.Values); return GV; @@ -702,6 +708,7 @@ ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage, GlobalVariable *GV = new GlobalVariable(Ty, isConstantGlobal, Linkage, Initializer, Name, CurModule.CurrentModule); + GV->setVisibility(Visibility); InsertValue(GV, CurModule.Values); return GV; } @@ -898,6 +905,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) { std::vector<llvm::Constant*> *ConstVector; llvm::GlobalValue::LinkageTypes Linkage; + llvm::GlobalValue::VisibilityTypes Visibility; llvm::FunctionType::ParameterAttributes ParamAttrs; int64_t SInt64Val; uint64_t UInt64Val; @@ -940,6 +948,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) { %type <BoolVal> OptSideEffect // 'sideeffect' or not. %type <Linkage> GVInternalLinkage GVExternalLinkage %type <Linkage> FunctionDefineLinkage FunctionDeclareLinkage +%type <Visibility> GVVisibilityStyle %type <Endianness> BigOrLittle // ValueRef - Unresolved reference to a definition or BB @@ -1011,6 +1020,9 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) { // Function Attributes %token NORETURN +// Visibility Styles +%token DEFAULT HIDDEN + %start Module %% @@ -1081,6 +1093,11 @@ GVExternalLinkage | EXTERNAL { $$ = GlobalValue::ExternalLinkage; } ; +GVVisibilityStyle + : /*empty*/ { $$ = GlobalValue::DefaultVisibility; } + | HIDDEN { $$ = GlobalValue::HiddenVisibility; } + ; + FunctionDeclareLinkage : /*empty*/ { $$ = GlobalValue::ExternalLinkage; } | DLLIMPORT { $$ = GlobalValue::DLLImportLinkage; } @@ -1225,7 +1242,7 @@ Types if (isVarArg) Params.pop_back(); FunctionType *FT = FunctionType::get(*$1, Params, isVarArg, Attrs); - delete $3; // Delete the argument list + delete $3; // Delete the argument list delete $1; // Delete the return type handle $$ = new PATypeHolder(HandleUpRefs(FT)); CHECK_FOR_ERROR @@ -1883,29 +1900,29 @@ Definition } CHECK_FOR_ERROR } - | OptAssign GlobalType ConstVal { /* "Externally Visible" Linkage */ - if ($3 == 0) + | OptAssign GVVisibilityStyle GlobalType ConstVal { /* "Externally Visible" Linkage */ + if ($4 == 0) GEN_ERROR("Global value initializer is not a constant!"); - CurGV = ParseGlobalVariable($1, GlobalValue::ExternalLinkage, $2, - $3->getType(), $3); + CurGV = ParseGlobalVariable($1, GlobalValue::ExternalLinkage, + $2, $3, $4->getType(), $4); CHECK_FOR_ERROR } GlobalVarAttributes { CurGV = 0; } - | OptAssign GVInternalLinkage GlobalType ConstVal { - if ($4 == 0) + | OptAssign GVInternalLinkage GVVisibilityStyle GlobalType ConstVal { + if ($5 == 0) GEN_ERROR("Global value initializer is not a constant!"); - CurGV = ParseGlobalVariable($1, $2, $3, $4->getType(), $4); + CurGV = ParseGlobalVariable($1, $2, $3, $4, $5->getType(), $5); CHECK_FOR_ERROR } GlobalVarAttributes { CurGV = 0; } - | OptAssign GVExternalLinkage GlobalType Types { + | OptAssign GVExternalLinkage GVVisibilityStyle GlobalType Types { if (!UpRefs.empty()) - GEN_ERROR("Invalid upreference in type: " + (*$4)->getDescription()); - CurGV = ParseGlobalVariable($1, $2, $3, *$4, 0); + GEN_ERROR("Invalid upreference in type: " + (*$5)->getDescription()); + CurGV = ParseGlobalVariable($1, $2, $3, $4, *$5, 0); CHECK_FOR_ERROR - delete $4; + delete $5; } GlobalVarAttributes { CurGV = 0; CHECK_FOR_ERROR @@ -2103,6 +2120,7 @@ FunctionHeaderH : OptCallingConv ResultTypes Name '(' ArgList ')' // correctly handle cases, when pointer to function is passed as argument to // another function. Fn->setLinkage(CurFun.Linkage); + Fn->setVisibility(CurFun.Visibility); } Fn->setCallingConv($1); Fn->setAlignment($9); @@ -2136,12 +2154,13 @@ FunctionHeaderH : OptCallingConv ResultTypes Name '(' ArgList ')' BEGIN : BEGINTOK | '{'; // Allow BEGIN or '{' to start a function -FunctionHeader : FunctionDefineLinkage FunctionHeaderH BEGIN { +FunctionHeader : FunctionDefineLinkage GVVisibilityStyle FunctionHeaderH BEGIN { $$ = CurFun.CurrentFunction; // Make sure that we keep track of the linkage type even if there was a // previous "declare". $$->setLinkage($1); + $$->setVisibility($2); }; END : ENDTOK | '}'; // Allow end of '}' to end a function @@ -2151,8 +2170,9 @@ Function : BasicBlockList END { CHECK_FOR_ERROR }; -FunctionProto : FunctionDeclareLinkage FunctionHeaderH { +FunctionProto : FunctionDeclareLinkage GVVisibilityStyle FunctionHeaderH { CurFun.CurrentFunction->setLinkage($1); + CurFun.CurrentFunction->setVisibility($2); $$ = CurFun.CurrentFunction; CurFun.FunctionDone(); CHECK_FOR_ERROR diff --git a/lib/Bytecode/Reader/Analyzer.cpp b/lib/Bytecode/Reader/Analyzer.cpp index 899a534272..465e3b053e 100644 --- a/lib/Bytecode/Reader/Analyzer.cpp +++ b/lib/Bytecode/Reader/Analyzer.cpp @@ -162,6 +162,7 @@ public: const Type* ElemType, bool isConstant, GlobalValue::LinkageTypes Linkage, + GlobalValue::VisibilityTypes Visibility, unsigned SlotNum, unsigned initSlot ) { @@ -169,7 +170,9 @@ public: *os << " GV: " << ( initSlot == 0 ? "Uni" : "I" ) << "nitialized, " << ( isConstant? "Constant, " : "Variable, ") - << " Linkage=" << Linkage << " Type="; + << " Linkage=" << Linkage + << " Visibility="<< Visibility + << " Type="; WriteTypeSymbolic(*os, ElemType, M); *os << " Slot=" << SlotNum << " InitSlot=" << initSlot << "\n"; @@ -206,6 +209,7 @@ public: *os << " Function Decl: "; WriteTypeSymbolic(*os,Func->getType(),M); *os <<", Linkage=" << Func->getLinkage(); + *os <<", Visibility=" << Func->getVisibility(); *os << "\n"; } } @@ -311,6 +315,7 @@ public: if (os) { *os << " BLOCK: Function {\n" << " Linkage: " << Func->getLinkage() << "\n" + << " Visibility: " << Func->getVisibility() << "\n" <&l |