#![allow(dead_code)]
#![allow(unused_imports)]
use clap::{Parser, Subcommand, ValueEnum};
use cmds::analyze::IrOutputFormat;
use std::path::PathBuf;
mod abi;
mod cmds;
mod codegen;
mod dependency;
#[derive(Parser)]
#[command(name = "abi")]
#[command(about = "ABI code generation tool for thru-net", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Codegen {
#[arg(short = 'f', long = "files", value_name = "FILE", required = true)]
files: Vec<PathBuf>,
#[arg(short = 'i', long = "include-dir", value_name = "DIR")]
include_dirs: Vec<PathBuf>,
#[arg(short = 'l', long = "language", value_enum)]
language: Language,
#[arg(
short = 'o',
long = "output",
value_name = "DIR",
default_value = "generated"
)]
output_dir: PathBuf,
#[arg(short = 'v', long = "verbose")]
verbose: bool,
},
Analyze {
#[arg(short = 'f', long = "files", value_name = "FILE", required = true)]
files: Vec<PathBuf>,
#[arg(short = 'i', long = "include-dir", value_name = "DIR")]
include_dirs: Vec<PathBuf>,
#[arg(long = "print-ir")]
print_ir: bool,
#[arg(long = "ir-format", value_enum, default_value = "json")]
ir_format: IrOutputFormat,
#[arg(long = "print-footprint", value_name = "TYPE")]
print_footprint: Option<String>,
#[arg(long = "print-validate", value_name = "TYPE")]
print_validate: Option<String>,
},
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug)]
enum Language {
C,
Rust,
#[value(name = "typescript")]
TypeScript,
}
impl From<Language> for cmds::codegen::Language {
fn from(lang: Language) -> Self {
match lang {
Language::C => cmds::codegen::Language::C,
Language::Rust => cmds::codegen::Language::Rust,
Language::TypeScript => cmds::codegen::Language::TypeScript,
}
}
}
fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
match cli.command {
Commands::Codegen {
files,
include_dirs,
language,
output_dir,
verbose,
} => {
cmds::codegen::run(files, include_dirs, language.into(), output_dir, verbose)?;
}
Commands::Analyze {
files,
include_dirs,
print_ir,
ir_format,
print_footprint,
print_validate,
} => {
cmds::analyze::run(
files,
include_dirs,
print_ir,
ir_format,
print_footprint,
print_validate,
)?;
}
}
Ok(())
}