Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: ppapi/native_client/src/trusted/plugin/pnacl_options.cc

Issue 12623004: Allow PNaCl NMF to set translator optimization options for experimentation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Default to -O0 instead of the default for now Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "native_client/src/trusted/plugin/pnacl_options.h"
6
7 #include <iterator>
8 #include <vector>
9
10 #include "native_client/src/include/nacl_string.h"
11
12 namespace plugin {
13
14 // Default to -O0 for now.
15 PnaclOptions::PnaclOptions() : translate_(false), opt_level_(0) { }
16
17 PnaclOptions::~PnaclOptions() {
18 }
19
20 nacl::string PnaclOptions::GetCacheKey() {
21 // TODO(jvoung): We need to read the PNaCl translator's manifest
22 // to grab the NaCl / PNaCl ABI version too.
23 nacl::stringstream ss;
24 // Cast opt_level_ as int so that it doesn't think it's a char.
25 ss << "-O:" << static_cast<int>(opt_level_)
26 << ";flags:" << experimental_flags_
27 << ";bitcode_hash:" << bitcode_hash_;
28 return ss.str();
29 }
30
31 void PnaclOptions::set_opt_level(int8_t l) {
32 if (l < 0) {
33 opt_level_ = 0;
34 return;
35 }
36 if (l > 3) {
37 opt_level_ = 3;
38 return;
39 }
40 opt_level_ = l;
41 }
42
43 std::vector<char> PnaclOptions::GetOptCommandline() {
44 std::vector<char> result;
45 std::vector<nacl::string> tokens;
46
47 // Split the experimental_flags_ + the -On along whitespace.
48 // Mostly a copy of "base/string_util.h", but avoid importing
49 // base into the PPAPI plugin for now.
50 nacl::string delim(" ");
51 nacl::string str = experimental_flags_;
52
53 if (opt_level_ != -1) {
54 nacl::stringstream ss;
55 // Cast as int so that it doesn't think it's a char.
56 ss << " -O" << static_cast<int>(opt_level_);
57 str += ss.str();
58 }
59
60 size_t start = str.find_first_not_of(delim);
61 while (start != nacl::string::npos) {
62 size_t end = str.find_first_of(delim, start + 1);
63 if (end == nacl::string::npos) {
64 tokens.push_back(str.substr(start));
65 break;
66 } else {
67 tokens.push_back(str.substr(start, end - start));
68 start = str.find_first_not_of(delim, end + 1);
69 }
70 }
71
72 for (size_t i = 0; i < tokens.size(); ++i) {
73 nacl::string t = tokens[i];
74 result.reserve(result.size() + t.size());
75 std::copy(t.begin(), t.end(), std::back_inserter(result));
76 result.push_back('\x00');
77 }
78
79 return result;
80 }
81
82 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698