-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFVParser.cpp
137 lines (122 loc) · 4.8 KB
/
FVParser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/***********************************************************************
* __________________________________________________________________
*
* _____ _ ____ _ __
* / ___/(_)___ ___ / __ \____ (_)___ / /_
* \__ \/ / __ `__ \/ /_/ / __ \/ / __ \/ __/
* ___/ / / / / / / / ____/ /_/ / / / / / /_
* /____/_/_/ /_/ /_/_/ \____/_/_/ /_/\__/
*
* __________________________________________________________________
*
* This file is part of the SimPoint Toolkit written by Greg Hamerly,
* Erez Perelman, Jeremy Lau, Tim Sherwood, and Brad Calder as part of
* Efficient Simulation Project at UCSD. If you find this toolkit useful please
* cite the following paper published at ASPLOS 2002.
*
* Timothy Sherwood, Erez Perelman, Greg Hamerly and Brad Calder,
* Automatically Characterizing Large Scale Program Behavior , In the
* 10th International Conference on Architectural Support for Programming
* Languages and Operating Systems, October 2002.
*
* Contact info:
* Brad Calder <[email protected]>, (858) 822 - 1619
* Greg Hamerly <[email protected]>,
* Erez Perelman <[email protected]>,
* Jeremy Lau <[email protected]>,
* Tim Sherwood <[email protected]>
*
* University of California, San Diego
* Department of Computer Science and Engineering
* 9500 Gilman Drive, Dept 0114
* La Jolla CA 92093-0114 USA
*
*
* Copyright 2001, 2002, 2003, 2004, 2005 The Regents of the University of
* California All Rights Reserved
*
* Permission to use, copy, modify and distribute any part of this
* SimPoint Toolkit for educational, non-profit, and industry research
* purposes, without fee, and without a written agreement is hereby
* granted, provided that the above copyright notice, this paragraph and
* the following four paragraphs appear in all copies and every modified
* file.
*
* Permission is not granted to include SimPoint into a commercial product.
* Those desiring to incorporate this SimPoint Toolkit into commercial
* products should contact the Technology Transfer Office, University of
* California, San Diego, 9500 Gilman Drive, La Jolla, CA 92093-0910, Ph:
* (619) 534-5815, FAX: (619) 534-7345.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
* INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THE SimPoint
* Toolkit, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* THE SimPoint Toolkit PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND THE
* UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
* SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. THE UNIVERSITY OF
* CALIFORNIA MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY
* KIND, EITHER IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
* PURPOSE, OR THAT THE USE OF THE SimPoint Toolkit WILL NOT INFRINGE ANY
* PATENT, TRADEMARK OR OTHER RIGHTS.
*
* No non-profit user may place any restrictions on the use of this
* software, including as modified by the user, by any other authorized
* user.
*
************************************************************************/
/***********************************************************************
* File: FVParser.cpp
* Author: Greg Hamerly
* Date: 8/20/2002
***********************************************************************/
#include "FVParser.h"
#include "Utilities.h"
#include <string>
// take care of a difference between G++ 2.96 and 3.x
#if (__GNUC__ >= 3)
#include <sstream>
#else
#include <strstream>
#endif
FVParser::FVParser(FILE *input_file) {
Utilities::check(input_file != NULL,
"FVParser::FVParser() input_file is NULL");
input = input_file;
lineNumber = 0;
}
bool FVParser::nextLine(list<FVParserToken> *result) {
string line;
const int BUF_SIZE = 1024 * 1024;
char buffer[BUF_SIZE];
buffer[0] = '\0';
do {
fgets(buffer, BUF_SIZE, input);
} while ((! eof()) && ((strlen(buffer) == 0) || ('T' != buffer[0])));
Utilities::check(strlen(buffer) != BUF_SIZE - 1,
"FVParser::nextLine() lines are too long for buffer");
if (eof()) { return false; }
#if (__GNUC__ >= 3)
istringstream parser(buffer);
#else
istrstream parser(buffer, strlen(buffer));
#endif
char t;
parser >> t;
result->clear();
char colon;
int dimension;
double value;
while (parser >> colon >> dimension >> colon >> value) {
result->push_back(FVParserToken(dimension, value));
}
if (result->size() > 0) {
lineNumber++;
return true;
} else {
return false;
}
}