const spv_ext_inst_table extInstTable, const ValidationState_t& state,
spv_position position, spv_diagnostic* pDiagnostic) {
position->index = SPV_INDEX_INSTRUCTION;
- spvCheckReturn(spvValidateInstructionIDs(pInsts, count, opcodeTable,
- operandTable, extInstTable, state,
- position, pDiagnostic));
+ if (auto error =
+ spvValidateInstructionIDs(pInsts, count, opcodeTable, operandTable,
+ extInstTable, state, position, pDiagnostic))
+ return error;
return SPV_SUCCESS;
}
DebugInstructionPass(_, inst);
// TODO(umar): Perform data rules pass
- spvCheckReturn(IdPass(_, inst));
- spvCheckReturn(ModuleLayoutPass(_, inst));
- spvCheckReturn(CfgPass(_, inst));
- spvCheckReturn(InstructionPass(_, inst));
+ if (auto error = IdPass(_, inst)) return error;
+ if (auto error = ModuleLayoutPass(_, inst)) return error;
+ if (auto error = CfgPass(_, inst)) return error;
+ if (auto error = InstructionPass(_, inst)) return error;
return SPV_SUCCESS;
}
#ifdef __clang__
#define UNUSED(func) [[gnu::unused]] func
#elif defined(__GNUC__)
-#define UNUSED(func) func __attribute__((unused)); func
+#define UNUSED(func) \
+ func __attribute__((unused)); \
+ func
#elif defined(_MSC_VER)
#define UNUSED(func) func
#endif
// NOTE: Parse the module and perform inline validation checks. These
// checks do not require the the knowledge of the whole module.
ValidationState_t vstate(pDiagnostic, context);
- spvCheckReturn(spvBinaryParse(context, &vstate, binary->code,
- binary->wordCount, setHeader,
- ProcessInstruction, pDiagnostic));
+ if (auto error =
+ spvBinaryParse(context, &vstate, binary->code, binary->wordCount,
+ setHeader, ProcessInstruction, pDiagnostic))
+ return error;
if (vstate.in_function_body())
return vstate.diag(SPV_ERROR_INVALID_LAYOUT)
// CFG checks are performed after the binary has been parsed
// and the CFGPass has collected information about the control flow
- spvCheckReturn(PerformCfgChecks(vstate));
- spvCheckReturn(UpdateIdUse(vstate));
- spvCheckReturn(CheckIdDefinitionDominateUse(vstate));
+ if (auto error = PerformCfgChecks(vstate)) return error;
+ if (auto error = UpdateIdUse(vstate)) return error;
+ if (auto error = CheckIdDefinitionDominateUse(vstate)) return error;
// NOTE: Copy each instruction for easier processing
std::vector<spv_instruction_t> instructions;
}
position.index = SPV_INDEX_INSTRUCTION;
- spvCheckReturn(spvValidateIDs(instructions.data(), instructions.size(),
- context->opcode_table, context->operand_table,
- context->ext_inst_table, vstate, &position,
- pDiagnostic));
-
- return SPV_SUCCESS;
+ return spvValidateIDs(instructions.data(), instructions.size(),
+ context->opcode_table, context->operand_table,
+ context->ext_inst_table, vstate, &position,
+ pDiagnostic);
}
const spv_ext_inst_table extInstTable,
spv_position position, spv_diagnostic* pDiagnostic);
-#define spvCheckReturn(expression) \
- if (spv_result_t error = (expression)) return error;
-
#endif // LIBSPIRV_VALIDATE_H_
auto ignore_edge = [](cbb_ptr, cbb_ptr) {};
if (!function.ordered_blocks().empty()) {
/// calculate dominators
- DepthFirstTraversal(function.first_block(),
- function.AugmentedCFGSuccessorsFunction(),
- ignore_block,
- [&](cbb_ptr b) { postorder.push_back(b); },
- ignore_edge);
+ DepthFirstTraversal(
+ function.first_block(), function.AugmentedCFGSuccessorsFunction(),
+ ignore_block, [&](cbb_ptr b) { postorder.push_back(b); },
+ ignore_edge);
auto edges = libspirv::CalculateDominators(
postorder, function.AugmentedCFGPredecessorsFunction());
for (auto edge : edges) {
}
/// calculate post dominators
- DepthFirstTraversal(function.pseudo_exit_block(),
- function.AugmentedCFGPredecessorsFunction(),
- ignore_block,
- [&](cbb_ptr b) { postdom_postorder.push_back(b); },
- ignore_edge);
+ DepthFirstTraversal(
+ function.pseudo_exit_block(),
+ function.AugmentedCFGPredecessorsFunction(), ignore_block,
+ [&](cbb_ptr b) { postdom_postorder.push_back(b); }, ignore_edge);
auto postdom_edges = libspirv::CalculateDominators(
postdom_postorder, function.AugmentedCFGSuccessorsFunction());
for (auto edge : postdom_edges) {
/// Structured control flow checks are only required for shader capabilities
if (_.HasCapability(SpvCapabilityShader)) {
- spvCheckReturn(StructuredControlFlowChecks(_, function, back_edges));
+ if (auto error = StructuredControlFlowChecks(_, function, back_edges))
+ return error;
}
}
return SPV_SUCCESS;
SpvOp opcode = static_cast<SpvOp>(inst->opcode);
switch (opcode) {
case SpvOpLabel:
- spvCheckReturn(_.current_function().RegisterBlock(inst->result_id));
+ if (auto error = _.current_function().RegisterBlock(inst->result_id))
+ return error;
break;
case SpvOpLoopMerge: {
uint32_t merge_block = inst->words[inst->operands[0].offset];
uint32_t continue_block = inst->words[inst->operands[1].offset];
CFG_ASSERT(MergeBlockAssert, merge_block);
- spvCheckReturn(
- _.current_function().RegisterLoopMerge(merge_block, continue_block));
+ if (auto error = _.current_function().RegisterLoopMerge(merge_block,
+ continue_block))
+ return error;
} break;
case SpvOpSelectionMerge: {
uint32_t merge_block = inst->words[inst->operands[0].offset];
CFG_ASSERT(MergeBlockAssert, merge_block);
- spvCheckReturn(_.current_function().RegisterSelectionMerge(merge_block));
+ if (auto error = _.current_function().RegisterSelectionMerge(merge_block))
+ return error;
} break;
case SpvOpBranch: {
uint32_t target = inst->words[inst->operands[0].offset];
}
auto control_mask = static_cast<SpvFunctionControlMask>(
inst->words[inst->operands[2].offset]);
- spvCheckReturn(
- _.RegisterFunction(inst->result_id, inst->type_id, control_mask,
- inst->words[inst->operands[3].offset]));
- if (_.current_layout_section() == kLayoutFunctionDefinitions)
- spvCheckReturn(_.current_function().RegisterSetFunctionDeclType(
- FunctionDecl::kFunctionDeclDefinition));
+ if (auto error =
+ _.RegisterFunction(inst->result_id, inst->type_id, control_mask,
+ inst->words[inst->operands[3].offset]))
+ return error;
+ if (_.current_layout_section() == kLayoutFunctionDefinitions) {
+ if (auto error = _.current_function().RegisterSetFunctionDeclType(
+ FunctionDecl::kFunctionDeclDefinition))
+ return error;
+ }
} break;
case SpvOpFunctionParameter:
<< "Function parameters must only appear immediately after "
"the function definition";
}
- spvCheckReturn(_.current_function().RegisterFunctionParameter(
- inst->result_id, inst->type_id));
+ if (auto error = _.current_function().RegisterFunctionParameter(
+ inst->result_id, inst->type_id))
+ return error;
break;
case SpvOpFunctionEnd:
"function definitions.";
}
if (_.current_layout_section() == kLayoutFunctionDeclarations) {
- spvCheckReturn(_.current_function().RegisterSetFunctionDeclType(
- FunctionDecl::kFunctionDeclDeclaration));
+ if (auto error = _.current_function().RegisterSetFunctionDeclType(
+ FunctionDecl::kFunctionDeclDeclaration))
+ return error;
}
- spvCheckReturn(_.RegisterFunctionEnd());
+ if (auto error = _.RegisterFunctionEnd()) return error;
break;
case SpvOpLine:
}
if (_.current_layout_section() == kLayoutFunctionDeclarations) {
_.ProgressToNextLayoutSectionOrder();
- spvCheckReturn(_.current_function().RegisterSetFunctionDeclType(
- FunctionDecl::kFunctionDeclDefinition));
+ if (auto error = _.current_function().RegisterSetFunctionDeclType(
+ FunctionDecl::kFunctionDeclDefinition))
+ return error;
}
break;
case kLayoutDebug2:
case kLayoutAnnotations:
case kLayoutTypes:
- spvCheckReturn(ModuleScopedInstructions(_, inst, opcode));
+ if (auto error = ModuleScopedInstructions(_, inst, opcode)) return error;
break;
case kLayoutFunctionDeclarations:
case kLayoutFunctionDefinitions:
- spvCheckReturn(FunctionScopedInstructions(_, inst, opcode));
+ if (auto error = FunctionScopedInstructions(_, inst, opcode)) {
+ return error;
+ }
break;
- } // switch(getLayoutSection())
+ }
return SPV_SUCCESS;
}
} /// namespace libspirv