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 |
|
|
// general functions
|
19 |
|
|
//
|
20 |
|
|
// stm2_int: convert a simulus entry to integer.
|
21 |
|
|
// is_var: check for and return varable type.
|
22 |
|
|
// is_ws: check if character is white space.
|
23 |
|
|
// is_digi: Check if is decimal character
|
24 |
|
|
// is_alpha: Check if is alphabetic character, Limited.
|
25 |
|
|
//
|
26 |
|
|
/////////////////////////////////////////////////////////////////////////
|
27 |
|
|
// stimulus value convert functions
|
28 |
|
|
// to_int function to convert string to integer
|
29 |
|
|
function integer stm2_int(string str);
|
30 |
|
|
integer t, i, len, rtn;
|
31 |
|
|
string tmp_str;
|
32 |
|
|
|
33 |
|
|
i = 0;
|
34 |
|
|
t = str.getc(i);
|
35 |
|
|
if ((t == "x") || (t == "h")) begin
|
36 |
|
|
tmp_str = str.substr(1, str.len()-1);
|
37 |
|
|
rtn = tmp_str.atohex();
|
38 |
|
|
end else if (t == "b") begin
|
39 |
|
|
tmp_str = str.substr(1, str.len()-1);
|
40 |
|
|
rtn = tmp_str.atobin();
|
41 |
|
|
end else begin
|
42 |
|
|
rtn = str.atoi();
|
43 |
|
|
end
|
44 |
|
|
return rtn;
|
45 |
|
|
endfunction // stm2_int
|
46 |
|
|
|
47 |
|
|
//////////////////////////////////////////////////////////////////////
|
48 |
|
|
// is_var function
|
49 |
|
|
// check if the string passed is a variable definition "syntax" wise
|
50 |
|
|
// return 0 if not a variable def
|
51 |
|
|
// return 1 if defined as value
|
52 |
|
|
// return 2 if defined as index
|
53 |
|
|
// retrun 3 if condition operator
|
54 |
|
|
function int is_var(string v);
|
55 |
|
|
byte c;
|
56 |
|
|
c = v[0];
|
57 |
|
|
if(is_digi(c)) begin
|
58 |
|
|
return 0;
|
59 |
|
|
end else if(c == "$") begin
|
60 |
|
|
return 1;
|
61 |
|
|
end else if (c == "<" || c == ">" || c == "=" || c == "!") begin
|
62 |
|
|
return 3;
|
63 |
|
|
end else if (c != "x" && c != "h" && c != "b") begin
|
64 |
|
|
return 2;
|
65 |
|
|
end else
|
66 |
|
|
return 0;
|
67 |
|
|
endfunction
|
68 |
|
|
|
69 |
|
|
//////////////////////////////////////////////////////////////////////
|
70 |
|
|
// string functions
|
71 |
|
|
// check character for white space
|
72 |
|
|
// return 1 if is white, 0 other wise.
|
73 |
|
|
function int is_ws(byte c);
|
74 |
|
|
if (c == " " || c == "\t" || c == "\n")
|
75 |
|
|
return 1;
|
76 |
|
|
else
|
77 |
|
|
return 0;
|
78 |
|
|
endfunction // is_ws
|
79 |
|
|
//////////////////////////////////////////////////////////////////////
|
80 |
|
|
// check for decimal digit return 1 if is, else 0
|
81 |
|
|
function int is_digi(byte c);
|
82 |
|
|
if (c >= "0" && c <= "9")
|
83 |
|
|
return 1;
|
84 |
|
|
else
|
85 |
|
|
return 0;
|
86 |
|
|
endfunction
|
87 |
|
|
//////////////////////////////////////////////////////////////////////
|
88 |
|
|
// check for alpha character.
|
89 |
|
|
// includes [ \ ] ^ _ ` { \ } ~
|
90 |
|
|
// return 1 if is, else 0
|
91 |
|
|
function int is_alpha(byte c);
|
92 |
|
|
if(c >= "A" && c <= "~")
|
93 |
|
|
return 1;
|
94 |
|
|
else
|
95 |
|
|
return 0;
|
96 |
|
|
endfunction
|