Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
Public Member Functions | Static Public Attributes | Private Attributes | Static Private Attributes | List of all members
miasm2.ir.translators.translator.Translator Class Reference
+ Inheritance diagram for miasm2.ir.translators.translator.Translator:
+ Collaboration diagram for miasm2.ir.translators.translator.Translator:

Public Member Functions

def register
 
def to_language
 
def available_languages
 
def __init__
 
def from_ExprInt
 
def from_ExprId
 
def from_ExprCompose
 
def from_ExprSlice
 
def from_ExprOp
 
def from_ExprMem
 
def from_ExprAff
 
def from_ExprCond
 
def from_expr
 

Static Public Attributes

list available_translators = []
 

Private Attributes

 _cache
 

Static Private Attributes

string __LANG__ = ""
 

Detailed Description

Definition at line 5 of file translator.py.

Constructor & Destructor Documentation

def miasm2.ir.translators.translator.Translator.__init__ (   self,
  cache_size = 1000 
)
Instance a translator
@cache_size: (optional) Expr cache size

Definition at line 38 of file translator.py.

38 
39  def __init__(self, cache_size=1000):
40  """Instance a translator
41  @cache_size: (optional) Expr cache size
42  """
43  self._cache = BoundedDict(cache_size)

Member Function Documentation

def miasm2.ir.translators.translator.Translator.available_languages (   cls)

Definition at line 34 of file translator.py.

34 
35  def available_languages(cls):
36  "Return the list of registered languages"
37  return [translator.__LANG__ for translator in cls.available_translators]
def miasm2.ir.translators.translator.Translator.from_expr (   self,
  expr 
)
Translate an expression according to its type
@expr: expression to translate

Definition at line 92 of file translator.py.

92 
93  def from_expr(self, expr):
94  """Translate an expression according to its type
95  @expr: expression to translate
96  """
97  # Use cache
98  if expr in self._cache:
99  return self._cache[expr]
100 
101  # Handle Expr type
102  handlers = {m2_expr.ExprInt: self.from_ExprInt,
103  m2_expr.ExprId: self.from_ExprId,
104  m2_expr.ExprCompose: self.from_ExprCompose,
105  m2_expr.ExprSlice: self.from_ExprSlice,
106  m2_expr.ExprOp: self.from_ExprOp,
107  m2_expr.ExprMem: self.from_ExprMem,
108  m2_expr.ExprAff: self.from_ExprAff,
109  m2_expr.ExprCond: self.from_ExprCond
110  }
111  for target, handler in handlers.iteritems():
112  if isinstance(expr, target):
113  ## Compute value and update the internal cache
114  ret = handler(expr)
115  self._cache[expr] = ret
116  return ret
117  raise ValueError("Unhandled type for %s" % expr)
118 

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.ir.translators.translator.Translator.from_ExprAff (   self,
  expr 
)
Translate an ExprAff
@expr: ExprAff to translate

Definition at line 80 of file translator.py.

80 
81  def from_ExprAff(self, expr):
82  """Translate an ExprAff
83  @expr: ExprAff to translate
84  """
85  raise NotImplementedError("Abstract method")

+ Here is the caller graph for this function:

def miasm2.ir.translators.translator.Translator.from_ExprCompose (   self,
  expr 
)
Translate an ExprCompose
@expr: ExprCompose to translate

Definition at line 56 of file translator.py.

56 
57  def from_ExprCompose(self, expr):
58  """Translate an ExprCompose
59  @expr: ExprCompose to translate
60  """
61  raise NotImplementedError("Abstract method")

+ Here is the caller graph for this function:

def miasm2.ir.translators.translator.Translator.from_ExprCond (   self,
  expr 
)
Translate an ExprCond
@expr: ExprCond to translate

Definition at line 86 of file translator.py.

86 
87  def from_ExprCond(self, expr):
88  """Translate an ExprCond
89  @expr: ExprCond to translate
90  """
91  raise NotImplementedError("Abstract method")

+ Here is the caller graph for this function:

def miasm2.ir.translators.translator.Translator.from_ExprId (   self,
  expr 
)
Translate an ExprId
@expr: ExprId to translate

Definition at line 50 of file translator.py.

50 
51  def from_ExprId(self, expr):
52  """Translate an ExprId
53  @expr: ExprId to translate
54  """
55  raise NotImplementedError("Abstract method")

+ Here is the caller graph for this function:

def miasm2.ir.translators.translator.Translator.from_ExprInt (   self,
  expr 
)
Translate an ExprInt
@expr: ExprInt to translate

Definition at line 44 of file translator.py.

44 
45  def from_ExprInt(self, expr):
46  """Translate an ExprInt
47  @expr: ExprInt to translate
48  """
49  raise NotImplementedError("Abstract method")

+ Here is the caller graph for this function:

def miasm2.ir.translators.translator.Translator.from_ExprMem (   self,
  expr 
)
Translate an ExprMem
@expr: ExprMem to translate

Definition at line 74 of file translator.py.

74 
75  def from_ExprMem(self, expr):
76  """Translate an ExprMem
77  @expr: ExprMem to translate
78  """
79  raise NotImplementedError("Abstract method")

+ Here is the caller graph for this function:

def miasm2.ir.translators.translator.Translator.from_ExprOp (   self,
  expr 
)
Translate an ExprOp
@expr: ExprOp to translate

Definition at line 68 of file translator.py.

68 
69  def from_ExprOp(self, expr):
70  """Translate an ExprOp
71  @expr: ExprOp to translate
72  """
73  raise NotImplementedError("Abstract method")

+ Here is the caller graph for this function:

def miasm2.ir.translators.translator.Translator.from_ExprSlice (   self,
  expr 
)
Translate an ExprSlice
@expr: ExprSlice to translate

Definition at line 62 of file translator.py.

62 
63  def from_ExprSlice(self, expr):
64  """Translate an ExprSlice
65  @expr: ExprSlice to translate
66  """
67  raise NotImplementedError("Abstract method")

+ Here is the caller graph for this function:

def miasm2.ir.translators.translator.Translator.register (   cls,
  translator 
)
Register a translator
@translator: Translator sub-class

Definition at line 14 of file translator.py.

14 
15  def register(cls, translator):
16  """Register a translator
17  @translator: Translator sub-class
18  """
19  cls.available_translators.append(translator)
def miasm2.ir.translators.translator.Translator.to_language (   cls,
  target_lang,
  args,
  kwargs 
)
Return the corresponding translator instance
@target_lang: str (case insensitive) wanted language
Raise a NotImplementedError in case of unmatched language

Definition at line 21 of file translator.py.

21 
22  def to_language(cls, target_lang, *args, **kwargs):
23  """Return the corresponding translator instance
24  @target_lang: str (case insensitive) wanted language
25  Raise a NotImplementedError in case of unmatched language
26  """
27  target_lang = target_lang.lower()
28  for translator in cls.available_translators:
29  if translator.__LANG__.lower() == target_lang:
30  return translator(*args, **kwargs)
31 
32  raise NotImplementedError("Unknown target language: %s" % target_lang)
tuple translator
Definition: ir2C.py:15

Member Data Documentation

string miasm2.ir.translators.translator.Translator.__LANG__ = ""
staticprivate

Definition at line 11 of file translator.py.

miasm2.ir.translators.translator.Translator._cache
private

Definition at line 42 of file translator.py.

list miasm2.ir.translators.translator.Translator.available_translators = []
static

Definition at line 9 of file translator.py.


The documentation for this class was generated from the following file: