├── README.md ├── autogen.py ├── fake_include ├── mswsock.h ├── port.h ├── sys │ ├── cdefs.h │ ├── param.h │ └── port.h ├── windows.h ├── winsock2.h └── ws2tcpip.h ├── fake_libc_include ├── CONTRIBUTORS ├── LICENSE ├── X11 │ ├── Intrinsic.h │ ├── Xlib.h │ ├── _X11_fake_defines.h │ └── _X11_fake_typedefs.h ├── _ansi.h ├── _fake_defines.h ├── _fake_typedefs.h ├── _syslist.h ├── aio.h ├── alloca.h ├── ar.h ├── argz.h ├── arpa │ └── inet.h ├── asm-generic │ └── int-ll64.h ├── assert.h ├── complex.h ├── cpio.h ├── ctype.h ├── dirent.h ├── dlfcn.h ├── emmintrin.h ├── endian.h ├── envz.h ├── errno.h ├── fastmath.h ├── fcntl.h ├── features.h ├── fenv.h ├── float.h ├── fmtmsg.h ├── fnmatch.h ├── ftw.h ├── getopt.h ├── glob.h ├── grp.h ├── iconv.h ├── ieeefp.h ├── immintrin.h ├── inttypes.h ├── iso646.h ├── langinfo.h ├── libgen.h ├── libintl.h ├── limits.h ├── linux │ ├── socket.h │ └── version.h ├── locale.h ├── malloc.h ├── math.h ├── mir_toolkit │ └── client_types.h ├── monetary.h ├── mqueue.h ├── ndbm.h ├── net │ └── if.h ├── netdb.h ├── netinet │ ├── in.h │ └── tcp.h ├── newlib.h ├── nl_types.h ├── openssl │ ├── err.h │ ├── evp.h │ ├── hmac.h │ ├── ssl.h │ └── x509v3.h ├── paths.h ├── poll.h ├── process.h ├── pthread.h ├── pwd.h ├── reent.h ├── regdef.h ├── regex.h ├── sched.h ├── search.h ├── semaphore.h ├── setjmp.h ├── signal.h ├── smmintrin.h ├── spawn.h ├── stdalign.h ├── stdarg.h ├── stdatomic.h ├── stdbool.h ├── stddef.h ├── stdint.h ├── stdio.h ├── stdlib.h ├── stdnoreturn.h ├── string.h ├── strings.h ├── stropts.h ├── sys │ ├── ioctl.h │ ├── ipc.h │ ├── mman.h │ ├── msg.h │ ├── poll.h │ ├── resource.h │ ├── select.h │ ├── sem.h │ ├── shm.h │ ├── socket.h │ ├── stat.h │ ├── statvfs.h │ ├── sysctl.h │ ├── time.h │ ├── times.h │ ├── types.h │ ├── uio.h │ ├── un.h │ ├── utsname.h │ └── wait.h ├── syslog.h ├── tar.h ├── termios.h ├── tgmath.h ├── threads.h ├── time.h ├── trace.h ├── ulimit.h ├── unctrl.h ├── unistd.h ├── utime.h ├── utmp.h ├── utmpx.h ├── wchar.h ├── wctype.h ├── wordexp.h ├── xcb │ └── xcb.h └── zlib.h ├── patched-quickjs-ffi-Makefile ├── qjs-cffi ├── qjs-pkg └── requirements.txt /README.md: -------------------------------------------------------------------------------- 1 | # quickjs-cffi 2 | 3 | ## Setup "C Headers" to "JavaScript" Translator 4 | 5 | ```bash 6 | python -m venv venv 7 | source venv/bin/activate 8 | cd ../pycparser 9 | python setup.py build 10 | python setup.py install 11 | pip install -r requirements.txt 12 | ``` 13 | 14 | ## Run Translator 15 | 16 | ### FLTK 1.3 17 | ```bash 18 | # multiple files 19 | python autogen.py -sizeof-cflags="-I../cfltk/include" -sizeof-include="cfl_box.h,cfl_browser.h,cfl_button.h,cfl_dialog.h,cfl_draw.h,cfl_enums.h,cfl_group.h,cfl.h,cfl_image.h,cfl_input.h,cfl_macros.h,cfl_menu.h,cfl_misc.h,cfl_printer.h,cfl_surface.h,cfl_table.h,cfl_text.h,cfl_tree.h,cfl_utils.h,cfl_valuator.h,cfl_widget.h,cfl_window.h" -i ../cfltk/include -o ../quickjs-fltk 20 | 21 | # single bundle file 22 | python autogen.py -sizeof-cflags="-I../cfltk/include" -sizeof-include="cfl_box.h,cfl_browser.h,cfl_button.h,cfl_dialog.h,cfl_draw.h,cfl_enums.h,cfl_group.h,cfl.h,cfl_image.h,cfl_input.h,cfl_macros.h,cfl_menu.h,cfl_misc.h,cfl_printer.h,cfl_surface.h,cfl_table.h,cfl_text.h,cfl_tree.h,cfl_utils.h,cfl_valuator.h,cfl_widget.h,cfl_window.h" -i ../cfltk/include -o ../quickjs-fltk/fltk.js 23 | ``` 24 | 25 | ### libuv 26 | ```bash 27 | python autogen.py -fc-cflags="-I../libuv/include -D__GNUC__=3 -DDIR=void" -sizeof-cflags="-I../libuv/include" -sizeof-include="uv.h" -i ../libuv/include/uv.h -o ../quickjs-libuv/uv.js -l libuv.so 28 | ``` 29 | 30 | ### gtk-3.0 31 | ```bash 32 | python autogen.py -fc-cflags "`pkg-config --cflags gtk+-3.0`" -i /usr/include/gtk-3.0/gtk/gtk.h -o ../quickjs-gtk-3.0 33 | ``` 34 | 35 | ### SDL2 36 | ```bash 37 | python autogen.py -fc-cflags "`pkg-config --cflags sdl2`" -i /usr/include/SDL2 -o ../quickjs-SDL2 38 | ``` 39 | -------------------------------------------------------------------------------- /autogen.py: -------------------------------------------------------------------------------- 1 | import os 2 | import argparse 3 | import traceback 4 | import subprocess 5 | from uuid import uuid4 6 | from json import dumps 7 | from copy import deepcopy 8 | from pprint import pprint 9 | from random import randint 10 | from typing import Union, Any 11 | from collections import ChainMap 12 | 13 | from pycparser import c_ast, parse_file 14 | 15 | 16 | DEFAULT_FRONTEND_CFLAGS = r"-nostdinc -D__attribute__(x) -Ilocal/quickjs-cffi/fake_libc_include -Ilocal/quickjs-cffi/fake_include".split(' ') 17 | 18 | QUICKJS_FFI_WRAP_PTR_FUNC_DECL = ''' 19 | const __quickjs_ffi_wrap_ptr_func_decl = (lib, name, nargs, ...types) => { 20 | // wrap C function 21 | const c_types = types.map(type => { 22 | if (typeof type == 'string') { 23 | return type; 24 | } else if (typeof type == 'object') { 25 | if (type.kind == 'PtrDecl') { 26 | if (type.type == 'char') { 27 | return 'string'; 28 | } else { 29 | return 'pointer'; 30 | } 31 | } else if (type.kind == 'PtrFuncDecl') { 32 | return 'pointer'; 33 | } else { 34 | throw new Error('Unsupported type'); 35 | } 36 | } else { 37 | throw new Error('Unsupported type'); 38 | } 39 | }); 40 | 41 | let c_func; 42 | 43 | try { 44 | c_func = new CFunction(lib, name, nargs, ...c_types); 45 | } catch (e) { 46 | console.log('Warning:', name, e); 47 | c_func = null; 48 | } 49 | 50 | const js_func = (...js_args) => { 51 | const c_args = types.slice(1).map((type, i) => { 52 | const js_arg = js_args[i]; 53 | 54 | if (typeof type == 'string') { 55 | return js_arg; 56 | } else if (typeof type == 'object') { 57 | if (type.kind == 'PtrFuncDecl') { 58 | const c_cb = new CCallback(js_arg, null, ...[type.return_type, ...type.params_types]); 59 | return c_cb.cfuncptr; 60 | } else { 61 | return js_arg; 62 | } 63 | } else { 64 | return js_arg; 65 | } 66 | }); 67 | 68 | return c_func.invoke(...c_args); 69 | }; 70 | 71 | return js_func; 72 | }; 73 | 74 | const _quickjs_ffi_wrap_ptr_func_decl = (lib, name, nargs, ...types) => { 75 | try { 76 | return __quickjs_ffi_wrap_ptr_func_decl(lib, name, nargs, ...types); 77 | } catch (e) { 78 | return undefined; 79 | } 80 | }; 81 | ''' 82 | 83 | 84 | CType = Union[str, dict] 85 | 86 | 87 | class CParser: 88 | BUILTIN_TYPES_NAMES = [ 89 | 'void', 90 | 'uint8', 91 | 'sint8', 92 | 'uint16', 93 | 'sint16', 94 | 'uint32', 95 | 'sint32', 96 | 'uint64', 97 | 'sint64', 98 | 'float', 99 | 'double', 100 | 'uchar', 101 | 'schar', 102 | 'ushort', 103 | 'sshort', 104 | 'uint', 105 | 'sint', 106 | 'ulong', 107 | 'slong', 108 | 'longdouble', 109 | 'pointer', 110 | 'complex_float', 111 | 'complex_double', 112 | 'complex_longdouble', 113 | 'char', 114 | 'short', 115 | 'int', 116 | 'long', 117 | 'string', 118 | 'uintptr_t', 119 | 'intptr_t', 120 | 'size_t', 121 | ] 122 | 123 | BUILTIN_TYPES = { 124 | **{n: n for n in BUILTIN_TYPES_NAMES}, 125 | '_Bool': 'int', 126 | 'signed char': 'schar', 127 | 'unsigned char': 'uchar', 128 | 'signed': 'sint', 129 | 'signed int': 'sint', 130 | 'unsigned': 'uint', 131 | 'unsigned int': 'uint', 132 | 'long long': 'sint64', # FIXME: platform specific 133 | 'signed long': 'uint32', # FIXME: platform specific 134 | 'unsigned long': 'uint32', # FIXME: platform specific 135 | 'signed long long': 'sint64', # FIXME: platform specific 136 | 'unsigned long long': 'uint64', # FIXME: platform specific 137 | 'long double': 'longdouble', 138 | 'int8_t': 'sint8', 139 | 'uint8_t': 'uint8', 140 | 'int16_t': 'sint16', 141 | 'uint16_t': 'uint16', 142 | 'int32_t': 'sint32', 143 | 'uint32_t': 'uint32', 144 | 'int64_t': 'sint64', 145 | 'uint64_t': 'uint64', 146 | } 147 | 148 | 149 | def __init__(self, 150 | frontend_compiler: str, 151 | frontend_cflags: str, 152 | sizeof_cflags: str, 153 | sizeof_include: str, 154 | backend_compiler: str, 155 | shared_library: str, 156 | input_path: str, 157 | output_path: str, 158 | keep_going: bool, 159 | verbose: bool): 160 | self.frontend_compiler = frontend_compiler 161 | self.sizeof_cflags = sizeof_cflags 162 | self.sizeof_include = sizeof_include 163 | self.backend_compiler = backend_compiler 164 | self.frontend_cflags = frontend_cflags 165 | self.shared_library = shared_library 166 | self.input_path = input_path 167 | self.output_path = output_path 168 | self.keep_going = keep_going 169 | self.verbose = verbose 170 | 171 | self.CONSTS = ChainMap() 172 | self.TYPE_DECL = ChainMap() 173 | self.FUNC_DECL = ChainMap() 174 | self.STRUCT_DECL = ChainMap() 175 | self.UNION_DECL = ChainMap() 176 | self.ENUM_DECL = ChainMap() 177 | self.ARRAY_DECL = ChainMap() 178 | 179 | self.TYPEDEF_STRUCT = ChainMap() 180 | self.TYPEDEF_UNION = ChainMap() 181 | self.TYPEDEF_ENUM = ChainMap() 182 | self.TYPEDEF_FUNC_DECL = ChainMap() 183 | self.TYPEDEF_PTR_DECL = ChainMap() 184 | self.TYPEDEF_TYPE_DECL = ChainMap() 185 | 186 | 187 | def push_new_processing_context(self): 188 | self.CONSTS = self.CONSTS.new_child() 189 | self.TYPE_DECL = self.TYPE_DECL.new_child() 190 | self.FUNC_DECL = self.FUNC_DECL.new_child() 191 | self.STRUCT_DECL = self.STRUCT_DECL.new_child() 192 | self.UNION_DECL = self.UNION_DECL.new_child() 193 | self.ENUM_DECL = self.ENUM_DECL.new_child() 194 | self.ARRAY_DECL = self.ARRAY_DECL.new_child() 195 | self.TYPEDEF_STRUCT = self.TYPEDEF_STRUCT.new_child() 196 | self.TYPEDEF_UNION = self.TYPEDEF_UNION.new_child() 197 | self.TYPEDEF_ENUM = self.TYPEDEF_ENUM.new_child() 198 | self.TYPEDEF_FUNC_DECL = self.TYPEDEF_FUNC_DECL.new_child() 199 | self.TYPEDEF_PTR_DECL = self.TYPEDEF_PTR_DECL.new_child() 200 | self.TYPEDEF_TYPE_DECL = self.TYPEDEF_TYPE_DECL.new_child() 201 | 202 | 203 | def pop_processing_context(self) -> dict[str, list[dict]]: 204 | context = { 205 | 'CONSTS': self.CONSTS.maps, 206 | 'TYPE_DECL': self.TYPE_DECL.maps, 207 | 'FUNC_DECL': self.FUNC_DECL.maps, 208 | 'STRUCT_DECL': self.STRUCT_DECL.maps, 209 | 'UNION_DECL': self.UNION_DECL.maps, 210 | 'ENUM_DECL': self.ENUM_DECL.maps, 211 | 'ARRAY_DECL': self.ARRAY_DECL.maps, 212 | 'TYPEDEF_STRUCT': self.TYPEDEF_STRUCT.maps, 213 | 'TYPEDEF_UNION': self.TYPEDEF_UNION.maps, 214 | 'TYPEDEF_ENUM': self.TYPEDEF_ENUM.maps, 215 | 'TYPEDEF_FUNC_DECL': self.TYPEDEF_FUNC_DECL.maps, 216 | 'TYPEDEF_PTR_DECL': self.TYPEDEF_PTR_DECL.maps, 217 | 'TYPEDEF_TYPE_DECL': self.TYPEDEF_TYPE_DECL.maps, 218 | } 219 | 220 | self.CONSTS = ChainMap() 221 | self.TYPE_DECL = ChainMap() 222 | self.FUNC_DECL = ChainMap() 223 | self.STRUCT_DECL = ChainMap() 224 | self.UNION_DECL = ChainMap() 225 | self.ENUM_DECL = ChainMap() 226 | self.ARRAY_DECL = ChainMap() 227 | self.TYPEDEF_STRUCT = ChainMap() 228 | self.TYPEDEF_UNION = ChainMap() 229 | self.TYPEDEF_ENUM = ChainMap() 230 | self.TYPEDEF_FUNC_DECL = ChainMap() 231 | self.TYPEDEF_PTR_DECL = ChainMap() 232 | self.TYPEDEF_TYPE_DECL = ChainMap() 233 | return context 234 | 235 | 236 | def push_processing_context(self, maps: dict[str, list[dict]]): 237 | self.CONSTS = ChainMap(dict(self.CONSTS), *maps['CONSTS']) 238 | self.TYPE_DECL = ChainMap(dict(self.TYPE_DECL), *maps['TYPE_DECL']) 239 | self.FUNC_DECL = ChainMap(dict(self.FUNC_DECL), *maps['FUNC_DECL']) 240 | self.STRUCT_DECL = ChainMap(dict(self.STRUCT_DECL), *maps['STRUCT_DECL']) 241 | self.UNION_DECL = ChainMap(dict(self.UNION_DECL), *maps['UNION_DECL']) 242 | self.ENUM_DECL = ChainMap(dict(self.ENUM_DECL), *maps['ENUM_DECL']) 243 | self.ARRAY_DECL = ChainMap(dict(self.ARRAY_DECL), *maps['ARRAY_DECL']) 244 | self.TYPEDEF_STRUCT = ChainMap(dict(self.TYPEDEF_STRUCT), *maps['TYPEDEF_STRUCT']) 245 | self.TYPEDEF_UNION = ChainMap(dict(self.TYPEDEF_UNION), *maps['TYPEDEF_UNION']) 246 | self.TYPEDEF_ENUM = ChainMap(dict(self.TYPEDEF_ENUM), *maps['TYPEDEF_ENUM']) 247 | self.TYPEDEF_FUNC_DECL = ChainMap(dict(self.TYPEDEF_FUNC_DECL), *maps['TYPEDEF_FUNC_DECL']) 248 | self.TYPEDEF_PTR_DECL = ChainMap(dict(self.TYPEDEF_PTR_DECL), *maps['TYPEDEF_PTR_DECL']) 249 | self.TYPEDEF_TYPE_DECL = ChainMap(dict(self.TYPEDEF_TYPE_DECL), *maps['TYPEDEF_TYPE_DECL']) 250 | 251 | 252 | def get_leaf_node(self, n): 253 | if hasattr(n, 'type'): 254 | return self.get_leaf_node(n.type) 255 | else: 256 | return n 257 | 258 | 259 | def get_leaf_name(self, n) -> list[str]: 260 | if isinstance(n, c_ast.IdentifierType): 261 | if hasattr(n, 'names'): 262 | return ' '.join(n.names) 263 | else: 264 | return '' 265 | else: 266 | return self.get_leaf_names(n.type) 267 | 268 | 269 | def get_typename(self, n, decl=None, func_decl=None) -> CType: 270 | js_type: CType = None 271 | js_name: str | None = None 272 | 273 | if decl: 274 | raise TypeError(type(n)) 275 | elif func_decl: 276 | js_name = n.name 277 | t = self.get_node(n.type, func_decl=func_decl) 278 | 279 | js_type = { 280 | 'kind': 'Typename', 281 | 'name': js_name, 282 | 'type': t, 283 | } 284 | else: 285 | raise TypeError(type(n)) 286 | 287 | return js_type 288 | 289 | 290 | def get_type_decl(self, n, typedef=None, decl=None, func_decl=None) -> CType: 291 | js_type: CType = None 292 | js_name: str | None = None 293 | 294 | if typedef: 295 | js_name = typedef.name 296 | 297 | if isinstance(n.type, c_ast.IdentifierType): 298 | js_name = n.declname 299 | js_type = self.get_leaf_name(n.type) 300 | self.TYPEDEF_TYPE_DECL[js_name] = js_type 301 | elif isinstance(n.type, c_ast.Enum): 302 | js_type = self.get_enum(n.type, typedef=typedef, type_decl=n) 303 | 304 | # js_type = { 305 | # 'kind': 'TypeDecl', 306 | # 'name': js_name, 307 | # 'type': t, 308 | # } 309 | 310 | if not js_name: 311 | js_name = f'_{randint(0, 2 ** 64)}_enum' 312 | 313 | js_type['name'] = js_name 314 | 315 | for item_name, item_value in js_type['items'].items(): 316 | self.CONSTS[item_name] = item_value 317 | 318 | if js_name not in self.ENUM_DECL: 319 | self.TYPEDEF_ENUM[js_name] = js_type 320 | elif isinstance(n.type, c_ast.Struct): 321 | js_type = self.get_struct(n.type, typedef=typedef, type_decl=n) 322 | 323 | # js_type = { 324 | # 'kind': 'TypeDecl', 325 | # 'name': js_name, 326 | # 'type': t, 327 | # } 328 | 329 | if not js_name: 330 | js_name = f'_{randint(0, 2 ** 64)}_struct' 331 | 332 | js_type['name'] = js_name 333 | 334 | if js_name not in self.STRUCT_DECL: 335 | self.TYPEDEF_STRUCT[js_name] = js_type 336 | elif isinstance(n.type, c_ast.Union): 337 | js_type = self.get_union(n.type, typedef=typedef, type_decl=n) 338 | 339 | # js_type = { 340 | # 'kind': 'TypeDecl', 341 | # 'name': js_name, 342 | # 'type': t, 343 | # } 344 | 345 | if not js_name: 346 | js_name = f'_{randint(0, 2 ** 64)}_union' 347 | 348 | js_type['name'] = js_name 349 | 350 | if js_name not in self.UNION_DECL: 351 | self.TYPEDEF_UNION[js_name] = js_type 352 | else: 353 | raise TypeError(n) 354 | elif decl or func_decl: 355 | if isinstance(n.type, c_ast.IdentifierType): 356 | js_name = n.declname 357 | js_type = self.get_leaf_name(n.type) 358 | self.TYPE_DECL[js_name] = js_type 359 | elif isinstance(n.type, c_ast.PtrDecl): 360 | js_type = self.get_ptr_decl(n.type, decl=decl, func_decl=func_decl) 361 | js_name = decl.name 362 | 363 | # js_type = { 364 | # 'kind': 'TypeDecl', 365 | # 'name': js_name, 366 | # 'type': t, 367 | # } 368 | elif isinstance(n.type, c_ast.Enum): 369 | js_type = self.get_enum(n.type, type_decl=n) 370 | js_name = n.declname 371 | 372 | # js_type = { 373 | # 'kind': 'TypeDecl', 374 | # 'name': js_name, 375 | # 'type': t, 376 | # } 377 | 378 | if not js_name: 379 | js_name = f'_{randint(0, 2 ** 64)}_enum' 380 | 381 | js_type['name'] = js_name 382 | 383 | for item_name, item_value in js_type['type']['items'].items(): 384 | self.CONSTS[item_name] = item_value 385 | 386 | if js_name not in self.TYPEDEF_ENUM: 387 | self.ENUM_DECL[js_name] = js_type 388 | elif isinstance(n.type, c_ast.Struct): 389 | js_type = self.get_struct(n.type, type_decl=n) 390 | 391 | # js_type = { 392 | # 'kind': 'TypeDecl', 393 | # 'name': js_name, 394 | # 'type': t, 395 | # } 396 | 397 | if not js_name: 398 | js_name = f'_{randint(0, 2 ** 64)}_struct' 399 | 400 | js_type['name'] = js_name 401 | 402 | if js_name not in self.TYPEDEF_STRUCT: 403 | self.STRUCT_DECL[js_name] = js_type 404 | elif isinstance(n.type, c_ast.Union): 405 | js_type = self.get_union(n.type, type_decl=n) 406 | 407 | # js_type = { 408 | # 'kind': 'TypeDecl', 409 | # 'name': js_name, 410 | # 'type': t, 411 | # } 412 | 413 | if not js_name: 414 | js_name = f'_{randint(0, 2 ** 64)}_union' 415 | 416 | js_type['name'] = js_name 417 | 418 | if js_name not in self.TYPEDEF_UNION: 419 | self.UNION_DECL[js_name] = js_type 420 | else: 421 | raise TypeError(n) 422 | else: 423 | if isinstance(n.type, c_ast.IdentifierType): 424 | js_name = n.declname 425 | js_type = self.get_leaf_name(n.type) 426 | self.TYPE_DECL[js_name] = js_type 427 | elif isinstance(n.type, c_ast.PtrDecl): 428 | js_type = self.get_ptr_decl(n.type, decl=decl, func_decl=func_decl) 429 | js_name = decl.name 430 | 431 | # js_type = { 432 | # 'kind': 'TypeDecl', 433 | # 'name': js_name, 434 | # 'type': t, 435 | # } 436 | elif isinstance(n.type, c_ast.Enum): 437 | js_type = self.get_enum(n.type, typedef=typedef, type_decl=n) 438 | js_name = n.declname 439 | 440 | # js_type = { 441 | # 'kind': 'TypeDecl', 442 | # 'name': js_name, 443 | # 'type': t, 444 | # } 445 | 446 | if not js_name: 447 | js_name = f'_{randint(0, 2 ** 64)}_enum' 448 | 449 | js_type['name'] = js_name 450 | 451 | for item_name, item_value in js_type['type']['items'].items(): 452 | self.CONSTS[item_name] = item_value 453 | 454 | if js_name not in self.TYPEDEF_ENUM: 455 | self.ENUM_DECL[js_name] = js_type 456 | elif isinstance(n.type, c_ast.Struct): 457 | js_type = self.get_struct(n.type, typedef=typedef, type_decl=n) 458 | 459 | # js_type = { 460 | # 'kind': 'TypeDecl', 461 | # 'name': js_name, 462 | # 'type': t, 463 | # } 464 | 465 | if not js_name: 466 | js_name = f'_{randint(0, 2 ** 64)}_struct' 467 | 468 | js_type['name'] = js_name 469 | 470 | if js_name not in self.TYPEDEF_STRUCT: 471 | self.STRUCT_DECL[js_name] = js_type 472 | elif isinstance(n.type, c_ast.Union): 473 | js_type = self.get_union(n.type, typedef=typedef, type_decl=n) 474 | 475 | # js_type = { 476 | # 'kind': 'TypeDecl', 477 | # 'name': js_name, 478 | # 'type': t, 479 | # } 480 | 481 | if not js_name: 482 | js_name = f'_{randint(0, 2 ** 64)}_union' 483 | 484 | js_type['name'] = js_name 485 | 486 | if js_name not in self.TYPEDEF_UNION: 487 | self.UNION_DECL[js_name] = js_type 488 | else: 489 | raise TypeError(n) 490 | 491 | return js_type 492 | 493 | 494 | def get_ptr_decl(self, n, typedef=None, decl=None, func_decl=None) -> CType: 495 | js_type: CType = None 496 | js_name: str | None = None 497 | 498 | if typedef: 499 | t = self.get_node(n.type, typedef=typedef, ptr_decl=n) 500 | js_name = typedef.name 501 | 502 | js_type = { 503 | 'kind': 'PtrDecl', 504 | 'name': js_name, 505 | 'type': t, 506 | } 507 | 508 | if not js_name: 509 | js_name = f'_{randint(0, 2 ** 64)}_ptr_decl' 510 | 511 | self.TYPEDEF_PTR_DECL[js_name] = js_type 512 | elif decl: 513 | t = self.get_node(n.type, decl=decl, ptr_decl=n) 514 | js_name = None # NOTE: in this implementation is always None, but can be set to real name 515 | 516 | js_type = { 517 | 'kind': 'PtrDecl', 518 | 'name': js_name, 519 | 'type': t, 520 | } 521 | elif func_decl: 522 | t = self.get_node(n.type, func_decl=func_decl, ptr_decl=n) 523 | js_name = None # NOTE: in this implementation is always None, but can be set to real name 524 | 525 | js_type = { 526 | 'kind': 'PtrDecl', 527 | 'name': js_name, 528 | 'type': t, 529 | } 530 | else: 531 | raise TypeError(type(n)) 532 | 533 | return js_type 534 | 535 | 536 | def get_struct(self, n, typedef=None, type_decl=None) -> CType: 537 | js_type: CType = None 538 | js_name: str 539 | js_fields: dict 540 | 541 | if n.name: 542 | js_name = n.name 543 | elif type_decl and type_decl.declname: 544 | js_name = type_decl.declname 545 | elif typedef and typedef.name: 546 | js_name = typedef.name 547 | else: 548 | raise ValueError(f'Could not get name of struct node {n}') 549 | 550 | # NOTE: does not parse struct fields 551 | js_fields = {} 552 | 553 | js_type = { 554 | 'kind': 'Struct', 555 | 'name': js_name, 556 | 'fields': js_fields, 557 | } 558 | 559 | if not js_name: 560 | js_name = f'_{randint(0, 2 ** 64)}_struct' 561 | 562 | self.STRUCT_DECL[js_name] = js_type 563 | return js_type 564 | 565 | 566 | def get_union(self, n, typedef=None, type_decl=None) -> CType: 567 | js_type: CType = None 568 | js_name: str 569 | js_fields: dict 570 | 571 | if n.name: 572 | js_name = n.name 573 | elif type_decl and type_decl.declname: 574 | js_name = type_decl.declname 575 | elif typedef and typedef.name: 576 | js_name = typedef.name 577 | else: 578 | raise ValueError(f'Could not get name of union node {n}') 579 | 580 | # NOTE: does not parse struct fields 581 | js_fields = {} 582 | 583 | js_type = { 584 | 'kind': 'Union', 585 | 'name': js_name, 586 | 'fields': js_fields, 587 | } 588 | 589 | if not js_name: 590 | js_name = f'_{randint(0, 2 ** 64)}_union' 591 | 592 | self.UNION_DECL[js_name] = js_type 593 | return js_type 594 | 595 | 596 | def get_enum(self, n, typedef=None, decl=None, type_decl=None) -> CType: 597 | # FIXME: use typedef 598 | js_type: CType 599 | 600 | 601 | def eval_op(n): 602 | if isinstance(n, c_ast.Constant): 603 | return eval(n.value) 604 | elif isinstance(n, c_ast.UnaryOp): 605 | return eval(f'{n.op} {eval_op(n.expr)}') 606 | elif isinstance(n, c_ast.BinaryOp): 607 | return eval(f'{eval_op(n.left)} {n.op} {eval_op(n.right)}') 608 | else: 609 | raise TypeError(f'get_enum: Unsupported {type(n)}') 610 | 611 | 612 | if decl or type_decl: 613 | assert isinstance(n.values, c_ast.EnumeratorList) 614 | assert isinstance(n.values.enumerators, list) 615 | last_enum_field_value: int = -1 616 | 617 | js_type = { 618 | 'kind': 'Enum', 619 | 'name': n.name, 620 | 'items': {}, 621 | } 622 | 623 | for m in n.values.enumerators: 624 | enum_field_name: str = m.name 625 | enum_field_value: Any 626 | 627 | if m.value: 628 | enum_field_value = eval_op(m.value) 629 | else: 630 | enum_field_value = last_enum_field_value + 1 631 | 632 | last_enum_field_value = enum_field_value 633 | js_type['items'][enum_field_name] = enum_field_value 634 | 635 | js_name = js_type['name'] 636 | 637 | if not js_name: 638 | js_name = f'_{randint(0, 2 ** 64)}_enum' 639 | 640 | self.ENUM_DECL[js_name] = js_type 641 | else: 642 | raise TypeError(type(n)) 643 | 644 | return js_type 645 | 646 | 647 | def get_func_decl(self, n, typedef=None, decl=None, ptr_decl=None) -> CType: 648 | assert isinstance(n.args, c_ast.ParamList) 649 | assert isinstance(n.args.params, list) 650 | js_type: CType = None 651 | js_name: str | None = None 652 | typedef_js_name: str | None = None 653 | decl_js_name: str | None = None 654 | 655 | if typedef: 656 | typedef_js_name = typedef.name 657 | 658 | if hasattr(n.type, 'declname'): 659 | decl_js_name = n.type.declname 660 | else: 661 | decl_js_name = n.type.type.declname 662 | 663 | js_name = decl_js_name 664 | elif decl: 665 | decl_js_name = decl.name 666 | js_name = decl_js_name 667 | 668 | js_type = { 669 | 'kind': 'FuncDecl', 670 | 'name': js_name, 671 | 'return_type': None, 672 | 'params_types': [], 673 | } 674 | 675 | # return type 676 | t = self.get_node(n.type, typedef=typedef, func_decl=n, ptr_decl=ptr_decl) 677 | js_type['return_type'] = t 678 | 679 | # params types 680 | for m in n.args.params: 681 | t = self.get_node(m, func_decl=n) 682 | js_type['params_types'].append(t) 683 | 684 | if not ptr_decl and typedef_js_name: 685 | self.TYPEDEF_FUNC_DECL[typedef_js_name] = js_type 686 | 687 | if not typedef and not ptr_decl and decl_js_name: 688 | self.FUNC_DECL[decl_js_name] = js_type 689 | 690 | return js_type 691 | 692 | 693 | def get_array_decl(self, n, decl=None) -> CType: 694 | # FIXME: implement 695 | js_type: CType = None 696 | return js_type 697 | 698 | 699 | def get_typedef(self, n) -> CType: 700 | js_type: CType 701 | js_name: str = n.name 702 | 703 | if isinstance(n.type, c_ast.TypeDecl): 704 | t = self.get_type_decl(n.type, typedef=n) 705 | elif isinstance(n.type, c_ast.FuncDecl): 706 | t = self.get_func_decl(n.type, typedef=n) 707 | elif isinstance(n.type, c_ast.PtrDecl): 708 | t = self.get_ptr_decl(n.type, typedef=n) 709 | else: 710 | raise TypeError(type(n.type)) 711 | 712 | js_type = { 713 | 'kind': 'Typedef', 714 | 'name': js_name, 715 | 'type': t, 716 | } 717 | 718 | return js_type 719 | 720 | 721 | def get_decl(self, n, func_decl=None) -> CType: 722 | js_type: CType = None 723 | 724 | if isinstance(n.type, c_ast.Enum): 725 | js_type = self.get_enum(n.type, decl=n) 726 | elif isinstance(n.type, c_ast.TypeDecl): 727 | js_type = self.get_type_decl(n.type, decl=n) 728 | elif isinstance(n.type, c_ast.FuncDecl): 729 | js_type = self.get_func_decl(n.type, decl=n) 730 | elif isinstance(n.type, c_ast.PtrDecl): 731 | js_type = self.get_ptr_decl(n.type, decl=n) 732 | elif isinstance(n.type, c_ast.ArrayDecl): 733 | js_type = self.get_array_decl(n.type, decl=n) 734 | elif isinstance(n.type, c_ast.Struct): 735 | js_type = self.get_type_decl(n, decl=n, func_decl=func_decl) 736 | elif isinstance(n.type, c_ast.Union): 737 | js_type = self.get_type_decl(n, decl=n, func_decl=func_decl) 738 | else: 739 | raise TypeError(type(n.type)) 740 | 741 | return js_type 742 | 743 | 744 | def get_node(self, n, typedef=None, decl=None, ptr_decl=None, func_decl=None) -> CType: 745 | # NOTE: typedef unused 746 | js_type: CType = None 747 | 748 | if isinstance(n, c_ast.Decl): 749 | js_type = self.get_decl(n, func_decl=func_decl) 750 | elif isinstance(n, c_ast.TypeDecl): 751 | js_type = self.get_type_decl(n, decl=decl, func_decl=func_decl) 752 | elif isinstance(n, c_ast.PtrDecl): 753 | js_type = self.get_ptr_decl(n, decl=decl, func_decl=func_decl) 754 | elif isinstance(n, c_ast.FuncDecl): 755 | js_type = self.get_func_decl(n, typedef=typedef, decl=decl, ptr_decl=ptr_decl) 756 | elif isinstance(n, c_ast.Typename): 757 | js_type = self.get_typename(n, decl=decl, func_decl=func_decl) 758 | elif isinstance(n, c_ast.EllipsisParam): 759 | pass 760 | else: 761 | raise TypeError(n) 762 | 763 | return js_type 764 | 765 | 766 | def get_file_ast(self, file_ast, shared_library: str): 767 | js_type: CType = None 768 | 769 | for n in file_ast.ext: 770 | # print(n) 771 | 772 | if isinstance(n, c_ast.Typedef): 773 | js_type = self.get_typedef(n) 774 | elif isinstance(n, c_ast.Decl): 775 | js_type = self.get_decl(n) 776 | else: 777 | raise TypeError(type(n.type)) 778 | 779 | 780 | def simplify_type(self, js_type: Union[str, dict]) -> CType: 781 | output_js_type: CType 782 | 783 | if isinstance(js_type, dict) and js_type['kind'] == 'PtrDecl': 784 | if js_type['type'] == 'char': 785 | output_js_type = 'string' 786 | else: 787 | output_js_type = 'pointer' 788 | elif isinstance(js_type, dict) and js_type['kind'] == 'Typename': 789 | output_js_type = self.simplify_type(js_type['type']) 790 | elif isinstance(js_type, str): 791 | js_name = js_type 792 | 793 | if js_name in self.BUILTIN_TYPES: 794 | output_js_type = self.BUILTIN_TYPES[js_name] 795 | elif js_name in self.TYPEDEF_PTR_DECL: 796 | output_js_type = 'pointer' 797 | elif js_name in self.TYPEDEF_ENUM or js_name in self.ENUM_DECL: 798 | output_js_type = 'int' 799 | else: 800 | output_js_type = js_type 801 | else: 802 | output_js_type = js_type 803 | 804 | return output_js_type 805 | 806 | 807 | def create_output_dir(self, output_path: str): 808 | dirpath, filename = os.path.split(output_path) 809 | 810 | if dirpath: 811 | os.makedirs(dirpath, exist_ok=True) 812 | 813 | 814 | def preprocess_header_file(self, compiler: str, cflags: list[str], input_path: str, output_path: str): 815 | # print('DEFAULT_FRONTEND_CFLAGS', DEFAULT_FRONTEND_CFLAGS) 816 | # print('cflags', cflags) 817 | new_cflags = DEFAULT_FRONTEND_CFLAGS + cflags 818 | cmd = [compiler, '-E', *new_cflags, input_path] 819 | output: bytes = subprocess.check_output(cmd) 820 | 821 | with open(output_path, 'w+b') as f: 822 | f.write(output) 823 | 824 | 825 | def _get_size_of(self, js_name: str) -> int: 826 | cmd = f""" 827 | rm -f ./a.out 828 | 829 | gcc -x c {self.sizeof_cflags} - <<<' 830 | #include 831 | """ 832 | 833 | cmd += '\n'.join(f'#include <{n}>' for n in self.sizeof_include.split(',')) 834 | 835 | cmd += f""" 836 | int main() {{ 837 | printf("%u", sizeof({js_name})); 838 | return 0; 839 | }} 840 | ' 841 | 842 | ./a.out 843 | """ 844 | 845 | output: bytes = subprocess.check_output(cmd, shell=True) 846 | 847 | # cleanup 848 | if os.path.exists('a.out'): 849 | os.remove('a.out') 850 | 851 | size: int = int(output.decode()) 852 | return size 853 | 854 | 855 | def get_size_of(self, js_name: str) -> int: 856 | try: 857 | return self._get_size_of(js_name) 858 | except Exception as e: 859 | return -1 860 | 861 | 862 | def translate_to_js(self) -> str: 863 | lines: list[str] = [ 864 | "import { CFunction, CCallback } from 'local/quickjs-cffi/quickjs-ffi.js';", 865 | "import * as ffi from 'local/quickjs-cffi/quickjs-ffi.so';", 866 | "export const malloc = ffi.malloc;", 867 | "export const free = ffi.free;", 868 | f"const LIB = {dumps(self.shared_library)};", 869 | "const None = null;", 870 | "", 871 | QUICKJS_FFI_WRAP_PTR_FUNC_DECL, 872 | "", 873 | ] 874 | 875 | # CONSTS 876 | line = 'export const CONSTS = {' 877 | lines.append(line) 878 | 879 | for js_name, value in self.CONSTS.items(): 880 | line = f' {js_name}: {value},' 881 | lines.append(line) 882 | 883 | line = '};' 884 | lines.append(line) 885 | 886 | # TYPEDEF_ENUM 887 | for js_name, js_type in self.TYPEDEF_ENUM.items(): 888 | line = f"export const {js_name} = {js_type['items']};" 889 | line += f"/* TYPEDEF_ENUM: {js_name} {js_type} */" 890 | lines.append(line) 891 | 892 | # ENUM_DECL 893 | for js_name, js_type in self.ENUM_DECL.items(): 894 | line = f"export const {js_name} = {js_type['items']};" 895 | line += f"/* ENUM_DECL: {js_name} {js_type} */" 896 | lines.append(line) 897 | 898 | # TYPEDEF_FUNC_DECL 899 | for js_name, js_type in self.TYPEDEF_FUNC_DECL.items(): 900 | line = f"/* TYPEDEF_FUNC_DECL: {js_name} {js_type} */" 901 | lines.append(line) 902 | 903 | # TYPEDEF_PTR_DECL 904 | for js_name, js_type in self.TYPEDEF_PTR_DECL.items(): 905 | line = f"/* TYPEDEF_PTR_DECL: {js_name} {js_type} */" 906 | lines.append(line) 907 | 908 | # FUNC_DECL 909 | for js_name, js_type in self.FUNC_DECL.items(): 910 | return_type = js_type['return_type'] 911 | params_types = js_type['params_types'] 912 | 913 | # prepare params_types 914 | _params_types = [] 915 | 916 | for pt in params_types: 917 | if isinstance(pt, dict): 918 | if pt['kind'] == 'Typename': 919 | pt = pt['type'] 920 | 921 | if isinstance(pt, dict) and isinstance(pt['type'], str) and pt['type'] in self.TYPEDEF_FUNC_DECL: 922 | typedef_func_decl = self.TYPEDEF_FUNC_DECL[pt['type']] 923 | typedef_func_decl_return_type = self.simplify_type(typedef_func_decl['return_type']) 924 | typedef_func_decl_params_types = [self.simplify_type(n) for n in typedef_func_decl['params_types']] 925 | 926 | new_pt = { 927 | 'kind': 'PtrFuncDecl', 928 | 'return_type': typedef_func_decl_return_type, 929 | 'params_types': typedef_func_decl_params_types, 930 | } 931 | 932 | _params_types.append(new_pt) 933 | else: 934 | new_pt = self.simplify_type(pt) 935 | _params_types.append(new_pt) 936 | else: 937 | new_pt = self.simplify_type(pt) 938 | _params_types.append(new_pt) 939 | else: 940 | _params_types.append(pt) 941 | 942 | params_types = _params_types 943 | 944 | # find additional PtrFuncDecl 945 | _params_types = [] 946 | 947 | for pt in params_types: 948 | if isinstance(pt, str): 949 | if pt in self.TYPEDEF_PTR_DECL: 950 | tpd = self.TYPEDEF_PTR_DECL[pt] 951 | 952 | if tpd['kind'] == 'PtrDecl' and isinstance(tpd['type'], dict) and tpd['type']['kind'] == 'FuncDecl': 953 | typedef_func_decl = tpd['type'] 954 | typedef_func_decl_return_type = self.simplify_type(typedef_func_decl['return_type']) 955 | typedef_func_decl_params_types = [self.simplify_type(n) for n in typedef_func_decl['params_types']] 956 | 957 | new_pt = { 958 | 'kind': 'PtrFuncDecl', 959 | 'return_type': typedef_func_decl_return_type, 960 | 'params_types': typedef_func_decl_params_types, 961 | } 962 | 963 | _params_types.append(new_pt) 964 | else: 965 | new_pt = self.simplify_type(pt) 966 | _params_types.append(new_pt) 967 | else: 968 | new_pt = self.simplify_type(pt) 969 | _params_types.append(new_pt) 970 | else: 971 | _params_types.append(pt) 972 | 973 | params_types = _params_types 974 | # print('!', js_name, return_type, params_types) 975 | 976 | # export of func 977 | types = [return_type, *params_types] 978 | line = f"export const {js_name} = _quickjs_ffi_wrap_ptr_func_decl(LIB, {dumps(js_name)}, null, ...{types});" 979 | line += f"/* FUNC_DECL: {js_name} {js_type} */" 980 | lines.append(line) 981 | 982 | # STRUCT_DECL 983 | for js_name, js_type in self.STRUCT_DECL.items(): 984 | if js_name.startswith('_') and js_name.endswith('_struct'): 985 | continue 986 | 987 | size = self.get_size_of(js_name) 988 | line = f'export const sizeof_{js_name} = {size};' 989 | line += f"/* STRUCT_DECL: {js_name} {js_type} */" 990 | lines.append(line) 991 | 992 | # UNION_DECL 993 | for js_name, js_type in self.UNION_DECL.items(): 994 | if js_name.startswith('_') and js_name.endswith('_union'): 995 | continue 996 | 997 | size = self.get_size_of(js_name) 998 | line = f'export const sizeof_{js_name} = {size};' 999 | line += f"/* UNION_DECL: {js_name} {js_type} */" 1000 | lines.append(line) 1001 | 1002 | # TYPEDEF_STRUCT 1003 | for js_name, js_type in self.TYPEDEF_STRUCT.items(): 1004 | if js_name.startswith('_') and js_name.endswith('_struct'): 1005 | continue 1006 | 1007 | size = self.get_size_of(js_name) 1008 | line = f'export const sizeof_{js_name} = {size};' 1009 | line += f"/* TYPEDEF_STRUCT: {js_name} {js_type} */" 1010 | lines.append(line) 1011 | 1012 | # TYPEDEF_UNION 1013 | for js_name, js_type in self.TYPEDEF_UNION.items(): 1014 | if js_name.startswith('_') and js_name.endswith('_union'): 1015 | continue 1016 | 1017 | size = self.get_size_of(js_name) 1018 | line = f'export const sizeof_{js_name} = {size};' 1019 | line += f"/* TYPEDEF_UNION: {js_name} {js_type} */" 1020 | lines.append(line) 1021 | 1022 | output: str = '\n'.join(lines) 1023 | return output 1024 | 1025 | 1026 | def translate(self): 1027 | # check existance of input_path 1028 | assert os.path.exists(self.input_path) 1029 | 1030 | # prepare input_paths 1031 | input_paths: list[str] 1032 | 1033 | if os.path.isfile(self.input_path): 1034 | input_paths = [self.input_path] 1035 | elif os.path.isdir(self.input_path): 1036 | input_paths = [] 1037 | 1038 | for root, dirs, files in os.walk(self.input_path): 1039 | for f in files: 1040 | # skip non-header files 1041 | _, ext = os.path.splitext(f) 1042 | 1043 | if ext != '.h': 1044 | continue 1045 | 1046 | # append header path to file 1047 | path = os.path.join(root, f) 1048 | input_paths.append(path) 1049 | 1050 | # output path 1051 | output_path_is_dir = False 1052 | 1053 | if not os.path.exists(self.output_path): 1054 | _, ext = os.path.splitext(self.output_path) 1055 | 1056 | if not ext: 1057 | output_path_is_dir = True 1058 | else: 1059 | if os.path.isdir(self.output_path): 1060 | output_path_is_dir = True 1061 | else: 1062 | _, ext = os.path.splitext(self.output_path) 1063 | 1064 | if not ext: 1065 | output_path_is_dir = True 1066 | 1067 | # create destination directory if does not exist 1068 | self.create_output_dir(self.output_path) 1069 | 1070 | # process input files 1071 | run_id = str(uuid4()) 1072 | processed_input_paths: list[str] = [] 1073 | 1074 | for input_path in input_paths: 1075 | # new processing context 1076 | self.push_new_processing_context() 1077 | 1078 | # preprocess input header path 1079 | dirpath, filename = os.path.split(input_path) 1080 | basename, ext = os.path.splitext(filename) 1081 | processed_input_path = os.path.join('/tmp', f'_{run_id}_{basename}.h') 1082 | 1083 | # preprocess input header file 1084 | try: 1085 | self.preprocess_header_file(self.frontend_compiler, self.frontend_cflags, input_path, processed_input_path) 1086 | except Exception as e: 1087 | if self.keep_going: 1088 | print('skipped [0]:', processed_input_path) 1089 | continue 1090 | else: 1091 | print('error parsing [0]:', processed_input_path) 1092 | raise e 1093 | 1094 | # parse input header path 1095 | try: 1096 | file_ast = parse_file(processed_input_path, use_cpp=True) 1097 | except Exception as e: 1098 | if self.keep_going: 1099 | print('skipped [1]:', processed_input_path) 1100 | continue 1101 | else: 1102 | print('error parsing [1]:', processed_input_path) 1103 | raise e 1104 | 1105 | processed_input_paths.append(processed_input_path) 1106 | assert isinstance(file_ast, c_ast.FileAST) 1107 | 1108 | # output individual files if required 1109 | if output_path_is_dir: 1110 | # pop processing context 1111 | prev_context = self.pop_processing_context() 1112 | 1113 | # process C ast 1114 | self.get_file_ast(file_ast, shared_library=self.shared_library) 1115 | 1116 | # output individual files if required 1117 | if output_path_is_dir: 1118 | # translate processed header files 1119 | output_data: str = self.translate_to_js() 1120 | output_path = os.path.join(self.output_path, f'{basename}.js') 1121 | 1122 | # create destination directory if does not exist 1123 | self.create_output_dir(output_path) 1124 | 1125 | with open(output_path, 'w+') as f: 1126 | f.write(output_data) 1127 | 1128 | # restore processing context 1129 | self.push_processing_context(prev_context) 1130 | 1131 | # output single file if required 1132 | if not output_path_is_dir: 1133 | # translate processed header files 1134 | output_data: str = self.translate_to_js() 1135 | 1136 | with open(self.output_path, 'w+') as f: 1137 | f.write(output_data) 1138 | 1139 | # cleanup 1140 | for processed_input_path in processed_input_paths: 1141 | os.remove(processed_input_path) 1142 | 1143 | # verbose 1144 | if self.verbose: 1145 | self.print() 1146 | 1147 | 1148 | def print(self): 1149 | print('CONSTS:') 1150 | pprint(self.CONSTS, sort_dicts=False) 1151 | print() 1152 | 1153 | print('TYPE_DECL:') 1154 | pprint(self.TYPE_DECL, sort_dicts=False) 1155 | print() 1156 | 1157 | print('FUNC_DECL:') 1158 | pprint(self.FUNC_DECL, sort_dicts=False) 1159 | print() 1160 | 1161 | print('STRUCT_DECL:') 1162 | pprint(self.STRUCT_DECL, sort_dicts=False) 1163 | print() 1164 | 1165 | print('UNION_DECL:') 1166 | pprint(self.UNION_DECL, sort_dicts=False) 1167 | print() 1168 | 1169 | print('ENUM_DECL:') 1170 | pprint(self.ENUM_DECL, sort_dicts=False) 1171 | print() 1172 | 1173 | print('ARRAY_DECL:') 1174 | pprint(self.ARRAY_DECL, sort_dicts=False) 1175 | print() 1176 | 1177 | print('TYPEDEF_STRUCT:') 1178 | pprint(self.TYPEDEF_STRUCT, sort_dicts=False) 1179 | print() 1180 | 1181 | print('TYPEDEF_UNION:') 1182 | pprint(self.TYPEDEF_UNION, sort_dicts=False) 1183 | print() 1184 | 1185 | print('TYPEDEF_ENUM:') 1186 | pprint(self.TYPEDEF_ENUM, sort_dicts=False) 1187 | print() 1188 | 1189 | print('TYPEDEF_FUNC_DECL:') 1190 | pprint(self.TYPEDEF_FUNC_DECL, sort_dicts=False) 1191 | print() 1192 | 1193 | print('TYPEDEF_PTR_DECL:') 1194 | pprint(self.TYPEDEF_PTR_DECL, sort_dicts=False) 1195 | print() 1196 | 1197 | print('TYPEDEF_TYPE_DECL:') 1198 | pprint(self.TYPEDEF_TYPE_DECL, sort_dicts=False) 1199 | print() 1200 | 1201 | 1202 | if __name__ == '__main__': 1203 | # cli arg parser 1204 | parser = argparse.ArgumentParser(description='Convert .h to .js') 1205 | parser.add_argument('-fc', dest='frontend_compiler', default='gcc', help='gcc, clang, tcc') 1206 | parser.add_argument('-bc', dest='backend_compiler', default='gcc', help='gcc, clang, tcc') 1207 | parser.add_argument('-fc-cflags', dest='frontend_cflags', default='', help='Frontend compiler\'s cflags') 1208 | parser.add_argument('-sizeof-cflags', dest='sizeof_cflags', default='', help='sizeof cflags') 1209 | parser.add_argument('-sizeof-include', dest='sizeof_include', default='', help='sizeof include path') 1210 | parser.add_argument('-l', dest='shared_library', default='./libcfltk.so', help='Shared library') 1211 | parser.add_argument('-i', dest='input_path', help='path to .h file or whole directory') 1212 | parser.add_argument('-o', dest='output_path', help='output path to translated .js/.so file or whole directory') 1213 | parser.add_argument('-k', dest='keep_going', action='store_true', help='keep translating even on errors') 1214 | parser.add_argument('-v', dest='verbose', action='store_true', help='verbose') 1215 | args = parser.parse_args() 1216 | 1217 | # translate 1218 | c_parser = CParser(args.frontend_compiler, 1219 | [n for n in args.frontend_cflags.split(',') if n], 1220 | args.sizeof_cflags, 1221 | args.sizeof_include, 1222 | args.backend_compiler, 1223 | args.shared_library, 1224 | args.input_path, 1225 | args.output_path, 1226 | args.keep_going, 1227 | args.verbose) 1228 | 1229 | c_parser.translate() 1230 | -------------------------------------------------------------------------------- /fake_include/mswsock.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtasic85/quickjs-cffi-generator/e9987252e84f4ca2819f889a5ea96579f7cd559c/fake_include/mswsock.h -------------------------------------------------------------------------------- /fake_include/port.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtasic85/quickjs-cffi-generator/e9987252e84f4ca2819f889a5ea96579f7cd559c/fake_include/port.h -------------------------------------------------------------------------------- /fake_include/sys/cdefs.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtasic85/quickjs-cffi-generator/e9987252e84f4ca2819f889a5ea96579f7cd559c/fake_include/sys/cdefs.h -------------------------------------------------------------------------------- /fake_include/sys/param.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtasic85/quickjs-cffi-generator/e9987252e84f4ca2819f889a5ea96579f7cd559c/fake_include/sys/param.h -------------------------------------------------------------------------------- /fake_include/sys/port.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtasic85/quickjs-cffi-generator/e9987252e84f4ca2819f889a5ea96579f7cd559c/fake_include/sys/port.h -------------------------------------------------------------------------------- /fake_include/windows.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtasic85/quickjs-cffi-generator/e9987252e84f4ca2819f889a5ea96579f7cd559c/fake_include/windows.h -------------------------------------------------------------------------------- /fake_include/winsock2.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtasic85/quickjs-cffi-generator/e9987252e84f4ca2819f889a5ea96579f7cd559c/fake_include/winsock2.h -------------------------------------------------------------------------------- /fake_include/ws2tcpip.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtasic85/quickjs-cffi-generator/e9987252e84f4ca2819f889a5ea96579f7cd559c/fake_include/ws2tcpip.h -------------------------------------------------------------------------------- /fake_libc_include/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | This is a list of people who have contributed to pycparser by supplying patches, 2 | opening issues, or generally helping out, before the project moved to Github. 3 | 4 | For more recent contributions, check out the "Contributors" page of the 5 | pycparser Github project. 6 | 7 | The list is sorted in increasing alphabetic order by first name. 8 | 9 | * Andreas Klöckner 10 | * Andrew de los Reyes 11 | * Benoit Pradelle 12 | * Dov Feldstern 13 | * Even Wiik Thomassen 14 | * Greg Smith 15 | * Jaroslav Franek 16 | * Li Xuan Ji 17 | * Mateusz Czaplinski 18 | * Paolo Di Maio 19 | * Rory Yorke 20 | * Rubin 21 | * Scott Tsai 22 | * Sye van der Veen 23 | * Thomas W. Barr 24 | * Tomer Segal 25 | * Weyllor 26 | -------------------------------------------------------------------------------- /fake_libc_include/LICENSE: -------------------------------------------------------------------------------- 1 | pycparser -- A C parser in Python 2 | 3 | Copyright (c) 2008-2020, Eli Bendersky 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, 7 | are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | * Neither the name of Eli Bendersky nor the names of its contributors may 15 | be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 24 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 27 | OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /fake_libc_include/X11/Intrinsic.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | #include "_X11_fake_defines.h" 4 | #include "_X11_fake_typedefs.h" 5 | -------------------------------------------------------------------------------- /fake_libc_include/X11/Xlib.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | #include "_X11_fake_defines.h" 4 | #include "_X11_fake_typedefs.h" 5 | -------------------------------------------------------------------------------- /fake_libc_include/X11/_X11_fake_defines.h: -------------------------------------------------------------------------------- 1 | #ifndef _X11_FAKE_DEFINES_H 2 | #define _X11_FAKE_DEFINES_H 3 | 4 | #define Atom CARD32 5 | #define Bool int 6 | #define KeySym CARD32 7 | #define Pixmap CARD32 8 | #define Time CARD32 9 | #define _XFUNCPROTOBEGIN 10 | #define _XFUNCPROTOEND 11 | #define _Xconst const 12 | 13 | #define _X_RESTRICT_KYWD 14 | #define Cardinal unsigned int 15 | #define Boolean int 16 | #endif 17 | -------------------------------------------------------------------------------- /fake_libc_include/X11/_X11_fake_typedefs.h: -------------------------------------------------------------------------------- 1 | #ifndef _X11_FAKE_TYPEDEFS_H 2 | #define _X11_FAKE_TYPEDEFS_H 3 | 4 | typedef char* XPointer; 5 | typedef unsigned char KeyCode; 6 | typedef unsigned int CARD32; 7 | typedef unsigned long VisualID; 8 | typedef unsigned long XIMResetState; 9 | typedef unsigned long XID; 10 | typedef XID Window; 11 | typedef XID Colormap; 12 | typedef XID Cursor; 13 | typedef XID Drawable; 14 | typedef void* XtPointer; 15 | typedef XtPointer XtRequestId; 16 | typedef struct Display Display; 17 | typedef struct Screen Screen; 18 | typedef struct Status Status; 19 | typedef struct Visual Visual; 20 | typedef struct Widget *Widget; 21 | typedef struct XColor XColor; 22 | typedef struct XClassHint XClassHint; 23 | typedef struct XEvent XEvent; 24 | typedef struct XFontStruct XFontStruct; 25 | typedef struct XGCValues XGCValues; 26 | typedef struct XKeyEvent XKeyEvent; 27 | typedef struct XKeyPressedEvent XKeyPressedEvent; 28 | typedef struct XPoint XPoint; 29 | typedef struct XRectangle XRectangle; 30 | typedef struct XSelectionRequestEvent XSelectionRequestEvent; 31 | typedef struct XWindowChanges XWindowChanges; 32 | typedef struct _XGC _XCG; 33 | typedef struct _XGC *GC; 34 | typedef struct _XIC *XIC; 35 | typedef struct _XIM *XIM; 36 | typedef struct _XImage XImage; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /fake_libc_include/_ansi.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/_fake_defines.h: -------------------------------------------------------------------------------- 1 | #ifndef _FAKE_DEFINES_H 2 | #define _FAKE_DEFINES_H 3 | 4 | #define NULL 0 5 | #define BUFSIZ 1024 6 | #define FOPEN_MAX 20 7 | #define FILENAME_MAX 1024 8 | 9 | #ifndef SEEK_SET 10 | #define SEEK_SET 0 /* set file offset to offset */ 11 | #endif 12 | #ifndef SEEK_CUR 13 | #define SEEK_CUR 1 /* set file offset to current plus offset */ 14 | #endif 15 | #ifndef SEEK_END 16 | #define SEEK_END 2 /* set file offset to EOF plus offset */ 17 | #endif 18 | 19 | #define __LITTLE_ENDIAN 1234 20 | #define LITTLE_ENDIAN __LITTLE_ENDIAN 21 | #define __BIG_ENDIAN 4321 22 | #define BIG_ENDIAN __BIG_ENDIAN 23 | #define __BYTE_ORDER __LITTLE_ENDIAN 24 | #define BYTE_ORDER __BYTE_ORDER 25 | 26 | #define EXIT_FAILURE 1 27 | #define EXIT_SUCCESS 0 28 | 29 | #define CHAR_MIN -128 30 | #define CHAR_MAX 127 31 | #define UCHAR_MAX 255 32 | #define SHRT_MIN -32768 33 | #define SHRT_MAX 32767 34 | #define USHRT_MAX 65535 35 | #define INT_MIN -2147483648 36 | #define INT_MAX 2147483647 37 | #define UINT_MAX 4294967295U 38 | #define LONG_MIN -9223372036854775808L 39 | #define LONG_MAX 9223372036854775807L 40 | #define ULONG_MAX 18446744073709551615UL 41 | #define RAND_MAX 32767 42 | 43 | /* C99 inttypes.h defines */ 44 | #define PRId8 "d" 45 | #define PRIi8 "i" 46 | #define PRIo8 "o" 47 | #define PRIu8 "u" 48 | #define PRIx8 "x" 49 | #define PRIX8 "X" 50 | #define PRId16 "d" 51 | #define PRIi16 "i" 52 | #define PRIo16 "o" 53 | #define PRIu16 "u" 54 | #define PRIx16 "x" 55 | #define PRIX16 "X" 56 | #define PRId32 "d" 57 | #define PRIi32 "i" 58 | #define PRIo32 "o" 59 | #define PRIu32 "u" 60 | #define PRIx32 "x" 61 | #define PRIX32 "X" 62 | #define PRId64 "d" 63 | #define PRIi64 "i" 64 | #define PRIo64 "o" 65 | #define PRIu64 "u" 66 | #define PRIx64 "x" 67 | #define PRIX64 "X" 68 | #define PRIdLEAST8 "d" 69 | #define PRIiLEAST8 "i" 70 | #define PRIoLEAST8 "o" 71 | #define PRIuLEAST8 "u" 72 | #define PRIxLEAST8 "x" 73 | #define PRIXLEAST8 "X" 74 | #define PRIdLEAST16 "d" 75 | #define PRIiLEAST16 "i" 76 | #define PRIoLEAST16 "o" 77 | #define PRIuLEAST16 "u" 78 | #define PRIxLEAST16 "x" 79 | #define PRIXLEAST16 "X" 80 | #define PRIdLEAST32 "d" 81 | #define PRIiLEAST32 "i" 82 | #define PRIoLEAST32 "o" 83 | #define PRIuLEAST32 "u" 84 | #define PRIxLEAST32 "x" 85 | #define PRIXLEAST32 "X" 86 | #define PRIdLEAST64 "d" 87 | #define PRIiLEAST64 "i" 88 | #define PRIoLEAST64 "o" 89 | #define PRIuLEAST64 "u" 90 | #define PRIxLEAST64 "x" 91 | #define PRIXLEAST64 "X" 92 | #define PRIdFAST8 "d" 93 | #define PRIiFAST8 "i" 94 | #define PRIoFAST8 "o" 95 | #define PRIuFAST8 "u" 96 | #define PRIxFAST8 "x" 97 | #define PRIXFAST8 "X" 98 | #define PRIdFAST16 "d" 99 | #define PRIiFAST16 "i" 100 | #define PRIoFAST16 "o" 101 | #define PRIuFAST16 "u" 102 | #define PRIxFAST16 "x" 103 | #define PRIXFAST16 "X" 104 | #define PRIdFAST32 "d" 105 | #define PRIiFAST32 "i" 106 | #define PRIoFAST32 "o" 107 | #define PRIuFAST32 "u" 108 | #define PRIxFAST32 "x" 109 | #define PRIXFAST32 "X" 110 | #define PRIdFAST64 "d" 111 | #define PRIiFAST64 "i" 112 | #define PRIoFAST64 "o" 113 | #define PRIuFAST64 "u" 114 | #define PRIxFAST64 "x" 115 | #define PRIXFAST64 "X" 116 | #define PRIdPTR "d" 117 | #define PRIiPTR "i" 118 | #define PRIoPTR "o" 119 | #define PRIuPTR "u" 120 | #define PRIxPTR "x" 121 | #define PRIXPTR "X" 122 | #define PRIdMAX "d" 123 | #define PRIiMAX "i" 124 | #define PRIoMAX "o" 125 | #define PRIuMAX "u" 126 | #define PRIxMAX "x" 127 | #define PRIXMAX "X" 128 | #define SCNd8 "d" 129 | #define SCNi8 "i" 130 | #define SCNo8 "o" 131 | #define SCNu8 "u" 132 | #define SCNx8 "x" 133 | #define SCNd16 "d" 134 | #define SCNi16 "i" 135 | #define SCNo16 "o" 136 | #define SCNu16 "u" 137 | #define SCNx16 "x" 138 | #define SCNd32 "d" 139 | #define SCNi32 "i" 140 | #define SCNo32 "o" 141 | #define SCNu32 "u" 142 | #define SCNx32 "x" 143 | #define SCNd64 "d" 144 | #define SCNi64 "i" 145 | #define SCNo64 "o" 146 | #define SCNu64 "u" 147 | #define SCNx64 "x" 148 | #define SCNdLEAST8 "d" 149 | #define SCNiLEAST8 "i" 150 | #define SCNoLEAST8 "o" 151 | #define SCNuLEAST8 "u" 152 | #define SCNxLEAST8 "x" 153 | #define SCNdLEAST16 "d" 154 | #define SCNiLEAST16 "i" 155 | #define SCNoLEAST16 "o" 156 | #define SCNuLEAST16 "u" 157 | #define SCNxLEAST16 "x" 158 | #define SCNdLEAST32 "d" 159 | #define SCNiLEAST32 "i" 160 | #define SCNoLEAST32 "o" 161 | #define SCNuLEAST32 "u" 162 | #define SCNxLEAST32 "x" 163 | #define SCNdLEAST64 "d" 164 | #define SCNiLEAST64 "i" 165 | #define SCNoLEAST64 "o" 166 | #define SCNuLEAST64 "u" 167 | #define SCNxLEAST64 "x" 168 | #define SCNdFAST8 "d" 169 | #define SCNiFAST8 "i" 170 | #define SCNoFAST8 "o" 171 | #define SCNuFAST8 "u" 172 | #define SCNxFAST8 "x" 173 | #define SCNdFAST16 "d" 174 | #define SCNiFAST16 "i" 175 | #define SCNoFAST16 "o" 176 | #define SCNuFAST16 "u" 177 | #define SCNxFAST16 "x" 178 | #define SCNdFAST32 "d" 179 | #define SCNiFAST32 "i" 180 | #define SCNoFAST32 "o" 181 | #define SCNuFAST32 "u" 182 | #define SCNxFAST32 "x" 183 | #define SCNdFAST64 "d" 184 | #define SCNiFAST64 "i" 185 | #define SCNoFAST64 "o" 186 | #define SCNuFAST64 "u" 187 | #define SCNxFAST64 "x" 188 | #define SCNdPTR "d" 189 | #define SCNiPTR "i" 190 | #define SCNoPTR "o" 191 | #define SCNuPTR "u" 192 | #define SCNxPTR "x" 193 | #define SCNdMAX "d" 194 | #define SCNiMAX "i" 195 | #define SCNoMAX "o" 196 | #define SCNuMAX "u" 197 | #define SCNxMAX "x" 198 | 199 | /* C99 stdbool.h defines */ 200 | #define __bool_true_false_are_defined 1 201 | #define false 0 202 | #define true 1 203 | 204 | /* va_arg macros and type*/ 205 | #define va_start(_ap, _type) __builtin_va_start((_ap)) 206 | #define va_arg(_ap, _type) __builtin_va_arg((_ap)) 207 | #define va_end(_list) 208 | 209 | /* Vectors */ 210 | #define __m128 int 211 | #define __m128_u int 212 | #define __m128d int 213 | #define __m128d_u int 214 | #define __m128i int 215 | #define __m128i_u int 216 | #define __m256 int 217 | #define __m256_u int 218 | #define __m256d int 219 | #define __m256d_u int 220 | #define __m256i int 221 | #define __m256i_u int 222 | #define __m512 int 223 | #define __m512_u int 224 | #define __m512d int 225 | #define __m512d_u int 226 | #define __m512i int 227 | #define __m512i_u int 228 | 229 | /* C11 stdnoreturn.h defines */ 230 | #define __noreturn_is_defined 1 231 | #define noreturn _Noreturn 232 | 233 | /* C11 threads.h defines */ 234 | #define thread_local _Thread_local 235 | 236 | /* C11 assert.h defines */ 237 | #define static_assert _Static_assert 238 | 239 | /* C11 stdatomic.h defines */ 240 | #define ATOMIC_BOOL_LOCK_FREE 0 241 | #define ATOMIC_CHAR_LOCK_FREE 0 242 | #define ATOMIC_CHAR16_T_LOCK_FREE 0 243 | #define ATOMIC_CHAR32_T_LOCK_FREE 0 244 | #define ATOMIC_WCHAR_T_LOCK_FREE 0 245 | #define ATOMIC_SHORT_LOCK_FREE 0 246 | #define ATOMIC_INT_LOCK_FREE 0 247 | #define ATOMIC_LONG_LOCK_FREE 0 248 | #define ATOMIC_LLONG_LOCK_FREE 0 249 | #define ATOMIC_POINTER_LOCK_FREE 0 250 | #define ATOMIC_VAR_INIT(value) (value) 251 | #define ATOMIC_FLAG_INIT { 0 } 252 | #define kill_dependency(y) (y) 253 | 254 | /* C11 stdalign.h defines */ 255 | #define alignas _Alignas 256 | #define alignof _Alignof 257 | #define __alignas_is_defined 1 258 | #define __alignof_is_defined 1 259 | 260 | #endif 261 | -------------------------------------------------------------------------------- /fake_libc_include/_fake_typedefs.h: -------------------------------------------------------------------------------- 1 | #ifndef _FAKE_TYPEDEFS_H 2 | #define _FAKE_TYPEDEFS_H 3 | 4 | typedef int size_t; 5 | typedef int __builtin_va_list; 6 | typedef int __gnuc_va_list; 7 | typedef int va_list; 8 | typedef int __int8_t; 9 | typedef int __uint8_t; 10 | typedef int __int16_t; 11 | typedef int __uint16_t; 12 | typedef int __int_least16_t; 13 | typedef int __uint_least16_t; 14 | typedef int __int32_t; 15 | typedef int __uint32_t; 16 | typedef int __int64_t; 17 | typedef int __uint64_t; 18 | typedef int __int_least32_t; 19 | typedef int __uint_least32_t; 20 | typedef int __s8; 21 | typedef int __u8; 22 | typedef int __s16; 23 | typedef int __u16; 24 | typedef int __s32; 25 | typedef int __u32; 26 | typedef int __s64; 27 | typedef int __u64; 28 | typedef int _LOCK_T; 29 | typedef int _LOCK_RECURSIVE_T; 30 | typedef int _off_t; 31 | typedef int __dev_t; 32 | typedef int __uid_t; 33 | typedef int __gid_t; 34 | typedef int _off64_t; 35 | typedef int _fpos_t; 36 | typedef int _ssize_t; 37 | typedef int wint_t; 38 | typedef int _mbstate_t; 39 | typedef int _flock_t; 40 | typedef int _iconv_t; 41 | typedef int __ULong; 42 | typedef int __FILE; 43 | typedef int ptrdiff_t; 44 | typedef int wchar_t; 45 | typedef int char16_t; 46 | typedef int char32_t; 47 | typedef int __off_t; 48 | typedef int __pid_t; 49 | typedef int __loff_t; 50 | typedef int u_char; 51 | typedef int u_short; 52 | typedef int u_int; 53 | typedef int u_long; 54 | typedef int ushort; 55 | typedef int uint; 56 | typedef int clock_t; 57 | typedef int time_t; 58 | typedef int daddr_t; 59 | typedef int caddr_t; 60 | typedef int ino_t; 61 | typedef int off_t; 62 | typedef int dev_t; 63 | typedef int uid_t; 64 | typedef int gid_t; 65 | typedef int pid_t; 66 | typedef int key_t; 67 | typedef int ssize_t; 68 | typedef int mode_t; 69 | typedef int nlink_t; 70 | typedef int fd_mask; 71 | typedef int _types_fd_set; 72 | typedef int clockid_t; 73 | typedef int timer_t; 74 | typedef int useconds_t; 75 | typedef int suseconds_t; 76 | typedef int FILE; 77 | typedef int fpos_t; 78 | typedef int cookie_read_function_t; 79 | typedef int cookie_write_function_t; 80 | typedef int cookie_seek_function_t; 81 | typedef int cookie_close_function_t; 82 | typedef int cookie_io_functions_t; 83 | typedef int div_t; 84 | typedef int ldiv_t; 85 | typedef int lldiv_t; 86 | typedef int sigset_t; 87 | typedef int __sigset_t; 88 | typedef int _sig_func_ptr; 89 | typedef int sig_atomic_t; 90 | typedef int __tzrule_type; 91 | typedef int __tzinfo_type; 92 | typedef int mbstate_t; 93 | typedef int sem_t; 94 | typedef int pthread_t; 95 | typedef int pthread_attr_t; 96 | typedef int pthread_mutex_t; 97 | typedef int pthread_mutexattr_t; 98 | typedef int pthread_cond_t; 99 | typedef int pthread_condattr_t; 100 | typedef int pthread_key_t; 101 | typedef int pthread_once_t; 102 | typedef int pthread_rwlock_t; 103 | typedef int pthread_rwlockattr_t; 104 | typedef int pthread_spinlock_t; 105 | typedef int pthread_barrier_t; 106 | typedef int pthread_barrierattr_t; 107 | typedef int jmp_buf; 108 | typedef int rlim_t; 109 | typedef int sa_family_t; 110 | typedef int sigjmp_buf; 111 | typedef int stack_t; 112 | typedef int siginfo_t; 113 | typedef int z_stream; 114 | 115 | /* C99 exact-width integer types */ 116 | typedef int int8_t; 117 | typedef int uint8_t; 118 | typedef int int16_t; 119 | typedef int uint16_t; 120 | typedef int int32_t; 121 | typedef int uint32_t; 122 | typedef int int64_t; 123 | typedef int uint64_t; 124 | 125 | /* C99 minimum-width integer types */ 126 | typedef int int_least8_t; 127 | typedef int uint_least8_t; 128 | typedef int int_least16_t; 129 | typedef int uint_least16_t; 130 | typedef int int_least32_t; 131 | typedef int uint_least32_t; 132 | typedef int int_least64_t; 133 | typedef int uint_least64_t; 134 | 135 | /* C99 fastest minimum-width integer types */ 136 | typedef int int_fast8_t; 137 | typedef int uint_fast8_t; 138 | typedef int int_fast16_t; 139 | typedef int uint_fast16_t; 140 | typedef int int_fast32_t; 141 | typedef int uint_fast32_t; 142 | typedef int int_fast64_t; 143 | typedef int uint_fast64_t; 144 | 145 | /* C99 integer types capable of holding object pointers */ 146 | typedef int intptr_t; 147 | typedef int uintptr_t; 148 | 149 | /* C99 greatest-width integer types */ 150 | typedef int intmax_t; 151 | typedef int uintmax_t; 152 | 153 | /* C99 stdbool.h bool type. _Bool is built-in in C99 */ 154 | typedef _Bool bool; 155 | 156 | /* Mir typedefs */ 157 | typedef void* MirEGLNativeWindowType; 158 | typedef void* MirEGLNativeDisplayType; 159 | typedef struct MirConnection MirConnection; 160 | typedef struct MirSurface MirSurface; 161 | typedef struct MirSurfaceSpec MirSurfaceSpec; 162 | typedef struct MirScreencast MirScreencast; 163 | typedef struct MirPromptSession MirPromptSession; 164 | typedef struct MirBufferStream MirBufferStream; 165 | typedef struct MirPersistentId MirPersistentId; 166 | typedef struct MirBlob MirBlob; 167 | typedef struct MirDisplayConfig MirDisplayConfig; 168 | 169 | /* xcb typedefs */ 170 | typedef struct xcb_connection_t xcb_connection_t; 171 | typedef uint32_t xcb_window_t; 172 | typedef uint32_t xcb_visualid_t; 173 | 174 | /* C11 stdatomic.h types */ 175 | typedef _Atomic(_Bool) atomic_bool; 176 | typedef _Atomic(char) atomic_char; 177 | typedef _Atomic(signed char) atomic_schar; 178 | typedef _Atomic(unsigned char) atomic_uchar; 179 | typedef _Atomic(short) atomic_short; 180 | typedef _Atomic(unsigned short) atomic_ushort; 181 | typedef _Atomic(int) atomic_int; 182 | typedef _Atomic(unsigned int) atomic_uint; 183 | typedef _Atomic(long) atomic_long; 184 | typedef _Atomic(unsigned long) atomic_ulong; 185 | typedef _Atomic(long long) atomic_llong; 186 | typedef _Atomic(unsigned long long) atomic_ullong; 187 | typedef _Atomic(uint_least16_t) atomic_char16_t; 188 | typedef _Atomic(uint_least32_t) atomic_char32_t; 189 | typedef _Atomic(wchar_t) atomic_wchar_t; 190 | typedef _Atomic(int_least8_t) atomic_int_least8_t; 191 | typedef _Atomic(uint_least8_t) atomic_uint_least8_t; 192 | typedef _Atomic(int_least16_t) atomic_int_least16_t; 193 | typedef _Atomic(uint_least16_t) atomic_uint_least16_t; 194 | typedef _Atomic(int_least32_t) atomic_int_least32_t; 195 | typedef _Atomic(uint_least32_t) atomic_uint_least32_t; 196 | typedef _Atomic(int_least64_t) atomic_int_least64_t; 197 | typedef _Atomic(uint_least64_t) atomic_uint_least64_t; 198 | typedef _Atomic(int_fast8_t) atomic_int_fast8_t; 199 | typedef _Atomic(uint_fast8_t) atomic_uint_fast8_t; 200 | typedef _Atomic(int_fast16_t) atomic_int_fast16_t; 201 | typedef _Atomic(uint_fast16_t) atomic_uint_fast16_t; 202 | typedef _Atomic(int_fast32_t) atomic_int_fast32_t; 203 | typedef _Atomic(uint_fast32_t) atomic_uint_fast32_t; 204 | typedef _Atomic(int_fast64_t) atomic_int_fast64_t; 205 | typedef _Atomic(uint_fast64_t) atomic_uint_fast64_t; 206 | typedef _Atomic(intptr_t) atomic_intptr_t; 207 | typedef _Atomic(uintptr_t) atomic_uintptr_t; 208 | typedef _Atomic(size_t) atomic_size_t; 209 | typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t; 210 | typedef _Atomic(intmax_t) atomic_intmax_t; 211 | typedef _Atomic(uintmax_t) atomic_uintmax_t; 212 | typedef struct atomic_flag { atomic_bool _Value; } atomic_flag; 213 | typedef enum memory_order { 214 | memory_order_relaxed, 215 | memory_order_consume, 216 | memory_order_acquire, 217 | memory_order_release, 218 | memory_order_acq_rel, 219 | memory_order_seq_cst 220 | } memory_order; 221 | 222 | #endif 223 | -------------------------------------------------------------------------------- /fake_libc_include/_syslist.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/aio.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/alloca.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/ar.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/argz.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/arpa/inet.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/asm-generic/int-ll64.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/assert.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/complex.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/cpio.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/ctype.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/dirent.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/dlfcn.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/emmintrin.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/endian.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/envz.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/errno.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/fastmath.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/fcntl.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/features.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/fenv.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/float.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/fmtmsg.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/fnmatch.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/ftw.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/getopt.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/glob.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/grp.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/iconv.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/ieeefp.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/immintrin.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/inttypes.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/iso646.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/langinfo.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/libgen.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/libintl.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/limits.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/linux/socket.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/linux/version.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/locale.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/malloc.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/math.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/mir_toolkit/client_types.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/monetary.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/mqueue.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/ndbm.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/net/if.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/netdb.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/netinet/in.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/netinet/tcp.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/newlib.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/nl_types.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/openssl/err.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/openssl/evp.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/openssl/hmac.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/openssl/ssl.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/openssl/x509v3.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/paths.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/poll.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/process.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/pthread.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/pwd.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/reent.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/regdef.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/regex.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sched.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/search.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/semaphore.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/setjmp.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/signal.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/smmintrin.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/spawn.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/stdalign.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/stdarg.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/stdatomic.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/stdbool.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/stddef.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/stdint.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/stdio.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/stdlib.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/stdnoreturn.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/string.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/strings.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/stropts.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/ioctl.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/ipc.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/mman.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/msg.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/poll.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/resource.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/select.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/sem.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/shm.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/socket.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/stat.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/statvfs.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/sysctl.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/time.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/times.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/types.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/uio.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/un.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/utsname.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/sys/wait.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/syslog.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/tar.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/termios.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/tgmath.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/threads.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/time.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/trace.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/ulimit.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/unctrl.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/unistd.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/utime.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/utmp.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/utmpx.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/wchar.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/wctype.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/wordexp.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/xcb/xcb.h: -------------------------------------------------------------------------------- 1 | #include "_fake_defines.h" 2 | #include "_fake_typedefs.h" 3 | -------------------------------------------------------------------------------- /fake_libc_include/zlib.h: -------------------------------------------------------------------------------- 1 | #ifndef ZLIB_H 2 | #define ZLIB_H 3 | 4 | #include "_fake_defines.h" 5 | #include "_fake_typedefs.h" 6 | 7 | typedef int uInt; 8 | typedef int uLong; 9 | #if !defined(__MACTYPES__) 10 | typedef int Byte; 11 | #endif 12 | 13 | typedef int Bytef; 14 | typedef int charf; 15 | typedef int intf; 16 | typedef int uIntf; 17 | typedef int uLongf; 18 | 19 | typedef int voidpc; 20 | typedef int voidpf; 21 | typedef int voidp; 22 | 23 | #if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) 24 | typedef int Z_U4; 25 | #endif 26 | 27 | typedef int z_crc_t; 28 | typedef int z_size_t; 29 | 30 | typedef int alloc_func; 31 | typedef int free_func; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /patched-quickjs-ffi-Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-I../.. 2 | 3 | ffi: quickjs-ffi.c test-lib.c 4 | gcc $(CFLAGS) quickjs-ffi.c -o quickjs-ffi.so -ldl -lffi -shared -fPIC 5 | 6 | test1: test1.c 7 | gcc $(CFLAGS) test1.c -o test1 -lffi -ldl -fPIC 8 | ./test1 9 | 10 | fib: fib.c 11 | gcc $(CFLAGS) fib.c -o fib.so -shared -fPIC 12 | 13 | null: null.c 14 | gcc $(CFLAGS) null.c -o null1 15 | gcc $(CFLAGS) null.c -o null2 -fPIC 16 | -------------------------------------------------------------------------------- /qjs-cffi: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PYTHONPATH=local/quickjs-cffi/venv/lib/python3.9/site-packages/ python -B -u local/quickjs-cffi/autogen.py ${@:1} -------------------------------------------------------------------------------- /qjs-pkg: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PACKAGE_NAME="quickjs-cffi" 4 | PACKAGE_VER="0.1.0" 5 | 6 | function prepare () { 7 | # args 8 | local ENV_PATH=$1 9 | local CACHE_PACKAGE_PATH=$2 10 | local LOCAL_PACKAGE_PATH=$3 11 | 12 | # rm if existing 13 | local CACHE_QUICKJS_FFI_PATH=$ENV_PATH/$CACHE_PACKAGE_PATH/quickjs-ffi 14 | 15 | if [ -d $CACHE_QUICKJS_FFI_PATH ]; then 16 | rm -rf CACHE_QUICKJS_FFI_PATH 17 | fi 18 | 19 | # clone 20 | git clone git@github.com:shajunxing/quickjs-ffi.git $CACHE_QUICKJS_FFI_PATH 21 | cp patched-quickjs-ffi-Makefile $CACHE_QUICKJS_FFI_PATH/Makefile 22 | echo prepare $PACKAGE_NAME $PACKAGE_VER 23 | } 24 | 25 | function build () { 26 | # args 27 | local ENV_PATH=$1 28 | local CACHE_PACKAGE_PATH=$2 29 | local LOCAL_PACKAGE_PATH=$3 30 | 31 | # setup python venv 32 | python -m venv venv 33 | source venv/bin/activate 34 | pip install -r requirements.txt 35 | deactivate 36 | 37 | # build quickjs-ffi 38 | local CACHE_QUICKJS_FFI_PATH=$ENV_PATH/$CACHE_PACKAGE_PATH/quickjs-ffi 39 | cd $CACHE_QUICKJS_FFI_PATH 40 | make 41 | 42 | echo build $PACKAGE_NAME $PACKAGE_VER 43 | } 44 | 45 | function install () { 46 | # args 47 | local ENV_PATH=$1 48 | local CACHE_PACKAGE_PATH=$2 49 | local LOCAL_PACKAGE_PATH=$3 50 | 51 | # copy python venv 52 | cp -r $ENV_PATH/$CACHE_PACKAGE_PATH/venv $ENV_PATH/$LOCAL_PACKAGE_PATH/venv 53 | cp -r $ENV_PATH/$CACHE_PACKAGE_PATH/fake_include $ENV_PATH/$LOCAL_PACKAGE_PATH/fake_include 54 | cp -r $ENV_PATH/$CACHE_PACKAGE_PATH/fake_libc_include $ENV_PATH/$LOCAL_PACKAGE_PATH/fake_libc_include 55 | cp $ENV_PATH/$CACHE_PACKAGE_PATH/autogen.py $ENV_PATH/$LOCAL_PACKAGE_PATH/autogen.py 56 | 57 | # copy quickjs-ffi.js and quickjs-ffi.so 58 | local CACHE_QUICKJS_FFI_PATH=$ENV_PATH/$CACHE_PACKAGE_PATH/quickjs-ffi 59 | cp $CACHE_QUICKJS_FFI_PATH/quickjs-ffi.js $ENV_PATH/$LOCAL_PACKAGE_PATH/quickjs-ffi.js 60 | cp $CACHE_QUICKJS_FFI_PATH/quickjs-ffi.so $ENV_PATH/$LOCAL_PACKAGE_PATH/quickjs-ffi.so 61 | cp $ENV_PATH/$CACHE_PACKAGE_PATH/qjs-cffi $ENV_PATH/qjs-cffi 62 | 63 | echo install $PACKAGE_NAME $PACKAGE_VER 64 | } 65 | 66 | function uninstall () { 67 | # args 68 | local ENV_PATH=$1 69 | local CACHE_PACKAGE_PATH=$2 70 | local LOCAL_PACKAGE_PATH=$3 71 | 72 | # custom uninstall commands 73 | rm -f $ENV_PATH/qjs-cffi 74 | 75 | echo uninstall $PACKAGE_NAME $PACKAGE_VER 76 | } 77 | 78 | # dispatch function with args without $0 and $1 79 | echo $($1 ${@:2}) 80 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pycparser --------------------------------------------------------------------------------