mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 18:29:23 +00:00
ast: Add Source argument to literals
Bug: tint:396 Bug: tint:390 Change-Id: Ib78c19533dc65c85e2381bf1ce0d0966dd7babe9 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35019 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
604bc72dd9
commit
5ed161b2d9
@@ -695,7 +695,7 @@ void FunctionEmitter::PushTrueGuard(uint32_t end_id) {
|
||||
assert(!statements_stack_.empty());
|
||||
const auto& top = statements_stack_.back();
|
||||
|
||||
auto* cond = MakeTrue();
|
||||
auto* cond = MakeTrue(Source{});
|
||||
auto* body = create<ast::BlockStatement>();
|
||||
AddStatement(
|
||||
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
|
||||
@@ -2142,7 +2142,7 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
|
||||
ast::StorageClass::kFunction, // storage_class
|
||||
parser_impl_.Bool(), // type
|
||||
false, // is_const
|
||||
MakeTrue(), // constructor
|
||||
MakeTrue(Source{}), // constructor
|
||||
ast::VariableDecorationList{}); // decorations
|
||||
auto* guard_decl = create<ast::VariableDeclStatement>(guard_var);
|
||||
AddStatement(guard_decl);
|
||||
@@ -2354,10 +2354,10 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
|
||||
const uint32_t value32 = uint32_t(value & 0xFFFFFFFF);
|
||||
if (selector.type->is_unsigned_scalar_or_vector()) {
|
||||
selectors.emplace_back(
|
||||
create<ast::UintLiteral>(selector.type, value32));
|
||||
create<ast::UintLiteral>(Source{}, selector.type, value32));
|
||||
} else {
|
||||
selectors.emplace_back(
|
||||
create<ast::SintLiteral>(selector.type, value32));
|
||||
create<ast::SintLiteral>(Source{}, selector.type, value32));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2572,7 +2572,7 @@ ast::Statement* FunctionEmitter::MakeBranchDetailed(
|
||||
return create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>(
|
||||
ast_module_.RegisterSymbol(flow_guard), flow_guard),
|
||||
MakeFalse());
|
||||
MakeFalse(Source{}));
|
||||
}
|
||||
|
||||
// For an unconditional branch, the break out to an if-selection
|
||||
@@ -3256,7 +3256,7 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
|
||||
auto make_index = [this](uint32_t literal) {
|
||||
auto* type = create<ast::type::U32>();
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(type, literal));
|
||||
create<ast::UintLiteral>(Source{}, type, literal));
|
||||
};
|
||||
|
||||
const auto composite = inst.GetSingleWordInOperand(0);
|
||||
@@ -3356,15 +3356,15 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
|
||||
return current_expr;
|
||||
}
|
||||
|
||||
ast::Expression* FunctionEmitter::MakeTrue() const {
|
||||
ast::Expression* FunctionEmitter::MakeTrue(const Source& source) const {
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(parser_impl_.Bool(), true));
|
||||
create<ast::BoolLiteral>(source, parser_impl_.Bool(), true));
|
||||
}
|
||||
|
||||
ast::Expression* FunctionEmitter::MakeFalse() const {
|
||||
ast::Expression* FunctionEmitter::MakeFalse(const Source& source) const {
|
||||
ast::type::Bool bool_type;
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(parser_impl_.Bool(), false));
|
||||
create<ast::BoolLiteral>(source, parser_impl_.Bool(), false));
|
||||
}
|
||||
|
||||
TypedExpression FunctionEmitter::MakeVectorShuffle(
|
||||
|
||||
@@ -698,7 +698,7 @@ class FunctionEmitter {
|
||||
/// return the given value. Otherwise, wrap the value in a TypeConstructor
|
||||
/// expression.
|
||||
/// @param value the value to pass through or convert
|
||||
/// @reutrns the value as an I32 value.
|
||||
/// @returns the value as an I32 value.
|
||||
TypedExpression ToI32(TypedExpression value);
|
||||
|
||||
private:
|
||||
@@ -865,10 +865,10 @@ class FunctionEmitter {
|
||||
void PushTrueGuard(uint32_t end_id);
|
||||
|
||||
/// @returns a boolean true expression.
|
||||
ast::Expression* MakeTrue() const;
|
||||
ast::Expression* MakeTrue(const Source&) const;
|
||||
|
||||
/// @returns a boolean false expression.
|
||||
ast::Expression* MakeFalse() const;
|
||||
ast::Expression* MakeFalse(const Source&) const;
|
||||
|
||||
/// Creates a new `ast::Node` owned by the Module. When the Module is
|
||||
/// destructed, the `ast::Node` will also be destructed.
|
||||
|
||||
@@ -1033,7 +1033,7 @@ bool ParserImpl::EmitScalarSpecConstants() {
|
||||
ast_type = ConvertType(inst.type_id());
|
||||
ast_expr =
|
||||
create<ast::ScalarConstructorExpression>(create<ast::BoolLiteral>(
|
||||
ast_type, inst.opcode() == SpvOpSpecConstantTrue));
|
||||
Source{}, ast_type, inst.opcode() == SpvOpSpecConstantTrue));
|
||||
break;
|
||||
}
|
||||
case SpvOpSpecConstant: {
|
||||
@@ -1042,17 +1042,17 @@ bool ParserImpl::EmitScalarSpecConstants() {
|
||||
if (ast_type->Is<ast::type::I32>()) {
|
||||
ast_expr =
|
||||
create<ast::ScalarConstructorExpression>(create<ast::SintLiteral>(
|
||||
ast_type, static_cast<int32_t>(literal_value)));
|
||||
Source{}, ast_type, static_cast<int32_t>(literal_value)));
|
||||
} else if (ast_type->Is<ast::type::U32>()) {
|
||||
ast_expr =
|
||||
create<ast::ScalarConstructorExpression>(create<ast::UintLiteral>(
|
||||
ast_type, static_cast<uint32_t>(literal_value)));
|
||||
Source{}, ast_type, static_cast<uint32_t>(literal_value)));
|
||||
} else if (ast_type->Is<ast::type::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>(
|
||||
create<ast::FloatLiteral>(ast_type, float_value));
|
||||
create<ast::FloatLiteral>(Source{}, ast_type, float_value));
|
||||
} else {
|
||||
return Fail() << " invalid result type for OpSpecConstant "
|
||||
<< inst.PrettyPrint();
|
||||
@@ -1314,6 +1314,7 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto source = GetSourceForInst(inst);
|
||||
auto* ast_type = original_ast_type->UnwrapIfNeeded();
|
||||
|
||||
// TODO(dneto): Note: NullConstant for int, uint, float map to a regular 0.
|
||||
@@ -1322,25 +1323,25 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
|
||||
// See https://bugs.chromium.org/p/tint/issues/detail?id=34
|
||||
if (ast_type->Is<ast::type::U32>()) {
|
||||
return {ast_type,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(ast_type, spirv_const->GetU32()))};
|
||||
create<ast::ScalarConstructorExpression>(create<ast::UintLiteral>(
|
||||
source, ast_type, spirv_const->GetU32()))};
|
||||
}
|
||||
if (ast_type->Is<ast::type::I32>()) {
|
||||
return {ast_type,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(ast_type, spirv_const->GetS32()))};
|
||||
create<ast::ScalarConstructorExpression>(create<ast::SintLiteral>(
|
||||
source, ast_type, spirv_const->GetS32()))};
|
||||
}
|
||||
if (ast_type->Is<ast::type::F32>()) {
|
||||
return {ast_type,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(ast_type, spirv_const->GetFloat()))};
|
||||
create<ast::ScalarConstructorExpression>(create<ast::FloatLiteral>(
|
||||
source, ast_type, spirv_const->GetFloat()))};
|
||||
}
|
||||
if (ast_type->Is<ast::type::Bool>()) {
|
||||
const bool value = spirv_const->AsNullConstant()
|
||||
? false
|
||||
: spirv_const->AsBoolConstant()->value();
|
||||
return {ast_type, create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(ast_type, value))};
|
||||
create<ast::BoolLiteral>(source, ast_type, value))};
|
||||
}
|
||||
auto* spirv_composite_const = spirv_const->AsCompositeConstant();
|
||||
if (spirv_composite_const != nullptr) {
|
||||
@@ -1394,19 +1395,19 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
|
||||
|
||||
if (type->Is<ast::type::Bool>()) {
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(type, false));
|
||||
create<ast::BoolLiteral>(Source{}, type, false));
|
||||
}
|
||||
if (type->Is<ast::type::U32>()) {
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(type, 0u));
|
||||
create<ast::UintLiteral>(Source{}, type, 0u));
|
||||
}
|
||||
if (type->Is<ast::type::I32>()) {
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(type, 0));
|
||||
create<ast::SintLiteral>(Source{}, type, 0));
|
||||
}
|
||||
if (type->Is<ast::type::F32>()) {
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(type, 0.0f));
|
||||
create<ast::FloatLiteral>(Source{}, type, 0.0f));
|
||||
}
|
||||
if (const auto* vec_ty = type->As<ast::type::Vector>()) {
|
||||
ast::ExpressionList ast_components;
|
||||
|
||||
@@ -2678,19 +2678,19 @@ Maybe<ast::Literal*> ParserImpl::const_literal() {
|
||||
auto t = peek();
|
||||
if (match(Token::Type::kTrue)) {
|
||||
auto* type = module_.create<ast::type::Bool>();
|
||||
return create<ast::BoolLiteral>(type, true);
|
||||
return create<ast::BoolLiteral>(Source{}, type, true);
|
||||
}
|
||||
if (match(Token::Type::kFalse)) {
|
||||
auto* type = module_.create<ast::type::Bool>();
|
||||
return create<ast::BoolLiteral>(type, false);
|
||||
return create<ast::BoolLiteral>(Source{}, type, false);
|
||||
}
|
||||
if (match(Token::Type::kSintLiteral)) {
|
||||
auto* type = module_.create<ast::type::I32>();
|
||||
return create<ast::SintLiteral>(type, t.to_i32());
|
||||
return create<ast::SintLiteral>(Source{}, type, t.to_i32());
|
||||
}
|
||||
if (match(Token::Type::kUintLiteral)) {
|
||||
auto* type = module_.create<ast::type::U32>();
|
||||
return create<ast::UintLiteral>(type, t.to_u32());
|
||||
return create<ast::UintLiteral>(Source{}, type, t.to_u32());
|
||||
}
|
||||
if (match(Token::Type::kFloatLiteral)) {
|
||||
auto p = peek();
|
||||
@@ -2699,7 +2699,7 @@ Maybe<ast::Literal*> ParserImpl::const_literal() {
|
||||
add_error(p.source(), "float literals must not be suffixed with 'f'");
|
||||
}
|
||||
auto* type = module_.create<ast::type::F32>();
|
||||
return create<ast::FloatLiteral>(type, t.to_f32());
|
||||
return create<ast::FloatLiteral>(Source{}, type, t.to_f32());
|
||||
}
|
||||
return Failure::kNoMatch;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user