Verified Commit 0a96d6af authored by Camil Staps's avatar Camil Staps 🚀

Read integers in LEB encoding

parent 331f49d0
......@@ -121,6 +121,8 @@ read_profile f
| isError cost_centres = (Error (fromError cost_centres),f)
# (profile,f) = read_profile_stack f
| isError profile = (Error (fromError profile),f)
# (end,f) = fend f
| not end = (Error "garbage at end of file",f)
# profile =
{ modules = fromOk modules
, cost_centres = fromOk cost_centres
......@@ -144,7 +146,7 @@ where
read_cost_centres i n arr f
| i==n
= (Ok arr,f)
# (ok,module_id,f) = freadi f
# (ok,module_id,f) = read_var_width_int f
| not ok = (unexpected_eof,f)
# (name,f) = read_nul_terminated_string [] f
| isError name
......@@ -153,30 +155,26 @@ where
read_profile_stack :: !*File -> (!MaybeError String Stack, !*File)
read_profile_stack f
# (ok,cost_centre,f) = freadi f
# (ok,cost_centre,f) = read_var_width_int f
| not ok = (unexpected_eof,f)
# (ok,ticks_lo,f) = freadi f
# (ok,ticks,f) = read_var_width_int f
| not ok = (unexpected_eof,f)
# (ok,ticks_hi,f) = freadi f
# (ok,words,f) = read_var_width_int f
| not ok = (unexpected_eof,f)
# (ok,words_lo,f) = freadi f
# (ok,scalls,f) = read_var_width_int f
| not ok = (unexpected_eof,f)
# (ok,words_hi,f) = freadi f
# (ok,lcalls,f) = read_var_width_int f
| not ok = (unexpected_eof,f)
# (ok,scalls,f) = freadi f
# (ok,ccalls,f) = read_var_width_int f
| not ok = (unexpected_eof,f)
# (ok,lcalls,f) = freadi f
| not ok = (unexpected_eof,f)
# (ok,ccalls,f) = freadi f
| not ok = (unexpected_eof,f)
# (ok,n_children,f) = freadi f
# (ok,n_children,f) = read_var_width_int f
| not ok = (unexpected_eof,f)
# (children,f) = read_profile_stacks n_children [] f
| isError children = (Error (fromError children),f)
# profile =
{ cost_centre = cost_centre-1
, ticks = ticks_hi<<32 + ticks_lo
, words = words_hi<<32 + words_lo
, ticks = ticks
, words = words
, scalls = scalls
, lcalls = lcalls
, ccalls = ccalls
......@@ -204,6 +202,18 @@ where
= (Ok {c \\ c <- reverse cs},f)
= read_nul_terminated_string [c:cs] f
read_var_width_int :: !*File -> (!Bool,!Int,!*File)
read_var_width_int f = read 0 0 f
where
read :: !Int !Int !*File -> (!Bool,!Int,!*File)
read i sft f
# (ok,c,f) = freadc f
| not ok = (False,0,f)
# i = i + ((toInt c bitand 0x7f) << sft)
| toInt c bitand 0x80==0
= (True,i,f)
= read i (sft+7) f
prepare :: !Int !('Data.Set'.Set String) !Profile -> Profile
prepare min_cumulative_ticks excluded p =
{ p
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment