on 0752bed help sign in
Idris-dev/src/IRTS/CodegenC.hs
467 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 _ = "MKINT(42424242)"
110bcc i (UPDATE l r) = indent i ++ creg l ++ " = " ++ creg r ++ ";\n"
111bcc i (MKCON l tag args)
112 = indent i ++ "allocCon(" ++ creg Tmp ++ ", vm, " ++ show tag ++ "," ++
113 show (length args) ++ ", 0);\n" ++
114 indent i ++ setArgs 0 args ++ "\n" ++
115 indent i ++ creg l ++ " = " ++ creg Tmp ++ ";\n"
117-- "MKCON(vm, " ++ creg l ++ ", " ++ show tag ++ ", " ++
118-- show (length args) ++ concatMap showArg args ++ ");\n"
119 where showArg r = ", " ++ creg r
120 setArgs i [] = ""
121 setArgs i (x : xs) = "SETARG(" ++ creg Tmp ++ ", " ++ show i ++ ", " ++ creg x ++
122 "); " ++ setArgs (i + 1) xs
124bcc i (PROJECT l loc a) = indent i ++ "PROJECT(vm, " ++ creg l ++ ", " ++ show loc ++
125 ", " ++ show a ++ ");\n"
126bcc i (PROJECTINTO r t idx)
127 = indent i ++ creg r ++ " = GETARG(" ++ creg t ++ ", " ++ show idx ++ ");\n"
128bcc i (CASE True r code def)
129 | length code < 4 = showCase i def code
130 where
131 showCode :: Int -> [BC] -> String
132 showCode i bc = "{\n" ++ indent i ++ concatMap (bcc (i + 1)) bc ++
133 indent i ++ "}\n"
135 showCase :: Int -> Maybe [BC] -> [(Int, [BC])] -> String
136 showCase i Nothing [(t, c)] = showCode i c
137 showCase i (Just def) [] = showCode i def
138 showCase i def ((t, c) : cs)
139 = "if (CTAG(" ++ creg r ++ ") == " ++ show t ++ ") " ++ showCode i c
140 ++ "else " ++ showCase i def cs
142bcc i (CASE safe r code def)
143 = indent i ++ "switch(" ++ ctag safe ++ "(" ++ creg r ++ ")) {\n" ++
144 concatMap (showCase i) code ++
145 showDef i def ++
146 indent i ++ "}\n"
147 where
148 ctag True = "CTAG"
149 ctag False = "TAG"
151 showCase i (t, bc) = indent i ++ "case " ++ show t ++ ":\n"
152 ++ concatMap (bcc (i+1)) bc ++ indent (i + 1) ++ "break;\n"
153 showDef i Nothing = ""
154 showDef i (Just c) = indent i ++ "default:\n"
155 ++ concatMap (bcc (i+1)) c ++ indent (i + 1) ++ "break;\n"
156bcc i (CONSTCASE r code def)
157 | intConsts code
158-- = indent i ++ "switch(GETINT(" ++ creg r ++ ")) {\n" ++
159-- concatMap (showCase i) code ++
160-- showDef i def ++
161-- indent i ++ "}\n"
162 = concatMap (iCase (creg r)) code ++
163 indent i ++ "{\n" ++ showDefS i def ++ indent i ++ "}\n"
164 | strConsts code
165 = concatMap (strCase ("GETSTR(" ++ creg r ++ ")")) code ++
166 indent i ++ "{\n" ++ showDefS i def ++ indent i ++ "}\n"
167 | bigintConsts code
168 = concatMap (biCase (creg r)) code ++
169 indent i ++ "{\n" ++ showDefS i def ++ indent i ++ "}\n"
170 | otherwise = error $ "Can't happen: Can't compile const case " ++ show code
171 where
172 intConsts ((I _, _ ) : _) = True
173 intConsts ((Ch _, _ ) : _) = True
174 intConsts _ = False
176 bigintConsts ((BI _, _ ) : _) = True
177 bigintConsts _ = False
179 strConsts ((Str _, _ ) : _) = True
180 strConsts _ = False
182 strCase sv (s, bc) =
183 indent i ++ "if (strcmp(" ++ sv ++ ", " ++ show s ++ ") == 0) {\n" ++
184 concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
185 biCase bv (BI b, bc) =
186 indent i ++ "if (bigEqConst(" ++ bv ++ ", " ++ show b ++ ")) {\n"
187 ++ concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
188 iCase v (I b, bc) =
189 indent i ++ "if (GETINT(" ++ v ++ ") == " ++ show b ++ ") {\n"
190 ++ concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
191 iCase v (Ch b, bc) =
192 indent i ++ "if (GETINT(" ++ v ++ ") == " ++ show b ++ ") {\n"
193 ++ concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
195 showCase i (t, bc) = indent i ++ "case " ++ show t ++ ":\n"
196 ++ concatMap (bcc (i+1)) bc ++
197 indent (i + 1) ++ "break;\n"
198 showDef i Nothing = ""
199 showDef i (Just c) = indent i ++ "default:\n"
200 ++ concatMap (bcc (i+1)) c ++
201 indent (i + 1) ++ "break;\n"
202 showDefS i Nothing = ""
203 showDefS i (Just c) = concatMap (bcc (i+1)) c
205bcc i (CALL n) = indent i ++ "CALL(" ++ cname n ++ ");\n"
206bcc i (TAILCALL n) = indent i ++ "TAILCALL(" ++ cname n ++ ");\n"
207bcc i (SLIDE n) = indent i ++ "SLIDE(vm, " ++ show n ++ ");\n"
208bcc i REBASE = indent i ++ "REBASE;\n"
209bcc i (RESERVE 0) = ""
210bcc i (RESERVE n) = indent i ++ "RESERVE(" ++ show n ++ ");\n"
211bcc i (ADDTOP 0) = ""
212bcc i (ADDTOP n) = indent i ++ "ADDTOP(" ++ show n ++ ");\n"
213bcc i (TOPBASE n) = indent i ++ "TOPBASE(" ++ show n ++ ");\n"
214bcc i (BASETOP n) = indent i ++ "BASETOP(" ++ show n ++ ");\n"
215bcc i STOREOLD = indent i ++ "STOREOLD;\n"
216bcc i (OP l fn args) = indent i ++ doOp (creg l ++ " = ") fn args ++ ";\n"
217bcc i (FOREIGNCALL l LANG_C rty fn args)
218 = indent i ++
219 c_irts rty (creg l ++ " = ")
220 (fn ++ "(" ++ showSep "," (map fcall args) ++ ")") ++ ";\n"
221 where fcall (t, arg) = irts_c t (creg arg)
222bcc i (NULL r) = indent i ++ creg r ++ " = NULL;\n" -- clear, so it'll be GCed
223bcc i (ERROR str) = indent i ++ "fprintf(stderr, " ++ show str ++ "); assert(0); exit(-1);"
224-- bcc i _ = indent i ++ "// not done yet\n"
226c_irts FInt l x = l ++ "MKINT((i_int)(" ++ x ++ "))"
227c_irts FChar l x = l ++ "MKINT((i_int)(" ++ x ++ "))"
228c_irts FString l x = l ++ "MKSTR(vm, " ++ x ++ ")"
229c_irts FUnit l x = x
230c_irts FPtr l x = l ++ "MKPTR(vm, " ++ x ++ ")"
231c_irts FDouble l x = l ++ "MKFLOAT(vm, " ++ x ++ ")"
232c_irts FAny l x = l ++ x
234irts_c FInt x = "GETINT(" ++ x ++ ")"
235irts_c FChar x = "GETINT(" ++ x ++ ")"
236irts_c FString x = "GETSTR(" ++ x ++ ")"
237irts_c FUnit x = x
238irts_c FPtr x = "GETPTR(" ++ x ++ ")"
239irts_c FDouble x = "GETFLOAT(" ++ x ++ ")"
240irts_c FAny x = x
242doOp v LPlus [l, r] = v ++ "ADD(" ++ creg l ++ ", " ++ creg r ++ ")"
243doOp v LMinus [l, r] = v ++ "INTOP(-," ++ creg l ++ ", " ++ creg r ++ ")"
244doOp v LTimes [l, r] = v ++ "MULT(" ++ creg l ++ ", " ++ creg r ++ ")"
245doOp v LDiv [l, r] = v ++ "INTOP(/," ++ creg l ++ ", " ++ creg r ++ ")"
246doOp v LMod [l, r] = v ++ "INTOP(%," ++ creg l ++ ", " ++ creg r ++ ")"
247doOp v LAnd [l, r] = v ++ "INTOP(&," ++ creg l ++ ", " ++ creg r ++ ")"
248doOp v LOr [l, r] = v ++ "INTOP(|," ++ creg l ++ ", " ++ creg r ++ ")"
249doOp v LXOr [l, r] = v ++ "INTOP(^," ++ creg l ++ ", " ++ creg r ++ ")"
250doOp v LSHL [l, r] = v ++ "INTOP(<<," ++ creg l ++ ", " ++ creg r ++ ")"
251doOp v LSHR [l, r] = v ++ "INTOP(>>," ++ creg l ++ ", " ++ creg r ++ ")"
252doOp v LCompl [x] = v ++ "INTOP(~," ++ creg x ++ ")"
253doOp v LEq [l, r] = v ++ "INTOP(==," ++ creg l ++ ", " ++ creg r ++ ")"
254doOp v LLt [l, r] = v ++ "INTOP(<," ++ creg l ++ ", " ++ creg r ++ ")"
255doOp v LLe [l, r] = v ++ "INTOP(<=," ++ creg l ++ ", " ++ creg r ++ ")"
256doOp v LGt [l, r] = v ++ "INTOP(>," ++ creg l ++ ", " ++ creg r ++ ")"
257doOp v LGe [l, r] = v ++ "INTOP(>=," ++ creg l ++ ", " ++ creg r ++ ")"
259doOp v LFPlus [l, r] = v ++ "FLOATOP(+," ++ creg l ++ ", " ++ creg r ++ ")"
260doOp v LFMinus [l, r] = v ++ "FLOATOP(-," ++ creg l ++ ", " ++ creg r ++ ")"
261doOp v LFTimes [l, r] = v ++ "FLOATOP(*," ++ creg l ++ ", " ++ creg r ++ ")"
262doOp v LFDiv [l, r] = v ++ "FLOATOP(/," ++ creg l ++ ", " ++ creg r ++ ")"
263doOp v LFEq [l, r] = v ++ "FLOATBOP(==," ++ creg l ++ ", " ++ creg r ++ ")"
264doOp v LFLt [l, r] = v ++ "FLOATBOP(<," ++ creg l ++ ", " ++ creg r ++ ")"
265doOp v LFLe [l, r] = v ++ "FLOATBOP(<=," ++ creg l ++ ", " ++ creg r ++ ")"
266doOp v LFGt [l, r] = v ++ "FLOATBOP(>," ++ creg l ++ ", " ++ creg r ++ ")"
267doOp v LFGe [l, r] = v ++ "FLOATBOP(>=," ++ creg l ++ ", " ++ creg r ++ ")"
269doOp v LBPlus [l, r] = v ++ "idris_bigPlus(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
270doOp v LBMinus [l, r] = v ++ "idris_bigMinus(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
271doOp v LBDec [l] = v ++ "idris_bigMinus(vm, " ++ creg l ++ ", MKINT(1))"
272doOp v LBTimes [l, r] = v ++ "idris_bigTimes(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
273doOp v LBDiv [l, r] = v ++ "idris_bigDivide(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
274doOp v LBMod [l, r] = v ++ "idris_bigMod(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
275doOp v LBEq [l, r] = v ++ "idris_bigEq(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
276doOp v LBLt [l, r] = v ++ "idris_bigLt(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
277doOp v LBLe [l, r] = v ++ "idris_bigLe(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
278doOp v LBGt [l, r] = v ++ "idris_bigGt(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
279doOp v LBGe [l, r] = v ++ "idris_bigGe(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
281doOp v LStrConcat [l,r] = v ++ "idris_concat(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
282doOp v LStrLt [l,r] = v ++ "idris_strlt(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
283doOp v LStrEq [l,r] = v ++ "idris_streq(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
284doOp v LStrLen [x] = v ++ "idris_strlen(vm, " ++ creg x ++ ")"
286doOp v LIntFloat [x] = v ++ "idris_castIntFloat(" ++ creg x ++ ")"
287doOp v LFloatInt [x] = v ++ "idris_castFloatInt(" ++ creg x ++ ")"
288doOp v LIntStr [x] = v ++ "idris_castIntStr(vm, " ++ creg x ++ ")"
289doOp v LStrInt [x] = v ++ "idris_castStrInt(vm, " ++ creg x ++ ")"
290doOp v LIntBig [x] = v ++ "idris_castIntBig(vm, " ++ creg x ++ ")"
291doOp v LBigInt [x] = v ++ "idris_castBigInt(vm, " ++ creg x ++ ")"
292doOp v LStrBig [x] = v ++ "idris_castStrBig(vm, " ++ creg x ++ ")"
293doOp v LBigStr [x] = v ++ "idris_castBigStr(vm, " ++ creg x ++ ")"
294doOp v LFloatStr [x] = v ++ "idris_castFloatStr(vm, " ++ creg x ++ ")"
295doOp v LStrFloat [x] = v ++ "idris_castStrFloat(vm, " ++ creg x ++ ")"
297doOp v LReadStr [x] = v ++ "idris_readStr(vm, GETPTR(" ++ creg x ++ "))"
298doOp _ LPrintNum [x] = "printf(\"%ld\\n\", GETINT(" ++ creg x ++ "))"
299doOp _ LPrintStr [x] = "fputs(GETSTR(" ++ creg x ++ "), stdout)"
301doOp v LIntB8 [x] = v ++ "idris_b8(vm, " ++ creg x ++ ")"
302doOp v LIntB16 [x] = v ++ "idris_b16(vm, " ++ creg x ++ ")"
303doOp v LIntB32 [x] = v ++ "idris_b32(vm, " ++ creg x ++ ")"
304doOp v LIntB64 [x] = v ++ "idris_b64(vm, " ++ creg x ++ ")"
306doOp v LB32Int [x] = v ++ "idris_castB32Int(vm, " ++ creg x ++ ")"
308doOp v LB8Lt [x, y] = v ++ "idris_b8Lt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
309doOp v LB8Lte [x, y] = v ++ "idris_b8Lte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
310doOp v LB8Eq [x, y] = v ++ "idris_b8Eq(vm, " ++ creg x ++ "," ++ creg y ++ ")"
311doOp v LB8Gte [x, y] = v ++ "idris_b8Gte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
312doOp v LB8Gt [x, y] = v ++ "idris_b8Gt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
314doOp v LB8Shl [x, y] = v ++ "idris_b8Shl(vm, " ++ creg x ++ "," ++ creg y ++ ")"
315doOp v LB8LShr [x, y] = v ++ "idris_b8Shr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
316doOp v LB8AShr [x, y] = v ++ "idris_b8AShr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
317doOp v LB8And [x, y] = v ++ "idris_b8And(vm, " ++ creg x ++ "," ++ creg y ++ ")"
318doOp v LB8Or [x, y] = v ++ "idris_b8Or(vm, " ++ creg x ++ "," ++ creg y ++ ")"
319doOp v LB8Xor [x, y] = v ++ "idris_b8Xor(vm, " ++ creg x ++ "," ++ creg y ++ ")"
320doOp v LB8Compl [x] = v ++ "idris_b8Compl(vm, " ++ creg x ++ ")"
322doOp v LB8Plus [x, y] = v ++ "idris_b8Plus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
323doOp v LB8Minus [x, y] = v ++ "idris_b8Minus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
324doOp v LB8Times [x, y] = v ++ "idris_b8Times(vm, " ++ creg x ++ "," ++ creg y ++ ")"
325doOp v LB8UDiv [x, y] = v ++ "idris_b8UDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
326doOp v LB8SDiv [x, y] = v ++ "idris_b8SDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
327doOp v LB8URem [x, y] = v ++ "idris_b8URem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
328doOp v LB8SRem [x, y] = v ++ "idris_b8SRem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
330doOp v LB8Z16 [x] = v ++ "idris_b8Z16(vm, " ++ creg x ++ ")"
331doOp v LB8Z32 [x] = v ++ "idris_b8Z32(vm, " ++ creg x ++ ")"
332doOp v LB8Z64 [x] = v ++ "idris_b8Z64(vm, " ++ creg x ++ ")"
333doOp v LB8S16 [x] = v ++ "idris_b8S16(vm, " ++ creg x ++ ")"
334doOp v LB8S32 [x] = v ++ "idris_b8S32(vm, " ++ creg x ++ ")"
335doOp v LB8S64 [x] = v ++ "idris_b8S64(vm, " ++ creg x ++ ")"
337doOp v LB16Lt [x, y] = v ++ "idris_b16Lt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
338doOp v LB16Lte [x, y] = v ++ "idris_b16Lte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
339doOp v LB16Eq [x, y] = v ++ "idris_b16Eq(vm, " ++ creg x ++ "," ++ creg y ++ ")"
340doOp v LB16Gte [x, y] = v ++ "idris_b16Gte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
341doOp v LB16Gt [x, y] = v ++ "idris_b16Gt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
343doOp v LB16Shl [x, y] = v ++ "idris_b16Shl(vm, " ++ creg x ++ "," ++ creg y ++ ")"
344doOp v LB16LShr [x, y] = v ++ "idris_b16Shr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
345doOp v LB16AShr [x, y] = v ++ "idris_b16AShr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
346doOp v LB16And [x, y] = v ++ "idris_b16And(vm, " ++ creg x ++ "," ++ creg y ++ ")"
347doOp v LB16Or [x, y] = v ++ "idris_b16Or(vm, " ++ creg x ++ "," ++ creg y ++ ")"
348doOp v LB16Xor [x, y] = v ++ "idris_b16Xor(vm, " ++ creg x ++ "," ++ creg y ++ ")"
349doOp v LB16Compl [x] = v ++ "idris_b16Compl(vm, " ++ creg x ++ ")"
351doOp v LB16Plus [x, y] =
352 v ++ "idris_b16Plus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
353doOp v LB16Minus [x, y] =
354 v ++ "idris_b16Minus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
355doOp v LB16Times [x, y] =
356 v ++ "idris_b16Times(vm, " ++ creg x ++ "," ++ creg y ++ ")"
357doOp v LB16UDiv [x, y] =
358 v ++ "idris_b16UDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
359doOp v LB16SDiv [x, y] =
360 v ++ "idris_b16SDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
361doOp v LB16URem [x, y] =
362 v ++ "idris_b16URem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
363doOp v LB16SRem [x, y] =
364 v ++ "idris_b16SRem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
366doOp v LB16Z32 [x] = v ++ "idris_b16Z32(vm, " ++ creg x ++ ")"
367doOp v LB16Z64 [x] = v ++ "idris_b16Z64(vm, " ++ creg x ++ ")"
368doOp v LB16S32 [x] = v ++ "idris_b16S32(vm, " ++ creg x ++ ")"
369doOp v LB16S64 [x] = v ++ "idris_b16S64(vm, " ++ creg x ++ ")"
370doOp v LB16T8 [x] = v ++ "idris_b16T8(vm, " ++ creg x ++ ")"
372doOp v LB32Lt [x, y] = v ++ "idris_b32Lt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
373doOp v LB32Lte [x, y] = v ++ "idris_b32Lte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
374doOp v LB32Eq [x, y] = v ++ "idris_b32Eq(vm, " ++ creg x ++ "," ++ creg y ++ ")"
375doOp v LB32Gte [x, y] = v ++ "idris_b32Gte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
376doOp v LB32Gt [x, y] = v ++ "idris_b32Gt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
378doOp v LB32Shl [x, y] = v ++ "idris_b32Shl(vm, " ++ creg x ++ "," ++ creg y ++ ")"
379doOp v LB32LShr [x, y] = v ++ "idris_b32Shr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
380doOp v LB32AShr [x, y] = v ++ "idris_b32AShr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
381doOp v LB32And [x, y] = v ++ "idris_b32And(vm, " ++ creg x ++ "," ++ creg y ++ ")"
382doOp v LB32Or [x, y] = v ++ "idris_b32Or(vm, " ++ creg x ++ "," ++ creg y ++ ")"
383doOp v LB32Xor [x, y] = v ++ "idris_b32Xor(vm, " ++ creg x ++ "," ++ creg y ++ ")"
384doOp v LB32Compl [x] = v ++ "idris_b32Compl(vm, " ++ creg x ++ ")"
386doOp v LB32Plus [x, y] =
387 v ++ "idris_b32Plus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
388doOp v LB32Minus [x, y] =
389 v ++ "idris_b32Minus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
390doOp v LB32Times [x, y] =
391 v ++ "idris_b32Times(vm, " ++ creg x ++ "," ++ creg y ++ ")"
392doOp v LB32UDiv [x, y] =
393 v ++ "idris_b32UDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
394doOp v LB32SDiv [x, y] =
395 v ++ "idris_b32SDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
396doOp v LB32URem [x, y] =
397 v ++ "idris_b32URem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
398doOp v LB32SRem [x, y] =
399 v ++ "idris_b32SRem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
401doOp v LB32Z64 [x] = v ++ "idris_b32Z64(vm, " ++ creg x ++ ")"
402doOp v LB32S64 [x] = v ++ "idris_b32S64(vm, " ++ creg x ++ ")"
403doOp v LB32T8 [x] = v ++ "idris_b32T8(vm, " ++ creg x ++ ")"
404doOp v LB32T16 [x] = v ++ "idris_b32T16(vm, " ++ creg x ++ ")"
406doOp v LB64Lt [x, y] = v ++ "idris_b64Lt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
407doOp v LB64Lte [x, y] = v ++ "idris_b64Lte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
408doOp v LB64Eq [x, y] = v ++ "idris_b64Eq(vm, " ++ creg x ++ "," ++ creg y ++ ")"
409doOp v LB64Gte [x, y] = v ++ "idris_b64Gte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
410doOp v LB64Gt [x, y] = v ++ "idris_b64Gt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
412doOp v LB64Shl [x, y] = v ++ "idris_b64Shl(vm, " ++ creg x ++ "," ++ creg y ++ ")"
413doOp v LB64LShr [x, y] = v ++ "idris_b64Shr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
414doOp v LB64AShr [x, y] = v ++ "idris_b64AShr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
415doOp v LB64And [x, y] = v ++ "idris_b64And(vm, " ++ creg x ++ "," ++ creg y ++ ")"
416doOp v LB64Or [x, y] = v ++ "idris_b64Or(vm, " ++ creg x ++ "," ++ creg y ++ ")"
417doOp v LB64Xor [x, y] = v ++ "idris_b64Xor(vm, " ++ creg x ++ "," ++ creg y ++ ")"
418doOp v LB64Compl [x] = v ++ "idris_b64Compl(vm, " ++ creg x ++ ")"
420doOp v LB64Plus [x, y] =
421 v ++ "idris_b64Plus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
422doOp v LB64Minus [x, y] =
423 v ++ "idris_b64Minus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
424doOp v LB64Times [x, y] =
425 v ++ "idris_b64Times(vm, " ++ creg x ++ "," ++ creg y ++ ")"
426doOp v LB64UDiv [x, y] =
427 v ++ "idris_b64UDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
428doOp v LB64SDiv [x, y] =
429 v ++ "idris_b64SDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
430doOp v LB64URem [x, y] =
431 v ++ "idris_b64URem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
432doOp v LB64SRem [x, y] =
433 v ++ "idris_b64SRem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
435doOp v LB64T8 [x] = v ++ "idris_b64T8(vm, " ++ creg x ++ ")"
436doOp v LB64T16 [x] = v ++ "idris_b64T16(vm, " ++ creg x ++ ")"
437doOp v LB64T32 [x] = v ++ "idris_b64T32(vm, " ++ creg x ++ ")"
439doOp v LFExp [x] = v ++ "MKFLOAT(exp(GETFLOAT(" ++ creg x ++ ")))"
440doOp v LFLog [x] = v ++ "MKFLOAT(log(GETFLOAT(" ++ creg x ++ ")))"
441doOp v LFSin [x] = v ++ "MKFLOAT(sin(GETFLOAT(" ++ creg x ++ ")))"
442doOp v LFCos [x] = v ++ "MKFLOAT(cos(GETFLOAT(" ++ creg x ++ ")))"
443doOp v LFTan [x] = v ++ "MKFLOAT(tan(GETFLOAT(" ++ creg x ++ ")))"
444doOp v LFASin [x] = v ++ "MKFLOAT(asin(GETFLOAT(" ++ creg x ++ ")))"
445doOp v LFACos [x] = v ++ "MKFLOAT(acos(GETFLOAT(" ++ creg x ++ ")))"
446doOp v LFATan [x] = v ++ "MKFLOAT(atan(GETFLOAT(" ++ creg x ++ ")))"
447doOp v LFSqrt [x] = v ++ "MKFLOAT(floor(GETFLOAT(" ++ creg x ++ ")))"
448doOp v LFFloor [x] = v ++ "MKFLOAT(ceil(GETFLOAT(" ++ creg x ++ ")))"
449doOp v LFCeil [x] = v ++ "MKFLOAT(sqrt(GETFLOAT(" ++ creg x ++ ")))"
451doOp v LStrHead [x] = v ++ "idris_strHead(vm, " ++ creg x ++ ")"
452doOp v LStrTail [x] = v ++ "idris_strTail(vm, " ++ creg x ++ ")"
453doOp v LStrCons [x, y] = v ++ "idris_strCons(vm, " ++ creg x ++ "," ++ creg y ++ ")"
454doOp v LStrIndex [x, y] = v ++ "idris_strIndex(vm, " ++ creg x ++ "," ++ creg y ++ ")"
455doOp v LStrRev [x] = v ++ "idris_strRev(vm, " ++ creg x ++ ")"
457doOp v LStdIn [] = v ++ "MKPTR(vm, stdin)"
458doOp v LStdOut [] = v ++ "MKPTR(vm, stdout)"
459doOp v LStdErr [] = v ++ "MKPTR(vm, stderr)"
461doOp v LFork [x] = v ++ "MKPTR(vm, vmThread(vm, " ++ cname (MN 0 "EVAL") ++ ", " ++ creg x ++ "))"
462doOp v LPar [x] = v ++ creg x -- "MKPTR(vm, vmThread(vm, " ++ cname (MN 0 "EVAL") ++ ", " ++ creg x ++ "))"
463doOp v LVMPtr [] = v ++ "MKPTR(vm, vm)"
464doOp v LChInt args = v ++ creg (last args)
465doOp v LIntCh args = v ++ creg (last args)
466doOp v LNoOp args = v ++ creg (last args)
467doOp _ op _ = "FAIL /* " ++ show op ++ " */"