1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-06-29 00:13:14 +00:00
gnss-sdr/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_tmpl_utils.py

73 lines
2.4 KiB
Python
Raw Normal View History

2014-09-07 23:56:09 +00:00
#!/usr/bin/env python
#
2015-01-08 18:49:59 +00:00
# Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors)
2014-09-07 23:56:09 +00:00
#
2014-11-07 17:02:52 +00:00
# This file is part of GNSS-SDR.
2014-09-07 23:56:09 +00:00
#
2014-11-07 17:02:52 +00:00
# GNSS-SDR is free software: you can redistribute it and/or modify
2014-09-07 23:56:09 +00:00
# it under the terms of the GNU General Public License as published by
2014-11-07 17:02:52 +00:00
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
2014-09-07 23:56:09 +00:00
#
2014-11-07 17:02:52 +00:00
# GNSS-SDR is distributed in the hope that it will be useful,
2014-09-07 23:56:09 +00:00
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
2014-11-07 17:02:52 +00:00
# along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
2014-09-07 23:56:09 +00:00
#
import os
import re
import sys
import optparse
import volk_gnsssdr_arch_defs
import volk_gnsssdr_machine_defs
import volk_gnsssdr_kernel_defs
from Cheetah import Template
def __escape_pre_processor(code):
out = list()
for line in code.splitlines():
m = re.match('^(\s*)#(\s*)(\w+)(.*)$', line)
if m:
p0, p1, fcn, stuff = m.groups()
conly = fcn in ('include', 'define', 'ifdef', 'ifndef', 'endif', 'elif', 'pragma')
both = fcn in ('if', 'else')
istmpl = '$' in stuff
if 'defined' in stuff: istmpl = False
if conly or (both and not istmpl):
line = '%s\\#%s%s%s'%(p0, p1, fcn, stuff)
out.append(line)
return '\n'.join(out)
def __parse_tmpl(_tmpl, **kwargs):
defs = {
'archs': volk_gnsssdr_arch_defs.archs,
'arch_dict': volk_gnsssdr_arch_defs.arch_dict,
'machines': volk_gnsssdr_machine_defs.machines,
'machine_dict': volk_gnsssdr_machine_defs.machine_dict,
'kernels': volk_gnsssdr_kernel_defs.kernels,
}
defs.update(kwargs)
_tmpl = __escape_pre_processor(_tmpl)
_tmpl = """
/* this file was generated by volk_gnsssdr template utils, do not edit! */
""" + _tmpl
return str(Template.Template(_tmpl, defs))
def main():
parser = optparse.OptionParser()
parser.add_option('--input', type='string')
parser.add_option('--output', type='string')
(opts, args) = parser.parse_args()
output = __parse_tmpl(open(opts.input).read(), args=args)
if opts.output: open(opts.output, 'w').write(output)
else: print output
if __name__ == '__main__': main()