PreviousUpNext

15.4.532  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  =  prettyprint;                                 # prettyprint                           is from   src/lib/prettyprint/big/src/prettyprint.pkg
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 pp;

        fun unparse_code_and_data_segments  pps   code_segments         # "pps" == "prettyprint_stream"
            =
            {   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 pps;
                pp::newline pps;
                pp::string pps "code_segments listing: ";
                begin_indented_vertical_box  pps  (BOX_RELATIVE 4);             pp::newline pps;                pp::newline pps;
                pp::string pps ("code_segments.bytecodes_to_regenerate_literals_vector is " + (int::to_string data_len) + " bytes long");       pp::newline pps;
                pp::string pps ("code_segments zero entrypoint is " + (int::to_string c0_entrypoint));  pp::newline pps;
                pp::string pps ("code_segments zero vector length is " + (int::to_string c0_bytes_len));
                end_box pps;
                pp::newline pps;            pp::newline pps;        pp::newline pps;        pp::newline pps;

                pp::string pps ("code segments vector zero hex dump: ");
                begin_indented_vertical_box  pps  (BOX_RELATIVE 4);     pp::newline pps;

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

                             if   (i % 32 == 0)

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

                                  pp::newline pps;
                                  pp::string pps address;
                             fi;

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

                             pp::string pps byte_as_hex;

                             loop (i + 1);
                        fi;
                end;
                end_box pps;

                pp::newline pps;
                pp::newline pps;

                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-2013,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext