Migrate argh to argp, topological-sort to petgraph

This commit is contained in:
2023-08-03 18:55:57 -04:00
parent 8660984d40
commit bd0422e92a
18 changed files with 366 additions and 260 deletions

View File

@@ -6,33 +6,33 @@ use std::{
};
use anyhow::{anyhow, bail, Result};
use argh::FromArgs;
use argp::FromArgs;
use object::{Object, ObjectSymbol, SymbolScope};
use crate::util::file::{map_file, process_rsp};
#[derive(FromArgs, PartialEq, Debug)]
/// Commands for processing static libraries.
#[argh(subcommand, name = "ar")]
#[argp(subcommand, name = "ar")]
pub struct Args {
#[argh(subcommand)]
#[argp(subcommand)]
command: SubCommand,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand)]
#[argp(subcommand)]
enum SubCommand {
Create(CreateArgs),
}
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Creates a static library.
#[argh(subcommand, name = "create")]
#[argp(subcommand, name = "create")]
pub struct CreateArgs {
#[argh(positional)]
#[argp(positional)]
/// output file
out: PathBuf,
#[argh(positional)]
#[argp(positional)]
/// input files
files: Vec<PathBuf>,
}

View File

@@ -1,15 +1,15 @@
use anyhow::{anyhow, Result};
use argh::FromArgs;
use argp::FromArgs;
use cwdemangle::{demangle, DemangleOptions};
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Demangle a CodeWarrior C++ symbol.
#[argh(subcommand, name = "demangle")]
#[argp(subcommand, name = "demangle")]
pub struct Args {
#[argh(positional)]
#[argp(positional)]
/// symbol to demangle
symbol: String,
#[argh(switch)]
#[argp(switch)]
/// disable replacing `(void)` with `()`
keep_void: bool,
}

View File

@@ -7,7 +7,7 @@ use std::{
};
use anyhow::{anyhow, bail, Context, Result};
use argh::FromArgs;
use argp::FromArgs;
use crate::{
analysis::{
@@ -33,14 +33,14 @@ use crate::{
#[derive(FromArgs, PartialEq, Debug)]
/// Commands for processing DOL files.
#[argh(subcommand, name = "dol")]
#[argp(subcommand, name = "dol")]
pub struct Args {
#[argh(subcommand)]
#[argp(subcommand)]
command: SubCommand,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand)]
#[argp(subcommand)]
enum SubCommand {
Info(InfoArgs),
Split(SplitArgs),
@@ -48,30 +48,30 @@ enum SubCommand {
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Views DOL file information.
#[argh(subcommand, name = "info")]
#[argp(subcommand, name = "info")]
pub struct InfoArgs {
#[argh(positional)]
#[argp(positional)]
/// DOL file
dol_file: PathBuf,
}
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Splits a DOL into relocatable objects.
#[argh(subcommand, name = "split")]
#[argp(subcommand, name = "split")]
pub struct SplitArgs {
#[argh(positional)]
#[argp(positional)]
/// input file
in_file: PathBuf,
#[argh(positional)]
#[argp(positional)]
/// output directory
out_dir: PathBuf,
#[argh(option, short = 's')]
#[argp(option, short = 's')]
/// path to symbols file
symbols_file: Option<PathBuf>,
#[argh(option, short = 'p')]
#[argp(option, short = 'p')]
/// path to splits file
splits_file: Option<PathBuf>,
#[argh(option, short = 'e')]
#[argp(option, short = 'e')]
/// ELF file to validate against (debugging only)
elf_file: Option<PathBuf>,
}

View File

@@ -6,7 +6,7 @@ use std::{
};
use anyhow::{anyhow, bail, Result};
use argh::FromArgs;
use argp::FromArgs;
use object::{elf, Object, ObjectSection, ObjectSymbol, RelocationKind, RelocationTarget, Section};
use crate::util::{
@@ -18,28 +18,28 @@ use crate::util::{
};
#[derive(FromArgs, PartialEq, Debug)]
/// process DWARF 1.1 information
#[argh(subcommand, name = "dwarf")]
/// Commands for processing DWARF 1.1 information.
#[argp(subcommand, name = "dwarf")]
pub struct Args {
#[argh(subcommand)]
#[argp(subcommand)]
command: SubCommand,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand)]
#[argp(subcommand)]
enum SubCommand {
Dump(DumpArgs),
}
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// dumps DWARF 1.1 info from an object or archive
#[argh(subcommand, name = "dump")]
/// Dumps DWARF 1.1 info from an object or archive.
#[argp(subcommand, name = "dump")]
pub struct DumpArgs {
#[argh(positional)]
/// input object (ELF or archive)
#[argp(positional)]
/// Input object. (ELF or archive)
in_file: PathBuf,
#[argh(option, short = 'o')]
/// output file (or directory, for archive)
#[argp(option, short = 'o')]
/// Output file. (Or directory, for archive)
out: Option<PathBuf>,
}

View File

@@ -7,7 +7,7 @@ use std::{
};
use anyhow::{anyhow, bail, ensure, Context, Result};
use argh::FromArgs;
use argp::FromArgs;
use object::{
elf,
write::{Mangling, SectionId, SymbolId},
@@ -31,14 +31,14 @@ use crate::{
#[derive(FromArgs, PartialEq, Debug)]
/// Commands for processing ELF files.
#[argh(subcommand, name = "elf")]
#[argp(subcommand, name = "elf")]
pub struct Args {
#[argh(subcommand)]
#[argp(subcommand)]
command: SubCommand,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand)]
#[argp(subcommand)]
enum SubCommand {
Config(ConfigArgs),
Disasm(DisasmArgs),
@@ -49,63 +49,63 @@ enum SubCommand {
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Disassembles an ELF file.
#[argh(subcommand, name = "disasm")]
#[argp(subcommand, name = "disasm")]
pub struct DisasmArgs {
#[argh(positional)]
#[argp(positional)]
/// input file
elf_file: PathBuf,
#[argh(positional)]
#[argp(positional)]
/// output file (.o) or directory (.elf)
out: PathBuf,
}
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Fixes issues with GNU assembler built object files.
#[argh(subcommand, name = "fixup")]
#[argp(subcommand, name = "fixup")]
pub struct FixupArgs {
#[argh(positional)]
#[argp(positional)]
/// input file
in_file: PathBuf,
#[argh(positional)]
#[argp(positional)]
/// output file
out_file: PathBuf,
}
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Splits an executable ELF into relocatable objects.
#[argh(subcommand, name = "split")]
#[argp(subcommand, name = "split")]
pub struct SplitArgs {
#[argh(positional)]
#[argp(positional)]
/// input file
in_file: PathBuf,
#[argh(positional)]
#[argp(positional)]
/// output directory
out_dir: PathBuf,
}
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Generates configuration files from an executable ELF.
#[argh(subcommand, name = "config")]
#[argp(subcommand, name = "config")]
pub struct ConfigArgs {
#[argh(positional)]
#[argp(positional)]
/// input file
in_file: PathBuf,
#[argh(positional)]
#[argp(positional)]
/// output directory
out_dir: PathBuf,
}
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Builds function signatures from an ELF file.
#[argh(subcommand, name = "sigs")]
#[argp(subcommand, name = "sigs")]
pub struct SignaturesArgs {
#[argh(positional)]
#[argp(positional)]
/// input file(s)
files: Vec<PathBuf>,
#[argh(option, short = 's')]
#[argp(option, short = 's')]
/// symbol name
symbol: String,
#[argh(option, short = 'o')]
#[argp(option, short = 'o')]
/// output yml
out_file: PathBuf,
}

View File

@@ -5,19 +5,19 @@ use std::{
};
use anyhow::{anyhow, bail, ensure, Context, Result};
use argh::FromArgs;
use argp::FromArgs;
use object::{Architecture, Endianness, Object, ObjectKind, ObjectSection, SectionKind};
use crate::util::file::map_file;
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Converts an ELF file to a DOL file.
#[argh(subcommand, name = "elf2dol")]
#[argp(subcommand, name = "elf2dol")]
pub struct Args {
#[argh(positional)]
#[argp(positional)]
/// path to input ELF
elf_file: PathBuf,
#[argh(positional)]
#[argp(positional)]
/// path to output DOL
dol_file: PathBuf,
}

View File

@@ -2,7 +2,7 @@
use std::path::PathBuf;
use anyhow::{bail, Result};
use argh::FromArgs;
use argp::FromArgs;
use cwdemangle::{demangle, DemangleOptions};
use crate::util::{
@@ -12,14 +12,14 @@ use crate::util::{
#[derive(FromArgs, PartialEq, Debug)]
/// Commands for processing CodeWarrior maps.
#[argh(subcommand, name = "map")]
#[argp(subcommand, name = "map")]
pub struct Args {
#[argh(subcommand)]
#[argp(subcommand)]
command: SubCommand,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand)]
#[argp(subcommand)]
enum SubCommand {
Entries(EntriesArgs),
Symbol(SymbolArgs),
@@ -30,51 +30,51 @@ enum SubCommand {
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Displays all entries for a particular TU.
#[argh(subcommand, name = "entries")]
#[argp(subcommand, name = "entries")]
pub struct EntriesArgs {
#[argh(positional)]
#[argp(positional)]
/// path to input map
map_file: PathBuf,
#[argh(positional)]
#[argp(positional)]
/// TU to display entries for
unit: String,
}
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Displays all references to a symbol.
#[argh(subcommand, name = "symbol")]
#[argp(subcommand, name = "symbol")]
pub struct SymbolArgs {
#[argh(positional)]
#[argp(positional)]
/// path to input map
map_file: PathBuf,
#[argh(positional)]
#[argp(positional)]
/// symbol to display references for
symbol: String,
}
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Attempts to resolve global link order.
#[argh(subcommand, name = "order")]
#[argp(subcommand, name = "order")]
pub struct OrderArgs {
#[argh(positional)]
#[argp(positional)]
/// path to input map
map_file: PathBuf,
}
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Emits a slices.yml for ppcdis. (WIP)
#[argh(subcommand, name = "slices")]
#[argp(subcommand, name = "slices")]
pub struct SlicesArgs {
#[argh(positional)]
#[argp(positional)]
/// path to input map
map_file: PathBuf,
}
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Emits a symbols.yml for ppcdis. (WIP)
#[argh(subcommand, name = "symbols")]
#[argp(subcommand, name = "symbols")]
pub struct SymbolsArgs {
#[argh(positional)]
#[argp(positional)]
/// path to input map
map_file: PathBuf,
}

View File

@@ -1,18 +1,18 @@
use std::path::PathBuf;
use anyhow::{bail, ensure, Context, Result};
use argh::FromArgs;
use argp::FromArgs;
use memchr::memmem;
use memmap2::MmapOptions;
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Sets the MetroidBuildInfo tag value in a given binary.
#[argh(subcommand, name = "metroidbuildinfo")]
#[argp(subcommand, name = "metroidbuildinfo")]
pub struct Args {
#[argh(positional)]
#[argp(positional)]
/// path to source binary
binary: PathBuf,
#[argh(positional)]
#[argp(positional)]
/// path to build info string
build_info: PathBuf,
}

View File

@@ -6,7 +6,7 @@ use std::{
};
use anyhow::{bail, ensure, Context, Result};
use argh::FromArgs;
use argp::FromArgs;
use crate::{
analysis::{
@@ -28,14 +28,14 @@ use crate::{
#[derive(FromArgs, PartialEq, Debug)]
/// Commands for processing REL files.
#[argh(subcommand, name = "rel")]
#[argp(subcommand, name = "rel")]
pub struct Args {
#[argh(subcommand)]
#[argp(subcommand)]
command: SubCommand,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand)]
#[argp(subcommand)]
enum SubCommand {
Info(InfoArgs),
Merge(MergeArgs),
@@ -43,24 +43,24 @@ enum SubCommand {
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Views REL file information.
#[argh(subcommand, name = "info")]
#[argp(subcommand, name = "info")]
pub struct InfoArgs {
#[argh(positional)]
#[argp(positional)]
/// REL file
rel_file: PathBuf,
}
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Merges a DOL + REL(s) into an ELF.
#[argh(subcommand, name = "merge")]
#[argp(subcommand, name = "merge")]
pub struct MergeArgs {
#[argh(positional)]
#[argp(positional)]
/// DOL file
dol_file: PathBuf,
#[argh(positional)]
#[argp(positional)]
/// REL file(s)
rel_files: Vec<PathBuf>,
#[argh(option, short = 'o')]
#[argp(option, short = 'o')]
/// output ELF
out_file: PathBuf,
}

View File

@@ -1,29 +1,29 @@
use std::path::PathBuf;
use anyhow::Result;
use argh::FromArgs;
use argp::FromArgs;
use crate::util::rso::process_rso;
#[derive(FromArgs, PartialEq, Debug)]
/// Commands for processing RSO files.
#[argh(subcommand, name = "rso")]
#[argp(subcommand, name = "rso")]
pub struct Args {
#[argh(subcommand)]
#[argp(subcommand)]
command: SubCommand,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand)]
#[argp(subcommand)]
enum SubCommand {
Info(InfoArgs),
}
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Views RSO file information.
#[argh(subcommand, name = "info")]
#[argp(subcommand, name = "info")]
pub struct InfoArgs {
#[argh(positional)]
#[argp(positional)]
/// RSO file
rso_file: PathBuf,
}

View File

@@ -5,7 +5,7 @@ use std::{
};
use anyhow::{anyhow, bail, Context, Result};
use argh::FromArgs;
use argp::FromArgs;
use filetime::{set_file_mtime, FileTime};
use sha1::{Digest, Sha1};
@@ -13,15 +13,15 @@ use crate::util::file::process_rsp;
#[derive(FromArgs, PartialEq, Eq, Debug)]
/// Print or check SHA1 (160-bit) checksums.
#[argh(subcommand, name = "shasum")]
#[argp(subcommand, name = "shasum")]
pub struct Args {
#[argh(switch, short = 'c')]
#[argp(switch, short = 'c')]
/// check SHA sums against given list
check: bool,
#[argh(positional)]
#[argp(positional)]
/// path to input file(s)
files: Vec<PathBuf>,
#[argh(option, short = 'o')]
#[argp(option, short = 'o')]
/// touch output file on successful check
output: Option<PathBuf>,
}