2018-01-25 23:32:01 +00:00
|
|
|
// Copyright (c) 2018 LunarG Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
// Validates correctness of the intra-block preconditions of SPIR-V
|
|
|
|
// instructions.
|
|
|
|
|
2018-07-11 14:27:34 +00:00
|
|
|
#include "source/val/validate.h"
|
2018-01-25 23:32:01 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2018-07-11 14:27:34 +00:00
|
|
|
#include "source/diagnostic.h"
|
|
|
|
#include "source/opcode.h"
|
|
|
|
#include "source/val/instruction.h"
|
|
|
|
#include "source/val/validation_state.h"
|
2018-01-25 23:32:01 +00:00
|
|
|
|
2018-07-07 13:38:00 +00:00
|
|
|
namespace spvtools {
|
2018-07-10 03:18:44 +00:00
|
|
|
namespace val {
|
2018-01-25 23:32:01 +00:00
|
|
|
|
|
|
|
spv_result_t ValidateAdjacency(ValidationState_t& _) {
|
|
|
|
const auto& instructions = _.ordered_instructions();
|
|
|
|
for (auto i = instructions.cbegin(); i != instructions.cend(); ++i) {
|
|
|
|
switch (i->opcode()) {
|
|
|
|
case SpvOpPhi:
|
|
|
|
if (i != instructions.cbegin()) {
|
|
|
|
switch (prev(i)->opcode()) {
|
|
|
|
case SpvOpLabel:
|
|
|
|
case SpvOpPhi:
|
|
|
|
case SpvOpLine:
|
|
|
|
break;
|
|
|
|
default:
|
2018-07-31 19:31:09 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, &(*i))
|
2018-01-25 23:32:01 +00:00
|
|
|
<< "OpPhi must appear before all non-OpPhi instructions "
|
|
|
|
<< "(except for OpLine, which can be mixed with OpPhi).";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SpvOpLoopMerge:
|
|
|
|
if (next(i) != instructions.cend()) {
|
|
|
|
switch (next(i)->opcode()) {
|
|
|
|
case SpvOpBranch:
|
|
|
|
case SpvOpBranchConditional:
|
|
|
|
break;
|
|
|
|
default:
|
2018-07-31 19:31:09 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, &(*i))
|
2018-01-25 23:32:01 +00:00
|
|
|
<< "OpLoopMerge must immediately precede either an "
|
|
|
|
<< "OpBranch or OpBranchConditional instruction. "
|
|
|
|
<< "OpLoopMerge must be the second-to-last instruction in "
|
|
|
|
<< "its block.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SpvOpSelectionMerge:
|
|
|
|
if (next(i) != instructions.cend()) {
|
|
|
|
switch (next(i)->opcode()) {
|
|
|
|
case SpvOpBranchConditional:
|
|
|
|
case SpvOpSwitch:
|
|
|
|
break;
|
|
|
|
default:
|
2018-07-31 19:31:09 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, &(*i))
|
2018-01-25 23:32:01 +00:00
|
|
|
<< "OpSelectionMerge must immediately precede either an "
|
|
|
|
<< "OpBranchConditional or OpSwitch instruction. "
|
|
|
|
<< "OpSelectionMerge must be the second-to-last "
|
|
|
|
<< "instruction in its block.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SPV_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-07-10 03:18:44 +00:00
|
|
|
} // namespace val
|
2018-07-07 13:38:00 +00:00
|
|
|
} // namespace spvtools
|