aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts/gen_tasklet_reg.py
blob: 5b747c2eca2f0a927d7aa417bb167dfe44f7965f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import argparse

TEMPLATE = '''\
{includes}\
#include <tasklet/runtime/lib/{language}_wrapper.h>
#include <tasklet/runtime/lib/registry.h>

static const NTasklet::TRegHelper REG(
    "{name}",
    new NTasklet::{wrapper}
);
'''

WRAPPER = {
    'cpp': 'TCppWrapper<{impl}>()',
    'js': 'TJsWrapper("{impl}")',
    'go': 'TGoWrapper("{impl}")',
    'py': 'TPythonWrapper("{impl}")',
    'java': 'TJavaWrapper("{impl}", "{py_wrapper}")',
}


def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('name')
    parser.add_argument('output')
    parser.add_argument('-l', '--lang', choices=WRAPPER, required=True)
    parser.add_argument('-i', '--impl', required=True)
    parser.add_argument('-w', '--wrapper', required=False)
    parser.add_argument('includes', nargs='*')

    return parser.parse_args()


if __name__ == '__main__':
    args = parse_args()

    includes = ''.join(
        '#include <{}>\n'.format(include)
        for include in args.includes
    )

    code = TEMPLATE.format(
        includes=includes,
        language=args.lang,
        name=args.name,
        wrapper=WRAPPER[args.lang].format(impl=args.impl, py_wrapper=args.wrapper),
    )

    with open(args.output, 'w') as f:
        f.write(code)