Change BuildModule() to accept pointer-size pair for binary.

This commit is contained in:
Lei Zhang 2016-09-20 16:44:24 -04:00
parent 2cbb2cce3e
commit f8dbed0455
3 changed files with 12 additions and 11 deletions

View 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

View File

@ -25,12 +25,13 @@
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

View 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;