|
|
|
@ -6,6 +6,7 @@ use crate::asm::data::{DataDisp, Rd, RdData, reg, Wr, WrData}; |
|
|
|
|
use crate::asm::data::literal::Label; |
|
|
|
|
use crate::asm::error::CrsnError; |
|
|
|
|
use crate::asm::parse::sexp_expect::expect_string_atom; |
|
|
|
|
use std::borrow::Cow; |
|
|
|
|
|
|
|
|
|
/// Parse a label
|
|
|
|
|
pub fn parse_label(name: Option<Sexp>) -> Result<Label, CrsnError> { |
|
|
|
@ -47,12 +48,17 @@ pub fn parse_data_disp(tok: Option<Sexp>) -> Result<DataDisp, CrsnError> { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn parse_u64(literal: &str) -> anyhow::Result<u64> { |
|
|
|
|
if let Some(hex) = literal.strip_prefix("0x") { |
|
|
|
|
let mut without_underscores = Cow::Borrowed(literal); |
|
|
|
|
if without_underscores.contains('_') { |
|
|
|
|
without_underscores = without_underscores.replace('_', "").into(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if let Some(hex) = without_underscores.strip_prefix("0x") { |
|
|
|
|
Ok(u64::from_str_radix(hex, 16)?) |
|
|
|
|
} else if let Some(hex) = literal.strip_prefix("0b") { |
|
|
|
|
} else if let Some(hex) = without_underscores.strip_prefix("0b") { |
|
|
|
|
Ok(u64::from_str_radix(hex, 2)?) |
|
|
|
|
} else { |
|
|
|
|
Ok(u64::from_str_radix(literal, 10)?) |
|
|
|
|
Ok(u64::from_str_radix(&without_underscores, 10)?) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|