summaryrefslogtreecommitdiffstats
path: root/lldb/examples/customization/bin-utils/binutils.py
diff options
context:
space:
mode:
authorKate Stone <katherine.stone@apple.com>2016-09-06 20:57:50 +0000
committerKate Stone <katherine.stone@apple.com>2016-09-06 20:57:50 +0000
commitb9c1b51e45b845debb76d8658edabca70ca56079 (patch)
treedfcb5a13ef2b014202340f47036da383eaee74aa /lldb/examples/customization/bin-utils/binutils.py
parentd5aa73376966339caad04013510626ec2e42c760 (diff)
downloadbcm5719-llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.gz
bcm5719-llvm-b9c1b51e45b845debb76d8658edabca70ca56079.zip
*** This commit represents a complete reformatting of the LLDB source code
*** to conform to clang-format’s LLVM style. This kind of mass change has *** two obvious implications: Firstly, merging this particular commit into a downstream fork may be a huge effort. Alternatively, it may be worth merging all changes up to this commit, performing the same reformatting operation locally, and then discarding the merge for this particular commit. The commands used to accomplish this reformatting were as follows (with current working directory as the root of the repository): find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} + find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ; The version of clang-format used was 3.9.0, and autopep8 was 1.2.4. Secondly, “blame” style tools will generally point to this commit instead of a meaningful prior commit. There are alternatives available that will attempt to look through this change and find the appropriate prior commit. YMMV. llvm-svn: 280751
Diffstat (limited to 'lldb/examples/customization/bin-utils/binutils.py')
-rw-r--r--lldb/examples/customization/bin-utils/binutils.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/lldb/examples/customization/bin-utils/binutils.py b/lldb/examples/customization/bin-utils/binutils.py
index 313a354ec3a..576dcba02f7 100644
--- a/lldb/examples/customization/bin-utils/binutils.py
+++ b/lldb/examples/customization/bin-utils/binutils.py
@@ -2,6 +2,7 @@
import StringIO
+
def binary(n, width=None):
"""
Return a list of (0|1)'s for the binary representation of n where n >= 0.
@@ -12,7 +13,7 @@ def binary(n, width=None):
if width and width <= 0:
width = None
while n > 0:
- l.append(1 if n&1 else 0)
+ l.append(1 if n & 1 else 0)
n = n >> 1
if width:
@@ -22,14 +23,15 @@ def binary(n, width=None):
l.reverse()
return l
+
def twos_complement(n, width):
"""
Return a list of (0|1)'s for the binary representation of a width-bit two's
complement numeral system of an integer n which may be negative.
"""
- val = 2**(width-1)
+ val = 2**(width - 1)
if n >= 0:
- if n > (val-1):
+ if n > (val - 1):
return None
# It is safe to represent n with width-bits.
return binary(n, width)
@@ -38,7 +40,7 @@ def twos_complement(n, width):
if abs(n) > val:
return None
# It is safe to represent n (a negative int) with width-bits.
- return binary(val*2 - abs(n))
+ return binary(val * 2 - abs(n))
# print binary(0xABCD)
# [1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1]
@@ -53,12 +55,13 @@ def twos_complement(n, width):
# print twos_complement(-5, 64)
# [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1]
+
def positions(width):
"""Helper function returning a list describing the bit positions.
Bit positions greater than 99 are truncated to 2 digits, for example,
100 -> 00 and 127 -> 27."""
return ['{0:2}'.format(i)[-2:] for i in reversed(range(width))]
-
+
def utob(debugger, command_line, result, dict):
"""Convert the unsigned integer to print its binary representation.
@@ -88,9 +91,10 @@ def utob(debugger, command_line, result, dict):
return
if verbose and width > 0:
pos = positions(width)
- print ' '+' '.join(pos)
+ print ' ' + ' '.join(pos)
print ' %s' % str(bits)
+
def itob(debugger, command_line, result, dict):
"""Convert the integer to print its two's complement representation.
args[0] (mandatory) is the integer to be converted
@@ -117,6 +121,5 @@ def itob(debugger, command_line, result, dict):
return
if verbose and width > 0:
pos = positions(width)
- print ' '+' '.join(pos)
+ print ' ' + ' '.join(pos)
print ' %s' % str(bits)
-
OpenPOWER on IntegriCloud