Created
November 16, 2024 20:14
-
-
Save MaskRay/1a13aab842db0d98000515fdc3fbd039 to your computer and use it in GitHub Desktop.
lld/ELF: replace log(...) with `Log(ctx) << `
This file contains hidden or 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/env python | |
import os, re, sys | |
from ipdb import set_trace as bp | |
X = 'log' | |
Y = 'Log' | |
def update(lines): | |
ret = [] | |
s = 0 | |
for line in lines: | |
if f' {X}(' in line: | |
s = 1 | |
line = re.sub(fr'{X}\(', f'{Y}(ctx) << ', line) | |
if s: | |
#bp() | |
line = re.sub(r' toString\(([^ ]+)\)', r' \1', line) | |
line = re.sub(r' \+', ' <<', line) | |
if line.endswith(';'): | |
if s: | |
line = re.sub(r'\);$', ';', line) | |
s = 0 | |
ret.append(line) | |
return ret | |
def main(filename): | |
with open(filename, 'r+') as file: | |
text = file.read() | |
lines = update(text.splitlines()) | |
file.seek(0) | |
file.truncate(0) | |
file.write('\n'.join(lines) + '\n') | |
for f in sys.argv[1:]: | |
main(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment