@@ -15,19 +15,19 @@ def add_connection(elements, connections, input_id, output_id, timing, input_por
15
15
# Determine element types from the dictionaries
16
16
print (input_io )
17
17
print (output_io )
18
- if input_id in elements ["LUTs " ]:
18
+ if input_id in elements ["luts " ]:
19
19
input_type = "lut"
20
- elif input_id in elements ["FlipFlops " ]:
20
+ elif input_id in elements ["flipflops " ]:
21
21
input_type = "DFF"
22
22
else :
23
- input_type = elements ["IOs " ].get (input_id , {}).get ("name" )
23
+ input_type = elements ["ios " ].get (input_id , {}).get ("name" )
24
24
25
- if output_id in elements ["LUTs " ]:
25
+ if output_id in elements ["luts " ]:
26
26
output_type = "lut"
27
- elif output_id in elements ["FlipFlops " ]:
27
+ elif output_id in elements ["flipflops " ]:
28
28
output_type = "DFF"
29
29
else :
30
- output_type = elements ["IOs " ].get (output_id , {}).get ("name" )
30
+ output_type = elements ["ios " ].get (output_id , {}).get ("name" )
31
31
if input_type is None or output_type is None :
32
32
print (f"Error: One of the elements ({ input_id } , { output_id } ) does not exist." )
33
33
return
@@ -50,15 +50,16 @@ def add_connection(elements, connections, input_id, output_id, timing, input_por
50
50
connections .append (connection )
51
51
52
52
def user_input ():
53
- elements = {"LUTs " : {}, "FlipFlops " : {}, "IOs " : {}}
53
+ elements = {"luts " : {}, "flipflops " : {}, "ios " : {}}
54
54
connections = []
55
55
56
56
# Creating elements
57
57
while True :
58
58
element_type = input ("Enter element type (LUT, FlipFlop, IO) or 'done' to finish: " )
59
- if element_type .lower () == 'done' :
59
+ element_type = element_type .lower ()
60
+ if element_type == 'done' :
60
61
break
61
- if element_type != "IO " :
62
+ if element_type != "io " :
62
63
while True :
63
64
element_id = input ("Enter element ID (numeric): " )
64
65
if element_id .isdigit ():
@@ -67,19 +68,19 @@ def user_input():
67
68
print ("Invalid input. Please enter a numeric ID." )
68
69
key = element_id
69
70
elements [element_type + "s" ][key ] = create_element (element_type , key )
70
- if element_type == "LUT " :
71
+ if element_type == "lut " :
71
72
# For LUTs, let the user add port definitions
72
73
while True :
73
74
add_port = input (f"Do you want to add a port for { element_type } with ID { element_id } ? (yes/no): " )
74
- if add_port . lower () != "yes" :
75
+ if add_port != "yes" :
75
76
break
76
77
port_io = input ("Enter port's io (input/output): " )
77
78
port_id = input ("Enter port id: " )
78
79
elements [element_type + "s" ][key ]["connections" ].append ({
79
80
"io" : port_io ,
80
81
"id" : port_id
81
82
})
82
- elif element_type == "FlipFlop " :
83
+ elif element_type == "flipflop " :
83
84
# For FlipFlops, automatically add the three ports.
84
85
elements [element_type + "s" ][key ]["connections" ] = [
85
86
{"port" : "clock" },
@@ -89,7 +90,7 @@ def user_input():
89
90
else :
90
91
name = input ("Enter name (for IO element): " )
91
92
key = name
92
- elements ["IOs " ][key ] = create_element ("IO" , key , name )
93
+ elements ["ios " ][key ] = create_element ("IO" , key , name )
93
94
94
95
# Adding global connections between elements
95
96
while True :
@@ -98,29 +99,59 @@ def user_input():
98
99
break
99
100
100
101
input_id = input ("Enter input element ID or IO name: " )
101
- output_id = input ( "Enter output element ID or IO name: " )
102
+ print ( input_id )
102
103
103
104
# If the input element is a LUT or a DFF, prompt for its output port.
104
105
input_port = "0"
105
106
input_io = "0"
106
- if input_id in elements ["LUTs" ]:
107
+ if input_id in elements ["luts" ]:
108
+ input_port = input ("Enter the port number for the LUT output: " )
109
+ if input_port == "" :
110
+ input_port = "0"
111
+ if input_id .lower ()== "lut" :
112
+ input_id = input ("Enter the id number for the LUT: " )
113
+ while input_id not in elements ["luts" ]:
114
+ input_id = input ("This id does not exist, please try again." )
107
115
input_port = input ("Enter the port number for the LUT output: " )
108
116
if input_port == "" :
109
117
input_port = "0"
110
- if input_id in elements ["FlipFlops " ]:
118
+ if input_id in elements ["flipflops " ]:
111
119
input_io = input ("Enter the port number for the FlipFlop output: " )
112
120
if input_io == "" :
113
121
input_io = "0"
122
+ if input_id .lower ()== "flipflop" :
123
+ input_id = input ("Enter the id number for the FlipFlop: " )
124
+ while input_id not in elements ["flipflops" ]:
125
+ input_id = input ("This id does not exist, please try again." )
126
+ input_io = input ("Enter the port number for the FlipFlop output: " )
127
+ if input_io == "" :
128
+ input_io = "0"
129
+
130
+ output_id = input ("Enter output element ID or IO name: " )
131
+ print (output_id )
114
132
115
133
# If the output element is a LUT or a DFF, prompt for its input port.
116
134
output_port = "0"
117
135
output_io = "0"
118
- if output_id in elements ["LUTs" ]:
136
+ if output_id in elements ["luts" ]:
137
+ output_port = input ("Enter the port number for the LUT input: " )
138
+ if output_port == "" :
139
+ output_port = "0"
140
+ if output_id .lower ()== "lut" :
141
+ output_id = input ("Enter the id number for the LUT: " )
142
+ while output_id not in elements ["luts" ]:
143
+ output_id = input ("This id does not exist, please try again." )
119
144
output_port = input ("Enter the port number for the LUT input: " )
120
145
if output_port == "" :
121
146
output_port = "0"
122
- if output_id in elements ["FlipFlops" ]:
123
- print ("test" )
147
+ if output_id in elements ["flipflops" ]:
148
+ output_io = input ("Enter the port number for the FlipFlop input: " )
149
+ if output_io == "" :
150
+ output_io = "0"
151
+ if output_id .lower ()== "flipflop" :
152
+ output_id = input ("Enter the id number for the FlipFlop: " )
153
+ while output_id not in elements ["flipflops" ]:
154
+ output_id = input ("This id does not exist, please try again." )
124
155
output_io = input ("Enter the port number for the FlipFlop input: " )
125
156
if output_io == "" :
126
157
output_io = "0"
@@ -133,9 +164,9 @@ def user_input():
133
164
add_connection (elements , connections , input_id , output_id , timing , input_port , output_port , input_io , output_io )
134
165
135
166
json_output = {
136
- "LUTs" : list (elements ["LUTs " ].values ()),
167
+ "LUTs" : list (elements ["luts " ].values ()),
137
168
"FlipFlops" : list (elements ["FlipFlops" ].values ()),
138
- "IOs" : list (elements ["IOs " ].values ()),
169
+ "IOs" : list (elements ["ios " ].values ()),
139
170
"Connections" : connections
140
171
}
141
172
0 commit comments