diff options
author | Björn Gustavsson <[email protected]> | 2016-12-15 09:20:12 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2017-01-12 12:10:11 +0100 |
commit | 7d3502edc002ecf8c02eeacd313bf9353067ba0d (patch) | |
tree | b54e2f52560c749798c5ade5c3cb509485528c93 /lib/compiler/src | |
parent | e701ae9aa398f34014e2957921c5e2dbecabbcd5 (diff) | |
download | otp-7d3502edc002ecf8c02eeacd313bf9353067ba0d.tar.gz otp-7d3502edc002ecf8c02eeacd313bf9353067ba0d.tar.bz2 otp-7d3502edc002ecf8c02eeacd313bf9353067ba0d.zip |
beam_clean: Add types and specs
Diffstat (limited to 'lib/compiler/src')
-rw-r--r-- | lib/compiler/src/beam_clean.erl | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/compiler/src/beam_clean.erl b/lib/compiler/src/beam_clean.erl index 10805a3c36..b736d39f9c 100644 --- a/lib/compiler/src/beam_clean.erl +++ b/lib/compiler/src/beam_clean.erl @@ -26,6 +26,9 @@ -export([clean_labels/1]). -import(lists, [map/2,foldl/3,reverse/1,filter/2]). +-spec module(beam_utils:module_code(), [compile:option()]) -> + {'ok',beam_utils:module_code()}. + module({Mod,Exp,Attr,Fs0,_}, Opts) -> Order = [Lbl || {function,_,_,Lbl,_} <- Fs0], All = foldl(fun({function,_,_,Lbl,_}=Func,D) -> dict:store(Lbl, Func, D) end, @@ -39,6 +42,10 @@ module({Mod,Exp,Attr,Fs0,_}, Opts) -> {ok,{Mod,Exp,Attr,Fs,Lc}}. %% Remove all bs_save2/2 instructions not referenced by a bs_restore2/2. + +-spec bs_clean_saves([beam_utils:instruction()]) -> + [beam_utils:instruction()]. + bs_clean_saves(Is) -> Needed = bs_restores(Is, []), bs_clean_saves_1(Is, gb_sets:from_list(Needed), []). @@ -98,13 +105,18 @@ add_to_work_list(F, {Fs,Used}=Sets) -> %%% want to see the expanded code in a .S file. %%% --record(st, {lmap, %Translation tables for labels. - entry, %Number of entry label. - lc %Label counter +-type label() :: beam_asm:label(). + +-record(st, {lmap :: [{label(),label()}], %Translation tables for labels. + entry :: beam_asm:label(), %Number of entry label. + lc :: non_neg_integer() %Label counter }). +-spec clean_labels([beam_utils:instruction()]) -> + {[beam_utils:instruction()],pos_integer()}. + clean_labels(Fs0) -> - St0 = #st{lmap=[],lc=1}, + St0 = #st{lmap=[],entry=1,lc=1}, {Fs1,#st{lmap=Lmap0,lc=Lc}} = function_renumber(Fs0, St0, []), Lmap = gb_trees:from_orddict(ordsets:from_list(Lmap0)), Fs = function_replace(Fs1, Lmap, []), |