Handle 5 to 8 args. Generate a test file with all instructions for asm/disasm.
This commit is contained in:
parent
6f67da1292
commit
5eb3689458
@ -341,14 +341,13 @@ deserialize_op(?SWITCH_VN, Rest, Code) ->
|
||||
<<ArgType:8, Rest2/binary>> = Rest,
|
||||
{Arg0, Rest3} = aeb_fate_encoding:deserialize_one(Rest2),
|
||||
case aeb_fate_encoding:deserialize_one(Rest3) of
|
||||
{N, Rest4} when is_integer(N), N >= 0 ->
|
||||
{L, Rest4} when is_list(L) ->
|
||||
Modifier0 = bits_to_modifier(ArgType band 2#11),
|
||||
immediate = bits_to_modifier((ArgType bsr 2) band 2#11),
|
||||
{BBs, Rest5} = deserialize_n(N, Rest4),
|
||||
{Rest5, [{aeb_fate_opcodes:mnemonic(?SWITCH_VN)
|
||||
{Rest4, [{aeb_fate_opcodes:mnemonic(?SWITCH_VN)
|
||||
, {Modifier0, Arg0}
|
||||
, {immediate, N}
|
||||
, list_to_tuple(BBs)}
|
||||
, {immediate, L}
|
||||
}
|
||||
| Code]};
|
||||
_ -> exit(bad_argument_to_switch_vn)
|
||||
end;
|
||||
@ -397,17 +396,107 @@ deserialize_op(Op, Rest, Code) ->
|
||||
, {Modifier1, Arg1}
|
||||
, {Modifier2, Arg2}
|
||||
, {Modifier3, Arg3}}
|
||||
| Code]};
|
||||
5 ->
|
||||
<<ArgType:8, ArgType2:8, Rest2/binary>> = Rest,
|
||||
{Arg0, Rest3} = aeb_fate_encoding:deserialize_one(Rest2),
|
||||
{Arg1, Rest4} = aeb_fate_encoding:deserialize_one(Rest3),
|
||||
{Arg2, Rest5} = aeb_fate_encoding:deserialize_one(Rest4),
|
||||
{Arg3, Rest6} = aeb_fate_encoding:deserialize_one(Rest5),
|
||||
{Arg4, Rest7} = aeb_fate_encoding:deserialize_one(Rest6),
|
||||
Modifier0 = bits_to_modifier(ArgType band 2#11),
|
||||
Modifier1 = bits_to_modifier((ArgType bsr 2) band 2#11),
|
||||
Modifier2 = bits_to_modifier((ArgType bsr 4) band 2#11),
|
||||
Modifier3 = bits_to_modifier((ArgType bsr 6) band 2#11),
|
||||
Modifier4 = bits_to_modifier(ArgType2 band 2#11),
|
||||
{Rest7, [{ OpName
|
||||
, {Modifier0, Arg0}
|
||||
, {Modifier1, Arg1}
|
||||
, {Modifier2, Arg2}
|
||||
, {Modifier3, Arg3}
|
||||
, {Modifier4, Arg4}
|
||||
}
|
||||
| Code]};
|
||||
6 ->
|
||||
<<ArgType:8, ArgType2:8, Rest2/binary>> = Rest,
|
||||
{Arg0, Rest3} = aeb_fate_encoding:deserialize_one(Rest2),
|
||||
{Arg1, Rest4} = aeb_fate_encoding:deserialize_one(Rest3),
|
||||
{Arg2, Rest5} = aeb_fate_encoding:deserialize_one(Rest4),
|
||||
{Arg3, Rest6} = aeb_fate_encoding:deserialize_one(Rest5),
|
||||
{Arg4, Rest7} = aeb_fate_encoding:deserialize_one(Rest6),
|
||||
{Arg5, Rest8} = aeb_fate_encoding:deserialize_one(Rest7),
|
||||
Modifier0 = bits_to_modifier(ArgType band 2#11),
|
||||
Modifier1 = bits_to_modifier((ArgType bsr 2) band 2#11),
|
||||
Modifier2 = bits_to_modifier((ArgType bsr 4) band 2#11),
|
||||
Modifier3 = bits_to_modifier((ArgType bsr 6) band 2#11),
|
||||
Modifier4 = bits_to_modifier(ArgType2 band 2#11),
|
||||
Modifier5 = bits_to_modifier((ArgType2 bsr 2) band 2#11),
|
||||
{Rest8, [{ OpName
|
||||
, {Modifier0, Arg0}
|
||||
, {Modifier1, Arg1}
|
||||
, {Modifier2, Arg2}
|
||||
, {Modifier3, Arg3}
|
||||
, {Modifier4, Arg4}
|
||||
, {Modifier5, Arg5}
|
||||
}
|
||||
| Code]};
|
||||
7 ->
|
||||
<<ArgType:8, ArgType2:8, Rest2/binary>> = Rest,
|
||||
{Arg0, Rest3} = aeb_fate_encoding:deserialize_one(Rest2),
|
||||
{Arg1, Rest4} = aeb_fate_encoding:deserialize_one(Rest3),
|
||||
{Arg2, Rest5} = aeb_fate_encoding:deserialize_one(Rest4),
|
||||
{Arg3, Rest6} = aeb_fate_encoding:deserialize_one(Rest5),
|
||||
{Arg4, Rest7} = aeb_fate_encoding:deserialize_one(Rest6),
|
||||
{Arg5, Rest8} = aeb_fate_encoding:deserialize_one(Rest7),
|
||||
{Arg6, Rest9} = aeb_fate_encoding:deserialize_one(Rest8),
|
||||
Modifier0 = bits_to_modifier(ArgType band 2#11),
|
||||
Modifier1 = bits_to_modifier((ArgType bsr 2) band 2#11),
|
||||
Modifier2 = bits_to_modifier((ArgType bsr 4) band 2#11),
|
||||
Modifier3 = bits_to_modifier((ArgType bsr 6) band 2#11),
|
||||
Modifier4 = bits_to_modifier(ArgType2 band 2#11),
|
||||
Modifier5 = bits_to_modifier((ArgType2 bsr 2) band 2#11),
|
||||
Modifier6 = bits_to_modifier((ArgType2 bsr 4) band 2#11),
|
||||
{Rest9, [{ OpName
|
||||
, {Modifier0, Arg0}
|
||||
, {Modifier1, Arg1}
|
||||
, {Modifier2, Arg2}
|
||||
, {Modifier3, Arg3}
|
||||
, {Modifier4, Arg4}
|
||||
, {Modifier5, Arg5}
|
||||
, {Modifier6, Arg6}
|
||||
}
|
||||
| Code]};
|
||||
8 ->
|
||||
<<ArgType:8, ArgType2:8, Rest2/binary>> = Rest,
|
||||
{Arg0, Rest3} = aeb_fate_encoding:deserialize_one(Rest2),
|
||||
{Arg1, Rest4} = aeb_fate_encoding:deserialize_one(Rest3),
|
||||
{Arg2, Rest5} = aeb_fate_encoding:deserialize_one(Rest4),
|
||||
{Arg3, Rest6} = aeb_fate_encoding:deserialize_one(Rest5),
|
||||
{Arg4, Rest7} = aeb_fate_encoding:deserialize_one(Rest6),
|
||||
{Arg5, Rest8} = aeb_fate_encoding:deserialize_one(Rest7),
|
||||
{Arg6, Rest9} = aeb_fate_encoding:deserialize_one(Rest8),
|
||||
{Arg7, Rest10} = aeb_fate_encoding:deserialize_one(Rest9),
|
||||
Modifier0 = bits_to_modifier(ArgType band 2#11),
|
||||
Modifier1 = bits_to_modifier((ArgType bsr 2) band 2#11),
|
||||
Modifier2 = bits_to_modifier((ArgType bsr 4) band 2#11),
|
||||
Modifier3 = bits_to_modifier((ArgType bsr 6) band 2#11),
|
||||
Modifier4 = bits_to_modifier(ArgType2 band 2#11),
|
||||
Modifier5 = bits_to_modifier((ArgType2 bsr 2) band 2#11),
|
||||
Modifier6 = bits_to_modifier((ArgType2 bsr 4) band 2#11),
|
||||
Modifier7 = bits_to_modifier((ArgType2 bsr 6) band 2#11),
|
||||
{Rest10, [{ OpName
|
||||
, {Modifier0, Arg0}
|
||||
, {Modifier1, Arg1}
|
||||
, {Modifier2, Arg2}
|
||||
, {Modifier3, Arg3}
|
||||
, {Modifier4, Arg4}
|
||||
, {Modifier5, Arg5}
|
||||
, {Modifier6, Arg6}
|
||||
, {Modifier7, Arg7}
|
||||
}
|
||||
| Code]}
|
||||
end.
|
||||
|
||||
deserialize_n(N, Binary) ->
|
||||
deserialize_n(N, Binary, []).
|
||||
|
||||
deserialize_n(0, Binary, Acc) ->
|
||||
{lists:reverse(Acc), Binary};
|
||||
deserialize_n(N, Binary, Acc) ->
|
||||
{Value, Rest} = aeb_fate_encoding:deserialize_one(Binary),
|
||||
deserialize_n(N-1, Rest, [Value|Acc]).
|
||||
|
||||
|
||||
|
||||
@ -447,11 +536,114 @@ serialize(#{functions := Functions} =_Env) ->
|
||||
%% bitpos: 6 4 2 0
|
||||
%% xx xx xx xx
|
||||
%% Arg3 Arg2 Arg1 Arg0
|
||||
%% For 5-8 args another Argument Spec Byte is used
|
||||
%% Bit pattern
|
||||
%% 00 : stack/unused (depending on instruction)
|
||||
%% 01 : argN
|
||||
%% 10 : varN
|
||||
%% 11 : immediate
|
||||
serialize_code([ {Arg0Type, Arg0}
|
||||
, {Arg1Type, Arg1}
|
||||
, {Arg2Type, Arg2}
|
||||
, {Arg3Type, Arg3}
|
||||
, {Arg4Type, Arg4}
|
||||
, {Arg5Type, Arg5}
|
||||
, {Arg6Type, Arg6}
|
||||
, {Arg7Type, Arg7}
|
||||
| Rest]) ->
|
||||
ArgSpec1 =
|
||||
modifier_bits(Arg0Type) bor
|
||||
(modifier_bits(Arg1Type) bsl 2) bor
|
||||
(modifier_bits(Arg2Type) bsl 4) bor
|
||||
(modifier_bits(Arg3Type) bsl 6),
|
||||
ArgSpec2 =
|
||||
modifier_bits(Arg4Type) bor
|
||||
(modifier_bits(Arg5Type) bsl 2) bor
|
||||
(modifier_bits(Arg6Type) bsl 4) bor
|
||||
(modifier_bits(Arg7Type) bsl 6),
|
||||
[ ArgSpec1
|
||||
, ArgSpec2
|
||||
, serialize_data(Arg0Type, Arg0)
|
||||
, serialize_data(Arg1Type, Arg1)
|
||||
, serialize_data(Arg2Type, Arg2)
|
||||
, serialize_data(Arg3Type, Arg3)
|
||||
, serialize_data(Arg4Type, Arg4)
|
||||
, serialize_data(Arg5Type, Arg5)
|
||||
, serialize_data(Arg6Type, Arg6)
|
||||
, serialize_data(Arg7Type, Arg7)
|
||||
| serialize_code(Rest)];
|
||||
serialize_code([ {Arg0Type, Arg0}
|
||||
, {Arg1Type, Arg1}
|
||||
, {Arg2Type, Arg2}
|
||||
, {Arg3Type, Arg3}
|
||||
, {Arg4Type, Arg4}
|
||||
, {Arg5Type, Arg5}
|
||||
, {Arg6Type, Arg6}
|
||||
| Rest]) ->
|
||||
ArgSpec1 =
|
||||
modifier_bits(Arg0Type) bor
|
||||
(modifier_bits(Arg1Type) bsl 2) bor
|
||||
(modifier_bits(Arg2Type) bsl 4) bor
|
||||
(modifier_bits(Arg3Type) bsl 6),
|
||||
ArgSpec2 =
|
||||
modifier_bits(Arg4Type) bor
|
||||
(modifier_bits(Arg5Type) bsl 2) bor
|
||||
(modifier_bits(Arg6Type) bsl 4),
|
||||
[ ArgSpec1
|
||||
, ArgSpec2
|
||||
, serialize_data(Arg0Type, Arg0)
|
||||
, serialize_data(Arg1Type, Arg1)
|
||||
, serialize_data(Arg2Type, Arg2)
|
||||
, serialize_data(Arg3Type, Arg3)
|
||||
, serialize_data(Arg4Type, Arg4)
|
||||
, serialize_data(Arg5Type, Arg5)
|
||||
, serialize_data(Arg6Type, Arg6)
|
||||
| serialize_code(Rest)];
|
||||
serialize_code([ {Arg0Type, Arg0}
|
||||
, {Arg1Type, Arg1}
|
||||
, {Arg2Type, Arg2}
|
||||
, {Arg3Type, Arg3}
|
||||
, {Arg4Type, Arg4}
|
||||
, {Arg5Type, Arg5}
|
||||
| Rest]) ->
|
||||
ArgSpec1 =
|
||||
modifier_bits(Arg0Type) bor
|
||||
(modifier_bits(Arg1Type) bsl 2) bor
|
||||
(modifier_bits(Arg2Type) bsl 4) bor
|
||||
(modifier_bits(Arg3Type) bsl 6),
|
||||
ArgSpec2 =
|
||||
modifier_bits(Arg4Type) bor
|
||||
(modifier_bits(Arg5Type) bsl 2),
|
||||
[ ArgSpec1
|
||||
, ArgSpec2
|
||||
, serialize_data(Arg0Type, Arg0)
|
||||
, serialize_data(Arg1Type, Arg1)
|
||||
, serialize_data(Arg2Type, Arg2)
|
||||
, serialize_data(Arg3Type, Arg3)
|
||||
, serialize_data(Arg4Type, Arg4)
|
||||
, serialize_data(Arg5Type, Arg5)
|
||||
| serialize_code(Rest)];
|
||||
serialize_code([ {Arg0Type, Arg0}
|
||||
, {Arg1Type, Arg1}
|
||||
, {Arg2Type, Arg2}
|
||||
, {Arg3Type, Arg3}
|
||||
, {Arg4Type, Arg4}
|
||||
| Rest]) ->
|
||||
ArgSpec1 =
|
||||
modifier_bits(Arg0Type) bor
|
||||
(modifier_bits(Arg1Type) bsl 2) bor
|
||||
(modifier_bits(Arg2Type) bsl 4) bor
|
||||
(modifier_bits(Arg3Type) bsl 6),
|
||||
ArgSpec2 =
|
||||
modifier_bits(Arg4Type),
|
||||
[ ArgSpec1
|
||||
, ArgSpec2
|
||||
, serialize_data(Arg0Type, Arg0)
|
||||
, serialize_data(Arg1Type, Arg1)
|
||||
, serialize_data(Arg2Type, Arg2)
|
||||
, serialize_data(Arg3Type, Arg3)
|
||||
, serialize_data(Arg4Type, Arg4)
|
||||
| serialize_code(Rest)];
|
||||
|
||||
serialize_code([ {Arg0Type, Arg0}
|
||||
, {Arg1Type, Arg1}
|
||||
@ -505,17 +697,15 @@ serialize_code([ ?ELEMENT
|
||||
| serialize_code(Rest)];
|
||||
serialize_code([ ?SWITCH_VN
|
||||
, {Arg0Type, Arg0}
|
||||
, {immediate, N}
|
||||
| Rest]) when is_integer(N), N >= 0 ->
|
||||
, {immediate, L}
|
||||
| Rest]) ->
|
||||
ArgSpec =
|
||||
modifier_bits(Arg0Type) bor
|
||||
(modifier_bits(immediate) bsl 2),
|
||||
{Serialization, Rest2} = serialize_n_ints(N, Rest),
|
||||
[?SWITCH_VN
|
||||
, ArgSpec
|
||||
, serialize_data(Arg0Type, Arg0)
|
||||
, serialize_data(immediate, N)
|
||||
| Serialization] ++ serialize_code(Rest2);
|
||||
, serialize_data(immediate, L)] ++ serialize_code(Rest);
|
||||
serialize_code([B|Rest]) ->
|
||||
[B | serialize_code(Rest)];
|
||||
serialize_code([]) -> [].
|
||||
|
@ -55,8 +55,8 @@ FUNCTION : {token, {function, TokenLine, 'FUNCTION' }}.
|
||||
\: : {token, {to, TokenLine}}.
|
||||
|
||||
\=\> : {token, {arrow, TokenLine}}.
|
||||
\(\| : {token, {start_varaint, TokenLine}}.
|
||||
\|\) : {token, {end_varaint, TokenLine}}.
|
||||
\(\| : {token, {start_variant, TokenLine}}.
|
||||
\|\) : {token, {end_variant, TokenLine}}.
|
||||
|
||||
, : {token, {',', TokenLine}}.
|
||||
\( : {token, {'(', TokenLine}}.
|
||||
|
@ -1,7 +1,8 @@
|
||||
-module(aeb_fate_generate_ops).
|
||||
|
||||
-export([ gen_and_halt/1
|
||||
, generate/0]).
|
||||
, generate/0
|
||||
, test_asm_generator/1]).
|
||||
|
||||
gen_and_halt([SrcDirArg, IncludeDirArg]) ->
|
||||
generate(atom_to_list(SrcDirArg),
|
||||
@ -34,7 +35,7 @@ ops_defs() ->
|
||||
, { 'JUMPIF', 16#07, 2, true, 4, [a,ii], jumpif, "Conditional jump to a basic block. If Arg0 then jump to Arg1."}
|
||||
, { 'SWITCH_V2', 16#08, 3, true, 4, [a,ii,ii], switch, "Conditional jump to a basic block on variant tag."}
|
||||
, { 'SWITCH_V3', 16#09, 4, true, 4, [a,ii,ii,ii], switch, "Conditional jump to a basic block on variant tag."}
|
||||
, { 'SWITCH_VN', 16#0a, 2, true, 4, [a,li], switch, "Conditional jump to a basic block on variant tag."}
|
||||
, { 'SWITCH_VN', 16#0a, 2, true, 4, [a, li], switch, "Conditional jump to a basic block on variant tag."}
|
||||
, { 'PUSH', 16#0b, 1, false, 2, [a], push, "Push argument to stack."}
|
||||
, { 'DUPA', 16#0c, 0, false, 3, atomic, dup, "push copy of accumulator on stack."}
|
||||
, { 'DUP', 16#0d, 1, false, 3, [a], dup, "push Arg0 stack pos on top of stack."}
|
||||
@ -411,8 +412,8 @@ gen_asm_pp(Module, Path, Ops) ->
|
||||
"-export([format_op/2]).\n\n"
|
||||
"format_arg(t, T) ->\n"
|
||||
" io_lib:format(\"~~p \", [T]);\n"
|
||||
"format_arg(li, List) ->\n"
|
||||
" [[\" \", E] || {immedate, E} <- List];\n"
|
||||
"format_arg(li, {immediate, LI}) ->\n"
|
||||
" aeb_fate_data:format(LI);\n"
|
||||
"format_arg(_, {immediate, I}) ->\n"
|
||||
" aeb_fate_data:format(I);\n"
|
||||
"format_arg(a, {arg, N}) -> io_lib:format(\"arg~~p\", [N]);\n"
|
||||
@ -420,7 +421,7 @@ gen_asm_pp(Module, Path, Ops) ->
|
||||
"format_arg(a, {stack, 0}) -> \"a\";\n"
|
||||
"format_arg(a, {stack, N}) -> io_lib:format(\"a~~p\", [N]).\n\n"
|
||||
"lookup(Name, Symbols) ->\n"
|
||||
" maps:get(Name, Symbols, Name).\n\n"
|
||||
" maps:get(Name, Symbols, io_lib:format(\"~~w\",[Name])).\n\n"
|
||||
"~s"
|
||||
, [Formats]),
|
||||
|
||||
@ -499,3 +500,123 @@ gen_format(#{opname := Name, format := Args}) ->
|
||||
"\" \", format_arg(~w, Arg6)];",
|
||||
[Name, NameAsString, T0, T1, T2, T3, T4, T5, T6])
|
||||
end.
|
||||
|
||||
test_asm_generator(Filename) ->
|
||||
{ok, File} = file:open(Filename, [write]),
|
||||
Instructions = lists:flatten([gen_instruction(Op)++"\n" || Op <- gen(ops_defs())]),
|
||||
io:format(File,
|
||||
";; CONTRACT all_instructions\n\n"
|
||||
";; Dont expect this contract to typecheck or run.\n"
|
||||
";; Just used to check assembler rountrip of all instruction.\n\n"
|
||||
"FUNCTION foo () : {tuple, []}\n"
|
||||
"~s"
|
||||
, [Instructions]),
|
||||
io:format(File, " RETURNR ()\n", []),
|
||||
file:close(File).
|
||||
|
||||
|
||||
gen_instruction(#{opname := Name, format := atomic}) ->
|
||||
io_lib:format(" ~s\n", [Name]);
|
||||
gen_instruction(#{opname := Name, format := ArgTypes}) ->
|
||||
Args = lists:flatten(lists:join(" ", [gen_arg(A) || A <- ArgTypes])),
|
||||
I = io_lib:format(" ~s ~s\n", [Name, Args]),
|
||||
I.
|
||||
|
||||
%% This should be done with a Quick Check generator...
|
||||
gen_arg(a) -> any_arg();
|
||||
gen_arg(is) -> "foo";
|
||||
gen_arg(ii) -> gen_int();
|
||||
gen_arg(li) -> "[1, 2, 3]";
|
||||
gen_arg(t) -> "integer".
|
||||
|
||||
any_arg() ->
|
||||
element(rand:uniform(5), {"a", stack_arg(), var_arg(), arg_arg(), imm_arg()}).
|
||||
stack_arg() -> "a" ++ integer_to_list(rand:uniform(255)-1).
|
||||
arg_arg() -> "arg" ++ integer_to_list(rand:uniform(256)-1).
|
||||
var_arg() -> "var" ++ integer_to_list(rand:uniform(256)-1).
|
||||
imm_arg() ->
|
||||
case rand:uniform(15) of
|
||||
1 -> gen_int();
|
||||
2 -> gen_int();
|
||||
3 -> gen_int();
|
||||
4 -> gen_int();
|
||||
5 -> gen_int();
|
||||
6 -> gen_int();
|
||||
7 -> gen_int();
|
||||
8 -> gen_address();
|
||||
9 -> gen_boolean();
|
||||
10 -> gen_string();
|
||||
11 -> gen_map();
|
||||
12 -> gen_list();
|
||||
13 -> gen_bits();
|
||||
14 -> gen_tuple();
|
||||
15 -> gen_variant()
|
||||
end.
|
||||
|
||||
gen_key() ->
|
||||
case rand:uniform(15) of
|
||||
1 -> gen_int();
|
||||
2 -> gen_int();
|
||||
3 -> gen_int();
|
||||
4 -> gen_int();
|
||||
5 -> gen_int();
|
||||
6 -> gen_int();
|
||||
7 -> gen_int();
|
||||
8 -> gen_address();
|
||||
9 -> gen_boolean();
|
||||
10 -> gen_string();
|
||||
11 -> gen_string();
|
||||
12 -> gen_list();
|
||||
13 -> gen_bits();
|
||||
14 -> gen_tuple();
|
||||
15 -> gen_variant()
|
||||
end.
|
||||
|
||||
gen_boolean() ->
|
||||
element(rand:uniform(2), {"true", "false"}).
|
||||
|
||||
gen_int() ->
|
||||
element(rand:uniform(4),
|
||||
{ integer_to_list(rand:uniform(round(math:pow(10,40))))
|
||||
, integer_to_list(rand:uniform(10))
|
||||
, integer_to_list(rand:uniform(100))
|
||||
, io_lib:format("0x~.16b",[rand:uniform(round(math:pow(10,10)))])}).
|
||||
|
||||
gen_address() -> "#nv5B93FPzRHrGNmMdTDfGdd5xGZvep3MVSpJqzcQmMp59bBCv".
|
||||
gen_string() -> "\"foo\"".
|
||||
gen_map() -> "{ " ++ gen_key() ++ " => " ++ imm_arg() ++ "}".
|
||||
gen_list() ->
|
||||
case rand:uniform(4) of
|
||||
1 -> "[]";
|
||||
2 -> "[" ++ lists:join(", ", gen_list_elements()) ++ " ]";
|
||||
3 -> "[ " ++ imm_arg() ++ " ]";
|
||||
4 -> "[ " ++ imm_arg() ++ ", " ++ imm_arg() ++ " ]"
|
||||
end.
|
||||
|
||||
%% Not type correct.
|
||||
gen_list_elements() ->
|
||||
case rand:uniform(3) of
|
||||
1 -> [imm_arg() | gen_list_elements()];
|
||||
2 -> [];
|
||||
3 -> [imm_arg()]
|
||||
end.
|
||||
|
||||
gen_bits() ->
|
||||
element(rand:uniform(3),
|
||||
{"<>"
|
||||
,"!<>"
|
||||
, "101010"}).
|
||||
|
||||
gen_tuple() ->
|
||||
case rand:uniform(3) of
|
||||
1 -> "()";
|
||||
2 -> "(42)";
|
||||
3 -> "(" ++ imm_arg() ++ ")"
|
||||
end.
|
||||
|
||||
gen_variant() ->
|
||||
case rand:uniform(3) of
|
||||
1 -> "(| 5 | 2 | (1, \"foo\", ()) |)";
|
||||
2 -> "(| 2 | 1 | ( " ++ imm_arg() ++ " ) |)";
|
||||
3 -> "(| 2 | 0 | ( " ++ imm_arg() ++ ", " ++ imm_arg() ++ " ) |)"
|
||||
end.
|
||||
|
@ -52,6 +52,7 @@ sources() ->
|
||||
, "tuple"
|
||||
, "mapofmap"
|
||||
, "immediates"
|
||||
, "all_instructions"
|
||||
].
|
||||
|
||||
check_roundtrip(File) ->
|
||||
|
229
test/asm_code/all_instructions.fate
Normal file
229
test/asm_code/all_instructions.fate
Normal file
@ -0,0 +1,229 @@
|
||||
;; CONTRACT all_instructions
|
||||
|
||||
;; Dont expect this contract to typecheck or run.
|
||||
;; Just used to check assembler rountrip of all instruction.
|
||||
|
||||
FUNCTION foo () : {tuple, []}
|
||||
RETURN
|
||||
|
||||
RETURNR var150
|
||||
|
||||
CALL foo
|
||||
|
||||
CALL_R arg242 foo
|
||||
|
||||
CALL_T foo
|
||||
|
||||
CALL_TR a foo
|
||||
|
||||
JUMP 2778181099722339546444847932597842403980
|
||||
|
||||
JUMPIF arg71 17
|
||||
|
||||
SWITCH_V2 var242 7 51
|
||||
|
||||
SWITCH_V3 var90 0x1bdd846f3 9 0x17cbdd6c9
|
||||
|
||||
SWITCH_VN arg153 [1, 2, 3]
|
||||
|
||||
PUSH var118
|
||||
|
||||
DUPA
|
||||
|
||||
DUP var85
|
||||
|
||||
POP (| 2 | 1 | ( 4557687389579322034215261600548680294108 ) |)
|
||||
|
||||
STORE 0x23f57a6d7 a
|
||||
|
||||
INCA
|
||||
|
||||
INC var100
|
||||
|
||||
DECA
|
||||
|
||||
DEC var230
|
||||
|
||||
ADD a111 a a
|
||||
|
||||
SUB 93 arg198 a140
|
||||
|
||||
MUL var240 a77 arg67
|
||||
|
||||
DIV arg169 1 95
|
||||
|
||||
MOD a241 a a
|
||||
|
||||
POW arg143 a a121
|
||||
|
||||
LT a252 var158 var204
|
||||
|
||||
GT var141 a195 6565006908676281259280322225737939009024
|
||||
|
||||
EQ arg16 a166 0x8f076589
|
||||
|
||||
ELT var117 0x8175205c 0xb659ba4a
|
||||
|
||||
EGT a a a
|
||||
|
||||
NEQ var105 a arg170
|
||||
|
||||
AND a154 var183 a55
|
||||
|
||||
OR var103 var201 a250
|
||||
|
||||
NOT arg158 a17
|
||||
|
||||
TUPLE 6
|
||||
|
||||
ELEMENT integer (| 2 | 0 | ( 7875086700039857579956050953972728274596, 35 ) |) a9 a27
|
||||
|
||||
MAP_EMPTY a180
|
||||
|
||||
MAP_LOOKUP var76 arg238 arg180
|
||||
|
||||
MAP_LOOKUPD a arg209 arg71 !<>
|
||||
|
||||
MAP_UPDATE arg243 a13 false a
|
||||
|
||||
MAP_DELETE arg237 arg138 0x16bb2da52
|
||||
|
||||
MAP_MEMBER a134 a49 arg231
|
||||
|
||||
MAP_FROM_LIST a250 8
|
||||
|
||||
NIL [ ]
|
||||
|
||||
IS_NIL 0x21968d787 5311352343894713188976994917630885293949
|
||||
|
||||
CONS a arg209 57
|
||||
|
||||
HD arg242 a
|
||||
|
||||
TL a var194
|
||||
|
||||
LENGTH var70 a236
|
||||
|
||||
STR_EQ (| 5 | 2 | (1, "foo", ()) |) 50 (| 2 | 1 | ( 0x17a9e8119 ) |)
|
||||
|
||||
STR_JOIN a1 a85 <>
|
||||
|
||||
INT_TO_STR a82 var203
|
||||
|
||||
ADDR_TO_STR arg159 a199
|
||||
|
||||
STR_REVERSE a36 a
|
||||
|
||||
INT_TO_ADDR var161 arg92
|
||||
|
||||
VARIANT var252 a162 a 0xb1912372
|
||||
|
||||
VARIANT_TEST 11 arg173 [ (), 3 ]
|
||||
|
||||
VARIANT_ELEMENT a103 a201 a
|
||||
|
||||
BITS_NONEA
|
||||
|
||||
BITS_NONE [ (| 2 | 1 | ( { 0xa0ee2284 => [ 6 ]} ) |) ]
|
||||
|
||||
BITS_ALLA
|
||||
|
||||
BITS_ALL "foo"
|
||||
|
||||
BITS_ALL_N a a77
|
||||
|
||||
BITS_SET a53 var101 arg213
|
||||
|
||||
BITS_CLEAR arg142 a var157
|
||||
|
||||
BITS_TEST var125 ([(| 2 | 1 | ( 4 ) |) ]) 3084289254269705189827835600187262322355
|
||||
|
||||
BITS_SUM var197 a
|
||||
|
||||
BITS_OR a var35 ("foo")
|
||||
|
||||
BITS_AND a1 a8 arg213
|
||||
|
||||
BITS_DIFF a var24 a
|
||||
|
||||
ADDRESS 8
|
||||
|
||||
BALANCE 2
|
||||
|
||||
ORIGIN var208
|
||||
|
||||
CALLER 90
|
||||
|
||||
GASPRICE a188
|
||||
|
||||
BLOCKHASH arg18
|
||||
|
||||
BENEFICIARY a
|
||||
|
||||
TIMESTAMP arg84
|
||||
|
||||
GENERATION arg110
|
||||
|
||||
MICROBLOCK { 3 => 7374978216136870915189251106310661704403}
|
||||
|
||||
DIFFICULTY var58
|
||||
|
||||
GASLIMIT a
|
||||
|
||||
GAS { true => 0x10acb2ff2}
|
||||
|
||||
LOG0 var170 arg108
|
||||
|
||||
LOG1 a [] arg209
|
||||
|
||||
LOG2 a var170 arg8 a
|
||||
|
||||
LOG3 arg213 a #nv5B93FPzRHrGNmMdTDfGdd5xGZvep3MVSpJqzcQmMp59bBCv [ "foo", [] ] var204
|
||||
|
||||
LOG4 a57 a 0x237fcc40c arg167 arg230 var59
|
||||
|
||||
DEACTIVATE
|
||||
|
||||
SPEND arg243 var172
|
||||
|
||||
ORACLE_REGISTER a arg223 var193 arg60 a111 a182
|
||||
|
||||
ORACLE_QUERY
|
||||
|
||||
ORACLE_RESPOND
|
||||
|
||||
ORACLE_EXTEND
|
||||
|
||||
ORACLE_GET_ANSWER
|
||||
|
||||
ORACLE_GET_QUESTION
|
||||
|
||||
ORACLE_QUERY_FEE
|
||||
|
||||
AENS_RESOLVE
|
||||
|
||||
AENS_PRECLAIM
|
||||
|
||||
AENS_CLAIM
|
||||
|
||||
AENS_UPDATE
|
||||
|
||||
AENS_TRANSFER
|
||||
|
||||
AENS_REVOKE
|
||||
|
||||
ECVERIFY
|
||||
|
||||
SHA3
|
||||
|
||||
SHA256
|
||||
|
||||
BLAKE2B
|
||||
|
||||
ABORT a
|
||||
|
||||
EXIT (0x34df4f98)
|
||||
|
||||
NOP
|
||||
|
||||
RETURNR ()
|
@ -69,5 +69,9 @@ FUNCTION address() : address
|
||||
RETURNR #deadbeef
|
||||
|
||||
;; Option(integer) = NONE | SOME(integer)
|
||||
FUNCTION varaint() : {variant, [{tuple, []}, {tuple, [integer]}]}
|
||||
RETURNR #deadbeef
|
||||
FUNCTION variant_none() : {variant, [{tuple, []}, {tuple, [integer]}]}
|
||||
RETURNR (| 2 | 0 | () |)
|
||||
|
||||
;; Option(integer) = NONE | SOME(integer)
|
||||
FUNCTION variant_some() : {variant, [{tuple, []}, {tuple, [integer]}]}
|
||||
RETURNR (| 2 | 1 | (42) |)
|
||||
|
Loading…
x
Reference in New Issue
Block a user