Changeset - b9e63d3e470b
[Not reviewed]
0 3 0
Max Henger - 3 years ago 2022-05-16 01:15:27
henger@cwi.nl
fix: add support for log level to bin-compiler
3 files changed with 19 insertions and 7 deletions:
0 comments (0 inline, 0 general)
.gitignore
Show inline comments
 
# TODO Documents and notes
 
todo_*.md
 
notes_*.md
 

	
 
# Build system
 
Cargo.lock
 
target
 
**/*.rs.bk
 

	
 
# IDEs
 
/.idea
 
bin-compiler/.idea
 

	
 
# Binaries
 
main
 

	
 
# Examples
 
examples/*/*.exe
 
examples/*.dll
 
examples/reowolf*
 
examples/*.txt
 
examples/lib*
 
examples/lib*.*
 
examples/*/amy
bin-compiler/src/main.rs
Show inline comments
 
@@ -18,28 +18,30 @@ fn main() {
 
                .takes_value(true)
 
                .multiple_occurrences(true)
 
        )
 
        .arg(
 
            Arg::new("threads")
 
                .long("threads")
 
                .short('t')
 
                .help("number of runtime threads")
 
                .default_value("1")
 
                .takes_value(true)
 
        )
 
        .arg(
 
            Arg::new("debug")
 
                .long("debug")
 
                .short('d')
 
                .help("enable debug logging")
 
            Arg::new("loglevel")
 
                .long("log_level")
 
                .short('l')
 
                .help("set log level ('none', 'info', 'debug' or 'all')")
 
                .default_value("all")
 
                .takes_value(true)
 
        )
 
        .arg(
 
            Arg::new("stdlib")
 
                .long("stdlib")
 
                .short('s')
 
                .help("standard library directory (overrides default)")
 
                .takes_value(true)
 
        );
 

	
 
    // Retrieve arguments and convert
 
    let app = app.get_matches();
 
    let input_files = app.values_of("input");
 
@@ -55,25 +57,34 @@ fn main() {
 
                println!("ERROR: Number of threads must be a number between 0 and 256");
 
                return;
 
            }
 

	
 
            num_threads as u32
 
        },
 
        Err(err) => {
 
            println!("ERROR: Failed to parse number of threads\nbecause: {}", err);
 
            return;
 
        }
 
    };
 

	
 
    let debug_enabled = app.is_present("debug");
 
    let log_level = app.value_of("loglevel").unwrap();
 
    let log_level = match log_level {
 
        "none" | "None" => rw::runtime2::LogLevel::None,
 
        "debug" | "Debug" => rw::runtime2::LogLevel::Debug,
 
        "info" | "Info" | "all" | "All" => rw::runtime2::LogLevel::Info,
 
        _ => {
 
            println!("ERROR: Unexpected log level");
 
            return;
 
        }
 
    };
 

	
 
    let standard_library_dir = app.value_of("stdlib")
 
        .map(|v| v.to_string());
 

	
 
    // Add input files to file buffer
 
    let input_files = input_files.unwrap();
 
    assert!(input_files.len() > 0); // because arg is required
 

	
 
    let mut builder = rw::ProtocolDescriptionBuilder::new(standard_library_dir)
 
        .expect("create protocol description builder");
 
    let mut file_buffer = Vec::with_capacity(4096);
 

	
 
@@ -105,25 +116,25 @@ fn main() {
 
    let protocol_description = match builder.compile() {
 
        Ok(pd) => pd,
 
        Err(err) => {
 
            println!("FAILED\nbecause:\n{}", err);
 
            return;
 
        }
 
    };
 

	
 
    println!("Success");
 

	
 
    // Start runtime
 
    print!("Startup of runtime ... ");
 
    let runtime = rw::runtime2::Runtime::new(num_threads, debug_enabled, protocol_description);
 
    let runtime = rw::runtime2::Runtime::new(num_threads, log_level, protocol_description);
 
    if let Err(err) = &runtime {
 
        println!("FAILED\nbecause:\n{}", err);
 
    }
 
    println!("Success");
 

	
 
    // Make sure there is a nameless module with a main component
 
    print!("Creating main component ... ");
 
    let runtime = runtime.unwrap();
 
    if let Err(err) = runtime.create_component(b"", b"main") {
 
        use rw::ComponentCreationError as CCE;
 
        let reason = match err {
 
            CCE::ModuleDoesntExist => "Input files did not contain a nameless module (that should contain the 'main' component)",
src/runtime2/mod.rs
Show inline comments
 
#[macro_use] mod error;
 
mod store;
 
mod runtime;
 
mod component;
 
mod communication;
 
mod scheduler;
 
mod poll;
 
mod stdlib;
 
#[cfg(test)] mod tests;
 

	
 
pub use runtime::Runtime;
 
pub use runtime::{Runtime, LogLevel};
 
pub(crate) use error::RtError;
 
pub(crate) use scheduler::SchedulerCtx;
 
pub(crate) use communication::{
 
    PortId,
 
    Message, ControlMessage, SyncMessage, DataMessage,
 
    SyncRoundDecision
 
};
 
\ No newline at end of file
0 comments (0 inline, 0 general)