about summary refs log tree commit diff stats
path: root/miasm2/core/parse_asm.py
diff options
context:
space:
mode:
authorCamille Mougey <camille.mougey@cea.fr>2015-02-18 11:04:59 +0100
committerCamille Mougey <camille.mougey@cea.fr>2015-02-18 15:49:36 +0100
commit86e9499be55b85b386dab3257e2c1946e094afb6 (patch)
tree7f3c76f0773d5380aacad13072b2581f25aaacd8 /miasm2/core/parse_asm.py
parent5b3589b4735024e96becb5dbd8d25de4416f7cfb (diff)
downloadmiasm-86e9499be55b85b386dab3257e2c1946e094afb6.tar.gz
miasm-86e9499be55b85b386dab3257e2c1946e094afb6.zip
Core/ParseASM: Remove wildcard import and too long lines
Diffstat (limited to 'miasm2/core/parse_asm.py')
-rw-r--r--miasm2/core/parse_asm.py61
1 files changed, 27 insertions, 34 deletions
diff --git a/miasm2/core/parse_asm.py b/miasm2/core/parse_asm.py
index dba097fa..ba2769e6 100644
--- a/miasm2/core/parse_asm.py
+++ b/miasm2/core/parse_asm.py
@@ -1,11 +1,12 @@
 #!/usr/bin/env python
 #-*- coding:utf-8 -*-
-
 import re
+
 import miasm2.expression.expression as m2_expr
-from miasm2.core.asmbloc import *
+import miasm2.core.asmbloc as asmbloc
 from miasm2.core.utils import pck
 from miasm2.core.cpu import gen_base_expr, parse_ast
+
 declarator = {'byte': 8,
               'word': 16,
               'dword': 32,
@@ -33,12 +34,15 @@ def guess_next_new_label(symbol_pool, gen_label_index=0):
 
 def parse_txt(mnemo, attrib, txt, symbol_pool=None, gen_label_index=0):
     if symbol_pool is None:
-        symbol_pool = asm_symbol_pool()
+        symbol_pool = asmbloc.asm_symbol_pool()
 
     lines_text = []
     lines_data = []
     lines_bss = []
 
+    C_NEXT = asmbloc.asm_constraint.c_next
+    C_TO = asmbloc.asm_constraint.c_to
+
     lines = lines_text
     # parse each line
     for line in txt.split('\n'):
@@ -79,7 +83,7 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None, gen_label_index=0):
                 raw = raw.decode('string_escape')
                 if directive == 'string':
                     raw += "\x00"
-                lines.append(asm_raw(raw))
+                lines.append(asmbloc.asm_raw(raw))
                 continue
             if directive == 'ustring':
                 # XXX HACK
@@ -87,7 +91,7 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None, gen_label_index=0):
                 raw = line[line.find(r'"') + 1:line.rfind(r"'")] + "\x00"
                 raw = raw.decode('string_escape')
                 raw = "".join(map(lambda x: x + '\x00', raw))
-                lines.append(asm_raw(raw))
+                lines.append(asmbloc.asm_raw(raw))
                 continue
             if directive in declarator:
                 data_raw = line[r.end():].split(' ', 1)[1]
@@ -99,7 +103,8 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None, gen_label_index=0):
                 # parser
                 variable, operand, base_expr = gen_base_expr()
                 my_var_parser = parse_ast(lambda x:m2_expr.ExprId(x, size),
-                                          lambda x:m2_expr.ExprInt_fromsize(size, x))
+                                          lambda x:
+                                              m2_expr.ExprInt_fromsize(size, x))
                 base_expr.setParseAction(my_var_parser)
 
                 for b in data_raw:
@@ -108,7 +113,7 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None, gen_label_index=0):
                     data_int.append(x.canonize())
                 p = size2pck[size]
                 raw = data_int
-                x = asm_raw(raw)
+                x = asmbloc.asm_raw(raw)
                 x.element_size = size
                 lines.append(x)
                 continue
@@ -116,12 +121,12 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None, gen_label_index=0):
                 # TODO
                 continue
             if directive == 'split':  # custom command
-                x = asm_raw()
+                x = asmbloc.asm_raw()
                 x.split = True
                 lines.append(x)
                 continue
             if directive == 'dontsplit':  # custom command
-                lines.append(asm_raw(line.strip()))
+                lines.append(asmbloc.asm_raw(line.strip()))
                 continue
             if directive in ['file', 'intel_syntax', 'globl', 'local',
                              'type', 'size', 'align', 'ident', 'section']:
@@ -148,7 +153,7 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None, gen_label_index=0):
             instr.dstflow2label(symbol_pool)
         lines.append(instr)
 
-    log_asmbloc.info("___pre asm oki___")
+    asmbloc.log_asmbloc.info("___pre asm oki___")
     # make blocs
     # gen_label_index = 0
 
@@ -165,12 +170,12 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None, gen_label_index=0):
             # print 'DEAL', lines[i], state
             # no current bloc
             if state == 0:
-                if not isinstance(lines[i], asm_label):
+                if not isinstance(lines[i], asmbloc.asm_label):
                     l = guess_next_new_label(symbol_pool)
                     lines[i:i] = [l]
                 else:
                     l = lines[i]
-                    b = asm_bloc(l)
+                    b = asmbloc.asm_bloc(l)
                     b.bloc_num = bloc_num
                     bloc_num += 1
                     blocs.append(b)
@@ -178,14 +183,14 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None, gen_label_index=0):
                     i += 1
                     if bloc_to_nlink:
                         # print 'nlink!'
-                        bloc_to_nlink.addto(
-                            asm_constraint(b.label, asm_constraint.c_next))
+                        bloc_to_nlink.addto(asmbloc.asm_constraint(b.label,
+                                                                   C_NEXT))
                         bloc_to_nlink = None
 
             # in bloc
             elif state == 1:
-                # asm_raw
-                if isinstance(lines[i], asm_raw):
+                # asmbloc.asm_raw
+                if isinstance(lines[i], asmbloc.asm_raw):
                     if hasattr(lines[i], 'split'):
                         state = 0
                         block_may_link = False
@@ -202,41 +207,29 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None, gen_label_index=0):
                         b.addline(lines[i])
                         i += 1
                     """
-                # asm_label
-                elif isinstance(lines[i], asm_label):
+                # asmbloc.asm_label
+                elif isinstance(lines[i], asmbloc.asm_label):
                     if block_may_link:
                         # print 'nlink!'
                         b.addto(
-                            asm_constraint(lines[i], asm_constraint.c_next))
+                            asmbloc.asm_constraint(lines[i], C_NEXT))
                         block_may_link = False
                     state = 0
                 # instruction
                 else:
                     b.addline(lines[i])
                     if lines[i].dstflow():
-                        '''
-                        mydst = lines[i].args
-                        if len(mydst)==1 and mnemo.get_symbols(mydst[0]):
-                            arg = dict(mydst[0])
-                            symbs = mnemo.get_symbols(arg)
-                            """
-                            TODO XXX redo this (as many miasm parts)
-                            """
-                            l = symbs[0][0]
-                            lines[i].setdstflow([l])
-                            b.addto(asm_constraint(l, asm_constraint.c_to))
-                        '''
                         for x in lines[i].getdstflow(symbol_pool):
                             if not isinstance(x, m2_expr.ExprId):
                                 continue
                             if x in mnemo.regs.all_regs_ids:
                                 continue
-                            b.addto(asm_constraint(x, asm_constraint.c_to))
+                            b.addto(asmbloc.asm_constraint(x, C_TO))
 
                         # TODO XXX redo this really
 
                         if not lines[i].breakflow() and i + 1 < len(lines):
-                            if isinstance(lines[i + 1], asm_label):
+                            if isinstance(lines[i + 1], asmbloc.asm_label):
                                 l = lines[i + 1]
                             else:
                                 l = guess_next_new_label(symbol_pool)
@@ -254,6 +247,6 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None, gen_label_index=0):
                     i += 1
 
     for b in blocs_sections[0]:
-        log_asmbloc.info(b)
+        asmbloc.log_asmbloc.info(b)
 
     return blocs_sections, symbol_pool