mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-22 12:08:26 +00:00
492acdd450
Differential Revision: http://reviews.llvm.org/D19154 Patch by Eugene Kosov <claprix@yandex.ru> From: Mehdi Amini <mehdi.amini@apple.com> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266524 91177308-0d34-0410-b5e6-96231b3b80d8
44 lines
1.4 KiB
C++
44 lines
1.4 KiB
C++
//===-- llvm/ADT/APSInt.cpp - Arbitrary Precision Signed Int ---*- C++ -*--===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements the APSInt class, which is a simple class that
|
|
// represents an arbitrary sized integer that knows its signedness.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/ADT/APSInt.h"
|
|
#include "llvm/ADT/FoldingSet.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
using namespace llvm;
|
|
|
|
APSInt::APSInt(StringRef Str) {
|
|
assert(!Str.empty() && "Invalid string length");
|
|
|
|
// (Over-)estimate the required number of bits.
|
|
unsigned NumBits = ((Str.size() * 64) / 19) + 2;
|
|
APInt Tmp(NumBits, Str, /*Radix=*/10);
|
|
if (Str[0] == '-') {
|
|
unsigned MinBits = Tmp.getMinSignedBits();
|
|
if (MinBits > 0 && MinBits < NumBits)
|
|
Tmp = Tmp.trunc(MinBits);
|
|
*this = APSInt(Tmp, /*IsUnsigned=*/false);
|
|
return;
|
|
}
|
|
unsigned ActiveBits = Tmp.getActiveBits();
|
|
if (ActiveBits > 0 && ActiveBits < NumBits)
|
|
Tmp = Tmp.trunc(ActiveBits);
|
|
*this = APSInt(Tmp, /*IsUnsigned=*/true);
|
|
}
|
|
|
|
void APSInt::Profile(FoldingSetNodeID& ID) const {
|
|
ID.AddInteger((unsigned) (IsUnsigned ? 1 : 0));
|
|
APInt::Profile(ID);
|
|
}
|