This is a python project that converts Liberty library format to JSON format.
Also, an easy parser of the resulting JSON files is presented.
usage: main.py [-h] [--libfile LIBFILE] [--libdir LIBDIR] [--jsondir JSONDIR]
Turn liberty format file(s) into json format file(s).
optional arguments:
-h, --help show this help message and exit
--libfile LIBFILE filepath of a liberty format file
--libdir LIBDIR dirpath of a directory containing liberty format file(s)
--jsondir JSONDIR dirpath for output json file(s)
Three levels of classes are supported: class liberty
, class cell
, and class pin
.
For detailed usage and modification methods, please refer to liberty.py and test.py.
Compared to other previous liberty2json projects, this project has some special features:
- This project is written in Python.
- This project is purely based on the general syntax of Liberty library format.
- Unlike the other projects, this project does not predefine any names (group/attribute/define) nor presume any input orders.
- Hence, this project can deal with any unexpected names or orders.
- The code is very clean and elegant.
- Less than 300 lines of code in liberty2json.py, including comments.
- Another liberty.py is also created for parsing the resulted JSON files.
- Basic methods are created for common needs (ex: get_attributes/get_cells/get_pins).
- Additional methods can be easily added in similar way according to users' needs.
All docstrings in this project are mainly generated by ChatGPT.
The resulting docstrings are amazingly formal and accurate. I only modified few places.
Liberty library format is the most-widely-used industry standard format in EDA implementation.
A liberty library file contains information of library cells of a particular technology, including timing, power, area, noise, and etc.
In Liberty library format, there are three kinds of statement: group statment, attribute statement, and define statement.
group_name (name) {
... statements ...
}
/* simple attribute statement */
attribute_name: attribute_value;
/* complex attribute statement */
attribute_name (param1, [param2, param3, ...]);
define (attribute_name, group_name, attribute_type);
JSON(JavaScript Object Notion) is a text format that is “self-describing” and easy to understand, and JSON is supported by many programming languages, including C/C++, C#, Java, Perl, Python, etc.
In Python, with import json
, you can manipulate JSON format files easily.
In many cases (for example: my research), we might need information in Liberty files. However, the general syntax of Liberty library format is rather irregular and hard to process. JSON format is more regular and easy to manipulate, so I want to convert Liberty library format to JSON format.
Since all previous implementations of liberty2json do not seem to be general enough, I created this project to meet my needs.
MIT