fd_array.cc (12697:cd71b966be1e) | fd_array.cc (13029:75abda747dc3) |
---|---|
1/* 2 * Copyright (c) 2016 Advanced Micro Devices, Inc. 3 * All rights reserved. 4 * 5 * For use for simulation and test purposes only 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are met: --- 34 unchanged lines hidden (view full) --- 43#include <string> 44 45#include "base/logging.hh" 46#include "params/Process.hh" 47#include "sim/fd_entry.hh" 48 49FDArray::FDArray(std::string const& input, std::string const& output, 50 std::string const& errout) | 1/* 2 * Copyright (c) 2016 Advanced Micro Devices, Inc. 3 * All rights reserved. 4 * 5 * For use for simulation and test purposes only 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are met: --- 34 unchanged lines hidden (view full) --- 43#include <string> 44 45#include "base/logging.hh" 46#include "params/Process.hh" 47#include "sim/fd_entry.hh" 48 49FDArray::FDArray(std::string const& input, std::string const& output, 50 std::string const& errout) |
51 : _input(input), _output(output), _errout(errout), _fdArray(), 52 imap {{"", -1}, 53 {"cin", STDIN_FILENO}, 54 {"stdin", STDIN_FILENO}}, 55 oemap{{"", -1}, 56 {"cout", STDOUT_FILENO}, 57 {"stdout", STDOUT_FILENO}, 58 {"cerr", STDERR_FILENO}, 59 {"stderr", STDERR_FILENO}} | 51 : _fdArray(), _input(input), _output(output), _errout(errout), 52 _imap {{"", -1}, 53 {"cin", STDIN_FILENO}, 54 {"stdin", STDIN_FILENO}}, 55 _oemap{{"", -1}, 56 {"cout", STDOUT_FILENO}, 57 {"stdout", STDOUT_FILENO}, 58 {"cerr", STDERR_FILENO}, 59 {"stderr", STDERR_FILENO}} |
60{ 61 int sim_fd; 62 std::map<std::string, int>::iterator it; 63 64 /** 65 * Search through the input options and setup the default fd if match is 66 * found; otherwise, open an input file and seek to location. 67 */ | 60{ 61 int sim_fd; 62 std::map<std::string, int>::iterator it; 63 64 /** 65 * Search through the input options and setup the default fd if match is 66 * found; otherwise, open an input file and seek to location. 67 */ |
68 if ((it = imap.find(input)) != imap.end()) | 68 if ((it = _imap.find(input)) != _imap.end()) |
69 sim_fd = it->second; 70 else 71 sim_fd = openInputFile(input); 72 73 auto ffd = std::make_shared<FileFDEntry>(sim_fd, O_RDONLY, input, false); 74 _fdArray[STDIN_FILENO] = ffd; 75 76 /** 77 * Search through the output/error options and setup the default fd if 78 * match is found; otherwise, open an output file and seek to location. 79 */ | 69 sim_fd = it->second; 70 else 71 sim_fd = openInputFile(input); 72 73 auto ffd = std::make_shared<FileFDEntry>(sim_fd, O_RDONLY, input, false); 74 _fdArray[STDIN_FILENO] = ffd; 75 76 /** 77 * Search through the output/error options and setup the default fd if 78 * match is found; otherwise, open an output file and seek to location. 79 */ |
80 if ((it = oemap.find(output)) != oemap.end()) | 80 if ((it = _oemap.find(output)) != _oemap.end()) |
81 sim_fd = it->second; 82 else 83 sim_fd = openOutputFile(output); 84 85 ffd = std::make_shared<FileFDEntry>(sim_fd, O_WRONLY | O_CREAT | O_TRUNC, 86 output, false); 87 _fdArray[STDOUT_FILENO] = ffd; 88 89 if (output == errout) 90 ; /* Reuse the same file descriptor if these match. */ | 81 sim_fd = it->second; 82 else 83 sim_fd = openOutputFile(output); 84 85 ffd = std::make_shared<FileFDEntry>(sim_fd, O_WRONLY | O_CREAT | O_TRUNC, 86 output, false); 87 _fdArray[STDOUT_FILENO] = ffd; 88 89 if (output == errout) 90 ; /* Reuse the same file descriptor if these match. */ |
91 else if ((it = oemap.find(errout)) != oemap.end()) | 91 else if ((it = _oemap.find(errout)) != _oemap.end()) |
92 sim_fd = it->second; 93 else 94 sim_fd = openOutputFile(errout); 95 96 ffd = std::make_shared<FileFDEntry>(sim_fd, O_WRONLY | O_CREAT | O_TRUNC, 97 errout, false); 98 _fdArray[STDERR_FILENO] = ffd; 99} --- 51 unchanged lines hidden (view full) --- 151 152 if (_input != stdin_ffd->getFileName()) { 153 warn("Using new input file (%s) rather than checkpointed (%s)\n", 154 _input, stdin_ffd->getFileName()); 155 stdin_ffd->setFileName(_input); 156 stdin_ffd->setFileOffset(0); 157 } 158 | 92 sim_fd = it->second; 93 else 94 sim_fd = openOutputFile(errout); 95 96 ffd = std::make_shared<FileFDEntry>(sim_fd, O_WRONLY | O_CREAT | O_TRUNC, 97 errout, false); 98 _fdArray[STDERR_FILENO] = ffd; 99} --- 51 unchanged lines hidden (view full) --- 151 152 if (_input != stdin_ffd->getFileName()) { 153 warn("Using new input file (%s) rather than checkpointed (%s)\n", 154 _input, stdin_ffd->getFileName()); 155 stdin_ffd->setFileName(_input); 156 stdin_ffd->setFileOffset(0); 157 } 158 |
159 if ((it = imap.find(stdin_ffd->getFileName())) != imap.end()) { | 159 if ((it = _imap.find(stdin_ffd->getFileName())) != _imap.end()) { |
160 stdin_ffd->setSimFD(it->second); 161 } else { 162 stdin_ffd->setSimFD(openInputFile(stdin_ffd->getFileName())); 163 seek(stdin_ffd); 164 } 165 166 /** 167 * Search through the output options and set fd if match is found; --- 7 unchanged lines hidden (view full) --- 175 176 if (_output != stdout_ffd->getFileName()) { 177 warn("Using new output file (%s) rather than checkpointed (%s)\n", 178 _output, stdout_ffd->getFileName()); 179 stdout_ffd->setFileName(_output); 180 stdout_ffd->setFileOffset(0); 181 } 182 | 160 stdin_ffd->setSimFD(it->second); 161 } else { 162 stdin_ffd->setSimFD(openInputFile(stdin_ffd->getFileName())); 163 seek(stdin_ffd); 164 } 165 166 /** 167 * Search through the output options and set fd if match is found; --- 7 unchanged lines hidden (view full) --- 175 176 if (_output != stdout_ffd->getFileName()) { 177 warn("Using new output file (%s) rather than checkpointed (%s)\n", 178 _output, stdout_ffd->getFileName()); 179 stdout_ffd->setFileName(_output); 180 stdout_ffd->setFileOffset(0); 181 } 182 |
183 if ((it = oemap.find(stdout_ffd->getFileName())) != oemap.end()) { | 183 if ((it = _oemap.find(stdout_ffd->getFileName())) != _oemap.end()) { |
184 stdout_ffd->setSimFD(it->second); 185 } else { 186 stdout_ffd->setSimFD(openOutputFile(stdout_ffd->getFileName())); 187 seek(stdout_ffd); 188 } 189 190 /** 191 * Search through the error options and set fd if match is found; --- 10 unchanged lines hidden (view full) --- 202 _errout, stderr_ffd->getFileName()); 203 stderr_ffd->setFileName(_errout); 204 stderr_ffd->setFileOffset(0); 205 } 206 207 if (stdout_ffd->getFileName() == stderr_ffd->getFileName()) { 208 /* Reuse the same sim_fd file descriptor if these match. */ 209 stderr_ffd->setSimFD(stdout_ffd->getSimFD()); | 184 stdout_ffd->setSimFD(it->second); 185 } else { 186 stdout_ffd->setSimFD(openOutputFile(stdout_ffd->getFileName())); 187 seek(stdout_ffd); 188 } 189 190 /** 191 * Search through the error options and set fd if match is found; --- 10 unchanged lines hidden (view full) --- 202 _errout, stderr_ffd->getFileName()); 203 stderr_ffd->setFileName(_errout); 204 stderr_ffd->setFileOffset(0); 205 } 206 207 if (stdout_ffd->getFileName() == stderr_ffd->getFileName()) { 208 /* Reuse the same sim_fd file descriptor if these match. */ 209 stderr_ffd->setSimFD(stdout_ffd->getSimFD()); |
210 } else if ((it = oemap.find(stderr_ffd->getFileName())) != oemap.end()) { | 210 } else if ((it = _oemap.find(stderr_ffd->getFileName())) != _oemap.end()) { |
211 stderr_ffd->setSimFD(it->second); 212 } else { 213 stderr_ffd->setSimFD(openOutputFile(stderr_ffd->getFileName())); 214 seek(stderr_ffd); 215 } 216 217 for (int tgt_fd = 3; tgt_fd < _fdArray.size(); tgt_fd++) { 218 std::shared_ptr<FDEntry> fdp = _fdArray[tgt_fd]; --- 132 unchanged lines hidden --- | 211 stderr_ffd->setSimFD(it->second); 212 } else { 213 stderr_ffd->setSimFD(openOutputFile(stderr_ffd->getFileName())); 214 seek(stderr_ffd); 215 } 216 217 for (int tgt_fd = 3; tgt_fd < _fdArray.size(); tgt_fd++) { 218 std::shared_ptr<FDEntry> fdp = _fdArray[tgt_fd]; --- 132 unchanged lines hidden --- |