一、参考链接

1.Yosys内部结构doxygen文件

yosys-master: RTLIL Namespace Reference

2.yosys内部结构介绍

https://yosyshq.readthedocs.io/projects/yosys/en/docs-preview-cellhelp/yosys_internals/formats/rtlil_rep.html

二、概览

1 网表核心数据结构

如图 1所示,所有结构体均可以使用”=”判断是否相同,因此可以直接使用RTLIL::SigSpec判断两根线是否相同。

三、主要结构体

图 2 yosys内部结构主要类

上图为yosys内部网表的主要数据结构

以下是 rtlil.h 和 rtlil.cc 文件中一些关键类含义:

1.RTLIL::IdString

可以理解为std::string,所有module、cell、port等结构的名称,均用此结构体表示,可以转为std::string和const char*

1)转std::string

std::string str = name.str();

2)转const char*

const char* str = name.c_str();

2.RTLIL::Design 类

定义了 RTLIL::Design 类,它表示整个设计,包含所有模块和其他全局信息。RTLIL::Design 类中有一个 modules 成员,它是一个 std::vector,存储设计中的所有模块。

1)获取所有module

for (auto module : design->modules())

2)根据名字获取指定module

top_model = design->module("\\top");

获取design中名为\top的模块

3.RTLIL::Module 类

定义了 RTLIL::Module 类,它表示设计中的一个模块,是设计的基本构建块。RTLIL::Module 类包含成员如 wires、cells 等,用于存储模块内的线网和单元。

1)获取所有Cell

for (auto cell : module->cells())

2)获取所有Wire

for (auto wire : module->wires())

3)通过端口获取SigSpec

RTLIL::SigSpec I = inv_cell->getPort("\\I");

获取反相器inv_cell中名为\I的端口对应的SigSpec

4.RTLIL::Wire 类

定义了 RTLIL::Wire 类,它表示一个线网,用于连接模块内的信号。

5.获取Wire名称

// 遍历模块中的所有连线

for (auto wire : module->wires()) {

 log("wire %s\n", wire->name.c_str());

}

6.RTLIL::Cell 类

定义了 RTLIL::Cell 类,它表示一个单元,如逻辑门或存储元件。

1)获取Cell名称

log("cell %s   type %s\n", cell->name.c_str(), cell->type.c_str());

2)获取Cell类型

log("cell %s   type %s\n", cell->name.c_str(), cell->type.c_str());

3)获取所有端口

// 遍历单元的端口
for (auto &conn : cell->connections()) {
	log("  Cell port %s is connected to %s\n", conn.first.c_str(), conn.second.as_string().c_str());
	for (auto &chunk : conn.second.chunks()) {
		if (chunk.wire != nullptr) {
			// 打印线(wire)的名称和信号块的偏移量及宽度
			log("Wire: %s, Offset: %d, Width: %d\n", chunk.wire->name.c_str(), chunk.offset, chunk.width);
			}
		}
	//printf("  %s",conn.second.c_str());
	// 这里可以添加更多的逻辑来处理单元的端口连接
}

4)移除某个cell

top_model->remove(inv_cell);

7.RTLIL::SigSpec 类

定义了 RTLIL::SigSpec 类,它表示一个信号规范,可以包含多个信号位或信号块。RTLIL::Wire属于其子集。

1)连接两根线

top_model->connect(iserdesSig, new_sig);

8.RTLIL::SigBit 类

定义了 RTLIL::SigBit 类,它表示一个信号位,可以是一个线网的一部分或一个常量值。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐