Table of Contents
Scripting interface
Workcraft supports scripting using JavaScript language. Two modes of script execution are supported:
- Interactively, by entering the script commands in the Javascript tab and pressing Ctrl+Enter to execute them. The output of the commands is redirected to the Output tab.
- In batch mode, by passing the script file name or a one-liner script after the
-exec:command line parameter.
For batch mode it is often convenient to start Workcraft without GUI and without reading/writing configuration files. This is achieved by using -nogui and -noconfig command line parameter as follows (We presume that Workcraft home is in the search PATH and the platform-specific .sh/.bat extension of Workcraft runner is omitted):
workcraft -nogui -noconfig -exec:'/path/to/script.js'
If a script contains file operation commands, such as loading work files or exporting the models, then all the file names in these commands are relative to the working directory. By default this coincides with Workcraft home, however, an alternative working directory can be passed after the -dir: command line parameter, as follows:
workcraft -nogui -noconfig -exec:script.js -dir:'/working/directory/path/'
since v3.2.3 For a short JavaScript snippet, it may be more convenient to pass it directly in the command line:
workcraft -nogui -exec:'print("Hello!");exit();'
For more information about these and other Workcraft startup options see Command line interface document.
Functions and variables
Here is a list of predefined wrapper functions, partitioned into categories, and global variables available for scripting.
Help
help(substring)– output all the helper functions whose name contains the givensubstringapropos(substring)– output all the helper functions whose name or description contains the givensubstringgetHelp(substring, searchDescription)– return a string with all helper functions whose name contains thesubstring; if thesearchDescriptionis true, then also search the function descriptions
Text output
print(msg)– outputmsgto stdout and add a newlineeprint(msg)– outputmsgto stderr and add a newlinewrite(text, fileName)– writetextto a filefileName(relative to the working directory) or to stdout iffileNameis skipped
Note that conventional Java print functions can be also used, e.g. if you need to output text without adding a newline:
System.out.print(text)– outputtextto stdoutSystem.err.print(text)– outputtextto stderr
GUI and exit
startGUI()– start GUIstopGUI()– stop GUI and switch to console modequit()orexit()– request Workcraft shutdown after script execution is completeNote that
quit()andexit()do not terminate Workcraft immediately, and therefore should not be used in the middle of JavaScript program as a way to abort its execution. Insteadthrow('message')JavaScript statement should be used for this purpose.
Global variables
args– command line parameters passed to Workcraft; these can be iterated over as follows:for each (arg in args) {…}framework– the Workcraft framework singletonworkspaceEntry– the current workmodelEntry– the current model entry, a shortcut toworkspaceEntry.getModelEntry()visualModel– the current visual model, a shortcut tomodelEntry.getVisualModel()mathModel– the current math model, a shortcut tomodelEntry.getMathModel()
Workspace functions
getWorks()– return an iterable array of loaded worksgetWorkFile(work)– return a file object for the modelworkgetModelDescriptor(work)– return a descriptor string for the modelworkgetModelTitle(work)– return a title string for the modelworksetModelTitle(work, title)– set a title of the modelworkto the stringtitlecloseWork(work)– close the modelworkcloseAllWorks()– close all the open workssetWorkingDirectory(path)– setpathas the working directory since v3.3.7getWorkingDirectory()– get the working directory since v3.3.7
Editor functions
select(ref, …)– select the nodes passed as a list of references since v3.5.1
File operations
load(fileName)– load a model from the work filefileName(or import from external file and determine the model type by the extension) and return its workimport(fileName)– import a model from the filefileNameand return its work (the model type is determined by thefileNameextension) deprecated since v3.3.8 in favour of model-specific functions, as import is a reserved keyword in JavaScript ES6importCircuitVerilog(vFileName)– import a Circuit from the given Verilog netlist (*.v) filevFileNameand return its work since v3.3.8importCircuitVerilog(vFileName, topModuleName)– import a CircuittopModuleName(can be skipped for auto detection) with its dependencies from the given Verilog netlist (*.v) filevFileNameand return its work since v3.3.9importFstSg(sgFileName)– import an FST from the State Graph (*.sg) filesgFileNameand return its work since v3.3.8importStgG(gFileName)– import an STG from the Signal Transition Graph (*.g) filegFileNameand return its work since v3.3.8importStgLpn(lpnFileName)– import an STG from the Labeled Petri Net (*.lpn) filelpnFileNameand return its work since v3.3.8save(work, fileName)– save the modelworkinto a file with the givenfileNameexportSvg(work, fileName)– export the modelworkas a Scalable Vector Graphics (*.svg) filefileNameexportPng(work, fileName)– export the modelworkas a Portable Network Graphics (*.png) filefileNameexportPdf(work, fileName)– export the modelworkas a Portable Document Format (*.pdf) filefileNameexportPs(work, fileName)– export the modelworkas a PostScript (*.ps) filefileNameexportEps(work, fileName)– export the modelworkas an Encapsulated PostScript (*.eps) filefileNameexportDot(work, fileName)– export the modelworkas a GraphViz (*.dot) filefileNameexportStgG(work, fileName)– export the STGworkas a Signal Transition Graph (*.g) filefileNameexportStgLpn(work, fileName)– export the STGworkas a Labelled Petri Net (*.lpn) filefileNameexportFstSg(work, fileName)– export the FSTworkas a State Graph (*.sg) filefileNameexportCircuitVerilog(work, fileName)– export the Circuitworkas a Verilog netlist (*.v) filefileNameexportDfsVerilog(work, fileName)– export the DFSworkas a Verilog netlist (*.v) filefileName
Configuration
setConfigVar(key, val)– set the config variablekeyto valuevalgetConfigVar(key)– return the value of config variablekeysaveConfig()– save settings into the default config fileloadConfig()– load settings from the default config file
Config variables are saved in config.xml file (located under ~/.config/workcraft/ in Linux or ~\AppData\Roaming\workcraft\ in Windows). The variable name you pass to setConfigVar/getConfigVar functions can be derived from config.xml file and should include its dot-separated path in the XML tree. For example, setConfigVar("CircuitSettings.clearPin", "RN"); sets the variable clearPin under CircuitSettings group to a string RN.
Command execution
execFile(fileName)– execute JavaScript filefileNamerunCommand(work, className)– apply the commandclassNameto the modelworkas a background taskexecuteCommand(work, className)– apply the commandclassNameto the modelworkand wait for the result
Model specific commands
Commands for conversion, transformation and verification of specific models.
Conversion commands
These commands are applied to the given work of a specific model type and produce a new model work.
- Conversion between different model types (sorted alphabetically)
convertCircuitToStg(work)– convert the Circuitworkinto a new STG workconvertCircuitToStgWithEnvironment(work)– convert the Circuitworkand its environment into a new STG workconvertDfsToStg(work)– convert the DFSworkinto a new STG workconvertFsmToFst(work)– convert the FSMworkinto a new FST workconvertFsmToGraph(work)– convert the FSMworkinto a new Graph workconvertFsmToPetri(work)– convert the FSMworkinto a new Petri net workconvertFstToFsm(work)– convert the FSTworkinto a new FSM workconvertFstToStg(work)– convert the FSTworkinto a new STG workconvertGraphToFsm(work)– convert the Graphworkinto a new FSM workconvertGraphToPetri(work)– convert the Graphworkinto a new Petri net workconvertPetriToFsm(work)– convert the Petri networkinto a new FSM workconvertPetriToPolicy(work)– convert the Petri networkinto a new Policy net workconvertPetriToStg(work)– convert the Petri networkinto a new STG workconvertPolicyToPetri(work)– convert the Policy networkinto a new Petri net workconvertStgToBinaryFst(work)– convert the STGworkinto a new binary FST workconvertStgToFst(work)– convert the STGworkinto a new FST workconvertStgToPetri(work)– convert the STGworkinto a new Petri net workconvertWtgToStg(work)– convert the WTGworkinto a new STG work
- Conversion of STG and Petri net models using net synthesis of Petrify
convertPetriSynthesis(work)– convert the Petri net/STG/FSM/FSTworkinto a new work using net synthesisconvertPetriSynthesisEr(work)– convert the Petri net/FSM or STG/FSTworkinto a new Petri net or STG work using net synthesis with a different label for each excitation regionconvertPetriHideTransition(work)– convert the Petri net/STGworkinto a new work hiding selected transitionsconvertPetriHideErTransition(work)– convert the Petri net or STGworkinto a new Petri net or STG work hiding selected signals and dummies with a different label for each excitation regionconvertStgUntoggle(work)– convert the STGworkinto a new work where the selected (or all) transitions are untoggledconvertStgHideDummy(work)– convert the STGworkinto a new work without dummies
Composition commands
These commands are applied to a set of STG works passed as a space-separated list of file names relative to the working directory, and produce a new STG work.
composeStg(work, data)– compose STGs specified by the space-separated list of work file namesdata(workparameter is ignored) since v3.3.0
Statistics commands
These commands produce a statistics string for the given work of a specific model type.
statModel(work)– node and arc count for the modelwork(all model types are supported)statPetri(work)– advanced complexity estimates for the Petri networkstatStg(work)– advanced complexity estimates for the STGworkstatCircuit(work)– advanced complexity estimates for the CircuitworkstatCircuitRefinement(work)– refinement dependencies for the Circuitworksince v3.3.8
Synthesis commands
These commands are applied to the given work of a specific model type and return a new model work.
- Logic synthesis of Circuits from STGs using Petrify backend
resolveCscConflictPetrify(work)– resolve complete state coding conflicts in the STGworkusing PetrifysynthComplexGatePetrify(work)– logic synthesis of the STGworkinto a complex gate Circuit work using PetrifysynthGeneralisedCelementPetrify(work)– synthesis of the STGworkinto a generalised C-element Circuit using PetrifysynthStandardCelementPetrify(work)– synthesis of the STGworkinto a standard C-element Circuit work using PetrifysynthTechnologyMappingPetrify(work)– technology mapping of the STGworkinto a Circuit work using Petrify
- Logic synthesis of Circuits from STGs using MPSat backend
resolveCscConflictMpsat(work)– resolve complete state coding conflicts in the STGworkusing MPSatsynthComplexGateMpsat(work)– logic synthesis of the STGworkinto a complex gate Circuit work using MPSatsynthGeneralisedCelementMpsat(work)– synthesis of the STGworkinto a generalised C-element Circuit work using MPSatsynthStandardCelementMpsat(work)– synthesis of the STGworkinto a standard C-element Circuit work using MPSatsynthTechnologyMappingMpsat(work)– technology mapping of the STGworkinto a Circuit work using MPSat
- Logic synthesis of Circuits from STGs using ATACS backend
synthComplexGateAtacs(work)– logic synthesis of the STGworkinto a complex gate Circuit work using ATACSsynthGeneralisedCelementAtacs(work)– synthesis of the STGworkinto a generalised C-element Circuit work using ATACSsynthStandardCelementAtacs(work)– synthesis of the STGworkinto a standard C-element Circuit work using ATACS
Layout commands
These commands modify the given work of a specific model type.
layoutModelDot(work)– position nodes and shape the arcs using of the modelworkusing Graphviz backendlayoutModelRandom(work)– randomly position graph nodes of the modelworkand connect them by straight arcslayoutCircuit(work)– place components and route wires of the CircuitworklayoutCircuitPlacement(work)– place components of the CircuitworklayoutCircuitRouting(work)– route wires of the Circuitwork
Verification commands
These commands are applied to the given work of a specific model type and return a Boolean outcome of the check.
Note that the result of verification commands is of object Boolean type (with capital B), as opposed to primitive boolean type (with small b). In addition to the conventional true and false values, Boolean may also evaluate to null (e.g. when verification command is not applicable to the supplied model).
Care should be taken when handling Boolean values in JavaScript – they cannot be directly used in logic expressions. For example, consider function 'f()' that returns a Boolean.
The following code snippet would always print pass, because the Boolean value is implicitly converted into a non-empty string ("true", "false" or "null"), which always evaluates to boolean true:
if (f()) print("pass"); else print("fail"); // PROBLEM: this always prints pass
Instead, an explicit comparison to the expected boolean value should be used, thus forcing the cast of Boolean into boolean (instead of string) for subsequent comparison:
if (f() == true) print("pass"); else print("fail");
A cleaner way to encode logic expressions is to explicitly convert the value into boolean by using booleanValue() method of Boolean type (this code would throw an exception if the result of f() is not Boolean or the returned value is null):
if (f().booleanValue()) print("pass"); else print("fail");
- Commands specific for Circuit models
checkCircuitBinateImplementation(work)– check the Circuitworkfor correct implementation of its binate functions since v3.2.5checkCircuitCombined(work)– combined check of the Circuitworkfor all essential properties (conformation to environment, output persistency, deadlock freeness)checkCircuitConformation(work)– check the Circuitworkfor conformation to environmentcheckCircuitCycles(work)– check if the Circuitworkis free from cyclic pathscheckCircuitDeadlockFreeness(work)– check the Circuitworkfor deadlock freenesscheckCircuitOutputPersistency(work)– check the Circuitworkfor output persistencycheckCircuitReachAssertion(work, data)– check the Circuitworkfor REACH assertiondatasince v3.3.0checkCircuitReset(work)– check if the Circuitworkis correctly initialised via forced input portscheckCircuitSignalAssertion(work, data)– check the Circuitworkfor signal assertiondatasince v3.3.0checkCircuitStrictImplementation(work)– check the Circuitworkfor strict implementation of its signals according to the environment
- Commands specific for DFS models
checkDfsCombined(work)– combined check of the DFSworkfor deadlock freeness and output persistencycheckDfsDeadlockFreeness(work)– check the DFSworkfor deadlock freenesscheckDfsOutputPersistency(work)– check the DFSworkfor output persistency
- Commands specific for FSM/FST models
checkFsmDeadlockFreeness(work)- check the FSM/FSTworkfor deadlock freenesscheckFsmDeterminism(work)- check the FSM/FSTworkfor determinismcheckFsmReachability(work)- check the FSM/FSTworkfor reachability of all statescheckFsmReversibility(work)- check the FSM/FSTworkfor reversibility of all states
- Commands specific for Graph models
checkGraphReachability(work)– check the Graphworkfor reachability of all its nodes
- Commands specific for Policy net models
checkPolicyDeadlockFreeness(work)– check the Policy networkfor deadlock freeness
- Commands specific for STG models
checkStgCombined(work)– combined check of the STGworkfor all essential properties (consistency, output determinacy, input properness, mutex protocol, output persistency, absence of local self-triggering, deadlock freeness, delay insensitive interface)checkStgConformation(work, data)– check the STGworkfor conformation to the STG specified by file namedatasince v3.3.0checkStgConsistency(work)– check the STGworkfor consistencycheckStgCsc(work)– check the STGworkfor CSCcheckStgDeadlockFreeness(work)– check the STG (or Petri net)workfor deadlock freenesscheckStgDiInterface(work)– check the STGworkfor delay insensitive interfacecheckStgHandshakeProtocol(work, data)– check the STGworkfor following a handshake protocol as specified bydata, e.g.{req1 req2} {ack12}since v3.3.0checkStgInputProperness(work)– check the STGworkfor input propernesscheckStgLocalSelfTriggering(work)– check the STGworkfor absence of local self-triggeringcheckStgMutexImplementability(work)– check the STGworkfor implementability of its mutex placescheckStgNormalcy(work)– check the STGworkfor normalcycheckStgNwayConformation(work, data)– check the STGs specified by space-separated list of file namesdatafor N-way conformation (workparameter is ignored) since v3.2.3, changed v3.3.0checkStgOutputDeterminacy(work)– check the STGworkfor output determinacycheckStgOutputPersistency(work)– check the STGworkfor output persistencycheckStgPlaceRedundancy(work, data)– check the STG (or Petri net)workfor redundancy of places in space-separated listdatasince v3.3.0checkStgReachAssertion(work, data)– check the STGworkfor REACH assertiondatasince v3.3.0checkStgSignalAssertion(work, data)– check the STGworkfor signal assertiondatasince v3.3.0checkStgSpotAssertion(work, data)– check the STGworkfor SPOT assertiondatasince v3.3.0checkStgUsc(work)– check the STGworkfor USC
- Commands specific for WTG models
checkWtgInputProperness(work)– check the WTGworkfor input propernesscheckWtgReachability(work)– check the WTGworkfor reachability of nodes and transitionscheckWtgSoundness(work)– check the WTGworkfor soundness and consistencycheckWtgSynthesisGuidelines(work)– check the WTGworkfor compliance with the synthesis guidelines
Transformation commands
These commands modify the given work of a specific model type.
- Generic commands applicable to all models
transformModelAnonymise(work)– anonymise the modelworkby randomly renaming its nodestransformModelCopyLabel(work)– transform the modelworkby copying unique names of the selected (or all) nodes into their labelstransformModelStraightenConnection(work)– transform the modelworkby straightening selected (or all) arcs
- Commands specific for FSM and derived models
transformFsmMergeState(work)– transform the FSM/FSTworkby merging selected statestransformFsmContractState(work)– transform the FSM/FSTworkby contracting selected states
- Commands specific for generic transformations in Circuit models
transformCircuitContractComponent(work)– transform the Circuitworkby contracting selected single-input/single-output componentstransformCircuitContractJoint(work)– transform the Circuitworkby contracting selected (or all) jointstransformCircuitDetachJoint(work)– transform the Circuitworkby detaching selected (or all) jointstransformCircuitDissolveJoint(work)– transform the Circuitworkby dissolving selected (or all) jointstransformCircuitInsertBuffer(work)– transform the Circuitworkby inserting buffers into selected wirestransformCircuitPropagateInversion(work)– transform the Circuitworkby propagating inversion through selected (or all) gatestransformCircuitSplitGate(work)– transform the Circuitworkby splitting selected (or all) complex gates into simple gatestransformCircuitToggleBubble(work)– transform the Circuitworkby toggling inversion of selected contacts and outputs of selected componentstransformCircuitToggleZeroDelay(work)– transform the Circuitworkby toggling zero delay of selected inverters and bufferstransformCircuitOptimiseZeroDelay(work)– transform the Circuitworkby discarding redundant zero delay attribute for selected (or all) inverters and buffers since v3.2.5transformCircuitMutexProtocolEarly(work)– transform the Circuitworkby setting early protocol for selected (or all) mutex components since v3.5.1transformCircuitMutexProtocolLate(work)– transform the Circuitworkby setting late protocol for selected (or all) mutex components since v3.5.1
- Commands specific for reset insertion in Circuit models since v3.2.2, change in v3.2.3
insertCircuitResetActiveHigh(work)– insert active-high reset into the CircuitworkinsertCircuitResetActiveLow(work)– insert active-low reset into the CircuitworktagCircuitForcedInitAutoAppend(work)– append force init pins as necessary to complete initialisation of the Circuitwork
tagCircuitForceInitAutoAppend(work) before v3.4.0 – deprecatedtagCircuitForcedInitAutoDiscard(work)– discard force init pins that are redundant for initialisation of the Circuitwork
tagCircuitForceInitAutoDiscard(work) before v3.4.0 – deprecatedtagCircuitForcedInitClearAll(work)– clear all force init input ports and output pins in the Circuitwork
tagCircuitForceInitClearAll(work) before v3.4.0 – deprecatedtagCircuitForcedInitInputPorts(work)– force init all input ports in the Circuitwork(environment must initialise them)
tagCircuitForceInitInputPorts(work) before v3.4.0 – deprecatedtagCircuitForcedInitProblematicPins(work)– force init output pins with problematic initial state in the Circuitwork
tagCircuitForceInitProblematicPins(work) before v3.4.0 – deprecatedtagCircuitForcedInitSequentialPins(work)- force init output pins of sequential gates in the Circuitwork
tagCircuitForceInitSequentialPins(work) before v3.4.0 – deprecatedsetCircuitDriverInitToOne(work, ref, value)– setvalueas Init to one attribute for driverref(input port or output pin) in Circuitworksince v3.4.0getCircuitDriverInitToOne(work, ref)– get Init to one attribute for driverref(input port or output pin) in Circuitworksince v3.4.0setCircuitDriverForcedInit(work, ref, value)– setvalueas Forced init attribute for driverref(input port or output pin) in Circuitworksince v3.4.0getCircuitDriverForcedInit(work, ref)– get Forced init attribute for driverref(input port or output pin) in Circuitworksince v3.4.0constrainCircuitInputPortRiseOnly(work, ref)– constrain input portrefin Circuitworkas rise only since v3.4.0constrainCircuitInputPortFallOnly(work, ref)– constrain input portrefin Circuitworkas fall only since v3.4.0constrainCircuitInputPortAny(work, ref)– clear constrains from input portrefin Circuitworksince v3.4.0getCircuitDriverSetFunction(work, ref)– get Set function of driverrefin Circuitworksince v3.4.0getCircuitDriverResetFunction(work, ref)– get Reset function of driverrefin Circuitworksince v3.4.0
- Commands specific for loop breaking and scan insertion in Circuit models since v3.2.3
insertCircuitScan(work)– insert scan for path breaker components into the CircuitworkinsertCircuitTestableGates(work)– insert testable buffers/inverters for path breaker components in the CircuitworktagCircuitPathBreakerAutoAppend(work)– append path breaker pins as necessary to complete cycle breaking in the CircuitworktagCircuitPathBreakerAutoDiscard(work)– discard path breaker pins that are redundant for cycle breaking in the CircuitworktagCircuitPathBreakerClearAll(work)– clear all path breaker pins in the CircuitworktagCircuitPathBreakerSelfloopPins(work)– path breaker output pins within self-loops in the CircuitworksetCircuitPinPathBreaker(work, ref, value)– setvalueas Path breaker attribute for pinrefin Circuitworksince v3.4.0getCircuitPinPathBreaker(work, ref)– get Path breaker attribute for pinrefin Circuitworksince v3.4.0
- Commands specific for DFS models
transformDfsContractComponent(work)– transform the DFSworkby contracting selected componentstransformDfsMergeComponent(work)– transform the DFSworkby merging selected componentstransformDfsSplitComponent(work)– transform the DFSworkby splitting selected components since v3.5.2transformDfsWagging2Way(work)– transform the DFSworkby applying 2-way wagging to the selected pipeline sectiontransformDfsWagging3Way(work)– transform the DFSworkby applying 3-way wagging to the selected pipeline sectiontransformDfsWagging4Way(work)– transform the DFSworkby applying 4-way wagging to the selected pipeline section
- Commands specific for FSM and FST models
transformFsmContractState(work)– transform the FSM/FSTworkby contracting selected statestransformFsmSplitState(work)– transform the FSM/FSTworkby splitting selected states since v3.5.2- transformFsmMergeState
(work)– transform the FSM/FSTworkby merging selected states
- Commands specific for Petri net and (if explicitly stated) for derived models
transformPetriCollapseProxy(work)– transform the Petri net (or derived model, e.g.STG)workby collapsing selected (or all) proxy placestransformPetriContractTransition(work)– transform the Petri networkby contracting a selected transitiontransformPetriDirectedArcToReadArc(work)– transform the Petri net (or derived model, e.g.STG)workby converting selected arcs to read-arcstransformPetriDualArcToReadArc(work)– transform the Petri net (or derived model, e.g.STG)workby converting selected (or all) dual producing/consuming arcs to read-arcstransformPetriMergePlace(work)– transform the Petri net (or derived model, e.g.STG)workby merging selected placestransformPetriMergeTransition(work)– transform the Petri networkby merging selected transitionstransformPetriProxyDirectedArcPlace(work)– transform the Petri net (or derived model, e.g.STG)workby creating proxies for selected producing/consuming arc placestransformPetriProxyReadArcPlace(work)– transform the Petri net (or derived model, e.g.STG)workby creating selected (or all) proxies for read-arc placestransformPetriReadArcToDualArc(work)– transform the Petri net (or derived model, e.g.STG)workby converting selected (or all) read-arcs to dual producing/consuming arcs
- Commands specific for Policy net models
transformPolicyBundleTransition(work)– transform the Policy networkby bundling selected transitions
- Commands specific for STG models
transformStgContractNamedTransition(work)– transform the STGworkby contracting a selected transitiontransformStgDummyToSignalTransition(work)– transform the STGworkby converting selected dummies to signal transitionstransformStgExpandHandshake(work)– transform the STGworkby expanding selected handshake transitionstransformStgExpandHandshakeReqAck(work)– transform the STGworkby expanding selected handshake transitions by adding _req and _ack suffixestransformStgExplicitPlace(work)– transform the STGworkby making selected (or all) places explicittransformStgImplicitPlace(work)– transform the STGworkby making selected (or all) places implicittransformStgInsertDummy(work)– transform the STGworkby inserting dummies into selected arcstransformStgMergeTransition(work)– transform the STGworkby merging selected transitionstransformStgMirrorSignal(work)– transform the STGworkby mirroring selected (or all) signalstransformStgMirrorTransition(work)– transform the STGworkby mirroring selected (or all) transition signtransformStgSelectAllSignalTransitions(work)– select all transitions of selected signals in the STGworktransformStgSignalToDummyTransition(work)– transform the STGworkby converting selected signal transitions to dummiestransformStgSplitTransition(work)– transform the STGworkby splitting selected transitions since v3.5.2
- Commands specific for WTG models
transformWtgStructureWaveform(work)– transform the WTGworkby structuring the waveforms
Cross-reference commands
These commands are intended for cross-referencing between work files.
- Commands specific for Circuit models
setCircuitEnvironment(work, env)– setenvSTG file or work as an environment for the Circuitworksince v3.2.3getCircuitEnvironment(work)– get an environment STG file for the Circuitworksince v3.2.3setCircuitComponentRefinement(work, ref, path)– setpathfile as refinement for componentrefin Circuitworksince v3.3.7getCircuitComponentRefinement(work, ref)– get path to refinement file for componentrefin Circuitworksince v3.3.7
- Commands specific for STG models
setStgRefinement(work, path)– setpathfile as refinement for STGworksince v3.3.7getStgRefinement(work)– get path to refinement file for STGworksince v3.3.7
Script examples
Basic
- stg-transform.js
// Mirror signals and untoggle transitions of STG model inStgWork = load("in.stg.work"); transformStgMirrorSignal(inStgWork); outStgWork = convertStgUntoggle(inStgWork); save(outStgWork, "out.stg.work"); exit();
- buck-synth.js
// Complex gate implementation for basic buck controller stgWork = load("buck.stg.work"); circuitWork = synthComplexGatePetrify(stgWork); save(circuitWork, "buck.circuit.work"); exportVerilog(circuitWork, "buck.v"); exit();
- workspace-info.js
// Print info for each loaded work and convert its title to upper case for each (work in getWorks()) { title = work.getTitle(); print("Info for " + title); print(" * Descriptor: " + getModelDescriptor(work)); print(" * File: " + getWorkFile(work).getName()); setModelTitle(work, title.toUpperCase()); print(" * Title: " + getModelTitle(work); }
Advanced
- synth.js
// Technology mapping of the specified .g files whose names are passed // without extension, as follows: // workcraft -dir:WORKING_DIRECTORY_PATH -exec:synth.js TEST1 TEST2 setConfigVar("CircuitSettings.gateLibrary", "path-to-genlib-file"); for each (name in args) { stgWork = import(name + ".g"); if (stgWork == null) { eprint("STG work loading failed!"); exit(); } if (checkStgCsc(stgWork) == true) { cscStgWork = stgWork; } else { cscStgWork = resolveCscConflictPetrify(stgWork); if (cscStgWork == null) { eprint("CSC conflict resolution failed!"); exit(); } save(cscStgWork, "vme-csc.stg.work"); } tmCircuitWork = synthTechnologyMappingMpsat(cscStgWork); if (tmCircuitWork == null) { eprint("Circuit synthesis failed!"); exit(); } if (checkCircuitCombined(tmCircuitWork) == true) { exportVerilog(tmCircuitWork, name + ".v"); } else { eprint("Circuit verification failed!"); } } exit();
- reset.js
// Define circuit initialisation scheme and insert active-low reset // (requires Workcraft v3.2.3 or newer) work = load("test-tm.circuit.work"); if (checkCircuitCombined(work) != true) { eprint("Circuit verification failed"); exit(); } tagCircuitForcedInitClearAll(work); tagCircuitForcedInitInputPorts(work); tagCircuitForcedInitAutoAppend(work); insertCircuitResetActiveLow(work); if (checkCircuitReset(work) != true) { eprint("Circuit cannot be reset to the required initial state"); exit(); } if (checkCircuitCombined(work) != true) { eprint("Circuit verification failed after reset insertion"); exit(); } exportVerilog(work, "test-tm-reset.v"); exit();