Skip to content

Commit

Permalink
Initial VAY draft
Browse files Browse the repository at this point in the history
Signed-off-by: Claire Xenia Wolf <claire@clairexen.net>
  • Loading branch information
clairexen committed Jul 18, 2024
1 parent 3537976 commit 5a53212
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 17 deletions.
30 changes: 22 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ ENABLE_COVER := 1
ENABLE_LIBYOSYS := 0
ENABLE_ZLIB := 1

# enable virtual APIs, create "vay" executable instead of "yosys"
ENABLE_VIRTUAL_APIS := 0

# python wrappers
ENABLE_PYOSYS := 0

Expand Down Expand Up @@ -77,7 +80,11 @@ OBJS =
GENFILES =
EXTRA_OBJS =
EXTRA_TARGETS =
ifeq ($(ENABLE_VIRTUAL_APIS),1)
TARGETS = $(PROGRAM_PREFIX)vay$(EXE) $(PROGRAM_PREFIX)vay-config
else
TARGETS = $(PROGRAM_PREFIX)yosys$(EXE) $(PROGRAM_PREFIX)yosys-config
endif

PRETTY = 1
SMALL = 0
Expand All @@ -101,6 +108,9 @@ EXE_LDFLAGS := -Wl,--export-all-symbols -Wl,--out-implib,libyosys_exe.a
PLUGIN_LDFLAGS += -L"$(LIBDIR)"
PLUGIN_LDLIBS := -lyosys_exe
endif
ifeq ($(ENABLE_VIRTUAL_APIS),1)
CXXFLAGS := $(CXXFLAGS) -D_YOSYS_VAY_
endif

PKG_CONFIG ?= pkg-config
SED ?= sed
Expand Down Expand Up @@ -376,8 +386,12 @@ $(error Invalid CONFIG setting '$(CONFIG)'. Valid values: clang, gcc, emcc, mxe,
endif

ifeq ($(ENABLE_LIBYOSYS),1)
ifeq ($(ENABLE_VIRTUAL_APIS,1)
TARGETS += libvay.so
else
TARGETS += libyosys.so
endif
endif

ifeq ($(ENABLE_PYOSYS),1)
# Detect name of boost_python library. Some distros use boost_python-py<version>, other boost_python<version>, some only use the major version number, some a concatenation of major and minor version numbers
Expand Down Expand Up @@ -750,14 +764,14 @@ ifeq ($(CONFIG),emcc)
yosys.js: $(filter-out yosysjs-$(YOSYS_VER).zip,$(EXTRA_TARGETS))
endif

$(PROGRAM_PREFIX)yosys$(EXE): $(OBJS)
$(P) $(LD) -o $(PROGRAM_PREFIX)yosys$(EXE) $(EXE_LDFLAGS) $(LDFLAGS) $(OBJS) $(LDLIBS) $(LDLIBS_VERIFIC)
$(PROGRAM_PREFIX)yosys$(EXE) $(PROGRAM_PREFIX)vay$(EXE): $(OBJS)
$(P) $(LD) -o $@ $(EXE_LDFLAGS) $(LDFLAGS) $(OBJS) $(LDLIBS) $(LDLIBS_VERIFIC)

libyosys.so: $(filter-out kernel/driver.o,$(OBJS))
libyosys.so libvay.so: $(filter-out kernel/driver.o,$(OBJS))
ifeq ($(OS), Darwin)
$(P) $(LD) -o libyosys.so -shared -Wl,-install_name,$(LIBDIR)/libyosys.so $(LDFLAGS) $^ $(LDLIBS) $(LDLIBS_VERIFIC)
$(P) $(LD) -o $@ -shared -Wl,-install_name,$(LIBDIR)/$@ $(LDFLAGS) $^ $(LDLIBS) $(LDLIBS_VERIFIC)
else
$(P) $(LD) -o libyosys.so -shared -Wl,-soname,$(LIBDIR)/libyosys.so $(LDFLAGS) $^ $(LDLIBS) $(LDLIBS_VERIFIC)
$(P) $(LD) -o $@ -shared -Wl,-soname,$(LIBDIR)/$@ $(LDFLAGS) $^ $(LDLIBS) $(LDLIBS_VERIFIC)
endif

%.o: %.cc
Expand Down Expand Up @@ -793,11 +807,11 @@ CXXFLAGS_NOVERIFIC = $(CXXFLAGS)
LDLIBS_NOVERIFIC = $(LDLIBS)
endif

$(PROGRAM_PREFIX)yosys-config: misc/yosys-config.in
$(PROGRAM_PREFIX)yosys-config $(PROGRAM_PREFIX)vay-config: misc/yosys-config.in
$(P) $(SED) -e 's#@CXXFLAGS@#$(subst -Ilibs/dlfcn-win32,,$(subst -I. -I"$(YOSYS_SRC)",-I"$(DATDIR)/include",$(strip $(CXXFLAGS_NOVERIFIC))))#;' \
-e 's#@CXX@#$(strip $(CXX))#;' -e 's#@LDFLAGS@#$(strip $(LDFLAGS) $(PLUGIN_LDFLAGS))#;' -e 's#@LDLIBS@#$(strip $(LDLIBS_NOVERIFIC) $(PLUGIN_LDLIBS))#;' \
-e 's#@BINDIR@#$(strip $(BINDIR))#;' -e 's#@DATDIR@#$(strip $(DATDIR))#;' < $< > $(PROGRAM_PREFIX)yosys-config
$(Q) chmod +x $(PROGRAM_PREFIX)yosys-config
-e 's#@BINDIR@#$(strip $(BINDIR))#;' -e 's#@DATDIR@#$(strip $(DATDIR))#;' < $< > $@
$(Q) chmod +x $@

abc/abc-$(ABCREV)$(EXE) abc/libabc-$(ABCREV).a:
$(P)
Expand Down
119 changes: 110 additions & 9 deletions kernel/rtlil.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ namespace RTLIL
struct Process;
struct Binding;

#ifdef _YOSYS_VAY_
struct CoarseCell; // same as Cell in a NOVAY build
struct FineCell; // only single-bit ports and no parameters
struct AYFineCell; // cell with single-bit ports "A" and "Y" and no parameters
struct ABYFineCell; // cell with single-bit ports "A", "B", and "Y" and no parameters
// ...
#endif

typedef std::pair<SigSpec, SigSpec> SigSig;

struct IdString
Expand Down Expand Up @@ -1155,6 +1163,10 @@ struct RTLIL::Design
#ifdef WITH_PYTHON
static std::map<unsigned int, RTLIL::Design*> *get_all_designs(void);
#endif

// Memory profiling API
int getAllocations(std::vector<RTLIL::IdString> tags,
std::vector<std::pair<int,std::vector<RTLIL::IdString>>> *allocsPtr = nullptr) const;
};

struct RTLIL::Module : public RTLIL::AttrObject
Expand Down Expand Up @@ -1497,6 +1509,10 @@ struct RTLIL::Module : public RTLIL::AttrObject
#ifdef WITH_PYTHON
static std::map<unsigned int, RTLIL::Module*> *get_all_modules(void);
#endif

// Memory profiling API
int getAllocations(std::vector<RTLIL::IdString> tags,
std::vector<std::pair<int,std::vector<RTLIL::IdString>>> *allocsPtr = nullptr) const;
};

struct RTLIL::Wire : public RTLIL::AttrObject
Expand All @@ -1523,6 +1539,10 @@ struct RTLIL::Wire : public RTLIL::AttrObject
#ifdef WITH_PYTHON
static std::map<unsigned int, RTLIL::Wire*> *get_all_wires(void);
#endif

// Memory profiling API
int getAllocations(std::vector<RTLIL::IdString> tags,
std::vector<std::pair<int,std::vector<RTLIL::IdString>>> *allocsPtr = nullptr) const;
};

inline int GetSize(RTLIL::Wire *wire) {
Expand All @@ -1546,32 +1566,55 @@ struct RTLIL::Memory : public RTLIL::AttrObject

struct RTLIL::Cell : public RTLIL::AttrObject
{
unsigned int hashidx_;
unsigned int hash() const { return hashidx_; }
// do not simply copy cells
Cell(RTLIL::Cell &other) = delete;
void operator=(RTLIL::Cell &other) = delete;

protected:
// use module->addCell() and module->remove() to create or destroy cells
friend struct RTLIL::Module;
Cell();
~Cell();
YS_VAY_VIRTUAL ~Cell();

public:
// do not simply copy cells
Cell(RTLIL::Cell &other) = delete;
void operator=(RTLIL::Cell &other) = delete;

RTLIL::Module *module;
RTLIL::IdString name;
RTLIL::IdString type;

#ifdef _YOSYS_VAY_
// Virtual Coarse Cell API (abstract)
virtual RTLIL::SigSpec getPort(const RTLIL::IdString &portname) const = 0;
//...

// Virtual Fine Cell API (with default implementations)
virtual RTLIL::SigBit getPortBit(const RTLIL::IdString &portname) const { return getPort(portname).as_bit(); }
///...

// Virtual Compact Cell API (with default implementations)
virtual RTLIL::SigSpec getPortA() const { return getPort(ID::A); }
virtual RTLIL::SigBit getPortBitA() const { return getPort(ID::A).as_bit(); }
///...

// Memory profiling API
virtual int getAllocations(std::vector<RTLIL::IdString> tags,
std::vector<std::pair<int,std::vector<RTLIL::IdString>>> *allocsPtr = nullptr) const = 0;
};

struct RTLIL::CoarseCell final : public RTLIL::Cell
{
#endif
unsigned int hashidx_;
unsigned int hash() const { return hashidx_; }

dict<RTLIL::IdString, RTLIL::SigSpec> connections_;
dict<RTLIL::IdString, RTLIL::Const> parameters;

// access cell ports
bool hasPort(const RTLIL::IdString &portname) const;
void unsetPort(const RTLIL::IdString &portname);
void setPort(const RTLIL::IdString &portname, RTLIL::SigSpec signal);
const RTLIL::SigSpec &getPort(const RTLIL::IdString &portname) const;
const dict<RTLIL::IdString, RTLIL::SigSpec> &connections() const;
YS_NOVAY_CONSTREF(RTLIL::SigSpec) getPort(const RTLIL::IdString &portname) const;
YS_NOVAY_CONSTREF(dict<RTLIL::IdString YS_COMMA RTLIL::SigSpec>) connections() const;

// information about cell ports
bool known() const;
Expand Down Expand Up @@ -1602,8 +1645,66 @@ struct RTLIL::Cell : public RTLIL::AttrObject

bool has_memid() const;
bool is_mem_cell() const;

// Memory profiling API
int getAllocations(std::vector<RTLIL::IdString> tags,
std::vector<std::pair<int,std::vector<RTLIL::IdString>>> *allocsPtr = nullptr) const;
};

#ifdef _YOSYS_VAY_
struct RTLIL::FineCell final : public RTLIL::Cell
{
dict<RTLIL::IdString, RTLIL::SigBit> connections_;

//...

// Memory profiling API
int getAllocations(std::vector<RTLIL::IdString> tags,
std::vector<std::pair<int,std::vector<RTLIL::IdString>>> *allocsPtr = nullptr) const;
};

struct RTLIL::AYFineCell final : public RTLIL::Cell
{
SigBit portA_, portY_;

virtual RTLIL::SigSpec getPort(const RTLIL::IdString &portname) const {
if (portname == ID::A) return portA_;
if (portname == ID::Y) return portY_;
log_abort();
}
//...
RTLIL::SigSpec getPortA() const { return portA_; }
RTLIL::SigBit getPortBitA() const { return portA_; }
//...

// Memory profiling API
int getAllocations(std::vector<RTLIL::IdString> tags,
std::vector<std::pair<int,std::vector<RTLIL::IdString>>> *allocsPtr = nullptr) const;
};

struct RTLIL::ABYFineCell final : public RTLIL::Cell
{
SigBit portA_, portB_, portY_;

virtual RTLIL::SigSpec getPort(const RTLIL::IdString &portname) const {
if (portname == ID::A) return portA_;
if (portname == ID::B) return portB_;
if (portname == ID::Y) return portY_;
log_abort();
}
//...
RTLIL::SigSpec getPortA() const { return portA_; }
RTLIL::SigBit getPortBitA() const { return portA_; }
//...

// Memory profiling API
int getAllocations(std::vector<RTLIL::IdString> tags,
std::vector<std::pair<int,std::vector<RTLIL::IdString>>> *allocsPtr = nullptr) const;
};

//...
#endif

struct RTLIL::CaseRule : public RTLIL::AttrObject
{
std::vector<RTLIL::SigSpec> compare;
Expand Down
12 changes: 12 additions & 0 deletions kernel/yosys.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ extern Tcl_Obj *Tcl_ObjSetVar2(Tcl_Interp *interp, Tcl_Obj *part1Ptr, Tcl_Obj *p
# define YS_FALLTHROUGH
#endif

#define YS_COMMA ,

#ifdef _YOSYS_VAY_
# define YS_VAY_VIRTUAL virtual
# define YS_VAY_ABSTRACT = 0
# define YS_NOVAY_CONSTREF(type) type
#else
# define YS_VAY_VIRTUAL
# define YS_VAY_ABSTRACT
# define YS_NOVAY_CONSTREF(type) const type &
#endif

YOSYS_NAMESPACE_BEGIN

// Note: All headers included in hashlib.h must be included
Expand Down

0 comments on commit 5a53212

Please sign in to comment.