From 70f571ea428b247ab5f951b6735c55c0eade0612 Mon Sep 17 00:00:00 2001 From: jiangzesong <2504228846@qq.com> Date: Thu, 2 Nov 2023 10:19:21 +0800 Subject: [PATCH] generate_tech_xml_files.sh --- vtr_flow/scripts/generate_tech_xml_files.sh | 5 ++++ vtr_flow/scripts/transform_the_content.py | 30 +++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 vtr_flow/scripts/transform_the_content.py diff --git a/vtr_flow/scripts/generate_tech_xml_files.sh b/vtr_flow/scripts/generate_tech_xml_files.sh index 1ed77ea09dd..b0b2f9d32b7 100755 --- a/vtr_flow/scripts/generate_tech_xml_files.sh +++ b/vtr_flow/scripts/generate_tech_xml_files.sh @@ -3,3 +3,8 @@ ./generate_cmos_tech_data.pl ../tech/PTM_22nm/22nm.pm 22e-9 0.8 85 > ../tech/PTM_22nm/22nm.xml & ./generate_cmos_tech_data.pl ../tech/PTM_45nm/45nm.pm 45e-9 0.9 85 > ../tech/PTM_45nm/45nm.xml & ./generate_cmos_tech_data.pl ../tech/PTM_130nm/130nm.pm 130e-9 1.3 85 > ../tech/PTM_130nm/130nm.xml & + +# If you encounter a situation where the units in the generated numerical content +# have not been converted to exponential levels, you may try using the following code snippet. + +# python3 ./transform_the_content.py \ No newline at end of file diff --git a/vtr_flow/scripts/transform_the_content.py b/vtr_flow/scripts/transform_the_content.py new file mode 100644 index 00000000000..29597e9797c --- /dev/null +++ b/vtr_flow/scripts/transform_the_content.py @@ -0,0 +1,30 @@ +import re +def convert_suffix(match): + num = match.group(1) + suffix = match.group(2) + suffix_map = { + 'a': 'E-18', + 'f': 'E-15', + 'u': 'E-6', + 'n': 'E-9', + 'p': 'E-12', + 'm': 'E-3', + 'e': 'E' + } + return num + suffix_map.get(suffix.lower(), '') + +# if you want to modify .xml files under other processes, you may need to modify the path below. +xml_file = "~/vtr-verilog-to-routing/vtr_flow/tech/PTM_22nm/22nm.xml" + +# read .xml file +with open(xml_file, 'r') as file: + lines = file.readlines() + +# Replace the units with the corresponding exponential level. +for i in range(1,len(lines)): + lines[i] = re.sub(r'(\d+(?:\.\d*)?)([a-zA-Z])(?![a-zA-Z])', convert_suffix, lines[i]) + + +# write the content to the .xml file +with open(xml_file, 'w') as file: + file.writelines(lines) \ No newline at end of file