pub struct Lowerer<'source, 'temp> {
index: &'temp Index<'source>,
}
Fields§
§index: &'temp Index<'source>
Implementations§
Source§impl<'source> Lowerer<'source, '_>
impl<'source> Lowerer<'source, '_>
Sourcepub fn construct(
&mut self,
span: Span,
constructor: &ConstructorType<'source>,
ty_span: Span,
components: &[Handle<Expression<'source>>],
ctx: &mut ExpressionContext<'source, '_, '_>,
) -> Result<Handle<Expression>, Box<Error<'source>>>
pub fn construct( &mut self, span: Span, constructor: &ConstructorType<'source>, ty_span: Span, components: &[Handle<Expression<'source>>], ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Handle<Expression>, Box<Error<'source>>>
Generate Naga IR for a type constructor expression.
The constructor
value represents the head of the constructor
expression, which is at least a hint of which type is being built; if
it’s one of the Partial
variants, we need to consider the argument
types as well.
This is used for Construct
expressions, but also for Call
expressions, once we’ve determined that the “callable” (in WGSL spec
terms) is actually a type.
Sourcefn constructor<'out>(
&mut self,
constructor: &ConstructorType<'source>,
ctx: &mut ExpressionContext<'source, '_, 'out>,
) -> Result<Constructor<Handle<Type>>, Box<Error<'source>>>
fn constructor<'out>( &mut self, constructor: &ConstructorType<'source>, ctx: &mut ExpressionContext<'source, '_, 'out>, ) -> Result<Constructor<Handle<Type>>, Box<Error<'source>>>
Build a Constructor
for a WGSL construction expression.
If constructor
conveys enough information to determine which Naga Type
we’re actually building (i.e., it’s not a partial constructor), then
ensure the Type
exists in ctx.module
, and return
Constructor::Type
.
Otherwise, return the Constructor
partial variant corresponding to
constructor
.
Source§impl<'source, 'temp> Lowerer<'source, 'temp>
impl<'source, 'temp> Lowerer<'source, 'temp>
pub const fn new(index: &'temp Index<'source>) -> Self
pub fn lower( &mut self, tu: TranslationUnit<'source>, ) -> Result<Module, Box<Error<'source>>>
Sourcefn type_and_init(
&mut self,
name: Ident<'source>,
init: Option<Handle<Expression<'source>>>,
explicit_ty: Option<Handle<Type>>,
abstract_rule: AbstractRule,
ectx: &mut ExpressionContext<'source, '_, '_>,
) -> Result<(Handle<Type>, Option<Handle<Expression>>), Box<Error<'source>>>
fn type_and_init( &mut self, name: Ident<'source>, init: Option<Handle<Expression<'source>>>, explicit_ty: Option<Handle<Type>>, abstract_rule: AbstractRule, ectx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<(Handle<Type>, Option<Handle<Expression>>), Box<Error<'source>>>
Obtain (inferred) type and initializer after automatic conversion
fn function( &mut self, f: &Function<'source>, span: Span, ctx: &mut GlobalContext<'source, '_, '_>, ) -> Result<LoweredGlobalDecl, Box<Error<'source>>>
fn workgroup_size_override( &mut self, size_expr: Handle<Expression<'source>>, ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Handle<Expression>, Box<Error<'source>>>
fn block( &mut self, b: &Block<'source>, is_inside_loop: bool, ctx: &mut StatementContext<'source, '_, '_>, ) -> Result<Block, Box<Error<'source>>>
fn statement( &mut self, stmt: &Statement<'source>, block: &mut Block, is_inside_loop: bool, ctx: &mut StatementContext<'source, '_, '_>, ) -> Result<(), Box<Error<'source>>>
Sourcefn expression(
&mut self,
expr: Handle<Expression<'source>>,
ctx: &mut ExpressionContext<'source, '_, '_>,
) -> Result<Handle<Expression>, Box<Error<'source>>>
fn expression( &mut self, expr: Handle<Expression<'source>>, ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Handle<Expression>, Box<Error<'source>>>
Lower expr
and apply the Load Rule if possible.
For the time being, this concretizes abstract values, to support
consumers that haven’t been adapted to consume them yet. Consumers
prepared for abstract values can call expression_for_abstract
.
fn expression_for_abstract( &mut self, expr: Handle<Expression<'source>>, ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Handle<Expression>, Box<Error<'source>>>
fn expression_for_reference( &mut self, expr: Handle<Expression<'source>>, ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Typed<Handle<Expression>>, Box<Error<'source>>>
fn binary( &mut self, op: BinaryOperator, left: Handle<Expression<'source>>, right: Handle<Expression<'source>>, span: Span, ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Typed<Expression>, Box<Error<'source>>>
Sourcefn call(
&mut self,
span: Span,
function: &Ident<'source>,
arguments: &[Handle<Expression<'source>>],
ctx: &mut ExpressionContext<'source, '_, '_>,
is_statement: bool,
) -> Result<Option<Handle<Expression>>, Box<Error<'source>>>
fn call( &mut self, span: Span, function: &Ident<'source>, arguments: &[Handle<Expression<'source>>], ctx: &mut ExpressionContext<'source, '_, '_>, is_statement: bool, ) -> Result<Option<Handle<Expression>>, Box<Error<'source>>>
Generate Naga IR for call expressions and statements, and type constructor expressions.
The “function” being called is simply an Ident
that we know refers to
some module-scope definition.
-
If it is the name of a type, then the expression is a type constructor expression: either constructing a value from components, a conversion expression, or a zero value expression.
-
If it is the name of a function, then we’re generating a
Call
statement. We may be in the midst of generating code for an expression, in which case we must generate anEmit
statement to force evaluation of the IR expressions we’ve generated so far, add theCall
statement to the current block, and then resume generating expressions.
Sourcefn math_function_helper(
&mut self,
span: Span,
fun: MathFunction,
ast_arguments: &[Handle<Expression<'source>>],
ctx: &mut ExpressionContext<'source, '_, '_>,
) -> Result<Expression, Box<Error<'source>>>
fn math_function_helper( &mut self, span: Span, fun: MathFunction, ast_arguments: &[Handle<Expression<'source>>], ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Expression, Box<Error<'source>>>
Generate a Naga IR Math
expression.
Generate Naga IR for a call to the MathFunction
fun
, whose
unlowered arguments are ast_arguments
.
The span
argument should give the span of the function name in the
call expression.
Sourcefn resolve_overloads<O, F>(
&self,
span: Span,
fun: F,
overloads: O,
arguments: &[Handle<Expression>],
ctx: &ExpressionContext<'source, '_, '_>,
) -> Result<Rule, Box<Error<'source>>>
fn resolve_overloads<O, F>( &self, span: Span, fun: F, overloads: O, arguments: &[Handle<Expression>], ctx: &ExpressionContext<'source, '_, '_>, ) -> Result<Rule, Box<Error<'source>>>
Choose the right overload for a function call.
Return a Rule
representing the most preferred overload in
overloads
to apply to arguments
, or return an error explaining why
the call is not valid.
Use fun
to identify the function being called in error messages;
span
should be the span of the function name in the call expression.
Sourcefn apply_automatic_conversions_for_call(
&self,
rule: &Rule,
arguments: &mut [Handle<Expression>],
ctx: &mut ExpressionContext<'source, '_, '_>,
) -> Result<(), Box<Error<'source>>>
fn apply_automatic_conversions_for_call( &self, rule: &Rule, arguments: &mut [Handle<Expression>], ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<(), Box<Error<'source>>>
Apply automatic type conversions for a function call.
Apply whatever automatic conversions are needed to pass arguments
to
the function overload described by rule
. Update arguments
to refer
to the converted arguments.
fn atomic_pointer( &mut self, expr: Handle<Expression<'source>>, ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Handle<Expression>, Box<Error<'source>>>
fn atomic_helper( &mut self, span: Span, fun: AtomicFunction, args: &[Handle<Expression<'source>>], is_statement: bool, ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Option<Handle<Expression>>, Box<Error<'source>>>
fn texture_sample_helper( &mut self, fun: Texture, args: &[Handle<Expression<'source>>], span: Span, ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Expression, Box<Error<'source>>>
fn subgroup_operation_helper( &mut self, span: Span, op: SubgroupOperation, collective_op: CollectiveOperation, arguments: &[Handle<Expression<'source>>], ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Handle<Expression>, Box<Error<'source>>>
fn subgroup_gather_helper( &mut self, span: Span, mode: SubgroupGather, arguments: &[Handle<Expression<'source>>], ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Handle<Expression>, Box<Error<'source>>>
fn struct( &mut self, s: &Struct<'source>, span: Span, ctx: &mut GlobalContext<'source, '_, '_>, ) -> Result<Handle<Type>, Box<Error<'source>>>
fn const_u32( &mut self, expr: Handle<Expression<'source>>, ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<(u32, Span), Box<Error<'source>>>
fn array_size( &mut self, size: ArraySize<'source>, ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<ArraySize, Box<Error<'source>>>
fn array_size_override( &mut self, size_expr: Handle<Expression<'source>>, ctx: &mut ExpressionContext<'source, '_, '_>, span: Span, ) -> Result<Handle<Override>, Box<Error<'source>>>
Sourcefn resolve_named_ast_type(
&mut self,
handle: Handle<Type<'source>>,
name: Option<String>,
ctx: &mut ExpressionContext<'source, '_, '_>,
) -> Result<Handle<Type>, Box<Error<'source>>>
fn resolve_named_ast_type( &mut self, handle: Handle<Type<'source>>, name: Option<String>, ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Handle<Type>, Box<Error<'source>>>
Build the Naga equivalent of a named AST type.
Return a Naga Handle<Type>
representing the front-end type
handle
, which should be named name
, if given.
If handle
refers to a type cached in SpecialTypes
,
name
may be ignored.
Sourcefn resolve_ast_type(
&mut self,
handle: Handle<Type<'source>>,
ctx: &mut ExpressionContext<'source, '_, '_>,
) -> Result<Handle<Type>, Box<Error<'source>>>
fn resolve_ast_type( &mut self, handle: Handle<Type<'source>>, ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Handle<Type>, Box<Error<'source>>>
Return a Naga Handle<Type>
representing the front-end type handle
.