コード例 #1
0
ファイル: instrumenter.py プロジェクト: lihebi/PyHelium
 def __init__(self):
     self.output_folder = config.get('output_folder')
     self.doc = domutil.get_doc_from_c_file(self.output_folder+'/generate.c')
     self.support_doc = domutil.get_doc_from_c_file(self.output_folder+'/support.h')
     # the fields used in the generated program.
     # this is a big heuristic
     self.needed_fields = set()
     # dict to hold {alias: name}
     self.alias_to_name = {}
     self.code = ''
     self.output_folder = config.get('output_folder')
     self.struct_limit = 0
     self.helium_size_defined = False
コード例 #2
0
ファイル: remove_comment.py プロジェクト: lihebi/PyHelium
def func(directory):
    for root,_,files in os.walk(directory):
        for f in files:
            if f.endswith('.c') or f.endswith('.h'):
                filename = os.path.join(root, f)
                print(filename)
                doc = domutil.get_doc_from_c_file(filename)
                for comment_node in doc.getElementsByTagName('comment'):
                    comment_node.parentNode.removeChild(comment_node)
                with open(filename, 'w') as f:
                    f.write(domutil.get_text_content(doc.documentElement))
コード例 #3
0
ファイル: reader.py プロジェクト: lihebi/PyHelium
 def start(self):
     for root,_,files in os.walk(self.folder):
         for f in files:
             if f.endswith('.c') and f != 'generate.c':
                 if config.get('file_include'):
                     if f.split('/')[-1] not in file_include: continue
                 if config.get('file_exclude'):
                     if f.split('/')[-1] in file_exclude: continue
                 filename = os.path.join(root, f)
                 doc = domutil.get_doc_from_c_file(filename)
                 segments = get_segments(doc)
                 if segments:
                     if config.get('show_filename') == 'true':
                         print(filename)
                     if config.get('interact_before_segment') == 'true':
                         c = input('Enter to start the file, anything to break the file ...')
                         if c: continue
                 for segment in segments:
                     self.handle_segment(doc, segment)
コード例 #4
0
ファイル: build_recursive.py プロジェクト: lihebi/PyHelium
def func(directory, output):
    if not output:
        logger.error('no output folder')
        exit(1)
    os.makedirs(output, exist_ok=True)
    with open(os.path.join(output, 'Makefile'), 'w') as f:
        f.write(makefile)
    count=0
    for root,_,files in os.walk(directory):
        for f in files:
            if f.endswith('.c'):
                filename = os.path.join(root, f)
                doc = domutil.get_doc_from_c_file(filename)
                for node in annotation.get_comment_nodes_by_annotation(doc, 'HeliumRecur'):
                    function_node = domutil.get_next_sibling_by_tagname(node, 'function')
                    if function_node:
                        code = build(function_node)
                        output_filename = os.path.join(output, 'recur'+str(count)+'.c')
                        count+=1
                        with open(output_filename,'w') as f:
                            f.write(code)
コード例 #5
0
ファイル: builder.py プロジェクト: lihebi/PyHelium
 def resolve(self):
     doc = domutil.get_doc_from_c_file(self.output_folder + "/generate.c")
     self.resolved = resolver.resolve(doc.documentElement, exception=self.functions.keys())