mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-26 02:25:35 +00:00
docs/functional: Add dummy toy example
Add `dummy.cc`, loosely based on `backends/functional/test_generic.cc` but as an actualy backend and without the memory testing. Skeleton section for minimal functional backend, describing the aforementioned `dummy.cc`.
This commit is contained in:
parent
db823a6acb
commit
560b5fe6bd
2 changed files with 79 additions and 0 deletions
44
docs/source/code_examples/functional/dummy.cc
Normal file
44
docs/source/code_examples/functional/dummy.cc
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include "kernel/functional.h"
|
||||
#include "kernel/yosys.h"
|
||||
|
||||
USING_YOSYS_NAMESPACE
|
||||
PRIVATE_NAMESPACE_BEGIN
|
||||
|
||||
struct FunctionalDummyBackend : public Backend {
|
||||
FunctionalDummyBackend() : Backend("functional_dummy", "dump generated Functional IR") {}
|
||||
void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) override
|
||||
{
|
||||
// backend pass boiler plate
|
||||
log_header(design, "Executing dummy functional backend.\n");
|
||||
|
||||
size_t argidx = 1;
|
||||
extra_args(f, filename, args, argidx, design);
|
||||
|
||||
for (auto module : design->selected_modules())
|
||||
{
|
||||
log("Processing module `%s`.\n", module->name.c_str());
|
||||
|
||||
// convert module to FunctionalIR
|
||||
auto ir = Functional::IR::from_module(module);
|
||||
*f << "module " << module->name.c_str() << "\n";
|
||||
|
||||
// write node functions
|
||||
for (auto node : ir)
|
||||
*f << " assign " << id2cstr(node.name())
|
||||
<< " = " << node.to_string() << "\n";
|
||||
*f << "\n";
|
||||
|
||||
// write outputs and next state
|
||||
for (auto output : ir.outputs())
|
||||
*f << " " << id2cstr(output->kind)
|
||||
<< " " << id2cstr(output->name)
|
||||
<< " = " << id2cstr(output->value().name()) << "\n";
|
||||
for (auto state : ir.states())
|
||||
*f << " " << id2cstr(state->kind)
|
||||
<< " " << id2cstr(state->name)
|
||||
<< " = " << id2cstr(state->next_value().name()) << "\n";
|
||||
}
|
||||
}
|
||||
} FunctionalDummyBackend;
|
||||
|
||||
PRIVATE_NAMESPACE_END
|
Loading…
Add table
Add a link
Reference in a new issue