[llvm-commits] CVS: llvm/lib/AsmParser/llvmAsmParser.y
Chris Lattner
lattner at cs.uiuc.edu
Sat Nov 12 10:21:33 PST 2005
Changes in directory llvm/lib/AsmParser:
llvmAsmParser.y updated: 1.238 -> 1.239
---
Log message:
refactor grammar to eliminate shift-reduce conflict. Move alignment checking
code out of all of the clients and into OptAlign/OptCAlign
---
Diffs of the changes: (+45 -49)
llvmAsmParser.y | 94 ++++++++++++++++++++++++++------------------------------
1 files changed, 45 insertions(+), 49 deletions(-)
Index: llvm/lib/AsmParser/llvmAsmParser.y
diff -u llvm/lib/AsmParser/llvmAsmParser.y:1.238 llvm/lib/AsmParser/llvmAsmParser.y:1.239
--- llvm/lib/AsmParser/llvmAsmParser.y:1.238 Fri Nov 11 18:11:10 2005
+++ llvm/lib/AsmParser/llvmAsmParser.y Sat Nov 12 12:21:21 2005
@@ -50,7 +50,8 @@
static bool ObsoleteVarArgs;
static bool NewVarArgs;
-static BasicBlock* CurBB;
+static BasicBlock *CurBB;
+static GlobalVariable *CurGV;
// This contains info used when building the body of a function. It is
@@ -515,13 +516,10 @@
/// 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, char *Section,
- unsigned Align) {
- if (Align != 0 && !isPowerOf2_32(Align))
- ThrowException("Global alignment must be a power of two!");
-
+static GlobalVariable *
+ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
+ bool isConstantGlobal, const Type *Ty,
+ Constant *Initializer) {
if (isa<FunctionType>(Ty))
ThrowException("Cannot declare global vars of function type!");
@@ -551,13 +549,8 @@
GV->setInitializer(Initializer);
GV->setLinkage(Linkage);
GV->setConstant(isConstantGlobal);
- GV->setAlignment(Align);
- if (Section) {
- free(Section);
- GV->setSection(Section);
- }
InsertValue(GV, CurModule.Values);
- return;
+ return GV;
}
// If this global has a name, check to see if there is already a definition
@@ -582,12 +575,7 @@
if (isConstantGlobal)
EGV->setConstant(true);
EGV->setLinkage(Linkage);
- EGV->setAlignment(Align);
- if (Section) {
- free(Section);
- EGV->setSection(Section);
- }
- return;
+ return EGV;
}
ThrowException("Redefinition of global variable named '" + Name +
@@ -599,12 +587,8 @@
GlobalVariable *GV =
new GlobalVariable(Ty, isConstantGlobal, Linkage, Initializer, Name,
CurModule.CurrentModule);
- GV->setAlignment(Align);
- if (Section) {
- free(Section);
- GV->setSection(Section);
- }
InsertValue(GV, CurModule.Values);
+ return GV;
}
// setTypeName - Set the specified type to the name given. The name may be
@@ -969,7 +953,7 @@
%token <StrVal> VAR_ID LABELSTR STRINGCONSTANT
%type <StrVal> Name OptName OptAssign
%type <UIntVal> OptAlign OptCAlign
-%type <StrVal> OptSection OptCSection SectionString
+%type <StrVal> OptSection SectionString
%token IMPLEMENTATION ZEROINITIALIZER TRUETOK FALSETOK BEGINTOK ENDTOK
%token DECLARE GLOBAL CONSTANT SECTION VOLATILE
@@ -1059,9 +1043,18 @@
// OptAlign/OptCAlign - An optional alignment, and an optional alignment with
// a comma before it.
OptAlign : /*empty*/ { $$ = 0; } |
- ALIGN EUINT64VAL { $$ = $2; };
+ ALIGN EUINT64VAL {
+ $$ = $2;
+ if ($$ != 0 && !isPowerOf2_32($$))
+ ThrowException("Alignment must be a power of two!");
+};
OptCAlign : /*empty*/ { $$ = 0; } |
- ',' ALIGN EUINT64VAL { $$ = $3; };
+ ',' ALIGN EUINT64VAL {
+ $$ = $3;
+ if ($$ != 0 && !isPowerOf2_32($$))
+ ThrowException("Alignment must be a power of two!");
+};
+
SectionString : SECTION STRINGCONSTANT {
for (unsigned i = 0, e = strlen($2); i != e; ++i)
@@ -1072,9 +1065,21 @@
OptSection : /*empty*/ { $$ = 0; } |
SectionString { $$ = $1; };
-OptCSection : /*empty*/ { $$ = 0; } |
- ',' SectionString { $$ = $2; };
+// GlobalVarAttributes - Used to pass the attributes string on a global. CurGV
+// is set to be the global we are processing.
+//
+GlobalVarAttributes : /* empty */ {} |
+ ',' GlobalVarAttribute GlobalVarAttributes {};
+GlobalVarAttribute : SectionString {
+ CurGV->setSection($1);
+ free($1);
+ }
+ | ALIGN EUINT64VAL {
+ if ($2 != 0 && !isPowerOf2_32($2))
+ ThrowException("Alignment must be a power of two!");
+ CurGV->setAlignment($2);
+ };
//===----------------------------------------------------------------------===//
// Types includes all predefined types... except void, because it can only be
@@ -1584,13 +1589,18 @@
}
| ConstPool FunctionProto { // Function prototypes can be in const pool
}
- | ConstPool OptAssign OptLinkage GlobalType ConstVal OptCSection OptCAlign {
+ | ConstPool OptAssign OptLinkage GlobalType ConstVal {
if ($5 == 0) ThrowException("Global value initializer is not a constant!");
- ParseGlobalVariable($2, $3, $4, $5->getType(), $5, $6, $7);
- }
- | ConstPool OptAssign EXTERNAL GlobalType Types OptCSection OptCAlign {
- ParseGlobalVariable($2, GlobalValue::ExternalLinkage, $4, *$5, 0, $6, $7);
+ CurGV = ParseGlobalVariable($2, $3, $4, $5->getType(), $5);
+ } GlobalVarAttributes {
+ CurGV = 0;
+ }
+ | ConstPool OptAssign EXTERNAL GlobalType Types {
+ CurGV = ParseGlobalVariable($2, GlobalValue::ExternalLinkage,
+ $4, *$5, 0);
delete $5;
+ } GlobalVarAttributes {
+ CurGV = 0;
}
| ConstPool TARGET TargetDefinition {
}
@@ -1682,8 +1692,6 @@
if (!(*$2)->isFirstClassType() && *$2 != Type::VoidTy)
ThrowException("LLVM functions cannot return aggregate types!");
- if ($8 != 0 && !isPowerOf2_32($8))
- ThrowException("Function alignment must be a power of two!");
std::vector<const Type*> ParamTypeList;
if ($5) { // If there are arguments...
@@ -2254,30 +2262,18 @@
MemoryInst : MALLOC Types OptCAlign {
- if ($3 != 0 && !isPowerOf2_32($3))
- ThrowException("Alignment amount '" + utostr($3) +
- "' is not a power of 2!");
$$ = new MallocInst(*$2, 0, $3);
delete $2;
}
| MALLOC Types ',' UINT ValueRef OptCAlign {
- if ($6 != 0 && !isPowerOf2_32($6))
- ThrowException("Alignment amount '" + utostr($6) +
- "' is not a power of 2!");
$$ = new MallocInst(*$2, getVal($4, $5), $6);
delete $2;
}
| ALLOCA Types OptCAlign {
- if ($3 != 0 && !isPowerOf2_32($3))
- ThrowException("Alignment amount '" + utostr($3) +
- "' is not a power of 2!");
$$ = new AllocaInst(*$2, 0, $3);
delete $2;
}
| ALLOCA Types ',' UINT ValueRef OptCAlign {
- if ($6 != 0 && !isPowerOf2_32($6))
- ThrowException("Alignment amount '" + utostr($6) +
- "' is not a power of 2!");
$$ = new AllocaInst(*$2, getVal($4, $5), $6);
delete $2;
}
More information about the llvm-commits
mailing list