Skip to content

Commit f116113

Browse files
committed
UPDATE: json-creator.py
made the code not case-sensitive and made the connection adding, more permissive.
1 parent 9a5f2de commit f116113

File tree

1 file changed

+52
-21
lines changed

1 file changed

+52
-21
lines changed

src/json_creator/json-creator.py

+52-21
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ def add_connection(elements, connections, input_id, output_id, timing, input_por
1515
# Determine element types from the dictionaries
1616
print(input_io)
1717
print(output_io)
18-
if input_id in elements["LUTs"]:
18+
if input_id in elements["luts"]:
1919
input_type = "lut"
20-
elif input_id in elements["FlipFlops"]:
20+
elif input_id in elements["flipflops"]:
2121
input_type = "DFF"
2222
else:
23-
input_type = elements["IOs"].get(input_id, {}).get("name")
23+
input_type = elements["ios"].get(input_id, {}).get("name")
2424

25-
if output_id in elements["LUTs"]:
25+
if output_id in elements["luts"]:
2626
output_type = "lut"
27-
elif output_id in elements["FlipFlops"]:
27+
elif output_id in elements["flipflops"]:
2828
output_type = "DFF"
2929
else:
30-
output_type = elements["IOs"].get(output_id, {}).get("name")
30+
output_type = elements["ios"].get(output_id, {}).get("name")
3131
if input_type is None or output_type is None:
3232
print(f"Error: One of the elements ({input_id}, {output_id}) does not exist.")
3333
return
@@ -50,15 +50,16 @@ def add_connection(elements, connections, input_id, output_id, timing, input_por
5050
connections.append(connection)
5151

5252
def user_input():
53-
elements = {"LUTs": {}, "FlipFlops": {}, "IOs": {}}
53+
elements = {"luts": {}, "flipflops": {}, "ios": {}}
5454
connections = []
5555

5656
# Creating elements
5757
while True:
5858
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':
6061
break
61-
if element_type != "IO":
62+
if element_type != "io":
6263
while True:
6364
element_id = input("Enter element ID (numeric): ")
6465
if element_id.isdigit():
@@ -67,19 +68,19 @@ def user_input():
6768
print("Invalid input. Please enter a numeric ID.")
6869
key = element_id
6970
elements[element_type + "s"][key] = create_element(element_type, key)
70-
if element_type == "LUT":
71+
if element_type == "lut":
7172
# For LUTs, let the user add port definitions
7273
while True:
7374
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":
7576
break
7677
port_io = input("Enter port's io (input/output): ")
7778
port_id = input("Enter port id: ")
7879
elements[element_type + "s"][key]["connections"].append({
7980
"io": port_io,
8081
"id": port_id
8182
})
82-
elif element_type == "FlipFlop":
83+
elif element_type == "flipflop":
8384
# For FlipFlops, automatically add the three ports.
8485
elements[element_type + "s"][key]["connections"] = [
8586
{"port": "clock"},
@@ -89,7 +90,7 @@ def user_input():
8990
else:
9091
name = input("Enter name (for IO element): ")
9192
key = name
92-
elements["IOs"][key] = create_element("IO", key, name)
93+
elements["ios"][key] = create_element("IO", key, name)
9394

9495
# Adding global connections between elements
9596
while True:
@@ -98,29 +99,59 @@ def user_input():
9899
break
99100

100101
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)
102103

103104
# If the input element is a LUT or a DFF, prompt for its output port.
104105
input_port = "0"
105106
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.")
107115
input_port = input("Enter the port number for the LUT output: ")
108116
if input_port == "":
109117
input_port = "0"
110-
if input_id in elements["FlipFlops"]:
118+
if input_id in elements["flipflops"]:
111119
input_io = input("Enter the port number for the FlipFlop output: ")
112120
if input_io == "":
113121
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)
114132

115133
# If the output element is a LUT or a DFF, prompt for its input port.
116134
output_port = "0"
117135
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.")
119144
output_port = input("Enter the port number for the LUT input: ")
120145
if output_port == "":
121146
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.")
124155
output_io = input("Enter the port number for the FlipFlop input: ")
125156
if output_io == "":
126157
output_io = "0"
@@ -133,9 +164,9 @@ def user_input():
133164
add_connection(elements, connections, input_id, output_id, timing, input_port, output_port, input_io, output_io)
134165

135166
json_output = {
136-
"LUTs": list(elements["LUTs"].values()),
167+
"LUTs": list(elements["luts"].values()),
137168
"FlipFlops": list(elements["FlipFlops"].values()),
138-
"IOs": list(elements["IOs"].values()),
169+
"IOs": list(elements["ios"].values()),
139170
"Connections": connections
140171
}
141172

0 commit comments

Comments
 (0)