Vasm cli wrapper will now export a symbol table

This commit is contained in:
2023-01-07 02:09:27 -06:00
parent 3e6a33899a
commit 11f0760b01
5 changed files with 58 additions and 15 deletions
+2 -1
View File
@@ -8,4 +8,5 @@ edition = "2021"
[dependencies]
vasm_core = { path = "../vasm_core" }
clap = { version = "3.1.18", features = ["derive"] }
regex = "1.7.0"
regex = "1.7.0"
serde_json = "1.0.91"
+21 -3
View File
@@ -1,8 +1,10 @@
use std::collections::BTreeMap;
use std::fs::File;
use std::io::Write;
use clap::lazy_static::lazy_static;
use clap::Parser;
use regex::Regex;
use serde_json::json;
/// Vulcan Assembler
#[derive(Parser, Debug)]
@@ -12,6 +14,10 @@ struct Args {
#[clap(short, long)]
output: Option<String>,
/// Whether to generate a JSON file containing the symbol table
#[clap(short, long)]
symbols: bool,
/// Input file
#[clap()]
file: String,
@@ -51,10 +57,22 @@ fn main() {
args.deduce();
match vasm_core::assemble_file(args.file.as_str()) {
Ok(bytes) => {
//println!("We got some bytes... {} of them", bytes.len());
let mut outfile = File::create(args.output.unwrap()).expect("Failed to open output file");
Ok((bytes, scope)) => {
let mut outfile = File::create(args.output.as_ref().unwrap()).expect("Failed to open output file");
outfile.write(bytes.as_slice()).expect("Failed to write to output file");
if args.symbols {
let mut important_symbols : BTreeMap<String, i32> = BTreeMap::new();
for (sym, addr) in scope {
if !sym.starts_with("__gensym") {
important_symbols.insert(sym, addr);
}
}
let mut symfile = File::create(format!("{}.sym", args.output.unwrap())).expect("Failed to open symbol file");
let json = json!(important_symbols).to_string();
symfile.write(json.as_bytes()).expect("Failed to write to symbol file");
}
}
Err(error) => {
println!("{}", error)