Skip to content

Instantly share code, notes, and snippets.

@ORBAT
Created August 7, 2018 12:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ORBAT/ef397b68569560d0ed62b544b42c1bdf to your computer and use it in GitHub Desktop.
Save ORBAT/ef397b68569560d0ed62b544b42c1bdf to your computer and use it in GitHub Desktop.
Playing around with HiPE compilation
defmodule HiPE.Loader do
@doc "Returns `module_info`s for all loaded modules, with `native: true|false`"
def all_modules(native \\ false) do
:code.all_loaded()
|> Enum.map(&elem(&1, 0))
|> Enum.map(&Kernel.apply(&1, :module_info, []))
|> Enum.map(&Enum.into(&1, %{}))
|> Enum.filter(fn %{compile: compile} ->
!match?([], compile)
end)
|> Enum.filter(&(&1.native == native))
end
@doc "HiPE compile the given modules (as returned by `all_modules/1`) with the given options. See the `:hipe` Erlang module for more info"
def to_hipe(modules, opts \\ [:load, :o3, :verbose]) do
modules
|> Enum.map(& &1.module)
|> Enum.map(&:hipe.c(&1, opts))
end
@doc "Compile all modules"
def all_to_hipe(native \\ false) do
all_modules(native) |> to_hipe()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment