Compare commits
No commits in common. "b848d5d3ea0bffc8556c167f4a42a74d95abeefa" and "da5258a11a6da767a6c8b1b9af8ef3849ac415ff" have entirely different histories.
b848d5d3ea
...
da5258a11a
|
@ -66,52 +66,17 @@ fn lower_expression(
|
|||
Ok(rtlil::SigSpec::Wire(expr_wire_name))
|
||||
}
|
||||
ExprKind::Literal(lit) => Ok(rtlil::SigSpec::Const(
|
||||
ctx.types
|
||||
.elab_as_u32(lit)
|
||||
.expect("const does not fit in 32 bits") as i64,
|
||||
todo!(),
|
||||
ctx.types.get_width(expr.typ).expect("signal has no size"),
|
||||
)),
|
||||
ExprKind::Match(match_) => {
|
||||
let cases = match_
|
||||
.arms
|
||||
.iter()
|
||||
.map(|(pat, val)| {
|
||||
Ok((
|
||||
lower_expression(ctx, module, pat)?,
|
||||
rtlil::CaseRule {
|
||||
assign: vec![(
|
||||
rtlil::SigSpec::Wire(expr_wire_name.clone()),
|
||||
lower_expression(ctx, module, val)?,
|
||||
)],
|
||||
switches: vec![],
|
||||
},
|
||||
))
|
||||
})
|
||||
.collect::<Result<Vec<_>, CompileError>>()
|
||||
.unwrap();
|
||||
let root_switch = rtlil::SwitchRule {
|
||||
signal: lower_expression(ctx, module, &match_.expr)?,
|
||||
cases,
|
||||
};
|
||||
let root_case = rtlil::CaseRule {
|
||||
assign: vec![],
|
||||
switches: vec![root_switch],
|
||||
};
|
||||
let proc = rtlil::Process {
|
||||
id: module.make_genid("match"),
|
||||
root_case,
|
||||
sync_rules: vec![],
|
||||
};
|
||||
module.add_process(proc);
|
||||
Ok(rtlil::SigSpec::Wire(expr_wire_name))
|
||||
}
|
||||
ExprKind::Match(_) => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn lower_comb(
|
||||
ctx: &mut Context,
|
||||
module: &mut rtlil::Module,
|
||||
block: &typed_ir::Block,
|
||||
block: typed_ir::Block,
|
||||
) -> Result<(), CompileError> {
|
||||
for (num, sig) in block.signals.iter().enumerate() {
|
||||
let sig_id = format!("\\$sig_{}", sig.id.0);
|
||||
|
@ -136,7 +101,7 @@ fn lower_comb(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn lower_block(context: &mut Context, block: &typed_ir::Block) -> Result<String, CompileError> {
|
||||
pub fn lower_block(context: &mut Context, block: typed_ir::Block) -> Result<String, CompileError> {
|
||||
let mut writer = rtlil::ILWriter::new();
|
||||
let mut ir_module = rtlil::Module::new(make_pubid("test"));
|
||||
|
||||
|
|
|
@ -150,16 +150,6 @@ impl TypingContext {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn elab_as_u32(&self, data: &ElabData) -> Option<u32> {
|
||||
match &data.value {
|
||||
ElabValue::Infer => None,
|
||||
ElabValue::Concrete(val) => match val {
|
||||
ElabValueData::U32(val) => Some(*val),
|
||||
ElabValueData::Bytes(_val) => None,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_logic_size(&self, width: u32) -> Type {
|
||||
let widthnum = self.make_elabnum_u32(width);
|
||||
self.parameterize(self.primitives.logic, &[GenericArg::Elab(widthnum)])
|
||||
|
|
|
@ -41,7 +41,7 @@ fn main() {
|
|||
.expect("error reading file");
|
||||
let input: &str = input.as_str();
|
||||
let input = parser::Span::new(input);
|
||||
let lexed = parser::tokens::lex(input).expect("failed to lex");
|
||||
let lexed = parser::tokens::lex(input).unwrap();
|
||||
let tokens = parser::tokens::TokenSpan::new(&lexed.1);
|
||||
let parsed = parser::parse(tokens);
|
||||
match parsed {
|
||||
|
@ -61,7 +61,6 @@ fn main() {
|
|||
let mut frontendcontext = crate::frontend::Context::new();
|
||||
let typed = frontendcontext.type_module(res.1);
|
||||
if let Ok(module) = typed {
|
||||
let mut typed_modules = vec![];
|
||||
for block in module.blocks {
|
||||
if opt.debug {
|
||||
let mut pretty_block = String::new();
|
||||
|
@ -78,10 +77,9 @@ fn main() {
|
|||
.unwrap();
|
||||
println!("{}", &pretty_block);
|
||||
}
|
||||
typed_modules.push(typed_inferred);
|
||||
}
|
||||
let typed_inferred = typed_modules.first().unwrap();
|
||||
// TODO: be able to determine modules that are fully parameterized
|
||||
/*
|
||||
let lowered = frontend::lowering::lower_block(&mut frontendcontext, typed_inferred);
|
||||
match lowered {
|
||||
Ok(res) => {
|
||||
|
@ -93,6 +91,7 @@ fn main() {
|
|||
}
|
||||
Err(err) => eprintln!("{:#?}", err),
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
eprintln!("{:#?}", typed);
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ impl InputPos for Span<'_> {
|
|||
}
|
||||
|
||||
fn tokspan_to_range(input: TokenSpan) -> std::ops::Range<usize> {
|
||||
let first = input.first().expect("eof in token").span().position();
|
||||
let first = input.first().unwrap().span().position();
|
||||
let last_span = input.last().unwrap().span();
|
||||
let last = last_span.position() + last_span.len();
|
||||
first..last
|
||||
|
|
|
@ -7,12 +7,11 @@ use super::{
|
|||
};
|
||||
use nom::{
|
||||
branch::alt,
|
||||
bytes::complete::{is_not, tag},
|
||||
character::complete::{anychar, digit1, line_ending},
|
||||
bytes::complete::tag,
|
||||
character::complete::{anychar, digit1},
|
||||
combinator::{consumed, map, recognize},
|
||||
error::ParseError,
|
||||
multi::many0,
|
||||
sequence::tuple,
|
||||
InputTake,
|
||||
};
|
||||
use std::fmt;
|
||||
|
@ -86,11 +85,8 @@ pub enum TokenKind {
|
|||
State,
|
||||
Proc,
|
||||
Comb,
|
||||
// whitespace
|
||||
Comment,
|
||||
// Error
|
||||
Error,
|
||||
Eof,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
|
@ -151,11 +147,6 @@ pub fn token<'a>(kind: TokenKind) -> impl FnMut(TokenSpan<'a>) -> IResult<TokenS
|
|||
nom::error::ErrorKind::Eof,
|
||||
)));
|
||||
};
|
||||
// TODO: HACKS HACKS HACKS EWW
|
||||
if next.kind == TokenKind::Comment {
|
||||
let (_, tail) = input.take_split(1);
|
||||
return token(kind)(tail);
|
||||
}
|
||||
if next.kind == kind {
|
||||
let rest = TokenSpan::with_pos(&input.rest[1..], input.pos + 1);
|
||||
Ok((rest, next))
|
||||
|
@ -168,7 +159,6 @@ pub fn token<'a>(kind: TokenKind) -> impl FnMut(TokenSpan<'a>) -> IResult<TokenS
|
|||
pub fn lex(input: Span) -> IResult<Span, Vec<Token>> {
|
||||
many0(ws0(alt((
|
||||
lex_keywords,
|
||||
lex_trivials,
|
||||
lex_literals,
|
||||
lex_braces,
|
||||
lex_punctuation,
|
||||
|
@ -237,13 +227,3 @@ fn lex_keywords(input: Span) -> IResult<Span, Token> {
|
|||
|(span, kind)| Token::new(span, kind),
|
||||
)(input)
|
||||
}
|
||||
|
||||
fn lex_trivials(input: Span) -> IResult<Span, Token> {
|
||||
map(
|
||||
consumed(alt((map(
|
||||
tuple((tag("//"), is_not("\r\n"), line_ending)),
|
||||
|_| TokenKind::Comment,
|
||||
),))),
|
||||
|(span, kind)| Token::new(span, kind),
|
||||
)(input)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue