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

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: rebase 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 PnaclOptions::PnaclOptions() : translate_(false), opt_level_(-1) { }
15
16 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
17 translate_ = opt.translate_;
18 opt_level_ = opt.opt_level_;
19 experimental_flags_ = opt.experimental_flags_;
20 bitcode_hash_ = opt.bitcode_hash_;
21 }
22
23 PnaclOptions::~PnaclOptions() {
24 }
25
26 nacl::string PnaclOptions::GetCacheKey() {
27 // TODO(jvoung): We need to read the PNaCl translator's manifest
28 // to grab the NaCl / PNaCl ABI version too.
29 nacl::stringstream ss;
30 // Cast opt_level_ as int so that it doesn't think it's a char.
31 ss << "-O:" << static_cast<int>(opt_level_)
32 << ";flags:" << experimental_flags_
33 << ";bitcode_hash:" << bitcode_hash_;
34 return ss.str();
35 }
36
37 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
38 if (l < 0) {
39 opt_level_ = 0;
40 return;
41 }
42 if (l > 3) {
43 opt_level_ = 3;
44 return;
45 }
46 opt_level_ = l;
47 }
48
49 std::vector<char> PnaclOptions::GetOptCommandline() {
50 std::vector<char> result;
51 std::vector<nacl::string> tokens;
52
53 // Split the experimental_flags_ + the -On along whitespace.
54 // Mostly a copy of "base/string_util.h", but avoid importing
55 // base into the PPAPI plugin for now.
56 nacl::string delim(" ");
57 nacl::string str = experimental_flags_;
58
59 if (opt_level_ != -1) {
60 nacl::stringstream ss;
61 // Cast as int so that it doesn't think it's a char.
62 ss << " -O" << static_cast<int>(opt_level_);
63 str += ss.str();
64 }
65
66 size_t start = str.find_first_not_of(delim);
67 while (start != nacl::string::npos) {
68 size_t end = str.find_first_of(delim, start + 1);
69 if (end == nacl::string::npos) {
70 tokens.push_back(str.substr(start));
71 break;
72 } else {
73 tokens.push_back(str.substr(start, end - start));
74 start = str.find_first_not_of(delim, end + 1);
75 }
76 }
77
78 for (size_t i = 0; i < tokens.size(); ++i) {
79 nacl::string t = tokens[i];
80 result.reserve(result.size() + t.size());
81 std::copy(t.begin(), t.end(), std::back_inserter(result));
82 result.push_back('\x00');
83 }
84
85 return result;
86 }
87
88 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698