diff --git a/.travis.yml b/.travis.yml index ce0ff20694..f459135156 100644 --- a/.travis.yml +++ b/.travis.yml @@ -59,7 +59,7 @@ matrix: - mkdir -p ghdl/build-llvm - curl -fsSL https://codeload.github.com/ghdl/ghdl/tar.gz/master | tar xzf - -C ghdl --strip-components=1 - cd ghdl/build-llvm - - ../configure --prefix=../../install-ghdl-llvm/ --with-llvm-config=llvm-config-3.5 + - ../configure --default-pic --prefix=../../install-ghdl-llvm/ --with-llvm-config=llvm-config-3.5 - make - make install - cd ../../ diff --git a/examples/vhdl/external_buffer/run.py b/examples/vhdl/external_buffer/run.py new file mode 100644 index 0000000000..84cca6a2b2 --- /dev/null +++ b/examples/vhdl/external_buffer/run.py @@ -0,0 +1,31 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this file, +# You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Copyright (c) 2014-2019, Lars Asplund lars.anders.asplund@gmail.com + + +from vunit import VUnit +from sys import argv +from os import popen +from os.path import join, dirname + + +src_path = join(dirname(__file__), "src") + +ui = VUnit.from_argv(vhdl_standard="2008", external=[True]) + +lib = ui.add_library("lib") +lib.add_source_files(join(src_path, "test", "*.vhd")) + +c_obj = join(src_path, 'test', 'main.o') + +print(popen(' '.join([ + 'gcc -fPIC -rdynamic', + '-c', join(src_path, '**', 'main.c'), + '-o', c_obj +])).read()) + +ui.set_sim_option("ghdl.elab_flags", ['-Wl,' + c_obj]) + +ui.main() diff --git a/examples/vhdl/external_buffer/src/grt.ver b/examples/vhdl/external_buffer/src/grt.ver new file mode 100644 index 0000000000..58d63945cd --- /dev/null +++ b/examples/vhdl/external_buffer/src/grt.ver @@ -0,0 +1,15 @@ +VHPI { + global: +main; +read_char; +write_char; +read_integer; +write_integer; +set_string_ptr; +get_string_ptr; +set_intvec_ptr; +get_intvec_ptr; + local: + *; +}; + diff --git a/examples/vhdl/external_buffer/src/test/main.c b/examples/vhdl/external_buffer/src/test/main.c new file mode 100644 index 0000000000..5592b884f2 --- /dev/null +++ b/examples/vhdl/external_buffer/src/test/main.c @@ -0,0 +1,71 @@ +#include +#include +#include +#include + +extern int ghdl_main (int argc, char **argv); + +uint8_t *D[1]; +char is_allocated[1] = {0}; +const uint32_t length = 5; + +void set_string_ptr(uint8_t id, uint8_t *p) { + //printf("C set_string_ptr(%d, %p)\n", id, p); + D[id] = p; + is_allocated[id] = 1; +} + +uintptr_t get_string_ptr(uint8_t id) { + //printf("C get_string_ptr(%d): %p\n", id, D[id]); + return (uintptr_t)D[id]; +} + +void write_char(uint8_t id, uint32_t i, uint8_t v ) { + //printf("C write_char(%d, %d): %d\n", id, i, v); + D[id][i] = v; +} + +uint8_t read_char(uint8_t id, uint32_t i) { + //printf("C read_char(%d, %d): %d\n", id, i, D[id][i]); + return D[id][i]; +} + +void sigabrtHandler(int sig_num) +{ + /* Reset handler to catch SIGINT next time. Refer http://en.cppreference.com/w/c/program/signal */ + signal(SIGABRT, sigabrtHandler); + printf("\nSIGABRT caught!\n"); + fflush(stdout); +} + +static void exit_handler(void) { + if (is_allocated[0] == 0) { + int i; + for(i=0; i<3*length; i++) { + printf("%d: %d\n", i, D[0][i]); + } + free(D[0]); + } +} + +int main(int argc, char **argv) { + if (is_allocated[0] == 0) { + D[0] = (uint8_t *) malloc(3*length*sizeof(uint8_t)); + if ( D[0] == NULL ) { + perror("execution of malloc() failed!\n"); + return -1; + } + int i; + for(i=0; i