Summary: The program works normally when calling external functions in FUNCTION format and returns error while in PROCEDURE format.
The program below is working:
------------- t.vhdl-------------------
package math is
function fxch(x: integer) return integer;
attribute foreign of fxch : function is "VHPIDIRECT fxch";
end math;
package body math is
function fxch(x: integer) return integer is
begin
assert false severity failure;
end fxch;
end math;
function fxch(x: integer) return integer;
attribute foreign of fxch : function is "VHPIDIRECT fxch";
end math;
package body math is
function fxch(x: integer) return integer is
begin
assert false severity failure;
end fxch;
end math;
-- Hello world program.
use std.textio.all; -- Imports the standard textio package.
use work.math.all;
use std.textio.all; -- Imports the standard textio package.
use work.math.all;
-- Defines a design entity, without any ports.
entity hello_world is
end hello_world;
entity hello_world is
end hello_world;
architecture behaviour of hello_world is
begin
process
variable x: integer;
begin
x := fxch(1);
wait;
end process;
end behaviour;
begin
process
variable x: integer;
begin
x := fxch(1);
wait;
end process;
end behaviour;
--------------------------------------------------------------------------
---------------- fxch.c ------------------------
#include <stdio.h>
int fxch(int x)
{
printf("hi\n");
return 0;
}
int fxch(int x)
{
printf("hi\n");
return 0;
}
-------------------------------------------
------- terminal ----------------------------------
------- terminal ----------------------------------
$ gcc -c fxch.c
$ ghdl -a t.vhdl
$ ghdl -e -Wl,fxch.o hello_world
$ ./hello_world
hi
$
-------------------------------------------------
This code above uses FUNCTION, however when I use PROCEDURE something goes wrong, see below:
------------- t2.vhdl-------------------
package math is
procedure fxch;
attribute foreign of fxch : procedure is "VHPIDIRECT fxch";
end math;
package body math is
procedure fxch is
begin
assert false severity failure;
end fxch;
end math;
procedure fxch;
attribute foreign of fxch : procedure is "VHPIDIRECT fxch";
end math;
package body math is
procedure fxch is
begin
assert false severity failure;
end fxch;
end math;
-- Hello world program.
use std.textio.all; -- Imports the standard textio package.
use work.math.all;
use std.textio.all; -- Imports the standard textio package.
use work.math.all;
-- Defines a design entity, without any ports.
entity hello_world is
end hello_world;
entity hello_world is
end hello_world;
architecture behaviour of hello_world is
begin
process
begin
fxch;
wait;
end process;
end behaviour;
begin
process
begin
fxch;
wait;
end process;
end behaviour;
-------------------------------------------------
------- fxch2.c -------------
#include <stdio.h>
void fxch()
{
printf("hi\n");
}
void fxch()
{
printf("hi\n");
}
------------------
--------- terminal -------------
$ gcc -c fxch2.c
$ ghdl -a t2.vhdl
******************** GHDL Bug occured ****************************
Please report this bug on http://gna.org/projects/ghdl
GHDL release: GHDL 0.33 (20150921) [Dunoon edition]
Compiled with GNAT Version: 4.9.2
In directory: /home/pi/
Command line:
/usr/local/bin/ghdl1-llvm -P/usr/local/lib/ghdl/v93/std/ -P/usr/local/lib/ghdl/v93/ieee/ -c -o t2.o t2.vhdl
Exception CONSTRAINT_ERROR raised
Exception information:
Exception name: CONSTRAINT_ERROR
Message: ortho_llvm.adb:2911 access check failed
******************************************************************
ghdl: compilation error
Please report this bug on http://gna.org/projects/ghdl
GHDL release: GHDL 0.33 (20150921) [Dunoon edition]
Compiled with GNAT Version: 4.9.2
In directory: /home/pi/
Command line:
/usr/local/bin/ghdl1-llvm -P/usr/local/lib/ghdl/v93/std/ -P/usr/local/lib/ghdl/v93/ieee/ -c -o t2.o t2.vhdl
Exception CONSTRAINT_ERROR raised
Exception information:
Exception name: CONSTRAINT_ERROR
Message: ortho_llvm.adb:2911 access check failed
******************************************************************
ghdl: compilation error
-------------------------------------------------------------
My system is:
$ uname -a
Linux raspberrypi 4.4.9-v7+ #884 SMP Fri May 6 17:28:59 BST 2016 armv7l GNU/Linux
Linux raspberrypi 4.4.9-v7+ #884 SMP Fri May 6 17:28:59 BST 2016 armv7l GNU/Linux
My ghdl was compiled as follow:
./configure --prefix=/usr/local --with-llvm=/usr
make
make install
_______________________________________________ Ghdl-discuss mailing list Ghdl-discuss@gna.org https://mail.gna.org/listinfo/ghdl-discuss