From 66db8e4aab851c3b759be0400ad324bc3dd3a9ff Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 6 Nov 2005 06:34:12 +0000 Subject: [PATCH] factor optional alignment git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24207 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AsmParser/llvmAsmParser.y | 57 ++++++++++++++--------------------- 1 file changed, 23 insertions(+), 34 deletions(-) diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 6bfc3bb8e83..678e62746e2 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -948,7 +948,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) { %token VAR_ID LABELSTR STRINGCONSTANT %type Name OptName OptAssign - +%type OptCAlign %token IMPLEMENTATION ZEROINITIALIZER TRUETOK FALSETOK BEGINTOK ENDTOK %token DECLARE GLOBAL CONSTANT VOLATILE @@ -1035,6 +1035,11 @@ OptCallingConv : /*empty*/ { $$ = CallingConv::C; } | $$ = $2; }; +// OptAlign/OptCAlign - An optional alignment, and an optional alignment with +// a comma before it. +OptCAlign : /*empty*/ { $$ = 0; } | + ',' ALIGN EUINT64VAL { $$ = $3; }; + //===----------------------------------------------------------------------===// // Types includes all predefined types... except void, because it can only be // used in specific contexts (function returning void for example). To have @@ -2204,48 +2209,32 @@ OptVolatile : VOLATILE { -MemoryInst : MALLOC Types { - $$ = new MallocInst(*$2); +MemoryInst : MALLOC Types OptCAlign { + if ($3 & ($3-1)) + ThrowException("Alignment amount '" + utostr($3) + + "' is not a power of 2!"); + $$ = new MallocInst(*$2, 0, $3); delete $2; } - | MALLOC Types ',' ALIGN EUINT64VAL { - if ($5 & ($5-1)) - ThrowException("Alignment amount '" + utostr($5) + + | MALLOC Types ',' UINT ValueRef OptCAlign { + if ($6 & ($6-1)) + ThrowException("Alignment amount '" + utostr($6) + "' is not a power of 2!"); - $$ = new MallocInst(*$2, 0, $5); - delete $2; - } - | MALLOC Types ',' UINT ValueRef { - $$ = new MallocInst(*$2, getVal($4, $5)); + $$ = new MallocInst(*$2, getVal($4, $5), $6); delete $2; } - | MALLOC Types ',' UINT ValueRef ',' ALIGN EUINT64VAL { - if ($8 & ($8-1)) - ThrowException("Alignment amount '" + utostr($8) + + | ALLOCA Types OptCAlign { + if ($3 & ($3-1)) + ThrowException("Alignment amount '" + utostr($3) + "' is not a power of 2!"); - $$ = new MallocInst(*$2, getVal($4, $5), $8); - delete $2; - } - | ALLOCA Types { - $$ = new AllocaInst(*$2); - delete $2; - } - | ALLOCA Types ',' ALIGN EUINT64VAL { - if ($5 & ($5-1)) - ThrowException("Alignment amount '" + utostr($5) + - "' is not a power of 2!"); - $$ = new AllocaInst(*$2, 0, $5); - delete $2; - } - | ALLOCA Types ',' UINT ValueRef { - $$ = new AllocaInst(*$2, getVal($4, $5)); + $$ = new AllocaInst(*$2, 0, $3); delete $2; } - | ALLOCA Types ',' UINT ValueRef ',' ALIGN EUINT64VAL { - if ($8 & ($8-1)) - ThrowException("Alignment amount '" + utostr($8) + + | ALLOCA Types ',' UINT ValueRef OptCAlign { + if ($6 & ($6-1)) + ThrowException("Alignment amount '" + utostr($6) + "' is not a power of 2!"); - $$ = new AllocaInst(*$2, getVal($4, $5), $8); + $$ = new AllocaInst(*$2, getVal($4, $5), $6); delete $2; } | FREE ResolvedVal { -- 2.34.1