Mercurial > hg > Members > shinya > pyrect
changeset 37:95fd780875bf
bug fix: LLVMGREPTranslator.
author | Ryoma SHINYA <shinya@firefly.cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 11 Jul 2010 23:04:48 +0900 |
parents | 71fa409932bd |
children | 06826250198b |
files | pyrect/llvm_grep_translator.py pyrect/llvm_translator.py |
diffstat | 2 files changed, 11 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/pyrect/llvm_grep_translator.py Sun Jul 11 22:54:39 2010 +0900 +++ b/pyrect/llvm_grep_translator.py Sun Jul 11 23:04:48 2010 +0900 @@ -7,14 +7,17 @@ from dfareg import Regexp, CallGraph class LLVMGREPTranslator(LLVMTranslator): - """LLVMTranslator - This Class can translate from DFA or NFA into LLVM-IR. - and also can JIT-Compile/evaluate it's self using llvm-py. + """LLVMGREPTranslator + This class can translate from DFA into grep LLVM-module. + which can translate LLVM-IR, and also can execute it's self. >>> string = 'def' >>> reg = Regexp(string) >>> dfacg = CallGraph(reg.dfa) >>> lt = LLVMGREPTranslator(string, dfacg) >>> lt.translate() + >>> ret = lt.execute() + >>> isinstance(ret, llvm.ee.GenericValue) + True """ def __init__(self, regexp, cg):
--- a/pyrect/llvm_translator.py Sun Jul 11 22:54:39 2010 +0900 +++ b/pyrect/llvm_translator.py Sun Jul 11 23:04:48 2010 +0900 @@ -57,7 +57,7 @@ emit.ret(ret) self.main = main - def _compile(self): + def jitcompile(self): self.matchp_str = self.new_str_const(self.string) self.debug_str = self.new_str_const("state: %s, arg: %c(int %d)\n") @@ -134,11 +134,11 @@ def emit_from_callgraph(self): if not self.compiled: - self._compile() + self.jitcompile() self.emit(str(self.llvm_module)) def get_execution_engine(self): if not self.compiled: - self._compile() + self.jitcompile() return self.ee def do_optimize(self): @@ -160,12 +160,12 @@ def print_module(self): if not self.compiled: - self._compile() + self.jitcompile() print self.llvm_module def execute(self): if not self.compiled: - self._compile() + self.jitcompile() return self.ee.run_function(self.main, (GenericValue.int(self.int_t, 0),))