summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Li <li.davidm96@gmail.com>2017-11-07 16:50:39 -0500
committerDavid Li <li.davidm96@gmail.com>2017-11-07 16:50:39 -0500
commit4c6fd6e670264b01a84ee76e99e28d6be7789f1a (patch)
tree1dd17a6fdb50ef0d0e12c76153fe94c26e3a7fbf
parenta90fdb63e8adb09dafcc050344c443d3b73838bc (diff)
Add stub of frame module
-rw-r--r--src/semantic/frame.rs44
-rw-r--r--src/semantic/mod.rs2
-rw-r--r--src/semantic/temp.rs26
3 files changed, 72 insertions, 0 deletions
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<Escape>) -> 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<Escape>) -> 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)
+ }
+}