mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-01 20:21:23 +00:00
Parsers need fixing up. Bug: tint:396 Bug: tint:390 Change-Id: I7f823e2489101b43c1b21a6b89c248695a3f35b7 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35160 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
78 lines
2.8 KiB
C++
78 lines
2.8 KiB
C++
// Copyright 2020 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 <memory>
|
|
|
|
#include "gtest/gtest.h"
|
|
#include "src/ast/binary_expression.h"
|
|
#include "src/ast/identifier_expression.h"
|
|
#include "src/ast/module.h"
|
|
#include "src/writer/msl/generator_impl.h"
|
|
#include "src/writer/msl/test_helper.h"
|
|
|
|
namespace tint {
|
|
namespace writer {
|
|
namespace msl {
|
|
namespace {
|
|
|
|
struct BinaryData {
|
|
const char* result;
|
|
ast::BinaryOp op;
|
|
};
|
|
inline std::ostream& operator<<(std::ostream& out, BinaryData data) {
|
|
out << data.op;
|
|
return out;
|
|
}
|
|
using MslBinaryTest = TestParamHelper<BinaryData>;
|
|
TEST_P(MslBinaryTest, Emit) {
|
|
auto params = GetParam();
|
|
|
|
auto* left = create<ast::IdentifierExpression>(
|
|
Source{}, mod.RegisterSymbol("left"), "left");
|
|
auto* right = create<ast::IdentifierExpression>(
|
|
Source{}, mod.RegisterSymbol("right"), "right");
|
|
|
|
ast::BinaryExpression expr(Source{}, params.op, left, right);
|
|
|
|
ASSERT_TRUE(gen.EmitExpression(&expr)) << gen.error();
|
|
EXPECT_EQ(gen.result(), params.result);
|
|
}
|
|
INSTANTIATE_TEST_SUITE_P(
|
|
MslGeneratorImplTest,
|
|
MslBinaryTest,
|
|
testing::Values(
|
|
BinaryData{"(left & right)", ast::BinaryOp::kAnd},
|
|
BinaryData{"(left | right)", ast::BinaryOp::kOr},
|
|
BinaryData{"(left ^ right)", ast::BinaryOp::kXor},
|
|
BinaryData{"(left && right)", ast::BinaryOp::kLogicalAnd},
|
|
BinaryData{"(left || right)", ast::BinaryOp::kLogicalOr},
|
|
BinaryData{"(left == right)", ast::BinaryOp::kEqual},
|
|
BinaryData{"(left != right)", ast::BinaryOp::kNotEqual},
|
|
BinaryData{"(left < right)", ast::BinaryOp::kLessThan},
|
|
BinaryData{"(left > right)", ast::BinaryOp::kGreaterThan},
|
|
BinaryData{"(left <= right)", ast::BinaryOp::kLessThanEqual},
|
|
BinaryData{"(left >= right)", ast::BinaryOp::kGreaterThanEqual},
|
|
BinaryData{"(left << right)", ast::BinaryOp::kShiftLeft},
|
|
BinaryData{"(left >> right)", ast::BinaryOp::kShiftRight},
|
|
BinaryData{"(left + right)", ast::BinaryOp::kAdd},
|
|
BinaryData{"(left - right)", ast::BinaryOp::kSubtract},
|
|
BinaryData{"(left * right)", ast::BinaryOp::kMultiply},
|
|
BinaryData{"(left / right)", ast::BinaryOp::kDivide},
|
|
BinaryData{"(left % right)", ast::BinaryOp::kModulo}));
|
|
|
|
} // namespace
|
|
} // namespace msl
|
|
} // namespace writer
|
|
} // namespace tint
|