summaryrefslogtreecommitdiff
path: root/source/link
diff options
context:
space:
mode:
authordan sinclair <dj2@everburning.com>2018-07-07 09:38:00 -0400
committerGitHub <noreply@github.com>2018-07-07 09:38:00 -0400
commit3dad1cda1168b56e5326305b395c25afa06feff2 (patch)
tree5b51a44170f0a4a1992de292ed5afea9b4bb4a3b /source/link
parent76e0bde19633fc8c45f7de52029e3d517b2e1561 (diff)
Change libspirv to spvtools namespace (#1678)
This CL changes all of the libspirv namespace code to spvtools to match the rest of the code base.
Diffstat (limited to 'source/link')
-rw-r--r--source/link/linker.cpp78
1 files changed, 27 insertions, 51 deletions
diff --git a/source/link/linker.cpp b/source/link/linker.cpp
index daa584dc..15393bad 100644
--- a/source/link/linker.cpp
+++ b/source/link/linker.cpp
@@ -95,7 +95,7 @@ static spv_result_t GenerateHeader(const MessageConsumer& consumer,
// |linked_context| should not be null.
static spv_result_t MergeModules(const MessageConsumer& consumer,
const std::vector<Module*>& in_modules,
- const libspirv::AssemblyGrammar& grammar,
+ const AssemblyGrammar& grammar,
IRContext* linked_context);
// Compute all pairs of import and export and return it in |linkings_to_do|.
@@ -172,8 +172,7 @@ spv_result_t Link(const Context& context, const uint32_t* const* binaries,
linked_binary->clear();
if (num_binaries == 0u)
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_BINARY)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_BINARY)
<< "No modules were given.";
std::vector<std::unique_ptr<IRContext>> ir_contexts;
@@ -183,16 +182,14 @@ spv_result_t Link(const Context& context, const uint32_t* const* binaries,
const uint32_t schema = binaries[i][4u];
if (schema != 0u) {
position.index = 4u;
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_BINARY)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_BINARY)
<< "Schema is non-zero for module " << i << ".";
}
std::unique_ptr<IRContext> ir_context = BuildModule(
c_context->target_env, consumer, binaries[i], binary_sizes[i]);
if (ir_context == nullptr)
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_BINARY)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_BINARY)
<< "Failed to build a module out of " << ir_contexts.size() << ".";
modules.push_back(ir_context->module());
ir_contexts.push_back(std::move(ir_context));
@@ -212,7 +209,7 @@ spv_result_t Link(const Context& context, const uint32_t* const* binaries,
linked_context.module()->SetHeader(header);
// Phase 3: Merge all the binaries into a single one.
- libspirv::AssemblyGrammar grammar(c_context);
+ AssemblyGrammar grammar(c_context);
res = MergeModules(consumer, modules, grammar, &linked_context);
if (res != SPV_SUCCESS) return res;
@@ -270,16 +267,13 @@ static spv_result_t ShiftIdsInModules(const MessageConsumer& consumer,
spv_position_t position = {};
if (modules == nullptr)
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_DATA)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_DATA)
<< "|modules| of ShiftIdsInModules should not be null.";
if (modules->empty())
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_DATA)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_DATA)
<< "|modules| of ShiftIdsInModules should not be empty.";
if (max_id_bound == nullptr)
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_DATA)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_DATA)
<< "|max_id_bound| of ShiftIdsInModules should not be null.";
uint32_t id_bound = modules->front()->IdBound() - 1u;
@@ -291,8 +285,7 @@ static spv_result_t ShiftIdsInModules(const MessageConsumer& consumer,
});
id_bound += module->IdBound() - 1u;
if (id_bound > 0x3FFFFF)
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_ID)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_ID)
<< "The limit of IDs, 4194303, was exceeded:"
<< " " << id_bound << " is the current ID bound.";
@@ -301,8 +294,7 @@ static spv_result_t ShiftIdsInModules(const MessageConsumer& consumer,
}
++id_bound;
if (id_bound > 0x3FFFFF)
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_ID)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_ID)
<< "The limit of IDs, 4194303, was exceeded:"
<< " " << id_bound << " is the current ID bound.";
@@ -318,12 +310,10 @@ static spv_result_t GenerateHeader(const MessageConsumer& consumer,
spv_position_t position = {};
if (modules.empty())
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_DATA)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_DATA)
<< "|modules| of GenerateHeader should not be empty.";
if (max_id_bound == 0u)
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_DATA)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_DATA)
<< "|max_id_bound| of GenerateHeader should not be null.";
uint32_t version = 0u;
@@ -341,13 +331,12 @@ static spv_result_t GenerateHeader(const MessageConsumer& consumer,
static spv_result_t MergeModules(const MessageConsumer& consumer,
const std::vector<Module*>& input_modules,
- const libspirv::AssemblyGrammar& grammar,
+ const AssemblyGrammar& grammar,
IRContext* linked_context) {
spv_position_t position = {};
if (linked_context == nullptr)
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_DATA)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_DATA)
<< "|linked_module| of MergeModules should not be null.";
Module* linked_module = linked_context->module();
@@ -385,8 +374,7 @@ static spv_result_t MergeModules(const MessageConsumer& consumer,
grammar.lookupOperand(SPV_OPERAND_TYPE_ADDRESSING_MODEL,
memory_model_inst->GetSingleWordOperand(0u),
&current_desc);
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INTERNAL)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INTERNAL)
<< "Conflicting addressing models: " << initial_desc->name
<< " vs " << current_desc->name << ".";
}
@@ -397,8 +385,7 @@ static spv_result_t MergeModules(const MessageConsumer& consumer,
grammar.lookupOperand(SPV_OPERAND_TYPE_MEMORY_MODEL,
memory_model_inst->GetSingleWordOperand(1u),
&current_desc);
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INTERNAL)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INTERNAL)
<< "Conflicting memory models: " << initial_desc->name << " vs "
<< current_desc->name << ".";
}
@@ -423,8 +410,7 @@ static spv_result_t MergeModules(const MessageConsumer& consumer,
if (i != entry_points.end()) {
spv_operand_desc desc = nullptr;
grammar.lookupOperand(SPV_OPERAND_TYPE_EXECUTION_MODEL, model, &desc);
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INTERNAL)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INTERNAL)
<< "The entry point \"" << name << "\", with execution model "
<< desc->name << ", was already defined.";
}
@@ -484,8 +470,7 @@ static spv_result_t MergeModules(const MessageConsumer& consumer,
}
}
if (num_global_values > 0xFFFF)
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INTERNAL)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INTERNAL)
<< "The limit of global values, 65535, was exceeded;"
<< " " << num_global_values << " global values were found.";
@@ -509,8 +494,7 @@ static spv_result_t GetImportExportPairs(
spv_position_t position = {};
if (linkings_to_do == nullptr)
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_DATA)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_DATA)
<< "|linkings_to_do| of GetImportExportPairs should not be empty.";
std::vector<LinkageSymbolInfo> imports;
@@ -549,8 +533,7 @@ static spv_result_t GetImportExportPairs(
// types.
const Instruction* def_inst = def_use_manager.GetDef(id);
if (def_inst == nullptr)
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_BINARY)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_BINARY)
<< "ID " << id << " is never defined:\n";
if (def_inst->opcode() == SpvOpVariable) {
@@ -568,8 +551,7 @@ static spv_result_t GetImportExportPairs(
});
}
} else {
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_BINARY)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_BINARY)
<< "Only global variables and functions can be decorated using"
<< " LinkageAttributes; " << id << " is neither of them.\n";
}
@@ -586,12 +568,10 @@ static spv_result_t GetImportExportPairs(
const auto& exp = exports.find(import.name);
if (exp != exports.end()) possible_exports = exp->second;
if (possible_exports.empty() && !allow_partial_linkage)
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_BINARY)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_BINARY)
<< "Unresolved external reference to \"" << import.name << "\".";
else if (possible_exports.size() > 1u)
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_BINARY)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_BINARY)
<< "Too many external references, " << possible_exports.size()
<< ", were found for \"" << import.name << "\".";
@@ -615,8 +595,7 @@ static spv_result_t CheckImportExportCompatibility(
*def_use_manager.GetDef(linking_entry.imported_symbol.type_id),
*def_use_manager.GetDef(linking_entry.exported_symbol.type_id),
context))
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_BINARY)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_BINARY)
<< "Type mismatch on symbol \""
<< linking_entry.imported_symbol.name
<< "\" between imported variable/function %"
@@ -629,8 +608,7 @@ static spv_result_t CheckImportExportCompatibility(
for (const auto& linking_entry : linkings_to_do) {
if (!decoration_manager.HaveTheSameDecorations(
linking_entry.imported_symbol.id, linking_entry.exported_symbol.id))
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_BINARY)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_BINARY)
<< "Decorations mismatch on symbol \""
<< linking_entry.imported_symbol.name
<< "\" between imported variable/function %"
@@ -654,13 +632,11 @@ static spv_result_t RemoveLinkageSpecificInstructions(
spv_position_t position = {};
if (decoration_manager == nullptr)
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_DATA)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_DATA)
<< "|decoration_manager| of RemoveLinkageSpecificInstructions "
"should not be empty.";
if (linked_context == nullptr)
- return libspirv::DiagnosticStream(position, consumer, "",
- SPV_ERROR_INVALID_DATA)
+ return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_DATA)
<< "|linked_module| of RemoveLinkageSpecificInstructions should not "
"be empty.";