1 | /*! @file CoverageWriterTSIM.cc |
---|
2 | * @brief CoverageWriterTSIM Implementation |
---|
3 | * |
---|
4 | * This file contains the implementation of the CoverageWriter class |
---|
5 | * for the coverage files written by the SPARC simulator TSIM. |
---|
6 | */ |
---|
7 | |
---|
8 | #include <stdio.h> |
---|
9 | #include <stdlib.h> |
---|
10 | |
---|
11 | #include <iostream> |
---|
12 | #include <iomanip> |
---|
13 | |
---|
14 | #include <rld.h> |
---|
15 | |
---|
16 | #include "CoverageWriterTSIM.h" |
---|
17 | |
---|
18 | namespace Coverage { |
---|
19 | |
---|
20 | CoverageWriterTSIM::CoverageWriterTSIM() |
---|
21 | { |
---|
22 | } |
---|
23 | |
---|
24 | CoverageWriterTSIM::~CoverageWriterTSIM() |
---|
25 | { |
---|
26 | } |
---|
27 | |
---|
28 | |
---|
29 | void CoverageWriterTSIM::writeFile( |
---|
30 | const char* const file, |
---|
31 | CoverageMapBase* coverage, |
---|
32 | uint32_t lowAddress, |
---|
33 | uint32_t highAddress |
---|
34 | ) |
---|
35 | { |
---|
36 | uint32_t a; |
---|
37 | int cover; |
---|
38 | FILE* coverageFile; |
---|
39 | int i; |
---|
40 | int status; |
---|
41 | |
---|
42 | /* |
---|
43 | * read the file and update the coverage map passed in |
---|
44 | */ |
---|
45 | coverageFile = ::fopen( file, "w" ); |
---|
46 | if ( !coverageFile ) { |
---|
47 | std::ostringstream what; |
---|
48 | what << "Unable to open " << file; |
---|
49 | throw rld::error( what, "CoverageWriterTSIM::writeFile" ); |
---|
50 | } |
---|
51 | |
---|
52 | for ( a = lowAddress; a < highAddress; a += 0x80 ) { |
---|
53 | status = fprintf( coverageFile, "%x : ", a ); |
---|
54 | if ( status == EOF || status == 0 ) { |
---|
55 | break; |
---|
56 | } |
---|
57 | for ( i = 0; i < 0x80; i += 4 ) { |
---|
58 | cover = ((coverage->wasExecuted( a + i )) ? 1 : 0); |
---|
59 | status = ::fprintf( coverageFile, "%d ", cover ); |
---|
60 | if ( status == EOF || status == 0 ) { |
---|
61 | ::fclose( coverageFile ); |
---|
62 | std::ostringstream what; |
---|
63 | what << "write to " << file |
---|
64 | << " at address 0x" |
---|
65 | << std::hex << std::setfill('0') |
---|
66 | << std::setw(8) << a |
---|
67 | << std::setfill(' ') << std::dec |
---|
68 | << "failed"; |
---|
69 | throw rld::error( what, "CoverageWriterTSIM::writeFile" ); |
---|
70 | } |
---|
71 | } |
---|
72 | ::fprintf( coverageFile, "\n" ); |
---|
73 | } |
---|
74 | |
---|
75 | ::fclose( coverageFile ); |
---|
76 | } |
---|
77 | } |
---|