Eda Scripting Languages
Eda Scripting Languages
Eda Scripting Languages
Desmond A. Kirkpatrick Intel Corp. Microprocessor Products Group Hillsboro, OR 97124, USA [email protected]
guage, it lacks the ability to integrate with the other existing systems, or has a poor programming, scripting or customization capability. We propose an approach to fast linking EDA tools with scripting languages using an interface wrapper generator. A possible system conguration may be as shown in Fig.1, where a scripting language is used to integrate or glue
Interface Wrapper
Interface Wrapper
Interface Wrapper
EDA Engine
Database
Numerical Modeling
Figure 1: Tools Integration by a Scripting Language tools together, providing a full programming capability to end users. All the pieces of tools are dynamic loadable, which means that one can choose components based on the task need, and tool vendors can develop their own application system independently and hook it up later, or even create revision without affecting the system integrity. Scripting capability is usually important for major EDA tools. Commercial tools usually adopt a dialect of some popular language such as Skill for Silicon Ensemble[8], Scheme for Apollo II[9], or Tcl for Design Compiler[10]. It provides APIs access to automate a design job. However, many tools just adopt a simple and original interactive shell, which is neither extensible nor exible and not easy to program. Besides, a specic scripting language may be another stopping factor for a user to further explore the tool, just because there is a long learning curve for a new programming language.
1 Introduction
Scripting languages such as Perl and Tcl[7] are well-suited for a high level programming job and system integration. The code required for a same task is usually less by a factor of 5 to 10X [7] compared with a system programming language such as C/C++ or Java. However, it is not efcient or optimal for performance oriented task, for which the traditional system programming languages can work very well. One approach naturally combines a scripting language at the top and uses the dedicated and optimized algorithm engine from system programming languages for the underlying structure. This approach is very powerful, exible, and easy for scripting or rapid prototyping of an application system. For EDA tools, as they are often characterized as an efcient core engine optimized for performance based on a system programming lan-
Rapid prototyping and reuse of software components are a key to software productivity. Many high level algorithms are not even possible without the underlying database and supporting routines available. It is thus desirable that an EDA tool developer can implement a new algorithm efciently by leveraging existing software components. Scripting languages can bridge the gap by providing a full programming environment and linking with existing tools from a higher level of language description without any compilation. EDA tools have been lack of interoperability for a long time. There are several methods to communicate between two programs or working processes. Consider a delay calculator and a Verilog simulator as an example, which is shown in Fig. 2. The delay calculator will send delay data back to the VerScript Language
provide service routines, linked to a host, the Verilog simulator, through these PLIs. One has to be very careful about data types and usage details of PLIs to make it work smoothly. It requires a separate linking pass to make it an executable simulator, resulting in a very time-consuming, non-extensible, and inexible solution. Client-Server Mode The third approach uses a client-server mode. For example, the delay calculator runs as a server waiting for the Verilog simulator to input information and feedbacks with delay data. It requires a detailed set of communication protocol to make this feasible. It is very time-consuming to implement and verify the complicated communication protocol. It seems that EDA tools seldom take this approach. Direct Access of Internal Data Structure The fourth approach uses internal data access. This is the most efcient one. However, due to data abstraction and code consistency, and different tool providers, it is almost against all the software engineering principles. It is not only difcult to maintain, but also easy to crash a whole system. API Access through a General Scripting Language We therefore propose that all the design tasks can be integrated onto a uniform platform to reduce the text/binary le exchange, and the end users can access some of the APIs to do customization to t their need using most popular scripting languages such as Perl or Tcl. The development time can be much reduced. Each component can be hooked up to that platform dynamically under the control of a script to complete a design task. Comprehensive testing of a software routine is generally very difcult and time-consuming. The common testing approach is based on an outer input and output pair. It can not handle ner grain testing for any specic API. However, with the integrated APIs in the scripting language, a tool developer can design a set of very dedicated scripts to test each API and does not have to compile another testing programs to intervene with the production code. A series of regression tests for the API can thus be easily created to guarantee high software quality. In general, integrating APIs into a popular scripting language is not very straight-forward. Frequently, there are lots of extra work required to make the interface self-consistent. We emphasize the minimal extra coding to link a set of APIs into a scripting language, and provide some approaches to easing the integration work. SWIG[11] was designed to automatically generate the wrapper functions. It can reduce most of routine jobs into some simple conguration and generate the required codes to bridge the gap. In this paper, we study and address techniques using SWIG and some simple scripts to interface and link the features or functions that an EDA tool may have to most popular script languages such as Tcl and Perl. These two tools have been extensively used in the design community for a long time due to
API
PLI
Verilog Simulator
Figure 2: Two Communicating Processes ilog simulator. There are several approaches to exchange data: Text/Binary File The rst approach uses some specic format to exchange data through normal OS les, for example, using standard delay format(SDF) to exchange delay data. This approach has serious drawbacks: 1. Extra dumping of data into the specic format and parsing of that format are required, 2. The input and output formats between two tools can be very possibly mismatched or misrepresented, i.e., format compatibility problem, 3. The input or output formats are thus xed without any exibility to change unless any further post processing is performed, From a high productivity point of view, it is not desirable to learn too many formal programming languages for a designer. It is not uncommon that a designer may have to know at least a dozen of programming/scripting languages and formats to do a good job just for using various EDA tools, and a dozen of supporting scripts may be required to transform formats between different tools. Programming Language Interface The second approach uses a set of programming language interface(PLI)s to communicate with each other. The delay calculator will
its powerful scripting capability, popularity, and extensibility. Both can process a simple text le very efciently without the tedium to program a full parser and a lexical analyzer. We will show how to integrate Tcl and Perl interfaces to a logic synthesis system Sis[1]. We will rst introduce briey the SWIG functionality. It is followed by various techniques used in our case study. We conclude by interface design consideration and propose for future work.
use sis_script; package sis_script; network_set_name("a_new_name"); print network_name($current_network); SWIG provides rich features to support interface and data type mapping functions plus many examples to show how to handle each case. It also supports linking with Python and Guile[11].
%init %{ avl_foreach_item(command_table, gen, AVL_FORWARD, &key, NIL(char *)){ Tcl_CreateCommand(interp, key, _tcl_dispatch,(ClientData)NULL, (Tcl_CmdDeleteProc *) NULL); } %} or when Perl initializes: %init %{ char buf[4096]; avl_foreach_item(command_table, gen, AVL_FORWARD, &key, NIL(char *)){ sprintf(buf,"sis_script::%s",key); newXS(buf, _perl_dispatch, file); } %} With this translation, we can port the Sis command set into a Tcl dynamic extension library or a Perl package within 5 minuates of work. It is amazing that the original Sis script can run in Tcl without any modication. For example, an original script script.rugged as shown below can run without any syntax modication: sweep; eliminate -1 simplify -m nocomp eliminate -1 sweep; eliminate 5 simplify -m nocomp resub -a fx resub -a; sweep eliminate -1; sweep full_simplify -m nocomp or in Perl with minor syntax differences: use sis_script; package sis_script; sweep; eliminate -1; simplify -m,nocomp; eliminate -1; sweep; eliminate 5; simplify -m,nocomp; resub -a; fx; resub -a; sweep; eliminate -1; sweep; full_simplify -m,nocomp;
proc get_map_result {} { set result [get_output\ {map -s -n 1 -c 0}] regexp \ {total neg slack:\s*\(([\d.-]+),([\d.-]+)}\ $result dummy rise_slack fall_slack return [expr $rise_slack+$fall_slack] } set slack -10000000 while 1 { source script.algebraic set old_slack $slack set slack [get_map_result] puts "Slack=$slack" if {$old_slack > $slack + 40} break } or in Perl: sub get_map_result{ my $result=get_output &sis_script::map("-s","-n",1,"-c",0); my ($rise_slack,$fall_slack)= ($result = /total neg slack:\s*\(([\d.-]+),([\d.-]+)/o); return ($rise_slack+$fall_slack)/2; } $slack=-10000000; while(1){ require "script.algebraic.pl"; $old_slack=$slack; $slack=get_map_result(); print "Slack=$slack\n"; if($old_slack > $slack + 40){ last;} } The function get map result is used to extract the total slack information. We implement a very useful output redirection routine get output to catch the information from standard output and standard error. With the powerful regular expression operations from Perl or Tcl, one can extract any information from an APIs output. This reduces the complexity to understand each detail inside the C/C++ data structure. Also, it is a crucial technique for black-box testing. For example, one can test a function API in test in Tcl as set output [get_output API_in_test $args errlog] if {regexp -nocase error $errlog} { puts "Testing of API_in_test fails!" } else { puts "OK!" }
3.2
Information Extraction
The rich regular expression operations from Tcl or Perl can be used to extract run-time information for adaptively control based on the progress of optimization, for example, in Tcl:
macro denitions may be required to tune the data type and APIs name. %name and $rename are supported in SWIG to change names. Creation of an object interface requires some extra work in SWIG. First, we have to congure some declarations for an object in the SWIG conguration le. For example, network object is specied as: typedef struct{ }network; typedef network network_t; %addmethods network{ network(network_t *default=NULL); network(); node_t* find_node(char *name); int num_pi(); } Using this, SWIG will set new network for the object constructor, delete network for the object destructor, and adds a prex network for the other member functions in C/C++. Note that typedef network network t can create an equivalent data type class in SWIG. For Tcl, one can thus create a network object as: set network [network -this [current_network_get]] , delete an network object by rename $network {} , or call a member function find node by $network find_node "input_node1" For Perl, one can create a network object as: $network=new network($current_network); , delete an network object by $network->DESTORY(); , or call a member function find node by $network->find_node "input_node1"; Note that one has to turn on -shadow in SWIG to generate the object oriented interface for Perl.
to dump all the fanin of a node in $network. The implementation of foreach node command is very similar to the command while implementation in Tcl[4]. Although this implementation is quite complex, SWIG support a full C preprocessor capability. It can be used as a simple template generator to handle this type of macros. For Perl, unfortunately, there is no corresponding syntax construct that can emulate this macro. One has to implement a function to return a list consisting of all the nodes in the network.
3.4
There are often some macros that will traverse some data structures to examine each object. This saves extra memory to build a pointer array. For example, in Tcl, one can use foreach_node n $network { puts -nonewline \ "Node [node_name $n] has fanin: " foreach_fanin p $n { puts -nonewline "[node_name $p] " } puts "" }
3.6
For SWIG implementation, it encodes a pointer into a string with its hex address attached with datatype. However, in some situation, it may require a type transformation. It can be done in Tcl as regsub {(_[0-9a-f]+)_.*$} $old_ptr\ "\\1_$new_datatype" $new_ptr or in Perl, due to SWIGs implementation, as bless $old_ptr,$new_datatype;
3.7
Namespace Coniction
Since each module is developed independently, it is easy to have name conictions when linking all modules together. Tcl has a command supporting namespace along with a SWIG switch -namespace. Perl supports package directive and Exporter class to avoid this problems[5]. Some C dynamic library may have name collisions as well. It can be solved by linking each package with -Bsymbolic switch or conservatively with -Bstatic.
3.8
Memory Management
In general, the user must be responsible for releasing unused memory. However, it is possible to set up a variable trace command in Tcl to automatically delete a local object: trace variable $obj u delete_obj proc delete_obj {name1 name2 op} { rename $name1 {} } For Perl, with -shadow switch, SWIG can emulate an object behavior naturally, the local variable is thus destroyed automatically by Perls scoping mechanism.
3.9
Variable Trace
For common data types such as int, double, and string, SWIG can implement trace capacibility. That is to say, a Tcl variable will be created to follow the value changes in C/C++ code. However, for pointer types, SWIG will create read and write routines for each variable for Tcl. There are some tricky implementation techniques to use trace command to tie a Tcl variable and C/C++ variable together. For Perl, SWIG uses a technique to tie the variable with associated access routines, so it is transparent to the user.
References
[1] E. M. Sentovich and etc. SIS: A System for Sequential Circuit Synthesis. Electronics Research Laboratory Memo. No. ERL/UCB M92/41, May 1992. [2] A. Aziz and etc. VIS Users Manual. http://wwwcad.eecs.berkeley.edu/Respep/Research/vis/index.html. [3] Magic A VLSI Layout System. http://www.research.digital.com/wrl/projects/magic/ magic.html. [4] J. K. Ousterhout. Tcl and the Tk Toolkit. AddisonWesley, 1994. [5] L. Wall, T. Christiansen, and R. Schwartz. Programming Perl. OReilly and Assoicates, 1996. [6] http://www.cpan.org. [7] J. K. Ousterhout. Scripting::Higher Level Programming for the 21st Century. IEEE Computer magazine, Mar. 1998. [8] http://www.cadence.com.
3.10
SWIG supports document generation by extracting information from the interface conguration le. If some document is embedded in the C/C++ code as some comments around an API, it can be extracted and organized as a html or latex document.
[9] http://www.avanticorp.com. [10] http://www.synopsys.com. [11] Simplied Wrapper http://www.swig.org. and Interface Generator.
[12] D. M. Beazley, D. Fletcher, and D. Dumont. Perl Extension Building with SWIG. OReilly Perl Conference 2.0, pages 1720, Aug. 1998.