aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src/asn1ct_gen.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2014-01-22 16:19:10 +0100
committerBjörn Gustavsson <[email protected]>2014-01-22 16:19:10 +0100
commit990b655c92f889d2c45e6f43ee6fdae29ffc8464 (patch)
tree5e1fb70caadb1374130b86989537c9e024ffb8dd /lib/asn1/src/asn1ct_gen.erl
parentd203887853971d58a4054400a88f91bbf73b19c8 (diff)
parent7699312823b259c3735d7045b4224a50d1256ec5 (diff)
downloadotp-990b655c92f889d2c45e6f43ee6fdae29ffc8464.tar.gz
otp-990b655c92f889d2c45e6f43ee6fdae29ffc8464.tar.bz2
otp-990b655c92f889d2c45e6f43ee6fdae29ffc8464.zip
Merge branch 'bjorn/asn1/optimizations/OTP-11573'
* bjorn/asn1/optimizations/OTP-11573: Optimize code surrounding calls to complete/1 asn1ct_imm: Add the intermediate instruction {list,List,Dst} Generate intermediate code that is easier to optimize asn1ct_imm: Add the {set,{var,Src},{var,Dst}} instruction Keep type information in the apply intermediate instruction asn1ct_imm: Add a field for intermediate code for call_gen Introduce asn1ct_gen:open_output_file/1 Factor out printing of verbose messages Improve optimization of alignment for encoding Improve construction of {cons,H,T} instructions Teach asn1ct_func:call_gen/4 to quote the generated function name Test open types that may need more than 128 bytes
Diffstat (limited to 'lib/asn1/src/asn1ct_gen.erl')
-rw-r--r--lib/asn1/src/asn1ct_gen.erl24
1 files changed, 13 insertions, 11 deletions
diff --git a/lib/asn1/src/asn1ct_gen.erl b/lib/asn1/src/asn1ct_gen.erl
index 30d337635b..37b33194d0 100644
--- a/lib/asn1/src/asn1ct_gen.erl
+++ b/lib/asn1/src/asn1ct_gen.erl
@@ -23,6 +23,7 @@
-export([demit/1,
emit/1,
+ open_output_file/1,close_output_file/0,
get_inner/1,type/1,def_to_tag/1,prim_bif/1,
list2name/1,
list2rname/1,
@@ -70,8 +71,7 @@ pgen_module(OutFile,Erules,Module,
HrlGenerated = pgen_hrl(Erules,Module,TypeOrVal,Options,Indent),
asn1ct_name:start(),
ErlFile = lists:concat([OutFile,".erl"]),
- Fid = fopen(ErlFile),
- put(gen_file_out,Fid),
+ open_output_file(ErlFile),
asn1ct_func:start_link(),
gen_head(Erules,Module,HrlGenerated),
pgen_exports(Erules,Module,TypeOrVal),
@@ -85,9 +85,9 @@ pgen_module(OutFile,Erules,Module,
"%%%",nl,
"%%% Run-time functions.",nl,
"%%%",nl]),
- asn1ct_func:generate(Fid),
- file:close(Fid),
- _ = erase(gen_file_out),
+ Fd = get(gen_file_out),
+ asn1ct_func:generate(Fd),
+ close_output_file(),
_ = erase(outfile),
asn1ct:verbose("--~p--~n",[{generated,ErlFile}],Options).
@@ -1121,8 +1121,7 @@ pgen_info() ->
open_hrl(OutFile,Module) ->
File = lists:concat([OutFile,".hrl"]),
- Fid = fopen(File),
- put(gen_file_out,Fid),
+ open_output_file(File),
gen_hrlhead(Module).
%% EMIT functions ************************
@@ -1195,15 +1194,19 @@ call_args([A|As], Sep) ->
[Sep,do_emit(A)|call_args(As, ", ")];
call_args([], _) -> [].
-fopen(F) ->
+open_output_file(F) ->
case file:open(F, [write,raw,delayed_write]) of
- {ok, Fd} ->
+ {ok,Fd} ->
+ put(gen_file_out, Fd),
Fd;
{error, Reason} ->
io:format("** Can't open file ~p ~n", [F]),
exit({error,Reason})
end.
+close_output_file() ->
+ ok = file:close(erase(gen_file_out)).
+
pgen_hrl(Erules,Module,TypeOrVal,Options,_Indent) ->
put(currmod,Module),
{Types,Values,Ptypes,_,_,_} = TypeOrVal,
@@ -1226,8 +1229,7 @@ pgen_hrl(Erules,Module,TypeOrVal,Options,_Indent) ->
0 ->
0;
Y ->
- Fid = get(gen_file_out),
- file:close(Fid),
+ close_output_file(),
asn1ct:verbose("--~p--~n",
[{generated,lists:concat([get(outfile),".hrl"])}],
Options),