summaryrefslogtreecommitdiff
path: root/emit.fun
diff options
context:
space:
mode:
authorVladimir Azarov <avm@intermediate-node.net>2025-08-08 23:51:31 +0200
committerVladimir Azarov <avm@intermediate-node.net>2025-08-08 23:51:31 +0200
commitffee5da4dab26c8500add63da540ee252545370f (patch)
tree0306ad055672bb684687e342b318745df1e057ce /emit.fun
parenta417225089fd78d53d73ad63cd79f57d1a4a8ff1 (diff)
Variadic function declarations and calls
Diffstat (limited to 'emit.fun')
-rw-r--r--emit.fun34
1 files changed, 34 insertions, 0 deletions
diff --git a/emit.fun b/emit.fun
index c794f26..ada0217 100644
--- a/emit.fun
+++ b/emit.fun
@@ -847,6 +847,36 @@ functor Emit(I: IL) = struct
List.app (printAllocVar rinfo) toAlloc
end
+ fun getUsedRegs rinfo =
+ let
+ val regs = Array.array (usedRegNum, false)
+
+ fun loop idx =
+ if idx = Array.length rinfo then
+ ()
+ else
+ let
+ val (_, vt) = Array.sub (rinfo, idx)
+ in
+ case vt of
+ VtReg reg => Array.update (regs, reg2idx reg - firstUsedReg, true)
+ | _ => ();
+ loop (idx + 1)
+ end
+ val () = loop 0
+
+ fun collect idx acc =
+ if idx = usedRegNum then
+ acc
+ else
+ if Array.sub (regs, idx) then
+ collect (idx + 1) (idx2reg (idx + firstUsedReg) :: acc)
+ else
+ collect (idx + 1) acc
+ in
+ collect 0 []
+ end
+
fun regAlloc (F as I.Fi { vregs, ops, paramNum, ... }) =
let
val (toAlloc, regInfo) = prepareRegInfo paramNum ops vregs
@@ -858,6 +888,10 @@ functor Emit(I: IL) = struct
val () = linearscan regInfo intervals
val () = printAlloced regInfo toAlloc
+
+ val usedRegs = getUsedRegs regInfo
+ val () = printfn
+ `"used registers: " Plist preg usedRegs (", ", true, 0) %
in
raise Unimplemented
end