PreviousUpNext

15.4.531  src/lib/compiler/execution/code-segments/unparse-code-and-data-segments.pkg

## unparse-code-and-data-segments.pkg

# Compiled by:
#     src/lib/compiler/execution/execute.sublib


stipulate
    package cs  =  code_segment;                                        # code_segment                          is from   src/lib/compiler/execution/code-segments/code-segment.pkg
    package pp  =  standard_prettyprinter;                              # standard_prettyprinter                is from   src/lib/prettyprint/big/src/standard-prettyprinter.pkg
    Pp = pp::Pp;
herein

    package unparse_code_and_data_segments
    :       Unparse_Code_And_Data_Segments                              # Unparse_Code_And_Data_Segments        is from   src/lib/compiler/execution/code-segments/unparse-code-and-data-segments.api
    {
        include package   pp;

        fun unparse_code_and_data_segments  (pp:Pp)   code_segments             # "pp" == "prettyprint (mill)"
            =
            {
                code_segments
                    ->
                    { code_segment, bytecodes_to_regenerate_literals_vector };

                                                                        # vector_of_one_byte_unts               is from   src/lib/std/src/vector-of-one-byte-unts.pkg
                                                                        # file__premicrothread                  is from   src/lib/std/src/posix/file--premicrothread.pkg

                data_len =  vector_of_one_byte_unts::length code_segments.bytecodes_to_regenerate_literals_vector;
                c0_entrypoint = cs::get_entrypoint code_segment;

                c0_bytes     = cs::get_machinecode_bytevector  code_segment;
                c0_bytes_len = rw_vector_of_one_byte_unts::length  c0_bytes;

                pp.newline();
                pp.newline();
                pp.lit "code_segments listing: ";
                pp.box {.                                                               pp.rulename "ucds1";
                    pp.newline();
                    pp.newline();
                    pp.lit ("code_segments.bytecodes_to_regenerate_literals_vector is " + (int::to_string data_len) + " bytes long");   pp.newline();
                    pp.lit ("code_segments zero entrypoint is " + (int::to_string c0_entrypoint));      pp.newline();
                    pp.lit ("code_segments zero vector length is " + (int::to_string c0_bytes_len));
                };
                pp.newline();       pp.newline();           pp.newline();           pp.newline();

                pp.lit ("code segments vector zero hex dump: ");

                pp.box {.                                                               pp.rulename "ucds2";
                    pp.newline();

                    loop 0
                    where
                        fun loop i
                            =
                            if   (i < c0_bytes_len)

                                 if   (i % 32 == 0)

                                      address = sfprintf::sprintf' "%04x: " [ sfprintf::INT i ];

                                      pp.newline();
                                      pp.lit address;
                                 fi;

                                 byte =  rw_vector_of_one_byte_unts::get (c0_bytes, i);
                                 byte_as_hex = sfprintf::sprintf' " %02x" [ sfprintf::UNT8 byte ];

                                 pp.lit byte_as_hex;

                                 loop (i + 1);
                            fi;
                    end;
                };

                pp.newline();
                pp.newline();

                c0_disassembly =  disassembler_intel32::disassemble c0_bytes;
            };
                                        # sfprintf              is from   src/lib/src/sfprintf.pkg
                                        # disassembler_intel32  is from   src/lib/src/disassembler-intel32.pkg
    };
end;

## Code by Jeff Prothero: Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext