62 lines
1.7 KiB
Rust
62 lines
1.7 KiB
Rust
// This example contains information adapted from the MSPGCC project's documentation.
|
|
// As such, it is licensed under the GPL, to the extent that such a thing is possible.
|
|
// https://mspgcc.sourceforge.net/manual/ln16.html
|
|
#![feature(decl_macro)]
|
|
|
|
use anes::{Color, ResetAttributes, SetForegroundColor};
|
|
use msp430_asm::parser::preamble::*;
|
|
use msp430_asm::preamble::*;
|
|
use std::{
|
|
error::Error,
|
|
io::{stdin, IsTerminal, Write},
|
|
};
|
|
|
|
type AsmResult<T> = Result<T, Box<dyn Error>>;
|
|
|
|
mod data;
|
|
|
|
fn main() -> AsmResult<()> {
|
|
if stdin().is_terminal() {
|
|
hello();
|
|
}
|
|
repl()
|
|
}
|
|
|
|
fn hello() {
|
|
println!(
|
|
"{}{} v{}
|
|
This software contains instruction and register descriptions adapted from
|
|
the mspgcc project's fantastic documentation, which is licensed under the GPL.
|
|
https://mspgcc.sourceforge.net/manual/book1.html{}\n",
|
|
SetForegroundColor(Color::DarkGray),
|
|
env!("CARGO_BIN_NAME"),
|
|
env!("CARGO_PKG_VERSION"),
|
|
ResetAttributes
|
|
);
|
|
}
|
|
|
|
fn repl() -> AsmResult<()> {
|
|
printflush!("> ");
|
|
let mut line = String::new();
|
|
while let Ok(len) = stdin().read_line(&mut line) {
|
|
match len {
|
|
0 => break, // No newline (reached EOF)
|
|
1 => (), // Line is empty
|
|
_ => {
|
|
if line.starts_with('?') || line.starts_with("help") {
|
|
data::list_opcodes()
|
|
} else if let Ok(sf) = data::SyntaxFragment::try_from(line.as_str()) {
|
|
sf.info();
|
|
}
|
|
}
|
|
}
|
|
printflush!("> ");
|
|
line.clear();
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
macro printflush ($($x: expr),+) {
|
|
{print!($($x),+); let _ = ::std::io::stdout().flush();}
|
|
}
|