Esempio n. 1
0
def mdoc_structure_type((cu, die)):
	cv = (cu, die)
	# struct <name> " {" [<member>] " };"
	return bind(mdoc_name(cv), lambda name:
		   bind(mdoc_decl_function_struct_type_getter(cv), lambda struct_getter:
		   bind(unit(die.iter_children()), lambda members:
		   bind(sequence([mdoc_member((cu, member)) for member in members]), lambda docMembers:
		   unit(P.text("struct ") + name + P.space() + P.block(intersperse(docMembers, P.newline())) + P.text(";") + P.newline() + struct_getter)))))
Esempio n. 2
0
def gen_vw_command(mod):
    mod.vw_options = format_setting(mod.vw_run_tmplt, mod.param)
    vw_options_list = []
    for k, v in mod.vw_options.items():
        vw_options_list.append('--'+str(k))
        vw_options_list.append(str(v))
    cmd = intersperse([mod.vw_path]+vw_options_list, ' ')
    return cmd
Esempio n. 3
0
def mdoc_compile_unit((cu, die)):
	notOrdered = [child for child in die.iter_children()]

	# all subprogram which is a kind of function should be placed at bottom
	children = flatten(splitBy(isTagNotSubprogram, notOrdered))
	# [M doc]
	definitions = [mdoc((cu, child)) for child in children]
	# (a -> b) -> F  a -> F b
	return fmap(lambda xs: flatten(intersperse(xs, P.newline())), 
				sequence(definitions))
Esempio n. 4
0
def mdoc_typedef_fp(cv):
	m_subroutine = chain(unit(cv), [mdie_type, mdie_type])

	m_params = bind(m_subroutine, lambda ((cu, die)):
		sequence([mdoc_formalparameter((cu, child)) for child in die.iter_children()])
	)
	m_docParams = bind(m_params, lambda docs: unit(intersperse(docs, P.comma())))
	m_returnType = chain(m_subroutine, [mdie_type, mdoc_typeref])
	
	return bind(m_returnType, lambda ret:
		   bind(m_docParams, lambda params:
		   bind(mdoc_name(cv), lambda name:
		   unit(P.text("typedef ") + ret + P.text(" (*") + name + P.text(") ") + P.text('(') + params + P.text(');')))))
Esempio n. 5
0
def mdoc_subprogram_legacy(cv):
	(cu, die) = cv
	# <return-type> <function-name> <params>	
	name = mdoc_name(cv)
	typeDie = mdie_type(cv) 
	# TODO: use Monad. if die has no DW_AT_type, return P.text("void "), otherwise typeref(die.type)
	returnType = mkDoc_typeref(cu, typeDie) if typeDie else P.text("void ")
	params = [mkDoc_formalparameter(cu, child) for child in die.iter_children()
									   if child.tag == 'DW_TAG_formal_parameter']
	paramsCallback = params + P.text("int stubCallCount")

	varType = P.text("STUBGEN_") + value(name) + P.text("_CALLBACK")
	decl_typedef_callback = mkDoc_decl_typedef_fp(returnType, paramsCallback, varType)
	
	
	varFp = value(name) + P.text("_Callback")
	value = P.text("(") + varType + P.text(") 0")
	decl_var_callback_fp = doc_decl_static_var(varType, varFp, value)

	# [M doc]
	paramNamesCallback = [mdoc_name(cu, child) for child in die.iter_children()
				if child.tag == 'DW_TAG_formal_parameter'] + P.text("stubCallCount++")
	callExp = mkDoc_exp_function_call(varFp, sequence(paramNamesCallback))
	thenBlock = P.block(P.text("static int stubCallCount = 0;") + P.newline() + (P.text("return ") if typeDie else P.empty()) + callExp + P.text(";"))
	# FIXME: use monad
	elseBlock = P.block(doc_stmt_return(value(mdoc_exp_call_default_type_value(cv))))
	if_stmt = doc_stmt_if(varFp, thenBlock, elseBlock)
	# return, name, params, block
	stub_function = doc_decl_function(returnType, name, params, P.block(if_stmt))

	# decl callback setter function
	# void XXX_StubWithCallback (STUBGEN_XXX_CALLBACK cb)
	setter = name + P.text('_StubWithCallback')
	setter_param = [varType + P.text(' cb')] 
	setter_body = P.block(varFp + P.text(' = cb;'))
	setter_function = doc_decl_function(P.text('void'), setter, setter_param, setter_body)
	return intersperse([decl_typedef_callback, decl_var_callback_fp, stub_function, setter_function], P.newline()) + P.newline() 
Esempio n. 6
0
def doc_decl_function(retType, fname, params, body):
	assert body
	assert len(body) >= 2
	assert body[0] == '{'
	return retType + P.space() + fname + P.text(" (") + intersperse(params, P.comma()) + P.text(") ") + body
Esempio n. 7
0
def doc_exp_function_call(function_name, argList):
	return function_name + P.text("(") + intersperse(argList, P.comma() + P.space()) + P.text(")")
Esempio n. 8
0
def mkDoc_decl_typedef_fp(returnType, params, typedefName):
	return P.text("typedef ") + returnType + P.text("(*") + typedefName + P.text(")") + P.text("(") + intersperse(params, P.text(', ')) + P.text(");")
Esempio n. 9
0
def write_row(fn, row, mode):
    summary_file = open(fn, mode)
    if mode == 'a':
        summary_file.truncate()
    summary_file.write(intersperse(row, '\t') + '\n')
    summary_file.close()