Switch IR to use Option<Target>

This commit is contained in:
Maxime Chevalier-Boisvert 2022-05-12 14:05:48 -04:00 committed by Takashi Kokubun
parent 96e5f9def0
commit 92e9d1e661
No known key found for this signature in database
GPG Key ID: 6FFC433B12EE23DD

View File

@ -44,10 +44,7 @@ pub enum Op
// operand (typically generated by ir_str_ptr).
Comment,
// Add a label into the IR at the point that this instruction is added. It
// will eventually be translated into an offset when generating code such
// that EIR_LABEL_IDX operands know where to jump to. Accepts as its only
// operand an EIR_LABEL_NAME operand (typically generated by ir_label_opnd).
// Add a label into the IR at the point that this instruction is added.
Label,
// Add two operands together, and return the result as a new operand. This
@ -323,7 +320,7 @@ enum Target
{
CodePtr(CodePtr), // Pointer to a piece of code (e.g. side-exit)
LabelName(String), // A label without an index in the output
LabelIdx(u32), // A label that has been indexed
LabelIdx(usize), // A label that has been indexed
}
/// YJIT IR instruction
@ -335,9 +332,8 @@ pub struct Insn
// List of input operands/values
opnds: Vec<Opnd>,
// Kevin asks: do we really need multiple branch targets?
// List of branch targets (branch instructions only)
targets: Vec<Target>,
target: Option<Target>,
// Position in the generated machine code
// Useful for comments and for patching jumps
@ -359,14 +355,14 @@ impl Assembler
}
}
fn push_insn(&mut self, op: Op, opnds: Vec<Opnd>, targets: Vec<Target>) -> Opnd
fn push_insn(&mut self, op: Op, opnds: Vec<Opnd>, target: Option<Target>) -> Opnd
{
let insn_idx = self.insns.len();
let insn = Insn {
op: op,
opnds: opnds,
targets: targets,
target: target,
pos: None
};
self.insns.push(insn);
@ -375,10 +371,26 @@ impl Assembler
Opnd::InsnOut(insn_idx)
}
// TODO:
//fn label(&self, name: &str) -> Target
//{
//}
// Add a label at the current position
fn label(&mut self, name: &str) -> Target
{
let insn_idx = self.insns.len();
let insn = Insn {
op: Op::Label,
opnds: vec![],
target: None,
pos: None
};
self.insns.push(insn);
Target::LabelIdx(insn_idx)
}
fn alloc_regs(&mut self)
{
// ???
}
// Optimize and compile the stored instructions
fn compile()
@ -395,32 +407,25 @@ impl Assembler
// Add a comment, no output operand
fn comment(&mut self, text: &str)
{
self.push_insn(Op::Add, vec![ Opnd::String(text.to_owned()) ], vec![]);
self.push_insn(Op::Add, vec![ Opnd::String(text.to_owned()) ], None);
}
/*
fn add(&mut self, opnd0: Opnd, opnd1: Opnd) -> Opnd
{
self.push_insn(Op::Add, vec![opnd0, opnd1], vec![])
}
*/
// Low-level, no output operand
fn test(&mut self, opnd0: Opnd, opnd1: Opnd)
{
self.push_insn(Op::Add, vec![opnd0, opnd1], vec![]);
self.push_insn(Op::Add, vec![opnd0, opnd1], None);
}
// Low-level, no output operand
fn mov(&mut self, opnd0: Opnd, opnd1: Opnd)
{
self.push_insn(Op::Add, vec![opnd0, opnd1], vec![]);
self.push_insn(Op::Add, vec![opnd0, opnd1], None);
}
// Jump if not zero
fn jnz(&mut self, target: Target)
{
self.push_insn(Op::Jnz, vec![], vec![target]);
self.push_insn(Op::Jnz, vec![], Some(target));
}
}
@ -430,7 +435,7 @@ macro_rules! def_push_insn_2_opnd {
{
fn $op_name(&mut self, opnd0: Opnd, opnd1: Opnd) -> Opnd
{
self.push_insn($opcode, vec![opnd0, opnd1], vec![])
self.push_insn($opcode, vec![opnd0, opnd1], None)
}
}
};