OpenCores
URL https://opencores.org/ocsvn/uart2bus_testbench/uart2bus_testbench/trunk

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [dpi/] [uvm_svcmd_dpi.c] - Blame information for rev 16

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 HanySalah
//
2
//------------------------------------------------------------------------------
3
//   Copyright 2011 Mentor Graphics Corporation
4
//   Copyright 2011 Cadence Design Systems, Inc. 
5
//   Copyright 2011 Synopsys, Inc.
6
//   All Rights Reserved Worldwide
7
//
8
//   Licensed under the Apache License, Version 2.0 (the
9
//   "License"); you may not use this file except in
10
//   compliance with the License.  You may obtain a copy of
11
//   the License at
12
//
13
//       http://www.apache.org/licenses/LICENSE-2.0
14
//
15
//   Unless required by applicable law or agreed to in
16
//   writing, software distributed under the License is
17
//   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
18
//   CONDITIONS OF ANY KIND, either express or implied.  See
19
//   the License for the specific language governing
20
//   permissions and limitations under the License.
21
//------------------------------------------------------------------------------
22
 
23
#include "uvm_dpi.h"
24
#include <assert.h>
25
 
26
#define ARGV_STACK_PTR_SIZE 32
27
 
28
// the total number of arguments (minus the -f/-F minus associated filenames) 
29
int argc_total;
30
// the ptr to the array of ptrs to the args
31
char** argv_stack=NULL;
32
 
33
char ** argv_ptr=NULL;
34
 
35
 
36
void push_data(int lvl,char *entry, int cmd) {
37
  if(cmd==0)
38
    argc_total++;
39
  else
40
    *argv_ptr++=entry;
41
}
42
 
43
// walk one level (potentially recursive)
44
void walk_level(int lvl, int argc, char**argv,int cmd) {
45
    int idx;
46
    for(idx=0; ((lvl==0) && idx<argc) || ((lvl>0) && (*argv));idx++,argv++) {
47
      if(strcmp(*argv, "-f") && strcmp(*argv, "-F")) {
48
        push_data(lvl,*argv,cmd);
49
      } else {
50
        argv++;
51
        idx++;
52
        char **n=(char**) *argv;
53
        walk_level(lvl+1,argc,++n,cmd);
54
      }
55
    }
56
}
57
 
58
const char *uvm_dpi_get_next_arg_c (int init) {
59
        s_vpi_vlog_info info;
60
        static int idx=0;
61
 
62
        if(init==1)
63
        {
64
                // free if necessary
65
                free(argv_stack);
66
                argc_total=0;
67
 
68
                vpi_get_vlog_info(&info);
69
                walk_level(0,info.argc,info.argv,0);
70
 
71
                argv_stack = (char**) malloc (sizeof(char*)*argc_total);
72
                argv_ptr=argv_stack;
73
                walk_level(0,info.argc,info.argv,1);
74
                idx=0;
75
                argv_ptr=argv_stack;
76
        }
77
 
78
        if(idx++>=argc_total)
79
          return NULL;
80
 
81
        return *argv_ptr++;
82
}
83
 
84
extern char* uvm_dpi_get_tool_name_c ()
85
{
86
  s_vpi_vlog_info info;
87
  vpi_get_vlog_info(&info);
88
  return info.product;
89
}
90
 
91
extern char* uvm_dpi_get_tool_version_c ()
92
{
93
  s_vpi_vlog_info info;
94
  vpi_get_vlog_info(&info);
95
  return info.version;
96
}
97
 
98
extern regex_t* uvm_dpi_regcomp (char* pattern)
99
{
100
  regex_t* re = (regex_t*) malloc (sizeof(regex_t));
101
  int status = regcomp(re, pattern, REG_NOSUB|REG_EXTENDED);
102
  if(status)
103
  {
104
      const char * err_str = "uvm_dpi_regcomp : Unable to compile regex: |%s|, Element 0 is: %c";
105
      char buffer[strlen(err_str) + strlen(pattern) + 1];
106
      sprintf(buffer, err_str, pattern, pattern[0]);
107
      m_uvm_report_dpi(M_UVM_ERROR,
108
                  (char*)"UVM/DPI/REGCOMP",
109
                       &buffer[0],
110
                       M_UVM_NONE,
111
                       (char*) __FILE__,
112
                       __LINE__);
113
      regfree(re);
114
      free (re);
115
    return NULL;
116
  }
117
  return re;
118
}
119
 
120
extern int uvm_dpi_regexec (regex_t* re, char* str)
121
{
122
  if(!re )
123
  {
124
    return 1;
125
  }
126
  return regexec(re, str, (size_t)0, NULL, 0);
127
}
128
 
129
extern void uvm_dpi_regfree (regex_t* re)
130
{
131
  if(!re) return;
132
  regfree(re);
133
  free (re);
134
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.