-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Lua bytecode parser -- -- Lua bytecode parser @package lua-bc @version 0.1.1 module Language.Lua.Bytecode.FunId -- | Path from root to function. newtype FunId FunId :: [Int] -> FunId isRootFun :: FunId -> Bool getRoot :: FunId -> Maybe Int noFun :: FunId isNoFun :: FunId -> Bool rootFun :: Int -> FunId subFun :: FunId -> Int -> FunId funIdString :: FunId -> String funIdFromString :: String -> Maybe FunId funIdList :: FunId -> [Int] funNestDepth :: FunId -> Int instance GHC.Show.Show Language.Lua.Bytecode.FunId.FunId instance GHC.Classes.Ord Language.Lua.Bytecode.FunId.FunId instance GHC.Classes.Eq Language.Lua.Bytecode.FunId.FunId module Language.Lua.Bytecode newtype Reg Reg :: Int -> Reg -- | Zero-based index into upvalues newtype UpIx UpIx :: Int -> UpIx newtype ProtoIx ProtoIx :: Int -> ProtoIx newtype Kst Kst :: Int -> Kst data RK RK_Reg :: !Reg -> RK RK_Kst :: !Kst -> RK data Chunk -- | number of upvalues and function body Chunk :: !Int -> Function -> Chunk data OpCode -- | A B R(A) := R(B) OP_MOVE :: !Reg -> !Reg -> OpCode -- | A Bx R(A) := Kst(Bx) OP_LOADK :: !Reg -> !Kst -> OpCode -- | A R(A) := Kst(extra arg) OP_LOADKX :: !Reg -> OpCode -- | A B C R(A) := (Bool)B; if (C) pc++ OP_LOADBOOL :: !Reg -> !Bool -> !Bool -> OpCode -- | A B R(A), R(A+1), ..., R(A+B) := nil OP_LOADNIL :: !Reg -> !Int -> OpCode -- | A B R(A) := UpValue[B] OP_GETUPVAL :: !Reg -> !UpIx -> OpCode -- | A B C R(A) := UpValue[B][RK(C)] OP_GETTABUP :: !Reg -> !UpIx -> !RK -> OpCode -- | A B C R(A) := R(B)[RK(C)] OP_GETTABLE :: !Reg -> !Reg -> !RK -> OpCode -- | A B C UpValue[A][RK(B)] := RK(C) OP_SETTABUP :: !UpIx -> !RK -> !RK -> OpCode -- | A B UpValue[B] := R(A) OP_SETUPVAL :: !Reg -> !UpIx -> OpCode -- | A B C R(A)[RK(B)] := RK(C) OP_SETTABLE :: !Reg -> !RK -> !RK -> OpCode -- | A B C R(A) := {} (size = B,C) OP_NEWTABLE :: !Reg -> !Int -> !Int -> OpCode -- | A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] OP_SELF :: !Reg -> !Reg -> !RK -> OpCode -- | A B C R(A) := RK(B) + RK(C) OP_ADD :: !Reg -> !RK -> !RK -> OpCode -- | A B C R(A) := RK(B) - RK(C) OP_SUB :: !Reg -> !RK -> !RK -> OpCode -- | A B C R(A) := RK(B) * RK(C) OP_MUL :: !Reg -> !RK -> !RK -> OpCode -- | A B C R(A) := RK(B) % RK(C) OP_MOD :: !Reg -> !RK -> !RK -> OpCode -- | A B C R(A) := RK(B) ^ RK(C) OP_POW :: !Reg -> !RK -> !RK -> OpCode -- | A B C R(A) := RK(B) / RK(C) OP_DIV :: !Reg -> !RK -> !RK -> OpCode -- | A B C R(A) := RK(B) // RK(C) OP_IDIV :: !Reg -> !RK -> !RK -> OpCode -- | A B C R(A) := RK(B) & RK(C) OP_BAND :: !Reg -> !RK -> !RK -> OpCode -- | A B C R(A) := RK(B) | RK(C) OP_BOR :: !Reg -> !RK -> !RK -> OpCode -- | A B C R(A) := RK(B) ~ RK(C) OP_BXOR :: !Reg -> !RK -> !RK -> OpCode -- | A B C R(A) := RK(B) << RK(C) OP_SHL :: !Reg -> !RK -> !RK -> OpCode -- | A B C R(A) := RK(B) >> RK(C) OP_SHR :: !Reg -> !RK -> !RK -> OpCode -- | A B R(A) := -R(B) OP_UNM :: !Reg -> !Reg -> OpCode -- | A B R(A) := ~R(B) OP_BNOT :: !Reg -> !Reg -> OpCode -- | A B R(A) := not R(B) OP_NOT :: !Reg -> !Reg -> OpCode -- | A B R(A) := length of R(B) OP_LEN :: !Reg -> !Reg -> OpCode -- | A B C R(A) := R(B).. ... ..R(C) OP_CONCAT :: !Reg -> !Reg -> !Reg -> OpCode -- | A sBx pc+=sBx; if (A) close all upvalues >= R(A - 1) OP_JMP :: !(Maybe Reg) -> !Int -> OpCode -- | A B C if ((RK(B) == RK(C)) ~= A) then pc++ OP_EQ :: !Bool -> !RK -> !RK -> OpCode -- | A B C if ((RK(B) < RK(C)) ~= A) then pc++ OP_LT :: !Bool -> !RK -> !RK -> OpCode -- | A B C if ((RK(B) <= RK(C)) ~= A) then pc++ OP_LE :: !Bool -> !RK -> !RK -> OpCode -- | A C if not (R(A) = C) then pc++ OP_TEST :: !Reg -> !Bool -> OpCode -- | A B C if (R(B) = C) then R(A) := R(B) else pc++ OP_TESTSET :: !Reg -> !Reg -> !Bool -> OpCode -- | A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) OP_CALL :: !Reg -> !Count -> !Count -> OpCode -- | A B C return R(A)(R(A+1), ... ,R(A+B-1)) OP_TAILCALL :: !Reg -> !Count -> !Count -> OpCode -- | A B return R(A), ... ,R(A+B-2) (see note) OP_RETURN :: !Reg -> !Count -> OpCode -- | A sBx R(A)+=R(A+2); if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) -- } OP_FORLOOP :: !Reg -> !Int -> OpCode -- | A sBx R(A)-=R(A+2); pc+=sBx OP_FORPREP :: !Reg -> !Int -> OpCode -- | A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); OP_TFORCALL :: !Reg -> !Int -> OpCode -- | A sBx if R(A+1) ~= nil then { R(A)=R(A+1); pc += sBx } OP_TFORLOOP :: !Reg -> !Int -> OpCode -- | A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B OP_SETLIST :: !Reg -> !Int -> !Int -> OpCode -- | A Bx R(A) := closure(KPROTO[Bx]) OP_CLOSURE :: !Reg -> !ProtoIx -> OpCode -- | A B R(A), R(A+1), ..., R(A+B-2) = vararg OP_VARARG :: !Reg -> !Count -> OpCode -- | Ax extra (larger) argument for previous opcode OP_EXTRAARG :: !Int -> OpCode data Count CountInt :: !Int -> Count CountTop :: Count data Function Function :: !(Maybe ByteString) -> !Int -> !Int -> !Int -> !Bool -> !Int -> !(Vector OpCode) -> !(Vector Constant) -> !(Vector Upvalue) -> !(Vector Function) -> !DebugInfo -> Function [funcSource] :: Function -> !(Maybe ByteString) [funcLineDefined] :: Function -> !Int [funcLastLineDefined] :: Function -> !Int [funcNumParams] :: Function -> !Int [funcIsVararg] :: Function -> !Bool [funcMaxStackSize] :: Function -> !Int [funcCode] :: Function -> !(Vector OpCode) [funcConstants] :: Function -> !(Vector Constant) [funcUpvalues] :: Function -> !(Vector Upvalue) [funcProtos] :: Function -> !(Vector Function) [funcDebug] :: Function -> !DebugInfo data Constant KNil :: Constant KBool :: Bool -> Constant KNum :: Double -> Constant KInt :: Int -> Constant KString :: ByteString -> Constant KLongString :: ByteString -> Constant data Upvalue UpReg :: Reg -> Upvalue UpUp :: UpIx -> Upvalue type LineNumber = Int data DebugInfo DebugInfo :: !(Vector LineNumber) -> !(Vector VarInfo) -> !(Vector ByteString) -> DebugInfo [debugInfoLines] :: DebugInfo -> !(Vector LineNumber) [debugInfoVars] :: DebugInfo -> !(Vector VarInfo) [debugInfoUpvalues] :: DebugInfo -> !(Vector ByteString) data VarInfo VarInfo :: !ByteString -> !Int -> VarInfo [varInfoName] :: VarInfo -> !ByteString [varInfoStart, varInfoEnd] :: VarInfo -> !Int propagateSources :: Function -> Function -- | Compute a register relative to another. plusReg :: Reg -> Int -> Reg -- | Compute the distance between two registers. diffReg :: Reg -> Reg -> Int -- | Compute a list of registers given a startin register and length. regRange :: Reg -> Int -> [Reg] instance GHC.Classes.Eq Language.Lua.Bytecode.Chunk instance GHC.Show.Show Language.Lua.Bytecode.Chunk instance GHC.Read.Read Language.Lua.Bytecode.Chunk instance GHC.Classes.Eq Language.Lua.Bytecode.Function instance GHC.Show.Show Language.Lua.Bytecode.Function instance GHC.Read.Read Language.Lua.Bytecode.Function instance GHC.Classes.Eq Language.Lua.Bytecode.DebugInfo instance GHC.Show.Show Language.Lua.Bytecode.DebugInfo instance GHC.Read.Read Language.Lua.Bytecode.DebugInfo instance GHC.Classes.Eq Language.Lua.Bytecode.VarInfo instance GHC.Show.Show Language.Lua.Bytecode.VarInfo instance GHC.Read.Read Language.Lua.Bytecode.VarInfo instance GHC.Classes.Ord Language.Lua.Bytecode.Upvalue instance GHC.Classes.Eq Language.Lua.Bytecode.Upvalue instance GHC.Show.Show Language.Lua.Bytecode.Upvalue instance GHC.Read.Read Language.Lua.Bytecode.Upvalue instance GHC.Classes.Ord Language.Lua.Bytecode.Constant instance GHC.Classes.Eq Language.Lua.Bytecode.Constant instance GHC.Show.Show Language.Lua.Bytecode.Constant instance GHC.Read.Read Language.Lua.Bytecode.Constant instance GHC.Classes.Ord Language.Lua.Bytecode.OpCode instance GHC.Classes.Eq Language.Lua.Bytecode.OpCode instance GHC.Show.Show Language.Lua.Bytecode.OpCode instance GHC.Read.Read Language.Lua.Bytecode.OpCode instance GHC.Classes.Ord Language.Lua.Bytecode.Count instance GHC.Classes.Eq Language.Lua.Bytecode.Count instance GHC.Show.Show Language.Lua.Bytecode.Count instance GHC.Read.Read Language.Lua.Bytecode.Count instance GHC.Classes.Ord Language.Lua.Bytecode.RK instance GHC.Classes.Eq Language.Lua.Bytecode.RK instance GHC.Show.Show Language.Lua.Bytecode.RK instance GHC.Read.Read Language.Lua.Bytecode.RK instance GHC.Classes.Ord Language.Lua.Bytecode.Kst instance GHC.Classes.Eq Language.Lua.Bytecode.Kst instance GHC.Show.Show Language.Lua.Bytecode.Kst instance GHC.Read.Read Language.Lua.Bytecode.Kst instance GHC.Classes.Ord Language.Lua.Bytecode.ProtoIx instance GHC.Classes.Eq Language.Lua.Bytecode.ProtoIx instance GHC.Show.Show Language.Lua.Bytecode.ProtoIx instance GHC.Read.Read Language.Lua.Bytecode.ProtoIx instance GHC.Classes.Ord Language.Lua.Bytecode.UpIx instance GHC.Classes.Eq Language.Lua.Bytecode.UpIx instance GHC.Show.Show Language.Lua.Bytecode.UpIx instance GHC.Read.Read Language.Lua.Bytecode.UpIx instance GHC.Classes.Ord Language.Lua.Bytecode.Reg instance GHC.Classes.Eq Language.Lua.Bytecode.Reg instance GHC.Show.Show Language.Lua.Bytecode.Reg instance GHC.Read.Read Language.Lua.Bytecode.Reg instance GHC.Enum.Enum Language.Lua.Bytecode.Reg module Language.Lua.Bytecode.Debug lookupLineNumber :: Function -> Int -> Maybe Int -- | Given a function, compute a map from line numbers to op-codes in the -- function. This is useful for adding break-points identified by line -- number. Does not consider nested functions. shallowLineNumberMap :: Function -> Map Int [Int] -- | Given a function, compute a map from line numbers to op-codes in this -- function or a nested function. For each line number we return a list -- of pairs (typically just 1). The first element in the pair is the path -- to the nested function---empty if not nested---and the second one are -- the PC locations associated with that function. deepLineNumberMap :: Function -> Map Int [(FunId, [Int])] -- | Compute the locals at a specific program counter. This function is -- memoized, so it is fast to lookup things many times. lookupLocalName :: Function -> Int -> Reg -> Maybe ByteString -- | Get what registers are in scope at a particular op-code. R1 is at -- entry 0, R2 is entry 1, etc. NOTE that there might be multiple -- registers with the same named thing. The one currently in scope is the -- last one. getRegistersAt :: Function -> Int -> Vector VarInfo -- | Compute the names for the functions defined withing the given -- function. The Int is the index of the sub-function's prototype. inferSubFunctionNames :: Function -> [(Int, ByteString)] -- | Figure out a name for the function defined at the given program -- counter in a function. Note that this operation could be fairly -- expensive, so probably a good idea to cache the results. inferFunctionName :: Function -> Int -> Maybe ByteString module Language.Lua.Bytecode.Parser parseLuaBytecode :: Maybe String -> ByteString -> Either String Chunk parseLuaBytecodeFile :: FilePath -> IO (Either String Chunk) dumpLuaBytecode :: BytecodeMode -> Chunk -> ByteString dumpLuaBytecodeFile :: FilePath -> Chunk -> IO () data BytecodeMode BytecodeMode :: !LuacVersion -> !Sizet -> BytecodeMode [bytecodeVersion] :: BytecodeMode -> !LuacVersion [bytecodeSizet] :: BytecodeMode -> !Sizet data Sizet Sizet32 :: Sizet Sizet64 :: Sizet data LuacVersion Luac52 :: LuacVersion Luac53 :: LuacVersion luaBytecodeMode53 :: BytecodeMode instance GHC.Read.Read Language.Lua.Bytecode.Parser.LuacVersion instance GHC.Show.Show Language.Lua.Bytecode.Parser.LuacVersion instance GHC.Classes.Ord Language.Lua.Bytecode.Parser.LuacVersion instance GHC.Classes.Eq Language.Lua.Bytecode.Parser.LuacVersion instance Language.Lua.Bytecode.Parser.OpArg Language.Lua.Bytecode.Reg instance Language.Lua.Bytecode.Parser.OpArg Language.Lua.Bytecode.UpIx instance Language.Lua.Bytecode.Parser.OpArg Language.Lua.Bytecode.Kst instance Language.Lua.Bytecode.Parser.OpArg Language.Lua.Bytecode.ProtoIx instance Language.Lua.Bytecode.Parser.OpArg GHC.Types.Int instance Language.Lua.Bytecode.Parser.OpArg GHC.Word.Word32 instance Language.Lua.Bytecode.Parser.OpArg GHC.Types.Bool instance Language.Lua.Bytecode.Parser.OpArg Language.Lua.Bytecode.RK instance Language.Lua.Bytecode.Parser.OpArg Language.Lua.Bytecode.Count module Language.Lua.Bytecode.Pretty data PPInfo PPInfo :: (Int -> Reg -> Maybe Doc) -> (Kst -> Maybe Doc) -> (UpIx -> Maybe Doc) -> (ProtoIx -> Maybe Doc) -> Maybe Int -> !Int -> PPInfo [ppVarAt] :: PPInfo -> Int -> Reg -> Maybe Doc [ppConstant] :: PPInfo -> Kst -> Maybe Doc [ppUpIx] :: PPInfo -> UpIx -> Maybe Doc [ppFun] :: PPInfo -> ProtoIx -> Maybe Doc [ppExtraArg] :: PPInfo -> Maybe Int [ppPC] :: PPInfo -> !Int ppVar :: PPInfo -> Reg -> Maybe Doc blankPPInfo :: PPInfo ppNextPC :: PPInfo -> PPInfo ppCode :: Function -> Doc ppOpCode :: Function -> Int -> Doc showLuaString :: ByteString -> String class PP a pp :: PP a => PPInfo -> a -> Doc ppRegRange :: PPInfo -> Reg -> Int -> Doc ppRegRangeInf :: PPInfo -> Reg -> Doc ppRegRangeCount :: PPInfo -> Reg -> Count -> Doc instance Language.Lua.Bytecode.Pretty.PP Language.Lua.Bytecode.Constant instance Language.Lua.Bytecode.Pretty.PP Language.Lua.Bytecode.FunId.FunId instance Language.Lua.Bytecode.Pretty.PP Language.Lua.Bytecode.Reg instance Language.Lua.Bytecode.Pretty.PP Language.Lua.Bytecode.Kst instance Language.Lua.Bytecode.Pretty.PP Language.Lua.Bytecode.UpIx instance Language.Lua.Bytecode.Pretty.PP Language.Lua.Bytecode.ProtoIx instance Language.Lua.Bytecode.Pretty.PP Language.Lua.Bytecode.RK instance Language.Lua.Bytecode.Pretty.PP Text.PrettyPrint.HughesPJ.Doc instance Language.Lua.Bytecode.Pretty.PP GHC.Types.Bool instance Language.Lua.Bytecode.Pretty.PP Language.Lua.Bytecode.OpCode