cargo fmt
This commit is contained in:
parent
220d827dbb
commit
c32da018ad
|
@ -8,8 +8,8 @@ pub use callable::Callable;
|
|||
pub use types::{Type, TypeStruct};
|
||||
|
||||
mod callable;
|
||||
pub mod types;
|
||||
pub mod typed_ir;
|
||||
pub mod types;
|
||||
|
||||
/// lots of code is still not width-aware, this constant keeps track of that
|
||||
const TODO_WIDTH: u32 = 1;
|
||||
|
@ -316,11 +316,7 @@ pub fn lower_module(pa_module: parser::Module) -> Result<String, CompileError> {
|
|||
parser::PortDirection::Input => rtlil::PortOption::Input(idx as i32 + 1),
|
||||
parser::PortDirection::Output => rtlil::PortOption::Output(idx as i32 + 1),
|
||||
};
|
||||
let wire = rtlil::Wire::new(
|
||||
sig.il_id.to_owned(),
|
||||
TODO_WIDTH,
|
||||
Some(dir_option),
|
||||
);
|
||||
let wire = rtlil::Wire::new(sig.il_id.to_owned(), TODO_WIDTH, Some(dir_option));
|
||||
ir_module.add_wire(wire);
|
||||
}
|
||||
for item in pa_module.items {
|
||||
|
|
|
@ -9,8 +9,7 @@ struct Element<'ty> {
|
|||
|
||||
struct Signal<'ty> {
|
||||
pub id: u32,
|
||||
pub typ: Type<'ty>
|
||||
pub typ: Type<'ty>,
|
||||
}
|
||||
|
||||
struct Expression {
|
||||
}
|
||||
struct Expression {}
|
||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -8,9 +8,8 @@ use std::fs::File;
|
|||
use std::io::prelude::*;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use structopt::StructOpt;
|
||||
use nom_greedyerror::convert_error;
|
||||
use ariadne::Source;
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(name = "example", about = "An example of StructOpt usage.")]
|
||||
|
@ -45,9 +44,14 @@ fn main() {
|
|||
let parsed = parser::parse(input);
|
||||
match parsed {
|
||||
Err(nom::Err::Error(err) | nom::Err::Failure(err)) => {
|
||||
parser::error::convert_error(input, err).eprint(Source::from(input.fragment())).unwrap();
|
||||
if opt.debug {
|
||||
println!("{err:#?}");
|
||||
}
|
||||
Err(_) => ( unreachable!() ),
|
||||
parser::error::convert_error(input, err)
|
||||
.eprint(Source::from(input.fragment()))
|
||||
.unwrap();
|
||||
}
|
||||
Err(_) => (unreachable!()),
|
||||
Ok(res) => {
|
||||
if opt.debug {
|
||||
println!("{:#?}", res);
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
pub mod error;
|
||||
mod literals;
|
||||
pub mod module;
|
||||
pub mod proc;
|
||||
mod literals;
|
||||
pub mod error;
|
||||
|
||||
use nom::{
|
||||
branch::alt,
|
||||
bytes::complete::tag,
|
||||
character::complete::{alpha1, alphanumeric1, char, multispace0, u64 as decimal},
|
||||
combinator::{map, opt, recognize},
|
||||
error::{ParseError, ErrorKind},
|
||||
error::{ErrorKind, ParseError},
|
||||
multi::{many0, separated_list0},
|
||||
sequence::{delimited, pair, preceded, separated_pair, terminated, tuple},
|
||||
};
|
||||
|
@ -22,8 +22,8 @@ pub type IErr<I> = GreedyError<I, ErrorKind>;
|
|||
// custom IResult type for VerboseError
|
||||
pub type IResult<I, O, E = IErr<I>> = nom::IResult<I, O, E>;
|
||||
|
||||
use literals::hexadecimal;
|
||||
pub use crate::parser::module::{module, Module, ModuleItem, PortDirection};
|
||||
use literals::hexadecimal;
|
||||
|
||||
fn ws0<'a, F: 'a, O, E: ParseError<Span<'a>>>(
|
||||
inner: F,
|
||||
|
@ -46,14 +46,12 @@ fn typename(input: Span) -> IResult<Span, TypeName> {
|
|||
map(
|
||||
tuple((
|
||||
identifier,
|
||||
opt(delimited(char('<'), ws0(expression), char('>')))
|
||||
opt(delimited(char('<'), ws0(expression), char('>'))),
|
||||
)),
|
||||
|(ident, _)| {
|
||||
TypeName {
|
||||
|(ident, _)| TypeName {
|
||||
name: ident,
|
||||
generics: ()
|
||||
}
|
||||
}
|
||||
generics: (),
|
||||
},
|
||||
)(input)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,36 +1,29 @@
|
|||
use std::fmt::Debug;
|
||||
use std::ops::Deref;
|
||||
|
||||
use super::{Span, IErr};
|
||||
use super::{IErr, Span};
|
||||
use ariadne::{Label, Report, ReportKind};
|
||||
use nom::error::ErrorKind;
|
||||
use nom_greedyerror::{Position, GreedyErrorKind};
|
||||
use ariadne::{Report, ReportKind, Label};
|
||||
use nom_greedyerror::{GreedyErrorKind, Position};
|
||||
|
||||
fn span_to_range(input: Span) -> std::ops::Range<usize> {
|
||||
input.position()..(input.position() + input.len())
|
||||
}
|
||||
|
||||
pub fn convert_error(
|
||||
input: Span,
|
||||
e: IErr<Span>,
|
||||
) -> Report {
|
||||
pub fn convert_error(input: Span, e: IErr<Span>) -> Report {
|
||||
let mut labels = Vec::new();
|
||||
for err in e.errors {
|
||||
let label = match err.1 {
|
||||
GreedyErrorKind::Context(ctx) => {
|
||||
Label::new(span_to_range(err.0))
|
||||
.with_message(format!("in {ctx}"))
|
||||
},
|
||||
GreedyErrorKind::Char(c) => {
|
||||
Label::new(err.0.position()..err.0.position())
|
||||
.with_message(format!("expected {c:?}"))
|
||||
},
|
||||
Label::new(span_to_range(err.0)).with_message(format!("in {ctx}"))
|
||||
}
|
||||
GreedyErrorKind::Char(c) => Label::new(err.0.position()..err.0.position())
|
||||
.with_message(format!("expected {c:?}")),
|
||||
GreedyErrorKind::Nom(_) => todo!(),
|
||||
};
|
||||
labels.push(label);
|
||||
}
|
||||
let mut rep = Report::build(ReportKind::Error, (), 0)
|
||||
.with_message("Parse Error");
|
||||
let mut rep = Report::build(ReportKind::Error, (), 0).with_message("Parse Error");
|
||||
for lbl in labels {
|
||||
rep = rep.with_label(lbl)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,8 @@ pub fn hexadecimal(input: Span) -> IResult<Span, u64> {
|
|||
))),
|
||||
),
|
||||
|out: Span| {
|
||||
u64::from_str_radix(&str::replace(out.fragment(), "_", ""), 16).expect("error parsing literal")
|
||||
u64::from_str_radix(&str::replace(out.fragment(), "_", ""), 16)
|
||||
.expect("error parsing literal")
|
||||
},
|
||||
)(input)
|
||||
}
|
||||
|
|
|
@ -5,13 +5,13 @@ use nom::{
|
|||
combinator::{consumed, map},
|
||||
error::context,
|
||||
multi::{many0, separated_list0},
|
||||
sequence::{delimited, terminated, tuple, preceded},
|
||||
sequence::{delimited, preceded, terminated, tuple},
|
||||
};
|
||||
|
||||
use crate::parser::{
|
||||
assign_statement, declaration, identifier,
|
||||
proc::{proc_block, ProcBlock},
|
||||
ws0, Assign, IResult, NetDecl, Span, typename
|
||||
typename, ws0, Assign, IResult, NetDecl, Span,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -41,16 +41,11 @@ pub enum ModuleItem<'a> {
|
|||
}
|
||||
|
||||
fn port_decl(i: Span) -> IResult<Span, PortDecl> {
|
||||
map(
|
||||
consumed(
|
||||
declaration,
|
||||
),
|
||||
|(pos, net)| PortDecl {
|
||||
map(consumed(declaration), |(pos, net)| PortDecl {
|
||||
pos,
|
||||
direction: PortDirection::Input,
|
||||
net,
|
||||
},
|
||||
)(i)
|
||||
})(i)
|
||||
}
|
||||
|
||||
fn inputs_list(input: Span) -> IResult<Span, Vec<PortDecl>> {
|
||||
|
@ -85,7 +80,11 @@ pub fn module(input: Span) -> IResult<Span, Module> {
|
|||
ws0(identifier),
|
||||
ws0(delimited(char('('), ws0(inputs_list), char(')'))),
|
||||
ws0(preceded(tag("->"), ws0(typename))),
|
||||
ws0(delimited(char('{'), ws0(many0(ws0(module_item))), char('}'))),
|
||||
ws0(delimited(
|
||||
char('{'),
|
||||
ws0(many0(ws0(module_item))),
|
||||
char('}'),
|
||||
)),
|
||||
)),
|
||||
|(_, name, inputs, ret, items)| Module {
|
||||
name,
|
||||
|
|
Loading…
Reference in New Issue