Change BuildModule() to accept pointer-size pair for binary.
authorLei Zhang <antiagainst@google.com>
Tue, 20 Sep 2016 20:44:24 +0000 (16:44 -0400)
committerLei Zhang <antiagainst@google.com>
Tue, 20 Sep 2016 20:44:24 +0000 (16:44 -0400)
source/opt/build_module.cpp
source/opt/build_module.h
tools/opt/opt.cpp

index d42c7f8..ba4d1f3 100644 (file)
@@ -44,16 +44,16 @@ spv_result_t SetSpvInst(void* builder, const spv_parsed_instruction_t* inst) {
 
 std::unique_ptr<ir::Module> BuildModule(spv_target_env env,
                                         MessageConsumer consumer,
-                                        const std::vector<uint32_t>& binary) {
+                                        const uint32_t* binary,
+                                        const size_t size) {
   auto context = spvContextCreate(env);
   SetContextMessageConsumer(context, consumer);
 
   auto module = MakeUnique<ir::Module>();
   ir::IrLoader loader(context->consumer, module.get());
 
-  spv_result_t status =
-      spvBinaryParse(context, &loader, binary.data(), binary.size(),
-                     SetSpvHeader, SetSpvInst, nullptr);
+  spv_result_t status = spvBinaryParse(context, &loader, binary, size,
+                                       SetSpvHeader, SetSpvInst, nullptr);
   loader.EndModule();
 
   spvContextDestroy(context);
@@ -68,7 +68,7 @@ std::unique_ptr<ir::Module> BuildModule(spv_target_env env,
   t.SetMessageConsumer(consumer);
   std::vector<uint32_t> binary;
   if (!t.Assemble(text, &binary)) return nullptr;
-  return BuildModule(env, consumer, binary);
+  return BuildModule(env, consumer, binary.data(), binary.size());
 }
 
 }  // namespace spvtools
index 65d5107..e3464c8 100644 (file)
 
 namespace spvtools {
 
-// Builds and returns an ir::Module from the given SPIR-V |binary|. The |binary|
-// will be decoded according to the given target |env|. Returns nullptr if erors
-// occur and sends the errors to |consumer|.
+// Builds and returns an ir::Module from the given SPIR-V |binary|. |size|
+// specifies number of words in |binary|. The |binary| will be decoded
+// according to the given target |env|. Returns nullptr if erors occur and
+// sends the errors to |consumer|.
 std::unique_ptr<ir::Module> BuildModule(spv_target_env env,
                                         MessageConsumer consumer,
-                                        const std::vector<uint32_t>& binary);
+                                        const uint32_t* binary, size_t size);
 
 // Builds and returns an ir::Module from the given SPIR-V assembly |text|.
 // The |text| will be encoded according to the given target |env|. Returns
index 5f51669..cc10dfc 100644 (file)
@@ -140,8 +140,8 @@ int main(int argc, char** argv) {
   spvDiagnosticDestroy(diagnostic);
   spvContextDestroy(context);
 
-  std::unique_ptr<ir::Module> module =
-      BuildModule(target_env, pass_manager.consumer(), source);
+  std::unique_ptr<ir::Module> module = BuildModule(
+      target_env, pass_manager.consumer(), source.data(), source.size());
   pass_manager.Run(module.get());
 
   std::vector<uint32_t> target;