Skip to content

Commit

Permalink
Shorten the ast2str file massively and try again to fix the CI
Browse files Browse the repository at this point in the history
  • Loading branch information
moste00 committed Oct 11, 2024
1 parent eff559e commit 2d76492
Show file tree
Hide file tree
Showing 8 changed files with 12,422 additions and 110,415 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/end2end-smoke-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
cd generator && source ~/.bash_profile
export OPAMCONFIRMLEVEL=yes
opam update
opam install sail=0.18
sudo apt-get install z3
opam install . --deps-only
Expand All @@ -60,6 +60,9 @@ jobs:
echo '#include "riscv_ast2str.gen.inc"' >> test_main.c
echo >> test_main.c
echo 'void main() {}' >> test_main.c
mv ../old_output/riscv_helpers_ast2str.h riscv_helpers_ast2str.h
mv ../old_output/riscv_helpers_rvconf.h riscv_helpers_rvconf.h
gcc test_main.c || { echo "Failure: Trying to compile the tool-generated C code failed."; exit 1; }
Expand Down
12 changes: 10 additions & 2 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ let proc_dec_str = Stringify.stringify_decode_procedure proc_dec typdefwalker

let asm = Gen_assembler.gen_asm ast analysis

let asm_str = Stringify.stringify_assembler asm typdefwalker
let asm_str, tables_str = Stringify.stringify_assembler asm typdefwalker

let () = write_c_file Constants.ast_type_filename ctypedefs_str
let () =
Expand All @@ -102,4 +102,12 @@ let () =
let () =
write_c_file Constants.assembler_filename asm_str
~additional_includes:
["\"" ^ Constants.ast_type_filename ^ "\""; "\"riscv_helpers_ast2str.h\""]
[
"\"" ^ Constants.ast_type_filename ^ "\"";
"\"" ^ Constants.ast2str_tables_filename ^ "\"";
"\"riscv_helpers_ast2str.h\"";
]

let () =
write_c_file Constants.ast2str_tables_filename tables_str
~additional_includes:["\"" ^ Constants.ast_type_filename ^ "\""]
8 changes: 4 additions & 4 deletions lib/assembler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ type intrinsic_logic_arg =

type tostr_logic =
| Lit of string
| Bitv2Str of int * bv2str_table
| Enum2Str of int * enum2str_table
| Bool2Str of int * bool2str_table
| Struct2str of int * struct2str_table
| Bitv2Str of string * int * bv2str_table
| Enum2Str of string * int * enum2str_table
| Bool2Str of string * int * bool2str_table
| Struct2str of string * int * struct2str_table
| Intrinsic_tostr_logic of string * intrinsic_logic_arg list

type subcase_condition = (int * string) option
Expand Down
2 changes: 2 additions & 0 deletions lib/constants.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ let identifier_prefix = "RISCV_"
let ast_assembly_mapping = "assembly"

let assembler_filename = "riscv_ast2str.gen.inc"

let ast2str_tables_filename = "riscv_ast2str_tbls.gen.inc"
26 changes: 13 additions & 13 deletions lib/gen_assembler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ let get_case analysis pat =
| _ -> failwith "1"
)

let create_bv2str tbl arg_names_to_indices args =
let create_bv2str name tbl arg_names_to_indices args =
match args with
| [arg] ->
let arg_name = id_to_str (Option.get (case_arg_to_id arg)) in
let arg_idx = Hashtbl.find arg_names_to_indices arg_name in
Bitv2Str (arg_idx, tbl)
Bitv2Str (name, arg_idx, tbl)
| _ -> failwith ""

let create_enum2str analysis tbl arg_names_to_indices args =
let create_enum2str analysis name tbl arg_names_to_indices args =
match args with
| [arg] ->
let arg_id = Option.get (case_arg_to_id arg) in
Expand All @@ -122,11 +122,11 @@ let create_enum2str analysis tbl arg_names_to_indices args =
else (
(* emit the table lookup as-is *)
let arg_idx = Hashtbl.find arg_names_to_indices arg_name in
Enum2Str (arg_idx, tbl)
Enum2Str (name, arg_idx, tbl)
)
| _ -> failwith ""

let create_bool2str tbl arg_names_to_indices args =
let create_bool2str name tbl arg_names_to_indices args =
match args with
| [arg] -> (
match arg with
Expand All @@ -139,16 +139,16 @@ let create_bool2str tbl arg_names_to_indices args =
Hashtbl.find arg_names_to_indices
(id_to_str (Option.get (case_arg_to_id arg)))
in
Bool2Str (arg_idx, tbl)
Bool2Str (name, arg_idx, tbl)
)
| _ -> failwith ""

let create_struct2str tbl arg_names_to_indices args =
let create_struct2str name tbl arg_names_to_indices args =
match args with
| [arg] ->
let arg_name = id_to_str (Option.get (case_arg_to_id arg)) in
let arg_idx = Hashtbl.find arg_names_to_indices arg_name in
Struct2str (arg_idx, tbl)
Struct2str (name, arg_idx, tbl)
| _ -> failwith ""

let create_to_str_from_pattern analysis arg_names_to_indices pat =
Expand All @@ -159,28 +159,28 @@ let create_to_str_from_pattern analysis arg_names_to_indices pat =
let name = id_to_str id in
let maybe_bv2str = get_bv2str_mapping analysis name in
if Option.is_some maybe_bv2str then
create_bv2str (Option.get maybe_bv2str) arg_names_to_indices args
create_bv2str name (Option.get maybe_bv2str) arg_names_to_indices args
else (
let maybe_enum2str = get_enum2str_mapping analysis name in
if Option.is_some maybe_enum2str then
create_enum2str analysis
create_enum2str analysis name
(Option.get maybe_enum2str)
arg_names_to_indices args
else (
let maybe_bool2str = get_bool2str_mapping analysis name in
if Option.is_some maybe_bool2str then
create_bool2str
create_bool2str name
(Option.get maybe_bool2str)
arg_names_to_indices args
else (
let maybe_struct2str = get_struct2str_mapping analysis name in
if Option.is_some maybe_struct2str then
create_struct2str
create_struct2str name
(Option.get maybe_struct2str)
arg_names_to_indices args
else
Intrinsic_tostr_logic
( id_to_str id,
( name,
case_args_to_intrinsic_logic_args analysis
arg_names_to_indices args
)
Expand Down
Loading

0 comments on commit 2d76492

Please sign in to comment.