OpenCores
URL https://opencores.org/ocsvn/ezidebug/ezidebug/trunk

Subversion Repositories ezidebug

[/] [ezidebug/] [trunk/] [EziDebug_src/] [ezidebugvlgfile.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 EziDebug
#include "ezidebugfile.h"
2
#include "ezidebugvlgfile.h"
3
#include "ezidebugprj.h"
4
#include "ezidebugscanchain.h"
5
#include "ezidebugmodule.h"
6
#include "reg_scan.h"
7
#include "string.h"
8
#include <QDebug>
9
#include <QMessageBox>
10
 
11
extern unsigned int unModuCnt ;
12
extern unsigned int unMacroCnt ;
13
 
14
extern ModuleMem ModuleTab[MAX_T_LEN];
15
extern MacroMem MacroTab[MAX_T_LEN];
16
 
17
extern QMap<QString,QString> def_map ;  // 实体名.端口名,数值
18
extern QMap<QString ,QMap<QString,QString> >inst_map ;
19
extern QStringList iinstNameList ;
20
 
21
char buffer[200000];
22
 
23
 
24
const char *g_pscanRegModuleName =
25
"" ;
26
const char *g_pScanRegfileContentFirst =
27
"(\n"
28
"\tclock,\n"
29
"\tresetn,\n"
30
"\tTDI_reg,\n"
31
"\tTDO_reg,\n"
32
"\tTOUT_reg,\n"
33
"\tshift_reg\n"
34
"\t);\n"
35
"\tparameter shift_width = 100;\n"
36
"\n"
37
"\tinput   clock;\n"
38
"\tinput   resetn;\n"
39
"\tinput   TDI_reg;\n"
40
"\toutput  TDO_reg;\n"
41
"\tinput   TOUT_reg;\n"
42
"\tinput   [shift_width-1:0] shift_reg;\n"
43
"\n"
44
"\treg     [shift_width-1:0] shift_reg_r;\n" ;
45
 
46
 
47
 
48
const char *g_pScanRegfileContentSecond =
49
"\talways@(posedge clock or negedge resetn)\n"
50
"\t\tif(!resetn)\n"
51
"\t\t\tshift_reg_r <= ~shift_reg_r ;\n"
52
"\t\telse if(TOUT_reg)\n"
53
"\t\t\tshift_reg_r <=  shift_reg;\n"
54
"\t\telse\n"
55
"\t\t\tshift_reg_r <= {shift_reg_r[shift_width-2:0],TDI_reg};\n"
56
"\n"
57
"\tassign TDO_reg = shift_reg_r[shift_width-1] ;\n"
58
"\n"
59
"endmodule\n"
60
;
61
 
62
 
63
 
64
//  "\talways@(posedge clock or negedge resetn)\n"
65
 
66
 
67
const char *g_pscanIoModuleName =
68
"module _EziDebugScanChainIo(\n" ;
69
const char *g_pScanIofileContentFirst =
70
"\tclock,\n"
71
"\tresetn,\n"
72
"\tTDI_reg,\n"
73
"\tTDO_reg,\n"
74
"\tTOUT_reg,\n"
75
"\tshift_reg\n"
76
"\t);\n"
77
"\tparameter shift_width = 100;\n"
78
"\n"
79
"\tinput   clock;\n"
80
"\tinput   resetn;\n"
81
"\tinput   TDI_reg;\n"
82
"\toutput  TDO_reg;\n"
83
"\tinput   TOUT_reg;\n"
84
"\tinput   [shift_width-1:0] shift_io;\n"
85
"\n"
86
"\treg     [shift_width-1:0] shift_io_r;\n" ;
87
 
88
 
89
 
90
 
91
const char*g_pScanIoFileContentSecond =
92
"\talways@(posedge clock or negedge resetn)\n"
93
"\t\tif(!resetn)\n"
94
"\t\t\tshift_io_r <= 0;\n"
95
"\t\telse if(TOUT_reg)\n"
96
"\t\t\tshift_io_r <=  shift_io;\n"
97
"\t\telse\n"
98
"\t\t\tshift_io_r <= {shift_io_r[shift_width-2:0],TDI_reg};\n"
99
"\n"
100
"\tassign TDO_reg = shift_io_r[shift_width-1] ;\n"
101
"\n"
102
"endmodule\n"
103
;
104
 
105
 
106
const char* g_ptoutfileContentFirst =
107
"(\n"
108
"\t""clock ,\n"
109
"\t""reset ,\n"
110
"\t""rstn_out ,\n"
111
"\t""TOUT_reg \n"
112
"\t"") ;\n"
113
"\n"
114
"\t""input   clock ;\n"
115
"\t""input   reset ;\n"
116
"\t""output  rstn_out ;\n"
117
"\t""output  TOUT_reg ;\n"
118
"\t""reg[31:0] cnt ;\n"
119
"\t""reg[31:0] counter ;\n"
120
"\t""parameter CNT_MAX = 32'd";
121
 
122
 
123
const char* g_ptoutfileContentSecond =
124
"\n\n\t""always@(posedge clock or posedge reset)\n"
125
"\t\t""if(reset)\n"
126
"\t\t\t""cnt <= 32'h0 ;\n"
127
"\t\t""else if(cnt != CNT_MAX)\n"
128
"\t\t\t""cnt <= cnt + 32'h1 ;\n"
129
"\n\t""assign rstn_out = (cnt != CNT_MAX ) ? 1'b0 : 1'b1 ;"
130
"\n\n\t""always@(posedge clock or posedge reset)\n"
131
"\t\t""if(reset)\n"
132
"\t\t\t""counter <= 32'h0 ;\n"
133
"\t\t""else if(counter >= CNT_MAX)\n"
134
"\t\t\t""counter <= 32'h0 ;\n"
135
"\t\t""else\n"
136
"\t\t\t""counter <= counter + 32'h1 ;\n"
137
"\n"
138
"\t""assign TOUT_reg = (counter == 32'h0)? 1'b1 : 1'b0 ;\n"
139
"\n\t""endmodule\n";
140
 
141
 
142
 
143
 
144
EziDebugVlgFile::EziDebugVlgFile(const QString &filename):EziDebugFile(filename)
145
{
146
 
147
}
148
 
149
EziDebugVlgFile::EziDebugVlgFile(const QString &filename,const QDateTime &datetime,const QStringList &modulelist)\
150
    :EziDebugFile(filename,datetime,modulelist)
151
{
152
 
153
}
154
 
155
 
156
EziDebugVlgFile::~EziDebugVlgFile()
157
{
158
 
159
}
160
 
161
int EziDebugVlgFile::deleteScanChain(QStringList &ideletelinecodelist,const QStringList &ideleteblockcodelist,EziDebugScanChain *pchain,EziDebugPrj::OPERATE_TYPE type)
162
{
163
    int npos = 0 ;
164
    int ndeletePos = 0 ;
165
    int nresultPos = 0 ;
166
    QList<int> iposList ;
167
    QMap<int,int> ideleteCodePosMap ;
168
    QDateTime ilastModifedTime ;
169
 
170
    qDebug() << fileName() ;
171
 
172
    if(fileName().endsWith("SspApbifX.v"))
173
    {
174
        qDebug() << "SspApbifX.v";
175
    }
176
 
177
    // 打开
178
    // 读取 文件
179
    if(!open(QIODevice::ReadOnly | QIODevice::Text))
180
    {
181
        // 向用户输出  文件打不开
182
        qDebug() << errorString() << fileName() ;
183
        return 1 ;
184
    }
185
 
186
    QTextStream iin(this);
187
    QString ifileContent = iin.readAll();
188
 
189
    // 关闭
190
    close();
191
    // 打开 写 文件
192
 
193
    /*备份扫描过的文件*/
194
    QString ieziDebugFileSuffix ;
195
    if(type == EziDebugPrj::OperateTypeDelSingleScanChain)
196
    {
197
        ieziDebugFileSuffix.append(tr(".delete.%1").arg(pchain->getChainName()));
198
    }
199
    else if(type == EziDebugPrj::OperateTypeDelAllScanChain)
200
    {
201
        ieziDebugFileSuffix.append(tr(".deleteall"));
202
    }
203
    else
204
    {
205
        return 1 ;
206
    }
207
 
208
    EziDebugPrj *pprj = const_cast<EziDebugPrj *>(EziDebugInstanceTreeItem::getProject());
209
    QFileInfo ifileInfo(fileName());
210
 
211
    QString idir = EziDebugScanChain::getUserDir() ;
212
    QString ibackupFileName = pprj->getCurrentDir().absolutePath()\
213
            + idir + tr("/") + ifileInfo.fileName() \
214
            + ieziDebugFileSuffix ;
215
    copy(ibackupFileName);
216
    pchain->addToScanedFileList(fileName());
217
 
218
 
219
    // 将注释 替换成 空格
220
    QString iblankString = replaceCommentaryByBlank(ifileContent);
221
 
222
#if 0
223
    QFile itestfile("d:/test.txt");
224
    if(!itestfile.open(QIODevice::Text|QIODevice::WriteOnly))
225
    {
226
        qDebug()<<"aaaaaaaa";
227
    }
228
    QTextStream itestout(&itestfile);
229
    itestout << iblankString ;
230
    itestfile.close();
231
#endif
232
 
233
    //QString icaptureString ;
234
    // 删除行代码
235
    for(int i = 0 ; i < ideletelinecodelist.count() ; i++)
236
    {
237
        // 从 stringlist 提取 字符串 创建 QRegExp
238
        QRegExp ifindExp(ideletelinecodelist.at(i));
239
        ifindExp.setMinimal(true);
240
        QRegExp ifindExpOther(tr("\\s*") + ideletelinecodelist.at(i) );
241
        ifindExpOther.setMinimal(true);
242
        // 查找 待删除的字符串
243
        if((nresultPos = ifindExp.indexIn(iblankString,npos)) == -1)
244
        {
245
            // 向用户输出  查找不到 字符串
246
            qDebug() << "EziDebug info: Can't find the string:" <<ideletelinecodelist.at(i) ;
247
            continue ;
248
        }
249
        else
250
        {
251
            // 删除至 上一个非空白字符
252
            ndeletePos = nresultPos ;
253
            int nlastNoBlankChar = ifileContent.lastIndexOf(QRegExp("\\S"),ndeletePos-1) ;
254
 
255
            npos = ndeletePos + ifindExp.matchedLength() ;
256
 
257
            if(-1 == nlastNoBlankChar)
258
            {
259
                ndeletePos = ndeletePos ;
260
            }
261
            else
262
            {
263
                ndeletePos = nlastNoBlankChar + 1 ;
264
            }
265
 
266
            //QString icatchStr = ifindExp.capturedTexts().at(0) ;
267
            //QString itest = ifileContent.mid(ndeletePos,nresultPos - ndeletePos +ifindExp.matchedLength()) ;
268
            //qDebug() << itest << icatchStr ;
269
            iposList.append(ndeletePos);
270
            ideleteCodePosMap.insert(ndeletePos,(nresultPos - ndeletePos + ifindExp.matchedLength()));
271
 
272
            // 替换 带删除的字符串 为空字符串
273
            //ifileContent.replace(icaptureString,tr(""));
274
        }
275
    }
276
 
277
    // 删除块代码
278
    npos = 0 ;
279
    for(int i = 0 ; i < ideleteblockcodelist.count() ; i++)
280
    {
281
        // 从 stringlist 提取 字符串 创建 QRegExp
282
        QRegExp ifindExp(ideleteblockcodelist.at(i));
283
 
284
 
285
        // 查找 待删除的字符串
286
        if((npos = ifindExp.indexIn(iblankString,npos)) == -1)
287
        {
288
            // 向用户输出  查找不到 字符串
289
            qDebug() << ideletelinecodelist.at(i) ;
290
        }
291
        else
292
        {
293
            // always 和 ;
294
 
295
            // 寻找 always
296
            int nalwaysPos = iblankString.lastIndexOf(QRegExp(QObject::tr("\\balways\\b")),npos);
297
            // 最近的非空白字符, 从第一个空白字符开始 到 always 结束 替换为空
298
            if(-1 != ifileContent.lastIndexOf(QRegExp(QObject::tr("\\S")),nalwaysPos-1))
299
            {
300
                nalwaysPos = ifileContent.lastIndexOf(QRegExp(QObject::tr("\\S")),nalwaysPos-1) + 1;
301
            }
302
 
303
            int nfirstBeginPos = iblankString.indexOf(QRegExp(QObject::tr("\\bbegin\\b")),nalwaysPos);
304
            /*查找匹配的  end*/
305
            QRegExp iwordsExp(QObject::tr("\\b\\w+\\b"));
306
            iwordsExp.setMinimal(true);
307
            int nmatch = 1 ;
308
            int nendPos = 0 ;
309
            int nbeginPos = nfirstBeginPos + 5 ;
310
 
311
            while((nbeginPos = iwordsExp.indexIn(iblankString,nbeginPos)) != -1)
312
            {
313
                if(iwordsExp.capturedTexts().at(0) == "begin")
314
                {
315
                    nmatch++ ;
316
 
317
                }
318
                else if(iwordsExp.capturedTexts().at(0) == "end")
319
                {
320
                    nmatch-- ;
321
                    if(0 == nmatch)
322
                    {
323
                        nendPos = nbeginPos ;
324
                        break ;
325
                    }
326
 
327
                }
328
                else
329
                {
330
                    //
331
                }
332
                nbeginPos += iwordsExp.matchedLength();
333
            }
334
 
335
            if(nmatch != 0)
336
            {
337
                qDebug() << "no matching end string!";
338
                close();
339
                return 1 ;
340
            }
341
 
342
            if(nendPos != 0)
343
            {
344
                //qDebug() << ifileContent.mid(nalwaysPos,nendPos - nalwaysPos + 3);
345
                //ifileContent.replace(nalwaysPos , nendPos - nalwaysPos + 3 ,"");
346
                iposList.append(nalwaysPos);
347
                ideleteCodePosMap.insert(nalwaysPos , nendPos - nalwaysPos + 3);
348
                npos = nendPos + 3 ;
349
            }
350
            else
351
            {
352
                qDebug() << "no finding end string!";
353
            }
354
        }
355
    }
356
 
357
    qSort(iposList.begin(), iposList.end(), qGreater<int>());
358
 
359
    for(int j = 0 ; j < iposList.count() ; j++)
360
    {
361
        int nstartPos = iposList.at(j) ;
362
        int nlength = ideleteCodePosMap.value(nstartPos , -1) ;
363
        ifileContent.replace(nstartPos , nlength ,"");
364
    }
365
 
366
 
367
    if(!open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate))
368
    {
369
        // 向用户输出  文件打不开
370
        qDebug() << errorString() << fileName() ;
371
        return 1 ;
372
    }
373
 
374
    QTextStream iout(this);
375
    iout << ifileContent ;
376
 
377
    //关闭
378
    close();
379
 
380
    ilastModifedTime = ifileInfo.lastModified() ;
381
    modifyStoredTime(ilastModifedTime);
382
 
383
    return 0 ;
384
}
385
 
386
int EziDebugVlgFile::addScanChain(INSERT_TYPE type,QMap<QString,EziDebugInstanceTreeItem::SCAN_CHAIN_STRUCTURE*> &chainStructuremap ,EziDebugScanChain* pchain, EziDebugInstanceTreeItem *pitem)
387
{
388
 
389
    QString ifileData ;
390
    QString ilastString ;
391
    QString ichainClock ;
392
    QString inoSynCode ;
393
    int noffSet = 0 ;
394
    EziDebugPrj * iprj = const_cast<EziDebugPrj *>(EziDebugInstanceTreeItem::getProject());
395
    EziDebugModule *pmodule =  iprj->getPrjModuleMap().value(pitem->getModuleName()) ;
396
 
397
    EziDebugModule *pparentMoudle = iprj->getPrjModuleMap().value(pitem->parent()->getModuleName()) ;
398
    QMap<QString,QString> iclockMap = pmodule->getClockSignal() ;
399
    //QMap<QString,QString> iresetMap = pmodule->getResetSignal() ;
400
 
401
    qDebug() << "Add chain in file:" << fileName();
402
    if(!open(QIODevice::ReadOnly|QIODevice::Text))
403
    {
404
        qDebug() << "Cannot Open file for reading:" << qPrintable(this->errorString());
405
        return 1 ;
406
    }
407
 
408
#if 0
409
    if(fileName().endsWith("ifft_airif_rdctrl.v"))
410
    {
411
        qDebug("add chain in iifft_airif_rdctrl.v");
412
    }
413
#endif
414
 
415
    /*遍历节点时生成 一个寄存器的 迭代关系 字符串  要传入 verilog 文件的 addScanChain 函数中 ,方便插完链之后  保存到相应的对象中*/
416
    /*读取文件所有字符  从上一个注释的结束端 到 下一个注释的开始端 之间 查找需要的字符串*/
417
    ifileData = this->readAll();
418
    close();
419
 
420
 
421
 
422
    /*记录到 扫描过的文件  并备份  */
423
    QFileInfo ifileInfo(fileName());
424
    pchain->addToScanedFileList(fileName());
425
 
426
    QString idir = EziDebugScanChain::getUserDir() ;
427
    QString ibackupFileName = iprj->getCurrentDir().absolutePath()\
428
            + idir + tr("/")+ ifileInfo.fileName() \
429
            + tr(".add") + tr(".%1").arg(pchain->getChainName());
430
    copy(ibackupFileName);
431
 
432
    QDateTime ilastModifedTime ;
433
 
434
    if(iprj->getToolType() == EziDebugPrj::ToolQuartus)
435
    {
436
        inoSynCode = "/*synthesis noprune*/" ;
437
    }
438
    else if(iprj->getToolType() == EziDebugPrj::ToolIse)
439
    {
440
        inoSynCode = "/* synthesis syn_keep = 1 xc_props = \"x\" */" ;
441
    }
442
 
443
    /*根据插入代码类型 分别加入代码 */
444
    // 加入函数 判断 新加入的 代码是否重复 ,如果重复 则在后面加入数字
445
    if(InsertTimer == type)
446
    {
447
        /*如果是定时器 相关代码  */
448
 
449
        struct SEARCH_STRING_STRUCTURE iModuleKeyWordSt ;
450
        iModuleKeyWordSt.m_etype = SearchModuleKeyWordPos ;
451
        iModuleKeyWordSt.m_icontent.m_imodulest.m_eportAnnounceFormat = NonAnsicFormat ;
452
        // 父节点的 的 module name
453
 
454
        strcpy(iModuleKeyWordSt.m_icontent.m_imodulest.m_amoduleName,pitem->parent()->getModuleName().toAscii().data());
455
        //  module 名
456
        int nmoduleKeyWordStartPos = 0 ;
457
        /*找到  右键加入扫描链的 module 对应例化 的 module */
458
        if(skipCommentaryFind(ifileData,0,iModuleKeyWordSt,nmoduleKeyWordStartPos))
459
        {
460
            close();
461
            return 1 ;
462
        }
463
 
464
        struct SEARCH_MODULE_POS_STRUCTURE imodulePos ;
465
        strcpy(imodulePos.m_amoduleName,iModuleKeyWordSt.m_icontent.m_imodulest.m_amoduleName);
466
        /*不用管 端口声明的  方式*/
467
        imodulePos.m_nendModuleKeyWordPos = -1 ;
468
        /*置为标准的,避免扫描 port */
469
        imodulePos.m_eportFormat = AnsicFormat ;
470
        imodulePos.m_nlastRegKeyWordPos = -1 ;
471
        imodulePos.m_nlastPortKeyWordPos = -1 ;
472
        imodulePos.m_nlastWireKeyWordPos = -1 ;
473
        imodulePos.m_nnextRightBracketPos = nmoduleKeyWordStartPos ;
474
 
475
 
476
        struct SEARCH_INSTANCE_POS_STRUCTURE *pinstanceSt = (struct SEARCH_INSTANCE_POS_STRUCTURE *)operator new(sizeof(struct SEARCH_INSTANCE_POS_STRUCTURE)) ;
477
        strcpy(pinstanceSt->m_amoduleName,pitem->getModuleName().toAscii().data());
478
        strcpy(pinstanceSt->m_ainstanceName,pitem->getInstanceName().toAscii().data());
479
        pinstanceSt->m_einstanceFormat = NonStardardFormat ;
480
        pinstanceSt->m_nnextRightBracketPos = -1 ;
481
 
482
        QMap<QString,SEARCH_INSTANCE_POS_STRUCTURE*> iinstancePosMap ;
483
        iinstancePosMap.insert(pitem->getInstanceName(),pinstanceSt);
484
        QString iinstanceCode ;
485
        QString iresetnWireName ;
486
        QString iresetnWireCode ;
487
        QString itoutWireName ;
488
        QString itoutRegName ;
489
        QString itdoWireCode ;
490
        QString itdoWireName ;
491
        QString itoutRegCode;
492
        QString itdoRegCode ;
493
        QString itdoRegName ;
494
        //QString itdoRegEvaluateCode ;
495
        QString itoutWireCode ;
496
        QString iblockCode ;
497
        QString ianncounceCode ;
498
        QString iaddedCode ;
499
        QStringList iaddedCodeList ;
500
        QStringList iaddedBlockCodeList ;
501
        // 找到 lastreg 、lastwire、右键节点的例化位置
502
        if(!matchingTargetString(ifileData,imodulePos,iinstancePosMap))
503
        {
504
 
505
            // 目前不 检查 端口名 是否 重复
506
            //5、查找 最后的寄存器代码 ,根据 端口 时钟个数 判断加入几个
507
 
508
            //怎么传入端口时钟
509
 
510
            // 加入 定义 线 tout_wire 的代码
511
            itoutWireName.append(tr("_EziDebug_%1_tout_w").arg(pchain->getChainName()));
512
            itoutWireCode.append(tr("\n\t""wire _EziDebug_%1_tout_w ;").arg(pchain->getChainName()));
513
            iaddedCodeList.append(tr("\\bwire\\s+_EziDebug_%1_tout_w\\s*;").arg(pchain->getChainName()));
514
 
515
 
516
 
517
            itoutRegName.append(tr("_EziDebug_%1_tout_r").arg(pchain->getChainName()));
518
            itoutRegCode.append(tr("\n\t""reg %1 %2 ;").arg(itoutRegName).arg(inoSynCode));
519
            iaddedCodeList.append(tr("\\breg\\s*%1\\s*.*;").arg(itoutRegName));
520
 
521
            // 加入用于控制翻转的 reset 信号
522
            iresetnWireName.append(tr("_EziDebug_%1_rstn_w").arg(pchain->getChainName()));
523
            iresetnWireCode.append(tr("\n\t""wire _EziDebug_%1_rstn_w ;").arg(pchain->getChainName()));
524
            iaddedCodeList.append(tr("\\bwire\\s+_EziDebug_%1_rstn_w\\s*;").arg(pchain->getChainName()));
525
 
526
            // iaddedCode.append(itoutWireCode) ;
527
            ianncounceCode.append(itoutWireCode);
528
            ianncounceCode.append(itoutRegCode);
529
            ianncounceCode.append(iresetnWireCode);
530
 
531
            SEARCH_INSTANCE_POS_STRUCTURE *pchainInstanceSt = iinstancePosMap.value(pitem->getInstanceName()) ;
532
            //clockname 为 module 里面的 clock 名字
533
            int num = 0 ;
534
            iinstanceCode.append("\n\t\t") ;
535
            QMap<QString,QString>::const_iterator i = iclockMap.constBegin();
536
            while(i != iclockMap.constEnd())
537
            {
538
                QString iparentClock ;
539
                QMap<QString,QString> iparentClockMap = pparentMoudle->getClockSignal();
540
                QMap<QString,QString>::const_iterator iparentClockIter = iparentClockMap.constBegin() ;
541
                while(iparentClockIter != iparentClockMap.constEnd())
542
                {
543
                    iparentClock = iparentClockIter.key();
544
                    ++iparentClockIter ;
545
                }
546
                /*根据当前节点的时钟 获得 扫描链个数  TDI 输入*/
547
                QString iconstBit(tr("%1'b").arg(chainStructuremap.value(i.key())->m_untotalChainNumber));
548
                for(int j = 0 ;j < chainStructuremap.value(i.key())->m_untotalChainNumber ; j++)
549
                {
550
                    iconstBit.append("1");
551
                }
552
                //6、查找 右键插入链的 instance 的代码 ,根据 时钟个数 ,插入多少个 2*TDI TDO ,位宽chainStructuremap 中有多少条链的变量
553
                // 根据 module 里面多少个 时钟, 创建 多少个 和
554
                //   _EziDebug_clockname_TDI_reg
555
                //   _EziDebug_clockname_TDO_reg
556
                //   _EziDebug_TOUT_reg
557
                //  1、 ,\n\t._EziDebug_clockname_TDI_reg(1),\n\t_EziDebug_clockname_TDO_reg(wire_tdo 名字),\n\t_EziDebug_TOUT_reg(wire_tout名字)\n
558
                //  2、 , 1 , wire_tdo 名字 , wire_tout名字
559
 
560
                //  加入定义 线  tdo_wire 的代码  // 位宽、多少个 wire(clock 个数)
561
                // wire [number:0] _EziDebug_chainName_tdo_wire序号 ;\n
562
 
563
                itdoWireName.append(tr("_EziDebug_%1_%2_tdo_w").arg(pchain->getChainName()).arg(i.key()));
564
                itdoRegName.append(tr("_EziDebug_%1_%2_tdo_r").arg(pchain->getChainName()).arg(i.key()));
565
 
566
                if((chainStructuremap.value(i.key())->m_untotalChainNumber) > 1)
567
                {
568
 
569
                    itdoWireCode.append(tr("\n\t""wire [%1:0] %2 ;").arg(chainStructuremap.value(i.key())->m_untotalChainNumber-1).arg(itdoWireName));
570
                    //wire [ %1 : 0 ] _EziDebug_%2_tdo_wire%3 ;
571
                    iaddedCodeList.append(tr("\\b")+tr("wire\\s+\\[")+tr("\\s*%1")\
572
                                          .arg(chainStructuremap.value(i.key())->m_untotalChainNumber - 1)\
573
                                          + tr("\\s*:\\s*0\\s*\\]\\s*") + tr("%1\\s*;")\
574
                                          .arg(itdoWireName));
575
 
576
                    itdoRegCode.append(tr("\n\t""reg [%1:0] %2 %3 ;").arg(chainStructuremap.value(i.key())->m_untotalChainNumber-1).arg(itdoRegName).arg(inoSynCode));
577
                    iaddedCodeList.append(tr("\\breg\\s*\\[\\s*%1\\s*:\\s*0\\s*\\]\\s*%2\\s*.*;").arg(chainStructuremap.value(i.key())->m_untotalChainNumber-1).arg(itdoRegName));
578
                }
579
                else
580
                {
581
                    itdoWireCode.append(tr("\n\t""wire %1 ;").arg(itdoWireName));
582
                    iaddedCodeList.append(tr("\\b")+tr("wire\\s+")+tr("%1\\s*;").arg(itdoWireName));
583
 
584
                    itdoRegCode.append(tr("\n\t""reg %1 %2 ;").arg(itdoRegName).arg(inoSynCode));
585
                    iaddedCodeList.append(tr("\\breg\\s*%1\\s*.*;").arg(itdoRegName));
586
                }
587
 
588
                //iaddedCode.append(itdoWireCode);
589
                //iaddedCode.append(itdoRegCode);
590
 
591
                ianncounceCode.append(itdoWireCode);
592
                ianncounceCode.append(itdoRegCode);
593
 
594
 
595
                // tdo always 赋值语句 无复位信号
596
 
597
                iblockCode.append(tr("\n\n\t""always@(posedge %1)").arg(iparentClock));
598
                iblockCode.append(tr("\n\t\tbegin"));
599
                iblockCode.append(tr("\n\t\t""%1 <= %2 ;").arg(itdoRegName).arg(itdoWireName));
600
                iblockCode.append(tr("\n\t\t""%1 <= %2 ;").arg(itoutRegName).arg(itoutWireName));
601
                iblockCode.append(tr("\n\t\tend"));
602
 
603
 
604
 
605
                iaddedBlockCodeList.append(tr("%1\\s*<=\\s*%2\\s*;").arg(itdoRegName).arg(itdoWireName));
606
                iaddedCode.append(iblockCode);
607
 
608
                /*
609
                    always@(posedge clk or negedge rstn)
610
                        if(!rstn)
611
                            TOut_reg <= 1'b0;
612
                        else if( addr[8:0] == 9'h0 )
613
                            TOut_reg <= 1'b1;
614
                        else
615
                            TOut_reg <= 1'b0;
616
                */
617
                if(StardardForamt == pchainInstanceSt->m_einstanceFormat)
618
                {
619
                    QString iportName = tr(",\n\t\t""._EziDebug_%1_%2_TDI_reg(%3),\n\t\t""._EziDebug_%4_%5_TDO_reg(%6)")\
620
                            .arg(pchain->getChainName()).arg(i.key()).arg(iconstBit).arg(pchain->getChainName()).arg(i.key()).arg(itdoWireName);
621
                    iinstanceCode.append(iportName);
622
                    //iportName.replace("\n\t","\\s*");
623
                    iaddedCodeList.append(tr(",\\s*\\._EziDebug_%1_%2_TDI_reg\\s*\\(\\s*%3\\s*\\)").arg(pchain->getChainName()).arg(i.key()).arg(iconstBit));
624
                    iaddedCodeList.append(tr(",\\s*\\._EziDebug_%1_%2_TDO_reg\\s*\\(\\s*%3\\s*\\)").arg(pchain->getChainName()).arg(i.key()).arg(itdoWireName));
625
                }
626
                else if(NonStardardFormat == pchainInstanceSt->m_einstanceFormat)
627
                {
628
                    QString iportName = tr(", %1 , %2 ,").arg(iconstBit).arg(itdoWireName) ;
629
 
630
                    iinstanceCode.append(iportName);
631
                    //iportName.replace(" ","\\s*");
632
                    iaddedCodeList.append(tr(",\\s*%1").arg(iconstBit));
633
                    iaddedCodeList.append(tr(",\\s*%1").arg(itdoWireName));
634
                }
635
                else
636
                {
637
                    // 释放内存
638
                    iinstancePosMap.remove(pitem->getInstanceName());
639
                    delete pinstanceSt ;
640
                    close();
641
                    return 1 ;
642
                }
643
                /*构造字符串*/
644
 
645
                ++i ;
646
                num++;
647
            }
648
 
649
            ifileData.insert(pinstanceSt->m_nstartPos,ianncounceCode);
650
            noffSet += ianncounceCode.size() ;
651
            // ._EziDebug_chn_rstn(_EziDebug_chn_rstn_w)
652
            if(StardardForamt == pchainInstanceSt->m_einstanceFormat)
653
            {
654
                iinstanceCode.append(tr(",\n\t\t""._EziDebug_%1_rstn(%2)"",\n\t\t""._EziDebug_%3_TOUT_reg(%4)").arg(pchain->getChainName()).arg(iresetnWireName).arg(pchain->getChainName()).arg(itoutWireName)) ;
655
 
656
                iaddedCodeList.append(tr(",\\s*\\._EziDebug_%1_rstn\\s*\\(\\s*%2\\s*\\)").arg(pchain->getChainName()).arg(iresetnWireName));
657
                iaddedCodeList.append(tr(",\\s*\\._EziDebug_%1_TOUT_reg\\s*\\(\\s*%2\\s*\\)").arg(pchain->getChainName()).arg(itoutWireName));
658
            }
659
            else
660
            {
661
                iinstanceCode.append(tr(", %1 , %2").arg(iresetnWireName).arg(itoutWireName)) ;
662
                iaddedCodeList.append(tr(",\\s*%1\\s*,\\s*%2").arg(iresetnWireName).arg(itoutWireName));
663
            }
664
 
665
            // 所有位置偏移 iinstanceCode.size()
666
            ifileData.insert(pinstanceSt->m_nnextRightBracketPos + noffSet , iinstanceCode);
667
            noffSet += iinstanceCode.size() ;
668
 
669
            // 端口对应 所有寄存器 定义
670
            iaddedCode.append(tr("\n"));
671
            QVector<EziDebugModule::PortStructure*> iportVec = pmodule->getPort(iprj,pitem->getInstanceName()) ;
672
            QString iportRegCode ;
673
            QString iportRegName ;
674
            QStringList iportRegEvaluationStrList ;
675
            QStringList iportRegRevereStrList ;
676
            QStringList iportRegResetStrList ;
677
            for(int i = 0 ; i < iportVec.count() ;i++)
678
            {
679
                QString iportWireName = pparentMoudle->getInstancePortMap(pitem->getInstanceName()).value(QString::fromAscii(iportVec.at(i)->m_pPortName));
680
                iportRegName.clear();
681
                iportRegCode.clear();
682
                iportRegName.append(tr("_EziDebug_%1_%2_r").arg(pchain->getChainName()).arg(QString::fromAscii(iportVec.at(i)->m_pPortName)));
683
 
684
                if(iportVec.at(i)->m_unBitwidth == 1)
685
                {
686
                    iportRegCode.append(tr("\n\t""reg %1 %2 ;").arg(iportRegName).arg(inoSynCode));
687
                    iaddedCodeList.append(tr("\\breg\\s+%1\\s*.*;").arg(iportRegName));
688
                }
689
                else
690
                {
691
                    iportRegCode.append(tr("\n\t""reg [%1:%2] %3 %4 ;").arg(iportVec.at(i)->m_unStartBit).arg(iportVec.at(i)->m_unEndBit).arg(iportRegName).arg(inoSynCode));
692
                    iaddedCodeList.append(tr("\\breg\\s*\\[\\s*%1\\s*:\\s*%2\\s*\\]\\s*%3\\s*.*;").arg(iportVec.at(i)->m_unStartBit).arg(iportVec.at(i)->m_unEndBit).arg(iportRegName));
693
                }
694
                iportRegEvaluationStrList.append(tr("%1 <= %2 ;").arg(iportRegName).arg(iportWireName));
695
                iportRegRevereStrList.append(tr("%1 <= ~%2 ;").arg(iportRegName).arg(iportRegName));
696
                iportRegResetStrList.append(tr("%1 <= 0 ;").arg(iportRegName));
697
                iaddedCode.append(iportRegCode);
698
 
699
                if(i == 0)
700
                {
701
                    iaddedBlockCodeList.append(tr("%1\\s*<=\\s*%2\\s*;").arg(iportRegName).arg(iportWireName));
702
                }
703
            }
704
 
705
            iblockCode.clear() ;
706
            if(pchain->getscaningPortClock().isEmpty())
707
            {
708
                if(pmodule->getClockSignal().count() > 1)
709
                {
710
                    qDebug() << "Error: There is two or more Clock Signal";
711
                    close();
712
                    return 1 ;
713
                }
714
 
715
                QString iscanningClock ;
716
                QMap<QString,QString> iparentClockMap = pparentMoudle->getClockSignal();
717
                QMap<QString,QString>::const_iterator iparentClockIter = iparentClockMap.constBegin() ;
718
                while(iparentClockIter != iparentClockMap.constEnd())
719
                {
720
                    iscanningClock = iparentClockIter.key();
721
                    ++iparentClockIter ;
722
                }
723
 
724
                iblockCode.append(tr("\n\n\t""always@(posedge %1 or negedge %2)").arg(iscanningClock).arg(iresetnWireName));
725
                iblockCode.append(tr("\n\tbegin"));
726
                iblockCode.append(tr("\n\t\t""if(!%1)").arg(iresetnWireName));
727
                iblockCode.append(tr("\n\t\t\t""begin"));
728
                iblockCode.append(tr("\n\t\t\t%1").arg(iportRegRevereStrList.join("\n\t\t\t"))) ;
729
                iblockCode.append(tr("\n\t\t\t""end"));
730
                iblockCode.append(tr("\n\t\t""else"));
731
                iblockCode.append(tr("\n\t\t\t""begin"));
732
                iblockCode.append(tr("\n\t\t\t%1").arg(iportRegEvaluationStrList.join("\n\t\t\t")));
733
                iblockCode.append(tr("\n\t\t\t""end"));
734
                iblockCode.append(tr("\n\tend"));
735
 
736
            }
737
            else
738
            {
739
 
740
                iblockCode.append(tr("\n\n\t""always@(posedge %1)").arg(pchain->getscaningPortClock()));
741
                iblockCode.append(tr("\n\t""begin"));
742
                iblockCode.append(tr("\n\t\t%1").arg(iportRegEvaluationStrList.join("\n\t\t")));
743
                iblockCode.append(tr("\n\t""end"));
744
 
745
            }
746
 
747
            iaddedCode.append(iblockCode);
748
 
749
 
750
            //7、加入 将 TDO 载入 reg 的代码
751
            // 找到时钟对应关系 , 定义有关 tdo 需要的 wire 和 生成 相关寄存器的语句
752
            // 并找到clock 和 reset 信号 的 时钟沿变化关系 定义相关的寄存器
753
            /*
754
              reg ......
755
              always@(posedge clock or negedge restn)
756
                if(!restn)
757
                    reg_n <= 0;
758
                else
759
                    reg_n <= wire tdo;
760
 
761
              always@(posedge clock or negedge restn)
762
                if(!restn)
763
                    reg_n <= 0;
764
                else
765
                    reg_n <= wire tdo;
766
            */
767
 
768
            //8、加入将端口保存的代码  在加入扫描链的界面 上 提供所有端口 和 clock 的对应关系
769
            // 根据 端口所在时钟个数 加入  并定义相关的寄存器  reg_n
770
            /*always@(posedge clock or negedge restn)
771
              if(!restn)
772
                  reg_n <= 0;
773
              else
774
                  reg_n <= wire tdo;
775
            */
776
 
777
 
778
            //9、在 endmodule 位置之前插入 timer 例化的代码 ;  不进行 例化名字 的重新改写,如果重复 直接报错 ,应该概率超级小
779
            // itoutCore
780
            /*
781
            itoutCore itoutCore_chainName_inst(
782
                    .clock(慢时钟名字),
783
                    .reset(module中复位信号名字),
784
                    .Tout_reg(wire_tout名)
785
                    );
786
            */
787
 
788
            QString itoutInstanceCode ;
789
            itoutInstanceCode.append("\n\n\t");
790
 
791
            itoutInstanceCode.append(EziDebugScanChain::getChainToutCore());
792
            QString itoutInstanceName(EziDebugScanChain::getChainToutCore() + tr("_%1_inst").arg(pchain->getChainName()));
793
 
794
            QString ireset = "1'b0";
795
            QString iclock ;
796
 
797
            QMap<QString,QString> iparentClockMap = pparentMoudle->getClockSignal();
798
            QMap<QString,QString>::const_iterator iparentClockIter = iparentClockMap.constBegin() ;
799
            while(iparentClockIter != iparentClockMap.constEnd())
800
            {
801
                iclock = iparentClockIter.key();
802
                ++iparentClockIter ;
803
            }
804
 
805
 
806
            if(pchain->getSlowClock().isEmpty())
807
            {
808
                if(iclockMap.count() > 1)
809
                {
810
 
811
                    qDebug() << "Error: There is two or more Clock Signal,Please Input the Tout Clock!";
812
                    close();
813
                    return 1 ;
814
                }
815
                else
816
                {
817
                    // .rstn_out (_EziDebug_chn_rstn_w ),
818
                    if(iclockMap.count() == 1)
819
                    {
820
 
821
                        itoutInstanceCode.append(tr(" ")+itoutInstanceName+tr("(\n\t\t"".clock(%1),\n\t\t"".reset(%2),\n\t\t"".rstn_out(%3),\n\t\t"".TOUT_reg(%4)\n\t);")\
822
                                             .arg(iclock).arg(ireset).arg(iresetnWireName).arg(itoutWireName));
823
 
824
 
825
                    }
826
                    else
827
                    {
828
                        qDebug() << "Error: There is no Clock Signal In moudle:" << pitem->getModuleName();
829
                        close();
830
                        return 1 ;
831
                    }
832
                }
833
            }
834
            else
835
            {
836
                itoutInstanceCode.append(tr(" ")+itoutInstanceName+tr("(\n\t\t"".clock(%1),\n\t\t"".reset(%2),\n\t\t"".rstn_out(%3),\n\t\t"".TOUT_reg(%4)\n\t);")\
837
                                         .arg(pchain->getSlowClock()).arg(ireset).arg(iresetnWireName).arg(itoutWireName));
838
            }
839
 
840
            iaddedCode.append(itoutInstanceCode) ;
841
 
842
            ifileData.insert(imodulePos.m_nendModuleKeyWordPos + noffSet ,iaddedCode);
843
            /*删除代码方法 itoutCore /s+ itoutInstanceName \s+ ( 任意字符 ) /s+ ;*/
844
            iaddedCodeList.append(EziDebugScanChain::getChainToutCore()+tr("\\s+")+itoutInstanceName+tr("\\(")+tr(".+")+tr("\\)")+tr("\\s*;"));
845
 
846
        }
847
        else
848
        {
849
            iinstancePosMap.remove(pitem->getInstanceName());
850
            delete pinstanceSt ;
851
            close();
852
            return 1 ;
853
        }
854
 
855
        //10、写入文件
856
 
857
        pchain->addToLineCodeMap(pitem->parent()->getModuleName(),iaddedCodeList);
858
        pchain->addToBlockCodeMap(pitem->parent()->getModuleName(),iaddedBlockCodeList);
859
 
860
        if(!open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Truncate))
861
        {
862
            qDebug() << "Cannot Open file for writing:" << qPrintable(this->errorString());
863
            return 1 ;
864
        }
865
 
866
        QTextStream iout(this);
867
 
868
        iout << ifileData  ;
869
        close();
870
 
871
        ilastModifedTime = ifileInfo.lastModified() ;
872
        modifyStoredTime(ilastModifedTime);
873
        // 释放内存
874
        iinstancePosMap.remove(pitem->getInstanceName());
875
        delete pinstanceSt ;
876
        return 0 ;
877
 
878
    }
879
    else if(InsertUserCore == type)
880
    {
881
        int nwireCount = pmodule->getEziDebugWireCounts(pchain->getChainName()) ;
882
        QStringList iaddedCodeList ;
883
        QStringList iaddedBlockCodeList ;
884
        QString iparentToutPort(tr("_EziDebug_%1_TOUT_reg").arg(pchain->getChainName())) ;
885
 
886
        struct SEARCH_STRING_STRUCTURE iModuleKeyWordSt ;
887
        iModuleKeyWordSt.m_etype = SearchModuleKeyWordPos ;
888
        iModuleKeyWordSt.m_icontent.m_imodulest.m_eportAnnounceFormat = NonAnsicFormat ;
889
        // 父节点的 的 module name
890
        strcpy(iModuleKeyWordSt.m_icontent.m_imodulest.m_amoduleName,pitem->getModuleName().toAscii().data());
891
        //  module 名
892
        int nmoduleKeyWordStartPos = 0 ;
893
        /*找到  定义本 module 的开始位置  */
894
        if(skipCommentaryFind(ifileData,0,iModuleKeyWordSt,nmoduleKeyWordStartPos))
895
        {
896
            close();
897
            return 1 ;
898
        }
899
 
900
        QString imodulePortCode ;
901
        // 判断这个  module 在本条扫描链 中 是否 被加入过了
902
        // 如果加过了,则直接跳到 加自定义 core 的地方 加代码
903
        if(!pmodule->getAddCodeFlag())
904
        {
905
            //  根据标准或者非标准 加入 本 moudle 的 新增端口  每个clock对应的(TDI TDO) 和 TOUT
906
            //clockname 为 module 里面的 clock 名字
907
            QMap<QString,QString>::const_iterator clockMapIterator = iclockMap.constBegin();
908
            imodulePortCode.append("\n\t\t") ;
909
            while(clockMapIterator != iclockMap.constEnd())
910
            {
911
                // 根据 module 里面多少个 时钟, 创建 多少个 和
912
                //  [bitwidth-1:0] _EziDebug_chainname_clockname_TDI_reg or _EziDebug_chainname_clockname_TDI_reg
913
                //  [bitwidth-1:0] _EziDebug_chainname_clockname_TDO_reg or _EziDebug_chainname_clockname_TDO_reg
914
                //  _EziDebug_chainname_TOUT_reg
915
 
916
                //  加入定义 线  tdo_wire 的代码  // 位宽、多少个 wire(clock 个数)
917
                // wire _EziDebug_chainName_tdo_wire序号[number:0] ;\n
918
 
919
                if(AnsicFormat == iModuleKeyWordSt.m_icontent.m_imodulest.m_eportAnnounceFormat)
920
                {
921
                    if((chainStructuremap.value(clockMapIterator.key())->m_untotalChainNumber) > 1)
922
                    {
923
                        QString iportName = tr(", input [%1:0] _EziDebug_%2_%3_TDI_reg ,\n\t""output [%4:0] _EziDebug_%5_%6_TDO_reg")\
924
                                .arg(chainStructuremap.value(clockMapIterator.key())->m_untotalChainNumber - 1).arg(pchain->getChainName()).arg(clockMapIterator.key())\
925
                                .arg(chainStructuremap.value(clockMapIterator.key())->m_untotalChainNumber - 1).arg(pchain->getChainName()).arg(clockMapIterator.key());
926
 
927
                        imodulePortCode.append(iportName);
928
                        //[ %1 : 0 ] _EziDebug_%2_%3_TDI_reg
929
                        iaddedCodeList.append(tr(",\\s*input\\s*\\[\\s*%1\\s*:\\s*0\\s*\\]\\s+_EziDebug_%2_%3_TDI_reg").arg(chainStructuremap.value(clockMapIterator.key())->m_untotalChainNumber - 1).arg(pchain->getChainName()).arg(clockMapIterator.key()));
930
                        //[ %1 : 0 ] _EziDebug_%2_%3_TDO_reg
931
                        iaddedCodeList.append(tr(",\\s*output\\s*\\[\\s*%1\\s*:\\s*0\\s*\\]\\s+_EziDebug_%2_%3_TDO_reg").arg(chainStructuremap.value(clockMapIterator.key())->m_untotalChainNumber - 1).arg(pchain->getChainName()).arg(clockMapIterator.key()));
932
                    }
933
                    else
934
                    {
935
                        imodulePortCode.append(tr(", input _EziDebug_%1_%2_TDI_reg ,\n\t""ouput_EziDebug_%3_%4_TDO_reg ,\n\t""input_EziDebug_%5_TOUT_reg")\
936
                                .arg(pchain->getChainName()).arg(clockMapIterator.key()).arg(pchain->getChainName()).arg(clockMapIterator.key()).arg(pchain->getChainName()));
937
                        iaddedCodeList.append(tr(",\\s*_EziDebug_%1_%2_TDI_reg\\s*").arg(pchain->getChainName()).arg(clockMapIterator.key()));
938
                        iaddedCodeList.append(tr(",\\s*_EziDebug_%1_%2_TDO_reg\\s*").arg(pchain->getChainName()).arg(clockMapIterator.key()));
939
                    }
940
                }
941
                else if(NonAnsicFormat == iModuleKeyWordSt.m_icontent.m_imodulest.m_eportAnnounceFormat)
942
                {
943
                    imodulePortCode.append(tr(",\n\t_EziDebug_%1_%2_TDI_reg ,\n\t""_EziDebug_%3_%4_TDO_reg")\
944
                            .arg(pchain->getChainName()).arg(clockMapIterator.key()).arg(pchain->getChainName()).arg(clockMapIterator.key()));
945
                    iaddedCodeList.append(tr(",\\s*_EziDebug_%1_%2_TDI_reg").arg(pchain->getChainName()).arg(clockMapIterator.key()));
946
                    iaddedCodeList.append(tr(",\\s*_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(clockMapIterator.key()));
947
 
948
                }
949
                else
950
                {
951
                    close();
952
                    return 1 ;
953
                }
954
                /*构造字符串*/
955
                ++clockMapIterator ;
956
            }
957
 
958
            if(AnsicFormat == iModuleKeyWordSt.m_icontent.m_imodulest.m_eportAnnounceFormat)
959
            {
960
                imodulePortCode.append(tr(",\n\t""input _EziDebug_%1_rstn"",\n\t""input _EziDebug_%2_TOUT_reg").arg(pchain->getChainName()).arg(pchain->getChainName())) ;
961
                iaddedCodeList.append(tr(",\\s*input\\s+_EziDebug_%1_rstn").arg(pchain->getChainName()));
962
                iaddedCodeList.append(tr(",\\s*input\\s+_EziDebug_%2_TOUT_reg").arg(pchain->getChainName()));
963
            }
964
            else
965
            {
966
                imodulePortCode.append(tr(",\n\t_EziDebug_%1_rstn,\n\t""_EziDebug_%2_TOUT_reg").arg(pchain->getChainName()).arg(pchain->getChainName())) ;
967
                iaddedCodeList.append(tr(",\\s*_EziDebug_%1_rstn").arg(pchain->getChainName()));
968
                iaddedCodeList.append(tr(",\\s*_EziDebug_%1_TOUT_reg").arg(pchain->getChainName()));
969
            }
970
 
971
            ifileData.insert(nmoduleKeyWordStartPos,imodulePortCode);
972
        }
973
 
974
        /*1、END 插入端口声明代码*/
975
 
976
        struct SEARCH_MODULE_POS_STRUCTURE imodulePos ;
977
        strcpy(imodulePos.m_amoduleName,iModuleKeyWordSt.m_icontent.m_imodulest.m_amoduleName);
978
 
979
        imodulePos.m_nendModuleKeyWordPos = -1 ;
980
        /*根据 端口声明的方式  决定是否搜索 端口*/
981
        imodulePos.m_eportFormat = iModuleKeyWordSt.m_icontent.m_imodulest.m_eportAnnounceFormat ;
982
        imodulePos.m_nlastRegKeyWordPos = -1 ;
983
        imodulePos.m_nlastPortKeyWordPos = -1 ;
984
        imodulePos.m_nlastWireKeyWordPos = -1 ;
985
        imodulePos.m_nnextRightBracketPos = nmoduleKeyWordStartPos ;
986
 
987
        QMap<QString,SEARCH_INSTANCE_POS_STRUCTURE*> iinstancePosMap ;
988
        int  nnumberOfNoLibCore = 0 ;
989
 
990
        // 遍历 本节点下面 的所有子节点
991
        for(int count = 0 ; count< pitem->childCount() ;count++ )
992
        {
993
            EziDebugInstanceTreeItem* pchildItem =  pitem->child(count) ;
994
            EziDebugPrj *prj = const_cast<EziDebugPrj*>(EziDebugInstanceTreeItem::getProject()) ;
995
            EziDebugModule *pchildModule = prj->getPrjModuleMap().value(pchildItem->getModuleName()) ;
996
            if(!pchildModule->isLibaryCore())
997
            {
998
                struct SEARCH_INSTANCE_POS_STRUCTURE *pinstanceSt = (struct SEARCH_INSTANCE_POS_STRUCTURE *)operator new(sizeof(struct SEARCH_INSTANCE_POS_STRUCTURE)) ;
999
                strcpy(pinstanceSt->m_amoduleName,pchildItem->getModuleName().toAscii().data());
1000
                strcpy(pinstanceSt->m_ainstanceName,pchildItem->getInstanceName().toAscii().data());
1001
                pinstanceSt->m_einstanceFormat = NonStardardFormat ;
1002
                pinstanceSt->m_nnextRightBracketPos = -1 ;
1003
                iinstancePosMap.insert(pchildItem->getInstanceName(),pinstanceSt);
1004
                nnumberOfNoLibCore++ ;
1005
            }
1006
        }
1007
 
1008
        QString ilastTdoWire ; // 保存上一个 tdo 用于 连接 两个 instance 之间 的 端口
1009
        QString itdoWire ;
1010
        imodulePortCode.clear();
1011
 
1012
        // 找到 lastreg 、lastwire
1013
        if(matchingTargetString(ifileData,imodulePos,iinstancePosMap))
1014
        {
1015
            // 释放内存
1016
            QMap<QString,SEARCH_INSTANCE_POS_STRUCTURE*>::iterator i = iinstancePosMap.begin();
1017
            while(i != iinstancePosMap.end())
1018
            {
1019
                struct SEARCH_INSTANCE_POS_STRUCTURE *pinstanceSt = i.value();
1020
                delete pinstanceSt ;
1021
                ++i ;
1022
            }
1023
            iinstancePosMap.clear();
1024
            close();
1025
            return 1 ;
1026
        }
1027
 
1028
 
1029
        if(!pmodule->getAddCodeFlag())
1030
        {
1031
            /*根据需要来 插入 TDI、TOUT、TDO 端口定义 */
1032
            if(NonAnsicFormat == iModuleKeyWordSt.m_icontent.m_imodulest.m_eportAnnounceFormat)
1033
            {
1034
                /*定义端口*/
1035
                QMap<QString,QString>::const_iterator i = iclockMap.constBegin();
1036
                while(i != iclockMap.constEnd())
1037
                {
1038
                    // 根据 module 里面多少个 时钟, 创建 多少个 和
1039
                    //  input  [bitwidth-1:0] _EziDebug_clockname_TDI_reg ; or input _EziDebug_clockname_TDI_reg ;
1040
                    //  output [bitwidth-1:0] _EziDebug_clockname_TDO_reg ; or output _EziDebug_clockname_TDO_reg ;
1041
                    //  input  _EziDebug_TOUT_reg ;
1042
 
1043
                    if((chainStructuremap.value(i.key())->m_untotalChainNumber) > 1)
1044
                    {
1045
                        QString iportName = tr("\n\t""input [%1:0] _EziDebug_%2_%3_TDI_reg ;\n\t""output [%4:0] _EziDebug_%5_%6_TDO_reg ;")\
1046
                                .arg(chainStructuremap.value(i.key())->m_untotalChainNumber - 1).arg(pchain->getChainName()).arg(i.key())\
1047
                                .arg(chainStructuremap.value(i.key())->m_untotalChainNumber - 1).arg(pchain->getChainName()).arg(i.key());
1048
 
1049
                        imodulePortCode.append(iportName);
1050
                        //input [ %1 : 0 ] _EziDebug_%2_%3_TDI_reg
1051
                        iaddedCodeList.append(tr("\\binput\\s*\\[\\s*%1\\s*:\\s*0\\s*\\]\\s+_EziDebug_%2_%3_TDI_reg\\s*;").arg(chainStructuremap.value(i.key())->m_untotalChainNumber - 1).arg(pchain->getChainName()).arg(i.key()));
1052
                        //output [ %1 : 0 ] _EziDebug_%2_%3_TDO_reg
1053
                        iaddedCodeList.append(tr("\\boutput\\s*\\[\\s*%1\\s*:\\s*0\\s*\\]\\s+_EziDebug_%2_%3_TDO_reg\\s*;").arg(chainStructuremap.value(i.key())->m_untotalChainNumber - 1).arg(pchain->getChainName()).arg(i.key()));
1054
                    }
1055
                    else
1056
                    {
1057
                        QString iportName = tr("\n\t""input _EziDebug_%1_%2_TDI_reg ;\n\t""output _EziDebug_%3_%4_TDO_reg ;")\
1058
                                .arg(pchain->getChainName()).arg(i.key())\
1059
                                .arg(pchain->getChainName()).arg(i.key());
1060
 
1061
                        imodulePortCode.append(iportName);
1062
                        //input _EziDebug_%1_%2_TDI_reg
1063
                        iaddedCodeList.append(tr("\\binput\\s+_EziDebug_%1_%2_TDI_reg\\s*;").arg(pchain->getChainName()).arg(i.key()));
1064
                        //output _EziDebug_%1_%2_TDO_reg
1065
                        iaddedCodeList.append(tr("\\boutput\\s+_EziDebug_%1_%2_TDO_reg\\s*;").arg(pchain->getChainName()).arg(i.key()));
1066
                    }
1067
 
1068
                    /*构造字符串*/
1069
                    ++i ;
1070
                }
1071
                imodulePortCode.append(tr("\n\t""input _EziDebug_%1_TOUT_reg ;").arg(pchain->getChainName())) ;
1072
                iaddedCodeList.append(tr("\\binput\\s+_EziDebug_%1_TOUT_reg\\s*;").arg(pchain->getChainName()));
1073
 
1074
                // _EziDebug_%1_rstn
1075
                imodulePortCode.append(tr("\n\t""input _EziDebug_%1_rstn ;").arg(pchain->getChainName())) ;
1076
                iaddedCodeList.append(tr("\\binput\\s+_EziDebug_%1_rstn\\s*;").arg(pchain->getChainName()));
1077
 
1078
                // 在最后一个端口声明之前加入  EziDebug 端口 TDI TDO TOUT 的声明
1079
                ifileData.insert(imodulePos.m_nlastPortKeyWordPos ,imodulePortCode);
1080
                noffSet += imodulePortCode.size() ;
1081
            }
1082
 
1083
            QString itdoWireDefinitionCode ;
1084
            QString iinstanceCode ;
1085
 
1086
            QString iclockString ;
1087
            QString iresetString ;
1088
            QString iresetRegStr ;
1089
            QString ievaluateRegStr ;
1090
            QString isysCoreCode ;
1091
            QString iregDefinitionCode ;
1092
            QString iinstanceExp ;
1093
 
1094
            int nnonCoreNum = 0 ;
1095
            int nFirstnonCoreNum = 0 ;
1096
 
1097
            // 遍历 本节点下面 的所有子节点
1098
            for(int i = 0 ; i< pitem->childCount() ;i++ )
1099
            {
1100
                int m = 0 ;
1101
                EziDebugInstanceTreeItem* pchildItem =  pitem->child(i) ;
1102
                EziDebugPrj *prj = const_cast<EziDebugPrj *>(EziDebugInstanceTreeItem::getProject()) ;
1103
                EziDebugModule *pchildModule = prj->getPrjModuleMap().value(pchildItem->getModuleName()) ;
1104
                QMap<QString,QString> ichildModulePortMap = pmodule->getInstancePortMap(pchildItem->getInstanceName()) ;
1105
                itdoWireDefinitionCode.clear();
1106
                iinstanceCode.clear();
1107
                itdoWire.clear();
1108
                iinstanceExp.clear();
1109
                if(!pchildModule->isLibaryCore())
1110
                {
1111
                    nnonCoreNum++ ;
1112
                    iinstanceCode.append("\n\t\t") ;
1113
                    /*在子模块例化中添加 新增的EziDebug端口代码 需要子节点与父模块的时钟相同*/
1114
                    QMap<QString,QString> ichildClockMap = pchildModule->getClockSignal();
1115
                    if(!ichildClockMap.count())
1116
                    {
1117
                        continue ;
1118
                    }
1119
                    nFirstnonCoreNum++ ;
1120
                    nwireCount++ ;
1121
                    /*根据 非系统core 子例化 加入代码:定义 wire 的代码  用于连接 各个例化 端口、例化模块代码的 端口插入代码*/
1122
                    struct SEARCH_INSTANCE_POS_STRUCTURE *pinstSt = iinstancePosMap.value(pchildItem->getInstanceName());
1123
 
1124
                    QMap<QString,QString>::const_iterator p = ichildClockMap.constBegin();
1125
                    while(p != ichildClockMap.constEnd())
1126
                    {
1127
                        QString iparentTdiPort ;
1128
                        QString iparentTdoPort ;
1129
 
1130
                        QString iparentClock = pitem->getModuleClockMap(pchildItem->getInstanceName()).key(p.key(),QString()) ;
1131
                        if(iparentClock.isEmpty())
1132
                        {
1133
                            // 释放内存
1134
                            QMap<QString,SEARCH_INSTANCE_POS_STRUCTURE*>::iterator i = iinstancePosMap.begin();
1135
                            while(i != iinstancePosMap.end())
1136
                            {
1137
                                struct SEARCH_INSTANCE_POS_STRUCTURE *pinstanceSt = i.value();
1138
                                delete pinstanceSt ;
1139
                                ++i ;
1140
                            }
1141
                            iinstancePosMap.clear();
1142
                            close();
1143
                            return 1 ;
1144
                        }
1145
                        else
1146
                        {
1147
                            iparentTdiPort.append(tr("_EziDebug_%1_%2_TDI_reg").arg(pchain->getChainName()).arg(iparentClock));
1148
                            iparentTdoPort.append(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iparentClock));
1149
                        }
1150
 
1151
                        // 定义用于连接  例化新增端口的 wire
1152
                        if((chainStructuremap.value(iparentClock)->m_untotalChainNumber) > 1)
1153
                        {
1154
                            /*1、加入 定义 wire TDO 根据不同的 clock 定义的代码*/
1155
                            itdoWireDefinitionCode.append(tr("\n\t""wire [%1:0] _EziDebug_%2_%3_tdo%4 ;").arg(chainStructuremap.value(iparentClock)->m_untotalChainNumber-1).arg(pchain->getChainName()).arg(iparentClock).arg(nwireCount));
1156
                            itdoWire.append(tr("_EziDebug_%1_%2_tdo%3").arg(pchain->getChainName()).arg(iparentClock).arg(nwireCount));
1157
                            iaddedCodeList.append(tr("\\bwire\\s*") + tr("\\[\\s*%1\\s*:\\s*0\\s*\\]\\s*").arg(chainStructuremap.value(iparentClock)->m_untotalChainNumber-1) +tr("_EziDebug_%1_%2_tdo%3\\s*;").arg(pchain->getChainName()).arg(iparentClock).arg(nwireCount));
1158
                        }
1159
                        else
1160
                        {
1161
                            /*1、加入 定义 wire TDO 根据不同的 clock 定义的代码*/
1162
                            itdoWireDefinitionCode.append(tr("\n\t""wire _EziDebug_%1_%2_tdo%3 ;").arg(pchain->getChainName()).arg(iparentClock).arg(nwireCount));
1163
                            itdoWire.append(tr("_EziDebug_%1_%2_tdo%3").arg(pchain->getChainName()).arg(iparentClock).arg(nwireCount));
1164
                            iaddedCodeList.append(tr("\\bwire\\s+") +tr("_EziDebug_%1_%2_tdo%3\\s*;").arg(pchain->getChainName()).arg(iparentClock).arg(nwireCount));
1165
                        }
1166
 
1167
                        // 根据例化 书写格式  填入新增端口以及端口连接代码
1168
                        if(StardardForamt == pinstSt->m_einstanceFormat)
1169
                        {
1170
 
1171
                            /*判断 时钟 是否  对应  找到 并将 module 的 clock 的那个 TDI 与 端口 相连 */
1172
                            // 第一个 instance 的 tdi 与 module 对应 clock 的 tdi 相连 , tdo 与 下一个 instance 相连 或者  本module 自定义的  core 相连
1173
                            if(1 == nFirstnonCoreNum)
1174
                            {
1175
                                /*非最后1个 no libcore instance*/
1176
                                // 第一个 instance 的 tdi 与 module 对应 clock 的 tdi 相连 , tdo 与 下一个 instance
1177
                                QString iportName = tr(" ,\n\t""._EziDebug_%1_%2_TDI_reg(%3) ,\n\t""._EziDebug_%4_%5_TDO_reg(%6)")\
1178
                                        .arg(pchain->getChainName()).arg(p.key()).arg(iparentTdiPort).arg(pchain->getChainName()).arg(p.key()).arg(itdoWire);
1179
                                iinstanceCode.append(iportName);
1180
 
1181
 
1182
                                iinstanceExp.append(tr("\\s*,\\s*._EziDebug_%1_%2_TDI_reg\\s*\\(\\s*%3\\s*\\)").arg(pchain->getChainName()).arg(p.key()).arg(iparentTdiPort));
1183
                                iinstanceExp.append(tr("\\s*,\\s*._EziDebug_%1_%2_TDO_reg\\s*\\(\\s*%3\\s*\\)").arg(pchain->getChainName()).arg(p.key()).arg(itdoWire));
1184
                            }
1185
                            else
1186
                            {
1187
                                //第一个 instance 的 tdi 与 module 对应 clock 的 tdi 相连,本module 自定义的  core 相连
1188
                                // 其余的 instance 的 tdi 与 上一个 instance 的 tdo 相连 , tdo 与 下一个  instacne 相连 或者 本 module  自定义的 core 相连
1189
                                QString iportName = tr(" ,\n\t""._EziDebug_%1_%2_TDI_reg(%3) ,\n\t""._EziDebug_%4_%5_TDO_reg(%6)")\
1190
                                        .arg(pchain->getChainName()).arg(p.key()).arg(ilastTdoWire).arg(pchain->getChainName()).arg(p.key()).arg(itdoWire);
1191
                                iinstanceCode.append(iportName);
1192
 
1193
                                // TDI 和  上一个  例化的
1194
                                iinstanceExp.append(tr("\\s*,\\s*._EziDebug_%1_%2_TDI_reg\\s*\\(\\s*%3\\s*\\)").arg(pchain->getChainName()).arg(p.key()).arg(ilastTdoWire));
1195
                                iinstanceExp.append(tr("\\s*,\\s*._EziDebug_%1_%2_TDO_reg\\s*\\(\\s*%3\\s*\\)").arg(pchain->getChainName()).arg(p.key()).arg(itdoWire));
1196
 
1197
                            }
1198
 
1199
                        }
1200
                        else if(NonStardardFormat == pinstSt->m_einstanceFormat)
1201
                        {
1202
 
1203
                            // 第一个 instance 的 tdi 与 module 对应 clock 的 tdi 相连 , tdo 与 下一个 instance 相连 或者  本module 自定义的  core 相连
1204
                            // 其余的 instance 的 tdi 与 上一个 instance 的 tdo 相连 , tdo 与 下一个  instacne 相连 或者 本 module  自定义的 core 相连
1205
                            if(1 == nFirstnonCoreNum) // 原来 为 i ,本意为 第一个 非系统例化 i = 0 只能保证是第一个 例化(有可能为 第一个 为 系统例化  第二个为  非系统例化 但 第二个 的 tdi 需要 与 端口 tdi 相连)
1206
                            {
1207
                                QString iportName = tr(" , %1 , %2 ").arg(iparentTdiPort).arg(itdoWire) ;
1208
                                iinstanceCode.append(iportName);
1209
                                iportName.replace(" ","\\s*");
1210
                                iinstanceExp.append(iportName);
1211
                            }
1212
                            else
1213
                            {
1214
                                QString iportName = tr(" , %1 , %2 ").arg(ilastTdoWire).arg(itdoWire) ;
1215
                                iinstanceCode.append(iportName);
1216
                                iportName.replace(" ","\\s*");
1217
                                iinstanceExp.append(iportName);
1218
                            }
1219
                        }
1220
                        else
1221
                        {
1222
                            // 释放内存
1223
                            QMap<QString,SEARCH_INSTANCE_POS_STRUCTURE*>::iterator i = iinstancePosMap.begin();
1224
                            while(i != iinstancePosMap.end())
1225
                            {
1226
                                struct SEARCH_INSTANCE_POS_STRUCTURE *pinstanceSt = i.value();
1227
                                iinstancePosMap.remove(i.key());
1228
                                delete pinstanceSt ;
1229
                            }
1230
                            close();
1231
                            return 1 ;
1232
                        }
1233
 
1234
                        /*当到了最后1个非系统例化时  保存当前的的最后 1 根 tdo wire ,它需要与后面添加 EziDebug 自定义例化的 tdi相连 */
1235
                        if(nnonCoreNum == nnumberOfNoLibCore)
1236
                        {
1237
                            /*保存最后的 clock 与 wire名称 的对应关系*/
1238
                            pmodule->AddToClockWireNameMap(pchain->getChainName(),iparentClock,itdoWire);
1239
                        }
1240
 
1241
                        ++p ;
1242
                        //num++;
1243
                    }
1244
 
1245
                    if(StardardForamt == pinstSt->m_einstanceFormat)
1246
                    {
1247
                        iinstanceCode.append(tr(",\n\t""._EziDebug_%1_rstn(_EziDebug_%2_rstn)").arg(pchain->getChainName()).arg(pchain->getChainName())) ;
1248
                        iinstanceExp.append(tr("\\s*,\\s*._EziDebug_%1_rstn\\s*\\(\\s*_EziDebug_%2_rstn\\s*\\)").arg(pchain->getChainName()).arg(pchain->getChainName()));
1249
 
1250
                        iinstanceCode.append(tr(",\n\t""._EziDebug_%1_TOUT_reg(%2)").arg(pchain->getChainName()).arg(iparentToutPort)) ;
1251
                        iinstanceExp.append(tr("\\s*,\\s*._EziDebug_%1_TOUT_reg\\s*\\(\\s*%2\\s*\\)").arg(pchain->getChainName()).arg(iparentToutPort));
1252
                    }
1253
                    else
1254
                    {
1255
                        QString iportName = tr(", _EziDebug_%1_rstn , %2").arg(pchain->getChainName()).arg(iparentToutPort) ;
1256
                        iinstanceCode.append(iportName) ;
1257
                        iinstanceExp.append(tr("\\s*,\\s*_EziDebug_%1_rstn\\s*,\\s*%2").arg(pchain->getChainName()).arg(iparentToutPort));
1258
                    }
1259
 
1260
 
1261
                    iaddedCodeList.append(iinstanceExp);
1262
 
1263
                    ifileData.insert(pinstSt->m_nstartPos + noffSet,itdoWireDefinitionCode);
1264
                    noffSet += itdoWireDefinitionCode.size() ;
1265
                    ifileData.insert(pinstSt->m_nnextRightBracketPos + noffSet,iinstanceCode);
1266
                    noffSet += iinstanceCode.size() ;
1267
 
1268
 
1269
                    /*保存最后一根 Tdo 的 线 名称 */
1270
 
1271
 
1272
                    // 记录上一次的一根线的名字,用于下一次的连接
1273
                    ilastTdoWire = itdoWire ;
1274
                }
1275
                else
1276
                {
1277
                    QMap<QString,QString> iinstancePortMap = pmodule->getInstancePortMap(pchildItem->getInstanceName());
1278
 
1279
                    /*根据 系统core 子例化  加入代码:定义 寄存器 reg_n 代码、将输出端口信号载入寄存器代码  */
1280
                    /*从module 中 获得 所有的 输出端口(位宽、大小端) 及其 时钟名 、时钟跳变方向、*/
1281
                    QVector<EziDebugModule::PortStructure*> iportVec =  pchildModule->getPort(iprj,pchildItem->getInstanceName());
1282
                    int nportCount = 0 ;
1283
                    for(; nportCount < iportVec.count() ; nportCount++)
1284
                    {
1285
                        if((EziDebugModule::directionTypeOutput == iportVec.at(nportCount)->eDirectionType)||(EziDebugModule::directionTypeInoutput == iportVec.at(nportCount)->eDirectionType))
1286
                        {
1287
#if 0
1288
                            QString iportName = iinstancePortMap.value(QString::fromAscii(iportVec.at(nportCount)->m_pPortName),QString());
1289
                            if(iportName.isEmpty())
1290
                            {
1291
                                // 释放内存
1292
                                QMap<QString,SEARCH_INSTANCE_POS_STRUCTURE*>::iterator j = iinstancePosMap.begin();
1293
                                while(j != iinstancePosMap.end())
1294
                                {
1295
                                    struct SEARCH_INSTANCE_POS_STRUCTURE *pinstanceSt = j.value();
1296
                                    iinstancePosMap.remove(j.key());
1297
                                    delete pinstanceSt ;
1298
                                }
1299
                                goto ErrorHandle ;
1300
                            }
1301
#else
1302
                            QString iportName = QString::fromAscii(iportVec.at(nportCount)->m_pPortName)   ;
1303
                            QString icomPortName = pchildItem->getItemHierarchyName() + iportName ;
1304
#endif
1305
 
1306
                            if(iportVec.at(nportCount)->m_unBitwidth > 1)
1307
                            {
1308
                                iregDefinitionCode.append(tr("\n\t""reg [%1:%2] _EziDebug_%3_%4_r %5 ;").arg(iportVec.at(nportCount)->m_unStartBit).arg(iportVec.at(nportCount)->m_unEndBit).arg(pchain->getChainName()).arg(QString::fromAscii(iportVec.at(nportCount)->m_pPortName)).arg(inoSynCode));
1309
                                //isysCoreCode.append(iregDefinitionCode);
1310
                                iaddedCodeList.append(tr("\\breg\\s*\\[\\s*%1\\s*:\\s*%2\\s*\\]\\s*_EziDebug_%3_%4_r.+;").arg(iportVec.at(nportCount)->m_unStartBit).arg(iportVec.at(nportCount)->m_unEndBit).arg(pchain->getChainName()).arg(QString::fromAscii(iportVec.at(nportCount)->m_pPortName)));
1311
                            }
1312
                            else
1313
                            {
1314
                                iregDefinitionCode.append(tr("\n\t""reg _EziDebug_%1_%2_r %3 ;").arg(pchain->getChainName()).arg(QString::fromAscii(iportVec.at(nportCount)->m_pPortName)).arg(inoSynCode));
1315
                                //isysCoreCode.append(iregDefinitionCode);
1316
                                iaddedCodeList.append(tr("\\breg\\s+_EziDebug_%1_%2_r\\s*.+;").arg(pchain->getChainName()).arg(QString::fromAscii(iportVec.at(nportCount)->m_pPortName)));
1317
                            }
1318
 
1319
 
1320
                            QString iregName(tr("_EziDebug_%1_%2_r").arg(pchain->getChainName()).arg(QString::fromAscii(iportVec.at(nportCount)->m_pPortName))) ;
1321
 
1322
 
1323
                            QString iregWireName = ichildModulePortMap.value(QString::fromAscii(iportVec.at(nportCount)->m_pPortName),QString());
1324
 
1325
                            //qDebug() << "EziDebug info:sys core wire name:" << iregWireName ;
1326
                            if((iregWireName.isEmpty()|(QRegExp(tr("^\\d+$")).exactMatch(iregWireName.toLower()))\
1327
                                |(QRegExp(tr("^\\d+'[bhd][\\da-f]+$")).exactMatch(iregWireName.toLower()))\
1328
                                |(QRegExp(tr("^`[ho][\\da-f]+$")).exactMatch(iregWireName.toLower()))
1329
                                |(iregWireName.toLower()== "null")))
1330
                            {
1331
                                continue ;
1332
                            }
1333
 
1334
                            QStringList iportList ;
1335
                            iportList << pitem->getItemHierarchyName() << icomPortName  << iregName << QString::number(iportVec.at(nportCount)->m_unBitwidth)  ;
1336
 
1337
                            pchain->addToSyscoreOutputPortList(iportList.join(tr("#")));
1338
 
1339
 
1340
                            //iresetRegStr.append(tr("\n\t\t%1 <= 0 ;").arg(iregName));
1341
                            iresetRegStr.clear();
1342
                            ievaluateRegStr.append(tr("\n\t\t%1 <= %2 ;").arg(iregName).arg(iregWireName));
1343
 
1344
 
1345
                            if(m == 0)
1346
                            {
1347
                                iaddedBlockCodeList.append(tr("%1\\s*<=\\s*%2\\s*;").arg(iregName).arg(iregWireName));
1348
                            }
1349
                            m++ ;
1350
 
1351
                        }
1352
                    }
1353
                }
1354
            }
1355
 
1356
            if(!ievaluateRegStr.isEmpty())
1357
            {
1358
                isysCoreCode.append(iregDefinitionCode);
1359
                /*统一加入 寄存器 载入 代码块*/
1360
 
1361
                /*根据 pchain 中保存的  clock list 找到 与扫描端口的时钟 对应的本模块的时钟 */
1362
                if(iclockMap.count() == 1)
1363
                {
1364
                    QMap<QString,QString>::const_iterator iclockIterator = iclockMap.constBegin();
1365
                    while(iclockIterator != iclockMap.constEnd())
1366
                    {
1367
                        iclockString.append(tr("%1 %2").arg(QObject::tr("posedge")).arg(iclockIterator.key()));
1368
                        ++iclockIterator ;
1369
                    }
1370
                }
1371
                else
1372
                {
1373
                    close();
1374
                    return 1 ;
1375
                }
1376
 
1377
                QString iprocessCode ;
1378
 
1379
                iprocessCode.append((tr("\n\n\t""always@(%1)").arg(iclockString)));
1380
                iprocessCode.append(tr("\n\t""begin"));
1381
                iprocessCode.append(tr("%1").arg(ievaluateRegStr));
1382
                iprocessCode.append(tr("\n\t""end"));
1383
 
1384
 
1385
                /*保存删除代码信息*/
1386
                isysCoreCode.append(iprocessCode);
1387
            }
1388
            /*写入文件*/
1389
            ifileData.insert(imodulePos.m_nendModuleKeyWordPos + noffSet ,isysCoreCode);
1390
            noffSet += isysCoreCode.size() ;
1391
        }
1392
 
1393
 
1394
        // 释放内存
1395
        QMap<QString,SEARCH_INSTANCE_POS_STRUCTURE*>::iterator iinstanceIter = iinstancePosMap.begin();
1396
        while(iinstanceIter != iinstancePosMap.end())
1397
        {
1398
            struct SEARCH_INSTANCE_POS_STRUCTURE *pinstanceSt = iinstanceIter.value();
1399
            delete pinstanceSt ;
1400
            ++iinstanceIter;
1401
        }
1402
        iinstancePosMap.clear();
1403
 
1404
#if 0
1405
        if(fileName().endsWith("ifft.v"))
1406
        {
1407
            qDebug("add chain in ifft.v");
1408
        }
1409
#endif
1410
        int nwireShiftRegNum = 0 ;
1411
        int nlastChainStartNum = 0 ;
1412
        int nlastChainEndNum = 0 ;
1413
        int nchainStartNum = 0 ;
1414
        int nchainEndNum = 0 ;
1415
        int nusedNum = 0  ;
1416
        QVector<EziDebugModule::RegStructure*> sregVec ;
1417
        QVector<EziDebugModule::RegStructure*> vregVec ;
1418
        QString ilastInput ;
1419
 
1420
        QString iusrCoreCode ;
1421
 
1422
        // 遍历所有时钟 去添加相应时钟的扫描链
1423
        QMap<QString,QString>::const_iterator iclockIterator = iclockMap.constBegin();
1424
        while(iclockIterator != iclockMap.constEnd())
1425
        {
1426
            EziDebugInstanceTreeItem::SCAN_CHAIN_STRUCTURE* pchainSt = chainStructuremap.value(iclockIterator.key()) ;
1427
 
1428
            int nSregNum = 0 ;
1429
            int nVregNum = 0 ;
1430
 
1431
            // 已经添加的 EziDebug core 的个数
1432
            int ninstNum = pmodule->getEziDebugCoreCounts(pchain->getChainName()) ;
1433
            int nleftRegNum = 0 ;
1434
            int nregBitCount = 0 ;
1435
            int nleftBit = -1 ;
1436
            int nlastStopNum =  0 ;
1437
            int nRegNum = 0 ;
1438
            bool isNeedAdded = false ;
1439
            ilastInput.clear();
1440
 
1441
            if(!pmodule->getAllRegMap(iclockIterator.key(),sregVec,vregVec))
1442
            {
1443
                qDebug() << "EeziDebug Error: Insert Chain Error!";
1444
                return 1 ;
1445
            }
1446
 
1447
            // 没有寄存器 直接看 next clock 是否有 reg
1448
            if((!sregVec.count())&&(!vregVec.count()))
1449
            {
1450
                // 不用加任何代码 ,不用记录当前的 链号
1451
                ++iclockIterator ;
1452
                continue ;
1453
            }
1454
 
1455
            // 计算固定位宽所有寄存器的bit总合
1456
            int nregCount = 0 ;
1457
 
1458
            if(pchainSt->m_unleftRegNumber == 0)
1459
            {
1460
               pchainSt->m_unleftRegNumber =  iprj->getMaxRegNumPerChain() ;
1461
               pchainSt->m_uncurrentChainNumber++ ;
1462
            }
1463
 
1464
            // 起始bit位
1465
            nchainStartNum = pchainSt->m_uncurrentChainNumber ;
1466
 
1467
            // 获取 module在 chainxxx 的 加链情况 占用了 从 nlastChainStartNum 到 nlastChainEndNum 的链
1468
            pmodule->getBitRangeInChain(pchain->getChainName(),iclockIterator.key(),&nlastChainStartNum ,&nlastChainEndNum);
1469
 
1470
 
1471
            /*
1472
                 判断当前module是否单独例化(只有静态寄存器)
1473
                 YES
1474
                 {
1475
                    判断剩余的扫描链个数 是否够用,够用则在旧的扫描链上继续添加,
1476
                    不够则新创建一条扫描链继续添加
1477
                   (不够再添加新的扫描链 ,至到结束为止)(计算最后剩余的寄存器个数)
1478
                 }
1479
                 NO (可能同时存在 静态与动态的寄存器 添加方法是 先添加静态的寄存器 再添加动态的寄存器)
1480
                 {
1481
                    原则:由于多次例化,寄存器不能因为链的变化 在不同的例化中 放在了不同的链里面
1482
                        if(静态+动态 < 剩余寄存器链个数)
1483
                        {
1484
                            if(这次添加扫描链时和上一次的链相同 )
1485
                            {
1486
                               则只记录寄存器位置信息 不添加任何
1487
                            }
1488
                            // 所有的里面放  计算剩余的 扫描链寄存器个数
1489
                        }
1490
                        else
1491
                        {
1492
                            // 从新的扫描链 开始添加
1493
                        }
1494
                 }
1495
                 // 最终目的是保证代码的唯一性
1496
            */
1497
            if(!pmodule->getConstInstacedTimesPerChain(pchain->getChainName()))
1498
            {
1499
                qDebug() << "EziDebug Error: the module instance times error!";
1500
                return 1 ;
1501
            }
1502
 
1503
            if(pmodule->getConstInstacedTimesPerChain(pchain->getChainName()) == 1)
1504
            {
1505
AddReg:
1506
                // 只存在静态的寄存器
1507
                /*移位寄存器 赋值 代码*/
1508
                QStringList iregNameList ;
1509
                QVector<EziDebugModule::RegStructure*> iregVec = sregVec ;
1510
                QStringList iregCombinationCode ;
1511
 
1512
 
1513
                if(nleftBit != -1)
1514
                {
1515
                    int nlastLeftRegNum = qAbs(iregVec.at(nleftRegNum)->m_unEndBit - nleftBit) + 1 ;
1516
 
1517
                    QVector<EziDebugModule::RegStructure*> iregVec =  sregVec ;
1518
                    // 剩余的个数
1519
                    if(nlastLeftRegNum >= iprj->getMaxRegNumPerChain())
1520
                    {
1521
                        while(nlastLeftRegNum >= iprj->getMaxRegNumPerChain())
1522
                        {
1523
 
1524
                            ninstNum++ ;
1525
                            nwireCount++ ;
1526
                            iregCombinationCode.clear();
1527
                            iregNameList.clear();
1528
 
1529
                            // 定义 wire 连接 tdo 代码
1530
                            QString iwireTdoName(tr("_EziDebug_%1_%2_tdo%3").arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireCount));
1531
                            QString iwireTdoDefinitionCode(tr("\n\n\t""wire ")+ iwireTdoName + tr(" ;")) ;
1532
                            iusrCoreCode.append(iwireTdoDefinitionCode);
1533
                            iaddedCodeList.append(tr("\\bwire\\s+_EziDebug_%1_%2_tdo%3\\s*;")\
1534
                                                  .arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireCount));
1535
 
1536
                            // 定义 wire 连接 移位寄存器 代码
1537
                            QString iwireShiftRegDefinitionCode(tr("\n\t""wire ") + tr("[%1:0]").arg(iprj->getMaxRegNumPerChain()-1)+ tr("_EziDebug_%1_%2_sr%3")\
1538
                                                                .arg(pchain->getChainName()).arg(iclockIterator.key()).arg(ninstNum) + tr(" ;"));
1539
                            QString iwireSrName(tr("_EziDebug_%1_%2_sr%3").arg(pchain->getChainName()).arg(iclockIterator.key()).arg(ninstNum)) ;
1540
 
1541
                            iaddedCodeList.append(tr("\\bwire\\s*\\[\\s*%1:\\s*0\\s*\\]\\s*").arg(iprj->getMaxRegNumPerChain()-1)+tr("_EziDebug_%1_%2_sr%3\\s*;")\
1542
                                                  .arg(pchain->getChainName()).arg(iclockIterator.key()).arg(ninstNum));
1543
 
1544
                            iusrCoreCode.append(iwireShiftRegDefinitionCode);
1545
                            nwireShiftRegNum++ ;
1546
 
1547
                            /*移位寄存器 赋值 代码*/
1548
                            // int nendBit = nleftBit + iprj->getMaxRegNumPerChain() -1;
1549
                            int nendBit = 0 ;
1550
                            if(iregVec.at(nleftRegNum)->m_unRegNum > 1)
1551
                            {
1552
                                if(iregVec.at(nleftRegNum)->m_eRegNumEndian == EziDebugModule::endianBig)
1553
                                {
1554
                                    /*高:低*/
1555
                                    // iregVec.at(nleftRegNum)->m_unBitWidth-1
1556
                                    nendBit = nleftBit + 1 - iprj->getMaxRegNumPerChain() ;
1557
                                    iregNameList << constructChainRegString(iregVec.at(nleftRegNum) , nlastStopNum , nleftBit , nendBit , pitem);
1558
 
1559
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1]").arg(iregVec.at(nleftRegNum)->m_unStartNum - nlastStopNum)+tr("[%1:%2]").arg(nleftBit).arg(nendBit));
1560
 
1561
                                    nleftBit = nendBit - 1 ;
1562
                                }
1563
                                else
1564
                                {
1565
                                    /*低:高*/
1566
                                    nendBit = nleftBit -1 + iprj->getMaxRegNumPerChain() ;
1567
                                    iregNameList << constructChainRegString(iregVec.at(nleftRegNum) , nlastStopNum , nleftBit , nendBit , pitem);
1568
 
1569
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1]").arg(iregVec.at(nleftRegNum)->m_unStartNum + nlastStopNum)+tr("[%1:%2]").arg(nleftBit).arg(nendBit));
1570
 
1571
                                    nleftBit = nendBit + 1 ;
1572
                                }
1573
                            }
1574
                            else
1575
                            {
1576
                                if(iregVec.at(nleftRegNum)->m_eRegNumEndian == EziDebugModule::endianBig)
1577
                                {
1578
                                    /*高:低*/
1579
                                    nendBit = nleftBit + 1 - iprj->getMaxRegNumPerChain() ;
1580
                                    iregNameList << constructChainRegString(iregVec.at(nleftRegNum) , nlastStopNum , nleftBit , nendBit , pitem);
1581
 
1582
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1:%2]") \
1583
                                                               .arg(nleftBit).arg(nendBit));
1584
                                    nleftBit = nendBit - 1 ;
1585
                                }
1586
                                else
1587
                                {
1588
                                    /*低:高*/
1589
                                    nendBit = nleftBit -1 + iprj->getMaxRegNumPerChain() ;
1590
                                    iregNameList << constructChainRegString(iregVec.at(nleftRegNum) , nlastStopNum , nleftBit , nendBit , pitem);
1591
 
1592
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1:%2]")\
1593
                                                               .arg(nleftBit).arg(nendBit));
1594
 
1595
                                    nleftBit = nendBit + 1 ;
1596
                                }
1597
                            }
1598
 
1599
 
1600
                            ichainClock = pchain->getChainClock(pitem->getInstanceName(),iclockIterator.key());
1601
                            if(ichainClock.isEmpty())
1602
                            {
1603
                                qDebug() << "EziDebug Error: the top clock is not finded!" << __LINE__;
1604
                                return 2 ;
1605
                            }
1606
 
1607
                            pchain->addToRegChain(ichainClock ,pchainSt->m_uncurrentChainNumber ,iregNameList);
1608
 
1609
                            // 插入扫描链代码
1610
                            QString iwireShiftRegEvaluateString ;
1611
                            iwireShiftRegEvaluateString.append(tr("\n\t""assign %1 = {\n\t\t\t\t\t\t\t\t\t""%2""\n\t\t\t\t\t\t\t\t\t};").arg(iwireSrName).arg(iregCombinationCode.join(" ,\n\t\t\t\t\t\t\t\t\t")));
1612
                            iaddedCodeList.append(tr("\\bassign\\s+%1.*;").arg(iwireSrName));
1613
                            iusrCoreCode.append(iwireShiftRegEvaluateString);
1614
 
1615
                            /*自定义 core 例化代码 */
1616
                            QString iusrCoreDefinitionCode ;
1617
                            // QString iresetName = "1'b1";
1618
                            // _EziDebug_chn_rstn
1619
                            QString iresetName = tr("_EziDebug_%1_rstn").arg(pchain->getChainName());
1620
                            QString iusrCoreTdi ;
1621
                            if(nnumberOfNoLibCore != 0)
1622
                            {
1623
                                if((chainStructuremap.value(iclockIterator.key())->m_untotalChainNumber) > 1)
1624
                                {
1625
                                    iusrCoreTdi.append(tr("%1[%2]").arg(pmodule->getChainClockWireNameMap(pchain->getChainName(),iclockIterator.key())).arg(pchainSt->m_uncurrentChainNumber));
1626
                                }
1627
                                else
1628
                                {
1629
                                    iusrCoreTdi.append(tr("%1").arg(pmodule->getChainClockWireNameMap(pchain->getChainName(),iclockIterator.key())));
1630
                                }
1631
                            }
1632
                            else
1633
                            {
1634
                                if((chainStructuremap.value(iclockIterator.key())->m_untotalChainNumber) > 1)
1635
                                {
1636
                                    iusrCoreTdi.append(tr("_EziDebug_%1_%2_TDI_reg[%3]").arg(pchain->getChainName()).arg(iclockIterator.key()).arg(pchainSt->m_uncurrentChainNumber));
1637
                                }
1638
                                else
1639
                                {
1640
                                    iusrCoreTdi.append(tr("_EziDebug_%1_%2_TDI_reg").arg(pchain->getChainName()).arg(iclockIterator.key()));
1641
                                }
1642
                            }
1643
 
1644
                            iusrCoreDefinitionCode.append(tr("\n\t")+ EziDebugScanChain::getChainRegCore() + tr(" %1_%2_inst%3(\n").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum));
1645
                            iusrCoreDefinitionCode.append(  tr("\t"".clock""\t(%1) ,\n").arg(iclockIterator.key()) \
1646
                                                            + tr("\t"".resetn""\t(%1) ,\n").arg(iresetName) \
1647
                                                            + tr("\t"".TDI_reg""\t(%1) ,\n").arg(iusrCoreTdi) \
1648
                                                            + tr("\t"".TDO_reg""\t(%1) ,\n").arg(iwireTdoName) \
1649
                                                            + tr("\t"".TOUT_reg""\t(%1) ,\n").arg(iparentToutPort) \
1650
                                                            + tr("\t"".shift_reg""\t(%1) \n\t) ;").arg(iwireSrName));
1651
 
1652
                            /*加入 定义 userCore regWidth 限定的 语句代码*/
1653
                            QString iparameterDefCode ;
1654
                            iparameterDefCode.append(tr("\n\t""defparam %1_%2_inst%3.shift_width = %4 ;").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum).arg(iprj->getMaxRegNumPerChain()));
1655
                            iaddedCodeList.append(tr("\\bdefparam\\s+%1_%2_inst%3\\.shift_width\\s*=.*;").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum));
1656
                            iusrCoreCode.append(iparameterDefCode)  ;
1657
 
1658
                            iaddedCodeList.append(EziDebugScanChain::getChainRegCore() + tr("\\s+%1_%2_inst%3\\s*\\(.*\\)\\s*;").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum));
1659
 
1660
                            iusrCoreCode.append(iusrCoreDefinitionCode);
1661
 
1662
 
1663
                            /*module 端口连接代码*/
1664
 
1665
                            QString iportConnectCode ;
1666
                            // condition (chain number > 1) is true
1667
                            iportConnectCode.append(tr("\n\t""assign %1[%2] = %3 ;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
1668
                                                    .arg(pchainSt->m_uncurrentChainNumber).arg(iwireTdoName));
1669
                            iaddedCodeList.append(tr("\\bassign\\s+%1\\s*\\[\\s*%2\\s*\\].*;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
1670
                                                  .arg(pchainSt->m_uncurrentChainNumber));
1671
                            iusrCoreCode.append(iportConnectCode);
1672
 
1673
 
1674
                            nlastLeftRegNum = nlastLeftRegNum - iprj->getMaxRegNumPerChain();
1675
                            pchainSt->m_uncurrentChainNumber++ ;
1676
                            pchainSt->m_unleftRegNumber = iprj->getMaxRegNumPerChain() ;
1677
                        }
1678
                    } // REG n 大于 maxregnum 的部分 添加完毕
1679
 
1680
                    //  REG n 剩余 的部分
1681
                    iregCombinationCode.clear();
1682
                    iregNameList.clear();
1683
 
1684
                    if(iregVec.at(nleftRegNum)->m_eRegBitWidthEndian == EziDebugModule::endianBig)
1685
                    {
1686
                        if((nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) > 0)
1687
                        {
1688
                            pchainSt->m_unleftRegNumber -= (qAbs(nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) + 1) ;
1689
                            nregBitCount = (qAbs(nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) + 1) ;
1690
                            iregNameList << constructChainRegString(iregVec.at(nleftRegNum),nlastStopNum,nleftBit,iregVec.at(nleftRegNum)->m_unEndBit ,pitem);
1691
 
1692
                            iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName) + QObject::tr("[%1][%2:%3]").arg(iregVec.at(nleftRegNum)->m_unStartNum - nlastStopNum).arg(nleftBit).arg(iregVec.at(nleftRegNum)->m_unEndBit));
1693
                        }
1694
                        else if((nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) == 0)
1695
                        {
1696
                            pchainSt->m_unleftRegNumber -= (qAbs(nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) + 1) ;
1697
                            nregBitCount = (qAbs(nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) + 1) ;
1698
                            iregNameList << constructChainRegString(iregVec.at(nleftRegNum),nlastStopNum,nleftBit,iregVec.at(nleftRegNum)->m_unEndBit ,pitem);
1699
 
1700
                            iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+QObject::tr("[%1][0]").arg(iregVec.at(nleftRegNum)->m_unStartNum - nlastStopNum));
1701
                        }
1702
                        else
1703
                        {
1704
                            // 上面已经加完了
1705
                        }
1706
 
1707
                    }
1708
                    else
1709
                    {
1710
                        if((iregVec.at(nleftRegNum)->m_unEndBit - nleftBit) > 0) // 剩大于1bit
1711
                        {
1712
                            pchainSt->m_unleftRegNumber -= (qAbs(nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) + 1) ;
1713
                            nregBitCount = (qAbs(nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) + 1) ;
1714
                            iregNameList << constructChainRegString(iregVec.at(nleftRegNum),nlastStopNum,nleftBit,iregVec.at(nleftRegNum)->m_unEndBit ,pitem);
1715
 
1716
                            iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName) + QObject::tr("[%1][%2:%3]").arg(iregVec.at(nleftRegNum)->m_unStartNum + nlastStopNum).arg(nleftBit).arg(iregVec.at(nleftRegNum)->m_unEndBit));
1717
                        }
1718
                        else if((iregVec.at(nleftRegNum)->m_unEndBit - nleftBit) == 0) // 剩1bit
1719
                        {
1720
                            pchainSt->m_unleftRegNumber -= (qAbs(nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) + 1) ;
1721
                            nregBitCount = (qAbs(nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) + 1) ;
1722
                            iregNameList << constructChainRegString(iregVec.at(nleftRegNum),nlastStopNum,nleftBit,iregVec.at(nleftRegNum)->m_unEndBit ,pitem);
1723
 
1724
                            iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1][0]").arg(iregVec.at(nleftRegNum)->m_unStartNum + nlastStopNum));
1725
                        }
1726
                        else
1727
                        {
1728
                            // 已经加完
1729
                        }
1730
                    }
1731
 
1732
 
1733
 
1734
                    if(iregVec.at(nleftRegNum)->m_unRegNum > 1)
1735
                    {
1736
                        nlastStopNum++ ;
1737
                    }
1738
                    else
1739
                    {
1740
                        nleftRegNum++ ;
1741
                        nlastStopNum = 0 ;
1742
                    }
1743
 
1744
                    nleftBit = -1 ;
1745
                }
1746
                else
1747
                {
1748
                    nregBitCount = 0 ;
1749
                }
1750
 
1751
 
1752
                for(; nleftRegNum < iregVec.count() ; nleftRegNum++)
1753
                {
1754
                    for(int m = nlastStopNum ; m < iregVec.at(nleftRegNum)->m_unRegNum; m++)
1755
                    {
1756
                        nregBitCount += iregVec.at(nleftRegNum)->m_unRegBitWidth ;
1757
 
1758
                        if(nregBitCount < pchainSt->m_unleftRegNumber)
1759
                        {
1760
                            /*数组情况下*/
1761
                            // 够用继续添加
1762
                            if(iregVec.at(nleftRegNum)->m_unRegNum > 1)
1763
                            {
1764
                                if(iregVec.at(nleftRegNum)->m_eRegNumEndian == EziDebugModule::endianBig)
1765
                                {
1766
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1]").arg(iregVec.at(nleftRegNum)->m_unStartNum - m));
1767
                                }
1768
                                else
1769
                                {
1770
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1]").arg(iregVec.at(nleftRegNum)->m_unStartNum + m));
1771
                                }
1772
                            }
1773
                            else
1774
                            {
1775
                                iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName));
1776
                            }
1777
 
1778
                            iregNameList << constructChainRegString(iregVec.at(nleftRegNum),m,iregVec.at(nleftRegNum)->m_unStartBit,iregVec.at(nleftRegNum)->m_unEndBit ,pitem);
1779
                        }
1780
                        else if(nregBitCount == pchainSt->m_unleftRegNumber)
1781
                        {
1782
                            // 刚好满  跳出  下次新的扫描链继续 添加
1783
                            if(iregVec.at(nleftRegNum)->m_unRegNum > 1)
1784
                            {
1785
                                if(iregVec.at(nleftRegNum)->m_eRegNumEndian == EziDebugModule::endianBig)
1786
                                {
1787
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1]").arg(iregVec.at(nleftRegNum)->m_unStartNum - m));
1788
                                }
1789
                                else
1790
                                {
1791
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1]").arg(iregVec.at(nleftRegNum)->m_unStartNum + m));
1792
                                }
1793
                            }
1794
                            else
1795
                            {
1796
                                iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName));
1797
                            }
1798
 
1799
                            iregNameList << constructChainRegString(iregVec.at(nleftRegNum),m,iregVec.at(nleftRegNum)->m_unStartBit,iregVec.at(nleftRegNum)->m_unEndBit,pitem);
1800
 
1801
                            nlastStopNum = m ;
1802
                            // nleftBit = -1 ;
1803
                            nleftRegNum++ ;
1804
                            isNeedAdded = true ;
1805
 
1806
 
1807
                            goto WireShiftRegEvaluate0 ;
1808
                        }
1809
                        else
1810
                        {
1811
                            if(iregVec.at(nleftRegNum)->m_unRegNum > 1)
1812
                            {
1813
 
1814
                                if(iregVec.at(nleftRegNum)->m_eRegNumEndian == EziDebugModule::endianBig)
1815
                                {
1816
                                    int nstartBit = iregVec.at(nleftRegNum)->m_unStartBit ;
1817
                                    int nendBit = nregBitCount- pchainSt->m_unleftRegNumber + iregVec.at(nleftRegNum)->m_unStartBit + 1 - iregVec.at(nleftRegNum)->m_unRegBitWidth ;
1818
                                    nleftBit = nendBit - 1 ;
1819
                                    iregNameList << constructChainRegString(iregVec.at(nleftRegNum),m,nstartBit,nendBit,pitem);
1820
 
1821
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1]").arg(iregVec.at(nleftRegNum)->m_unStartNum - m)+tr("[%1:%2]").arg(nstartBit).arg(nendBit));
1822
                                }
1823
                                else
1824
                                {
1825
                                    int nstartBit = iregVec.at(nleftRegNum)->m_unStartBit ;
1826
                                    int nendBit = iregVec.at(nleftRegNum)->m_unRegBitWidth + iregVec.at(nleftRegNum)->m_unStartBit - 1 - (nregBitCount- pchainSt->m_unleftRegNumber) ;
1827
                                    nleftBit = nendBit + 1 ;
1828
                                    iregNameList << constructChainRegString(iregVec.at(nleftRegNum),m,nstartBit,nendBit,pitem);
1829
 
1830
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1]").arg(iregVec.at(nleftRegNum)->m_unStartNum + m)+tr("[%1:%2]").arg(nstartBit).arg(nendBit));
1831
                                }
1832
                            }
1833
                            else
1834
                            {
1835
                                if(iregVec.at(nleftRegNum)->m_eRegNumEndian == EziDebugModule::endianBig)
1836
                                {
1837
                                    int nstartBit = iregVec.at(nleftRegNum)->m_unStartBit ;
1838
                                    int nendBit = nregBitCount- pchainSt->m_unleftRegNumber + iregVec.at(nleftRegNum)->m_unStartBit + 1 - iregVec.at(nleftRegNum)->m_unRegBitWidth ;
1839
                                    nleftBit = nendBit - 1 ;
1840
                                    iregNameList << constructChainRegString(iregVec.at(nleftRegNum),m,nstartBit,nendBit,pitem);
1841
 
1842
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1:%2]") \
1843
                                                               .arg(nstartBit).arg(nendBit));
1844
                                }
1845
                                else
1846
                                {
1847
                                    int nstartBit = iregVec.at(nleftRegNum)->m_unStartBit ;
1848
                                    int nendBit = iregVec.at(nleftRegNum)->m_unRegBitWidth + iregVec.at(nleftRegNum)->m_unStartBit - 1 - (nregBitCount- pchainSt->m_unleftRegNumber) ;
1849
                                    nleftBit = nendBit + 1 ;
1850
                                    iregNameList << constructChainRegString(iregVec.at(nleftRegNum),m,nstartBit,nendBit,pitem);
1851
 
1852
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1:%2]")\
1853
                                                               .arg(nstartBit).arg(nendBit));
1854
                                }
1855
                            }
1856
 
1857
                            nlastStopNum = m ;
1858
                            isNeedAdded = true ;
1859
                            goto WireShiftRegEvaluate0 ;
1860
                        }
1861
                    }
1862
                    nlastStopNum = 0 ;
1863
                }
1864
WireShiftRegEvaluate0:
1865
 
1866
 
1867
 
1868
                if(iregNameList.count())
1869
                {
1870
 
1871
                    ichainClock = pchain->getChainClock(pitem->getInstanceName(),iclockIterator.key());
1872
 
1873
                    if(ichainClock.isEmpty())
1874
                    {
1875
                        return 2 ;
1876
                    }
1877
 
1878
                    if(isNeedAdded == true)
1879
                    {
1880
                        nusedNum =  pchainSt->m_unleftRegNumber ;
1881
                    }
1882
                    else
1883
                    {
1884
                        nusedNum = nregBitCount ;
1885
                    }
1886
 
1887
                    pchain->addToRegChain(ichainClock,pchainSt->m_uncurrentChainNumber,iregNameList);
1888
 
1889
                    nwireCount++ ;
1890
                    // 定义 wire 连接 tdo 代码
1891
                    QString iwireTdoName(tr("_EziDebug_%1_%2_tdo%3").arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireCount));
1892
                    QString iwireTdoDefinitionCode(tr("\n\n\t""wire ")+ iwireTdoName + tr(" ;")) ;
1893
                    iusrCoreCode.append(iwireTdoDefinitionCode);
1894
                    iaddedCodeList.append(tr("\\bwire\\s+_EziDebug_%1_%2_tdo%3\\s*;")\
1895
                                          .arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireCount));
1896
 
1897
                    // 定义 wire 连接 移位寄存器 代码
1898
                    QString iwireShiftRegDefinitionCode(tr("\n\t""wire ") + tr("[%1:0] ").arg(nusedNum-1) + tr("_EziDebug_%1_%2_sr%3")\
1899
                                                        .arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireShiftRegNum) + tr(" ;"));
1900
                    QString iwireSrName(tr("_EziDebug_%1_%2_sr%3").arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireShiftRegNum)) ;
1901
 
1902
                    iaddedCodeList.append(tr("\\bwire\\s*\\[\\s*%1\\s*:\\s*0\\s*\\]\\s*").arg(nusedNum-1) + tr("_EziDebug_%1_%2_sr%3\\s*;")\
1903
                                          .arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireShiftRegNum));
1904
 
1905
                    iusrCoreCode.append(iwireShiftRegDefinitionCode);
1906
                    nwireShiftRegNum++ ;
1907
 
1908
                    //pchain->addToRegChain(ichainClock,pchainSt->m_uncurrentChainNumber,iregNameList);
1909
 
1910
                    QString iwireShiftRegEvaluateString ;
1911
                    iwireShiftRegEvaluateString.append(tr("\n\t""assign %1 = {\n\t\t\t\t\t\t\t\t\t""%2""\n\t\t\t\t\t\t\t\t\t};").arg(iwireSrName).arg(iregCombinationCode.join(" ,\n\t\t\t\t\t\t\t\t\t")));
1912
                    iaddedCodeList.append(tr("\\bassign\\s+%1.*;").arg(iwireSrName));
1913
                    iusrCoreCode.append(iwireShiftRegEvaluateString);
1914
 
1915
 
1916
                    /*自定义 core 例化代码 */
1917
                    QString iusrCoreDefinitionCode ;
1918
                    //QString iresetName = "1'b1";
1919
                    QString iresetName = tr("_EziDebug_%1_rstn").arg(pchain->getChainName());
1920
 
1921
 
1922
                    QString iusrCoreTdi ;
1923
                    if(nnumberOfNoLibCore != 0)
1924
                    {
1925
                        if((chainStructuremap.value(iclockIterator.key())->m_untotalChainNumber) > 1)
1926
                        {
1927
                            iusrCoreTdi.append(tr("%1[%2]").arg(pmodule->getChainClockWireNameMap(pchain->getChainName(),iclockIterator.key())).arg(pchainSt->m_uncurrentChainNumber));
1928
                        }
1929
                        else
1930
                        {
1931
                            iusrCoreTdi.append(tr("%1").arg(pmodule->getChainClockWireNameMap(pchain->getChainName(),iclockIterator.key())));
1932
                        }
1933
                    }
1934
                    else
1935
                    {
1936
                        if((chainStructuremap.value(iclockIterator.key())->m_untotalChainNumber) > 1)
1937
                        {
1938
                            iusrCoreTdi.append(tr("_EziDebug_%1_%2_TDI_reg[%3]").arg(pchain->getChainName()).arg(iclockIterator.key()).arg(pchainSt->m_uncurrentChainNumber));
1939
                        }
1940
                        else
1941
                        {
1942
                            iusrCoreTdi.append(tr("_EziDebug_%1_%2_TDI_reg").arg(pchain->getChainName()).arg(iclockIterator.key()));
1943
                        }
1944
                    }
1945
 
1946
                    iusrCoreDefinitionCode.append(tr("\n\t")+ EziDebugScanChain::getChainRegCore() + tr(" %1_%2_inst%3(\n").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum));
1947
                    iusrCoreDefinitionCode.append(  tr("\t"".clock""\t(%1) ,\n").arg(iclockIterator.key()) \
1948
                                                    + tr("\t"".resetn""\t(%1) ,\n").arg(iresetName) \
1949
                                                    + tr("\t"".TDI_reg""\t(%1) ,\n").arg(iusrCoreTdi) \
1950
                                                    + tr("\t"".TDO_reg""\t(%1) ,\n").arg(iwireTdoName) \
1951
                                                    + tr("\t"".TOUT_reg""\t(%1) ,\n").arg(iparentToutPort) \
1952
                                                    + tr("\t"".shift_reg""\t(%1) \n\t) ;").arg(iwireSrName));
1953
 
1954
 
1955
                    /*加入 定义 userCore regWidth 限定的 语句代码*/
1956
                    QString iparameterDefCode ;
1957
                    iparameterDefCode.append(tr("\n\n\t""defparam %1_%2_inst%3.shift_width = %4 ;").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum).arg(nusedNum));
1958
                    iaddedCodeList.append(tr("\\bdefparam\\s+%1_%2_inst%3\\.shift_width\\s*=.*;").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum));
1959
 
1960
                    iusrCoreCode.append(iparameterDefCode)  ;
1961
                    iaddedCodeList.append(EziDebugScanChain::getChainRegCore() + tr("\\s+%1_%2_inst%3\\s*(.*)\\s*;").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum));
1962
 
1963
                    iusrCoreCode.append(iusrCoreDefinitionCode);
1964
 
1965
                    /*module 端口连接代码*/
1966
                    QString iportConnectCode ;
1967
                    if((chainStructuremap.value(iclockIterator.key())->m_untotalChainNumber) > 1)
1968
                    {
1969
                        iportConnectCode.append(tr("\n\t""assign %1[%2] = %3 ;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
1970
                                                .arg(pchainSt->m_uncurrentChainNumber).arg(iwireTdoName));
1971
                        iaddedCodeList.append(tr("\\bassign\\s+%1\\s*\\[\\s*%2\\s*\\].*;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
1972
                                              .arg(pchainSt->m_uncurrentChainNumber));
1973
                    }
1974
                    else
1975
                    {
1976
                        iportConnectCode.append(tr("\n\t""assign %1 = %2 ;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
1977
                                                .arg(iwireTdoName));
1978
                        iaddedCodeList.append(tr("\\bassign\\s+%1\\s*=\\s*%2\\s*;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
1979
                                              .arg(iwireTdoName));
1980
                    }
1981
                    iusrCoreCode.append(iportConnectCode);
1982
                }
1983
 
1984
 
1985
                if(isNeedAdded == true)
1986
                {
1987
                    pchainSt->m_uncurrentChainNumber++ ;
1988
                    pchainSt->m_unleftRegNumber = iprj->getMaxRegNumPerChain() ;
1989
                    isNeedAdded = false ;
1990
                }
1991
                else
1992
                {
1993
                    pchainSt->m_unleftRegNumber -= nregBitCount ;
1994
                }
1995
 
1996
                if(nleftRegNum != iregVec.count())
1997
                {
1998
                    goto AddReg ;
1999
                }
2000
 
2001
            }
2002
            else
2003
            {
2004
                // 肯定为多次例化的 模块
2005
                for(;nregCount < sregVec.count(); nregCount++)
2006
                {
2007
                    EziDebugModule::RegStructure* preg =  sregVec.at(nregCount) ;
2008
                    nSregNum += preg->m_unMaxBitWidth ;
2009
                }
2010
 
2011
                nregCount = 0 ;
2012
 
2013
                for(;nregCount < vregVec.count();nregCount++)
2014
                {
2015
                    EziDebugModule::RegStructure* preg = vregVec.at(nregCount) ;
2016
                    nVregNum += preg->m_unMaxBitWidth ;
2017
                }
2018
 
2019
 
2020
                //
2021
                if((nSregNum + nVregNum) < pchainSt->m_unleftRegNumber)
2022
                {
2023
                    QStringList iregNameList ;
2024
                    QStringList iregCombinationCode ;
2025
 
2026
 
2027
                    QVector<EziDebugModule::RegStructure*> iregVec = sregVec ;
2028
                    nleftRegNum = 0 ;
2029
                    int nstaticRegBitSum = 0 ;
2030
                    for(; nleftRegNum < iregVec.count() ; nleftRegNum++)
2031
                    {
2032
                        for(int m = 0 ; m < iregVec.at(nleftRegNum)->m_unRegNum ; m++)
2033
                        {
2034
                            EziDebugModule::RegStructure* preg = sregVec.at(nleftRegNum)  ;
2035
 
2036
                            nstaticRegBitSum += preg->m_unRegBitWidth ;
2037
                            nRegNum += preg->m_unRegBitWidth ;
2038
 
2039
                            // reg pointer regnum  startbit  endbit  hiberarchyname
2040
                            if(preg->m_eRegNumEndian)
2041
                            {
2042
                                iregNameList << constructChainRegString(preg,iregVec.at(nleftRegNum)->m_unStartNum - m , preg->m_unStartBit , preg->m_unEndBit ,pitem);
2043
                                if(preg->m_unRegNum != 1)
2044
                                {
2045
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName) + tr("[%1]")\
2046
                                                               .arg(iregVec.at(nleftRegNum)->m_unStartNum - m));
2047
                                }
2048
                                else
2049
                                {
2050
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName));
2051
                                }
2052
                            }
2053
                            else
2054
                            {
2055
                                iregNameList << constructChainRegString(preg,iregVec.at(nleftRegNum)->m_unStartNum + m , preg->m_unStartBit , preg->m_unEndBit ,pitem);
2056
                                if(preg->m_unRegNum != 1)
2057
                                {
2058
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1]")\
2059
                                                               .arg(iregVec.at(nleftRegNum)->m_unStartNum + m));
2060
                                }
2061
                                else
2062
                                {
2063
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName));
2064
                                }
2065
                            }
2066
 
2067
                        }
2068
                    }
2069
 
2070
                    QString ivarRegBitSum ;
2071
                    if(nstaticRegBitSum)
2072
                    {
2073
                        ivarRegBitSum =  QString::number(nstaticRegBitSum) ;
2074
                    }
2075
                    nleftRegNum = 0 ;
2076
 
2077
                    iregVec = vregVec ;
2078
 
2079
                    for(; nleftRegNum < iregVec.count() ; nleftRegNum++)
2080
                    {
2081
                        EziDebugModule::RegStructure* pvarReg = iregVec.at(nleftRegNum) ;
2082
                        // 确切地定值 有 instancereg 提供
2083
                        EziDebugModule::RegStructure* pinstanceReg = pmodule->getInstanceReg(pitem->getInstanceName(),iclockIterator.key(),QString::fromAscii(pvarReg->m_pRegName));
2084
                        nRegNum += pvarReg->m_unMaxBitWidth ;
2085
                        // construct the bitwidth string
2086
                        if(pinstanceReg->m_unRegNum == 1)
2087
                        {
2088
                            ivarRegBitSum.append(QObject::tr("+") + QString::fromAscii(pvarReg->m_pExpString));
2089
                        }
2090
                        else
2091
                        {
2092
                            ivarRegBitSum.append(QObject::tr("+") + QObject::tr("(%1)*%2").arg(QString::fromAscii(pvarReg->m_pExpString)).arg(pinstanceReg->m_unRegNum));
2093
                        }
2094
                         // iprefixStr
2095
                        for(int m = 0 ; m < pinstanceReg->m_unRegNum ; m++)
2096
                        {
2097
 
2098
                            if(pinstanceReg->m_eRegNumEndian == EziDebugModule::endianBig)
2099
                            {
2100
                                iregNameList << constructChainRegString(pinstanceReg,pinstanceReg->m_unStartNum - m , pinstanceReg->m_unStartBit , pinstanceReg->m_unEndBit ,pitem);
2101
                                if(pinstanceReg->m_unRegNum != 1)
2102
                                {
2103
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName) + tr("[%1]")\
2104
                                                               .arg(iregVec.at(nleftRegNum)->m_unStartNum - m));
2105
                                }
2106
                                else
2107
                                {
2108
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName));
2109
                                }
2110
                            }
2111
                            else
2112
                            {
2113
                                iregNameList << constructChainRegString(pinstanceReg,pinstanceReg->m_unStartNum + m , pinstanceReg->m_unStartBit , pinstanceReg->m_unEndBit ,pitem);
2114
                                if(pinstanceReg->m_unRegNum != 1)
2115
                                {
2116
                                    iregCombinationCode.append( QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName) + tr("[%1]")\
2117
                                                               .arg(iregVec.at(nleftRegNum)->m_unStartNum - m));
2118
                                }
2119
                                else
2120
                                {
2121
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName));
2122
                                }
2123
                            }
2124
                        }
2125
 
2126
                    }
2127
 
2128
                    ichainClock = pchain->getChainClock(pitem->getInstanceName(),iclockIterator.key());
2129
 
2130
                    if(ichainClock.isEmpty())
2131
                    {
2132
                        return 2 ;
2133
                    }
2134
 
2135
                    pchain->addToRegChain(ichainClock,pchainSt->m_uncurrentChainNumber,iregNameList);
2136
 
2137
 
2138
                    // 不用添加 新的代码
2139
                    pchainSt->m_unleftRegNumber = pchainSt->m_unleftRegNumber - nRegNum ;
2140
 
2141
                    if(nchainStartNum == nlastChainEndNum) // 不用添加 新的代码,都在同一条扫描链中 且 剩余链寄存器够用
2142
                    {
2143
                        ++iclockIterator ;
2144
                        continue ;
2145
                    }
2146
 
2147
                    // defparameter 和 定义移位寄存器宽度 都为 字符串类型 非完全数字(如果存在变化位宽的寄存器的话)
2148
                    // 加入的 ezidebug core 的 tdi 根据 前面是否存在 非系统core 连接 模块端口的 tdi 或者 定义的
2149
                    // 非系统core 的 最后一根tdo_wire
2150
                    // ezidebug core 的tdo 根据是否为最后1次添加代码 与 lastwire 相连 或者 端口的 tdo 相连
2151
                    // 连接 这次添加链的 起始bit 与 上一次最后bit 之间的 连接  assign
2152
 
2153
                    nwireCount++ ;
2154
                    // 定义 wire 连接 tdo 代码
2155
                    QString iwireTdoName(tr("_EziDebug_%1_%2_tdo%3").arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireCount));
2156
                    QString iwireTdoDefinitionCode(tr("\n\n\t""wire ")+ iwireTdoName + tr(" ;")) ;
2157
                    iusrCoreCode.append(iwireTdoDefinitionCode);
2158
                    iaddedCodeList.append(tr("\\bwire\\s+_EziDebug_%1_%2_tdo%3\\s*;")\
2159
                                          .arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireCount));
2160
 
2161
 
2162
                    // 定义 wire 连接 移位寄存器 代码
2163
                    QString iwireShiftRegDefinitionCode(tr("\n\t""wire ") + tr("[%1:0] ").arg(ivarRegBitSum + tr(" - 1")) + tr("_EziDebug_%1_%2_sr%3")\
2164
                                                        .arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireShiftRegNum) + tr(" ;"));
2165
                    QString iwireSrName(tr("_EziDebug_%1_%2_sr%3").arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireShiftRegNum)) ;
2166
 
2167
                    iaddedCodeList.append(tr("\\bwire\\s*\\[\\s*%1\\s*:\\s*0\\s*\\]\\s*").arg(ivarRegBitSum + tr(" - 1")) + tr("_EziDebug_%1_%2_sr%3\\s*;")\
2168
                                          .arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireShiftRegNum));
2169
 
2170
                    iusrCoreCode.append(iwireShiftRegDefinitionCode);
2171
                    nwireShiftRegNum++ ;
2172
 
2173
                    //pchain->addToRegChain(ichainClock,pchainSt->m_uncurrentChainNumber,iregNameList);
2174
 
2175
                    QString iwireShiftRegEvaluateString ;
2176
                    iwireShiftRegEvaluateString.append(tr("\n\t""assign %1 = {\n\t\t\t\t\t\t\t\t\t""%2""\n\t\t\t\t\t\t\t\t\t};").arg(iwireSrName).arg(iregCombinationCode.join(" ,\n\t\t\t\t\t\t\t\t\t")));
2177
                    iaddedCodeList.append(tr("\\bassign\\s+%1.*;").arg(iwireSrName));
2178
                    iusrCoreCode.append(iwireShiftRegEvaluateString);
2179
 
2180
 
2181
                    /*自定义 core 例化代码 */
2182
                    QString iusrCoreDefinitionCode ;
2183
                    //QString iresetName = "1'b1";
2184
                    QString iresetName = tr("_EziDebug_%1_rstn").arg(pchain->getChainName());
2185
 
2186
 
2187
                    QString iusrCoreTdi ;
2188
                    if(nnumberOfNoLibCore != 0)
2189
                    {
2190
                        if((chainStructuremap.value(iclockIterator.key())->m_untotalChainNumber) > 1)
2191
                        {
2192
                            iusrCoreTdi.append(tr("%1[%2]").arg(pmodule->getChainClockWireNameMap(pchain->getChainName(),iclockIterator.key())).arg(pchainSt->m_uncurrentChainNumber));
2193
                        }
2194
                        else
2195
                        {
2196
                            iusrCoreTdi.append(tr("%1").arg(pmodule->getChainClockWireNameMap(pchain->getChainName(),iclockIterator.key())));
2197
                        }
2198
                    }
2199
                    else
2200
                    {
2201
                        if((chainStructuremap.value(iclockIterator.key())->m_untotalChainNumber) > 1)
2202
                        {
2203
                            iusrCoreTdi.append(tr("_EziDebug_%1_%2_TDI_reg[%3]").arg(pchain->getChainName()).arg(iclockIterator.key()).arg(pchainSt->m_uncurrentChainNumber));
2204
                        }
2205
                        else
2206
                        {
2207
                            iusrCoreTdi.append(tr("_EziDebug_%1_%2_TDI_reg").arg(pchain->getChainName()).arg(iclockIterator.key()));
2208
                        }
2209
                    }
2210
 
2211
                    iusrCoreDefinitionCode.append(tr("\n\t")+ EziDebugScanChain::getChainRegCore() + tr(" %1_%2_inst%3(\n").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum));
2212
                    iusrCoreDefinitionCode.append(  tr("\t"".clock""\t(%1) ,\n").arg(iclockIterator.key()) \
2213
                                                    + tr("\t"".resetn""\t(%1) ,\n").arg(iresetName) \
2214
                                                    + tr("\t"".TDI_reg""\t(%1) ,\n").arg(iusrCoreTdi) \
2215
                                                    + tr("\t"".TDO_reg""\t(%1) ,\n").arg(iwireTdoName) \
2216
                                                    + tr("\t"".TOUT_reg""\t(%1) ,\n").arg(iparentToutPort) \
2217
                                                    + tr("\t"".shift_reg""\t(%1) \n\t) ;").arg(iwireSrName));
2218
 
2219
 
2220
                    /*加入 定义 userCore regWidth 限定的 语句代码*/
2221
                    QString iparameterDefCode ;
2222
                    iparameterDefCode.append(tr("\n\n\t""defparam %1_%2_inst%3.shift_width = %4 ;").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum).arg(ivarRegBitSum));
2223
                    iaddedCodeList.append(tr("\\bdefparam\\s+%1_%2_inst%3\\.shift_width\\s*=.*;").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum));
2224
 
2225
                    iusrCoreCode.append(iparameterDefCode)  ;
2226
                    iaddedCodeList.append(EziDebugScanChain::getChainRegCore() + tr("\\s+%1_%2_inst%3\\s*(.*)\\s*;").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum));
2227
 
2228
                    iusrCoreCode.append(iusrCoreDefinitionCode);
2229
 
2230
                    /*module 端口连接代码*/
2231
                    QString iportConnectCode ;
2232
                    if((chainStructuremap.value(iclockIterator.key())->m_untotalChainNumber) > 1)
2233
                    {
2234
                        iportConnectCode.append(tr("\n\t""assign %1[%2] = %3 ;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
2235
                                                .arg(pchainSt->m_uncurrentChainNumber).arg(iwireTdoName));
2236
                        iaddedCodeList.append(tr("\\bassign\\s+%1\\s*\\[\\s*%2\\s*\\].*;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
2237
                                              .arg(pchainSt->m_uncurrentChainNumber));
2238
                    }
2239
                    else
2240
                    {
2241
                        iportConnectCode.append(tr("\n\t""assign %1 = %2 ;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
2242
                                                .arg(iwireTdoName));
2243
                        iaddedCodeList.append(tr("\\bassign\\s+%1\\s*=\\s*%2\\s*;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
2244
                                              .arg(iwireTdoName));
2245
                    }
2246
                    iusrCoreCode.append(iportConnectCode);
2247
                }
2248
                else
2249
                {
2250
                    // 从新的扫描链 开始添加
2251
                    pchainSt->m_uncurrentChainNumber++ ;
2252
                    pchainSt->m_unleftRegNumber = iprj->getMaxRegNumPerChain() ;
2253
 
2254
AddReg1:
2255
                    // 只存在静态的寄存器
2256
                    /*移位寄存器 赋值 代码*/
2257
                    QStringList iregNameList ;
2258
                    QVector<EziDebugModule::RegStructure*> iregVec = sregVec ;
2259
                    QStringList iregCombinationCode ;
2260
 
2261
 
2262
                    if(nleftBit != -1)
2263
                    {
2264
                        int nlastLeftRegNum = qAbs(iregVec.at(nleftRegNum)->m_unEndBit - nleftBit) + 1 ;
2265
 
2266
                        QVector<EziDebugModule::RegStructure*> iregVec =  sregVec ;
2267
                        // 剩余的个数
2268
                        if(nlastLeftRegNum >= iprj->getMaxRegNumPerChain())
2269
                        {
2270
                            while(nlastLeftRegNum >= iprj->getMaxRegNumPerChain())
2271
                            {
2272
                                ninstNum++ ;
2273
                                nwireCount++ ;
2274
                                iregCombinationCode.clear();
2275
                                iregNameList.clear();
2276
                                // 定义 wire 连接 tdo 代码
2277
                                QString iwireTdoName(tr("_EziDebug_%1_%2_tdo%3").arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireCount));
2278
                                QString iwireTdoDefinitionCode(tr("\n\n\t""wire ")+ iwireTdoName + tr(" ;")) ;
2279
                                iusrCoreCode.append(iwireTdoDefinitionCode);
2280
                                iaddedCodeList.append(tr("\\bwire\\s+_EziDebug_%1_%2_tdo%3\\s*;")\
2281
                                                      .arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireCount));
2282
 
2283
                                // 定义 wire 连接 移位寄存器 代码
2284
                                QString iwireShiftRegDefinitionCode(tr("\n\t""wire ") + tr("[%1:0]").arg(iprj->getMaxRegNumPerChain()-1)+ tr("_EziDebug_%1_%2_sr%3")\
2285
                                                                    .arg(pchain->getChainName()).arg(iclockIterator.key()).arg(ninstNum) + tr(" ;"));
2286
                                QString iwireSrName(tr("_EziDebug_%1_%2_sr%3").arg(pchain->getChainName()).arg(iclockIterator.key()).arg(ninstNum)) ;
2287
 
2288
                                iaddedCodeList.append(tr("\\bwire\\s*\\[\\s*%1:\\s*0\\s*\\]\\s*").arg(iprj->getMaxRegNumPerChain()-1)+tr("_EziDebug_%1_%2_sr%3\\s*;")\
2289
                                                      .arg(pchain->getChainName()).arg(iclockIterator.key()).arg(ninstNum));
2290
 
2291
                                iusrCoreCode.append(iwireShiftRegDefinitionCode);
2292
                                nwireShiftRegNum++ ;
2293
 
2294
                                /*移位寄存器 赋值 代码*/
2295
                                // int nendBit = nleftBit + iprj->getMaxRegNumPerChain() -1;
2296
                                int nendBit = 0 ;
2297
                                if(iregVec.at(nleftRegNum)->m_unRegNum > 1)
2298
                                {
2299
                                    if(iregVec.at(nleftRegNum)->m_eRegNumEndian == EziDebugModule::endianBig)
2300
                                    {
2301
                                        /*高:低*/
2302
                                        // iregVec.at(nleftRegNum)->m_unBitWidth-1
2303
                                        nendBit = nleftBit + 1 - iprj->getMaxRegNumPerChain() ;
2304
                                        iregNameList << constructChainRegString(iregVec.at(nleftRegNum) , nlastStopNum , nleftBit , nendBit , pitem);
2305
 
2306
                                        iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1]").arg(iregVec.at(nleftRegNum)->m_unStartNum - nlastStopNum)+tr("[%1:%2]").arg(nleftBit).arg(nendBit));
2307
 
2308
                                        nleftBit = nendBit - 1 ;
2309
                                    }
2310
                                    else
2311
                                    {
2312
                                        /*低:高*/
2313
                                        nendBit = nleftBit -1 + iprj->getMaxRegNumPerChain() ;
2314
                                        iregNameList << constructChainRegString(iregVec.at(nleftRegNum) , nlastStopNum , nleftBit , nendBit , pitem);
2315
 
2316
                                        iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1]").arg(iregVec.at(nleftRegNum)->m_unStartNum + nlastStopNum)+tr("[%1:%2]").arg(nleftBit).arg(nendBit));
2317
 
2318
                                        nleftBit = nendBit + 1 ;
2319
                                    }
2320
                                }
2321
                                else
2322
                                {
2323
                                    if(iregVec.at(nleftRegNum)->m_eRegNumEndian == EziDebugModule::endianBig)
2324
                                    {
2325
                                        /*高:低*/
2326
                                        nendBit = nleftBit + 1 - iprj->getMaxRegNumPerChain() ;
2327
                                        iregNameList << constructChainRegString(iregVec.at(nleftRegNum) , nlastStopNum , nleftBit , nendBit , pitem);
2328
 
2329
                                        iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1:%2]") \
2330
                                                                   .arg(nleftBit).arg(nendBit));
2331
                                        nleftBit = nendBit - 1 ;
2332
                                    }
2333
                                    else
2334
                                    {
2335
                                        /*低:高*/
2336
                                        nendBit = nleftBit -1 + iprj->getMaxRegNumPerChain() ;
2337
                                        iregNameList << constructChainRegString(iregVec.at(nleftRegNum) , nlastStopNum , nleftBit , nendBit , pitem);
2338
 
2339
                                        iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1:%2]")\
2340
                                                                   .arg(nleftBit).arg(nendBit));
2341
 
2342
                                        nleftBit = nendBit + 1 ;
2343
                                    }
2344
                                }
2345
 
2346
                                ichainClock = pchain->getChainClock(pitem->getInstanceName(),iclockIterator.key());
2347
                                if(ichainClock.isEmpty())
2348
                                {
2349
                                     // ichainClock = iclockIterator.key() ;
2350
                                    return 2 ;
2351
                                }
2352
 
2353
                                pchain->addToRegChain(ichainClock ,pchainSt->m_uncurrentChainNumber ,iregNameList);
2354
 
2355
                                QString iwireShiftRegEvaluateString ;
2356
                                iwireShiftRegEvaluateString.append(tr("\n\t""assign %1 = {\n\t\t\t\t\t\t\t\t\t""%2""\n\t\t\t\t\t\t\t\t\t};").arg(iwireSrName).arg(iregCombinationCode.join(" ,\n\t\t\t\t\t\t\t\t\t")));
2357
                                iaddedCodeList.append(tr("\\bassign\\s+%1.*;").arg(iwireSrName));
2358
                                iusrCoreCode.append(iwireShiftRegEvaluateString);
2359
 
2360
                                /*自定义 core 例化代码 */
2361
                                QString iusrCoreDefinitionCode ;
2362
                                //QString iresetName = "1'b1";
2363
                                QString iresetName = tr("_EziDebug_%1_rstn").arg(pchain->getChainName());
2364
 
2365
                                QString iusrCoreTdi ;
2366
                                if(nnumberOfNoLibCore != 0)
2367
                                {
2368
                                    if((chainStructuremap.value(iclockIterator.key())->m_untotalChainNumber) > 1)
2369
                                    {
2370
                                        iusrCoreTdi.append(tr("%1[%2]").arg(pmodule->getChainClockWireNameMap(pchain->getChainName(),iclockIterator.key())).arg(pchainSt->m_uncurrentChainNumber));
2371
                                    }
2372
                                    else
2373
                                    {
2374
                                        iusrCoreTdi.append(tr("%1").arg(pmodule->getChainClockWireNameMap(pchain->getChainName(),iclockIterator.key())));
2375
                                    }
2376
                                }
2377
                                else
2378
                                {
2379
                                    if((chainStructuremap.value(iclockIterator.key())->m_untotalChainNumber) > 1)
2380
                                    {
2381
                                        iusrCoreTdi.append(tr("_EziDebug_%1_%2_TDI_reg[%3]").arg(pchain->getChainName()).arg(iclockIterator.key()).arg(pchainSt->m_uncurrentChainNumber));
2382
                                    }
2383
                                    else
2384
                                    {
2385
                                        iusrCoreTdi.append(tr("_EziDebug_%1_%2_TDI_reg").arg(pchain->getChainName()).arg(iclockIterator.key()));
2386
                                    }
2387
                                }
2388
 
2389
                                iusrCoreDefinitionCode.append(tr("\n\t")+ EziDebugScanChain::getChainRegCore() + tr(" %1_%2_inst%3(\n").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum));
2390
                                iusrCoreDefinitionCode.append(  tr("\t"".clock""\t(%1) ,\n").arg(iclockIterator.key()) \
2391
                                                                + tr("\t"".resetn""\t(%1) ,\n").arg(iresetName) \
2392
                                                                + tr("\t"".TDI_reg""\t(%1) ,\n").arg(iusrCoreTdi) \
2393
                                                                + tr("\t"".TDO_reg""\t(%1) ,\n").arg(iwireTdoName) \
2394
                                                                + tr("\t"".TOUT_reg""\t(%1) ,\n").arg(iparentToutPort) \
2395
                                                                + tr("\t"".shift_reg""\t(%1) \n\t) ;").arg(iwireSrName));
2396
 
2397
                                /*加入 定义 userCore regWidth 限定的 语句代码*/
2398
                                QString iparameterDefCode ;
2399
                                iparameterDefCode.append(tr("\n\n\t""defparam %1_%2_inst%3.shift_width = %4 ;").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum).arg(iprj->getMaxRegNumPerChain()));
2400
                                iaddedCodeList.append(tr("\\bdefparam\\s+%1_%2_inst%3\\.shift_width\\s*=.*;").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum));
2401
                                iusrCoreCode.append(iparameterDefCode)  ;
2402
 
2403
                                iaddedCodeList.append(EziDebugScanChain::getChainRegCore() + tr("\\s+%1_%2_inst%3\\s*\\(.*\\)\\s*;").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum));
2404
 
2405
                                iusrCoreCode.append(iusrCoreDefinitionCode);
2406
 
2407
 
2408
                                /*module 端口连接代码*/
2409
                                QString iportConnectCode ;
2410
                                iportConnectCode.append(tr("\n\t""assign %1[%2] = %3 ;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
2411
                                                        .arg(pchainSt->m_uncurrentChainNumber).arg(iwireTdoName));
2412
                                iaddedCodeList.append(tr("\\bassign\\s+%1\\s*\\[\\s*%2\\s*\\].*;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
2413
                                                      .arg(pchainSt->m_uncurrentChainNumber));
2414
                                iusrCoreCode.append(iportConnectCode);
2415
 
2416
 
2417
                                nlastLeftRegNum = nlastLeftRegNum - iprj->getMaxRegNumPerChain();
2418
                                pchainSt->m_uncurrentChainNumber++ ;
2419
                                pchainSt->m_unleftRegNumber = iprj->getMaxRegNumPerChain() ;
2420
                            }
2421
                        }
2422
 
2423
                        // 将剩余的寄存器加入到链中
2424
                        iregCombinationCode.clear();
2425
                        iregNameList.clear();
2426
#if 1
2427
                        if(iregVec.at(nleftRegNum)->m_eRegBitWidthEndian == EziDebugModule::endianBig)
2428
                        {
2429
                            if((nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) > 0)
2430
                            {
2431
                                pchainSt->m_unleftRegNumber -= (qAbs(nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) + 1) ;
2432
                                nregBitCount = (qAbs(nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) + 1) ;
2433
                                iregNameList << constructChainRegString(iregVec.at(nleftRegNum),nlastStopNum,nleftBit,iregVec.at(nleftRegNum)->m_unEndBit ,pitem);
2434
 
2435
                                iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1][%2:%3]").arg(iregVec.at(nleftRegNum)->m_unStartNum - nlastStopNum).arg(nleftBit).arg(iregVec.at(nleftRegNum)->m_unEndBit));
2436
                            }
2437
                            else if((nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) == 0)
2438
                            {
2439
                                pchainSt->m_unleftRegNumber -= (qAbs(nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) + 1) ;
2440
                                nregBitCount = (qAbs(nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) + 1) ;
2441
                                iregNameList << constructChainRegString(iregVec.at(nleftRegNum),nlastStopNum,nleftBit,iregVec.at(nleftRegNum)->m_unEndBit ,pitem);
2442
 
2443
                                iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1][0]").arg(iregVec.at(nleftRegNum)->m_unStartNum - nlastStopNum));
2444
                            }
2445
                            else
2446
                            {
2447
                                // 上面已经加完了
2448
                            }
2449
 
2450
                        }
2451
                        else
2452
                        {
2453
                            if((iregVec.at(nleftRegNum)->m_unEndBit - nleftBit) > 0)
2454
                            {
2455
                                pchainSt->m_unleftRegNumber -= (qAbs(nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) + 1) ;
2456
                                nregBitCount = (qAbs(nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) + 1) ;
2457
                                iregNameList << constructChainRegString(iregVec.at(nleftRegNum),nlastStopNum,nleftBit,iregVec.at(nleftRegNum)->m_unEndBit ,pitem);
2458
 
2459
                                iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1][%2:%3]").arg(iregVec.at(nleftRegNum)->m_unStartNum + nlastStopNum).arg(nleftBit).arg(iregVec.at(nleftRegNum)->m_unEndBit));
2460
                            }
2461
                            else if((iregVec.at(nleftRegNum)->m_unEndBit - nleftBit) == 0)
2462
                            {
2463
                                pchainSt->m_unleftRegNumber -= (qAbs(nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) + 1) ;
2464
                                nregBitCount = (qAbs(nleftBit - iregVec.at(nleftRegNum)->m_unEndBit) + 1) ;
2465
                                iregNameList << constructChainRegString(iregVec.at(nleftRegNum),nlastStopNum,nleftBit,iregVec.at(nleftRegNum)->m_unEndBit ,pitem);
2466
 
2467
                                iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1][0]").arg(iregVec.at(nleftRegNum)->m_unStartNum + nlastStopNum));
2468
                            }
2469
                            else
2470
                            {
2471
                                // 已经加完
2472
                            }
2473
                        }
2474
#endif
2475
 
2476
 
2477
                        if(iregVec.at(nleftRegNum)->m_unRegNum > 1)
2478
                        {
2479
                            nlastStopNum++ ;
2480
                        }
2481
                        else
2482
                        {
2483
                            nleftRegNum++ ;
2484
                            nlastStopNum = 0 ;
2485
                        }
2486
 
2487
                        nleftBit = -1 ;
2488
                    }
2489
                    else
2490
                    {
2491
                        nregBitCount = 0 ;
2492
                    }
2493
 
2494
 
2495
                    for(; nleftRegNum < iregVec.count() ; nleftRegNum++)
2496
                    {
2497
                        for(int m = nlastStopNum ; m < iregVec.at(nleftRegNum)->m_unRegNum; m++)
2498
                        {
2499
                            nregBitCount += iregVec.at(nleftRegNum)->m_unRegBitWidth ;
2500
 
2501
                            if(nregBitCount < pchainSt->m_unleftRegNumber)
2502
                            {
2503
                                /*数组情况下*/
2504
                                // 够用继续添加
2505
                                if(iregVec.at(nleftRegNum)->m_unRegNum > 1)
2506
                                {
2507
                                    if(iregVec.at(nleftRegNum)->m_eRegNumEndian == EziDebugModule::endianBig)
2508
                                    {
2509
                                        iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1]").arg(iregVec.at(nleftRegNum)->m_unStartNum - m));
2510
                                    }
2511
                                    else
2512
                                    {
2513
                                        iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1]").arg(iregVec.at(nleftRegNum)->m_unStartNum + m));
2514
                                    }
2515
                                }
2516
                                else
2517
                                {
2518
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName));
2519
                                }
2520
 
2521
                                iregNameList << constructChainRegString(iregVec.at(nleftRegNum),m,iregVec.at(nleftRegNum)->m_unStartBit,iregVec.at(nleftRegNum)->m_unEndBit,pitem);
2522
                            }
2523
                            else if(nregBitCount == pchainSt->m_unleftRegNumber)
2524
                            {
2525
                                // 刚好满  跳出  下次新的扫描链继续 添加
2526
                                if(iregVec.at(nleftRegNum)->m_unRegNum > 1)
2527
                                {
2528
                                    if(iregVec.at(nleftRegNum)->m_eRegNumEndian == EziDebugModule::endianBig)
2529
                                    {
2530
                                        iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1]").arg(iregVec.at(nleftRegNum)->m_unStartNum - m));
2531
                                    }
2532
                                    else
2533
                                    {
2534
                                        iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1]").arg(iregVec.at(nleftRegNum)->m_unStartNum + m));
2535
                                    }
2536
                                }
2537
                                else
2538
                                {
2539
                                    iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName));
2540
                                }
2541
 
2542
                                iregNameList << constructChainRegString(iregVec.at(nleftRegNum),m,iregVec.at(nleftRegNum)->m_unStartBit,iregVec.at(nleftRegNum)->m_unEndBit,pitem);
2543
 
2544
                                nlastStopNum = m ;
2545
                                // nleftBit = -1 ;
2546
                                nleftRegNum++ ;
2547
                                isNeedAdded = true ;
2548
 
2549
                                goto WireShiftRegEvaluate1 ;
2550
                            }
2551
                            else
2552
                            {
2553
                                if(iregVec.at(nleftRegNum)->m_unRegNum > 1)
2554
                                {
2555
                                    if(iregVec.at(nleftRegNum)->m_eRegNumEndian == EziDebugModule::endianBig)
2556
                                    {
2557
                                        int nstartBit = iregVec.at(nleftRegNum)->m_unStartBit ;
2558
                                        int nendBit = nregBitCount- pchainSt->m_unleftRegNumber + iregVec.at(nleftRegNum)->m_unStartBit + 1 - iregVec.at(nleftRegNum)->m_unRegBitWidth ;
2559
                                        nleftBit = nendBit - 1 ;
2560
                                        iregNameList << constructChainRegString(iregVec.at(nleftRegNum),m,nstartBit,nendBit,pitem);
2561
 
2562
                                        iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1]").arg(iregVec.at(nleftRegNum)->m_unStartNum - m)+tr("[%1:%2]").arg(nstartBit).arg(nendBit));
2563
                                    }
2564
                                    else
2565
                                    {
2566
                                        int nstartBit = iregVec.at(nleftRegNum)->m_unStartBit ;
2567
                                        int nendBit = iregVec.at(nleftRegNum)->m_unRegBitWidth + iregVec.at(nleftRegNum)->m_unStartBit - 1 - (nregBitCount- pchainSt->m_unleftRegNumber) ;
2568
                                        nleftBit = nendBit + 1 ;
2569
                                        iregNameList << constructChainRegString(iregVec.at(nleftRegNum),m,nstartBit,nendBit,pitem);
2570
 
2571
                                        iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1]").arg(iregVec.at(nleftRegNum)->m_unStartNum + m)+tr("[%1:%2]").arg(nstartBit).arg(nendBit));
2572
                                    }
2573
                                }
2574
                                else
2575
                                {
2576
                                    if(iregVec.at(nleftRegNum)->m_eRegNumEndian == EziDebugModule::endianBig)
2577
                                    {
2578
                                        int nstartBit = iregVec.at(nleftRegNum)->m_unStartBit ;
2579
                                        int nendBit = nregBitCount- pchainSt->m_unleftRegNumber + iregVec.at(nleftRegNum)->m_unStartBit + 1 - iregVec.at(nleftRegNum)->m_unRegBitWidth ;
2580
                                        nleftBit = nendBit - 1 ;
2581
                                        iregNameList << constructChainRegString(iregVec.at(nleftRegNum),m,nstartBit,nendBit,pitem);
2582
 
2583
                                        iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1:%2]") \
2584
                                                                   .arg(nstartBit).arg(nendBit));
2585
                                    }
2586
                                    else
2587
                                    {
2588
                                        int nstartBit = iregVec.at(nleftRegNum)->m_unStartBit ;
2589
                                        int nendBit = iregVec.at(nleftRegNum)->m_unRegBitWidth + iregVec.at(nleftRegNum)->m_unStartBit - 1 - (nregBitCount- pchainSt->m_unleftRegNumber) ;
2590
                                        nleftBit = nendBit + 1 ;
2591
                                        iregNameList << constructChainRegString(iregVec.at(nleftRegNum),m,nstartBit,nendBit,pitem);
2592
 
2593
                                        iregCombinationCode.append(QString::fromAscii(iregVec.at(nleftRegNum)->m_pRegName)+tr("[%1:%2]")\
2594
                                                                   .arg(nstartBit).arg(nendBit));
2595
                                    }
2596
                                }
2597
 
2598
                                nlastStopNum = m ;
2599
                                isNeedAdded = true ;
2600
                                goto WireShiftRegEvaluate1 ;
2601
                            }
2602
                        }
2603
                        nlastStopNum = 0 ;
2604
                    }
2605
WireShiftRegEvaluate1:
2606
 
2607
                    if(isNeedAdded == true)
2608
                    {
2609
                        nusedNum =  pchainSt->m_unleftRegNumber ;
2610
                    }
2611
                    else
2612
                    {
2613
                        nusedNum = nregBitCount ;
2614
                    }
2615
 
2616
                    // 没加完继续加
2617
                    if(nleftRegNum != iregVec.count())
2618
                    {
2619
                        // 有寄存器
2620
                        if(iregNameList.count())
2621
                        {
2622
 
2623
                            ichainClock = pchain->getChainClock(pitem->getInstanceName(),iclockIterator.key());
2624
 
2625
                            if(ichainClock.isEmpty())
2626
                            {
2627
                                return 2 ;
2628
                            }
2629
 
2630
                            pchain->addToRegChain(ichainClock,pchainSt->m_uncurrentChainNumber,iregNameList);
2631
 
2632
                            nwireCount++ ;
2633
                            // 定义 wire 连接 tdo 代码
2634
                            QString iwireTdoName(tr("_EziDebug_%1_%2_tdo%3").arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireCount));
2635
                            QString iwireTdoDefinitionCode(tr("\n\n\t""wire ")+ iwireTdoName + tr(" ;")) ;
2636
                            iusrCoreCode.append(iwireTdoDefinitionCode);
2637
                            iaddedCodeList.append(tr("\\bwire\\s+_EziDebug_%1_%2_tdo%3\\s*;")\
2638
                                                  .arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireCount));
2639
 
2640
 
2641
                            // 定义 wire 连接 移位寄存器 代码
2642
                            QString iwireShiftRegDefinitionCode(tr("\n\t""wire ") + tr("[%1:0] ").arg(nusedNum - 1) + tr("_EziDebug_%1_%2_sr%3")\
2643
                                                                .arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireShiftRegNum) + tr(" ;"));
2644
                            QString iwireSrName(tr("_EziDebug_%1_%2_sr%3").arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireShiftRegNum)) ;
2645
 
2646
                            iaddedCodeList.append(tr("\\bwire\\s*\\[\\s*%1\\s*:\\s*0\\s*\\]\\s*").arg(nusedNum - 1) + tr("_EziDebug_%1_%2_sr%3\\s*;")\
2647
                                                  .arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireShiftRegNum));
2648
 
2649
                            iusrCoreCode.append(iwireShiftRegDefinitionCode);
2650
                            nwireShiftRegNum++ ;
2651
 
2652
                            //pchain->addToRegChain(ichainClock,pchainSt->m_uncurrentChainNumber,iregNameList);
2653
 
2654
                            QString iwireShiftRegEvaluateString ;
2655
                            iwireShiftRegEvaluateString.append(tr("\n\t""assign %1 = {\n\t\t\t\t\t\t\t\t\t""%2""\n\t\t\t\t\t\t\t\t\t};").arg(iwireSrName).arg(iregCombinationCode.join(" ,\n\t\t\t\t\t\t\t\t\t")));
2656
                            iaddedCodeList.append(tr("\\bassign\\s+%1\\s*=.*;").arg(iwireSrName));
2657
                            iusrCoreCode.append(iwireShiftRegEvaluateString);
2658
 
2659
 
2660
                            /*自定义 core 例化代码 */
2661
                            QString iusrCoreDefinitionCode ;
2662
                            //QString iresetName = "1'b1";
2663
                            QString iresetName = tr("_EziDebug_%1_rstn").arg(pchain->getChainName());
2664
 
2665
 
2666
                            QString iusrCoreTdi ;
2667
                            if(nnumberOfNoLibCore != 0)
2668
                            {
2669
                                if((chainStructuremap.value(iclockIterator.key())->m_untotalChainNumber) > 1)
2670
                                {
2671
                                    iusrCoreTdi.append(tr("%1[%2]").arg(pmodule->getChainClockWireNameMap(pchain->getChainName(),iclockIterator.key())).arg(pchainSt->m_uncurrentChainNumber));
2672
                                }
2673
                                else
2674
                                {
2675
                                    iusrCoreTdi.append(tr("%1").arg(pmodule->getChainClockWireNameMap(pchain->getChainName(),iclockIterator.key())));
2676
                                }
2677
                            }
2678
                            else
2679
                            {
2680
                                if((chainStructuremap.value(iclockIterator.key())->m_untotalChainNumber) > 1)
2681
                                {
2682
                                    iusrCoreTdi.append(tr("_EziDebug_%1_%2_TDI_reg[%3]").arg(pchain->getChainName()).arg(iclockIterator.key()).arg(pchainSt->m_uncurrentChainNumber));
2683
                                }
2684
                                else
2685
                                {
2686
                                    iusrCoreTdi.append(tr("_EziDebug_%1_%2_TDI_reg").arg(pchain->getChainName()).arg(iclockIterator.key()));
2687
                                }
2688
                            }
2689
 
2690
                            iusrCoreDefinitionCode.append(tr("\n\n\t")+EziDebugScanChain::getChainRegCore() + tr(" %1_%2_inst%3(\n").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum));
2691
                            iusrCoreDefinitionCode.append(  tr("\t\t"".clock""\t(%1) ,\n").arg(iclockIterator.key()) \
2692
                                                            + tr("\t\t"".resetn""\t(%1) ,\n").arg(iresetName) \
2693
                                                            + tr("\t\t"".TDI_reg""\t(%1) ,\n").arg(iusrCoreTdi) \
2694
                                                            + tr("\t\t"".TDO_reg""\t(%1) ,\n").arg(iwireTdoName) \
2695
                                                            + tr("\t\t"".TOUT_reg""\t(%1) ,\n").arg(iparentToutPort) \
2696
                                                            + tr("\t\t"".shift_reg""\t(%1) \n\t) ;").arg(iwireSrName));
2697
 
2698
 
2699
                            /*加入 定义 userCore regWidth 限定的 语句代码*/
2700
                            QString iparameterDefCode ;
2701
                            iparameterDefCode.append(tr("\n\n\t""defparam %1_%2_inst%3.shift_width = %4 ;").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum).arg(nusedNum));
2702
                            iaddedCodeList.append(tr("\\bdefparam\\s+%1_%2_inst%3\\.shift_width\\s*=.*;").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum));
2703
 
2704
                            iusrCoreCode.append(iparameterDefCode)  ;
2705
                            iaddedCodeList.append(EziDebugScanChain::getChainRegCore() + tr("\\s+%1_%2_inst%3\\s*(.*)\\s*;").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum));
2706
 
2707
                            iusrCoreCode.append(iusrCoreDefinitionCode);
2708
 
2709
                            /*module 端口连接代码*/
2710
                            QString iportConnectCode ;
2711
                            if((chainStructuremap.value(iclockIterator.key())->m_untotalChainNumber) > 1)
2712
                            {
2713
                                iportConnectCode.append(tr("\n\n\t""assign %1[%2] = %3 ;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
2714
                                                        .arg(pchainSt->m_uncurrentChainNumber).arg(iwireTdoName));
2715
                                iaddedCodeList.append(tr("\\bassign\\s+%1\\s*\\[\\s*%2\\s*\\].*;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
2716
                                                      .arg(pchainSt->m_uncurrentChainNumber));
2717
                            }
2718
                            else
2719
                            {
2720
                                iportConnectCode.append(tr("\n\n\t""assign %1 = %2 ;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
2721
                                                        .arg(iwireTdoName));
2722
                                iaddedCodeList.append(tr("\\bassign\\s+%1\\s*=\\s*%2\\s*;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
2723
                                                      .arg(iwireTdoName));
2724
                            }
2725
                            iusrCoreCode.append(iportConnectCode);
2726
                        }
2727
 
2728
                        pchainSt->m_uncurrentChainNumber++ ;
2729
                        pchainSt->m_unleftRegNumber = iprj->getMaxRegNumPerChain() ;
2730
                        isNeedAdded = false ;
2731
                        goto AddReg ;
2732
                    }
2733
                    else
2734
                    {
2735
                        pchainSt->m_unleftRegNumber -= nregBitCount ;
2736
                    }
2737
#if 0
2738
                    if(!sregVec.count())
2739
                    {
2740
                        pchainSt->m_uncurrentChainNumber++ ;
2741
                        pchainSt->m_unleftRegNumber = iprj->getMaxRegNumPerChain() ;
2742
                    }
2743
#endif
2744
 
2745
                    // 添加动态寄存器
2746
                    QString ivarRegSumStr ;
2747
                    int nregNumCount = 0 ;
2748
                    nleftRegNum = 0 ;
2749
 
2750
AddVReg:
2751
                    if(nregBitCount != 0)
2752
                    {
2753
                        ivarRegSumStr = QString::number(nregBitCount) ;
2754
                    }
2755
                    else
2756
                    {
2757
                        ivarRegSumStr.clear();
2758
                        iregCombinationCode.clear();
2759
                    }
2760
 
2761
                    for(;nleftRegNum < vregVec.count();nleftRegNum++)
2762
                    {
2763
                        // 还要考虑 regnum  记录添加到了 哪个 寄存器
2764
                        EziDebugModule::RegStructure* preg = vregVec.at(nleftRegNum) ;
2765
                        EziDebugModule::RegStructure* pinstancereg = pmodule->getInstanceReg(pitem->getInstanceName(),iclockIterator.key(),QString::fromAscii(preg->m_pRegName));
2766
 
2767
                        if(preg->m_unMaxBitWidth < pchainSt->m_unleftRegNumber)
2768
                        {
2769
                            pchainSt->m_unleftRegNumber -= preg->m_unMaxBitWidth ;
2770
 
2771
                            if(pinstancereg->m_unRegNum == 1)
2772
                            {
2773
                                if(!ivarRegSumStr.isEmpty())
2774
                                {
2775
                                    ivarRegSumStr.append(QObject::tr("+") + QString::fromAscii(preg->m_pExpString));
2776
                                }
2777
                                else
2778
                                {
2779
                                    ivarRegSumStr.append(QString::fromAscii(preg->m_pExpString));
2780
                                }
2781
 
2782
                                iregNameList << constructChainRegString(pinstancereg , 0 ,pinstancereg->m_unStartBit , pinstancereg->m_unEndBit , pitem);
2783
 
2784
                                iregCombinationCode.append(QString::fromAscii(preg->m_pRegName));
2785
                            }
2786
                            else if(pinstancereg->m_unRegNum > 1)
2787
                            {
2788
                                if(!ivarRegSumStr.isEmpty())
2789
                                {
2790
                                    ivarRegSumStr.append(QObject::tr("+") + QString::fromAscii(preg->m_pExpString) + QObject::tr("*") + QString::number(pinstancereg->m_unRegNum));
2791
                                }
2792
                                else
2793
                                {
2794
                                    ivarRegSumStr.append(QString::fromAscii(preg->m_pExpString) + QObject::tr("*") + QString::number(pinstancereg->m_unRegNum));
2795
                                }
2796
 
2797
                                for( ; nregNumCount < pinstancereg->m_unRegNum ; nregNumCount++ )
2798
                                {
2799
                                    QString iregNumStr ;
2800
                                    if(pinstancereg->m_eRegNumEndian == EziDebugModule::endianBig)
2801
                                    {
2802
                                        iregNumStr = QString::number(pinstancereg->m_unStartNum - nregNumCount) ;
2803
                                    }
2804
                                    else
2805
                                    {
2806
                                        iregNumStr = QString::number(pinstancereg->m_unStartNum + nregNumCount) ;
2807
                                    }
2808
                                    iregNameList << constructChainRegString(pinstancereg , nregNumCount ,pinstancereg->m_unStartBit , pinstancereg->m_unEndBit , pitem);
2809
 
2810
                                    iregCombinationCode.append(QObject::tr("%1[%2]").arg(QString::fromAscii(pinstancereg->m_pRegName)).arg(iregNumStr)) ;
2811
                                }
2812
                            }
2813
                        }
2814
                        else
2815
                        {
2816
                            // 跳出添加链
2817
                            break ;
2818
                        }
2819
                    }
2820
 
2821
                    // 添加扫描链
2822
                    ichainClock = pchain->getChainClock(pitem->getInstanceName(),iclockIterator.key());
2823
                    if(ichainClock.isEmpty())
2824
                    {
2825
                        ichainClock = iclockIterator.key() ;
2826
                    }
2827
 
2828
                    pchain->addToRegChain(ichainClock ,pchainSt->m_uncurrentChainNumber ,iregNameList);
2829
 
2830
 
2831
                    nwireCount++ ;
2832
                    // 定义 wire 连接 tdo 代码
2833
                    QString iwireTdoName(tr("_EziDebug_%1_%2_tdo%3").arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireCount));
2834
                    QString iwireTdoDefinitionCode(tr("\n\n\t""wire ")+ iwireTdoName + tr(" ;")) ;
2835
                    iusrCoreCode.append(iwireTdoDefinitionCode);
2836
                    iaddedCodeList.append(tr("\\bwire\\s+_EziDebug_%1_%2_tdo%3\\s*;")\
2837
                                          .arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireCount));
2838
 
2839
 
2840
                    // 定义 wire 连接 移位寄存器 代码
2841
                    QString iwireShiftRegDefinitionCode(tr("\n\t""wire ") + tr("[%1:0] ").arg(ivarRegSumStr + tr(" - 1")) + tr("_EziDebug_%1_%2_sr%3")\
2842
                                                        .arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireShiftRegNum) + tr(" ;"));
2843
                    QString iwireSrName(tr("_EziDebug_%1_%2_sr%3").arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireShiftRegNum)) ;
2844
 
2845
                    iaddedCodeList.append(tr("\\bwire\\s*\\[\\s*%1\\s*:\\s*0\\s*\\]\\s*").arg(ivarRegSumStr + tr(" - 1")) + tr("_EziDebug_%1_%2_sr%3\\s*;")\
2846
                                          .arg(pchain->getChainName()).arg(iclockIterator.key()).arg(nwireShiftRegNum));
2847
 
2848
                    iusrCoreCode.append(iwireShiftRegDefinitionCode);
2849
                    nwireShiftRegNum++ ;
2850
 
2851
                    QString iwireShiftRegEvaluateString ;
2852
                    iwireShiftRegEvaluateString.append(tr("\n\t""assign %1 = {\n\t\t\t\t\t\t\t\t\t""%2""\n\t\t\t\t\t\t\t\t\t};").arg(iwireSrName).arg(iregCombinationCode.join(" ,\n\t\t\t\t\t\t\t\t\t")));
2853
                    iaddedCodeList.append(tr("\\bassign\\s+%1.*;").arg(iwireSrName));
2854
                    iusrCoreCode.append(iwireShiftRegEvaluateString);
2855
 
2856
                    /*自定义 core 例化代码 */
2857
                    QString iusrCoreDefinitionCode ;
2858
                    //QString iresetName ;
2859
                    QString iresetName = tr("_EziDebug_%1_rstn").arg(pchain->getChainName());
2860
 
2861
                    QString iusrCoreTdi ;
2862
                    if(nnumberOfNoLibCore != 0)
2863
                    {
2864
                        if((chainStructuremap.value(iclockIterator.key())->m_untotalChainNumber) > 1)
2865
                        {
2866
                            iusrCoreTdi.append(tr("%1[%2]").arg(pmodule->getChainClockWireNameMap(pchain->getChainName(),iclockIterator.key())).arg(pchainSt->m_uncurrentChainNumber));
2867
                        }
2868
                        else
2869
                        {
2870
                            iusrCoreTdi.append(tr("%1").arg(pmodule->getChainClockWireNameMap(pchain->getChainName(),iclockIterator.key())));
2871
                        }
2872
                    }
2873
                    else
2874
                    {
2875
                        if((chainStructuremap.value(iclockIterator.key())->m_untotalChainNumber) > 1)
2876
                        {
2877
                            iusrCoreTdi.append(tr("_EziDebug_%1_%2_TDI_reg[%3]").arg(pchain->getChainName()).arg(iclockIterator.key()).arg(pchainSt->m_uncurrentChainNumber));
2878
                        }
2879
                        else
2880
                        {
2881
                            iusrCoreTdi.append(tr("_EziDebug_%1_%2_TDI_reg").arg(pchain->getChainName()).arg(iclockIterator.key()));
2882
                        }
2883
                    }
2884
 
2885
                    iusrCoreDefinitionCode.append(tr("\n\t")+ EziDebugScanChain::getChainRegCore() + tr(" %1_%2_inst%3(\n").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum));
2886
                    iusrCoreDefinitionCode.append(  tr("\t"".clock""\t(%1) ,\n").arg(iclockIterator.key()) \
2887
                                                    + tr("\t"".resetn""\t(%1) ,\n").arg(iresetName) \
2888
                                                    + tr("\t"".TDI_reg""\t(%1) ,\n").arg(iusrCoreTdi) \
2889
                                                    + tr("\t"".TDO_reg""\t(%1) ,\n").arg(iwireTdoName) \
2890
                                                    + tr("\t"".TOUT_reg""\t(%1) ,\n").arg(iparentToutPort) \
2891
                                                    + tr("\t"".shift_reg""\t(%1) \n\t) ;").arg(iwireSrName));
2892
 
2893
                    /*加入 定义 userCore regWidth 限定的 语句代码*/
2894
                    QString iparameterDefCode ;
2895
                    iparameterDefCode.append(tr("\n\n\t""defparam %1_%2_inst%3.shift_width = %4 ;").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum).arg(ivarRegSumStr));
2896
                    iaddedCodeList.append(tr("\\bdefparam\\s+%1_%2_inst%3\\.shift_width\\s*=.*;").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum));
2897
                    iusrCoreCode.append(iparameterDefCode)  ;
2898
 
2899
                    iaddedCodeList.append(EziDebugScanChain::getChainRegCore() + tr("\\s+%1_%2_inst%3\\s*\\(.*\\)\\s*;").arg(EziDebugScanChain::getChainRegCore()).arg(pchain->getChainName()).arg(ninstNum));
2900
 
2901
                    iusrCoreCode.append(iusrCoreDefinitionCode);
2902
 
2903
 
2904
                    /*module 端口连接代码*/
2905
                    QString iportConnectCode ;
2906
                    iportConnectCode.append(tr("\n\t""assign %1[%2] = %3 ;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
2907
                                            .arg(pchainSt->m_uncurrentChainNumber).arg(iwireTdoName));
2908
                    iaddedCodeList.append(tr("\\bassign\\s+%1\\s*\\[\\s*%2\\s*\\].*;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
2909
                                          .arg(pchainSt->m_uncurrentChainNumber));
2910
                    iusrCoreCode.append(iportConnectCode);
2911
 
2912
                    ivarRegSumStr.clear();
2913
 
2914
                    if(iregNameList.count())
2915
                    {
2916
                        // 将第一部分的寄存器 最后一次的 regbitcount 记录下来
2917
                        // 转换为 QString 类型
2918
 
2919
                        if(nleftRegNum != vregVec.count())
2920
                        {
2921
                            // 还有寄存器
2922
                            pchainSt->m_uncurrentChainNumber++ ;
2923
                            pchainSt->m_unleftRegNumber = iprj->getMaxRegNumPerChain() ;
2924
                            goto AddVReg ;
2925
                        }
2926
                    }
2927
                }
2928
 
2929
            }
2930
            // 根据 要例化 数目 创建 例化 ,并创建 wire_tdo 信号 、移位寄存器 、
2931
            if(fileName().endsWith("fft_ram_256x17.v"))
2932
            {
2933
                qDebug("add chain in fft_ram_256x17.v");
2934
            }
2935
            QString ilastPortConnect ;
2936
            nchainEndNum = pchainSt->m_uncurrentChainNumber ;
2937
 
2938
            // 上一次链结束 到 这一次链开始 的 端口连接
2939
            ilastInput.clear();
2940
            if(nnumberOfNoLibCore != 0)
2941
            {
2942
                // 用 lastwire
2943
                ilastInput = pmodule->getChainClockWireNameMap(pchain->getChainName(),iclockIterator.key()) ;
2944
            }
2945
            else
2946
            {
2947
                // 用 tdi
2948
                ilastInput = tr("_EziDebug_%1_%2_TDI_reg").arg(pchain->getChainName()).arg(iclockIterator.key()) ;
2949
            }
2950
 
2951
            // 不在同一条链上,且不是从0条链开始加
2952
            if((nlastChainEndNum != nchainStartNum)&&(nchainStartNum != 0))
2953
            {
2954
                int nstartBit = 0 ;
2955
 
2956
                nstartBit = nlastChainEndNum + 1;
2957
 
2958
 
2959
                if((nchainStartNum - nlastChainEndNum) > 2)
2960
                {
2961
                    ilastPortConnect.append(tr("\n\t""assign %1[%2:%3] = %4[%5:%6] ;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
2962
                                            .arg(nchainStartNum-1).arg(nstartBit).arg(ilastInput).arg(nchainStartNum-1).arg(nstartBit));
2963
                    iusrCoreCode.append(ilastPortConnect);
2964
                    iaddedCodeList.append(tr("\\bassign\\s+%1\\s*\\[\\s*%2\\s*:\\s*%3\\s*\\]\\s*=\\s*%4\\[\\s*%5\\s*:\\s*%6\\s*\\]\\s*;")
2965
                                          .arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
2966
                                                                                      .arg(nchainStartNum-1).arg(nstartBit).arg(ilastInput).arg(nchainStartNum-1).arg(nstartBit));
2967
                }
2968
                else
2969
                {
2970
                    ilastPortConnect.append(tr("\n\t""assign %1[%2] = %3[%4] ;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
2971
                                            .arg(nstartBit)\
2972
                                            .arg(ilastInput)\
2973
                                            .arg(nstartBit));
2974
                    iusrCoreCode.append(ilastPortConnect);
2975
                    iaddedCodeList.append(tr("\\bassign\\s+%1\\s*\\[\\s*%2\\s*\\]\\s*=\\s*%3\\s*\\[\\s*%4\\s*\\]\\s*;")\
2976
                                          .arg(tr("_EziDebug_%1_%2_TDO_reg")\
2977
                                          .arg(pchain->getChainName())\
2978
                                          .arg(iclockIterator.key()))\
2979
                                          .arg(nstartBit)\
2980
                                          .arg(ilastInput)\
2981
                                          .arg(nstartBit));
2982
                }
2983
            }
2984
 
2985
            pmodule->setBitRangeInChain(pchain->getChainName(),iclockIterator.key(),nchainStartNum ,nchainEndNum);
2986
            pmodule->setEziDebugCoreCounts(pchain->getChainName(),ninstNum);
2987
            ++iclockIterator ;
2988
        }
2989
 
2990
            pmodule->setEziDebugWireCounts(pchain->getChainName(),nwireCount);
2991
 
2992
        /*
2993
                自定义core 的例化代码
2994
                1、  _EziDebugScanChainReg + 例化名(
2995
                    .clock      (module中的各个clock)  ,
2996
                    .resetn     (module中的复位信号)  ,
2997
                    .TDI_reg    (非系统core 的 最后一个 wire_tdo)  ,
2998
                    .TDO_reg    (自定义的 wire_tdo  )  ,
2999
                    .TOUT_reg   (module端口的 tout  )  ,
3000
                    .shift_reg  (自定义的 shift_reg )
3001
                 );
3002
            */
3003
        int ntimesPerChain = pmodule->getInstancedTimesPerChain(pchain->getChainName()) ;
3004
        if(1 == ntimesPerChain)
3005
        {
3006
            iclockIterator = iclockMap.constBegin();
3007
            while(iclockIterator != iclockMap.constEnd())
3008
            {
3009
                EziDebugInstanceTreeItem::SCAN_CHAIN_STRUCTURE* pchainSt = chainStructuremap.value(iclockIterator.key()) ;
3010
                QString ilastInput ;
3011
                QString ilastPortConnect ;
3012
                if(nnumberOfNoLibCore != 0)
3013
                {
3014
                    // 用 lastwire
3015
                    ilastInput = pmodule->getChainClockWireNameMap(pchain->getChainName(),iclockIterator.key()) ;
3016
 
3017
                }
3018
                else
3019
                {
3020
                    // 用 tdi
3021
                    ilastInput = tr("_EziDebug_%1_%2_TDI_reg").arg(pchain->getChainName()).arg(iclockIterator.key()) ;
3022
                }
3023
 
3024
                // 这次最后1bit wire
3025
                pmodule->getBitRangeInChain(pchain->getChainName(),iclockIterator.key(),&nlastChainStartNum ,&nlastChainEndNum);
3026
 
3027
                int nbitNum = 0 ;
3028
 
3029
                // 端口连接不完全
3030
                if(nlastChainEndNum != (pchainSt->m_untotalChainNumber-1))
3031
                {
3032
                    if((pchainSt->m_untotalChainNumber - nlastChainEndNum) > 2)
3033
                    {
3034
                        if( -1 == nlastChainEndNum)
3035
                        {
3036
                            // 没加过自定义core
3037
                            nbitNum  = 0 ;
3038
                        }
3039
                        else
3040
                        {
3041
                            nbitNum = nlastChainEndNum + 1 ;
3042
                        }
3043
 
3044
                        ilastPortConnect.append(tr("\n\t""assign %1[%2:%3] = %4[%5:%6] ;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
3045
                                                .arg(pchainSt->m_untotalChainNumber-1).arg(nbitNum).arg(ilastInput).arg(pchainSt->m_untotalChainNumber-1).arg(nbitNum));
3046
                        iusrCoreCode.append(ilastPortConnect);
3047
                        iaddedCodeList.append(tr("\\bassign\\s+")+tr("%1\\s*\\[\\s*%2\\s*:\\s*%3\\s*\\]\\s*=\\s*%4\\s*\\[\\s*%5\\s*:\\s*%6\\s*\\]\\s*;") \
3048
                                              .arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
3049
                                              .arg(pchainSt->m_untotalChainNumber-1)\
3050
                                              .arg(nbitNum).arg(ilastInput).arg(pchainSt->m_untotalChainNumber-1).arg(nbitNum)
3051
                                              );
3052
                    }
3053
                    else
3054
                    {
3055
 
3056
                        if(nlastChainEndNum == -1) // module无寄存器 无插入链代码  直接透传
3057
                        {
3058
                            ilastPortConnect.append(tr("\n\t""assign %1 = %2 ;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
3059
                                                    .arg(ilastInput));
3060
                            iusrCoreCode.append(ilastPortConnect);
3061
                            iaddedCodeList.append(tr("\\bassign\\s+")+tr("%1\\s*=\\s*%2\\s*;") \
3062
                                                  .arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
3063
                                                  .arg(ilastInput));
3064
                        }
3065
                        else
3066
                        {
3067
                            ilastPortConnect.append(tr("\n\t""assign %1[%2] = %3[%4] ;").arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key())).arg(pchainSt->m_untotalChainNumber-1)\
3068
                                                    .arg(ilastInput).arg(pchainSt->m_untotalChainNumber-1));
3069
                            iusrCoreCode.append(ilastPortConnect);
3070
                            iaddedCodeList.append(tr("\\bassign\\s+")+tr("%1\\s*\\[\\s*%2\\s*\\]\\s*=\\s*%3\\s*\\[\\s*%4\\s*\\]\\s*;") \
3071
                                                  .arg(tr("_EziDebug_%1_%2_TDO_reg").arg(pchain->getChainName()).arg(iclockIterator.key()))\
3072
                                                  .arg(pchainSt->m_untotalChainNumber-1)\
3073
                                                  .arg(ilastInput).arg(pchainSt->m_untotalChainNumber-1)
3074
                                                  );
3075
                        }
3076
                    }
3077
                }
3078
 
3079
                ++iclockIterator ;
3080
            }
3081
        }
3082
        else
3083
        {
3084
            ntimesPerChain-- ;
3085
            pmodule->setInstancedTimesPerChain(pchain->getChainName(),ntimesPerChain);
3086
        }
3087
 
3088
        pchain->addToLineCodeMap(pmodule->getModuleName(),iaddedCodeList);
3089
        pchain->addToBlockCodeMap(pmodule->getModuleName(),iaddedBlockCodeList);
3090
        /*插入到字符串中*/
3091
 
3092
        ifileData.insert(imodulePos.m_nendModuleKeyWordPos + noffSet ,iusrCoreCode);
3093
 
3094
        if(!open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Truncate))
3095
        {
3096
            qDebug() << "Cannot Open file for writing:" << qPrintable(this->errorString());
3097
            return 1 ;
3098
        }
3099
 
3100
        QTextStream iout(this);
3101
        /*写入文件 */
3102
        iout <<  ifileData ;
3103
 
3104
        // 记录已经加入了 一系列 用户 core 代码
3105
        pmodule->setAddCodeFlag(true);
3106
 
3107
        close();
3108
        ilastModifedTime = ifileInfo.lastModified() ;
3109
        modifyStoredTime(ilastModifedTime);
3110
        return 0 ;
3111
    }
3112
    else
3113
    {
3114
        goto ErrorHandle ;
3115
    }
3116
 
3117
 
3118
ErrorHandle:
3119
 
3120
    /*关闭文件*/
3121
    close();
3122
    return 1 ;
3123
 
3124
}
3125
 
3126
int  EziDebugVlgFile::skipCommentaryFind(const QString &rangestring,int startpos ,SEARCH_STRING_STRUCTURE &stringtype,int &targetpos)
3127
{
3128
    int ncommentaryEnd = startpos ;
3129
    int isNoCommentary = 0 ;
3130
 
3131
    int  nfindPosOther = 0 ;
3132
    int  nfindPos = 0 ;
3133
    int  noffset = 0 ;
3134
    int  nleftBracketPos = 0 ;
3135
    int  nstartPos = 0 ;
3136
 
3137
    QString imoduleName(tr("No Name")) ;
3138
    QString ikeyWord(tr("No Name"));
3139
    QRegExp ifindExp(tr(" ")) ;
3140
    QRegExp ifindExpOther(tr(" ")) ;
3141
 
3142
 
3143
    QString ipartString ;
3144
 
3145
    if(stringtype.m_etype == SearchModuleKeyWordPos)
3146
    {
3147
        ikeyWord = tr("module");
3148
        imoduleName = QString::fromAscii(stringtype.m_icontent.m_imodulest.m_amoduleName);
3149
        ifindExpOther.setPattern(tr("\\b")+ikeyWord+tr("\\b"));
3150
        ifindExp.setPattern(tr("\\b")+ikeyWord+(tr("\\s+"))+imoduleName);
3151
    }
3152
    else if(stringtype.m_etype == SearchLeftBracketPos)
3153
    {
3154
        ifindExp.setPattern(tr("\\("));
3155
    }
3156
    else if(stringtype.m_etype == SearchSemicolonPos)
3157
    {
3158
        ifindExp.setPattern(tr(";"));
3159
    }
3160
    else
3161
    {
3162
        return 1 ;
3163
    }
3164
 
3165
    while(1)
3166
    {
3167
        nstartPos = ncommentaryEnd ;
3168
        ipartString = getNoCommentaryString(rangestring,ncommentaryEnd,isNoCommentary) ;
3169
        /*封装成1个函数 用于得到   输入为 上一个注释的结束、下一个注释的开始  输出为 一个无注释的字符串*/
3170
        /* 先扫描 module + module 名 并获得相应位置 */
3171
        /*1、如果没有扫到  直到字符串结束 ;如果最后也没有 就返回错误 ;如果成功就继续下一步 */
3172
        // while 循环
3173
        /*2、接着扫描所有 reg、port、wire、endmodule、instance*/
3174
 
3175
        /*3、遇到匹配的就 保存相应的字符串的位置 例如 遇到 "reg"  关键字时,从reg 下一个字符 获得 无注释字符串
3176
          查找 紧接着的 ; ,查找直到  最后1段无注释代码 也没有则 退出并返回错误,
3177
         并且重新 从匹配到的字符串后面 重新得到 下一个无注释字符串
3178
        然后继续扫描下个可能匹配的字符,直到遇到endmode 关键字 就退出 或者 最后1段无注释代码 匹配完成之后退出
3179
        当进行匹配 instance 时 分别构造正则表达式,进行匹配,如果匹配到 instance , 退出条件为最后1段无注释代码
3180
        */
3181
 
3182
FindString:
3183
 
3184
        if(SearchModuleKeyWordPos == stringtype.m_etype)
3185
        {
3186
            nfindPosOther = ipartString.indexOf(ifindExpOther) ;
3187
            nfindPos = ipartString.indexOf(ifindExp) ;
3188
            noffset = nstartPos + nfindPos + ifindExp.capturedTexts().at(0).count() ;
3189
 
3190
 
3191
            if(NO_STRING_FINDED == nfindPos)
3192
            {
3193
                if(NO_STRING_FINDED == nfindPosOther)
3194
                {
3195
                    /*在无注释情况下查找的*/
3196
                    if(NO_COMMENTARY == isNoCommentary)
3197
                    {
3198
                        return 1 ;
3199
                    }
3200
//                    isNeededFindFlag = true ;
3201
                    /*继续下一轮查找*/
3202
                    continue ;
3203
                }
3204
                else
3205
                {
3206
                    noffset = nstartPos + nfindPosOther + ifindExpOther.capturedTexts().count();
3207
 
3208
                    struct SEARCH_STRING_STRUCTURE inextFindSemicolon ;
3209
                    inextFindSemicolon.m_etype =  SearchSemicolonPos ;
3210
                    inextFindSemicolon.m_icontent.m_nreserved = 0 ;
3211
                    int nSemicolonPos = 0 ;
3212
                    /*查找 下一个有效的 ";" 字符 */
3213
                    if(!skipCommentaryFind(rangestring,noffset,inextFindSemicolon,nSemicolonPos))
3214
                    {
3215
                        /*截取从 module 名字出现的位置  到 ;所有的字符*/
3216
                        QString itruncateString  = rangestring.mid(nfindPosOther,nSemicolonPos-nfindPosOther-1);
3217
                        PORT_ANNOUNCE_FORMAT iportAnnounceformat = NonAnsicFormat ;
3218
                        int  nrelativeRightBracketPos = 0 ;
3219
                        int  nresult = 0 ;
3220
                        /*判断这段字符是否 匹配 module + module名  并判断是否为规范的port声明*/
3221
                        nresult =isModuleDefinition(itruncateString,imoduleName,iportAnnounceformat,nrelativeRightBracketPos) ;
3222
                        if(!nresult)
3223
                        {
3224
                            // 保存相应的位置  以及  类型信息
3225
                            /*找到 module */
3226
                            stringtype.m_icontent.m_imodulest.m_eportAnnounceFormat = iportAnnounceformat ;
3227
                            /*计算 ")" 绝对位置*/
3228
                            targetpos = nrelativeRightBracketPos + nfindPosOther ;
3229
                            int nlastNoblankChar = rangestring.lastIndexOf(QRegExp("\\S"),(targetpos-1));
3230
                            targetpos = nlastNoblankChar +1 ;
3231
                            return 0 ;
3232
                        }
3233
                        else if(1 == nresult)
3234
                        {
3235
//                          isNeededFindFlag = true ;
3236
                            /*继续下一轮查找*/
3237
                            continue;
3238
                        }
3239
                        else
3240
                        {
3241
                           return 1 ;
3242
                        }
3243
 
3244
                    }
3245
                    else
3246
                    {
3247
                        return 1 ;
3248
                    }
3249
                }
3250
            }// if(NO_STRING_FINDED == nfindPos)
3251
 
3252
            SEARCH_STRING_STRUCTURE inextFind ;
3253
            inextFind.m_etype = SearchLeftBracketPos ;
3254
            inextFind.m_icontent.m_nreserved = 0 ;
3255
 
3256
            int nleftBracketPos = 0 ;
3257
            if(!skipCommentaryFind(rangestring,noffset,inextFind,nleftBracketPos))
3258
            {
3259
                /*查找 与之对应的 下一个 ")"*/
3260
                struct  SEARCH_MODULE_STRUCTURE imoduleSt ;
3261
                imoduleSt.m_eportAnnounceFormat = NonAnsicFormat ;
3262
                strcpy(imoduleSt.m_amoduleName,imoduleName.toAscii().data());
3263
                struct  SEARCH_STRING_STRUCTURE inextFindRightBracket ;
3264
                inextFindRightBracket.m_etype = SearchModuleKeyWordPos ;
3265
                inextFindRightBracket.m_icontent.m_imodulest = imoduleSt ;
3266
                int nrightBracketPos = noffset ;
3267
                qDebug() << rangestring.mid(nleftBracketPos+1,100);
3268
                if(!findOppositeBracket(rangestring,nleftBracketPos+1,inextFindRightBracket,nrightBracketPos))
3269
                {
3270
                    targetpos = nrightBracketPos ;
3271
                    int nlastNoblankChar = rangestring.lastIndexOf(QRegExp("\\S"),(targetpos-1));
3272
                    targetpos = nlastNoblankChar + 1 ;
3273
                    /*接着返回 module 端口的书写类型 是否为标准 */
3274
                    stringtype.m_icontent.m_imodulest.m_eportAnnounceFormat =  \
3275
                            inextFindRightBracket.m_icontent.m_imodulest.m_eportAnnounceFormat ;
3276
                    // 保存相应的位置  以及  类型信息
3277
                   return 0 ;
3278
                }
3279
                else
3280
                {
3281
                    return 1 ;
3282
                }
3283
            }
3284
            else
3285
            {
3286
                return 1 ;
3287
            }
3288
        } //if(SearchModuleKeyWordPos == stringtype.m_etype)
3289
        else if(stringtype.m_etype == SearchLeftBracketPos)
3290
        {
3291
            nleftBracketPos = ipartString.indexOf(ifindExp) ;
3292
 
3293
            if(NO_STRING_FINDED == nleftBracketPos)
3294
            {
3295
                /*在字符串无注释情况下查找的*/
3296
                if(NO_COMMENTARY == isNoCommentary)
3297
                {
3298
                    return 1 ;
3299
                }
3300
                continue ;
3301
            }
3302
            else
3303
            {
3304
                nleftBracketPos += nstartPos ;
3305
                targetpos = nleftBracketPos ;
3306
                return 0 ;
3307
            }
3308
        }
3309
        else if(stringtype.m_etype == SearchSemicolonPos)
3310
        {
3311
            int nBackToBackSemicolonPos = 0 ;
3312
            nBackToBackSemicolonPos = ipartString.indexOf(ifindExp) ;
3313
            if(NO_STRING_FINDED == nBackToBackSemicolonPos)
3314
            {
3315
                /*在字符串无注释情况下查找的*/
3316
                if(NO_COMMENTARY == isNoCommentary)
3317
                {
3318
                    return 1 ;
3319
                }
3320
                continue ;
3321
            }
3322
            else
3323
            {
3324
                nBackToBackSemicolonPos += nstartPos ;
3325
                targetpos = nBackToBackSemicolonPos ;
3326
                return 0 ;
3327
            }
3328
        }
3329
        else if(stringtype.m_etype == SearchRightBracketPos)
3330
        {
3331
            // do nothing
3332
        }
3333
        else
3334
        {
3335
            return 1 ;
3336
        }
3337
 
3338
        if(1 == isNoCommentary)
3339
        {
3340
            goto FindString ;
3341
        }
3342
 
3343
      } // while(1)
3344
 
3345
 
3346
      return 0 ;
3347
    }
3348
 
3349
int EziDebugVlgFile::matchingTargetString(const QString &rangestring ,SEARCH_MODULE_POS_STRUCTURE &modulepos ,QMap<QString,SEARCH_INSTANCE_POS_STRUCTURE*> &instanceposmap)
3350
{
3351
    // 传入的是 无注释的字符串
3352
    /*port(output input)*/
3353
    QString ipartString ;
3354
    QString imoduleName ;
3355
    QString iinstanceName ;
3356
 
3357
    int ncommentaryEnd = modulepos.m_nnextRightBracketPos + 1;
3358
    int isNoCommentary = 0 ;
3359
    int nlastRegtKeyWordPos = -1 ;
3360
    int nlastWireKeyWordPos = -1 ;
3361
    int nendmoduleKeyWordPos = -1 ;
3362
 
3363
    int  nfindPosOther = 0 ;
3364
    int  nfindPos = 0 ;
3365
    int  noffset = 0 ;
3366
    int  nsaveStartPos = 0 ;
3367
    int  nendInsertPos = 0 ;
3368
    int  nendLastChar = 0 ;
3369
    int  nannounceInsertPos  = 0 ;
3370
 
3371
    bool ismoduleEnd = false ;
3372
    QRegExp ifindOutputPortExp(tr("\\b") + tr("output") +tr("\\b")) ;
3373
    QRegExp ifindInputPortPortExpOther(tr("\\b") + tr("input") +tr("\\b")) ;
3374
    /*reg*/
3375
    QRegExp ifindRegExp(tr("\\b") + tr("reg") +tr("\\b"));
3376
    /*wire*/
3377
    QRegExp ifindWireExp(tr("\\b") + tr("wire") +tr("\\b"));
3378
    /*endmodule*/
3379
    QRegExp ifindEndmoduleExp(tr("\\b") + tr("endmodule") +tr("\\b"));
3380
 
3381
    QRegExp ifindInstanceExp(tr(" "));
3382
    QRegExp ifindInstanceExpOther(tr(" "));
3383
 
3384
 
3385
    while(1)
3386
    {
3387
        nsaveStartPos = ncommentaryEnd ;
3388
        ipartString = getNoCommentaryString(rangestring,ncommentaryEnd,isNoCommentary) ;
3389
 
3390
        nendmoduleKeyWordPos = ipartString.indexOf(ifindEndmoduleExp);
3391
        if(nendmoduleKeyWordPos != -1)
3392
        {
3393
            /*保存相应位置*/
3394
            // endmodule 关键字不能为 顶头字符串,否则从 最后查找
3395
            if(nendmoduleKeyWordPos)
3396
            {
3397
                if(ipartString.lastIndexOf(QRegExp(tr("\\S")),nendmoduleKeyWordPos -1) != -1)
3398
                {
3399
                    nendInsertPos = nsaveStartPos + ipartString.lastIndexOf(QRegExp(tr("\\S")),nendmoduleKeyWordPos -1) ;
3400
                }
3401
            }
3402
 
3403
            modulepos.m_nendModuleKeyWordPos = nendInsertPos + 1;
3404
 
3405
            ismoduleEnd = true ;
3406
        }
3407
        else
3408
        {
3409
            if(-1 != ipartString.lastIndexOf(QRegExp(tr("\\S"))))
3410
            {
3411
                qDebug() << ipartString ;
3412
                nendInsertPos = nsaveStartPos + ipartString.lastIndexOf(QRegExp(tr("\\S"))) ;
3413
            }
3414
        }
3415
 
3416
        // 非标准则进行扫描 最后个端口位置
3417
        if(NonAnsicFormat == modulepos.m_eportFormat)
3418
        {
3419
            if(ipartString.contains(ifindOutputPortExp)||ipartString.contains(ifindInputPortPortExpOther))
3420
            {
3421
                int nlastPortKeyWordPos = 0 ;
3422
                int noutputKeyWordPos = ipartString.lastIndexOf(ifindOutputPortExp,nendmoduleKeyWordPos) ;
3423
                int ninputKeyWordPos = ipartString.lastIndexOf(ifindInputPortPortExpOther,nendmoduleKeyWordPos) ;
3424
 
3425
 
3426
                if(-1 == ninputKeyWordPos)
3427
                {
3428
                    nlastPortKeyWordPos = nsaveStartPos + noutputKeyWordPos ;
3429
                }
3430
                else if(-1 == noutputKeyWordPos)
3431
                {
3432
                    nlastPortKeyWordPos = nsaveStartPos + ninputKeyWordPos ;
3433
                }
3434
                else
3435
                {
3436
                    if(noutputKeyWordPos > ninputKeyWordPos)
3437
                    {
3438
                        nlastPortKeyWordPos = nsaveStartPos + noutputKeyWordPos ;
3439
                    }
3440
                    else
3441
                    {
3442
                        nlastPortKeyWordPos = nsaveStartPos + ninputKeyWordPos ;
3443
                    }
3444
                }
3445
 
3446
                /*保存相应位置*/
3447
                /*找到 紧接着的 ";" */
3448
                struct SEARCH_STRING_STRUCTURE inextFind ;
3449
                inextFind.m_etype = SearchSemicolonPos ;
3450
                inextFind.m_icontent.m_nreserved = 0 ;
3451
                int  nsemicolonPos = 0 ;
3452
                if(!skipCommentaryFind(rangestring , nlastPortKeyWordPos , inextFind , nsemicolonPos))
3453
                {
3454
                    // 然后保存 继续下一个判断
3455
                    modulepos.m_nlastPortKeyWordPos = nsemicolonPos + 1;
3456
                }
3457
                else
3458
                {
3459
                    return 1 ;
3460
                }
3461
            }
3462
        }
3463
 
3464
 
3465
        QMap<QString,SEARCH_INSTANCE_POS_STRUCTURE*>::iterator i = instanceposmap.begin();
3466
        while (i != instanceposmap.end())
3467
        {
3468
            struct SEARCH_INSTANCE_POS_STRUCTURE *pinstance = i.value() ;
3469
            imoduleName = QString::fromAscii(pinstance->m_amoduleName);
3470
            iinstanceName = QString::fromAscii(pinstance->m_ainstanceName) ;
3471
            ifindInstanceExp.setPattern(tr("\\b")+ imoduleName + tr("\\s+") + iinstanceName +tr("\\b"));
3472
            ifindInstanceExpOther.setPattern(tr("\\b")+imoduleName+tr("\\b"));
3473
 
3474
            /*搜索 例化模块 出现的位置*/
3475
            /*判断例化的类型 并返回紧接着的与第一次出现 "(" 相对应的 ")" 的位置 */
3476
            nfindPosOther = ipartString.indexOf(ifindInstanceExpOther) ;
3477
            nfindPos = ipartString.indexOf(ifindInstanceExp) ;
3478
            noffset = nsaveStartPos + nfindPos + ifindInstanceExp.capturedTexts().at(0).count() ;
3479
 
3480
            if(NO_STRING_FINDED == nfindPos)
3481
            {
3482
                if(NO_STRING_FINDED == nfindPosOther)
3483
                {
3484
                    /*在无注释情况下查找的*/
3485
                    if(NO_COMMENTARY == isNoCommentary)
3486
                    {
3487
                        return 1 ;
3488
                    }
3489
                    /*继续下一轮查找 1 个 例化 */
3490
                    i++ ;
3491
                    continue ;
3492
                }
3493
                else
3494
                {
3495
                    noffset = nsaveStartPos + nfindPosOther + ifindInstanceExpOther.capturedTexts().count() ;
3496
                    /*查找紧接着的左括号 */
3497
                    /*查找与左括号对应的 右括号 */
3498
                    /*返回找到的位置 如果错误则 返回*/
3499
                    struct SEARCH_STRING_STRUCTURE inextFindSemicolon ;
3500
                    inextFindSemicolon.m_etype = SearchSemicolonPos ;
3501
                    inextFindSemicolon.m_icontent.m_nreserved = 0 ;
3502
 
3503
                    int nrightSemicolonPos = 0 ;
3504
                    /*查找 下一个有效的 ";" 字符 */
3505
                    if(!skipCommentaryFind(rangestring,noffset,inextFindSemicolon,nrightSemicolonPos))
3506
                    {
3507
                        /*截取从 module 名字出现的位置  到 ;所有的字符*/
3508
                        QString itruncateString  = rangestring.mid(nfindPosOther,nrightSemicolonPos-nfindPosOther +1);
3509
                        INSTANCE_FORMAT iinstance_format = NonStardardFormat ;
3510
                        int nresult = 0 ;
3511
                        int nrelativeRightBracketPos = 0 ;
3512
                        nresult = isModuleInstance(itruncateString,imoduleName,iinstanceName,iinstance_format,nrelativeRightBracketPos) ;
3513
 
3514
                        if(rangestring.lastIndexOf(QRegExp(tr("\\S")),(nsaveStartPos + nfindPosOther -1)) != -1)
3515
                        {
3516
                            nannounceInsertPos = rangestring.lastIndexOf(QRegExp(tr("\\S")),(nsaveStartPos + nfindPosOther -1)) ;
3517
                        }
3518
 
3519
                        /*判断这段字符是否 匹配 module名+例化名  并判断是否为规范的端口连接*/
3520
                        if(!nresult)
3521
                        {
3522
                            /*找到 module 保存信息*/
3523
                            pinstance->m_nnextRightBracketPos = nrelativeRightBracketPos +  nfindPosOther ;
3524
                            pinstance->m_nstartPos  = nannounceInsertPos + 1 ;
3525
                            pinstance->m_einstanceFormat = iinstance_format ;
3526
                            i++ ;
3527
                            continue ;
3528
                        }
3529
                        else if(1 == nresult)
3530
                        {
3531
//                          isNeededFindFlag = true ;
3532
                            /*继续下一轮查找*/
3533
                            i++ ;
3534
                            continue ;
3535
                        }
3536
                        else
3537
                        {
3538
                            return 1 ;
3539
                        }
3540
                    }
3541
                    else
3542
                    {
3543
                        return 1 ;
3544
                    }
3545
                }
3546
            }
3547
 
3548
            struct SEARCH_STRING_STRUCTURE inextFind ;
3549
            inextFind.m_etype = SearchLeftBracketPos ;
3550
            inextFind.m_icontent.m_eInstanceFormat = NonStardardFormat ;
3551
 
3552
            if(rangestring.lastIndexOf(QRegExp(tr("\\S")),(nsaveStartPos + nfindPos -1)) != -1)
3553
            {
3554
                nannounceInsertPos = rangestring.lastIndexOf(QRegExp(tr("\\S")),(nsaveStartPos + nfindPos -1)) ;
3555
            }
3556
 
3557
            int nleftBracketPos = 0 ;
3558
//          QString itest1 = rangestring.mid(noffset);
3559
//          qDebug() << itest1 ;
3560
            if(!skipCommentaryFind(rangestring,noffset,inextFind,nleftBracketPos))
3561
            {
3562
                /*查找 与之对应的 下一个 ")"*/
3563
                struct SEARCH_STRING_STRUCTURE inextFindRightBracket ;
3564
                inextFindRightBracket.m_etype = SearchInstancePos ;
3565
                inextFindRightBracket.m_icontent.m_eInstanceFormat = NonStardardFormat ;
3566
 
3567
                int nrightBracketPos = 0 ;
3568
                if(!findOppositeBracket(rangestring,nleftBracketPos+1,inextFindRightBracket,nrightBracketPos))
3569
                {
3570
                      QString itest2 = rangestring.mid(noffset,nrightBracketPos - nleftBracketPos - 1);
3571
                      QString itest3 = rangestring.mid(nannounceInsertPos , nrightBracketPos - nannounceInsertPos - 1);
3572
                      pinstance->m_nnextRightBracketPos = nrightBracketPos ;
3573
                      pinstance->m_nstartPos  = nannounceInsertPos + 1 ;
3574
                      pinstance->m_einstanceFormat = inextFindRightBracket.m_icontent.m_eInstanceFormat ;
3575
 
3576
                      /*接着返回 module 端口的书写类型 是否为标准 */
3577
//                    stringtype.m_isearchContent.m_iinstanceStructure.m_einstanceFormat =  \
3578
//                            inextFindRightBracket.m_isearchContent.m_iinstanceStructure.m_einstanceFormat ;
3579
                      ++i ;
3580
                      continue ;
3581
                }
3582
                else
3583
                {
3584
                    return 1 ;
3585
                }
3586
            }
3587
            else
3588
            {
3589
                return 1 ;
3590
            }
3591
 
3592
            ++i;
3593
        }
3594
 
3595
        if(ismoduleEnd)
3596
        {
3597
            return 0 ;
3598
        }
3599
 
3600
        // 正常时扫描到 endmodule 关键字 再退出 ,不应该在无注释下 没扫描到  endmodule 退出
3601
        if(isNoCommentary)
3602
        {
3603
            return 1 ;
3604
        }
3605
    }
3606
}
3607
 
3608
 
3609
 
3610
int EziDebugVlgFile::findOppositeBracket(const QString &rangestring,int startpos ,SEARCH_STRING_STRUCTURE &stringtype,int &targetpos)
3611
{
3612
    int ncommentaryBegin = 0 ;
3613
    int ncommentaryEnd   = startpos ;
3614
    QString ipartString ;
3615
    QString inoCommentaryStr ;
3616
    QString icheckString ;
3617
    QString itestString ;
3618
 
3619
    int commentaryBegin_row  = 0 ; // 行注释开始
3620
    int commentaryBegin_sec  = 0 ; // 段注释开始
3621
    int scanPos = startpos ;
3622
    int nsavePos = 0 ;
3623
    int nstartBracketPos = 0 ;
3624
 
3625
    //bool isNeededFindFlag = 0 ;
3626
    int  nappearanceCount = 1 ;
3627
    int  nleftBracketPos = 0 ;
3628
    int  nrightBracketPos = 0 ;
3629
    //inoCommentaryStr = replaceCommentaryByBlank(rangestring) ;
3630
//    QFile itest("d:/save.txt") ;
3631
//    itest.open(QIODevice::WriteOnly|QIODevice::Truncate);
3632
 
3633
//    QTextStream iout(&itest) ;
3634
//    iout << inoCommentaryStr ;
3635
//    int Pos1 = rangestring.indexOf("ifft_airif_rdctrl");
3636
//    int Pos2 = inoCommentaryStr.indexOf("ifft_airif_rdctrl");
3637
 
3638
    while(1)
3639
    {
3640
        // 查找下一个 注释的开始位置
3641
        commentaryBegin_row = rangestring.indexOf(tr("//"),scanPos) ;
3642
        commentaryBegin_sec = rangestring.indexOf(tr("/*"),scanPos) ;
3643
 
3644
        if((commentaryBegin_row == -1)&&(commentaryBegin_sec == -1))
3645
        {
3646
            /*没有注释了 从scanPos 截取剩余所有的字符串 */
3647
            ipartString = rangestring.mid(ncommentaryEnd) ;
3648
            nsavePos = ncommentaryEnd ;
3649
            ncommentaryEnd = NO_COMMENTARY ;
3650
        }
3651
        else if(commentaryBegin_row == -1)
3652
        {
3653
            /*下一个注释开始位置为 */
3654
            ncommentaryBegin = commentaryBegin_sec ;
3655
            ipartString = rangestring.mid(ncommentaryEnd,ncommentaryBegin-ncommentaryEnd) ;
3656
            nsavePos = ncommentaryEnd ;
3657
            // 下一个注释结束位置 */
3658
            ncommentaryEnd = rangestring.indexOf(tr("*/"),ncommentaryBegin) ;
3659
 
3660
            if(ncommentaryEnd == -1)
3661
            {
3662
                return 1;
3663
            }
3664
            scanPos = ncommentaryEnd + 2 ;
3665
        }
3666
        else if(commentaryBegin_sec == -1)
3667
        {
3668
            /*下一个注释开始位置为 */
3669
            ncommentaryBegin = commentaryBegin_row ;
3670
            ipartString = rangestring.mid(ncommentaryEnd,ncommentaryBegin-ncommentaryEnd) ;
3671
 
3672
            nsavePos = ncommentaryEnd ;
3673
            ncommentaryEnd = rangestring.indexOf(tr("\n"),ncommentaryBegin) ;
3674
            if(ncommentaryEnd == -1)
3675
            {
3676
                return 1;
3677
            }
3678
            scanPos = ncommentaryEnd + 1;
3679
        }
3680
        else
3681
        {
3682
            if(commentaryBegin_row < commentaryBegin_sec)
3683
            {
3684
                ncommentaryBegin = commentaryBegin_row ;
3685
                ipartString = rangestring.mid(ncommentaryEnd,ncommentaryBegin-ncommentaryEnd) ;
3686
                nsavePos = ncommentaryEnd ;
3687
                ncommentaryEnd = rangestring.indexOf(tr("\n"),ncommentaryBegin) ;
3688
                if(ncommentaryEnd == -1)
3689
                {
3690
                    return 1 ;
3691
                }
3692
                scanPos = ncommentaryEnd + 1;
3693
            }
3694
            else
3695
            {
3696
                ncommentaryBegin = commentaryBegin_sec ;
3697
                ipartString = rangestring.mid(ncommentaryEnd,ncommentaryBegin-ncommentaryEnd) ;
3698
                nsavePos = ncommentaryEnd ;
3699
                ncommentaryEnd = rangestring.indexOf(tr("*/"),ncommentaryBegin) ;
3700
                if(ncommentaryEnd == -1)
3701
                {
3702
                    return 1;
3703
                }
3704
                scanPos = ncommentaryEnd + 2 ;
3705
            }
3706
        }
3707
 
3708
        //int  nstartPos = startpos ;
3709
 
3710
        /*从这段无注释的代码中 找对应的括号的位置*/
3711
 
3712
        /*如果这段无注释 代码 包含 "output" 或者 "input "关键字,则为*/
3713
 
3714
        if(-1 == nsavePos)
3715
        {
3716
            return 1 ;
3717
        }
3718
 
3719
 
3720
        qDebug() << ipartString ;
3721
        nstartBracketPos = 0 ;
3722
        while(1)
3723
        {
3724
            /*是否存在 左括号 和 右括号*/
3725
            nleftBracketPos = ipartString.indexOf("(",nstartBracketPos);
3726
            nrightBracketPos = ipartString.indexOf(")",nstartBracketPos);
3727
 
3728
            if((NO_STRING_FINDED == nleftBracketPos)&&(NO_STRING_FINDED == nrightBracketPos))
3729
            {
3730
                break ;
3731
            }
3732
            else if(NO_STRING_FINDED == nleftBracketPos)
3733
            {
3734
                /*只有 ")"*/
3735
                nappearanceCount-- ;
3736
                if(0 == nappearanceCount)
3737
                {
3738
                    goto CheckType ;
3739
                }
3740
                nstartBracketPos = nrightBracketPos + 1 ;
3741
            }
3742
            else if(NO_STRING_FINDED == nrightBracketPos)
3743
            {
3744
                /*只有 "("*/
3745
                nstartBracketPos = nleftBracketPos + 1 ;
3746
                nappearanceCount++ ;
3747
            }
3748
            else
3749
            {
3750
                if(nleftBracketPos < nrightBracketPos)
3751
                {
3752
                    /*遇到 "("*/
3753
                    nappearanceCount++ ;
3754
                    nstartBracketPos = nleftBracketPos + 1 ;
3755
                }
3756
                else
3757
                {
3758
                    /*遇到 ")"*/
3759
                    nappearanceCount-- ;
3760
 
3761
                    if(0 == nappearanceCount)
3762
                    {
3763
 
3764
                        goto CheckType ;
3765
                    }
3766
                    nstartBracketPos = nrightBracketPos + 1 ;
3767
                }
3768
            }
3769
        }
3770
    }
3771
 
3772
CheckType:
3773
        qDebug() << rangestring.mid(nsavePos,nrightBracketPos);
3774
        targetpos = nsavePos + nrightBracketPos ;
3775
        int n = targetpos - startpos + 1 ;
3776
        icheckString = rangestring.mid(startpos , n );
3777
        qDebug() << "origin string! "<<icheckString ;
3778
        icheckString = replaceCommentaryByBlank(icheckString);
3779
        qDebug() << "port string! "<<icheckString ;
3780
 
3781
        //itestString = rangestring.mid(scanPos ,targetpos - scanPos + 1 );
3782
        if(SearchModuleKeyWordPos == stringtype.m_etype)
3783
        {
3784
            if(icheckString.contains("input",Qt::CaseInsensitive)||icheckString.contains("output",Qt::CaseInsensitive))
3785
            {
3786
                stringtype.m_icontent.m_imodulest.m_eportAnnounceFormat = AnsicFormat ;
3787
            }
3788
        }
3789
        else if(SearchInstancePos == stringtype.m_etype)
3790
        {
3791
            // .mc_ul_start       ( mc_ul_start       ),
3792
            // 标准的 查找 上一个 ")"
3793
            if(icheckString.contains(QRegExp(tr(".")+ tr("\\s*\\w+") + tr("\\s*\\(")+ tr(".*") + tr("\\)"))))
3794
            {
3795
                stringtype.m_icontent.m_eInstanceFormat = StardardForamt ;
3796
                targetpos = ipartString.lastIndexOf(')',nrightBracketPos-1);
3797
                if(-1 == targetpos)
3798
                {
3799
                   return 1 ;
3800
                }
3801
                targetpos = nsavePos + targetpos + 1 ;
3802
            }
3803
            else
3804
            {
3805
                // 非标准的 查找 上一个 非空白字符
3806
                targetpos = ipartString.lastIndexOf(QRegExp(tr("\\S")),nrightBracketPos-1);
3807
                if(-1 == targetpos)
3808
                {
3809
                   return 1 ;
3810
                }
3811
                targetpos = nsavePos + targetpos + 1 ;
3812
            }
3813
        }
3814
        else
3815
        {
3816
            return 1 ;
3817
        }
3818
 
3819
    return 0 ;
3820
}
3821
 
3822
 
3823
QString EziDebugVlgFile::getNoCommentaryString(const QString &rangestring,int &lastcommentaryend ,int &nocommontaryflag)
3824
{
3825
    int commentaryBegin_row = 0 ;
3826
    int commentaryBegin_sec = 0 ;
3827
    int scanPos = lastcommentaryend ;
3828
    int ncommentaryEnd = 0 ;
3829
    int ncommentaryBegin = 0 ;
3830
    QString ipartString ;
3831
    // 查找下一个 注释的开始位置
3832
 
3833
    if(lastcommentaryend == -1)
3834
    {
3835
        /*全是注释  返回空字符串*/
3836
        ipartString.clear();
3837
        return ipartString ;
3838
    }
3839
 
3840
    commentaryBegin_row = rangestring.indexOf(tr("//"),scanPos) ;
3841
    commentaryBegin_sec = rangestring.indexOf(tr("/*"),scanPos) ;
3842
 
3843
    if((commentaryBegin_row == -1)&&(commentaryBegin_sec == -1))
3844
    {
3845
        ipartString = rangestring.mid(scanPos) ;
3846
        /*没有注释了 从scanPos 截取剩余所有的字符串 */
3847
        ncommentaryEnd = -1 ;
3848
        // 最后一次扫描 的起始位置  就无注释
3849
        lastcommentaryend =  scanPos ;
3850
        nocommontaryflag = true ;
3851
    }
3852
    else if(commentaryBegin_row == -1)
3853
    {
3854
        /*下一个注释开始位置为 */
3855
        ncommentaryBegin = commentaryBegin_sec ;
3856
        ipartString = rangestring.mid(scanPos,ncommentaryBegin-scanPos) ;
3857
 
3858
        // 下一个注释结束位置 */
3859
        ncommentaryEnd = rangestring.indexOf(tr("*/"),ncommentaryBegin) ;
3860
        if(ncommentaryEnd == -1)
3861
        {
3862
            // 接下来都是注释
3863
            lastcommentaryend = -1 ;
3864
            return ipartString ;
3865
        }
3866
        lastcommentaryend = ncommentaryEnd  + 2;
3867
    }
3868
    else if(commentaryBegin_sec == -1)
3869
    {
3870
        /*下一个注释开始位置为 // */
3871
        ncommentaryBegin = commentaryBegin_row ;
3872
        ipartString = rangestring.mid(scanPos,ncommentaryBegin-scanPos) ;
3873
 
3874
 
3875
        ncommentaryEnd = rangestring.indexOf(tr("\n"),ncommentaryBegin + 2);
3876
        if(ncommentaryEnd == -1)
3877
        {
3878
            // 接下来都是注释
3879
            lastcommentaryend = -1 ;
3880
            return ipartString ;
3881
        }
3882
        lastcommentaryend =  ncommentaryEnd + 1;
3883
    }
3884
    else
3885
    {
3886
        if(commentaryBegin_row < commentaryBegin_sec)
3887
        {
3888
            ncommentaryBegin = commentaryBegin_row ;
3889
            ipartString = rangestring.mid(scanPos,ncommentaryBegin-scanPos) ;
3890
 
3891
            ncommentaryEnd = rangestring.indexOf(tr("\n"),ncommentaryBegin) ;
3892
            if(ncommentaryEnd == -1)
3893
            {
3894
                // 接下来都是注释
3895
                lastcommentaryend = -1 ;
3896
                return ipartString ;
3897
            }
3898
            lastcommentaryend =  ncommentaryEnd + 1 ;
3899
        }
3900
        else
3901
        {
3902
            ncommentaryBegin = commentaryBegin_sec ;
3903
            ipartString = rangestring.mid(scanPos,ncommentaryBegin-scanPos) ;
3904
 
3905
            ncommentaryEnd = rangestring.indexOf(tr("*/"),ncommentaryBegin) ;
3906
            if(ncommentaryEnd == -1)
3907
            {
3908
                // 接下来都是注释
3909
                lastcommentaryend = -1 ;
3910
                return ipartString ;
3911
 
3912
            }
3913
            lastcommentaryend =  ncommentaryEnd + 2 ;
3914
        }
3915
    }
3916
    return  ipartString ;
3917
}
3918
 
3919
 
3920
 
3921
QString EziDebugVlgFile::replaceCommentaryByBlank(const QString &rangestring)
3922
{
3923
    QString data = rangestring ;
3924
    int commentaryBegin_row = 0 ; // 行注释开始
3925
    int commentaryBegin_sec = 0 ; // 段注释开始
3926
    int commentaryEnd_row = 0 ;  // 行注释结束
3927
    int commentaryEnd_sec = 0 ;  // 段注释结束
3928
    int nstartPos = 0 ;
3929
 
3930
    commentaryBegin_row =  data.indexOf(tr("//"),nstartPos);
3931
    commentaryBegin_sec =  data.indexOf(tr("/*"),nstartPos);
3932
    while((commentaryBegin_row != -1)||(commentaryBegin_sec != -1))
3933
    {
3934
        if(commentaryBegin_row == -1)
3935
        {
3936
            commentaryEnd_sec = data.indexOf(tr("*/"), commentaryBegin_sec);
3937
            data.replace(commentaryBegin_sec,commentaryEnd_sec - commentaryBegin_sec + 2,tr(" ").repeated(commentaryEnd_sec - commentaryBegin_sec + 2));
3938
            commentaryBegin_sec =  data.indexOf(tr("/*"), commentaryBegin_sec);
3939
        }
3940
        else if(commentaryBegin_sec == -1)
3941
        {
3942
            commentaryEnd_row = data.indexOf(tr("\n"), commentaryBegin_row);
3943
            if(commentaryEnd_row == -1)
3944
            {
3945
                int ncharPos = data.lastIndexOf(QRegExp(".*")) ;
3946
                data.replace(commentaryBegin_row , ncharPos - commentaryBegin_row + 1,tr(" ").repeated(ncharPos - commentaryBegin_row + 1));
3947
            }
3948
            else
3949
            {
3950
                data.replace(commentaryBegin_row,commentaryEnd_row - commentaryBegin_row,tr(" ").repeated(commentaryEnd_row - commentaryBegin_row));
3951
            }
3952
            commentaryBegin_row =  data.indexOf(tr("//"), commentaryBegin_row);
3953
 
3954
        }
3955
        else
3956
        {
3957
            /*行注释开始 在 段注释开始 之前*/
3958
            if( commentaryBegin_row < commentaryBegin_sec )
3959
            {
3960
                /*删除行注释表示符开始后的一行字符*/
3961
                commentaryEnd_row = data.indexOf(tr("\n"), commentaryBegin_row);
3962
                if(commentaryEnd_row == -1)
3963
                {
3964
                    int ncharPos = data.lastIndexOf(QRegExp(".*")) ;
3965
                    data.replace(commentaryBegin_row , ncharPos - commentaryBegin_row + 1,tr(" ").repeated(ncharPos - commentaryBegin_row + 1));
3966
                }
3967
                else
3968
                {
3969
                    data.replace(commentaryBegin_row,commentaryEnd_row - commentaryBegin_row,tr(" ").repeated(commentaryEnd_row - commentaryBegin_row));
3970
                }
3971
                commentaryBegin_sec =  data.indexOf(tr("/*"), commentaryBegin_row);
3972
                commentaryBegin_row =  data.indexOf(tr("//"), commentaryBegin_row);
3973
            }
3974
            /*段注释开始 在 行注释开始 之前*/
3975
            else
3976
            {
3977
                commentaryEnd_sec = data.indexOf(tr("*/"), commentaryBegin_sec);
3978
                data.replace(commentaryBegin_sec,commentaryEnd_sec - commentaryBegin_sec + 2,tr(" ").repeated(commentaryEnd_sec - commentaryBegin_sec + 2));
3979
                commentaryBegin_row =  data.indexOf(tr("//"), commentaryBegin_sec);
3980
                commentaryBegin_sec =  data.indexOf(tr("/*"), commentaryBegin_sec);
3981
            }
3982
        }
3983
 
3984
    }
3985
    return data ;
3986
}
3987
 
3988
int EziDebugVlgFile::isModuleInstance(const QString &rangestring,const QString &modulename , const QString& instancename,INSTANCE_FORMAT &type ,int &targetpos)
3989
{
3990
    QString data = replaceCommentaryByBlank(rangestring);
3991
 
3992
    QRegExp ifindExp(tr("\\b")+ modulename + tr("\\s+") + instancename +tr("\\b")) ;
3993
 
3994
    if(NO_STRING_FINDED == data.indexOf(ifindExp))
3995
    {
3996
        return 1 ;
3997
    }
3998
 
3999
    /*找到接着的 "("*/
4000
    struct SEARCH_STRING_STRUCTURE ifindLeftBracket ;
4001
    ifindLeftBracket.m_etype = SearchLeftBracketPos ;
4002
    ifindLeftBracket.m_icontent.m_nreserved = 0  ;
4003
 
4004
    int nleftBracketPos = 0 ;
4005
    if(!skipCommentaryFind(rangestring,0,ifindLeftBracket,nleftBracketPos))
4006
    {
4007
        struct SEARCH_STRING_STRUCTURE ifindRightBracket ;
4008
        ifindRightBracket.m_etype = SearchInstancePos ;
4009
        ifindRightBracket.m_icontent.m_eInstanceFormat = NonStardardFormat ;
4010
 
4011
        int nrightBracketPos = 0 ;
4012
        if(!findOppositeBracket(rangestring,nleftBracketPos+1,ifindRightBracket,nrightBracketPos))
4013
        {
4014
            targetpos = nrightBracketPos ;
4015
            type = ifindRightBracket.m_icontent.m_eInstanceFormat ;
4016
            return 0 ;
4017
        }
4018
        else
4019
        {
4020
            return 2 ;
4021
        }
4022
    }
4023
    else
4024
    {
4025
        return 2 ;
4026
    }
4027
}
4028
 
4029
 
4030
int EziDebugVlgFile::isModuleDefinition(const QString &rangestring,const QString &modulename ,PORT_ANNOUNCE_FORMAT &type,int &targetpos)
4031
{
4032
    QString data = replaceCommentaryByBlank(rangestring);
4033
 
4034
    QRegExp ifindExp(tr("\\b")+ modulename + tr("\\b")) ;
4035
 
4036
    if(NO_STRING_FINDED == data.indexOf(ifindExp))
4037
    {
4038
        return 1 ;
4039
    }
4040
 
4041
    /*找到接着的 "("*/
4042
    struct SEARCH_STRING_STRUCTURE ifindLeftBracket ;
4043
    ifindLeftBracket.m_etype = SearchLeftBracketPos ;
4044
    ifindLeftBracket.m_icontent.m_nreserved = 0 ;
4045
 
4046
    int nleftBracketPos = 0 ;
4047
    if(!skipCommentaryFind(rangestring,0,ifindLeftBracket,nleftBracketPos))
4048
    {
4049
        struct  SEARCH_MODULE_STRUCTURE imoduleSt ;
4050
        struct SEARCH_STRING_STRUCTURE ifindRightBracket ;
4051
        ifindRightBracket.m_etype = SearchRightBracketPos ;
4052
        imoduleSt.m_eportAnnounceFormat = NonAnsicFormat ;
4053
        strcpy(imoduleSt.m_amoduleName,modulename.toAscii().data());
4054
        ifindRightBracket.m_icontent.m_imodulest = imoduleSt ;
4055
 
4056
 
4057
        int nrightBracketPos = 0 ;
4058
        if(!findOppositeBracket(rangestring,nleftBracketPos+1,ifindRightBracket,nrightBracketPos))
4059
        {
4060
            targetpos = nrightBracketPos ;
4061
            type = ifindRightBracket.m_icontent.m_imodulest.m_eportAnnounceFormat ;
4062
            return 0 ;
4063
        }
4064
        else
4065
        {
4066
            return 2 ;
4067
        }
4068
    }
4069
    else
4070
    {
4071
        return 2 ;
4072
    }
4073
 
4074
//    // 存在 output 或者 input 关键字
4075
//    ifindExp.setPattern(tr("\\b") + tr("output") + tr("\\b"));
4076
//    QRegExp ifindExpOther(tr("\\b") + tr("input") + tr("\\b"));
4077
 
4078
//    if(data.contains(ifindExp)||data.contains(ifindExpOther))
4079
//    {
4080
//        type = AnsicFormat ;
4081
//    }
4082
//    else
4083
//    {
4084
//        type = NonAnsicFormat ;
4085
//    }
4086
 
4087
}
4088
 
4089
int EziDebugVlgFile::isStringReiteration(const QString &poolstring ,const QString& string)
4090
{
4091
    if(poolstring.contains(QRegExp(tr("\b")+string + tr("\b"))))
4092
    {
4093
        return 0 ;
4094
    }
4095
    return 1 ;
4096
}
4097
 
4098
QString  EziDebugVlgFile::constructChainRegString(EziDebugModule::RegStructure* reg, int regnum , int startbit ,int endbit ,EziDebugInstanceTreeItem *item)
4099
{
4100
    QString iregName ;
4101
    QString istartBit ;
4102
    QString iendBit ;
4103
    QString imoduleName = QString::fromAscii(reg->m_pMouduleName);
4104
    QStringList ifullNameList ;
4105
    QString ibitWitdth = QString::fromAscii(reg->m_pExpString);
4106
 
4107
    QString istartRegNum = QString::number(reg->m_unStartNum);
4108
    QString iendRegNum = QString::number(reg->m_unEndNum);
4109
 
4110
    QString ihiberarchyname = item->getItemHierarchyName() ;
4111
    QString iinstanceName = item->getInstanceName() ;
4112
 
4113
    QString iregNum = QString::fromAscii(reg->m_pregNum);
4114
    QString iclockName = QString::fromAscii(reg->m_pclockName);
4115
 
4116
    QString iresult ;
4117
    if(!reg)
4118
    {
4119
        return QString();
4120
    }
4121
    else
4122
    {
4123
        // 寄存器名 包括数组时 使用  aaa[m]
4124
        if(reg->m_unRegNum != 1)
4125
        {
4126
            iregName.append(tr("%1[%2]").arg(QString::fromAscii(reg->m_pRegName)).arg(regnum));
4127
        }
4128
        else
4129
        {
4130
            iregName.append(tr("%1").arg(QString::fromAscii(reg->m_pRegName)));
4131
        }
4132
 
4133
        // 开始位
4134
        istartBit.append(QString::number(startbit));
4135
        // 结束位
4136
        iendBit.append(QString::number(endbit));
4137
 
4138
    }
4139
 
4140
    ifullNameList << imoduleName << iinstanceName << iclockName << ihiberarchyname << iregName << istartBit << iendBit << ibitWitdth << istartRegNum  << iendRegNum << iregNum   ;
4141
    iresult = ifullNameList.join(tr("#")) ;
4142
    return (iresult) ;
4143
}
4144
 
4145
 
4146
int EziDebugVlgFile::scanFile(EziDebugPrj* prj,EziDebugPrj::SCAN_TYPE type,QList<EziDebugPrj::LOG_FILE_INFO*> &addedinfolist,QList<EziDebugPrj::LOG_FILE_INFO*> &deletedinfolist)
4147
{
4148
    qDebug() << "verilog file scanfile!" << fileName();
4149
    bool echainExistFlag = false ;
4150
    int i = 0 ;
4151
    QString ifileName = fileName() ;
4152
    EziDebugModule *poldModule  = NULL ;
4153
    EziDebugVlgFile *poldFile = NULL ;
4154
    QDir icurrentDir = prj->getCurrentDir() ;
4155
    QString irelativeFileName = icurrentDir.relativeFilePath(this->fileName()) ;
4156
    QStringList ieziPort ;
4157
    QFileInfo ifileInfo(this->fileName()) ;
4158
    QStringList ichangedchainList ;
4159
    QStringList icheckChainList ;
4160
    int nresult = 0 ;
4161
 
4162
    QDateTime ilastModifedTime = ifileInfo.lastModified() ;
4163
 
4164
 
4165
    QMap<QString,QString> iclockMap ;
4166
    QMap<QString,QString> iresetMap ;
4167
 
4168
 
4169
    poldFile = prj->getPrjVlgFileMap().value(irelativeFileName ,NULL);
4170
 
4171
    if(poldFile)
4172
    {
4173
        for( ; i < poldFile->getModuleList().count();i++)
4174
        {
4175
            EziDebugModule *pmodule = prj->getPrjModuleMap().value(poldFile->getModuleList().at(i),NULL) ;
4176
            if(pmodule)
4177
            {
4178
                QString imoduleName = pmodule->getModuleName() ;
4179
                struct EziDebugPrj::LOG_FILE_INFO* pdelmoduleInfo = new EziDebugPrj::LOG_FILE_INFO ;
4180
                pdelmoduleInfo->etype = EziDebugPrj::infoTypeModuleStructure ;
4181
                pdelmoduleInfo->pinfo = NULL ;
4182
                qstrcpy(pdelmoduleInfo->ainfoName,imoduleName.toAscii().data());
4183
                deletedinfolist.append(pdelmoduleInfo);
4184
            }
4185
        }
4186
    }
4187
 
4188
#if 1
4189
    if(fileName().endsWith("SspTxFIFO.v"))
4190
    {
4191
        qDebug() << "SspTxFIFO.v";
4192
    }
4193
#endif
4194
 
4195
    // 清空原文件的  modulelist
4196
    clearModuleList();
4197
 
4198
    unModuCnt = 0  ;
4199
    unMacroCnt = 0 ;
4200
 
4201
    //  memset((void*)module_tab,0,MAX_T_LEN*sizeof(struct Module_Mem)) ;
4202
    //  memset((void*)macro_table,0,MAX_T_LEN*sizeof(struct macro_Mem)) ;
4203
 
4204
    inst_map.clear();
4205
    iinstNameList.clear();
4206
 
4207
    reg_scan reg_search ;
4208
 
4209
    memset((void*)buffer,0,sizeof(buffer)) ;
4210
 
4211
    //qDebug()  <<  ifileName.toAscii().data() ;
4212
    if(reg_search.LoadVeriFile(buffer,ifileName.toAscii().data()))
4213
    {
4214
        reg_search.prog = buffer ;
4215
        try
4216
        {
4217
            reg_search.ScanPre();
4218
            reg_search.Interp();
4219
        }
4220
        catch (InterpExc &except)
4221
        {
4222
            qDebug() << "EziDebug file parse Error!" ;
4223
            return 1 ;
4224
        }
4225
    }
4226
    else
4227
    {
4228
        qDebug() << "EziDebug Error: read file error!" ;
4229
        return 1 ;
4230
    }
4231
 
4232
 
4233
    //qDebug() << "Find Module Number:"  << mod_count;
4234
 
4235
    for(i = 0 ; i < unModuCnt ;i++)
4236
    {
4237
        QString imoduleName = QString::fromAscii(ModuleTab[i].cModuleName) ;
4238
        EziDebugModule *pmodule = new EziDebugModule(imoduleName) ;
4239
        if(!pmodule)
4240
        {
4241
            qDebug() << "There is not memory left!"  ;
4242
            return 1 ;
4243
        }
4244
 
4245
        //qDebug() << "GET A Module!"  << module_tab[i].inst_map.count() ;
4246
 
4247
        QMap<QString,QMap<QString,QString> > iinstMap = inst_map ;
4248
        int ninstanceCount = 0 ;
4249
        for( ; ninstanceCount < iinstNameList.count() ;ninstanceCount++)
4250
        {
4251
            QString iinst = iinstNameList.at(ninstanceCount) ;
4252
            QString iinstanceName = iinst.split('#').at(1) ;
4253
 
4254
            qDebug() << __LINE__  << "EziDebug instance:" << iinst;
4255
 
4256
            if(QRegExp(QObject::tr("_EziDebug_\\w+")).exactMatch(iinstanceName))
4257
            {
4258
                //ieziInstList.append(iinst.split('#').at(1));
4259
 
4260
                //echainExistFlag = true ;
4261
                continue ;
4262
            }
4263
 
4264
            pmodule->m_iinstanceNameList << iinst.replace("#",":");
4265
            pmodule->m_iinstancePortMap.insert(iinstanceName,iinstMap.value(iinstNameList.at(ninstanceCount)));
4266
        }
4267
 
4268
 
4269
        for(int m = 0 ; m< ModuleTab[i].unParaCnt ;m++)
4270
        {
4271
            pmodule->addToParameterMap(QString::fromAscii(ModuleTab[i].ParaTab[m].cParaName),\
4272
                                       ModuleTab[i].ParaTab[m].iParaVal);
4273
 
4274
        }
4275
 
4276
        // 向文件中添加 defparameter 信息
4277
        QMap<QString,QString>::const_iterator idefParamIter = def_map.constBegin() ;
4278
        while(idefParamIter != def_map.constEnd())
4279
        {
4280
             // <inst_name.para_name,para_value>
4281
            QString icombName = idefParamIter.key() ;
4282
            if(!icombName.contains("."))
4283
            {
4284
                qDebug() << "EziDebug Error: scan file Error , parameter pattern error!"  ;
4285
                return 1 ;
4286
            }
4287
            QString iinstanceName = icombName.split(".").at(0) ;
4288
 
4289
            if(QRegExp(QObject::tr("_EziDebug_\\w+")).exactMatch(iinstanceName))
4290
            {
4291
                ++idefParamIter ;
4292
                continue ;
4293
            }
4294
 
4295
            QString iparamterStr = icombName.split(".").at(1) ;
4296
            QString iparamterVal = idefParamIter.value() ;
4297
 
4298
            addToDefParameterMap(iinstanceName,iparamterStr,iparamterVal);
4299
            ++idefParamIter ;
4300
        }
4301
 
4302
        int j = 0 ;
4303
        // 向文件中添加 define  信息
4304
        for(; j < unMacroCnt ; j++)
4305
        {
4306
           addToMacroMap(QString::fromAscii(MacroTab[j].cMacroName),MacroTab[j].iMacroVal);
4307
        }
4308
 
4309
        for(j = 0 ;j < ModuleTab[i].unRegCnt ; j++)
4310
        {
4311
            QString iedge ;
4312
 
4313
            if(QRegExp(QObject::tr("_EziDebug_\\w+")).exactMatch(QString::fromAscii(ModuleTab[i].RegTab[j].cRegName)))
4314
            {
4315
                // 提示 文件中包含有EziDebug添加的代码  是否进行删除
4316
 
4317
                // 删除指针
4318
                //echainExistFlag = true ;
4319
                continue ;
4320
            }
4321
 
4322
            if(QString::fromAscii(ModuleTab[i].RegTab[j].ClkAttri.cClkName).isEmpty())
4323
            {
4324
                continue ;
4325
            }
4326
 
4327
            if(ModuleTab[i].RegTab[j].IsFlag == 0)
4328
            {
4329
                continue ;
4330
            }
4331
 
4332
            struct EziDebugModule::RegStructure * preg = new EziDebugModule::RegStructure ;
4333
 
4334
 
4335
            memset((char*)preg,0,sizeof(struct EziDebugModule::RegStructure));
4336
 
4337
 
4338
            qstrcpy(preg->m_pRegName,ModuleTab[i].RegTab[j].cRegName) ;
4339
 
4340
            if(ModuleTab[i].RegTab[j].iRegWidth.size() >= 64)
4341
            {
4342
                qDebug() << "EziDebug Error: the reg number string is too long!";
4343
                continue ;
4344
            }
4345
 
4346
            if(ModuleTab[i].RegTab[j].iRegCnt.isEmpty())
4347
            {
4348
                qstrcpy(preg->m_pregNum,"1") ;
4349
            }
4350
            else
4351
            {
4352
                qstrcpy(preg->m_pregNum,ModuleTab[i].RegTab[j].iRegCnt.toAscii().constData());
4353
            }
4354
 
4355
 
4356
            if(ModuleTab[i].RegTab[j].iRegWidth.count() >= 64 )
4357
            {
4358
                qDebug() << "EziDebug Error: the reg width string is too long!";
4359
                continue ;
4360
            }
4361
 
4362
            qstrcpy(preg->m_pExpString , ModuleTab[i].RegTab[j].iRegWidth.toAscii().constData());
4363
 
4364
 
4365
            //  初始化寄存器数据
4366
            preg->m_unStartNum = 0 ;
4367
            preg->m_unEndNum = 0 ;
4368
            preg->m_unRegNum = 0 ;
4369
 
4370
            preg->m_unStartBit = 0 ;
4371
            preg->m_unEndBit = 0 ;
4372
            preg->m_unRegBitWidth = 0 ;
4373
 
4374
 
4375
            preg->m_unMaxRegNum = 0 ;
4376
            preg->m_eRegNumEndian = EziDebugModule::endianOther ;
4377
            preg->m_eRegNumType = EziDebugModule::attributeOther ;
4378
            preg->m_unMaxBitWidth = 0 ;
4379
            preg->m_eRegBitWidthEndian = EziDebugModule::endianOther ;
4380
            preg->m_eRegBitWidthType = EziDebugModule::attributeOther ;
4381
 
4382
 
4383
            qstrcpy(preg->m_pclockName,ModuleTab[i].RegTab[j].ClkAttri.cClkName);
4384
 
4385
 
4386
            if(ModuleTab[i].RegTab[j].ClkAttri.eClkEdge == POSE)
4387
            {
4388
                iedge = QObject::tr("posedge");
4389
                preg->m_eedge =  EziDebugModule::signalPosEdge ;
4390
            }
4391
            else if(ModuleTab[i].RegTab[j].ClkAttri.eClkEdge == NEGE)
4392
            {
4393
                iedge = QObject::tr("negedge");
4394
                preg->m_eedge =  EziDebugModule::signalNegEdge ;
4395
            }
4396
            else if(ModuleTab[i].RegTab[j].ClkAttri.eClkEdge == LOW)
4397
            {
4398
                iedge = QObject::tr("low");
4399
                preg->m_eedge =  EziDebugModule::signalLow ;
4400
            }
4401
            else if(ModuleTab[i].RegTab[j].ClkAttri.eClkEdge == HIGH)
4402
            {
4403
                iedge = QObject::tr("high");
4404
                preg->m_eedge =  EziDebugModule::signalHigh ;
4405
            }
4406
            else
4407
            {
4408
                iedge = QObject::tr("posedge");
4409
                preg->m_eedge =  EziDebugModule::signalPosEdge ;
4410
            }
4411
 
4412
            if(QString::fromAscii(ModuleTab[i].RegTab[j].ClkAttri.cClkName).isEmpty())
4413
            {
4414
                qDebug() << "no clock " << preg->m_pRegName;
4415
            }
4416
 
4417
            iclockMap.insert(QString::fromAscii(ModuleTab[i].RegTab[j].ClkAttri.cClkName),\
4418
                             iedge);
4419
 
4420
            if(ModuleTab[i].RegTab[j].RstAttri.eRstEdge == POSE)
4421
            {
4422
                iedge = QObject::tr("posedge");
4423
            }
4424
            else if(ModuleTab[i].RegTab[j].RstAttri.eRstEdge == NEGE)
4425
            {
4426
                iedge = QObject::tr("negedge");
4427
            }
4428
            else
4429
            {
4430
                iedge = QObject::tr("posedge");
4431
            }
4432
 
4433
 
4434
            qstrcpy(preg->m_pMouduleName,ModuleTab[i].cModuleName) ;
4435
 
4436
            preg->m_unStartNum = 0 ;
4437
 
4438
            if(!QString::fromAscii(ModuleTab[i].RegTab[j].RstAttri.cRstName).isEmpty())
4439
            {
4440
                iresetMap.insert(QString::fromAscii(ModuleTab[i].RegTab[j].RstAttri.cRstName),\
4441
                                 iedge);
4442
            }
4443
 
4444
            QString iclockName = QString::fromAscii(preg->m_pclockName);
4445
 
4446
            // 全部加入 到固定位宽 , 待生成树状节点时,划分出来 非固定位宽
4447
            pmodule->AddToRegMap(iclockName ,preg);
4448
 
4449
        }
4450
 
4451
        pmodule->m_iclockMap = iclockMap ;
4452
 
4453
        pmodule->m_iresetMap = iresetMap ;
4454
 
4455
        QVector<EziDebugModule::PortStructure*> iportVec ;
4456
 
4457
        //qDebug() << "scan port !"  ;
4458
        int k = 0 ;
4459
        for(; k < ModuleTab[i].unIOCnt ; k++)
4460
        {
4461
            // 暂时修改
4462
            if(QRegExp(QObject::tr("_EziDebug_\\w+")).exactMatch(QString::fromAscii(ModuleTab[i].IOTab[k].cIOName)))
4463
            {
4464
                QString ieziPortName = QString::fromAscii(ModuleTab[i].IOTab[k].cIOName) ;
4465
                ieziPort <<  ieziPortName ;
4466
 
4467
                echainExistFlag = true ;
4468
                // 提示 文件中包含有EziDebug添加的代码  是否进行删除
4469
                continue ;
4470
 
4471
            }
4472
 
4473
            struct EziDebugModule::PortStructure * pport = new EziDebugModule::PortStructure ;
4474
 
4475
            memset((char*)pport,0,sizeof(struct EziDebugModule::PortStructure)) ;
4476
 
4477
            qstrcpy(pport->m_pPortName,ModuleTab[i].IOTab[k].cIOName);
4478
 
4479
            pport->m_unStartBit = 0 ;
4480
            pport->m_unBitwidth = 0 ;
4481
            pport->m_unEndBit = 0 ;
4482
            pport->m_eEndian  = EziDebugModule::endianOther ;
4483
 
4484
            if(ModuleTab[i].IOTab[k].iIOWidth.size() >= 64)
4485
            {
4486
                qDebug() << "EziDebug Error: the reg width string is too long!";
4487
                continue ;
4488
            }
4489
 
4490
            qstrcpy(pport->m_pBitWidth,ModuleTab[i].IOTab[k].iIOWidth.toAscii().constData()) ;
4491
 
4492
            if(ModuleTab[i].IOTab[k].eIOAttri == IO_INPUT)
4493
            {
4494
                pport->eDirectionType = EziDebugModule::directionTypeInput ;
4495
            }
4496
            else if(ModuleTab[i].IOTab[k].eIOAttri == IO_OUTPUT)
4497
            {
4498
                pport->eDirectionType = EziDebugModule::directionTypeOutput ;
4499
            }
4500
            else if(ModuleTab[i].IOTab[k].eIOAttri == IO_INOUT)
4501
            {
4502
                pport->eDirectionType = EziDebugModule::directionTypeInoutput ;
4503
            }
4504
            else
4505
            {
4506
                pport->eDirectionType = EziDebugModule::directionTypeInoutput ;
4507
            }
4508
 
4509
            qstrcpy(pport->m_pModuleName,ModuleTab[i].cModuleName);
4510
 
4511
            iportVec.append(pport);
4512
 
4513
        }
4514
 
4515
        pmodule->m_iportVec = iportVec ;
4516
 
4517
        // QDir(工程路径). relativeFilePath(完整的文件路径) 得到文件相对路径
4518
        pmodule->m_ilocatedFile = prj->getCurrentDir().relativeFilePath(fileName());
4519
 
4520
        // bool m_isLibaryCore ;
4521
        pmodule->m_isLibaryCore |= ModuleTab[i].nIPCore ;
4522
 
4523
        if(this->isLibaryFile())
4524
        {
4525
            pmodule->m_isLibaryCore = true ;
4526
        }
4527
 
4528
        qDebug() << "add to moudle list" << imoduleName << __FILE__ << __LINE__;
4529
 
4530
        // 加入 module map
4531
        qDebug() << "Add to moudle map" << imoduleName << pmodule << __FILE__ << __LINE__;
4532
 
4533
 
4534
        poldModule = prj->getPrjModuleMap().value(imoduleName,NULL) ;
4535
 
4536
        // 扫描完成后再 提示 信息 扫描链被破坏  是否重新添加链
4537
#if 0
4538
        if(pmodule->getModuleName() == "ifft")
4539
        {
4540
            qDebug() << "ifft" ;
4541
        }
4542
#endif
4543
        addToModuleList(imoduleName);
4544
        prj->addToModuleMap(imoduleName,pmodule);
4545
 
4546
        if(echainExistFlag)
4547
        {
4548
            /*
4549
                1、无log文件,打开工程进行更新扫描
4550
                  无对比对象,不进行对比
4551
                2、有log文件,打开工程进行更新扫描
4552
                  更扫描链进行对比,来判断是否 链被破坏
4553
                3、在已打开工程进行更新
4554
                  直接跟 已经记录的 module 进行对比
4555
                  注:2013.3.26  由于parameter存在 可能 跟原module相比  会出错,以后均采用根据
4556
                  扫描链的信息进行比较
4557
            */
4558
            // 根据log文件 进行对比
4559
            if(true == prj->getLogFileExistFlag())
4560
            {
4561
                for(int i = 0 ; i < ieziPort.count() ; i++)
4562
                {
4563
                    QString iportName = ieziPort.at(i) ;
4564
                    if(iportName.split('_',QString::SkipEmptyParts).count() >= 4)
4565
                    {
4566
                        QString ichainName = iportName.split('_',QString::SkipEmptyParts).at(1) ;
4567
                        // prj->addToCheckedChainList(ichainName);
4568
                        if(!icheckChainList.contains(ichainName))
4569
                        {
4570
                            icheckChainList.append(ichainName);
4571
                            EziDebugScanChain* pchain = prj->getScanChainInfo().value(ichainName ,NULL) ;
4572
                            if(pchain)
4573
                            {
4574
                                if(!pmodule->isChainCompleted(pchain))
4575
                                {
4576
                                    ichangedchainList.append(ichainName);
4577
                                    prj->addToDestroyedChainList(ichainName);
4578
                                }
4579
                            }
4580
                            else
4581
                            {
4582
                                // log 文件被破坏(并非log文件本身格式问题,而是代码中的链 log文件中不存在)
4583
                                prj->setLogfileDestroyedFlag(true);
4584
                            }
4585
                        }
4586
                    }
4587
                }
4588
 
4589
            }
4590
 
4591
        }
4592
    }
4593
 
4594
    // 有哪些module、
4595
    // 遍历扫描链代码 如果扫描链包括这个module 然后检测  line_code block_code 是否存在
4596
    // All code in this file
4597
    // QStringList icodeList ;
4598
    QStringList ichainNameList ;
4599
    for(int nmoduleNum = 0 ; nmoduleNum < this->getModuleList().count() ;nmoduleNum++)
4600
    {
4601
        QString imoduleName = this->getModuleList().at(nmoduleNum) ;
4602
        QMap<QString,EziDebugScanChain*> iscanChainMap = prj->getScanChainInfo() ;
4603
        QMap<QString,EziDebugScanChain*>::const_iterator iscanchainIter = iscanChainMap.constBegin() ;
4604
        while(iscanchainIter != iscanChainMap.constEnd())
4605
        {
4606
            EziDebugScanChain* pchain = iscanchainIter.value() ;
4607
            QString ichainName = iscanchainIter.key() ;
4608
            if(pchain->getLineCode().contains(imoduleName))
4609
            {
4610
                if(!ichainNameList.contains(ichainName))
4611
                {
4612
                    ichainNameList.append(ichainName);
4613
                }
4614
            }
4615
 
4616
            if(pchain->getBlockCode().contains(imoduleName))
4617
            {
4618
                if(!ichainNameList.contains(ichainName))
4619
                {
4620
                    ichainNameList.append(ichainName);
4621
                }
4622
            }
4623
            ++iscanchainIter ;
4624
        }
4625
 
4626
        if((nresult = checkedEziDebugCodeExist(prj,imoduleName,ichainNameList)) != 0)
4627
        {
4628
            return nresult ;
4629
        }
4630
    }
4631
 
4632
 
4633
//    // 如果在扫描被修改的文件, 则更新 相关的 module 对象
4634
//    if(!(this->getLastStoredTime().isNull()))
4635
//    {
4636
//        // 更改的文件
4637
//        if(isModifedRecently())
4638
//        {
4639
//            // 文件被改动 更新 相关的 module 对象
4640
 
4641
//            // 将文件 与 module 挂在 删除的链表上
4642
////            struct EziDebugPrj::LOG_FILE_INFO* pdelFileInfo = new EziDebugPrj::LOG_FILE_INFO ;
4643
////            pdelFileInfo->etype = EziDebugPrj::infoTypeFileInfo ;
4644
////            pdelFileInfo->pinfo = NULL ;
4645
////            memcpy(pdelFileInfo->ainfoName,this->fileName().toAscii(),this->fileName().size()+1);
4646
////            deletedinfolist.append(pdelFileInfo);
4647
 
4648
////            for(int i = 0 ; i < getModuleList().count();i++)
4649
////            {
4650
////                EziDebugModule *pmodule = prj->getPrjModuleMap().value(getModuleList().at(i),NULL) ;
4651
////                if(!pmodule)
4652
////                {
4653
////                    struct EziDebugPrj::LOG_FILE_INFO* pdelmoduleInfo = new EziDebugPrj::LOG_FILE_INFO ;
4654
 
4655
////                    pdelmoduleInfo->etype = EziDebugPrj::infoTypeModuleStructure ;
4656
////                    pdelmoduleInfo->pinfo = NULL ;
4657
////                    memcpy(pdelmoduleInfo->ainfoName,pmodule->getModuleName().toAscii(),pmodule->getModuleName().size()+1);
4658
////                    deletedinfolist.append(pdelmoduleInfo);
4659
////                }
4660
////            }
4661
 
4662
//            // 将更改后的文件 与 新的module 挂在 添加的链表上 需要重新添加
4663
//            struct EziDebugPrj::LOG_FILE_INFO* paddFileInfo = new EziDebugPrj::LOG_FILE_INFO ;
4664
//            paddFileInfo->etype = EziDebugPrj::infoTypeFileInfo ;
4665
//            paddFileInfo->pinfo = this ;
4666
//            memcpy(paddFileInfo->ainfoName,this->fileName().toAscii(),this->fileName().size()+1);
4667
//            addedinfolist.append(paddFileInfo);
4668
 
4669
//            for(int i = 0 ; i < getModuleList().count();i++)
4670
//            {
4671
//                EziDebugModule *pmodule = prj->getPrjModuleMap().value(getModuleList().at(i),NULL) ;
4672
//                if(pmodule)
4673
//                {
4674
//                    struct EziDebugPrj::LOG_FILE_INFO* paddModuleInfo = new EziDebugPrj::LOG_FILE_INFO ;
4675
//                    paddModuleInfo->etype = EziDebugPrj::infoTypeModuleStructure ;
4676
//                    paddModuleInfo->pinfo = pmodule ;
4677
//                    memcpy(paddModuleInfo->ainfoName,pmodule->getModuleName().toAscii(),pmodule->getModuleName().size()+1);
4678
//                    addedinfolist.append(paddModuleInfo);
4679
//                }
4680
//                else
4681
//                {
4682
//                    return 1 ;
4683
//                }
4684
//            }
4685
//        }
4686
//    }
4687
//    else
4688
//    {
4689
        // 将最新扫描过的 信息 保存
4690
 
4691
 
4692
        qDebug() << " !!module count !!"<< getModuleList().count();
4693
        for(i = 0 ; i < getModuleList().count();i++)
4694
        {
4695
            EziDebugModule *pmodule = prj->getPrjModuleMap().value(getModuleList().at(i),NULL) ;
4696
            if(pmodule)
4697
            {
4698
                qDebug() << " add module info " ;
4699
                struct EziDebugPrj::LOG_FILE_INFO* paddModuleInfo = new EziDebugPrj::LOG_FILE_INFO ;
4700
                paddModuleInfo->etype = EziDebugPrj::infoTypeModuleStructure ;
4701
                paddModuleInfo->pinfo = pmodule ;
4702
                memcpy(paddModuleInfo->ainfoName,pmodule->getModuleName().toAscii().data(),pmodule->getModuleName().size()+1);
4703
                addedinfolist.append(paddModuleInfo);
4704
            }
4705
            else
4706
            {
4707
                return 1 ;
4708
            }
4709
        }
4710
//    }
4711
    //qDebug() << addedinfolist.count() <<  deletedinfolist.count();
4712
    // 更改文件扫描时间
4713
    modifyStoredTime(ilastModifedTime);
4714
 
4715
    return 0 ;
4716
}
4717
 
4718
int EziDebugVlgFile::checkedEziDebugCodeExist(EziDebugPrj* prj ,QString imoduleName ,QStringList &chainnamelist)
4719
{
4720
    QMap<QString,EziDebugScanChain*> ichainMap = prj->getScanChainInfo() ;
4721
    QMap<QString,int> ilinesearchposMap ;
4722
    QMap<QString,int> iblocksearchposMap ;
4723
    QMap<QString,QStringList> ichainLineCodeMap ;
4724
    QMap<QString,QStringList> ichainBlockCodeMap ;
4725
    QStringList idestroyChainList ;
4726
    QStringList icheckChainList ;
4727
    QList<int>  iposList ;
4728
 
4729
    if(!open(QIODevice::ReadOnly | QIODevice::Text))
4730
    {
4731
        // 向用户输出  文件打不开
4732
        qDebug() << errorString() << fileName() ;
4733
        return 1 ;
4734
    }
4735
 
4736
    QTextStream iin(this);
4737
    QString ifileContent = iin.readAll();
4738
    QString inoCommentaryStr = replaceCommentaryByBlank(ifileContent) ;
4739
    QRegExp imoduleStartExp(tr("module\\s+%1").arg(imoduleName)) ;
4740
    int nstartPos = inoCommentaryStr.indexOf(imoduleStartExp);
4741
    if(-1 == nstartPos)
4742
    {
4743
        qDebug() << "EziDebug Error: parse file error ,please check the file!";
4744
        return -2 ;
4745
    }
4746
    int nendPos = inoCommentaryStr.indexOf("endmodule",nstartPos);
4747
    if(-1 == nendPos)
4748
    {
4749
        qDebug() << "EziDebug Error: parse file error ,please check the file!";
4750
        return -2 ;
4751
    }
4752
    QString icheckStr = inoCommentaryStr.mid(nstartPos,nendPos-1);
4753
    // 关闭
4754
    close();
4755
 
4756
    for(int nchainNum = 0 ; nchainNum < chainnamelist.count() ; nchainNum++)
4757
    {
4758
        QString ichainName = chainnamelist.at(nchainNum) ;
4759
        EziDebugScanChain * pchain = ichainMap.value(ichainName,NULL);
4760
        if(pchain)
4761
        {
4762
            QMap<QString,QStringList> icodeListMap = pchain->getLineCode() ;
4763
            QStringList icodeList ;
4764
            icodeList = icodeListMap.value(imoduleName,icodeList) ;
4765
            if(icodeList.count())
4766
            {
4767
                ichainLineCodeMap.insert(ichainName,icodeList);
4768
            }
4769
 
4770
            icodeList.clear();
4771
            icodeListMap = pchain->getBlockCode();
4772
            icodeList = icodeListMap.value(imoduleName,icodeList);
4773
            if(icodeList.count())
4774
            {
4775
                ichainBlockCodeMap.insert(ichainName,icodeList) ;
4776
            }
4777
        }
4778
        else
4779
        {
4780
            qDebug() << "NULL Pointer!" << ichainName << "is not exist!";
4781
            return -1 ;
4782
        }
4783
    }
4784
 
4785
    // linecode
4786
    QMap<QString ,QStringList>::const_iterator icodeIter = ichainLineCodeMap.constBegin() ;
4787
    while(icodeIter != ichainLineCodeMap.constEnd())
4788
    {
4789
        int ncodeNum = 0 ;
4790
        QString chainname = icodeIter.key() ;
4791
        QStringList icode = icodeIter.value() ;
4792
        iposList.clear();
4793
        EziDebugScanChain * pchain = ichainMap.value(chainname);
4794
        int nsearchPos = 0 ;
4795
        for(;ncodeNum < icode.count();ncodeNum++)
4796
        {
4797
            QString isearchLineStr = icode.at(ncodeNum) ;
4798
            if(-1 != (nsearchPos = icheckStr.indexOf(QRegExp(isearchLineStr))))
4799
            {
4800
                ilinesearchposMap.insert(isearchLineStr ,nsearchPos);
4801
                iposList.append(nsearchPos);
4802
            }
4803
            else
4804
            {
4805
                qDebug() <<"EziDebug Warning:"<< isearchLineStr << "is not finded!";
4806
                if(!idestroyChainList.contains(chainname))
4807
                {
4808
                    idestroyChainList.append(chainname);
4809
                }
4810
                break ;
4811
            }
4812
        }
4813
 
4814
        // check code sequence
4815
        if(ncodeNum == icode.count())
4816
        {
4817
            QSet<int> isimplifiedSet = iposList.toSet();
4818
            if(isimplifiedSet.count() == iposList.count())
4819
            {
4820
                 QStringList inewCodeList ;
4821
                 qSort(iposList.begin(), iposList.end(), qLess<int>());
4822
                 for(int ncodeNum = 0 ; ncodeNum < iposList.count() ; ncodeNum++)
4823
                 {
4824
                    int npos = iposList.at(ncodeNum) ;
4825
                    QString icodeStr = ilinesearchposMap.key(npos) ;
4826
                    inewCodeList.append(icodeStr);
4827
                 }
4828
 
4829
                 if(inewCodeList != icode)
4830
                 {
4831
                    pchain->replaceLineCodeMap(imoduleName,inewCodeList);
4832
                    prj->addToCheckedChainList(chainname);
4833
                 }
4834
            }
4835
            else
4836
            {
4837
                qDebug() << "Please remove the repeated code !";
4838
                for(int i = 0 ; i < icode.count() ; i++)
4839
                {
4840
                    qDebug() << icode.at(i) << endl ;
4841
                }
4842
                return -2 ;
4843
            }
4844
 
4845
        }
4846
        ilinesearchposMap.clear();
4847
        ++icodeIter ;
4848
    }
4849
 
4850
 
4851
    // blockcode
4852
    icodeIter = ichainBlockCodeMap.constBegin() ;
4853
    while(icodeIter != ichainBlockCodeMap.constEnd())
4854
    {
4855
        int ncodeNum = 0 ;
4856
        iposList.clear();
4857
        QString chainname = icodeIter.key() ;
4858
        QStringList icode = icodeIter.value() ;
4859
        EziDebugScanChain * pchain = ichainMap.value(chainname);
4860
        // the code in icode is from little to big
4861
        int nsearchPos = 0 ;
4862
        for(;ncodeNum < icode.count();ncodeNum++)
4863
        {
4864
            QString isearchLineStr = icode.at(ncodeNum) ;
4865
            if(-1 != (nsearchPos = icheckStr.indexOf(QRegExp(isearchLineStr))))
4866
            {
4867
                iblocksearchposMap.insert(isearchLineStr ,nsearchPos);
4868
                iposList.append(nsearchPos);
4869
            }
4870
            else
4871
            {
4872
                qDebug() <<"EziDebug Warning:"<< isearchLineStr << "is not finded!";
4873
                if(!idestroyChainList.contains(chainname))
4874
                {
4875
                    idestroyChainList.append(chainname);
4876
                }
4877
                break ;
4878
            }
4879
        }
4880
 
4881
        // check code sequence
4882
        if(ncodeNum == icode.count())
4883
        {
4884
            QSet<int> isimplifiedSet = iposList.toSet();
4885
            if(isimplifiedSet.count() == iposList.count())
4886
            {
4887
                 QStringList inewCodeList ;
4888
                 qSort(iposList.begin(), iposList.end(), qLess<int>());
4889
                 for(int ncodeNum = 0 ; ncodeNum < iposList.count() ; ncodeNum++)
4890
                 {
4891
                    int npos = iposList.at(ncodeNum) ;
4892
                    QString icodeStr = iblocksearchposMap.key(npos) ;
4893
                    inewCodeList.append(icodeStr);
4894
                 }
4895
 
4896
                 if(inewCodeList != icode)
4897
                 {
4898
                    pchain->replaceBlockCodeMap(imoduleName,inewCodeList);
4899
 
4900
                    prj->addToCheckedChainList(chainname);
4901
                 }
4902
            }
4903
            else
4904
            {
4905
                qDebug() << "Please remove the repeated code !\n";
4906
                for(int i = 0 ; i < icode.count() ; i++)
4907
                {
4908
                    qDebug() << icode.at(i) << endl ;
4909
                }
4910
                return -2 ;
4911
            }
4912
        }
4913
        iblocksearchposMap.clear();
4914
        ++icodeIter ;
4915
    }
4916
 
4917
    // check the destroyed chain!
4918
    for(int nchaincount = 0 ; nchaincount < idestroyChainList.count() ;nchaincount++)
4919
    {
4920
        QString ichainName = idestroyChainList.at(nchaincount) ;
4921
        qDebug()  << "EziDebug Error:" << ichainName << "is destroyed!" << "checkedEziDebugCodeExist !";
4922
        prj->addToDestroyedChainList(ichainName);
4923
    }
4924
 
4925
    return 0 ;
4926
}
4927
 
4928
int EziDebugVlgFile::createUserCoreFile(EziDebugPrj* prj)
4929
{
4930
    if(!prj)
4931
        return 1 ;
4932
    QString iregModuleName(tr("_EziDebug_ScnReg")) ;
4933
    QString itimerName(tr("_EziDebug_TOUT_m"));
4934
 
4935
 
4936
    QFileInfo iPrjFileInfo(prj->getPrjName());
4937
    /*创建新的文件夹  并 创建自己的core文件*/
4938
    QDir idirPrj(iPrjFileInfo.absolutePath());
4939
    QString inewDirName = iPrjFileInfo.absolutePath() + tr("/") + tr("EziDebug_1.0") ;
4940
    QDir idir(inewDirName);
4941
    QTime icurrentTime = QTime::currentTime() ;
4942
 
4943
    if(idir.exists())
4944
    {
4945
        qDebug() <<  "There is already exist folder!" << inewDirName ;
4946
        // 检测 文件是否存在
4947
        if(idir.exists("_EziDebug_ScanChainReg.v"))
4948
        {
4949
            if(idir.exists("_EziDebug_TOUT_m.v"))
4950
            {
4951
               EziDebugScanChain::saveEziDebugAddedInfo(iregModuleName,itimerName,QObject::tr("/EziDebug_1.0"));
4952
               // 重新创建 tout 文件
4953
               QString ifileToutName(tr("_EziDebug_TOUT_m.v"));
4954
               QFile itoutfile(inewDirName + tr("/") + ifileToutName);
4955
               if(!itoutfile.open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Truncate))
4956
               {
4957
                    /*在文本栏 提示插入链错误 无法创建文件 文件无法打开*/
4958
                    return 1 ;
4959
               }
4960
 
4961
 
4962
               /*写入 tout 文件*/
4963
               QTextStream itoutStream(&itoutfile);
4964
 
4965
               itoutStream <<"module ";
4966
 
4967
               /*写入module名字*/
4968
               itoutStream << itimerName;
4969
               itoutStream << g_ptoutfileContentFirst ;
4970
               itoutStream << prj->getMaxRegNumPerChain() << ";" ;
4971
               itoutStream << g_ptoutfileContentSecond ;
4972
 
4973
               itoutfile.close();
4974
               return 0 ;
4975
            }
4976
        }
4977
        // 重新创建 文件
4978
        idir.remove("_EziDebug_ScanChainReg.v") ;
4979
        idir.remove("_EziDebug_TOUT_m.v");
4980
    }
4981
    else
4982
    {
4983
        idirPrj.mkdir(tr("EziDebug_1.0"));
4984
    }
4985
 
4986
    QString ifileRegName(tr("_EziDebug_ScanChainReg.v")) ;
4987
    QString ifileToutName(tr("_EziDebug_TOUT_m.v"));
4988
    QStringList ifileList = prj->getFileNameList();
4989
 
4990
    for (int i = 0; i < ifileList.size(); ++i)
4991
    {
4992
       QFileInfo ifileInfo(prj->getCurrentDir(),ifileList.at(i));
4993
       if(ifileInfo.fileName() == ifileRegName)
4994
       {
4995
           ifileRegName = tr("_EziDebug_ScanChainReg")+tr("_")+ icurrentTime.toString("hh_mm_ss") + tr(".v") ;
4996
           if(ifileInfo.fileName() == ifileRegName)
4997
           {
4998
                /*在文本栏 提示插入链错误  无法创建文件  文件名重复*/
4999
               qDebug() << "EziDebug encounter error,Please ensure your fileName is right" << ifileRegName ;
5000
               return 1 ;
5001
           }
5002
       }
5003
 
5004
 
5005
       if(ifileInfo.fileName() == ifileToutName)
5006
       {
5007
           ifileToutName = tr("_EziDebug_TOUT_m")+tr("_")+ icurrentTime.toString("hh_mm_ss") + tr(".v") ;
5008
           if(ifileInfo.fileName() == ifileToutName)
5009
           {
5010
                /*在文本栏 提示插入链错误  无法创建文件  文件名重复*/
5011
               qDebug() << "EziDebug encounter error,Please ensure your fileName is right" << ifileToutName ;
5012
               return 1 ;
5013
           }
5014
       }
5015
    }
5016
 
5017
#if 0
5018
    /*检查module名字是否存在重复*/
5019
    QMap<QString,EziDebugModule*>::const_iterator i = prj->getPrjModuleMap().constBegin();
5020
    while (i != prj->getPrjModuleMap().constEnd())
5021
    {
5022
 
5023
    }
5024
 #endif
5025
 
5026
    QFile itoutfile(inewDirName + tr("/") + ifileToutName);
5027
    if(!itoutfile.open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Truncate))
5028
    {
5029
         /*在文本栏 提示插入链错误 无法创建文件 文件无法打开*/
5030
         return 1 ;
5031
    }
5032
 
5033
 
5034
    /*写入 tout 文件*/
5035
    QTextStream itoutStream(&itoutfile);
5036
 
5037
    itoutStream <<"module ";
5038
 
5039
    /*写入module名字*/
5040
    itoutStream << itimerName;
5041
    itoutStream << g_ptoutfileContentFirst ;
5042
    itoutStream << prj->getMaxRegNumPerChain() << ";" ;
5043
    itoutStream << g_ptoutfileContentSecond ;
5044
 
5045
    itoutfile.close();
5046
 
5047
 
5048
    QFile iscanRegfile(inewDirName + tr("/") + ifileRegName);
5049
    if(!iscanRegfile.open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Append))
5050
    {
5051
         /*在文本栏 提示插入链错误 无法创建文件 文件无法打开*/
5052
         return 1 ;
5053
    }
5054
    /*写入 ScanReg 文件*/
5055
    QTextStream iscanRegout(&iscanRegfile);
5056
 
5057
    iscanRegout <<"module ";
5058
 
5059
    /*写入module名字*/
5060
    iscanRegout << iregModuleName ;
5061
    iscanRegout << g_pScanRegfileContentFirst ;
5062
    iscanRegout << g_pScanRegfileContentSecond ;
5063
 
5064
    iscanRegfile.close();
5065
 
5066
    EziDebugScanChain::saveEziDebugAddedInfo(iregModuleName,itimerName,QObject::tr("/EziDebug_1.0"));
5067
 
5068
    return 0 ;
5069
}
5070
 
5071
int EziDebugVlgFile::caculateExpression(QString string)
5072
{
5073
    return 0 ;
5074
}
5075
 
5076
void EziDebugVlgFile::addToMacroMap(const QString &macrostring , const QString &macrovalue)
5077
{
5078
    m_imacro.insert(macrostring,macrovalue) ;
5079
}
5080
 
5081
void EziDebugVlgFile::addToDefParameterMap(const QString &instancename ,const QString &parameter ,const QString &value)
5082
{
5083
    QMap<QString,QString> iparameterMap ;
5084
    iparameterMap = m_idefparameter.value(instancename ,iparameterMap) ;
5085
    iparameterMap.insert(parameter,value);
5086
    m_idefparameter.insert(instancename,iparameterMap) ;
5087
}
5088
 
5089
const QMap<QString,QString> & EziDebugVlgFile::getMacroMap(void) const
5090
{
5091
    return m_imacro ;
5092
}
5093
 
5094
const QMap<QString,QMap<QString,QString> > & EziDebugVlgFile::getDefParamMap(void) const
5095
{
5096
    return m_idefparameter ;
5097
}
5098
 
5099
 
5100
#if 0
5101
bool EziDebugVlgFile::isLibaryFile()
5102
{
5103
    return 0 ;
5104
}
5105
#endif
5106
 
5107
 
5108
int  EziDebugVlgFile::deleteEziDebugCode(void)
5109
{
5110
    // 只读方式 打开文件
5111
    QString ifileContent ;
5112
    QString inewContent ;
5113
    //QString ikeyWords ;
5114
    int nkeyWordsPos = 0 ;
5115
    QList<int> iposList ;
5116
    QMap<int,int> ideleteCodePosMap ;
5117
 
5118
    //QRegExp ieziDebugFlagExp(QObject::tr("\\b_EziDebug_\\w+\\b"));
5119
    QRegExp ieziDebugFlagWithEnterExp(QObject::tr("\\s*\\b_EziDebug_\\w+\\b"));
5120
    QRegExp ikeyWordsExp(QObject::tr("\\s*\\b[a-z]+\\b"));
5121
    //QRegExp ikeyWordsWithEnterExp(QObject::tr("\\s*\\b\\w+\\b"));
5122
 
5123
 
5124
 
5125
    /*
5126
        _EziDebug_ScnReg _EziDebug_ScnReg_chn_inst0(
5127
        .clock  (HCLK) ,
5128
        .resetn (_EziDebug_chn_rstn) ,
5129
        .TDI_reg        (_EziDebug_chn_HCLK_TDI_reg) ,
5130
        .TDO_reg        (_EziDebug_chn_HCLK_tdo1) ,
5131
        .TOUT_reg       (_EziDebug_chn_TOUT_reg) ,
5132
        .shift_reg      (_EziDebug_chn_HCLK_sr0)
5133
        )
5134
    */
5135
    QRegExp ieziDebugScnInstExp(QObject::tr("\\s*_EziDebug_ScnReg\\s+_EziDebug_ScnReg_chn\\d*_inst\\d*\\s*\\(.+\\)\\s*"));
5136
 
5137
 
5138
    QRegExp ieziDebugToutInstExp(QObject::tr("\\s*_EziDebug_TOUT_m\\s+_EziDebug_TOUT_m_chn\\d*_inst\\d*\\s*\\(.+\\)\\s*"));
5139
    //_EziDebug_TOUT_m _EziDebug_TOUT_m_chn_inst
5140
 
5141
    int npostion = 0 ;
5142
    if(!open(QIODevice::ReadOnly | QIODevice::Text))
5143
    {
5144
        // 向用户输出  文件打不开
5145
        qDebug() << errorString() << fileName() ;
5146
        return 1 ;
5147
    }
5148
    // 全部读出
5149
    QTextStream iin(this);
5150
    ifileContent = iin.readAll();
5151
    // 关闭
5152
    close();
5153
 
5154
    // 替换所有注释为  空格
5155
    inewContent = replaceCommentaryByBlank(ifileContent);
5156
    qDebug() << "EziDebug info: start file---" << fileName();
5157
    if(fileName().endsWith("fft_ram_256x17.v"))
5158
    {
5159
        qDebug() << "EziDebug Info : halt Point!";
5160
    }
5161
 
5162
     qDebug() << fileName() ;
5163
 
5164
    // 查找 以 "_EziDebug" 开头的字符串
5165
    while((npostion = ieziDebugFlagWithEnterExp.indexIn(inewContent,npostion)) != -1)
5166
    {
5167
        // EziDebug 自定义 core 的例化
5168
        int nnextSemicolonPos = inewContent.indexOf(';',npostion + ieziDebugFlagWithEnterExp.matchedLength()) ;
5169
        QString itruncateStr = inewContent.mid(npostion , (nnextSemicolonPos - npostion));
5170
        qDebug() << "test string!" << itruncateStr  << ieziDebugScnInstExp.exactMatch(itruncateStr) << ieziDebugToutInstExp.exactMatch(itruncateStr) ;
5171
 
5172
        int nin = ieziDebugScnInstExp.indexIn(itruncateStr) ;
5173
        qDebug() << nin <<  ieziDebugScnInstExp.matchedLength() << ieziDebugScnInstExp.capturedTexts().at(0);
5174
 
5175
        if(ieziDebugScnInstExp.exactMatch(itruncateStr)||ieziDebugToutInstExp.exactMatch(itruncateStr))
5176
        {
5177
            iposList.append(npostion);
5178
            ideleteCodePosMap.insert(npostion,(nnextSemicolonPos - npostion + 1));
5179
            qDebug() << " instance match!" <<  ifileContent.mid(npostion ,(nnextSemicolonPos - npostion + 1)) ;
5180
 
5181
            npostion = nnextSemicolonPos + 1 ;
5182
        }
5183
        else
5184
        {
5185
            if(QRegExp(QObject::tr("\\s*\\b_EziDebug\\w+\\s*<=.*")).exactMatch(itruncateStr))
5186
            {
5187
                // 寻找 always
5188
                int nalwaysPos = inewContent.lastIndexOf(QRegExp(QObject::tr("\\balways\\b")),npostion);
5189
                int nlastNoneblankCharPos = inewContent.lastIndexOf(QRegExp(QObject::tr("\\S")),nalwaysPos);
5190
                if(nlastNoneblankCharPos != -1)
5191
                {
5192
                    // nalwaysPos   =  nlastNoneblankCharPos + 1 ;
5193
                    nalwaysPos   =  nlastNoneblankCharPos ;
5194
                }
5195
                int nfirstBeginPos = inewContent.indexOf(QRegExp(QObject::tr("\\bbegin\\b")),nalwaysPos);
5196
                /*查找匹配的  end*/
5197
                QRegExp iwordsExp(QObject::tr("\\b\\w+\\b"));
5198
                int nmatch = 1 ;
5199
                int nendPos = 0 ;
5200
                int nbeginPos = nfirstBeginPos + 5 ;
5201
 
5202
                while((nbeginPos = iwordsExp.indexIn(ifileContent,nbeginPos)) != -1)
5203
                {
5204
                    if(iwordsExp.capturedTexts().at(0) == "begin")
5205
                    {
5206
                        nmatch++ ;
5207
                    }
5208
                    else if(iwordsExp.capturedTexts().at(0) == "end")
5209
                    {
5210
                        nmatch-- ;
5211
                        if(0 == nmatch)
5212
                        {
5213
                            nendPos = nbeginPos ;
5214
                            break ;
5215
                        }
5216
                    }
5217
                    else
5218
                    {
5219
                        // do nothing
5220
                    }
5221
                    nbeginPos = nbeginPos + iwordsExp.matchedLength();
5222
                }
5223
 
5224
                if(nmatch != 0)
5225
                {
5226
                    return 1 ;
5227
                }
5228
 
5229
                iposList.append(nalwaysPos);
5230
                ideleteCodePosMap.insert(nalwaysPos,(nendPos - nalwaysPos + 3));
5231
 
5232
                qDebug()<< "1" << ifileContent.mid(nalwaysPos ,(nendPos - nalwaysPos + 3)) ;
5233
 
5234
                npostion = nendPos + 3 ;
5235
            }
5236
            else
5237
            {
5238
                // 查找最近的单词
5239
                nkeyWordsPos = ikeyWordsExp.lastIndexIn(inewContent,npostion) ;
5240
                QString ikeyWord = ikeyWordsExp.capturedTexts().at(0) ;
5241
                // 最近的 ','
5242
                int nlastCommaPos = inewContent.lastIndexOf(',',npostion);
5243
 
5244
                if(nlastCommaPos > nkeyWordsPos)
5245
                {
5246
                    // 是否包含 '.'
5247
                    /*只能是 例化 中加入 的端口连接 */
5248
                    // 标准的 ,.(),.(),.()
5249
                    // 截取 上一个 逗号 之间的 字符 看是否包含 ".( 字符"
5250
                    QString ipartStr = inewContent.mid((nlastCommaPos+1) , (npostion - nlastCommaPos -1));
5251
                    if(QRegExp(QObject::tr("\\s*\\.")).exactMatch(ipartStr))
5252
                    {
5253
                        // 删除上一个逗号 到 下一个 ) 之间字符串
5254
                        int nnextRightBracketPos = inewContent.indexOf(')',npostion);
5255
                        iposList.append(nlastCommaPos);
5256
                        ideleteCodePosMap.insert(nlastCommaPos,(nnextRightBracketPos - nlastCommaPos + 1));
5257
                        qDebug()<< "2" << ifileContent.mid(nlastCommaPos ,(nnextRightBracketPos - nlastCommaPos + 1)) ;
5258
 
5259
                        npostion = nnextRightBracketPos + 1 ;
5260
                    }
5261
                    else
5262
                    {
5263
                        // 删除上一个逗号 到 本字符串结束
5264
                        iposList.append(nlastCommaPos);
5265
                        ideleteCodePosMap.insert(nlastCommaPos,(npostion + ieziDebugFlagWithEnterExp.matchedLength()- nlastCommaPos));
5266
                        qDebug()<< "3" << ifileContent.mid(nlastCommaPos ,(npostion + ieziDebugFlagWithEnterExp.matchedLength()- nlastCommaPos)) ;
5267
 
5268
                        npostion =  npostion + ieziDebugFlagWithEnterExp.matchedLength() ;
5269
                    }
5270
                }
5271
                else
5272
                {
5273
                    if(ikeyWordsExp.capturedTexts().at(0).contains(QRegExp(QObject::tr("\\binput\\b"))))
5274
                    {
5275
                        int nlastCommaPos = inewContent.lastIndexOf(',',npostion);
5276
                        int nlastSemicolon = inewContent.lastIndexOf(';',npostion);
5277
                        int nnextSemicolon = inewContent.indexOf(';',npostion);
5278
 
5279
                        if(nlastCommaPos > nlastSemicolon)
5280
                        {
5281
                            // 端口声明
5282
                            iposList.append(nlastCommaPos);
5283
                            ideleteCodePosMap.insert(nlastCommaPos,(npostion + ieziDebugFlagWithEnterExp.matchedLength() - nlastCommaPos));
5284
                            qDebug() << "4" << ifileContent.mid(nlastCommaPos ,(npostion + ieziDebugFlagWithEnterExp.matchedLength() - nlastCommaPos)) ;
5285
 
5286
                            npostion = npostion + ieziDebugFlagWithEnterExp.matchedLength() ;
5287
                        }
5288
                        else
5289
                        {
5290
                            nkeyWordsPos = inewContent.lastIndexOf(QRegExp(QObject::tr("\\S")),nkeyWordsPos-1) + 1 ;
5291
                            iposList.append(nkeyWordsPos);
5292
                            ideleteCodePosMap.insert(nkeyWordsPos,(nnextSemicolon - nkeyWordsPos + 1));
5293
                            qDebug() << "5" << ifileContent.mid(nkeyWordsPos ,(nnextSemicolon - nkeyWordsPos + 1)) ;
5294
 
5295
                            npostion = nnextSemicolon + 1 ;
5296
                        }
5297
                    }
5298
                    else if(ikeyWordsExp.capturedTexts().at(0).contains(QRegExp(QObject::tr("\\boutput\\b"))))
5299
                    {
5300
                        int nlastCommaPos = inewContent.lastIndexOf(',',npostion);
5301
                        int nlastSemicolon = inewContent.lastIndexOf(';',npostion);
5302
                        int nnextSemicolon = inewContent.indexOf(';',npostion);
5303
 
5304
                        if(nlastCommaPos > nlastSemicolon)
5305
                        {
5306
                            iposList.append(nlastCommaPos);
5307
                            ideleteCodePosMap.insert(nlastCommaPos,(npostion + ieziDebugFlagWithEnterExp.matchedLength() - nlastCommaPos));
5308
                            qDebug() << "6" << ifileContent.mid(nlastCommaPos ,(npostion + ieziDebugFlagWithEnterExp.matchedLength() - nlastCommaPos)) ;
5309
 
5310
                            npostion = npostion + ieziDebugFlagWithEnterExp.matchedLength() ;
5311
                        }
5312
                        else
5313
                        {
5314
                            nkeyWordsPos = inewContent.lastIndexOf(QRegExp(QObject::tr("\\S")),nkeyWordsPos-1) + 1 ;
5315
                            iposList.append(nkeyWordsPos);
5316
                            ideleteCodePosMap.insert(nkeyWordsPos,(nnextSemicolon - nkeyWordsPos + 1));
5317
                            qDebug() << "7" << ifileContent.mid(nkeyWordsPos ,(nnextSemicolon - nkeyWordsPos + 1)) ;
5318
                            npostion = nnextSemicolon + 1 ;
5319
                        }
5320
                    }
5321
                    else if(ikeyWordsExp.capturedTexts().at(0).contains(QRegExp(QObject::tr("\\breg\\b"))))
5322
                    {
5323
                        int nnextSemicolon = inewContent.indexOf(';',npostion);
5324
                        nkeyWordsPos = inewContent.lastIndexOf(QRegExp(QObject::tr("\\S")),nkeyWordsPos-1) + 1 ;
5325
                        iposList.append(nkeyWordsPos);
5326
                        ideleteCodePosMap.insert(nkeyWordsPos,(nnextSemicolon - nkeyWordsPos + 1));
5327
                        qDebug() << "8" << ifileContent.mid(nkeyWordsPos ,(nnextSemicolon - nkeyWordsPos + 1)) ;
5328
                        npostion = nnextSemicolon + 1;
5329
                    }
5330
                    else if(ikeyWordsExp.capturedTexts().at(0).contains(QRegExp(QObject::tr("\\bwire\\b"))))
5331
                    {
5332
                        int nnextSemicolon = inewContent.indexOf(';',npostion);
5333
                        nkeyWordsPos = inewContent.lastIndexOf(QRegExp(QObject::tr("\\S")),nkeyWordsPos-1) + 1 ;
5334
                        iposList.append(nkeyWordsPos);
5335
                        ideleteCodePosMap.insert(nkeyWordsPos,(nnextSemicolon - nkeyWordsPos + 1));
5336
                        qDebug() << "9" << ifileContent.mid(nkeyWordsPos ,(nnextSemicolon - nkeyWordsPos + 1)) ;
5337
                        npostion = nnextSemicolon + 1;
5338
                    }
5339
                    else if(ikeyWordsExp.capturedTexts().at(0).contains(QRegExp(QObject::tr("\\bdefparam\\b"))))
5340
                    {
5341
                        int nnextSemicolon = inewContent.indexOf(';',npostion);
5342
                        nkeyWordsPos = inewContent.lastIndexOf(QRegExp(QObject::tr("\\S")),nkeyWordsPos-1) + 1 ;
5343
                        iposList.append(nkeyWordsPos);
5344
                        ideleteCodePosMap.insert(nkeyWordsPos,(nnextSemicolon - nkeyWordsPos + 1));
5345
                        qDebug() << "10" << ifileContent.mid(nkeyWordsPos ,(nnextSemicolon - nkeyWordsPos + 1)) ;
5346
                        npostion = nnextSemicolon + 1;
5347
                    }
5348
                    else if(ikeyWordsExp.capturedTexts().at(0).contains(QRegExp(QObject::tr("\\bassign\\b"))))
5349
                    {
5350
                        int nnextSemicolon = inewContent.indexOf(';',npostion);
5351
                        nkeyWordsPos = inewContent.lastIndexOf(QRegExp(QObject::tr("\\S")),nkeyWordsPos-1) + 1 ;
5352
                        iposList.append(nkeyWordsPos);
5353
                        ideleteCodePosMap.insert(nkeyWordsPos,(nnextSemicolon - nkeyWordsPos + 1));
5354
                        qDebug() << "11" << ifileContent.mid(nkeyWordsPos ,(nnextSemicolon - nkeyWordsPos + 1)) ;
5355
                        npostion = nnextSemicolon + 1;
5356
                    }
5357
                    else
5358
                    {
5359
                        // do nothing
5360
                        npostion = npostion + ikeyWordsExp.matchedLength();
5361
                    }
5362
                }
5363
            }
5364
        }
5365
    }
5366
 
5367
    // from big to small
5368
    qSort(iposList.begin(), iposList.end(), qGreater<int>());
5369
 
5370
    // j < iposList.count()
5371
    for(int j = 0 ; j < iposList.count() ; j++)
5372
    {
5373
        int nstartPos = iposList.at(j) ;
5374
        int nlength = ideleteCodePosMap.value(nstartPos , 0) ;
5375
        ifileContent.replace(nstartPos , nlength ,"");
5376
    }
5377
 
5378
 
5379
    if(!open(QIODevice::WriteOnly | QIODevice::Truncate))
5380
    {
5381
        // 向用户输出  文件打不开
5382
        qDebug() << "EziDebug Error:" << errorString() << ":" << fileName() ;
5383
        return 1 ;
5384
    }
5385
 
5386
    qDebug() << "EziDebug info: finish file---" << fileName();
5387
    // 全部写入
5388
    QTextStream iout(this);
5389
    iout << ifileContent ;
5390
    close() ;
5391
 
5392
    QFileInfo ifileInfo(fileName()) ;
5393
    this->modifyStoredTime(ifileInfo.lastModified()) ;
5394
 
5395
    return 0 ;
5396
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.