Copyright | (c) Christian Gram Kalhauge 2018 |
---|---|
License | MIT |
Maintainer | kalhuage@cs.ucla.edu |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- newtype ByteCode i = ByteCode {
- unByteCode :: Choice (Word32, Vector (ByteCodeInst Low)) (Vector (ByteCodeOpr High)) 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
- 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
- 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 !Int32 !(SwitchTable r)
- | LookupSwitch !Int32 (Vector (Int32, Int32))
- | Get !FieldAccess !(DeepRef (InClass FieldId) r)
- | Put !FieldAccess !(DeepRef (InClass FieldId) r)
- | Invoke !(Invocation r)
- | New !(Ref ClassName r)
- | NewArray !(ExactArrayType r)
- | ArrayLength
- | Throw
- | CheckCast !(Ref ClassName r)
- | InstanceOf !(Ref ClassName r)
- | Monitor !Bool
- | MultiNewArray !(Ref ClassName r) !Word8
- | Return !(Maybe LocalType)
- | Nop
- | Pop WordSize
- | Dup WordSize
- | DupX1 WordSize
- | DupX2 WordSize
- | Swap
- 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 !(DeepRef AbsVariableMethodId r)
- | InvkVirtual !(DeepRef AbsMethodId r)
- | InvkStatic !(DeepRef AbsVariableMethodId r)
- | InvkInterface !Word8 !(DeepRef AbsInterfaceMethodId r)
- | InvkDynamic !(DeepRef InvokeDynamic r)
- data BinOpr
- data BitOpr
- data CmpOpr
- data CastOpr
- data ArithmeticType
- data SmallArithmeticType
- data LocalType
- data ArrayType
- data ExactArrayType r
- type WordSize = OneOrTwo
- type ByteOffset = Int64
- type LocalAddress = Word16
- type IncrementAmount = Int16
Documentation
ByteCode is a newtype wrapper around a list of ByteCode instructions. if the ByteCode is in the Low stage then the byte code instructions are annotated with the byte code offsets.
ByteCode | |
|
Instances
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
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 !Int32 !(SwitchTable r) | a table switch has 2 values a `default` and a |
LookupSwitch !Int32 (Vector (Int32, Int32)) | a lookup switch has a `default` value and a list of pairs. |
Get !FieldAccess !(DeepRef (InClass FieldId) r) | |
Put !FieldAccess !(DeepRef (InClass FieldId) r) | |
Invoke !(Invocation r) | |
New !(Ref ClassName r) | |
NewArray !(ExactArrayType r) | |
ArrayLength | |
Throw | |
CheckCast !(Ref ClassName r) | |
InstanceOf !(Ref ClassName r) | |
Monitor !Bool | True => Enter, False => Exit |
MultiNewArray !(Ref ClassName r) !Word8 | Create a new multi array of 2 dimensions ^ This might point to an array type. |
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
Eq FieldAccess Source # | |
Defined in Language.JVM.ByteCode (==) :: FieldAccess -> FieldAccess -> Bool # (/=) :: FieldAccess -> FieldAccess -> Bool # | |
Ord FieldAccess Source # | |
Defined in Language.JVM.ByteCode compare :: FieldAccess -> FieldAccess -> Ordering # (<) :: FieldAccess -> FieldAccess -> Bool # (<=) :: FieldAccess -> FieldAccess -> Bool # (>) :: FieldAccess -> FieldAccess -> Bool # (>=) :: FieldAccess -> FieldAccess -> Bool # max :: FieldAccess -> FieldAccess -> FieldAccess # min :: FieldAccess -> FieldAccess -> FieldAccess # | |
Show FieldAccess Source # | |
Defined in Language.JVM.ByteCode showsPrec :: Int -> FieldAccess -> ShowS # show :: FieldAccess -> String # showList :: [FieldAccess] -> ShowS # | |
Generic FieldAccess Source # | |
Defined in Language.JVM.ByteCode type Rep FieldAccess :: * -> * # from :: FieldAccess -> Rep FieldAccess x # to :: Rep FieldAccess x -> FieldAccess # | |
NFData FieldAccess Source # | |
Defined in Language.JVM.ByteCode rnf :: FieldAccess -> () # | |
type Rep FieldAccess Source # | |
data Invocation r Source #
InvkSpecial !(DeepRef AbsVariableMethodId r) | Variable since 52.0 |
InvkVirtual !(DeepRef AbsMethodId r) | |
InvkStatic !(DeepRef AbsVariableMethodId r) | Variable since 52.0 |
InvkInterface !Word8 !(DeepRef AbsInterfaceMethodId r) | Should be a positive number |
InvkDynamic !(DeepRef InvokeDynamic r) |
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.2.0-ADCW9RHs0rpAV30EV0jcz6" False) ((C1 (MetaCons "Add" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "Sub" PrefixI False) (U1 :: * -> *)) :+: (C1 (MetaCons "Mul" PrefixI False) (U1 :: * -> *) :+: (C1 (MetaCons "Div" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "Rem" PrefixI False) (U1 :: * -> *)))) |
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.2.0-ADCW9RHs0rpAV30EV0jcz6" False) ((C1 (MetaCons "ShL" PrefixI False) (U1 :: * -> *) :+: (C1 (MetaCons "ShR" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "UShR" PrefixI False) (U1 :: * -> *))) :+: (C1 (MetaCons "And" PrefixI False) (U1 :: * -> *) :+: (C1 (MetaCons "Or" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "XOr" PrefixI False) (U1 :: * -> *)))) |
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.2.0-ADCW9RHs0rpAV30EV0jcz6" False) ((C1 (MetaCons "CEq" PrefixI False) (U1 :: * -> *) :+: (C1 (MetaCons "CNe" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "CLt" PrefixI False) (U1 :: * -> *))) :+: (C1 (MetaCons "CGe" PrefixI False) (U1 :: * -> *) :+: (C1 (MetaCons "CGt" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "CLe" PrefixI False) (U1 :: * -> *)))) |
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.2.0-ADCW9RHs0rpAV30EV0jcz6" False) (C1 (MetaCons "CastDown" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 SmallArithmeticType)) :+: C1 (MetaCons "CastTo" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 ArithmeticType) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (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.2.0-ADCW9RHs0rpAV30EV0jcz6" False) (((C1 (MetaCons "AByte" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "AChar" PrefixI False) (U1 :: * -> *)) :+: (C1 (MetaCons "AShort" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "AInt" PrefixI False) (U1 :: * -> *))) :+: ((C1 (MetaCons "ALong" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "AFloat" PrefixI False) (U1 :: * -> *)) :+: (C1 (MetaCons "ADouble" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "ARef" PrefixI False) (U1 :: * -> *)))) |
data ExactArrayType r Source #
Instances
Renames
type ByteOffset = Int64 #
An offset, counted in bytes.
type LocalAddress = Word16 Source #
type IncrementAmount = Int16 Source #