source: sources/src/sc_vcd_trace.cc @ 33

Last change on this file since 33 was 33, checked in by joel.porquet@…, 15 years ago

Make systemcass compile with gcc 4.4.* and remove redundancies in header install.

File size: 4.1 KB
Line 
1/*------------------------------------------------------------\
2|                                                             |
3| Tool    :                  systemcass                       |
4|                                                             |
5| File    :                 sc_vcd_trace.cc                   |
6|                                                             |
7| Author  :                 Kingbo Paul-Jerome                |
8|                           Buchmann Richard                  |
9|                                                             |
10| Date    :                   09_07_2004                      |
11|                                                             |
12\------------------------------------------------------------*/
13
14/*
15 * This file is part of the Disydent Project
16 * Copyright (C) Laboratoire LIP6 - Département ASIM
17 * Universite Pierre et Marie Curie
18 *
19 * Home page          : http://www-asim.lip6.fr/disydent
20 * E-mail             : mailto:richard.buchmann@lip6.fr
21 *
22 * This library is free software; you  can redistribute it and/or modify it
23 * under the terms  of the GNU Library General Public  License as published
24 * by the Free Software Foundation; either version 2 of the License, or (at
25 * your option) any later version.
26 *
27 * Disydent is distributed  in the hope  that it  will be
28 * useful, but WITHOUT  ANY WARRANTY; without even the  implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
30 * Public License for more details.
31 *
32 * You should have received a copy  of the GNU General Public License along
33 * with the GNU C Library; see the  file COPYING. If not, write to the Free
34 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 */
36
37
38#include "sc_trace.h"
39#include "sc_vcd_trace.h"
40#include "sc_ver.h"
41#include "internal.h"
42
43#include <cstdio>
44#include <cassert>
45#include <ctime>
46#include <string>
47
48#ifdef HAVE_CONFIG_H
49#include "config.h"
50#endif
51
52//-----------------------------------------*/
53
54using namespace std;
55
56namespace sc_core {
57
58//-----------------------------------------*/
59
60sc_trace_file*
61sc_create_vcd_trace_file(const char * name)
62{
63  if (notrace)
64    return NULL;
65  assert(name != NULL);
66        string filename;
67        filename = name;
68        filename += ".vcd";
69        //char varToday[1024];system(varToday=echo `date`);
70       
71        //création d'1 instance de la structure Sc_trace_file:
72        sc_trace_file *traceFic=new sc_trace_file();
73        traceFic->flag = VCD_FORMAT;   
74       
75        trace_file_list.push_back(traceFic);
76       
77        //en-tête du fichier VCD:
78        char entete[]="$date\n\t%s\n$end\n\n$version\n\t%s\n$end\n\n$timescale\n\t1 ps\n$end\n\n$scope module SystemC $end\n";
79       
80        //ouverture du fichier nommé "*name":
81        traceFic->pfic=fopen(filename.c_str(),"w+");//on a un pointeur sur le fichier
82        if((traceFic->pfic)==NULL)
83        {
84                /* fopen renvoie NULL si erreur */
85                fprintf(stderr,"\n\terreur ouverture outVcd\n");
86                exit(15);
87        }
88
89  char date[128];       
90  time_t timep = time (NULL);
91  const struct tm *tm = localtime (&timep);
92  strftime (date, 128, "%A %d %B %y %Z - %R:%S -", tm); 
93
94        //écriture de l'en-tête du format VCD:
95        if ((fprintf(traceFic->pfic,entete, date, sc_version ()))==0)
96                {
97                        /* fprintf renvoie 0 si erreur */
98                        cerr << "\n\terreur ecriture de l'entete \n";
99                        exit(2);
100                }
101       
102        //on retourne un pointeur sur la structure traceFile
103        //dont un des éléments pointe sur notre fichier VCD:
104        return traceFic;
105}
106
107
108//*************************************************************************
109
110void
111sc_close_vcd_trace_file( sc_trace_file* traceFic )
112{       
113  if (notrace)
114    return;
115  if (!traceFic)
116  {
117    cerr << "Warning : Unable to close vcd trace file.\n";
118    return;
119  }
120
121  if (cpt >= trace_start)
122  {
123    trace (*traceFic,false);
124    cpt++;
125    trace (*traceFic,true);
126  }
127
128        //fermeture fichier VCD
129        if (fclose(traceFic->pfic))
130        {
131                /* fclose renvoie 0 si OK */
132                perror("\n\tclosing VCD file.");
133                exit(4);
134        }
135
136        //libération de l'instance de la structure en mémoire:
137        delete traceFic;
138
139        vector<sc_trace_file*>::iterator i;
140        for (i = trace_file_list.begin (); i != trace_file_list.end(); ++i)
141                if (*i == traceFic) {
142                        trace_file_list.erase(i);
143                        break;
144                }
145
146}
147
148} // end of sc_core namespace
149
Note: See TracBrowser for help on using the repository browser.