summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ast-expr.h
blob: fb0ac2a677cf2c84000b26b3c92266790bc439bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
// slang-ast-expr.h
#pragma once

#include "slang-ast-base.h"

//
#include "slang-ast-expr.h.fiddle"

FIDDLE()
namespace Slang
{

using SpvWord = uint32_t;

// Syntax class definitions for expressions.
//
// A placeholder for where an Expr is expected but is missing from source.
FIDDLE()
class IncompleteExpr : public Expr
{
    FIDDLE(...)
};

// Base class for expressions that will reference declarations
FIDDLE(abstract)
class DeclRefExpr : public Expr
{
    FIDDLE(...)
    // The declaration of the symbol being referenced

    FIDDLE() DeclRef<Decl> declRef;
    // The name of the symbol being referenced
    Name* name = nullptr;

    // The original expr before DeclRef resolution.
    Expr* originalExpr = nullptr;

    // The scope in which to perform lookup
    Scope* scope = nullptr;
};

FIDDLE()
class VarExpr : public DeclRefExpr
{
    FIDDLE(...)
};

FIDDLE()
class DefaultConstructExpr : public Expr
{
    FIDDLE(...)
};

// An expression that references an overloaded set of declarations
// having the same name.
FIDDLE()
class OverloadedExpr : public Expr
{
    FIDDLE(...)
    // The name that was looked up and found to be overloaded
    Name* name = nullptr;

    // Optional: the base expression is this overloaded result
    // arose from a member-reference expression.
    Expr* base = nullptr;

    Expr* originalExpr = nullptr;

    // The lookup result that was ambiguous
    LookupResult lookupResult2;
};

// An expression that references an overloaded set of declarations
// having the same name.
FIDDLE()
class OverloadedExpr2 : public Expr
{
    FIDDLE(...)
    // Optional: the base expression is this overloaded result
    // arose from a member-reference expression.
    Expr* base = nullptr;

    // The lookup result that was ambiguous
    List<Expr*> candidateExprs;
};

FIDDLE(abstract)
class LiteralExpr : public Expr
{
    FIDDLE(...)
    // The token that was used to express the literal. This can be
    // used to get the raw text of the literal, including any suffix.
    Token token;
    FIDDLE() BaseType suffixType = BaseType::Void;
};

FIDDLE()
class IntegerLiteralExpr : public LiteralExpr
{
    FIDDLE(...)
    FIDDLE() IntegerLiteralValue value;
};

FIDDLE()
class FloatingPointLiteralExpr : public LiteralExpr
{
    FIDDLE(...)
    FIDDLE() FloatingPointLiteralValue value;
};

FIDDLE()
class BoolLiteralExpr : public LiteralExpr
{
    FIDDLE(...)
    FIDDLE() bool value;
};

FIDDLE()
class NullPtrLiteralExpr : public LiteralExpr
{
    FIDDLE(...)
};

FIDDLE()
class NoneLiteralExpr : public LiteralExpr
{
    FIDDLE(...)
};

FIDDLE()
class StringLiteralExpr : public LiteralExpr
{
    FIDDLE(...)
    // TODO: consider storing the "segments" of the string
    // literal, in the case where multiple literals were
    // lined up at the lexer level, e.g.:
    //
    //      "first" "second" "third"
    //
    FIDDLE() String value;
};

FIDDLE()
class MakeArrayFromElementExpr : public Expr
{
    FIDDLE(...)
};

// An initializer list, e.g. `{ 1, 2, 3 }`
FIDDLE()
class InitializerListExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() List<Expr*> args;

    bool useCStyleInitialization = true;
};

FIDDLE()
class GetArrayLengthExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Expr* arrayExpr = nullptr;
};

FIDDLE()
class ExpandExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Expr* baseExpr = nullptr;
};

FIDDLE()
class EachExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Expr* baseExpr = nullptr;
};

// A base class for expressions with arguments
FIDDLE(abstract)
class ExprWithArgsBase : public Expr
{
    FIDDLE(...)
    FIDDLE() List<Expr*> arguments;
};

// An aggregate type constructor
FIDDLE()
class AggTypeCtorExpr : public ExprWithArgsBase
{
    FIDDLE(...)
    FIDDLE() TypeExp base;
};


// A base expression being applied to arguments: covers
// both ordinary `()` function calls and `<>` generic application
FIDDLE(abstract)
class AppExprBase : public ExprWithArgsBase
{
    FIDDLE(...)
    FIDDLE() Expr* functionExpr = nullptr;

    // The original function expr before overload resolution.
    Expr* originalFunctionExpr = nullptr;

    // The source location of `(`, `)`, and `,` that marks the start/end of the application op and
    // each argument expr. This info is used by language server.
    List<SourceLoc> argumentDelimeterLocs;
};

FIDDLE()
class InvokeExpr : public AppExprBase
{
    FIDDLE(...)
};

FIDDLE()
class ExplicitCtorInvokeExpr : public InvokeExpr
{
    FIDDLE(...)
};

enum class TryClauseType
{
    None,
    Standard, // Normal `try` clause
    Optional, // (Not implemented) `try?` clause that returns an optional value.
    Assert, // (Not implemented) `try!` clause that should always succeed and triggers runtime error
            // if failed.
};

char const* getTryClauseTypeName(TryClauseType value);

FIDDLE()
class TryExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Expr* base;

    FIDDLE() TryClauseType tryClauseType = TryClauseType::Standard;

    // The scope of this expr.
    Scope* scope = nullptr;
};

FIDDLE()
class NewExpr : public InvokeExpr
{
    FIDDLE(...)
};

FIDDLE()
class OperatorExpr : public InvokeExpr
{
    FIDDLE(...)
};

FIDDLE()
class InfixExpr : public OperatorExpr
{
    FIDDLE(...)
};

FIDDLE()
class PrefixExpr : public OperatorExpr
{
    FIDDLE(...)
};

FIDDLE()
class PostfixExpr : public OperatorExpr
{
    FIDDLE(...)
};

FIDDLE()
class IndexExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Expr* baseExpression;
    FIDDLE() List<Expr*> indexExprs;

    // The source location of `(`, `)`, and `,` that marks the start/end of the application op and
    // each argument expr. This info is used by language server.
    List<SourceLoc> argumentDelimeterLocs;
};

FIDDLE()
class MemberExpr : public DeclRefExpr
{
    FIDDLE(...)
    FIDDLE() Expr* baseExpression = nullptr;
    SourceLoc memberOperatorLoc;
};

// Member expression that is dereferenced, e.g. `a->b`.
FIDDLE()
class DerefMemberExpr : public MemberExpr
{
    FIDDLE(...)
};

// Member looked up on a type, rather than a value
FIDDLE()
class StaticMemberExpr : public DeclRefExpr
{
    FIDDLE(...)
    Expr* baseExpression = nullptr;
    SourceLoc memberOperatorLoc;
};

FIDDLE()
struct MatrixCoord
{
    FIDDLE(...)

    bool operator==(const MatrixCoord& rhs) const { return row == rhs.row && col == rhs.col; };
    bool operator!=(const MatrixCoord& rhs) const { return !(*this == rhs); };

    // Rows and columns are zero indexed
    FIDDLE() Int32 row;
    FIDDLE() Int32 col;
};

FIDDLE()
class MatrixSwizzleExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Expr* base = nullptr;
    FIDDLE() int elementCount;
    FIDDLE() MatrixCoord elementCoords[4];
    SourceLoc memberOpLoc;
};

FIDDLE()
class SwizzleExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Expr* base = nullptr;
    FIDDLE() ShortList<uint32_t, 4> elementIndices;
    SourceLoc memberOpLoc;
};

// An operation to convert an l-value to a reference type.
FIDDLE()
class MakeRefExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Expr* base = nullptr;
};

// A dereference of a pointer or pointer-like type
FIDDLE()
class DerefExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Expr* base = nullptr;
};

// Any operation that performs type-casting
FIDDLE()
class TypeCastExpr : public InvokeExpr
{
    FIDDLE(...)
    //    TypeExp TargetType;
    //    Expr* Expression = nullptr;
};

// An explicit type-cast that appear in the user's code with `(type) expr` syntax
FIDDLE()
class ExplicitCastExpr : public TypeCastExpr
{
    FIDDLE(...)
};

// An implicit type-cast inserted during semantic checking
FIDDLE()
class ImplicitCastExpr : public TypeCastExpr
{
    FIDDLE(...)
};

// A builtin cast expr generated during semantic checking, where there is
// no associated conversion function decl.
FIDDLE()
class BuiltinCastExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Expr* base = nullptr;
};

FIDDLE()
class LValueImplicitCastExpr : public TypeCastExpr
{
    FIDDLE(...)
    explicit LValueImplicitCastExpr(const TypeCastExpr& rhs)
        : Super(rhs)
    {
    }
};

// To work around situations like int += uint
// where we want to allow an LValue to work with an implicit cast.
// The argument being cast *must* be an LValue.
FIDDLE()
class OutImplicitCastExpr : public LValueImplicitCastExpr
{
    FIDDLE(...)
    /// Allow explict construction from any TypeCastExpr
    explicit OutImplicitCastExpr(const TypeCastExpr& rhs)
        : Super(rhs)
    {
    }
};

FIDDLE()
class InOutImplicitCastExpr : public LValueImplicitCastExpr
{
    FIDDLE(...)
    /// Allow explict construction from any TypeCastExpr
    explicit InOutImplicitCastExpr(const TypeCastExpr& rhs)
        : Super(rhs)
    {
    }
};

/// A cast of a value to a super-type of its type.
///
/// The type being cast to is stored as this expression's `type`.
///
FIDDLE()
class CastToSuperTypeExpr : public Expr
{
    FIDDLE(...)
    /// The value being cast to a super type
    ///
    /// The type being cast from is `valueArg->type`.
    ///
    FIDDLE() Expr* valueArg = nullptr;

    /// A witness showing that `valueArg`'s type is a sub-type of this expression's `type`
    FIDDLE() Val* witnessArg = nullptr;
};

/// A `value is Type` expression that evaluates to `true` if type of `value` is a sub-type of
/// `Type`.
FIDDLE()
class IsTypeExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Expr* value = nullptr;
    FIDDLE() TypeExp typeExpr;

    // A witness showing that `typeExpr.type` is a subtype of `typeof(value)`.
    FIDDLE() Val* witnessArg = nullptr;

    // non-null if evaluates to a constant.
    FIDDLE() BoolLiteralExpr* constantVal = nullptr;
};

/// A `value as Type` expression that casts `value` to `Type` within type hierarchy.
/// The result is undefined if `value` is not `Type`.
FIDDLE()
class AsTypeExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Expr* value = nullptr;
    FIDDLE() Expr* typeExpr = nullptr;

    // A witness showing that `typeExpr` is a subtype of `typeof(value)`.
    FIDDLE() Val* witnessArg = nullptr;
};

FIDDLE(abstract)
class SizeOfLikeExpr : public Expr
{
    FIDDLE(...)
    // Set during the parse, could be an expression, a variable or a type
    FIDDLE() Expr* value = nullptr;

    // The type the size/alignment needs to operate on. Set during traversal of SemanticsExprVisitor
    FIDDLE() Type* sizedType = nullptr;
};

FIDDLE()
class SizeOfExpr : public SizeOfLikeExpr
{
    FIDDLE(...)
};

FIDDLE()
class AlignOfExpr : public SizeOfLikeExpr
{
    FIDDLE(...)
};

FIDDLE()
class CountOfExpr : public SizeOfLikeExpr
{
    FIDDLE(...)
};

FIDDLE()
class AddressOfExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Expr* arg = nullptr;
};

FIDDLE()
class MakeOptionalExpr : public Expr
{
    FIDDLE(...)
    // If `value` is null, this constructs an `Optional<T>` that doesn't have a value.
    FIDDLE() Expr* value = nullptr;
    FIDDLE() Expr* typeExpr = nullptr;
};

/// A cast of a value to the same type, with different modifiers.
///
/// The type being cast to is stored as this expression's `type`.
///
FIDDLE()
class ModifierCastExpr : public Expr
{
    FIDDLE(...)
    /// The value being cast.
    ///
    /// The type being cast from is `valueArg->type`.
    ///
    FIDDLE() Expr* valueArg = nullptr;
};

FIDDLE()
class SelectExpr : public OperatorExpr
{
    FIDDLE(...)
};

FIDDLE()
class LogicOperatorShortCircuitExpr : public OperatorExpr
{
    FIDDLE(...)
public:
    enum Flavor
    {
        And, // &&
        Or,  // ||
    };
    FIDDLE() Flavor flavor;
};


FIDDLE()
class GenericAppExpr : public AppExprBase
{
    FIDDLE(...)
};

// An expression representing re-use of the syntax for a type in more
// than once conceptually-distinct declaration
FIDDLE()
class SharedTypeExpr : public Expr
{
    FIDDLE(...)
    // The underlying type expression that we want to share
    TypeExp base;
};

FIDDLE()
class AssignExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Expr* left = nullptr;
    FIDDLE() Expr* right = nullptr;
};

// Just an expression inside parentheses `(exp)`
//
// We keep this around explicitly to be sure we don't lose any structure
// when we do rewriter stuff.
FIDDLE()
class ParenExpr : public Expr
{
    FIDDLE(...)
    Expr* base = nullptr;
};

// An expression that constructs a tuple `(arg1, arg2, ...)`
//
FIDDLE()
class TupleExpr : public Expr
{
    FIDDLE(...)
    List<Expr*> elements;
};


// An object-oriented `this` expression, used to
// refer to the current instance of an enclosing type.
FIDDLE()
class ThisExpr : public Expr
{
    FIDDLE(...)

    Scope* scope = nullptr;
};

// Represent a reference to the virtual __return_val object holding the return value of
// functions whose result type is non-copyable.
FIDDLE()
class ReturnValExpr : public Expr
{
    FIDDLE(...)

    Scope* scope = nullptr;
};

// An expression that binds a temporary variable in a local expression context
FIDDLE()
class LetExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() VarDecl* decl = nullptr;
    FIDDLE() Expr* body = nullptr;
};

FIDDLE()
class ExtractExistentialValueExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() DeclRef<VarDeclBase> declRef;
    Expr* originalExpr;
};

FIDDLE()
class OpenRefExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Expr* innerExpr = nullptr;
};

FIDDLE()
class DetachExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Expr* inner = nullptr;
};

/// Base class for higher-order function application
/// Eg: foo(fn) where fn is a function expression.
///
FIDDLE(abstract)
class HigherOrderInvokeExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Expr* baseFunction;
    FIDDLE() List<Name*> newParameterNames;
};

FIDDLE()
class PrimalSubstituteExpr : public HigherOrderInvokeExpr
{
    FIDDLE(...)
};

FIDDLE(abstract)
class DifferentiateExpr : public HigherOrderInvokeExpr
{
    FIDDLE(...)
};

/// An expression of the form `__fwd_diff(fn)` to access the
/// forward-mode derivative version of the function `fn`
///
FIDDLE()
class ForwardDifferentiateExpr : public DifferentiateExpr
{
    FIDDLE(...)
};

/// An expression of the form `__bwd_diff(fn)` to access the
/// forward-mode derivative version of the function `fn`
///
FIDDLE()
class BackwardDifferentiateExpr : public DifferentiateExpr
{
    FIDDLE(...)
};

/// An expression of the form `__dispatch_kernel(fn, threadGroupSize, dispatchSize)` to
/// dispatch a compute kernel from host.
///
FIDDLE()
class DispatchKernelExpr : public HigherOrderInvokeExpr
{
    FIDDLE(...)
    FIDDLE() Expr* threadGroupSize;
    FIDDLE() Expr* dispatchSize;
};

FIDDLE()
class LambdaExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() ScopeDecl* paramScopeDecl;
    FIDDLE() Stmt* bodyStmt;
};

/// An express to mark its inner expression as an intended non-differential call.
FIDDLE()
class TreatAsDifferentiableExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Expr* innerExpr;
    Scope* scope;

    enum Flavor
    {
        /// Represents a no_diff wrapper over
        /// a non-differentiable method.
        /// i.e. no_diff(fn(...))
        ///
        NoDiff,

        /// Represents a call to a method that
        /// is either marked differentiable, or has
        /// a user-defined derivative in scope.
        ///
        Differentiable
    };

    FIDDLE() Flavor flavor;
};

/// A type expression of the form `This`
///
/// Refers to the type of `this` in the current context.
///
FIDDLE()
class ThisTypeExpr : public Expr
{
    FIDDLE(...)

    Scope* scope = nullptr;
};


/// A type expression of the form `ThisInterface`
///
/// Refers to the interface type itself, not the conforming type from an interface decl.
///
FIDDLE()
class ThisInterfaceExpr : public VarExpr
{
    FIDDLE(...)
};

/// A type expression of the form `Left & Right`.
FIDDLE()
class AndTypeExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() TypeExp left;
    FIDDLE() TypeExp right;
};

/// A type exprssion that applies one or more modifiers to another type
FIDDLE()
class ModifiedTypeExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() Modifiers modifiers;
    FIDDLE() TypeExp base;
};

/// A type expression that rrepresents a pointer type, e.g. T*
FIDDLE()
class PointerTypeExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() TypeExp base;
};

/// A type expression that represents a function type, e.g. (bool, int) -> float
FIDDLE()
class FuncTypeExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() List<TypeExp> parameters;
    FIDDLE() TypeExp result;
};

FIDDLE()
class TupleTypeExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() List<TypeExp> members;
};

/// An expression that applies a generic to arguments for some,
/// but not all, of its explicit parameters.
///
FIDDLE()
class PartiallyAppliedGenericExpr : public Expr
{
    FIDDLE(...)
public:
    Expr* originalExpr = nullptr;
    Expr* baseExpr = nullptr;

    /// The generic being applied
    DeclRef<GenericDecl> baseGenericDeclRef;

    /// A substitution that includes the generic arguments known so far
    List<Val*> knownGenericArgs;
};


/// An expression that holds a set of argument exprs that got matched to a pack parameter
/// during overload resolution.
///
FIDDLE()
class PackExpr : public Expr
{
    FIDDLE(...)
    FIDDLE() List<Expr*> args;
};

FIDDLE()
struct SPIRVAsmOperand
{
    FIDDLE(...)

public:
    enum Flavor
    {
        Literal,      // No prefix
        Id,           // Prefixed with %
        ResultMarker, // "result" (without quotes)
        NamedValue,   // Any other identifier
        SlangValue,
        SlangValueAddr,
        SlangImmediateValue,
        SlangType,
        SampledType, // __sampledType(T), this becomes a 4 vector of the component type of T
        ImageType,   // __imageType(texture), returns the equivalaent OpTypeImage of a given texture
                     // typed value.
        SampledImageType, // __sampledImageType(texture), returns the equivalent OpTypeSampledImage
                          // of a given texture typed value.
        ConvertTexel,     // __convertTexel(value), converts `value` to the native texel type of a
                          // texture.
        TruncateMarker,   // __truncate, an invented instruction which coerces to the result type by
                          // truncating the element count
        EntryPoint,       // __entryPoint, a placeholder for the id of a referencing entryPoint.
        BuiltinVar,
        GLSL450Set,
        NonSemanticDebugPrintfExtSet,
        RayPayloadFromLocation, // insert from scope of all payloads in the spir-v shader the
                                // payload identified by the integer value provided
        RayAttributeFromLocation,
        RayCallableFromLocation,
    };

    // The flavour and token describes how this was parsed
    FIDDLE() Flavor flavor;
    // The single token this came from
    Token token;

    // If this was a SlangValue or SlangValueAddr or SlangType, then we also
    // store the expression, which should be a single VarExpr because we only
    // parse single idents at the moment
    FIDDLE() Expr* expr = nullptr;

    // If this is part of a bitwise or expression, this will point to the
    // remaining operands values in such an expression must be of flavour
    // Literal or NamedValue
    FIDDLE() List<SPIRVAsmOperand> bitwiseOrWith = List<SPIRVAsmOperand>();

    // If this is a named value then we calculate the value here during
    // checking. If this is an opcode, then the parser will populate this too
    // (or set it to 0xffffffff);
    FIDDLE() SpvWord knownValue = 0xffffffff;
    // Although this might be a constant in the source we should actually pass
    // it as an id created with OpConstant
    FIDDLE() bool wrapInId = false;

    // Once we've checked things, the SlangType and BuiltinVar flavour operands
    // will have this type populated.
    FIDDLE() TypeExp type = TypeExp();
};

FIDDLE()
struct SPIRVAsmInst
{
    FIDDLE(...)

public:
    FIDDLE() SPIRVAsmOperand opcode;
    FIDDLE() List<SPIRVAsmOperand> operands;
};

FIDDLE()
class SPIRVAsmExpr : public Expr
{
    FIDDLE(...)
public:
    FIDDLE() List<SPIRVAsmInst> insts;
};

} // namespace Slang