1 -- | This module exports shortcuts for some of JVM instructions (which are defined in JVM.Assembler).
2 -- These functions get Constants, put them into constants pool and generate instruction using index
3 -- of constant in the pool.
4 module JVM.Builder.Instructions where
7 import qualified Data.ByteString.Lazy as B
11 import JVM.Builder.Monad
15 aconst_null :: Generate ()
16 aconst_null = i0 ACONST_NULL
17 iconst_m1 :: Generate ()
18 iconst_m1 = i0 ICONST_M1
19 iconst_0 :: Generate ()
20 iconst_0 = i0 ICONST_0
21 iconst_1 :: Generate ()
22 iconst_1 = i0 ICONST_1
23 iconst_2 :: Generate ()
24 iconst_2 = i0 ICONST_2
25 iconst_3 :: Generate ()
26 iconst_3 = i0 ICONST_3
27 iconst_4 :: Generate ()
28 iconst_4 = i0 ICONST_4
29 iconst_5 :: Generate ()
30 iconst_5 = i0 ICONST_5
31 lconst_0 :: Generate ()
32 lconst_0 = i0 LCONST_0
33 lconst_1 :: Generate ()
34 lconst_1 = i0 LCONST_1
35 fconst_0 :: Generate ()
36 fconst_0 = i0 FCONST_0
37 fconst_1 :: Generate ()
38 fconst_1 = i0 FCONST_1
39 fconst_2 :: Generate ()
40 fconst_2 = i0 FCONST_2
41 dconst_0 :: Generate ()
42 dconst_0 = i0 DCONST_0
43 dconst_1 :: Generate ()
44 dconst_1 = i0 DCONST_1
46 bipush :: Word8 -> Generate ()
47 bipush x = i0 (BIPUSH x)
48 sipush :: Word16 -> Generate ()
49 sipush x = i0 (SIPUSH x)
51 ldc1 :: Constant Direct -> Generate ()
53 ldc2 :: Constant Direct -> Generate ()
55 ldc2w :: Constant Direct -> Generate ()
57 iload :: Constant Direct -> Generate ()
59 lload :: Constant Direct -> Generate ()
61 fload :: Constant Direct -> Generate ()
63 dload :: Constant Direct -> Generate ()
65 aload :: Constant Direct -> Generate ()
68 iload_ :: IMM -> Generate ()
69 iload_ x = i0 (ILOAD_ x)
70 lload_ :: IMM -> Generate ()
71 lload_ x = i0 (LLOAD_ x)
72 fload_ :: IMM -> Generate ()
73 fload_ x = i0 (FLOAD_ x)
74 dload_ :: IMM -> Generate ()
75 dload_ x = i0 (DLOAD_ x)
76 aload_ :: IMM -> Generate ()
77 aload_ x = i0 (ALOAD_ x)
94 istore :: Constant Direct -> Generate ()
95 istore x = i8 ISTORE x
96 lstore :: Constant Direct -> Generate ()
97 lstore x = i8 LSTORE x
98 fstore :: Constant Direct -> Generate ()
99 fstore x = i8 FSTORE x
100 dstore :: Constant Direct -> Generate ()
101 dstore x = i8 DSTORE x
102 astore :: Constant Direct -> Generate ()
103 astore x = i8 ASTORE x
105 istore_ :: Word8 -> Generate ()
106 istore_ x = i0 (ISTORE x)
107 lstore_ :: Word8 -> Generate ()
108 lstore_ x = i0 (LSTORE x)
109 fstore_ :: Word8 -> Generate ()
110 fstore_ x = i0 (FSTORE x)
111 dstore_ :: Word8 -> Generate ()
112 dstore_ x = i0 (DSTORE x)
113 astore_ :: Word8 -> Generate ()
114 astore_ x = i0 (ASTORE x)
116 iastore :: Generate ()
118 lastore :: Generate ()
120 fastore :: Generate ()
122 dastore :: Generate ()
124 aastore :: Generate ()
126 bastore :: Generate ()
128 castore :: Generate ()
130 sastore :: Generate ()
139 dup_x1 :: Generate ()
141 dup_x2 :: Generate ()
145 dup2_x1 :: Generate ()
147 dup2_x2 :: Generate ()
224 iinc :: Word8 -> Word8 -> Generate ()
225 iinc x y = i0 (IINC x y)
260 -- | Wide instruction
261 wide :: (Word8 -> Instruction) -> Constant Direct -> Generate ()
264 let ix0 = fromIntegral (ix `div` 0x100) :: Word8
265 ix1 = fromIntegral (ix `mod` 0x100) :: Word8
266 i0 (WIDE ix0 $ fn ix1)
268 new :: B.ByteString -> Generate ()
272 newArray :: ArrayType -> Generate ()
274 i0 (NEWARRAY $ atype2byte t)
276 allocNewArray :: B.ByteString -> Generate ()
278 i1 ANEWARRAY (CClass cls)
280 invokeVirtual :: B.ByteString -> NameType Method -> Generate ()
281 invokeVirtual cls sig =
282 i1 INVOKEVIRTUAL (CMethod cls sig)
284 invokeStatic :: B.ByteString -> NameType Method -> Generate ()
285 invokeStatic cls sig =
286 i1 INVOKESTATIC (CMethod cls sig)
288 invokeSpecial :: B.ByteString -> NameType Method -> Generate ()
289 invokeSpecial cls sig =
290 i1 INVOKESPECIAL (CMethod cls sig)
292 getStaticField :: B.ByteString -> NameType Field -> Generate ()
293 getStaticField cls sig =
294 i1 GETSTATIC (CField cls sig)
296 loadString :: B.ByteString -> Generate ()
298 i8 LDC1 (CString str)
300 allocArray :: B.ByteString -> Generate ()
302 i1 ANEWARRAY (CClass cls)