Move SetContextMessageConsumer into libspirv namespace

Avoid polluting the global namespace.
This commit is contained in:
David Neto 2017-11-22 15:18:37 -05:00
parent 28c415500d
commit c2999273d9
12 changed files with 16 additions and 9 deletions

View File

@ -2846,7 +2846,7 @@ spv_result_t SpirvToMarkv(
MessageConsumer message_consumer, MarkvLogConsumer log_consumer,
MarkvDebugConsumer debug_consumer, std::vector<uint8_t>* markv) {
spv_context_t hijack_context = *context;
SetContextMessageConsumer(&hijack_context, message_consumer);
libspirv::SetContextMessageConsumer(&hijack_context, message_consumer);
spv_const_binary_t spirv_binary = {spirv.data(), spirv.size()};
@ -2901,7 +2901,7 @@ spv_result_t MarkvToSpirv(
MarkvDebugConsumer debug_consumer, std::vector<uint32_t>* spirv) {
spv_position_t position = {};
spv_context_t hijack_context = *context;
SetContextMessageConsumer(&hijack_context, message_consumer);
libspirv::SetContextMessageConsumer(&hijack_context, message_consumer);
MarkvDecoder decoder(&hijack_context, markv, options, &markv_model);

View File

@ -117,7 +117,7 @@ void UseDiagnosticAsMessageConsumer(spv_context context,
spvDiagnosticDestroy(*diagnostic); // Avoid memory leak.
*diagnostic = spvDiagnosticCreate(&p, message);
};
SetContextMessageConsumer(context, std::move(create_diagnostic));
libspirv::SetContextMessageConsumer(context, std::move(create_diagnostic));
}
std::string spvResultToString(spv_result_t res) {

View File

@ -35,7 +35,7 @@ SpirvTools::SpirvTools(spv_target_env env) : impl_(new Impl(env)) {}
SpirvTools::~SpirvTools() {}
void SpirvTools::SetMessageConsumer(MessageConsumer consumer) {
SetContextMessageConsumer(impl_->context, std::move(consumer));
libspirv::SetContextMessageConsumer(impl_->context, std::move(consumer));
}
bool SpirvTools::Assemble(const std::string& text,

View File

@ -162,7 +162,7 @@ Linker::Linker(spv_target_env env) : impl_(new Impl(env)) {}
Linker::~Linker() {}
void Linker::SetMessageConsumer(MessageConsumer consumer) {
SetContextMessageConsumer(impl_->context, std::move(consumer));
libspirv::SetContextMessageConsumer(impl_->context, std::move(consumer));
}
spv_result_t Linker::Link(const std::vector<std::vector<uint32_t>>& binaries,

View File

@ -49,7 +49,7 @@ std::unique_ptr<ir::IRContext> BuildModule(spv_target_env env,
const uint32_t* binary,
const size_t size) {
auto context = spvContextCreate(env);
SetContextMessageConsumer(context, consumer);
libspirv::SetContextMessageConsumer(context, consumer);
auto irContext = MakeUnique<ir::IRContext>(consumer);
ir::IrLoader loader(consumer, irContext->module());

View File

@ -48,7 +48,7 @@ spv_context spvContextCreate(spv_target_env env) {
void spvContextDestroy(spv_context context) { delete context; }
void SetContextMessageConsumer(spv_context context,
spvtools::MessageConsumer consumer) {
void libspirv::SetContextMessageConsumer(spv_context context,
spvtools::MessageConsumer consumer) {
context->consumer = std::move(consumer);
}

View File

@ -100,10 +100,12 @@ struct spv_context_t {
spvtools::MessageConsumer consumer;
};
namespace libspirv {
// Sets the message consumer to |consumer| in the given |context|. The original
// message consumer will be overwritten.
void SetContextMessageConsumer(spv_context context,
spvtools::MessageConsumer consumer);
} // namespace libspirv
// Populates *table with entries for env.
spv_result_t spvOpcodeTableGet(spv_opcode_table* table, spv_target_env env);

View File

@ -35,6 +35,7 @@ static bool operator==(const spv_parsed_operand_t& a,
namespace {
using ::libspirv::SetContextMessageConsumer;
using ::spvtest::Concatenate;
using ::spvtest::MakeInstruction;
using ::spvtest::MakeVector;

View File

@ -22,6 +22,8 @@ namespace {
using namespace spvtools;
using libspirv::SetContextMessageConsumer;
// The default consumer is a null std::function.
TEST(CInterface, DefaultConsumerNullDiagnosticForValidInput) {
auto context = spvContextCreate(SPV_ENV_UNIVERSAL_1_1);

View File

@ -26,6 +26,7 @@
namespace {
using libspirv::SetContextMessageConsumer;
using spvtools::MarkvModelType;
using spvtest::ScopedContext;
using MarkvTest = ::testing::TestWithParam<MarkvModelType>;

View File

@ -22,6 +22,7 @@
namespace {
using libspirv::SetContextMessageConsumer;
using libspirv::SpirvStats;
using spvtest::ScopedContext;

View File

@ -181,7 +181,7 @@ int main(int argc, char** argv) {
std::cerr << "Processing " << paths.size() << " files..." << std::endl;
ScopedContext ctx(SPV_ENV_UNIVERSAL_1_1);
SetContextMessageConsumer(ctx.context, DiagnosticsMessageHandler);
libspirv::SetContextMessageConsumer(ctx.context, DiagnosticsMessageHandler);
libspirv::SpirvStats stats;
stats.opcode_markov_hist.resize(1);