forked from libre-chip/fayalite
simulator WIP: use petgraph for topological sort over assignments
This commit is contained in:
parent
3106a6fff6
commit
a6e40839ac
5 changed files with 887 additions and 145 deletions
|
@ -25,6 +25,7 @@ jobslot.workspace = true
|
|||
num-bigint.workspace = true
|
||||
num-traits.workspace = true
|
||||
os_pipe.workspace = true
|
||||
petgraph.workspace = true
|
||||
serde_json.workspace = true
|
||||
serde.workspace = true
|
||||
tempfile.workspace = true
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -362,6 +362,12 @@ pub(crate) struct Insns<BK: InsnsBuildingKind> {
|
|||
state_layout: StateLayout<BK>,
|
||||
}
|
||||
|
||||
impl<BK: InsnsBuildingKind> Insns<BK> {
|
||||
pub(crate) fn state_layout(&self) -> &StateLayout<BK> {
|
||||
&self.state_layout
|
||||
}
|
||||
}
|
||||
|
||||
struct InsnsDebug<'a> {
|
||||
insns: &'a [Insn],
|
||||
insn_source_locations: &'a [SourceLocation],
|
||||
|
@ -564,13 +570,13 @@ macro_rules! make_state_part_kinds {
|
|||
impl Copy for StateLayout<InsnsBuildingDone> {}
|
||||
|
||||
impl<BK: InsnsBuildingKind> StateLayout<BK> {
|
||||
pub(crate) fn len(self) -> StateLen {
|
||||
pub(crate) fn len(&self) -> StateLen {
|
||||
StateLen {
|
||||
ty: self.ty.len(),
|
||||
$($state_field: self.$state_field.len(),)*
|
||||
}
|
||||
}
|
||||
pub(crate) fn is_empty(self) -> bool {
|
||||
pub(crate) fn is_empty(&self) -> bool {
|
||||
self.ty.is_empty() $(&& self.$state_field.is_empty())*
|
||||
}
|
||||
pub(crate) fn empty() -> Self {
|
||||
|
@ -652,12 +658,12 @@ macro_rules! make_state_part_kinds {
|
|||
impl Copy for TypeLayout<InsnsBuildingDone> {}
|
||||
|
||||
impl<BK: InsnsBuildingKind> TypeLayout<BK> {
|
||||
pub(crate) fn len(self) -> TypeLen {
|
||||
pub(crate) fn len(&self) -> TypeLen {
|
||||
TypeLen {
|
||||
$($type_field: self.$type_field.len(),)*
|
||||
}
|
||||
}
|
||||
pub(crate) fn is_empty(self) -> bool {
|
||||
pub(crate) fn is_empty(&self) -> bool {
|
||||
$(self.$type_field.is_empty())&&+
|
||||
}
|
||||
pub(crate) fn empty() -> Self {
|
||||
|
@ -762,6 +768,14 @@ macro_rules! make_state_part_kinds {
|
|||
}
|
||||
|
||||
impl State {
|
||||
pub(crate) fn new(insns: Interned<Insns<InsnsBuildingDone>>) -> Self {
|
||||
Self {
|
||||
insns,
|
||||
pc: 0,
|
||||
$($state_field: StatePart::new(insns.state_layout.$state_field.len()),)*
|
||||
$($type_field: StatePart::new(insns.state_layout.ty.$type_field.len()),)*
|
||||
}
|
||||
}
|
||||
pub(crate) fn borrow(&mut self) -> BorrowedState<'_> {
|
||||
BorrowedState {
|
||||
orig_insns: self.insns,
|
||||
|
@ -1494,6 +1508,13 @@ impl<K: StatePartKind, V: fmt::Debug> fmt::Debug for StatePartIndexMap<K, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<K: StatePartKind, V> Extend<(StatePartIndex<K>, V)> for StatePartIndexMap<K, V> {
|
||||
fn extend<T: IntoIterator<Item = (StatePartIndex<K>, V)>>(&mut self, iter: T) {
|
||||
self.map
|
||||
.extend(iter.into_iter().map(|(k, v)| (k.as_usize(), v)));
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: StatePartKind, V> StatePartIndexMap<K, V> {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self {
|
||||
|
@ -1834,6 +1855,17 @@ impl_insns! {
|
|||
}
|
||||
next!();
|
||||
}
|
||||
CastBigToArrayIndex {
|
||||
#[kind = Output]
|
||||
dest: StatePartIndex<StatePartKindSmallSlots>,
|
||||
#[kind = Input]
|
||||
src: StatePartIndex<StatePartKindBigSlots>,
|
||||
} => {
|
||||
let src = &state.big_slots[src];
|
||||
let value = src.try_into().unwrap_or(SmallUInt::MAX);
|
||||
state.small_slots[dest] = value;
|
||||
next!();
|
||||
}
|
||||
CastToSInt {
|
||||
#[kind = Output]
|
||||
dest: StatePartIndex<StatePartKindBigSlots>,
|
||||
|
@ -2055,6 +2087,20 @@ impl_insns! {
|
|||
state.big_slots[dest] = value;
|
||||
next!();
|
||||
}
|
||||
SliceInt {
|
||||
#[kind = Output]
|
||||
dest: StatePartIndex<StatePartKindBigSlots>,
|
||||
#[kind = Input]
|
||||
src: StatePartIndex<StatePartKindBigSlots>,
|
||||
#[kind = Immediate]
|
||||
start: usize,
|
||||
#[kind = Immediate]
|
||||
len: usize,
|
||||
} => {
|
||||
let value = &state.big_slots[src] >> start;
|
||||
state.big_slots[dest] = value & &*bigint_mask(len);
|
||||
next!();
|
||||
}
|
||||
CmpEq {
|
||||
#[kind = Output]
|
||||
dest: StatePartIndex<StatePartKindBigSlots>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue