[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 | |
---|
[52] | 37 | #include <cstdio> |
---|
| 38 | #include <cassert> |
---|
| 39 | #include <ctime> |
---|
| 40 | #include <string> |
---|
[1] | 41 | |
---|
[27] | 42 | #include "sc_trace.h" |
---|
| 43 | #include "sc_vcd_trace.h" |
---|
| 44 | #include "sc_ver.h" |
---|
| 45 | #include "internal.h" |
---|
[1] | 46 | |
---|
[27] | 47 | #ifdef HAVE_CONFIG_H |
---|
| 48 | #include "config.h" |
---|
| 49 | #endif |
---|
| 50 | |
---|
[1] | 51 | |
---|
| 52 | using namespace std; |
---|
| 53 | |
---|
| 54 | namespace sc_core { |
---|
| 55 | |
---|
| 56 | //-----------------------------------------*/ |
---|
| 57 | |
---|
[52] | 58 | sc_trace_file * sc_create_vcd_trace_file(const char * name) { |
---|
| 59 | if (notrace) { |
---|
| 60 | return NULL; |
---|
| 61 | } |
---|
| 62 | assert(name != NULL); |
---|
| 63 | string filename; |
---|
| 64 | filename = name; |
---|
| 65 | filename += ".vcd"; |
---|
[1] | 66 | |
---|
[52] | 67 | // Création d'une instance de la structure Sc_trace_file: |
---|
| 68 | sc_trace_file * traceFic = new sc_trace_file(); |
---|
| 69 | traceFic->flag = VCD_FORMAT; |
---|
[1] | 70 | |
---|
[52] | 71 | trace_file_list.push_back(traceFic); |
---|
| 72 | |
---|
| 73 | //en-tête du fichier VCD: |
---|
| 74 | 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"; |
---|
| 75 | |
---|
| 76 | //ouverture du fichier nommé "*name": |
---|
| 77 | traceFic->pfic = fopen(filename.c_str(), "w+");//on a un pointeur sur le fichier |
---|
| 78 | if ((traceFic->pfic) == NULL) { |
---|
| 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 | /* fprintf renvoie 0 si erreur */ |
---|
| 92 | cerr << "\n\terreur ecriture de l'entete \n"; |
---|
| 93 | exit(2); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | //on retourne un pointeur sur la structure traceFile |
---|
| 97 | //dont un des éléments pointe sur notre fichier VCD: |
---|
| 98 | return traceFic; |
---|
[1] | 99 | } |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | //************************************************************************* |
---|
| 103 | |
---|
[52] | 104 | void sc_close_vcd_trace_file(sc_trace_file * traceFic) { |
---|
| 105 | if (notrace) { |
---|
| 106 | return; |
---|
| 107 | } |
---|
| 108 | if (!traceFic) { |
---|
| 109 | cerr << "Warning : Unable to close vcd trace file.\n"; |
---|
| 110 | return; |
---|
| 111 | } |
---|
[1] | 112 | |
---|
[52] | 113 | if (cpt >= trace_start) { |
---|
| 114 | trace (*traceFic, false); |
---|
| 115 | cpt++; |
---|
| 116 | trace (*traceFic, true); |
---|
| 117 | } |
---|
[1] | 118 | |
---|
[52] | 119 | //fermeture fichier VCD |
---|
| 120 | if (fclose(traceFic->pfic)) { |
---|
| 121 | /* fclose renvoie 0 si OK */ |
---|
| 122 | perror("\n\tclosing VCD file."); |
---|
| 123 | exit(4); |
---|
| 124 | } |
---|
[1] | 125 | |
---|
[52] | 126 | //libération de l'instance de la structure en mémoire: |
---|
| 127 | delete traceFic; |
---|
[1] | 128 | |
---|
[52] | 129 | vector<sc_trace_file *>::iterator i; |
---|
| 130 | for (i = trace_file_list.begin(); i != trace_file_list.end(); ++i) { |
---|
| 131 | if (*i == traceFic) { |
---|
| 132 | trace_file_list.erase(i); |
---|
| 133 | break; |
---|
| 134 | } |
---|
| 135 | } |
---|
[1] | 136 | } |
---|
| 137 | |
---|
[52] | 138 | |
---|
[1] | 139 | } // end of sc_core namespace |
---|
| 140 | |
---|
[52] | 141 | /* |
---|
| 142 | # Local Variables: |
---|
| 143 | # tab-width: 4; |
---|
| 144 | # c-basic-offset: 4; |
---|
| 145 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 146 | # indent-tabs-mode: nil; |
---|
| 147 | # End: |
---|
| 148 | # |
---|
| 149 | # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 150 | */ |
---|
| 151 | |
---|