Avoid using NO_INST in the parser.
This was only used for the comment rewrite mechanism, and we can just predict the next allocated instruction number instead. See the other uses of next_key() for gather_comments().
This commit is contained in:
@@ -301,6 +301,14 @@ impl DataFlowGraph {
|
|||||||
self.insts.push(data)
|
self.insts.push(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the instruction reference that will be assigned to the next instruction created by
|
||||||
|
/// `make_inst`.
|
||||||
|
///
|
||||||
|
/// This is only really useful to the parser.
|
||||||
|
pub fn next_inst(&self) -> Inst {
|
||||||
|
self.insts.next_key()
|
||||||
|
}
|
||||||
|
|
||||||
/// Create result values for an instruction that produces multiple results.
|
/// Create result values for an instruction that produces multiple results.
|
||||||
///
|
///
|
||||||
/// Instructions that produce 0 or 1 result values only need to be created with `make_inst`. If
|
/// Instructions that produce 0 or 1 result values only need to be created with `make_inst`. If
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use cretonne::ir::{Function, Ebb, Opcode, Value, Type, FunctionName, StackSlotDa
|
|||||||
FuncRef};
|
FuncRef};
|
||||||
use cretonne::ir::types::VOID;
|
use cretonne::ir::types::VOID;
|
||||||
use cretonne::ir::immediates::{Imm64, Ieee32, Ieee64};
|
use cretonne::ir::immediates::{Imm64, Ieee32, Ieee64};
|
||||||
use cretonne::ir::entities::{AnyEntity, NO_INST, NO_VALUE};
|
use cretonne::ir::entities::{AnyEntity, NO_VALUE};
|
||||||
use cretonne::ir::instructions::{InstructionFormat, InstructionData, VariableArgs,
|
use cretonne::ir::instructions::{InstructionFormat, InstructionData, VariableArgs,
|
||||||
TernaryOverflowData, JumpData, BranchData, CallData,
|
TernaryOverflowData, JumpData, BranchData, CallData,
|
||||||
IndirectCallData, ReturnData};
|
IndirectCallData, ReturnData};
|
||||||
@@ -283,17 +283,6 @@ impl<'a> Parser<'a> {
|
|||||||
mem::replace(&mut self.comments, Vec::new())
|
mem::replace(&mut self.comments, Vec::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rewrite the entity of the last added comments from `old` to `new`.
|
|
||||||
// Also switch to collecting future comments for `new`.
|
|
||||||
fn rewrite_last_comment_entities<E: Into<AnyEntity>>(&mut self, old: E, new: E) {
|
|
||||||
let old = old.into();
|
|
||||||
let new = new.into();
|
|
||||||
for comment in (&mut self.comments).into_iter().rev().take_while(|c| c.entity == old) {
|
|
||||||
comment.entity = new;
|
|
||||||
}
|
|
||||||
self.comment_entity = Some(new);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Match and consume a token without payload.
|
// Match and consume a token without payload.
|
||||||
fn match_token(&mut self, want: Token<'a>, err_msg: &str) -> Result<Token<'a>> {
|
fn match_token(&mut self, want: Token<'a>, err_msg: &str) -> Result<Token<'a>> {
|
||||||
if self.token() == Some(want) {
|
if self.token() == Some(want) {
|
||||||
@@ -906,9 +895,8 @@ impl<'a> Parser<'a> {
|
|||||||
// inst-results ::= Value(v) { "," Value(vx) }
|
// inst-results ::= Value(v) { "," Value(vx) }
|
||||||
//
|
//
|
||||||
fn parse_instruction(&mut self, ctx: &mut Context, ebb: Ebb) -> Result<()> {
|
fn parse_instruction(&mut self, ctx: &mut Context, ebb: Ebb) -> Result<()> {
|
||||||
// Collect comments for `NO_INST` while parsing the instruction, then rewrite after we
|
// Collect comments for the next instruction to be allocated.
|
||||||
// allocate an instruction number.
|
self.gather_comments(ctx.function.dfg.next_inst());
|
||||||
self.gather_comments(NO_INST);
|
|
||||||
|
|
||||||
// Result value numbers.
|
// Result value numbers.
|
||||||
let mut results = Vec::new();
|
let mut results = Vec::new();
|
||||||
@@ -969,10 +957,6 @@ impl<'a> Parser<'a> {
|
|||||||
results.len());
|
results.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we saw any comments while parsing the instruction, they will have been recorded as
|
|
||||||
// belonging to `NO_INST`.
|
|
||||||
self.rewrite_last_comment_entities(NO_INST, inst);
|
|
||||||
|
|
||||||
// Now map the source result values to the just created instruction results.
|
// Now map the source result values to the just created instruction results.
|
||||||
// Pass a reference to `ctx.values` instead of `ctx` itself since the `Values` iterator
|
// Pass a reference to `ctx.values` instead of `ctx` itself since the `Values` iterator
|
||||||
// holds a reference to `ctx.function`.
|
// holds a reference to `ctx.function`.
|
||||||
|
|||||||
Reference in New Issue
Block a user