/**CFile*********************************************************************** FileName [partCmd.c] PackageName [part] Synopsis [Command interface for the partition package.] Author [Abelardo Pardo] Copyright [This file was created at the University of Colorado at Boulder. The University of Colorado at Boulder makes no warranty about the suitability of this software for any purpose. It is presented on an AS IS basis.] ******************************************************************************/ #include "partInt.h" static char rcsid[] UNUSED = "$Id: partCmd.c,v 1.22 2009/04/11 01:47:18 fabio Exp $"; /*---------------------------------------------------------------------------*/ /* Variable declarations */ /*---------------------------------------------------------------------------*/ /**Variable******************************************************************** Synopsis [Buffer to store the environment in a setjmp call] SeeAlso [TimeOutHandle] ******************************************************************************/ static jmp_buf timeOutEnv; /**AutomaticStart*************************************************************/ /*---------------------------------------------------------------------------*/ /* Static function prototypes */ /*---------------------------------------------------------------------------*/ static int CommandBuildPartitionMdds(Hrc_Manager_t ** hmgr, int argc, char ** argv); static int CommandPrintPartition(Hrc_Manager_t **hmgr, int argc, char **argv); static int CommandPrintPartitionStats(Hrc_Manager_t **hmgr, int argc, char **argv); static void TimeOutHandle(void); /**AutomaticEnd***************************************************************/ /*---------------------------------------------------------------------------*/ /* Definition of exported functions */ /*---------------------------------------------------------------------------*/ /**Function******************************************************************** Synopsis [Initializes the partitioning package.] SideEffects [] SeeAlso [Part_End] ******************************************************************************/ void Part_Init(void) { Cmd_CommandAdd("build_partition_mdds", CommandBuildPartitionMdds, 0/* doesn't change network */); Cmd_CommandAdd("print_partition", CommandPrintPartition, 0/* doesn't change network */); Cmd_CommandAdd("print_partition_stats", CommandPrintPartitionStats, 0/* doesn't change network*/); } /* End of Part_Init */ /**Function******************************************************************** Synopsis [Ends the partitioning package.] SideEffects [] SeeAlso [Part_Init] ******************************************************************************/ void Part_End(void) { } /* End of Part_End */ /*---------------------------------------------------------------------------*/ /* Definition of internal functions */ /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ /* Definition of static functions */ /*---------------------------------------------------------------------------*/ /**Function******************************************************************** Synopsis [Implements the build_partition_mdds command.] Description [The data structure needed to store the information related to the partitioning process will be stored in a graph_t structure that will become part of the network. This procedure checks if the network has already registered this application. If not, a new structure is allocated. After this process, depending on the type of method specified in the command line, the specific routine is executed. The user may set the specific flag partition_method as the default to be used whenever no method is specified in the command line. If no flag is defined, the frontier method will be used.] CommandName [build_partition_mdds] CommandSynopsis [build a partition of MDDs for the flattened network] CommandArguments [\[-h\] \[-i\] \[-n <list>\] \[-s <num>\] \[-t <seconds>\] \[-v\] \[<method>\]] CommandDescription [Build the MDDs of a flattened network. Depending on the method selected, the MDDs for the combinational outputs (COs) are built in terms of either the combinational inputs (CIs) or in terms of some subset of intermediate nodes of the network. The MDDs built are stored in a DAG called a "partition". The vertices of a partition correspond to the CIs, COs, and any intermediate nodes used. Each vertex has a multi-valued function (represented by MDDs) expressing the function of the corresponding network node in terms of the partition vertices in its transitive fanin. Hence, the MDDs of the partition represent a partial collapsing of the network.
This command must be preceded by the commands flatten_hierarchy and static_order. The partition built is stored with the network for use by other commands, such as simulate, compute_reach, model_check, etc. This command has no affect when invoked on a network that already has a partition. To remove the existing partition of a network, reinvoke flatten_hierarchy.
The choice of method determines which intermediate nodes are used. The inout method represents one extreme where no intermediate nodes are used, and total represents the other extreme where every node in the network has a corresponding vertex in the partition. If no method is specified on the command line, then the value of the flag partition_method is used (this flag is set by the command set partition_method), unless it does not have a value, in which case the forntier method is used. The different methods available are:
]
SideEffects [Registers in the network the partition application with
the key specified by PART_NETWORK_APPL_KEY]
SeeAlso [Ntk_NetworkAddApplInfo]
******************************************************************************/
static int
CommandBuildPartitionMdds(
Hrc_Manager_t ** hmgr,
int argc,
char ** argv)
{
static Part_PartitionMethod method;
static boolean inTermsOfLeaves;
lsList nodeList = lsCreate();
graph_t *partition;
static int verbose;
static int sanityCheck;
static int timeOutPeriod;
int c;
int length;
char *methodString;
char *modelName;
Hrc_Node_t *currentNode;
Ntk_Network_t *network = Ntk_HrcManagerReadCurrentNetwork(*hmgr);
char *nodeName;
char *tmpNodeName;
char *realName;
FILE *nodeFile;
static boolean fileUsed;
fileUsed = FALSE;
inTermsOfLeaves = FALSE;
verbose = 0;
sanityCheck = 0;
timeOutPeriod = 0;
nodeFile = NIL(FILE);
util_getopt_reset();
while ((c = util_getopt(argc, argv, "f:hvin:s:t:")) != EOF) {
switch(c) {
case 'f':
fileUsed = TRUE;
nodeFile = Cmd_FileOpen(util_optarg, "r", &realName, 1);
FREE(realName);
if (nodeFile == NIL(FILE)){
(void)fprintf(vis_stderr,"Cannot open %s\n", util_optarg);
lsDestroy(nodeList, (void (*)(lsGeneric))0);
return 1;
}
else{
tmpNodeName = ALLOC(char, 512);
while(fscanf(nodeFile, "%s\n", tmpNodeName) != EOF){
if(*tmpNodeName != '#'){
nodeName = ALLOC(char, strlen(tmpNodeName) + 2);
sprintf(nodeName, "%s", tmpNodeName);
lsNewEnd(nodeList, (lsGeneric)nodeName, NIL(lsHandle));
}
}
FREE(tmpNodeName);
}
break;
case 'h':
goto usage;
case 'i':
inTermsOfLeaves = TRUE;
break;
case 'v':
verbose = 1;
break;
case 's':
sanityCheck = atoi(util_optarg);
break;
case 't':
timeOutPeriod = atoi(util_optarg);
break;
case 'n':
length = strlen(util_optarg);
for(c = 0; c < length; c++) {
if (util_optarg[c] == ',') {
util_optarg[c] = 0;
} /* End of if */
} /* End of for */
c = 0;
while (c < length) {
lsNewEnd(nodeList, &util_optarg[c], NIL(lsHandle));
while (util_optarg[c++] != 0);
} /* End of while */
break;
default:
goto usage;
}
}
if (argc == util_optind) {
/* No method specified. Choosing default */
methodString = Cmd_FlagReadByName("partition_method");
if (methodString == NIL(char)) {
methodString = "default";
}
}
else {
methodString = argv[util_optind];
}
if (strcmp(methodString,"inout") == 0) {
method = Part_InOut_c;
if (lsLength(nodeList) != 0) {
(void) fprintf(vis_stderr, "Ignoring provided list of nodes in
If no argument is specified on the command line, the output is written to
the standard output.
Command options:
\tComma separated list of network nodes to preserve in the\n");
(void) fprintf(vis_stderr, " \tpartitioning. It only matters if the partial method has been\n");
(void) fprintf(vis_stderr, " \tselected.\n");
(void) fprintf(vis_stderr, " -f
]
******************************************************************************/
static int
CommandPrintPartition(
Hrc_Manager_t **hmgr,
int argc,
char **argv)
{
FILE *fp;
int c, status;
graph_t *partition;
Ntk_Network_t *network = Ntk_HrcManagerReadCurrentNetwork(*hmgr);
util_getopt_reset();
while ((c = util_getopt(argc,argv,"h")) != EOF){
switch(c){
case 'h':
goto usage;
default:
goto usage;
}
}
/* Check if the network has been read in */
if (network == NIL(Ntk_Network_t)) {
return 1;
}
/* Check if there is a partition attached to the network */
partition = (graph_t *) Ntk_NetworkReadApplInfo(network,
PART_NETWORK_APPL_KEY);
if (partition == NIL(graph_t)) {
(void) fprintf(vis_stderr, "No partition has been created for this network.\n");
return 1;
}
if (argc == 1) {
fp = vis_stdout;
}
else if (argc == 2) {
fp = Cmd_FileOpen(*(++argv), "w", NIL(char *), /* silent */ 1);
if (fp == NIL(FILE)) {
(void) fprintf(vis_stderr, "Cannot write to %s\n", *argv);
return 1;
}
}
else {
goto usage;
}
error_init();
status = PartPartitionPrint(fp, partition);
(void) fprintf(vis_stderr, "%s", error_string());
fflush(fp);
/* If we opened a file before, close it */
if (argc == 2) {
(void) fclose(fp);
}
return (status ? 0 : 1);
usage:
(void) fprintf(vis_stderr, "usage: print_partition [-h] [file]\n");
(void) fprintf(vis_stderr, " -h\t\tprint the command usage\n");
return 1;
} /* End of CommandPrintPartition */
/**Function********************************************************************
Synopsis [Command level routine to print some stats of the partition DAG.]
SideEffects []
SeeAlso [CommandBuildPartitionMdds]
CommandName [print_partition_stats]
CommandSynopsis [print statistics about the partition graph]
CommandArguments [\[-h\] \[-n\]]
CommandDescription [Print statistics about the partition currently attached
to the network, such as: