Compare commits
2 Commits
main
...
mebi-patch
Author | SHA1 | Date | |
---|---|---|---|
|
cb6e6ece7d | ||
|
8ccc3c0503 |
22
src/main.rs
22
src/main.rs
|
@ -276,6 +276,13 @@ struct OperationTwo {
|
||||||
rhs: Box<AstNode>,
|
rhs: Box<AstNode>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This might be a terrible idea
|
||||||
|
#[derive(PartialEq, Debug, Clone)]
|
||||||
|
enum SizeOrLabelName {
|
||||||
|
Size(u32),
|
||||||
|
Label(String),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, Clone)]
|
#[derive(PartialEq, Debug, Clone)]
|
||||||
enum AstNode {
|
enum AstNode {
|
||||||
OperationZero(OperationZero) ,
|
OperationZero(OperationZero) ,
|
||||||
|
@ -317,7 +324,7 @@ enum AstNode {
|
||||||
DataStrZero(String),
|
DataStrZero(String),
|
||||||
DataFill {
|
DataFill {
|
||||||
value: u8,
|
value: u8,
|
||||||
size: u32,
|
size: SizeOrLabelName,
|
||||||
},
|
},
|
||||||
|
|
||||||
IncludedBinary(Vec<u8>),
|
IncludedBinary(Vec<u8>),
|
||||||
|
@ -412,6 +419,13 @@ fn main() {
|
||||||
current_address = origin_address;
|
current_address = origin_address;
|
||||||
instructions.push(vec![0; difference].into());
|
instructions.push(vec![0; difference].into());
|
||||||
} else if let AstNode::DataFill {value, size} = node {
|
} else if let AstNode::DataFill {value, size} = node {
|
||||||
|
let size = match size {
|
||||||
|
SizeOrLabelName::Size(size) => size,
|
||||||
|
SizeOrLabelName::Label(name) => {
|
||||||
|
let address_table = LABEL_ADDRESSES.lock().unwrap();
|
||||||
|
address_table.get(&name).expect(&format!("Label not found: {}", name)).0
|
||||||
|
},
|
||||||
|
};
|
||||||
current_address += size;
|
current_address += size;
|
||||||
instructions.push(vec![value; size as usize].into());
|
instructions.push(vec![value; size as usize].into());
|
||||||
} else if let AstNode::IncludedBinary(binary_vec) = node {
|
} else if let AstNode::IncludedBinary(binary_vec) = node {
|
||||||
|
@ -430,6 +444,7 @@ fn main() {
|
||||||
println!("Performing label backpatching...");
|
println!("Performing label backpatching...");
|
||||||
let table = LABEL_TARGETS.lock().unwrap();
|
let table = LABEL_TARGETS.lock().unwrap();
|
||||||
let address_table = LABEL_ADDRESSES.lock().unwrap();
|
let address_table = LABEL_ADDRESSES.lock().unwrap();
|
||||||
|
dbg!(&address_table);
|
||||||
|
|
||||||
let address_file = format_address_table(&address_table);
|
let address_file = format_address_table(&address_table);
|
||||||
println!("{}", address_file);
|
println!("{}", address_file);
|
||||||
|
@ -691,8 +706,11 @@ fn parse_data(pair: pest::iterators::Pair<Rule>) -> AstNode {
|
||||||
let size = {
|
let size = {
|
||||||
let ast = parse_operand(pair.into_inner().nth(1).unwrap(), false);
|
let ast = parse_operand(pair.into_inner().nth(1).unwrap(), false);
|
||||||
if let AstNode::Immediate32(word) = ast {
|
if let AstNode::Immediate32(word) = ast {
|
||||||
word
|
SizeOrLabelName::Size(word)
|
||||||
|
} else if let AstNode::LabelOperand {name, ..} = ast {
|
||||||
|
SizeOrLabelName::Label(name)
|
||||||
} else {
|
} else {
|
||||||
|
dbg!(ast);
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user