Skip to content

Commit

Permalink
convert class FunctionalIR to a namespace Functional, rename function…
Browse files Browse the repository at this point in the history
…alir.h to functional.h, rename functional.h to compute_graph.h
  • Loading branch information
aiju committed Jul 25, 2024
1 parent 5ba566a commit 97d2e5d
Show file tree
Hide file tree
Showing 11 changed files with 1,055 additions and 1,039 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ $(eval $(call add_include_file,backends/rtlil/rtlil_backend.h))
OBJS += kernel/driver.o kernel/register.o kernel/rtlil.o kernel/log.o kernel/calc.o kernel/yosys.o
OBJS += kernel/binding.o
OBJS += kernel/cellaigs.o kernel/celledges.o kernel/satgen.o kernel/scopeinfo.o kernel/qcsat.o kernel/mem.o kernel/ffmerge.o kernel/ff.o kernel/yw.o kernel/json.o kernel/fmt.o kernel/sexpr.o
OBJS += kernel/drivertools.o kernel/functionalir.o
OBJS += kernel/drivertools.o kernel/functional.o
ifeq ($(ENABLE_ZLIB),1)
OBJS += kernel/fstdata.o
endif
Expand Down
20 changes: 10 additions & 10 deletions backends/functional/cxx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

#include "kernel/yosys.h"
#include "kernel/functionalir.h"
#include "kernel/functional.h"
#include <ctype.h>

USING_YOSYS_NAMESPACE
Expand All @@ -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);
Expand All @@ -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());
Expand All @@ -66,7 +66,7 @@ struct CxxType {
}
};

using CxxWriter = FunctionalTools::Writer;
using CxxWriter = Functional::Writer;

struct CxxStruct {
std::string name;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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));
Expand Down
22 changes: 11 additions & 11 deletions backends/functional/smtlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
*/

#include "kernel/functionalir.h"
#include "kernel/functional.h"
#include "kernel/yosys.h"
#include "kernel/sexpr.h"
#include <ctype.h>
Expand All @@ -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);
Expand All @@ -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()));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -183,7 +183,7 @@ struct SmtPrintVisitor : public FunctionalIR::AbstractVisitor<SExpr> {
};

struct SmtModule {
FunctionalIR ir;
Functional::IR ir;
SmtScope scope;
std::string name;

Expand All @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions backends/functional/test_generic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

#include "kernel/yosys.h"
#include "kernel/functionalir.h"
#include "kernel/functional.h"
#include <random>

USING_YOSYS_NAMESPACE
Expand Down Expand Up @@ -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())
Expand Down
Loading

0 comments on commit 97d2e5d

Please sign in to comment.