annotate llvm/lib/Support/APSInt.cpp @ 181:df311c476dd5

CreateIdentifierInfo in ParseCbC (not yet worked)
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 31 May 2020 12:30:11 +0900
parents 0572611fdcc8
children 2e18cbf3894f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===-- llvm/ADT/APSInt.cpp - Arbitrary Precision Signed Int ---*- C++ -*--===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8 //
anatofuz
parents:
diff changeset
9 // This file implements the APSInt class, which is a simple class that
anatofuz
parents:
diff changeset
10 // represents an arbitrary sized integer that knows its signedness.
anatofuz
parents:
diff changeset
11 //
anatofuz
parents:
diff changeset
12 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 #include "llvm/ADT/APSInt.h"
anatofuz
parents:
diff changeset
15 #include "llvm/ADT/FoldingSet.h"
anatofuz
parents:
diff changeset
16 #include "llvm/ADT/StringRef.h"
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
17 #include <cassert>
150
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 using namespace llvm;
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 APSInt::APSInt(StringRef Str) {
anatofuz
parents:
diff changeset
22 assert(!Str.empty() && "Invalid string length");
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 // (Over-)estimate the required number of bits.
anatofuz
parents:
diff changeset
25 unsigned NumBits = ((Str.size() * 64) / 19) + 2;
anatofuz
parents:
diff changeset
26 APInt Tmp(NumBits, Str, /*radix=*/10);
anatofuz
parents:
diff changeset
27 if (Str[0] == '-') {
anatofuz
parents:
diff changeset
28 unsigned MinBits = Tmp.getMinSignedBits();
anatofuz
parents:
diff changeset
29 if (MinBits > 0 && MinBits < NumBits)
anatofuz
parents:
diff changeset
30 Tmp = Tmp.trunc(MinBits);
anatofuz
parents:
diff changeset
31 *this = APSInt(Tmp, /*isUnsigned=*/false);
anatofuz
parents:
diff changeset
32 return;
anatofuz
parents:
diff changeset
33 }
anatofuz
parents:
diff changeset
34 unsigned ActiveBits = Tmp.getActiveBits();
anatofuz
parents:
diff changeset
35 if (ActiveBits > 0 && ActiveBits < NumBits)
anatofuz
parents:
diff changeset
36 Tmp = Tmp.trunc(ActiveBits);
anatofuz
parents:
diff changeset
37 *this = APSInt(Tmp, /*isUnsigned=*/true);
anatofuz
parents:
diff changeset
38 }
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40 void APSInt::Profile(FoldingSetNodeID& ID) const {
anatofuz
parents:
diff changeset
41 ID.AddInteger((unsigned) (IsUnsigned ? 1 : 0));
anatofuz
parents:
diff changeset
42 APInt::Profile(ID);
anatofuz
parents:
diff changeset
43 }