Ejemplo n.º 1
0
 def __init__(self, name, dependencies, headers, prototypes, source):
     """Constructor."""
     self.__name = name
     self.__dependencies = listify(dependencies)
     self.__headers = listify(headers)
     self.__prototypes = listify(prototypes)
     self.__source = source
Ejemplo n.º 2
0
 def __init__(self, name, dependencies, headers, prototypes, source):
     """Constructor."""
     self.__name = name
     self.__dependencies = listify(dependencies)
     self.__headers = listify(headers)
     self.__prototypes = listify(prototypes)
     self.__source = source
Ejemplo n.º 3
0
 def link_binary(self, objcopy, src, dst):
     """Link a binary file with no bells and whistles."""
     ld_target = dst
     cmd = [
         self.__command, "--entry=" + str(PlatformVar("entry"))
     ] + listify(src) + self.__linker_script + self.__linker_flags_extra
     # Use objcopy if it was given.
     if objcopy:
         (dst_base, dst_ext) = os.path.splitext(dst)
         dst_bin = dst_base + ".out"
         objcopy_cmd = [objcopy, "--output-target=binary", dst_bin, dst]
         ld_target = dst_bin
     # Otherwise link directly into binary.
     else:
         cmd += ["--oformat=binary"]
     cmd += ["-o", ld_target]
     # Run linker command.
     (so, se) = run_command(cmd)
     if 0 < len(se) and is_verbose():
         print(se)
     # Only run objcopy commad if it was required.
     if objcopy:
         (so_add, se) = run_command(objcopy_cmd)
         if 0 < len(se) and is_verbose():
             print(se)
         so += so_add
     return so
Ejemplo n.º 4
0
 def format_comment(self, op, indent=""):
     """Get comment string."""
     ret = ""
     for ii in listify(op):
         if ii:
             ret += indent + self.__comment + " " + ii + "\n"
     return ret
Ejemplo n.º 5
0
 def format_data(self, size, value, indent=""):
     """Get data element."""
     size = int(size)
     value_strings = []
     for ii in listify(value):
         if isinstance(ii, int):
             value_strings += ["0x%x" % (ii)]
         else:
             value_strings += [str(ii)]
     if not value_strings:
         raise RuntimeError("unable to format value: '%s'" % (str(value)))
     value = ", ".join(value_strings)
     if value.startswith("\"") and 1 == size:
         return indent + self.__string + " " + value + "\n"
     if 1 == size:
         return indent + self.__byte + " " + value + "\n"
     elif 2 == size:
         return indent + self.__short + " " + value + "\n"
     elif 4 == size:
         return indent + self.__word + " " + value + "\n"
     elif 8 == size:
         return indent + self.__quad + " " + value + "\n"
     else:
         raise NotImplementedError("exporting assembler value of size %i",
                                   size)
Ejemplo n.º 6
0
 def format_comment(self, op, indent=""):
     """Get comment string."""
     ret = ""
     for ii in listify(op):
         if ii:
             ret += indent + self.__comment + " " + ii + "\n"
     return ret
Ejemplo n.º 7
0
 def link_binary(self, objcopy, src, dst):
     """Link a binary file with no bells and whistles."""
     ld_target = dst
     cmd = [self.__command, "--entry=" + str(PlatformVar("entry"))] + listify(src) + self.__linker_script + self.__linker_flags_extra
     # Use objcopy if it was given.
     if objcopy:
         (dst_base, dst_ext) = os.path.splitext(dst)
         dst_bin = dst_base + ".out"
         objcopy_cmd = [objcopy, "--output-target=binary", dst_bin, dst]
         ld_target = dst_bin
     # Otherwise link directly into binary.
     else:
         cmd += ["--oformat=binary"]
     cmd += ["-o", ld_target]
     # Run linker command.
     (so, se) = run_command(cmd)
     if 0 < len(se) and is_verbose():
         print(se)
     # Only run objcopy commad if it was required.
     if objcopy:
         (so_add, se) = run_command(objcopy_cmd)
         if 0 < len(se) and is_verbose():
             print(se)
         so += so_add
     return so
Ejemplo n.º 8
0
 def link_binary(self, src, dst):
     """Link a binary file with no bells and whistles."""
     cmd = [self.__command,
            "--entry=" + str(PlatformVar("entry"))] + listify(src) + [
                "-o", dst
            ] + self.__linker_script + self.__linker_flags_extra
     (so, se) = run_command(cmd)
     if 0 < len(se) and is_verbose():
         print(se)
     return so
Ejemplo n.º 9
0
 def format_data(self, size, value, indent=""):
     """Get data element."""
     size = int(size)
     value_strings = []
     for ii in listify(value):
         if isinstance(ii, int):
             value_strings += ["0x%x" % (ii)]
         else:
             value_strings += [str(ii)]
     if not value_strings:
         raise RuntimeError("unable to format value: '%s'" % (str(value)))
     value = ", ".join(value_strings)
     if value.startswith("\"") and 1 == size:
         return indent + self.__string + " " + value + "\n"
     if 1 == size:
         return indent + self.__byte + " " + value + "\n"
     elif 2 == size:
         return indent + self.__short + " " + value + "\n"
     elif 4 == size:
         return indent + self.__word + " " + value + "\n"
     elif 8 == size:
         return indent + self.__quad + " " + value + "\n"
     else:
         raise NotImplementedError("exporting assembler value of size %i", size)
Ejemplo n.º 10
0
 def reconstruct(self, lst):
     """Reconstruct variable from a listing."""
     original_size = int(self.__original_size)
     self.__original_size = -1
     if 1 >= original_size:
         return False
     if len(lst) < original_size - 1:
         return False
     ret = chr(self.__value)
     for ii in range(original_size - 1):
         op = lst[ii]
         if not op.reconstructable((original_size - 2) == ii):
             return False
         self.__label_post = listify(self.__label_post, op.label_post)
         ret += chr(op.value)
     bom = str(PlatformVar("bom"))
     if 2 == original_size:
         self.__value = struct.unpack(bom + "H", ret)[0]
     elif 4 == original_size:
         self.__value = struct.unpack(bom + "I", ret)[0]
     elif 8 == original_size:
         self.__value = struct.unpack(bom + "Q", ret)[0]
     self.__size = original_size
     return original_size - 1
Ejemplo n.º 11
0
 def reconstruct(self, lst):
     """Reconstruct variable from a listing."""
     original_size = int(self.__original_size)
     self.__original_size = -1
     if 1 >= original_size:
         return False
     if len(lst) < original_size - 1:
         return False
     ret = chr(self.__value)
     for ii in range(original_size - 1):
         op = lst[ii]
         if not op.reconstructable((original_size - 2) == ii):
             return False
         self.__label_post = listify(self.__label_post, op.label_post)
         ret += chr(op.value)
     bom = str(PlatformVar("bom"))
     if 2 == original_size:
         self.__value = struct.unpack(bom + "H", ret)[0]
     elif 4 == original_size:
         self.__value = struct.unpack(bom + "I", ret)[0]
     elif 8 == original_size:
         self.__value = struct.unpack(bom + "Q", ret)[0]
     self.__size = original_size
     return original_size - 1
Ejemplo n.º 12
0
 def add_sections(self, op):
   """Manually add one or more sections."""
   self.__sections += listify(op)
Ejemplo n.º 13
0
 def add_sections(self, op):
     """Manually add one or more sections."""
     self.__sections += listify(op)
Ejemplo n.º 14
0
 def merge(self, op):
     """Merge two assembler variables into one."""
     self.__desc = listify(self.__desc, op.__desc)
     self.__name = listify(self.__name, op.__name)
     self.__label_pre = listify(self.__label_pre, op.__label_pre)
     self.__label_post = listify(self.__label_post, op.__label_post)
Ejemplo n.º 15
0
 def merge(self, op):
     """Merge two assembler variables into one."""
     self.__desc = listify(self.__desc, op.__desc)
     self.__name = listify(self.__name, op.__name)
     self.__label_pre = listify(self.__label_pre, op.__label_pre)
     self.__label_post = listify(self.__label_post, op.__label_post)