From 4c6fd6e670264b01a84ee76e99e28d6be7789f1a Mon Sep 17 00:00:00 2001
From: David Li
Date: Tue, 7 Nov 2017 16:50:39 -0500
Subject: Add stub of frame module
---
src/semantic/frame.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++
src/semantic/mod.rs | 2 ++
src/semantic/temp.rs | 26 ++++++++++++++++++++++++++
3 files changed, 72 insertions(+)
create mode 100644 src/semantic/frame.rs
create mode 100644 src/semantic/temp.rs
(limited to 'src')
diff --git a/src/semantic/frame.rs b/src/semantic/frame.rs
new file mode 100644
index 0000000..ddfc330
--- /dev/null
+++ b/src/semantic/frame.rs
@@ -0,0 +1,44 @@
+use super::temp;
+
+pub enum Location {
+ InFrame {
+ offset: usize,
+ },
+ Register(temp::TempName),
+}
+
+pub enum Escape {
+ No,
+ Yes,
+}
+
+pub trait Frame {
+ fn new(name: temp::TempLabel, formals: Vec) -> Self;
+ fn name(&self) -> temp::TempLabel;
+ fn formals(&self) -> &[Location];
+ fn alloc_local(&mut self, escapes: Escape) -> Location;
+}
+
+pub struct Amd64Frame {
+ name: temp::TempLabel,
+}
+
+impl Frame for Amd64Frame {
+ fn new(name: temp::TempLabel, formals: Vec) -> Self {
+ Amd64Frame {
+ name,
+ }
+ }
+
+ fn name(&self) -> temp::TempLabel {
+ self.name
+ }
+
+ fn formals(&self) -> &[Location] {
+ unimplemented!();
+ }
+
+ fn alloc_local(&mut self, escapes: Escape) -> Location {
+ unimplemented!();
+ }
+}
diff --git a/src/semantic/mod.rs b/src/semantic/mod.rs
index e2edc24..afc56ef 100644
--- a/src/semantic/mod.rs
+++ b/src/semantic/mod.rs
@@ -4,5 +4,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
pub mod environment;
+pub mod frame;
+pub mod temp;
pub mod translate;
pub mod types;
diff --git a/src/semantic/temp.rs b/src/semantic/temp.rs
new file mode 100644
index 0000000..abd7e86
--- /dev/null
+++ b/src/semantic/temp.rs
@@ -0,0 +1,26 @@
+pub struct Temp {
+ counter: usize,
+}
+
+#[derive(Copy,Clone,Debug,Eq,PartialEq)]
+pub struct TempName(usize);
+#[derive(Copy,Clone,Debug,Eq,PartialEq)]
+pub struct TempLabel(usize);
+
+impl Temp {
+ pub fn new() -> Temp {
+ Temp { counter: 0 }
+ }
+
+ pub fn next_name(&mut self) -> TempName {
+ let idx = self.counter;
+ self.counter += 1;
+ TempName(idx)
+ }
+
+ pub fn next_label(&mut self) -> TempLabel {
+ let idx = self.counter;
+ self.counter += 1;
+ TempLabel(idx)
+ }
+}
--
cgit v1.2.3