Skip to content

Commit

Permalink
Merge graph simplification changes from master
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwalker committed May 13, 2020
2 parents 3052dad + 2daf708 commit c6ce7bb
Show file tree
Hide file tree
Showing 64 changed files with 6,450 additions and 1,755 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ members = [
"util/libeir_util_parse_listing",
"util/libeir_util_dot_graph",
"util/scoped_cell",
"util/meta_table",
]
238 changes: 174 additions & 64 deletions libeir_interpreter/src/process/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::rc::Rc;
use std::collections::HashMap;
use std::any::TypeId;

use num_traits::cast::ToPrimitive;

use libeir_ir::{ FunctionIdent, Block, Value, OpKind, BinOp, ValueKind, PrimOpKind, LogicOp };
use libeir_ir::{ MapPutUpdate };
use libeir_ir::{ BinaryEntrySpecifier, Endianness };
use libeir_ir::operation::binary_construct::{BinaryConstructStart, BinaryConstructPush, BinaryConstructFinish};
use libeir_ir::constant::{ Const, ConstKind, AtomicTerm };
use libeir_intern::Ident;

Expand Down Expand Up @@ -340,85 +342,193 @@ impl CallExecutor {
OpKind::Match { branches } => {
self::r#match::match_op(self, fun, branches, block)
}
OpKind::BinaryPush { specifier } => {
let bin_term = self.make_term(fun, reads[2]);
let mut bin = match &*bin_term {
Term::Binary(bin) => (**bin).clone(),
Term::BinarySlice { buf, bit_offset, bit_length } => {
let slice = BitSlice::with_offset_length(
&**buf, *bit_offset, *bit_length);
let mut new = BitVec::new();
new.push(slice);
new
OpKind::Dyn(dyn_op) => {
let tid = dyn_op.type_id();
match () {
_ if tid == TypeId::of::<BinaryConstructStart>() => {
TermCall {
fun: self.make_term(fun, reads[0]),
args: vec![Term::Binary(Default::default()).into()],
}
}
_ => panic!(),
};
_ if tid == TypeId::of::<BinaryConstructPush>() => {
let ok_cont = reads[0];
let err_cont = reads[1];
let bin_ref = reads[2];
let value = reads[3];
let size = reads.get(4);

let bin_push = dyn_op.downcast_ref::<BinaryConstructPush>().unwrap();
let specifier = bin_push.specifier;

let bin_term = self.make_term(fun, bin_ref);
let mut bin = match &*bin_term {
Term::Binary(bin) => (**bin).clone(),
Term::BinarySlice { buf, bit_offset, bit_length } => {
let slice = BitSlice::with_offset_length(
&**buf, *bit_offset, *bit_length);
let mut new = BitVec::new();
new.push(slice);
new
}
_ => panic!(),
};

let val_term = self.make_term(fun, reads[3]);
let val_term = self.make_term(fun, reads[3]);

assert!(reads.len() == 4 || reads.len() == 5);
let size_term = reads.get(4).map(|r| self.make_term(fun, *r));
assert!(reads.len() == 4 || reads.len() == 5);
let size_term = reads.get(4).map(|r| self.make_term(fun, *r));

match specifier {
BinaryEntrySpecifier::Integer {
signed: _, unit, endianness } =>
{
let size = size_term.unwrap().as_usize().unwrap();
let bit_size = *unit as usize * size;
match specifier {
BinaryEntrySpecifier::Integer {
signed: _, unit, endianness } =>
{
let size = size_term.unwrap().as_usize().unwrap();
let bit_size = unit as usize * size;

let endian = match *endianness {
Endianness::Big => Endian::Big,
Endianness::Little => Endian::Little,
Endianness::Native => Endian::Big,
};
let endian = match endianness {
Endianness::Big => Endian::Big,
Endianness::Little => Endian::Little,
Endianness::Native => Endian::Big,
};

let val = val_term.as_integer().unwrap().clone();
let carrier = integer_to_carrier(
val, bit_size, endian);
let val = val_term.as_integer().unwrap().clone();
let carrier = integer_to_carrier(
val, bit_size, endian);

bin.push(carrier);
}
BinaryEntrySpecifier::Float {
endianness: Endianness::Big, unit } =>
{
let size = size_term.unwrap().as_usize().unwrap();
let bit_size = *unit as usize * size;

assert!(bit_size == 32 || bit_size == 64);

let num = match &*val_term {
Term::Float(flt) => flt.0,
Term::Integer(int) => {
let int_f = int.to_i64().unwrap();
int_f as f64
bin.push(carrier);
}
_ => panic!(),
};
BinaryEntrySpecifier::Float {
endianness: Endianness::Big, unit } =>
{
let size = size_term.unwrap().as_usize().unwrap();
let bit_size = unit as usize * size;

assert!(bit_size == 32 || bit_size == 64);

let num = match &*val_term {
Term::Float(flt) => flt.0,
Term::Integer(int) => {
let int_f = int.to_i64().unwrap();
int_f as f64
}
_ => panic!(),
};

match bit_size {
32 => bin.push(&num),
64 => bin.push(&num),
_ => unreachable!(),
}
}
BinaryEntrySpecifier::Bytes { unit: 1 } => {
let binary = val_term.as_binary().unwrap();

match bit_size {
32 => bin.push(&num),
64 => bin.push(&num),
_ => unreachable!(),
}
}
BinaryEntrySpecifier::Bytes { unit: 1 } => {
let binary = val_term.as_binary().unwrap();
if let Some(size_term) = size_term {
dbg!(&size_term, &binary);
assert!(size_term.as_usize().unwrap() == binary.len());
}

if let Some(size_term) = size_term {
dbg!(&size_term, &binary);
assert!(size_term.as_usize().unwrap() == binary.len());
bin.push(binary);
}
k => unimplemented!("{:?}", k),
}

bin.push(binary);
return TermCall {
fun: self.make_term(fun, ok_cont),
args: vec![Term::Binary(bin.into()).into()],
};
}
_ if tid == TypeId::of::<BinaryConstructFinish>() => {
TermCall {
fun: self.make_term(fun, reads[0]),
args: vec![self.make_term(fun, reads[1])],
}
}
_ => {
unimplemented!()
}
k => unimplemented!("{:?}", k),
}

return TermCall {
fun: self.make_term(fun, reads[0]),
args: vec![Term::Binary(bin.into()).into()],
};
}
//OpKind::BinaryPush { specifier } => {
// let bin_term = self.make_term(fun, reads[2]);
// let mut bin = match &*bin_term {
// Term::Binary(bin) => (**bin).clone(),
// Term::BinarySlice { buf, bit_offset, bit_length } => {
// let slice = BitSlice::with_offset_length(
// &**buf, *bit_offset, *bit_length);
// let mut new = BitVec::new();
// new.push(slice);
// new
// }
// _ => panic!(),
// };

// let val_term = self.make_term(fun, reads[3]);

// assert!(reads.len() == 4 || reads.len() == 5);
// let size_term = reads.get(4).map(|r| self.make_term(fun, *r));

// match specifier {
// BinaryEntrySpecifier::Integer {
// signed: _, unit, endianness } =>
// {
// let size = size_term.unwrap().as_usize().unwrap();
// let bit_size = *unit as usize * size;

// let endian = match *endianness {
// Endianness::Big => Endian::Big,
// Endianness::Little => Endian::Little,
// Endianness::Native => Endian::Big,
// };

// let val = val_term.as_integer().unwrap().clone();
// let carrier = integer_to_carrier(
// val, bit_size, endian);

// bin.push(carrier);
// }
// BinaryEntrySpecifier::Float {
// endianness: Endianness::Big, unit } =>
// {
// let size = size_term.unwrap().as_usize().unwrap();
// let bit_size = *unit as usize * size;

// assert!(bit_size == 32 || bit_size == 64);

// let num = match &*val_term {
// Term::Float(flt) => flt.0,
// Term::Integer(int) => {
// let int_f = int.to_i64().unwrap();
// int_f as f64
// }
// _ => panic!(),
// };

// match bit_size {
// 32 => bin.push(&num),
// 64 => bin.push(&num),
// _ => unreachable!(),
// }
// }
// BinaryEntrySpecifier::Bytes { unit: 1 } => {
// let binary = val_term.as_binary().unwrap();

// if let Some(size_term) = size_term {
// dbg!(&size_term, &binary);
// assert!(size_term.as_usize().unwrap() == binary.len());
// }

// bin.push(binary);
// }
// k => unimplemented!("{:?}", k),
// }

// return TermCall {
// fun: self.make_term(fun, reads[0]),
// args: vec![Term::Binary(bin.into()).into()],
// };
//}
OpKind::MapPut { action } => {
let map_term = self.make_term(fun, reads[2]);
let mut map = map_term.as_map().unwrap().clone();
Expand Down
3 changes: 3 additions & 0 deletions libeir_ir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ libeir_util_datastructures = { path = "../util/libeir_util_datastructures" }
libeir_util_parse = { path = "../util/libeir_util_parse" }
libeir_util_number = { path = "../util/libeir_util_number" }
libeir_util_dot_graph = { path = "../util/libeir_util_dot_graph" }
meta_table = { path = "../util/meta_table" }

stack_dst = { version = "0.6.0" }

string-intern = { version = "0.1.7", default-features = false }
pretty = "0.7"
Expand Down
Loading

0 comments on commit c6ce7bb

Please sign in to comment.