# HG changeset patch # User Windel Bouwman # Date 1398613825 -7200 # Node ID 94f5b719ad0b848b7450dc356cdacd3e13c2ab25 # Parent 173e20a47fda0f5790fdd9f82b71da65798e1eb5 Small refactor diff -r 173e20a47fda -r 94f5b719ad0b python/ppci/assembler.py --- a/python/ppci/assembler.py Sun Apr 27 17:40:39 2014 +0200 +++ b/python/ppci/assembler.py Sun Apr 27 17:50:25 2014 +0200 @@ -2,7 +2,7 @@ import re import pyyacc from baselex import BaseLexer -from . import Token, CompilerError, SourceLocation +from . import Token, CompilerError, SourceLocation, make_num from .target import Target, Label @@ -37,10 +37,7 @@ return (typ, val) def handle_number(self, typ, val): - if val.startswith('0x'): - val = int(val[2:], 16) - else: - val = int(val) + val = make_num(val) typ = bit_type(val) return typ, val diff -r 173e20a47fda -r 94f5b719ad0b python/ppci/objectfile.py --- a/python/ppci/objectfile.py Sun Apr 27 17:40:39 2014 +0200 +++ b/python/ppci/objectfile.py Sun Apr 27 17:50:25 2014 +0200 @@ -6,7 +6,7 @@ import json import binascii -from . import CompilerError +from . import CompilerError, make_num class Symbol: def __init__(self, name, value, section): @@ -139,23 +139,16 @@ return res -def make_int(txt): - if txt.startswith('0x'): - return int(txt[2:], 16) - else: - return int(txt) - - def deserialize(d): obj = ObjectFile() for section in d['sections']: so = obj.get_section(section['name']) - so.address = make_int(section['address']) + so.address = make_num(section['address']) so.data = bytearray(binascii.unhexlify(section['data'].encode('ascii'))) for reloc in d['relocations']: - obj.add_relocation(reloc['symbol'], make_int(reloc['offset']), + obj.add_relocation(reloc['symbol'], make_num(reloc['offset']), reloc['type'], reloc['section']) for sym in d['symbols']: - obj.add_symbol(sym['name'], make_int(sym['value']), sym['section']) + obj.add_symbol(sym['name'], make_num(sym['value']), sym['section']) return obj diff -r 173e20a47fda -r 94f5b719ad0b test/testemulation.py --- a/test/testemulation.py Sun Apr 27 17:40:39 2014 +0200 +++ b/test/testemulation.py Sun Apr 27 17:50:25 2014 +0200 @@ -21,6 +21,8 @@ def has_qemu(): """ Determines if qemu is possible """ + if not hasattr(shutil, 'which'): + return False return bool(shutil.which(qemu_app))