blob: cc8c4c08bbd0edc6d20114ddc2c79eb499e351f1 [file] [log] [blame]
agorararmard22561582021-01-15 17:55:59 +02001#!/usr/bin/env python3
2# Copyright 2020 Efabless Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# This script is for the sake of DRC batch running, since batch running only requires the text section of .lydrc
17# I thought it would be better to have open_pdks handle this in a case by case basis (pdk by pdk) instead of having
18# that code somewhwere in OpenLANE as this is more PDK related.
19
20import os
21import argparse
22
23
24parser = argparse.ArgumentParser(
25 description='The script parses a lydrc klayout xml database and extracts the runnable text section inside it')
26
27parser.add_argument('--lydrc', '-l',required=True,
28 help='lydrc klayout xml database.')
29
30parser.add_argument('--output_script', '-o',required=True,
31 help="outputs the script to be used to run klayout drc.")
32
33
34args = parser.parse_args()
35lydrc = args.lydrc
36output_script = args.output_script
37
38def cleanup(text):
39 return str(text).replace("&gt;",">").replace("&lt;","<").replace("&amp;","&")
40
41def make_verbose(text):
42 return str(text).replace("verbose(false)","verbose(true)")
43
44if(os.path.exists(lydrc)):
45 lydrcFileOpener = open(lydrc, "r", encoding="utf-8")
46 if lydrcFileOpener.mode == 'r':
47 lydrcContent = lydrcFileOpener.read()
48 lydrcFileOpener.close()
49 sections = lydrcContent.split("<text>")
50 if len(sections) == 2:
51 text = sections[1].split("</text>")[0]
52 output_scriptFileOpener = open(output_script,"w", encoding="utf-8")
53 output_scriptFileOpener.write(make_verbose(cleanup(text)))
54 output_scriptFileOpener.close()