diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-03-01 19:32:01 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-03-01 19:32:01 +0000 |
commit | af1aacd91a3194dc3894cc84ea0982f364ebb762 (patch) | |
tree | b5cb23c0f1f869d82df622997b65b90d047d4c39 | |
parent | ef2185b4d2784d25c0fc6849b298a61e90541096 (diff) |
Use a simpler constructor when constructing ConstantInt. Also, replace
verbose code to sext/trunc or zext/trunc and APInt with new methods on
that class.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34794 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/AsmParser/llvmAsmParser.y | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index e70f25a7cf..1af8fda49c 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -1713,22 +1713,17 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr GEN_ERROR("Constant value doesn't fit in type"); APInt Val(64, $2); uint32_t BitWidth = cast<IntegerType>($1)->getBitWidth(); - if (BitWidth > 64) - Val.sext(BitWidth); - else if (BitWidth < 64) - Val.trunc(BitWidth); - $$ = ConstantInt::get($1, Val); + Val.sextOrTrunc(BitWidth); + $$ = ConstantInt::get(Val); CHECK_FOR_ERROR } | IntType ESAPINTVAL { // arbitrary precision integer constants uint32_t BitWidth = cast<IntegerType>($1)->getBitWidth(); if ($2->getBitWidth() > BitWidth) { GEN_ERROR("Constant value does not fit in type"); - } else if ($2->getBitWidth() < BitWidth) - $2->sext(BitWidth); - else if ($2->getBitWidth() > BitWidth) - $2->trunc(BitWidth); - $$ = ConstantInt::get($1, *$2); + } + $2->sextOrTrunc(BitWidth); + $$ = ConstantInt::get(*$2); delete $2; CHECK_FOR_ERROR } @@ -1737,18 +1732,16 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr GEN_ERROR("Constant value doesn't fit in type"); uint32_t BitWidth = cast<IntegerType>($1)->getBitWidth(); APInt Val(BitWidth, $2); - $$ = ConstantInt::get($1, Val); + $$ = ConstantInt::get(Val); CHECK_FOR_ERROR } | IntType EUAPINTVAL { // arbitrary precision integer constants uint32_t BitWidth = cast<IntegerType>($1)->getBitWidth(); if ($2->getBitWidth() > BitWidth) { GEN_ERROR("Constant value does not fit in type"); - } else if ($2->getBitWidth() < BitWidth) - $2->zext(BitWidth); - else if ($2->getBitWidth() > BitWidth) - $2->trunc(BitWidth); - $$ = ConstantInt::get($1, *$2); + } + $2->zextOrTrunc(BitWidth); + $$ = ConstantInt::get(*$2); delete $2; CHECK_FOR_ERROR } |