forked from koniifer/ableos
removing comand line parsing library that is used for tool that anybody can read to see how to use it
This commit is contained in:
parent
56420ad5c5
commit
5b51e22750
83
Cargo.lock
generated
83
Cargo.lock
generated
|
@ -3,30 +3,10 @@
|
|||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "argh"
|
||||
version = "0.1.12"
|
||||
source = "git+https://github.com/google/argh.git?branch=master#f02f6b44444b340a553ff2db298744721ebc77a7"
|
||||
dependencies = [
|
||||
"argh_derive",
|
||||
"argh_shared",
|
||||
"rust-fuzzy-search",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "argh_derive"
|
||||
version = "0.1.12"
|
||||
source = "git+https://github.com/google/argh.git?branch=master#f02f6b44444b340a553ff2db298744721ebc77a7"
|
||||
dependencies = [
|
||||
"argh_shared",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "argh_shared"
|
||||
version = "0.1.12"
|
||||
source = "git+https://github.com/google/argh.git?branch=master#f02f6b44444b340a553ff2db298744721ebc77a7"
|
||||
name = "hashbrown"
|
||||
version = "0.14.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||
|
||||
[[package]]
|
||||
name = "hbbytecode"
|
||||
|
@ -41,6 +21,7 @@ name = "hblang"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"hbvm",
|
||||
"regalloc2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -60,63 +41,41 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.154"
|
||||
version = "0.2.158"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346"
|
||||
checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"
|
||||
|
||||
[[package]]
|
||||
name = "memmap2"
|
||||
version = "0.9.4"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe751422e4a8caa417e13c3ea66452215d7d63e19e604f4980461212f3ae1322"
|
||||
checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.82"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b"
|
||||
name = "regalloc2"
|
||||
version = "0.10.2"
|
||||
source = "git+https://github.com/jakubDoka/regalloc2.git#34d8424a0d74746d231a96239fdb32e3d5ec0245"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
"hashbrown",
|
||||
"rustc-hash",
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.36"
|
||||
name = "rustc-hash"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
|
||||
|
||||
[[package]]
|
||||
name = "rust-fuzzy-search"
|
||||
version = "0.1.1"
|
||||
name = "smallvec"
|
||||
version = "1.13.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a157657054ffe556d8858504af8a672a054a6e0bd9e8ee531059100c0fa11bb2"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.63"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
|
||||
|
||||
[[package]]
|
||||
name = "xtask"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"argh",
|
||||
]
|
||||
|
|
|
@ -2,9 +2,16 @@
|
|||
resolver = "2"
|
||||
members = ["hbbytecode", "hbvm", "hbxrt", "xtask", "hblang", "hbjit"]
|
||||
|
||||
[profile.release]
|
||||
strip = true
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
panic = "abort"
|
||||
|
||||
[profile.small]
|
||||
inherits = "release"
|
||||
opt-level = "z"
|
||||
strip = true
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
panic = "abort"
|
||||
|
|
|
@ -9,3 +9,4 @@ path = "src/main.rs"
|
|||
|
||||
[dependencies]
|
||||
hbvm = { path = "../hbvm", features = ["nightly"] }
|
||||
regalloc2 = { git = "https://github.com/jakubDoka/regalloc2.git" }
|
||||
|
|
|
@ -2249,12 +2249,12 @@ impl Codegen {
|
|||
if node.color != 0 {
|
||||
let &[_, lhs, rhs] = node.inputs.as_slice() else { unreachable!() };
|
||||
|
||||
self.lazy_init(ctrl);
|
||||
if self.ci.nodes[rhs].color == 0
|
||||
&& let Kind::CInt { value } = self.ci.nodes[rhs].kind
|
||||
&& let Some(op) =
|
||||
op.imm_binop(node.ty.is_signed(), self.tys.size_of(node.ty))
|
||||
{
|
||||
self.lazy_init(ctrl);
|
||||
self.ci.emit(op(
|
||||
node_loc!(self, ctrl).reg,
|
||||
node_loc!(self, lhs).reg,
|
||||
|
@ -2263,7 +2263,6 @@ impl Codegen {
|
|||
} else if let Some(op) =
|
||||
op.binop(node.ty.is_signed(), self.tys.size_of(node.ty))
|
||||
{
|
||||
self.lazy_init(ctrl);
|
||||
self.ci.emit(op(
|
||||
node_loc!(self, ctrl).reg,
|
||||
node_loc!(self, lhs).reg,
|
||||
|
|
|
@ -13,9 +13,6 @@ libfuzzer-sys = "0.4"
|
|||
[dependencies.hbvm]
|
||||
path = ".."
|
||||
|
||||
[dependencies.hbbytecode]
|
||||
path = "../../hbbytecode"
|
||||
|
||||
# Prevent this from interfering with workspaces
|
||||
[workspace]
|
||||
members = ["."]
|
||||
|
|
|
@ -3,8 +3,3 @@ name = "xtask"
|
|||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies.argh]
|
||||
git = "https://github.com/google/argh.git"
|
||||
branch = "master"
|
||||
default-features = false
|
||||
features = ["help"]
|
||||
|
|
|
@ -1,89 +0,0 @@
|
|||
use {
|
||||
crate::utils::IterExt,
|
||||
argh::FromArgs,
|
||||
std::{
|
||||
fs::File,
|
||||
io::{self, BufRead, BufReader, BufWriter, Seek, Write},
|
||||
},
|
||||
};
|
||||
|
||||
/// Format `instructions.in`
|
||||
#[derive(Debug, FromArgs, PartialEq)]
|
||||
#[argh(subcommand, name = "fmt")]
|
||||
pub struct Command {
|
||||
/// renumber instructions in their definition order
|
||||
#[argh(switch, short = 'r')]
|
||||
renumber: bool,
|
||||
}
|
||||
|
||||
pub fn command(args: Command) -> io::Result<()> {
|
||||
let mut file = File::options()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.open(crate::root().join("hbbytecode/instructions.in"))?;
|
||||
|
||||
// Extract records
|
||||
let reader = BufReader::new(&file);
|
||||
let mut recs = vec![];
|
||||
let mut lens = [0_usize; 4];
|
||||
|
||||
for rec in reader.split(b';').filter_map(|r| {
|
||||
r.map(|ln| {
|
||||
let s = String::from_utf8_lossy(&ln);
|
||||
let s = s.trim_matches('\n');
|
||||
if s.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
s.split(',').map(|s| Box::<str>::from(s.trim())).collect_array::<4>().map(Ok::<_, ()>)
|
||||
})
|
||||
.transpose()
|
||||
}) {
|
||||
let rec = rec?.expect("Valid record format");
|
||||
for (current, next) in lens.iter_mut().zip(rec.iter()) {
|
||||
*current = (*current).max(next.len());
|
||||
}
|
||||
|
||||
recs.push(rec);
|
||||
}
|
||||
|
||||
// Clear file!
|
||||
file.set_len(0)?;
|
||||
file.seek(std::io::SeekFrom::Start(0))?;
|
||||
|
||||
let mut writer = BufWriter::new(file);
|
||||
|
||||
let ord_opco_len = digit_count(recs.len()) as usize;
|
||||
for (n, rec) in recs.iter().enumerate() {
|
||||
// Write opcode number
|
||||
if args.renumber {
|
||||
let n = format!("{n:#04X}");
|
||||
write!(writer, "{n}, {}", padding(ord_opco_len, &n))?;
|
||||
} else {
|
||||
write!(writer, "{}, {}", rec[0], padding(lens[0], &rec[0]))?;
|
||||
}
|
||||
|
||||
// Write other fields
|
||||
writeln!(
|
||||
writer,
|
||||
"{}, {}{},{} {}{};",
|
||||
rec[1],
|
||||
padding(lens[1], &rec[1]),
|
||||
rec[2],
|
||||
padding(lens[2], &rec[2]),
|
||||
rec[3],
|
||||
padding(lens[3], &rec[3]),
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn padding(req: usize, s: &str) -> Box<str> {
|
||||
" ".repeat(req.saturating_sub(s.len())).into()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn digit_count(n: usize) -> u32 {
|
||||
n.checked_ilog10().unwrap_or(0) + 1
|
||||
}
|
|
@ -1,30 +1,94 @@
|
|||
mod fmt;
|
||||
mod utils;
|
||||
|
||||
use {
|
||||
argh::FromArgs,
|
||||
std::{io, path::Path},
|
||||
crate::utils::IterExt,
|
||||
std::{
|
||||
fs::File,
|
||||
io::{self, BufRead, BufReader, BufWriter, Seek, Write},
|
||||
path::Path,
|
||||
},
|
||||
};
|
||||
|
||||
fn root() -> &'static Path {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap()
|
||||
}
|
||||
|
||||
/// xTask for Holey Bytes project
|
||||
#[derive(FromArgs)]
|
||||
struct Command {
|
||||
#[argh(subcommand)]
|
||||
subcom: Subcommands,
|
||||
}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
#[argh(subcommand)]
|
||||
enum Subcommands {
|
||||
Format(fmt::Command),
|
||||
}
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
match argh::from_env::<Command>().subcom {
|
||||
Subcommands::Format(com) => fmt::command(com),
|
||||
let args = std::env::args().collect::<Vec<_>>();
|
||||
match args[0].as_str() {
|
||||
"fmt" => fmt(args[1] == "-r" || args[1] == "--renumber"),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fmt(renumber: bool) -> io::Result<()> {
|
||||
let mut file = File::options()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.open(crate::root().join("hbbytecode/instructions.in"))?;
|
||||
|
||||
// Extract records
|
||||
let reader = BufReader::new(&file);
|
||||
let mut recs = vec![];
|
||||
let mut lens = [0_usize; 4];
|
||||
|
||||
for rec in reader.split(b';').filter_map(|r| {
|
||||
r.map(|ln| {
|
||||
let s = String::from_utf8_lossy(&ln);
|
||||
let s = s.trim_matches('\n');
|
||||
if s.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
s.split(',').map(|s| Box::<str>::from(s.trim())).collect_array::<4>().map(Ok::<_, ()>)
|
||||
})
|
||||
.transpose()
|
||||
}) {
|
||||
let rec = rec?.expect("Valid record format");
|
||||
for (current, next) in lens.iter_mut().zip(rec.iter()) {
|
||||
*current = (*current).max(next.len());
|
||||
}
|
||||
|
||||
recs.push(rec);
|
||||
}
|
||||
|
||||
// Clear file!
|
||||
file.set_len(0)?;
|
||||
file.seek(std::io::SeekFrom::Start(0))?;
|
||||
|
||||
let mut writer = BufWriter::new(file);
|
||||
|
||||
let ord_opco_len = digit_count(recs.len()) as usize;
|
||||
for (n, rec) in recs.iter().enumerate() {
|
||||
// Write opcode number
|
||||
if renumber {
|
||||
let n = format!("{n:#04X}");
|
||||
write!(writer, "{n}, {}", padding(ord_opco_len, &n))?;
|
||||
} else {
|
||||
write!(writer, "{}, {}", rec[0], padding(lens[0], &rec[0]))?;
|
||||
}
|
||||
|
||||
// Write other fields
|
||||
writeln!(
|
||||
writer,
|
||||
"{}, {}{},{} {}{};",
|
||||
rec[1],
|
||||
padding(lens[1], &rec[1]),
|
||||
rec[2],
|
||||
padding(lens[2], &rec[2]),
|
||||
rec[3],
|
||||
padding(lens[3], &rec[3]),
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn padding(req: usize, s: &str) -> Box<str> {
|
||||
" ".repeat(req.saturating_sub(s.len())).into()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn digit_count(n: usize) -> u32 {
|
||||
n.checked_ilog10().unwrap_or(0) + 1
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue