diff options
author | Anders Svensson <[email protected]> | 2013-12-01 14:19:27 +0100 |
---|---|---|
committer | Anders Svensson <[email protected]> | 2013-12-01 19:34:22 +0100 |
commit | 2eb76ba556b8775cffc94eac26b448eac70af267 (patch) | |
tree | ca08b7baf11525683b9f7b642aae572174f6d723 /lib/diameter | |
parent | 743773a87e24db2ba0f0222bcf4dcaba7ae7adcf (diff) | |
download | otp-2eb76ba556b8775cffc94eac26b448eac70af267.tar.gz otp-2eb76ba556b8775cffc94eac26b448eac70af267.tar.bz2 otp-2eb76ba556b8775cffc94eac26b448eac70af267.zip |
Return compilable forms instead of beam
That is, preprocessed forms that can be passed to compile:forms/1,2.
Diffstat (limited to 'lib/diameter')
-rw-r--r-- | lib/diameter/doc/src/diameter_make.xml | 21 | ||||
-rw-r--r-- | lib/diameter/src/compiler/diameter_codegen.erl | 26 | ||||
-rw-r--r-- | lib/diameter/src/compiler/diameter_make.erl | 5 | ||||
-rw-r--r-- | lib/diameter/test/diameter_compiler_SUITE.erl | 33 |
4 files changed, 34 insertions, 51 deletions
diff --git a/lib/diameter/doc/src/diameter_make.xml b/lib/diameter/doc/src/diameter_make.xml index c8c0f2fbc7..68780b1e05 100644 --- a/lib/diameter/doc/src/diameter_make.xml +++ b/lib/diameter/doc/src/diameter_make.xml @@ -1,5 +1,7 @@ <?xml version="1.0" encoding="latin1" ?> <!DOCTYPE erlref SYSTEM "erlref.dtd" [ + <!ENTITY compile_forms2 + '<seealso marker="compiler:compile#forms-2">compile:forms/2</seealso>'> <!ENTITY filename '<seealso marker="kernel:file#type-name">file:name()</seealso>'> <!ENTITY dictionary @@ -80,28 +82,27 @@ written to file or returned, and can have the following types.</p> <taglist> -<tag><c>parse | forms | erl | hrl | beam</c></tag> +<tag><c>parse | forms | erl | hrl</c></tag> <item> <p> Specifies an output format. Whether the output is returned or written to file depends on whether or not option <c>return</c> is specified. When written to file, the resulting file(s) will have extensions -<c>.D</c>, <c>.F</c>, <c>.erl</c>, <c>.hrl</c> and <c>.beam</c> +<c>.D</c>, <c>.F</c>, <c>.erl</c>, and <c>.hrl</c> respectively, basenames defaulting to <c>dictionary</c> if the input dictionary is literal and does not specify <c>&dict_name;</c>. -When returned, results are returned in the <c>Out</c> list in the -order specified. +When returned, results are in the order of the corresponding format +options. Format options default to <c>erl</c> and <c>hrl</c> (in this order) if unspecified.</p> <p> -The <c>parsed</c> format is an internal representation that can be -passed to &format; and &flatten;, while the <c>forms</c> format is -only intended for debugging purposes. -Output for the <c>erl</c> and <c>hrl</c> formats are returned as -iolists, while the <c>beam</c> format returns a <c>{module(), -binary()}</c> tuple.</p> +The <c>parse</c> format is an internal representation that can be +passed to &flatten; and &format;, while the <c>forms</c> format can be +passed to &compile_forms2;. +The <c>erl</c> and <c>hrl</c> formats are returned as +iolists.</p> <!-- That codec/2 can take the parsed format is undocumented, and options name and inherits have no effect in this case. --> </item> diff --git a/lib/diameter/src/compiler/diameter_codegen.erl b/lib/diameter/src/compiler/diameter_codegen.erl index 47da193457..22422f2ef2 100644 --- a/lib/diameter/src/compiler/diameter_codegen.erl +++ b/lib/diameter/src/compiler/diameter_codegen.erl @@ -49,7 +49,7 @@ when File :: string(), ParseD :: orddict:orddict(), Opts :: list(), - Mode :: parse | forms | erl | hrl | beam. + Mode :: parse | forms | erl | hrl. from_dict(File, ParseD, Opts, Mode) -> Outdir = proplists:get_value(outdir, Opts, "."), @@ -85,8 +85,6 @@ do_write(M, Path, T) when M == parse; M == forms -> write_term(Path, T); -do_write(beam, Path, {_Mod, Beam}) -> - write(Path, Beam); do_write(_, Path, T) -> write(Path, T). @@ -130,10 +128,7 @@ gen(parse, ParseD, _Mod) -> [?VERSION | ParseD]; gen(forms, ParseD, Mod) -> - erl_forms(Mod, ParseD); - -gen(beam, ParseD, Mod) -> - compile(pp(erl_forms(Mod, ParseD))); + pp(erl_forms(Mod, ParseD)); gen(hrl, ParseD, Mod) -> gen_hrl(Mod, ParseD); @@ -141,17 +136,6 @@ gen(hrl, ParseD, Mod) -> gen(erl, ParseD, Mod) -> [header(), prettypr(erl_forms(Mod, ParseD)), $\n]. -compile({ok, Forms}) -> - case compile:forms(Forms, [debug_info, return]) of - {ok, Mod, Beam, _Warnings} -> - {Mod, Beam}; - {error, Errors, _Warnings} -> - erlang:error({compile, Errors}) - end; - -compile({error, Reason}) -> - erlang:error(Reason). - erl_forms(Mod, ParseD) -> Forms = [[{?attribute, module, Mod}, {?attribute, compile, {parse_transform, diameter_exprecs}}, @@ -866,10 +850,10 @@ pp(Forms) -> pp(Forms, {ok, Code}) -> Files = files(Code, []), - {ok, lists:flatmap(fun(T) -> include(T, Files) end, Forms)}; + lists:flatmap(fun(T) -> include(T, Files) end, Forms); -pp(_, {error, _} = No) -> - No. +pp(Forms, {error, Reason}) -> + erlang:error({forms, Reason, Forms}). include({attribute, _, include_lib, Path}, Files) -> Inc = filename:basename(Path), diff --git a/lib/diameter/src/compiler/diameter_make.erl b/lib/diameter/src/compiler/diameter_make.erl index 99034734c5..2f314b7e57 100644 --- a/lib/diameter/src/compiler/diameter_make.erl +++ b/lib/diameter/src/compiler/diameter_make.erl @@ -44,8 +44,7 @@ | return | verbose | parse %% internal parsed form - | forms %% abstract format from which erl is generated - | beam %% compiled directly from preprocessed forms + | forms %% abstract format for compile:forms/1,2 | erl | hrl. @@ -218,7 +217,7 @@ modes(Opts) -> lists:filter(fun is_mode/1, Opts). is_mode(T) -> - lists:member(T, [erl, hrl, parse, forms, beam]). + lists:member(T, [erl, hrl, parse, forms]). identify([Vsn | [T|_] = ParseD]) when is_tuple(T) -> diff --git a/lib/diameter/test/diameter_compiler_SUITE.erl b/lib/diameter/test/diameter_compiler_SUITE.erl index a37f52a2c5..ed369e8af3 100644 --- a/lib/diameter/test/diameter_compiler_SUITE.erl +++ b/lib/diameter/test/diameter_compiler_SUITE.erl @@ -435,7 +435,8 @@ generate(forms, File, _) -> generate(parse, File, Dict) -> {ok, [Dict]} = file:consult(File ++ ".D"), %% assert - {ok, [_]} = diameter_make:codec(Dict, [beam, return]); + {ok, [F]} = diameter_make:codec(Dict, [forms, return]), + {ok, _, _, _} = compile:forms(F, [return]); generate(hrl, _, _) -> ok. @@ -482,30 +483,23 @@ flatten2(_Config) -> "@inherits diameter_gen_base_rfc6733\n" "@avp_vendor_id 333 A1\n", - {ok, [E1, {_,B1}]} - = diameter_make:codec(Dict1, [erl, beam, return]), + {ok, [E1, F1]} + = diameter_make:codec(Dict1, [erl, forms, return]), ct:pal("~s", [E1]), - {module, diameter_test1} - = code:load_binary(diameter_test1, "diameter_test1", B1), + diameter_test1 = M1 = load_forms(F1), - - {ok, [D2, E2, {_,B2}]} - = diameter_make:codec(Dict2, [parse, erl, beam, return]), + {ok, [D2, E2, F2]} + = diameter_make:codec(Dict2, [parse, erl, forms, return]), ct:pal("~s", [E2]), - {module, diameter_test2} - = code:load_binary(diameter_test2, "diameter_test2", B2), - + diameter_test2 = M2 = load_forms(F2), Flat = lists:flatten(diameter_make:format(diameter_make:flatten(D2))), ct:pal("~s", [Flat]), - {ok, [E3, {_,B3}]} - = diameter_make:codec(Flat, [erl, beam, return, + {ok, [E3, F3]} + = diameter_make:codec(Flat, [erl, forms, return, {name, "diameter_test3"}]), ct:pal("~s", [E3]), - {module, diameter_test3} - = code:load_binary(diameter_test3, "diameter_test3", B3), - - {M1, M2, M3} = {diameter_test1, diameter_test2, diameter_test3}, + diameter_test3 = M3 = load_forms(F3), [{1001, 111, M1, 'A1'}, %% @avp_vendor_id {1002, 666, M1, 'A2'}, %% @vendor @@ -538,6 +532,11 @@ flatten2(_Config) -> 'Unsigned32'(T, 'A3', Ref) -> {T, Ref}. +load_forms(Forms) -> + {ok, Mod, Bin, _} = compile:forms(Forms, [return]), + {module, Mod} = code:load_binary(Mod, ?S(Mod), Bin), + Mod. + %% =========================================================================== modify(Bin, Mods) -> |