Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ppapi / native_client / src / trusted / plugin / pnacl_translate_thread.cc
index 7cb98b8..695e7f2 100644 (file)
@@ -7,6 +7,7 @@
 #include <iterator>
 
 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
+#include "ppapi/cpp/var.h"
 #include "ppapi/native_client/src/trusted/plugin/plugin.h"
 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h"
 #include "ppapi/native_client/src/trusted/plugin/pnacl_resources.h"
 #include "ppapi/native_client/src/trusted/plugin/utility.h"
 
 namespace plugin {
+namespace {
+
+template <typename Val>
+nacl::string MakeCommandLineArg(const char* key, const Val val) {
+  nacl::stringstream ss;
+  ss << key << val;
+  return ss.str();
+}
+
+void GetLlcCommandLine(Plugin* plugin,
+                       std::vector<char>* split_args,
+                       size_t obj_files_size,
+                       int32_t opt_level,
+                       bool is_debug,
+                       const nacl::string &architecture_attributes) {
+  typedef std::vector<nacl::string> Args;
+  Args args;
+
+  // TODO(dschuff): This CL override is ugly. Change llc to default to
+  // using the number of modules specified in the first param, and
+  // ignore multiple uses of -split-module
+  args.push_back(MakeCommandLineArg("-split-module=", obj_files_size));
+  args.push_back(MakeCommandLineArg("-O=", opt_level));
+  if (is_debug)
+    args.push_back("-bitcode-format=llvm");
+  if (!architecture_attributes.empty())
+    args.push_back("-mattr=" + architecture_attributes);
+
+  for (Args::const_iterator arg(args.begin()); arg != args.end(); ++arg) {
+    std::copy(arg->begin(), arg->end(), std::back_inserter(*split_args));
+    split_args->push_back('\x00');
+  }
+}
+
+}  // namespace
 
 PnaclTranslateThread::PnaclTranslateThread() : llc_subprocess_active_(false),
                                                ld_subprocess_active_(false),
                                                done_(false),
                                                compile_time_(0),
-                                               manifest_(NULL),
+                                               manifest_id_(0),
                                                obj_files_(NULL),
                                                nexe_file_(NULL),
                                                coordinator_error_info_(NULL),
@@ -34,23 +70,25 @@ PnaclTranslateThread::PnaclTranslateThread() : llc_subprocess_active_(false),
 
 void PnaclTranslateThread::RunTranslate(
     const pp::CompletionCallback& finish_callback,
-    const Manifest* manifest,
+    int32_t manifest_id,
     const std::vector<TempFile*>* obj_files,
     TempFile* nexe_file,
     nacl::DescWrapper* invalid_desc_wrapper,
     ErrorInfo* error_info,
     PnaclResources* resources,
-    PnaclOptions* pnacl_options,
+    PP_PNaClOptions* pnacl_options,
+    const nacl::string &architecture_attributes,
     PnaclCoordinator* coordinator,
     Plugin* plugin) {
   PLUGIN_PRINTF(("PnaclStreamingTranslateThread::RunTranslate)\n"));
-  manifest_ = manifest;
+  manifest_id_ = manifest_id;
   obj_files_ = obj_files;
   nexe_file_ = nexe_file;
   invalid_desc_wrapper_ = invalid_desc_wrapper;
   coordinator_error_info_ = error_info;
   resources_ = resources;
   pnacl_options_ = pnacl_options;
+  architecture_attributes_ = architecture_attributes;
   coordinator_ = coordinator;
   plugin_ = plugin;
 
@@ -110,7 +148,7 @@ void PnaclTranslateThread::PutBytes(std::vector<char>* bytes,
 
 NaClSubprocess* PnaclTranslateThread::StartSubprocess(
     const nacl::string& url_for_nexe,
-    const Manifest* manifest,
+    int32_t manifest_id,
     ErrorInfo* error_info) {
   PLUGIN_PRINTF(("PnaclTranslateThread::StartSubprocess (url_for_nexe=%s)\n",
                  url_for_nexe.c_str()));
@@ -121,8 +159,8 @@ NaClSubprocess* PnaclTranslateThread::StartSubprocess(
   // string gets silently dropped by GURL.
   nacl::string full_url = resources_->GetFullUrl(
       url_for_nexe, plugin_->nacl_interface()->GetSandboxArch());
-  nacl::scoped_ptr<NaClSubprocess> subprocess(
-      plugin_->LoadHelperNaClModule(full_url, wrapper, manifest, error_info));
+  nacl::scoped_ptr<NaClSubprocess> subprocess(plugin_->LoadHelperNaClModule(
+      full_url, wrapper, manifest_id, error_info));
   if (subprocess.get() == NULL) {
     PLUGIN_PRINTF((
         "PnaclTranslateThread::StartSubprocess: subprocess creation failed\n"));
@@ -154,7 +192,7 @@ void PnaclTranslateThread::DoTranslate() {
     nacl::MutexLocker ml(&subprocess_mu_);
     int64_t llc_start_time = NaClGetTimeOfDayMicroseconds();
     llc_subprocess_.reset(
-      StartSubprocess(resources_->GetLlcUrl(), manifest_, &error_info));
+      StartSubprocess(resources_->GetLlcUrl(), manifest_id_, &error_info));
     if (llc_subprocess_ == NULL) {
       TranslateFailed(PP_NACL_ERROR_PNACL_LLC_SETUP,
                       "Compile process could not be created: " +
@@ -179,16 +217,12 @@ void PnaclTranslateThread::DoTranslate() {
   bool init_success;
 
   std::vector<char> split_args;
-  nacl::stringstream ss;
-  // TODO(dschuff): This CL override is ugly. Change llc to default to using
-  // the number of modules specified in the first param, and ignore multiple
-  // uses of -split-module
-  ss << "-split-module=" << obj_files_->size();
-  nacl::string split_arg = ss.str();
-  std::copy(split_arg.begin(), split_arg.end(), std::back_inserter(split_args));
-  split_args.push_back('\x00');
-  std::vector<char> options = pnacl_options_->GetOptCommandline();
-  std::copy(options.begin(), options.end(), std::back_inserter(split_args));
+  GetLlcCommandLine(plugin_,
+                    &split_args,
+                    obj_files_->size(),
+                    pnacl_options_->opt_level,
+                    pnacl_options_->is_debug,
+                    architecture_attributes_);
   init_success = llc_subprocess_->InvokeSrpcMethod(
       "StreamInitWithSplit",
       "ihhhhhhhhhhhhhhhhC",
@@ -330,7 +364,7 @@ bool PnaclTranslateThread::RunLdSubprocess() {
     nacl::MutexLocker ml(&subprocess_mu_);
     int64_t ld_start_time = NaClGetTimeOfDayMicroseconds();
     ld_subprocess_.reset(
-      StartSubprocess(resources_->GetLdUrl(), manifest_, &error_info));
+      StartSubprocess(resources_->GetLdUrl(), manifest_id_, &error_info));
     if (ld_subprocess_ == NULL) {
       TranslateFailed(PP_NACL_ERROR_PNACL_LD_SETUP,
                       "Link process could not be created: " +