#define
lines create constants. Just create variables in python for those:
STDIN_BASEADDRESS = 0x40600000
STDOUT_BASEADDRESS = 0x40600000
# ******************************************************************
# Definitions for driver UARTLITE
XPAR_XUARTLITE_NUM_INSTANCES = 1
So all you need to do is remove the #define
part, and insert a =
equals sign. A set of regular expressions would do the job:
import re
from functools import partial
replacements = (
partial(re.compile(r'\s*#define ([A-Z_]+) (.*)').sub, r'\1 = \2'),
partial(re.compile(r'\s*/\*\s*(.*?)\s*\*/').sub, r'# \1'),
)
for line in inputsequence:
for transform in replacements:
line = transform(line)
print line
Demo:
>>> import re
>>> from functools import partial
>>> replacements = (
... partial(re.compile(r'\s*#define ([A-Z_]+) (.*)').sub, r'\1 = \2'),
... partial(re.compile(r'\s*/\*\s*(.*?)\s*\*/').sub, r'# \1'),
... )
>>> for line in inputsequence:
... for transform in replacements:
... line = transform(line)
... print line
...
STDIN_BASEADDRESS = 0x40600000
STDOUT_BASEADDRESS = 0x40600000
# ****************************************************************
# Definitions for driver UARTLITE
XPAR_XUARTLITE_NUM_INSTANCES = 1
If you still want to transform the defines to functions, just adjust the replacement pattern:
partial(re.compile(r'\s*#define ([A-Z_]+) (.*)').sub, r'def \1():\n return \2'),
which results in:
def STDIN_BASEADDRESS():
return 0x40600000
def STDOUT_BASEADDRESS():
return 0x40600000
# ****************************************************************
# Definitions for driver UARTLITE
def XPAR_XUARTLITE_NUM_INSTANCES():
return 1