Last active
December 28, 2015 01:49
-
-
Save aczid/7423399 to your computer and use it in GitHub Desktop.
A disgusting Python kludge to convert from Atmel to GNU assembly syntax. If you are reading this I'm sorry. Only here as a reference.
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
import sys | |
lines = open(sys.argv[1]).readlines() | |
double_if=False | |
print "#include <avr/io.h>" | |
print ".global encrypt" | |
print ".global decrypt" | |
for line in lines: | |
if '.endmacro' in line: | |
line = line.replace("endmacro", "endm") | |
if '.db' in line: | |
line = line.replace('.db','.byte') | |
if '.equ' in line: | |
line = line.replace('.equ','') | |
if '#ifdef' in line: | |
line = line.replace('#ifdef', '.ifdef') | |
elif '#if defined' in line: | |
line = line.replace('#if defined(', '.ifdef ') | |
line = line.replace('&& defined(', '\n.ifdef ') | |
line = line.replace(')','') | |
double_if = True | |
if '#ifndef' in line: | |
line = line.replace('#ifndef', '.ifndef') | |
if '#else' in line: | |
line = line.replace('#else', '.else') | |
if '#define' in line: | |
# FIXME | |
line = line.replace('#define ', '.set ').strip() + ", 1" | |
if '#endif' in line: | |
line = line.replace('#endif', '.endif') | |
if double_if: | |
double_if = False | |
print '.endif' | |
if '.def' in line: | |
bits = line.split(' ') | |
line = "#define %s %s" % (bits[1].strip(), bits[3].strip()) | |
bits = line.split(':') | |
line = line.replace('high(', 'hi8(pm(') | |
line = line.replace('low(', 'lo8(pm(') | |
if '<<' in line: | |
# FIXME | |
print "FIXME" | |
print line.strip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment