Пример #1
0
def gen_executor(mapir):
	from iegen.codegen import Function,gen_index_array
	from iegen.idg.visitor import ParamVisitor,DeclVisitor,OutputERVisitor

	#Create the executor function with the necessary parameters
	executor=Function(iegen.settings.executor_name,'void',ParamVisitor().visit(mapir.idg).get_params())

	#Add the necessary variable declarations
	executor.body.extend(DeclVisitor(mapir).visit(mapir.idg).get_decls())

	#Generate wrappers for the index arrays
	for index_array in mapir.get_index_arrays():
		executor.body.extend(gen_index_array(index_array))

	#Generate assignment statements for the output ERs
	executor.body.extend(OutputERVisitor(mapir).visit(mapir.idg).get_assigns())

	#Generate the loop statement definitions
	executor.body.extend(gen_executor_loop_stmts(mapir))
	executor.newline()

	#Generate the loop body using CLooG
	executor.body.extend(gen_executor_loop(mapir))
	executor.newline()

	#Generate the loop statement undefines
	executor.body.extend(gen_executor_undefs(mapir))
	executor.newline()

	return executor
Пример #2
0
def gen_inspector(mapir):
	from iegen.codegen import Function
	from iegen.idg.visitor import ParamVisitor,DeclVisitor,CodegenVisitor

	#Create the inspector function with the necessary parameters
	inspector=Function(iegen.settings.inspector_name,'void',ParamVisitor().visit(mapir.idg).get_params())

	#If there are no transformations, don't bother doing any codegen
	if len(mapir.transformations)>0:
		#Add the necessary variable declarations
		inspector.body.extend(DeclVisitor(mapir).visit(mapir.idg).get_decls())
		inspector.newline()

		#Add the code for the body of the inspector
		inspector.body.extend(CodegenVisitor(mapir).visit(mapir.idg).stmts)

		#Add the code to free any necessary memory
		#TODO: Need to add a visitor that adds destructor calls for the necessary ERs
		#      Also need to add a node to the IDG that represents deallocation of an ER
		#      when it is no longer needed
		#inspector.body.extend(gen_destroy_index_array_wrappers(mapir))

	return inspector