compilation of bluespec sv

68 views Asked by At
`*function Bit#(2) haa(Bit#(1)a,Bit#(1)b);
let s=a^b;
let c=a&b;
return {s,c};
endfunction*`

This is my attempt to write a half adder in bsv, but when I try to compile it, it just ended in .bo without forming .v

This is copied from a lecture at mit, but i am not sure it work without package and module keyword. but that also not ended in right way. please help me to write a compilable bsv file based on this (also provide some good sources to study bsv step by step on actual coding).

1

There are 1 answers

2
thatbangaloreanguy On

The function looks correct. In order to generate Verilog out of this, you can either use a UniqueWrapper* or expose this function as a value method in the interface provided by a dummy module.

When I say dummy module, I mean something like this:

package dummy_wrapper;

interface Ifc_dummy_wrapper;
    method Bit#(2) mv_func(Bit#(1) a, Bit#(1) b);
endinterface: Ifc_dummy_wrapper

function Bit#(2) haa(Bit#(1)a,Bit#(1)b);
    let s=a^b;
    let c=a&b;
    return {s,c};
endfunction

module mk_dummy_wrapper(Ifc_dummy_wrapper);
    method Bit#(2) mv_func(Bit#(1) a, Bit#(1) b) = haa(a, b);
endmodule: mk_dummy_wrapper

endpackage: dummy_wrapper

You should now be able to instantiate this module in whatever place you want, and call that value method instead of that function.

Here's how you can compile a bsv file to generate Verilog:

bsc -u -verilog -vdir <verilog_dir> -bdir <build_dir> -info-dir <info_dir> [flags] -p <paths> -g <top_module> <top_file>

You can find the reference manuals and the user guides here: https://github.com/B-Lang-org/bsc/releases/tag/2023.07

You can find some example bluespec code and a nice little environment where you can simply plug your code, over here: https://github.com/rsnikhil/Bluespec_BSV_Tutorial