PreviousUpNext

15.4.530  src/lib/compiler/execution/code-segments/code-segment-buffer.pkg

## code-segment-buffer.pkg

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



###                                  "If it were easy, everyone would be doing it."
###
###                                                         -- Roger Johnson



stipulate
    package cs  =  code_segment;                # code_segment          is from   src/lib/compiler/execution/code-segments/code-segment.pkg
    package u8v =  rw_vector_of_one_byte_unts;          # rw_vector_of_one_byte_unts    is from   src/lib/std/src/rw-vector-of-one-byte-unts.pkg
herein

    package   code_segment_buffer
    : (weak)  Code_Segment_Buffer               # Code_Segment_Buffer   is from   src/lib/compiler/execution/code-segments/code-segment-buffer.api
    {
        codeseg__global =  REF (NULL:  Null_Or( cs::Code_Segment ));                    # More icky thread-hostile mutable global state. XXX BUGGO FIXME
        rw_vec__global  =  REF (u8v::make_rw_vector (0, 0u0));                          # More icky thread-hostile mutable global state. XXX BUGGO FIXME



        fun initialize_code_segment_buffer { size_in_bytes: Int }
            =
            {   codeseg =   cs::make_code_segment_of_bytesize  size_in_bytes;

                codeseg__global :=  THE codeseg;
                rw_vec__global  :=  cs::get_machinecode_bytevector  codeseg;
            };



        # This fun is called (only) from:
        #
        #     src/lib/compiler/back/low/jmp/squash-jumps-and-write-code-to-code-segment-buffer-intel32-g.pkg
        #     src/lib/compiler/back/low/pwrpc32/emit/translate-machcode-to-execode-pwrpc32-g.codemade.pkg
        #     src/lib/compiler/back/low/sparc32/emit/translate-machcode-to-execode-sparc32-g.codemade.pkg
        #
        fun write_byte_to_code_segment_buffer { offset, byte }
            =
            u8v::set (*rw_vec__global, offset, byte);



        # This fun is called (only) from:
        #
        #     src/lib/compiler/back/low/main/intel32/backend-intel32-g.pkg
        #     src/lib/compiler/back/low/main/pwrpc32/backend-pwrpc32.pkg
        #     src/lib/compiler/back/low/main/sparc32/backend-sparc32.pkg
        #
        fun harvest_code_segment_buffer entrypoint                              # The 'entrypoint' arg gives offset into machinecode bytevector for first function.  (In practice this offset is currently always zero.)
            =
            {   codeseg = the *codeseg__global;

                cs::set_entrypoint (codeseg, entrypoint);

                rw_vec__global   :=  u8v::make_rw_vector (0, 0u0);
                codeseg__global  :=  NULL;

                codeseg;
            };
    };
end;


## COPYRIGHT (c) 1998 Bell Labs, Lucent Technologies.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2013,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext