@@ -654,6 +654,15 @@ class Builder {
654
654
// / @returns the instruction
655
655
ir::Discard* Discard ();
656
656
657
+ // / Creates a user function call instruction
658
+ // / @param func the function to call
659
+ // / @param args the call arguments
660
+ // / @returns the instruction
661
+ template <typename ... ARGS>
662
+ ir::UserCall* Call (ir::Function* func, ARGS&&... args) {
663
+ return Call (func->ReturnType (), func, std::forward<ARGS>(args)...);
664
+ }
665
+
657
666
// / Creates a user function call instruction
658
667
// / @param type the return type of the call
659
668
// / @param func the function to call
@@ -688,6 +697,15 @@ class Builder {
688
697
Values (std::forward<ARGS>(args)...)));
689
698
}
690
699
700
+ // / Creates a value conversion instruction to the template type T
701
+ // / @param val the value to be converted
702
+ // / @returns the instruction
703
+ template <typename T, typename VAL>
704
+ ir::Convert* Convert (VAL&& val) {
705
+ auto * type = ir.Types ().Get <T>();
706
+ return Convert (type, std::forward<VAL>(val));
707
+ }
708
+
691
709
// / Creates a value conversion instruction
692
710
// / @param to the type converted to
693
711
// / @param val the value to be converted
@@ -698,6 +716,15 @@ class Builder {
698
716
Value (std::forward<VAL>(val))));
699
717
}
700
718
719
+ // / Creates a value constructor instruction to the template type T
720
+ // / @param args the arguments to the constructor
721
+ // / @returns the instruction
722
+ template <typename T, typename ... ARGS>
723
+ ir::Construct* Construct (ARGS&&... args) {
724
+ auto * type = ir.Types ().Get <T>();
725
+ return Construct (type, std::forward<ARGS>(args)...);
726
+ }
727
+
701
728
// / Creates a value constructor instruction
702
729
// / @param type the type to constructed
703
730
// / @param args the arguments to the constructor
@@ -768,6 +795,25 @@ class Builder {
768
795
// / @returns the instruction
769
796
ir::Var* Var (std::string_view name, const core::type::Pointer* type);
770
797
798
+ // / Creates a new `var` declaration with a name and initializer value
799
+ // / @param name the var name
800
+ // / @param init the var initializer
801
+ // / @returns the instruction
802
+ template <core::AddressSpace SPACE = core::AddressSpace::kFunction ,
803
+ core::Access ACCESS = core::Access::kReadWrite ,
804
+ typename VALUE = void >
805
+ ir::Var* Var (std::string_view name, VALUE&& init) {
806
+ auto * val = Value (std::forward<VALUE>(init));
807
+ if (TINT_UNLIKELY (!val)) {
808
+ TINT_ASSERT (val);
809
+ return nullptr ;
810
+ }
811
+ auto * var = Var (name, ir.Types ().ptr (SPACE, val->Type (), ACCESS));
812
+ var->SetInitializer (val);
813
+ ir.SetName (var->Result (), name);
814
+ return var;
815
+ }
816
+
771
817
// / Creates a new `let` declaration
772
818
// / @param name the let name
773
819
// / @param value the let value
0 commit comments