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
|
import java.io.FileNotFoundException;
import java.io.IOException;
public class VHDLLevel
{
/* Utility Class */
private VHDLLevel () {}
public static boolean add_to_model
(
final VHDLModel m,
final String filename
)
throws FileNotFoundException
{
final QuickParser qp;
String[] input;
boolean success;
qp = new QuickParser(filename);
for (;;)
{
try
{
input = qp.parse_line();
if (input == null)
{
qp.finalize();
return false;
}
else if (input.length == 0)
{
qp.finalize();
break;
}
}
catch (final IOException e)
{
System.err.println
(
"[E] IO error while parsing file \""
+ filename
+ "\":"
/* FIXME: can be null */
+ e.getMessage()
);
return false;
}
if (input[0].equals("add_type"))
{
success = handle_add_type(input, m);
}
else if (input[0].equals("add_predicate"))
{
success = handle_add_predicate(input, m, false);
}
else if (input[0].equals("add_function"))
{
success = handle_add_predicate(input, m, true);
}
else
{
System.err.println
(
"[E] Unknown instruction type \""
+ input[0]
+ "\" in file \""
+ filename
+ "\"."
);
return false;
}
if (!success)
{
System.err.println
(
"[E] An erroneous instruction was found in file \""
+ filename
+ "\"."
);
try
{
qp.finalize();
}
catch (final Exception e)
{
System.err.println("[E] Additionally:");
e.printStackTrace();
}
return false;
}
}
return true;
}
private static boolean handle_add_type
(
final String[] cmd,
final VHDLModel m
)
{
if (cmd.length != 2)
{
System.err.println
(
"[E] Badly formed \"add_type\" instruction: \""
+ String.join(" ", cmd)
+ "\"."
);
return false;
}
m.add_type(cmd[1]);
return true;
}
private static boolean handle_add_predicate
(
final String[] cmd,
final VHDLModel m,
final boolean is_function
)
{
final String[] signature;
if (cmd.length < 2)
{
System.err.println
(
"[E] Badly formed \"add_predicate\" or \"add_function\""
+ " instruction: \""
+ String.join(" ", cmd)
+ "\"."
);
return false;
}
signature = new String[cmd.length - 2];
for (int i = 2; i < cmd.length; ++i)
{
signature[i - 2] = cmd[i];
}
return m.add_predicate(cmd[1], signature, is_function);
}
}
|