-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Java .class files assembler/disassembler -- -- This package declares data types for Java .class files format and -- functions to assemble/disassemble Java bytecode. See dump-class.hs, -- rebuild-class.hs, TestGen.hs for examples of usage. @package hs-java @version 0.2 module JVM.Exceptions data NoItemInPool NoItemInPool :: a -> NoItemInPool force :: String -> EM AnyException a -> a instance Typeable NoItemInPool instance Show NoItemInPool instance Exception NoItemInPool -- | This module declares (low-level) data types for Java .class files -- structures, and Binary instances to read/write them. module JVM.ClassFile -- | Any (class field method/ ...) attribute format. Some formats -- specify special formats for attributeValue. data Attribute Attribute :: Word16 -> Word32 -> ByteString -> Attribute attributeName :: Attribute -> Word16 attributeLength :: Attribute -> Word32 attributeValue :: Attribute -> ByteString -- | Field signature format data FieldType -- | B SignedByte :: FieldType -- | C CharByte :: FieldType -- | D DoubleType :: FieldType -- | F FloatType :: FieldType -- | I IntType :: FieldType -- | J LongInt :: FieldType -- | S ShortInt :: FieldType -- | Z BoolType :: FieldType -- | L {class name} ObjectType :: String -> FieldType -- |
--   [{type}
--   
Array :: (Maybe Int) -> FieldType -> FieldType -- | Class field signature type FieldSignature = FieldType -- | Class method argument signature data MethodSignature MethodSignature :: [ArgumentSignature] -> ReturnSignature -> MethodSignature -- | Return value signature data ReturnSignature Returns :: FieldType -> ReturnSignature ReturnsVoid :: ReturnSignature -- | Method argument signature type ArgumentSignature = FieldType -- | Constant pool type Pool stage = Map Word16 (Constant stage) -- | Class method format data Method stage Method :: AccessFlags stage -> Link stage ByteString -> Link stage MethodSignature -> Word16 -> Attributes stage -> Method stage methodAccessFlags :: Method stage -> AccessFlags stage methodName :: Method stage -> Link stage ByteString methodSignature :: Method stage -> Link stage MethodSignature methodAttributesCount :: Method stage -> Word16 methodAttributes :: Method stage -> Attributes stage -- | Class field format data Field stage Field :: AccessFlags stage -> Link stage ByteString -> Link stage FieldSignature -> Word16 -> Attributes stage -> Field stage fieldAccessFlags :: Field stage -> AccessFlags stage fieldName :: Field stage -> Link stage ByteString fieldSignature :: Field stage -> Link stage FieldSignature fieldAttributesCount :: Field stage -> Word16 fieldAttributes :: Field stage -> Attributes stage -- | Generic .class file format data Class stage Class :: Word32 -> Word16 -> Word16 -> Word16 -> Pool stage -> AccessFlags stage -> Link stage ByteString -> Link stage ByteString -> Word16 -> [Link stage ByteString] -> Word16 -> [Field stage] -> Word16 -> [Method stage] -> Word16 -> Attributes stage -> Class stage -- | Magic value: 0xCAFEBABE magic :: Class stage -> Word32 minorVersion :: Class stage -> Word16 majorVersion :: Class stage -> Word16 -- | Number of items in constants pool constsPoolSize :: Class stage -> Word16 -- | Constants pool itself constsPool :: Class stage -> Pool stage -- | See JVM.Types.AccessFlag accessFlags :: Class stage -> AccessFlags stage -- | Constants pool item index for this class thisClass :: Class stage -> Link stage ByteString -- | superClass :: Class stage -> Link stage ByteString -- | Number of implemented interfaces interfacesCount :: Class stage -> Word16 -- | Constants pool item indexes for implemented interfaces interfaces :: Class stage -> [Link stage ByteString] -- | Number of class fileds classFieldsCount :: Class stage -> Word16 -- | Class fields classFields :: Class stage -> [Field stage] -- | Number of class methods classMethodsCount :: Class stage -> Word16 -- | Class methods classMethods :: Class stage -> [Method stage] -- | Number of class attributes classAttributesCount :: Class stage -> Word16 -- | Class attributes classAttributes :: Class stage -> Attributes stage -- | Constant pool item data Constant stage CClass :: (Link stage ByteString) -> Constant stage CField :: Link stage ByteString -> Link stage (NameType Field) -> Constant stage refClass :: Constant stage -> Link stage ByteString fieldNameType :: Constant stage -> Link stage (NameType Field) CMethod :: Link stage ByteString -> Link stage (NameType Method) -> Constant stage refClass :: Constant stage -> Link stage ByteString nameType :: Constant stage -> Link stage (NameType Method) CIfaceMethod :: Link stage ByteString -> Link stage (NameType Method) -> Constant stage refClass :: Constant stage -> Link stage ByteString nameType :: Constant stage -> Link stage (NameType Method) CString :: (Link stage ByteString) -> Constant stage CInteger :: Word32 -> Constant stage CFloat :: Float -> Constant stage CLong :: Integer -> Constant stage CDouble :: Double -> Constant stage CNameType :: (Link stage ByteString) -> (Link stage ByteString) -> Constant stage CUTF8 :: ByteString -> Constant stage getString :: Constant stage -> ByteString CUnicode :: ByteString -> Constant stage getString :: Constant stage -> ByteString data Pointers data Resolved -- | Name and signature pair. Used for methods and fields. data NameType a NameType :: ByteString -> Signature a -> NameType a ntName :: NameType a -> ByteString ntSignature :: NameType a -> Signature a class HasSignature a where { type family Signature a; } class HasAttributes a attributes :: HasAttributes a => a stage -> Attributes stage -- | Access flags. Used for classess, methods, variables. data AccessFlag -- | 0x0001 Visible for all ACC_PUBLIC :: AccessFlag -- | 0x0002 Visible only for defined class ACC_PRIVATE :: AccessFlag -- | 0x0004 Visible only for subclasses ACC_PROTECTED :: AccessFlag -- | 0x0008 Static method or variable ACC_STATIC :: AccessFlag -- | 0x0010 No further subclassing or assignments ACC_FINAL :: AccessFlag -- | 0x0020 Uses monitors ACC_SYNCHRONIZED :: AccessFlag -- | 0x0040 Could not be cached ACC_VOLATILE :: AccessFlag -- | 0x0080 ACC_TRANSIENT :: AccessFlag -- | 0x0100 Implemented in other language ACC_NATIVE :: AccessFlag -- | 0x0200 Class is interface ACC_INTERFACE :: AccessFlag -- | 0x0400 ACC_ABSTRACT :: AccessFlag className :: Constant Resolved -> ByteString apsize :: Attributes Pointers -> Int arsize :: Attributes Resolved -> Int arlist :: Attributes Resolved -> [(ByteString, ByteString)] instance Show (Method Resolved) instance Show (Method Pointers) instance Eq (Method Resolved) instance Eq (Method Pointers) instance Show (Field Resolved) instance Show (Field Pointers) instance Eq (Field Resolved) instance Eq (Field Pointers) instance Show (Constant Pointers) instance Eq (Constant Resolved) instance Eq (Constant Pointers) instance Eq (Signature a) => Eq (NameType a) instance Eq (Attributes Resolved) instance Show (Attributes Resolved) instance Eq AccessFlag instance Show AccessFlag instance Ord AccessFlag instance Enum AccessFlag instance Eq FieldType instance Eq ReturnSignature instance Eq MethodSignature instance Eq Attribute instance Show Attribute instance Eq (Attributes Pointers) instance Show (Attributes Pointers) instance HasAttributes Method instance HasAttributes Field instance HasAttributes Class instance Binary Attribute instance Binary (Method Pointers) instance Binary (Field Pointers) instance Binary (Constant Pointers) instance Binary MethodSignature instance Show MethodSignature instance Binary ReturnSignature instance Show ReturnSignature instance Binary FieldType instance Show FieldType instance Binary (Class Pointers) instance Show (Constant Resolved) instance Binary (Signature a) => Binary (NameType a) instance Show (Signature a) => Show (NameType a) instance HasSignature Method instance HasSignature Field -- | This module declares data type for JVM instructions, and BinaryState -- instances to read/write them. module JVM.Assembler -- | JVM instruction set data Instruction -- | 0 NOP :: Instruction -- | 1 ACONST_NULL :: Instruction -- | 2 ICONST_M1 :: Instruction -- | 3 ICONST_0 :: Instruction -- | 4 ICONST_1 :: Instruction -- | 5 ICONST_2 :: Instruction -- | 6 ICONST_3 :: Instruction -- | 7 ICONST_4 :: Instruction -- | 8 ICONST_5 :: Instruction -- | 9 LCONST_0 :: Instruction -- | 10 LCONST_1 :: Instruction -- | 11 FCONST_0 :: Instruction -- | 12 FCONST_1 :: Instruction -- | 13 FCONST_2 :: Instruction -- | 14 DCONST_0 :: Instruction -- | 15 DCONST_1 :: Instruction -- | 16 BIPUSH :: Word8 -> Instruction -- | 17 SIPUSH :: Word16 -> Instruction -- | 18 LDC1 :: Word8 -> Instruction -- | 19 LDC2 :: Word16 -> Instruction -- | 20 LDC2W :: Word16 -> Instruction -- | 21 ILOAD :: Word8 -> Instruction -- | 22 LLOAD :: Word8 -> Instruction -- | 23 FLOAD :: Word8 -> Instruction -- | 24 DLOAD :: Word8 -> Instruction -- | 25 ALOAD :: Word8 -> Instruction -- | 26, 27, 28, 29 ILOAD_ :: IMM -> Instruction -- | 30, 31, 32, 33 LLOAD_ :: IMM -> Instruction -- | 34, 35, 36, 37 FLOAD_ :: IMM -> Instruction -- | 38, 39, 40, 41 DLOAD_ :: IMM -> Instruction -- | 42, 43, 44, 45 ALOAD_ :: IMM -> Instruction -- | 46 IALOAD :: Instruction -- | 47 LALOAD :: Instruction -- | 48 FALOAD :: Instruction -- | 49 DALOAD :: Instruction -- | 50 AALOAD :: Instruction -- | 51 BALOAD :: Instruction -- | 52 CALOAD :: Instruction -- | 53 SALOAD :: Instruction -- | 54 ISTORE :: Word8 -> Instruction -- | 55 LSTORE :: Word8 -> Instruction -- | 56 FSTORE :: Word8 -> Instruction -- | 57 DSTORE :: Word8 -> Instruction -- | 58 ASTORE :: Word8 -> Instruction -- | 59, 60, 61, 62 ISTORE_ :: IMM -> Instruction -- | 63, 64, 65, 66 LSTORE_ :: IMM -> Instruction -- | 67, 68, 69, 70 FSTORE_ :: IMM -> Instruction -- | 71, 72, 73, 74 DSTORE_ :: IMM -> Instruction -- | 75, 76, 77, 78 ASTORE_ :: IMM -> Instruction -- | 79 IASTORE :: Instruction -- | 80 LASTORE :: Instruction -- | 81 FASTORE :: Instruction -- | 82 DASTORE :: Instruction -- | 83 AASTORE :: Instruction -- | 84 BASTORE :: Instruction -- | 85 CASTORE :: Instruction -- | 86 SASTORE :: Instruction -- | 87 POP :: Instruction -- | 88 POP2 :: Instruction -- | 89 DUP :: Instruction -- | 90 DUP_X1 :: Instruction -- | 91 DUP_X2 :: Instruction -- | 92 DUP2 :: Instruction -- | 93 DUP2_X1 :: Instruction -- | 94 DUP2_X2 :: Instruction -- | 95 SWAP :: Instruction -- | 96 IADD :: Instruction -- | 97 LADD :: Instruction -- | 98 FADD :: Instruction -- | 99 DADD :: Instruction -- | 100 ISUB :: Instruction -- | 101 LSUB :: Instruction -- | 102 FSUB :: Instruction -- | 103 DSUB :: Instruction -- | 104 IMUL :: Instruction -- | 105 LMUL :: Instruction -- | 106 FMUL :: Instruction -- | 107 DMUL :: Instruction -- | 108 IDIV :: Instruction -- | 109 LDIV :: Instruction -- | 110 FDIV :: Instruction -- | 111 DDIV :: Instruction -- | 112 IREM :: Instruction -- | 113 LREM :: Instruction -- | 114 FREM :: Instruction -- | 115 DREM :: Instruction -- | 116 INEG :: Instruction -- | 117 LNEG :: Instruction -- | 118 FNEG :: Instruction -- | 119 DNEG :: Instruction -- | 120 ISHL :: Instruction -- | 121 LSHL :: Instruction -- | 122 ISHR :: Instruction -- | 123 LSHR :: Instruction -- | 124 IUSHR :: Instruction -- | 125 LUSHR :: Instruction -- | 126 IAND :: Instruction -- | 127 LAND :: Instruction -- | 128 IOR :: Instruction -- | 129 LOR :: Instruction -- | 130 IXOR :: Instruction -- | 131 LXOR :: Instruction -- | 132 IINC :: Word8 -> Word8 -> Instruction -- | 133 I2L :: Instruction -- | 134 I2F :: Instruction -- | 135 I2D :: Instruction -- | 136 L2I :: Instruction -- | 137 L2F :: Instruction -- | 138 L2D :: Instruction -- | 139 F2I :: Instruction -- | 140 F2L :: Instruction -- | 141 F2D :: Instruction -- | 142 D2I :: Instruction -- | 143 D2L :: Instruction -- | 144 D2F :: Instruction -- | 145 I2B :: Instruction -- | 146 I2C :: Instruction -- | 147 I2S :: Instruction -- | 148 LCMP :: Instruction -- | 149, 150 FCMP :: CMP -> Instruction -- | 151, 152 DCMP :: CMP -> Instruction -- | 153, 154, 155, 156, 157, 158 IF :: CMP -> Instruction -- | 159, 160, 161, 162, 163, 164 IF_ICMP :: CMP -> Word16 -> Instruction -- | 165, 166 IF_ACMP :: CMP -> Word16 -> Instruction -- | 167 GOTO :: Instruction -- | 168 JSR :: Word16 -> Instruction -- | 169 RET :: Instruction -- | 170 TABLESWITCH :: Word32 -> Word32 -> Word32 -> [Word32] -> Instruction -- | 171 LOOKUPSWITCH :: Word32 -> Word32 -> [(Word32, Word32)] -> Instruction -- | 172 IRETURN :: Instruction -- | 173 LRETURN :: Instruction -- | 174 FRETURN :: Instruction -- | 175 DRETURN :: Instruction -- | 177 RETURN :: Instruction -- | 178 GETSTATIC :: Word16 -> Instruction -- | 179 PUTSTATIC :: Word16 -> Instruction -- | 180 GETFIELD :: Word16 -> Instruction -- | 181 PUTFIELD :: Word16 -> Instruction -- | 182 INVOKEVIRTUAL :: Word16 -> Instruction -- | 183 INVOKESPECIAL :: Word16 -> Instruction -- | 184 INVOKESTATIC :: Word16 -> Instruction -- | 185 INVOKEINTERFACE :: Word16 -> Word8 -> Instruction -- | 187 NEW :: Word16 -> Instruction -- | 188, see ArrayType NEWARRAY :: Word8 -> Instruction -- | 189 ANEWARRAY :: Word16 -> Instruction -- | 190 ARRAYLENGTH :: Instruction -- | 191 ATHROW :: Instruction -- | 192 CHECKCAST :: Word16 -> Instruction -- | 193 INSTANCEOF :: Word16 -> Instruction -- | 194 MONITORENTER :: Instruction -- | 195 MONITOREXIT :: Instruction -- | 196 WIDE :: Word8 -> Instruction -> Instruction -- | 197 MULTINANEWARRAY :: Word16 -> Word8 -> Instruction -- | 198 IFNULL :: Word16 -> Instruction -- | 199 IFNONNULL :: Word16 -> Instruction -- | 200 GOTO_W :: Word32 -> Instruction -- | 201 JSR_W :: Word32 -> Instruction -- | JVM array type (primitive types) data ArrayType -- | 4 T_BOOLEAN :: ArrayType -- | 5 T_CHAR :: ArrayType -- | 6 T_FLOAT :: ArrayType -- | 7 T_DOUBLE :: ArrayType -- | 8 T_BYTE :: ArrayType -- | 9 T_SHORT :: ArrayType -- | 10 T_INT :: ArrayType -- | 11 T_LONG :: ArrayType -- | Exception descriptor data CodeException CodeException :: Word16 -> Word16 -> Word16 -> Word16 -> CodeException eStartPC :: CodeException -> Word16 eEndPC :: CodeException -> Word16 eHandlerPC :: CodeException -> Word16 eCatchType :: CodeException -> Word16 -- | Format of Code method attribute. data Code Code :: Word16 -> Word16 -> Word32 -> [Instruction] -> Word16 -> [CodeException] -> Word16 -> Attributes Pointers -> Code codeStackSize :: Code -> Word16 codeMaxLocals :: Code -> Word16 codeLength :: Code -> Word32 codeInstructions :: Code -> [Instruction] codeExceptionsN :: Code -> Word16 codeExceptions :: Code -> [CodeException] codeAttrsN :: Code -> Word16 codeAttributes :: Code -> Attributes Pointers -- | Immediate constant. Corresponding value will be added to base opcode. data IMM -- | 0 I0 :: IMM -- | 1 I1 :: IMM -- | 2 I2 :: IMM -- | 3 I3 :: IMM -- | Comparation operation type. Not all CMP instructions support all -- operations. data CMP C_EQ :: CMP C_NE :: CMP C_LT :: CMP C_GE :: CMP C_GT :: CMP C_LE :: CMP atype2byte :: ArrayType -> Word8 encodeInstructions :: [Instruction] -> ByteString -- | Encode Java method encodeMethod :: Code -> ByteString -- | Decode Java method decodeMethod :: ByteString -> Code instance Eq IMM instance Ord IMM instance Enum IMM instance Show IMM instance Eq CMP instance Ord CMP instance Enum CMP instance Show CMP instance Eq CodeException instance Show CodeException instance Eq Instruction instance Show Instruction instance Eq Code instance Show Code instance Eq ArrayType instance Show ArrayType instance Enum ArrayType instance BinaryState Integer Instruction instance BinaryState Integer ArrayType instance BinaryState Integer Code instance BinaryState Integer Attribute instance BinaryState Integer CodeException -- | This module declares `high-level' data types for Java classes, methods -- etc. module JVM.Common toCharList :: ByteString -> [Int] poolSize :: Pool stage -> Int (!) :: Ord k => Map k a -> k -> a showListIx :: Show a => [a] -> String byteString :: Binary t => t -> ByteString instance IsString ByteString -- | Functions to convert from low-level .class format representation and -- high-level Java classes, methods etc representation module JVM.Converter -- | Parse .class file data parseClass :: ByteString -> Class Resolved -- | Parse class data from file parseClassFile :: FilePath -> IO (Class Resolved) convertClass :: Class Pointers -> Class Resolved classFile :: Class Resolved -> Class Pointers encodeClass :: (Class Resolved) -> ByteString -- | Try to get class method by name methodByName :: Class Resolved -> ByteString -> Maybe (Method Resolved) -- | Try to get object attribute by name attrByName :: HasAttributes a => a Resolved -> ByteString -> Maybe ByteString -- | Try to get Code for class method (no Code for interface methods) methodCode :: Class Resolved -> ByteString -> Maybe ByteString module JVM.Builder.Monad data GState GState :: [Instruction] -> Pool Resolved -> [Method Resolved] -> Maybe (Method Resolved) -> GState generated :: GState -> [Instruction] currentPool :: GState -> Pool Resolved doneMethods :: GState -> [Method Resolved] currentMethod :: GState -> Maybe (Method Resolved) type Generate a = State GState a appendPool :: Constant Resolved -> Pool Resolved -> (Pool Resolved, Word16) addItem :: Constant Resolved -> Generate Word16 lookupPool :: Constant Resolved -> Pool Resolved -> Maybe Word16 addNT :: Binary (Signature a) => NameType a -> Generate Word16 addSig :: MethodSignature -> Generate Word16 addToPool :: Constant Resolved -> Generate Word16 putInstruction :: Instruction -> Generate () i0 :: Instruction -> Generate () i1 :: (Word16 -> Instruction) -> Constant Resolved -> Generate () i8 :: (Word8 -> Instruction) -> Constant Resolved -> Generate () startMethod :: [AccessFlag] -> ByteString -> MethodSignature -> Generate () endMethod :: Generate () newMethod :: [AccessFlag] -> ByteString -> [ArgumentSignature] -> ReturnSignature -> Generate () -> Generate (NameType Method) genCode :: GState -> Code initClass :: ByteString -> Generate Word16 generate :: ByteString -> Generate () -> Class Resolved instance Eq GState instance Show GState module JVM.Builder.Instructions module JVM.Builder arrayOf :: FieldType -> FieldType sizedArray :: Int -> FieldType -> FieldType module JVM.Dump dumpClass :: Class Resolved -> IO () module Java.Lang object :: IsString s => s string :: IsString s => s integer :: IsString s => s system :: IsString s => s objectInit :: NameType Method valueOfInteger :: NameType Method module Java.IO printStream :: IsString s => s println :: NameType Method out :: NameType Field printf :: NameType Method