Rename arg_value to param_value for consistency.

Also rename FunctionBuilder's `pristine` to `params_values_initialized`
to avoid confusion with the unrelated `is_pristine` accessor function.
This commit is contained in:
Dan Gohman
2017-10-25 10:14:10 -07:00
parent b6eae2cfb6
commit dbd75483e8
3 changed files with 48 additions and 31 deletions

View File

@@ -22,7 +22,7 @@ where
ssa: SSABuilder<Variable>,
ebbs: EntityMap<Ebb, EbbData>,
types: EntityMap<Variable, Type>,
function_args_values: Vec<Value>,
function_params_values: Vec<Value>,
}
@@ -40,7 +40,9 @@ where
builder: &'a mut ILBuilder<Variable>,
position: Position,
pristine: bool,
/// Has builder.function_params_values been populated yet?
params_values_initialized: bool,
}
#[derive(Clone, Default)]
@@ -66,7 +68,7 @@ where
ssa: SSABuilder::new(),
ebbs: EntityMap::new(),
types: EntityMap::new(),
function_args_values: Vec::new(),
function_params_values: Vec::new(),
}
}
@@ -74,12 +76,12 @@ where
self.ssa.clear();
self.ebbs.clear();
self.types.clear();
self.function_args_values.clear();
self.function_params_values.clear();
}
fn is_empty(&self) -> bool {
self.ssa.is_empty() && self.ebbs.is_empty() && self.types.is_empty() &&
self.function_args_values.is_empty()
self.function_params_values.is_empty()
}
}
@@ -234,7 +236,7 @@ where
ebb: Ebb::new(0),
basic_block: Block::new(0),
},
pristine: true,
params_values_initialized: false,
}
}
@@ -263,8 +265,8 @@ where
/// successor), the block will be declared filled and it will not be possible to append
/// instructions to it.
pub fn switch_to_block(&mut self, ebb: Ebb, jump_args: &[Value]) -> &[Value] {
if self.pristine {
self.fill_function_args_values(ebb);
if !self.params_values_initialized {
self.fill_function_params_values(ebb);
}
if !self.builder.ebbs[self.position.ebb].pristine {
// First we check that the previous block has been filled.
@@ -332,12 +334,21 @@ where
);
}
/// Returns the value corresponding to the `i`-th argument of the function as defined by
/// Returns the value corresponding to the `i`-th parameter of the function as defined by
/// the function signature. Panics if `i` is out of bounds or if called before the first call
/// to `switch_to_block`.
pub fn param_value(&self, i: usize) -> Value {
debug_assert!(
self.params_values_initialized,
"you have to call switch_to_block first."
);
self.builder.function_params_values[i]
}
/// Use param_value instead.
#[deprecated(since = "forever", note = "arg_value is renamed to param_value")]
pub fn arg_value(&self, i: usize) -> Value {
debug_assert!(!self.pristine, "you have to call switch_to_block first.");
self.builder.function_args_values[i]
self.param_value(i)
}
/// Creates a jump table in the function, to be used by `br_table` instructions.
@@ -475,6 +486,12 @@ where
self.builder.ssa.predecessors(self.position.ebb).is_empty())
}
/// Returns `true` if and only if the entry block has been started and `param_value`
/// may be called.
pub fn entry_block_started(&self) -> bool {
self.params_values_initialized
}
/// Returns `true` if and only if no instructions have been added since the last call to
/// `switch_to_block`.
pub fn is_pristine(&self) -> bool {
@@ -556,14 +573,14 @@ where
}
}
fn fill_function_args_values(&mut self, ebb: Ebb) {
debug_assert!(self.pristine);
fn fill_function_params_values(&mut self, ebb: Ebb) {
debug_assert!(!self.params_values_initialized);
for argtyp in &self.func.signature.params {
self.builder.function_args_values.push(
self.builder.function_params_values.push(
self.func.dfg.append_ebb_param(ebb, argtyp.value_type),
);
}
self.pristine = false;
self.params_values_initialized = true;
}
@@ -685,7 +702,7 @@ mod tests {
builder.switch_to_block(block0, &[]);
builder.seal_block(block0);
{
let tmp = builder.arg_value(0);
let tmp = builder.param_value(0);
builder.def_var(x, tmp);
}
{

View File

@@ -84,7 +84,7 @@
//! builder.switch_to_block(block0, &[]);
//! builder.seal_block(block0);
//! {
//! let tmp = builder.arg_value(0);
//! let tmp = builder.param_value(0);
//! builder.def_var(x, tmp);
//! }
//! {

View File

@@ -88,14 +88,14 @@ impl FuncTranslator {
// `environ`. The callback functions may need to insert things in the entry block.
builder.ensure_inserted_ebb();
let num_args = declare_wasm_arguments(&mut builder);
let num_params = declare_wasm_parameters(&mut builder);
// Set up the translation state with a single pushed control block representing the whole
// function and its return values.
let exit_block = builder.create_ebb();
self.state.initialize(&builder.func.signature, exit_block);
parse_local_decls(&mut reader, &mut builder, num_args)?;
parse_local_decls(&mut reader, &mut builder, num_params)?;
parse_function_body(reader, &mut builder, &mut self.state, environ)
}
}
@@ -103,21 +103,21 @@ impl FuncTranslator {
/// Declare local variables for the signature parameters that correspond to WebAssembly locals.
///
/// Return the number of local variables declared.
fn declare_wasm_arguments(builder: &mut FunctionBuilder<Local>) -> usize {
fn declare_wasm_parameters(builder: &mut FunctionBuilder<Local>) -> usize {
let sig_len = builder.func.signature.params.len();
let mut next_local = 0;
for i in 0..sig_len {
let arg_type = builder.func.signature.params[i];
// There may be additional special-purpose arguments following the normal WebAssembly
// signature arguments. For example, a `vmctx` pointer.
if arg_type.purpose == ir::ArgumentPurpose::Normal {
// This is a normal WebAssembly signature argument, so create a local for it.
let param_type = builder.func.signature.params[i];
// There may be additional special-purpose parameters following the normal WebAssembly
// signature parameters. For example, a `vmctx` pointer.
if param_type.purpose == ir::ArgumentPurpose::Normal {
// This is a normal WebAssembly signature parameter, so create a local for it.
let local = Local::new(next_local);
builder.declare_var(local, arg_type.value_type);
builder.declare_var(local, param_type.value_type);
next_local += 1;
let arg_value = builder.arg_value(i);
builder.def_var(local, arg_value);
let param_value = builder.param_value(i);
builder.def_var(local, param_value);
}
}
@@ -126,13 +126,13 @@ fn declare_wasm_arguments(builder: &mut FunctionBuilder<Local>) -> usize {
/// Parse the local variable declarations that precede the function body.
///
/// Declare local variables, starting from `num_args`.
/// Declare local variables, starting from `num_params`.
fn parse_local_decls(
reader: &mut BinaryReader,
builder: &mut FunctionBuilder<Local>,
num_args: usize,
num_params: usize,
) -> CtonResult {
let mut next_local = num_args;
let mut next_local = num_params;
let local_count = reader.read_local_count().map_err(
|_| CtonError::InvalidInput,
)?;