/ adl-cli / cli / main.rs
main.rs
 1  // Copyright (C) 2019-2025 ADnet Contributors
 2  // This file is part of the ADL library.
 3  
 4  // The ADL library is free software: you can redistribute it and/or modify
 5  // it under the terms of the GNU General Public License as published by
 6  // the Free Software Foundation, either version 3 of the License, or
 7  // (at your option) any later version.
 8  
 9  // The ADL library is distributed in the hope that it will be useful,
10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  // GNU General Public License for more details.
13  
14  // You should have received a copy of the GNU General Public License
15  // along with the ADL library. If not, see <https://www.gnu.org/licenses/>.
16  
17  use adl_lang::cli::*;
18  use adl_span::create_session_if_not_set_then;
19  
20  use clap::Parser;
21  
22  fn set_panic_hook() {
23      std::panic::set_hook({
24          Box::new(move |e| {
25              eprintln!("thread `{}` {}", std::thread::current().name().unwrap_or("<unnamed>"), e);
26              eprintln!("stack backtrace: \n{:?}", backtrace::Backtrace::new());
27              eprintln!("error: internal compiler error: unexpected panic\n");
28              eprintln!("note: the compiler unexpectedly panicked. this is a bug.\n");
29              eprintln!(
30                  "note: we would appreciate a bug report: https://github.com/ProvableHQ/leo/issues/new?labels=bug,panic&template=bug.md&title=[Bug]\n"
31              );
32              eprintln!(
33                  "note: {} {} running on {} {}\n",
34                  env!("CARGO_PKG_NAME"),
35                  env!("CARGO_PKG_VERSION"),
36                  sys_info::os_type().unwrap_or_else(|e| e.to_string()),
37                  sys_info::os_release().unwrap_or_else(|e| e.to_string()),
38              );
39              eprintln!("note: compiler args: {}\n", std::env::args().collect::<Vec<_>>().join(" "));
40              eprintln!("note: compiler flags: {:?}\n", CLI::parse());
41          })
42      });
43  }
44  
45  fn main() {
46      set_panic_hook();
47      create_session_if_not_set_then(|_| handle_error(run_with_args(CLI::parse())));
48  }