//
// The LLVM Compiler Infrastructure
//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Check to make sure that "Ty" is an integral type, and that our
// value will fit into the specified type...
case ValID::ConstSIntVal: // Is it a constant pool reference??
- if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
+ if (!isa<IntegerType>(Ty) ||
+ !ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
GenerateError("Signed integral constant '" +
itostr(D.ConstPool64) + "' is invalid for type '" +
Ty->getDescription() + "'");
return ConstantInt::get(Ty, D.ConstPool64, true);
case ValID::ConstUIntVal: // Is it an unsigned const pool reference?
- if (!ConstantInt::isValueValidForType(Ty, D.UConstPool64)) {
- if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
- GenerateError("Integral constant '" + utostr(D.UConstPool64) +
- "' is invalid or out of range");
- return 0;
- } else { // This is really a signed reference. Transmogrify.
- return ConstantInt::get(Ty, D.ConstPool64, true);
- }
- } else {
+ if (isa<IntegerType>(Ty) &&
+ ConstantInt::isValueValidForType(Ty, D.UConstPool64))
return ConstantInt::get(Ty, D.UConstPool64);
+
+ if (!isa<IntegerType>(Ty) ||
+ !ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
+ GenerateError("Integral constant '" + utostr(D.UConstPool64) +
+ "' is invalid or out of range for type '" +
+ Ty->getDescription() + "'");
+ return 0;
}
+ // This is really a signed reference. Transmogrify.
+ return ConstantInt::get(Ty, D.ConstPool64, true);
case ValID::ConstFPVal: // Is it a floating point const pool reference?
- if (!ConstantFP::isValueValidForType(Ty, *D.ConstPoolFP)) {
+ if (!Ty->isFloatingPoint() ||
+ !ConstantFP::isValueValidForType(Ty, *D.ConstPoolFP)) {
GenerateError("FP constant invalid for type");
return 0;
}
} if (ID.Type == ValID::LocalName) {
std::string Name = ID.getName();
Value *N = CurFun.CurrentFunction->getValueSymbolTable().lookup(Name);
- if (N)
+ if (N) {
if (N->getType()->getTypeID() == Type::LabelTyID)
BB = cast<BasicBlock>(N);
else
GenerateError("Reference to label '" + Name + "' is actually of type '"+
N->getType()->getDescription() + "'");
+ }
} else if (ID.Type == ValID::LocalID) {
if (ID.Num < CurFun.NextValNum && ID.Num < CurFun.Values.size()) {
if (CurFun.Values[ID.Num]->getType()->getTypeID() == Type::LabelTyID)
llvm::GlobalValue::LinkageTypes Linkage;
llvm::GlobalValue::VisibilityTypes Visibility;
- uint16_t ParamAttrs;
+ llvm::ParameterAttributes ParamAttrs;
llvm::APInt *APIntVal;
int64_t SInt64Val;
uint64_t UInt64Val;
%type <StrVal> GlobalName OptGlobalAssign GlobalAssign
%type <StrVal> OptSection SectionString OptGC
-%type <UIntVal> OptAlign OptCAlign
+%type <UIntVal> OptAlign OptCAlign OptAddrSpace
%token ZEROINITIALIZER TRUETOK FALSETOK BEGINTOK ENDTOK
%token DECLARE DEFINE GLOBAL CONSTANT SECTION ALIAS VOLATILE THREAD_LOCAL
// Other Operators
%token <OtherOpVal> PHI_TOK SELECT VAARG
%token <OtherOpVal> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
+%token <OtherOpVal> GETRESULT
// Function Attributes
%token SIGNEXT ZEROEXT NORETURN INREG SRET NOUNWIND NOALIAS BYVAL NEST
LocalName : LOCALVAR | STRINGCONSTANT | PCTSTRINGCONSTANT ;
OptLocalName : LocalName | /*empty*/ { $$ = 0; };
+OptAddrSpace : ADDRSPACE '(' EUINT64VAL ')' { $$=$3; }
+ | /*empty*/ { $$=0; };
+
/// OptLocalAssign - Value producing statements have an optional assignment
/// component.
OptLocalAssign : LocalName '=' {
$$ = new PATypeHolder($1);
CHECK_FOR_ERROR
}
- | Types '*' { // Pointer type?
- if (*$1 == Type::LabelTy)
- GEN_ERROR("Cannot form a pointer to a basic block");
- $$ = new PATypeHolder(HandleUpRefs(PointerType::get(*$1)));
- delete $1;
- CHECK_FOR_ERROR
- }
- | Types ADDRSPACE '(' EUINT64VAL ')' '*' { // Pointer type?
+ | Types OptAddrSpace '*' { // Pointer type?
if (*$1 == Type::LabelTy)
GEN_ERROR("Cannot form a pointer to a basic block");
- $$ = new PATypeHolder(HandleUpRefs(PointerType::get(*$1, $4)));
+ $$ = new PATypeHolder(HandleUpRefs(PointerType::get(*$1, $2)));
delete $1;
CHECK_FOR_ERROR
}
GEN_ERROR("Invalid upreference in type: " + (*$1)->getDescription());
const PointerType *Ty = dyn_cast<PointerType>($1->get());
if (Ty == 0)
- GEN_ERROR("Global const reference must be a pointer type");
+ GEN_ERROR("Global const reference must be a pointer type " + (*$1)->getDescription());
// ConstExprs can exist in the body of a function, thus creating
// GlobalValues whenever they refer to a variable. Because we are in
}
CHECK_FOR_ERROR
}
- | OptGlobalAssign GVVisibilityStyle ThreadLocal GlobalType ConstVal {
+ | OptGlobalAssign GVVisibilityStyle ThreadLocal GlobalType ConstVal
+ OptAddrSpace {
/* "Externally Visible" Linkage */
if ($5 == 0)
GEN_ERROR("Global value initializer is not a constant");
CurGV = ParseGlobalVariable($1, GlobalValue::ExternalLinkage,
- $2, $4, $5->getType(), $5, $3);
- CHECK_FOR_ERROR
- } GlobalVarAttributes {
- CurGV = 0;
- }
- | OptGlobalAssign GVVisibilityStyle ThreadLocal GlobalType ConstVal
- ADDRSPACE '(' EUINT64VAL ')' {
- /* "Externally Visible" Linkage with address space qualifier */
- if ($5 == 0)
- GEN_ERROR("Global value initializer is not a constant");
- CurGV = ParseGlobalVariable($1, GlobalValue::ExternalLinkage,
- $2, $4, $5->getType(), $5, $3, $8);
+ $2, $4, $5->getType(), $5, $3, $6);
CHECK_FOR_ERROR
} GlobalVarAttributes {
CurGV = 0;
}
| OptGlobalAssign GVInternalLinkage GVVisibilityStyle ThreadLocal GlobalType
- ConstVal {
+ ConstVal OptAddrSpace {
if ($6 == 0)
GEN_ERROR("Global value initializer is not a constant");
- CurGV = ParseGlobalVariable($1, $2, $3, $5, $6->getType(), $6, $4);
+ CurGV = ParseGlobalVariable($1, $2, $3, $5, $6->getType(), $6, $4, $7);
CHECK_FOR_ERROR
} GlobalVarAttributes {
CurGV = 0;
}
| OptGlobalAssign GVExternalLinkage GVVisibilityStyle ThreadLocal GlobalType
- Types {
+ Types OptAddrSpace {
if (!UpRefs.empty())
GEN_ERROR("Invalid upreference in type: " + (*$6)->getDescription());
- CurGV = ParseGlobalVariable($1, $2, $3, $5, *$6, 0, $4);
+ CurGV = ParseGlobalVariable($1, $2, $3, $5, *$6, 0, $4, $7);
CHECK_FOR_ERROR
delete $6;
} GlobalVarAttributes {
PAL = ParamAttrsList::get(Attrs);
FunctionType *FT = FunctionType::get(*$2, ParamTypeList, isVarArg);
- const PointerType *PFT = PointerType::get(FT);
+ const PointerType *PFT = PointerType::getUnqual(FT);
delete $2;
ValID ID;
ParamTypes.push_back(Ty);
}
Ty = FunctionType::get($3->get(), ParamTypes, false);
- PFTy = PointerType::get(Ty);
+ PFTy = PointerType::getUnqual(Ty);
}
delete $3;
if (Ty->isVarArg()) {
if (I == E)
- for (; ArgI != ArgE; ++ArgI)
+ for (; ArgI != ArgE; ++ArgI, ++index) {
Args.push_back(ArgI->Val); // push the remaining varargs
+ if (ArgI->Attrs != ParamAttr::None) {
+ ParamAttrsWithIndex PAWI;
+ PAWI.index = index;
+ PAWI.attrs = ArgI->Attrs;
+ Attrs.push_back(PAWI);
+ }
+ }
} else if (I != E || ArgI != ArgE)
GEN_ERROR("Invalid number of parameters detected");
}
ParamTypes.push_back(Ty);
}
Ty = FunctionType::get($3->get(), ParamTypes, false);
- PFTy = PointerType::get(Ty);
+ PFTy = PointerType::getUnqual(Ty);
}
Value *V = getVal(PFTy, $4); // Get the function we're calling...
}
if (Ty->isVarArg()) {
if (I == E)
- for (; ArgI != ArgE; ++ArgI)
+ for (; ArgI != ArgE; ++ArgI, ++index) {
Args.push_back(ArgI->Val); // push the remaining varargs
+ if (ArgI->Attrs != ParamAttr::None) {
+ ParamAttrsWithIndex PAWI;
+ PAWI.index = index;
+ PAWI.attrs = ArgI->Attrs;
+ Attrs.push_back(PAWI);
+ }
+ }
} else if (I != E || ArgI != ArgE)
GEN_ERROR("Invalid number of parameters detected");
}
$$ = new StoreInst($3, tmpVal, $1, $7);
delete $5;
}
+| GETRESULT Types LocalName ',' ConstVal {
+ ValID TmpVID = ValID::createLocalName(*$3);
+ Value *TmpVal = getVal($2->get(), TmpVID);
+ if (!GetResultInst::isValidOperands(TmpVal, $5))
+ GEN_ERROR("Invalid getresult operands");
+ $$ = new GetResultInst(TmpVal, $5);
+ CHECK_FOR_ERROR
+ }
| GETELEMENTPTR Types ValueRef IndexList {
if (!UpRefs.empty())
GEN_ERROR("Invalid upreference in type: " + (*$2)->getDescription());