提交 3e9854d8 编写于 作者: 饶先宏's avatar 饶先宏

202106131851...

202106131851 改了N个各式各样的错误之后,汇编器终于可以运行了,counter和terris应用能够直接从verilog代码编译出来的目标代码运行了。下一步逐步增加语法结构支持,直到RTL全支持。
上级 9d69d016
......@@ -33,11 +33,13 @@
* bignumber.c
202105201110: rxh, initial version
202105260952: rxh, 修改了接口,为verilog语言编译做准备,主要是区分了带符号和不带符号计算
202106130718: rxh, 增加实现了DList接口,支持放在双向链表中
*/
#include "stdlib.h"
#include "stdio.h"
#include "object.h"
#include "dlist.h"
#include "string.h"
#define IMPLEMENT_GUID
#include "bignumber.h"
......@@ -52,6 +54,7 @@ typedef struct _sBigInteger {
OBJECT_HEADER
INTERFACE_DECLARE(IBigNumber)
BIGNUMBER_VARDECLARE
DLIST_VARDECLARE
int buflen;
int width;
......@@ -61,11 +64,14 @@ typedef struct _sBigInteger {
OBJECT_FUNCDECLARE(bigint, CLSID_BIGINTEGER);
BIGNUMBER_FUNCDECLARE(bigint, CLSID_BIGINTEGER, sBigInteger);
DLIST_FUNCIMPL(bigint, CLSID_BIGINTEGER, sBigInteger);
OBJECT_FUNCIMPL(bigint, sBigInteger, CLSID_BIGINTEGER);
QUERYINTERFACE_BEGIN(bigint, CLSID_BIGINTEGER)
QUERYINTERFACE_ITEM(IID_BIGNUMBER, IBigNumber, sBigInteger)
QUERYINTERFACE_ITEM(IID_DLIST, IDList, sBigInteger)
QUERYINTERFACE_END
static const char* bigintModuleInfo()
......@@ -83,6 +89,7 @@ static int bigintCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* pObje
*pObject = 0;
BIGNUMBER_VARINIT(pobj, CLSID_BIGINTEGER);
INTERFACE_INIT(IBigNumber, pobj, bigint, bn);
DLIST_VARINIT(pobj, bigint);
pobj->width = 64;
for (i = 0; i < paramcount; i++) {
......@@ -179,7 +186,20 @@ static int bigint_bn_SetWidth(HOBJECT object, int width, int signexpand)
free(pobj->buf);
pobj->buf = buf;
}
blen = pobj->width / CELL_WIDTH;
if (blen < pobj->buflen) {
bc = pobj->width & (CELL_WIDTH - 1);
if (sign)
pobj->buf[blen] |= CELL_MASK << bc;
else
pobj->buf[blen] &= CELL_MASK >> (CELL_WIDTH - bc);
}
for (i = blen + 1; i < pobj->buflen; i++) {
pobj->buf[i] = sign ? CELL_MASK : 0;
}
blen = width / CELL_WIDTH;
if (blen < pobj->buflen) {
bc = width & (CELL_WIDTH - 1);
......@@ -949,9 +969,15 @@ static int bigint_bn_Add(HOBJECT object, HOBJECT src0, HOBJECT src1)
static int bigint_bn_Sub(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
if (EIID_OK != bigint_bn_Neg(object, src1))
IBigNumber** temp;
int ret;
temp = bigintegerCreate(32);
objectCall1(temp, Clone, src1);
if (EIID_OK != bigint_bn_Neg(temp, temp))
return -1;
return bigint_bn_Add(object, src0, object);
ret = bigint_bn_Add(object, src0, temp);
objectRelease(temp);
return ret;
}
static int bigint_bn_MulFunc(HOBJECT object, HOBJECT src0, HOBJECT src1, int signexpand)
......@@ -1658,7 +1684,7 @@ static int bigint_bn_And(HOBJECT object, HOBJECT src0, HOBJECT src1)
static int bigint_bn_Or(HOBJECT object, HOBJECT src0, HOBJECT src1)
{
int signexpand = 1;
int signexpand = 0;
sBigInteger* pobj;
IBigNumber** psrc0;
IBigNumber** psrc1;
......@@ -1805,8 +1831,17 @@ static int bigint_bn_uAndNot(HOBJECT object, HOBJECT src)
static int bigint_bn_uOr(HOBJECT object, HOBJECT src)
{
sBigInteger* pobj;
IBigNumber** psrc;
pobj = (sBigInteger*)objectThis(object);
NOTIMPL;
if (EIID_OK != objectQueryInterface(src, IID_BIGNUMBER, (void**)&psrc)) {
return -1;
}
if (objectCall0(psrc, IsZero)) {
bigint_bn_AssignInt32(object, 0);
}
else {
bigint_bn_AssignInt32(object, 1);
}
return 0;
}
......@@ -1960,8 +1995,10 @@ static int bigint_bn_SAR(HOBJECT object, HOBJECT src, int bits)
int ifrom, ito, i, zerolen;
unsigned long long current, next;
pobj = (sBigInteger*)objectThis(object);
if (bits == 0)
return 0;
if (bits == 0) {
if (object != src)
return bigint_bn_Clone(object, src);
}
if (bits < 0)
return bigint_bn_SHL(object, src, -bits);
if (EIID_OK != objectQueryInterface(src, IID_BIGNUMBER, (void**)&psrc)) {
......
......@@ -10,7 +10,7 @@ add_executable (counter
"src/main.c"
"src/main_gen.c"
)
target_link_libraries(counter hdl4sesim hdl4secell bignumber digitled hdl4seutils verilog_parser glfw lcom)
target_link_libraries(counter hdl4sesim hdl4secell bignumber digitled hdl4seutils verilog_preprocess verilog_parser glfw lcom)
include_directories("../../../lcom/include")
include_directories("../../hdl4sesim/include")
......
......@@ -45,7 +45,10 @@
#include "conststring.h"
#include "verilog_parsetree.h"
IHDL4SEUnit** hdl4seCreate_0010(IHDL4SEModule** parent, const char* instanceparam, const char* name);
IHDL4SEUnit** hdl4seCreate_000F(IHDL4SEModule** parent, const char* instanceparam, const char* name);
static IHDL4SEUnit** hdl4seCreateDec2seg(IHDL4SEModule** parent, char* instanceparam, char* name) { /* module dec2seg */
return hdl4seCreate_000F(parent, instanceparam, name);
IHDL4SEUnit** unit_const[11];
IHDL4SEUnit** unit_mux16 = NULL;
IHDL4SEModule** module_dec2seg = NULL;
......@@ -98,6 +101,7 @@ static IHDL4SEUnit** hdl4seCreateDec2seg(IHDL4SEModule** parent, char* instancep
}
static IHDL4SEUnit** hdl4seCreateCounter(IHDL4SEModule** parent, char* instanceparam, char* name) { /* module counter */
return hdl4seCreate_0010(parent, instanceparam, name);
IHDL4SEModule** module_counter = NULL;
IHDL4SEUnit** unit_counter = NULL;
int width, maxvalue, resetvalue;
......@@ -108,16 +112,17 @@ static IHDL4SEUnit** hdl4seCreateCounter(IHDL4SEModule** parent, char* instancep
/* 得到对象的IHDL4SEModule 接口 */
objectQueryInterface(unit_counter, IID_HDL4SEMODULE, (void **)&module_counter);
/* 增加端口 */
objectCall3(module_counter, AddPort, 1, PORT_DIRECT_INPUT, "0.nwReset");
objectCall3(module_counter, AddPort, 1, PORT_DIRECT_INPUT, "1.wCounterIt");
objectCall3(module_counter, AddPort, width, PORT_DIRECT_OUTPUT, "2.bCounter");
objectCall3(module_counter, AddPort, 1, PORT_DIRECT_OUTPUT, "3.wCounterOverflow");
objectCall3(module_counter, AddPort, 1, PORT_DIRECT_INPUT, "0.wClk");
objectCall3(module_counter, AddPort, 1, PORT_DIRECT_INPUT, "1.nwReset");
objectCall3(module_counter, AddPort, 1, PORT_DIRECT_INPUT, "2.wCounterIt");
objectCall3(module_counter, AddPort, width, PORT_DIRECT_OUTPUT, "3.bCounter");
objectCall3(module_counter, AddPort, 1, PORT_DIRECT_OUTPUT, "4.wCounterOverflow");
/*WIDTH宽度的寄存器用来保存计数器的值*/
sprintf(temp, "%d", width);
IHDL4SEUnit** reg_bCurrentCounter = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_REG, temp, "bCurrentCounter");
objectCall3(unit_counter, Connect, 2, reg_bCurrentCounter, 1);
objectCall3(unit_counter, Connect, 3, reg_bCurrentCounter, 1);
sprintf(temp, "%d, %d", width, maxvalue);
IHDL4SEUnit** unit_const_MAXVALUE = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_CONST, temp, "const_MAXVALUE");
......@@ -130,11 +135,11 @@ static IHDL4SEUnit** hdl4seCreateCounter(IHDL4SEModule** parent, char* instancep
objectCall3(unit_binop_EQ_bCurrentCounter_MAXVALUE, Connect, 0, reg_bCurrentCounter, 1);
objectCall3(unit_binop_EQ_bCurrentCounter_MAXVALUE, Connect, 1, unit_const_MAXVALUE, 0);
sprintf(temp, "%d, %d, 1, %d", width, width, BINOP_AND);
sprintf(temp, "1, 1, 1, %d",BINOP_AND);
IHDL4SEUnit** unit_binop_overflow = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_BINOP, temp, "unit_binop_overflow");
objectCall3(unit_binop_overflow, Connect, 0, unit_binop_EQ_bCurrentCounter_MAXVALUE, 2);
objectCall3(unit_binop_overflow, Connect, 1, unit_counter, 1);
objectCall3(unit_counter, Connect, 3, unit_binop_overflow, 2);
objectCall3(unit_binop_overflow, Connect, 1, unit_counter, 2);
objectCall3(unit_counter, Connect, 4, unit_binop_overflow, 2);
/* bCurrentCounter+1 用加法器实现 */
/* 常数 1 */
sprintf(temp, "%d, %d", width, 1);
......@@ -158,12 +163,12 @@ static IHDL4SEUnit** hdl4seCreateCounter(IHDL4SEModule** parent, char* instancep
sprintf(temp, "%d", width);
IHDL4SEUnit** unit_mux_bCurrentCounter_if_nwReset = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_MUX2, temp, "mux_bCurrentCounter_if_nwReset");
objectCall3(unit_mux_bCurrentCounter_if_nwReset, Connect, 0, module_counter, 1);
objectCall3(unit_mux_bCurrentCounter_if_nwReset, Connect, 0, unit_counter, 2);
objectCall3(unit_mux_bCurrentCounter_if_nwReset, Connect, 1, reg_bCurrentCounter, 0);
objectCall3(unit_mux_bCurrentCounter_if_nwReset, Connect, 2, unit_mux_bCounter_If_EQMAXvalue, 2);
IHDL4SEUnit** unit_mux_bCurrentCounter = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_MUX2, temp, "mux_bCurrentCounter");
objectCall3(unit_mux_bCurrentCounter, Connect, 0, module_counter, 0);
objectCall3(unit_mux_bCurrentCounter, Connect, 0, unit_counter, 1);
objectCall3(unit_mux_bCurrentCounter, Connect, 1, unit_const_RESETVALUE, 0);
objectCall3(unit_mux_bCurrentCounter, Connect, 2, unit_mux_bCurrentCounter_if_nwReset, 2);
objectCall3(reg_bCurrentCounter, Connect, 0, unit_mux_bCurrentCounter, 3);
......@@ -240,15 +245,15 @@ IHDL4SEUnit** hdl4seCreateMain(IHDL4SEModule** parent, char* instanceparam, char
dec2seg[i] = hdl4seCreateDec2seg(module_main, "", temp);
sprintf(temp, "reg_overflow%d", i);
reg_overflow[i] = hdl4seCreateUnit(module_main, CLSID_HDL4SE_REG, "1", temp);
objectCall3(counter[i], Connect, 0, binop_resetcounter, 2);
objectCall3(counter[i], Connect, 1, binop_resetcounter, 2);
if (i == 0) {
objectCall3(counter[i], Connect, 1, binop_counterit, 2);
objectCall3(counter[i], Connect, 2, binop_counterit, 2);
}
else {
objectCall3(counter[i], Connect, 1, counter[i - 1], 3);
objectCall3(counter[i], Connect, 2, counter[i - 1], 4);
}
objectCall3(dec2seg[i], Connect, 0, counter[i], 2);
objectCall3(reg_overflow[i], Connect, 0, counter[i], 3);
objectCall3(dec2seg[i], Connect, 0, counter[i], 3);
objectCall3(reg_overflow[i], Connect, 0, counter[i], 4);
}
sprintf(temp, "1, 1, 1, %d", BINOP_OR);
......
......@@ -83,33 +83,32 @@ typedef struct s_signal_item {
} signal_item;
signal_item signal_list[] = {
{"/simulator/digitled", "nwReset", NULL, 0, 0},
{"/simulator/digitled", "wWrite", NULL, 0, 0},
{"/simulator/digitled", "bWriteAddr", NULL, 0, 0},
{"/simulator/digitled", "bWriteData", NULL, 0, 0},
{"/simulator/digitled", "wRead", NULL, 0, 0},
{"/simulator/digitled", "bReadAddr", NULL, 0, 0},
{"/simulator/digitled", "bReadData", NULL, 0, 0},
{"/simulator/main", "2.bWriteAddr", NULL, 0, 0},
{"/simulator/main", "3.bWriteData", NULL, 0, 0},
{"/simulator/main/bind4_3210", "out", NULL, 0, 0},
{"/simulator/main/bind4_7654", "out", NULL, 0, 0},
{"/simulator/main/counter0", "2.bCounter", NULL, 0, 0},
{"/simulator/main/counter1", "2.bCounter", NULL, 0, 0},
{"/simulator/main/counter2", "2.bCounter", NULL, 0, 0},
{"/simulator/main/counter3", "2.bCounter", NULL, 0, 0},
{"/simulator/main/counter4", "2.bCounter", NULL, 0, 0},
{"/simulator/main/counter5", "2.bCounter", NULL, 0, 0},
{"/simulator/main/counter6", "2.bCounter", NULL, 0, 0},
{"/simulator/main/counter7", "2.bCounter", NULL, 0, 0},
{"/simulator/main/dec2seg0", "1.seg", NULL, 0, 0},
{"/simulator/main/dec2seg1", "1.seg", NULL, 0, 0},
{"/simulator/main/dec2seg2", "1.seg", NULL, 0, 0},
{"/simulator/main/dec2seg3", "1.seg", NULL, 0, 0},
{"/simulator/main/dec2seg4", "1.seg", NULL, 0, 0},
{"/simulator/main/dec2seg5", "1.seg", NULL, 0, 0},
{"/simulator/main/dec2seg6", "1.seg", NULL, 0, 0},
{"/simulator/main/dec2seg7", "1.seg", NULL, 0, 0},
{"/simulator/main", "nwReset", NULL, 0, 0},
{"/simulator/main", "wWrite", NULL, 0, 0},
{"/simulator/main", "bWriteAddr", NULL, 0, 0},
{"/simulator/main", "bWriteData", NULL, 0, 0},
{"/simulator/main", "bReadData", NULL, 0, 0},
{"/simulator/main/wirein_bWriteAddr", "out", NULL, 0, 0},
{"/simulator/main/wire_bWriteAddr_if_bCounterChanged2", "out", NULL, 0, 0},
{"/simulator/main/wire_bWriteAddr_if_bCounterChanged1", "out", NULL, 0, 0},
{"/simulator/main/wire_bWriteAddr_if_bCounterChanged0", "out", NULL, 0, 0},
{"/simulator/main/wCounterChanged0", "out", NULL, 0, 0},
{"/simulator/main/nwResetCount", "out", NULL, 0, 0},
{"/simulator/main/counter0", "bCounter", NULL, 0, 0},
{"/simulator/main/counter1", "bCounter", NULL, 0, 0},
{"/simulator/main/wCounterChanged0", "out", NULL, 0, 0},
{"/simulator/main/wCounterChanged1", "out", NULL, 0, 0},
{"/simulator/main/wCounterChanged2", "out", NULL, 0, 0},
{"/simulator/main/wCounterin98", "out", NULL, 0, 0},
{"/simulator/main/wCounterin7654", "out", NULL, 0, 0},
{"/simulator/main/wCounterin3210", "out", NULL, 0, 0},
{"/simulator/main/wCounterin10", "out", NULL, 0, 0},
{"/simulator/main/wCounterin98", "out", NULL, 0, 0},
{"/simulator/main/wCounterin7654", "out", NULL, 0, 0},
{"/simulator/main/wireout_bCounterChanged", "out", NULL, 0, 0},
{"/simulator/main/bChanged_if_nwReset", "out", NULL, 0, 0},
{"/simulator/main/or_bCounterChanged", "in", NULL, 0, 0},
{"/simulator/main/or_bCounterChanged", "out", NULL, 0, 0},
};
#define signal_list_count (sizeof(signal_list) / sizeof(signal_list[0]))
......@@ -123,6 +122,9 @@ static int hdl4se_init_signal_list(IHDL4SEDetector** detector, const char* pathn
for (j = 0; j < signal_list_count; j++) {
if (strcmp(pathname, signal_list[j].unitname) == 0) {
count = objectCall0(detector, GetSignalCount);
signal_list[j].detector = NULL;
signal_list[j].index = 0;
signal_list[j].width = 0;
for (i = 0; i < count; i++) {
objectCall3(detector, GetSignalInfo, i, &name, &width);
if (strcmp(name, signal_list[j].signalname) == 0) {
......@@ -131,8 +133,12 @@ static int hdl4se_init_signal_list(IHDL4SEDetector** detector, const char* pathn
signal_list[j].width = width;
printf("sig: %s, unit=%s, index=%d, width=%d\n", name, pathname, i, width);
(*pcount)++;
break;
}
}
if (signal_list[j].detector == NULL) {
printf("Error: signal %s/%s not found\n", signal_list[j].unitname, signal_list[j].signalname);
}
}
}
return 0;
......@@ -185,6 +191,7 @@ static int hdl4se_print_signal_list_detector()
return 0;
}
IHDL4SEUnit** hdl4seCreate_main(IHDL4SEModule** parent, const char* instanceparam, const char* name);
int main(int argc, char* argv[])
{
......@@ -194,7 +201,8 @@ int main(int argc, char* argv[])
IHDL4SEUnit** sim_unit;
IHDL4SEWaveOutput** vcdfile;
sim = hdl4sesimCreateSimulator();
topmodule = hdl4seCreateMain(NULL, "", "main");
// topmodule = hdl4seCreateMain(NULL, "", "main");
topmodule = hdl4seCreate_main(NULL, "", "main");
gui = guiCreate(0xf0000000, "digitled");
objectCall1(sim, SetTopModule, topmodule);
objectCall1(sim, AddDevice, gui);
......
此差异已折叠。
......@@ -78,7 +78,7 @@ endmodule
module counter
#(parameter WIDTH=4, MAXVALUE=9, RESETVALUE=0)
(input wClk, nwReset, wCounterIt,
output [WIDTH-1:0] bCouter,
output [WIDTH-1:0] bCounter,
output wCounterOverflow);
/*WIDTH宽度的寄存器用来保存计数器的值*/
......@@ -90,11 +90,18 @@ output wCounterOverflow);
wireout_bCurrentCounter
);
wire [WIDTH-1:0] bCounter;
//wire [WIDTH-1:0] bCounter;
wire wCounterOverflow;
assign bCounter = wireout_bCurrentCounter;
//assign bCounter = wireout_bCurrentCounter;
//assign wCounterOverflow = wireout_wOverflow;
/*目前不支持assign,这样只能做一个mux*/
hdl4se_mux2 #(WIDTH) mux_temp
( wConst_1,
wireout_bCurrentCounter,
wireout_bCurrentCounter,
bCounter);
wire [WIDTH-1:0] bConst_MAXVALUE;
/*常数 MAXVALUE*/
hdl4se_const #(WIDTH, MAXVALUE) const_MAXVALUE(bConst_MAXVALUE);
......@@ -123,7 +130,7 @@ hdl4se_binop #(1, 1, 1, `BINOP_AND)
wire [WIDTH-1:0] bConst_One;
wire [WIDTH-1:0] bCurrentCounterPlusOne;
hdl4se_const #(WIDTH, 1) const_One(bConst_One);
hdl4se_binop #(WIDTH, WIDTH, 1, `BINOP_ADD)
hdl4se_binop #(WIDTH, WIDTH, WIDTH, `BINOP_ADD)
binop_bCurrentCounterInc(
wireout_bCurrentCounter,
bConst_One,
......@@ -181,20 +188,22 @@ module main(input wClk,
input nwReset,
output wWrite,
output [31:0] bWriteAddr,
output [31:0] bWiteData,
output [31:0] bWriteData,
output [3:0] bWriteMask,
output wRead,
output [31:0] bReadAddr,
input [31:0] bReadData);
wire wButton0Pressed;
wire wButton1Pressed;
wire wButton2Pressed;
wire wnouse;
/*我们一直在读按键的状态*/
hdl4se_const #(1, 1) const_0_wRead(wRead);
hdl4se_const #(32, 32'hF000_0000) const_bReadAddr(bReadAddr);
wire wButton0Pressed;
wire wButton1Pressed;
wire wButton2Pressed;
wire wCounterIt;
hdl4se_split4
#(.INPUTWIDTH(32),
.OUTPUTWIDTH0(1), .OUTPUTFROM0(0),
......@@ -210,55 +219,38 @@ module main(input wClk,
wnouse
);
/* 以下是计数器连接 */
wire nwResetCount;
wire wCounterin0, wCounterin1, wCounterin2,
wCounterin3, wCounterin4, wCounterin5,
wCounterin6, wCounterin7, wCounterin8,
wCounterin9;
wire wOverflow0, wOverflow1, wOverflow2, wOverflow3, wOverflow4;
wire wOverflow5, wOverflow6, wOverflow7, wOverflow8, wOverflow9;
assign wCounterin0 = wCounterIt;
assign wCounterin1 = wCounterin0;
assign wCounterin2 = wCounterin1;
assign wCounterin3 = wCounterin2;
assign wCounterin4 = wCounterin3;
assign wCounterin5 = wCounterin4;
assign wCounterin6 = wCounterin5;
assign wCounterin7 = wCounterin6;
assign wCounterin8 = wCounterin7;
assign wCounterin9 = wCounterin8;
wire [3:0] bCount0, bCount1, bCount2, bCount3, bCount4,
bCount5, bCount6, bCount7, bCount8, bCount9;
counter #(4,9,0) counter0(wClk, nwResetCount, wCounterin0, bCount0, wOverflow0);
counter #(4,9,0) counter1(wClk, nwResetCount, wCounterin1, bCount1, wOverflow1);
counter #(4,9,0) counter2(wClk, nwResetCount, wCounterin2, bCount2, wOverflow2);
counter #(4,9,0) counter3(wClk, nwResetCount, wCounterin3, bCount3, wOverflow3);
counter #(4,9,0) counter4(wClk, nwResetCount, wCounterin4, bCount4, wOverflow4);
counter #(4,9,0) counter5(wClk, nwResetCount, wCounterin5, bCount5, wOverflow5);
counter #(4,9,0) counter6(wClk, nwResetCount, wCounterin6, bCount6, wOverflow6);
counter #(4,9,0) counter7(wClk, nwResetCount, wCounterin7, bCount7, wOverflow7);
counter #(4,9,0) counter8(wClk, nwResetCount, wCounterin8, bCount8, wOverflow8);
counter #(4,9,0) counter9(wClk, nwResetCount, wCounterin9, bCount9, wnouse);
wire wirein_wCounterIt, wireout_wCounterIt;
hdl4se_reg #(1) wCounterIt(
wClk,
wirein_wCounterIt,
wireout_wCounterIt
);
wire wButton0NotPressed;
hdl4se_unop #(1, 1, `UNOP_NOT) Button0NotPressed(wButton0Pressed, wButton0NotPressed);
/*counterit= (~b1) & b2*/
wire wButton1NotPressed;
hdl4se_unop #(1, 1, `UNOP_NOT) unop_Button1NotPressed(wButton1Pressed, wButton1NotPressed);
hdl4se_binop #(1, 1, 1, `BINOP_AND) binop_counterit(wButton1NotPressed, wButton2Pressed, wirein_wCounterIt);
hdl4se_binop #(1, 1, 1, `BINOP_AND) binop_counterit(wButton1NotPressed, wButton2Pressed, wCounterIt);
/*assign nwResetCount = (~b0) & nwReset; */
hdl4se_binop #(1, 1, 1, `BINOP_AND) binop_resetcounter(wButton0NotPressed, nwReset, nwResetCount);
/* 以下是计数器连接 */
wire nwResetCount;
wire wOverflow0, wOverflow1, wOverflow2, wOverflow3, wOverflow4;
wire wOverflow5, wOverflow6, wOverflow7, wOverflow8, wOverflow9;
wire [3:0] bCount0, bCount1, bCount2, bCount3, bCount4,
bCount5, bCount6, bCount7, bCount8, bCount9;
counter #(4,9,0) counter0(wClk, nwResetCount, wCounterIt, bCount0, wOverflow0);
counter #(4,9,0) counter1(wClk, nwResetCount, wOverflow0, bCount1, wOverflow1);
counter #(4,9,0) counter2(wClk, nwResetCount, wOverflow1, bCount2, wOverflow2);
counter #(4,9,0) counter3(wClk, nwResetCount, wOverflow2, bCount3, wOverflow3);
counter #(4,9,0) counter4(wClk, nwResetCount, wOverflow3, bCount4, wOverflow4);
counter #(4,9,0) counter5(wClk, nwResetCount, wOverflow4, bCount5, wOverflow5);
counter #(4,9,0) counter6(wClk, nwResetCount, wOverflow5, bCount6, wOverflow6);
counter #(4,9,0) counter7(wClk, nwResetCount, wOverflow6, bCount7, wOverflow7);
counter #(4,9,0) counter8(wClk, nwResetCount, wOverflow7, bCount8, wOverflow8);
counter #(4,9,0) counter9(wClk, nwResetCount, wOverflow8, bCount9, wOverflow9);
/* 以下是译码器连接,十个计数器的输出对应到十个译码器 */
wire [7:0] code0;
wire [7:0] code1;
......@@ -286,11 +278,11 @@ dec2seg dec9(bCount9, code9);
wire wCounterin98, wCounterin76, wCounterin54, wCounterin32, wCounterin10,
wCounterin7654, wCounterin3210;
hdl4se_binop #(1, 1, 1, `BINOP_OR) or98(wCounterin9, wCounterin8, wCounterin98);
hdl4se_binop #(1, 1, 1, `BINOP_OR) or76(wCounterin7, wCounterin6, wCounterin76);
hdl4se_binop #(1, 1, 1, `BINOP_OR) or54(wCounterin5, wCounterin4, wCounterin54);
hdl4se_binop #(1, 1, 1, `BINOP_OR) or32(wCounterin3, wCounterin2, wCounterin32);
hdl4se_binop #(1, 1, 1, `BINOP_OR) or10(wCounterin1, wCounterin0, wCounterin10);
hdl4se_binop #(1, 1, 1, `BINOP_OR) or98(wOverflow8, wOverflow7, wCounterin98);
hdl4se_binop #(1, 1, 1, `BINOP_OR) or76(wOverflow6, wOverflow5, wCounterin76);
hdl4se_binop #(1, 1, 1, `BINOP_OR) or54(wOverflow4, wOverflow3, wCounterin54);
hdl4se_binop #(1, 1, 1, `BINOP_OR) or32(wOverflow2, wOverflow1, wCounterin32);
hdl4se_binop #(1, 1, 1, `BINOP_OR) or10(wOverflow0, wCounterIt, wCounterin10);
hdl4se_binop #(1, 1, 1, `BINOP_OR) or32(wCounterin76, wCounterin54, wCounterin7654);
hdl4se_binop #(1, 1, 1, `BINOP_OR) or10(wCounterin32, wCounterin10, wCounterin3210);
......@@ -301,7 +293,7 @@ dec2seg dec9(bCount9, code9);
wireout_bCounterChanged);
wire [2:0] bChanged_if_nwReset;
hdl4se_bind3 #(1, 1, 1) bind_wCounterin(wCounterin98, wCounterin7654, wCounterin3210, bChanged_if_nwReset);
hdl4se_bind3 #(1, 1, 1) bind_wCounterin(wCounterin3210, wCounterin7654, wCounterin98 , bChanged_if_nwReset);
wire [2:0] b3b0;
hdl4se_const #(3, 0) const_b3b0(b3b0);
......@@ -325,11 +317,11 @@ dec2seg dec9(bCount9, code9);
wnouse
);
wire wirein_wWrite, wireout_wWrite;
wire wirein_wWrite;
hdl4se_reg #(1) reg_wWrite(
wClk,
wirein_wWrite,
wireout_wWrite
wWrite
);
wire [31:0] wirein_bWriteAddr, wireout_bWriteAddr;
......@@ -353,6 +345,27 @@ dec2seg dec9(bCount9, code9);
wireout_bWriteMask
);
wire wConst_1;
hdl4se_const #(1, 1) const_1(wConst_1);
/*目前不支持assign,这样只能做一个mux*/
hdl4se_mux2 #(32) mux_Addr
( wConst_1,
wireout_bWriteAddr,
wireout_bWriteAddr,
bWriteAddr);
hdl4se_mux2 #(32) mux_Data
( wConst_1,
wireout_bWriteData,
wireout_bWriteData,
bWriteData);
hdl4se_mux2 #(32) mux_Mask
( wConst_1,
wireout_bWriteMask,
wireout_bWriteMask,
bWriteMask);
wire [7:0] b8b0;
hdl4se_const #(8, 0) const_b8b0(b8b0);
wire [3:0] b4b0000;
......@@ -439,22 +452,22 @@ dec2seg dec9(bCount9, code9);
wire [3:0] wire_bWriteMask_if_nwReset;
hdl4se_mux2 #(4) mux_bWriteMask_if_nwReset(nwReset,
wire_bWriteMask_if_bCounterChanged2,
b4b0000,
wire_bWriteMask_if_bCounterChanged2,
wirein_bWriteMask
);
wire [31:0] wire_bWriteAddr_if_nwReset;
hdl4se_mux2 #(32) mux_bWriteAddr_if_nwReset(nwReset,
wire_bWriteAddr_if_bCounterChanged2,
b32b0,
wire_bWriteAddr_if_bCounterChanged2,
wirein_bWriteAddr
);
wire [31:0] wire_bWriteData_if_nwReset;
hdl4se_mux2 #(32) mux_bWriteData_if_nwReset(nwReset,
wire_bWriteData_if_bCounterChanged2,
b32b0,
wire_bWriteData_if_bCounterChanged2,
wirein_bWriteData
);
......
......@@ -439,13 +439,12 @@ module counter
input wClk,
input nwReset,
input wCounterIt,
output [WIDTH-1:0] bCouter,
output [WIDTH-1:0] bCounter,
output wCounterOverflow
)
;
wire [WIDTH-1:0] wirein_bCurrentCounter;
wire [WIDTH-1:0] wireout_bCurrentCounter;
wire [WIDTH-1:0] bCounter;
wire wCounterOverflow;
wire [WIDTH-1:0] bConst_MAXVALUE;
wire [WIDTH-1:0] bConst_RESETVALUE;
......@@ -459,12 +458,13 @@ module counter
wire [WIDTH-1:0] bCurrentCounter_if_nwReset;
wire wOverflow_if_nwReset;
hdl4se_reg #( WIDTH ) bCurrentCounter( wClk, wirein_bCurrentCounter, wireout_bCurrentCounter );
hdl4se_mux2 #( WIDTH ) mux_temp( wConst_1, wireout_bCurrentCounter, wireout_bCurrentCounter, bCounter );
hdl4se_const #( WIDTH, MAXVALUE ) const_MAXVALUE( bConst_MAXVALUE );
hdl4se_const #( WIDTH, RESETVALUE ) const_RESETVALUE( bConst_RESETVALUE );
hdl4se_binop #( WIDTH, WIDTH, 1, 4 ) binop_EQ_bCurrentCounter_MAXVALUE( wireout_bCurrentCounter, bConst_MAXVALUE, wEQ_bCurrentCounter_MAXVALUE );
hdl4se_binop #( 1, 1, 1, 10 ) binop_counter_overfloat( wEQ_bCurrentCounter_MAXVALUE, wCounterIt, wCounterOverflow );
hdl4se_const #( WIDTH, 1 ) const_One( bConst_One );
hdl4se_binop #( WIDTH, WIDTH, 1, 0 ) binop_bCurrentCounterInc( wireout_bCurrentCounter, bConst_One, bCurrentCounterPlusOne );
hdl4se_binop #( WIDTH, WIDTH, WIDTH, 0 ) binop_bCurrentCounterInc( wireout_bCurrentCounter, bConst_One, bCurrentCounterPlusOne );
hdl4se_mux2 #( WIDTH ) mux_bCurrentCounter_if_wCounterIt( wEQ_bCurrentCounter_MAXVALUE, bCurrentCounterPlusOne, bConst_RESETVALUE, bCurrentCounter_if_wCounterIt );
hdl4se_const #( 1, 1 ) const_1( wConst_1 );
hdl4se_const #( 1, 0 ) const_0( wConst_0 );
......@@ -482,28 +482,21 @@ module main
input nwReset,
output wWrite,
output [31:0] bWriteAddr,
output [31:0] bWiteData,
output [31:0] bWriteData,
output [3:0] bWriteMask,
output wRead,
output [31:0] bReadAddr,
input [31:0] bReadData
)
;
wire wnouse;
wire wButton0Pressed;
wire wButton1Pressed;
wire wButton2Pressed;
wire wnouse;
wire wCounterIt;
wire wButton0NotPressed;
wire wButton1NotPressed;
wire nwResetCount;
wire wCounterin0;
wire wCounterin1;
wire wCounterin2;
wire wCounterin3;
wire wCounterin4;
wire wCounterin5;
wire wCounterin6;
wire wCounterin7;
wire wCounterin8;
wire wCounterin9;
wire wOverflow0;
wire wOverflow1;
wire wOverflow2;
......@@ -524,10 +517,6 @@ module main
wire [3:0] bCount7;
wire [3:0] bCount8;
wire [3:0] bCount9;
wire wirein_wCounterIt;
wire wireout_wCounterIt;
wire wButton0NotPressed;
wire wButton1NotPressed;
wire [7:0] code0;
wire [7:0] code1;
wire [7:0] code2;
......@@ -553,13 +542,13 @@ module main
wire wCounterChanged1;
wire wCounterChanged2;
wire wirein_wWrite;
wire wireout_wWrite;
wire [31:0] wirein_bWriteAddr;
wire [31:0] wireout_bWriteAddr;
wire [31:0] wirein_bWriteData;
wire [31:0] wireout_bWriteData;
wire [3:0] wirein_bWriteMask;
wire [3:0] wireout_bWriteMask;
wire wConst_1;
wire [7:0] b8b0;
wire [3:0] b4b0000;
wire [3:0] b4b1100;
......@@ -587,21 +576,20 @@ module main
hdl4se_const #( 32, 32'hF000_0000 ) const_bReadAddr( bReadAddr );
hdl4se_split4 #( .INPUTWIDTH(32), .OUTPUTWIDTH0(1), .OUTPUTFROM0(0), .OUTPUTWIDTH1(1), .OUTPUTFROM1(1), .OUTPUTWIDTH2(1)
, .OUTPUTFROM2(2), .OUTPUTWIDTH3(1), .OUTPUTFROM3(3) ) bReadData_wButton012( bReadData, wButton0Pressed, wButton1Pressed, wButton2Pressed, wnouse );
counter #( 4, 9, 0 ) counter0( wClk, nwResetCount, wCounterin0, bCount0, wOverflow0 );
counter #( 4, 9, 0 ) counter1( wClk, nwResetCount, wCounterin1, bCount1, wOverflow1 );
counter #( 4, 9, 0 ) counter2( wClk, nwResetCount, wCounterin2, bCount2, wOverflow2 );
counter #( 4, 9, 0 ) counter3( wClk, nwResetCount, wCounterin3, bCount3, wOverflow3 );
counter #( 4, 9, 0 ) counter4( wClk, nwResetCount, wCounterin4, bCount4, wOverflow4 );
counter #( 4, 9, 0 ) counter5( wClk, nwResetCount, wCounterin5, bCount5, wOverflow5 );
counter #( 4, 9, 0 ) counter6( wClk, nwResetCount, wCounterin6, bCount6, wOverflow6 );
counter #( 4, 9, 0 ) counter7( wClk, nwResetCount, wCounterin7, bCount7, wOverflow7 );
counter #( 4, 9, 0 ) counter8( wClk, nwResetCount, wCounterin8, bCount8, wOverflow8 );
counter #( 4, 9, 0 ) counter9( wClk, nwResetCount, wCounterin9, bCount9, wnouse );
hdl4se_reg #( 1 ) wCounterIt( wClk, wirein_wCounterIt, wireout_wCounterIt );
hdl4se_unop #( 1, 1, 1 ) Button0NotPressed( wButton0Pressed, wButton0NotPressed );
hdl4se_unop #( 1, 1, 1 ) unop_Button1NotPressed( wButton1Pressed, wButton1NotPressed );
hdl4se_binop #( 1, 1, 1, 10 ) binop_counterit( wButton1NotPressed, wButton2Pressed, wirein_wCounterIt );
hdl4se_binop #( 1, 1, 1, 10 ) binop_counterit( wButton1NotPressed, wButton2Pressed, wCounterIt );
hdl4se_binop #( 1, 1, 1, 10 ) binop_resetcounter( wButton0NotPressed, nwReset, nwResetCount );
counter #( 4, 9, 0 ) counter0( wClk, nwResetCount, wCounterIt, bCount0, wOverflow0 );
counter #( 4, 9, 0 ) counter1( wClk, nwResetCount, wOverflow0, bCount1, wOverflow1 );
counter #( 4, 9, 0 ) counter2( wClk, nwResetCount, wOverflow1, bCount2, wOverflow2 );
counter #( 4, 9, 0 ) counter3( wClk, nwResetCount, wOverflow2, bCount3, wOverflow3 );
counter #( 4, 9, 0 ) counter4( wClk, nwResetCount, wOverflow3, bCount4, wOverflow4 );
counter #( 4, 9, 0 ) counter5( wClk, nwResetCount, wOverflow4, bCount5, wOverflow5 );
counter #( 4, 9, 0 ) counter6( wClk, nwResetCount, wOverflow5, bCount6, wOverflow6 );
counter #( 4, 9, 0 ) counter7( wClk, nwResetCount, wOverflow6, bCount7, wOverflow7 );
counter #( 4, 9, 0 ) counter8( wClk, nwResetCount, wOverflow7, bCount8, wOverflow8 );
counter #( 4, 9, 0 ) counter9( wClk, nwResetCount, wOverflow8, bCount9, wOverflow9 );
dec2seg dec0( bCount0, code0 );
dec2seg dec1( bCount1, code1 );
dec2seg dec2( bCount2, code2 );
......@@ -612,23 +600,27 @@ module main
dec2seg dec7( bCount7, code7 );
dec2seg dec8( bCount8, code8 );
dec2seg dec9( bCount9, code9 );
hdl4se_binop #( 1, 1, 1, 11 ) or98( wCounterin9, wCounterin8, wCounterin98 );
hdl4se_binop #( 1, 1, 1, 11 ) or76( wCounterin7, wCounterin6, wCounterin76 );
hdl4se_binop #( 1, 1, 1, 11 ) or54( wCounterin5, wCounterin4, wCounterin54 );
hdl4se_binop #( 1, 1, 1, 11 ) or32( wCounterin3, wCounterin2, wCounterin32 );
hdl4se_binop #( 1, 1, 1, 11 ) or10( wCounterin1, wCounterin0, wCounterin10 );
hdl4se_binop #( 1, 1, 1, 11 ) or98( wOverflow8, wOverflow7, wCounterin98 );
hdl4se_binop #( 1, 1, 1, 11 ) or76( wOverflow6, wOverflow5, wCounterin76 );
hdl4se_binop #( 1, 1, 1, 11 ) or54( wOverflow4, wOverflow3, wCounterin54 );
hdl4se_binop #( 1, 1, 1, 11 ) or32( wOverflow2, wOverflow1, wCounterin32 );
hdl4se_binop #( 1, 1, 1, 11 ) or10( wOverflow0, wCounterIt, wCounterin10 );
hdl4se_binop #( 1, 1, 1, 11 ) or32( wCounterin76, wCounterin54, wCounterin7654 );
hdl4se_binop #( 1, 1, 1, 11 ) or10( wCounterin32, wCounterin10, wCounterin3210 );
hdl4se_reg #( 3 ) reg_bCounterChanged( wClk, wirein_bCounterChanged, wireout_bCounterChanged );
hdl4se_bind3 #( 1, 1, 1 ) bind_wCounterin( wCounterin98, wCounterin7654, wCounterin3210, bChanged_if_nwReset );
hdl4se_bind3 #( 1, 1, 1 ) bind_wCounterin( wCounterin3210, wCounterin7654, wCounterin98, bChanged_if_nwReset );
hdl4se_const #( 3, 0 ) const_b3b0( b3b0 );
hdl4se_mux2 #( 3 ) mux_if_nwReset( nwReset, b3b0, bChanged_if_nwReset, wirein_bCounterChanged );
hdl4se_split4 #( .INPUTWIDTH(3), .OUTPUTWIDTH0(1), .OUTPUTFROM0(0), .OUTPUTWIDTH1(1), .OUTPUTFROM1(1), .OUTPUTWIDTH2(1)
, .OUTPUTFROM2(2), .OUTPUTWIDTH3(1), .OUTPUTFROM3(2) ) split4_bCounterChanged( wireout_bCounterChanged, wCounterChanged0, wCounterChanged1, wCounterChanged2, wnouse );
hdl4se_reg #( 1 ) reg_wWrite( wClk, wirein_wWrite, wireout_wWrite );
hdl4se_reg #( 1 ) reg_wWrite( wClk, wirein_wWrite, wWrite );
hdl4se_reg #( 32 ) reg_bWriteAddr( wClk, wirein_bWriteAddr, wireout_bWriteAddr );
hdl4se_reg #( 32 ) reg_bWriteData( wClk, wirein_bWriteData, wireout_bWriteData );
hdl4se_reg #( 4 ) reg_bWriteMask( wClk, wirein_bWriteMask, wireout_bWriteMask );
hdl4se_const #( 1, 1 ) const_1( wConst_1 );
hdl4se_mux2 #( 32 ) mux_Addr( wConst_1, wireout_bWriteAddr, wireout_bWriteAddr, bWriteAddr );
hdl4se_mux2 #( 32 ) mux_Data( wConst_1, wireout_bWriteData, wireout_bWriteData, bWriteData );
hdl4se_mux2 #( 32 ) mux_Mask( wConst_1, wireout_bWriteMask, wireout_bWriteMask, bWriteMask );
hdl4se_const #( 8, 0 ) const_b8b0( b8b0 );
hdl4se_const #( 4, 0 ) const_b4b0000( b4b0000 );
hdl4se_const #( 4, 4'b1100 ) const_b4b1100( b4b1100 );
......@@ -648,9 +640,9 @@ module main
hdl4se_mux2 #( 4 ) mux_bWriteMask_if_bCounterChanged2( wCounterChanged2, wire_bWriteMask_if_bCounterChanged1, b4b1100, wire_bWriteMask_if_bCounterChanged2 );
hdl4se_mux2 #( 32 ) mux_bWriteAddr_if_bCounterChanged1( wCounterChanged2, wire_bWriteAddr_if_bCounterChanged1, b32hf0000018, wire_bWriteAddr_if_bCounterChanged2 );
hdl4se_mux2 #( 32 ) mux_bWriteData_if_bCounterChanged2( wCounterChanged2, wire_bWriteData_if_bCounterChanged1, b0098, wire_bWriteData_if_bCounterChanged2 );
hdl4se_mux2 #( 4 ) mux_bWriteMask_if_nwReset( nwReset, wire_bWriteMask_if_bCounterChanged2, b4b0000, wirein_bWriteMask );
hdl4se_mux2 #( 32 ) mux_bWriteAddr_if_nwReset( nwReset, wire_bWriteAddr_if_bCounterChanged2, b32b0, wirein_bWriteAddr );
hdl4se_mux2 #( 32 ) mux_bWriteData_if_nwReset( nwReset, wire_bWriteData_if_bCounterChanged2, b32b0, wirein_bWriteData );
hdl4se_mux2 #( 4 ) mux_bWriteMask_if_nwReset( nwReset, b4b0000, wire_bWriteMask_if_bCounterChanged2, wirein_bWriteMask );
hdl4se_mux2 #( 32 ) mux_bWriteAddr_if_nwReset( nwReset, b32b0, wire_bWriteAddr_if_bCounterChanged2, wirein_bWriteAddr );
hdl4se_mux2 #( 32 ) mux_bWriteData_if_nwReset( nwReset, b32b0, wire_bWriteData_if_bCounterChanged2, wirein_bWriteData );
hdl4se_unop #( 3, 1, 3 ) or_bCounterChanged( wireout_bCounterChanged, wire_or_bCounterChanged );
hdl4se_binop #( 1, 1, 1, 10 ) and_nwReset_bCounterChanged( nwReset, wire_or_bCounterChanged, wirein_wWrite );
endmodule
......@@ -31,7 +31,7 @@
/*
* Created by HDL4SE @ Sat Jun 12 21:02:17 2021
* Created by HDL4SE @ Sun Jun 13 18:50:14 2021
* Don't edit it.
*/
......@@ -59,15 +59,15 @@ IHDL4SEUnit** hdl4seCreate_main(IHDL4SEModule** parent, const char* instancepara
objectQueryInterface(unit, IID_HDL4SEMODULE, (void**)&module);
/* 增加端口 */
/* 0*/ objectCall3(module, AddPort, PORT_DIRECT_INPUT , 1, "wClk");
/* 1*/ objectCall3(module, AddPort, PORT_DIRECT_INPUT , 1, "nwReset");
/* 2*/ objectCall3(module, AddPort, PORT_DIRECT_OUTPUT, 1, "wWrite");
/* 3*/ objectCall3(module, AddPort, PORT_DIRECT_OUTPUT, 32, "bWriteAddr");
/* 4*/ objectCall3(module, AddPort, PORT_DIRECT_OUTPUT, 32, "bWriteData");
/* 5*/ objectCall3(module, AddPort, PORT_DIRECT_OUTPUT, 4, "bWriteMask");
/* 6*/ objectCall3(module, AddPort, PORT_DIRECT_OUTPUT, 1, "wRead");
/* 7*/ objectCall3(module, AddPort, PORT_DIRECT_OUTPUT, 32, "bReadAddr");
/* 8*/ objectCall3(module, AddPort, PORT_DIRECT_INPUT , 32, "bReadData");
/* 0*/ objectCall3(module, AddPort, 1, PORT_DIRECT_INPUT , "wClk");
/* 1*/ objectCall3(module, AddPort, 1, PORT_DIRECT_INPUT , "nwReset");
/* 2*/ objectCall3(module, AddPort, 1, PORT_DIRECT_OUTPUT, "wWrite");
/* 3*/ objectCall3(module, AddPort, 32, PORT_DIRECT_OUTPUT, "bWriteAddr");
/* 4*/ objectCall3(module, AddPort, 32, PORT_DIRECT_OUTPUT, "bWriteData");
/* 5*/ objectCall3(module, AddPort, 4, PORT_DIRECT_OUTPUT, "bWriteMask");
/* 6*/ objectCall3(module, AddPort, 1, PORT_DIRECT_OUTPUT, "wRead");
/* 7*/ objectCall3(module, AddPort, 32, PORT_DIRECT_OUTPUT, "bReadAddr");
/* 8*/ objectCall3(module, AddPort, 32, PORT_DIRECT_INPUT , "bReadData");
{/* 模块实例化 */
modules[ 0] = hdl4seCreateUnit2(module, "6f8a9aa6-ec57-4734-a183-7871ed57ea95", "", "ctrl");
......
......@@ -243,10 +243,7 @@ static int hdl4se_unop_hdl4se_unit_GetValue(HOBJECT object, int index, int width
break;
case UNOP_OR:
objectCall3(pobj->wire_in, GetValue, pobj->wire_in_index, pobj->in_width, pobj->in_data);
objectCall1(pobj->out_data, AssignInt32, 0);
if (objectCall1(pobj->out_data, uOr, pobj->out_data) != 0) {
objectCall1(pobj->out_data, AssignInt32, 1);
}
objectCall1(pobj->out_data, uOr, pobj->in_data);
break;
case UNOP_XOR:
objectCall3(pobj->wire_in, GetValue, pobj->wire_in_index, pobj->in_width, pobj->in_data);
......
......@@ -209,10 +209,27 @@ static int hdl4sevcdfile_output_item_data(IDListVarPtr item, sHDL4SEVcdFile* pob
IMapStr2PtrItem** itemobj;
if (0 == objectQueryInterface(item, IID_MAPSTR2PTRITEM, (void**)&itemobj)) {
objectCall1(itemobj, GetData, &pitem);
objectCall2(pobj->tempvar, SetWidth, pitem->width, 0);
objectCall2(pitem->detector, GetSignalValue, pitem->index, pobj->tempvar);
if (!objectCall1(pobj->tempvar, IsEQU, pitem->lastvalue)) {
objectCall1(pitem->lastvalue, AssignU, pobj->tempvar);
if (pitem->detector != NULL) {
objectCall2(pobj->tempvar, SetWidth, pitem->width, 0);
objectCall2(pitem->detector, GetSignalValue, pitem->index, pobj->tempvar);
if (!objectCall1(pobj->tempvar, IsEQU, pitem->lastvalue)) {
objectCall1(pitem->lastvalue, AssignU, pobj->tempvar);
objectCall3(pitem->lastvalue, GetStr, 2, pobj->tempbuf, MAXWIDTH);
fprintf(pobj->pFile, "b%s %s\n", pobj->tempbuf, pitem->vcdname);
}
}
objectRelease(itemobj);
}
return 0;
}
static int hdl4sevcdfile_output_item_data_init(IDListVarPtr item, sHDL4SEVcdFile* pobj)
{
signalitem* pitem;
IMapStr2PtrItem** itemobj;
if (0 == objectQueryInterface(item, IID_MAPSTR2PTRITEM, (void**)&itemobj)) {
objectCall1(itemobj, GetData, &pitem);
if (pitem->detector != NULL) {
objectCall3(pitem->lastvalue, GetStr, 2, pobj->tempbuf, MAXWIDTH);
fprintf(pobj->pFile, "b%s %s\n", pobj->tempbuf, pitem->vcdname);
}
......@@ -228,7 +245,12 @@ static int hdl4sevcdfile_hdl4se_waveoutput_ClkTick(HOBJECT object, unsigned long
if (pobj->pFile == NULL)
return -1;
fprintf(pobj->pFile, "#%lld\n", clktick);
dlistTraversal(&pobj->signallist, hdl4sevcdfile_output_item_data, pobj);
if (clktick == 0) {
dlistTraversal(&pobj->signallist, hdl4sevcdfile_output_item_data_init, pobj);
}
else {
dlistTraversal(&pobj->signallist, hdl4sevcdfile_output_item_data, pobj);
}
return 0;
}
......@@ -250,6 +272,7 @@ static int hdl4sevcdfile_init_signal_item(IDListVarPtr item, init_signal_list_pa
objectCall1(itemobj, GetData, &pitem);
if (strcmp(param->pathname, pitem->unitname) == 0) {
int count, i;
pitem->detector = NULL;
count = objectCall0(param->detector, GetSignalCount);
for (i = 0; i < count; i++) {
objectCall3(param->detector, GetSignalInfo, i, &name, &width);
......@@ -293,8 +316,10 @@ static int hdl4sevcdfile_output_item_info(IDListVarPtr item, sHDL4SEVcdFile* pob
IMapStr2PtrItem** itemobj;
if (0 == objectQueryInterface(item, IID_MAPSTR2PTRITEM, (void**)&itemobj)) {
objectCall1(itemobj, GetData, &pitem);
fprintf(pobj->pFile, "$var reg %d %s %s/%s[%d:0] $end\n",
pitem->width, pitem->vcdname, pitem->unitname, pitem->signalname, pitem->width - 1);
if (pitem->detector != NULL) {
fprintf(pobj->pFile, "$var reg %d %s %s/%s[%d:0] $end\n",
pitem->width, pitem->vcdname, pitem->unitname, pitem->signalname, pitem->width - 1);
}
objectRelease(itemobj);
}
return 0;
......
......@@ -253,6 +253,233 @@ static int expr_setto_number(sExpr* pobj, IBigNumber** number)
return 0;
}
int const_expr_eval(int expr_infosize, expr_code* expr_info, int paramcount, IBigNumber*** parameters)
{
IDListVar calcstack;
int i;
dlistInit(&calcstack);
for (i = 0; i < expr_infosize; i++) {
switch (expr_info[i].exprtype) {
case EXPRTYPE_NUMBER:
{ /* 数字常量,转换成数字,压到栈中 */
IBigNumber** num = bigintegerCreate(32);
objectCall3(num, AssignStr, expr_info[i].value, NULL, 1);
dlistAppendItem(&calcstack, num);
break;
}
case EXPRTYPE_BIGNUMBER:
{ /* 不可能出现 */
ASSERT(0);
break;
}
case EXPRTYPE_PARAM:
{
IBigNumber** num = NULL;
ASSERT(expr_info[i].index >= 0 && expr_info[i].index < paramcount);
objectQueryInterface(parameters[expr_info[i].index], IID_BIGNUMBER, &num);
dlistAppendItem(&calcstack, num);
break;
}
case EXPRTYPE_LOCALPARAM:
{/*还不支持*/
ASSERT(0);
break;
}
case EXPRTYPE_STRING:
{/*还不支持*/
ASSERT(0);
break;
}
case EXPRTYPE_UNOP:
{ /*直接对栈顶操作*/
IDListVar * stacktop;
IBigNumber** stacktopnum = NULL;
stacktop = calcstack.__dlist_pLast;
ASSERT(stacktop != &calcstack);
objectQueryInterface(stacktop, IID_BIGNUMBER, &stacktopnum);
ASSERT(stacktopnum != NULL);
expr_calc_unop(expr_info[i].op, stacktopnum, stacktopnum);
objectRelease(stacktopnum);
break;
}
case EXPRTYPE_BINOP:
{
IDListVar* src;
IBigNumber** srcnum = NULL;
IDListVar* stacktop;
IBigNumber** stacktopnum = NULL;
src = calcstack.__dlist_pLast;
ASSERT(src != &calcstack);
objectQueryInterface(src, IID_BIGNUMBER, &srcnum);
ASSERT(srcnum != NULL);
dlistDetach(src);
stacktop = calcstack.__dlist_pLast;
ASSERT(stacktop != &calcstack);
objectQueryInterface(stacktop, IID_BIGNUMBER, &stacktopnum);
ASSERT(stacktopnum != NULL);
expr_calc_binop(expr_info[i].op, stacktopnum, stacktopnum, srcnum);
objectRelease(stacktopnum);
objectRelease(src);
objectRelease(srcnum);
break;
}
case EXPRTYPE_IFOP:
{/*还不支持*/
ASSERT(0);
break;
}
case EXPRTYPE_IDENT:
{ /* 不可能出现 */
ASSERT(0);
break;
}
case EXPRTYPE_HIERARCHICAL_IDENT:
break;
case EXPRTYPE_EMIT:
{ /* 不可能出现 */
ASSERT(0);
break;
}
default:
{
ASSERT(0);
break;
}
}
}
{/* 返回栈顶 */
IDListVar* stacktop;
IBigNumber** stacktopnum = NULL;
int ret;
stacktop = calcstack.__dlist_pLast;
ASSERT(stacktop != &calcstack);
objectQueryInterface(stacktop, IID_BIGNUMBER, &stacktopnum);
ASSERT(stacktopnum != NULL);
objectCall1(stacktopnum, GetInt32, &ret);
objectRelease(stacktopnum);
return ret;
}
}
const char* const_expr_list_eval(int expr_infosize, expr_code* expr_info, int paramcount, IBigNumber*** parameters)
{
char* buf = hdl4se_parse_logbuf();
char* tempbuf = buf;
IDListVar calcstack;
int i;
int index;
index = 0;
dlistInit(&calcstack);
buf[0] = 0;
for (i = 0; i < expr_infosize; i++) {
switch (expr_info[i].exprtype) {
case EXPRTYPE_NUMBER:
{ /* 数字常量,转换成数字,压到栈中 */
IBigNumber** num = bigintegerCreate(32);
objectCall3(num, AssignStr, expr_info[i].value, NULL, 1);
dlistAppendItem(&calcstack, num);
break;
}
case EXPRTYPE_BIGNUMBER:
{ /* 不可能出现 */
ASSERT(0);
break;
}
case EXPRTYPE_PARAM:
{
IBigNumber** num = NULL;
ASSERT(expr_info[i].index >= 0 && expr_info[i].index < paramcount);
objectQueryInterface(parameters[expr_info[i].index], IID_BIGNUMBER, &num);
dlistAppendItem(&calcstack, num);
break;
}
case EXPRTYPE_LOCALPARAM:
{/*还不支持*/
ASSERT(0);
break;
}
case EXPRTYPE_STRING:
{/*还不支持*/
ASSERT(0);
break;
}
case EXPRTYPE_UNOP:
{ /*直接对栈顶操作*/
IDListVar* stacktop;
IBigNumber** stacktopnum = NULL;
stacktop = calcstack.__dlist_pLast;
ASSERT(stacktop != &calcstack);
objectQueryInterface(stacktop, IID_BIGNUMBER, &stacktopnum);
ASSERT(stacktopnum != NULL);
expr_calc_unop(expr_info[i].op, stacktopnum, stacktopnum);
objectRelease(stacktopnum);
break;
}
case EXPRTYPE_BINOP:
{
IDListVar* src;
IBigNumber** srcnum = NULL;
IDListVar* stacktop;
IBigNumber** stacktopnum = NULL;
src = calcstack.__dlist_pLast;
ASSERT(src != &calcstack);
objectQueryInterface(src, IID_BIGNUMBER, &srcnum);
ASSERT(srcnum != NULL);
dlistDetach(src);
stacktop = calcstack.__dlist_pLast;
ASSERT(stacktop != &calcstack);
objectQueryInterface(stacktop, IID_BIGNUMBER, &stacktopnum);
ASSERT(stacktopnum != NULL);
expr_calc_binop(expr_info[i].op, stacktopnum, stacktopnum, srcnum);
objectRelease(stacktopnum);
objectRelease(src);
objectRelease(srcnum);
break;
}
case EXPRTYPE_IFOP:
{/*还不支持*/
ASSERT(0);
break;
}
case EXPRTYPE_IDENT:
{ /* 不可能出现 */
ASSERT(0);
break;
}
case EXPRTYPE_HIERARCHICAL_IDENT:
break;
case EXPRTYPE_EMIT:
{/* 栈顶 */
IDListVar* stacktop;
IBigNumber** stacktopnum = NULL;
stacktop = calcstack.__dlist_pLast;
ASSERT(stacktop != &calcstack);
objectQueryInterface(stacktop, IID_BIGNUMBER, &stacktopnum);
ASSERT(stacktopnum != NULL);
if (index > 0) {
*buf++ = ',';
*buf++ = ' ';
}
index++;
objectCall3(stacktopnum, GetStr, 16, buf, 1024);
buf = buf + strlen(buf);
objectRelease(stacktopnum);
dlistDetach(stacktop);
objectRelease(stacktop);
}
break;
default:
{
ASSERT(0);
break;
}
}
}
return hdl4se_parse_logbuf();
}
static int expr_verilognode_procheck(HOBJECT object, HOBJECT module, void * param)
{
sExpr* pobj;
......
......@@ -382,7 +382,7 @@ static int verilogmodule_verilognode_gencode(HOBJECT object, FILE * pFile, const
pitemtemp = pitem->__dlist_pNext;
port->index = index++;
if (port->range_type == RANGE_TYPE_NONE) {
fprintf(pFile, "\t/*%3d*/ objectCall3(module, AddPort, %s, 1, \"%s\");\n",
fprintf(pFile, "\t/*%3d*/ objectCall3(module, AddPort, 1, %s, \"%s\");\n",
port->index,
PORTNAME[port->port_direct],
port->name->string
......@@ -400,10 +400,10 @@ static int verilogmodule_verilognode_gencode(HOBJECT object, FILE * pFile, const
objectCall2(temp, AddInt32, temp, 1);
objectCall1(temp, GetInt32, &width);
objectRelease(temp);
fprintf(pFile, "\t/*%3d*/ objectCall3(module, AddPort, %s, %3d, \"%s\");\n",
fprintf(pFile, "\t/*%3d*/ objectCall3(module, AddPort, %3d, %s, \"%s\");\n",
port->index,
PORTNAME[port->port_direct],
width,
PORTNAME[port->port_direct],
port->name->string
);
......@@ -424,7 +424,7 @@ static int verilogmodule_verilognode_gencode(HOBJECT object, FILE * pFile, const
expropcount,
paramcount,
paramcount > 0 ? "parameters" : "NULL");
fprintf(pFile, "\t/*%3d*/ objectCall3(module, AddPort, %s, portwidth, \"%s\");\n",
fprintf(pFile, "\t/*%3d*/ objectCall3(module, AddPort, portwidth, %s, \"%s\");\n",
port->index,
PORTNAME[port->port_direct],
port->name->string
......@@ -706,6 +706,9 @@ static int verilogmodule_verilognode_gencode(HOBJECT object, FILE * pFile, const
}
}
/*持续性赋值*/
if (paramcount > 0) {
fprintf(pFile, "\n\t{/* 释放实例化参数 */\n\t\tint i;\n");
fprintf(pFile, "\t\tfor (i = 0;i<%d;i++) {\n", paramcount);
......
......@@ -175,12 +175,3 @@ char* hdl4se_parse_logbuf()
return log_buf;
}
int const_expr_eval(int expr_infosize, expr_code* expr_info, int paramcount, IBigNumber*** parameters)
{
IDListVar calcstack;
int i;
for (i = 0; i < expr_infosize; i++) {
}
return 10;
}
......@@ -18,8 +18,8 @@ char* yytext;
static char logbuf[64 * 1024];
#define TERRIS 0
#define COUNTER 1
#define TERRIS 1
#define COUNTER 0
int main(int argc, char* argv[])
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册