1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use std::{path::PathBuf, sync::Arc};

/// Configuration for the overall build and compilation process.
#[derive(Clone)]
pub struct BuildConfig {
    pub(crate) file_name: Arc<PathBuf>,
    pub(crate) dir_of_code: Arc<PathBuf>,
    pub(crate) manifest_path: Arc<PathBuf>,
    pub(crate) use_ir: bool,
    pub(crate) print_intermediate_asm: bool,
    pub(crate) print_finalized_asm: bool,
    pub(crate) print_ir: bool,
}

impl BuildConfig {
    // note this is intentionally not the trait Default
    // since we need at least a manifest path to work with
    pub fn root_from_file_name_and_manifest_path(
        file_name: PathBuf,
        canonicalized_manifest_path: PathBuf,
    ) -> Self {
        let mut path = canonicalized_manifest_path.clone();
        path.push("src");
        Self {
            file_name: Arc::new(file_name),
            dir_of_code: Arc::new(path),
            manifest_path: Arc::new(canonicalized_manifest_path),
            use_ir: false,
            print_intermediate_asm: false,
            print_finalized_asm: false,
            print_ir: false,
        }
    }

    pub fn use_ir(self, a: bool) -> Self {
        Self { use_ir: a, ..self }
    }

    pub fn print_intermediate_asm(self, a: bool) -> Self {
        Self {
            print_intermediate_asm: a,
            ..self
        }
    }

    pub fn print_finalized_asm(self, a: bool) -> Self {
        Self {
            print_finalized_asm: a,
            ..self
        }
    }

    pub fn print_ir(self, a: bool) -> Self {
        Self {
            print_ir: a,
            ..self
        }
    }

    pub fn path(&self) -> Arc<PathBuf> {
        self.file_name.clone()
    }
}