aboutsummaryrefslogtreecommitdiffstats
path: root/src/edif/edif-disp_edif.adb
blob: 05e48059c15a2aff5cc7c113321d93356c5a7a50 (plain)
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
--  EDIF printer.
--  Copyright (C) 2019 Tristan Gingold
--
--  This program is free software: you can redistribute it and/or modify
--  it under the terms of the GNU General Public License as published by
--  the Free Software Foundation, either version 2 of the License, or
--  (at your option) any later version.
--
--  This program is distributed in the hope that it will be useful,
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--  GNU General Public License for more details.
--
--  You should have received a copy of the GNU General Public License
--  along with this program.  If not, see <gnu.org/licenses>.

with Ada.Text_IO; use Ada.Text_IO;
with Types; use Types;
with Str_Table;
with Name_Table;

package body Edif.Disp_Edif is
   procedure Disp (N : Node; Indent : Natural);

   procedure Disp_Int32 (V : Int32)
   is
      S : constant String := Int32'Image (V);
   begin
      if S (1) = ' ' then
         Put (S (2 .. S'Last));
      else
         Put (S);
      end if;
   end Disp_Int32;

   procedure Disp_Symbol (S : Name_Id)
   is
      Img : constant String := Name_Table.Image (S);
   begin
      if Img (Img'First) not in 'a' .. 'z' then
         Put ('&');
      end if;
      Put (Img);
   end Disp_Symbol;

   procedure Disp_Indent (Indent : Natural) is
   begin
      Put ((1 .. 2 * Indent => ' '));
   end Disp_Indent;

   procedure Disp_Chain (Chain : Node; Indent : Natural)
   is
      N : Node;
   begin
      N := Chain;
      while N /= Null_Node loop
         Disp (N, Indent);
         N := Get_Chain (N);
      end loop;
   end Disp_Chain;

   procedure Disp_Keyword_Head (Name : String; Indent : Natural) is
   begin
      Disp_Indent (Indent);
      Put ('(');
      Put (Name);
      Put (' ');
   end Disp_Keyword_Head;

   procedure Disp_Keyword_Tail is
   begin
      Put (')');
      New_Line;
   end Disp_Keyword_Tail;

   procedure Disp_Keyword (Name : String; Arg : Int32; Indent : Natural) is
   begin
      Disp_Keyword_Head (Name, Indent);
      Disp_Int32 (Arg);
      Disp_Keyword_Tail;
   end Disp_Keyword;

   procedure Disp_Keyword (Name : String; Arg : Node; Indent : Natural) is
   begin
      Disp_Keyword_Head (Name, Indent);
      Disp (Arg, Indent + 1);
      Disp_Keyword_Tail;
   end Disp_Keyword;

   procedure Disp_Keyword (Name : String; Arg : Name_Id; Indent : Natural) is
   begin
      Disp_Keyword_Head (Name, Indent);
      Disp_Symbol (Arg);
      Disp_Keyword_Tail;
   end Disp_Keyword;

   procedure Disp_Decl_Head (Name : String; N : Node; Indent : Natural) is
   begin
      Disp_Keyword_Head (Name, Indent);
      Disp (Get_Name (N), Indent);
      New_Line;
   end Disp_Decl_Head;

   procedure Disp_Decl_Tail (Indent : Natural) is
   begin
      Disp_Indent (Indent);
      Disp_Keyword_Tail;
   end Disp_Decl_Tail;

   procedure Disp_Opt (N : Node; Indent : Natural) is
   begin
      if N /= Null_Node then
         Disp (N, Indent);
      end if;
   end Disp_Opt;

   procedure Disp (N : Node; Indent : Natural) is
   begin
      if N = Null_Node then
         Put ("()");
         return;
      end if;

      case Get_Kind (N) is
         when N_Keyword =>
            declare
               El : Node;
            begin
               New_Line;
               Disp_Indent (Indent);
               Put ('(');
               Put (Name_Table.Image (Get_Keyword (N)));
               El := Get_CDR (N);
               while El /= Null_Node loop
                  Put (' ');
                  Disp (Get_CAR (El), Indent + 1);
                  El := Get_CDR (El);
               end loop;
               Put (')');
            end;

         when N_Symbol =>
            Disp_Symbol (Get_Symbol (N));

         when N_Number =>
            Disp_Int32 (Get_Number (N));

         when N_String =>
            Put ('"');
            Put (Str_Table.String_String8
                   (Get_String_Id (N), Nat32 (Get_String_Len (N))));
            Put ('"');

         when N_Edif =>
            Disp_Decl_Head ("edif", N, Indent);
            Disp_Keyword ("edifversion", Get_Edif_Version (N), Indent + 1);
            Disp_Keyword ("ediflevel", Get_Edif_Level (N), Indent + 1);
            Disp_Keyword ("keywordmap", Get_Keyword_Map (N), Indent + 1);
            Disp_Keyword ("status", Get_Status (N), Indent + 1);
            Disp_Chain (Get_External_Chain (N), Indent + 1);
            Disp_Chain (Get_Library_Chain (N), Indent + 1);
            Disp (Get_Design (N), Indent + 1);
            Disp_Decl_Tail (Indent);

         when N_Library =>
            Disp_Decl_Head ("library", N, Indent);
            Disp_Keyword ("ediflevel", Get_Edif_Level (N), Indent + 1);
            Disp_Keyword ("technology", Get_Technology (N), Indent + 1);
            Disp_Chain (Get_Cells_Chain (N), Indent + 1);
            Disp_Decl_Tail (Indent);

         when N_External =>
            Disp_Decl_Head ("external", N, Indent);
            Disp_Keyword ("ediflevel", Get_Edif_Level (N), Indent + 1);
            Disp_Keyword ("technology", Get_Technology (N), Indent + 1);
            Disp_Chain (Get_Cells_Chain (N), Indent + 1);
            Disp_Decl_Tail (Indent);

         when N_Cell =>
            Disp_Decl_Head ("cell", N, Indent);
            Disp_Keyword ("celltype", Get_Cell_Type (N), Indent + 1);
            Disp (Get_View (N), Indent + 1);
            Disp_Decl_Tail (Indent);

         when N_View =>
            Disp_Decl_Head ("view", N, Indent);
            Disp_Keyword ("viewtype", Get_View_Type (N), Indent + 1);
            Disp (Get_Interface (N), Indent + 1);
            declare
               Contents : constant Node := Get_Contents_Chain (N);
            begin
               if Contents /= Null_Node then
                  Disp_Keyword_Head ("contents", Indent + 1);
                  New_Line;
                  Disp_Chain (Contents, Indent + 2);
                  Disp_Indent (Indent + 1);
                  Disp_Keyword_Tail;
               end if;
            end;
            Disp_Decl_Tail (Indent);

         when N_Interface =>
            Disp_Keyword_Head ("interface", Indent);
            New_Line;
            Disp_Chain (Get_Ports_Chain (N), Indent + 1);
            Disp_Chain (Get_Properties_Chain (N), Indent + 1);
            Disp_Indent (Indent);
            Disp_Keyword_Tail;

         when N_Port =>
            Disp_Decl_Head ("port", N, Indent);
            Disp_Keyword_Head ("direction", Indent + 1);
            case Get_Direction (N) is
               when Dir_Input =>
                  Put ("input");
               when Dir_Output =>
                  Put ("output");
               when Dir_Inout =>
                  Put ("inout");
            end case;
            Disp_Keyword_Tail;
            Disp_Decl_Tail (Indent);

         when N_Rename =>
            Put ("(rename ");
            Disp (Get_Name (N), Indent);
            Put (' ');
            Disp (Get_String (N), Indent);
            Put (')');

         when N_Member =>
            Put ("(member ");
            Disp (Get_Name (N), Indent);
            Put (' ');
            Disp_Int32 (Get_Index (N));
            Put (')');

         when N_Array =>
            Put ("(array ");
            Disp (Get_Name (N), Indent);
            Put (' ');
            Disp_Int32 (Get_Array_Length (N));
            Put (')');

         when N_Instance =>
            Disp_Decl_Head ("instance", N, Indent);
            Disp (Get_Instance_Ref (N), Indent + 1);
            Disp_Chain (Get_Port_Instances_Chain (N), Indent + 1);
            Disp_Chain (Get_Properties_Chain (N), Indent + 1);
            Disp_Decl_Tail (Indent);

         when N_Net =>
            Disp_Decl_Head ("net", N, Indent);
            Disp_Chain (Get_Joined_Chain (N), Indent + 1);
            Disp_Decl_Tail (Indent);

         when N_View_Ref =>
            Disp_Decl_Head ("viewref", N, Indent);
            Disp (Get_Cell_Ref (N), Indent + 1);
            Disp_Decl_Tail (Indent);

         when N_Cell_Ref =>
            Disp_Keyword_Head ("cellref", Indent);
            Disp (Get_Name (N), Indent);
            Disp_Opt (Get_Library_Ref (N), Indent + 1);
            Disp_Keyword_Tail;

         when N_Port_Ref =>
            Disp_Keyword_Head ("portref", Indent);
            Disp (Get_Port (N), Indent);
            Disp_Opt (Get_Instance_Ref (N), Indent + 1);
            Disp_Keyword_Tail;

         when N_Property =>
            Disp_Keyword_Head ("property", Indent);
            Disp (Get_Name (N), Indent);
            Put (' ');
            Disp (Get_Value (N), Indent);
            Disp_Keyword_Tail;

         when N_Port_Instance =>
            Disp_Decl_Head ("portinstance", N, Indent);
            Disp_Chain (Get_Properties_Chain (N), Indent + 1);
            Disp_Decl_Tail (Indent);

         when N_Design =>
            Disp_Decl_Head ("design", N, Indent);
            Disp (Get_Cell_Ref (N), Indent + 1);
            Disp_Chain (Get_Properties_Chain (N), Indent + 1);
            Disp_Decl_Tail (Indent);

         when N_Boolean =>
            if Get_Boolean (N) then
               Put ("(true)");
            else
               Put ("(false)");
            end if;

         when others =>
            Put ("??? " & Nkind'Image (Get_Kind (N)));
      end case;
   end Disp;

   procedure Disp_Node (N : Node) is
   begin
      Disp (N, 0);
   end Disp_Node;
end Edif.Disp_Edif;