]>
Witch of Git - ivy/blob - src/main.rs
   4     trans
::{self, translate
}, 
   9     io
::{self, Read
, Write
}, 
  10     path
::{Path
, PathBuf
}, 
  13 use structopt
::{clap
, StructOpt
}; 
  18 /// If no mode is specified, this will fully compile the program. 
  19 #[derive(Debug, StructOpt)] 
  20 #[structopt(setting = clap::AppSettings::ArgRequiredElseHelp)] 
  23     #[structopt(short = "S", long = "assembly", conflicts_with = "pretty")] 
  26     /// Pretty-print the source code. 
  27     #[structopt(short = "p", long = "pretty")] 
  30     /// Input path. Use "-" for stdin. 
  33     /// Output path. Defaults to stdout or a.out, depending on the mode. 
  34     #[structopt(short = "o", long = "output")] 
  35     output
: Option
<PathBuf
>, 
  38 fn main() -> io
::Result
<()> { 
  39     let opt 
= Opt
::from_args(); 
  40     let text 
= match &opt
.input 
{ 
  41         path 
if path 
== Path
::new("-") => { 
  42             let mut text 
= String
::new(); 
  43             std
::io
::stdin().read_to_string(&mut text
)?
; 
  46         path 
=> fs
::read_to_string(path
)?
, 
  48     let sexp 
= match parse(&text
) { 
  51             println!("{:?}", err
); 
  52             std
::process
::exit(1); 
  55     let (ast
, mut builtins
) = match Ast
::parse(BUILTINS
, &sexp
) { 
  59             std
::process
::exit(1); 
  65                 let mut file 
= fs
::File
::create(path
)?
; 
  66                 writeln!(file
, "{}", ast
.to_doc().pretty(80))?
; 
  68             None 
=> println!("{}", ast
.to_doc().pretty(80)), 
  72     let mut code 
= match translate(&ast
) { 
  76             std
::process
::exit(1); 
  79     code
.globals
.insert(1); // builtins true 
  80     code
.globals
.insert(2); // builtins false 
  81     builtins
.retain(|_
, v
| code
.globals
.contains(&v
.global_number().unwrap())); 
  85                 let mut file 
= fs
::File
::create(path
)?
; 
  86                 trans
::x64
::write_compile(&builtins
, &mut file
, &code
)?
; 
  89                 let stdout 
= std
::io
::stdout(); 
  90                 trans
::x64
::write_compile(&builtins
, &mut stdout
.lock(), &code
)?
; 
  95     let mut file 
= tempfile
::Builder
::new().suffix(".s").tempfile()?
; 
  96     trans
::x64
::write_compile(&builtins
, &mut file
, &code
)?
; 
  98         .args(&["-masm=intel", "-nostartfiles", "-livy_rt", "-Wl,-e,_start"]) 
 101         .arg(opt
.output
.unwrap_or_else(|| "a.out".into())) 
 
This page took 0.052294 seconds  and 5 git commands  to generate.