-- 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.3.4 module Java.META.Types type Section = Map String String type META = [Section] module Java.META.Parser parseMeta :: String -> Either ParseError META parseMetaFile :: FilePath -> IO (Either ParseError META) module Java.META.Spec class MetaSpec s where loadOtherSection s _ = s loadFirstSection :: MetaSpec s => Section -> s loadOtherSection :: MetaSpec s => s -> Section -> s storeMeta :: MetaSpec s => s -> META loadSpec :: MetaSpec s => META -> s lookupList :: String -> Maybe String -> [(String, String)] bool2string :: Bool -> String string2bool :: String -> Bool -- | This module declares functions and data types for JAR meta-information -- classes, such as MANIFEST.MF etc. module Java.META -- | JAR MANIFEST.MF data Manifest Manifest :: String -> String -> Bool -> Maybe String -> [String] -> Maybe String -> [ManifestEntry] -> Manifest manifestVersion :: Manifest -> String createdBy :: Manifest -> String sealed :: Manifest -> Bool signatureVersion :: Manifest -> Maybe String classPath :: Manifest -> [String] mainClass :: Manifest -> Maybe String manifestEntries :: Manifest -> [ManifestEntry] -- | Manifest entry data ManifestEntry ManifestEntry :: String -> Bool -> Maybe String -> Bool -> ManifestEntry meName :: ManifestEntry -> String meSealed :: ManifestEntry -> Bool meContentType :: ManifestEntry -> Maybe String meBean :: ManifestEntry -> Bool instance Eq ManifestEntry instance Show ManifestEntry instance Eq Manifest instance Show Manifest instance MetaSpec Manifest -- | 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 -- | File stage data File -- | Direct representation stage data Direct -- | Constant pool type Pool stage = Map Word16 (Constant stage) -- | Link to some object -- | 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 stage))) -> Constant stage CMethod :: (Link stage ByteString) -> (Link stage (NameType (Method stage))) -> Constant stage CIfaceMethod :: (Link stage ByteString) -> (Link stage (NameType (Method stage))) -> Constant stage CString :: (Link stage ByteString) -> Constant stage CInteger :: Word32 -> Constant stage CFloat :: Float -> Constant stage CLong :: Word64 -> 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 -- | 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 -- | Object (class, method, field …) access flags -- | Object (class, method, field) attributes -- | Default (empty) class file definition. defaultClass :: (Default (AccessFlags stage), Default (Link stage ByteString), Default (Attributes stage)) => Class stage -- | Fields and methods have signatures. class (Binary (Signature a), Show (Signature a), Eq (Signature a)) => HasSignature a where type family Signature a class HasAttributes a attributes :: HasAttributes a => a stage -> Attributes stage -- | 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 fieldNameType :: Field Direct -> NameType (Field Direct) methodNameType :: Method Direct -> NameType (Method Direct) lookupField :: ByteString -> Class Direct -> Maybe (Field Direct) lookupMethod :: ByteString -> Class Direct -> Maybe (Method Direct) long :: Constant stage -> Bool toString :: ByteString -> String -- | Name of the CClass. Error on any other constant. className :: Constant Direct -> ByteString -- | Size of attributes set at File stage apsize :: Attributes File -> Int -- | Size of attributes set at Direct stage arsize :: Attributes Direct -> Int -- | Associative list of attributes at Direct stage arlist :: Attributes Direct -> [(ByteString, ByteString)] instance Show (Method Direct) instance Show (Method File) instance Eq (Method Direct) instance Eq (Method File) instance Show (Field Direct) instance Show (Field File) instance Eq (Field Direct) instance Eq (Field File) instance Show (Constant File) instance Eq (Constant Direct) instance Eq (Constant File) instance Show (Class Direct) instance Show (Class File) instance Eq (Class Direct) instance Eq (Class File) instance HasSignature a => Eq (NameType a) instance Eq AccessFlag instance Show AccessFlag instance Ord AccessFlag instance Enum AccessFlag instance Eq FieldType instance Ord FieldType instance Eq ReturnSignature instance Ord ReturnSignature instance Eq MethodSignature instance Ord MethodSignature instance Eq Attribute instance Show Attribute instance Eq (Attributes Direct) instance Show (Attributes Direct) instance Eq (Attributes File) instance Show (Attributes File) instance HasAttributes Method instance HasAttributes Field instance HasAttributes Class instance Binary Attribute instance Binary (Method File) instance Binary (Field File) instance Binary MethodSignature instance Show MethodSignature instance Binary ReturnSignature instance Show ReturnSignature instance Binary FieldType instance Show FieldType instance Binary (Class File) instance Show (Constant Direct) instance HasSignature a => Binary (NameType a) instance HasSignature a => Show (NameType a) instance HasSignature (Method Direct) instance HasSignature (Field Direct) instance Default (Attributes Direct) instance Default (Attributes File) -- | This module declares data type for JVM instructions, and BinaryState -- instances to read/write them. module JVM.Assembler -- | JVM instruction set. For comments, see JVM specification. 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 -> Word16 -> Instruction -- | 159, 160, 161, 162, 163, 164 IF_ICMP :: CMP -> Word16 -> Instruction -- | 165, 166 IF_ACMP :: CMP -> Word16 -> Instruction -- | 167 GOTO :: Word16 -> Instruction -- | 168 JSR :: Word16 -> Instruction -- | 169 RET :: Instruction -- | 170 TABLESWITCH :: Word8 -> Word32 -> Word32 -> Word32 -> [Word32] -> Instruction -- | 171 LOOKUPSWITCH :: Word8 -> Word32 -> Word32 -> [(Word32, Word32)] -> Instruction -- | 172 IRETURN :: Instruction -- | 173 LRETURN :: Instruction -- | 174 FRETURN :: Instruction -- | 175 DRETURN :: Instruction -- | 176 ARETURN :: 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 File -> 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 File -- | 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 -- | Encode list of instructions 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 module JVM.Exceptions data NoItemInPool NoItemInPool :: a -> NoItemInPool data UnexpectedEndMethod UnexpectedEndMethod :: UnexpectedEndMethod data ENotLoaded ClassFileNotLoaded :: FilePath -> ENotLoaded JARNotLoaded :: FilePath -> String -> ENotLoaded data ENotFound ClassNotFound :: String -> ENotFound FieldNotFound :: String -> ByteString -> ENotFound MethodNotFound :: String -> ByteString -> ENotFound force :: String -> EM AnyException a -> a instance Typeable NoItemInPool instance Typeable UnexpectedEndMethod instance Typeable ENotLoaded instance Typeable ENotFound instance Exception ENotFound instance Show ENotFound instance Exception ENotLoaded instance Show ENotLoaded instance Exception UnexpectedEndMethod instance Show UnexpectedEndMethod instance Show NoItemInPool instance Exception NoItemInPool module Java.ClassPath.Types -- | Directories tree data Tree a Directory :: FilePath -> [Tree a] -> Tree a File :: a -> Tree a -- | ClassPath entry data CPEntry -- | Not loaded .class file NotLoaded :: FilePath -> CPEntry -- | Class loaded from .class file Loaded :: FilePath -> (Class Direct) -> CPEntry -- | Not loaded .jar file NotLoadedJAR :: FilePath -> FilePath -> CPEntry -- | Class loaded from .jar file LoadedJAR :: FilePath -> (Class Direct) -> CPEntry -- | ClassPath monad type ClassPath a = StateT [Tree CPEntry] IO a instance Eq a => Eq (Tree a) instance Eq CPEntry instance Show CPEntry instance Show a => Show (Tree a) module Java.ClassPath.Common -- | map on forest mapF :: (t -> a) -> [Tree t] -> [Tree a] -- | mapM on forest mapFM :: (Monad m, Functor m) => (t -> m a) -> [Tree t] -> m [Tree a] -- | mapM on tree mapTM :: (Monad m, Functor m) => (t -> m a) -> Tree t -> m (Tree a) mapFMF :: (Monad m, Functor m) => (FilePath -> t -> m a) -> [Tree t] -> m [Tree a] mapTMF :: (Monad m, Functor m) => (FilePath -> t -> m a) -> Tree t -> m (Tree a) -- | map on tree mapT :: (t -> a) -> Tree t -> Tree a buildTree :: [FilePath] -> [Tree FilePath] -- | Merge ClassPath forest. For example, [orghaskell, orgjava] -- --> [org/{haskell, java}]. merge :: [Tree CPEntry] -> [Tree CPEntry] -- | Add one ClassPath tree to forest. merge1 :: [Tree CPEntry] -> Tree CPEntry -> [Tree CPEntry] -- | This module declares some commonly used functions and instances. module JVM.Common toCharList :: ByteString -> [Int] poolSize :: Pool stage -> Int (!) :: Ord k => Map k a -> k -> a showListIx :: (Show i, Show a) => [(i, a)] -> String mapFindIndex :: Num k => (v -> Bool) -> Map k v -> Maybe k byteString :: Binary t => t -> ByteString instance Default 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 Direct -- | Parse class data from file parseClassFile :: FilePath -> IO (Class Direct) classFile2Direct :: Class File -> Class Direct classDirect2File :: Class Direct -> Class File encodeClass :: (Class Direct) -> ByteString -- | Try to get class method by name methodByName :: Class Direct -> ByteString -> Maybe (Method Direct) -- | Try to get object attribute by name attrByName :: HasAttributes a => a Direct -> ByteString -> Maybe ByteString -- | Try to get Code for class method (no Code for interface methods) methodCode :: Class Direct -> ByteString -> Maybe ByteString -- | This module defines functions to read Java JAR files. module Java.JAR.Archive readJAREntry :: Enum a => FilePath -> String -> IO (Maybe [a]) -- | Read all entires from JAR file readAllJAR :: FilePath -> IO [Tree CPEntry] -- | Read one class from JAR file readFromJAR :: FilePath -> FilePath -> IO (Class Direct) checkClassTree :: [Tree CPEntry] -> IO [Tree (FilePath, Class Direct)] zipJAR :: [Tree (FilePath, Class Direct)] -> Archive () module Java.ClassPath -- | Append one file to ClassPath forest appendPath :: FilePath -> [Tree CPEntry] -> [Tree CPEntry] -- | Add one directory to current ClassPath addDirectory :: FilePath -> ClassPath () -- | Load one class in current ClassPath loadClass :: String -> ClassPath () -- | Run ClassPath monad runClassPath :: ClassPath a -> IO a -- | Run ClassPath monad and return resulting ClassPath execClassPath :: ClassPath () -> IO [Tree CPEntry] -- | Get one ClassPath entry getEntry :: [Tree CPEntry] -> String -> IO (Maybe CPEntry) module Java.JAR readManifest :: Archive (Maybe Manifest) -- | Read entries from JAR file, using MANIFEST.MF if it exists. readJAR :: FilePath -> IO [Tree CPEntry] -- | Read MainClass Entry of a MANIFEST.MF file readMainClass :: FilePath -> IO (Maybe String) -- | Add given JAR file to ClassPath addJAR :: FilePath -> ClassPath () -- | This module defines Generate[IO] monad, which helps generating JVM -- code and creating Java class constants pool. -- -- Code generation could be done using one of two monads: Generate and -- GenerateIO. Generate monad is pure (simply State monad), while -- GenerateIO is IO-related. In GenerateIO additional actions are -- available, such as setting up ClassPath and loading classes (from -- .class files or JAR archives). module JVM.Builder.Monad -- | Generator state data GState GState :: [Instruction] -> Pool Direct -> Word16 -> [Method Direct] -> Maybe (Method Direct) -> Word16 -> Word16 -> [Tree CPEntry] -> GState -- | Already generated code (in current method) generated :: GState -> [Instruction] -- | Already generated constants pool currentPool :: GState -> Pool Direct -- | Next index to be used in constants pool nextPoolIndex :: GState -> Word16 -- | Already generated class methods doneMethods :: GState -> [Method Direct] -- | Current method currentMethod :: GState -> Maybe (Method Direct) -- | Maximum stack size for current method stackSize :: GState -> Word16 -- | Maximum number of local variables for current method locals :: GState -> Word16 classPath :: GState -> [Tree CPEntry] -- | Empty generator state emptyGState :: GState class (Monad (g e), MonadState GState (g e)) => Generator e g throwG :: (Generator e g, Exception x, Throws x e) => x -> g e a -- | Generate monad data Generate e a -- | IO version of Generate monad data GenerateIO e a -- | Add a constant into pool addToPool :: Generator e g => Constant Direct -> g e Word16 -- | Generate one (zero-arguments) instruction i0 :: Generator e g => Instruction -> g e () -- | Generate one one-argument instruction i1 :: Generator e g => (Word16 -> Instruction) -> Constant Direct -> g e () -- | Generate one one-argument instruction i8 :: Generator e g => (Word8 -> Instruction) -> Constant Direct -> g e () -- | Generate new method newMethod :: (Generator e g, Throws UnexpectedEndMethod e) => [AccessFlag] -> ByteString -> [ArgumentSignature] -> ReturnSignature -> g e () -> g e (NameType (Method Direct)) -- | Set maximum stack size for current method setStackSize :: Generator e g => Word16 -> g e () -- | Set maximum number of local variables for current method setMaxLocals :: Generator e g => Word16 -> g e () -- | Update ClassPath withClassPath :: ClassPath () -> GenerateIO e () -- | Get class field signature from current ClassPath getClassField :: (Throws ENotFound e, Throws ENotLoaded e) => String -> ByteString -> GenerateIO e (NameType (Field Direct)) -- | Get class method signature from current ClassPath getClassMethod :: (Throws ENotFound e, Throws ENotLoaded e) => String -> ByteString -> GenerateIO e (NameType (Method Direct)) -- | Generate a class generate :: [Tree CPEntry] -> ByteString -> Generate (Caught SomeException NoExceptions) () -> Class Direct -- | Generate a class generateIO :: [Tree CPEntry] -> ByteString -> GenerateIO (Caught SomeException NoExceptions) () -> IO (Class Direct) generateCodeLength :: Generate (Caught SomeException NoExceptions) a -> Word32 instance Eq GState instance Show GState instance Monad (Generate e) instance MonadState GState (Generate e) instance Monad (GenerateIO e) instance MonadState GState (GenerateIO e) instance MonadIO (GenerateIO e) instance MonadState GState (EMT e (State GState)) => Generator e Generate instance Generator e GenerateIO instance MonadIO (EMT e (StateT GState IO)) instance MonadState st (EMT e (State st)) instance MonadState st (EMT e (StateT st IO)) -- | This module exports shortcuts for some of JVM instructions (which are -- defined in JVM.Assembler). These functions get Constants, put them -- into constants pool and generate instruction using index of constant -- in the pool. module JVM.Builder.Instructions nop :: Generator e g => g e () aconst_null :: Generator e g => g e () iconst_m1 :: Generator e g => g e () iconst_0 :: Generator e g => g e () iconst_1 :: Generator e g => g e () iconst_2 :: Generator e g => g e () iconst_3 :: Generator e g => g e () iconst_4 :: Generator e g => g e () iconst_5 :: Generator e g => g e () lconst_0 :: Generator e g => g e () lconst_1 :: Generator e g => g e () fconst_0 :: Generator e g => g e () fconst_1 :: Generator e g => g e () fconst_2 :: Generator e g => g e () dconst_0 :: Generator e g => g e () dconst_1 :: Generator e g => g e () bipush :: Generator e g => Word8 -> g e () sipush :: Generator e g => Word16 -> g e () ldc1 :: Generator e g => Constant Direct -> g e () ldc2 :: Generator e g => Constant Direct -> g e () ldc2w :: Generator e g => Constant Direct -> g e () iload :: Generator e g => Constant Direct -> g e () lload :: Generator e g => Constant Direct -> g e () fload :: Generator e g => Constant Direct -> g e () dload :: Generator e g => Constant Direct -> g e () aload :: Generator e g => Constant Direct -> g e () iload_ :: Generator e g => IMM -> g e () lload_ :: Generator e g => IMM -> g e () fload_ :: Generator e g => IMM -> g e () dload_ :: Generator e g => IMM -> g e () aload_ :: Generator e g => IMM -> g e () iaload :: Generator e g => g e () laload :: Generator e g => g e () faload :: Generator e g => g e () daload :: Generator e g => g e () aaload :: Generator e g => g e () caload :: Generator e g => g e () saload :: Generator e g => g e () istore :: Generator e g => Constant Direct -> g e () lstore :: Generator e g => Constant Direct -> g e () fstore :: Generator e g => Constant Direct -> g e () dstore :: Generator e g => Constant Direct -> g e () astore :: Generator e g => Constant Direct -> g e () istore_ :: Generator e g => Word8 -> g e () lstore_ :: Generator e g => Word8 -> g e () fstore_ :: Generator e g => Word8 -> g e () dstore_ :: Generator e g => Word8 -> g e () astore_ :: Generator e g => Word8 -> g e () iastore :: Generator e g => g e () lastore :: Generator e g => g e () fastore :: Generator e g => g e () dastore :: Generator e g => g e () aastore :: Generator e g => g e () bastore :: Generator e g => g e () castore :: Generator e g => g e () sastore :: Generator e g => g e () pop :: Generator e g => g e () pop2 :: Generator e g => g e () dup :: Generator e g => g e () dup_x1 :: Generator e g => g e () dup_x2 :: Generator e g => g e () dup2 :: Generator e g => g e () dup2_x1 :: Generator e g => g e () dup2_x2 :: Generator e g => g e () swap :: Generator e g => g e () iadd :: Generator e g => g e () ladd :: Generator e g => g e () fadd :: Generator e g => g e () dadd :: Generator e g => g e () isub :: Generator e g => g e () lsub :: Generator e g => g e () fsub :: Generator e g => g e () dsub :: Generator e g => g e () imul :: Generator e g => g e () lmul :: Generator e g => g e () fmul :: Generator e g => g e () dmul :: Generator e g => g e () idiv :: Generator e g => g e () ldiv :: Generator e g => g e () fdiv :: Generator e g => g e () ddiv :: Generator e g => g e () irem :: Generator e g => g e () lrem :: Generator e g => g e () frem :: Generator e g => g e () drem :: Generator e g => g e () ineg :: Generator e g => g e () lneg :: Generator e g => g e () fneg :: Generator e g => g e () dneg :: Generator e g => g e () ishl :: Generator e g => g e () lshl :: Generator e g => g e () ishr :: Generator e g => g e () lshr :: Generator e g => g e () iushr :: Generator e g => g e () lushr :: Generator e g => g e () iand :: Generator e g => g e () land :: Generator e g => g e () ior :: Generator e g => g e () lor :: Generator e g => g e () ixor :: Generator e g => g e () lxor :: Generator e g => g e () iinc :: Generator e g => Word8 -> Word8 -> g e () i2l :: Generator e g => g e () i2f :: Generator e g => g e () i2d :: Generator e g => g e () l2i :: Generator e g => g e () l2f :: Generator e g => g e () l2d :: Generator e g => g e () f2i :: Generator e g => g e () f2l :: Generator e g => g e () f2d :: Generator e g => g e () d2i :: Generator e g => g e () d2l :: Generator e g => g e () d2f :: Generator e g => g e () i2b :: Generator e g => g e () i2c :: Generator e g => g e () i2s :: Generator e g => g e () lcmp :: Generator e g => g e () -- | Wide instruction wide :: Generator e g => (Word8 -> Instruction) -> Constant Direct -> g e () new :: Generator e g => ByteString -> g e () newArray :: Generator e g => ArrayType -> g e () allocNewArray :: Generator e g => ByteString -> g e () invokeVirtual :: Generator e g => ByteString -> NameType (Method Direct) -> g e () invokeStatic :: Generator e g => ByteString -> NameType (Method Direct) -> g e () invokeSpecial :: Generator e g => ByteString -> NameType (Method Direct) -> g e () getStaticField :: Generator e g => ByteString -> NameType (Field Direct) -> g e () loadString :: Generator e g => String -> g e () allocArray :: Generator e g => ByteString -> g e () module JVM.Builder arrayOf :: FieldType -> FieldType sizedArray :: Int -> FieldType -> FieldType module JVM.Dump -- | Dump a class to console. dumpClass :: Class Direct -> IO () -- | This module exports some definitions from standard Java java.lang -- package. module Java.Lang objectClass :: FieldType stringClass :: FieldType integerClass :: FieldType systemClass :: FieldType object :: IsString s => s string :: IsString s => s integer :: IsString s => s system :: IsString s => s -- | java.lang.Object.init() method objectInit :: NameType (Method Direct) -- | java.lang.Integer.valueOf() method valueOfInteger :: NameType (Method Direct) -- | This module exports definitions for some most used classes and methods -- from standard Java java.io package. module Java.IO -- | java.io.PrintStream class name printStream :: IsString s => s -- | java.io.PrintStream class as field type printStreamClass :: FieldType println :: NameType (Method Direct) out :: NameType (Field Direct) printf :: NameType (Method Direct)