1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Generation of bytecode for .cmo files *)
|
|
|
|
|
|
|
|
open Lambda
|
|
|
|
open Instruct
|
|
|
|
|
|
|
|
(* Relocation information *)
|
|
|
|
|
|
|
|
type reloc_info =
|
|
|
|
Reloc_literal of structured_constant (* structured constant *)
|
1996-11-29 10:36:42 -08:00
|
|
|
| Reloc_getglobal of Ident.t (* reference to a global *)
|
|
|
|
| Reloc_setglobal of Ident.t (* definition of a global *)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Reloc_primitive of string (* C primitive number *)
|
|
|
|
|
|
|
|
(* Descriptor for compilation units *)
|
|
|
|
|
|
|
|
type compilation_unit =
|
1995-10-09 06:37:11 -07:00
|
|
|
{ cu_name: string; (* Name of compilation unit *)
|
|
|
|
mutable cu_pos: int; (* Absolute position in file *)
|
1995-05-04 03:15:53 -07:00
|
|
|
cu_codesize: int; (* Size of code block *)
|
|
|
|
cu_reloc: (reloc_info * int) list; (* Relocation information *)
|
1995-10-09 06:37:11 -07:00
|
|
|
cu_imports: (string * Digest.t) list; (* Names and CRC of intfs imported *)
|
1996-04-18 09:28:28 -07:00
|
|
|
cu_primitives: string list; (* Primitives declared inside *)
|
1996-11-29 10:36:42 -08:00
|
|
|
mutable cu_force_link: bool; (* Must be linked even if unref'ed *)
|
1997-02-19 08:08:05 -08:00
|
|
|
mutable cu_debug: int; (* Position of debugging info, or 0 *)
|
|
|
|
cu_debugsize: int } (* Length of debugging info *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
(* Format of a .cmo file:
|
1996-04-18 09:28:28 -07:00
|
|
|
magic number (Config.cmo_magic_number)
|
1995-05-04 03:15:53 -07:00
|
|
|
absolute offset of compilation unit descriptor
|
|
|
|
block of relocatable bytecode
|
|
|
|
compilation unit descriptor *)
|
|
|
|
|
2000-03-09 01:12:28 -08:00
|
|
|
(* Descriptor for libraries *)
|
|
|
|
|
|
|
|
type library =
|
|
|
|
{ lib_units: compilation_unit list; (* List of compilation units *)
|
|
|
|
lib_custom: bool; (* Requires custom mode linking? *)
|
|
|
|
lib_ccobjs: string list; (* C object files needed *)
|
|
|
|
lib_ccopts: string list } (* Extra opts to C compiler *)
|
|
|
|
|
|
|
|
(* Format of a .cma file:
|
|
|
|
magic number (Config.cma_magic_number)
|
|
|
|
absolute offset of library descriptor
|
|
|
|
object code for first library member
|
|
|
|
...
|
|
|
|
object code for last library member
|
|
|
|
library descriptor *)
|
|
|
|
|
1997-05-15 06:25:14 -07:00
|
|
|
val to_file: out_channel -> string -> instruction list -> unit
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Arguments:
|
|
|
|
channel on output file
|
|
|
|
name of compilation unit implemented
|
|
|
|
list of instructions to emit *)
|
|
|
|
val to_memory: instruction list -> instruction list ->
|
|
|
|
string * int * (reloc_info * int) list
|
|
|
|
(* Arguments:
|
|
|
|
initialization code (terminated by STOP)
|
|
|
|
function code
|
|
|
|
Results:
|
|
|
|
block of relocatable bytecode
|
|
|
|
size of this block
|
|
|
|
relocation information *)
|
|
|
|
|