Implementing Pcells Through Tcl (Beta)


OpenAccess implements Pcells in Tcl by using the oaPcellScript and oaTclEngine plug-ins. The oaPcellScript plug-in is a Pcell evaluator that uses a scripting engine to interpret a Pcell evaluation procedure written in a scripting language that supports the OpenAccess binding. Provided the necessary scripting engine, the Pcell evaluator can work with different types of scripting languages. The oaTclEngine is a scripting engine included with OpenAccess that provides the OpenAccess binding through the oaTcl shared library. See Tcl Bindings for OpenAccess APIs for information about installing the oaTcl shared library. The oaTclEngine plug-in supports Tcl version 8.4 or later.

Using these two plug-ins, applications can create Tcl based Pcells by defining a procedure definition to generate design content based on a set of parameters. This document explains how a Tcl Pcell can be created using the OpenAccess Tcl binding or using the OpenAccess C++ API.

Understanding the Pcell Evaluation Procedure

An application must create a procedure definition that consists of an argument list with a single argument and a body. The argument is the design where the content will be generated. The following Tcl procedure definition shows how to retrieve the parameters from a design and use them to generate a rectangle in the design.

{design} {set paramArray [oa::getParams $design]
              set param [oa::Param]
              oa::find $paramArray locX param
              set locXVal [oa::getDoubleVal $param]
              oa::find $paramArray locY param
              set locYVal [oa::getDoubleVal $param]
              oa::find $paramArray width param
              set widthVal [oa::getDoubleVal $param]
              oa::find $paramArray height param
              set heightVal [oa::getDoubleVal $param]
              set topBlock [oa::getTopBlock $design]
              if {$topBlock == ""} {
                set topBlock [oa::BlockCreate $design]
              }
              set x1 $locXVal
              set y1 $locYVal
              set x2 [expr $x1 + $widthVal]
              set y2 [expr $y1 + $heightVal]
              set bbox [list [list $x1 $y1] [list $x2 $y2]]
              oa::RectCreate $topBlock 1 2 $bbox
		}

Creating a Tcl Pcell superMaster in Tcl

A Tcl Pcell superMaster can be created in the Tcl environment using the oaTclEngine. You must start a Tcl shell and load the oaTcl binding in order to create an OpenAccess Tcl Pcell superMaster. Use the following steps:

  1. Set a body variable that defines the procedure body.
  2. Set the procDef variable equal to the procedure definition "{design} \{$body\}".
  3. Set the view type variable and open the design library in write mode for creating the superMaster.
  4. Retrieve an oaPcellDef from oaPcellScript by using
        set def [oa::PcellLinkGetPcellDef oaPcellScript]
  5. Specify the scripting engine by using oa::addData and the data value named ScriptEngineName.
  6. Specify the procedure definition by using the data value named GenCellProc.
  7. Create the superMaster parameters by calling oa::Param and oa::setDoubleVal (or other appropriate type for your parameters).
  8. Create a parameter array to specify the parameters for this Pcell by calling oa::ParamArray.
  9. Call oa::defineSuperMaster on the superMaster with the modified oaPcellDef and oaParamArray.
  10. Save the design.

The following Tcl script implements these steps.

set body    {set paramArray [oa::getParams $design]
              set param [oa::Param]
              oa::find $paramArray locX param
              set locXVal [oa::getDoubleVal $param]
              oa::find $paramArray locY param
              set locYVal [oa::getDoubleVal $param]
              oa::find $paramArray width param
              set widthVal [oa::getDoubleVal $param]
              oa::find $paramArray height param
              set heightVal [oa::getDoubleVal $param]
              set topBlock [oa::getTopBlock $design]
              if {$topBlock == ""} {
                set topBlock [oa::BlockCreate $design]
              }
              set x1 $locXVal
              set y1 $locYVal
              set x2 [expr $x1 + $widthVal]
              set y2 [expr $y1 + $heightVal]
              set bbox [list [list $x1 $y1] [list $x2 $y2]]
              oa::RectCreate $topBlock 1 2 $bbox}
set procDef  "{design} \{$body\}"


set viewType [oa::ViewTypeGet maskLayout]
set master  [oa::DesignOpen testLib tclSuperMaster2 layout $viewType w]
 

set def     [oa::PcellLinkGetPcellDef oaPcellScript]


oa::addData $def ScriptEngineName oaTclEngine
oa::addData $def GenCellProc $procDef


set p1      [oa::Param locX 0]
oa::setDoubleVal $p1 0.0
set p2      [oa::Param locY 0.0]
oa::setDoubleVal $p2 0.0
set p3      [oa::Param width 0.0]
oa::setDoubleVal $p3 3.0
set p4      [oa::Param height 0.0]
oa::setDoubleVal $p4 1.0
 

set paramArray    [oa::ParamArray 4]
oa::append  $paramArray $p1
oa::append  $paramArray $p2
oa::append  $paramArray $p3
oa::append  $paramArray $p4
 

oa::defineSuperMaster $master $def $paramArray 
oa::save $master

Controlling Error Logging

By default, errors that occur during Pcell evaluation are logged to the Tcl interpreter. You can disable this error logging to suppress errors encountered during the evaluation of a Pcell script by using:

    setPcellErrorLogging false

You enable error logging by using:

    setPcellErrorLogging true

If error logging is disabled, errors are silently ignored.

Creating a Tcl Pcell superMaster in C++

An application can create a Tcl Pcell by using the oaPcellScript plug-in in a way that is similar to how the oaPcellCPP plug-in is used (see Writing a C++ Pcell Generator). The following steps explain the C++ code for creating a Tcl Pcell supermaster.

  1. Define a function that returns the Tcl procedure definition as an oaString type.
  2. Get the view type and open the design library in write mode for creating the superMaster.
  3. Retrieve an oaPcellDef from oaPcellScript by using oaPcellLink::getPcellDef("oaPcellScript").
  4. Specify the scripting engine by using the data value named ScriptEngineName.
  5. Specify the content generator procedure definition by using the data value named GenCellProc.
  6. Create an oaParamArray to specify the parameters for this Pcell
  7. Call oaDesign::defineSuperMaster() on the superMaster with the modified oaPcellDef and oaParamArray.
  8. Save the design.

The following code implements these steps.

oaNativeNS      ns;
  oaScalarName    libName(ns, "testLib");
  oaScalarName    cellName(ns, "tclPcellMaster");
  oaScalarName    viewName(ns, "layout");
  oaViewType      *viewType = oaViewType::get(oacMaskLayout);
 

  oaDesign  *sMaster = oaDesign::open(libName, cellName, viewName, viewType, 'w'); 
  oaString  gcProc("{design} {\n\
                      set paramArray [oa::getParams $design]\n\
                      set param [oa::Param]\n\
                      oa::find $paramArray locX param\n\
                      set locXVal [oa::getDoubleVal $param]\n\
                      oa::find $paramArray locY param\n\
                      set locYVal [oa::getDoubleVal $param]\n\
                            oa::find $paramArray width param\n\
                      set widthVal [oa::getDoubleVal $param]\n\
                            oa::find $paramArray height param\n\
                      set heightVal [oa::getDoubleVal $param]\n\
                      set topBlock [oa::getTopBlock $design]\n\
                      if {$topBlock == \"\"} {\n\
                        set topBlock [oa::BlockCreate $design]\n\
                      }\n\
                      set x1 $locXVal\n\
                      set y1 $locYVal\n\
                      set x2 [expr $x1 + $widthVal]\n\
                      set y2 [expr $y1 + $heightVal]\n\
                      set bbox [list [list $x1 $y1] [list $x2 $y2]]\n\
                      oa::RectCreate $topBlock 1 2 $bbox\n\
                  }");
    oaString      seName("oaTclEngine");
    oaPcellDef    *pDef = oaPcellLink::getPcellDef("oaPcellScript");
 

    pDef->addData("ScriptEngineName", seName);
    pDef->addData("GenCellProc", gcProc);
 

    oaParam p1;
    p1.setName("locX");
    p1.setDoubleVal(0.0);
 

    oaParam p2;
    p2.setName("locY");
    p2.setDoubleVal(0.0);


    oaParam p3;
    p3.setName("width");
    p3.setDoubleVal(3.0);


    oaParam p4;
    p4.setName("height");
    p4.setDoubleVal(1.0);
 

    oaParamArray    paramArray;
    paramArray.append(p1);
    paramArray.append(p2);
    paramArray.append(p3);
    paramArray.append(p4);


    sMaster->defineSuperMaster(pDef, paramArray);
    sMaster->save();

Return to top of page

Return to Programmers Guide topics


Copyright © 2010 Cadence Design Systems, Inc.
All rights reserved.