Compare commits

..

No commits in common. "07b0403e9b0fb5f3460afc6a553f7885e4199aad" and "7dd06567bb14e4fc72c4bfe77e5b7557bb795920" have entirely different histories.

2 changed files with 8 additions and 49 deletions

View File

@ -104,15 +104,3 @@ fn find_objectfile(name: &str) -> String {
.unwrap()
.to_owned()
}
pub fn execute(path: &PathBuf) -> Option<i32> {
let output = Command::new(path.clone()).output().expect("Unable to execute {path}");
if !output.status.success() {
let code = output.status.code().unwrap_or(255);
log::error!("{path:?} exited with code {code}");
println!("{}", unsafe { String::from_utf8_unchecked(output.stderr) });
}
output.status.code()
}

View File

@ -1,12 +1,8 @@
use std::{fs, path::PathBuf, process};
use std::{fs, path::PathBuf};
use argh::FromArgs;
use log::*;
use reid::{
compile_simple,
ld::{execute, LDRunner},
CustomIRs,
};
use reid::{compile_simple, ld::LDRunner, CustomIRs};
use reid_lib::compile::CompileOutput;
#[derive(FromArgs, PartialEq, Debug)]
@ -27,7 +23,6 @@ struct Options {
#[argh(subcommand)]
enum Command {
Build(BuildOpts),
Run(RunOpts),
}
#[derive(FromArgs, PartialEq, Debug)]
@ -41,17 +36,6 @@ struct BuildOpts {
path: PathBuf,
}
#[derive(FromArgs, PartialEq, Debug)]
/// Build and then execute the executable
#[argh(subcommand, name = "run")]
struct RunOpts {
#[argh(option, long = "lib", short = 'l')]
/// additional libraries to link against (with ld)
libraries: Vec<String>,
#[argh(positional)]
path: PathBuf,
}
fn main() {
let options: Options = argh::from_env();
let mut errlog = stderrlog::new();
@ -61,12 +45,12 @@ fn main() {
}
errlog.init().unwrap();
match &options.command {
Command::Build(BuildOpts { libraries, path }) | Command::Run(RunOpts { libraries, path }) => {
match options.command {
Command::Build(build) => {
let cpu = std::env::var("CPU").unwrap_or("generic".to_owned());
let features = std::env::var("REIDFLAGS").unwrap_or("".to_owned());
let path = match path.canonicalize() {
let path = match build.path.canonicalize() {
Ok(path) => path,
Err(e) => {
error!("{e}");
@ -80,7 +64,6 @@ fn main() {
let llir_path = parent.with_extension("llir");
let mir_path = parent.with_extension("mir");
let asm_path = parent.with_extension("asm");
let out_path = object_path.with_extension("out");
let before = std::time::SystemTime::now();
@ -125,25 +108,13 @@ fn main() {
let linker = std::env::var("LD").unwrap_or("ld".to_owned());
let mut linker = LDRunner::from_command(&linker).with_library("c").with_library("m");
for library in libraries {
for library in build.libraries {
linker = linker.with_library(&library);
}
linker.invoke(&object_path, &out_path);
}
Err(e) => {
log::error!("{e}");
return;
linker.invoke(&object_path, &object_path.with_extension("out"));
}
Err(e) => panic!("{}", e),
};
match &options.command {
Command::Build(_) => {}
Command::Run(_) => {
if let Some(code) = execute(&out_path) {
process::exit(code);
}
}
}
}
}
}