Generate the kernel buffers using bin_to_assembly rule
instead of dill_to_cc.
This should fix the clang tool errors we are seeing.

Change-Id: I9a17a8028bc4f3e2352793ffe41a7444ae06956b
Reviewed-on: https://dart-review.googlesource.com/61107
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
diff --git a/runtime/bin/BUILD.gn b/runtime/bin/BUILD.gn
index 15c9fb7..27506b0 100644
--- a/runtime/bin/BUILD.gn
+++ b/runtime/bin/BUILD.gn
@@ -593,9 +593,7 @@
     deps += [ "//third_party/boringssl" ]
 
     if (is_fuchsia) {
-      deps += [
-        "//garnet/public/lib/netstack/c",
-      ]
+      deps += [ "//garnet/public/lib/netstack/c" ]
       public_deps = [
         "//zircon/public/lib/fdio",
       ]
@@ -701,6 +699,14 @@
       "--target_os",
       current_os,
     ]
+    if (defined(invoker.size_symbol)) {
+      args += [
+        "--size_symbol_name",
+        invoker.size_symbol,
+        "--target_arch",
+        current_cpu,
+      ]
+    }
     if (invoker.executable) {
       args += [ "--executable" ]
     }
@@ -754,64 +760,37 @@
   executable = true
 }
 
-template("dill_to_cc") {
-  assert(defined(invoker.dill_file), "Need dill_file in $target_name.")
-  assert(defined(invoker.data_symbol), "Need data_symbol in $target_name.")
-  assert(defined(invoker.size_symbol), "Need size_symbol in $target_name.")
-  assert(defined(invoker.output), "Need output in $target_name.")
-
-  extra_deps = []
-  if (defined(invoker.deps)) {
-    extra_deps += invoker.deps
-  }
-
-  action(target_name) {
-    deps = extra_deps
-    script = "../tools/dill_to_data_cc.py"
-    inputs = [
-      "../tools/dill_to_data_cc.py",
-      invoker.dill_file,
-    ]
-    outputs = [
-      invoker.output,
-    ]
-    args = [
-      "--dill_file=" + rebase_path(invoker.dill_file),
-      "--data_symbol=" + invoker.data_symbol,
-      "--size_symbol=" + invoker.size_symbol,
-      "--output=" + rebase_path(invoker.output),
-    ]
-  }
-}
-
-dill_to_cc("kernel_service_dill_cc") {
+bin_to_assembly("kernel_service_dill_S") {
   deps = [
     "../../utils/kernel-service:kernel_service_dill",
   ]
-  dill_file = "$root_gen_dir/kernel_service.dill"
-  data_symbol = "kKernelServiceDill"
+  input = "$root_gen_dir/kernel_service.dill"
+  output = "$root_gen_dir/kernel_service.dill.S"
+  symbol = "kKernelServiceDill"
   size_symbol = "kKernelServiceDillSize"
-  output = "$root_gen_dir/kernel_service.dill.cc"
+  executable = false
 }
 
-dill_to_cc("platform_dill_cc") {
+bin_to_assembly("platform_dill_S") {
   deps = [
     "../vm:vm_legacy_platform",
   ]
-  dill_file = "$root_out_dir/vm_platform.dill"
-  data_symbol = "kPlatformDill"
+  input = "$root_out_dir/vm_platform.dill"
+  output = "$target_gen_dir/vm_platform.dill.S"
+  symbol = "kPlatformDill"
   size_symbol = "kPlatformDillSize"
-  output = "$target_gen_dir/vm_platform.dill.cc"
+  executable = false
 }
 
-dill_to_cc("platform_strong_dill_cc") {
+bin_to_assembly("platform_strong_dill_S") {
   deps = [
     "../vm:vm_platform",
   ]
-  dill_file = "$root_out_dir/vm_platform_strong.dill"
-  data_symbol = "kPlatformStrongDill"
+  input = "$root_out_dir/vm_platform_strong.dill"
+  output = "$target_gen_dir/vm_platform_strong.dill.S"
+  symbol = "kPlatformStrongDill"
   size_symbol = "kPlatformStrongDillSize"
-  output = "$target_gen_dir/vm_platform_strong.dill.cc"
+  executable = false
 }
 
 source_set("dart_snapshot_cc") {
@@ -831,14 +810,14 @@
 
 source_set("dart_kernel_platform_cc") {
   deps = [
-    ":kernel_service_dill_cc",
-    ":platform_dill_cc",
-    ":platform_strong_dill_cc",
+    ":kernel_service_dill_S",
+    ":platform_dill_S",
+    ":platform_strong_dill_S",
   ]
   sources = [
-    "$root_gen_dir/kernel_service.dill.cc",
-    "$target_gen_dir/vm_platform.dill.cc",
-    "$target_gen_dir/vm_platform_strong.dill.cc",
+    "$root_gen_dir/kernel_service.dill.S",
+    "$target_gen_dir/vm_platform.dill.S",
+    "$target_gen_dir/vm_platform_strong.dill.S",
   ]
 }
 
diff --git a/runtime/tools/bin_to_assembly.py b/runtime/tools/bin_to_assembly.py
index 941a050..8bc5d8c 100755
--- a/runtime/tools/bin_to_assembly.py
+++ b/runtime/tools/bin_to_assembly.py
@@ -25,6 +25,10 @@
                     action="store_true", default=False)
   parser.add_option("--target_os",
                     action="store", type="string")
+  parser.add_option("--size_symbol_name",
+                    action="store", type="string")
+  parser.add_option("--target_arch",
+                    action="store", type="string")
 
   (options, args) = parser.parse_args()
   if not options.output:
@@ -78,18 +82,53 @@
       output_file.write(".balign 32\n")
       output_file.write("%s:\n" % options.symbol_name)
 
+    size = 0
     with open(options.input, "rb") as input_file:
       if options.target_os in ["win"]:
         for byte in input_file.read():
           output_file.write("byte %d\n" % ord(byte))
-        output_file.write("end\n")
+          size += 1
       else:
         for byte in input_file.read():
           output_file.write(".byte %d\n" % ord(byte))
+          size += 1
 
     if options.target_os not in ["mac", "ios", "win"]:
       output_file.write(".size {0}, .-{0}\n".format(options.symbol_name))
 
+    if options.size_symbol_name:
+      if not options.target_arch:
+        sys.stderr.write("--target_arch not specified\n")
+        parser.print_help();
+        return -1
+
+      is64bit = 0
+      if options.target_arch:
+        if options.target_arch in ["arm64", "x64"]:
+          is64bit = 1
+
+      if options.target_os in ["win"]:
+        output_file.write("public %s\n" % options.size_symbol_name)
+        output_file.write("%s label byte\n" % options.size_symbol_name)
+        if (is64bit == 1):
+          output_file.write("qword %d\n" % size )
+        else:
+          output_file.write("dword %d\n" % size )
+      else:
+        if options.target_os in ["mac", "ios"]:
+          output_file.write(".global _%s\n" % options.size_symbol_name)
+          output_file.write("_%s:\n" % options.size_symbol_name)
+        else:
+          output_file.write(".global %s\n" % options.size_symbol_name)
+          output_file.write("%s:\n" % options.size_symbol_name)
+        if (is64bit == 1):
+          output_file.write(".quad %d\n" % size )
+        else:
+          output_file.write(".long %d\n" % size )
+
+    if options.target_os in ["win"]:
+      output_file.write("end\n")
+
   return 0
 
 if __name__ == "__main__":
diff --git a/runtime/tools/dill_to_data_cc.py b/runtime/tools/dill_to_data_cc.py
deleted file mode 100755
index b3b1211..0000000
--- a/runtime/tools/dill_to_data_cc.py
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (c) 2018, the Dart project authors.  Please see the AUTHORS file
-# for details. All rights reserved. Use of this source code is governed by a
-# BSD-style license that can be found in the LICENSE file.
-
-# Script to create a cc file with uint8 array of bytes corresponding to the
-# content of given a dill file.
-
-import optparse
-import sys
-
-# Option => Help mapping.
-OPTION_MAP = {
-  'dill_file': 'Path to the input dill file.',
-  'data_symbol': 'The C name for the data array.',
-  'size_symbol': 'The C name for the data size variable.',
-  'output': 'Path to the generated cc file.',
-}
-
-
-def BuildOptionParser():
-  parser = optparse.OptionParser()
-  for opt, help_text in OPTION_MAP.iteritems():
-    parser.add_option('--%s' % opt, type='string', help=help_text)
-  return parser
-
-
-def ValidateOptions(options):
-  for opt in OPTION_MAP.keys():
-    if getattr(options, opt) is None:
-      sys.stderr.write('--%s option not specified.\n' % opt)
-      return False
-  return True
-
-
-def WriteData(input_filename, data_symbol, output_file):
-  output_file.write('uint8_t %s[] = {\n' % data_symbol)
-  with open(input_filename, 'rb') as f:
-    first = True
-    size = 0
-    for byte in f.read():
-      if first:
-        output_file.write('  %d' % ord(byte))
-        first = False
-      else:
-        output_file.write(',\n  %d' % ord(byte))
-      size += 1
-  output_file.write('\n};\n')
-  return size
-
-
-def WriteSize(size_symbol, size, output_file):
-  output_file.write('intptr_t %s = %d;\n' % (size_symbol, size))
-
-
-def Main():
-  opt_parser = BuildOptionParser()
-  (options, args) = opt_parser.parse_args()
-  if not ValidateOptions(options):
-    opt_parser.print_help()
-    return 1
-  if args:
-    sys.stderr.write('Unknown args: "%s"\n' % str(args))
-    parser.print_help()
-    return 1
-
-  with open(options.output, 'w') as output_file:
-    output_file.write('#include <stdint.h>\n')
-    output_file.write('extern "C" {\n')
-    size = WriteData(options.dill_file, options.data_symbol, output_file)
-    WriteSize(options.size_symbol, size, output_file)
-    output_file.write("}")
-
-
-if __name__ == '__main__':
-  sys.exit(Main())