MCPcopy Create free account
hub / github.com/Rust-GPU/rust-gpu / parse_operands

Method parse_operands

crates/rustc_codegen_spirv/src/builder/spirv_asm.rs:500–602  ·  view source on GitHub ↗
(
        &mut self,
        id_map: &mut FxHashMap<&'a str, Word>,
        id_to_type_map: &FxHashMap<Word, Word>,
        mut tokens: impl Iterator<Item = Token<'a, 'cx, 'tcx>>,
        instruction:

Source from the content-addressed store, hash-verified

498 }
499
500 fn parse_operands<'a>(
501 &mut self,
502 id_map: &mut FxHashMap<&'a str, Word>,
503 id_to_type_map: &FxHashMap<Word, Word>,
504 mut tokens: impl Iterator<Item = Token<'a, 'cx, 'tcx>>,
505 instruction: &mut dr::Instruction,
506 ) where
507 'cx: 'a,
508 'tcx: 'a,
509 {
510 let mut saw_id_result = false;
511 let mut need_result_type_infer = false;
512
513 let mut logical_operand_stack = instruction
514 .class
515 .operands
516 .iter()
517 .cloned()
518 .collect::<std::collections::VecDeque<_>>();
519
520 while let Some(LogicalOperand { kind, quantifier }) = logical_operand_stack.pop_front() {
521 if kind == OperandKind::IdResult {
522 assert_eq!(quantifier, OperandQuantifier::One);
523 if instruction.result_id.is_none() {
524 self.err(&format!(
525 "instruction {} expects a result id",
526 instruction.class.opname
527 ));
528 }
529 saw_id_result = true;
530 continue;
531 }
532
533 if kind == OperandKind::IdResultType {
534 assert_eq!(quantifier, OperandQuantifier::One);
535 if let Some(token) = tokens.next() {
536 if let Token::Word("_") = token {
537 need_result_type_infer = true;
538 } else if let Some(id) = self.parse_id_in(id_map, token) {
539 instruction.result_type = Some(id);
540 }
541 } else {
542 self.err(&format!(
543 "instruction {} expects a result type",
544 instruction.class.opname
545 ));
546 }
547 continue;
548 }
549
550 let operands_start = instruction.operands.len();
551
552 match quantifier {
553 OperandQuantifier::One => {
554 if !self.parse_one_operand(id_map, instruction, kind, &mut tokens) {
555 self.err(&format!(
556 "expected operand after instruction: {}",
557 instruction.class.opname

Callers 1

codegen_asmMethod · 0.80

Calls 6

iterMethod · 0.80
errMethod · 0.80
parse_id_inMethod · 0.80
parse_one_operandMethod · 0.80
infer_result_typeMethod · 0.80
nextMethod · 0.45

Tested by

no test coverage detected