Fix register rgd name

pull/1/head
trivernis 4 years ago
parent 18691a25df
commit 1db0144eb7

@ -28,13 +28,25 @@ struct Opts {
fn main() -> io::Result<()> { fn main() -> io::Result<()> {
let opts: Opts = Opts::from_args(); let opts: Opts = Opts::from_args();
let contents = read_to_string(opts.input_file)?; let input_file_name = opts.input_file;
let contents = read_to_string(&input_file_name)?;
let f = File::create(opts.output_file)?; let f = File::create(opts.output_file)?;
let mut writer = BufWriter::new(f); let mut writer = BufWriter::new(f);
let mut line_number = 0;
contents contents
.lines() .lines()
.map(|line| get_token(line)) .filter_map(|line| {
.filter_map(|token| Some(token?.to_bytecode())) line_number += 1;
if let Some(token) = get_token(line) {
Some(token.to_bytecode())
} else {
println!(
"Failed to parse instruction '{}' \n-> {}:{}",
line, &input_file_name, line_number
);
None
}
})
.for_each(|code| { .for_each(|code| {
writer.write(&code).expect("Failed to write output."); writer.write(&code).expect("Failed to write output.");
}); });
@ -43,8 +55,8 @@ fn main() -> io::Result<()> {
Ok(()) Ok(())
} }
/// Parses the line into a token
fn get_token(line: &str) -> Option<Box<dyn Token>> { fn get_token(line: &str) -> Option<Box<dyn Token>> {
println!("{}", line);
let mut instr_parts = line.split_whitespace(); let mut instr_parts = line.split_whitespace();
match instr_parts.next()? { match instr_parts.next()? {
@ -85,6 +97,8 @@ fn get_token(line: &str) -> Option<Box<dyn Token>> {
} }
} }
/// Parses a value depending on if it starts with 0x (as a hex value)
/// or just is a plain base-10 number
fn parse_value(value: &str) -> Result<u8, ParseIntError> { fn parse_value(value: &str) -> Result<u8, ParseIntError> {
if value.starts_with("0x") { if value.starts_with("0x") {
let value = value.trim_start_matches("0x"); let value = value.trim_start_matches("0x");

@ -2,7 +2,7 @@ pub const RCS: u8 = 0x01;
pub const RCR: u8 = 0x02; pub const RCR: u8 = 0x02;
pub const RCG: u8 = 0x03; pub const RCG: u8 = 0x03;
pub const RCB: u8 = 0x04; pub const RCB: u8 = 0x04;
pub const RCD: u8 = 0x05; pub const RGD: u8 = 0x05;
pub const RGP: u8 = 0x06; pub const RGP: u8 = 0x06;
pub const RGI: u8 = 0x07; pub const RGI: u8 = 0x07;
pub const RGO: u8 = 0x08; pub const RGO: u8 = 0x08;
@ -15,14 +15,19 @@ pub fn get_register_by_name(name: &str) -> Option<u8> {
("rcr", RCR), ("rcr", RCR),
("rcg", RCG), ("rcg", RCG),
("rcb", RCB), ("rcb", RCB),
("rcd", RCD), ("rgd", RGD),
("rgp", RGP), ("rgp", RGP),
("rgi", RGI), ("rgi", RGI),
("rgo", RGO), ("rgo", RGO),
("rgl", RGL), ("rgl", RGL),
] ]
.iter() .iter()
.find(|(reg, bc)| *reg == name)?; .find(|(reg, bc)| *reg == name);
Some((*item).1) if let Some(item) = item {
Some((*item).1)
} else {
println!("Unknown register: {}", name);
None
}
} }

Loading…
Cancel
Save