pub struct Lowerer<'source, 'temp> {
index: &'temp Index<'source>,
layouter: Layouter,
}
Fields§
§index: &'temp Index<'source>
§layouter: Layouter
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>, 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>, 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>>, Error<'source>>
fn constructor<'out>( &mut self, constructor: &ConstructorType<'source>, ctx: &mut ExpressionContext<'source, '_, 'out>, ) -> Result<Constructor<Handle<Type>>, 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 fn new(index: &'temp Index<'source>) -> Self
pub fn lower( &mut self, tu: &'temp TranslationUnit<'source>, ) -> Result<Module, Error<'source>>
fn function( &mut self, f: &Function<'source>, span: Span, ctx: &mut GlobalContext<'source, '_, '_>, ) -> Result<LoweredGlobalDecl, Error<'source>>
fn workgroup_size_override( &mut self, size_expr: Handle<Expression<'source>>, ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Handle<Expression>, Error<'source>>
fn block( &mut self, b: &Block<'source>, is_inside_loop: bool, ctx: &mut StatementContext<'source, '_, '_>, ) -> Result<Block, Error<'source>>
fn statement( &mut self, stmt: &Statement<'source>, block: &mut Block, is_inside_loop: bool, ctx: &mut StatementContext<'source, '_, '_>, ) -> Result<(), Error<'source>>
sourcefn expression(
&mut self,
expr: Handle<Expression<'source>>,
ctx: &mut ExpressionContext<'source, '_, '_>,
) -> Result<Handle<Expression>, Error<'source>>
fn expression( &mut self, expr: Handle<Expression<'source>>, ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Handle<Expression>, 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>, Error<'source>>
fn expression_for_reference( &mut self, expr: Handle<Expression<'source>>, ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Typed<Handle<Expression>>, 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>, 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>>, 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>>, 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.
fn atomic_pointer( &mut self, expr: Handle<Expression<'source>>, ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Handle<Expression>, 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>>, Error<'source>>
fn texture_sample_helper( &mut self, fun: Texture, args: &[Handle<Expression<'source>>], span: Span, ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Expression, 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>, Error<'source>>
fn subgroup_gather_helper( &mut self, span: Span, mode: SubgroupGather, arguments: &[Handle<Expression<'source>>], ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<Handle<Expression>, Error<'source>>
fn struct( &mut self, s: &Struct<'source>, span: Span, ctx: &mut GlobalContext<'source, '_, '_>, ) -> Result<Handle<Type>, Error<'source>>
fn const_u32( &mut self, expr: Handle<Expression<'source>>, ctx: &mut ExpressionContext<'source, '_, '_>, ) -> Result<(u32, Span), Error<'source>>
fn array_size( &mut self, size: ArraySize<'source>, ctx: &mut GlobalContext<'source, '_, '_>, ) -> Result<ArraySize, Error<'source>>
fn array_size_override( &mut self, size_expr: Handle<Expression<'source>>, ctx: &mut ExpressionContext<'source, '_, '_>, span: Span, ) -> Result<PendingArraySize, Error<'source>>
sourcefn resolve_named_ast_type(
&mut self,
handle: Handle<Type<'source>>,
name: Option<String>,
ctx: &mut GlobalContext<'source, '_, '_>,
) -> Result<Handle<Type>, Error<'source>>
fn resolve_named_ast_type( &mut self, handle: Handle<Type<'source>>, name: Option<String>, ctx: &mut GlobalContext<'source, '_, '_>, ) -> Result<Handle<Type>, 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 GlobalContext<'source, '_, '_>,
) -> Result<Handle<Type>, Error<'source>>
fn resolve_ast_type( &mut self, handle: Handle<Type<'source>>, ctx: &mut GlobalContext<'source, '_, '_>, ) -> Result<Handle<Type>, Error<'source>>
Return a Naga Handle<Type>
representing the front-end type handle
.