-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
198 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
public module Top { | ||
incoming clock : Clock; | ||
incoming in : Word[8]; | ||
outgoing out : Word[8]; | ||
outgoing out : Word[9]; | ||
|
||
reg r : Word[8] on clock; | ||
r <= r->add(in); | ||
out := r; | ||
r <= r->add(1); | ||
out := cat(r, 1w1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use crate::common::*; | ||
use super::*; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct ExprCat(pub Vec<Expr>); | ||
|
||
impl IsExpr for ExprCat { | ||
fn subexprs(&self) -> Vec<Expr> { | ||
self.0.clone() | ||
} | ||
|
||
fn typeinfer(&self, ctx: Context<Path, Arc<Type>>) -> Result<Expr, TypeError> { | ||
let mut args = vec![]; | ||
let mut w = 0u64; | ||
for e in &self.0 { | ||
let arg: Expr = e.typeinfer(ctx.clone())?; | ||
let arg_typ: Arc<Type> = arg.type_of().unwrap(); | ||
args.push(arg); | ||
if let Type::Word(m) = arg_typ.as_ref() { | ||
w += m; | ||
} else { | ||
return Err(TypeError::Unknown); | ||
} | ||
} | ||
let typ: Arc<Type> = Type::Word(w).into(); | ||
Ok(ExprNode::Cat(ExprCat(args)).with_type(typ)) | ||
} | ||
|
||
/* | ||
let typed_args: Vec<Expr> = self.0.iter().map(|arg| arg.typeinfer(ctx.clone()).unwrap()).collect(); | ||
let element_type = typed_args[0].type_of().unwrap(); | ||
for typed_arg in &typed_args { | ||
if typed_arg.type_of().unwrap() != element_type { | ||
return Err(TypeError::Unknown); | ||
} | ||
} | ||
let typ: Arc<Type> = Type::Vec(element_type, self.0.len()).into(); | ||
Ok(ExprNode::Vec(ExprVec(typed_args)).with_type(typ)) | ||
*/ | ||
|
||
fn eval(&self, ctx: Context<Path, Value>, typ: Arc<Type>) -> Value { | ||
let mut cat_width: u64 = 0; | ||
let mut cat_val: u64 = 0; | ||
let values = self.0.iter().map(|e| e.eval(ctx.clone())); | ||
dbg!(&typ); | ||
dbg!(&values); | ||
|
||
for v in values.rev() { | ||
if let Value::Word(width, val) = v { | ||
cat_val |= val << cat_width; | ||
cat_width += width; | ||
} else { | ||
return Value::X(typ.clone()); | ||
} | ||
} | ||
|
||
Value::Word(cat_width, cat_val) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use crate::common::*; | ||
use super::*; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct ExprIdx(pub Expr, pub StaticIndex); | ||
|
||
impl ExprIdx { | ||
fn subject(&self) -> Expr { | ||
self.0.clone() | ||
} | ||
|
||
fn index(&self) -> StaticIndex { | ||
self.1 | ||
} | ||
} | ||
|
||
impl IsExpr for ExprIdx { | ||
fn subexprs(&self) -> Vec<Expr> { | ||
vec![self.0.clone()] | ||
} | ||
|
||
fn typeinfer(&self, ctx: Context<Path, Arc<Type>>) -> Result<Expr, TypeError> { | ||
let typed_subject: Expr = self.subject().typeinfer(ctx.clone())?; | ||
let subject_type: Arc<Type> = typed_subject.type_of().unwrap(); | ||
if let Type::Word(n) = subject_type.as_ref() { | ||
if self.index() < *n { | ||
let typ: Arc<Type> = Type::Word(1).into(); | ||
Ok(ExprNode::Idx(ExprIdx(typed_subject, self.index())).with_type(typ)) | ||
} else { | ||
Err(TypeError::Unknown) | ||
} | ||
} else { | ||
Err(TypeError::Unknown) | ||
} | ||
} | ||
|
||
fn eval(&self, ctx: Context<Path, Value>, typ: Arc<Type>) -> Value { | ||
let subject_value = self.subject().eval(ctx); | ||
if let Value::Word(_width, v) = subject_value { | ||
// v_index_masked should be 0b00..000100..00 | ||
// eg, 1 in position self.index(), or else all zeroes | ||
let v_index_masked = v & (1 << self.index()); | ||
// v_new should be 0b000.....01 | ||
// eg, 1 in index 0, or else all zeroes | ||
let v_new = v_index_masked >> self.index(); | ||
assert!(v_new == 0 || v_new == 1); | ||
Value::Word(1, v_new) | ||
} else { | ||
Value::X(typ.clone()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.