Пример #1
0
def test_convert_to_ssa_instr_phi():
	''' Test ssa conversion with a more complicated phi case. '''
	args = {}
	block_size = (4, 4)
	def codegen(code, block_size, args):
		with scoped_alloc(code, 4) as (a, b, c, d):
			yield Imm(a, 1)
			yield Imm(b, 2)
			yield Cmp(a, b)
			yield Inv(c, a, cond='LE')
			yield Imm(a, 3) # to check if a is captured before new assignment
			yield Mov(c, b, cond='GT')
			yield Mov(d, c)
	expect = '''
imm r0~0, 1
imm r1~0, 2
cmp r0~0, r1~0
inv tmp_1, r0~0
imm r0~1, 3
mov tmp_0, r1~0
phi{LE} r2~1, tmp_1, tmp_0
mov r3~1, r2~1
'''
	convertor = CodegenToSSAConvertor(100)
	ref_code = convert_code_to_compact_repr(list(codegen(Code(), block_size, args)))
	test_code = convert_compact_repr_to_obj(convertor._convert_code_to_ssa(ref_code)[0])
	assert match_code(test_code, expect)
Пример #2
0
	def __init__(self, code, trace, reg_used):
		self.code = code
		# needs to copied because this trace is modified.
		self.trace = trace[:]
		self.compact_trace = convert_code_to_compact_repr(self.trace)
		self.reg_used = reg_used[:]
		self.ptr = 0
Пример #3
0
def test_convert_to_ssa_easy():
	''' Test for the simple case without any branches. '''
	args = {}
	block_size = (4, 4)
	def codegen(code, block_size, args):
		with scoped_alloc(code, 2) as (a, b):
			yield Imm(a, 1)
			yield Imm(b, 2)
			yield Add(a, a, b)
	expect = '''
imm r0~0, 1
imm r1~0, 2
add r0~1, r0~0, r1~0
'''
	convertor = CodegenToSSAConvertor(100)
	ref_code = convert_code_to_compact_repr(list(codegen(Code(), block_size, args)))
	test_code = convert_compact_repr_to_obj(convertor._convert_code_to_ssa(ref_code)[0])
	
	assert match_code(test_code, expect)
Пример #4
0
def test_convert_to_ssa_ports():
	''' Test for the simple case without any branches, with port communication. '''
	args = {}
	block_size = (4, 4)
	def codegen(code, block_size, args):
		with scoped_alloc(code, 2) as (a, b):
			yield Imm(a, 1)
			yield Mov(code.out, a)
			yield Mov(b, code.east)
			yield Add(a, a, b)
	expect = '''
imm r0~0, 1
mov out, r0~0
mov r1~0, east
add r0~1, r0~0, r1~0
'''
	convertor = CodegenToSSAConvertor(100)
	ref_code = convert_code_to_compact_repr(list(codegen(Code(), block_size, args)))
	test_code = convert_compact_repr_to_obj(convertor._convert_code_to_ssa(ref_code)[0])
	assert match_code(test_code, expect)
Пример #5
0
	def _convert_code_to_ssa_adapter(self, source_fragment, code_start_ind = 0, regs_used_buffer = []):
		''' First convert code to compiler format before executing _convert_code_to_ssa. '''
		code_buffer, regs_used_buffer = source_fragment.instructions, source_fragment.regs_used
		res_code, res_usage = self._convert_code_to_ssa(convert_code_to_compact_repr(code_buffer), code_start_ind, regs_used_buffer)
		return CodeFragment(res_code, res_usage)