[ktap] [PATCH 0/8] FFI support for ktap

  • From: Yicheng Qin <qycqycqycqycqyc@xxxxxxxxx>
  • To: ktap@xxxxxxxxxxxxx
  • Date: Tue, 26 Nov 2013 14:52:28 -0500

This patch set implements basic FFI support for ktap.

A brief overview of current design:
* user define needed C symbols in ktap script (functions, structs, etc)
* C symbols get compiled through cparser into chunk and passed into
ktap vm
* ktap vm generates ktap_cdata according to symbol information from
chunks
* when ktap script calls "C.foo()", ktap vm detects that it's a FFI
function, and does following:
  - sets up the hardware stack
  - calls into the C function
  - put back return value to ktap stack
* continue executing next instructions

Implementation of cparser is under userspace/ffi/, which currenly
supports parsing functions, structs and typedef.

Implementation of function call module is under interpreter/ffi/,
including argument check, type conversion, stack setup and return value
handling.

Support:
- x86_64 machine
- (u)char, (u)short, (u)int, (u)long, (u)longlong, void and pointer type
- 'cdef' keyword used to define external C functions
- implicit type conversion between ctypes and ktap types

Test:
```
New test script is under test/ffi/
```

Plan:
https://github.com/ktap/ktap/wiki/FFI-Support

Signed-off-by: Yicheng Qin <qycqycqycqycqyc@xxxxxxxxx>
Signed-off-by: Qingping Hou <qingping.hou@xxxxxxxxx>


Yicheng Qin (8):
  Introduce ffi_type, csymbol and ktap_cdata
  Cparser to parse C declareation
  Integrate cparser into ktap compiler
  Introduce ffi call module in vm
  Integrate ffi call module into vm
  Modify gitignore setting to submit .s file
  Modify makefile to build ffi module
  Add ffi test cases and script

 .gitignore                    |    1 -
 Makefile                      |   29 +
 include/ktap_types.h          |   22 +-
 interpreter/ffi/call_x86_64.S |  139 +++
 interpreter/ffi/cdata.c       |   68 ++
 interpreter/ffi/ffi_call.c    |  361 ++++++++
 interpreter/ffi/ffi_symbol.c  |  143 ++++
 interpreter/ffi/ffi_type.c    |   50 ++
 interpreter/ffi/ffi_util.c    |   93 ++
 interpreter/kp_ffi.h          |  258 ++++++
 interpreter/kp_load.c         |   80 +-
 interpreter/kp_obj.c          |    6 +
 interpreter/kp_tab.c          |    2 +-
 interpreter/kp_vm.c           |   35 +-
 interpreter/ktap.h            |    9 +
 interpreter/lib_ffi.c         |   62 ++
 test/ffi/Makefile             |   48 ++
 test/ffi/cparser_test.c       |  304 +++++++
 test/ffi/current.kp           |    2 +
 test/ffi/funct.c              |   40 +
 test/ffi/halt.kp              |    3 +
 test/ffi/kfunct.kp            |    8 +
 test/ffi/ufunct.kp            |   24 +
 test/run_test.sh              |    2 +
 userspace/cparser.h           |  188 ++++
 userspace/dump.c              |   61 ++
 userspace/ffi/cparser.c       | 1894 +++++++++++++++++++++++++++++++++++++++++
 userspace/ffi/ctype.c         |  536 ++++++++++++
 userspace/ktapc.h             |   14 +
 userspace/lex.c               |    8 +-
 userspace/main.c              |    4 +
 userspace/parser.c            |   49 +-
 userspace/util.c              |    1 -
 33 files changed, 4531 insertions(+), 13 deletions(-)
 create mode 100644 interpreter/ffi/call_x86_64.S
 create mode 100644 interpreter/ffi/cdata.c
 create mode 100644 interpreter/ffi/ffi_call.c
 create mode 100644 interpreter/ffi/ffi_symbol.c
 create mode 100644 interpreter/ffi/ffi_type.c
 create mode 100644 interpreter/ffi/ffi_util.c
 create mode 100644 interpreter/kp_ffi.h
 create mode 100644 interpreter/lib_ffi.c
 create mode 100644 test/ffi/Makefile
 create mode 100644 test/ffi/cparser_test.c
 create mode 100644 test/ffi/current.kp
 create mode 100644 test/ffi/funct.c
 create mode 100644 test/ffi/halt.kp
 create mode 100644 test/ffi/kfunct.kp
 create mode 100644 test/ffi/ufunct.kp
 create mode 100644 userspace/cparser.h
 create mode 100644 userspace/ffi/cparser.c
 create mode 100644 userspace/ffi/ctype.c

-- 
1.8.3.4 (Apple Git-47)


Other related posts:

  • » [ktap] [PATCH 0/8] FFI support for ktap - Yicheng Qin