tenseleyflow/bencch / 13ff73e

Browse files

Isolate linked compiler adapter

Authored by espadonne
SHA
13ff73eb0ce96d920e8e9049b0d6296b75930dee
Parents
3a2b78f
Tree
82290f1

2 changed files

StatusFile+-
A bench/src/compiler.rs 43 0
M bench/src/lib.rs 15 18
bench/src/compiler.rsadded
@@ -0,0 +1,43 @@
1
+use std::path::{Path, PathBuf};
2
+
3
+pub use armfortas::driver::OptLevel;
4
+pub use armfortas::testing::{
5
+    capture_from_path, CaptureFailure, CaptureRequest, CaptureResult, CapturedStage,
6
+    FailureStage, RunCapture, Stage,
7
+};
8
+
9
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10
+pub enum EmitMode {
11
+    Asm,
12
+    Obj,
13
+    Binary,
14
+}
15
+
16
+pub fn compile_output(
17
+    input: &Path,
18
+    opt_level: OptLevel,
19
+    mode: EmitMode,
20
+    output: &Path,
21
+) -> Result<(), String> {
22
+    let opts = armfortas::driver::Options {
23
+        input: input.to_path_buf(),
24
+        output: Some(PathBuf::from(output)),
25
+        emit_asm: matches!(mode, EmitMode::Asm),
26
+        emit_obj: matches!(mode, EmitMode::Obj),
27
+        emit_ir: false,
28
+        preprocess_only: false,
29
+        opt_level,
30
+    };
31
+
32
+    armfortas::driver::compile(&opts)
33
+}
34
+
35
+#[cfg(test)]
36
+pub mod test_support {
37
+    pub use armfortas::ir::inst::{
38
+        BlockParam, Function, Inst, InstKind, Module, Terminator, ValueId,
39
+    };
40
+    pub use armfortas::ir::types::{FloatWidth, IntWidth, IrType};
41
+    pub use armfortas::ir::verify::verify_module;
42
+    pub use armfortas::lexer::{Position, Span};
43
+}
bench/src/lib.rsmodified
@@ -1,13 +1,14 @@
1
+mod compiler;
2
+
13
 use std::collections::{BTreeMap, BTreeSet, VecDeque};
24
 use std::fs;
35
 use std::path::{Path, PathBuf};
46
 use std::process::Command;
57
 use std::sync::atomic::{AtomicU64, Ordering};
68
 
7
-use armfortas::driver::{self, OptLevel};
8
-use armfortas::testing::{
9
-    capture_from_path, CaptureFailure, CaptureRequest, CaptureResult, CapturedStage, FailureStage,
10
-    RunCapture, Stage,
9
+use crate::compiler::{
10
+    capture_from_path, compile_output, CaptureFailure, CaptureRequest, CaptureResult,
11
+    CapturedStage, EmitMode, FailureStage, OptLevel, RunCapture, Stage,
1112
 };
1213
 
1314
 const SUITE_EXTENSION: &str = "afs";
@@ -3446,17 +3447,13 @@ fn compile_with_driver(
34463447
             return Err(format!("{} failed:\n{}", command, stderr.trim_end()));
34473448
         }
34483449
     } else {
3449
-        let opts = driver::Options {
3450
-            input: source.to_path_buf(),
3451
-            output: Some(output.to_path_buf()),
3452
-            emit_asm: matches!(mode, DriverEmitMode::Asm),
3453
-            emit_obj: matches!(mode, DriverEmitMode::Obj),
3454
-            emit_ir: false,
3455
-            preprocess_only: false,
3456
-            opt_level,
3450
+        let emit_mode = match mode {
3451
+            DriverEmitMode::Asm => EmitMode::Asm,
3452
+            DriverEmitMode::Obj => EmitMode::Obj,
3453
+            DriverEmitMode::Binary => EmitMode::Binary,
34573454
         };
3458
-
3459
-        driver::compile(&opts).map_err(|detail| format!("{} failed:\n{}", command, detail))?;
3455
+        compile_output(source, opt_level, emit_mode, output)
3456
+            .map_err(|detail| format!("{} failed:\n{}", command, detail))?;
34603457
     }
34613458
     Ok(command)
34623459
 }
@@ -4658,10 +4655,10 @@ fn match_checks(checks: &[Check], output: &str, case_name: &str) -> Result<(), S
46584655
 #[cfg(test)]
46594656
 mod tests {
46604657
     use super::*;
4661
-    use armfortas::ir::inst::{BlockParam, Function, Inst, InstKind, Module, Terminator, ValueId};
4662
-    use armfortas::ir::types::{FloatWidth, IntWidth, IrType};
4663
-    use armfortas::ir::verify::verify_module;
4664
-    use armfortas::lexer::{Position, Span};
4658
+    use crate::compiler::test_support::{
4659
+        verify_module, BlockParam, FloatWidth, Function, Inst, InstKind, IntWidth, IrType,
4660
+        Module, Position, Span, Terminator, ValueId,
4661
+    };
46654662
 
46664663
     fn dummy_span() -> Span {
46674664
         Span {