systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
Testing.h
Go to the documentation of this file.
1#ifndef _TESTING_H_
2#define _TESTING_H_
3
4// Includes
5#include <fstream>
6#include <sstream>
7#include <string>
8
9namespace systemc_clang {
10
11std::ifstream file{};
12// Open the file for reading
13std::string read_systemc_file(std::string const data_dir,
14 std::string const name) {
15 // If the file is already open, close it
16 // - this is just in case the file changed since the last opening
17 if (file.is_open()) {
18 file.close();
19 }
20
21 // Open the file and set the character position to zero
22 file.open(data_dir + name);
23
24 // If the file did not open, indicate an error occurred.
25 if (!file.is_open()) {
26 llvm::errs() << "[ERROR]: " << name << " not found" << "\n";
27 return "";
28 }
29
30 std::string content;
31 // Assign to the string the 'content' the contents of the file
32 content = std::string(std::istreambuf_iterator<char>(file),
33 std::istreambuf_iterator<char>());
34
35 return content;
36}
37
38}; // namespace systemc_clang
39
40#endif
std::ifstream file
Definition Testing.h:11
std::string read_systemc_file(std::string const data_dir, std::string const name)
Definition Testing.h:13