Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/packbeam.erl
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ do_create(Opts, Args) ->
#{
prune => maps:get(prune, Opts, false),
start_module => maps:get(start_module, Opts, undefined),
include_lines => not maps:get(remove_lines, Opts, false)
include_lines => not maps:get(remove_lines, Opts, false),
arch => maps:get(arch, Opts, undefined)
}
),
0.
Expand Down Expand Up @@ -346,5 +347,9 @@ parse_args(["-f", Format | T], {Opts, Args}) ->
parse_args(["--format", Format | T], {Opts, Args});
parse_args(["--format", Format | T], {Opts, Args}) ->
parse_args(T, {Opts#{format => Format}, Args});
parse_args(["--arch", Arch | T], {Opts, Args}) ->
parse_args(T, {Opts#{arch => list_to_atom(Arch)}, Args});
parse_args(["--platform", Platform | T], {Opts, Args}) ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to add these parameters to the print_help() function in packbeam.erl.

parse_args(T, {Opts#{platform => list_to_atom(Platform)}, Args});
parse_args([H | T], {Opts, Args}) ->
parse_args(T, {Opts, [H | Args]}).
94 changes: 83 additions & 11 deletions src/packbeam_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
prune => boolean(),
start_module => module() | undefined,
application_module => module() | undefined,
include_lines => boolean()
include_lines => boolean(),
arch => atom()
}.

-export_type([
Expand All @@ -68,7 +69,9 @@
prune => false,
start_module => undefined,
application_module => undefined,
include_lines => true
include_lines => true,
arch => undefined,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to make the arch parameter pass though all of the atomvm_rebar3_plugin tasks, so the default (non-jit) arch will be emu for the standard emulated VM. It will simplify integration if we use emu here as the default if no native arch target is supplied.

platform => generic_unix
}).

%%
Expand All @@ -88,7 +91,9 @@
%% prune => false,
%% start_module => undefined,
%% application_module => undefined,
%% include_lines => false
%% include_lines => false,
%% arch => undefined,
%% platform => generic_unix
%% }'
%%
%% @end
Expand Down Expand Up @@ -122,15 +127,20 @@ create(OutputPath, InputPaths, Options) ->
prune := Prune,
start_module := StartModule,
application_module := ApplicationModule,
include_lines := IncludeLines
include_lines := IncludeLines,
arch := Arch,
platform := Platform
} = maps:merge(?DEFAULT_OPTIONS, Options),
ParsedFiles = parse_files(InputPaths, StartModule, IncludeLines),
Files0 = parse_files(InputPaths, StartModule, IncludeLines),
Files1 = filter_jit(Files0, Arch, Platform),
Files2 =
if
Prune -> prune(Files1, ApplicationModule);
true -> Files1
end,
write_packbeam(
OutputPath,
case Prune of
true -> prune(ParsedFiles, ApplicationModule);
_ -> ParsedFiles
end
Files2
).

%%-----------------------------------------------------------------------------
Expand Down Expand Up @@ -782,9 +792,14 @@ ends_with(String, Suffix) ->

%% @private
filter_chunks(Chunks, IncludeLines) ->
AllowedChunks = allowed_chunks(IncludeLines),
AllowedChunks0 = allowed_chunks(IncludeLines),
AllowedChunks1 =
case lists:keymember("avmN", 1, Chunks) of
true -> AllowedChunks0 -- ["Code", "Type"];
false -> AllowedChunks0 -- ["avmN"]
end,
lists:filter(
fun({Tag, _Data}) -> lists:member(Tag, AllowedChunks) end,
fun({Tag, _Data}) -> lists:member(Tag, AllowedChunks1) end,
Chunks
).

Expand Down Expand Up @@ -853,3 +868,60 @@ deduplicate([]) ->
[];
deduplicate([H | T]) ->
[H | [X || X <- deduplicate(T), X /= H]].

filter_jit(Files0, undefined, generic_unix) ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether or not we use emu as the default non jit arch I think we should also match undefined too and the third parameter should match to anything (for either undefined or emu), since the emulated code can be run on any platform and some user or even another application using the API might pass a different "platform" here, which should be allowed.

Files0;
filter_jit(Files0, aarch64, generic_unix) ->
lists:filter(
fun(File) ->
filter_jit0(File, [
"jit.beam", "jit_stream_mmap.beam", "jit_aarch64.beam", "jit_aarch64_asm.beam"
])
end,
Files0
);
filter_jit(Files0, x86_64, generic_unix) ->
lists:filter(
fun(File) ->
filter_jit0(File, [
"jit.beam", "jit_stream_mmap.beam", "jit_x86_64.beam", "jit_x86_64_asm.beam"
])
end,
Files0
);
filter_jit(Files0, armv6m, generic_unix) ->
lists:filter(
fun(File) ->
filter_jit0(File, [
"jit.beam", "jit_stream_mmap.beam", "jit_armv6m.beam", "jit_armv6m_asm.beam"
])
end,
Files0
);
filter_jit(Files0, armv6m, rp2) ->
lists:filter(
fun(File) ->
filter_jit0(File, [
"jit.beam", "jit_stream_flash.beam", "jit_armv6m.beam", "jit_armv6m_asm.beam"
])
end,
Files0
);
filter_jit(Files0, armv6m, stm32) ->
lists:filter(
fun(File) ->
filter_jit0(File, [
"jit.beam", "jit_stream_flash.beam", "jit_armv6m.beam", "jit_armv6m_asm.beam"
])
end,
Files0
).

filter_jit0(File, JITModules) ->
ModuleName = lists:flatten(get_element_name(File)),
case ModuleName of
"jit" ++ _ ->
lists:member(ModuleName, JITModules);
_ ->
true
end.