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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.6/] [rtl/] [vlib/] [simlib/] [simlib.vhd] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 wfjm
-- $Id: simlib.vhd 314 2010-07-09 17:38:41Z mueller $
2
--
3
-- Copyright 2006-2008 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4
--
5
-- This program is free software; you may redistribute and/or modify it under
6
-- the terms of the GNU General Public License as published by the Free
7
-- Software Foundation, either version 2, or at your option any later version.
8
--
9
-- This program is distributed in the hope that it will be useful, but
10
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
-- for complete details.
13
--
14
------------------------------------------------------------------------------
15
-- Module Name:    simlib - sim
16
-- Description:    Support routines for test benches
17
--
18
-- Dependencies:   -
19
-- Test bench:     -
20
-- Target Devices: generic
21
-- Tool versions:  xst 8.1, 8.2, 9.1, 9.2; ghdl 0.18-0.25
22
-- Revision History: 
23
-- Date         Rev Version  Comment
24
-- 2008-03-24   129   1.3.5  CLK_CYCLE now 31 bits
25
-- 2008-03-02   121   1.3.4  added readempty (to discard rest of line)
26
-- 2007-12-27   106   1.3.3  added simclk2v
27
-- 2007-12-15   101   1.3.2  add read_ea(time), readtagval[_ea](std_logic)
28
-- 2007-10-12    88   1.3.1  avoid ieee.std_logic_unsigned, use cast to unsigned
29
-- 2007-08-28    76   1.3    added writehex and writegen
30
-- 2007-08-10    72   1.2.2  remove entity simclk, put into separate source
31
-- 2007-08-03    71   1.2.1  readgen, readtagval, readtagval2: add base arg
32
-- 2007-07-29    70   1.2    readtagval2: add tag=- support; add readword_ea,
33
--                           readoptchar, writetimestamp
34
-- 2007-07-28    69   1.1.1  rename readrest -> testempty; add readgen
35
--                           use readgen in readtagval() and readtagval2()
36
-- 2007-07-22    68   1.1    add readrest, readtagval, readtagval2
37
-- 2007-06-30    62   1.0.1  remove clock_period ect constant defs
38
-- 2007-06-14    56   1.0    Initial version (renamed from pdp11_sim.vhd)
39
------------------------------------------------------------------------------
40
 
41
library ieee;
42
use ieee.std_logic_1164.all;
43
use ieee.std_logic_arith.all;
44
use ieee.std_logic_textio.all;
45
use std.textio.all;
46
 
47
use work.slvtypes.all;
48
 
49
package simlib is
50
 
51
constant null_char : character := character'val(0);            -- '\0'
52
constant null_string : string(1 to 1) := (others=>null_char);  -- "\0"
53
 
54
procedure readwhite(                    -- read over white space
55
  L: inout line);                       -- line
56
 
57
procedure readoct(                      -- read slv in octal base (arb. length)
58
  L: inout line;                        -- line
59
  value: out std_logic_vector;          -- value to be read
60
  good: out boolean);                   -- success flag
61
 
62
procedure readhex(                      -- read slv in hex base (arb. length)
63
  L: inout line;                        -- line
64
  value: out std_logic_vector;          -- value to be read
65
  good: out boolean);                   -- success flag
66
 
67
procedure readgen(                      -- read slv generic base
68
  L: inout line;                        -- line
69
  value: out std_logic_vector;          -- value to be read
70
  good: out boolean;                    -- success flag
71
  base: in integer:= 2);                -- default base
72
 
73
procedure readcomment(
74
  L: inout line;
75
  good: out boolean);
76
 
77
procedure readcommand(
78
  L: inout line;
79
  name: out string;
80
  good: out boolean);
81
 
82
procedure readword(
83
  L: inout line;
84
  name: out string;
85
  good: out boolean);
86
 
87
procedure readoptchar(
88
  L: inout line;
89
  char: in character;
90
  good: out boolean);
91
 
92
procedure readempty(
93
  L: inout line);
94
 
95
procedure testempty(
96
  L: inout line;
97
  good: out boolean);
98
 
99
procedure testempty_ea(
100
  L: inout line);
101
 
102
procedure read_ea(
103
  L: inout line;
104
  value: out integer);
105
procedure read_ea(
106
  L: inout line;
107
  value: out time);
108
 
109
procedure read_ea(
110
  L: inout line;
111
  value: out std_logic);
112
procedure read_ea(
113
  L: inout line;
114
  value: out std_logic_vector);
115
 
116
procedure readoct_ea(
117
  L: inout line;
118
  value: out std_logic_vector);
119
 
120
procedure readhex_ea(
121
  L: inout line;
122
  value: out std_logic_vector);
123
 
124
procedure readgen_ea(
125
  L: inout line;
126
  value: out std_logic_vector;
127
  base: in integer:= 2);
128
 
129
procedure readword_ea(
130
  L: inout line;
131
  name: out string);
132
 
133
procedure readtagval(
134
  L: inout line;
135
  tag: in string;
136
  match: out boolean;
137
  val: out std_logic_vector;
138
  good: out boolean;
139
  base: in integer:= 2);
140
procedure readtagval_ea(
141
  L: inout line;
142
  tag: in string;
143
  match: out boolean;
144
  val: out std_logic_vector;
145
  base: in integer:= 2);
146
 
147
procedure readtagval(
148
  L: inout line;
149
  tag: in string;
150
  match: out boolean;
151
  val: out std_logic;
152
  good: out boolean);
153
procedure readtagval_ea(
154
  L: inout line;
155
  tag: in string;
156
  match: out boolean;
157
  val: out std_logic);
158
 
159
procedure readtagval2(
160
  L: inout line;
161
  tag: in string;
162
  match: out boolean;
163
  val1: out std_logic_vector;
164
  val2: out std_logic_vector;
165
  good: out boolean;
166
  base: in integer:= 2);
167
procedure readtagval2_ea(
168
  L: inout line;
169
  tag: in string;
170
  match: out boolean;
171
  val1: out std_logic_vector;
172
  val2: out std_logic_vector;
173
  base: in integer:= 2);
174
 
175
procedure writeoct(                     -- write slv in octal base (arb. length)
176
  L: inout line;                        -- line
177
  value: in std_logic_vector;           -- value to be written
178
  justified: in side:=right;            -- justification (left/right)
179
  field: in width:=0);                  -- field width
180
 
181
procedure writehex(                     -- write slv in hex base (arb. length)
182
  L: inout line;                        -- line
183
  value: in std_logic_vector;           -- value to be written
184
  justified: in side:=right;            -- justification (left/right)
185
  field: in width:=0);                  -- field width
186
 
187
procedure writegen(                     -- write slv in generic base (arb. lth)
188
  L: inout line;                        -- line
189
  value: in std_logic_vector;           -- value to be written
190
  justified: in side:=right;            -- justification (left/right)
191
  field: in width:=0;                   -- field width
192
  base: in integer:= 2);                -- default base
193
 
194
procedure writetimestamp(
195
  L: inout line;
196
  clkcyc: in slv31;
197
  str : in string := null_string);
198
 
199
-- ----------------------------------------------------------------------------
200
 
201
component simclk is                   -- test bench clock generator
202
  generic (
203
    PERIOD : time := 20 ns;           -- clock period
204
    OFFSET : time := 200 ns);         -- clock offset (first up transition)
205
  port (
206
    CLK  : out slbit;                 -- clock
207
    CLK_CYCLE  : out slv31;           -- clock cycle number
208
    CLK_STOP : in slbit               -- clock stop trigger
209
  );
210
end component;
211
 
212
component simclkv is                  -- test bench clock generator
213
                                      --  with variable periods
214
  port (
215
    CLK  : out slbit;                 -- clock
216
    CLK_CYCLE  : out slv31;           -- clock cycle number
217
    CLK_PERIOD : in time;             -- clock period
218
    CLK_HOLD : in slbit;              -- if 1, hold clocks in 0 state
219
    CLK_STOP : in slbit               -- clock stop trigger
220
  );
221
end component;
222
 
223
end package simlib;
224
 
225
-- ----------------------------------------------------------------------------
226
 
227
package body simlib is
228
 
229
procedure readwhite(                  -- read over white space
230
  L: inout line) is                   -- line
231
  variable ch : character;
232
begin
233
  while L'length>0 loop
234
    ch := L(L'left);
235
    exit when (ch/=' ' and ch/=HT);
236
    read(L,ch);
237
  end loop;
238
 
239
end procedure readwhite;
240
 
241
-- -------------------------------------
242
 
243
procedure readoct(                      -- read slv in octal base (arb. length)
244
  L: inout line;                        -- line 
245
  value: out std_logic_vector;          -- value to be read
246
  good: out boolean) is                 -- success flag
247
 
248
  variable nibble : std_logic_vector(2 downto 0);
249
  variable sum : std_logic_vector(31 downto 0);
250
  variable ndig : integer;              -- number of digits
251
  variable ok : boolean;
252
  variable ichar : character;
253
 
254
begin
255
 
256
  assert not value'ascending(1)
257
    report "readoct called with ascending range"
258
    severity failure;
259
  assert value'length<=32
260
    report "readoct called with value'length > 32"
261
    severity failure;
262
 
263
  readwhite(L);
264
 
265
  ndig := 0;
266
  sum := (others=>'U');
267
 
268
  while L'length>0 loop
269
    ok := true;
270
    case L(L'left) is
271
      when '0' => nibble := "000";
272
      when '1' => nibble := "001";
273
      when '2' => nibble := "010";
274
      when '3' => nibble := "011";
275
      when '4' => nibble := "100";
276
      when '5' => nibble := "101";
277
      when '6' => nibble := "110";
278
      when '7' => nibble := "111";
279
      when 'u'|'U' => nibble := "UUU";
280
      when 'x'|'X' => nibble := "XXX";
281
      when 'z'|'Z' => nibble := "ZZZ";
282
      when '-' => nibble := "---";
283
      when others => ok := false;
284
    end case;
285
 
286
    exit when not ok;
287
    read(L,ichar);
288
    ndig := ndig + 1;
289
    sum(sum'left downto 3) := sum(sum'left-3 downto 0);
290
    sum(2 downto 0) := nibble;
291
  end loop;
292
 
293
  ok := ndig>0;
294
  value := sum(value'range);
295
  good := ok;
296
 
297
end procedure readoct;
298
 
299
-- -------------------------------------
300
 
301
procedure readhex(                      -- read slv in hex base (arb. length)
302
  L: inout line;                        -- line
303
  value: out std_logic_vector;          -- value to be read
304
  good: out boolean) is                 -- success flag
305
 
306
  variable nibble : std_logic_vector(3 downto 0);
307
  variable sum : std_logic_vector(31 downto 0);
308
  variable ndig : integer;              -- number of digits
309
  variable ok : boolean;
310
  variable ichar : character;
311
 
312
begin
313
 
314
  assert not value'ascending(1)
315
    report "readhex called with ascending range"
316
    severity failure;
317
  assert value'length<=32
318
    report "readhex called with value'length > 32"
319
    severity failure;
320
 
321
  readwhite(L);
322
 
323
  ndig := 0;
324
  sum := (others=>'U');
325
 
326
  while L'length>0 loop
327
    ok := true;
328
    case L(L'left) is
329
      when '0'     => nibble := "0000";
330
      when '1'     => nibble := "0001";
331
      when '2'     => nibble := "0010";
332
      when '3'     => nibble := "0011";
333
      when '4'     => nibble := "0100";
334
      when '5'     => nibble := "0101";
335
      when '6'     => nibble := "0110";
336
      when '7'     => nibble := "0111";
337
      when '8'     => nibble := "1000";
338
      when '9'     => nibble := "1001";
339
      when 'a'|'A' => nibble := "1010";
340
      when 'b'|'B' => nibble := "1011";
341
      when 'c'|'C' => nibble := "1100";
342
      when 'd'|'D' => nibble := "1101";
343
      when 'e'|'E' => nibble := "1110";
344
      when 'f'|'F' => nibble := "1111";
345
      when 'u'|'U' => nibble := "UUUU";
346
      when 'x'|'X' => nibble := "XXXX";
347
      when 'z'|'Z' => nibble := "ZZZZ";
348
      when '-'     => nibble := "----";
349
      when others  => ok := false;
350
    end case;
351
 
352
    exit when not ok;
353
    read(L,ichar);
354
    ndig := ndig + 1;
355
    sum(sum'left downto 4) := sum(sum'left-4 downto 0);
356
    sum(3 downto 0) := nibble;
357
  end loop;
358
 
359
  ok := ndig>0;
360
  value := sum(value'range);
361
  good := ok;
362
 
363
end procedure readhex;
364
 
365
-- -------------------------------------
366
 
367
procedure readgen(                    -- read slv generic base
368
  L: inout line;            -- line
369
  value: out std_logic_vector;  -- value to be read
370
  good: out boolean;            -- success flag
371
  base: in integer := 2) is     -- default base
372
 
373
  variable nibble : std_logic_vector(3 downto 0);
374
  variable sum : std_logic_vector(31 downto 0);
375
  variable lbase : integer;           -- local base
376
  variable cbase : integer;           -- current base
377
  variable ok : boolean;
378
  variable ivalue : integer;
379
  variable ichar : character;
380
 
381
begin
382
 
383
  assert not value'ascending(1)
384
    report "readgen called with ascending range"
385
    severity failure;
386
  assert value'length<=32
387
    report "readgen called with value'length > 32"
388
    severity failure;
389
  assert base=2 or base=8 or base=10 or base=16
390
    report "readgen base not 2,8,10, or 16"
391
    severity failure;
392
 
393
  readwhite(L);
394
 
395
  cbase := base;
396
  lbase := 0;
397
  ok := true;
398
 
399
  if L'length >= 2 then
400
    if L(L'left+1) = '"' then
401
      case L(L'left) is
402
        when 'b'|'B' => lbase :=  2;
403
        when 'o'|'O' => lbase :=  8;
404
        when 'd'|'D' => lbase := 10;
405
        when 'x'|'X' => lbase := 16;
406
        when others => ok := false;
407
      end case;
408
    end if;
409
    if lbase /= 0 then
410
      read(L, ichar);
411
      read(L, ichar);
412
      cbase := lbase;
413
    end if;
414
  end if;
415
 
416
  if ok then
417
    case cbase is
418
      when  2 => read(L, value, ok);
419
      when  8 => readoct(L, value, ok);
420
      when 16 => readhex(L, value, ok);
421
      when 10 =>
422
        read(L, ivalue, ok);
423
        value := conv_std_logic_vector(ivalue, value'length);
424
      when others => null;
425
    end case;
426
  end if;
427
 
428
  if ok and lbase/=0 then
429
    if L'length>0 and  L(L'left)='"' then
430
      read(L, ichar);
431
    else
432
      ok := false;
433
    end if;
434
  end if;
435
 
436
  good := ok;
437
 
438
end procedure readgen;
439
 
440
-- -------------------------------------
441
 
442
procedure readcomment(
443
  L: inout line;
444
  good: out boolean) is
445
  variable ichar : character;
446
begin
447
 
448
  readwhite(L);
449
 
450
  good := true;
451
  if L'length > 0 then
452
    good := false;
453
    if L(L'left) = '#' then
454
      good := true;
455
    elsif L(L'left) = 'C' then
456
      good := true;
457
      writeline(output, L);
458
    end if;
459
  end if;
460
 
461
end procedure readcomment;
462
 
463
-- -------------------------------------
464
 
465
procedure readcommand(
466
  L: inout line;
467
  name: out string;
468
  good: out boolean) is
469
begin
470
 
471
  for i in name'range loop
472
    name(i) := ' ';
473
  end loop;
474
  good := false;
475
 
476
  if L'length>0 and L(L'left)='.' then
477
    readword(L, name, good);
478
  end if;
479
 
480
end procedure readcommand;
481
 
482
-- -------------------------------------
483
 
484
procedure readword(
485
  L: inout line;
486
  name: out string;
487
  good: out boolean) is
488
 
489
  variable ichar : character;
490
  variable ind : integer;
491
 
492
begin
493
 
494
  assert name'ascending(1)
495
    report "readword called with descending range for name"
496
    severity failure;
497
 
498
  readwhite(L);
499
 
500
  for i in name'range loop
501
    name(i) := ' ';
502
  end loop;
503
  ind := name'left;
504
 
505
  while L'length>0 and ind<=name'right loop
506
    ichar := L(L'left);
507
    exit when ichar=' ' or ichar=',' or ichar='|';
508
    read(L,ichar);
509
    name(ind) := ichar;
510
    ind := ind + 1;
511
  end loop;
512
 
513
  good := ind /= name'left;             -- ok if one non-blank found
514
 
515
end procedure readword;
516
 
517
-- -------------------------------------
518
 
519
procedure readoptchar(
520
  L: inout line;
521
  char: in character;
522
  good: out boolean) is
523
 
524
  variable ichar : character;
525
 
526
begin
527
 
528
  good := false;
529
  if L'length > 0 then
530
    if L(L'left) = char then
531
      read(L, ichar);
532
      good := true;
533
    end if;
534
  end if;
535
 
536
end procedure readoptchar;
537
 
538
-- -------------------------------------
539
 
540
procedure readempty(
541
  L: inout line) is
542
 
543
  variable ch : character;
544
 
545
begin
546
 
547
  while L'length>0 loop               -- anything left ?
548
    read(L,ch);                         -- read and discard it
549
  end loop;
550
 
551
end procedure readempty;
552
 
553
-- -------------------------------------
554
 
555
procedure testempty(
556
  L: inout line;
557
  good: out boolean) is
558
 
559
begin
560
 
561
  readwhite(L);                       -- discard white space
562
  good := true;                       -- good if now empty
563
 
564
  if L'length > 0 then                -- anything left ?
565
    good := false;                    -- assume bad
566
    if L'length >= 2 and              -- check for "--"
567
      L(L'left)='-' and L(L'left+1)='-' then
568
      good := true;                   -- in that case comment -> good
569
    end if;
570
  end if;
571
 
572
end procedure testempty;
573
 
574
-- -------------------------------------
575
 
576
procedure testempty_ea(
577
  L: inout line) is
578
 
579
  variable ok : boolean := false;
580
 
581
begin
582
 
583
  testempty(L, ok);
584
  assert ok report "extra chars in """ & L.all & """" severity failure;
585
 
586
end procedure testempty_ea;
587
 
588
-- -------------------------------------
589
 
590
procedure read_ea(
591
  L: inout line;
592
  value: out integer) is
593
 
594
  variable ok : boolean := false;
595
 
596
begin
597
 
598
  read(L, value, ok);
599
  assert ok report "read(integer) conversion error in """ &
600
                   L.all & """" severity failure;
601
 
602
end procedure read_ea;
603
 
604
-- -------------------------------------
605
 
606
procedure read_ea(
607
  L: inout line;
608
  value: out time) is
609
 
610
  variable ok : boolean := false;
611
 
612
begin
613
 
614
  read(L, value, ok);
615
  assert ok report "read(time) conversion error in """ &
616
                   L.all & """" severity failure;
617
 
618
end procedure read_ea;
619
 
620
-- -------------------------------------
621
 
622
procedure read_ea(
623
  L: inout line;
624
  value: out std_logic) is
625
 
626
  variable ok : boolean := false;
627
 
628
begin
629
 
630
  read(L, value, ok);
631
  assert ok report "read(std_logic) conversion error in """ &
632
                   L.all & """" severity failure;
633
 
634
end procedure read_ea;
635
 
636
-- -------------------------------------
637
 
638
procedure read_ea(
639
  L: inout line;
640
  value: out std_logic_vector) is
641
 
642
  variable ok : boolean := false;
643
 
644
begin
645
 
646
  read(L, value, ok);
647
  assert ok report "read(std_logic_vector) conversion error in """ &
648
                   L.all & """" severity failure;
649
 
650
end procedure read_ea;
651
 
652
-- -------------------------------------
653
 
654
procedure readoct_ea(
655
  L: inout line;
656
  value: out std_logic_vector) is
657
 
658
  variable ok : boolean := false;
659
 
660
begin
661
 
662
  readoct(L, value, ok);
663
  assert ok report "readoct() conversion error in """ &
664
                   L.all & """" severity failure;
665
 
666
end procedure readoct_ea;
667
 
668
-- -------------------------------------
669
 
670
procedure readhex_ea(
671
  L: inout line;
672
  value: out std_logic_vector) is
673
 
674
  variable ok : boolean := false;
675
 
676
begin
677
 
678
  readhex(L, value, ok);
679
  assert ok report "readhex() conversion error in """ &
680
                   L.all & """" severity failure;
681
 
682
end procedure readhex_ea;
683
 
684
-- -------------------------------------
685
 
686
procedure readgen_ea(
687
  L: inout line;
688
  value: out std_logic_vector;
689
  base: in integer := 2) is
690
 
691
  variable ok : boolean := false;
692
 
693
begin
694
 
695
  readgen(L, value, ok, base);
696
  assert ok report "readgen() conversion error in """ &
697
                   L.all & """" severity failure;
698
 
699
end procedure readgen_ea;
700
 
701
-- -------------------------------------
702
 
703
procedure readword_ea(
704
  L: inout line;
705
  name: out string) is
706
 
707
  variable ok : boolean := false;
708
 
709
begin
710
 
711
  readword(L, name, ok);
712
  assert ok report "readword() read error in """ &
713
                   L.all & """" severity failure;
714
 
715
end procedure readword_ea;
716
 
717
-- -------------------------------------
718
 
719
procedure readtagval(
720
  L: inout line;
721
  tag: in string;
722
  match: out boolean;
723
  val: out std_logic_vector;
724
  good: out boolean;
725
  base: in integer:= 2) is
726
 
727
  variable itag : string(tag'range);
728
  variable ichar : character;
729
  variable imatch : boolean;
730
 
731
begin
732
 
733
  readwhite(L);
734
 
735
  for i in val'range loop
736
    val(i) := '0';
737
  end loop;
738
  good := true;
739
  imatch := false;
740
 
741
  if L'length > tag'length then
742
    imatch := L(L'left to L'left+tag'length-1) = tag and
743
              L(L'left+tag'length) = '=';
744
    if imatch then
745
      read(L, itag);
746
      read(L, ichar);
747
      readgen(L, val, good, base);
748
    end if;
749
  end if;
750
  match := imatch;
751
 
752
end procedure readtagval;
753
 
754
-- -------------------------------------
755
 
756
procedure readtagval_ea(
757
  L: inout line;
758
  tag: in string;
759
  match: out boolean;
760
  val: out std_logic_vector;
761
  base: in integer:= 2) is
762
 
763
  variable ok : boolean := false;
764
 
765
begin
766
  readtagval(L, tag, match, val, ok, base);
767
  assert ok report "readtagval(std_logic_vector) conversion error in """ &
768
                   L.all & """" severity failure;
769
end procedure readtagval_ea;
770
 
771
-- -------------------------------------
772
 
773
procedure readtagval(
774
  L: inout line;
775
  tag: in string;
776
  match: out boolean;
777
  val: out std_logic;
778
  good: out boolean) is
779
 
780
  variable itag : string(tag'range);
781
  variable ichar : character;
782
  variable imatch : boolean;
783
 
784
begin
785
 
786
  readwhite(L);
787
 
788
  val := '0';
789
  good := true;
790
  imatch := false;
791
 
792
  if L'length > tag'length then
793
    imatch := L(L'left to L'left+tag'length-1) = tag and
794
              L(L'left+tag'length) = '=';
795
    if imatch then
796
      read(L, itag);
797
      read(L, ichar);
798
      read(L, val, good);
799
    end if;
800
  end if;
801
  match := imatch;
802
 
803
end procedure readtagval;
804
 
805
-- -------------------------------------
806
 
807
procedure readtagval_ea(
808
  L: inout line;
809
  tag: in string;
810
  match: out boolean;
811
  val: out std_logic) is
812
 
813
  variable ok : boolean := false;
814
 
815
begin
816
  readtagval(L, tag, match, val, ok);
817
  assert ok report "readtagval(std_logic) conversion error in """ &
818
                   L.all & """" severity failure;
819
end procedure readtagval_ea;
820
 
821
-- -------------------------------------
822
 
823
procedure readtagval2(
824
  L: inout line;
825
  tag: in string;
826
  match: out boolean;
827
  val1: out std_logic_vector;
828
  val2: out std_logic_vector;
829
  good: out boolean;
830
  base: in integer:= 2) is
831
 
832
  variable itag : string(tag'range);
833
  variable imatch : boolean;
834
  variable igood : boolean;
835
  variable ichar : character;
836
  variable ok : boolean;
837
 
838
begin
839
 
840
  readwhite(L);
841
 
842
  for i in val1'range loop            -- zero val1
843
    val1(i) := '0';
844
  end loop;
845
  for i in val2'range loop            -- zero val2
846
    val2(i) := '0';
847
  end loop;
848
  igood := true;
849
  imatch := false;
850
 
851
  if L'length > tag'length then       -- check for tag
852
    imatch := L(L'left to L'left+tag'length-1) = tag and
853
              L(L'left+tag'length) = '=';
854
 
855
    if imatch then                      -- if found
856
      read(L, itag);                    -- remove tag
857
      read(L, ichar);                   -- remove =
858
 
859
      igood := false;
860
      readoptchar(L, '-', ok);          -- check for tag=-
861
      if ok then
862
        for i in val2'range loop        -- set mask to all 1 (ignore)
863
          val2(i) := '1';
864
        end loop;
865
        igood := true;
866
      else                              -- here if tag=bit[,bit]
867
        readgen(L, val1, igood, base);  -- read val1
868
        if igood then
869
          readoptchar(L, ',', ok);      -- check(and remove) ,
870
          if ok then
871
            readgen(L, val2, igood, base); -- and read val2
872
          end if;
873
        end if;
874
      end if;
875
    end if;
876
  end if;
877
 
878
  match := imatch;
879
  good := igood;
880
 
881
end procedure readtagval2;
882
 
883
-- -------------------------------------
884
 
885
procedure readtagval2_ea(
886
  L: inout line;
887
  tag: in string;
888
  match: out boolean;
889
  val1: out std_logic_vector;
890
  val2: out std_logic_vector;
891
  base: in integer:= 2) is
892
 
893
  variable ok : boolean := false;
894
 
895
begin
896
  readtagval2(L, tag, match, val1, val2, ok, base);
897
  assert ok report "readtagval2() conversion error in """ &
898
                   L.all & """" severity failure;
899
end procedure readtagval2_ea;
900
 
901
-- -------------------------------------
902
 
903
procedure writeoct(                     -- write slv in octal base (arb. length)
904
  L: inout line;                        -- line
905
  value: in std_logic_vector;           -- value to be written
906
  justified: in side:=right;            -- justification (left/right)
907
  field: in width:=0) is                -- field width
908
 
909
  variable nbit : integer;              -- number of bits
910
  variable ndig : integer;              -- number of digits
911
  variable iwidth : integer;
912
  variable ioffset : integer;
913
  variable nibble : std_logic_vector(2 downto 0);
914
  variable ochar : character;
915
 
916
begin
917
 
918
  assert not value'ascending(1)
919
    report "writeoct called with ascending range"
920
    severity failure;
921
 
922
  nbit := value'length(1);
923
  ndig := (nbit+2)/3;
924
  iwidth := nbit mod 3;
925
  if iwidth = 0 then
926
    iwidth := 3;
927
  end if;
928
  ioffset := value'left(1) - iwidth+1;
929
  if justified=right and field>ndig then
930
    for i in ndig+1 to field loop
931
      write(L,' ');
932
    end loop;  -- i
933
  end if;
934
  for i in 0 to ndig-1 loop
935
    nibble := "000";
936
    nibble(iwidth-1 downto 0) := value(ioffset+iwidth-1 downto ioffset);
937
    ochar := ' ';
938
    for i in nibble'range loop
939
      case nibble(i) is
940
        when 'U' => ochar := 'U';
941
        when 'X' => ochar := 'X';
942
        when 'Z' => ochar := 'Z';
943
        when '-' => ochar := '-';
944
        when others => null;
945
      end case;
946
    end loop;  -- i
947
    if ochar = ' ' then
948
      write(L,conv_integer(unsigned(nibble)));
949
    else
950
      write(L,ochar);
951
    end if;
952
    iwidth := 3;
953
    ioffset := ioffset - 3;
954
  end loop;  -- i
955
  if justified=left and field>ndig then
956
    for i in ndig+1 to field loop
957
      write(L,' ');
958
    end loop;  -- i
959
  end if;
960
end procedure writeoct;
961
 
962
-- -------------------------------------
963
 
964
procedure writehex(                     -- write slv in hex base (arb. length)
965
  L: inout line;                        -- line
966
  value: in std_logic_vector;           -- value to be written
967
  justified: in side:=right;            -- justification (left/right)
968
  field: in width:=0) is                -- field width
969
 
970
  variable nbit : integer;              -- number of bits
971
  variable ndig : integer;              -- number of digits
972
  variable iwidth : integer;
973
  variable ioffset : integer;
974
  variable nibble : std_logic_vector(3 downto 0);
975
  variable ochar : character;
976
  variable hextab : string(1 to 16) := "0123456789abcdef";
977
 
978
begin
979
 
980
  assert not value'ascending(1)
981
    report "writehex called with ascending range"
982
    severity failure;
983
 
984
  nbit := value'length(1);
985
  ndig := (nbit+3)/4;
986
  iwidth := nbit mod 4;
987
  if iwidth = 0 then
988
    iwidth := 4;
989
  end if;
990
  ioffset := value'left(1) - iwidth+1;
991
  if justified=right and field>ndig then
992
    for i in ndig+1 to field loop
993
      write(L,' ');
994
    end loop;  -- i
995
  end if;
996
  for i in 0 to ndig-1 loop
997
    nibble := "0000";
998
    nibble(iwidth-1 downto 0) := value(ioffset+iwidth-1 downto ioffset);
999
    ochar := ' ';
1000
    for i in nibble'range loop
1001
      case nibble(i) is
1002
        when 'U' => ochar := 'U';
1003
        when 'X' => ochar := 'X';
1004
        when 'Z' => ochar := 'Z';
1005
        when '-' => ochar := '-';
1006
        when others => null;
1007
      end case;
1008
    end loop;  -- i
1009
    if ochar = ' ' then
1010
      write(L,hextab(conv_integer(unsigned(nibble))+1));
1011
    else
1012
      write(L,ochar);
1013
    end if;
1014
    iwidth := 4;
1015
    ioffset := ioffset - 4;
1016
  end loop;  -- i
1017
  if justified=left and field>ndig then
1018
    for i in ndig+1 to field loop
1019
      write(L,' ');
1020
    end loop;  -- i
1021
  end if;
1022
end procedure writehex;
1023
 
1024
-- -------------------------------------
1025
 
1026
procedure writegen(                     -- write slv in generic base (arb. lth)
1027
  L: inout line;                        -- line
1028
  value: in std_logic_vector;           -- value to be written
1029
  justified: in side:=right;            -- justification (left/right)
1030
  field: in width:=0;                   -- field width
1031
  base: in integer:=2) is               -- default base
1032
 
1033
begin
1034
 
1035
  case base is
1036
    when  2 => write(L, value, justified, field);
1037
    when  8 => writeoct(L, value, justified, field);
1038
    when 16 => writehex(L, value, justified, field);
1039
    when others => report "writegen base not 2,8, or 16"
1040
                     severity failure;
1041
  end case;
1042
 
1043
end procedure writegen;
1044
 
1045
-- -------------------------------------
1046
 
1047
procedure writetimestamp(
1048
  L: inout line;
1049
  clkcyc: in slv31;
1050
  str: in string := null_string) is
1051
 
1052
begin
1053
 
1054
  write(L, now, right, 12);
1055
  write(L, conv_integer(unsigned(clkcyc)), right, 7);
1056
  if str /= null_string then
1057
    write(L, str);
1058
  end if;
1059
 
1060
end procedure writetimestamp;
1061
 
1062
end package body simlib;
1063
 

powered by: WebSVN 2.1.0

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