| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "native_client/src/trusted/plugin/pnacl_options.h" | 5 #include "native_client/src/trusted/plugin/pnacl_options.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "native_client/src/include/nacl_string.h" | 10 #include "native_client/src/include/nacl_string.h" |
| 11 | 11 |
| 12 namespace { |
| 13 |
| 14 nacl::string ReplaceBadFSChars(nacl::string str, |
| 15 const nacl::string& bad_chars, |
| 16 const nacl::string& replacement) { |
| 17 size_t replace_pos = str.find_first_of(bad_chars); |
| 18 while (replace_pos != nacl::string::npos) { |
| 19 str = str.replace(replace_pos, 1, replacement); |
| 20 replace_pos = str.find_first_of(bad_chars); |
| 21 } |
| 22 return str; |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
| 12 namespace plugin { | 27 namespace plugin { |
| 13 | 28 |
| 14 // Default to -O0 for now. | 29 // Default to -O0 for now. |
| 15 PnaclOptions::PnaclOptions() : translate_(false), opt_level_(0) { } | 30 PnaclOptions::PnaclOptions() : translate_(false), opt_level_(0) { } |
| 16 | 31 |
| 17 PnaclOptions::~PnaclOptions() { | 32 PnaclOptions::~PnaclOptions() { |
| 18 } | 33 } |
| 19 | 34 |
| 20 nacl::string PnaclOptions::GetCacheKey() { | 35 nacl::string PnaclOptions::GetCacheKey() const { |
| 21 // TODO(jvoung): We need to read the PNaCl translator's manifest | 36 // TODO(jvoung): We need to read the PNaCl translator's manifest |
| 22 // to grab the NaCl / PNaCl ABI version too. | 37 // to grab the NaCl / PNaCl ABI version too. |
| 23 nacl::stringstream ss; | 38 nacl::stringstream ss; |
| 24 // Cast opt_level_ as int so that it doesn't think it's a char. | 39 // Cast opt_level_ as int so that it doesn't think it's a char. |
| 25 ss << "-O:" << static_cast<int>(opt_level_) | 40 ss << "-O:" << static_cast<int>(opt_level_) |
| 26 << ";flags:" << experimental_flags_ | 41 << ";flags:" << experimental_flags_ |
| 27 << ";bitcode_hash:" << bitcode_hash_; | 42 << ";cache_validators:" << cache_validators_; |
| 28 return ss.str(); | 43 // HTML5 FileSystem-based cache does not allow some characters which |
| 44 // may appear in URLs, ETags, or Last-Modified times. Once we move to |
| 45 // our own cache-backend, it will be more tolerant of various cache |
| 46 // key values. |
| 47 // See: http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#naming-restri
ctions |
| 48 nacl::string key = ss.str(); |
| 49 key = ReplaceBadFSChars(key, "/", "_FWDSLASH_"); |
| 50 key = ReplaceBadFSChars(key, "\\", "_BCKSLASH_"); |
| 51 key = ReplaceBadFSChars(key, "\0", "_NULL_"); |
| 52 return key; |
| 29 } | 53 } |
| 30 | 54 |
| 31 void PnaclOptions::set_opt_level(int8_t l) { | 55 void PnaclOptions::set_opt_level(int8_t l) { |
| 32 if (l < 0) { | 56 if (l < 0) { |
| 33 opt_level_ = 0; | 57 opt_level_ = 0; |
| 34 return; | 58 return; |
| 35 } | 59 } |
| 36 if (l > 3) { | 60 if (l > 3) { |
| 37 opt_level_ = 3; | 61 opt_level_ = 3; |
| 38 return; | 62 return; |
| 39 } | 63 } |
| 40 opt_level_ = l; | 64 opt_level_ = l; |
| 41 } | 65 } |
| 42 | 66 |
| 43 std::vector<char> PnaclOptions::GetOptCommandline() { | 67 std::vector<char> PnaclOptions::GetOptCommandline() const { |
| 44 std::vector<char> result; | 68 std::vector<char> result; |
| 45 std::vector<nacl::string> tokens; | 69 std::vector<nacl::string> tokens; |
| 46 | 70 |
| 47 // Split the experimental_flags_ + the -On along whitespace. | 71 // Split the experimental_flags_ + the -On along whitespace. |
| 48 // Mostly a copy of "base/strings/string_util.h", but avoid importing | 72 // Mostly a copy of "base/strings/string_util.h", but avoid importing |
| 49 // base into the PPAPI plugin for now. | 73 // base into the PPAPI plugin for now. |
| 50 nacl::string delim(" "); | 74 nacl::string delim(" "); |
| 51 nacl::string str = experimental_flags_; | 75 nacl::string str = experimental_flags_; |
| 52 | 76 |
| 53 if (opt_level_ != -1) { | 77 if (opt_level_ != -1) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 73 nacl::string t = tokens[i]; | 97 nacl::string t = tokens[i]; |
| 74 result.reserve(result.size() + t.size()); | 98 result.reserve(result.size() + t.size()); |
| 75 std::copy(t.begin(), t.end(), std::back_inserter(result)); | 99 std::copy(t.begin(), t.end(), std::back_inserter(result)); |
| 76 result.push_back('\x00'); | 100 result.push_back('\x00'); |
| 77 } | 101 } |
| 78 | 102 |
| 79 return result; | 103 return result; |
| 80 } | 104 } |
| 81 | 105 |
| 82 } // namespace plugin | 106 } // namespace plugin |
| OLD | NEW |