def map_functions(triple_arch, action, source, config, env, func_map_cmd, temp_fnmap_folder): """ Generate function map file for the current source. """ cmd = ctu_triple_arch.get_compile_command(action, config) cmd[0] = func_map_cmd cmd.insert(1, source) cmd.insert(2, '--') cmdstr = ' '.join(cmd) LOG.debug_analyzer("Generating function map using '%s'" % cmdstr) ret_code, stdout, err \ = analyzer_base.SourceAnalyzer.run_proc(cmdstr, env, action.directory) if ret_code != 0: LOG.error("Error generating function map." "\n\ncommand:\n\n%s\n\nstderr:\n\n%s", cmdstr, err) return func_src_list = stdout.splitlines() func_ast_list = func_map_list_src_to_ast(func_src_list) extern_fns_map_folder = os.path.join(config.ctu_dir, triple_arch, temp_fnmap_folder) if not os.path.isdir(extern_fns_map_folder): try: os.makedirs(extern_fns_map_folder) except OSError: pass if func_ast_list: with tempfile.NamedTemporaryFile(mode='w', dir=extern_fns_map_folder, delete=False) as out_file: out_file.write("\n".join(func_ast_list) + "\n")
def generate_ast(triple_arch, action, source, config, env): """ Generates ASTs for the current compilation command. """ ast_joined_path = os.path.join(config.ctu_dir, triple_arch, 'ast', os.path.realpath(source)[1:] + '.ast') ast_path = os.path.abspath(ast_joined_path) ast_dir = os.path.dirname(ast_path) if not os.path.isdir(ast_dir): try: os.makedirs(ast_dir) except OSError: pass cmd = ctu_triple_arch.get_compile_command(action, config, source) cmd.extend(['-emit-ast', '-w', '-o', ast_path]) cmdstr = ' '.join(cmd) LOG.debug_analyzer("Generating AST using '%s'" % cmdstr) ret_code, _, _ = analyzer_base.SourceAnalyzer.run_proc(cmdstr, env) if ret_code != 0: LOG.error("Error generating AST using '%s'", cmdstr)