Index: ppapi/native_client/src/trusted/plugin/pnacl_options.cc |
diff --git a/ppapi/native_client/src/trusted/plugin/pnacl_options.cc b/ppapi/native_client/src/trusted/plugin/pnacl_options.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4f756715a9f91e230cdb97dfa90c978739b2df2f |
--- /dev/null |
+++ b/ppapi/native_client/src/trusted/plugin/pnacl_options.cc |
@@ -0,0 +1,88 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "native_client/src/trusted/plugin/pnacl_options.h" |
+ |
+#include <iterator> |
+#include <vector> |
+ |
+#include "native_client/src/include/nacl_string.h" |
+ |
+namespace plugin { |
+ |
+PnaclOptions::PnaclOptions() : translate_(false), opt_level_(-1) { } |
+ |
+PnaclOptions::PnaclOptions(const PnaclOptions& opt) { |
Derek Schuff
2013/03/08 21:34:55
do we really need a copy constructor? is there som
jvoung (off chromium)
2013/03/08 23:21:41
Yeah, I think the default works. Removed.
Derek Schuff
2013/03/08 23:37:51
for that matter, where are we actually copying it?
jvoung (off chromium)
2013/03/08 23:49:47
We make a version that is a stack variable, which
Derek Schuff
2013/03/11 16:08:24
I see. maybe we should add a comment somewhere in
jvoung (off chromium)
2013/03/11 17:29:23
Okay, I added a note by the private fields where p
|
+ translate_ = opt.translate_; |
+ opt_level_ = opt.opt_level_; |
+ experimental_flags_ = opt.experimental_flags_; |
+ bitcode_hash_ = opt.bitcode_hash_; |
+} |
+ |
+PnaclOptions::~PnaclOptions() { |
+} |
+ |
+nacl::string PnaclOptions::GetCacheKey() { |
+ // TODO(jvoung): We need to read the PNaCl translator's manifest |
+ // to grab the NaCl / PNaCl ABI version too. |
+ nacl::stringstream ss; |
+ // Cast opt_level_ as int so that it doesn't think it's a char. |
+ ss << "-O:" << static_cast<int>(opt_level_) |
+ << ";flags:" << experimental_flags_ |
+ << ";bitcode_hash:" << bitcode_hash_; |
+ return ss.str(); |
+} |
+ |
+void PnaclOptions::set_opt_level(int8_t l) { |
Derek Schuff
2013/03/08 21:34:55
could we use uint8_t here or is that still against
jvoung (off chromium)
2013/03/08 23:21:41
Well, I made the field a int8_t, so that I could u
Derek Schuff
2013/03/08 23:37:51
oh, i forgot we were using -1.
int8_t is probably
|
+ if (l < 0) { |
+ opt_level_ = 0; |
+ return; |
+ } |
+ if (l > 3) { |
+ opt_level_ = 3; |
+ return; |
+ } |
+ opt_level_ = l; |
+} |
+ |
+std::vector<char> PnaclOptions::GetOptCommandline() { |
+ std::vector<char> result; |
+ std::vector<nacl::string> tokens; |
+ |
+ // Split the experimental_flags_ + the -On along whitespace. |
+ // Mostly a copy of "base/string_util.h", but avoid importing |
+ // base into the PPAPI plugin for now. |
+ nacl::string delim(" "); |
+ nacl::string str = experimental_flags_; |
+ |
+ if (opt_level_ != -1) { |
+ nacl::stringstream ss; |
+ // Cast as int so that it doesn't think it's a char. |
+ ss << " -O" << static_cast<int>(opt_level_); |
+ str += ss.str(); |
+ } |
+ |
+ size_t start = str.find_first_not_of(delim); |
+ while (start != nacl::string::npos) { |
+ size_t end = str.find_first_of(delim, start + 1); |
+ if (end == nacl::string::npos) { |
+ tokens.push_back(str.substr(start)); |
+ break; |
+ } else { |
+ tokens.push_back(str.substr(start, end - start)); |
+ start = str.find_first_not_of(delim, end + 1); |
+ } |
+ } |
+ |
+ for (size_t i = 0; i < tokens.size(); ++i) { |
+ nacl::string t = tokens[i]; |
+ result.reserve(result.size() + t.size()); |
+ std::copy(t.begin(), t.end(), std::back_inserter(result)); |
+ result.push_back('\x00'); |
+ } |
+ |
+ return result; |
+} |
+ |
+} // namespace plugin |