Remove kernel isolate API from the public dart_api.h

This is the first step in moving the kernel isolate out
of the VM and into the standalone embedder.

Bug: https://github.com/dart-lang/sdk/issues/33433
Change-Id: Ie8d9ac1c27efe2661f0441b75275119966d197af
Reviewed-on: https://dart-review.googlesource.com/c/84829
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
diff --git a/runtime/bin/BUILD.gn b/runtime/bin/BUILD.gn
index fd56f45..d3bc4df 100644
--- a/runtime/bin/BUILD.gn
+++ b/runtime/bin/BUILD.gn
@@ -157,6 +157,8 @@
       "dfe.cc",
       "dfe.h",
       "gen_snapshot.cc",
+      "kernel_isolate.cc",
+      "kernel_isolate.h",
       "options.cc",
       "options.h",
       "vmservice_impl.cc",
@@ -717,6 +719,8 @@
                 "dart_embedder_api_impl.cc",
                 "error_exit.cc",
                 "error_exit.h",
+                "kernel_isolate.cc",
+                "kernel_isolate.h",
                 "main.cc",
                 "main_options.cc",
                 "main_options.h",
@@ -939,6 +943,8 @@
               "dfe.h",
               "error_exit.cc",
               "error_exit.h",
+              "kernel_isolate.cc",
+              "kernel_isolate.h",
               "run_vm_tests.cc",
               "snapshot_utils.cc",
               "snapshot_utils.h",
diff --git a/runtime/bin/dfe.h b/runtime/bin/dfe.h
index af520658..47d95d2 100644
--- a/runtime/bin/dfe.h
+++ b/runtime/bin/dfe.h
@@ -5,6 +5,7 @@
 #ifndef RUNTIME_BIN_DFE_H_
 #define RUNTIME_BIN_DFE_H_
 
+#include "bin/kernel_isolate.h"
 #include "include/dart_api.h"
 #include "include/dart_native_api.h"
 #include "platform/assert.h"
diff --git a/runtime/bin/kernel_isolate.cc b/runtime/bin/kernel_isolate.cc
new file mode 100644
index 0000000..c6bc711
--- /dev/null
+++ b/runtime/bin/kernel_isolate.cc
@@ -0,0 +1,110 @@
+// 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.
+
+#include "bin/kernel_isolate.h"
+
+#include "vm/dart_api_impl.h"
+#include "vm/isolate.h"
+#include "vm/kernel_isolate.h"
+
+namespace dart {
+
+DART_EXPORT bool Dart_IsKernelIsolate(Dart_Isolate isolate) {
+#if defined(DART_PRECOMPILED_RUNTIME)
+  return false;
+#else
+  Isolate* iso = reinterpret_cast<Isolate*>(isolate);
+  return KernelIsolate::IsKernelIsolate(iso);
+#endif
+}
+
+DART_EXPORT bool Dart_KernelIsolateIsRunning() {
+#if defined(DART_PRECOMPILED_RUNTIME)
+  return false;
+#else
+  return KernelIsolate::IsRunning();
+#endif
+}
+
+DART_EXPORT Dart_Port Dart_KernelPort() {
+#if defined(DART_PRECOMPILED_RUNTIME)
+  return false;
+#else
+  return KernelIsolate::KernelPort();
+#endif
+}
+
+DART_EXPORT Dart_KernelCompilationResult
+Dart_CompileToKernel(const char* script_uri,
+                     const uint8_t* platform_kernel,
+                     intptr_t platform_kernel_size,
+                     bool incremental_compile,
+                     const char* package_config) {
+  API_TIMELINE_DURATION(Thread::Current());
+
+  Dart_KernelCompilationResult result;
+#if defined(DART_PRECOMPILED_RUNTIME)
+  result.status = Dart_KernelCompilationStatus_Unknown;
+  result.error = strdup("Dart_CompileToKernel is unsupported.");
+#else
+  result = KernelIsolate::CompileToKernel(script_uri, platform_kernel,
+                                          platform_kernel_size, 0, NULL,
+                                          incremental_compile, package_config);
+  if (result.status == Dart_KernelCompilationStatus_Ok) {
+    Dart_KernelCompilationResult accept_result =
+        KernelIsolate::AcceptCompilation();
+    if (accept_result.status != Dart_KernelCompilationStatus_Ok) {
+      FATAL1(
+          "An error occurred in the CFE while accepting the most recent"
+          " compilation results: %s",
+          accept_result.error);
+    }
+  }
+#endif
+  return result;
+}
+
+DART_EXPORT Dart_KernelCompilationResult
+Dart_CompileSourcesToKernel(const char* script_uri,
+                            const uint8_t* platform_kernel,
+                            intptr_t platform_kernel_size,
+                            int source_files_count,
+                            Dart_SourceFile sources[],
+                            bool incremental_compile,
+                            const char* package_config,
+                            const char* multiroot_filepaths,
+                            const char* multiroot_scheme) {
+  Dart_KernelCompilationResult result;
+#if defined(DART_PRECOMPILED_RUNTIME)
+  result.status = Dart_KernelCompilationStatus_Unknown;
+  result.error = strdup("Dart_CompileSourcesToKernel is unsupported.");
+#else
+  result = KernelIsolate::CompileToKernel(
+      script_uri, platform_kernel, platform_kernel_size, source_files_count,
+      sources, incremental_compile, package_config, multiroot_filepaths,
+      multiroot_scheme);
+  if (result.status == Dart_KernelCompilationStatus_Ok) {
+    if (KernelIsolate::AcceptCompilation().status !=
+        Dart_KernelCompilationStatus_Ok) {
+      FATAL(
+          "An error occurred in the CFE while accepting the most recent"
+          " compilation results.");
+    }
+  }
+#endif
+  return result;
+}
+
+DART_EXPORT Dart_KernelCompilationResult Dart_KernelListDependencies() {
+  Dart_KernelCompilationResult result;
+#if defined(DART_PRECOMPILED_RUNTIME)
+  result.status = Dart_KernelCompilationStatus_Unknown;
+  result.error = strdup("Dart_KernelListDependencies is unsupported.");
+#else
+  result = KernelIsolate::ListDependencies();
+#endif
+  return result;
+}
+
+}  // namespace dart
diff --git a/runtime/bin/kernel_isolate.h b/runtime/bin/kernel_isolate.h
new file mode 100644
index 0000000..4a9e667
--- /dev/null
+++ b/runtime/bin/kernel_isolate.h
@@ -0,0 +1,58 @@
+// 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.
+
+#ifndef RUNTIME_BIN_KERNEL_ISOLATE_H_
+#define RUNTIME_BIN_KERNEL_ISOLATE_H_
+
+#include "include/dart_api.h"
+
+namespace dart {
+
+typedef enum {
+  Dart_KernelCompilationStatus_Unknown = -1,
+  Dart_KernelCompilationStatus_Ok = 0,
+  Dart_KernelCompilationStatus_Error = 1,
+  Dart_KernelCompilationStatus_Crash = 2,
+} Dart_KernelCompilationStatus;
+
+typedef struct {
+  Dart_KernelCompilationStatus status;
+  char* error;
+
+  uint8_t* kernel;
+  intptr_t kernel_size;
+} Dart_KernelCompilationResult;
+
+DART_EXPORT bool Dart_IsKernelIsolate(Dart_Isolate isolate);
+DART_EXPORT bool Dart_KernelIsolateIsRunning();
+DART_EXPORT Dart_Port Dart_KernelPort();
+DART_EXPORT Dart_KernelCompilationResult
+Dart_CompileToKernel(const char* script_uri,
+                     const uint8_t* platform_kernel,
+                     const intptr_t platform_kernel_size,
+                     bool incremental_compile,
+                     const char* package_config);
+
+typedef struct {
+  const char* uri;
+  const char* source;
+} Dart_SourceFile;
+DART_EXPORT Dart_KernelCompilationResult
+Dart_CompileSourcesToKernel(const char* script_uri,
+                            const uint8_t* platform_kernel,
+                            intptr_t platform_kernel_size,
+                            int source_files_count,
+                            Dart_SourceFile source_files[],
+                            bool incremental_compile,
+                            const char* package_config,
+                            const char* multiroot_filepaths,
+                            const char* multiroot_scheme);
+
+DART_EXPORT Dart_KernelCompilationResult Dart_KernelListDependencies();
+
+#define DART_KERNEL_ISOLATE_NAME "kernel-service"
+
+}  // namespace dart
+
+#endif  // RUNTIME_BIN_KERNEL_ISOLATE_H_
diff --git a/runtime/include/dart_api.h b/runtime/include/dart_api.h
index 01e0668..9bfdefa 100644
--- a/runtime/include/dart_api.h
+++ b/runtime/include/dart_api.h
@@ -3083,65 +3083,6 @@
 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer);
 
 /*
- * ======
- * Kernel
- * ======
- */
-
-/**
- * Experimental support for Dart to Kernel parser isolate.
- *
- * TODO(hausner): Document finalized interface.
- *
- */
-
-// TODO(33433): Remove kernel service from the embedding API.
-
-typedef enum {
-  Dart_KernelCompilationStatus_Unknown = -1,
-  Dart_KernelCompilationStatus_Ok = 0,
-  Dart_KernelCompilationStatus_Error = 1,
-  Dart_KernelCompilationStatus_Crash = 2,
-} Dart_KernelCompilationStatus;
-
-typedef struct {
-  Dart_KernelCompilationStatus status;
-  char* error;
-
-  uint8_t* kernel;
-  intptr_t kernel_size;
-} Dart_KernelCompilationResult;
-
-DART_EXPORT bool Dart_IsKernelIsolate(Dart_Isolate isolate);
-DART_EXPORT bool Dart_KernelIsolateIsRunning();
-DART_EXPORT Dart_Port Dart_KernelPort();
-DART_EXPORT Dart_KernelCompilationResult
-Dart_CompileToKernel(const char* script_uri,
-                     const uint8_t* platform_kernel,
-                     const intptr_t platform_kernel_size,
-                     bool incremental_compile,
-                     const char* package_config);
-
-typedef struct {
-  const char* uri;
-  const char* source;
-} Dart_SourceFile;
-DART_EXPORT Dart_KernelCompilationResult
-Dart_CompileSourcesToKernel(const char* script_uri,
-                            const uint8_t* platform_kernel,
-                            intptr_t platform_kernel_size,
-                            int source_files_count,
-                            Dart_SourceFile source_files[],
-                            bool incremental_compile,
-                            const char* package_config,
-                            const char* multiroot_filepaths,
-                            const char* multiroot_scheme);
-
-DART_EXPORT Dart_KernelCompilationResult Dart_KernelListDependencies();
-
-#define DART_KERNEL_ISOLATE_NAME "kernel-service"
-
-/*
  * =======
  * Service
  * =======
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index c6a5a93..e179fca 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -5614,105 +5614,6 @@
   return Api::Success();
 }
 
-// --- Dart Front-End (Kernel) support ---
-
-DART_EXPORT bool Dart_IsKernelIsolate(Dart_Isolate isolate) {
-#if defined(DART_PRECOMPILED_RUNTIME)
-  return false;
-#else
-  Isolate* iso = reinterpret_cast<Isolate*>(isolate);
-  return KernelIsolate::IsKernelIsolate(iso);
-#endif
-}
-
-DART_EXPORT bool Dart_KernelIsolateIsRunning() {
-#if defined(DART_PRECOMPILED_RUNTIME)
-  return false;
-#else
-  return KernelIsolate::IsRunning();
-#endif
-}
-
-DART_EXPORT Dart_Port Dart_KernelPort() {
-#if defined(DART_PRECOMPILED_RUNTIME)
-  return false;
-#else
-  return KernelIsolate::KernelPort();
-#endif
-}
-
-DART_EXPORT Dart_KernelCompilationResult
-Dart_CompileToKernel(const char* script_uri,
-                     const uint8_t* platform_kernel,
-                     intptr_t platform_kernel_size,
-                     bool incremental_compile,
-                     const char* package_config) {
-  API_TIMELINE_DURATION(Thread::Current());
-
-  Dart_KernelCompilationResult result;
-#if defined(DART_PRECOMPILED_RUNTIME)
-  result.status = Dart_KernelCompilationStatus_Unknown;
-  result.error = strdup("Dart_CompileToKernel is unsupported.");
-#else
-  result = KernelIsolate::CompileToKernel(script_uri, platform_kernel,
-                                          platform_kernel_size, 0, NULL,
-                                          incremental_compile, package_config);
-  if (result.status == Dart_KernelCompilationStatus_Ok) {
-    Dart_KernelCompilationResult accept_result =
-        KernelIsolate::AcceptCompilation();
-    if (accept_result.status != Dart_KernelCompilationStatus_Ok) {
-      FATAL1(
-          "An error occurred in the CFE while accepting the most recent"
-          " compilation results: %s",
-          accept_result.error);
-    }
-  }
-#endif
-  return result;
-}
-
-DART_EXPORT Dart_KernelCompilationResult
-Dart_CompileSourcesToKernel(const char* script_uri,
-                            const uint8_t* platform_kernel,
-                            intptr_t platform_kernel_size,
-                            int source_files_count,
-                            Dart_SourceFile sources[],
-                            bool incremental_compile,
-                            const char* package_config,
-                            const char* multiroot_filepaths,
-                            const char* multiroot_scheme) {
-  Dart_KernelCompilationResult result;
-#if defined(DART_PRECOMPILED_RUNTIME)
-  result.status = Dart_KernelCompilationStatus_Unknown;
-  result.error = strdup("Dart_CompileSourcesToKernel is unsupported.");
-#else
-  result = KernelIsolate::CompileToKernel(
-      script_uri, platform_kernel, platform_kernel_size, source_files_count,
-      sources, incremental_compile, package_config, multiroot_filepaths,
-      multiroot_scheme);
-  if (result.status == Dart_KernelCompilationStatus_Ok) {
-    if (KernelIsolate::AcceptCompilation().status !=
-        Dart_KernelCompilationStatus_Ok) {
-      FATAL(
-          "An error occurred in the CFE while accepting the most recent"
-          " compilation results.");
-    }
-  }
-#endif
-  return result;
-}
-
-DART_EXPORT Dart_KernelCompilationResult Dart_KernelListDependencies() {
-  Dart_KernelCompilationResult result;
-#if defined(DART_PRECOMPILED_RUNTIME)
-  result.status = Dart_KernelCompilationStatus_Unknown;
-  result.error = strdup("Dart_KernelListDependencies is unsupported.");
-#else
-  result = KernelIsolate::ListDependencies();
-#endif
-  return result;
-}
-
 // --- Service support ---
 
 DART_EXPORT bool Dart_IsServiceIsolate(Dart_Isolate isolate) {
diff --git a/runtime/vm/isolate_reload.h b/runtime/vm/isolate_reload.h
index 082bc48..35e6a7d 100644
--- a/runtime/vm/isolate_reload.h
+++ b/runtime/vm/isolate_reload.h
@@ -7,6 +7,7 @@
 
 #include "include/dart_tools_api.h"
 
+#include "bin/kernel_isolate.h"
 #include "vm/globals.h"
 #include "vm/growable_array.h"
 #include "vm/hash_map.h"
diff --git a/runtime/vm/kernel_isolate.h b/runtime/vm/kernel_isolate.h
index a271351..ed610c5 100644
--- a/runtime/vm/kernel_isolate.h
+++ b/runtime/vm/kernel_isolate.h
@@ -8,6 +8,7 @@
 #include "include/dart_api.h"
 #include "include/dart_native_api.h"
 
+#include "bin/kernel_isolate.h"
 #include "vm/allocation.h"
 #include "vm/dart.h"
 #include "vm/os_thread.h"
diff --git a/runtime/vm/unit_test.h b/runtime/vm/unit_test.h
index 6c53746..e99f521 100644
--- a/runtime/vm/unit_test.h
+++ b/runtime/vm/unit_test.h
@@ -9,6 +9,7 @@
 
 #include "platform/globals.h"
 
+#include "bin/kernel_isolate.h"
 #include "vm/dart.h"
 #include "vm/dart_api_state.h"
 #include "vm/dart_entry.h"