[llvm] [OCaml][NPM] Add OCaml bindings to new pass manager (PR #66421)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 14 12:57:48 PDT 2023


================
@@ -0,0 +1,135 @@
+/*===-- passbuilder_ocaml.c - LLVM OCaml Glue -------------------*- C++ -*-===*\
+|*                                                                            *|
+|* Part of the LLVM Project, under the Apache License v2.0 with LLVM          *|
+|* Exceptions.                                                                *|
+|* See https://llvm.org/LICENSE.txt for license information.                  *|
+|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception                    *|
+|*                                                                            *|
+|*===----------------------------------------------------------------------===*|
+|*                                                                            *|
+|* This file glues LLVM's OCaml interface to its C interface. These functions *|
+|* are by and large transparent wrappers to the corresponding C functions.    *|
+|*                                                                            *|
+|* Note that these functions intentionally take liberties with the CAMLparamX *|
+|* macros, since most of the parameters are not GC heap objects.              *|
+|*                                                                            *|
+\*===----------------------------------------------------------------------===*/
+
+#include "llvm_ocaml.h"
+#include "target_ocaml.h"
+#include "llvm-c/Error.h"
+#include "llvm-c/Transforms/PassBuilder.h"
+#include <caml/memory.h>
+
+#define PassBuilderOptions_val(v) ((LLVMPassBuilderOptionsRef)from_val(v))
+
+value llvm_run_passes(value M, value Passes, value TM, value Options) {
+  LLVMErrorRef Err =
+      LLVMRunPasses(Module_val(M), String_val(Passes), TargetMachine_val(TM),
+                    PassBuilderOptions_val(Options));
+  if (Err == LLVMErrorSuccess) {
+    value result = caml_alloc(1, 0);
----------------
alan-j-hu wrote:

Yes, this is what I meant by sharing the allocation.

https://github.com/llvm/llvm-project/pull/66421


More information about the llvm-commits mailing list