+ $$ = ConstantFP::get($1, $2);
+ };
+
+
+ConstExpr: CAST '(' ConstVal TO Types ')' {
+ $$ = ConstantExpr::getCast($3, $5->get());
+ delete $5;
+ }
+ | GETELEMENTPTR '(' ConstVal IndexList ')' {
+ if (!isa<PointerType>($3->getType()))
+ ThrowException("GetElementPtr requires a pointer operand!");
+
+ const Type *IdxTy =
+ GetElementPtrInst::getIndexedType($3->getType(), *$4, true);
+ if (!IdxTy)
+ ThrowException("Index list invalid for constant getelementptr!");
+
+ vector<Constant*> IdxVec;
+ for (unsigned i = 0, e = $4->size(); i != e; ++i)
+ if (Constant *C = dyn_cast<Constant>((*$4)[i]))
+ IdxVec.push_back(C);
+ else
+ ThrowException("Indices to constant getelementptr must be constants!");
+
+ delete $4;
+
+ $$ = ConstantExpr::getGetElementPtr($3, IdxVec);
+ }
+ | BinaryOps '(' ConstVal ',' ConstVal ')' {
+ if ($3->getType() != $5->getType())
+ ThrowException("Binary operator types must match!");
+ $$ = ConstantExpr::get($1, $3, $5);