diff --git a/src/hvm/check_net_size.rs b/src/hvm/check_net_size.rs index 2f4918146..1cf411298 100644 --- a/src/hvm/check_net_size.rs +++ b/src/hvm/check_net_size.rs @@ -1,5 +1,5 @@ use super::tree_children; -use crate::{diagnostics::Diagnostics, fun::Name, CompileOpts}; +use crate::{diagnostics::Diagnostics, fun::Name, CompilerTarget}; use hvm::ast::{Book, Net, Tree}; pub const MAX_NET_SIZE_C: usize = 4095; @@ -8,11 +8,12 @@ pub const MAX_NET_SIZE_CUDA: usize = 64; pub fn check_net_sizes( book: &Book, diagnostics: &mut Diagnostics, - opts: &CompileOpts, + target: &CompilerTarget, ) -> Result<(), Diagnostics> { - let net_size_bound = match opts.command.as_str() { - "run-cu" | "gen-cu" | "gen-hvm" => MAX_NET_SIZE_CUDA, - _ => MAX_NET_SIZE_C, + dbg!(&target); + let (net_size_bound, target_lang) = match target { + CompilerTarget::Cuda => (MAX_NET_SIZE_CUDA, "Cuda"), + _ => (MAX_NET_SIZE_C, "C"), }; diagnostics.start_pass(); @@ -21,7 +22,7 @@ pub fn check_net_sizes( let nodes = count_nodes(net); if nodes > net_size_bound { diagnostics.add_rule_error( - format!("Definition is too large for hvm (size={nodes}, max size={net_size_bound}). Please break it into smaller pieces."), + format!("Definition is too large for HVM {target_lang} (size={nodes}, max size={net_size_bound}). Please break it into smaller pieces."), Name::new(name), ); } diff --git a/src/lib.rs b/src/lib.rs index 92a0da231..1deec0176 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,7 +73,7 @@ pub fn compile_book( } if opts.check_net_size { - check_net_sizes(&hvm_book, &mut diagnostics, &opts)?; + check_net_sizes(&hvm_book, &mut diagnostics, &opts.target_architecture)?; } add_recursive_priority(&mut hvm_book); @@ -329,10 +329,17 @@ impl OptLevel { } } +#[derive(Clone, Debug)] +pub enum CompilerTarget { + C, + Cuda, + Unknown, +} + #[derive(Clone, Debug)] pub struct CompileOpts { - /// The Bend command - pub command: String, + /// The Compiler target architecture + pub target_architecture: CompilerTarget, /// Enables [hvm::eta_reduce]. pub eta: bool, @@ -364,7 +371,7 @@ impl CompileOpts { #[must_use] pub fn set_all(self) -> Self { Self { - command: self.command, + target_architecture: self.target_architecture, eta: true, prune: true, float_combinators: true, @@ -380,7 +387,7 @@ impl CompileOpts { #[must_use] pub fn set_no_all(self) -> Self { Self { - command: self.command, + target_architecture: self.target_architecture, eta: false, prune: false, linearize_matches: OptLevel::Disabled, @@ -411,7 +418,7 @@ impl Default for CompileOpts { /// Uses num-scott ADT encoding. fn default() -> Self { Self { - command: String::from("run"), + target_architecture: CompilerTarget::Cuda, eta: true, prune: false, linearize_matches: OptLevel::Enabled, diff --git a/src/main.rs b/src/main.rs index 270c527e0..caa03ae9b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use bend::{ fun::{Book, Name}, hvm::hvm_book_show_pretty, imports::DefaultLoader, - load_file_to_book, run_book, AdtEncoding, CompileOpts, OptLevel, RunOpts, + load_file_to_book, run_book, AdtEncoding, CompileOpts, CompilerTarget, OptLevel, RunOpts, }; use clap::{Args, CommandFactory, Parser, Subcommand}; use std::{ @@ -190,13 +190,10 @@ pub enum OptArgs { AdtNumScott, } -fn compile_opts_from_cli(args: &Vec, cmd: Option<&str>) -> CompileOpts { +fn compile_opts_from_cli(args: &Vec, compiler_target: CompilerTarget) -> CompileOpts { use OptArgs::*; let mut opts = CompileOpts::default(); - - if let Some(cmd) = cmd { - opts.command = cmd.to_string(); - } + opts.target_architecture = compiler_target; for arg in args { match arg { @@ -292,10 +289,18 @@ fn execute_cli_mode(mut cli: Cli) -> Result<(), Diagnostics> { _ => "run-c", }; + let compiler_target = match &cli.mode { + Mode::RunC(..) => CompilerTarget::C, + Mode::GenC(..) => CompilerTarget::C, + Mode::RunCu(..) => CompilerTarget::Cuda, + Mode::GenCu(..) => CompilerTarget::Cuda, + _ => CompilerTarget::Unknown, + }; + match cli.mode { Mode::Check { comp_opts, warn_opts, path } => { let diagnostics_cfg = set_warning_cfg_from_cli(DiagnosticsConfig::default(), warn_opts); - let compile_opts = compile_opts_from_cli(&comp_opts, None); + let compile_opts = compile_opts_from_cli(&comp_opts, compiler_target); let mut book = load_book(&path, diagnostics_cfg)?; let diagnostics = check_book(&mut book, diagnostics_cfg, compile_opts)?; @@ -304,7 +309,7 @@ fn execute_cli_mode(mut cli: Cli) -> Result<(), Diagnostics> { Mode::GenHvm(GenArgs { comp_opts, warn_opts, path, .. }) => { let diagnostics_cfg = set_warning_cfg_from_cli(DiagnosticsConfig::default(), warn_opts); - let opts = compile_opts_from_cli(&comp_opts, Some("gen-hvm")); + let opts = compile_opts_from_cli(&comp_opts, compiler_target); let mut book = load_book(&path, diagnostics_cfg)?; let compile_res = compile_book(&mut book, opts, diagnostics_cfg, None)?; @@ -321,7 +326,7 @@ fn execute_cli_mode(mut cli: Cli) -> Result<(), Diagnostics> { let diagnostics_cfg = set_warning_cfg_from_cli(DiagnosticsConfig::new(Severity::Allow, arg_verbose), warn_opts); - let compile_opts = compile_opts_from_cli(&comp_opts, Some(run_cmd)); + let compile_opts = compile_opts_from_cli(&comp_opts, compiler_target); compile_opts.check_for_strict(); @@ -346,7 +351,7 @@ fn execute_cli_mode(mut cli: Cli) -> Result<(), Diagnostics> { Mode::GenC(GenArgs { comp_opts, warn_opts, path }) | Mode::GenCu(GenArgs { comp_opts, warn_opts, path }) => { let diagnostics_cfg = set_warning_cfg_from_cli(DiagnosticsConfig::default(), warn_opts); - let opts = compile_opts_from_cli(&comp_opts, Some(gen_cmd)); + let opts = compile_opts_from_cli(&comp_opts, compiler_target); let mut book = load_book(&path, diagnostics_cfg)?; let compile_res = compile_book(&mut book, opts, diagnostics_cfg, None)?; @@ -377,7 +382,7 @@ fn execute_cli_mode(mut cli: Cli) -> Result<(), Diagnostics> { Mode::Desugar { path, comp_opts, warn_opts, pretty } => { let diagnostics_cfg = set_warning_cfg_from_cli(DiagnosticsConfig::default(), warn_opts); - let opts = compile_opts_from_cli(&comp_opts, None); + let opts = compile_opts_from_cli(&comp_opts, compiler_target); let mut book = load_book(&path, diagnostics_cfg)?; let diagnostics = desugar_book(&mut book, opts, diagnostics_cfg, None)?;