summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-03-01 19:32:01 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-03-01 19:32:01 +0000
commit666ea0d046cfa43068f2f873cceeed6820c5bdcd (patch)
tree83cd5af3ca2d4be0d565f4dd5a67fd0b5ac26998
parenta127633716e6539b80c2b76e69b16c91c5511f4e (diff)
downloadbcm5719-llvm-666ea0d046cfa43068f2f873cceeed6820c5bdcd.tar.gz
bcm5719-llvm-666ea0d046cfa43068f2f873cceeed6820c5bdcd.zip
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. llvm-svn: 34794
-rw-r--r--llvm/lib/AsmParser/llvmAsmParser.y25
1 files changed, 9 insertions, 16 deletions
diff --git a/llvm/lib/AsmParser/llvmAsmParser.y b/llvm/lib/AsmParser/llvmAsmParser.y
index e70f25a7cf5..1af8fda49c6 100644
--- a/llvm/lib/AsmParser/llvmAsmParser.y
+++ b/llvm/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
}
OpenPOWER on IntegriCloud