-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautomatic.vim
4939 lines (4440 loc) · 152 KB
/
automatic.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
" Vim Plugin for Verilog Code Automactic Generation
" RtlTree
" Language: Verilog
" Maintainer: zhangguo
" Version: 2.2.4
" Last Update: 2017-09-18
" For version 7.x or above
" the new signal define store format
" will applied
"
" dict {key : value}
" array [value0, value1]
"
" signal_dict:
" {
" signal_name :
" 0 1 2 3 4 5 6 7
" [width,type,has_defined,seq,line,signal_name,io_dir,last_port]
" }
" width : is the result -1 by number or define or parameter; if no define, set to ''
" type : is io_wire,io_reg,usrdef,inst_wire,freg,creg,wire;
" if no define, set to ''
" if type is io, default value is io_wire, and will update to io_reg if it use in always block
" if type is 'keep', rev for `ifdef `ifndef ...
" has_defined : only use for io, default value set to 0
" seq : normal value is 0 - n, only for io & usrdefine, keep define sequence number not change; if no use, set to -1
" line : it is the define line contents, only use for usrdefine; if no use, set to ''
" signal_name : signal net name
" io_dir : if signal is io net, show io_dir, input / output / inout
"
"
" signal with is same, so use link_dict
" link_dict:
" {
" signal_name :
" {
" {siga : ''},
" {sigb : ''},
" ...
" {sign : ''}
" }
" }
"
" below is all signals
" unresolved_dict:
" {sig : ''}
"
if version < 700
finish
endif
if exists("vlog_plugin")
finish
endif
let vlog_plugin = 1
"iabbrev <= <= #0.1
"Variable & Config & Type {{{1
"let s:GotoInstFile_use = 0
"let s:tree_array_idx = 0
"let s:tree_array = []
if exists("s:vlog_max_col") == 0
let s:vlog_max_col = 40
endif
if exists("s:vlog_arg_margin") == 0
let s:vlog_arg_margin = " "
endif
if exists("s:vlog_inst_margin") == 0
let s:vlog_inst_margin = " "
endif
if exists("s:verilog_indent_width")
let s:vlog_ind = s:verilog_indent_width
let s:indent = repeat(' ',s:vlog_ind)
else
let s:vlog_ind = 4
let s:indent = repeat(' ',s:vlog_ind)
endif
if exists("s:autodef_max_len") == 0
let s:autodef_max_len = 39
endif
if exists("s:autoinst_prefix_max_len") == 0
let s:autoinst_prefix_max_len = 26+4
endif
if exists("s:autoinst_suffix_max_len") == 0
let s:autoinst_suffix_max_len = 30+12
endif
if exists("s:rtltree_init_max_display_layer") == 0
let s:rtltree_init_max_display_layer = 2
endif
if exists("t:RtlTreeVlogDefine") == 0
let t:RtlTreeVlogDefine = 1
endif
let s:sig_offset = 13
let s:clk_period = 8
let s:clk_num = 16
let s:cq_trans = 1
let s:wave_max_wd = s:sig_offset + s:clk_num*s:clk_period
"0 is clk posedge, 4 is clk negedge
" Verilog Type Define
let s:VlogTypePort = '\<input\>\|'
let s:VlogTypePort = s:VlogTypePort . '\<output\>\|'
let s:VlogTypePort = s:VlogTypePort . '\<inout\>'
let s:VlogTypeData = '\<wire\>\|'
let s:VlogTypeData = s:VlogTypeData . '\<reg\>\|'
let s:VlogTypeData = s:VlogTypeData . '\<parameter\>\|'
let s:VlogTypeData = s:VlogTypeData . '\<localparam\>\|'
let s:VlogTypeData = s:VlogTypeData . '\<genvar\>\|'
let s:VlogTypeData = s:VlogTypeData . '\<integer\>'
let s:VlogTypeCalc = '\<assign\>\|'
let s:VlogTypeCalc = s:VlogTypeCalc . '\<always\>'
let s:VlogTypeStru = '\<module\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<endmodule\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<function\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<endfunction\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<task\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<endtask\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<generate\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<endgenerate\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<begin\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<end\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<case\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<casex\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<casez\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<endcase\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<default\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<for\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<if\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<define\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<ifdef\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<ifndef\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<elsif\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<else\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<endif\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<celldefine\>\|'
let s:VlogTypeStru = s:VlogTypeStru . '\<endcelldefine\>'
let s:VlogTypeOthe = '\<posedge\>\|'
let s:VlogTypeOthe = s:VlogTypeOthe . '\<negedge\>\|'
let s:VlogTypeOthe = s:VlogTypeOthe . '\<timescale\>\|'
let s:VlogTypeOthe = s:VlogTypeOthe . '\<initial\>\|'
let s:VlogTypeOthe = s:VlogTypeOthe . '\<forever\>\|'
let s:VlogTypeOthe = s:VlogTypeOthe . '\<specify\>\|'
let s:VlogTypeOthe = s:VlogTypeOthe . '\<endspecify\>\|'
let s:VlogTypeOthe = s:VlogTypeOthe . '\<include\>\|'
let s:VlogTypeOthe = s:VlogTypeOthe . '\<or\>'
let s:VlogTypePre = '\('
let s:VlogTypePost = '\)'
let s:VlogTypeConn = '\|'
let s:VlogTypePorts = s:VlogTypePre . s:VlogTypePort . s:VlogTypePost
let s:VlogTypeDatas = s:VlogTypePre . s:VlogTypeData . s:VlogTypePost
let s:VlogTypeCalcs = s:VlogTypePre . s:VlogTypeCalc . s:VlogTypePost
let s:VlogTypeStrus = s:VlogTypePre . s:VlogTypeStru . s:VlogTypePost
let s:VlogTypeOthes = s:VlogTypePre . s:VlogTypeOthe . s:VlogTypePost
let s:VlogKeyWords = s:VlogTypePre . s:VlogTypePort . s:VlogTypeConn . s:VlogTypeData . s:VlogTypeConn. s:VlogTypeCalc . s:VlogTypeConn. s:VlogTypeStru . s:VlogTypeConn. s:VlogTypeOthe . s:VlogTypePost
let s:not_keywords_pattern = s:VlogKeyWords . '\@!\(\<\w\+\>\)'
"}}}1
"Menu definition{{{1
amenu &TimingWave.AddClk :call AddClk()<CR>
amenu &TimingWave.AddSig :call AddSig()<CR>
amenu &TimingWave.AddBus :call AddBus()<CR>
amenu &TimingWave.AddBlk :call AddBlk()<CR>
amenu &TimingWave.-Operation- :
amenu &TimingWave.Invert<TAB><C-F8> :call Invert()<CR>
amenu &AlwaysBlock.always\ @(posedge\ or\ negedge) :call AlBpn()<CR>
amenu &AlwaysBlock.always\ @(*) :call AlB()<CR>
amenu &AlwaysBlock.always\ @(negedge\ or\ negedge) :call AlBnn()<CR>
amenu &AlwaysBlock.always\ @(posedge) :call AlBp()<CR>
amenu &AlwaysBlock.always\ @(negedge) :call AlBn()<CR>
" null b
" ) b
" a b
" b null
" b (
" ========================================== ^ null or ) or a b null or (
"amenu &Search.instance\ -\ up<TAB><C-F1> :call search('^\s*'.'\(\\|.*)\s\+\\|\w\+\s\+\)'.'\(\w\+\)'.'\(\s*$\\|\s*(\)','be')<CR>
"amenu &Search.instance\ -\ down<TAB><C-F2> :call search('^\s*'.'\(\\|.*)\s\+\\|\w\+\s\+\)'.'\(\w\+\)'.'\(\s*$\\|\s*(\)','e')<CR>
"amenu &Search.instance\ -\ up<TAB><C-F1> :call search('^\s*'.'\(\\|.*)\s\+\\|'.not_keywords_pattern.'\s\+\)'.not_keywords_pattern.'\(\s*$\\|\s*(\)','be')<CR>
"amenu &Search.instance\ -\ down<TAB><C-F2> :call search('^\s*'.'\(\\|.*)\s\+\\|'.not_keywords_pattern.'\s\+\)'.not_keywords_pattern.'\(\s*$\\|\s*(\)','e')<CR>
amenu &Search.instance\ -\ up<TAB><C-F1> :call SearchInstance(1)<CR>
amenu &Search.instance\ -\ down<TAB><C-F2> :call SearchInstance(0)<CR>
amenu &Search.-structure- :
amenu &Search.module\ -\ up<TAB><C-F3> :call SearchModule(1)<CR>
amenu &Search.module\ -\ down<TAB><C-F4> :call SearchModule(0)<CR>
amenu &Search.-driver- :
amenu &Search.Trace\ Driver(Lite)<TAB><AS-D> :call SearchDriverLite(0)<CR>
amenu &Search.-navigation- :
amenu &Search.Backward\ History<TAB><CA-B> :call BackwardMark()<CR>
amenu &Search.Forward\ History<TAB><CA-F> :call ForwardMark()<CR>
"amenu &Search.-netlist- :
"amenu &Search.NETLIST\ -\ instance\ -\ up :call search('^\s*\w\+\s\+\w\+','be')<CR>
"amenu &Search.NETLIST\ -\ instance\ -\ down :call search('^\s*\w\+\s\+\w\+','e')<CR>
amenu &Verilog.AddHeader :call AddHeader()<CR>
amenu &Verilog.-Misc- :
amenu &Verilog.SingleLineComment<TAB><F2> :call AutoComment()<CR>
amenu &Verilog.MultiLineComment<TAB><F3> :call AutoComment2()<CR>
amenu &Verilog.AddCurLineComment<TAB><F4> :call AddCurLineComment()<CR>
amenu &Verilog.WireDef2PortConn<TAB><F5> :call WireDef2PortConn()<CR>
amenu &Verilog.Input<->Output<TAB><F6> :call Input2Output()<CR>
"amenu &Verilog.SearchUpInstLine<TAB><F9> :call SearchUpInstLine()<CR>
amenu &Verilog.-Automatic- :
amenu &Verilog.AutoArg<TAB><S-F1> :call AutoArg()<CR>
amenu &Verilog.AutoDef<TAB><S-F2> :call AutoDef()<CR>
amenu &Verilog.-AutomaticInst- :
amenu &Verilog.AutoInst<TAB><S-F3> :call AutoInst(0)<CR>
amenu &Verilog.AutoInstUpdate<TAB> :call AutoInstUpdate(0)<CR>
amenu &Verilog.AutoInstUpdateOrder<TAB> :call AutoInstUpdateOrder(0)<CR>
amenu &Verilog.AutoInstPortReAlign<TAB><NA> :call AutoInstPortReAlign()<CR>
amenu &Verilog.AppendPortDriectionToInst<TAB><NA> :call AppendPortDriectionToInst(0)<CR>
"amenu &Verilog.AutoInst\ -\ all :call AutoInst(1)<CR>
amenu &Verilog.-Kill- :
amenu &Verilog.KillAuto :call KillAuto()<CR>
amenu &Verilog.KillAutoArg :call KillAutoArg()<CR>
amenu &Verilog.KillAutoDef :call KillAutoDef()<CR>
amenu &Verilog.KillAutoInst :call KillAutoInst(0)<CR>
"amenu &Verilog.KillAutoInst\ -\ all :call KillAutoInst(1)<CR>
"}}}1
"ToolBar definition{{{1
amenu ToolBar.-Show- :
amenu icon=$HOME/.vim/after/ShowCall.xpm ToolBar.ShowCall :call ShowCall()<CR>
amenu icon=$HOME/.vim/after/ShowDef.xpm ToolBar.ShowDef :call ShowDef()<CR>
amenu ToolBar.-TimingWave- :
amenu icon=$HOME/.vim/after/AddClk.xpm ToolBar.AddClk :call AddClk()<CR>
amenu icon=$HOME/.vim/after/AddSig.xpm ToolBar.AddSig :call AddSig()<CR>
amenu icon=$HOME/.vim/after/AddBus.xpm ToolBar.AddBus :call AddBus()<CR>
amenu icon=$HOME/.vim/after/AddNeg.xpm ToolBar.AddNeg :call AddNeg()<CR>
amenu icon=$HOME/.vim/after/AddBlk.xpm ToolBar.AddBlk :call AddBlk()<CR>
amenu ToolBar.-Always- :
amenu icon=$HOME/.vim/after/alpn.xpm ToolBar.alpn :call AlBpn()<CR>
amenu icon=$HOME/.vim/after/al.xpm ToolBar.al :call AlB()<CR>
amenu icon=$HOME/.vim/after/alnn.xpm ToolBar.alnn :call AlBnn()<CR>
tmenu ToolBar.ShowCall ShowCall
tmenu ToolBar.ShowDef ShowDef
tmenu ToolBar.AddClk AddClk
tmenu ToolBar.AddSig AddSig
tmenu ToolBar.AddBus AddBus
tmenu ToolBar.AddNeg AddNeg
tmenu ToolBar.AddBlk AddSep line
tmenu ToolBar.alpn always @(posedge clk or negedge rst_n)
tmenu ToolBar.al always @(*)
tmenu ToolBar.alnn always @(negedge clk or negedge rst_n)
"}}}1
"Command definition{{{1
command RtlTree :call RtlTree()
map <C-J> :call ShowInst()<ESC>
map <CA-A> :call ShowCall()<ESC>
map <CA-N> :call ShowDef()<ESC>
map <S-F1> :call AutoArg()<ESC>
map <S-F2> :call AutoDef()<ESC>
map <S-F3> :call AutoInst(0)<ESC>
map <S-F4> :call AppendPortDriectionToInst(0)<ESC>
map <C-F8> :call Invert()<ESC>
map <F2> :call AutoComment()<ESC>
map <F3> <ESC>:call AutoComment2()<ESC>
map <F4> :call AddCurLineComment()<ESC>
map <F5> :call WireDef2PortConn()<ESC>
map <F6> :call Input2Output()<ESC>
"map <F9> :call SearchUpInstLine()<ESC>
map <C-F1> :call SearchInstance(1)<ESC>
map <C-F2> :call SearchInstance(0)<ESC>
map <C-F3> :call SearchModule(1)<ESC>
map <C-F4> :call SearchModule(0)<ESC>
map <AS-D> :call SearchDriverLite(0)<ESC>
map <CA-B> :call BackwardMark()<ESC>
map <CA-F> :call ForwardMark()<ESC>
autocmd BufNewFile *.v call AutoTemplate()
"autocmd BufWrite *.v call UpdateLastModifyTime()
"autocmd BufRead *.v call GotoInstRenderTree()
"}}}1
"Search instance / module definition {{{1
function SearchInstance(backward)
call s:PushMark()
if (a:backward == 1)
" null b
" ) b
" a b
" b null
" b (
" ================ ^ null or ) or a b null or //.*$ or (
execute "normal 0"
call search('^\s*'.'\(\|.*)\s\+\|'.s:not_keywords_pattern.'\s\+\)'.s:not_keywords_pattern.'\(\s*$\|\s*\/\/.*$\|\s*(\)','be')
"call search('^\s*'.'\(\|.*)\s\+\|'.s:not_keywords_pattern.'\s\+\)'.s:not_keywords_pattern.'\(\s*$\|\s*(\)','be')
else
execute "normal $"
call search('^\s*'.'\(\|.*)\s\+\|'.s:not_keywords_pattern.'\s\+\)'.s:not_keywords_pattern.'\(\s*$\|\s*\/\/.*$\|\s*(\)','e')
endif
endfunction
function SearchModule(backward)
call s:PushMark()
if (a:backward)
execute "normal 0"
call search('^\s*module','be')
else
execute "normal $"
call search('^\s*module','e')
endif
endfunction
function SearchDriverLite(backward)
call s:PushMark()
" input ... <cword> or <cword> =/<= ...
call search('\('.'\<input\>'.'.*'.'\<'.expand("<cword>").'\>'.'\)' .'\|'. '\('.'\<'.expand("<cword>").'\>'.'\([.*]\)\?'.'\s*<\?=\s'.'\)','')
endfunction
"}}}1
"Mark definition {{{1
let b:markchar = 'a'
function s:MarkCharAdd()
if (b:markchar == 'z')
let b:markchar = 'a'
else
let l:markchar2nr = char2nr(b:markchar) + 1
let b:markchar = nr2char(l:markchar2nr)
endif
endfunction
function s:MarkCharDec()
if (b:markchar == 'a')
let b:markchar = 'z'
else
let l:markchar2nr = char2nr(b:markchar) - 1
let b:markchar = nr2char(l:markchar2nr)
endif
endfunction
function s:PushMark()
if exists("b:markchar") == 0
let b:markchar = 'a'
endif
execute "normal m" . b:markchar
call s:MarkCharAdd()
execute "normal :delmarks " . b:markchar
endfunction
function ForwardMark()
if exists("b:markchar") == 0
let b:markchar = 'a'
endif
call s:MarkCharAdd()
execute "normal g`" . b:markchar
endfunction
function BackwardMark()
if exists("b:markchar") == 0
let b:markchar = 'a'
endif
call s:MarkCharDec()
execute "normal g`" . b:markchar
endfunction
"}}}1
"TimingWave definition {{{1
function AddClk() "{{{2
let ret = []
let ret0 = "// . . ."
let ret1 = "// +"
let ret2 = "// clk |"
let ret3 = "// +"
let format = '%' . s:clk_period/2 . 'd'
for idx in range(1,s:clk_num)
let ret0 = ret0 . printf(format,idx) . repeat(' ',s:clk_period/2)
for idx2 in range(1,s:clk_period/2-1)
let ret1 = ret1 . '-'
let ret2 = ret2 . ' '
let ret3 = ret3 . ' '
endfor
let ret1 = ret1 . '+'
let ret2 = ret2 . '|'
let ret3 = ret3 . '+'
for idx2 in range(1,s:clk_period/2-1)
let ret1 = ret1 . ' '
let ret2 = ret2 . ' '
let ret3 = ret3 . '-'
endfor
let ret1 = ret1 . '+'
let ret2 = ret2 . '|'
let ret3 = ret3 . '+'
endfor
call add(ret,ret0)
call add(ret,ret1)
call add(ret,ret2)
call add(ret,ret3)
let lnum = line(".")
let col = col(".")
call append(line("."),ret)
call cursor(lnum+4,col)
endfunction "}}}2
function AddSig() "{{{2
let ret = []
let ret0 = "// "
let ret1 = "// sig "
let ret2 = "// "
for idx in range(s:sig_offset,s:wave_max_wd)
let ret0 = ret0 . " "
let ret1 = ret1 . " "
let ret2 = ret2 . "-"
endfor
call add(ret,ret0)
call add(ret,ret1)
call add(ret,ret2)
let lnum = line(".")
let col = col(".")
call append(line("."),ret)
call cursor(lnum+3,col)
endfunction "}}}2
function AddBus() "{{{2
let ret = []
let ret0 = "// "
let ret1 = "// bus "
let ret2 = "// "
for idx in range(s:sig_offset,s:wave_max_wd)
let ret0 = ret0 . "-"
let ret1 = ret1 . " "
let ret2 = ret2 . "-"
endfor
call add(ret,ret0)
call add(ret,ret1)
call add(ret,ret2)
let lnum = line(".")
let col = col(".")
call append(line("."),ret)
call cursor(lnum+3,col)
endfunction "}}}2
function AddNeg() "{{{2
let lnum = s:GetSigNameLineNum()
if lnum == -1
return
endif
let line = getline(lnum)
if line =~ 'neg\s*$'
return
endif
call setline(lnum,line." neg")
endfunction "}}}2
function AddBlk() "{{{2
let ret = []
let ret0 = "// "
for idx in range(s:sig_offset,s:wave_max_wd)
let ret0 = ret0 . " "
endfor
call add(ret,ret0)
let lnum = line(".")
let col = col(".")
call append(line("."),ret)
call cursor(lnum+1,col)
endfunction "}}}2
function s:My_mod(int1,int2) "{{{2
let ret = a:int1
while 1
if ret >= a:int2
let ret = ret - a:int2
else
break
endif
endwhile
return ret
endfunction "}}}2
function s:GetSigNameLineNum() "{{{2
let lnum = -1
let cur_lnum = line(".")
if getline(cur_lnum) =~ '^\/\/\s*\w\+'
let lnum = cur_lnum
elseif getline(cur_lnum-1) =~ '^\/\/\s*\w\+'
let lnum = cur_lnum-1
elseif getline(cur_lnum+1) =~ '^\/\/\s*\w\+'
let lnum = cur_lnum+1
endif
return lnum
endfunction "}}}2
function s:GetPosedge(signeg) "{{{2
if a:signeg == 0
return col(".") - s:My_mod(col(".") - s:sig_offset,s:clk_period)
else
return col(".") - s:My_mod(col(".") - s:sig_offset + s:clk_period/2,s:clk_period)
endif
endfunction "}}}2
function s:GetNegedge(signeg) "{{{2
return s:GetPosedge(a:signeg) + s:clk_period/2
endfunction "}}}2
function s:SigLastClkIsHigh(lnum,posedge,negedge) "{{{2
let ret = 0
let line = getline(a:lnum - 1)
if line[a:posedge-1] =~ '-'
let ret = 1
endif
return ret
endfunction "}}}2
function s:SigCurClkIsHigh(lnum,posedge,negedge) "{{{2
let ret = 0
let line = getline(a:lnum - 1)
if line[a:negedge-1] =~ '-'
let ret = 1
endif
return ret
endfunction "}}}2
function s:SigNextClkIsHigh(lnum,posedge,negedge) "{{{2
let ret = 0
let line = getline(a:lnum - 1)
if line[a:negedge+s:clk_period-1] =~ '-'
let ret = 1
endif
return ret
endfunction "}}}2
function s:BusCurClkHaveChg(lnum,posedge,negedge) "{{{2
let ret = 0
let line = getline(a:lnum)
if line[a:posedge+s:cq_trans-1] =~ 'X'
let ret = 1
endif
return ret
endfunction "}}}2
function s:SigIsNeg() "{{{2
let ret = 0
let lnum = s:GetSigNameLineNum()
if getline(lnum) =~ 'neg\s*$'
let ret = 1
endif
return ret
endfunction "}}}2
function Invert() "{{{2
let lnum = s:GetSigNameLineNum()
if lnum == -1
return
endif
let top = getline(lnum-1)
let mid = getline(lnum)
let bot = getline(lnum+1)
let signeg = s:SigIsNeg()
let posedge = s:GetPosedge(signeg)
let negedge = s:GetNegedge(signeg)
let next_posedge = posedge + s:clk_period
let last = s:SigLastClkIsHigh(lnum,posedge,negedge)
let cur = s:SigCurClkIsHigh(lnum,posedge,negedge)
let next = s:SigNextClkIsHigh(lnum,posedge,negedge)
let chg = s:BusCurClkHaveChg(lnum,posedge,negedge)
let res_top = strpart(top,0,posedge+s:cq_trans-1)
let res_mid = strpart(mid,0,posedge+s:cq_trans-1)
let res_bot = strpart(bot,0,posedge+s:cq_trans-1)
let init_top_char = ' '
let init_mid_char = ' '
let init_bot_char = ' '
let top_char = ' '
let mid_char = ' '
let bot_char = ' '
let is_bus = 0
if top[negedge] =~ '-' && bot[negedge] =~ '-'
let is_bus = 1
if chg
let init_top_char = '-'
let init_mid_char = ' '
let init_bot_char = '-'
else
let init_top_char = ' '
let init_mid_char = 'X'
let init_bot_char = ' '
endif
let top_char = '-'
let mid_char = ' '
let bot_char = '-'
let res_top = res_top . init_top_char
let res_mid = res_mid . init_mid_char
let res_bot = res_bot . init_bot_char
for idx in range(1,s:clk_period-1)
let res_top = res_top . top_char
let res_mid = res_mid . mid_char
let res_bot = res_bot . bot_char
endfor
else
if last == cur
if cur
let init_top_char = '+'
let init_mid_char = '|'
let init_bot_char = '+'
let top_char = ' '
let bot_char = '-'
else
let init_top_char = '+'
let init_mid_char = '|'
let init_bot_char = '+'
let top_char = '-'
let bot_char = ' '
endif
else
if cur
let init_top_char = ' '
let init_mid_char = ' '
let init_bot_char = '-'
let top_char = ' '
let bot_char = '-'
else
let init_top_char = '-'
let init_mid_char = ' '
let init_bot_char = ' '
let top_char = '-'
let bot_char = ' '
endif
endif
let res_top = res_top . init_top_char
let res_mid = res_mid . init_mid_char
let res_bot = res_bot . init_bot_char
for idx in range(1,s:clk_period-1)
let res_top = res_top . top_char
let res_mid = res_mid . mid_char
let res_bot = res_bot . bot_char
endfor
if next == cur
let init_top_char = '+'
let init_mid_char = '|'
let init_bot_char = '+'
else
if cur
let init_top_char = ' '
let init_mid_char = ' '
let init_bot_char = '-'
else
let init_top_char = '-'
let init_mid_char = ' '
let init_bot_char = ' '
endif
endif
let res_top = res_top . init_top_char
let res_mid = res_mid . init_mid_char
let res_bot = res_bot . init_bot_char
endif
let res_top = res_top .strpart(top,posedge+s:cq_trans+s:clk_period-is_bus,s:wave_max_wd-1)
let res_mid = res_mid .strpart(mid,posedge+s:cq_trans+s:clk_period-is_bus,s:wave_max_wd-1)
let res_bot = res_bot .strpart(bot,posedge+s:cq_trans+s:clk_period-is_bus,s:wave_max_wd-1)
call setline(lnum-1,res_top)
call setline(lnum,res_mid)
call setline(lnum+1,res_bot)
endfunction "}}}2
"}}}1
"AutoTemplate definition {{{1
function s:GetUserName() "{{{2
let a:user = system("echo $USER_DIT")
let a:user = substitute(a:user,'\n','','')
if a:user =~ 'USER_DIT:'
let a:user = $USER
endif
return a:user
endfunction "}}}2
function AddHeader() "{{{2
let line = getline(1)
if line =~ '// +FHDR'
return
endif
let company = system("echo $COMPANY")
let company = substitute(company,'\n','','')
if company =~ 'COMPANY:'
echohl WarningMsg | echo "unix env $COMPANY: Undefined variable. Please set_env COMPANY in ~/.cshrc" | echohl None
endif
"===============================================================
" Add File Header
"===============================================================
let filename = expand("%")
call append(0, "// +FHDR------------------------------------------------------------")
call append(1, "// Copyright (c) ".strftime("%Y ") . company . ".")
call append(2, "// ALL RIGHTS RESERVED")
call append(3, "// -----------------------------------------------------------------")
call append(4, "// Filename : ".filename)
call append(5, "// Author : ".s:GetUserName())
call append(6, "// Created On : ".strftime("%Y-%m-%d %H:%M"))
call append(7, "// Last Modified : ")
call append(8, "// -----------------------------------------------------------------")
call append(9, "// Description:")
call append(10, "//")
call append(11, "//")
call append(12, "// -FHDR------------------------------------------------------------")
call append(13, "")
endfunction "}}}2
function AutoTemplate() "{{{2
let filename = expand("%")
let modulename = matchstr(filename,'\w\+')
call AddHeader()
call append(14, "`ifndef __" . substitute(toupper(filename),'\.','_','') . "__")
call append(15, "`define __" . substitute(toupper(filename),'\.','_','') . "__")
call append(16, "")
call append(17, "`timescale 1ns/1ps")
call append(18, "")
call append(19, "module " . modulename . '(/*autoarg*/);')
if modulename == 'top'
call append(20, "")
call append(21, "reg clk;")
call append(22, "reg rst_n;")
call append(23, "/*autodef off*/")
call append(24, "initial begin")
call append(25, " clk = 1'b0;")
call append(26, " forever #10 clk = ~clk;")
call append(27, "end")
call append(28, "initial begin")
call append(29, " rst_n = 1'b0;")
call append(30, " #52 rst_n = 1'b1;")
call append(31, "end")
call append(32, "initial begin")
call append(33, " //$vcdpluson(0,top);")
call append(34, " $fsdbDumpvars(0,top);")
call append(35, "end")
call append(36, "initial begin")
call append(37, " #1000;")
call append(38, " $finish;")
call append(39, "end")
call append(40, "/*autodef on*/")
call append(41, "")
call append(42, "//{{{")
call append(43, '/*autodef*/')
call append(44, "//}}}")
call append(45, "")
call append(46, "//inst u_inst(/*autoinst*/);")
call append(47, "")
call append(48, "endmodule")
call append(49, "")
call append(50, "`endif")
call search('inst')
else
call append(20, "")
call append(21, "input clk;")
call append(22, "input rst_n;")
call append(23, "")
call append(24, "input vld;")
call append(25, "input [7:0] data;")
call append(26, "output ack;")
call append(27, "")
call append(28, "//{{{")
call append(29, '/*autodef*/')
call append(30, "//}}}")
call append(31, "")
call append(32, "endmodule")
call append(33, "")
call append(34, "`endif")
call search('vld')
endif
endfunction "}}}2
function UpdateLastModifyTime() "{{{2
let line = getline(7)
if line =~ '// Last Modified'
call setline(7,"// Last Modified : " . strftime("%Y-%m-%d %H:%M"))
endif
endfunction "}}}2
"}}}1
"Always Block definition {{{1
function AlBpn() "{{{2
let lnum = line(".")
for idx in range(1,7)
call append(lnum,"")
endfor
call setline(lnum+1,"always @(posedge clk or negedge rst_n) begin")
call setline(lnum+2," if(!rst_n) begin")
call setline(lnum+3," ")
call setline(lnum+4," end else if() begin")
call setline(lnum+5," end else begin")
call setline(lnum+6," end")
call setline(lnum+7,"end")
call cursor(lnum+3,9)
endfunction "}}}2
function AlB() "{{{2
let lnum = line(".")
for idx in range(1,3)
call append(lnum,"")
endfor
call setline(lnum+1,"always @(*) begin")
call setline(lnum+2," ")
call setline(lnum+3,"end")
call cursor(lnum+2,5)
endfunction "}}}2
function AlBnn() "{{{2
let lnum = line(".")
for idx in range(1,7)
call append(lnum,"")
endfor
call setline(lnum+1,"always @(negedge clk or negedge rst_n) begin")
call setline(lnum+2," if(!rst_n) begin")
call setline(lnum+3," ")
call setline(lnum+4," end else if() begin")
call setline(lnum+5," end else begin")
call setline(lnum+6," end")
call setline(lnum+7,"end")
call cursor(lnum+3,9)
endfunction "}}}2
function AlBp() "{{{2
let lnum = line(".")
for idx in range(1,6)
call append(lnum,"")
endfor
call setline(lnum+1,"always @(posedge clk) begin")
call setline(lnum+2," if() begin")
call setline(lnum+3," ")
call setline(lnum+4," end else begin")
call setline(lnum+5," end")
call setline(lnum+6,"end")
call cursor(lnum+3,9)
endfunction "}}}2
function AlBn() "{{{2
let lnum = line(".")
for idx in range(1,6)
call append(lnum,"")
endfor
call setline(lnum+1,"always @(negedge clk) begin")
call setline(lnum+2," if() begin")
call setline(lnum+3," ")
call setline(lnum+4," end else begin")
call setline(lnum+5," end")
call setline(lnum+6,"end")
call cursor(lnum+3,9)
endfunction "}}}2
"}}}1
"AutoComment definition "{{{1
function AutoComment() "{{{2
let lnum = line(".")
let line = getline(lnum)
if line =~ '^\/\/ by .* \d\d\d\d-\d\d-\d\d'
let tmp_line = substitute(line,'^\/\/ by .* \d\d\d\d-\d\d-\d\d | ','','')
else
let tmp_line = '// by ' . s:GetUserName() . ' ' . strftime("%Y-%m-%d") . ' | ' . line
endif
call setline(lnum,tmp_line)
endfunction "}}}2
function AutoComment2() "{{{2
let col = col(".")
let lnum = line(".")
if line("'<") == lnum || line("'>") == lnum
if getline(line("'<")) =~ '^/\*'
'<
execute "normal dd"
'>
execute "normal dd"
if lnum != line("'<")
let lnum = line("'>")-1
endif
else
call append(line("'<")-1,'/*------\/-------- by '.s:GetUserName().' '.strftime("%Y-%m-%d").' --------\/--------{{{')
call append(line("'>") ,'--------/\-------- by '.s:GetUserName().' '.strftime("%Y-%m-%d").' --------/\------}}}*/')
let lnum = line(".")
endif
endif
call cursor(lnum,col)
"echo "< = " . line("'<") . " > = " . line("'>") . " cur = " . line(".")
endfunction "}}}2
function AddCurLineComment() "{{{2
let lnum = line(".")
let line = getline(lnum)
let tmp_line = line . ' // ' . s:GetUserName() . ' ' . strftime("%Y-%m-%d") . ' |'
call setline(lnum,tmp_line)
normal $
endfunction "}}}2
"}}}1
"Line Number definition "{{{1
function LineNumber() "{{{2
let startlinenumber = line("'<")
let endlinenumber = line("'>")
let lines = endlinenumber - startlinenumber + 1
echo startlinenumber . "-" . endlinenumber . ", lines:" . lines
endfunction "}}}2
"}}}1
"WireDef2PortConn definition "{{{1
function WireDef2PortConn() "{{{2
let lnum = line(".")
let line = getline(lnum)
if line =~ '^\s*\/\/' || line =~ '^\s*$'
return 0
endif
let type = matchstr(line,s:VlogTypePorts)
let line = substitute(line,'^\s*' . s:VlogTypePorts . '\s*','','')
let line = substitute(line,'^\s*' . s:VlogTypeDatas . '\s*','','')
let width = matchstr(line,'\[.*:.*\]')
let line = substitute(line,'\[.*:.*\]','','')
let sig = matchstr(line,'\w\+')
if line =~ '('
if type =~ '\w\+'
let tmp_line = type . s:CalMargin(7,len(type)) . 'wire ' . width
else
let tmp_line = 'wire ' . s:CalMargin(7,0) . width
endif
let margin = s:CalMargin(s:autodef_max_len, len(tmp_line))
let tmp_line = tmp_line . margin . sig . ";"
else
let prefix_margin = s:CalMargin(s:autoinst_prefix_max_len, len(sig))
let suffix_margin = s:CalMargin(s:autoinst_suffix_max_len, len(sig)+len(width))
let tmp_line = ' .' . sig . prefix_margin .'(' . sig . width . suffix_margin . '), // ' . type
endif
call setline(lnum,tmp_line)
endfunction "}}}2
"}}}1