Пример #1
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
Пример #2
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
Пример #3
0
 def assemble(self, src, dst):
     """Assemble a file."""
     cmd = [self.__executable, src, "-o", dst
            ] + self.__assembler_flags_extra
     (so, se) = run_command(cmd)
     if 0 < len(se) and is_verbose():
         print(se)
Пример #4
0
 def generate_linker_script(self, dst, modify_start=False):
     """Get linker script from linker, improve it, write improved linker script to given file."""
     (so, se) = run_command([self.__command, "--verbose"] +
                            self.__linker_flags_extra)
     if 0 < len(se) and is_verbose():
         print(se)
     # Linker script is the block of code between lines of multiple '=':s.
     match = re.match(r'.*\n=+\s*\n(.*)\n=+\s*\n.*', so, re.DOTALL)
     if not match:
         raise RuntimeError("could not extract script from linker output")
     ld_script = match.group(1)
     # Remove unwanted symbol definitions one at a time.
     unwanted_symbols = [
         "__bss_end__", "__bss_start__", "__end__", "__bss_start",
         "_bss_end__", "_edata", "_end"
     ]
     for ii in unwanted_symbols:
         ld_script = re.sub(r'\n([ \f\r\t\v]+)(%s)(\s*=[^\n]+)\n' % (ii),
                            r'\n\1/*\2\3*/\n', ld_script, re.MULTILINE)
     ld_script = re.sub(
         r'SEGMENT_START\s*\(\s*(\S+)\s*,\s*\d*x?\d+\s*\)',
         r'SEGMENT_START(\1, %s)' % (str(PlatformVar("entry"))), ld_script,
         re.MULTILINE)
     if modify_start:
         ld_script = re.sub(
             r'(SEGMENT_START.*\S)\s*\+\s*SIZEOF_HEADERS\s*;', r'\1;',
             ld_script, re.MULTILINE)
     fd = open(dst, "w")
     fd.write(ld_script)
     fd.close()
     if is_verbose():
         print("Wrote linker script '%s'." % (dst))
     return ld_script
Пример #5
0
 def link(self, src, dst, extra_args=[]):
     """Link a file."""
     cmd = [self.__command, src, "-o", dst] + self.__linker_flags + self.get_library_directory_list() + self.get_library_list() + extra_args + self.__linker_script + self.__linker_flags_extra
     (so, se) = run_command(cmd)
     if 0 < len(se) and is_verbose():
         print(se)
     return so
Пример #6
0
 def compile_asm(self, src, dst, whole_program=False):
     """Compile a file into assembler source."""
     cmd = [self.get_command(), "-S", src, "-o", dst] + self.__standard + self.__compiler_flags + self._compiler_flags_extra + self._definitions + self._include_directories
     if whole_program:
         cmd += self.__compiler_flags_generate_asm
     (so, se) = run_command(cmd)
     if 0 < len(se) and is_verbose():
         print(se)
Пример #7
0
 def compile_asm(self, src, dst, whole_program=False):
     """Compile a file into assembler source."""
     cmd = [self.get_command(), "-S", src, "-o", dst] + self.__standard + self.__compiler_flags + self._compiler_flags_extra + self._definitions + self._include_directories
     if whole_program:
         cmd += self.__compiler_flags_generate_asm
     (so, se) = run_command(cmd)
     if 0 < len(se) and is_verbose():
         print(se)
Пример #8
0
 def preprocess(self, op):
     """Preprocess a file, return output."""
     args = [self.get_command(), op] + self._compiler_flags_extra + self._definitions + self._include_directories
     if self.is_msvc():
         args += ["/E"]
     (so, se) = run_command(args)
     if 0 < len(se) and is_verbose():
         print(se)
     return so
Пример #9
0
 def preprocess(self, op):
     """Preprocess a file, return output."""
     args = [self.get_command(), op] + self._compiler_flags_extra + self._definitions + self._include_directories
     if self.command_basename_startswith("cl."):
         args += ["/E"]
     (so, se) = run_command(args)
     if 0 < len(se) and is_verbose():
         print(se)
     return so
Пример #10
0
 def compile_and_link(self, src, dst):
     """Compile and link a file directly."""
     cmd = [
         self.get_command(), src, "-o", dst
     ] + self.__standard + self.__compiler_flags + self._compiler_flags_extra + self._definitions + self._include_directories + self.get_linker_flags(
     ) + self.get_library_directory_list() + self.get_library_list()
     (so, se) = run_command(cmd)
     if 0 < len(se) and is_verbose():
         print(se)
Пример #11
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
Пример #12
0
 def link(self, src, dst, extra_args=[]):
     """Link a file."""
     cmd = [
         self.__command, src, "-o", dst
     ] + self.__linker_flags + self.get_library_directory_list(
     ) + self.get_library_list(
     ) + extra_args + self.__linker_script + self.__linker_flags_extra
     (so, se) = run_command(cmd)
     if 0 < len(se) and is_verbose():
         print(se)
     return so
Пример #13
0
 def get_extra_library_directories(self):
     """Determine extra library requirements for the compiler."""
     ret = []
     if self.is_gcc():
         (so, se) = run_command([self.get_command(), "-v"])
         match = re.search(r'COLLECT_LTO_WRAPPER\s*\=\s*([^\n]+)', se, re.I | re.M)
         if match:
             ret += [os.path.dirname(match.group(1))]
     if is_verbose() and ret:
         print("Compiler '%s' requires additional library directories: %s" % (self.get_command_basename(), str(ret)))
     return ret
Пример #14
0
def compress_file(compression, src, dst):
  """Compress a file to be a self-extracting file-dumping executable."""
  if "lzma" == compression:
    command = ["xz", "--format=lzma", "--lzma1=preset=9,lc=1,lp=0,nice=273,pb=0", "--stdout"]
  elif "xz" == compression:
    command = ["xz", "--format=xz", "--lzma2=preset=9,lc=1,nice=273,pb=0", "--stdout"]
  else:
    raise RuntimeError("unknown compression format '%s'" % compression)
  (compressed, se) = run_command(command + [src], False)
  wfd = open(dst, "wb")
  wfd.write(compressed)
  wfd.close()
  print("Wrote '%s': %i -> %i bytes" % (dst, os.path.getsize(src), os.path.getsize(dst)))
Пример #15
0
def compress_file(compression, src, dst):
    """Compress a file to be a self-extracting file-dumping executable."""
    if "lzma" == compression:
        command = ["xz", "--format=lzma", "--lzma1=preset=9,lc=1,lp=0,nice=273,pb=0", "--stdout"]
    elif "xz" == compression:
        command = ["xz", "--format=xz", "--lzma2=preset=9,lc=1,nice=273,pb=0", "--stdout"]
    else:
        raise RuntimeError("unknown compression format '%s'" % compression)
    (compressed, se) = run_command(command + [src], False)
    wfd = open(dst, "wb")
    wfd.write(compressed)
    wfd.close()
    print("Wrote '%s': %i -> %i bytes" % (dst, os.path.getsize(src), os.path.getsize(dst)))
Пример #16
0
 def generate_linker_script(self, dst, modify_start=False):
     """Get linker script from linker, improve it, write improved linker script to given file."""
     (so, se) = run_command([self.__command, "--verbose"] + self.__linker_flags_extra)
     if 0 < len(se) and is_verbose():
         print(se)
     # Linker script is the block of code between lines of multiple '=':s.
     match = re.match(r'.*\n=+\s*\n(.*)\n=+\s*\n.*', so, re.DOTALL)
     if not match:
         raise RuntimeError("could not extract script from linker output")
     ld_script = match.group(1)
     # Remove unwanted symbol definitions one at a time.
     unwanted_symbols = ["__bss_end__", "__bss_start__", "__end__", "__bss_start", "_bss_end__", "_edata", "_end"]
     for ii in unwanted_symbols:
         ld_script = re.sub(r'\n([ \f\r\t\v]+)(%s)(\s*=[^\n]+)\n' % (ii), r'\n\1/*\2\3*/\n', ld_script, re.MULTILINE)
     ld_script = re.sub(r'SEGMENT_START\s*\(\s*(\S+)\s*,\s*\d*x?\d+\s*\)', r'SEGMENT_START(\1, %s)' % (str(PlatformVar("entry"))), ld_script, re.MULTILINE)
     if modify_start:
         ld_script = re.sub(r'(SEGMENT_START.*\S)\s*\+\s*SIZEOF_HEADERS\s*;', r'\1;', ld_script, re.MULTILINE)
     fd = open(dst, "w")
     fd.write(ld_script)
     fd.close()
     if is_verbose():
         print("Wrote linker script '%s'." % (dst))
     return ld_script
Пример #17
0
def main():
  """Main function."""
  default_preprocessor_list = ["cpp", "clang-cpp"]
  preprocessor = None
  
  parser = argparse.ArgumentParser(usage = "GLSL minifying test.", formatter_class = CustomHelpFormatter, add_help = False)
  parser.add_argument("-h", "--help", action = "store_true", help = "Print this help string and exit.")
  parser.add_argument("--preprocessor", default = None, help = "Try to use given preprocessor executable as opposed to autodetect.")
  parser.add_argument("-v", "--verbose", action = "store_true", help = "Print more info about what is being done.")
  parser.add_argument("source", default = [], nargs = "*", help = "Source file(s) to process.")
 
  args = parser.parse_args()

  preprocessor = args.preprocessor

  if args.help:
    print(parser.format_help().strip())
    return 0

  # Verbosity.
  if args.verbose:
    set_verbose(True)

  # Source files to process.
  if not args.source:
    raise RuntimeError("no source files to process")
  source_files = []
  for ii in args.source:
    if re.match(r'.*\.(glsl|vert|geom|frag)$', ii, re.I):
      source_files += [ii]
    else:
      raise RuntimeError("unknown source file: '%s'" % (ii))

  dl = find_executable("dnload.py", "dnload")
  if is_verbose():
    print("found dnload: '%s'" % (dl))
  sm = find_executable("shader_minifier.exe", "Shader_Minifier")
  if is_verbose():
    print("found shader_minifier: '%s'" % (sm))

  # Find preprocessor.
  if preprocessor:
    if not executable_check(preprocessor):
      raise RuntimeError("could not use supplied preprocessor '%s'" % (preprocessor))
  else:
    preprocessor_list = default_preprocessor_list
    if os.name == "nt":
      preprocessor_list = ["cl.exe"] + preprocessor_list
    preprocessor = executable_search(preprocessor_list, "preprocessor")
  if not preprocessor:
    raise RuntimeError("suitable preprocessor not found")
  preprocessor = Preprocessor(preprocessor)

  for ii in source_files:
    fname = "/tmp/" + os.path.basename(ii)
    fname_dn = fname + ".dnload"
    fname_dn_in = fname_dn + ".h"
    fname_dn_out = fname_dn + ".payload"
    fname_sm = fname + ".shaderminifier"
    fname_sm_in = fname_sm + ".h"
    fname_sm_out = fname_sm + ".payload"
    run_command(["python", dl, ii, "-o", fname_dn_in])
    if is_verbose():
      print("Wrote dnload -minified shader: '%s'" % (fname_dn_in))
    run_command(["mono", sm, ii, "-o", fname_sm_in])
    if is_verbose():
      print("Wrote shader_minifier -minified shader: '%s'" % (fname_sm_in))
    extract_shader_payload(preprocessor, fname_dn_in, fname_dn_out)
    extract_shader_payload(preprocessor, fname_sm_in, fname_sm_out)
    compress_file("lzma", fname_dn_out, fname_dn + ".lzma")
    #compress_file("xz", fname_dn_out, fname_dn + ".xz")
    compress_file("lzma", fname_sm_out, fname_sm + ".lzma")
    #compress_file("xz", fname_sm_out, fname_sm + ".xz")

  return 0
Пример #18
0
def main():
    """Main function."""
    default_preprocessor_list = ["cpp", "clang-cpp"]
    preprocessor = None

    parser = argparse.ArgumentParser(usage="GLSL minifying test.", formatter_class=CustomHelpFormatter, add_help=False)
    parser.add_argument("-h", "--help", action="store_true", help="Print this help string and exit.")
    parser.add_argument("--preprocessor", default=None, help="Try to use given preprocessor executable as opposed to autodetect.")
    parser.add_argument("-v", "--verbose", action="store_true", help="Print more info about what is being done.")
    parser.add_argument("source", default=[], nargs="*", help="Source file(s) to process.")

    args = parser.parse_args()

    preprocessor = args.preprocessor

    if args.help:
        print(parser.format_help().strip())
        return 0

    # Verbosity.
    if args.verbose:
        set_verbose(True)

    # Source files to process.
    if not args.source:
        raise RuntimeError("no source files to process")
    source_files = []
    for ii in args.source:
        if re.match(r'.*\.(glsl|vert|geom|frag)$', ii, re.I):
            source_files += [ii]
        else:
            raise RuntimeError("unknown source file: '%s'" % (ii))

    dl = find_executable("dnload.py", "dnload")
    if is_verbose():
        print("found dnload: '%s'" % (dl))
    sm = find_executable("shader_minifier.exe", "Shader_Minifier")
    if is_verbose():
        print("found shader_minifier: '%s'" % (sm))

    # Find preprocessor.
    if preprocessor:
        if not executable_check(preprocessor):
            raise RuntimeError("could not use supplied preprocessor '%s'" % (preprocessor))
    else:
        preprocessor_list = default_preprocessor_list
        if os.name == "nt":
            preprocessor_list = ["cl.exe"] + preprocessor_list
        preprocessor = executable_search(preprocessor_list, "preprocessor")
    if not preprocessor:
        raise RuntimeError("suitable preprocessor not found")
    preprocessor = Preprocessor(preprocessor)

    for ii in source_files:
        fname = "/tmp/" + os.path.basename(ii)
        fname_dn = fname + ".dnload"
        fname_dn_in = fname_dn + ".h"
        fname_dn_out = fname_dn + ".payload"
        fname_sm = fname + ".shaderminifier"
        fname_sm_in = fname_sm + ".h"
        fname_sm_out = fname_sm + ".payload"
        run_command(["python", dl, ii, "-o", fname_dn_in])
        if is_verbose():
            print("Wrote dnload -minified shader: '%s'" % (fname_dn_in))
        run_command(["mono", sm, ii, "-o", fname_sm_in])
        if is_verbose():
            print("Wrote shader_minifier -minified shader: '%s'" % (fname_sm_in))
        extract_shader_payload(preprocessor, fname_dn_in, fname_dn_out)
        extract_shader_payload(preprocessor, fname_sm_in, fname_sm_out)
        compress_file("lzma", fname_dn_out, fname_dn + ".lzma")
        compress_file("lzma", fname_sm_out, fname_sm + ".lzma")

    return 0
Пример #19
0
 def compile_and_link(self, src, dst):
     """Compile and link a file directly."""
     cmd = [self.get_command(), src, "-o", dst] + self.__standard + self.__compiler_flags + self._compiler_flags_extra + self._definitions + self._include_directories + self.get_linker_flags() + self.get_library_directory_list() + self.get_library_list()
     (so, se) = run_command(cmd)
     if 0 < len(se) and is_verbose():
         print(se)
Пример #20
0
 def assemble(self, src, dst):
     """Assemble a file."""
     cmd = [self.__executable, src, "-o", dst] + self.__assembler_flags_extra
     (so, se) = run_command(cmd)
     if 0 < len(se) and is_verbose():
         print(se)