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