Skip to content

Commit

Permalink
b
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanWoollett-Light committed Dec 23, 2023
1 parent cffeb47 commit 5fba572
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 46 deletions.
4 changes: 4 additions & 0 deletions hello-world/build/assembly.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ svc #0
mov x8, #93
mov x0, #0
svc #0
.data
a: .byte 72,101,108,108,111,44,32,87,111,114,108,100,33,10
b: .byte 1
g: .byte 0
3 changes: 3 additions & 0 deletions hello-world/build/optimized.abc
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
a : u8 u8 u8 u8 u8 u8 u8 u8 u8 u8 u8 u8 u8 u8 := "Hello, World!\n"
b : u8 := 1
mov x8 64
mov x0 1
mov x1 &a
mov x2 14
svc 0
g : u8 := 0
mov x8 93
mov x0 0
svc 0
Expand Down
2 changes: 2 additions & 0 deletions hello-world/lock.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
file,hash
included,BA31DDA88BF964E1E0BECCE57A3D68274597370BCDA19EA0A8DEF9859875C8AD
inlined,B85A04079A92BF865231D5F7D2DFA174927B481578722B25FA07D26B4CDD978F
optimized,718CCA90149231FB51B65B49D1C51D6CA1B2825968BD049B6B03AB26F212D825
assembly,B5FB3A50526C034561CBBD463D99F097050A83F2C73F670D3527E96045BB79D5
4 changes: 2 additions & 2 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ pub unsafe fn instruction_from_node(
let parent_opt = loop {
#[cfg(debug_assertions)]
{
assert!(checker < 9);
assert!(checker < 100);
checker += 1;
}
preceding = match preceding {
Expand All @@ -643,7 +643,7 @@ pub unsafe fn instruction_from_node(
};
};

println!("parent_opt: {parent_opt:?}");
// println!("parent_opt: {parent_opt:?}");
parent_opt
};
// If there is no parent the write stack should be empty.
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ fn main() {
);
}

// panic!("does not hit this");

// Construct assembly
let assembly = assembly_from_node(optimized);
if let Some(path) = path_opt {
Expand Down
93 changes: 49 additions & 44 deletions src/middle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ pub unsafe fn build_optimized_tree(
while let Some(mut current) = next_state_node {
#[cfg(debug_assertions)]
{
assert!(checker < 100);
// println!("current: {:?}",current.as_ref());
// println!("current: {:?}", current.as_ref().statement.as_ref());
// assert!(checker < 8);
checker += 1;
}

Expand All @@ -134,6 +136,8 @@ pub unsafe fn build_optimized_tree(
.and(current.as_ref().next.1)
.is_none());

// debug_assert!(checker < 8);

// println!("------------checking optimization input------------");
// let mut check_stack = vec![first_state_node.unwrap()];
// let mut check_counter = 0;
Expand All @@ -157,7 +161,12 @@ pub unsafe fn build_optimized_tree(
// println!("-----------------------------------------------");

let slice = current.as_ref().statement.as_ref().statement.arg.as_slice();
match current.as_ref().statement.as_ref().statement.op {
// debug_assert!(checker < 8);
println!("slice: {slice:?}");
let op = &current.as_ref().statement.as_ref().statement.op;
println!("op: {op:?}");
// debug_assert!(checker < 8);
match op {
Op::Intrinsic(Intrinsic::Assign) => match slice {
[Value::Variable(variable), Value::Literal(Literal::Integer(_))] => {
let variable_state = current
Expand Down Expand Up @@ -538,70 +547,66 @@ pub unsafe fn build_optimized_tree(
else {
todo!()
};
match type_value {
println!("type_value: {type_value:?}");
// debug_assert!(checker < 8);

let rhs = &mut current.as_mut().statement.as_mut().statement.arg[1];
*rhs = match type_value {
TypeValue::Integer(TypeValueInteger::U64(range))
if let Some(integer) = range.value() =>
{
current.as_mut().statement.as_mut().statement.arg[1] =
Value::Literal(Literal::Integer(integer as i128));
Value::Literal(Literal::Integer(integer as i128))
}
TypeValue::Integer(TypeValueInteger::U32(range))
if let Some(integer) = range.value() =>
{
current.as_mut().statement.as_mut().statement.arg[1] =
Value::Literal(Literal::Integer(integer as i128));
Value::Literal(Literal::Integer(integer as i128))
}
TypeValue::Integer(TypeValueInteger::U16(range))
if let Some(integer) = range.value() =>
{
current.as_mut().statement.as_mut().statement.arg[1] =
Value::Literal(Literal::Integer(integer as i128));
Value::Literal(Literal::Integer(integer as i128))
}
TypeValue::Integer(TypeValueInteger::U8(range))
if let Some(integer) = range.value() =>
{
current.as_mut().statement.as_mut().statement.arg[1] =
Value::Literal(Literal::Integer(integer as i128));
Value::Literal(Literal::Integer(integer as i128))
}
TypeValue::Integer(TypeValueInteger::I64(range))
if let Some(integer) = range.value() =>
{
current.as_mut().statement.as_mut().statement.arg[1] =
Value::Literal(Literal::Integer(integer as i128));
Value::Literal(Literal::Integer(integer as i128))
}
TypeValue::Integer(TypeValueInteger::I32(range))
if let Some(integer) = range.value() =>
{
current.as_mut().statement.as_mut().statement.arg[1] =
Value::Literal(Literal::Integer(integer as i128));
Value::Literal(Literal::Integer(integer as i128))
}
TypeValue::Integer(TypeValueInteger::I16(range))
if let Some(integer) = range.value() =>
{
current.as_mut().statement.as_mut().statement.arg[1] =
Value::Literal(Literal::Integer(integer as i128));
Value::Literal(Literal::Integer(integer as i128))
}
TypeValue::Reference(VariableAlias { identifier, index }) => {
current.as_mut().statement.as_mut().statement.arg[1] =
Value::Variable(Variable {
addressing: Addressing::Reference,
identifier: identifier.clone(),
index: index.clone(),
});
}
x @ _ => todo!("{x:?}"),
}
TypeValue::Reference(alias @ VariableAlias { identifier, index }) => {
// I expect it will be the case in the future that the use of 1 variable means
// the use of multiple other variables, this design supports this with slight
// alteration.
let mut read_stack = vec![alias.clone()];
while let Some(read_current) = read_stack.pop() {
if let Some(link) = read_links.get(&read_current) {
read_stack.push(link.clone());
}
read.insert(read_current);
}

// I expect it will be the case in the future that the use of 1 variable means
// the use of multiple other variables, this design supports this with slight
// alteration.
let mut read_stack = vec![VariableAlias::from(variable.clone())];
while let Some(read_current) = read_stack.pop() {
if let Some(link) = read_links.get(&read_current) {
read_stack.push(link.clone());
Value::Variable(Variable {
addressing: Addressing::Reference,
identifier: identifier.clone(),
index: index.clone(),
})
}
read.insert(read_current);
}
x @ _ => todo!("{x:?}"),
};

// Set next node.
debug_assert!(current
Expand Down Expand Up @@ -726,18 +731,18 @@ pub unsafe fn finish_optimized_tree(

// Applies typical optimizations. E.g. removing unused variables, unreachable code, etc.
pub unsafe fn optimize(graph: NonNull<NewStateNode>) -> NonNull<NewNode> {
// println!("graph {:?}", graph.as_ref());
// println!("graph {:?}", graph.as_ref().statement.as_ref());
// panic!("hit this");

// Construct new optimized abstract syntax tree.
// TODO This doesn't dealloc anything in `graph` which may be very very big. Do this deallocation.
// TODO This doesn't dealloc anything in `graph` which may be very very big. Do this deallocation.
let (new_nodes, read) = build_optimized_tree(graph);

println!("read {:?}", read);
panic!("hit this");

let x = finish_optimized_tree(new_nodes.unwrap(), read).unwrap();

panic!("hit this");
// println!("read {:?}", read);
// panic!("does not hit this");

x
finish_optimized_tree(new_nodes.unwrap(), read).unwrap()
}

unsafe fn new_passback_end(mut node: NonNull<NewStateNode>, end: GraphNodeEnd) {
Expand Down

0 comments on commit 5fba572

Please sign in to comment.