(&self, global: Word, initializer: Word)
| 805 | } |
| 806 | |
| 807 | pub fn set_global_initializer(&self, global: Word, initializer: Word) { |
| 808 | let mut builder = self.builder.borrow_mut(); |
| 809 | let module = builder.module_mut(); |
| 810 | let index = module |
| 811 | .types_global_values |
| 812 | .iter() |
| 813 | .enumerate() |
| 814 | .find_map(|(index, inst)| { |
| 815 | if inst.result_id == Some(global) { |
| 816 | Some(index) |
| 817 | } else { |
| 818 | None |
| 819 | } |
| 820 | }) |
| 821 | .expect("set_global_initializer global not found"); |
| 822 | // Remove and push it to the end, to keep spir-v definition order. |
| 823 | let mut inst = module.types_global_values.remove(index); |
| 824 | assert_eq!(inst.class.opcode, Op::Variable); |
| 825 | assert_eq!( |
| 826 | inst.operands.len(), |
| 827 | 1, |
| 828 | "global already has initializer defined: {global}" |
| 829 | ); |
| 830 | inst.operands.push(Operand::IdRef(initializer)); |
| 831 | module.types_global_values.push(inst); |
| 832 | } |
| 833 | |
| 834 | pub fn select_block_by_id(&self, id: Word) -> BuilderCursor { |
| 835 | fn block_matches(block: &Block, id: Word) -> bool { |
no test coverage detected