clippy fix

main
NotAFile 2022-01-05 02:11:13 +01:00
parent 6cc7b3bcee
commit 99369b8f38
4 changed files with 14 additions and 15 deletions

View File

@ -63,7 +63,7 @@ fn lower_expression(
expr: &parser::Expression, expr: &parser::Expression,
) -> Result<String, CompileError> { ) -> Result<String, CompileError> {
match expr { match expr {
parser::Expression::Ident(ident) => Ok(make_pubid(&ident)), parser::Expression::Ident(ident) => Ok(make_pubid(ident)),
parser::Expression::Call(call) => { parser::Expression::Call(call) => {
let output_gen_id = module.make_genid("cell"); let output_gen_id = module.make_genid("cell");
module.add_wire(rtlil::Wire::new(&output_gen_id, 1, None)); module.add_wire(rtlil::Wire::new(&output_gen_id, 1, None));
@ -98,7 +98,7 @@ fn lower_assignment(
module: &mut rtlil::Module, module: &mut rtlil::Module,
assignment: parser::Assign, assignment: parser::Assign,
) -> Result<(), CompileError> { ) -> Result<(), CompileError> {
let target_id = make_pubid(&assignment.lhs); let target_id = make_pubid(assignment.lhs);
let return_wire = lower_expression(ctx, module, &assignment.expr)?; let return_wire = lower_expression(ctx, module, &assignment.expr)?;
module.add_connection(target_id, return_wire); module.add_connection(target_id, return_wire);
Ok(()) Ok(())
@ -106,8 +106,8 @@ fn lower_assignment(
pub fn lower_module(pa_module: parser::Module) -> Result<String, CompileError> { pub fn lower_module(pa_module: parser::Module) -> Result<String, CompileError> {
let mut writer = rtlil::ILWriter::new(); let mut writer = rtlil::ILWriter::new();
let mut ir_module = rtlil::Module::new(make_pubid(&pa_module.name)); let mut ir_module = rtlil::Module::new(make_pubid(pa_module.name));
let mut context = Context { let context = Context {
callables: get_builtins() callables: get_builtins()
.into_iter() .into_iter()
.map(|clb| (clb.name.to_owned(), clb)) .map(|clb| (clb.name.to_owned(), clb))
@ -120,7 +120,7 @@ pub fn lower_module(pa_module: parser::Module) -> Result<String, CompileError> {
parser::PortDirection::Output => rtlil::PortOption::Output(idx as i32 + 1), parser::PortDirection::Output => rtlil::PortOption::Output(idx as i32 + 1),
}; };
let wire = rtlil::Wire::new( let wire = rtlil::Wire::new(
make_pubid(&port.net.name), make_pubid(port.net.name),
port.net.width.unwrap_or(1) as u32, port.net.width.unwrap_or(1) as u32,
Some(dir_option), Some(dir_option),
); );

View File

@ -1,11 +1,10 @@
use std::ops::{RangeFrom, RangeTo};
use nom::{ use nom::{
character::complete::{char, one_of}, character::complete::{char, one_of},
combinator::{map_res, recognize}, combinator::{map_res, recognize},
multi::{many0, many1}, multi::{many0, many1},
sequence::{preceded, terminated}, sequence::{preceded, terminated},
AsChar, FindToken, InputIter, InputLength, Offset, Slice,
}; };
use crate::parser::{IResult, Span}; use crate::parser::{IResult, Span};
@ -19,7 +18,7 @@ pub fn hexadecimal(input: Span) -> IResult<Span, u64> {
many0(char('_')), many0(char('_')),
))), ))),
), ),
|out: Span| u64::from_str_radix(&str::replace(&out.fragment(), "_", ""), 16), |out: Span| u64::from_str_radix(&str::replace(out.fragment(), "_", ""), 16),
)(input) )(input)
} }

View File

@ -4,7 +4,7 @@ mod literals;
mod parser; mod parser;
mod rtlil; mod rtlil;
use nom::error::convert_error;
use std::fs::File; use std::fs::File;
use std::io::prelude::*; use std::io::prelude::*;
use std::path::PathBuf; use std::path::PathBuf;
@ -29,7 +29,7 @@ fn main() {
let input = parser::Span::new(input); let input = parser::Span::new(input);
let parsed = parser::parse(input); let parsed = parser::parse(input);
match parsed { match parsed {
Err(nom::Err::Error(err) | nom::Err::Failure(err)) => { Err(nom::Err::Error(_err) | nom::Err::Failure(_err)) => {
// TODO: get this working again // TODO: get this working again
// print!("{}", convert_error(input, err)) // print!("{}", convert_error(input, err))
} }

View File

@ -8,7 +8,7 @@ use nom::{
sequence::{delimited, pair, preceded, separated_pair, terminated, tuple}, sequence::{delimited, pair, preceded, separated_pair, terminated, tuple},
}; };
use nom_locate::{position, LocatedSpan}; use nom_locate::{LocatedSpan};
// custom span type for nom_locate // custom span type for nom_locate
pub type Span<'a> = LocatedSpan<&'a str>; pub type Span<'a> = LocatedSpan<&'a str>;
@ -166,7 +166,7 @@ fn call_item(input: Span) -> IResult<Span, Call> {
char(')'), char(')'),
), ),
)), )),
|(name, args)| Call { name: name, args }, |(name, args)| Call { name, args },
)(input) )(input)
} }
@ -175,7 +175,7 @@ fn expression(input: Span) -> IResult<Span, Expression> {
map(ws0(operation), |op| Expression::Operation(Box::new(op))), map(ws0(operation), |op| Expression::Operation(Box::new(op))),
map(ws0(call_item), |call| Expression::Call(Box::new(call))), map(ws0(call_item), |call| Expression::Call(Box::new(call))),
map(ws0(identifier), |ident| { map(ws0(identifier), |ident| {
Expression::Ident((*ident.fragment()).into()) Expression::Ident(*ident.fragment())
}), }),
))(input) ))(input)
} }
@ -189,7 +189,7 @@ fn assign_statement(input: Span) -> IResult<Span, Statement> {
separated_pair(ws0(identifier), char('='), ws0(expression)), separated_pair(ws0(identifier), char('='), ws0(expression)),
|(lhs, expr)| { |(lhs, expr)| {
Statement::Assign(Assign { Statement::Assign(Assign {
lhs: (*lhs.fragment()).into(), lhs: (*lhs.fragment()),
expr, expr,
}) })
}, },
@ -214,7 +214,7 @@ pub fn module(input: Span) -> IResult<Span, Module> {
)), )),
)), )),
|(_, name, ports, statements)| Module { |(_, name, ports, statements)| Module {
name: (*name.fragment()).into(), name: (*name.fragment()),
ports, ports,
statements, statements,
}, },