Browse Source

gen_cid add gen_yml.py and gen_cc.ysl2

master
heck 5 years ago
parent
commit
d509fa9108
  1. 4
      gen/gen_cid/c_2_ast.py
  2. 1
      gen/gen_cid/cid_2_yml.py
  3. 5
      gen/gen_cid/gen_cc.ysl2
  4. 58
      gen/gen_cid/gen_yml.py

4
gen/gen_cid/c_2_ast.py

@ -6,11 +6,11 @@ from clang.cindex import CursorKind
class C2AST:
def __init__(self, library_file):
if not clang.cindex.Config.loaded:
print("Using libclang from: %s", library_file)
# print("Using libclang from: %s", library_file)
clang.cindex.Config.set_library_file(library_file)
import sys
sys.setrecursionlimit(10000)
print("max recursion limit set to:", sys.getrecursionlimit())
# print("max recursion limit set to:", sys.getrecursionlimit())
def parse(self, filename, content=None, follow_includes=False):
index = clang.cindex.Index.create()

1
gen/gen_cid/cid_2_yml.py

@ -15,6 +15,7 @@ def generate_yml(cid, module_name):
def _grammar_header():
grammar = """
decl module @name;
decl method @name;
decl struct @name;

5
gen/examples/synth_shed/gen_pybind.ysl2 → gen/gen_cid/gen_cc.ysl2

@ -1,7 +1,7 @@
include yslt.yml2
tstylesheet {
template "pEp" {
template "module" {
document("py_module.cc", "text") {
||
#include <string>
@ -13,7 +13,7 @@ tstylesheet {
using namespace std;
namespace py = pybind11;
PYBIND11_MODULE(synth_shed, m) {
PYBIND11_MODULE(«@name», m) {
`` apply "method"
@ -24,7 +24,6 @@ tstylesheet {
}
||
}
document("gen_pybind.marker", "text") > ""
}
template "method" {

58
gen/gen_cid/gen_yml.py

@ -0,0 +1,58 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import json
import gen_cid
from gen_cid import utils
def print_indent(*args, indent=0):
print('\t' * indent, *args)
def main():
cfg_file = sys.argv[1]
print("reading cfg file:", cfg_file)
data = []
try:
with open(cfg_file) as json_data_file:
data = json.load(json_data_file)
except IOError:
print("cfg file not readble:", cfg_file)
exit(-1)
pymodule_name = data["module_name"]
libclang_path = data["libclang_path"]
header_filename = data["header_filename"]
vars = data["variables"]
funcs = data["functions"]
print_indent("CONFIG:")
print_indent("module_name:", pymodule_name, indent=1)
print_indent("libclang_path:", libclang_path, indent=1)
print_indent("header_filename:", header_filename, indent=1)
print_indent("variables:", indent=1)
for var in vars:
print_indent(var, indent=2)
print_indent("functions:", indent=1)
for func in funcs:
print_indent(func, indent=2)
cidtools = gen_cid.CIDTools(libclang_path, header_filename, pymodule_name)
header = cidtools.extract(vars, funcs, debug_ast=False, debug_cid=False, debug_yml=False)
print_indent("OUTPUT:")
print_indent(header["yml"])
utils.write_string(header["yml"], "./" + "py_module" + ".yml2", )
if __name__ == "__main__":
main()
Loading…
Cancel
Save