2021-01-26 16:57:10 +00:00
|
|
|
// Copyright 2021 The Tint Authors.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
#include "src/program.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include "src/clone_context.h"
|
|
|
|
#include "src/type/struct_type.h"
|
|
|
|
|
|
|
|
namespace tint {
|
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
Program::Program() : ast_(nodes_.Create<ast::Module>()) {}
|
2021-01-26 16:57:10 +00:00
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
Program::Program(Program&& rhs) = default;
|
2021-01-26 16:57:10 +00:00
|
|
|
|
|
|
|
Program& Program::operator=(Program&& rhs) = default;
|
|
|
|
|
|
|
|
Program::~Program() = default;
|
|
|
|
|
|
|
|
Program Program::Clone() const {
|
|
|
|
Program out;
|
|
|
|
CloneContext(&out, this).Clone();
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Program::Clone(CloneContext* ctx) const {
|
2021-01-26 16:57:10 +00:00
|
|
|
for (auto* ty : AST().ConstructedTypes()) {
|
|
|
|
ctx->dst->AST().AddConstructedType(ctx->Clone(ty));
|
2021-01-26 16:57:10 +00:00
|
|
|
}
|
2021-01-26 16:57:10 +00:00
|
|
|
for (auto* var : AST().GlobalVariables()) {
|
|
|
|
ctx->dst->AST().AddGlobalVariable(ctx->Clone(var));
|
2021-01-26 16:57:10 +00:00
|
|
|
}
|
2021-01-26 16:57:10 +00:00
|
|
|
for (auto* func : AST().Functions()) {
|
|
|
|
ctx->dst->AST().Functions().Add(ctx->Clone(func));
|
2021-01-26 16:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Program::IsValid() const {
|
2021-01-26 16:57:10 +00:00
|
|
|
return ast_->IsValid();
|
2021-01-26 16:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Program::to_str() const {
|
2021-01-26 16:57:10 +00:00
|
|
|
return ast_->to_str();
|
2021-01-26 16:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace tint
|