mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 05:57:51 +00:00
ast: Remove types from ast::Literals
A literal has an implicit type, so there should be no type on the AST node. This highlighted that the resolver was nto canonicalizing TypeConstructorExpression types, which has been fixed. This required preservation of the declared type name in order for error messages to contain aliased names. Bug: tint:724 Change-Id: I21594a3e8a0fb1b73c6c5b46a14b8664b7f28512 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49345 Reviewed-by: Antonio Maiorano <amaiorano@google.com> Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
0bf0fb9b29
commit
109b18f504
@@ -2032,10 +2032,9 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) {
|
||||
<< id;
|
||||
return {};
|
||||
case SkipReason::kPointSizeBuiltinValue: {
|
||||
auto* f32 = create<sem::F32>();
|
||||
return {f32,
|
||||
return {create<sem::F32>(),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, f32, 1.0f))};
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, 1.0f))};
|
||||
}
|
||||
case SkipReason::kPointSizeBuiltinPointer:
|
||||
Fail() << "unhandled use of a pointer to the PointSize builtin, with ID: "
|
||||
@@ -2545,11 +2544,9 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
|
||||
// The Tint AST handles 32-bit values.
|
||||
const uint32_t value32 = uint32_t(value & 0xFFFFFFFF);
|
||||
if (selector.type->is_unsigned_scalar_or_vector()) {
|
||||
selectors.emplace_back(
|
||||
create<ast::UintLiteral>(Source{}, selector.type, value32));
|
||||
selectors.emplace_back(create<ast::UintLiteral>(Source{}, value32));
|
||||
} else {
|
||||
selectors.emplace_back(
|
||||
create<ast::SintLiteral>(Source{}, selector.type, value32));
|
||||
selectors.emplace_back(create<ast::SintLiteral>(Source{}, value32));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3679,7 +3676,7 @@ TypedExpression FunctionEmitter::MakeCompositeValueDecomposition(
|
||||
|
||||
auto make_index = [this](uint32_t literal) {
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(Source{}, u32_, literal));
|
||||
Source{}, create<ast::UintLiteral>(Source{}, literal));
|
||||
};
|
||||
|
||||
// Build up a nested expression for the decomposition by walking down the type
|
||||
@@ -3795,13 +3792,13 @@ TypedExpression FunctionEmitter::MakeCompositeValueDecomposition(
|
||||
|
||||
ast::Expression* FunctionEmitter::MakeTrue(const Source& source) const {
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
source, create<ast::BoolLiteral>(source, parser_impl_.Bool(), true));
|
||||
source, create<ast::BoolLiteral>(source, true));
|
||||
}
|
||||
|
||||
ast::Expression* FunctionEmitter::MakeFalse(const Source& source) const {
|
||||
sem::Bool bool_type;
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
source, create<ast::BoolLiteral>(source, parser_impl_.Bool(), false));
|
||||
source, create<ast::BoolLiteral>(source, false));
|
||||
}
|
||||
|
||||
TypedExpression FunctionEmitter::MakeVectorShuffle(
|
||||
|
||||
@@ -1066,9 +1066,8 @@ bool ParserImpl::EmitScalarSpecConstants() {
|
||||
case SpvOpSpecConstantFalse: {
|
||||
ast_type = ConvertType(inst.type_id());
|
||||
ast_expr = create<ast::ScalarConstructorExpression>(
|
||||
Source{},
|
||||
create<ast::BoolLiteral>(Source{}, ast_type,
|
||||
inst.opcode() == SpvOpSpecConstantTrue));
|
||||
Source{}, create<ast::BoolLiteral>(
|
||||
Source{}, inst.opcode() == SpvOpSpecConstantTrue));
|
||||
break;
|
||||
}
|
||||
case SpvOpSpecConstant: {
|
||||
@@ -1076,21 +1075,18 @@ bool ParserImpl::EmitScalarSpecConstants() {
|
||||
const uint32_t literal_value = inst.GetSingleWordInOperand(0);
|
||||
if (ast_type->Is<sem::I32>()) {
|
||||
ast_expr = create<ast::ScalarConstructorExpression>(
|
||||
Source{},
|
||||
create<ast::SintLiteral>(Source{}, ast_type,
|
||||
static_cast<int32_t>(literal_value)));
|
||||
Source{}, create<ast::SintLiteral>(
|
||||
Source{}, static_cast<int32_t>(literal_value)));
|
||||
} else if (ast_type->Is<sem::U32>()) {
|
||||
ast_expr = create<ast::ScalarConstructorExpression>(
|
||||
Source{},
|
||||
create<ast::UintLiteral>(Source{}, ast_type,
|
||||
static_cast<uint32_t>(literal_value)));
|
||||
Source{}, create<ast::UintLiteral>(
|
||||
Source{}, static_cast<uint32_t>(literal_value)));
|
||||
} else if (ast_type->Is<sem::F32>()) {
|
||||
float float_value;
|
||||
// Copy the bits so we can read them as a float.
|
||||
std::memcpy(&float_value, &literal_value, sizeof(float_value));
|
||||
ast_expr = create<ast::ScalarConstructorExpression>(
|
||||
Source{},
|
||||
create<ast::FloatLiteral>(Source{}, ast_type, float_value));
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, float_value));
|
||||
} else {
|
||||
return Fail() << " invalid result type for OpSpecConstant "
|
||||
<< inst.PrettyPrint();
|
||||
@@ -1421,30 +1417,26 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
|
||||
// Currently "null<type>" is missing from the WGSL parser.
|
||||
// See https://bugs.chromium.org/p/tint/issues/detail?id=34
|
||||
if (ast_type->Is<sem::U32>()) {
|
||||
return {ast_type,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(source, ast_type,
|
||||
spirv_const->GetU32()))};
|
||||
return {ast_type, create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(
|
||||
source, spirv_const->GetU32()))};
|
||||
}
|
||||
if (ast_type->Is<sem::I32>()) {
|
||||
return {ast_type,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(source, ast_type,
|
||||
spirv_const->GetS32()))};
|
||||
return {ast_type, create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(
|
||||
source, spirv_const->GetS32()))};
|
||||
}
|
||||
if (ast_type->Is<sem::F32>()) {
|
||||
return {ast_type,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(source, ast_type,
|
||||
spirv_const->GetFloat()))};
|
||||
return {ast_type, create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(
|
||||
source, spirv_const->GetFloat()))};
|
||||
}
|
||||
if (ast_type->Is<sem::Bool>()) {
|
||||
const bool value = spirv_const->AsNullConstant()
|
||||
? false
|
||||
: spirv_const->AsBoolConstant()->value();
|
||||
return {ast_type,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::BoolLiteral>(source, ast_type, value))};
|
||||
return {ast_type, create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::BoolLiteral>(source, value))};
|
||||
}
|
||||
auto* spirv_composite_const = spirv_const->AsCompositeConstant();
|
||||
if (spirv_composite_const != nullptr) {
|
||||
@@ -1498,19 +1490,19 @@ ast::Expression* ParserImpl::MakeNullValue(sem::Type* type) {
|
||||
|
||||
if (type->Is<sem::Bool>()) {
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::BoolLiteral>(Source{}, type, false));
|
||||
Source{}, create<ast::BoolLiteral>(Source{}, false));
|
||||
}
|
||||
if (type->Is<sem::U32>()) {
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(Source{}, type, 0u));
|
||||
Source{}, create<ast::UintLiteral>(Source{}, 0u));
|
||||
}
|
||||
if (type->Is<sem::I32>()) {
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, type, 0));
|
||||
Source{}, create<ast::SintLiteral>(Source{}, 0));
|
||||
}
|
||||
if (type->Is<sem::F32>()) {
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, type, 0.0f));
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, 0.0f));
|
||||
}
|
||||
if (const auto* vec_ty = type->As<sem::Vector>()) {
|
||||
ast::ExpressionList ast_components;
|
||||
|
||||
@@ -2840,20 +2840,16 @@ Maybe<ast::AssignmentStatement*> ParserImpl::assignment_stmt() {
|
||||
Maybe<ast::Literal*> ParserImpl::const_literal() {
|
||||
auto t = peek();
|
||||
if (match(Token::Type::kTrue)) {
|
||||
auto* type = builder_.create<sem::Bool>();
|
||||
return create<ast::BoolLiteral>(Source{}, type, true);
|
||||
return create<ast::BoolLiteral>(Source{}, true);
|
||||
}
|
||||
if (match(Token::Type::kFalse)) {
|
||||
auto* type = builder_.create<sem::Bool>();
|
||||
return create<ast::BoolLiteral>(Source{}, type, false);
|
||||
return create<ast::BoolLiteral>(Source{}, false);
|
||||
}
|
||||
if (match(Token::Type::kSintLiteral)) {
|
||||
auto* type = builder_.create<sem::I32>();
|
||||
return create<ast::SintLiteral>(Source{}, type, t.to_i32());
|
||||
return create<ast::SintLiteral>(Source{}, t.to_i32());
|
||||
}
|
||||
if (match(Token::Type::kUintLiteral)) {
|
||||
auto* type = builder_.create<sem::U32>();
|
||||
return create<ast::UintLiteral>(Source{}, type, t.to_u32());
|
||||
return create<ast::UintLiteral>(Source{}, t.to_u32());
|
||||
}
|
||||
if (match(Token::Type::kFloatLiteral)) {
|
||||
auto p = peek();
|
||||
@@ -2861,8 +2857,7 @@ Maybe<ast::Literal*> ParserImpl::const_literal() {
|
||||
next(); // Consume 'f'
|
||||
add_error(p.source(), "float literals must not be suffixed with 'f'");
|
||||
}
|
||||
auto* type = builder_.create<sem::F32>();
|
||||
return create<ast::FloatLiteral>(Source{}, type, t.to_f32());
|
||||
return create<ast::FloatLiteral>(Source{}, t.to_f32());
|
||||
}
|
||||
return Failure::kNoMatch;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user