diff options
Diffstat (limited to 'bruiser/hs')
-rw-r--r-- | bruiser/hs/.depend | 0 | ||||
-rw-r--r-- | bruiser/hs/Safe.hs | 9 | ||||
-rw-r--r-- | bruiser/hs/Safe_stub.h | 9 | ||||
-rw-r--r-- | bruiser/hs/bruiserhs.c | 45 | ||||
-rw-r--r-- | bruiser/hs/bruiserhs.h | 0 | ||||
-rw-r--r-- | bruiser/hs/makefile | 37 | ||||
-rwxr-xr-x | bruiser/hs/run.sh | 6 |
7 files changed, 106 insertions, 0 deletions
diff --git a/bruiser/hs/.depend b/bruiser/hs/.depend new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/bruiser/hs/.depend diff --git a/bruiser/hs/Safe.hs b/bruiser/hs/Safe.hs new file mode 100644 index 0000000..8994e9e --- /dev/null +++ b/bruiser/hs/Safe.hs @@ -0,0 +1,9 @@ +{-#Language ForeignFunctionInterface#-} +module Safe where +import Foreign.C.Types +fibonacci :: Int -> Int +fibonacci n = fibs !! n + where fibs = 0 : 1: zipWith (+) fibs (tail fibs) +fibonacci_hs ::CInt -> CInt +fibonacci_hs = fromIntegral.fibonacci.fromIntegral +foreign export ccall fibonacci_hs::CInt->CInt diff --git a/bruiser/hs/Safe_stub.h b/bruiser/hs/Safe_stub.h new file mode 100644 index 0000000..3d939a1 --- /dev/null +++ b/bruiser/hs/Safe_stub.h @@ -0,0 +1,9 @@ +#include "HsFFI.h" +#ifdef __cplusplus +extern "C" { +#endif +extern HsInt32 fibonacci_hs(HsInt32 a1); +#ifdef __cplusplus +} +#endif + diff --git a/bruiser/hs/bruiserhs.c b/bruiser/hs/bruiserhs.c new file mode 100644 index 0000000..1ab34d8 --- /dev/null +++ b/bruiser/hs/bruiserhs.c @@ -0,0 +1,45 @@ + +/***************************************************Project Mutator****************************************************/ +/*first line intentionally left blank.*/ +/*bruiser's lua asmrewriter implementation for jump tables*/ +/*Copyright (C) 2018 Farzad Sadeghi + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/ +/**********************************************************************************************************************/ +#include <HsFFI.h> +#ifdef __GLASCOW_HASKELL__ +#include "Safe_stub.h" +extern void __stginit_Safe(void); +#endif +#include "bruiserhs.h" +#include <stdio.h> + +#pragma weak main +int main(int argc, char** argv) { + int i; + hs_init(&argc, &argv); +#ifdef __GLASCOW_HASKELL__ + hs_add_root(__stginit_Safe); +#endif + + i = fibonacci_hs(42); + printf("Fibonnaci:%d\n", i); + + hs_exit(); + return 0; +} +/**********************************************************************************************************************/ +/*last line intentionally left blank*/ + diff --git a/bruiser/hs/bruiserhs.h b/bruiser/hs/bruiserhs.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/bruiser/hs/bruiserhs.h diff --git a/bruiser/hs/makefile b/bruiser/hs/makefile new file mode 100644 index 0000000..8787dd4 --- /dev/null +++ b/bruiser/hs/makefile @@ -0,0 +1,37 @@ +TARGET=bruiserhs +CC=clang +CC?=clang +CC_FLAGS= +CC_EXTRA?= +CC_FLAGS+=$(CC_EXTRA) + +SRCS=$(wildcard *.c) + +.DEFAULT:all clean + +.PHONY:all clean help + +all:$(TARGET) + +depend:.depend + +.depend:$(SRCS) + rm -rf .depend + $(CC) -MM $(CC_FLAGS) $^ > ./.depend + +-include ./.depend + +.c.o: + $(CC) $(CC_FLAGS) -c $< -o $@ + +$(TARGET): $(TARGET).o + $(CC) $^ $(LD_FLAGS) -o $@ + +clean: + rm -f *.o *~ $(TARGET) + rm .depend + +help: + @echo "all is the default target" + @echo "there is delete." + @echo "there is clean." diff --git a/bruiser/hs/run.sh b/bruiser/hs/run.sh new file mode 100755 index 0000000..413b088 --- /dev/null +++ b/bruiser/hs/run.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +ghc -c -O Safe.hs +ghc --make -no-hs-main -optc-O bruiserhs.c Safe -o bruiserhs + +"./bruiserhs" |