summaryrefslogtreecommitdiffstats
path: root/llvm/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
commit3ab46f1383c57f744b694ab3c2f00fcdaca4c69c (patch)
treeec486adf35a6b186711972ebba6493238e6ddd12 /llvm/lib/AsmParser/llvmAsmParser.y
parent401ef2e426ea24b28649037044aaacc3dbc25b8f (diff)
downloadbcm5719-llvm-3ab46f1383c57f744b694ab3c2f00fcdaca4c69c.tar.gz
bcm5719-llvm-3ab46f1383c57f744b694ab3c2f00fcdaca4c69c.zip
AsmParser support for immediate constant aggregate values.
llvm-svn: 52149
Diffstat (limited to 'llvm/lib/AsmParser/llvmAsmParser.y')
-rw-r--r--llvm/lib/AsmParser/llvmAsmParser.y82
1 files changed, 75 insertions, 7 deletions
diff --git a/llvm/lib/AsmParser/llvmAsmParser.y b/llvm/lib/AsmParser/llvmAsmParser.y
index fd1fe41a1ef..ea3aef3a0bc 100644
--- a/llvm/lib/AsmParser/llvmAsmParser.y
+++ b/llvm/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
OpenPOWER on IntegriCloud