surround routines by far jump across
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
use std::sync::atomic::AtomicU32;
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
|
||||
use crate::asm::data::{Rd, RdData};
|
||||
use crate::asm::data::literal::{Label, Value};
|
||||
@@ -63,7 +63,10 @@ impl Flatten for Vec<Box<dyn Flatten>> {
|
||||
|
||||
impl Flatten for Routine {
|
||||
fn flatten(self: Box<Self>, label_num: &AtomicU32) -> Result<Vec<Op>, CrsnError> {
|
||||
let mut ops = vec![
|
||||
let skip_label = Label::Numbered(label_num.fetch_add(1, Ordering::Relaxed));
|
||||
|
||||
let mut ops : Vec<Op> = vec![
|
||||
BuiltinOp::FarJump(skip_label.clone()).into(),
|
||||
BuiltinOp::Barrier(Some(format!("Routine \"{}\" start", self.name).into())).into(),
|
||||
BuiltinOp::Routine(self.name.clone()).into(),
|
||||
];
|
||||
@@ -71,6 +74,7 @@ impl Flatten for Routine {
|
||||
ops.extend(self.body.flatten(label_num)?);
|
||||
|
||||
ops.push(BuiltinOp::Barrier(Some(format!("Routine \"{}\" end", self.name).into())).into());
|
||||
ops.push(BuiltinOp::FarLabel(skip_label).into());
|
||||
|
||||
numbered_labels_to_skips(ops)
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ impl Program {
|
||||
/// Read a program instruction at address
|
||||
pub fn read(&self, addr: Addr) -> &Op {
|
||||
if addr.0 >= self.ops.len() as u64 {
|
||||
&Op::BuiltIn(BuiltinOp::Nop)
|
||||
&Op::BuiltIn(BuiltinOp::Halt)
|
||||
} else {
|
||||
&self.ops[addr.0 as usize]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
(
|
||||
(ld r0 1)
|
||||
|
||||
; the procedure is surrounded by a jump and a label
|
||||
(proc foo
|
||||
(nop)
|
||||
(ret)
|
||||
)
|
||||
|
||||
(ld r0 2)
|
||||
)
|
||||
@@ -11,5 +11,4 @@
|
||||
(cmp r1 1 (ne? (fault)))
|
||||
|
||||
(drop @r0)
|
||||
(halt)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user