Beispiel #1
0
static PLI_INT32 from_myhdl_calltf(PLI_BYTE8 *user_data)
{
  vpiHandle reg_iter, reg_handle;
  s_vpi_time verilog_time_s;
  char buf[MAXLINE];
  char s[MAXWIDTH];
  int n;

  static int from_myhdl_flag = 0;

  if (from_myhdl_flag) {
    vpi_printf("ERROR: $from_myhdl called more than once\n");
    vpi_control(vpiFinish, 1);  /* abort simulation */
    return(0);
  }
  from_myhdl_flag = 1;

  init_pipes();

  verilog_time_s.type = vpiSimTime;
  vpi_get_time(NULL, &verilog_time_s);
  verilog_time = timestruct_to_time(&verilog_time_s);
  if (verilog_time != 0) {
    vpi_printf("ERROR: $from_myhdl should be called at time 0\n");
    vpi_control(vpiFinish, 1);  /* abort simulation */
    return(0);
  }
  sprintf(buf, "FROM 0 ");
  pli_time = 0;
  delta = 0;

  from_myhdl_systf_handle = vpi_handle(vpiSysTfCall, NULL);
  reg_iter = vpi_iterate(vpiArgument, from_myhdl_systf_handle);
  while ((reg_handle = vpi_scan(reg_iter)) != NULL) {
    if (vpi_get(vpiType, reg_handle) != vpiReg) {
      vpi_printf("ERROR: $from_myhdl argument %s should be a reg\n",
		 vpi_get_str(vpiName, reg_handle));
      vpi_control(vpiFinish, 1);  /* abort simulation */
      return(0);
    }
    strcat(buf, vpi_get_str(vpiName, reg_handle));
    strcat(buf, " ");
    sprintf(s, "%d ", vpi_get(vpiSize, reg_handle));
    strcat(buf, s);
    vpi_free_object(reg_handle);
  }
  //vpi_free_object(reg_iter);

  n = write(wpipe, buf, strlen(buf));  

  if ((n = read(rpipe, buf, MAXLINE)) == 0) {
    vpi_printf("Info: MyHDL simulator down\n");
    vpi_control(vpiFinish, 1);  /* abort simulation */
    return(0);
  }
  assert(n > 0);
  buf[n] = '\0';

  return(0);
}
Beispiel #2
0
static int s1AssemblerCalltf(char*user_data)
{
  s_vpi_value value_s;
  vpiHandle systf_handle;
  vpiHandle arg_itr;
  vpiHandle arg_handle;
  char *s;

  systf_handle = vpi_handle(vpiSysTfCall, NULL);
  if ((arg_itr = vpi_iterate(vpiArgument, systf_handle)) == NULL) {
    vpi_printf("ERROR: $s1Assembler failed to obtain systf arg handle\n");
    return(0);
  }

  arg_handle = vpi_scan(arg_itr);
  value_s.format = vpiStringVal;
  vpi_get_value(arg_handle, &value_s);
  
  //vpi_printf("hello string size: %0d\n", (int)strlen(value_s.value.str));
  s = calloc(strlen(value_s.value.str), sizeof(char));
  memset(s, '\0',strlen(value_s.value.str));
  strncpy(s,value_s.value.str, strlen(value_s.value.str));
  vpi_printf("[ s1Assembler ] argument: %s\n", s);

  {
    parserData *parser;
    parser = ParserNew(s);
    ParserStart(parser);
    ParserDelete(&parser);
  }

  free(s);  
  return 0;
}
Beispiel #3
0
static PLI_INT32 sys_dumpfile_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);
      char *path;

        /* $dumpfile must be called before $dumpvars starts! */
      if (dumpvars_status != 0) {
	    char msg[64];
	    snprintf(msg, sizeof(msg), "FST warning: %s:%d:",
	             vpi_get_str(vpiFile, callh),
	             (int)vpi_get(vpiLineNo, callh));
	    msg[sizeof(msg)-1] = 0;
	    vpi_printf("%s %s called after $dumpvars started,\n", msg, name);
	    vpi_printf("%*s using existing file (%s).\n",
	               (int) strlen(msg), " ", dump_path);
	    vpi_free_object(argv);
	    return 0;
      }

      path = get_filename(callh, name, vpi_scan(argv));
      vpi_free_object(argv);
      if (! path) return 0;

      if (dump_path) {
	    vpi_printf("FST warning: %s:%d: ", vpi_get_str(vpiFile, callh),
	               (int)vpi_get(vpiLineNo, callh));
	    vpi_printf("Overriding dump file %s with %s.\n", dump_path, path);
	    free(dump_path);
      }
      dump_path = path;

      return 0;
}
Beispiel #4
0
/*
 * routine to build an error indication string 
 */
int my_error_handler(struct t_cb_data *cbp)
{
 struct t_vpi_error_info einfotab;
 struct t_vpi_error_info *einfop;
 char s1[128];

 einfop = &einfotab;
 vpi_chk_error(einfop);

 if (einfop->state == vpiCompile) strcpy(s1, "vpiCompile");
 else if (einfop->state == vpiPLI) strcpy(s1, "vpiPLI");
 else if (einfop->state == vpiRun) strcpy(s1, "vpiRun");
 else strcpy(s1, "**unknown**");

 vpi_printf("**ERR(%s) %s (level %d) at **%s(%d):\n  %s\n",
  einfop->code, s1, einfop->level, einfop->file, einfop->line,
  einfop->message);

 /* if serious error give up */
 if (einfop->level == vpiSystem || einfop->level == vpiInternal)
  {
   vpi_printf("**FATAL: encountered error - giving up\n");
   vpi_sim_control(vpiFinish, 0);
  }
 /* will just return and leave 0 in vpi_fopen return value */
 return(0);
}
Beispiel #5
0
/* For system tasks/functions that do not take an argument. */
PLI_INT32 sys_no_arg_compiletf(ICARUS_VPI_CONST PLI_BYTE8 *name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);

      /* Make sure there are no arguments. */
      if (argv != 0) {
	    char msg[64];
	    unsigned argc;

	    snprintf(msg, sizeof(msg), "ERROR: %s:%d:",
	             vpi_get_str(vpiFile, callh),
	             (int)vpi_get(vpiLineNo, callh));
	    msg[sizeof(msg)-1] = 0;

	    argc = 0;
	    while (vpi_scan(argv)) argc += 1;

            vpi_printf("%s %s does not take an argument.\n", msg, name);
            vpi_printf("%*s Found %u extra argument%s.\n",
	               (int) strlen(msg), " ", argc, argc == 1 ? "" : "s");
            vpi_control(vpiFinish, 1);
      }

      return 0;
}
Beispiel #6
0
/*
 * Routine to return the current hierarchical path (implements %m).
 */
static int scan_format_module_path(vpiHandle callh, vpiHandle argv,
                                   unsigned suppress_flag, PLI_BYTE8 *name)
{
      vpiHandle scope, arg;
      char *module_path;
      s_vpi_value val;

	/* If this format code is being suppressed then just return that no
	 * arguments were used. */
      if (suppress_flag) return -1;

	/* We must have a variable to put the hierarchical path into. */
      arg = vpi_scan(argv);
      if (! arg) {
	    vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
	               (int)vpi_get(vpiLineNo, callh));
	    vpi_printf("%s() ran out of variables for %%m format code.", name);
	    vpi_control(vpiFinish, 1);
	    return 0;
      }

	/* Get the current hierarchical path. */
      scope = vpi_handle(vpiScope, callh);
      assert(scope);
      module_path = vpi_get_str(vpiFullName, scope);

	/* Put the hierarchical path into the variable. */
      val.format = vpiStringVal;
      val.value.str = module_path;
      vpi_put_value(arg, &val, 0, vpiNoDelay);

	/* We always consume one variable if it is available. */
      return 1;
}
Beispiel #7
0
static PLI_INT32 my_hello_calltf(PLI_BYTE8 *xx)
#endif
{
      s_vpi_value value;

      (void)xx;  /* Parameter is not used. */

      vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, sys);
      vpiHandle arg;

      if (argv == 0) {
	    vpi_printf("ERROR: $hello_poke requires one argument\n");
	    vpi_sim_control(vpiFinish, 1);
	    return 0;
      }

      arg = vpi_scan(argv);
      assert(arg != 0);

      value.format = vpiStringVal;
      value.value.str = "Hello";

      vpi_put_value(arg, &value, 0, vpiNoDelay);

      arg = vpi_scan(argv);
      if (arg != 0) {
	    vpi_printf("ERROR: too many arguments to $hello_poke\n");
	    vpi_sim_control(vpiFinish, 1);
      }

      return 0;
}
static int sys_fgets_compiletf(char*name)
{
      vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, sys);
      vpiHandle item = vpi_scan(argv);
      int type;

      if (item == 0) {
	    vpi_printf("%s: string parameter missing.\n", name);
	    return 0;
      }

      type = vpi_get(vpiType, item);

      if (type != vpiReg) {
	    vpi_printf("%s: string parameter must be a reg.\n", name);
	    vpi_free_object(argv);
	    return 0;
      }

      item = vpi_scan(argv);
      if (item == 0) {
	    vpi_printf("%s: mcd parameter missing.\n", name);
	    return 0;
      }

	/* That should be all the arguments. */
      item = vpi_scan(argv);
      assert(item == 0);

      return 0;
}
static int sys_ungetc_compiletf(char*name)
{
      int type;
      vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, sys);
      vpiHandle item = vpi_scan(argv);

      if (item == 0) {
	    vpi_printf("%s: mcd parameter missing.\n", name);
	    return 0;
      }

      type = vpi_get(vpiType, item);
      switch (type) {
	    case vpiReg:
	    case vpiRealVal:
	    case vpiIntegerVar:
	      break;
	    default:
	      vpi_printf("ERROR: %s mcd parameter must be of integral", name);
	      vpi_printf(", got vpiType=%d\n", type);
	      vpi_free_object(argv);
	      return 0;
      }

      return 0;
}
Beispiel #10
0
static void param_by_name(vpiHandle scope, const char*key)
{
      vpiHandle iter = vpi_iterate(vpiParameter, scope);
      vpiHandle item;

      while ( (item = vpi_scan(iter)) ) {

	    s_vpi_value value;

	    if (strcmp(key, vpi_get_str(vpiName,item)) != 0)
		  continue;

	    vpi_printf("%8s: ", vpi_get_str(vpiName, item));

	    switch (vpi_get(vpiConstType, item)) {
		case vpiStringConst:
		  value.format = vpiStringVal;
		  vpi_get_value(item, &value);
		  vpi_printf("%s", value.value.str);
		  break;
		case vpiBinaryConst:
		  value.format = vpiBinStrVal;
		  vpi_get_value(item, &value);
		  vpi_printf("%s", value.value.str);
		  break;
		default:
		  break;
	    }

	    vpi_printf("\n");
      }
}
/*
 * Implement $fclose system function
 */
static int sys_fclose_calltf(char *name)
{
      unsigned int mcd;
      int type;
      s_vpi_value value;

      vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, sys);
      vpiHandle item = vpi_scan(argv);

      if (item == 0) {
	    vpi_printf("%s: mcd parameter missing.\n", name);
	    return 0;
      }
      type = vpi_get(vpiType, item);
      switch (type) {
	    case vpiReg:
	    case vpiRealVal:
	    case vpiIntegerVar:
	      break;
	    default:
	      vpi_printf("ERROR: %s mcd parameter must be of integral type",
		name);
	      vpi_printf(", got vpiType=%d\n", type);
	      vpi_free_object(argv);
	      return 0;
      }

      value.format = vpiIntVal;
      vpi_get_value(item, &value);
      mcd = value.value.integer;

      vpi_mcd_close(mcd);
      return 0;
}
Beispiel #12
0
/*
 * Implement $fclose system function
 */
static PLI_INT32 sys_fclose_calltf(PLI_BYTE8*name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);
      vpiHandle fd = vpi_scan(argv);
      s_vpi_value val;
      PLI_UINT32 fd_mcd;
      errno = 0;

      vpi_free_object(argv);

	/* Get the file/MC descriptor and verify that it is valid. */
      val.format = vpiIntVal;
      vpi_get_value(fd, &val);
      fd_mcd = val.value.integer;

      if ((! IS_MCD(fd_mcd) && vpi_get_file(fd_mcd) == NULL) ||
          ( IS_MCD(fd_mcd) && vpi_mcd_printf(fd_mcd, "%s", "") == EOF) ||
          (! fd_mcd)) {
	    vpi_printf("WARNING: %s:%d: ", vpi_get_str(vpiFile, callh),
	               (int)vpi_get(vpiLineNo, callh));
	    vpi_printf("invalid file descriptor/MCD (0x%x) given to %s.\n",
	               (unsigned int)fd_mcd, name);
	    errno = EBADF;
	    return 0;
      }

	/* We need to cancel any active $fstrobe()'s for this FD/MCD.
	 * For now we check in the strobe callback and skip the output
	 * generation when needed. */
      vpi_mcd_close(fd_mcd);

      return 0;
}
Beispiel #13
0
static void error_message(vpiHandle callh, const char* msg)
{
    vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
               (int)vpi_get(vpiLineNo, callh));
    vpi_printf(msg, vpi_get_str(vpiName, callh));
    vpi_control(vpiFinish, 1);
}
Beispiel #14
0
/*
 * check - must be at end of compile after sim data structure set up
 */
PLI_INT32 hello_chk(struct t_cb_data *cbp)
{
 vpiHandle href, iref;
 struct t_vpi_error_info einfotab;

 vpi_printf("... executing EndOfCompile callback for checking.\n");
 href = vpi_handle(vpiSysTfCall, NULL); 
 if (vpi_chk_error(&einfotab))
  {  
   if (href != NULL) vpi_printf("... why is handle not nil\n"); 
   vpi_printf("** ERR: $hello PLI 2.0 can not access systf call handle\n");
   prtvpiemsg(&einfotab);
   /* vpi_sim_control(vpiFinish, 0); */
  }
 iref = vpi_iterate(vpiArgument, href);
 if (vpi_chk_error(&einfotab))
  {
   vpi_printf("** ERR: vpi_iterate error:\n");
   prtvpiemsg(&einfotab);
   vpi_sim_control(vpiFinish, 0);
  }
 if (iref != NULL) 
  { 
   vpi_printf(
    "** ERR: $hello PLI 2.0 task called with %d arguments but none allowed",
    count_systf_args(iref));
   vpi_free_object(iref);
   vpi_sim_control(vpiFinish, 0);
  }
 return(0);
}
Beispiel #15
0
static PLI_INT32 sys_fscanf_compiletf(ICARUS_VPI_CONST PLI_BYTE8 *name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);

	/* Check that there are arguments. */
      if (argv == 0) {
	    vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
	               (int)vpi_get(vpiLineNo, callh));
	    vpi_printf("%s requires at least three argument.\n", name);
	    vpi_control(vpiFinish, 1);
	    return 0;
      }

	/* The first argument must be a file descriptor. */
      if (! is_numeric_obj(vpi_scan(argv))) {
	    vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
	               (int)vpi_get(vpiLineNo, callh));
	    vpi_printf("%s's first argument (fd) must be numeric.\n", name);
	    vpi_control(vpiFinish, 1);
	    vpi_free_object(argv);
	    return 0;
      }

      if (sys_check_args(callh, argv, name)) vpi_control(vpiFinish, 1);
      return 0;
}
Beispiel #16
0
static PLI_INT32 simbus_connect_compiletf(char*my_name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);

      /* Check that there is an argument and that it is a string. */
      if (argv == 0) {
            vpi_printf("ERROR: %s line %d: ", vpi_get_str(vpiFile, callh),
                       (int)vpi_get(vpiLineNo, callh));
            vpi_printf("%s requires a single string argument.\n", my_name);
            vpi_control(vpiFinish, 1);
            return 0;
      }

      if (! is_string_obj(vpi_scan(argv))) {
            vpi_printf("ERROR: %s line %d: ", vpi_get_str(vpiFile, callh),
                       (int)vpi_get(vpiLineNo, callh));
            vpi_printf("%s's argument must be a constant string.\n", my_name);
            vpi_control(vpiFinish, 1);
      }

      /* Make sure there are no extra arguments. */
      while (vpi_scan(argv)) { ; }

      return 0;
}
Beispiel #17
0
static PLI_INT32 sys_fscanf_calltf(ICARUS_VPI_CONST PLI_BYTE8 *name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);
      s_vpi_value val;
      struct byte_source src;
      FILE *fd;
      errno = 0;

      val.format = vpiIntVal;
      vpi_get_value(vpi_scan(argv), &val);
      fd = vpi_get_file(val.value.integer);
      if (!fd) {
	    vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
	               (int)vpi_get(vpiLineNo, callh));
	    vpi_printf("invalid file descriptor (0x%x) given to %s.\n",
	               (int)val.value.integer, name);
	    errno = EBADF;
	    val.format = vpiIntVal;
	    val.value.integer = EOF;
	    vpi_put_value(callh, &val, 0, vpiNoDelay);
	    vpi_free_object(argv);
	    return 0;
      }

      src.str = 0;
      src.fd = fd;
      scan_format(callh, &src, argv, name);

      return 0;
}
Beispiel #18
0
static PLI_INT32 simbus_poll_compiletf(char*my_name)
{
      vpiHandle sys  = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, sys);

      vpiHandle bus_h = vpi_scan(argv);
      if (bus_h == 0) {
	    vpi_printf("%s:%d: Missing argument to $simbus_poll function\n",
		       vpi_get_str(vpiFile, sys), (int)vpi_get(vpiLineNo, sys));
	    vpi_control(vpiFinish, 1);
	    return 0;
      }

      vpiHandle trig = vpi_scan(argv);
      if (trig == 0) {
	    vpi_printf("%s:%d: Missing argument to $simbus_poll function\n",
		       vpi_get_str(vpiFile, sys), (int)vpi_get(vpiLineNo, sys));
	    vpi_control(vpiFinish, 1);
	    return 0;
      }

      if (vpi_get(vpiType, trig) != vpiReg || vpi_get(vpiSize, trig) != 1) {
	    vpi_printf("%s:%d: Trigger argument to $simbus_poll must be a single-bit reg.\n",
		       vpi_get_str(vpiFile, sys), (int)vpi_get(vpiLineNo, sys));
	    vpi_control(vpiFinish, 1);
	    return 0;
      }

      vpi_free_object(argv);

      return 0;
}
Beispiel #19
0
static PLI_INT32 one_darray_arg_compiletf(ICARUS_VPI_CONST PLI_BYTE8*name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv;
      vpiHandle arg;

      argv = vpi_iterate(vpiArgument, callh);
      if (argv == 0) {
	    vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
	               (int)vpi_get(vpiLineNo, callh));
	    vpi_printf("%s requires a string argument.\n", name);
	    vpi_control(vpiFinish, 1);
	    return 0;
      }

      arg =  vpi_scan(argv);
      if (arg == 0) return 0;

      arg = vpi_scan(argv);
      if (arg != 0) {
	    vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
	               (int)vpi_get(vpiLineNo, callh));
	    vpi_printf("%s has too many arguments.\n", name);
	    vpi_control(vpiFinish, 1);
	    return 0;
      }

      return 0;
}
Beispiel #20
0
static int check_integer_constant(char*name, vpiHandle handle)
{
    if (vpi_get(vpiType, handle) != vpiConstant) {
        vpi_printf("ERROR: %s parameter must be a constant (vpiType=%d)\n",
                   name, vpi_get(vpiType, handle));
        return 0;
    }

    switch(vpi_get(vpiConstType, handle)) {
    case vpiDecConst:
    case vpiBinaryConst:
    case vpiOctConst:
    case vpiHexConst:
        return 1;
        break;

    /* We rely on vpi_get_value for reals and strings to return a correct */
    /* integer value when this is requested. So only a warning is generated. */
    case vpiRealConst:
        vpi_printf("Warning: real supplied to %s instead of integer.\n", name);
        return 1;
        break;

    case vpiStringConst:
        vpi_printf("Warning: string supplied to %s instead of integer.\n", name);
        return 1;
        break;
    }

    /* switch statement covers all possibilities. Code should never come here... */
    assert(0);
    return 0;
}
Beispiel #21
0
static PLI_INT32 sys_sdf_annotate_compiletf(PLI_BYTE8*name)
{
      check_command_line_args();

      vpiHandle sys = vpi_handle(vpiSysTfCall,0);
      vpiHandle argv = vpi_iterate(vpiArgument, sys);

      vpiHandle path = vpi_scan(argv);
      if (path == 0) {
	    vpi_printf("SDF ERROR: First argument of %s is required.\n", name);
	    vpi_control(vpiFinish, 1);
	    return 0;
      }

      assert(path);

      vpiHandle scope = vpi_scan(argv);
      if (scope == 0)
	    return 0;

      if (vpi_get(vpiType,scope) != vpiModule) {
	    vpi_printf("SDF ERROR: The second argument of %s"
		       " must be a module instance.\n", name);
	    vpi_control(vpiFinish, 1);
      }

      vpi_free_object(argv);

      return 0;
}
Beispiel #22
0
/*
 * This function makes sure the handle is of an object that can get a
 * string value for a file name.
 */
static int check_file_name(const char*name, vpiHandle item)
{
    switch (vpi_get(vpiType, item)) {

    case vpiConstant:
        if (vpi_get(vpiConstType, item) != vpiStringConst) {
            vpi_printf("ERROR: %s argument 1: file name argument "
                       "must be a string.\n", name);
            return 0;
        }
        break;

    case vpiParameter:
        if (vpi_get(vpiConstType,item) != vpiStringConst) {
            vpi_printf("ERROR: %s argument 1: Parameter %s is "
                       "not a string in this context.\n",
                       name, vpi_get_str(vpiName,item));
            return 0;
        }
        break;

    case vpiReg:
        break;

    default:
        vpi_printf("ERROR: %s argument 1: must be a string\n", name);
        return 0;
    }

    return 1;
}
Beispiel #23
0
static void open_dumpfile(vpiHandle callh)
{
      if (dump_path == 0) dump_path = strdup("dump.lxt");

      dump_file = lt_init(dump_path);

      if (dump_file == 0) {
	    vpi_printf("LXT Error: %s:%d: ", vpi_get_str(vpiFile, callh),
	               (int)vpi_get(vpiLineNo, callh));
	    vpi_printf("Unable to open %s for output.\n", dump_path);
	    vpi_control(vpiFinish, 1);
	    return;
      } else {
	    int prec = vpi_get(vpiTimePrecision, 0);

	    vpi_printf("LXT info: dumpfile %s opened for output.\n",
	               dump_path);

	    assert(prec >= -15);
	    lt_set_timescale(dump_file, prec);

	    lt_set_initial_value(dump_file, 'x');
	    lt_set_clock_compress(dump_file);

            atexit((void(*)(void))close_dumpfile);
      }
}
Beispiel #24
0
static PLI_INT32 sys_sdf_annotate_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);
      FILE *sdf_fd;
      char *fname = get_filename(callh, name, vpi_scan(argv));

      if (fname == 0) return 0;

      sdf_fd = fopen(fname, "r");
      if (sdf_fd == 0) {
	    vpi_printf("WARNING: %s:%d: ", vpi_get_str(vpiFile, callh),
	               (int)vpi_get(vpiLineNo, callh));
	    vpi_printf("Unable to open SDF file \"%s\"."
		       " Skipping this annotation.\n", fname);
	    return 0;
      }

	/* The optional second argument is the scope to annotate. */
      sdf_scope = vpi_scan(argv);
      if (sdf_scope) vpi_free_object(argv);
      else sdf_scope = vpi_handle(vpiScope, callh);

	/* Select which delay to use. */
      sdf_min_typ_max = vpi_get(_vpiDelaySelection, 0);

      sdf_cur_cell = 0;
      sdf_callh = callh;
      sdf_process_file(sdf_fd, fname);
      sdf_callh = 0;

      fclose(sdf_fd);
      free(fname);
      return 0;
}
Beispiel #25
0
/* For system tasks/functions that take a single string argument. */
PLI_INT32 sys_one_string_arg_compiletf(ICARUS_VPI_CONST PLI_BYTE8 *name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);

      /* Check that there is an argument and that it is a string. */
      if (argv == 0) {
            vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
                       (int)vpi_get(vpiLineNo, callh));
            vpi_printf("%s requires a single string argument.\n", name);
            vpi_control(vpiFinish, 1);
            return 0;
      }
      if (! is_string_obj(vpi_scan(argv))) {
            vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
                       (int)vpi_get(vpiLineNo, callh));
            vpi_printf("%s's argument must be a string.\n", name);
            vpi_control(vpiFinish, 1);
      }

      /* Make sure there are no extra arguments. */
      check_for_extra_args(argv, callh, name, "a single string argument", 0);

      return 0;
}
Beispiel #26
0
static PLI_INT32 number_compiletf(PLI_BYTE8 *x)
#endif
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);
      vpiHandle arg;
      char *name;

      s_vpi_value var;

      (void)x;  /* Parameter is not used. */

      if (argv == 0) {
	    vpi_printf("ERROR: missing required numeric argument.\n"),
	    vpi_control(vpiFinish, 1);
	    return 0;
      }
      arg = vpi_scan(argv);

	/* Check to see what vpi_get_value does during compiletf. */
      name = vpi_get_str(vpiName, arg);
      vpi_printf("vpi_get_value (%s):\n", name ? name : "<N/A>");
      var.format = vpiObjTypeVal;
      vpi_get_value(arg, &var);
      vpi_printf("  format = %d\n", (int) var.format);
      var.format = vpiDecStrVal;
      vpi_get_value(arg, &var);
      vpi_printf("   value = %s\n", var.value.str);

      vpi_free_object(argv);
      return 0;
}
Beispiel #27
0
static int s1AssemblerCompiletf(char*user_data)
{
  vpiHandle systf_handle;
  vpiHandle arg_itr;
  vpiHandle arg_handle;
  PLI_INT32 tfarg_type;
  int err_flag = 0;

  systf_handle = vpi_handle(vpiSysTfCall, NULL);
  arg_itr = vpi_iterate(vpiArgument, systf_handle);
  if (arg_itr == NULL) {
    vpi_printf("ERROR: $s1Assember requires 1 argument. has none.\n");
    err_flag = 1;
  }
  arg_handle = vpi_scan(arg_itr);
  tfarg_type = vpi_get(vpiType, arg_handle);
  if (tfarg_type != vpiConstant &&
      tfarg_type != vpiStringVal &&
      tfarg_type != vpiReg) {
    vpi_printf("$s1Assember argument must be a string.\n");
    vpi_printf("            tfarg_type is %0d\n", tfarg_type);
    err_flag = 1;
  }
  if (vpi_scan(arg_itr) != NULL) {
    vpi_printf("ERROR: $s1Assember requires 1 argument. has too many.\n");
  }

  if (err_flag) {
    vpi_control(vpiFinish, 1);
  }

  return 0;
}
Beispiel #28
0
/*
 * Standard error message routine. The format string must take one
 * string argument (the name of the function).
 */
static void va_error_message(vpiHandle callh, const char *format,
                             const char *name) {
    vpi_printf("%s:%d: error: ", vpi_get_str(vpiFile, callh),
               (int)vpi_get(vpiLineNo, callh));
    vpi_printf(format, name);
    vpi_control(vpiFinish, 1);
}
Beispiel #29
0
/*
 * Check to see if an argument is a variable.
 */
static void check_var_arg(vpiHandle arg, vpiHandle callh, const char *name,
                          const char *arg_name)
{
      assert(arg);

      switch (vpi_get(vpiType, arg)) {
	  case vpiPartSelect:
            if (vpi_get(vpiType, vpi_handle(vpiParent, arg)) == vpiNet)
                  break;
	  case vpiMemoryWord:
	  case vpiBitVar:
	  case vpiReg:
	  case vpiIntegerVar:
	  case vpiIntVar:
	  case vpiLongIntVar:
	  case vpiTimeVar:
	    return;
	  default:
            break;
      }
      vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
                 (int)vpi_get(vpiLineNo, callh));
      vpi_printf("%s's %s argument must be a variable.\n",
                 name, arg_name);
      vpi_control(vpiFinish, 1);
}
Beispiel #30
0
static int init_pipes()
{
  char *w;
  char *r;

  static int init_pipes_flag = 0;

  if (init_pipes_flag) {
    return(0);
  }

  if ((w = getenv("MYHDL_TO_PIPE")) == NULL) {
    vpi_printf("ERROR: no write pipe to myhdl\n");
    vpi_control(vpiFinish, 1);  /* abort simulation */
    return(0);
  }
  if ((r = getenv("MYHDL_FROM_PIPE")) == NULL) {
    vpi_printf("ERROR: no read pipe from myhdl\n");
    vpi_control(vpiFinish, 1);  /* abort simulation */
    return(0);
  }
  wpipe = atoi(w);
  rpipe = atoi(r);
  init_pipes_flag = 1;
  return (0);
}