FFI: Set up tests

This commit is contained in:
Bretton 2022-08-02 19:31:33 -07:00
parent e4880c979d
commit 7294acc805
6 changed files with 41 additions and 0 deletions

2
tests/.gitignore vendored
View File

@ -1 +1,3 @@
output
*.so
*.dylib

28
tests/ffi/Makefile Normal file
View File

@ -0,0 +1,28 @@
CFLAGS += -Wall -Werror
# For each C file foo.c, we make a phony target foo, then depending on the OS
# map that to either foo.dylib or foo.so.
CFILES = $(wildcard *.c)
TARGETS = $(CFILES:.c=)
all: $(TARGETS)
.PHONY: all clean $(TARGETS)
ifeq ($(shell uname),Darwin)
EXT = .dylib
else
EXT = .so
endif
$(TARGETS): %: %$(EXT)
%.dylib: %.c
$(CC) $(CFLAGS) -dynamiclib $< -o $@
%.so: %.c
$(CC) $(CFLAGS) -fPIC -shared $< -o $@
clean:
rm *$(EXT)

3
tests/ffi/test-ffi.c Normal file
View File

@ -0,0 +1,3 @@
int add(int x, int y) {
return x + y;
}

1
tests/ffi/test-ffi.cry Normal file
View File

@ -0,0 +1 @@
foreign add : [32] -> [32] -> [32]

3
tests/ffi/test-ffi.icry Normal file
View File

@ -0,0 +1,3 @@
:! make -s test-ffi
:l test-ffi.cry
add 1 2

View File

@ -0,0 +1,4 @@
Loading module Cryptol
Loading module Cryptol
Loading module Main
0x00000003