Provide a way to disassemble code in a tombstone.

Test: ran disassemble_test.py

Change-Id: Id6beb23ff40d72b89b4d8400d645f7f868fd87d2
diff --git a/scripts/architecture.py b/scripts/architecture.py
new file mode 100644
index 0000000..f239250
--- /dev/null
+++ b/scripts/architecture.py
@@ -0,0 +1,58 @@
+"""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)]
+
+
+ASSEMBLE = 'as'
+DISASSEMBLE = 'objdump'
+LINK = 'ld'
+UNPACK = 'unpack'
+
+OPTIONS = {
+    'x86': {
+        ASSEMBLE: ['--32'],
+        LINK: ['-melf_i386']
+    }
+}
+
+
+class Architecture(object):
+  """Creates an architecture abstraction for a given ABI.
+
+  Args:
+    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, []) +
+            args)
+
+  def WordToBytes(self, word):
+    """Unpacks a hexadecimal string in the architecture's byte order.
+
+    Args:
+      word: A string representing a hexadecimal value.
+
+    Returns:
+      An array of hexadecimal byte values.
+    """
+    return self.options.get(UNPACK, UnpackLittleEndian)(word)