Skip to content

mirkat1206/liberty2json-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

liberty2json-python

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

liberty2json.py & main.py

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)

liberty.py & test.py

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.

Features

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.
  • 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.

Fun Fact

All docstrings in this project are mainly generated by ChatGPT.

The resulting docstrings are amazingly formal and accurate. I only modified few places.


What is Liberty library format?

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.

General Syntax of Liberty library format

In Liberty library format, there are three kinds of statement: group statment, attribute statement, and define statement.

Group statement

group_name (name) {
    ... statements ...
}

Attribute statement

/* simple attribute statement */
attribute_name: attribute_value;

/* complex attribute statement */
attribute_name (param1, [param2, param3, ...]);

Define statement

define (attribute_name, group_name, attribute_type);

What is JSON format?

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.

Why do we need liberty2json-python?

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.


License

MIT

Reference

Previous Projects

About

An elegant Python implementation to convert Liberty library format into JSON format

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages