Mercurial > hg > Members > shinya > pyrect
view src/converter.py @ 18:ec36e784df2e
add LLVMTranslator(Translator) (and remove reg2llvm.py), add --LLVM option to converter.py.
author | Ryoma SHINYA <shinya@firefly.cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 05 Jul 2010 08:36:11 +0900 |
parents | 11fba907c0af |
children | d40b248a526b |
line wrap: on
line source
#!/usr/bin/env python import sys from dfareg import Regexp, CallGraph from cTranslator import CTranslator from cbcTranslator import CbCTranslator from dotTranslator import DotTranslator from llvm_translator import LLVMTranslator from optparse import OptionParser def main(argv): myusage = "%prog [-C] regexp" psr = OptionParser(usage=myusage) psr.add_option("--CbC", action="store_true", dest="emit_cbc", default=False, help="emit CbC-source") psr.add_option("--LLVM", action="store_true", dest="emit_llvm", default=False, help="emit LLVM-source") psr.add_option("--Dot", action="store_true", dest="emit_dot", default=False, help="emit Dot-source") psr.add_option("--from-dfa", action="store_true", dest="dfa", default=True, help="translate from DFA") psr.add_option("--from-nfa", action="store_true", dest="nfa", default=False, help="translate from NFA") psr.add_option("-o", action="store", type="string", dest="output", default=False, help="output file", metavar="FILE") psr.add_option("-O", action="store", type="string", dest="optimize", default=False, help="do optimization (only in llvm).", metavar="FILE") psr.add_option("-L", action="store_true", dest="label", default=False, help="implement with label&goto. (only in llvm).") psr.add_option("-g", action="store_true", dest="debug", default=False, help="embed debug info") psr.add_option("-D", action="store_true", dest="emitDot", default=False, help="emit Dot file") (opts, args) = psr.parse_args(sys.argv) if len(args) == 1: psr.print_help() exit() reg = Regexp(args[1]) if not opts.output: output = sys.stdout else: output = open(opts.output,"w") if opts.nfa: fa = reg.nfa else: fa = reg.dfa if opts.emit_dot: translator = DotTranslator(reg.regexp, CallGraph(fa)) translator.debug = opts.debug elif opts.emit_llvm: translator = LLVMTranslator(reg.regexp, CallGraph(fa)) translator.debug = opts.debug translator.optimize = opts.optimize translator.impl_label = opts.label elif opts.emit_cbc: translator = CbCTranslator(reg.regexp, CallGraph(fa)) translator.debug = opts.debug else: translator = CTranslator(reg.regexp, CallGraph(fa)) translator.debug = opts.debug translator.translate(output) if __name__ == '__main__' : main(sys.argv)