Add source location support to FuncCursor and EncCursor.

A cursor now also remembers a current source location which will be
assigned to all new instructions created with the cursor.

The old layout::Cursor can't support source locations because it doesn't
have a reference to the full ir::Function.
This commit is contained in:
Jakob Stoklund Olesen
2017-09-21 10:38:11 -07:00
parent b2a314a229
commit 4d4da2dc60
9 changed files with 143 additions and 38 deletions

View File

@@ -358,6 +358,7 @@ def gen_xform_group(xgrp, fmt, type_sets):
'cfg: &mut ::flowgraph::ControlFlowGraph) -> '
'bool {{'.format(xgrp.name), '}'):
fmt.line('use ir::{InstBuilder, CursorBase};')
fmt.line('let srcloc = func.srclocs[inst];')
# Group the xforms by opcode so we can generate a big switch.
# Preserve ordering.
@@ -372,8 +373,9 @@ def gen_xform_group(xgrp, fmt, type_sets):
with fmt.indented(
'ir::Opcode::{} => {{'.format(camel_name), '}'):
fmt.line(
'let pos = &mut '
'ir::Cursor::new(&mut func.layout)'
'let pos = &mut ir::Cursor::new'
'(&mut func.layout, &mut func.srclocs)'
'.with_srcloc(srcloc)'
'.at_inst(inst);')
fmt.line('let dfg = &mut func.dfg;')
for xform in xforms[camel_name]: