Make functions cloneable for testing.

It's not super fast to clone a function, but it is faster than
re-parsing the test case file it came from.

Some tests want to mutate the function, and there may be other tests in
the same script that need the original function.
This commit is contained in:
Jakob Stoklund Olesen
2016-09-15 08:41:19 -07:00
parent 2901a85a36
commit 6ffca9ec99
7 changed files with 17 additions and 8 deletions

View File

@@ -45,7 +45,7 @@ pub trait EntityRef: Copy + Eq {
}
/// A mapping `K -> V` for densely indexed entity references.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct EntityMap<K, V>
where K: EntityRef
{

View File

@@ -15,6 +15,7 @@ use std::u16;
/// The layout of EBBs in the function and of instructions in each EBB is recorded by the
/// `FunctionLayout` data structure which form the other half of the function representation.
///
#[derive(Clone)]
pub struct DataFlowGraph {
/// Data about all of the instructions in the function, including opcodes and operands.
/// The instructions in this map are not in program order. That is tracked by `Layout`, along
@@ -119,6 +120,7 @@ pub enum ValueDef {
}
// Internal table storage for extended values.
#[derive(Clone)]
enum ValueData {
// Value is defined by an instruction, but it is not the first result.
Inst {
@@ -336,6 +338,7 @@ impl DataFlowGraph {
// Arguments for an extended basic block are values that dominate everything in the EBB. All
// branches to this EBB must provide matching arguments, and the arguments to the entry EBB must
// match the function arguments.
#[derive(Clone)]
struct EbbData {
// First argument to this EBB, or `NO_VALUE` if the block has no arguments.
//

View File

@@ -9,6 +9,10 @@ use entity_map::{EntityMap, PrimaryEntityData};
use std::fmt::{self, Debug, Formatter};
/// A function.
///
/// Functions can be cloned, but it is not a very fast operation.
/// The clone will have all the same entity numbers as the original.
#[derive(Clone)]
pub struct Function {
/// Name of this function. Mostly used by `.cton` files.
pub name: FunctionName,

View File

@@ -93,7 +93,7 @@ impl FromStr for Opcode {
/// value should have its `ty` field set to `VOID`. The size of `InstructionData` should be kept at
/// 16 bytes on 64-bit architectures. If more space is needed to represent an instruction, use a
/// `Box<AuxData>` to store the additional information out of line.
#[derive(Debug)]
#[derive(Clone, Debug)]
pub enum InstructionData {
Nullary { opcode: Opcode, ty: Type },
Unary {
@@ -203,7 +203,7 @@ pub enum InstructionData {
/// A variable list of `Value` operands used for function call arguments and passing arguments to
/// basic blocks.
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct VariableArgs(Vec<Value>);
impl VariableArgs {
@@ -256,7 +256,7 @@ impl Default for VariableArgs {
/// Payload data for jump instructions. These need to carry lists of EBB arguments that won't fit
/// in the allowed InstructionData size.
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct JumpData {
pub destination: Ebb,
pub arguments: VariableArgs,
@@ -274,7 +274,7 @@ impl Display for JumpData {
/// Payload data for branch instructions. These need to carry lists of EBB arguments that won't fit
/// in the allowed InstructionData size.
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct BranchData {
pub arg: Value,
pub destination: Ebb,
@@ -292,7 +292,7 @@ impl Display for BranchData {
}
/// Payload of a call instruction.
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct CallData {
/// Second result value for a call producing multiple return values.
second_result: Value,
@@ -308,7 +308,7 @@ impl Display for CallData {
}
/// Payload of a return instruction.
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct ReturnData {
// Dynamically sized array containing return values.
pub args: VariableArgs,

View File

@@ -12,6 +12,7 @@ use std::fmt::{self, Display, Formatter};
///
/// All jump tables use 0-based indexing and are expected to be densely populated. They don't need
/// to be completely populated, though. Individual entries can be missing.
#[derive(Clone)]
pub struct JumpTableData {
// Table entries, using NO_EBB as a placeholder for missing entries.
table: Vec<Ebb>,

View File

@@ -20,6 +20,7 @@ use ir::entities::{Ebb, NO_EBB, Inst, NO_INST};
/// While data dependencies are not recorded, instruction ordering does affect control
/// dependencies, so part of the semantics of the program are determined by the layout.
///
#[derive(Clone)]
pub struct Layout {
// Linked list nodes for the layout order of EBBs Forms a doubly linked list, terminated in
// both ends by NO_EBB.

View File

@@ -6,7 +6,7 @@
use std::fmt::{self, Display, Formatter};
/// Contents of a stack slot.
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct StackSlotData {
/// Size of stack slot in bytes.
pub size: u32,