2016-01-14 04:25:11 +00:00
|
|
|
// Copyright (c) 2015-2016 The Khronos Group Inc.
|
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// 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
|
2016-01-14 04:25:11 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2016-01-14 04:25:11 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// 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.
|
2016-01-14 04:25:11 +00:00
|
|
|
|
2016-11-08 18:26:09 +00:00
|
|
|
#include "val/construct.h"
|
2016-01-14 04:25:11 +00:00
|
|
|
|
2016-06-04 01:24:24 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstddef>
|
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
namespace libspirv {
|
2016-01-14 04:25:11 +00:00
|
|
|
|
2017-11-08 17:40:02 +00:00
|
|
|
Construct::Construct(ConstructType construct_type, BasicBlock* entry,
|
|
|
|
BasicBlock* exit, std::vector<Construct*> constructs)
|
2016-06-25 03:45:25 +00:00
|
|
|
: type_(construct_type),
|
2016-06-04 01:24:24 +00:00
|
|
|
corresponding_constructs_(constructs),
|
|
|
|
entry_block_(entry),
|
|
|
|
exit_block_(exit) {}
|
|
|
|
|
2016-06-25 03:45:25 +00:00
|
|
|
ConstructType Construct::type() const { return type_; }
|
2016-06-04 01:24:24 +00:00
|
|
|
|
2016-06-25 03:45:25 +00:00
|
|
|
const std::vector<Construct*>& Construct::corresponding_constructs() const {
|
2016-06-04 01:24:24 +00:00
|
|
|
return corresponding_constructs_;
|
|
|
|
}
|
2016-06-25 03:45:25 +00:00
|
|
|
std::vector<Construct*>& Construct::corresponding_constructs() {
|
2016-06-04 01:24:24 +00:00
|
|
|
return corresponding_constructs_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ValidateConstructSize(ConstructType type, size_t size) {
|
|
|
|
switch (type) {
|
2017-11-08 17:40:02 +00:00
|
|
|
case ConstructType::kSelection:
|
|
|
|
return size == 0;
|
|
|
|
case ConstructType::kContinue:
|
|
|
|
return size == 1;
|
|
|
|
case ConstructType::kLoop:
|
|
|
|
return size == 1;
|
|
|
|
case ConstructType::kCase:
|
|
|
|
return size >= 1;
|
|
|
|
default:
|
|
|
|
assert(1 == 0 && "Type not defined");
|
2016-06-04 01:24:24 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Construct::set_corresponding_constructs(
|
|
|
|
std::vector<Construct*> constructs) {
|
|
|
|
assert(ValidateConstructSize(type_, constructs.size()));
|
|
|
|
corresponding_constructs_ = constructs;
|
|
|
|
}
|
|
|
|
|
2016-06-25 03:45:25 +00:00
|
|
|
const BasicBlock* Construct::entry_block() const { return entry_block_; }
|
|
|
|
BasicBlock* Construct::entry_block() { return entry_block_; }
|
2016-01-14 04:25:11 +00:00
|
|
|
|
2016-06-25 03:45:25 +00:00
|
|
|
const BasicBlock* Construct::exit_block() const { return exit_block_; }
|
|
|
|
BasicBlock* Construct::exit_block() { return exit_block_; }
|
2016-01-14 04:25:11 +00:00
|
|
|
|
2016-06-25 03:45:25 +00:00
|
|
|
void Construct::set_exit(BasicBlock* block) { exit_block_ = block; }
|
2017-11-27 15:16:41 +00:00
|
|
|
} // namespace libspirv
|