tab2sim.c 3.31 KB
/*
 * tab2sim.c -- convert tabular file to Compass Qsim script
 *
 */

#define MAIN

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>

#include "tab2sim.h"


extern FILE *yyin;
extern int StepTime;
extern SigDef Signal[MAX_SIGNALS];

#ifdef __linux__
FILE *Vecfp = 0; /* vector file */
#else
FILE *Vecfp = stdout; /* vector file */
#endif
int   EchoComments = 1;
int   VerilogMode  = 0;
int   Clocks2Dump  = 20;
int   FloatPrec    = 2;
float Clocks2Test  = 0;

#define OPTSTR          "ucvo:d:p:t:"

void
  print_usage(char *prog)
{
  printf("Usage: %s [-o <outfile>] [-c] [-v] [-d <#clocks>] [-p <flt_prec>] [-t <#clocks>]  infile\n", prog);
  printf("  -o <outfile> is name of output sim file including extension\n");
  printf("  -d <#clocks> is number of clocks between number of cycles print (default 20)\n");
  printf("  -t <#clocks> is number of clocks before allowing testing (based on the frequency of the vectors)\n");
  printf("  -p <flt_prec> is number of digits to use for float precision in prints (default 2)\n");
  printf("  -c disables echoing of comments from .tab file\n");
  printf("  -v sample signals the way Verilog does\n");
}



int main(int argc, char **argv)		/* Main entry */
{
   FILE *txtin = NULL;
   char *fname, *outfilename;
   int c;

   extern char *optarg;
   extern int optind, opterr;

  if(argc < 2) {
    print_usage(argv[0]);
    return (0);
  }

   /*
    *  Parser Args
    */

   while ((c = getopt(argc, argv, OPTSTR)) != -1) 
   {
      switch(c) {

      case 'c':
	EchoComments = 0;
	break;

      case 'v':
	VerilogMode = 1;
	break;

      case 'p':
	FloatPrec = atoi(optarg);
	break;

      case 'd':
	Clocks2Dump = atoi(optarg);
	if(Clocks2Dump <= 0) Clocks2Dump = 1;
	break;

      case 't':
	Clocks2Test = atof(optarg);
	if(Clocks2Test < 0) Clocks2Test = 0;
	break;

      case 'o':
	if((Vecfp = fopen(optarg, "w")) == NULL)
	{
          perror(optarg);
          return (1);
	}
        outfilename = optarg;
	break;
      case 'u':
        print_usage(argv[0]);
        return (0);
        break;

      }
   }
#ifdef __linux__
   if (!Vecfp) Vecfp = stderr;
#endif

   if (optind < argc)
   {
      if ((txtin = fopen(argv[optind], "r")) == NULL)
      {
         perror(argv[optind]);
         return (1);
      }
      yyin = txtin;
   }
   else
   {
      yyin = stdin;
   }


   /* print header */
   fprintf(Vecfp,"####################################################\n");
   fprintf(Vecfp,"#  this file produced by tab2sim                   #\n");
   fprintf(Vecfp,"#                                                  #\n");
   fprintf(Vecfp,"#  tab2sim written by Rob Moore                    #\n");
   fprintf(Vecfp,"#  Silicon Graphics, Inc.                          #\n");
   fprintf(Vecfp,"#  November  1994                                  #\n");
   fprintf(Vecfp,"####################################################\n");
   fprintf(Vecfp,"\n");
   fprintf(Vecfp,"alias i inputs\n");
   fprintf(Vecfp,"alias c charged\n");
   fprintf(Vecfp,"alias t test\n\n");
   fprintf(Vecfp,"forced high vdd\n");
   fprintf(Vecfp,"forced low vss\n\n");

   /* print changes in signals */
   yyparse();

   /*
    * cleanup 
    */
   if (StepTime)
     fprintf(Vecfp,"s %.*f\n", FloatPrec, StepTime);
 
   if (txtin) (void) fclose(txtin);
   if (Vecfp) (void) fclose(Vecfp);
   exit(0);


}

#undef MAIN