Skip to content

Register derived from (resolve) #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ path = "src/main.rs"
cast = "0.2.2"
clap = "2.26.0"
either = "1.0.3"
env_logger = "~0.5"
error-chain = "0.11.0"
inflections = "1.1.0"
log = { version = "~0.4", features = ["std"] }
quote = "0.3.15"
svd-parser = "0.7.0"
syn = "0.11.11"
13 changes: 7 additions & 6 deletions src/generate/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::svd::{
};
use quote::{ToTokens, Tokens};
use syn::{self, Ident};
use log::warn;

use crate::errors::*;
use crate::util::{self, ToSanitizedSnakeCase, ToSanitizedUpperCase, BITS_PER_BYTE};
Expand Down Expand Up @@ -442,8 +443,8 @@ impl FieldRegions {
r.fields.len() > 1 && (idents.iter().filter(|ident| **ident == r.ident).count() > 1)
})
.inspect(|r| {
eprintln!(
"WARNING: Found type name conflict with region {:?}, renamed to {:?}",
warn!(
"Found type name conflict with region {:?}, renamed to {:?}",
r.ident,
r.shortest_ident()
)
Expand Down Expand Up @@ -485,8 +486,8 @@ fn register_or_cluster_block_stable(
let pad = if let Some(pad) = reg_block_field.offset.checked_sub(offset) {
pad
} else {
eprintln!(
"WARNING {:?} overlaps with another register block at offset {}. \
warn!(
"{:?} overlaps with another register block at offset {}. \
Ignoring.",
reg_block_field.field.ident, reg_block_field.offset
);
Expand Down Expand Up @@ -574,8 +575,8 @@ fn register_or_cluster_block_nightly(
if reg_block_field.offset != region.offset {
// TODO: need to emit padding for this case.
// Happens for freescale_mkl43z4
eprintln!(
"WARNING: field {:?} has different offset {} than its union container {}",
warn!(
"field {:?} has different offset {} than its union container {}",
reg_block_field.field.ident, reg_block_field.offset, region.offset
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/generate/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ pub fn render(
for<'w> F: FnOnce(&R, &'w mut W) -> &'w mut W
{
let bits = self.register.get();
let r = R { bits: bits };
let mut w = W { bits: bits };
let r = R { bits };
let mut w = W { bits };
f(&r, &mut w);
self.register.set(w.bits);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ pub enum SvdError {
pub fn generate(xml: &str, target: Target, nightly: bool) -> Result<Generation> {
use std::fmt::Write;

let device = svd::parse(xml).expect("//TODO(AJM)");
let device = svd::parse(xml).unwrap(); //TODO(AJM)
let mut device_x = String::new();
let items = generate::device::render(&device, target, nightly, &mut device_x)
.or(Err(SvdError::Render))?;
Expand Down
58 changes: 49 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#[macro_use]
extern crate error_chain;
#[macro_use]
extern crate log;
#[macro_use]
extern crate quote;
use svd_parser as svd;

Expand Down Expand Up @@ -43,12 +45,25 @@ fn run() -> Result<()> {
.long("nightly")
.help("Enable features only available to nightly rustc"),
)
.arg(
Arg::with_name("log_level")
.long("log")
.short("l")
.help(&format!(
"Choose which messages to log (overrides {})",
env_logger::DEFAULT_FILTER_ENV
))
.takes_value(true)
.possible_values(&["off", "error", "warn", "info", "debug", "trace"])
)
.version(concat!(
env!("CARGO_PKG_VERSION"),
include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt"))
))
.get_matches();

setup_logging(&matches);

let target = matches
.value_of("target")
.map(|s| Target::parse(s))
Expand All @@ -71,7 +86,7 @@ fn run() -> Result<()> {
}
}

let device = svd::parse(xml).expect("//TODO(AJM)");
let device = svd::parse(xml).unwrap(); //TODO(AJM)

let nightly = matches.is_present("nightly_features");

Expand All @@ -88,21 +103,46 @@ fn run() -> Result<()> {
Ok(())
}

fn main() {
if let Err(e) = &run() {
let stderr = io::stderr();
let mut stderr = stderr.lock();
fn setup_logging(matches: &clap::ArgMatches) {
// * Log at info by default.
// * Allow users the option of setting complex logging filters using
// env_logger's `RUST_LOG` environment variable.
// * Override both of those if the logging level is set via the `--log`
// command line argument.
let env = env_logger::Env::default()
.filter_or(env_logger::DEFAULT_FILTER_ENV, "info");
let mut builder = env_logger::Builder::from_env(env);
builder.default_format_timestamp(false);

let log_lvl_from_env =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks shady. Why store it in a variable and then ignore it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea. All commits except mine are already in master.

This PR is only due to:
#308 (comment)

std::env::var_os(env_logger::DEFAULT_FILTER_ENV).is_some();

if log_lvl_from_env {
log::set_max_level(log::LevelFilter::Trace);
} else {
let level = match matches.value_of("log_level") {
Some(lvl) => lvl.parse().unwrap(),
None => log::LevelFilter::Info,
};
log::set_max_level(level);
builder.filter_level(level);
}

writeln!(stderr, "error: {}", e).ok();
builder.init();
}

fn main() {
if let Err(ref e) = run() {
error!("{}", e);

for e in e.iter().skip(1) {
writeln!(stderr, "caused by: {}", e).ok();
error!("caused by: {}", e);
}

if let Some(backtrace) = e.backtrace() {
writeln!(stderr, "backtrace: {:?}", backtrace).ok();
error!("backtrace: {:?}", backtrace);
} else {
writeln!(stderr, "note: run with `RUST_BACKTRACE=1` for a backtrace").ok();
error!("note: run with `RUST_BACKTRACE=1` for a backtrace")
}

process::exit(1);
Expand Down