1(**************************************************************************** 2*Copyright 2008 3* Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow 4****************************************************************************) 5(**************************************************************************** 6* This file is part of Teyjus. 7* 8* Teyjus is free software: you can redistribute it and/or modify 9* it under the terms of the GNU General Public License as published by 10* the Free Software Foundation, either version 3 of the License, or 11* (at your option) any later version. 12* 13* Teyjus is distributed in the hope that it will be useful, 14* but WITHOUT ANY WARRANTY; without even the implied warranty of 15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16* GNU General Public License for more details. 17* 18* You should have received a copy of the GNU General Public License 19* along with Teyjus. If not, see <http://www.gnu.org/licenses/>. 20****************************************************************************) 21(**************************************************************************) 22(* This module provides auxiliary functions and flags for writing and *) 23(* reading bytecode files. *) 24(**************************************************************************) 25 26(** ******************************************************************** **) 27(** BYTECODE FORMAT **) 28(** ******************************************************************** **) 29val byteCodeVersionNumber : int 30val makeByteCodeFileName : string -> string 31 32val linkedByteCodeVersionNumber : int 33val makeLinkedByteCodeName : string -> string 34 35(* type skeleton representation *) 36val typeMarkArrow : int 37val typeMarkKind : int 38val typeMarkSkeletonVar : int 39 40(* constant fixity *) 41val fixityMarkInfix : int 42val fixityMarkInfixl : int 43val fixityMarkInfixr : int 44val fixityMarkNoFixity : int 45val fixityMarkPrefix : int 46val fixityMarkPrefixr : int 47val fixityMarkPostfix : int 48val fixityMarkPostfixl : int 49 50(* constant/kind category *) 51val global : int 52val local : int 53val hidden : int 54val pervasive : int 55 56(* find code function: hash or sequence search *) 57val findCodeFuncMarkHash : int 58val findCodeFuncMarkSeq : int 59 60(** ******************************************************************** **) 61(** IO FACILITIES **) 62(** ******************************************************************** **) 63 64(**********************************************************************) 65(* record the number of bytes contained by a word (needed for reading *) 66(* or writing a word). *) 67(**********************************************************************) 68val setWordSize : unit -> unit 69val getWordSize : unit -> int 70 71(******************************************************************) 72(* management of output channel *) 73(******************************************************************) 74val openOutChannel : string -> unit 75val closeOutChannel : unit -> unit 76 77(******************************************************************) 78(* management of input channel *) 79(******************************************************************) 80val openInChannel : string -> unit 81val closeInChannel : unit -> unit 82 83(** ******************************************************************* **) 84(** WRITE FUNCTIONS **) 85(** ******************************************************************* **) 86 87(*******************************************************************) 88(* functions for writing certain numbers of bytes to output channel*) 89(*******************************************************************) 90val writeint1 : int -> unit (* one byte *) 91val writeint2 : int -> unit (* two bytes *) 92val writeint4 : int -> unit (* four bytes *) 93val writeintref4 : int ref -> unit (* four bytes reference *) 94val writeint8 : int -> unit (* eight bytes *) 95val writeintref8 : int ref -> unit (* eight bytes reference*) 96 97(* write a word: *) 98(* the number of bytes depend on machine architecture *) 99val writeWord : int -> unit 100 101(* write a float number: *) 102(* 8 bytes with the first four being the mantissa and *) 103(* the folloing being the exponent. *) 104val writefloat4 : float -> unit 105 106(* write a string: *) 107(* the leading 4 bytes contains the length of the string *) 108(* and is followed by a sequence of characters. *) 109val writeString : string -> unit 110 111 112(* write a kind index: *) 113(* a one byte flag indicating the kind category *) 114(* followed by two bytes kind table index. *) 115val writeakind2 : Absyn.akind -> unit 116 117(* write a constant index: *) 118(* a one byte flag indicating the constant category *) 119(* followed by two bytes constant table index. *) 120val writeaconstant2 : Absyn.aconstant -> unit 121 122(** ******************************************************************* **) 123(** READ FUNCTIONS **) 124(** ******************************************************************* **) 125 126(********************************************************************) 127(* functions for reading certain numbers of bytes from input channel*) 128(********************************************************************) 129val readOneByte : unit -> int (* read one byte *) 130val readTwoBytes : unit -> int (* read two bytes *) 131val readWord : unit -> int (* read a word *) 132val readString : unit -> string (* read a string *) 133 134 135val skipNBytes : int -> unit (* skip n bytes *) 136val skipNWords : int -> unit (* skip n words *) 137 138(********************************************************************) 139(* functions for reading certain data structures *) 140(********************************************************************) 141(* kind/constant indexes *) 142val readKindIndex : 143 (int -> int -> Absyn.akind option) -> Absyn.akind option 144val readConstantIndex : 145 (int -> int -> Absyn.aconstant option) -> Absyn.aconstant option 146 147(* kind data *) 148val readGlobalKind : int -> Absyn.akind (* read a global kind *) 149val readLocalKind : int -> Absyn.akind (* read a local kind *) 150 151(* constant data *) 152val readGlobalConstant : (* read a global constant *) 153 (int -> Absyn.askeleton) -> int -> Absyn.aconstant 154val readLocalConstant : (* read a local constant *) 155 (int -> Absyn.askeleton) -> int -> Absyn.aconstant 156val readHiddenConstant : (* read a hidden constant *) 157 (int -> Absyn.askeleton) -> int -> Absyn.aconstant 158 159(* read a type skeleton *) 160val readTypeSkeleton : (int -> int -> Absyn.akind option) -> Absyn.atype 161 162(* find code function *) 163val readFindCodeFn : unit -> int 164 165(* read instruction operands *) 166val readint1 : unit -> int 167val readint2 : unit -> int 168val readint4 : unit -> int 169val readint8 : unit -> int 170val readintref4 : unit -> int ref 171val readintref8 : unit -> int ref 172val readfloat4 : unit -> float 173val readakind2 : unit -> Absyn.akind 174val readaconstant2 : unit -> Absyn.aconstant 175 176val setGetKindFn : (int -> int -> Absyn.akind option) -> unit 177val setGetConstantFn : (int -> int -> Absyn.aconstant option) -> unit 178val setGetLabelFn : (int -> unit) -> unit 179 180(** ******************************************************************* **) 181(** DISPLAY FUNCTIONS FOR DISASSEMBLY **) 182(** ******************************************************************* **) 183val setFindLabelFn : (int -> string) -> unit 184 185val displayR : int -> string 186val displayE : int -> string 187val displayN : int -> string 188val displayI1 : int -> string 189val displayCE : int -> string 190val displaySEG : int -> string 191val displayI : int -> string 192val displayF : float -> string 193val displayS : int -> string 194val displayMT : int -> string 195val displayIT : int -> string 196val displayHT : int -> string 197val displayBVT : int -> string 198val displayL : int ref -> string 199 200(* display a kind data *) 201val displayK : Absyn.akind -> string 202(* display a constant data *) 203val displayC : Absyn.aconstant -> string 204 205(* display find code function *) 206val displayFindCodeFn : int -> string 207 208 209