Pt 164460166 generate documentation (#17)

* Generate docs.

* Test lists of length 16.
This commit is contained in:
Erik Stenman 2019-03-08 07:59:09 +01:00 committed by GitHub
parent 6c60f1e37f
commit 9763a1a6f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 0 deletions

View File

@ -2,6 +2,7 @@
-export([ gen_and_halt/1
, generate/0
, generate_documentation/1
, test_asm_generator/1]).
gen_and_halt([SrcDirArg, IncludeDirArg]) ->
@ -635,3 +636,52 @@ gen_variant() ->
2 -> "(| 2 | 1 | ( " ++ imm_arg() ++ " ) |)";
3 -> "(| 2 | 0 | ( " ++ imm_arg() ++ ", " ++ imm_arg() ++ " ) |)"
end.
%% TODO: add gas cost.
generate_documentation(Filename) ->
{ok, File} = file:open(Filename, [write]),
Instructions = lists:flatten([gen_doc(Op)++"\n" || Op <- gen(ops_defs())]),
io:format(File,
"### Operations\n\n"
"| OpCode | Name | Args | Description |\n"
"| --- | --- | --- | --- |\n"
"~s"
, [Instructions]),
io:format(File, "\n", []),
file:close(File).
gen_doc(#{ opname := Name
, opcode := OpCode
, args := Args
, end_bb := EndBB
, format := FateFormat
, macro := Macro
, type_name := TypeName
, doc := Doc
, gas := Gas
, type := Type
, constructor := Constructor
, constructor_type := ConstructorType
}) ->
Arguments =
case FateFormat of
atomic -> "";
_ -> lists:join(" ",
[format_arg_doc(A) ||
A <-
lists:zip(FateFormat,
lists:seq(0,length(FateFormat)-1))])
end,
io_lib:format("| 0x~.16b | ~w | ~s | ~s |\n",
[ OpCode
, Name
, Arguments
, Doc]).
format_arg_doc({a, N}) -> io_lib:format("Arg~w", [N]);
format_arg_doc({is,N}) -> "Identifier";
format_arg_doc({ii,N}) -> "Integer";
format_arg_doc({li,N}) -> "[Integers]";
format_arg_doc({t,N}) -> "Type".

View File

@ -61,6 +61,7 @@ sources() ->
"0123456789012345678901234567890123456789">>), %% Magic concat 80 char string.
aeb_fate_data:make_tuple({True, FortyTwo}),
aeb_fate_data:make_tuple(list_to_tuple(make_int_list(65))),
aeb_fate_data:make_tuple(list_to_tuple(make_int_list(16))),
aeb_fate_data:make_map(#{ aeb_fate_data:make_integer(1) => True, aeb_fate_data:make_integer(2) => False}),
aeb_fate_data:make_map(#{ aeb_fate_data:make_string(<<"foo">>) => aeb_fate_data:make_tuple({FortyTwo, True})}),
aeb_fate_data:make_list(make_int_list(3)),