Define stack_load, stack_store, and stack_addr instructions.

This commit is contained in:
Jakob Stoklund Olesen
2017-04-10 13:20:41 -07:00
parent 7c3bc9d19f
commit 222ae8af22
10 changed files with 163 additions and 56 deletions

View File

@@ -5,8 +5,8 @@
use ir::types;
use ir::{InstructionData, DataFlowGraph, Cursor};
use ir::{Opcode, Type, Inst, Value, Ebb, JumpTable, SigRef, FuncRef, ValueList};
use ir::immediates::{Imm64, Uimm8, Ieee32, Ieee64};
use ir::{Opcode, Type, Inst, Value, Ebb, JumpTable, SigRef, FuncRef, StackSlot, ValueList};
use ir::immediates::{Imm64, Uimm8, Ieee32, Ieee64, Offset32};
use ir::condcodes::{IntCC, FloatCC};
/// Base trait for instruction builders.

View File

@@ -10,8 +10,8 @@ use std::fmt::{self, Display, Formatter};
use std::str::FromStr;
use std::ops::{Deref, DerefMut};
use ir::{Value, Type, Ebb, JumpTable, SigRef, FuncRef};
use ir::immediates::{Imm64, Uimm8, Ieee32, Ieee64};
use ir::{Value, Type, Ebb, JumpTable, SigRef, FuncRef, StackSlot};
use ir::immediates::{Imm64, Uimm8, Ieee32, Ieee64, Offset32};
use ir::condcodes::*;
use ir::types;
use ir::DataFlowGraph;
@@ -227,6 +227,19 @@ pub enum InstructionData {
sig_ref: SigRef,
args: ValueList,
},
StackLoad {
opcode: Opcode,
ty: Type,
stack_slot: StackSlot,
offset: Offset32,
},
StackStore {
opcode: Opcode,
ty: Type,
arg: Value,
stack_slot: StackSlot,
offset: Offset32,
},
}
/// A variable list of `Value` operands used for function call arguments and passing arguments to

View File

@@ -57,7 +57,8 @@ use dominator_tree::DominatorTree;
use flowgraph::ControlFlowGraph;
use ir::entities::AnyEntity;
use ir::instructions::{InstructionFormat, BranchInfo, ResolvedConstraint, CallInfo};
use ir::{types, Function, ValueDef, Ebb, Inst, SigRef, FuncRef, ValueList, JumpTable, Value, Type};
use ir::{types, Function, ValueDef, Ebb, Inst, SigRef, FuncRef, ValueList, JumpTable, StackSlot,
Value, Type};
use Context;
use std::fmt::{self, Display, Formatter};
use std::result;
@@ -248,6 +249,11 @@ impl<'a> Verifier<'a> {
self.verify_sig_ref(inst, sig_ref)?;
self.verify_value_list(inst, args)?;
}
&StackLoad { stack_slot, .. } |
&StackStore { stack_slot, .. } => {
self.verify_stack_slot(inst, stack_slot)?;
}
// Exhaustive list so we can't forget to add new formats
&Nullary { .. } |
&Unary { .. } |
@@ -293,6 +299,14 @@ impl<'a> Verifier<'a> {
}
}
fn verify_stack_slot(&self, inst: Inst, ss: StackSlot) -> Result<()> {
if !self.func.stack_slots.is_valid(ss) {
err!(inst, "invalid stack slot {}", ss)
} else {
Ok(())
}
}
fn verify_value_list(&self, inst: Inst, l: &ValueList) -> Result<()> {
if !l.is_valid(&self.func.dfg.value_lists) {
err!(inst, "invalid value list reference {:?}", l)

View File

@@ -313,6 +313,13 @@ pub fn write_operands(w: &mut Write, dfg: &DataFlowGraph, inst: Inst) -> Result
args[0],
DisplayValues(&args[1..]))
}
StackLoad { stack_slot, offset, .. } => write!(w, " {}{}", stack_slot, offset),
StackStore {
arg,
stack_slot,
offset,
..
} => write!(w, " {}, {}{}", arg, stack_slot, offset),
}
}