MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / parse_csr_name

Function parse_csr_name

crates/asm-to-binary/src/assembler/parser.rs:566–596  ·  view source on GitHub ↗

Map a CSR name or numeric literal to its 12-bit address.

(name: &str)

Source from the content-addressed store, hash-verified

564 let rd = parse_int_reg(parts[0].trim())?;
565 let target = parts[1].trim().to_owned();
566 Some(AsmToken::Jal { rd, target })
567 }
568 1 => {
569 // Bare `jal label` means `jal ra, label`.
570 let target = parts[0].trim().to_owned();
571 if target.is_empty() {
572 None
573 } else {
574 Some(AsmToken::Jal { rd: 1, target })
575 }
576 }
577 _ => None,
578 }
579}
580
581// Parse `rd, symbol` for the `la` pseudo-instruction.
582fn parse_la(operands: &str) -> Option<AsmToken> {
583 let parts: Vec<&str> = operands.splitn(2, ',').collect();
584 if parts.len() != 2 {
585 return None;
586 }
587 let rd = parse_int_reg(parts[0].trim())?;
588 let symbol = parts[1].trim().to_owned();
589 if symbol.is_empty() {
590 None
591 } else {
592 Some(AsmToken::La { rd, symbol })
593 }
594}
595
596// Parse `rs, label` for a compare-with-zero branch pseudo (`blez`/`bgez`/`bltz`/`bgtz`),
597// expanding to the spec's `bge`/`blt` form against x0.
598fn parse_branch_vs_zero(mnemonic: &str, operands: &str) -> Option<AsmToken> {
599 let comma = operands.find(',')?;

Callers 3

parse_csrrFunction · 0.85
parse_csrwFunction · 0.85
parse_csr_rmwFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected