From 10ac321771a09a71f48c8a93cf9917c928d8316f Mon Sep 17 00:00:00 2001 From: Gavan Fantom Date: Sun, 29 Apr 2007 13:15:34 +0000 Subject: [PATCH] First cut of formal ABI definition, so that the same definition can be used to generate the function table in lsi as the header file which code can include to get a matching ABI definition. --- src/lsi/Makefile | 11 +++++++- src/lsi/abi.h | 40 +++++++++++++++++++++++++++ src/lsi/abispec | 39 +++++++++++++++++++++++++++ src/lsi/makeabi | 50 ++++++++++++++++++++++++++++++++++ src/lsi/vm.c | 70 +++--------------------------------------------- 5 files changed, 142 insertions(+), 68 deletions(-) create mode 100644 src/lsi/abi.h create mode 100644 src/lsi/abispec create mode 100755 src/lsi/makeabi diff --git a/src/lsi/Makefile b/src/lsi/Makefile index 9a82cc2..7e21f0e 100644 --- a/src/lsi/Makefile +++ b/src/lsi/Makefile @@ -5,6 +5,9 @@ PREFIX?= /usr/local OBJS= main.o vm.o plugins.o dmx.o midi.o beatdetect.o fft.o map3d.o mouse.o SRCS= main.c vm.c plugins.c dmx.c midi.c beatdetect.c fft.c map3d.c mouse.c +OBJS+= abi.o +SRCS+= abi.c + COMMONOBJS= mem.o hash.o COMMONDIR= ../common @@ -20,6 +23,12 @@ PROGOBJS= ${OBJS} ${COMMONOBJS:S/^/${COMMONDIR}\//} lsi: ${OBJS} ${LINK.c} -o ${.TARGET} ${PROGOBJS} ${LDLIBS} +abi.c: abispec makeabi + ./makeabi abispec + +abi.lh: abispec makeabi + ./makeabi abispec + install: lsi ${INSTALL} -d ${PREFIX}/bin ${INSTALL} -c lsi ${PREFIX}/bin/lsi @@ -28,4 +37,4 @@ depend: mkdep -- ${CFLAGS} ${CPPFLAGS} ${SRCS} clean: - rm -f ${OBJS} lsi + rm -f ${OBJS} lsi abi.c abi.lh diff --git a/src/lsi/abi.h b/src/lsi/abi.h new file mode 100644 index 0000000..b3759f4 --- /dev/null +++ b/src/lsi/abi.h @@ -0,0 +1,40 @@ +/* abi.h */ + +typedef int (*vm_intfn)(void); + +/* + * We must include here all prototypes for functions which can be + * included in the ABI function table + */ + +int vm_intfn_nop(void); +int vm_intfn_global_store(void); +int vm_intfn_global_load(void); +int vm_intfn_global_array_store(void); +int vm_intfn_global_array_load(void); +int vm_intfn_printint(void); +int vm_intfn_printreal(void); +int vm_intfn_printstr(void); +int vm_intfn_dmxsetchannel(void); +int vm_intfn_dmxoutput(void); +int vm_intfn_gettime(void); +int vm_intfn_waittime(void); +int vm_intfn_wait(void); +int vm_intfn_wakeup(void); +int vm_intfn_spawn(void); +int vm_intfn_midi_read(void); +int vm_intfn_beatdetect_read(void); +int vm_intfn_beatdetect_phase(void); +int vm_intfn_beatdetect_confidence(void); +int vm_intfn_realtoint(void); +int vm_intfn_inttoreal(void); +int vm_intfn_map3d_setcal(void); +int vm_intfn_map3d_calibrate(void); +int vm_intfn_map3d_transform(void); +int vm_intfn_map3d_setparams(void); +int vm_intfn_map3d_load(void); +int vm_intfn_map3d_save(void); +int vm_intfn_sin(void); +int vm_intfn_cos(void); +int vm_intfn_random(void); +int vm_intfn_mouse_read(void); diff --git a/src/lsi/abispec b/src/lsi/abispec new file mode 100644 index 0000000..0d35714 --- /dev/null +++ b/src/lsi/abispec @@ -0,0 +1,39 @@ +/* This should be a master file specifying all aspects of ABI */ + +/* Function assignments */ + +function nop +function global_store +function global_load +function global_array_store +function global_array_load +function printint +function printreal +function printstr +function dmxsetchannel +function dmxoutput +function gettime +function waittime +function wait +function wakeup +function spawn +function midi_read +function beatdetect_read +function beatdetect_phase +function beatdetect_confidence +funciton realtoint +function inttoreal +function map3d_setcal +function map3d_calibrate +function map3d_transform +function map3d_setparams +function map3d_load +function map3d_save +function sin +function cos +function random +function mouse_read + +/* + * The ABI should be identified by a SHA1 hash of this file + */ diff --git a/src/lsi/makeabi b/src/lsi/makeabi new file mode 100755 index 0000000..78322bd --- /dev/null +++ b/src/lsi/makeabi @@ -0,0 +1,50 @@ +#!/bin/sh + +INFILE=$1 + +if [ "X${INFILE}" = "X" ] +then + echo "Usage: $0 abispec" + exit 1 +fi + +ABI=abi.c +HEADER=abi.lh + +FNCOUNT=0 + +do_function() +{ + echo " vm_intfn_${ARG1}," >>${ABI} + echo "fndefint ${ARG1} ${FNCOUNT};" >>${HEADER} + FNCOUNT=$((${FNCOUNT}+1)) +} + +cat <${ABI} +/* abi.c */ +/* autogenerated - do not edit */ + +#include "abi.h" + +vm_intfn vm_intfn_table[] = { +EOF + +cat <${HEADER} +/* abi.lh */ +/* autogenerated - do not edit */ + +EOF + +while read TYPE ARG1 ARG2 +do + case "$TYPE" in + function) do_function + ;; + esac +done <${INFILE} + +cat <>${ABI} +}; + +const int vm_intfn_size = sizeof(vm_intfn_table) / sizeof(vm_intfn); +EOF diff --git a/src/lsi/vm.c b/src/lsi/vm.c index 5651695..1762158 100644 --- a/src/lsi/vm.c +++ b/src/lsi/vm.c @@ -67,78 +67,14 @@ struct hashentry *arrayhash[HASHSIZE]; #define GLOB_MAXNAMELEN 1024 -int vm_intfn_nop(void); -int vm_intfn_global_store(void); -int vm_intfn_global_load(void); -int vm_intfn_global_array_store(void); -int vm_intfn_global_array_load(void); -int vm_intfn_printint(void); -int vm_intfn_printreal(void); -int vm_intfn_printstr(void); -int vm_intfn_dmxsetchannel(void); -int vm_intfn_dmxoutput(void); -int vm_intfn_gettime(void); -int vm_intfn_waittime(void); -int vm_intfn_wait(void); -int vm_intfn_wakeup(void); -int vm_intfn_spawn(void); -int vm_intfn_midi_read(void); -int vm_intfn_beatdetect_read(void); -int vm_intfn_beatdetect_phase(void); -int vm_intfn_beatdetect_confidence(void); -int vm_intfn_realtoint(void); -int vm_intfn_inttoreal(void); -int vm_intfn_map3d_setcal(void); -int vm_intfn_map3d_calibrate(void); -int vm_intfn_map3d_transform(void); -int vm_intfn_map3d_setparams(void); -int vm_intfn_map3d_load(void); -int vm_intfn_map3d_save(void); -int vm_intfn_sin(void); -int vm_intfn_cos(void); -int vm_intfn_random(void); -int vm_intfn_mouse_read(void); void vm_destroy(struct vm_thread *); void vm_unqueue(struct vm_thread *); void vm_queue(struct vm_thread *, int); -typedef int (*vm_intfn)(void); - -vm_intfn vm_intfn_table[] = { - vm_intfn_nop, - vm_intfn_global_store, - vm_intfn_global_load, - vm_intfn_global_array_store, - vm_intfn_global_array_load, - vm_intfn_printint, - vm_intfn_printreal, - vm_intfn_printstr, - vm_intfn_dmxsetchannel, - vm_intfn_dmxoutput, - vm_intfn_gettime, - vm_intfn_waittime, - vm_intfn_wait, - vm_intfn_wakeup, - vm_intfn_spawn, - vm_intfn_midi_read, - vm_intfn_beatdetect_read, - vm_intfn_beatdetect_phase, - vm_intfn_beatdetect_confidence, - vm_intfn_realtoint, - vm_intfn_inttoreal, - vm_intfn_map3d_setcal, - vm_intfn_map3d_calibrate, - vm_intfn_map3d_transform, - vm_intfn_map3d_setparams, - vm_intfn_map3d_load, - vm_intfn_map3d_save, - vm_intfn_sin, - vm_intfn_cos, - vm_intfn_random, - vm_intfn_mouse_read, -}; +#include "abi.h" -const int vm_intfn_size = sizeof(vm_intfn_table) / sizeof(vm_intfn); +extern vm_intfn vm_intfn_table[]; +extern const int vm_intfn_size; void stack_push(struct vm_thread *thread, stkentry e); void stack_pop(struct vm_thread *thread, int count);