Debian Codegraph @

lib/mlrisc-lib/MLRISC/c-call/test/test-varargs.sml

raw
1 structure TestVarargs =
2 struct
3
4 local
5 structure T = X86MLTree
6 structure C = X86Cells
7 in
8 structure X86GenInterp = X86GenFn(
9 fun push e = T.EXT(X86InstrExt.PUSHL e)
10 val leave = T.EXT X86InstrExt.LEAVE
11 structure MLRISCGen =
12 struct
13 structure T = T
14 fun gen (l, stms, mlrs) =
15 X86MLRISCGen.dumpOutput(X86MLRISCGen.codegen'(l, stms, mlrs))
16 end
17 structure Gen = X86CCall.Gen
18 )
19 end
20
21 local
22 structure T = SparcMLTree
23 structure C = SparcCells
24 val GP = C.GPReg
25 val FP = C.FPReg
26
27 fun greg r = GP r
28 fun oreg r = GP (r + 8)
29 fun ireg r = GP (r + 24)
30 fun freg r = FP r
31 fun reg32 r = T.REG (32, r)
32 fun freg64 r = T.FREG (64, r)
33 fun LI i = T.LI (T.I.fromInt (32, i))
34 val g_regs = List.map greg [1, 2, 3, 4, 5, 6, 7]
35 val o_regs = List.map oreg [0, 1, 2, 3, 4, 5, 6, 7]
36 val a_regs = List.take(o_regs, 6)
37 val l_reg = oreg 7
38 val f_regs = List.map freg
39 [0, 2, 4, 6, 8, 10, 12, 14,
40 16, 18, 20, 22, 24, 26, 28, 30]
41 in
42 structure SparcGenInterp = SparcGenFn(
43 structure Gen = SparcCCall.Gen
44 structure MLRISCGen =
45 struct
46 structure T = T
47 fun gen (l, stms, mlrs) =
48 SparcMLRISCGen.dumpOutput(SparcMLRISCGen.gen(l, stms, mlrs))
49 end
50 val gprs = g_regs
51 val fprs = []
52 val callerSaves = g_regs @ a_regs
53 val calleeSaves = []
54 val callerSavesF = f_regs
55 val calleeSavesF = []
56 val oRegs = o_regs
57 )
58 end
59
60 structure VC = VarargCall
61 structure V = Vararg
62 structure DL = DynLinkage
63 fun main's s = DL.lib_symbol (DL.main_lib, s)
64 val printf_h = main's "printf"
65 fun call args = VC.X86VarargCall.dispatchLowlevelCall(printf_h, args)
66
67 fun ex1 () = call [V.STRING_ARG "test123\n"]
68 fun ex2 () = call [V.STRING_ARG "%d %s\n", V.SINT_ARG 1024, V.STRING_ARG "xxx"]
69 fun ex3 () = call [V.STRING_ARG "%d %s %d\n", V.SINT_ARG 1024, V.STRING_ARG "xxx", V.SINT_ARG 222333]
70
71
72 end