purged .unwrap()
This commit is contained in:
+69
-32
@@ -22,13 +22,17 @@ fn build_instruction(node: Node) -> Result<Instruction, AssembleError> {
|
|||||||
match opcode {
|
match opcode {
|
||||||
Opcode::Nop => Ok(Instruction::Nop),
|
Opcode::Nop => Ok(Instruction::Nop),
|
||||||
Opcode::Mov => {
|
Opcode::Mov => {
|
||||||
let src = expect_token!(args.first().unwrap(), Register)?;
|
let src =
|
||||||
let dest = expect_token!(args.get(1).unwrap(), Register)?;
|
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
||||||
|
let dest =
|
||||||
|
expect_token!(args.get(1).expect("The spanish Inquisition"), Register)?;
|
||||||
Ok(Instruction::Mov(args!(R, sr1: src, dr: dest)))
|
Ok(Instruction::Mov(args!(R, sr1: src, dr: dest)))
|
||||||
}
|
}
|
||||||
Opcode::Movs => {
|
Opcode::Movs => {
|
||||||
let src = expect_token!(args.first().unwrap(), Register)?;
|
let src =
|
||||||
let dest = expect_token!(args.get(1).unwrap(), Register)?;
|
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
||||||
|
let dest =
|
||||||
|
expect_token!(args.get(1).expect("The spanish Inquisition"), Register)?;
|
||||||
Ok(Instruction::MovSigned(args!(R, sr1: src, dr: dest)))
|
Ok(Instruction::MovSigned(args!(R, sr1: src, dr: dest)))
|
||||||
}
|
}
|
||||||
Opcode::Ldb
|
Opcode::Ldb
|
||||||
@@ -39,9 +43,12 @@ fn build_instruction(node: Node) -> Result<Instruction, AssembleError> {
|
|||||||
| Opcode::Stb
|
| Opcode::Stb
|
||||||
| Opcode::Stw
|
| Opcode::Stw
|
||||||
| Opcode::Sth => {
|
| Opcode::Sth => {
|
||||||
let base = expect_token!(args.first().unwrap(), Register)?;
|
let base =
|
||||||
let dest = expect_token!(args.get(1).unwrap(), Register)?;
|
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
||||||
let offset = expect_token!(args.get(2).unwrap(), Immediate)?;
|
let dest =
|
||||||
|
expect_token!(args.get(1).expect("The spanish Inquisition"), Register)?;
|
||||||
|
let offset =
|
||||||
|
expect_token!(args.get(2).expect("The spanish Inquisition"), Immediate)?;
|
||||||
let args = args!(I, immediate: offset as u16, r1: base, r2: dest);
|
let args = args!(I, immediate: offset as u16, r1: base, r2: dest);
|
||||||
|
|
||||||
match opcode {
|
match opcode {
|
||||||
@@ -57,15 +64,20 @@ fn build_instruction(node: Node) -> Result<Instruction, AssembleError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Opcode::Lli => {
|
Opcode::Lli => {
|
||||||
let value = expect_token!(args.first().unwrap(), Immediate)?;
|
let value =
|
||||||
let dest = expect_token!(args.get(1).unwrap(), Register)?;
|
expect_token!(args.first().expect("The spanish Inquisition"), Immediate)?;
|
||||||
|
let dest =
|
||||||
|
expect_token!(args.get(1).expect("The spanish Inquisition"), Register)?;
|
||||||
let args = args!(I, immediate: value as u16, r1: dest);
|
let args = args!(I, immediate: value as u16, r1: dest);
|
||||||
|
|
||||||
Ok(Instruction::LoadLowerImmediate(args))
|
Ok(Instruction::LoadLowerImmediate(args))
|
||||||
}
|
}
|
||||||
Opcode::Lui => {
|
Opcode::Lui => {
|
||||||
let value = expect_token!(args.first().unwrap(), Immediate)? >> 16;
|
let value =
|
||||||
let dest = expect_token!(args.get(1).unwrap(), Register)?;
|
expect_token!(args.first().expect("The spanish Inquisition"), Immediate)?
|
||||||
|
>> 16;
|
||||||
|
let dest =
|
||||||
|
expect_token!(args.get(1).expect("The spanish Inquisition"), Register)?;
|
||||||
let args = args!(I, immediate: value as u16, r1: dest);
|
let args = args!(I, immediate: value as u16, r1: dest);
|
||||||
|
|
||||||
Ok(Instruction::LoadUpperImmediate(args))
|
Ok(Instruction::LoadUpperImmediate(args))
|
||||||
@@ -77,8 +89,10 @@ fn build_instruction(node: Node) -> Result<Instruction, AssembleError> {
|
|||||||
| Opcode::Jge
|
| Opcode::Jge
|
||||||
| Opcode::Jlt
|
| Opcode::Jlt
|
||||||
| Opcode::Jle => {
|
| Opcode::Jle => {
|
||||||
let address = expect_token!(args.first().unwrap(), Immediate)?;
|
let address =
|
||||||
let offset = expect_token!(args.get(1).unwrap(), Register)?;
|
expect_token!(args.first().expect("The spanish Inquisition"), Immediate)?;
|
||||||
|
let offset =
|
||||||
|
expect_token!(args.get(1).expect("The spanish Inquisition"), Register)?;
|
||||||
let args = args!(I, immediate: address as u16, r1: offset);
|
let args = args!(I, immediate: address as u16, r1: offset);
|
||||||
|
|
||||||
match opcode {
|
match opcode {
|
||||||
@@ -93,26 +107,36 @@ fn build_instruction(node: Node) -> Result<Instruction, AssembleError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Opcode::Cmp => {
|
Opcode::Cmp => {
|
||||||
let left = expect_token!(args.first().unwrap(), Register)?;
|
let left =
|
||||||
let right = expect_token!(args.get(1).unwrap(), Register)?;
|
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
||||||
|
let right =
|
||||||
|
expect_token!(args.get(1).expect("The spanish Inquisition"), Register)?;
|
||||||
Ok(Instruction::Compare(args!(R, sr1: left, sr2: right)))
|
Ok(Instruction::Compare(args!(R, sr1: left, sr2: right)))
|
||||||
}
|
}
|
||||||
Opcode::Inc => {
|
Opcode::Inc => {
|
||||||
let reg = expect_token!(args.first().unwrap(), Register)?;
|
let reg =
|
||||||
|
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
||||||
Ok(Instruction::Increment(args!(R, sr1: reg)))
|
Ok(Instruction::Increment(args!(R, sr1: reg)))
|
||||||
}
|
}
|
||||||
Opcode::Dec => {
|
Opcode::Dec => {
|
||||||
let reg = expect_token!(args.first().unwrap(), Register)?;
|
let reg =
|
||||||
|
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
||||||
Ok(Instruction::Decrement(args!(R, sr1: reg)))
|
Ok(Instruction::Decrement(args!(R, sr1: reg)))
|
||||||
}
|
}
|
||||||
Opcode::Shl => {
|
Opcode::Shl => {
|
||||||
let reg = expect_token!(args.first().unwrap(), Register)?;
|
let reg =
|
||||||
let amount = expect_token!(args.get(1).unwrap(), Immediate)? as u8;
|
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
||||||
|
let amount =
|
||||||
|
expect_token!(args.get(1).expect("The spanish Inquisition"), Immediate)?
|
||||||
|
as u8;
|
||||||
Ok(Instruction::ShiftLeft(args!(R, sr1: reg, shamt: amount)))
|
Ok(Instruction::ShiftLeft(args!(R, sr1: reg, shamt: amount)))
|
||||||
}
|
}
|
||||||
Opcode::Shr => {
|
Opcode::Shr => {
|
||||||
let reg = expect_token!(args.first().unwrap(), Register)?;
|
let reg =
|
||||||
let amount = expect_token!(args.get(1).unwrap(), Immediate)? as u8;
|
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
||||||
|
let amount =
|
||||||
|
expect_token!(args.get(1).expect("The spanish Inquisition"), Immediate)?
|
||||||
|
as u8;
|
||||||
Ok(Instruction::ShiftRight(args!(R, sr1: reg, shamt: amount)))
|
Ok(Instruction::ShiftRight(args!(R, sr1: reg, shamt: amount)))
|
||||||
}
|
}
|
||||||
Opcode::Add
|
Opcode::Add
|
||||||
@@ -123,9 +147,12 @@ fn build_instruction(node: Node) -> Result<Instruction, AssembleError> {
|
|||||||
| Opcode::Nand
|
| Opcode::Nand
|
||||||
| Opcode::Nor
|
| Opcode::Nor
|
||||||
| Opcode::Xnor => {
|
| Opcode::Xnor => {
|
||||||
let left = expect_token!(args.first().unwrap(), Register)?;
|
let left =
|
||||||
let right = expect_token!(args.get(1).unwrap(), Register)?;
|
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
||||||
let dest = expect_token!(args.get(2).unwrap(), Register)?;
|
let right =
|
||||||
|
expect_token!(args.get(1).expect("The spanish Inquisition"), Register)?;
|
||||||
|
let dest =
|
||||||
|
expect_token!(args.get(2).expect("The spanish Inquisition"), Register)?;
|
||||||
let args = args!(R, sr1: left, sr2: right, dr: dest);
|
let args = args!(R, sr1: left, sr2: right, dr: dest);
|
||||||
|
|
||||||
match opcode {
|
match opcode {
|
||||||
@@ -141,9 +168,13 @@ fn build_instruction(node: Node) -> Result<Instruction, AssembleError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Opcode::Iadd | Opcode::Isub => {
|
Opcode::Iadd | Opcode::Isub => {
|
||||||
let reg = expect_token!(args.first().unwrap(), Register)?;
|
let reg =
|
||||||
let immediate = expect_token!(args.get(1).unwrap(), Immediate)? as u16;
|
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
||||||
let dest = expect_token!(args.get(2).unwrap(), Register)?;
|
let immediate =
|
||||||
|
expect_token!(args.get(1).expect("The spanish Inquisition"), Immediate)?
|
||||||
|
as u16;
|
||||||
|
let dest =
|
||||||
|
expect_token!(args.get(2).expect("The spanish Inquisition"), Register)?;
|
||||||
let args = args!(I, immediate: immediate, r1: reg, r2: dest);
|
let args = args!(I, immediate: immediate, r1: reg, r2: dest);
|
||||||
|
|
||||||
match opcode {
|
match opcode {
|
||||||
@@ -153,22 +184,28 @@ fn build_instruction(node: Node) -> Result<Instruction, AssembleError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Opcode::Not => {
|
Opcode::Not => {
|
||||||
let reg = expect_token!(args.first().unwrap(), Register)?;
|
let reg =
|
||||||
let dest = expect_token!(args.get(1).unwrap(), Register)?;
|
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
||||||
|
let dest =
|
||||||
|
expect_token!(args.get(1).expect("The spanish Inquisition"), Register)?;
|
||||||
Ok(Instruction::Not(args!(R, sr1: reg, dr: dest)))
|
Ok(Instruction::Not(args!(R, sr1: reg, dr: dest)))
|
||||||
}
|
}
|
||||||
Opcode::Int => {
|
Opcode::Int => {
|
||||||
let code = expect_token!(args.first().unwrap(), Immediate)? as u8;
|
let code =
|
||||||
|
expect_token!(args.first().expect("The spanish Inquisition"), Immediate)?
|
||||||
|
as u8;
|
||||||
Ok(Instruction::Interrupt(Interrupt::Software(code)))
|
Ok(Instruction::Interrupt(Interrupt::Software(code)))
|
||||||
}
|
}
|
||||||
Opcode::Irt => Ok(Instruction::IntReturn),
|
Opcode::Irt => Ok(Instruction::IntReturn),
|
||||||
Opcode::Hlt => Ok(Instruction::Halt),
|
Opcode::Hlt => Ok(Instruction::Halt),
|
||||||
Opcode::Data => {
|
Opcode::Data => {
|
||||||
let immediate = expect_token!(args.first().unwrap(), Immediate)?;
|
let immediate =
|
||||||
|
expect_token!(args.first().expect("The spanish Inquisition"), Immediate)?;
|
||||||
Ok(Instruction::Data(immediate))
|
Ok(Instruction::Data(immediate))
|
||||||
}
|
}
|
||||||
Opcode::Segment => {
|
Opcode::Segment => {
|
||||||
let immediate = expect_token!(args.first().unwrap(), Immediate)?;
|
let immediate =
|
||||||
|
expect_token!(args.first().expect("The spanish Inquisition"), Immediate)?;
|
||||||
Ok(Instruction::Segment(immediate))
|
Ok(Instruction::Segment(immediate))
|
||||||
}
|
}
|
||||||
Opcode::Db
|
Opcode::Db
|
||||||
|
|||||||
+22
-13
@@ -44,7 +44,7 @@ fn try_expand(
|
|||||||
|
|
||||||
fn expand_push(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
fn expand_push(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
||||||
let label = current.label();
|
let label = current.label();
|
||||||
let reg = expect_type!(current.arg(0).unwrap(), Register)?;
|
let reg = expect_type!(current.arg(0).expect("The spanish Inquisition"), Register)?;
|
||||||
|
|
||||||
nodes.extend(vec![
|
nodes.extend(vec![
|
||||||
node!(
|
node!(
|
||||||
@@ -68,7 +68,7 @@ fn expand_push(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError
|
|||||||
|
|
||||||
fn expand_pop(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
fn expand_pop(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
||||||
let label = current.label();
|
let label = current.label();
|
||||||
let reg = expect_type!(current.arg(0).unwrap(), Register)?;
|
let reg = expect_type!(current.arg(0).expect("The spanish Inquisition"), Register)?;
|
||||||
|
|
||||||
nodes.extend(vec![
|
nodes.extend(vec![
|
||||||
node!(
|
node!(
|
||||||
@@ -92,9 +92,10 @@ fn expand_pop(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError>
|
|||||||
|
|
||||||
fn expand_ldx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
fn expand_ldx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
||||||
let opcode = current.opcode();
|
let opcode = current.opcode();
|
||||||
let name = expect_type!(current.arg(0).unwrap(), Symbol)?;
|
let name = expect_type!(current.arg(0).expect("The spanish Inquisition"), Symbol)?;
|
||||||
let reg = expect_type!(current.arg(1).unwrap(), Register)?;
|
let reg = expect_type!(current.arg(1).expect("The spanish Inquisition"), Register)?;
|
||||||
let offset = expect_type!(current.arg(2).unwrap(), Immediate)?;
|
let offset =
|
||||||
|
expect_type!(current.arg(2).expect("The spanish Inquisition"), Immediate)?;
|
||||||
|
|
||||||
nodes.extend(vec![
|
nodes.extend(vec![
|
||||||
node!(current.label(), Opcode::Lli, name.clone(), reg.clone()),
|
node!(current.label(), Opcode::Lli, name.clone(), reg.clone()),
|
||||||
@@ -107,9 +108,10 @@ fn expand_ldx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError>
|
|||||||
|
|
||||||
fn expand_stx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
fn expand_stx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
||||||
let opcode = current.opcode();
|
let opcode = current.opcode();
|
||||||
let base = expect_type!(current.arg(0).unwrap(), Register)?;
|
let base = expect_type!(current.arg(0).expect("The spanish Inquisition"), Register)?;
|
||||||
let dest = expect_type!(current.arg(1).unwrap(), Symbol)?;
|
let dest = expect_type!(current.arg(1).expect("The spanish Inquisition"), Symbol)?;
|
||||||
let offset = expect_type!(current.arg(2).unwrap(), Immediate)?;
|
let offset =
|
||||||
|
expect_type!(current.arg(2).expect("The spanish Inquisition"), Immediate)?;
|
||||||
nodes.extend(vec![
|
nodes.extend(vec![
|
||||||
node!(
|
node!(
|
||||||
current.label(),
|
current.label(),
|
||||||
@@ -130,8 +132,12 @@ fn expand_stx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError>
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn expand_lwi(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
fn expand_lwi(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
||||||
let val = expect_type!(current.arg(0).unwrap(), Symbol, Immediate)?;
|
let val = expect_type!(
|
||||||
let reg = expect_type!(current.arg(1).unwrap(), Register)?;
|
current.arg(0).expect("The spanish Inquisition"),
|
||||||
|
Symbol,
|
||||||
|
Immediate
|
||||||
|
)?;
|
||||||
|
let reg = expect_type!(current.arg(1).expect("The spanish Inquisition"), Register)?;
|
||||||
|
|
||||||
nodes.extend(vec![
|
nodes.extend(vec![
|
||||||
node!(current.label(), Opcode::Lli, val.clone(), reg.clone()),
|
node!(current.label(), Opcode::Lli, val.clone(), reg.clone()),
|
||||||
@@ -142,8 +148,10 @@ fn expand_lwi(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError>
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn expand_resx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
fn expand_resx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
||||||
let region_label = expect_token!(current.arg(0).unwrap(), Symbol)?;
|
let region_label =
|
||||||
let size = expect_token!(current.arg(1).unwrap(), Immediate)?;
|
expect_token!(current.arg(0).expect("The spanish Inquisition"), Symbol)?;
|
||||||
|
let size =
|
||||||
|
expect_token!(current.arg(1).expect("The spanish Inquisition"), Immediate)?;
|
||||||
|
|
||||||
let units_per = match current.opcode() {
|
let units_per = match current.opcode() {
|
||||||
Opcode::Resb => 4,
|
Opcode::Resb => 4,
|
||||||
@@ -165,7 +173,8 @@ fn expand_resx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn expand_dx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
fn expand_dx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
||||||
let region_label = expect_token!(current.arg(0).unwrap(), Symbol)?;
|
let region_label =
|
||||||
|
expect_token!(current.arg(0).expect("The spanish Inquisition"), Symbol)?;
|
||||||
let size = match current.opcode() {
|
let size = match current.opcode() {
|
||||||
Opcode::Db => 4,
|
Opcode::Db => 4,
|
||||||
Opcode::Dh => 2,
|
Opcode::Dh => 2,
|
||||||
|
|||||||
+27
-12
@@ -59,7 +59,10 @@ impl Parser {
|
|||||||
let mut dependencies = Vec::new();
|
let mut dependencies = Vec::new();
|
||||||
for node in nodes {
|
for node in nodes {
|
||||||
if let Opcode::Include = node.opcode() {
|
if let Opcode::Include = node.opcode() {
|
||||||
let path = expect_token!(node.args().get(1).unwrap(), StringLit)?;
|
let path = expect_token!(
|
||||||
|
node.args().get(1).expect("The spanish Inquisition"),
|
||||||
|
StringLit
|
||||||
|
)?;
|
||||||
dependencies.push(PathBuf::from(path));
|
dependencies.push(PathBuf::from(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,12 +245,16 @@ impl Parser {
|
|||||||
Opcode::Db => {
|
Opcode::Db => {
|
||||||
// db can take string literals or u8 immediates
|
// db can take string literals or u8 immediates
|
||||||
while !self.tokens.is_empty() {
|
while !self.tokens.is_empty() {
|
||||||
match self.tokens.last().unwrap() {
|
match self.tokens.last().expect("The spanish Inquisition") {
|
||||||
Token::StringLit(_) => {
|
Token::StringLit(_) => {
|
||||||
values.push(self.tokens.pop().unwrap());
|
values.push(
|
||||||
|
self.tokens.pop().expect("The spanish Inquisition"),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Token::Immediate(val) if *val <= u8::MAX as u32 => {
|
Token::Immediate(val) if *val <= u8::MAX as u32 => {
|
||||||
values.push(self.tokens.pop().unwrap());
|
values.push(
|
||||||
|
self.tokens.pop().expect("The spanish Inquisition"),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
_ => break,
|
_ => break,
|
||||||
}
|
}
|
||||||
@@ -257,12 +264,16 @@ impl Parser {
|
|||||||
Opcode::Dh => {
|
Opcode::Dh => {
|
||||||
// dh can take u16 immediates
|
// dh can take u16 immediates
|
||||||
while !self.tokens.is_empty() {
|
while !self.tokens.is_empty() {
|
||||||
match self.tokens.last().unwrap() {
|
match self.tokens.last().expect("The spanish Inquisition") {
|
||||||
Token::StringLit(_) => {
|
Token::StringLit(_) => {
|
||||||
values.push(self.tokens.pop().unwrap());
|
values.push(
|
||||||
|
self.tokens.pop().expect("The spanish Inquisition"),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Token::Immediate(val) if *val <= u16::MAX as u32 => {
|
Token::Immediate(val) if *val <= u16::MAX as u32 => {
|
||||||
values.push(self.tokens.pop().unwrap());
|
values.push(
|
||||||
|
self.tokens.pop().expect("The spanish Inquisition"),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
_ => break,
|
_ => break,
|
||||||
}
|
}
|
||||||
@@ -272,12 +283,16 @@ impl Parser {
|
|||||||
Opcode::Dw => {
|
Opcode::Dw => {
|
||||||
// dw can take u32 immediates
|
// dw can take u32 immediates
|
||||||
while !self.tokens.is_empty() {
|
while !self.tokens.is_empty() {
|
||||||
match self.tokens.last().unwrap() {
|
match self.tokens.last().expect("The spanish Inquisition") {
|
||||||
Token::StringLit(_) => {
|
Token::StringLit(_) => {
|
||||||
values.push(self.tokens.pop().unwrap());
|
values.push(
|
||||||
|
self.tokens.pop().expect("The spanish Inquisition"),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Token::Immediate(_) => {
|
Token::Immediate(_) => {
|
||||||
values.push(self.tokens.pop().unwrap());
|
values.push(
|
||||||
|
self.tokens.pop().expect("The spanish Inquisition"),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
_ => break,
|
_ => break,
|
||||||
}
|
}
|
||||||
@@ -294,7 +309,7 @@ impl Parser {
|
|||||||
if self.tokens.is_empty() {
|
if self.tokens.is_empty() {
|
||||||
Err(AssembleError::UnexpectedEof)
|
Err(AssembleError::UnexpectedEof)
|
||||||
} else {
|
} else {
|
||||||
Ok(self.tokens.pop().unwrap())
|
Ok(self.tokens.pop().expect("The spanish Inquisition"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,7 +317,7 @@ impl Parser {
|
|||||||
if self.tokens.is_empty() {
|
if self.tokens.is_empty() {
|
||||||
Err(AssembleError::UnexpectedEof)
|
Err(AssembleError::UnexpectedEof)
|
||||||
} else {
|
} else {
|
||||||
Ok(self.tokens.last().unwrap().clone())
|
Ok(self.tokens.last().expect("The spanish Inquisition").clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ pub fn resolve_symbols(nodes: &mut [Node]) -> Result<(), AssembleError> {
|
|||||||
for node in nodes.iter_mut() {
|
for node in nodes.iter_mut() {
|
||||||
match node.opcode() {
|
match node.opcode() {
|
||||||
Opcode::Lli => {
|
Opcode::Lli => {
|
||||||
if let Token::Symbol(symbol) = node.arg(0).unwrap() {
|
if let Token::Symbol(symbol) =
|
||||||
|
node.arg(0).expect("The spanish Inquisition")
|
||||||
|
{
|
||||||
if let Some(address) = symbol_table.get(&symbol) {
|
if let Some(address) = symbol_table.get(&symbol) {
|
||||||
node.tokens[0] = Token::Immediate(*address);
|
node.tokens[0] = Token::Immediate(*address);
|
||||||
} else {
|
} else {
|
||||||
@@ -23,7 +25,9 @@ pub fn resolve_symbols(nodes: &mut [Node]) -> Result<(), AssembleError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Opcode::Lui => {
|
Opcode::Lui => {
|
||||||
if let Token::Symbol(symbol) = node.arg(0).unwrap() {
|
if let Token::Symbol(symbol) =
|
||||||
|
node.arg(0).expect("The spanish Inquisition")
|
||||||
|
{
|
||||||
if let Some(address) = symbol_table.get(&symbol) {
|
if let Some(address) = symbol_table.get(&symbol) {
|
||||||
node.tokens[0] = Token::Immediate(*address);
|
node.tokens[0] = Token::Immediate(*address);
|
||||||
} else {
|
} else {
|
||||||
@@ -38,7 +42,9 @@ pub fn resolve_symbols(nodes: &mut [Node]) -> Result<(), AssembleError> {
|
|||||||
| Opcode::Jge
|
| Opcode::Jge
|
||||||
| Opcode::Jlt
|
| Opcode::Jlt
|
||||||
| Opcode::Jle => {
|
| Opcode::Jle => {
|
||||||
if let Token::Symbol(symbol) = node.arg(0).unwrap() {
|
if let Token::Symbol(symbol) =
|
||||||
|
node.arg(0).expect("The spanish Inquisition")
|
||||||
|
{
|
||||||
if let Some(address) = symbol_table.get(&symbol) {
|
if let Some(address) = symbol_table.get(&symbol) {
|
||||||
node.tokens[0] = Token::Immediate(*address);
|
node.tokens[0] = Token::Immediate(*address);
|
||||||
} else {
|
} else {
|
||||||
@@ -71,12 +77,16 @@ pub fn resolve_dependencies(mut nodes: Vec<Node>) -> Result<Vec<Node>, AssembleE
|
|||||||
for node in &nodes {
|
for node in &nodes {
|
||||||
if let Opcode::Include = node.opcode() {
|
if let Opcode::Include = node.opcode() {
|
||||||
// we want the path, and the name
|
// we want the path, and the name
|
||||||
let name = if let Token::Symbol(name) = node.arg(0).unwrap() {
|
let name = if let Token::Symbol(name) =
|
||||||
|
node.arg(0).expect("The spanish Inquisition")
|
||||||
|
{
|
||||||
name.name.clone()
|
name.name.clone()
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}; //node.2.get(0).unwrap()
|
}; //node.2.get(0).expect("The spanish Inquisition")
|
||||||
let path = if let Token::StringLit(path) = node.arg(1).unwrap() {
|
let path = if let Token::StringLit(path) =
|
||||||
|
node.arg(1).expect("The spanish Inquisition")
|
||||||
|
{
|
||||||
path
|
path
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ impl Executable for Instruction {
|
|||||||
// To populate the lower 16 bits, see LLI.
|
// To populate the lower 16 bits, see LLI.
|
||||||
Self::LoadUpperImmediate(a) => {
|
Self::LoadUpperImmediate(a) => {
|
||||||
*cpu.reg(a.r1) =
|
*cpu.reg(a.r1) =
|
||||||
(cpu.get(a.r1) & 0x0000_FFFF) | u32::from(a.immediate) << 16;
|
(cpu.get(a.r1) & 0x0000_FFFF) | (u32::from(a.immediate) << 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unconditionally jumps to the calculated address or direct address
|
// Unconditionally jumps to the calculated address or direct address
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ impl Component for MemoryInspector {
|
|||||||
// combine all 4 bytes in the chunk into a u32
|
// combine all 4 bytes in the chunk into a u32
|
||||||
let combined = chunk
|
let combined = chunk
|
||||||
.iter()
|
.iter()
|
||||||
.fold(0u32, |acc, &byte| acc << 8 | u32::from(byte));
|
.fold(0u32, |acc, &byte| (acc << 8) | u32::from(byte));
|
||||||
|
|
||||||
ui.monospace(format!("{combined}"));
|
ui.monospace(format!("{combined}"));
|
||||||
ui.monospace(format!("{}", Instruction::decode(combined).unwrap_or(Instruction::Nop)));
|
ui.monospace(format!("{}", Instruction::decode(combined).unwrap_or(Instruction::Nop)));
|
||||||
|
|||||||
Reference in New Issue
Block a user