3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-24 01:25:33 +00:00

convert class FunctionalIR to a namespace Functional, rename functionalir.h to functional.h, rename functional.h to compute_graph.h

This commit is contained in:
Emily Schmidt 2024-07-25 12:10:59 +01:00
parent 8c0f625c3a
commit 850b3a6c29
11 changed files with 1055 additions and 1039 deletions

View file

@ -18,7 +18,7 @@
*/
#include "kernel/yosys.h"
#include "kernel/functionalir.h"
#include "kernel/functional.h"
#include <ctype.h>
USING_YOSYS_NAMESPACE
@ -42,7 +42,7 @@ const char *reserved_keywords[] = {
nullptr
};
template<typename Id> struct CxxScope : public FunctionalTools::Scope<Id> {
template<typename Id> struct CxxScope : public Functional::Scope<Id> {
CxxScope() {
for(const char **p = reserved_keywords; *p != nullptr; p++)
this->reserve(*p);
@ -53,8 +53,8 @@ template<typename Id> struct CxxScope : public FunctionalTools::Scope<Id> {
};
struct CxxType {
FunctionalIR::Sort sort;
CxxType(FunctionalIR::Sort sort) : sort(sort) {}
Functional::Sort sort;
CxxType(Functional::Sort sort) : sort(sort) {}
std::string to_string() const {
if(sort.is_memory()) {
return stringf("Memory<%d, %d>", sort.addr_width(), sort.data_width());
@ -66,7 +66,7 @@ struct CxxType {
}
};
using CxxWriter = FunctionalTools::Writer;
using CxxWriter = Functional::Writer;
struct CxxStruct {
std::string name;
@ -111,8 +111,8 @@ std::string cxx_const(RTLIL::Const const &value) {
return ss.str();
}
template<class NodePrinter> struct CxxPrintVisitor : public FunctionalIR::AbstractVisitor<void> {
using Node = FunctionalIR::Node;
template<class NodePrinter> struct CxxPrintVisitor : public Functional::AbstractVisitor<void> {
using Node = Functional::Node;
CxxWriter &f;
NodePrinter np;
CxxStruct &input_struct;
@ -165,12 +165,12 @@ bool equal_def(RTLIL::Const const &a, RTLIL::Const const &b) {
}
struct CxxModule {
FunctionalIR ir;
Functional::IR ir;
CxxStruct input_struct, output_struct, state_struct;
std::string module_name;
explicit CxxModule(Module *module) :
ir(FunctionalIR::from_module(module)),
ir(Functional::IR::from_module(module)),
input_struct("Inputs"),
output_struct("Outputs"),
state_struct("State")
@ -222,7 +222,7 @@ struct CxxModule {
locals.reserve("output");
locals.reserve("current_state");
locals.reserve("next_state");
auto node_name = [&](FunctionalIR::Node n) { return locals(n.id(), n.name()); };
auto node_name = [&](Functional::Node n) { return locals(n.id(), n.name()); };
CxxPrintVisitor printVisitor(f, node_name, input_struct, state_struct);
for (auto node : ir) {
f.print("\t{} {} = ", CxxType(node.sort()).to_string(), node_name(node));

View file

@ -17,7 +17,7 @@
*
*/
#include "kernel/functionalir.h"
#include "kernel/functional.h"
#include "kernel/yosys.h"
#include "kernel/sexpr.h"
#include <ctype.h>
@ -42,7 +42,7 @@ const char *reserved_keywords[] = {
nullptr
};
struct SmtScope : public FunctionalTools::Scope<int> {
struct SmtScope : public Functional::Scope<int> {
SmtScope() {
for(const char **p = reserved_keywords; *p != nullptr; p++)
reserve(*p);
@ -53,8 +53,8 @@ struct SmtScope : public FunctionalTools::Scope<int> {
};
struct SmtSort {
FunctionalIR::Sort sort;
SmtSort(FunctionalIR::Sort sort) : sort(sort) {}
Functional::Sort sort;
SmtSort(Functional::Sort sort) : sort(sort) {}
SExpr to_sexpr() const {
if(sort.is_memory()) {
return list("Array", list("_", "BitVec", sort.addr_width()), list("_", "BitVec", sort.data_width()));
@ -116,8 +116,8 @@ std::string smt_const(RTLIL::Const const &c) {
return s;
}
struct SmtPrintVisitor : public FunctionalIR::AbstractVisitor<SExpr> {
using Node = FunctionalIR::Node;
struct SmtPrintVisitor : public Functional::AbstractVisitor<SExpr> {
using Node = Functional::Node;
std::function<SExpr(Node)> n;
SmtStruct &input_struct;
SmtStruct &state_struct;
@ -183,7 +183,7 @@ struct SmtPrintVisitor : public FunctionalIR::AbstractVisitor<SExpr> {
};
struct SmtModule {
FunctionalIR ir;
Functional::IR ir;
SmtScope scope;
std::string name;
@ -192,7 +192,7 @@ struct SmtModule {
SmtStruct state_struct;
SmtModule(Module *module)
: ir(FunctionalIR::from_module(module))
: ir(Functional::IR::from_module(module))
, scope()
, name(scope.unique_name(module->name))
, input_struct(scope.unique_name(module->name.str() + "_Inputs"), scope)
@ -215,11 +215,11 @@ struct SmtModule {
list(list("inputs", input_struct.name),
list("state", state_struct.name)),
list("Pair", output_struct.name, state_struct.name)));
auto inlined = [&](FunctionalIR::Node n) {
return n.fn() == FunctionalIR::Fn::constant;
auto inlined = [&](Functional::Node n) {
return n.fn() == Functional::Fn::constant;
};
SmtPrintVisitor visitor(input_struct, state_struct);
auto node_to_sexpr = [&](FunctionalIR::Node n) -> SExpr {
auto node_to_sexpr = [&](Functional::Node n) -> SExpr {
if(inlined(n))
return n.visit(visitor);
else

View file

@ -18,7 +18,7 @@
*/
#include "kernel/yosys.h"
#include "kernel/functionalir.h"
#include "kernel/functional.h"
#include <random>
USING_YOSYS_NAMESPACE
@ -139,7 +139,7 @@ struct FunctionalTestGeneric : public Pass
for (auto module : design->selected_modules()) {
log("Dumping module `%s'.\n", module->name.c_str());
auto fir = FunctionalIR::from_module(module);
auto fir = Functional::IR::from_module(module);
for(auto node : fir)
std::cout << RTLIL::unescape_id(node.name()) << " = " << node.to_string([](auto n) { return RTLIL::unescape_id(n.name()); }) << "\n";
for(auto [name, sort] : fir.outputs())