on b82cec2 help sign in
Idris-dev/src/IRTS/CodegenC.hs
471 lines 23 kB history raw
1module IRTS.CodegenC (codegenC) where
3import Idris.AbsSyntax
4import IRTS.Bytecode
5import IRTS.Lang
6import IRTS.Simplified
7import IRTS.CodegenCommon
8import Core.TT
9import Paths_idris
10import Util.System
12import Data.Char
13import System.Process
14import System.Exit
15import System.IO
16import System.Directory
17import System.FilePath ((</>), (<.>))
18import Control.Monad
20codegenC :: [(Name, SDecl)] ->
21 String -> -- output file name
22 OutputType -> -- generate executable if True, only .o if False
23 [FilePath] -> -- include files
24 String -> -- extra object files
25 String -> -- extra compiler flags
26 DbgLevel ->
27 IO ()
28codegenC defs out exec incs objs libs dbg
29 = do -- print defs
30 let bc = map toBC defs
31 let h = concatMap toDecl (map fst bc)
32 let cc = concatMap (uncurry toC) bc
33 d <- getDataDir
34 mprog <- readFile (d </> "rts" </> "idris_main" <.> "c")
35 let cout = headers incs ++ debug dbg ++ h ++ cc ++
36 (if (exec == Executable) then mprog else "")
37 case exec of
38 Raw -> writeFile out cout
39 _ -> do
40 (tmpn, tmph) <- tempfile
41 hPutStr tmph cout
42 hFlush tmph
43 hClose tmph
44 let useclang = False
45 comp <- getCC
46 libFlags <- getLibFlags
47 incFlags <- getIncFlags
48 let gcc = comp ++ " " ++
49 gccDbg dbg ++
50 " -I. " ++ objs ++ " -x c " ++
51 "-static " ++ -- prevent linking to .so of rts
52 (if (exec == Executable) then "" else " -c ") ++
53 " " ++ tmpn ++
54 " " ++ libFlags ++
55 " " ++ incFlags ++
56 " " ++ libs ++
57 " -o " ++ out
58-- putStrLn gcc
59 exit <- system gcc
60 when (exit /= ExitSuccess) $
61 putStrLn ("FAILURE: " ++ gcc)
63headers xs =
64 concatMap
65 (\h -> "#include <" ++ h ++ ">\n")
66 (xs ++ ["idris_rts.h", "idris_bitstring.h", "idris_stdfgn.h", "gmp.h", "assert.h"])
68debug TRACE = "#define IDRIS_TRACE\n\n"
69debug _ = ""
71gccDbg DEBUG = "-g"
72gccDbg TRACE = "-O2"
73gccDbg _ = "-O2"
75cname :: Name -> String
76cname n = "_idris_" ++ concatMap cchar (show n)
77 where cchar x | isAlpha x || isDigit x = [x]
78 | otherwise = "_" ++ show (fromEnum x) ++ "_"
80indent :: Int -> String
81indent n = replicate (n*4) ' '
83creg RVal = "RVAL"
84creg (L i) = "LOC(" ++ show i ++ ")"
85creg (T i) = "TOP(" ++ show i ++ ")"
86creg Tmp = "REG1"
88toDecl :: Name -> String
89toDecl f = "void " ++ cname f ++ "(VM*, VAL*);\n"
91toC :: Name -> [BC] -> String
92toC f code
93 = -- "/* " ++ show code ++ "*/\n\n" ++
94 "void " ++ cname f ++ "(VM* vm, VAL* oldbase) {\n" ++
95 indent 1 ++ "INITFRAME;\n" ++
96 concatMap (bcc 1) code ++ "}\n\n"
98bcc :: Int -> BC -> String
99bcc i (ASSIGN l r) = indent i ++ creg l ++ " = " ++ creg r ++ ";\n"
100bcc i (ASSIGNCONST l c)
101 = indent i ++ creg l ++ " = " ++ mkConst c ++ ";\n"
102 where
103 mkConst (I i) = "MKINT(" ++ show i ++ ")"
104 mkConst (BI i) | i < (2^30) = "MKINT(" ++ show i ++ ")"
105 | otherwise = "MKBIGC(vm,\"" ++ show i ++ "\")"
106 mkConst (Fl f) = "MKFLOAT(vm, " ++ show f ++ ")"
107 mkConst (Ch c) = "MKINT(" ++ show (fromEnum c) ++ ")"
108 mkConst (Str s) = "MKSTR(vm, " ++ show s ++ ")"
109 mkConst (B8 b) = "MKB8(vm, " ++ show b ++")"
110 mkConst (B16 b) = "MKB16(vm, " ++ show b ++ ")"
111 mkConst (B32 b) = "MKB32(vm, " ++ show b ++ ")"
112 mkConst (B64 b) = "MKB64(vm, " ++ show b ++ ")"
113 mkConst _ = "MKINT(42424242)"
114bcc i (UPDATE l r) = indent i ++ creg l ++ " = " ++ creg r ++ ";\n"
115bcc i (MKCON l tag args)
116 = indent i ++ "allocCon(" ++ creg Tmp ++ ", vm, " ++ show tag ++ "," ++
117 show (length args) ++ ", 0);\n" ++
118 indent i ++ setArgs 0 args ++ "\n" ++
119 indent i ++ creg l ++ " = " ++ creg Tmp ++ ";\n"
121-- "MKCON(vm, " ++ creg l ++ ", " ++ show tag ++ ", " ++
122-- show (length args) ++ concatMap showArg args ++ ");\n"
123 where showArg r = ", " ++ creg r
124 setArgs i [] = ""
125 setArgs i (x : xs) = "SETARG(" ++ creg Tmp ++ ", " ++ show i ++ ", " ++ creg x ++
126 "); " ++ setArgs (i + 1) xs
128bcc i (PROJECT l loc a) = indent i ++ "PROJECT(vm, " ++ creg l ++ ", " ++ show loc ++
129 ", " ++ show a ++ ");\n"
130bcc i (PROJECTINTO r t idx)
131 = indent i ++ creg r ++ " = GETARG(" ++ creg t ++ ", " ++ show idx ++ ");\n"
132bcc i (CASE True r code def)
133 | length code < 4 = showCase i def code
134 where
135 showCode :: Int -> [BC] -> String
136 showCode i bc = "{\n" ++ indent i ++ concatMap (bcc (i + 1)) bc ++
137 indent i ++ "}\n"
139 showCase :: Int -> Maybe [BC] -> [(Int, [BC])] -> String
140 showCase i Nothing [(t, c)] = showCode i c
141 showCase i (Just def) [] = showCode i def
142 showCase i def ((t, c) : cs)
143 = "if (CTAG(" ++ creg r ++ ") == " ++ show t ++ ") " ++ showCode i c
144 ++ "else " ++ showCase i def cs
146bcc i (CASE safe r code def)
147 = indent i ++ "switch(" ++ ctag safe ++ "(" ++ creg r ++ ")) {\n" ++
148 concatMap (showCase i) code ++
149 showDef i def ++
150 indent i ++ "}\n"
151 where
152 ctag True = "CTAG"
153 ctag False = "TAG"
155 showCase i (t, bc) = indent i ++ "case " ++ show t ++ ":\n"
156 ++ concatMap (bcc (i+1)) bc ++ indent (i + 1) ++ "break;\n"
157 showDef i Nothing = ""
158 showDef i (Just c) = indent i ++ "default:\n"
159 ++ concatMap (bcc (i+1)) c ++ indent (i + 1) ++ "break;\n"
160bcc i (CONSTCASE r code def)
161 | intConsts code
162-- = indent i ++ "switch(GETINT(" ++ creg r ++ ")) {\n" ++
163-- concatMap (showCase i) code ++
164-- showDef i def ++
165-- indent i ++ "}\n"
166 = concatMap (iCase (creg r)) code ++
167 indent i ++ "{\n" ++ showDefS i def ++ indent i ++ "}\n"
168 | strConsts code
169 = concatMap (strCase ("GETSTR(" ++ creg r ++ ")")) code ++
170 indent i ++ "{\n" ++ showDefS i def ++ indent i ++ "}\n"
171 | bigintConsts code
172 = concatMap (biCase (creg r)) code ++
173 indent i ++ "{\n" ++ showDefS i def ++ indent i ++ "}\n"
174 | otherwise = error $ "Can't happen: Can't compile const case " ++ show code
175 where
176 intConsts ((I _, _ ) : _) = True
177 intConsts ((Ch _, _ ) : _) = True
178 intConsts _ = False
180 bigintConsts ((BI _, _ ) : _) = True
181 bigintConsts _ = False
183 strConsts ((Str _, _ ) : _) = True
184 strConsts _ = False
186 strCase sv (s, bc) =
187 indent i ++ "if (strcmp(" ++ sv ++ ", " ++ show s ++ ") == 0) {\n" ++
188 concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
189 biCase bv (BI b, bc) =
190 indent i ++ "if (bigEqConst(" ++ bv ++ ", " ++ show b ++ ")) {\n"
191 ++ concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
192 iCase v (I b, bc) =
193 indent i ++ "if (GETINT(" ++ v ++ ") == " ++ show b ++ ") {\n"
194 ++ concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
195 iCase v (Ch b, bc) =
196 indent i ++ "if (GETINT(" ++ v ++ ") == " ++ show b ++ ") {\n"
197 ++ concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
199 showCase i (t, bc) = indent i ++ "case " ++ show t ++ ":\n"
200 ++ concatMap (bcc (i+1)) bc ++
201 indent (i + 1) ++ "break;\n"
202 showDef i Nothing = ""
203 showDef i (Just c) = indent i ++ "default:\n"
204 ++ concatMap (bcc (i+1)) c ++
205 indent (i + 1) ++ "break;\n"
206 showDefS i Nothing = ""
207 showDefS i (Just c) = concatMap (bcc (i+1)) c
209bcc i (CALL n) = indent i ++ "CALL(" ++ cname n ++ ");\n"
210bcc i (TAILCALL n) = indent i ++ "TAILCALL(" ++ cname n ++ ");\n"
211bcc i (SLIDE n) = indent i ++ "SLIDE(vm, " ++ show n ++ ");\n"
212bcc i REBASE = indent i ++ "REBASE;\n"
213bcc i (RESERVE 0) = ""
214bcc i (RESERVE n) = indent i ++ "RESERVE(" ++ show n ++ ");\n"
215bcc i (ADDTOP 0) = ""
216bcc i (ADDTOP n) = indent i ++ "ADDTOP(" ++ show n ++ ");\n"
217bcc i (TOPBASE n) = indent i ++ "TOPBASE(" ++ show n ++ ");\n"
218bcc i (BASETOP n) = indent i ++ "BASETOP(" ++ show n ++ ");\n"
219bcc i STOREOLD = indent i ++ "STOREOLD;\n"
220bcc i (OP l fn args) = indent i ++ doOp (creg l ++ " = ") fn args ++ ";\n"
221bcc i (FOREIGNCALL l LANG_C rty fn args)
222 = indent i ++
223 c_irts rty (creg l ++ " = ")
224 (fn ++ "(" ++ showSep "," (map fcall args) ++ ")") ++ ";\n"
225 where fcall (t, arg) = irts_c t (creg arg)
226bcc i (NULL r) = indent i ++ creg r ++ " = NULL;\n" -- clear, so it'll be GCed
227bcc i (ERROR str) = indent i ++ "fprintf(stderr, " ++ show str ++ "); assert(0); exit(-1);"
228-- bcc i _ = indent i ++ "// not done yet\n"
230c_irts FInt l x = l ++ "MKINT((i_int)(" ++ x ++ "))"
231c_irts FChar l x = l ++ "MKINT((i_int)(" ++ x ++ "))"
232c_irts FString l x = l ++ "MKSTR(vm, " ++ x ++ ")"
233c_irts FUnit l x = x
234c_irts FPtr l x = l ++ "MKPTR(vm, " ++ x ++ ")"
235c_irts FDouble l x = l ++ "MKFLOAT(vm, " ++ x ++ ")"
236c_irts FAny l x = l ++ x
238irts_c FInt x = "GETINT(" ++ x ++ ")"
239irts_c FChar x = "GETINT(" ++ x ++ ")"
240irts_c FString x = "GETSTR(" ++ x ++ ")"
241irts_c FUnit x = x
242irts_c FPtr x = "GETPTR(" ++ x ++ ")"
243irts_c FDouble x = "GETFLOAT(" ++ x ++ ")"
244irts_c FAny x = x
246doOp v LPlus [l, r] = v ++ "ADD(" ++ creg l ++ ", " ++ creg r ++ ")"
247doOp v LMinus [l, r] = v ++ "INTOP(-," ++ creg l ++ ", " ++ creg r ++ ")"
248doOp v LTimes [l, r] = v ++ "MULT(" ++ creg l ++ ", " ++ creg r ++ ")"
249doOp v LDiv [l, r] = v ++ "INTOP(/," ++ creg l ++ ", " ++ creg r ++ ")"
250doOp v LMod [l, r] = v ++ "INTOP(%," ++ creg l ++ ", " ++ creg r ++ ")"
251doOp v LAnd [l, r] = v ++ "INTOP(&," ++ creg l ++ ", " ++ creg r ++ ")"
252doOp v LOr [l, r] = v ++ "INTOP(|," ++ creg l ++ ", " ++ creg r ++ ")"
253doOp v LXOr [l, r] = v ++ "INTOP(^," ++ creg l ++ ", " ++ creg r ++ ")"
254doOp v LSHL [l, r] = v ++ "INTOP(<<," ++ creg l ++ ", " ++ creg r ++ ")"
255doOp v LSHR [l, r] = v ++ "INTOP(>>," ++ creg l ++ ", " ++ creg r ++ ")"
256doOp v LCompl [x] = v ++ "INTOP(~," ++ creg x ++ ")"
257doOp v LEq [l, r] = v ++ "INTOP(==," ++ creg l ++ ", " ++ creg r ++ ")"
258doOp v LLt [l, r] = v ++ "INTOP(<," ++ creg l ++ ", " ++ creg r ++ ")"
259doOp v LLe [l, r] = v ++ "INTOP(<=," ++ creg l ++ ", " ++ creg r ++ ")"
260doOp v LGt [l, r] = v ++ "INTOP(>," ++ creg l ++ ", " ++ creg r ++ ")"
261doOp v LGe [l, r] = v ++ "INTOP(>=," ++ creg l ++ ", " ++ creg r ++ ")"
263doOp v LFPlus [l, r] = v ++ "FLOATOP(+," ++ creg l ++ ", " ++ creg r ++ ")"
264doOp v LFMinus [l, r] = v ++ "FLOATOP(-," ++ creg l ++ ", " ++ creg r ++ ")"
265doOp v LFTimes [l, r] = v ++ "FLOATOP(*," ++ creg l ++ ", " ++ creg r ++ ")"
266doOp v LFDiv [l, r] = v ++ "FLOATOP(/," ++ creg l ++ ", " ++ creg r ++ ")"
267doOp v LFEq [l, r] = v ++ "FLOATBOP(==," ++ creg l ++ ", " ++ creg r ++ ")"
268doOp v LFLt [l, r] = v ++ "FLOATBOP(<," ++ creg l ++ ", " ++ creg r ++ ")"
269doOp v LFLe [l, r] = v ++ "FLOATBOP(<=," ++ creg l ++ ", " ++ creg r ++ ")"
270doOp v LFGt [l, r] = v ++ "FLOATBOP(>," ++ creg l ++ ", " ++ creg r ++ ")"
271doOp v LFGe [l, r] = v ++ "FLOATBOP(>=," ++ creg l ++ ", " ++ creg r ++ ")"
273doOp v LBPlus [l, r] = v ++ "idris_bigPlus(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
274doOp v LBMinus [l, r] = v ++ "idris_bigMinus(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
275doOp v LBDec [l] = v ++ "idris_bigMinus(vm, " ++ creg l ++ ", MKINT(1))"
276doOp v LBTimes [l, r] = v ++ "idris_bigTimes(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
277doOp v LBDiv [l, r] = v ++ "idris_bigDivide(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
278doOp v LBMod [l, r] = v ++ "idris_bigMod(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
279doOp v LBEq [l, r] = v ++ "idris_bigEq(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
280doOp v LBLt [l, r] = v ++ "idris_bigLt(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
281doOp v LBLe [l, r] = v ++ "idris_bigLe(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
282doOp v LBGt [l, r] = v ++ "idris_bigGt(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
283doOp v LBGe [l, r] = v ++ "idris_bigGe(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
285doOp v LStrConcat [l,r] = v ++ "idris_concat(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
286doOp v LStrLt [l,r] = v ++ "idris_strlt(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
287doOp v LStrEq [l,r] = v ++ "idris_streq(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
288doOp v LStrLen [x] = v ++ "idris_strlen(vm, " ++ creg x ++ ")"
290doOp v LIntFloat [x] = v ++ "idris_castIntFloat(" ++ creg x ++ ")"
291doOp v LFloatInt [x] = v ++ "idris_castFloatInt(" ++ creg x ++ ")"
292doOp v LIntStr [x] = v ++ "idris_castIntStr(vm, " ++ creg x ++ ")"
293doOp v LStrInt [x] = v ++ "idris_castStrInt(vm, " ++ creg x ++ ")"
294doOp v LIntBig [x] = v ++ "idris_castIntBig(vm, " ++ creg x ++ ")"
295doOp v LBigInt [x] = v ++ "idris_castBigInt(vm, " ++ creg x ++ ")"
296doOp v LStrBig [x] = v ++ "idris_castStrBig(vm, " ++ creg x ++ ")"
297doOp v LBigStr [x] = v ++ "idris_castBigStr(vm, " ++ creg x ++ ")"
298doOp v LFloatStr [x] = v ++ "idris_castFloatStr(vm, " ++ creg x ++ ")"
299doOp v LStrFloat [x] = v ++ "idris_castStrFloat(vm, " ++ creg x ++ ")"
301doOp v LReadStr [x] = v ++ "idris_readStr(vm, GETPTR(" ++ creg x ++ "))"
302doOp _ LPrintNum [x] = "printf(\"%ld\\n\", GETINT(" ++ creg x ++ "))"
303doOp _ LPrintStr [x] = "fputs(GETSTR(" ++ creg x ++ "), stdout)"
305doOp v LIntB8 [x] = v ++ "idris_b8(vm, " ++ creg x ++ ")"
306doOp v LIntB16 [x] = v ++ "idris_b16(vm, " ++ creg x ++ ")"
307doOp v LIntB32 [x] = v ++ "idris_b32(vm, " ++ creg x ++ ")"
308doOp v LIntB64 [x] = v ++ "idris_b64(vm, " ++ creg x ++ ")"
310doOp v LB32Int [x] = v ++ "idris_castB32Int(vm, " ++ creg x ++ ")"
312doOp v LB8Lt [x, y] = v ++ "idris_b8Lt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
313doOp v LB8Lte [x, y] = v ++ "idris_b8Lte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
314doOp v LB8Eq [x, y] = v ++ "idris_b8Eq(vm, " ++ creg x ++ "," ++ creg y ++ ")"
315doOp v LB8Gte [x, y] = v ++ "idris_b8Gte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
316doOp v LB8Gt [x, y] = v ++ "idris_b8Gt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
318doOp v LB8Shl [x, y] = v ++ "idris_b8Shl(vm, " ++ creg x ++ "," ++ creg y ++ ")"
319doOp v LB8LShr [x, y] = v ++ "idris_b8Shr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
320doOp v LB8AShr [x, y] = v ++ "idris_b8AShr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
321doOp v LB8And [x, y] = v ++ "idris_b8And(vm, " ++ creg x ++ "," ++ creg y ++ ")"
322doOp v LB8Or [x, y] = v ++ "idris_b8Or(vm, " ++ creg x ++ "," ++ creg y ++ ")"
323doOp v LB8Xor [x, y] = v ++ "idris_b8Xor(vm, " ++ creg x ++ "," ++ creg y ++ ")"
324doOp v LB8Compl [x] = v ++ "idris_b8Compl(vm, " ++ creg x ++ ")"
326doOp v LB8Plus [x, y] = v ++ "idris_b8Plus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
327doOp v LB8Minus [x, y] = v ++ "idris_b8Minus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
328doOp v LB8Times [x, y] = v ++ "idris_b8Times(vm, " ++ creg x ++ "," ++ creg y ++ ")"
329doOp v LB8UDiv [x, y] = v ++ "idris_b8UDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
330doOp v LB8SDiv [x, y] = v ++ "idris_b8SDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
331doOp v LB8URem [x, y] = v ++ "idris_b8URem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
332doOp v LB8SRem [x, y] = v ++ "idris_b8SRem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
334doOp v LB8Z16 [x] = v ++ "idris_b8Z16(vm, " ++ creg x ++ ")"
335doOp v LB8Z32 [x] = v ++ "idris_b8Z32(vm, " ++ creg x ++ ")"
336doOp v LB8Z64 [x] = v ++ "idris_b8Z64(vm, " ++ creg x ++ ")"
337doOp v LB8S16 [x] = v ++ "idris_b8S16(vm, " ++ creg x ++ ")"
338doOp v LB8S32 [x] = v ++ "idris_b8S32(vm, " ++ creg x ++ ")"
339doOp v LB8S64 [x] = v ++ "idris_b8S64(vm, " ++ creg x ++ ")"
341doOp v LB16Lt [x, y] = v ++ "idris_b16Lt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
342doOp v LB16Lte [x, y] = v ++ "idris_b16Lte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
343doOp v LB16Eq [x, y] = v ++ "idris_b16Eq(vm, " ++ creg x ++ "," ++ creg y ++ ")"
344doOp v LB16Gte [x, y] = v ++ "idris_b16Gte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
345doOp v LB16Gt [x, y] = v ++ "idris_b16Gt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
347doOp v LB16Shl [x, y] = v ++ "idris_b16Shl(vm, " ++ creg x ++ "," ++ creg y ++ ")"
348doOp v LB16LShr [x, y] = v ++ "idris_b16Shr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
349doOp v LB16AShr [x, y] = v ++ "idris_b16AShr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
350doOp v LB16And [x, y] = v ++ "idris_b16And(vm, " ++ creg x ++ "," ++ creg y ++ ")"
351doOp v LB16Or [x, y] = v ++ "idris_b16Or(vm, " ++ creg x ++ "," ++ creg y ++ ")"
352doOp v LB16Xor [x, y] = v ++ "idris_b16Xor(vm, " ++ creg x ++ "," ++ creg y ++ ")"
353doOp v LB16Compl [x] = v ++ "idris_b16Compl(vm, " ++ creg x ++ ")"
355doOp v LB16Plus [x, y] =
356 v ++ "idris_b16Plus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
357doOp v LB16Minus [x, y] =
358 v ++ "idris_b16Minus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
359doOp v LB16Times [x, y] =
360 v ++ "idris_b16Times(vm, " ++ creg x ++ "," ++ creg y ++ ")"
361doOp v LB16UDiv [x, y] =
362 v ++ "idris_b16UDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
363doOp v LB16SDiv [x, y] =
364 v ++ "idris_b16SDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
365doOp v LB16URem [x, y] =
366 v ++ "idris_b16URem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
367doOp v LB16SRem [x, y] =
368 v ++ "idris_b16SRem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
370doOp v LB16Z32 [x] = v ++ "idris_b16Z32(vm, " ++ creg x ++ ")"
371doOp v LB16Z64 [x] = v ++ "idris_b16Z64(vm, " ++ creg x ++ ")"
372doOp v LB16S32 [x] = v ++ "idris_b16S32(vm, " ++ creg x ++ ")"
373doOp v LB16S64 [x] = v ++ "idris_b16S64(vm, " ++ creg x ++ ")"
374doOp v LB16T8 [x] = v ++ "idris_b16T8(vm, " ++ creg x ++ ")"
376doOp v LB32Lt [x, y] = v ++ "idris_b32Lt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
377doOp v LB32Lte [x, y] = v ++ "idris_b32Lte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
378doOp v LB32Eq [x, y] = v ++ "idris_b32Eq(vm, " ++ creg x ++ "," ++ creg y ++ ")"
379doOp v LB32Gte [x, y] = v ++ "idris_b32Gte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
380doOp v LB32Gt [x, y] = v ++ "idris_b32Gt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
382doOp v LB32Shl [x, y] = v ++ "idris_b32Shl(vm, " ++ creg x ++ "," ++ creg y ++ ")"
383doOp v LB32LShr [x, y] = v ++ "idris_b32Shr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
384doOp v LB32AShr [x, y] = v ++ "idris_b32AShr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
385doOp v LB32And [x, y] = v ++ "idris_b32And(vm, " ++ creg x ++ "," ++ creg y ++ ")"
386doOp v LB32Or [x, y] = v ++ "idris_b32Or(vm, " ++ creg x ++ "," ++ creg y ++ ")"
387doOp v LB32Xor [x, y] = v ++ "idris_b32Xor(vm, " ++ creg x ++ "," ++ creg y ++ ")"
388doOp v LB32Compl [x] = v ++ "idris_b32Compl(vm, " ++ creg x ++ ")"
390doOp v LB32Plus [x, y] =
391 v ++ "idris_b32Plus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
392doOp v LB32Minus [x, y] =
393 v ++ "idris_b32Minus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
394doOp v LB32Times [x, y] =
395 v ++ "idris_b32Times(vm, " ++ creg x ++ "," ++ creg y ++ ")"
396doOp v LB32UDiv [x, y] =
397 v ++ "idris_b32UDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
398doOp v LB32SDiv [x, y] =
399 v ++ "idris_b32SDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
400doOp v LB32URem [x, y] =
401 v ++ "idris_b32URem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
402doOp v LB32SRem [x, y] =
403 v ++ "idris_b32SRem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
405doOp v LB32Z64 [x] = v ++ "idris_b32Z64(vm, " ++ creg x ++ ")"
406doOp v LB32S64 [x] = v ++ "idris_b32S64(vm, " ++ creg x ++ ")"
407doOp v LB32T8 [x] = v ++ "idris_b32T8(vm, " ++ creg x ++ ")"
408doOp v LB32T16 [x] = v ++ "idris_b32T16(vm, " ++ creg x ++ ")"
410doOp v LB64Lt [x, y] = v ++ "idris_b64Lt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
411doOp v LB64Lte [x, y] = v ++ "idris_b64Lte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
412doOp v LB64Eq [x, y] = v ++ "idris_b64Eq(vm, " ++ creg x ++ "," ++ creg y ++ ")"
413doOp v LB64Gte [x, y] = v ++ "idris_b64Gte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
414doOp v LB64Gt [x, y] = v ++ "idris_b64Gt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
416doOp v LB64Shl [x, y] = v ++ "idris_b64Shl(vm, " ++ creg x ++ "," ++ creg y ++ ")"
417doOp v LB64LShr [x, y] = v ++ "idris_b64Shr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
418doOp v LB64AShr [x, y] = v ++ "idris_b64AShr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
419doOp v LB64And [x, y] = v ++ "idris_b64And(vm, " ++ creg x ++ "," ++ creg y ++ ")"
420doOp v LB64Or [x, y] = v ++ "idris_b64Or(vm, " ++ creg x ++ "," ++ creg y ++ ")"
421doOp v LB64Xor [x, y] = v ++ "idris_b64Xor(vm, " ++ creg x ++ "," ++ creg y ++ ")"
422doOp v LB64Compl [x] = v ++ "idris_b64Compl(vm, " ++ creg x ++ ")"
424doOp v LB64Plus [x, y] =
425 v ++ "idris_b64Plus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
426doOp v LB64Minus [x, y] =
427 v ++ "idris_b64Minus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
428doOp v LB64Times [x, y] =
429 v ++ "idris_b64Times(vm, " ++ creg x ++ "," ++ creg y ++ ")"
430doOp v LB64UDiv [x, y] =
431 v ++ "idris_b64UDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
432doOp v LB64SDiv [x, y] =
433 v ++ "idris_b64SDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
434doOp v LB64URem [x, y] =
435 v ++ "idris_b64URem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
436doOp v LB64SRem [x, y] =
437 v ++ "idris_b64SRem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
439doOp v LB64T8 [x] = v ++ "idris_b64T8(vm, " ++ creg x ++ ")"
440doOp v LB64T16 [x] = v ++ "idris_b64T16(vm, " ++ creg x ++ ")"
441doOp v LB64T32 [x] = v ++ "idris_b64T32(vm, " ++ creg x ++ ")"
443doOp v LFExp [x] = v ++ "MKFLOAT(exp(GETFLOAT(" ++ creg x ++ ")))"
444doOp v LFLog [x] = v ++ "MKFLOAT(log(GETFLOAT(" ++ creg x ++ ")))"
445doOp v LFSin [x] = v ++ "MKFLOAT(sin(GETFLOAT(" ++ creg x ++ ")))"
446doOp v LFCos [x] = v ++ "MKFLOAT(cos(GETFLOAT(" ++ creg x ++ ")))"
447doOp v LFTan [x] = v ++ "MKFLOAT(tan(GETFLOAT(" ++ creg x ++ ")))"
448doOp v LFASin [x] = v ++ "MKFLOAT(asin(GETFLOAT(" ++ creg x ++ ")))"
449doOp v LFACos [x] = v ++ "MKFLOAT(acos(GETFLOAT(" ++ creg x ++ ")))"
450doOp v LFATan [x] = v ++ "MKFLOAT(atan(GETFLOAT(" ++ creg x ++ ")))"
451doOp v LFSqrt [x] = v ++ "MKFLOAT(floor(GETFLOAT(" ++ creg x ++ ")))"
452doOp v LFFloor [x] = v ++ "MKFLOAT(ceil(GETFLOAT(" ++ creg x ++ ")))"
453doOp v LFCeil [x] = v ++ "MKFLOAT(sqrt(GETFLOAT(" ++ creg x ++ ")))"
455doOp v LStrHead [x] = v ++ "idris_strHead(vm, " ++ creg x ++ ")"
456doOp v LStrTail [x] = v ++ "idris_strTail(vm, " ++ creg x ++ ")"
457doOp v LStrCons [x, y] = v ++ "idris_strCons(vm, " ++ creg x ++ "," ++ creg y ++ ")"
458doOp v LStrIndex [x, y] = v ++ "idris_strIndex(vm, " ++ creg x ++ "," ++ creg y ++ ")"
459doOp v LStrRev [x] = v ++ "idris_strRev(vm, " ++ creg x ++ ")"
461doOp v LStdIn [] = v ++ "MKPTR(vm, stdin)"
462doOp v LStdOut [] = v ++ "MKPTR(vm, stdout)"
463doOp v LStdErr [] = v ++ "MKPTR(vm, stderr)"
465doOp v LFork [x] = v ++ "MKPTR(vm, vmThread(vm, " ++ cname (MN 0 "EVAL") ++ ", " ++ creg x ++ "))"
466doOp v LPar [x] = v ++ creg x -- "MKPTR(vm, vmThread(vm, " ++ cname (MN 0 "EVAL") ++ ", " ++ creg x ++ "))"
467doOp v LVMPtr [] = v ++ "MKPTR(vm, vm)"
468doOp v LChInt args = v ++ creg (last args)
469doOp v LIntCh args = v ++ creg (last args)
470doOp v LNoOp args = v ++ creg (last args)
471doOp _ op _ = "FAIL /* " ++ show op ++ " */"