Created
June 26, 2017 13:53
-
-
Save sciguy16/018d8c247b87961e23536a08e899bfc0 to your computer and use it in GitHub Desktop.
Converts the output of ethereum-decompile into an lstlisting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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