Copyright | (c) Christian Gram Kalhauge 2018 |
---|---|
License | MIT |
Maintainer | kalhuage@cs.ucla.edu |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- data ByteCode i = ByteCode {
- byteCodeSize :: !Word32
- byteCodeInstructions :: Vector (ByteCodeInst i)
- unByteCode :: ByteCode i -> Vector (ByteCodeInst i)
- evolveByteCode :: EvolveM m => ByteCode Low -> m (OffsetMap, ByteCode High)
- devolveByteCode :: DevolveM m => ByteCode High -> m (ByteCode Low)
- evolveOffset :: EvolveM m => OffsetMap -> ByteCodeOffset -> m ByteCodeIndex
- devolveOffset :: DevolveM m => ByteCode Low -> ByteCodeIndex -> m ByteCodeOffset
- class ByteCodeStaged s where
- evolveBC :: EvolveM m => (ByteCodeOffset -> m ByteCodeIndex) -> s Low -> m (s High)
- devolveBC :: DevolveM m => (ByteCodeIndex -> m ByteCodeOffset) -> s High -> m (s Low)
- data ByteCodeInst r = ByteCodeInst {
- offset :: !ByteCodeOffset
- opcode :: !(ByteCodeOpr r)
- type ByteCodeRef i = Choice ByteCodeOffset ByteCodeIndex i
- type ByteCodeOffset = Word16
- type ByteCodeIndex = Int
- type OffsetMap = IntMap ByteCodeIndex
- indexOffset :: ByteCode Low -> ByteCodeIndex -> Maybe ByteCodeOffset
- offsetIndex :: OffsetMap -> ByteCodeOffset -> Maybe ByteCodeIndex
- offsetMap :: ByteCode Low -> OffsetMap
- generateOffsets :: DevolveM m => Vector (ByteCodeOpr High) -> m (Word16, Vector ByteCodeOffset)
- data ByteCodeOpr r
- = ArrayLoad !ArrayType
- | ArrayStore !ArrayType
- | Push !(BConstant r)
- | Load !LocalType !LocalAddress
- | Store !LocalType !LocalAddress
- | BinaryOpr !BinOpr !ArithmeticType
- | Neg !ArithmeticType
- | BitOpr !BitOpr !WordSize
- | IncrLocal !LocalAddress !IncrementAmount
- | Cast !CastOpr
- | CompareLongs
- | CompareFloating !Bool !WordSize
- | If !CmpOpr !OneOrTwo !(ShortRelativeRef r)
- | IfRef !Bool !OneOrTwo !(ShortRelativeRef r)
- | Goto !(LongRelativeRef r)
- | Jsr !(LongRelativeRef r)
- | Ret !LocalAddress
- | TableSwitch !(LongRelativeRef r) !(SwitchTable r)
- | LookupSwitch !(LongRelativeRef r) (Vector (Int32, LongRelativeRef r))
- | Get !FieldAccess !(Ref AbsFieldId r)
- | Put !FieldAccess !(Ref AbsFieldId r)
- | Invoke !(Invocation r)
- | New !(Ref ClassName r)
- | NewArray !(Choice LowNewArrayType NewArrayType r)
- | ArrayLength
- | Throw
- | CheckCast !(Ref JRefType r)
- | InstanceOf !(Ref JRefType r)
- | Monitor !Bool
- | Return !(Maybe LocalType)
- | Nop
- | Pop !WordSize
- | Dup !WordSize
- | DupX1 !WordSize
- | DupX2 !WordSize
- | Swap
- type BConstant r = Choice (CConstant r) (Maybe JValue) r
- data CConstant r
- data OneOrTwo
- data SwitchTable r = SwitchTable {
- switchLow :: Int32
- switchOffsets :: Vector (LongRelativeRef r)
- switchHigh :: SwitchTable Low -> Int32
- data FieldAccess
- data Invocation r
- = InvkSpecial !(Ref AbsVariableMethodId r)
- | InvkVirtual !(Ref (InRefType MethodId) r)
- | InvkStatic !(Ref AbsVariableMethodId r)
- | InvkInterface !Word8 !(Ref AbsInterfaceMethodId r)
- | InvkDynamic !(DeepRef InvokeDynamic r)
- type ShortRelativeRef i = Choice Int16 ByteCodeIndex i
- type LongRelativeRef i = Choice Int32 ByteCodeIndex i
- data NewArrayType = NewArrayType Word8 JType
- newArrayTypeType :: NewArrayType -> JRefType
- data LowNewArrayType
- data BinOpr
- data BitOpr
- data CmpOpr
- data CastOpr
- data ArithmeticType
- data SmallArithmeticType
- data LocalType
- data ArrayType
- type WordSize = OneOrTwo
- type ByteOffset = Int64
- type LocalAddress = Word16
- type IncrementAmount = Int16
Documentation
ByteCode constains a list of ByteCode instructions and the size of the bytecode. if the ByteCode is in the Low stage then the byte code instructions are annotated with the byte code offsets.
ByteCode | |
|
Instances
unByteCode :: ByteCode i -> Vector (ByteCodeInst i) Source #
evolve and devolve
evolveOffset :: EvolveM m => OffsetMap -> ByteCodeOffset -> m ByteCodeIndex Source #
Given an OffsetMap
turn a offset into a bytecode index
devolveOffset :: DevolveM m => ByteCode Low -> ByteCodeIndex -> m ByteCodeOffset Source #
Given an OffsetMap
turn a offset into a bytecode index
class ByteCodeStaged s where Source #
evolveBC :: EvolveM m => (ByteCodeOffset -> m ByteCodeIndex) -> s Low -> m (s High) Source #
devolveBC :: DevolveM m => (ByteCodeIndex -> m ByteCodeOffset) -> s High -> m (s Low) Source #
Instances
Managing offsets
data ByteCodeInst r Source #
The byte code instruction is mostly used to succinctly read and write an bytecode instruction from a bytestring.
ByteCodeInst | |
|
Instances
type ByteCodeRef i = Choice ByteCodeOffset ByteCodeIndex i Source #
A ByteCode reference is either byte code offset in the low stage, and a byte code index in the high state
type ByteCodeOffset = Word16 Source #
The offset in the byte code
type ByteCodeIndex = Int Source #
The index of the byte code.
type OffsetMap = IntMap ByteCodeIndex Source #
The offset map, maps offset to instruction ids.
indexOffset :: ByteCode Low -> ByteCodeIndex -> Maybe ByteCodeOffset Source #
Return the bytecode offset from the bytecode.
offsetIndex :: OffsetMap -> ByteCodeOffset -> Maybe ByteCodeIndex Source #
Given an OffsetMap
turn a offset into a bytecode index
generateOffsets :: DevolveM m => Vector (ByteCodeOpr High) -> m (Word16, Vector ByteCodeOffset) Source #
ByteCode Operations
data ByteCodeOpr r Source #
ArrayLoad !ArrayType | aaload baload ... |
ArrayStore !ArrayType | aastore bastore ... |
Push !(BConstant r) | |
Load !LocalType !LocalAddress | aload_0, bload_2, iload 5 ... |
Store !LocalType !LocalAddress | aload, bload ... |
BinaryOpr !BinOpr !ArithmeticType | iadd ... |
Neg !ArithmeticType | ineg ... |
BitOpr !BitOpr !WordSize | Exclusively on int and long, identified by the word-size |
IncrLocal !LocalAddress !IncrementAmount | |
Cast !CastOpr | Only valid on different types |
CompareLongs | |
CompareFloating !Bool !WordSize | Compare two floating values, 2 is if float or double should be used. |
If !CmpOpr !OneOrTwo !(ShortRelativeRef r) | compare with 0 if #2 is False, and two ints from the stack if True. the last value is the offset |
IfRef !Bool !OneOrTwo !(ShortRelativeRef r) | check if two objects are equal, or not equal. If #2 is True, compare with null. |
Goto !(LongRelativeRef r) | |
Jsr !(LongRelativeRef r) | |
Ret !LocalAddress | |
TableSwitch !(LongRelativeRef r) !(SwitchTable r) | a table switch has 2 values a `default` and a |
LookupSwitch !(LongRelativeRef r) (Vector (Int32, LongRelativeRef r)) | a lookup switch has a `default` value and a list of pairs. |
Get !FieldAccess !(Ref AbsFieldId r) | |
Put !FieldAccess !(Ref AbsFieldId r) | |
Invoke !(Invocation r) | |
New !(Ref ClassName r) | |
NewArray !(Choice LowNewArrayType NewArrayType r) | the first argument is the number of dimentions of the array that have to be instantiatied. The JType indicates the type of the instantiated array |
ArrayLength | |
Throw | |
CheckCast !(Ref JRefType r) | |
InstanceOf !(Ref JRefType r) | |
Monitor !Bool | True => Enter, False => Exit |
Return !(Maybe LocalType) | |
Nop | |
Pop !WordSize | |
Dup !WordSize | |
DupX1 !WordSize | |
DupX2 !WordSize | |
Swap |
Instances
CNull | |
CIntM1 |
|
CInt0 | |
CInt1 | |
CInt2 | |
CInt3 | |
CInt4 | |
CInt5 | |
CLong0 | |
CLong1 | |
CFloat0 | |
CFloat1 | |
CFloat2 | |
CDouble0 | |
CDouble1 | |
CByte Int8 | |
CShort Int16 | |
CRef (Maybe WordSize) (Ref JValue r) |
Instances
Instances
Bounded OneOrTwo Source # | |
Enum OneOrTwo Source # | |
Eq OneOrTwo Source # | |
Ord OneOrTwo Source # | |
Defined in Language.JVM.ByteCode | |
Show OneOrTwo Source # | |
Generic OneOrTwo Source # | |
NFData OneOrTwo Source # | |
Defined in Language.JVM.ByteCode | |
type Rep OneOrTwo Source # | |
data SwitchTable r Source #
SwitchTable | |
|
Instances
switchHigh :: SwitchTable Low -> Int32 Source #
data FieldAccess Source #
Instances
data Invocation r Source #
InvkSpecial !(Ref AbsVariableMethodId r) | Variable since 52.0 |
InvkVirtual !(Ref (InRefType MethodId) r) | |
InvkStatic !(Ref AbsVariableMethodId r) | Variable since 52.0 |
InvkInterface !Word8 !(Ref AbsInterfaceMethodId r) | Should be a positive number |
InvkDynamic !(DeepRef InvokeDynamic r) |
Instances
type ShortRelativeRef i = Choice Int16 ByteCodeIndex i Source #
A short relative bytecode ref is defined in correspondence with the
type LongRelativeRef i = Choice Int32 ByteCodeIndex i Source #
A Long relative reference. The only reason this exist because the signed nature of int, looses a bit.
data NewArrayType Source #
Instances
data LowNewArrayType Source #
Instances
Operations
Instances
Eq BinOpr Source # | |
Ord BinOpr Source # | |
Show BinOpr Source # | |
Generic BinOpr Source # | |
NFData BinOpr Source # | |
Defined in Language.JVM.ByteCode | |
type Rep BinOpr Source # | |
Defined in Language.JVM.ByteCode type Rep BinOpr = D1 (MetaData "BinOpr" "Language.JVM.ByteCode" "jvm-binary-0.9.0-9S1OjG3yP2JAIJl8zf6L4B" False) ((C1 (MetaCons "Add" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Sub" PrefixI False) (U1 :: Type -> Type)) :+: (C1 (MetaCons "Mul" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "Div" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Rem" PrefixI False) (U1 :: Type -> Type)))) |
Instances
Eq BitOpr Source # | |
Ord BitOpr Source # | |
Show BitOpr Source # | |
Generic BitOpr Source # | |
NFData BitOpr Source # | |
Defined in Language.JVM.ByteCode | |
type Rep BitOpr Source # | |
Defined in Language.JVM.ByteCode type Rep BitOpr = D1 (MetaData "BitOpr" "Language.JVM.ByteCode" "jvm-binary-0.9.0-9S1OjG3yP2JAIJl8zf6L4B" False) ((C1 (MetaCons "ShL" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "ShR" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "UShR" PrefixI False) (U1 :: Type -> Type))) :+: (C1 (MetaCons "And" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "Or" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "XOr" PrefixI False) (U1 :: Type -> Type)))) |
Instances
Eq CmpOpr Source # | |
Ord CmpOpr Source # | |
Show CmpOpr Source # | |
Generic CmpOpr Source # | |
NFData CmpOpr Source # | |
Defined in Language.JVM.ByteCode | |
type Rep CmpOpr Source # | |
Defined in Language.JVM.ByteCode type Rep CmpOpr = D1 (MetaData "CmpOpr" "Language.JVM.ByteCode" "jvm-binary-0.9.0-9S1OjG3yP2JAIJl8zf6L4B" False) ((C1 (MetaCons "CEq" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "CNe" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "CLt" PrefixI False) (U1 :: Type -> Type))) :+: (C1 (MetaCons "CGe" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "CGt" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "CLe" PrefixI False) (U1 :: Type -> Type)))) |
CastDown SmallArithmeticType | Cast from Int to a smaller type |
CastTo ArithmeticType ArithmeticType | Cast from any to any arithmetic type. Cannot be the same type. |
Instances
Eq CastOpr Source # | |
Ord CastOpr Source # | |
Show CastOpr Source # | |
Generic CastOpr Source # | |
NFData CastOpr Source # | |
Defined in Language.JVM.ByteCode | |
type Rep CastOpr Source # | |
Defined in Language.JVM.ByteCode type Rep CastOpr = D1 (MetaData "CastOpr" "Language.JVM.ByteCode" "jvm-binary-0.9.0-9S1OjG3yP2JAIJl8zf6L4B" False) (C1 (MetaCons "CastDown" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 SmallArithmeticType)) :+: C1 (MetaCons "CastTo" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 ArithmeticType) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 ArithmeticType))) |
Type sets
data ArithmeticType Source #
Instances
data SmallArithmeticType Source #
Instances
Instances
Instances
Eq ArrayType Source # | |
Ord ArrayType Source # | |
Defined in Language.JVM.ByteCode | |
Show ArrayType Source # | |
Generic ArrayType Source # | |
NFData ArrayType Source # | |
Defined in Language.JVM.ByteCode | |
type Rep ArrayType Source # | |
Defined in Language.JVM.ByteCode type Rep ArrayType = D1 (MetaData "ArrayType" "Language.JVM.ByteCode" "jvm-binary-0.9.0-9S1OjG3yP2JAIJl8zf6L4B" False) (((C1 (MetaCons "AByte" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "AChar" PrefixI False) (U1 :: Type -> Type)) :+: (C1 (MetaCons "AShort" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "AInt" PrefixI False) (U1 :: Type -> Type))) :+: ((C1 (MetaCons "ALong" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "AFloat" PrefixI False) (U1 :: Type -> Type)) :+: (C1 (MetaCons "ADouble" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "ARef" PrefixI False) (U1 :: Type -> Type)))) |
Renames
type ByteOffset = Int64 #
An offset, counted in bytes.
type LocalAddress = Word16 Source #
type IncrementAmount = Int16 Source #