Add structopt and base argument parsing
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
68
src/main.rs
68
src/main.rs
@@ -1,6 +1,68 @@
|
||||
mod syn;
|
||||
//mod util;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
fs,
|
||||
io::{stdout, Write},
|
||||
path::{Path, PathBuf},
|
||||
process,
|
||||
};
|
||||
use structopt::StructOpt;
|
||||
|
||||
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
struct Options {
|
||||
/// The input file to work with.
|
||||
///
|
||||
/// By default, the file will be executed. If -c is passed, it will not run and only compile.
|
||||
/// Supplying - for the path will read from STDIN.
|
||||
#[structopt(name = "FILE", parse(from_os_str))]
|
||||
input: PathBuf,
|
||||
|
||||
/*
|
||||
/// Disassemble object that would be passed to VM and exit before running it.
|
||||
#[structopt(short = "d", long)]
|
||||
disassemble: bool,
|
||||
*/
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
use syn::{
|
||||
parser::Parser,
|
||||
};
|
||||
|
||||
let opt = Options::from_args();
|
||||
let text = fs::read_to_string(&opt.input)?;
|
||||
let parser = Parser::try_from(text.as_str())?;
|
||||
/*
|
||||
let object = assemble::assemble_path(&opt.input)?;
|
||||
|
||||
if opt.compile_only {
|
||||
let outfile = opt.out.clone().unwrap_or_else(|| {
|
||||
let mut outfile = opt.input.clone();
|
||||
assert!(outfile.set_extension("obj"));
|
||||
outfile
|
||||
});
|
||||
let bytes = object.to_bytes();
|
||||
let mut writer = get_writer(&outfile)?;
|
||||
writer.write(&bytes)?;
|
||||
Ok(())
|
||||
} else if opt.disassemble {
|
||||
let outfile = opt
|
||||
.out
|
||||
.as_ref()
|
||||
.map(|p| p.as_path())
|
||||
.unwrap_or_else(|| Path::new("-"));
|
||||
let mut writer = get_writer(&outfile)?;
|
||||
object.disasm(&mut writer)?;
|
||||
Ok(())
|
||||
} else {
|
||||
let mut state = State::new();
|
||||
state.load_object(object, opt.max_mem.unwrap_or(DEFAULT_MAX_MEM))?;
|
||||
let status = state.exec()?;
|
||||
process::exit((status & 0xffff_ffff) as i32);
|
||||
}
|
||||
*/
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user