当前位置: 首页>>代码示例>>Python>>正文


Python Suppress.transformString方法代码示例

本文整理汇总了Python中pyparsing.Suppress.transformString方法的典型用法代码示例。如果您正苦于以下问题:Python Suppress.transformString方法的具体用法?Python Suppress.transformString怎么用?Python Suppress.transformString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyparsing.Suppress的用法示例。


在下文中一共展示了Suppress.transformString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import transformString [as 别名]
def main():
   filename = sys.argv[1]
   source = open(filename).read()
   commentFilter = Suppress( javaStyleComment ).ignore( dblQuotedString )
   source = commentFilter.transformString(source)
   
   source = source.replace('\r\n', '\n')
   source = source.replace('\r', '')
   
   for m in re.finditer('#pragma[ \t][ \t]*pskel.*\n', source):
      pragma = m.group(0)
      begin = m.start(0)
      end = m.end(0)+1
      while pragma.strip()[-1]=='\\':
         pragma = pragma.strip()[:-1].strip()
         tmp = ''
         while source[end]!='\n':
            tmp += source[end]
            end += 1
         pragma += ' '+tmp.strip()
         end += 1
      pragma = pragma.strip()
      print begin, end
      print pragma
      #print source[begin:end]
      pinfo = parsePragma(pragma)
      print pinfo
      fcall = readFuncCall(source,end)
      print fcall
      
      kfunc = findFunctionDef(source,fcall[0])
      
      print source[fcall[2]:fcall[3]]
      mainf = readOutterFunction(source, begin)
      #print mainf
      fcall_name = '_pskelcc_stencil_'+str(fcall[2])+'_'+str(fcall[3])
      tmainf = mainf['src'].replace(source[begin:end],'\n').replace(source[fcall[2]:fcall[3]],fcall_name+'();')
      print tmainf
      parser = c_parser.CParser()
      ast = parser.parse(tmainf)
      pgen = PSkelGenerator(pinfo,fcall_name)
      new_mainf = pgen.visit(ast)
      
      parser = c_parser.CParser()
      ast = parser.parse(kfunc['src'])
      pgen = PSkelKernelGenerator(pinfo)
      new_kfunc = pgen.visit(ast)
      
      f = open(sys.argv[2],'w')
      
      f.write('#define PSKEL_OMP\n')
      if pinfo['device']=='gpu':
         f.write('#define PSKEL_CUDA\n')
      f.write('''
#include "include/PSkel.h"
using namespace PSkel;\n\n''')
      f.write(source[:kfunc['begin']]+new_kfunc+source[kfunc['end']:mainf['begin']]+new_mainf+source[mainf['end']:])
      f.close()
开发者ID:pskel,项目名称:benchmarks,代码行数:60,代码来源:pskelcc.py

示例2: parse_ttable

# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import transformString [as 别名]
 def parse_ttable(f):
     ttable = {}
     # com = Suppress('[') + ZeroOrMore(CharsNotIn(']')) + Suppress(']')
     com = Suppress('[' + ZeroOrMore(CharsNotIn(']') + ']'))
     while True:
         s = next(f).strip()
         if not s:
             continue
         s = com.transformString(s).strip()
         if s.lower() == ";":
             break
         b = False
         if s[-1] in ",;":
             if s[-1] == ';':
                 b = True
             s = s[:-1]
         # print(s)
         k, v = s.split()
         ttable[k] = v
         if b:
             break
     return ttable
开发者ID:rhr,项目名称:ivy,代码行数:24,代码来源:nexus.py

示例3: main

# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import transformString [as 别名]
def main():
   filename = sys.argv[1]
   source = open(filename).read()
   commentFilter = Suppress( javaStyleComment ).ignore( dblQuotedString )
   source = commentFilter.transformString(source)
   
   source = source.replace('\r\n', '\n')
   source = source.replace('\r', '')
   
   for m in re.finditer('#pragma[ \t][ \t]*pskel.*\n', source):
      pragma = m.group(0)
      begin = m.start(0)
      end = m.end(0)+1
      while pragma.strip()[-1]=='\\':
         pragma = pragma.strip()[:-1].strip()
         tmp = ''
         while source[end]!='\n':
            tmp += source[end]
            end += 1
         pragma += ' '+tmp.strip()
         end += 1
      pragma = pragma.strip()
      print begin, end
      print pragma
      print source[begin:end]
      pinfo = parsePragma(pragma)
      print pinfo
      fcall = readFuncCall(source,end)
      print fcall
      extraArgs = parseExtraArgs(fcall['args'],pinfo)
      print 'ExtraArgs:',extraArgs
      if len(extraArgs)>0:
         print 'TODO: create a struct for passing the extra arguments to the PSkel stencil kernel'
         print 'gather the types of the extra arguments from the original kernel function declaration'

      kfunc = findFunctionDef(source,fcall['name'])
      
      print fcall['src']
      mainf = readOutterFunction(source, begin)
      #print mainf
      fcall_name = '_pskelcc_stencil_'+str(fcall['begin'])+'_'+str(fcall['end'])
      tmainf = mainf['src'].replace(source[begin:end],'\n').replace(fcall['src'],fcall_name+'();')
      print tmainf
      parser = c_parser.CParser()
      ast = parser.parse(tmainf)
      pgen = PSkelGenerator(pinfo,fcall_name)
      new_mainf = pgen.visit(ast)
      receivedParameters = pgen.receivedParameters
         
      parser = c_parser.CParser()
      ast = parser.parse(kfunc['src'])
      pgen = PSkelKernelGenerator(pinfo)
      new_kfunc = pgen.visit(ast)
      
      src = source.replace(mainf['src'],new_mainf).replace(kfunc['src'],new_kfunc)

      while len(receivedParameters)>0:
         print 'TODO: Trace arguments back to original definition',pgen.receivedParameters
         print 'Searching for caller of function',mainf['name']
         #print findFunctionCall(src,mainf['name'])
         receivedParameters = []
         #src = src.replace(...)

      f = open(sys.argv[2],'w')
      
      f.write('#define PSKEL_OMP\n')
      if pinfo['device']=='gpu':
         f.write('#define PSKEL_CUDA\n')
      f.write('''
#include "PSkel.h"
using namespace PSkel;\n\n''')
      f.write(src)
      f.close()
开发者ID:pskel,项目名称:benchmarks,代码行数:75,代码来源:pskelccv2.py


注:本文中的pyparsing.Suppress.transformString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。