Created
August 7, 2018 12:45
-
-
Save ORBAT/ef397b68569560d0ed62b544b42c1bdf to your computer and use it in GitHub Desktop.
Playing around with HiPE compilation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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