3
0
mirror of https://github.com/triqs/dft_tools synced 2024-11-01 03:33:50 +01:00
dft_tools/pytriqs/wrap_generator/param_generator.py.in

53 lines
1.9 KiB
Python
Raw Normal View History

#!@PYTHON_INTERPRETER@
from clang_parser import parse
import sys, os
from mako.template import Template
# the instruction that created this file
shell_command = ' '.join( [ sys.argv[0].rsplit('/')[-1]] + [x if ' ' not in x else '"%s"'%x for x in sys.argv[1:]])
#
print "Welcome to the C++ code generator of TRIQS, based on libclang !"
# --- Parsing the arguments of the script and options
import argparse
parser = argparse.ArgumentParser(description='From a regular class, generate the h5_read/h5_write, mpi, python interface for a parameter class')
parser.add_argument('filename', help = "Name of the file")
parser.add_argument('--libclang_location', help='Location of the libclang', default = '@TRIQS_LIBCLANG_LOCATION@')
parser.add_argument('--compiler_options', nargs ='*', help='Options to pass to clang')
parser.add_argument('--includes', '-I', action='append', help='Includes to pass to clang')
args = parser.parse_args()
args.includes = (args.includes or []) + '@TRIQS_INCLUDE_ALL@'.split(';')
triqs_install_location = '@CMAKE_INSTALL_PREFIX@'
args.includes.insert(0, triqs_install_location + '/include')
#------------
if __name__ == '__main__' :
compiler_options = args.compiler_options or []
compiler_options += ['-I%s'%x for x in args.includes]
add_opts = '@TRIQS_LIBCLANG_CXX_ADDITIONAL_FLAGS@'.strip()
if add_opts:
compiler_options += add_opts.split()
functions, classes = parse(args.filename, debug = False, compiler_options = compiler_options, where_is_libclang = args.libclang_location)
print "Generating ..."
tpl = Template(filename=triqs_install_location + '/share/triqs/wrap_generator/param.mako.cxx')
shell_command = ' '.join( [ sys.argv[0].rsplit('/')[-1]] + sys.argv[1:])
rendered = tpl.render(classes = classes, functions = functions, args = args, shell_command= shell_command )
with open(args.filename.replace('.hpp',".hxx"), "w") as f:
f.write(rendered)
print "... done"