diff options
| author | David Li <li.davidm96@gmail.com> | 2017-11-26 19:59:00 -0500 | 
|---|---|---|
| committer | David Li <li.davidm96@gmail.com> | 2017-11-26 19:59:00 -0500 | 
| commit | 01daee374a299646c595dd245c8e4a4990769002 (patch) | |
| tree | d4f749c94afbed1143613977958b3216653f4393 /src/semantic/frame.rs | |
| parent | b007bc6f9dcbef41c3710cc8ce63b04504a14244 (diff) | |
Translate variable bindings
Diffstat (limited to 'src/semantic/frame.rs')
| -rw-r--r-- | src/semantic/frame.rs | 33 | 
1 files changed, 29 insertions, 4 deletions
diff --git a/src/semantic/frame.rs b/src/semantic/frame.rs index ddfc330..95d18a1 100644 --- a/src/semantic/frame.rs +++ b/src/semantic/frame.rs @@ -1,3 +1,4 @@ +use super::ir;  use super::temp;  pub enum Location { @@ -16,17 +17,20 @@ pub trait Frame {      fn new(name: temp::TempLabel, formals: Vec<Escape>) -> Self;      fn name(&self) -> temp::TempLabel;      fn formals(&self) -> &[Location]; -    fn alloc_local(&mut self, escapes: Escape) -> Location; +    fn alloc_local(&mut self, temp: &mut temp::Temp, escapes: Escape) -> Location; +    fn location_to_exp(&mut self, location: Location) -> ir::Expression;  }  pub struct Amd64Frame { +    offset: u64,      name: temp::TempLabel,  }  impl Frame for Amd64Frame {      fn new(name: temp::TempLabel, formals: Vec<Escape>) -> Self {          Amd64Frame { -            name, +            offset: 0, +            name: name,          }      } @@ -38,7 +42,28 @@ impl Frame for Amd64Frame {          unimplemented!();      } -    fn alloc_local(&mut self, escapes: Escape) -> Location { -        unimplemented!(); +    fn alloc_local(&mut self, temp: &mut temp::Temp, escapes: Escape) -> Location { +        // TODO: this is WRONG +        Location::InFrame { offset: 0 } +    } + +    fn location_to_exp(&mut self, location: Location) -> ir::Expression { +        match location { +            Location::InFrame { offset } => { +                ir::Expression::Memory( +                    Box::new( +                        ir::Expression::BinOp( +                            ir::BinOp::Plus, +                            Box::new(ir::Expression::Const(self.offset)), +                            Box::new(ir::Expression::Const(offset as u64)), +                        ) +                    ) +                ) +            } +            Location::Register(name) => { +                ir::Expression::Temp(name) +            } +        } +      }  }  | 
