blob: f239250c786240f59ce6f310f692e97742af7fd6 [file] [log] [blame]
"""Abstraction layer for different ABIs."""
import re
import symbol
def UnpackLittleEndian(word):
"""Split a hexadecimal string in little endian order."""
return [word[x:x+2] for x in range(len(word) - 2, -2, -2)]
DISASSEMBLE = 'objdump'
LINK = 'ld'
UNPACK = 'unpack'
'x86': {
ASSEMBLE: ['--32'],
LINK: ['-melf_i386']
class Architecture(object):
"""Creates an architecture abstraction for a given ABI.
name: The abi name, as represented in a tombstone.
def __init__(self, name):
symbol.ARCH = name
self.toolchain = symbol.FindToolchain()
self.options = OPTIONS.get(name, {})
def Assemble(self, args):
"""Generates an assembler command, appending the given args."""
return [symbol.ToolPath(ASSEMBLE)] + self.options.get(ASSEMBLE, []) + args
def Link(self, args):
"""Generates a link command, appending the given args."""
return [symbol.ToolPath(LINK)] + self.options.get(LINK, []) + args
def Disassemble(self, args):
"""Generates a disassemble command, appending the given args."""
return ([symbol.ToolPath(DISASSEMBLE)] + self.options.get(DISASSEMBLE, []) +
def WordToBytes(self, word):
"""Unpacks a hexadecimal string in the architecture's byte order.
word: A string representing a hexadecimal value.
An array of hexadecimal byte values.
return self.options.get(UNPACK, UnpackLittleEndian)(word)