1 (* Copyright (C) 2003-2007 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
4 * MLton is released under a BSD-style license.
5 * See the file MLton-LICENSE for details.
8 functor SourceInfo (S: SOURCE_INFO_STRUCTS): SOURCE_INFO =
22 if !Control.profile = Control.ProfileCallStack
23 then SourcePos.toString p
24 else concat [SourcePos.file p, ": ",
25 Int.toString (SourcePos.line p)]
26 | Unknown => "<unknown>"
35 Known p => SOME (SourcePos.file p)
42 | Function of {name: string list,
45 datatype t = T of {hash: word,
47 plist: PropertyList.t}
50 val r: t list ref = ref []
54 val res = T {hash = Random.word (),
56 plist = PropertyList.new ()}
58 if !Control.profile = Control.ProfileCount
59 then List.push (r, res)
68 fun make f (T r) = f r
72 val plist = make #plist
78 sourceInfo: t} HashSet.t =
79 HashSet.new {hash = #hash}
81 fun fromC (name: string) =
83 val hash = String.hash name
86 (HashSet.lookupOrInsert
87 (set, hash, fn {hash = h, ...} => hash = h,
88 fn () => {hash = hash,
90 sourceInfo = new (C name)}))
94 fun function {name, region} =
95 new (Function {name = name,
96 pos = Pos.fromRegion region})
98 fun toString' (si, sep) =
100 Anonymous pos => Pos.toString pos
101 | C s => concat ["<", s, ">"]
102 | Function {name, pos} =>
103 concat [concat (List.separate (List.rev name, ".")),
104 sep, Pos.toString pos]
106 fun toString si = toString' (si, " ")
108 val layout = Layout.str o toString
110 val equals: t * t -> bool =
111 fn (s, s') => PropertyList.equals (plist s, plist s')
114 Trace.trace2 ("SourceInfo.equals", layout, layout, Bool.layout) equals
116 fun file (s: t): File.t option =
118 Anonymous pos => Pos.file pos
120 | Function {pos, ...} => Pos.file pos
122 fun isC (s: t): bool =
128 val gcArrayAllocate = fromC "GC_arrayAllocate"
129 val main = fromC "main"
130 val polyEqual = fromC "poly-equal"
131 val polyHash = fromC "poly-hash"
132 val unknown = fromC "unknown"