Skip to content

Instantly share code, notes, and snippets.

@sciguy16
Created June 26, 2017 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sciguy16/018d8c247b87961e23536a08e899bfc0 to your computer and use it in GitHub Desktop.
Save sciguy16/018d8c247b87961e23536a08e899bfc0 to your computer and use it in GitHub Desktop.
Converts the output of ethereum-decompile into an lstlisting
#!/usr/bin/python
# Utility for converting the output of ethereum-decompile into a nice
# lstlisting format. Requires the following code somewhere before it:
# \let\othelstnumber=\thelstnumber
# \def\createlinenumber#1#2{
# \edef\thelstnumber{%
# \unexpanded{%
# \ifnum#1=\value{lstnumber}\relax
# #2%
# \else}%
# \expandafter\unexpanded\expandafter{\thelstnumber\othelstnumber\fi}%
# }
# \ifx\othelstnumber=\relax\else
# \let\othelstnumber\relax
# \fi
# }
import sys
currentLine = 0
preconf = "\\bgroup\n"
content = "\\begin{lstlisting}\n"
post = "\\end{lstlisting}\n\\egroup\n"
def makeLineNumber(currentLine,number):
return "\\createlinenumber{%i}{%s}\n"%(currentLine,number)
def makeContent(instruction):
return "%s\n"%instruction
for line in sys.stdin.readlines():
currentLine += 1
if ")" in line:
number,instruction = [x.strip() for x in line.split(")", 1)]
number = number[2:]
else:
instruction = "\t "+line.strip()
number = "$\\cdot$"
preconf += makeLineNumber(currentLine,number)
content += makeContent(instruction)
print preconf
print content
print post
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment