-
Notifications
You must be signed in to change notification settings - Fork 3
/
ptranspile-c.py
37 lines (28 loc) · 1.07 KB
/
ptranspile-c.py
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
import sys
sys.path.extend(['.', 'pycparser'])
# sudo easy_install pycparser
from pycparser import parse_file
import js_generator
def translate(filename):
ast = parse_file(filename,
use_cpp=True,
cpp_path='gcc',
cpp_args=[
"-E",
"-D__FBSDID(x)=", # FreeBSD identifier
"-D__attribute__(x)=", # attribute extension
"-D__builtin_va_list=void*", # include/x86/_types.h:154 typedef __builtin_va_list __va_list;
"-D__inline=",
"-D__asm(x)=",
"-D_RUNETYPE_H_=1", # skip include/runtype.h
"-D_RuneLocale=void*", # but it defines this type
"-D_Noreturn=",
"-U__BLOCKS__", # no (^) syntax: include/stdlib.h: int atexit_b(void (^)(void));
"-U__nonnull", # avoid __nonnull redefinition
"-nostdinc",
"-Ipycparser/utils/fake_libc_include",
"-Iinclude", # copy from /usr/include
])
generator = js_generator.JavaScriptGenerator()
print(generator.visit(ast))
translate(sys.argv[1])