For PR645:

Implement separation of local and global symbols. Local symbols and types
now use % prefix. Global variables and functions now use @ prefix.

For PR761:
Replace:
  target endian =
  target pointersize =
With:
  target datalayout =


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33524 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Spencer 2007-01-26 08:04:51 +00:00
parent 3702d265b8
commit b2d1786090
3 changed files with 174 additions and 158 deletions

View File

@ -148,8 +148,11 @@ using namespace llvm;
/* Comments start with a ; and go till end of line */ /* Comments start with a ; and go till end of line */
Comment ;.* Comment ;.*
/* Variable(Value) identifiers start with a % sign */ /* Local Values and Type identifiers start with a % sign */
VarID %[-a-zA-Z$._][-a-zA-Z$._0-9]* LocalVarName %[-a-zA-Z$._][-a-zA-Z$._0-9]*
/* Global Value identifiers start with an @ sign */
GlobalVarName @[-a-zA-Z$._][-a-zA-Z$._0-9]*
/* Label identifiers end with a colon */ /* Label identifiers end with a colon */
Label [-a-zA-Z$._0-9]+: Label [-a-zA-Z$._0-9]+:
@ -157,18 +160,16 @@ QuoteLabel \"[^\"]+\":
/* Quoted names can contain any character except " and \ */ /* Quoted names can contain any character except " and \ */
StringConstant \"[^\"]*\" StringConstant \"[^\"]*\"
AtStringConstant @\"[^\"]*\"
/* LocalVarID/GlobalVarID: match an unnamed local variable slot ID. */
LocalVarID %[0-9]+
GlobalVarID @[0-9]+
/* Integer types are specified with i and a bitwidth */
/* [PN]Integer: match positive and negative literal integer values that
* are preceeded by a '%' character. These represent unnamed variable slots.
*/
EPInteger %[0-9]+
ENInteger %-[0-9]+
IntegerType i[0-9]+ IntegerType i[0-9]+
/* E[PN]Integer: match positive and negative literal integer values. */
/* E[PN]Integer: match positive and negative literal integer values */
PInteger [0-9]+ PInteger [0-9]+
NInteger -[0-9]+ NInteger -[0-9]+
@ -216,11 +217,7 @@ tail { return TAIL; }
target { return TARGET; } target { return TARGET; }
triple { return TRIPLE; } triple { return TRIPLE; }
deplibs { return DEPLIBS; } deplibs { return DEPLIBS; }
endian { return ENDIAN; }
pointersize { return POINTERSIZE; }
datalayout { return DATALAYOUT; } datalayout { return DATALAYOUT; }
little { return LITTLE; }
big { return BIG; }
volatile { return VOLATILE; } volatile { return VOLATILE; }
align { return ALIGN; } align { return ALIGN; }
section { return SECTION; } section { return SECTION; }
@ -323,10 +320,15 @@ insertelement { RET_TOK(OtherOpVal, InsertElement, INSERTELEMENT); }
shufflevector { RET_TOK(OtherOpVal, ShuffleVector, SHUFFLEVECTOR); } shufflevector { RET_TOK(OtherOpVal, ShuffleVector, SHUFFLEVECTOR); }
{VarID} { {LocalVarName} {
UnEscapeLexed(yytext+1); UnEscapeLexed(yytext+1);
llvmAsmlval.StrVal = strdup(yytext+1); // Skip % llvmAsmlval.StrVal = strdup(yytext+1); // Skip %
return VAR_ID; return LOCALVAR;
}
{GlobalVarName} {
UnEscapeLexed(yytext+1);
llvmAsmlval.StrVal = strdup(yytext+1); // Skip @
return GLOBALVAR;
} }
{Label} { {Label} {
yytext[strlen(yytext)-1] = 0; // nuke colon yytext[strlen(yytext)-1] = 0; // nuke colon
@ -350,6 +352,12 @@ shufflevector { RET_TOK(OtherOpVal, ShuffleVector, SHUFFLEVECTOR); }
llvmAsmlval.StrVal = strdup(yytext+1); // Nuke start quote llvmAsmlval.StrVal = strdup(yytext+1); // Nuke start quote
return STRINGCONSTANT; return STRINGCONSTANT;
} }
{AtStringConstant} {
yytext[strlen(yytext)-1] = 0; // nuke end quote
llvmAsmlval.StrVal = strdup(yytext+2); // Nuke @, quote
return ATSTRINGCONSTANT;
}
{PInteger} { llvmAsmlval.UInt64Val = atoull(yytext); return EUINT64VAL; } {PInteger} { llvmAsmlval.UInt64Val = atoull(yytext); return EUINT64VAL; }
@ -366,20 +374,19 @@ shufflevector { RET_TOK(OtherOpVal, ShuffleVector, SHUFFLEVECTOR); }
return yytext[0] == 's' ? ESINT64VAL : EUINT64VAL; return yytext[0] == 's' ? ESINT64VAL : EUINT64VAL;
} }
{EPInteger} { {LocalVarID} {
uint64_t Val = atoull(yytext+1); uint64_t Val = atoull(yytext+1);
if ((unsigned)Val != Val) if ((unsigned)Val != Val)
GenerateError("Invalid value number (too large)!"); GenerateError("Invalid value number (too large)!");
llvmAsmlval.UIntVal = unsigned(Val); llvmAsmlval.UIntVal = unsigned(Val);
return UINTVAL; return LOCALVAL_ID;
} }
{ENInteger} { {GlobalVarID} {
uint64_t Val = atoull(yytext+2); uint64_t Val = atoull(yytext+1);
// +1: we have bigger negative range if ((unsigned)Val != Val)
if (Val > (uint64_t)INT32_MAX+1) GenerateError("Invalid value number (too large)!");
GenerateError("Constant too large for signed 32 bits!"); llvmAsmlval.UIntVal = unsigned(Val);
llvmAsmlval.SIntVal = (int)-Val; return GLOBALVAL_ID;
return SINTVAL;
} }
{FPConstant} { llvmAsmlval.FPVal = atof(yytext); return FPVAL; } {FPConstant} { llvmAsmlval.FPVal = atof(yytext); return FPVAL; }

View File

@ -88,12 +88,13 @@ struct InlineAsmDescriptor {
// //
struct ValID { struct ValID {
enum { enum {
NumberVal, NameVal, ConstSIntVal, ConstUIntVal, ConstFPVal, ConstNullVal, LocalID, GlobalID, LocalName, GlobalName,
ConstSIntVal, ConstUIntVal, ConstFPVal, ConstNullVal,
ConstUndefVal, ConstZeroVal, ConstantVal, InlineAsmVal ConstUndefVal, ConstZeroVal, ConstantVal, InlineAsmVal
} Type; } Type;
union { union {
int Num; // If it's a numeric reference unsigned Num; // If it's a numeric reference like %1234
char *Name; // If it's a named reference. Memory must be free'd. char *Name; // If it's a named reference. Memory must be free'd.
int64_t ConstPool64; // Constant pool reference. This is the value int64_t ConstPool64; // Constant pool reference. This is the value
uint64_t UConstPool64;// Unsigned constant pool reference. uint64_t UConstPool64;// Unsigned constant pool reference.
@ -102,14 +103,19 @@ struct ValID {
InlineAsmDescriptor *IAD; InlineAsmDescriptor *IAD;
}; };
static ValID create(int Num) { static ValID createLocalID(unsigned Num) {
ValID D; D.Type = NumberVal; D.Num = Num; return D; ValID D; D.Type = LocalID; D.Num = Num; return D;
} }
static ValID createGlobalID(unsigned Num) {
static ValID create(char *Name) { ValID D; D.Type = GlobalID; D.Num = Num; return D;
ValID D; D.Type = NameVal; D.Name = Name; return D;
} }
static ValID createLocalName(char *Name) {
ValID D; D.Type = LocalName; D.Name = Name; return D;
}
static ValID createGlobalName(char *Name) {
ValID D; D.Type = GlobalName; D.Name = Name; return D;
}
static ValID create(int64_t Val) { static ValID create(int64_t Val) {
ValID D; D.Type = ConstSIntVal; D.ConstPool64 = Val; return D; ValID D; D.Type = ConstSIntVal; D.ConstPool64 = Val; return D;
} }
@ -148,14 +154,14 @@ struct ValID {
} }
inline void destroy() const { inline void destroy() const {
if (Type == NameVal) if (Type == LocalName || Type == GlobalName)
free(Name); // Free this strdup'd memory. free(Name); // Free this strdup'd memory.
else if (Type == InlineAsmVal) else if (Type == InlineAsmVal)
delete IAD; delete IAD;
} }
inline ValID copy() const { inline ValID copy() const {
if (Type != NameVal) return *this; if (Type != LocalName && Type != GlobalName) return *this;
ValID Result = *this; ValID Result = *this;
Result.Name = strdup(Name); Result.Name = strdup(Name);
return Result; return Result;
@ -163,8 +169,10 @@ struct ValID {
inline std::string getName() const { inline std::string getName() const {
switch (Type) { switch (Type) {
case NumberVal : return std::string("#") + itostr(Num); case LocalID : return '%' + utostr(Num);
case NameVal : return Name; case GlobalID : return '@' + utostr(Num);
case LocalName : return Name;
case GlobalName : return Name;
case ConstFPVal : return ftostr(ConstPoolFP); case ConstFPVal : return ftostr(ConstPoolFP);
case ConstNullVal : return "null"; case ConstNullVal : return "null";
case ConstUndefVal : return "undef"; case ConstUndefVal : return "undef";
@ -185,8 +193,10 @@ struct ValID {
bool operator<(const ValID &V) const { bool operator<(const ValID &V) const {
if (Type != V.Type) return Type < V.Type; if (Type != V.Type) return Type < V.Type;
switch (Type) { switch (Type) {
case NumberVal: return Num < V.Num; case LocalID:
case NameVal: return strcmp(Name, V.Name) < 0; case GlobalID: return Num < V.Num;
case LocalName:
case GlobalName: return strcmp(Name, V.Name) < 0;
case ConstSIntVal: return ConstPool64 < V.ConstPool64; case ConstSIntVal: return ConstPool64 < V.ConstPool64;
case ConstUIntVal: return UConstPool64 < V.UConstPool64; case ConstUIntVal: return UConstPool64 < V.UConstPool64;
case ConstFPVal: return ConstPoolFP < V.ConstPoolFP; case ConstFPVal: return ConstPoolFP < V.ConstPoolFP;

View File

@ -270,12 +270,12 @@ static int InsertValue(Value *V,
static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) { static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) {
switch (D.Type) { switch (D.Type) {
case ValID::NumberVal: // Is it a numbered definition? case ValID::LocalID: // Is it a numbered definition?
// Module constants occupy the lowest numbered slots... // Module constants occupy the lowest numbered slots...
if ((unsigned)D.Num < CurModule.Types.size()) if (D.Num < CurModule.Types.size())
return CurModule.Types[(unsigned)D.Num]; return CurModule.Types[D.Num];
break; break;
case ValID::NameVal: // Is it a named definition? case ValID::LocalName: // Is it a named definition?
if (const Type *N = CurModule.CurrentModule->getTypeByName(D.Name)) { if (const Type *N = CurModule.CurrentModule->getTypeByName(D.Name)) {
D.destroy(); // Free old strdup'd memory... D.destroy(); // Free old strdup'd memory...
return N; return N;
@ -294,11 +294,11 @@ static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) {
if (inFunctionScope()) { if (inFunctionScope()) {
if (D.Type == ValID::NameVal) { if (D.Type == ValID::LocalName) {
GenerateError("Reference to an undefined type: '" + D.getName() + "'"); GenerateError("Reference to an undefined type: '" + D.getName() + "'");
return 0; return 0;
} else { } else {
GenerateError("Reference to an undefined type: #" + itostr(D.Num)); GenerateError("Reference to an undefined type: #" + utostr(D.Num));
return 0; return 0;
} }
} }
@ -312,13 +312,6 @@ static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) {
return Typ; return Typ;
} }
static Value *lookupInSymbolTable(const Type *Ty, const std::string &Name) {
SymbolTable &SymTab =
inFunctionScope() ? CurFun.CurrentFunction->getValueSymbolTable() :
CurModule.CurrentModule->getValueSymbolTable();
return SymTab.lookup(Ty, Name);
}
// getValNonImprovising - Look up the value specified by the provided type and // getValNonImprovising - Look up the value specified by the provided type and
// the provided ValID. If the value exists and has already been defined, return // the provided ValID. If the value exists and has already been defined, return
// it. Otherwise return null. // it. Otherwise return null.
@ -331,29 +324,39 @@ static Value *getValNonImprovising(const Type *Ty, const ValID &D) {
} }
switch (D.Type) { switch (D.Type) {
case ValID::NumberVal: { // Is it a numbered definition? case ValID::LocalID: { // Is it a numbered definition?
unsigned Num = (unsigned)D.Num; // Module constants occupy the lowest numbered slots.
std::map<const Type*,ValueList>::iterator VI = CurFun.Values.find(Ty);
// Module constants occupy the lowest numbered slots... // Make sure that our type is within bounds.
std::map<const Type*,ValueList>::iterator VI = CurModule.Values.find(Ty);
if (VI != CurModule.Values.end()) {
if (Num < VI->second.size())
return VI->second[Num];
Num -= VI->second.size();
}
// Make sure that our type is within bounds
VI = CurFun.Values.find(Ty);
if (VI == CurFun.Values.end()) return 0; if (VI == CurFun.Values.end()) return 0;
// Check that the number is within bounds... // Check that the number is within bounds.
if (VI->second.size() <= Num) return 0; if (D.Num >= VI->second.size()) return 0;
return VI->second[D.Num];
}
case ValID::GlobalID: { // Is it a numbered definition?
unsigned Num = D.Num;
// Module constants occupy the lowest numbered slots...
std::map<const Type*,ValueList>::iterator VI = CurModule.Values.find(Ty);
if (VI == CurModule.Values.end()) return 0;
if (D.Num >= VI->second.size()) return 0;
return VI->second[Num]; return VI->second[Num];
} }
case ValID::NameVal: { // Is it a named definition? case ValID::LocalName: { // Is it a named definition?
Value *N = lookupInSymbolTable(Ty, std::string(D.Name)); if (!inFunctionScope()) return 0;
SymbolTable &SymTab = CurFun.CurrentFunction->getValueSymbolTable();
Value *N = SymTab.lookup(Ty, D.Name);
if (N == 0) return 0;
D.destroy(); // Free old strdup'd memory...
return N;
}
case ValID::GlobalName: { // Is it a named definition?
SymbolTable &SymTab = CurModule.CurrentModule->getValueSymbolTable();
Value *N = SymTab.lookup(Ty, D.Name);
if (N == 0) return 0; if (N == 0) return 0;
D.destroy(); // Free old strdup'd memory... D.destroy(); // Free old strdup'd memory...
@ -488,12 +491,12 @@ static BasicBlock *getBBVal(const ValID &ID, bool isDefinition = false) {
default: default:
GenerateError("Illegal label reference " + ID.getName()); GenerateError("Illegal label reference " + ID.getName());
return 0; return 0;
case ValID::NumberVal: // Is it a numbered definition? case ValID::LocalID: // Is it a numbered definition?
if (unsigned(ID.Num) >= CurFun.NumberedBlocks.size()) if (ID.Num >= CurFun.NumberedBlocks.size())
CurFun.NumberedBlocks.resize(ID.Num+1); CurFun.NumberedBlocks.resize(ID.Num+1);
BB = CurFun.NumberedBlocks[ID.Num]; BB = CurFun.NumberedBlocks[ID.Num];
break; break;
case ValID::NameVal: // Is it a named definition? case ValID::LocalName: // Is it a named definition?
Name = ID.Name; Name = ID.Name;
if (Value *N = CurFun.CurrentFunction-> if (Value *N = CurFun.CurrentFunction->
getValueSymbolTable().lookup(Type::LabelTy, Name)) getValueSymbolTable().lookup(Type::LabelTy, Name))
@ -518,7 +521,7 @@ static BasicBlock *getBBVal(const ValID &ID, bool isDefinition = false) {
// Otherwise this block has not been seen before. // Otherwise this block has not been seen before.
BB = new BasicBlock("", CurFun.CurrentFunction); BB = new BasicBlock("", CurFun.CurrentFunction);
if (ID.Type == ValID::NameVal) { if (ID.Type == ValID::LocalName) {
BB->setName(ID.Name); BB->setName(ID.Name);
} else { } else {
CurFun.NumberedBlocks[ID.Num] = BB; CurFun.NumberedBlocks[ID.Num] = BB;
@ -585,7 +588,7 @@ ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
// resolver table // resolver table
InsertValue(V, *FutureLateResolvers); InsertValue(V, *FutureLateResolvers);
} else { } else {
if (DID.Type == ValID::NameVal) { if (DID.Type == ValID::LocalName || DID.Type == ValID::GlobalName) {
GenerateError("Reference to an invalid definition: '" +DID.getName()+ GenerateError("Reference to an invalid definition: '" +DID.getName()+
"' of type '" + V->getType()->getDescription() + "'", "' of type '" + V->getType()->getDescription() + "'",
PHI->second.second); PHI->second.second);
@ -610,8 +613,8 @@ ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
// //
static void ResolveTypeTo(char *Name, const Type *ToTy) { static void ResolveTypeTo(char *Name, const Type *ToTy) {
ValID D; ValID D;
if (Name) D = ValID::create(Name); if (Name) D = ValID::createLocalName(Name);
else D = ValID::create((int)CurModule.Types.size()); else D = ValID::createLocalID(CurModule.Types.size());
std::map<ValID, PATypeHolder>::iterator I = std::map<ValID, PATypeHolder>::iterator I =
CurModule.LateResolveTypes.find(D); CurModule.LateResolveTypes.find(D);
@ -626,26 +629,25 @@ static void ResolveTypeTo(char *Name, const Type *ToTy) {
// assumed to be a malloc'd string buffer, and is free'd by this function. // assumed to be a malloc'd string buffer, and is free'd by this function.
// //
static void setValueName(Value *V, char *NameStr) { static void setValueName(Value *V, char *NameStr) {
if (NameStr) { if (!NameStr) return;
std::string Name(NameStr); // Copy string std::string Name(NameStr); // Copy string
free(NameStr); // Free old string free(NameStr); // Free old string
if (V->getType() == Type::VoidTy) { if (V->getType() == Type::VoidTy) {
GenerateError("Can't assign name '" + Name+"' to value with void type!"); GenerateError("Can't assign name '" + Name+"' to value with void type!");
return; return;
}
assert(inFunctionScope() && "Must be in function scope!");
SymbolTable &ST = CurFun.CurrentFunction->getValueSymbolTable();
if (ST.lookup(V->getType(), Name)) {
GenerateError("Redefinition of value '" + Name + "' of type '" +
V->getType()->getDescription() + "'!");
return;
}
// Set the name.
V->setName(Name);
} }
assert(inFunctionScope() && "Must be in function scope!");
SymbolTable &ST = CurFun.CurrentFunction->getValueSymbolTable();
if (ST.lookup(V->getType(), Name)) {
GenerateError("Redefinition of value '" + Name + "' of type '" +
V->getType()->getDescription() + "'!");
return;
}
// Set the name.
V->setName(Name);
} }
/// ParseGlobalVariable - Handle parsing of a global. If Initializer is null, /// ParseGlobalVariable - Handle parsing of a global. If Initializer is null,
@ -673,9 +675,9 @@ ParseGlobalVariable(char *NameStr,
// object. // object.
ValID ID; ValID ID;
if (!Name.empty()) { if (!Name.empty()) {
ID = ValID::create((char*)Name.c_str()); ID = ValID::createGlobalName((char*)Name.c_str());
} else { } else {
ID = ValID::create((int)CurModule.Values[PTy].size()); ID = ValID::createGlobalID(CurModule.Values[PTy].size());
} }
if (GlobalValue *FWGV = CurModule.GetForwardRefForGlobal(PTy, ID)) { if (GlobalValue *FWGV = CurModule.GetForwardRefForGlobal(PTy, ID)) {
@ -922,7 +924,6 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
llvm::Instruction::MemoryOps MemOpVal; llvm::Instruction::MemoryOps MemOpVal;
llvm::Instruction::CastOps CastOpVal; llvm::Instruction::CastOps CastOpVal;
llvm::Instruction::OtherOps OtherOpVal; llvm::Instruction::OtherOps OtherOpVal;
llvm::Module::Endianness Endianness;
llvm::ICmpInst::Predicate IPredicate; llvm::ICmpInst::Predicate IPredicate;
llvm::FCmpInst::Predicate FPredicate; llvm::FCmpInst::Predicate FPredicate;
} }
@ -949,7 +950,6 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
%type <Linkage> GVInternalLinkage GVExternalLinkage %type <Linkage> GVInternalLinkage GVExternalLinkage
%type <Linkage> FunctionDefineLinkage FunctionDeclareLinkage %type <Linkage> FunctionDefineLinkage FunctionDeclareLinkage
%type <Visibility> GVVisibilityStyle %type <Visibility> GVVisibilityStyle
%type <Endianness> BigOrLittle
// ValueRef - Unresolved reference to a definition or BB // ValueRef - Unresolved reference to a definition or BB
%type <ValIDVal> ValueRef ConstValueRef SymbolicValueRef %type <ValIDVal> ValueRef ConstValueRef SymbolicValueRef
@ -962,9 +962,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
// EUINT64VAL - A positive number within uns. long long range // EUINT64VAL - A positive number within uns. long long range
%token <UInt64Val> EUINT64VAL %token <UInt64Val> EUINT64VAL
%token <SIntVal> SINTVAL // Signed 32 bit ints... %token <UIntVal> LOCALVAL_ID GLOBALVAL_ID // %123 @123
%token <UIntVal> UINTVAL // Unsigned 32 bit ints...
%type <SIntVal> INTVAL
%token <FPVal> FPVAL // Float or Double constant %token <FPVal> FPVAL // Float or Double constant
// Built in types... // Built in types...
@ -974,16 +972,17 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
%token <PrimType> FLOAT DOUBLE LABEL %token <PrimType> FLOAT DOUBLE LABEL
%token TYPE %token TYPE
%token <StrVal> VAR_ID LABELSTR STRINGCONSTANT %token<StrVal> LOCALVAR GLOBALVAR LABELSTR STRINGCONSTANT ATSTRINGCONSTANT
%type <StrVal> Name OptName OptAssign %type <StrVal> LocalName OptLocalName OptLocalAssign
%type <UIntVal> OptAlign OptCAlign %type <StrVal> GlobalName OptGlobalAssign
%type <UIntVal> OptAlign OptCAlign
%type <StrVal> OptSection SectionString %type <StrVal> OptSection SectionString
%token IMPLEMENTATION ZEROINITIALIZER TRUETOK FALSETOK BEGINTOK ENDTOK %token IMPLEMENTATION ZEROINITIALIZER TRUETOK FALSETOK BEGINTOK ENDTOK
%token DECLARE DEFINE GLOBAL CONSTANT SECTION VOLATILE %token DECLARE DEFINE GLOBAL CONSTANT SECTION VOLATILE
%token TO DOTDOTDOT NULL_TOK UNDEF INTERNAL LINKONCE WEAK APPENDING %token TO DOTDOTDOT NULL_TOK UNDEF INTERNAL LINKONCE WEAK APPENDING
%token DLLIMPORT DLLEXPORT EXTERN_WEAK %token DLLIMPORT DLLEXPORT EXTERN_WEAK
%token OPAQUE EXTERNAL TARGET TRIPLE ENDIAN POINTERSIZE LITTLE BIG ALIGN %token OPAQUE EXTERNAL TARGET TRIPLE ALIGN
%token DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT %token DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT
%token CC_TOK CCC_TOK CSRETCC_TOK FASTCC_TOK COLDCC_TOK %token CC_TOK CCC_TOK CSRETCC_TOK FASTCC_TOK COLDCC_TOK
%token X86_STDCALLCC_TOK X86_FASTCALLCC_TOK %token X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
@ -1026,15 +1025,6 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
%start Module %start Module
%% %%
// Handle constant integer size restriction and conversion...
//
INTVAL : SINTVAL;
INTVAL : UINTVAL {
if ($1 > (uint32_t)INT32_MAX) // Outside of my range!
GEN_ERROR("Value too large for type!");
$$ = (int32_t)$1;
CHECK_FOR_ERROR
};
// Operations that are notably excluded from this list include: // Operations that are notably excluded from this list include:
// RET, BR, & SWITCH because they end basic blocks and are treated specially. // RET, BR, & SWITCH because they end basic blocks and are treated specially.
@ -1069,8 +1059,23 @@ FPredicates
IntType : INTTYPE; IntType : INTTYPE;
FPType : FLOAT | DOUBLE; FPType : FLOAT | DOUBLE;
// OptAssign - Value producing statements have an optional assignment component LocalName : LOCALVAR | STRINGCONSTANT;
OptAssign : Name '=' { OptLocalName : LocalName | /*empty*/ { $$ = 0; };
/// OptLocalAssign - Value producing statements have an optional assignment
/// component.
OptLocalAssign : LocalName '=' {
$$ = $1;
CHECK_FOR_ERROR
}
| /*empty*/ {
$$ = 0;
CHECK_FOR_ERROR
};
GlobalName : GLOBALVAR | ATSTRINGCONSTANT;
OptGlobalAssign : GlobalName '=' {
$$ = $1; $$ = $1;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
@ -1630,7 +1635,10 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
$2.destroy(); $2.destroy();
} else { } else {
std::string Name; std::string Name;
if ($2.Type == ValID::NameVal) Name = $2.Name; if ($2.Type == ValID::GlobalName)
Name = $2.Name;
else if ($2.Type != ValID::GlobalID)
GEN_ERROR("Invalid reference to global");
// Create the forward referenced global. // Create the forward referenced global.
GlobalValue *GV; GlobalValue *GV;
@ -1857,7 +1865,7 @@ Definition
// Emit an error if there are any unresolved types left. // Emit an error if there are any unresolved types left.
if (!CurModule.LateResolveTypes.empty()) { if (!CurModule.LateResolveTypes.empty()) {
const ValID &DID = CurModule.LateResolveTypes.begin()->first; const ValID &DID = CurModule.LateResolveTypes.begin()->first;
if (DID.Type == ValID::NameVal) { if (DID.Type == ValID::LocalName) {
GEN_ERROR("Reference to an undefined type: '"+DID.getName() + "'"); GEN_ERROR("Reference to an undefined type: '"+DID.getName() + "'");
} else { } else {
GEN_ERROR("Reference to an undefined type: #" + itostr(DID.Num)); GEN_ERROR("Reference to an undefined type: #" + itostr(DID.Num));
@ -1865,7 +1873,7 @@ Definition
} }
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| OptAssign TYPE Types { | OptLocalAssign TYPE Types {
if (!UpRefs.empty()) if (!UpRefs.empty())
GEN_ERROR("Invalid upreference in type: " + (*$3)->getDescription()); GEN_ERROR("Invalid upreference in type: " + (*$3)->getDescription());
// Eagerly resolve types. This is not an optimization, this is a // Eagerly resolve types. This is not an optimization, this is a
@ -1889,7 +1897,7 @@ Definition
delete $3; delete $3;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| OptAssign TYPE VOID { | OptLocalAssign TYPE VOID {
ResolveTypeTo($1, $3); ResolveTypeTo($1, $3);
if (!setTypeName($3, $1) && !$1) { if (!setTypeName($3, $1) && !$1) {
@ -1900,7 +1908,8 @@ Definition
} }
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| OptAssign GVVisibilityStyle GlobalType ConstVal { /* "Externally Visible" Linkage */ | OptGlobalAssign GVVisibilityStyle GlobalType ConstVal {
/* "Externally Visible" Linkage */
if ($4 == 0) if ($4 == 0)
GEN_ERROR("Global value initializer is not a constant!"); GEN_ERROR("Global value initializer is not a constant!");
CurGV = ParseGlobalVariable($1, GlobalValue::ExternalLinkage, CurGV = ParseGlobalVariable($1, GlobalValue::ExternalLinkage,
@ -1909,7 +1918,7 @@ Definition
} GlobalVarAttributes { } GlobalVarAttributes {
CurGV = 0; CurGV = 0;
} }
| OptAssign GVInternalLinkage GVVisibilityStyle GlobalType ConstVal { | OptGlobalAssign GVInternalLinkage GVVisibilityStyle GlobalType ConstVal {
if ($5 == 0) if ($5 == 0)
GEN_ERROR("Global value initializer is not a constant!"); GEN_ERROR("Global value initializer is not a constant!");
CurGV = ParseGlobalVariable($1, $2, $3, $4, $5->getType(), $5); CurGV = ParseGlobalVariable($1, $2, $3, $4, $5->getType(), $5);
@ -1917,7 +1926,7 @@ Definition
} GlobalVarAttributes { } GlobalVarAttributes {
CurGV = 0; CurGV = 0;
} }
| OptAssign GVExternalLinkage GVVisibilityStyle GlobalType Types { | OptGlobalAssign GVExternalLinkage GVVisibilityStyle GlobalType Types {
if (!UpRefs.empty()) if (!UpRefs.empty())
GEN_ERROR("Invalid upreference in type: " + (*$5)->getDescription()); GEN_ERROR("Invalid upreference in type: " + (*$5)->getDescription());
CurGV = ParseGlobalVariable($1, $2, $3, $4, *$5, 0); CurGV = ParseGlobalVariable($1, $2, $3, $4, *$5, 0);
@ -1949,23 +1958,7 @@ AsmBlock : STRINGCONSTANT {
CHECK_FOR_ERROR CHECK_FOR_ERROR
}; };
BigOrLittle : BIG { $$ = Module::BigEndian; }; TargetDefinition : TRIPLE '=' STRINGCONSTANT {
BigOrLittle : LITTLE { $$ = Module::LittleEndian; };
TargetDefinition : ENDIAN '=' BigOrLittle {
CurModule.CurrentModule->setEndianness($3);
CHECK_FOR_ERROR
}
| POINTERSIZE '=' EUINT64VAL {
if ($3 == 32)
CurModule.CurrentModule->setPointerSize(Module::Pointer32);
else if ($3 == 64)
CurModule.CurrentModule->setPointerSize(Module::Pointer64);
else
GEN_ERROR("Invalid pointer size: '" + utostr($3) + "'!");
CHECK_FOR_ERROR
}
| TRIPLE '=' STRINGCONSTANT {
CurModule.CurrentModule->setTargetTriple($3); CurModule.CurrentModule->setTargetTriple($3);
free($3); free($3);
} }
@ -1995,10 +1988,7 @@ LibList : LibList ',' STRINGCONSTANT {
// Rules to match Function Headers // Rules to match Function Headers
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
Name : VAR_ID | STRINGCONSTANT; ArgListH : ArgListH ',' Types OptParamAttrs OptLocalName {
OptName : Name | /*empty*/ { $$ = 0; };
ArgListH : ArgListH ',' Types OptParamAttrs OptName {
if (!UpRefs.empty()) if (!UpRefs.empty())
GEN_ERROR("Invalid upreference in type: " + (*$3)->getDescription()); GEN_ERROR("Invalid upreference in type: " + (*$3)->getDescription());
if (*$3 == Type::VoidTy) if (*$3 == Type::VoidTy)
@ -2008,7 +1998,7 @@ ArgListH : ArgListH ',' Types OptParamAttrs OptName {
$1->push_back(E); $1->push_back(E);
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| Types OptParamAttrs OptName { | Types OptParamAttrs OptLocalName {
if (!UpRefs.empty()) if (!UpRefs.empty())
GEN_ERROR("Invalid upreference in type: " + (*$1)->getDescription()); GEN_ERROR("Invalid upreference in type: " + (*$1)->getDescription());
if (*$1 == Type::VoidTy) if (*$1 == Type::VoidTy)
@ -2046,7 +2036,7 @@ ArgList : ArgListH {
CHECK_FOR_ERROR CHECK_FOR_ERROR
}; };
FunctionHeaderH : OptCallingConv ResultTypes Name '(' ArgList ')' FunctionHeaderH : OptCallingConv ResultTypes GlobalName '(' ArgList ')'
OptFuncAttrs OptSection OptAlign { OptFuncAttrs OptSection OptAlign {
UnEscapeLexed($3); UnEscapeLexed($3);
std::string FunctionName($3); std::string FunctionName($3);
@ -2081,9 +2071,9 @@ FunctionHeaderH : OptCallingConv ResultTypes Name '(' ArgList ')'
ValID ID; ValID ID;
if (!FunctionName.empty()) { if (!FunctionName.empty()) {
ID = ValID::create((char*)FunctionName.c_str()); ID = ValID::createGlobalName((char*)FunctionName.c_str());
} else { } else {
ID = ValID::create((int)CurModule.Values[PFT].size()); ID = ValID::createGlobalID(CurModule.Values[PFT].size());
} }
Function *Fn = 0; Function *Fn = 0;
@ -2266,12 +2256,20 @@ ConstValueRef : ESINT64VAL { // A reference to a direct constant
// SymbolicValueRef - Reference to one of two ways of symbolically refering to // SymbolicValueRef - Reference to one of two ways of symbolically refering to
// another value. // another value.
// //
SymbolicValueRef : INTVAL { // Is it an integer reference...? SymbolicValueRef : LOCALVAL_ID { // Is it an integer reference...?
$$ = ValID::create($1); $$ = ValID::createLocalID($1);
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| Name { // Is it a named reference...? | GLOBALVAL_ID {
$$ = ValID::create($1); $$ = ValID::createGlobalID($1);
CHECK_FOR_ERROR
}
| LocalName { // Is it a named reference...?
$$ = ValID::createLocalName($1);
CHECK_FOR_ERROR
}
| GlobalName { // Is it a named reference...?
$$ = ValID::createGlobalName($1);
CHECK_FOR_ERROR CHECK_FOR_ERROR
}; };
@ -2304,7 +2302,7 @@ BasicBlockList : BasicBlockList BasicBlock {
// Basic blocks are terminated by branching instructions: // Basic blocks are terminated by branching instructions:
// br, br/cc, switch, ret // br, br/cc, switch, ret
// //
BasicBlock : InstructionList OptAssign BBTerminatorInst { BasicBlock : InstructionList OptLocalAssign BBTerminatorInst {
setValueName($3, $2); setValueName($3, $2);
CHECK_FOR_ERROR CHECK_FOR_ERROR
InsertValue($3); InsertValue($3);
@ -2325,7 +2323,7 @@ InstructionList : InstructionList Inst {
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| /* empty */ { | /* empty */ {
$$ = getBBVal(ValID::create((int)CurFun.NextBBNum++), true); $$ = getBBVal(ValID::createLocalID(CurFun.NextBBNum++), true);
CHECK_FOR_ERROR CHECK_FOR_ERROR
// Make sure to move the basic block to the correct location in the // Make sure to move the basic block to the correct location in the
@ -2337,7 +2335,7 @@ InstructionList : InstructionList Inst {
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| LABELSTR { | LABELSTR {
$$ = getBBVal(ValID::create($1), true); $$ = getBBVal(ValID::createLocalName($1), true);
CHECK_FOR_ERROR CHECK_FOR_ERROR
// Make sure to move the basic block to the correct location in the // Make sure to move the basic block to the correct location in the
@ -2502,7 +2500,7 @@ JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef {
$$->push_back(std::make_pair(V, tmpBB)); $$->push_back(std::make_pair(V, tmpBB));
}; };
Inst : OptAssign InstVal { Inst : OptLocalAssign InstVal {
// Is this definition named?? if so, assign the name... // Is this definition named?? if so, assign the name...
setValueName($2, $1); setValueName($2, $1);
CHECK_FOR_ERROR CHECK_FOR_ERROR
@ -2762,6 +2760,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
CI->setCallingConv($2); CI->setCallingConv($2);
$$ = CI; $$ = CI;
delete $6; delete $6;
delete $3;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| MemoryInst { | MemoryInst {