def my_module_gen(out_file): out = FileCodeSink(out_file) #pybindgen.write_preamble(out) out.writeln("#include \"hello.h\"") module_parser = ModuleParser('hello') module_parser.add_pre_scan_hook(pre_scan_hook) module = module_parser.parse(sys.argv[1:]) module.generate(out)
def my_module_gen(): #module_parser = ModuleParser('a1', '::') module_parser = ModuleParser('pypm', '::') module = module_parser.parse(['libpm.h'], ["/usr/include/", "lib/"]) module.add_include('"libpm.h"') pybindgen.write_preamble(FileCodeSink(sys.stdout)) module.generate(FileCodeSink(sys.stdout))
def my_module_gen(): libName = 'libPy' + sys.argv[2] className = sys.argv[2] + '.hh' includeFile = sys.argv[1] + '/' + className module_parser = ModuleParser(libName, '::') module_parser.parse([includeFile], includes=['"' + includeFile + '"'], pygen_sink=FileCodeSink(sys.stdout))
def my_module_gen(): module_parser = ModuleParser(NAME) module = module_parser.parse( [SRC], gccxml_options=dict(gccxml_path=GCCXML), #pygen_sink=FileCodeSink(sys.stdout), ) module.add_include('"%s"' % SRC) output = open(DEST, 'w') module.generate(FileCodeSink(output))
def module_gen(): os.chdir('/home/trevorsweetnam/Dropbox/notebooks/eef/emxarr/codegen/dll/emx_test') #module_parser = ModuleParser('emx_test_emxAPI', '::') #module = module_parser.parse(['emx_test_emxAPI.h']) #module.add_include('"emx_test_emxAPI.h"') module_parser = ModuleParser('emx_test', '::') module = module_parser.parse(['emx_test.h']) module.add_include('"rt_noninfite.h"') module.add_include('"emx_test_emxutil.h"') pybindgen.write_preamble(FileCodeSink(sys.stdout)) module.generate(FileCodeSink(sys.stdout))
def my_module_gen(): include_paths = [ os.path.join(base_dir, 'Include'), os.path.join(base_dir, 'Src'), ] header_files = [] for root, dirs, files in os.walk(base_dir): for filename in files: if filename.endswith('.h'): header_files.append( os.path.join(root, filename) ) module_parser = ModuleParser('OVR', '::') modules = dict() for header in header_files: name = header.split('/').pop() name = name.split('.')[0] try: modules[name] = module_parser.parse( [header, ], gccxml_options = dict(include_paths=include_paths), ) except Exception as _ex: logging.warning( "Couldn't parse {}: {}\n".format(header, _ex.message) ) for name, module in modules.iteritems(): try: outfile = open( os.path.join(build_dir, name + '.cpp') , 'w' ) write_preamble(FileCodeSink(outfile)) module.generate(FileCodeSink(outfile)) if not outfile.closed: outfile.close() except Exception as _ex: logging.warning( "Couldn't write {}: {}\n".format(name, _ex.message) )
def my_module_gen(inputdir, outputdir, includedirs): aliases = [("uint8_t*", "unsigned char*")] for alias in aliases: typehandlers.add_type_alias(alias[0], alias[1]) generator_fn = os.path.join(outputdir, "unitsync_python_wrapper.cc") module_parser = ModuleParser("pyunitsync") module_parser.add_pre_scan_hook(pre_scan_hook) with open(generator_fn, "wb") as output: # ensures file is closed after output module = module_parser.parse( [os.path.join(inputdir, "unitsync_api.h")], include_paths=includedirs, includes=['"../unitsync.h"', '"../unitsync_api.h"'], ) module.add_function( "GetMinimap", BufferReturn("unsigned short*", "1024*1024"), [Parameter.new("const char*", "fileName"), Parameter.new("int", "mipLevel")], ) module.generate(FileCodeSink(output))
def my_module_gen(inputdir, outputdir, includedirs): aliases = [('uint8_t*', 'unsigned char*')] for alias in aliases: typehandlers.add_type_alias(alias[0], alias[1]) generator_fn = os.path.join(outputdir, 'unitsync_python_wrapper.cc') module_parser = ModuleParser('pyunitsync') module_parser.add_pre_scan_hook(pre_scan_hook) with open(generator_fn, 'wb') as output: #ensures file is closed after output module = module_parser.parse( [os.path.join(inputdir, 'unitsync_api.h')], include_paths=includedirs, includes=['"../unitsync.h"', '"../unitsync_api.h"'], ) module.add_function("GetMinimap", BufferReturn("unsigned short*", "1024*1024"), [ Parameter.new('const char*', 'fileName'), Parameter.new('int', 'mipLevel') ]) module.generate(FileCodeSink(output))
def my_module_gen(): libName = 'libPy' + sys.argv[2] className = sys.argv[2] + '.hh' includeFile = sys.argv[1] + '/' + className module_parser = ModuleParser( libName, '::') module_parser.parse([includeFile], includes=['"' + includeFile + '"'], pygen_sink=FileCodeSink(sys.stdout))
def my_module_gen(): module_parser = ModuleParser('MyModule') module_parser.parse([sys.argv[1]], includes=['"my-module.h"'],pygen_sink=FileCodeSink(open('ko.py','wb')))
def ns3_module_scan(top_builddir, module_name, headers_map, output_file_name, cflags): module_parser = ModuleParser('ns.%s' % module_name.replace('-', '_'), 'ns3') module_parser.add_pre_scan_hook(PreScanHook(headers_map, module_name)) #module_parser.add_post_scan_hook(post_scan_hook) gccxml_options = dict( include_paths=[top_builddir], define_symbols={ #'NS3_ASSERT_ENABLE': None, #'NS3_LOG_ENABLE': None, }, cflags=('--gccxml-cxxflags "%s -DPYTHON_SCAN"' % cflags) ) try: os.unlink(output_file_name) except OSError: pass try: os.makedirs(os.path.dirname(output_file_name)) except OSError: pass output_file = open(output_file_name, "wt") output_sink = FileCodeSink(output_file) # if there exists a scan-header.h file in src/<module>/bindings, # scan it, otherwise scan ns3/xxxx-module.h. scan_header = os.path.join(os.path.dirname(output_file_name), "scan-header.h") if not os.path.exists(scan_header): scan_header = os.path.join(top_builddir, "ns3", "%s-module.h" % module_name) module_parser.parse_init([scan_header], None, whitelist_paths=[top_builddir], #includes=['"ns3/everything.h"'], pygen_sink=output_sink, gccxml_options=gccxml_options) module_parser.scan_types() callback_classes_file = open(os.path.join(os.path.dirname(output_file_name), "callbacks_list.py"), "wt") scan_callback_classes(module_parser, callback_classes_file) callback_classes_file.close() module_parser.scan_methods() module_parser.scan_functions() module_parser.parse_finalize() output_file.close() os.chmod(output_file_name, 0400)
def my_module_gen(): out = FileCodeSink(sys.stdout) pygen_file = open(sys.argv[3], "wt") module_parser = ModuleParser('foo2', '::') module_parser.enable_anonymous_containers = True print >> sys.stderr, "PYTHON_INCLUDES:", repr(sys.argv[2]) gccxml_options = dict( include_paths=eval(sys.argv[2]), ) module_parser.parse_init([sys.argv[1]], includes=['"foo.h"'], pygen_sink=FileCodeSink(pygen_file), gccxml_options=gccxml_options) module = module_parser.module module.add_exception('exception', foreign_cpp_namespace='std', message_rvalue='%(EXC)s.what()') module_parser.scan_types() module_parser.scan_methods() module_parser.scan_functions() module_parser.parse_finalize() pygen_file.close() foomodulegen_common.customize_module(module) module.generate(out)
def my_module_gen(): module_parser = ModuleParser('a1', '::') module = module_parser.parse([sys.argv[1]]) module.add_include('"a.h"') module.generate(FileCodeSink(sys.stdout))
def ns3_module_scan(top_builddir, pygen_file_name, everything_h, cflags): ns3_modules = eval(sys.stdin.readline()) ## do a topological sort on the modules graph from topsort import topsort graph = [] module_names = ns3_modules.keys() module_names.sort() for ns3_module_name in module_names: ns3_module_deps = list(ns3_modules[ns3_module_name][0]) ns3_module_deps.sort() for dep in ns3_module_deps: graph.append((dep, ns3_module_name)) sorted_ns3_modules = topsort(graph) #print >> sys.stderr, "******* topological sort: ", sorted_ns3_modules sections = [PygenSection('__main__', FileCodeSink(open(pygen_file_name, "wt")))] headers_map = {} # header_name -> section_name section_precendences = {} # section_name -> precedence for prec, ns3_module in enumerate(sorted_ns3_modules): section_name = "ns3_module_%s" % ns3_module.replace('-', '_') file_name = os.path.join(os.path.dirname(pygen_file_name), "%s.py" % section_name) sections.append(PygenSection(section_name, FileCodeSink(open(file_name, "wt")), section_name + "__local")) for header in ns3_modules[ns3_module][1]: headers_map[header] = section_name section_precendences[section_name] = prec module_parser = ModuleParser('ns3', 'ns3') module_parser.add_pre_scan_hook(pre_scan_hook) #module_parser.add_post_scan_hook(post_scan_hook) gccxml_options = dict( include_paths=[top_builddir], define_symbols={ #'NS3_ASSERT_ENABLE': None, #'NS3_LOG_ENABLE': None, }, cflags=('--gccxml-cxxflags %r' % (cflags,)) ) module_parser.parse_init([everything_h], None, whitelist_paths=[top_builddir, os.path.dirname(everything_h)], #includes=['"ns3/everything.h"'], pygen_sink=sections, pygen_classifier=MyPygenClassifier(headers_map, section_precendences), gccxml_options=gccxml_options) module_parser.scan_types() callback_classes_file = open(os.path.join(os.path.dirname(pygen_file_name), "callbacks_list.py"), "wt") scan_callback_classes(module_parser, callback_classes_file) callback_classes_file.close() module_parser.scan_methods() module_parser.scan_functions() module_parser.parse_finalize() for section in sections: section.code_sink.file.close()
def my_module_gen(): pygen = [ PygenSection('__main__', FileCodeSink(open(sys.argv[3], "wt"))), PygenSection('foomodulegen_module1', FileCodeSink(open(sys.argv[4], "wt")), 'foomodulegen_module1_local'), PygenSection('foomodulegen_module2', FileCodeSink(open(sys.argv[5], "wt")), 'foomodulegen_module2_local'), ] module_parser = ModuleParser('foo4', '::') module_parser.enable_anonymous_containers = True gccxml_options = dict( include_paths=eval(sys.argv[2]), ) module_parser.parse_init([sys.argv[1]], includes=['"foo.h"'], pygen_sink=pygen, pygen_classifier=MyPygenClassifier(), gccxml_options=gccxml_options) module = module_parser.module module.add_exception('exception', foreign_cpp_namespace='std', message_rvalue='%(EXC)s.what()') module_parser.scan_types() module_parser.scan_methods() module_parser.scan_functions() module_parser.parse_finalize() for sect in pygen: sect.code_sink.file.close()
def generate(): module_parser = ModuleParser('opennurbs', '::') module_parser.parse(["opennurbs.h"], includes=['"opennurbs.h"'], pygen_sink=FileCodeSink(sys.stdout))
try: annotations = knowledge.PARAMETER_ANNOTATIONS[pygccxml_definition.name] parameter_annotations.update(annotations) except KeyError: pass if __name__ == '__main__': #yuck, no waf or autotool here! Use pkg-config to get the libsyncml path pkgconfig = subprocess.Popen("pkg-config --cflags libsyncml-1.0",shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = pkgconfig.communicate() if pkgconfig.wait() != 0: raise Exception(stderr) #strip -I includes = stdout.replace("-I",'').strip() out_file=sys.stdout header=sys.argv[1] cpp_path=[includes] module_parser = ModuleParser('syncml') module_parser.add_pre_scan_hook(PreScanHook()) module = module_parser.parse( header_files=[os.path.abspath(header)], include_paths=cpp_path, whitelist_paths=cpp_path, pygen_sink=FileCodeSink(out_file))
def dcepy_module_gen(binddir, ns3path, dcepath): DCE_INCLUDE_PATH = dcepath ''' print "************************* dcepy_module_gen" print "* binddir = " + binddir print "* ns3path = " + ns3path print "* dcepath = " + dcepath print "******************************************" ''' cflags = '' bldpath = 'bindings/python' try: os.makedirs(bldpath) except OSError as exc: if exc.errno == errno.EEXIST and os.path.isdir(bldpath): pass else: raise ref_header_dir = binddir + "/refh" gccxml_options = dict( #include_paths=[ns3path, dcepath+"/model", dcepath + "/helper"], include_paths=[ref_header_dir, ns3path], define_symbols={ #'NS3_ASSERT_ENABLE': None, #'NS3_LOG_ENABLE': None, }, cflags=('--gccxml-cxxflags "%s -DPYTHON_SCAN"' % cflags)) inclfiles = [] for hf in includes_dce: inclfiles.append(ref_header_dir + "/" + hf) #inclfiles.append( dcepath+"/model/"+hf ) #whitelist_paths=[ dcepath+"/model", dcepath + "/helper", ns3path ] whitelist_paths = [ref_header_dir] module_parser = ModuleParser('dce', 'ns3') module_parser.enable_anonymous_containers = True module_parser.add_pre_scan_hook(pre_scan_hook) generatepyintermediate = True if generatepyintermediate: # Test with intermediate file fname = bldpath + '/temp_dce_bindings.py' print "Generating python pygendbind intermediate file: " + str(fname) py_file = open(fname, "wt") includes = [ '"ns3/dce-module.h"', '"ns3/dce-manager-helper.h"', '"ns3/dce-application.h"', '"ns3/ipv4-dce-routing-helper.h"' ] pysink = FileCodeSink(py_file) module_parser.parse_init(inclfiles, whitelist_paths=whitelist_paths, pygen_sink=pysink, gccxml_options=gccxml_options, includes=includes) module_parser.scan_types() module_parser.scan_methods() module_parser.scan_functions() module_parser.parse_finalize() else: # Test with cpp fname = bldpath + '/temp_dce_bindings.cpp' #fname = 'dce_bindings.cpp' print "Generating python bindings c++ file: " + str(fname) pygen_file = open(fname, "wt") module_parser.parse_init(inclfiles, whitelist_paths=whitelist_paths, gccxml_options=gccxml_options) module_parser.scan_types() module_parser.scan_methods() module_parser.scan_functions() module_parser.parse_finalize() module_parser.module.add_include('<ns3/dce-module.h>') module_parser.module.add_include('<ns3/dce-manager-helper.h>') module_parser.module.add_include('<ns3/dce-application.h>') module_parser.module.add_include('<ns3/ipv4-dce-routing-helper.h>') module_parser.module.add_include('<ns3/linux-stack-helper.h>') pybindgen.write_preamble(FileCodeSink(pygen_file)) module_parser.module.generate(FileCodeSink(pygen_file))
def my_module_gen(): out = FileCodeSink(sys.stdout) pygen_file = open(sys.argv[3], "wt") module_parser = ModuleParser('foo2', '::') module_parser.enable_anonymous_containers = True print("PYTHON_INCLUDES:", repr(sys.argv[2]), file=sys.stderr) gccxml_options = dict( include_paths=eval(sys.argv[2]), ) module_parser.parse_init([sys.argv[1]], includes=['"foo.h"'], pygen_sink=FileCodeSink(pygen_file), gccxml_options=gccxml_options) module = module_parser.module foomodulegen_common.customize_module_pre(module) module.add_exception('exception', foreign_cpp_namespace='std', message_rvalue='%(EXC)s.what()') module_parser.scan_types() module_parser.scan_methods() module_parser.scan_functions() module_parser.parse_finalize() pygen_file.close() foomodulegen_common.customize_module(module) module.generate(out)
def my_module_gen(): module_parser = ModuleParser("a2", "::") module_parser.parse([sys.argv[1]], includes=['"a.h"'], pygen_sink=FileCodeSink(sys.stdout))
def my_module_gen(): module_parser = ModuleParser('libPyIndexReader', '::') module_parser.parse([sys.argv[1]], includes=['"eudaq/IndexReader.hh"'], pygen_sink=FileCodeSink(sys.stdout))
def ns3_module_scan(top_builddir, pygen_file_name, everything_h, cflags): ns3_modules = eval(sys.stdin.read()) ## do a topological sort on the modules graph from topsort import topsort graph = [] module_names = ns3_modules.keys() module_names.sort() for ns3_module_name in module_names: ns3_module_deps = list(ns3_modules[ns3_module_name][0]) ns3_module_deps.sort() for dep in ns3_module_deps: graph.append((dep, ns3_module_name)) sorted_ns3_modules = topsort(graph) #print >> sys.stderr, "******* topological sort: ", sorted_ns3_modules sections = [ PygenSection('__main__', FileCodeSink(open(pygen_file_name, "wt"))) ] headers_map = {} # header_name -> section_name section_precendences = {} # section_name -> precedence for prec, ns3_module in enumerate(sorted_ns3_modules): section_name = "ns3_module_%s" % ns3_module.replace('-', '_') file_name = os.path.join(os.path.dirname(pygen_file_name), "%s.py" % section_name) sections.append( PygenSection(section_name, FileCodeSink(open(file_name, "wt")), section_name + "__local")) for header in ns3_modules[ns3_module][1]: headers_map[header] = section_name section_precendences[section_name] = prec module_parser = ModuleParser('ns3', 'ns3') module_parser.add_pre_scan_hook(pre_scan_hook) #module_parser.add_post_scan_hook(post_scan_hook) gccxml_options = dict( include_paths=[top_builddir], define_symbols={ #'NS3_ASSERT_ENABLE': None, #'NS3_LOG_ENABLE': None, }, cflags=('--gccxml-cxxflags %r' % (cflags, ))) module_parser.parse_init( [everything_h], None, whitelist_paths=[top_builddir, os.path.dirname(everything_h)], #includes=['"ns3/everything.h"'], pygen_sink=sections, pygen_classifier=MyPygenClassifier(headers_map, section_precendences), gccxml_options=gccxml_options) module_parser.scan_types() callback_classes_file = open( os.path.join(os.path.dirname(pygen_file_name), "callbacks_list.py"), "wt") scan_callback_classes(module_parser, callback_classes_file) callback_classes_file.close() module_parser.scan_methods() module_parser.scan_functions() module_parser.parse_finalize() for section in sections: section.code_sink.file.close()
def generate(): module_parser = ModuleParser("mymodule", "::") module_parser.parse(["my-module.h"], includes=['"my-module.h"'], pygen_sink=FileCodeSink(sys.stdout))
def ns3_module_scan(top_builddir, pygen_file_name, everything_h, cflags): ns3_modules = eval(sys.stdin.readline()) from topsort import topsort graph = [] module_names = ns3_modules.keys() module_names.sort() for ns3_module_name in module_names: ns3_module_deps = list(ns3_modules[ns3_module_name][0]) ns3_module_deps.sort() for dep in ns3_module_deps: graph.append((dep, ns3_module_name)) sorted_ns3_modules = topsort(graph) sections = [PygenSection('__main__', FileCodeSink(open(pygen_file_name, "wt")))] headers_map = {} section_precendences = {} for prec, ns3_module in enumerate(sorted_ns3_modules): section_name = "ns3_module_%s" % ns3_module.replace('-', '_') file_name = os.path.join(os.path.dirname(pygen_file_name), "%s.py" % section_name) sections.append(PygenSection(section_name, FileCodeSink(open(file_name, "wt")), section_name + "__local")) for header in ns3_modules[ns3_module][1]: headers_map[header] = section_name section_precendences[section_name] = prec module_parser = ModuleParser('ns3', 'ns3') module_parser.add_pre_scan_hook(pre_scan_hook) gccxml_options = dict( include_paths=[top_builddir], define_symbols={ }, cflags=('--gccxml-cxxflags "%s -DPYTHON_SCAN"' % cflags) ) module_parser.parse_init([everything_h], None, whitelist_paths=[top_builddir, os.path.dirname(everything_h)], pygen_sink=sections, pygen_classifier=MyPygenClassifier(headers_map, section_precendences), gccxml_options=gccxml_options) module_parser.scan_types() callback_classes_file = open(os.path.join(os.path.dirname(pygen_file_name), "callbacks_list.py"), "wt") scan_callback_classes(module_parser, callback_classes_file) callback_classes_file.close() module_parser.scan_methods() module_parser.scan_functions() module_parser.parse_finalize() for section in sections: section.code_sink.file.close()
def my_module_gen(): module_parser = ModuleParser('a2', '::') module_parser.parse([sys.argv[1]], includes=['"a.h"'], pygen_sink=FileCodeSink(sys.stdout))