ghdl-cosim
ghdl-cosim copied to clipboard
Header file for VHPIDIRECT/C and demo
This issue is to discuss the implementation of a header file ghdl.h
that provides an API to (de)code/convert GHDL's non-trivial data types. Precisely, to update https://ghdl.github.io/ghdl-cosim/vhpidirect/declarations.html by providing an easy-to-use solution for the types that are currently considered too difficult.
WIP: https://github.com/umarcor/ghdl-cosim/blob/header/vhpidirect/ghdl.h
Refs:
- ghdl/ghdl#1059
- umarcor/ghdl-cosim#1
- ghdl/ghdl#1053
- ghdl/ghdl#1052
- ghdl/ghdl#803
- VUnit/vunit#603
- SpinalHDL/SpinalHDL#146
- http://www.eda-twiki.org/cgi-bin/view.cgi/P1076/DpiProposal
This issue is directly related to #2, because the functions provided in ghdl.h
need to be accesible to foreign languages that load simulation models dynamically (as in VUnit/vunit#568). Hence, a *.ver
script needs to be provided along with ghdl.h
.
/cc @RocketRoss @bradleyharden
- [x] Most non-composite types (
character
/char
,integer
/int32_t
,natural
/uint32_t
,positive
/uint32_t
,real
/double
,boolean
/bool
,bit
/bool
,time
/int64_t
, shortenum
/uint8_t
) - [x] Record/struct
- [ ] Arrays with static bounds (note: we have found no issues with these so far)
- [ ] Unconstrained arrays
- [x] Strings
- [ ] With dimensions of type natural.
- [ ] Accesses to unconstrained arrays
- [x] Strings (i.e.
line
) - [ ] With dimensions of type natural.
- [x] Strings (i.e.
- [ ] Other accesses.
- [ ] Files
As expected, handling unconstrained arrays is neither straightforward nor intuitive. Hence, the main purpose of the demo is to make it easier for new users to use these. The following helper functions are provided:
-
char* ghdlToString(ghdl_NaturalDimArr_t* ptr)
: convert a fat pointer of an unconstrained string, to a (null terminated) C string -
void ghdlToArray(ghdl_NaturalDimArr_t* ptr, void** vec, int* len, int num)
: convert a fat pointer of an uncontrained array with (up to 3) dimensions of type 'natural', to C types -
ghdl_NaturalDimArr_t ghdlFromString(char *string)
: convert a (null terminated) C string, to a fat pointer of an unconstrained string -
ghdl_NaturalDimArr_t ghdlFromArray(void* vec, int* len, int num)
: convert C types representing an unconstrained array with a dimension of type 'natural', to a fat pointer (not complete yet -
char* ghdlAccToString(ghdl_AccNaturalDimArr_t *line)
: convert an access to an unconstrained string, to a (null terminated) C string -
void ghdlAccToArray(ghdl_AccNaturalDimArr_t* ptr, void** vec, int* len, int num)
: convert an access to an unconstrained array with a dimension of type 'natural', to C types (not implemented yet) -
ghdl_AccNaturalDimArr_t* ghdlAccFromArray(uint32_t length, size_t bytes)
: convert C types representing an unconstrained array with a dimension of type 'natural', to an access -
ghdl_AccNaturalDimArr_t* ghdlAccFromString(char *string)
: convert a (null terminated) C string, to an access to an unconstrained string
@RocketRoss, can you rebase/rework umarcor/ghdl#1 on top of https://github.com/umarcor/ghdl-cosim/tree/header?
Im on it
umarcor/ghdl-cosim/pull/3
Is that clean enough?
Ref https://github.com/umarcor/ghdl-cosim/pull/17#issuecomment-627854180