[llvm-commits] CVS: llvm/lib/AsmParser/llvmAsmParser.y
Chris Lattner
lattner at cs.uiuc.edu
Wed Jul 14 01:24:02 PDT 2004
Changes in directory llvm/lib/AsmParser:
llvmAsmParser.y updated: 1.183 -> 1.184
---
Log message:
Pull out code shared between GV forward-decl and definition processing.
This gives us only a single call site for setValueNameMergingDuplicates.
The next stage is the start merging them together.
---
Diffs of the changes: (+37 -50)
Index: llvm/lib/AsmParser/llvmAsmParser.y
diff -u llvm/lib/AsmParser/llvmAsmParser.y:1.183 llvm/lib/AsmParser/llvmAsmParser.y:1.184
--- llvm/lib/AsmParser/llvmAsmParser.y:1.183 Wed Jul 14 02:12:48 2004
+++ llvm/lib/AsmParser/llvmAsmParser.y Wed Jul 14 03:23:52 2004
@@ -591,7 +591,7 @@
// allowed to be redefined in the specified context. If the name is a new name
// for the typeplane, false is returned.
//
-static bool setValueNameMergingDuplicates(GlobalValue *V, char *NameStr) {
+static bool setValueNameMergingDuplicates(GlobalVariable *V, char *NameStr) {
if (NameStr == 0) return false;
std::string Name(NameStr); // Copy string
@@ -609,21 +609,19 @@
// 1. If at least one of the globals is uninitialized or
// 2. If both initializers have the same value.
//
- if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
- if (!EGV->hasInitializer() || !GV->hasInitializer() ||
- EGV->getInitializer() == GV->getInitializer()) {
-
- // Make sure the existing global version gets the initializer! Make
- // sure that it also gets marked const if the new version is.
- if (GV->hasInitializer() && !EGV->hasInitializer())
- EGV->setInitializer(GV->getInitializer());
- if (GV->isConstant())
- EGV->setConstant(true);
- EGV->setLinkage(GV->getLinkage());
-
- delete GV; // Destroy the duplicate!
- return true; // They are equivalent!
- }
+ if (!EGV->hasInitializer() || !V->hasInitializer() ||
+ EGV->getInitializer() == V->getInitializer()) {
+
+ // Make sure the existing global version gets the initializer! Make
+ // sure that it also gets marked const if the new version is.
+ if (V->hasInitializer() && !EGV->hasInitializer())
+ EGV->setInitializer(V->getInitializer());
+ if (V->isConstant())
+ EGV->setConstant(true);
+ EGV->setLinkage(V->getLinkage());
+
+ delete V; // Destroy the duplicate!
+ return true; // They are equivalent!
}
}
@@ -636,7 +634,26 @@
return false;
}
-
+/// ParseGlobalVariable - Handle parsing of a global. If Initializer is null,
+/// this is a declaration, otherwise it is a definition.
+static void ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
+ bool isConstantGlobal, const Type *Ty,
+ Constant *Initializer) {
+ // Global declarations appear in Constant Pool
+ GlobalVariable *GV = new GlobalVariable(Ty, isConstantGlobal, Linkage,
+ Initializer);
+ if (!setValueNameMergingDuplicates(GV, NameStr)) { // If not redefining...
+ CurModule.CurrentModule->getGlobalList().push_back(GV);
+ int Slot = InsertValue(GV, CurModule.Values);
+
+ if (Slot != -1) {
+ CurModule.DeclareNewGlobalValue(GV, ValID::create(Slot));
+ } else {
+ CurModule.DeclareNewGlobalValue(GV,
+ ValID::create((char*)GV->getName().c_str()));
+ }
+ }
+}
// setTypeName - Set the specified type to the name given. The name may be
// null potentially, in which case this is a noop. The string passed in is
@@ -1443,41 +1460,11 @@
| ConstPool FunctionProto { // Function prototypes can be in const pool
}
| ConstPool OptAssign OptLinkage GlobalType ConstVal {
- const Type *Ty = $5->getType();
- // Global declarations appear in Constant Pool
- Constant *Initializer = $5;
- if (Initializer == 0)
- ThrowException("Global value initializer is not a constant!");
-
- GlobalVariable *GV = new GlobalVariable(Ty, $4, $3, Initializer);
- if (!setValueNameMergingDuplicates(GV, $2)) { // If not redefining...
- CurModule.CurrentModule->getGlobalList().push_back(GV);
- int Slot = InsertValue(GV, CurModule.Values);
-
- if (Slot != -1) {
- CurModule.DeclareNewGlobalValue(GV, ValID::create(Slot));
- } else {
- CurModule.DeclareNewGlobalValue(GV, ValID::create(
- (char*)GV->getName().c_str()));
- }
- }
+ if ($5 == 0) ThrowException("Global value initializer is not a constant!");
+ ParseGlobalVariable($2, $3, $4, $5->getType(), $5);
}
| ConstPool OptAssign EXTERNAL GlobalType Types {
- const Type *Ty = *$5;
- // Global declarations appear in Constant Pool
- GlobalVariable *GV = new GlobalVariable(Ty,$4,GlobalValue::ExternalLinkage);
- if (!setValueNameMergingDuplicates(GV, $2)) { // If not redefining...
- CurModule.CurrentModule->getGlobalList().push_back(GV);
- int Slot = InsertValue(GV, CurModule.Values);
-
- if (Slot != -1) {
- CurModule.DeclareNewGlobalValue(GV, ValID::create(Slot));
- } else {
- assert(GV->hasName() && "Not named and not numbered!?");
- CurModule.DeclareNewGlobalValue(GV, ValID::create(
- (char*)GV->getName().c_str()));
- }
- }
+ ParseGlobalVariable($2, GlobalValue::ExternalLinkage, $4, *$5, 0);
delete $5;
}
| ConstPool TARGET TargetDefinition {
More information about the llvm-commits
mailing list