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

Subversion Repositories sv_dir_tb

[/] [sv_dir_tb/] [trunk/] [sv/] [tb_cmd.sv] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sckoarn
////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2014  Ken Campbell
4
//
5
//   Licensed under the Apache License, Version 2.0 (the "License");
6
//   you may not use this file except in compliance with the License.
7
//   You may obtain a copy of the License at
8
//
9
//     http://www.apache.org/licenses/LICENSE-2.0
10
//
11
//   Unless required by applicable law or agreed to in writing, software
12
//   distributed under the License is distributed on an "AS IS" BASIS,
13
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
//   See the License for the specific language governing permissions and
15
//   limitations under the License.
16
//
17
/////////////////////////////////////
18
 
19
  ////////////////////////////////////
20
  //  command  class
21
  typedef class tb_cmd;
22
class tb_cmd;
23
  integer idx;         // the index in the list
24
  integer valid_fld;   // number of valid fields
25
  string  cmd;         // instruction text
26
  string  var1;        // variable field one
27
  string  var2;
28
  string  var3;
29
  string  var4;
30
  string  var5;
31
  string  var6;
32
  string  cmd_str;      // any Dynamic text
33
 
34
  integer line_num;     // file line number
35
  integer file_idx;     // index of file name
36
 
37
  tb_cmd  next;         // ref to next command
38
  tb_cmd  prev;         // ref to prev command
39
 
40
  // prototypes
41
  //  function to parse string into fields.
42
  extern function tb_cmd parse_cmd(string str);
43
  //  function print this data.
44
  extern function void print();
45
  extern function new();
46
 
47
endclass // tb_cmd
48
 
49
///  tb_cmd  methods
50
  //  new function   init members.
51
  function tb_cmd::new();
52
    idx = 0;
53
    valid_fld = 0;
54
    cmd = "";
55
    var1 = "";
56
    var2 = "";
57
    var3 = "";
58
    var4 = "";
59
    var5 = "";
60
    var6 = "";
61
    cmd_str = "";
62
    line_num = 0;
63
    file_idx = 0;
64
    next = null;
65
    prev = null;
66
  endfunction
67
 
68
  //  print function intended for debug and developent.
69
  function void tb_cmd::print();
70
    $display("***************");
71
    $display("idx is: %d", this.idx);
72
    $display("valid_fld is: %d", this.valid_fld);
73
    $display("cmd is: %s", this.cmd);
74
    $display("var1 is: %s", this.var1);
75
    $display("var2 is: %s", this.var2);
76
    $display("var3 is: %s", this.var3);
77
    $display("var4 is: %s", this.var4);
78
    $display("var5 is: %s", this.var5);
79
    $display("var6 is: %s", this.var6);
80
    $display("cmd_str is: %s", this.cmd_str);
81
    $display("line_num is: %d", this.line_num);
82
    $display("file_idx is: %d", this.file_idx);
83
  endfunction
84
 
85
  ///////////
86
  //  function parse_cmd
87
  function tb_cmd tb_cmd::parse_cmd(string str);
88
    byte c = 0;
89
    byte c1 = 0;
90
    integer  err = 0;
91
    integer  length;
92
    integer  len;
93
    integer  idx = 0;
94
    integer  i;
95
    integer  tidx;
96
    integer  nonw;
97
    integer  gotd;
98
    string   tmp_str;
99
    string   sub_str;
100
    string   com_chars;
101
    string   dummy;
102
    integer  done = 0;
103
    integer  ds_start = 1000;
104
    integer  cs_start = 0;
105
    integer  ds_found = 0;
106
    integer  cs_found = 0;
107
 
108
    //  get length of string could include new line
109
    length = str.len();
110
    tmp_str = str.substr(0,length-2);
111
    //  if there is a comment get the start location.
112
    //   then strip off the comment.
113
    idx = 0;
114
    while((tmp_str.substr(idx,idx+1) != "--") && (idx < length-1)) begin
115
      idx++;
116
    end
117
    if(idx != length) begin
118
      cs_start = idx;
119
      cs_found = 1;
120
      tmp_str  = tmp_str.substr(0, cs_start-1);
121
      length = tmp_str.len();
122
    end
123
    //   Look for dynamic text.
124
    // if there is a dynamic text string, locate its start
125
    idx = 0;
126
    while((tmp_str.getc(idx) != "\"") && (idx < length)) begin
127
      idx++;
128
    end
129
    if(idx < length) begin
130
      ds_start = idx+1;
131
      ds_found = 1;
132
      dummy = tmp_str.substr(ds_start, length-2);
133
    end
134
    this.valid_fld = 0;
135
    //  if this is a full line comment, zero valid fields
136
    if(cs_start == 0 && cs_found) begin
137
      this.valid_fld = 0;
138
    end else begin
139
      // if there was a dynamic string ...
140
      if(ds_found) begin
141
        sub_str = tmp_str.substr(0, ds_start-2);
142
        this.cmd_str = tmp_str.substr(ds_start, length-1);
143
      end else begin
144
        sub_str = tmp_str;
145
        this.cmd_str = "";
146
      end
147
      // now parse the string into fields.
148
      //  get the sub string length
149
      len = sub_str.len();
150
      dummy = "";
151
      tidx  = 0;
152
      idx   = 0;
153
      nonw  = 0;
154
      gotd  = 0;
155
 
156
      //  extract fields
157
      for (i = 0; i <= len; i++) begin
158
        if (is_ws(sub_str[i])) begin
159
          if (nonw) begin
160
            nonw = 0;
161
            gotd = 1;
162
          end else begin
163
            continue;
164
          end
165
        end else begin
166
          dummy  =  {dummy, sub_str[i]};
167
          nonw   =  1;
168
        end
169
        //  if we transitioned to white from char
170
        if (gotd == 1) begin
171
          case(tidx)
172
            0: this.cmd  = dummy;
173
            1: this.var1 = dummy;
174
            2: this.var2 = dummy;
175
            3: this.var3 = dummy;
176
            4: this.var4 = dummy;
177
            5: this.var5 = dummy;
178
            6: this.var6 = dummy;
179
            default: err = 1;
180
          endcase
181
          if(err == 0) begin
182
            tidx++;
183
            this.valid_fld++;
184
            gotd = 0;
185
            dummy = "";
186
          end else begin
187
            if(this.line_num != 0) begin
188
              $fatal(0,"ERROR: Found more than six parameters in line: %s\nAt line: %d", tmp_str, this.line_num);
189
            end
190
          end
191
        end
192
      end  // end for
193
      //  get any left overs
194
      if(dummy != "") begin
195
        case(tidx)
196
          0: this.cmd  = dummy;
197
          1: this.var1 = dummy;
198
          2: this.var2 = dummy;
199
          3: this.var3 = dummy;
200
          4: this.var4 = dummy;
201
          5: this.var5 = dummy;
202
          6: this.var6 = dummy;
203
          default: err = 1;
204
        endcase
205
        if(err == 0) begin
206
          this.valid_fld++;
207
        end else begin
208
          if(this.line_num != 0) begin
209
            $fatal(0,"ERROR: Found more than six parameters on line: %s\nAt line: %d", tmp_str, this.line_num);
210
          end
211
        end
212
      end
213
    end
214
 
215
    //this.print();
216
    return this;
217
  endfunction // parse_cmd
218
 

powered by: WebSVN 2.1.0

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