|
|
1.1 ! root 1: \subsection{Handling IEEE floating point constants} ! 2: Here we take care of converting floating point constants from ! 3: string representation to 64-bit IEEE representation. ! 4: We use the machinery developed for the Sparc by John Reppy. ! 5: ! 6: Reppy's functor accepts a simple structure with a single value, ! 7: [[emitWord : int -> unit]], which emits a 16-bit word. ! 8: It produces a [[PRIMREAL]]. ! 9: When [[RealConst]] is applied to the result, it produces a ! 10: structure containing a single function, [[val realconst : string -> unit]]. ! 11: This function, when applied to a string, emits the four sixteen-bit words ! 12: of the IEEE representation, most significant first. ! 13: ! 14: Our job will be to convert this to something that emits the two 32-bit ! 15: words of the constant, least significant word first. ! 16: First, let's consider the state information that has to be retained ! 17: while the halfwords are being emitted, and functions that change that state. ! 18: <<state info>>= ! 19: val halfwords = ref nil : int list ref (* halfwords already out *) ! 20: val count = ref 0 (* length of halfwords *) ! 21: fun reset_state () = (halfwords := nil; count := 0) ! 22: fun add_half h = (count := !count + 1; halfwords := h :: (!halfwords)) ! 23: ! 24: <<emitting a halfword>>= ! 25: fun emit_half h = ! 26: if !count = 3 then (emit_four (h::(!halfwords)); reset_state()) ! 27: else add_half h ! 28: ! 29: @ To emit the whole list, we have to emit the words, one at a time. ! 30: We use descriptive names to remind ourselves what is signficant ! 31: (highest is most significant). ! 32: <<emitting four halfwords>>= ! 33: fun emit_four [lowest,low,high,highest] = ! 34: (emit_word(low,lowest);emit_word(highest,high)) ! 35: | emit_four _ = ErrorMsg.impossible "bad floating pt constant in mips" ! 36: ! 37: @ Now, we bundle up the whole thing in a functor that ! 38: gets passed a structure holding [[emit_word]] and returns ! 39: one containing [[realconst]]. ! 40: <<*>>= ! 41: functor MipsReal(E: sig val emit_word : int * int -> unit end) : REALCONST = ! 42: struct ! 43: open E ! 44: <<state info>> ! 45: <<emitting four halfwords>> ! 46: <<emitting a halfword>> ! 47: structure IEEERealConst = ! 48: RealConst(IEEEReal(struct val emitWord = emit_half end)) ! 49: val realconst = IEEERealConst.realconst ! 50: end ! 51: ! 52: ! 53: ! 54:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.