X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=JVM%2FAssembler.hs;h=b86bdbba7c2372d362e3f1116cc96b06f6aaab88;hb=afbece7c7a823691d1e17743aec4d94a930864c8;hp=a3162c0296b02dd2a685364ffecbb454b7faf2a9;hpb=87988b2e5fdbeb580e2065a8c6dca0a747bb1656;p=hs-java.git diff --git a/JVM/Assembler.hs b/JVM/Assembler.hs index a3162c0..b86bdbb 100644 --- a/JVM/Assembler.hs +++ b/JVM/Assembler.hs @@ -9,7 +9,10 @@ module JVM.Assembler CodeException (..), Code (..), IMM (..), - CMP (..) + CMP (..), + encodeInstructions, + encodeMethod, + decodeMethod ) where @@ -703,4 +706,17 @@ instance BinaryState Integer Instruction where | inRange (153, 158) c -> return $ IF (toEnum $ fromIntegral $ c-153) | inRange (159, 164) c -> IF_ICMP (toEnum $ fromIntegral $ c-159) <$> get | otherwise -> fail $ "Unknown instruction byte code: " ++ show c + +encodeInstructions :: [Instruction] -> B.ByteString +encodeInstructions code = + let p list = forM_ list put + in encodeWith p (0 :: Integer) code +-- | Decode Java method +decodeMethod :: B.ByteString -> Code +decodeMethod str = decodeS (0 :: Integer) str + +-- | Encode Java method +encodeMethod :: Code -> B.ByteString +encodeMethod code = encodeS (0 :: Integer) code +