mirror of
https://github.com/triqs/dft_tools
synced 2024-12-26 14:23:38 +01:00
ed6379ce63
wrapper generator: add treatment of parameter class - methods taking a parameter class are called by **kw - the dict is passed to the C++ - the converters for the parameters are generated.
53 lines
1.9 KiB
Python
53 lines
1.9 KiB
Python
#!@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"
|
|
|