[1] | 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 | |
---|
[8] | 38 | #include "sc_trace.h" |
---|
| 39 | #include "sc_vcd_trace.h" |
---|
| 40 | #include "sc_ver.h" |
---|
| 41 | #include "internal.h" |
---|
| 42 | #include <cassert> |
---|
[1] | 43 | |
---|
[20] | 44 | #include <ctime> |
---|
[8] | 45 | #include <string> |
---|
| 46 | #ifdef HAVE_CONFIG_H |
---|
| 47 | #include "config.h" |
---|
| 48 | #endif |
---|
[1] | 49 | |
---|
| 50 | //-----------------------------------------*/ |
---|
| 51 | |
---|
| 52 | using namespace std; |
---|
| 53 | |
---|
| 54 | namespace sc_core { |
---|
| 55 | |
---|
| 56 | //-----------------------------------------*/ |
---|
| 57 | |
---|
| 58 | sc_trace_file* |
---|
| 59 | sc_create_vcd_trace_file(const char * name) |
---|
| 60 | { |
---|
| 61 | if (notrace) |
---|
| 62 | return NULL; |
---|
[8] | 63 | assert(name != NULL); |
---|
[1] | 64 | string filename; |
---|
| 65 | filename = name; |
---|
| 66 | filename += ".vcd"; |
---|
| 67 | //char varToday[1024];system(varToday=echo `date`); |
---|
| 68 | |
---|
| 69 | //création d'1 instance de la structure Sc_trace_file: |
---|
| 70 | sc_trace_file *traceFic=new sc_trace_file(); |
---|
| 71 | traceFic->flag = VCD_FORMAT; |
---|
| 72 | |
---|
| 73 | trace_file_list.push_back(traceFic); |
---|
| 74 | |
---|
| 75 | //en-tête du fichier VCD: |
---|
| 76 | 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"; |
---|
| 77 | |
---|
| 78 | //ouverture du fichier nommé "*name": |
---|
| 79 | traceFic->pfic=fopen(filename.c_str(),"w+");//on a un pointeur sur le fichier |
---|
| 80 | if((traceFic->pfic)==NULL) |
---|
| 81 | { |
---|
| 82 | /* fopen renvoie NULL si erreur */ |
---|
| 83 | fprintf(stderr,"\n\terreur ouverture outVcd\n"); |
---|
| 84 | exit(15); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | char date[128]; |
---|
| 88 | time_t timep = time (NULL); |
---|
| 89 | const struct tm *tm = localtime (&timep); |
---|
| 90 | strftime (date, 128, "%A %d %B %y %Z - %R:%S -", tm); |
---|
| 91 | |
---|
| 92 | //écriture de l'en-tête du format VCD: |
---|
| 93 | if ((fprintf(traceFic->pfic,entete, date, sc_version ()))==0) |
---|
| 94 | { |
---|
| 95 | /* fprintf renvoie 0 si erreur */ |
---|
| 96 | cerr << "\n\terreur ecriture de l'entete \n"; |
---|
| 97 | exit(2); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | //on retourne un pointeur sur la structure traceFile |
---|
| 101 | //dont un des éléments pointe sur notre fichier VCD: |
---|
| 102 | return traceFic; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | //************************************************************************* |
---|
| 107 | |
---|
| 108 | void |
---|
| 109 | sc_close_vcd_trace_file( sc_trace_file* traceFic ) |
---|
| 110 | { |
---|
| 111 | if (notrace) |
---|
| 112 | return; |
---|
| 113 | if (!traceFic) |
---|
| 114 | { |
---|
| 115 | cerr << "Warning : Unable to close vcd trace file.\n"; |
---|
| 116 | return; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | if (cpt >= trace_start) |
---|
| 120 | { |
---|
| 121 | trace (*traceFic,false); |
---|
| 122 | cpt++; |
---|
| 123 | trace (*traceFic,true); |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | //fermeture fichier VCD |
---|
| 127 | if (fclose(traceFic->pfic)) |
---|
| 128 | { |
---|
| 129 | /* fclose renvoie 0 si OK */ |
---|
| 130 | perror("\n\tclosing VCD file."); |
---|
| 131 | exit(4); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | //libération de l'instance de la structure en mémoire: |
---|
| 135 | delete traceFic; |
---|
| 136 | |
---|
| 137 | vector<sc_trace_file*>::iterator i; |
---|
| 138 | for (i = trace_file_list.begin (); i != trace_file_list.end(); ++i) |
---|
| 139 | if (*i == traceFic) { |
---|
| 140 | trace_file_list.erase(i); |
---|
| 141 | break; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | } // end of sc_core namespace |
---|
| 147 | |
---|