aboutsummaryrefslogtreecommitdiff
path: root/lib/AsmParser/llvmAsmParser.y
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-06-09 14:45:02 +0000
committerDan Gohman <gohman@apple.com>2008-06-09 14:45:02 +0000
commitf910eaaddd2491d22eb4ec6b524dc9a7e80dfcb5 (patch)
treeb6fb8579cb510e6e37e301404d910c7dbb7ef03d /lib/AsmParser/llvmAsmParser.y
parent75146a6725739fe11ca183f1c4c5518eb164b2e5 (diff)
AsmParser support for immediate constant aggregate values.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52149 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AsmParser/llvmAsmParser.y')
-rw-r--r--lib/AsmParser/llvmAsmParser.y82
1 files changed, 75 insertions, 7 deletions
diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y
index fd1fe41a1e..ea3aef3a0b 100644
--- a/lib/AsmParser/llvmAsmParser.y
+++ b/lib/AsmParser/llvmAsmParser.y
@@ -2485,13 +2485,7 @@ ConstValueRef : ESINT64VAL { // A reference to a direct constant
GEN_ERROR("Invalid vector element type: " + ETy->getDescription());
VectorType* pt = VectorType::get(ETy, NumElements);
- PATypeHolder* PTy = new PATypeHolder(
- HandleUpRefs(
- VectorType::get(
- ETy,
- NumElements)
- )
- );
+ PATypeHolder* PTy = new PATypeHolder(HandleUpRefs(pt));
// Verify all elements are correct type!
for (unsigned i = 0; i < $2->size(); i++) {
@@ -2505,6 +2499,80 @@ ConstValueRef : ESINT64VAL { // A reference to a direct constant
delete PTy; delete $2;
CHECK_FOR_ERROR
}
+ | '[' ConstVector ']' { // Nonempty unsized arr
+ const Type *ETy = (*$2)[0]->getType();
+ int NumElements = $2->size();
+
+ if (!ETy->isFirstClassType())
+ GEN_ERROR("Invalid array element type: " + ETy->getDescription());
+
+ ArrayType *ATy = ArrayType::get(ETy, NumElements);
+ PATypeHolder* PTy = new PATypeHolder(HandleUpRefs(ATy));
+
+ // Verify all elements are correct type!
+ for (unsigned i = 0; i < $2->size(); i++) {
+ if (ETy != (*$2)[i]->getType())
+ GEN_ERROR("Element #" + utostr(i) + " is not of type '" +
+ ETy->getDescription() +"' as required!\nIt is of type '"+
+ (*$2)[i]->getType()->getDescription() + "'.");
+ }
+
+ $$ = ValID::create(ConstantArray::get(ATy, *$2));
+ delete PTy; delete $2;
+ CHECK_FOR_ERROR
+ }
+ | '[' ']' {
+ $$ = ValID::createUndef();
+ CHECK_FOR_ERROR
+ }
+ | 'c' STRINGCONSTANT {
+ int NumElements = $2->length();
+ const Type *ETy = Type::Int8Ty;
+
+ ArrayType *ATy = ArrayType::get(ETy, NumElements);
+
+ std::vector<Constant*> Vals;
+ for (unsigned i = 0; i < $2->length(); ++i)
+ Vals.push_back(ConstantInt::get(ETy, (*$2)[i]));
+ delete $2;
+ $$ = ValID::create(ConstantArray::get(ATy, Vals));
+ CHECK_FOR_ERROR
+ }
+ | '{' ConstVector '}' {
+ std::vector<const Type*> Elements($2->size());
+ for (unsigned i = 0, e = $2->size(); i != e; ++i)
+ Elements[i] = (*$2)[i]->getType();
+
+ const StructType *STy = StructType::get(Elements);
+ PATypeHolder* PTy = new PATypeHolder(HandleUpRefs(STy));
+
+ $$ = ValID::create(ConstantStruct::get(STy, *$2));
+ delete PTy; delete $2;
+ CHECK_FOR_ERROR
+ }
+ | '{' '}' {
+ const StructType *STy = StructType::get(std::vector<const Type*>());
+ $$ = ValID::create(ConstantStruct::get(STy, std::vector<Constant*>()));
+ CHECK_FOR_ERROR
+ }
+ | '<' '{' ConstVector '}' '>' {
+ std::vector<const Type*> Elements($3->size());
+ for (unsigned i = 0, e = $3->size(); i != e; ++i)
+ Elements[i] = (*$3)[i]->getType();
+
+ const StructType *STy = StructType::get(Elements, /*isPacked=*/true);
+ PATypeHolder* PTy = new PATypeHolder(HandleUpRefs(STy));
+
+ $$ = ValID::create(ConstantStruct::get(STy, *$3));
+ delete PTy; delete $3;
+ CHECK_FOR_ERROR
+ }
+ | '<' '{' '}' '>' {
+ const StructType *STy = StructType::get(std::vector<const Type*>(),
+ /*isPacked=*/true);
+ $$ = ValID::create(ConstantStruct::get(STy, std::vector<Constant*>()));
+ CHECK_FOR_ERROR
+ }
| ConstExpr {
$$ = ValID::create($1);
CHECK_FOR_ERROR