2

I have been working with two programs llvm's opt and clifford wolf's yosys both have similar interfaces for passes.(they use shared libraries as optimization passes)

I want to use certain data structures and functions from yosys.h to build a design module(which is then written in verilog to file) based on the data generated by my llvm opt pass.

PROBLEM: I want to make use of functions,data from yosys.h in the pass for llvm-opt. How do i compile(EDIT: and also execute either on llvm-opt or on yosys or a seperate binary executable) such code? individually they can be compiled and executed as seperate passes.

COMPILE YOSYS PASS

gcc `yosys-config --cxxflags --ldlibs --ldflags` --shared yosyspass.cpp -o yosyspass.so

and execute it with

yosys -m yosyspass.so verilogfile.v

COMPILE LLVM PASS

gcc  `llvm-config --cxxflags --ldlibs` --shared llvmpass.ccp -o llvmpass.so

and execute it with

opt -load ./llvmpass.so -llvmpass Somefile.bc

but how to build code which has both components from llvm , yosys? and how to execute it?

How can i make this happen without changing source code of yosys too much? All of this is to avoid writing a verilog generation backend for my llvm-opt pass.

ONE OF MY SOLUTIONS:

Metaprogramming: i.e., generate the code which when compiled and run as a yosys pass gives me the result.(verilog design file based on llvm opt input)

Maybe i'm missing something fundamental in build shared libraries? I'm new to this sort of thing. any input is welcome.

This project(though unrelated) may be similar to Rotems C-to-Verilog and univ of toronto's legup HLS tool.

4

1 回答 1

2

正如 Krzysztof Kosiński 指出的那样,到目前为止,Yosys 核心功能还不能作为库使用。然而,这在待办事项列表上已经有很长时间了,我现在已经将此功能添加到 Yosys git head中。

这是一个使用示例:

// example.cc

#include <kernel/yosys.h>

int main()
{
    Yosys::log_streams.push_back(&std::cout);
    Yosys::log_error_stderr = true;

    Yosys::yosys_setup();
    Yosys::yosys_banner();

    Yosys::run_pass("read_verilog example.v");
    Yosys::run_pass("synth -noabc");
    Yosys::run_pass("clean -purge");
    Yosys::run_pass("write_blif example.blif");

    Yosys::yosys_shutdown();
    return 0;
}

构建二进制文件:

yosys-config --exec --cxx -o example --cxxflags --ldflags example.cc -lyosys -lstdc++

现在您可以运行./example转换example.vexample.blif.

(由于这是一个全新的功能,如何使用 libyosys 构建程序或其他库的细节可能会在未来发生变化。)

编辑:在当前的 git head 中,Makefile 选项 ENABLE_LIBYOSYS 必须设置为 1 以启用 libyosys.so 的构建。


附加反馈:您可能要考虑编写一个 Yosys 插件,而不是实现一个使用 LLVM 库加载 .bc 文件的 Yosys 前端。如果您不打算在 LLVM 和 Yosys 之间来回切换,而只想执行一系列 LLVM 通道,然后执行一系列 Yosys 通道,那么此解决方案可能会在 LLVM 和 Yosys 之间提供更自然且更易于调试的接口。

于 2015-08-04T11:36:44.093 回答