Git Product home page Git Product logo

Comments (3)

hiyuh avatar hiyuh commented on August 25, 2024

on my foreign branch,

$ cat ext.c
#include <stdint.h>

int32_t ext_add_int32_t(int32_t l, int32_t r) { return l + r; }
int32_t ext_sub_int32_t(int32_t l, int32_t r) { return l - r; }
int32_t ext_mul_int32_t(int32_t l, int32_t r) { return l * r; }
int32_t ext_div_int32_t(int32_t l, int32_t r) { return l / r; }

double ext_add_double(double l, double r) { return l + r; }
double ext_sub_double(double l, double r) { return l - r; }
double ext_mul_double(double l, double r) { return l * r; }
double ext_div_double(double l, double r) { return l / r; }

$ cat ext.vhd
package ext is
        pure function ext_add(l : integer; r : integer) return integer;
        pure function ext_sub(l : integer; r : integer) return integer;
        pure function ext_mul(l : integer; r : integer) return integer;
        pure function ext_div(l : integer; r : integer) return integer;
        attribute foreign of ext_add : function is "ext_add_int32_t";
        attribute foreign of ext_sub : function is "ext_sub_int32_t";
        attribute foreign of ext_mul : function is "ext_mul_int32_t";
        attribute foreign of ext_div : function is "ext_div_int32_t";
end package ext;

use work.ext.all;

entity test is
begin
end entity test;

architecture a of test is
begin
        process
                constant w : integer range 1 to integer'high := 4;
        begin
                for l in 0 to 2**w-1 loop
                        for r in 0 to 2**w-1 loop
                                assert (ext_add(l, r) = l + r);
                                assert (ext_sub(l, r) = l - r);
                                assert (ext_mul(l, r) = l * r);
                                if (r /= 0) then
                                        assert (ext_div(l, r) = l / r);
                                end if;
                        end loop;
                end loop;
                wait;
        end process;
end architecture a;

$ NVC_LIBPATH=./lib/std:./lib/ieee:./lib/nvc NVC_CYG_LIB=./src ./src/nvc.exe -a ext.vhd

$ NVC_LIBPATH=./lib/std:./lib/ieee:./lib/nvc NVC_CYG_LIB=./src NVC_FOREIGN_OBJ=./ext.o ./src/nvc.exe -e --native test
/usr/bin/opt -O2 -o /home/hiyuh/git-repos/nvc/work/_WORK.TEST.final.bc /home/hiyuh/git-repos/nvc/work/_WORK.TEST.elab.bc
/usr/bin/llc -relocation-model=pic /home/hiyuh/git-repos/nvc/work/_WORK.TEST.final.bc
/usr/bin/gcc -shared -Wl,--export-all-symbols -Wl,--out-implib=/home/hiyuh/git-repos/nvc/work/_WORK.TEST.elab.a -o /home/hiyuh/git-repos/nvc/work/_WORK.TEST.final.so /home/hiyuh/git-repos/nvc/work/_WORK.TEST.final.s ./ext.o -L./src -lnvcimp

$ NVC_LIBPATH=./lib/std:./lib/ieee:./lib/nvc NVC_CYG_LIB=./src ./src/nvc.exe -r test
[no assertion faulure]

it looks ok to me, except NVC does not support signature in attribute_specification currently, which is required to handle attribute_specification properly for overloaded ones.

from nvc.

hiyuh avatar hiyuh commented on August 25, 2024

naming is improved.

from nvc.

nickg avatar nickg commented on August 25, 2024

I think this is fine for now: merged it.

In the future it would probably be best to have an option --load <so> to -r that loads shared libraries with user code. This is more similar to how Modelsim, etc. work and will work with JIT.

from nvc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.