Пример #1
0
def test_jmp_codegen():
	from blip.code.BlipCompiler import NamedValue, JmpValue, Codegenerator, Comparison
	kernelObject = KernelObject('test')
	kernelObject.values = [\
		(NamedValue('cmp', seq_value=True), Comparison(NamedValue('x', seq_value=True), 'Gt', NamedValue('y', seq_value=True))),
		(NamedValue('tmp', seq_value=True), JmpValue(NamedValue('cmp'), NamedValue('for_3')))
	]
	codegen = Codegenerator(Compiler())
	kernelObject = codegen.gen_code(kernelObject)
	code = [InstrAdapter(x) for x in kernelObject.code]

	pattern = '''
xcmp x, y
xjmp {GT} for_3
'''
	assert match_code(code, pattern)
Пример #2
0
def test_phi_codegen():
	from blip.code.BlipCompiler import NamedValue, PhiValue, Codegenerator, Comparison
	kernelObject = KernelObject('test')
	kernelObject.values = [\
		(NamedValue('cmp'), Comparison(NamedValue('x'), 'Gt', NamedValue('y'))),
		(NamedValue('z'), PhiValue(NamedValue('cmp'), NamedValue('x'), NamedValue('y')))
	]
	codegen = Codegenerator(Compiler())
	kernelObject = codegen.gen_code(kernelObject)
	code = [InstrAdapter(x) for x in kernelObject.code]

	pattern = '''
cmp x, y
phi {GT} z, x, y
'''
	assert match_code(code, pattern)