main.rs: Basic TUI experience: line numbers, better errors
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
//! Simple frontend for the assembler
|
||||
|
||||
use msp430_asm::preamble::*;
|
||||
use std::error::Error;
|
||||
use std::io::Read;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let mut repl = true;
|
||||
for arg in std::env::args() {
|
||||
match arg.as_str() {
|
||||
"-" | "-f" | "--file" => repl = false,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
let mut buf = String::new();
|
||||
if repl {
|
||||
let mut line = String::new();
|
||||
while let Ok(len) = std::io::stdin().read_line(&mut line) {
|
||||
match len {
|
||||
0 => break, // No newline (reached EOF)
|
||||
1 => continue, // Line is empty
|
||||
_ => {
|
||||
// Try to parse this line in isolation (this restricts preprocessing)
|
||||
match Parser::default().parse(&line) {
|
||||
Ok(_) => {
|
||||
buf += &line;
|
||||
}
|
||||
Err(error) => println!("{error}"),
|
||||
}
|
||||
line.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
match Assembler::assemble(&Parser::default().parse(&buf)?) {
|
||||
Err(error) => println!("{error}"),
|
||||
Ok(out) => {
|
||||
for word in out {
|
||||
print!("{:04x} ", word.swap_bytes())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println!();
|
||||
} else {
|
||||
std::io::stdin().lock().read_to_string(&mut buf)?;
|
||||
let tree = Parser::default().parse(&buf);
|
||||
match &tree {
|
||||
Ok(tree) => {
|
||||
//msp430_asm::linker::Printer::default().visit_root(tree);
|
||||
for insn in msp430_asm::assembler::Assembler::assemble(tree)? {
|
||||
print!("{:04x} ", insn.swap_bytes())
|
||||
}
|
||||
println!();
|
||||
}
|
||||
Err(error) => eprintln!("{error}"),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user