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
|
-- Renaming to avoid use of keywords.
-- Copyright (C) 2022 Tristan Gingold
--
-- This file is part of GHDL.
--
-- 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 Name_Table;
with Std_Names;
with Netlists.Gates; use Netlists.Gates;
with Netlists.Utils; use Netlists.Utils;
package body Netlists.Rename is
function Rename_Sname (Name : Sname; Lang : Language_Type) return Sname
is
use Name_Table;
use Std_Names;
Id : Name_Id;
Res : String (1 .. 12);
Len : Positive;
begin
-- Only user names can clash.
if Get_Sname_Kind (Name) /= Sname_User then
return Name;
end if;
-- If prefixed, it cannot clash with a reserved identifier.
if Get_Sname_Prefix (Name) /= No_Sname then
return Name;
end if;
Id := Get_Sname_Suffix (Name);
pragma Assert (Lang = Language_Verilog);
case Id is
when Name_First_Verilog .. Name_Last_V2001 =>
null;
when Name_Xnor
| Name_Nor
| Name_Nand
| Name_Xor
| Name_Or
| Name_And
| Name_Begin
| Name_Case
| Name_Else
| Name_End
| Name_For
| Name_Function
| Name_If
| Name_Inout
| Name_Not
| Name_While
| Name_Wait =>
null;
when others =>
-- Not a keyword
return Name;
end case;
Len := Get_Name_Length (Id);
Res (2 .. Len + 1) := Image (Id);
Res (1) := '\';
Res (Len + 2) := ' ';
Id := Get_Identifier (Res (1 .. Len + 2));
return New_Sname_User (Id, No_Sname);
end Rename_Sname;
procedure Rename_User_Module (M : Module; Lang : Language_Type)
is
Port : Port_Desc;
Inst : Instance;
begin
-- Rename inputs and outputs.
for I in 1 .. Get_Nbr_Inputs (M) loop
Port := Get_Input_Desc (M, I - 1);
Port.Name := Rename_Sname (Port.Name, Lang);
Set_Input_Desc (M, I - 1, Port);
end loop;
for I in 1 .. Get_Nbr_Outputs (M) loop
Port := Get_Output_Desc (M, I - 1);
Port.Name := Rename_Sname (Port.Name, Lang);
Set_Output_Desc (M, I - 1, Port);
end loop;
-- Rename some instances.
Inst := Get_First_Instance (M);
while Inst /= No_Instance loop
case Get_Id (Inst) is
when Id_Signal
| Id_Isignal =>
Set_Instance_Name
(Inst, Rename_Sname (Get_Instance_Name (Inst), Lang));
when others =>
null;
end case;
Inst := Get_Next_Instance (Inst);
end loop;
-- rename module name ?
-- rename parameters ?
end Rename_User_Module;
procedure Rename_Module (M : Module; Lang : Language_Type)
is
Sm : Module;
begin
Sm := Get_First_Sub_Module (M);
while Sm /= No_Module loop
if Get_Id (Sm) >= Id_User_None then
Rename_User_Module (Sm, Lang);
end if;
Sm := Get_Next_Sub_Module (Sm);
end loop;
end Rename_Module;
end Netlists.Rename;
|