mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-08 07:34:07 +00:00
FFI: Add C declaration parser.
This commit is contained in:
parent
526e087e63
commit
233076d3f9
@ -327,7 +327,7 @@ LJCORE_O= lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o \
|
|||||||
lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \
|
lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \
|
||||||
lj_opt_dce.o lj_opt_loop.o \
|
lj_opt_dce.o lj_opt_loop.o \
|
||||||
lj_mcode.o lj_snap.o lj_record.o lj_asm.o lj_trace.o lj_gdbjit.o \
|
lj_mcode.o lj_snap.o lj_record.o lj_asm.o lj_trace.o lj_gdbjit.o \
|
||||||
lj_ctype.o lj_cdata.o lj_cconv.o \
|
lj_ctype.o lj_cdata.o lj_cconv.o lj_cparse.o \
|
||||||
lj_lib.o lj_alloc.o lib_aux.o \
|
lj_lib.o lj_alloc.o lib_aux.o \
|
||||||
$(LJLIB_O) lib_init.o
|
$(LJLIB_O) lib_init.o
|
||||||
|
|
||||||
|
@ -57,6 +57,9 @@ lj_cconv.o: lj_cconv.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
|||||||
lj_cdata.o: lj_cdata.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
lj_cdata.o: lj_cdata.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
||||||
lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_ctype.h lj_cconv.h lj_cdata.h
|
lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_ctype.h lj_cconv.h lj_cdata.h
|
||||||
lj_char.o: lj_char.c lj_char.h lj_def.h lua.h luaconf.h
|
lj_char.o: lj_char.c lj_char.h lj_def.h lua.h luaconf.h
|
||||||
|
lj_cparse.o: lj_cparse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
||||||
|
lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_ctype.h lj_cparse.h lj_frame.h \
|
||||||
|
lj_bc.h lj_vm.h lj_char.h
|
||||||
lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
||||||
lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h
|
lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h
|
||||||
lj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
lj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
||||||
@ -139,11 +142,11 @@ ljamalg.o: ljamalg.c lua.h luaconf.h lauxlib.h lj_gc.c lj_obj.h lj_def.h \
|
|||||||
lj_func.c lj_udata.c lj_meta.c lj_state.c lj_lex.h lj_alloc.h \
|
lj_func.c lj_udata.c lj_meta.c lj_state.c lj_lex.h lj_alloc.h \
|
||||||
lj_dispatch.c lj_ff.h lj_ffdef.h luajit.h lj_vmevent.c lj_vmevent.h \
|
lj_dispatch.c lj_ff.h lj_ffdef.h luajit.h lj_vmevent.c lj_vmevent.h \
|
||||||
lj_api.c lj_parse.h lj_lex.c lj_parse.c lj_ctype.c lj_cdata.c lj_cconv.h \
|
lj_api.c lj_parse.h lj_lex.c lj_parse.c lj_ctype.c lj_cdata.c lj_cconv.h \
|
||||||
lj_cconv.c lj_lib.c lj_lib.h lj_ir.c lj_iropt.h lj_opt_mem.c \
|
lj_cconv.c lj_cparse.c lj_cparse.h lj_lib.c lj_lib.h lj_ir.c lj_iropt.h \
|
||||||
lj_opt_fold.c lj_folddef.h lj_opt_narrow.c lj_opt_dce.c lj_opt_loop.c \
|
lj_opt_mem.c lj_opt_fold.c lj_folddef.h lj_opt_narrow.c lj_opt_dce.c \
|
||||||
lj_snap.h lj_mcode.c lj_mcode.h lj_snap.c lj_target.h lj_target_*.h \
|
lj_opt_loop.c lj_snap.h lj_mcode.c lj_mcode.h lj_snap.c lj_target.h \
|
||||||
lj_record.c lj_record.h lj_asm.h lj_recdef.h lj_asm.c lj_trace.c \
|
lj_target_*.h lj_record.c lj_record.h lj_asm.h lj_recdef.h lj_asm.c \
|
||||||
lj_gdbjit.h lj_gdbjit.c lj_alloc.c lib_aux.c lib_base.c lualib.h \
|
lj_trace.c lj_gdbjit.h lj_gdbjit.c lj_alloc.c lib_aux.c lib_base.c \
|
||||||
lj_libdef.h lib_math.c lib_string.c lib_table.c lib_io.c lib_os.c \
|
lualib.h lj_libdef.h lib_math.c lib_string.c lib_table.c lib_io.c \
|
||||||
lib_package.c lib_debug.c lib_bit.c lib_jit.c lib_init.c
|
lib_os.c lib_package.c lib_debug.c lib_bit.c lib_jit.c lib_init.c
|
||||||
luajit.o: luajit.c lua.h luaconf.h lauxlib.h lualib.h luajit.h lj_arch.h
|
luajit.o: luajit.c lua.h luaconf.h lauxlib.h lualib.h luajit.h lj_arch.h
|
||||||
|
1802
src/lj_cparse.c
Normal file
1802
src/lj_cparse.c
Normal file
File diff suppressed because it is too large
Load Diff
63
src/lj_cparse.h
Normal file
63
src/lj_cparse.h
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
** C declaration parser.
|
||||||
|
** Copyright (C) 2005-2010 Mike Pall. See Copyright Notice in luajit.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _LJ_CPARSE_H
|
||||||
|
#define _LJ_CPARSE_H
|
||||||
|
|
||||||
|
#include "lj_obj.h"
|
||||||
|
#include "lj_ctype.h"
|
||||||
|
|
||||||
|
#if LJ_HASFFI
|
||||||
|
|
||||||
|
/* C parser limits. */
|
||||||
|
#define CPARSE_MAX_BUF 32768 /* Max. token buffer size. */
|
||||||
|
#define CPARSE_MAX_DECLSTACK 100 /* Max. declaration stack depth. */
|
||||||
|
#define CPARSE_MAX_DECLDEPTH 20 /* Max. recursive declaration depth. */
|
||||||
|
#define CPARSE_MAX_PACKSTACK 7 /* Max. pack pragma stack depth. */
|
||||||
|
|
||||||
|
/* Flags for C parser mode. */
|
||||||
|
#define CPARSE_MODE_MULTI 1 /* Process multiple declarations. */
|
||||||
|
#define CPARSE_MODE_ABSTRACT 2 /* Accept abstract declarators. */
|
||||||
|
#define CPARSE_MODE_DIRECT 4 /* Accept direct declarators. */
|
||||||
|
#define CPARSE_MODE_FIELD 8 /* Accept field width in bits, too. */
|
||||||
|
#define CPARSE_MODE_NOIMPLICIT 16 /* Reject implicit declarations. */
|
||||||
|
|
||||||
|
typedef int CPChar; /* C parser character. Unsigned ext. from char. */
|
||||||
|
typedef int CPToken; /* C parser token. */
|
||||||
|
|
||||||
|
/* C parser internal value representation. */
|
||||||
|
typedef struct CPValue {
|
||||||
|
union {
|
||||||
|
int32_t i32; /* Value for CTID_INT32. */
|
||||||
|
uint32_t u32; /* Value for CTID_UINT32. */
|
||||||
|
};
|
||||||
|
CTypeID id; /* C Type ID of the value. */
|
||||||
|
} CPValue;
|
||||||
|
|
||||||
|
/* C parser state. */
|
||||||
|
typedef struct CPState {
|
||||||
|
CPChar c; /* Current character. */
|
||||||
|
CPToken tok; /* Current token. */
|
||||||
|
CPValue val; /* Token value. */
|
||||||
|
GCstr *str; /* Interned string of identifier/keyword. */
|
||||||
|
CType *ct; /* C type table entry. */
|
||||||
|
const char *p; /* Current position in input buffer. */
|
||||||
|
SBuf sb; /* String buffer for tokens. */
|
||||||
|
lua_State *L; /* Lua state. */
|
||||||
|
CTState *cts; /* C type state. */
|
||||||
|
const char *srcname; /* Current source name. */
|
||||||
|
BCLine linenumber; /* Input line counter. */
|
||||||
|
int depth; /* Recursive declaration depth. */
|
||||||
|
uint32_t tmask; /* Type mask for next identifier. */
|
||||||
|
uint32_t mode; /* C parser mode. */
|
||||||
|
uint8_t packstack[CPARSE_MAX_PACKSTACK]; /* Stack for pack pragmas. */
|
||||||
|
uint8_t curpack; /* Current position in pack pragma stack. */
|
||||||
|
} CPState;
|
||||||
|
|
||||||
|
LJ_FUNC int lj_cparse(CPState *cp);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -43,6 +43,7 @@
|
|||||||
#include "lj_ctype.c"
|
#include "lj_ctype.c"
|
||||||
#include "lj_cdata.c"
|
#include "lj_cdata.c"
|
||||||
#include "lj_cconv.c"
|
#include "lj_cconv.c"
|
||||||
|
#include "lj_cparse.c"
|
||||||
#include "lj_lib.c"
|
#include "lj_lib.c"
|
||||||
#include "lj_ir.c"
|
#include "lj_ir.c"
|
||||||
#include "lj_opt_mem.c"
|
#include "lj_opt_mem.c"
|
||||||
|
Loading…
Reference in New Issue
Block a user