def gen_api(opts): filename = common.get_markdown_file(opts, 'api', 'fixed_point') with common.open_utf8(opts, filename) as fout: fout.write('''# NSIMD fixed point API\n''') for cat in fp_categories: ops = [op for op in fp_operators if cat in op.categories] if (len(ops) == 0): continue fout.write('\n## {}\n\n'.format(cat)) for op in ops: fout.write( '- [{} ({})](module_fixed_point_api_{}.md)\n'\ .format(op.full_name, op.name, common.to_filename(op.name)))
def gen_api(opts, op_list): api = dict() for _, operator in operators.operators.items(): if operator.name not in op_list: continue for c in operator.categories: if c not in api: api[c] = [operator] else: api[c].append(operator) filename = common.get_markdown_file(opts, 'api', 'fixed_point') with common.open_utf8(opts, filename) as fout: fout.write('''# NSIMD fixed point API\n''') for c, ops in api.items(): if len(ops) == 0: continue fout.write('\n## {}\n\n'.format(c.title)) for op in ops: fout.write('- [{} ({})](module_fixed_point_api_{}.md)\n'. \ format(op.full_name, op.name, common.to_filename(op.name)))
def gen_doc(opts): common.myprint(opts, 'Generating doc for each function') # Build tree for api.md api = dict() for _, operator in operators.items(): for c in operator.categories: if c not in api: api[c] = [operator] else: api[c].append(operator) # api.md # filename = os.path.join(opts.script_dir, '..','doc', 'markdown', 'api.md') filename = common.get_markdown_file(opts, 'api') if common.can_create_filename(opts, filename): with common.open_utf8(opts, filename) as fout: fout.write('# General API\n\n') fout.write('- [Memory function](memory.md)\n') fout.write('- [Float16 related functions](fp16.md)\n') fout.write('- [Defines provided by NSIMD](defines.md)\n') fout.write('- [NSIMD pack and related functions](pack.md)\n\n') fout.write('- [NSIMD C++20 concepts](concepts.md)\n\n') fout.write('# SIMD operators\n') for c, ops in api.items(): if len(ops) == 0: continue fout.write('\n## {}\n\n'.format(c.title)) for op in ops: Full_name = op.full_name[0].upper() + op.full_name[1:] fout.write('- [{} ({})](api_{}.md)\n'.format( Full_name, op.name, common.to_filename(op.name))) # helper to get list of function signatures def to_string(var): sigs = [var] if type(var) == str or not hasattr(var, '__iter__') \ else list(var) for i in range(0, len(sigs)): sigs[i] = re.sub('[ \n\t\r]+', ' ', sigs[i]) return '\n'.join(sigs) # Operators (one file per operator) # dirname = os.path.join(opts.script_dir, '..','doc', 'markdown') dirname = common.get_markdown_dir(opts) common.mkdir_p(dirname) for op_name, operator in operators.items(): # Skip non-matching doc if opts.match and not opts.match.match(op_name): continue # filename = os.path.join(dirname, 'api_{}.md'.format(common.to_filename( # operator.name))) filename = common.get_markdown_api_file(opts, operator.name) if not common.can_create_filename(opts, filename): continue Full_name = operator.full_name[0].upper() + operator.full_name[1:] with common.open_utf8(opts, filename) as fout: fout.write('# {}\n\n'.format(Full_name)) fout.write('## Description\n\n') fout.write(operator.desc) fout.write('\n\n## C base API (generic)\n\n') fout.write('```c\n') fout.write(to_string(operator.get_generic_signature('c_base'))) fout.write('\n```\n\n') fout.write('\n\n## C advanced API (generic, requires C11)\n\n') fout.write('```c\n') fout.write(to_string(operator.get_generic_signature('c_adv'))) fout.write('\n```\n\n') fout.write('## C++ base API (generic)\n\n') fout.write('```c++\n') fout.write(to_string(operator.get_generic_signature('cxx_base'))) fout.write('\n```\n\n') fout.write('## C++ advanced API\n\n') fout.write('```c++\n') fout.write(to_string(operator.get_generic_signature('cxx_adv'). \ values())) fout.write('\n```\n\n') fout.write('## C base API (architecture specifics)') for simd_ext in opts.simd: fout.write('\n\n### {}\n\n'.format(simd_ext.upper())) fout.write('```c\n') for typ in operator.types: fout.write(operator.get_signature(typ, 'c_base', simd_ext)) fout.write(';\n') fout.write('```') fout.write('\n\n## C++ base API (architecture specifics)') for simd_ext in opts.simd: fout.write('\n\n### {}\n\n'.format(simd_ext.upper())) fout.write('```c\n') for typ in operator.types: fout.write( operator.get_signature(typ, 'cxx_base', simd_ext)) fout.write(';\n') fout.write('```')
def gen_doc(opts): sys.stdout.write('-- Generating doc for each function\n') # Build tree for api.md api = dict() for _, operator in operators.items(): for c in operator.categories: if c not in api: api[c] = [operator] else: api[c].append(operator) # helper to construct filename for operator # def to_filename(op_name): # valid = string.ascii_letters + string.digits # ret = '' # for c in op_name: # ret += '-' if c not in valid else c # return ret # api.md # filename = os.path.join(opts.script_dir, '..','doc', 'markdown', 'api.md') filename = common.get_markdown_file(opts, 'api') if common.can_create_filename(opts, filename): with common.open_utf8(opts, filename) as fout: fout.write('# API\n') for c, ops in api.items(): if len(ops) == 0: continue fout.write('\n## {}\n\n'.format(c.title)) for op in ops: Full_name = op.full_name[0].upper() + op.full_name[1:] fout.write('- [{} ({})](api_{}.md)\n'.format( Full_name, op.name, common.to_filename(op.name))) # helper to get list of function signatures def to_string(var): sigs = [var] if type(var) == str or not hasattr(var, '__iter__') \ else list(var) for i in range(0, len(sigs)): sigs[i] = re.sub('[ \n\t\r]+', ' ', sigs[i]) return '\n'.join(sigs) # Operators (one file per operator) # dirname = os.path.join(opts.script_dir, '..','doc', 'markdown') dirname = common.get_markdown_dir(opts) common.mkdir_p(dirname) for op_name, operator in operators.items(): # Skip non-matching doc if opts.match and not opts.match.match(op_name): continue # filename = os.path.join(dirname, 'api_{}.md'.format(common.to_filename( # operator.name))) filename = common.get_markdown_api_file(opts, operator.name) if not common.can_create_filename(opts, filename): continue Full_name = operator.full_name[0].upper() + operator.full_name[1:] with common.open_utf8(opts, filename) as fout: fout.write('# {}\n\n'.format(Full_name)) fout.write('## Description\n\n') fout.write(operator.desc) fout.write('\n\n## C base API (generic)\n\n') fout.write('```c\n') fout.write(to_string(operator.get_generic_signature('c_base'))) fout.write('\n```\n\n') fout.write('## C++ base API (generic)\n\n') fout.write('```c++\n') fout.write(to_string(operator.get_generic_signature('cxx_base'))) fout.write('\n```\n\n') fout.write('## C++ advanced API\n\n') fout.write('```c++\n') fout.write(to_string(operator.get_generic_signature('cxx_adv'). \ values())) fout.write('\n```\n\n') fout.write('## C base API (architecture specifics)') for simd_ext in opts.simd: fout.write('\n\n### {}\n\n'.format(simd_ext.upper())) fout.write('```c\n') for typ in operator.types: fout.write(operator.get_signature(typ, 'c_base', simd_ext)) fout.write(';\n') fout.write('```') fout.write('\n\n## C++ base API (architecture specifics)') for simd_ext in opts.simd: fout.write('\n\n### {}\n\n'.format(simd_ext.upper())) fout.write('```c\n') for typ in operator.types: fout.write( operator.get_signature(typ, 'cxx_base', simd_ext)) fout.write(';\n') fout.write('```')