packages feed

asil-1.2: src/ByteCodeAst.ag

-- ABC/SWF byte code

--
-- Assumption: each branching target is preceded by a Location
--

SET AllSwf = SwfFile Rect Tags Tag TagKind AbcFlags AbcFlag AllAbcFile
SET OnlySwfAbc = SwfFile Tags Tag AbcFile
SET AllAbcFile = AbcFile AllAbc
SET AllAbc = MethodInfos MetaInfos InstanceInfos ClassInfos ScriptInfos BodyInfos PoolInfo PoolInts PoolUInts PoolDoubles PoolStrings NamespaceInfos SetInfos MultinameInfos NamespaceInfo NamespaceKind SetInfo NamespaceNames MultinameInfo MultinameKind MethodInfo ParamTypes MethodFlags MethodFlag Optionals Optional ValueKind ParamNames MetaInfo MetaItems MetaItem InstanceInfo InstanceFlags InstanceFlag Interfaces AllTraits ClassInfo ScriptInfo BodyInfo Instructions Instruction DebugType CaseOffsets Exceptions Exception
SET AllTraits = Traits Trait TraitKind TraitData TraitAttrs TraitAttr TraitMeta ValueKind


DATA SwfFile | File
  compressed : Bool
  version : Word8
  length : Word32
  size : Rect
  rate : Word16
  count : Word16
  tags : Tags

DATA Rect | Rect
  bits : Int
  xMin : Word32
  xMax : Word32
  yMin : Word32
  yMax : Word32

TYPE Tags = [Tag]

DATA Tag
  | Abc
      flags  : AbcFlags
      name   : ByteString
      file   : AbcFile
  | FileAttributes
      useDirectBlit : Bool
      useGPU        : Bool
      hasMetaData   : Bool
      hasAS3        : Bool
      useNetwork    : Bool
  | Opaque
      kind   : TagKind
      length : Word32
      body   : ByteString
  | End

TYPE AbcFlags = [AbcFlag]

DATA AbcFlag
  | LazyInit

DATA TagKind
  | End
  | ShowFrame
  | DefineShape
  | PlaceObject
  | RemoveObject
  | DefineBits
  | DefineButton
  | JPEGTables
  | SetBackgroundColor
  | DefineFont
  | DefineText
  | DoAction
  | DefineFontInfo
  | DefineSound
  | StartSound
  | DefineButtonSound
  | SoundStreamHead
  | SoundStreamBlock
  | DefineBitsLossless
  | DefineBitsJPEG2
  | DefineShape2
  | DefineButtonCxform
  | Protect
  | PlaceObject2
  | RemoveObject2
  | DefineShape3
  | DefineText2
  | DefineButton2
  | DefineBitsJPEG3
  | DefineBitsLossless2
  | DefineEditText
  | DefineSprite
  | FrameLabel
  | SoundStreamHead2
  | DefineMorphShape
  | DefineFont2
  | ExportAssets
  | ImportAssets
  | EnableDebugger
  | DoInitAction
  | DefineVideoStream
  | VideoFrame
  | DefineFontInfo2
  | EnableDebugger2
  | ScriptLimits
  | SetTabIndex
  | FileAttributes
  | PlaceObject3
  | ImportAssets2
  | DefineFontAlignZones
  | CSMTextSettings
  | DefineFont3
  | SymbolClass
  | Metadata
  | DefineScalingGrid
  | DoABC
  | DefineShape4
  | DefineMorphShape2
  | DefineSceneAndFrameLabelData
  | DefineBinaryData
  | DefineFontName
  | StartSound2
  | DefineBitsJPEG4
  | DefineFont4
  | Other code : Word16

DATA AbcFile | File
  minorVersion : Word16
  majorVersion : Word16
  constantPool : PoolInfo
  methods      : MethodInfos
  metadatas    : MetaInfos
  instances    : InstanceInfos
  classes      : ClassInfos
  scripts      : ScriptInfos
  bodies       : BodyInfos

TYPE MethodInfos   = [MethodInfo]
TYPE MetaInfos     = [MetaInfo]
TYPE InstanceInfos = [InstanceInfo]
TYPE ClassInfos    = [ClassInfo]
TYPE ScriptInfos   = [ScriptInfo]
TYPE BodyInfos     = [BodyInfo]

DATA PoolInfo | Info
  integers   : PoolInts
  uintegers  : PoolUInts
  doubles    : PoolDoubles
  strings    : PoolStrings
  namespaces : NamespaceInfos
  namesets   : SetInfos
  multinames : MultinameInfos

TYPE PoolInts       = [Word32]
TYPE PoolUInts      = [Word32]
TYPE PoolDoubles    = [Double]
TYPE PoolStrings    = [ByteString]
TYPE NamespaceInfos = [NamespaceInfo]
TYPE SetInfos       = [SetInfo]
TYPE MultinameInfos = [MultinameInfo]

DATA NamespaceInfo | Info
  kind : NamespaceKind
  name : Word32

DATA NamespaceKind
  | General
  | Package
  | Internal
  | Protected
  | Explicit
  | Static
  | Private

DATA SetInfo | Info
  names : NamespaceNames

TYPE NamespaceNames = [Word32]

DATA MultinameInfo
  | QName        namespace : Word32  name : Word32
  | QNameA       namespace : Word32  name : Word32
  | RTQName      name : Word32
  | RTQNameA     name : Word32
  | RTQNameL
  | RTQNameLA
  | Multiname    name : Word32       set : Word32
  | MultinameA   name : Word32       set : Word32
  | MultinameL   set : Word32
  | MultinameLA  set : Word32
  | Generic      name : Word32    params : ParamNames

DATA MultinameKind
  | QName
  | QNameA
  | RTQName
  | RTQNameA
  | RTQNameL
  | RTQNameLA
  | Multiname
  | MultinameA
  | MultinameL
  | MultinameLA
  | Generic

DATA MethodInfo | Info
  return  : Word32
  params  : ParamTypes
  name    : Word32
  flags   : MethodFlags
  options : Optionals
  names   : ParamNames

TYPE ParamTypes = [Word32]

TYPE MethodFlags = [MethodFlag]

DATA MethodFlag
  | NeedArgs
  | NeedAct
  | NeedRest
  | HasOptionals
  | SetDXNS
  | HasParamNames

TYPE Optionals = [Optional]

DATA Optional | Detail
  val  : Word32
  kind : ValueKind

DATA ValueKind
  | Int
  | UInt
  | Double
  | Utf8
  | True
  | False
  | Null
  | Undefined
  | Namespace
  | Package
  | Internal
  | Protected
  | Explicit
  | Static
  | Private

TYPE ParamNames = [Word32]

DATA MetaInfo | Info
  name  : Word32
  items : MetaItems

TYPE MetaItems = [MetaItem]

DATA MetaItem | Item
  key   : Word32
  value : Word32

DATA InstanceInfo | Info
  name        : Word32
  super       : Word32
  flags       : InstanceFlags
  protectedNs : Word32
  interfaces  : Interfaces
  constructor : Word32
  traits      : Traits

TYPE InstanceFlags = [InstanceFlag]

DATA InstanceFlag
  | ClassSealed
  | ClassFinal
  | ClassInterface
  | ClassProtected

TYPE Interfaces = [Word32]

TYPE Traits = [Trait]

DATA Trait | Trait
  name  : Word32
  data  : TraitData
  attrs : TraitAttrs
  meta  : TraitMeta

DATA TraitKind
  | Slot
  | Method
  | Getter
  | Setter
  | Class
  | Function
  | Const

DATA TraitData
  | Slot      slotId : Word32  tp : Word32  vindex : Word32  vkind : ValueKind
  | Const     slotId : Word32  tp : Word32  vindex : Word32  vkind : ValueKind
  | Method    dispId : Word32  method : Word32
  | Getter    dispId : Word32  method : Word32
  | Setter    dispId : Word32  method : Word32
  | Function  dispId : Word32  method : Word32
  | Class     slotId : Word32  class : Word32

TYPE TraitAttrs = [TraitAttr]

DATA TraitAttr
  | Final
  | Override
  | Metadata

TYPE TraitMeta = [Word32]

DATA ClassInfo | Info
  con    : Word32
  traits : Traits

DATA ScriptInfo | Info
  method : Word32
  traits : Traits

DATA BodyInfo | Info
  method : Word32
  maxStack : Word32
  localCount : Word32
  initScopeDepth : Word32
  maxScopeDepth : Word32
  instructions : Instructions
  exceptions : Exceptions
  traits : Traits

TYPE Instructions = [Instruction]

DATA Instruction
  | Add
  | Add_i
  | Add_d
  | ApplyType name : Word32
  | AsType  name : Word32
  | AsTypeLate
  | Breakpoint
  | BreakLine     line : Word32
  | BitAnd
  | BitNot
  | BitOr
  | BitXor
  | Call  argCount : Word32
  | CallInterface  name : Word32  argCount : Word32
  | CallMethod     index : Word32  argCount : Word32
  | CallProp       name : Word32   argCount : Word32
  | CallPropLex    name : Word32   argCount : Word32
  | CallPropVoid   name : Word32   argCount : Word32
  | CallStatic     method : Word32  argCount : Word32
  | CallSuper      name : Word32    argCount : Word32
  | CallSuperId
  | CallSuperVoid  name : Word32    argCount : Word32
  | CheckFilter
  | Coerce         name : Word32
  | Coerce_a
  | Coerce_b
  | Coerce_d
  | Coerce_i
  | Coerce_o
  | Coerce_s
  | Coerce_u
  | Concat
  | Construct      argCount : Word32
  | ConstructProp  name : Word32  argCount : Word32
  | ConstructSuper argCount : Word32
  | Convert_b
  | Convert_i
  | Convert_d
  | Convert_o
  | Convert_u
  | Convert_s
  | Debug          tp : DebugType  name : Word32  reg : Word32  extra : Word32
  | DebugFile      name : Word32
  | DebugLine      line : Word32
  | DecLocal       reg : Word32
  | DecLocal_i     reg : Word32
  | Decrement
  | Decrement_i
  | DeleteProperty  name : Word32
  | DeletePropertyLate
  | Divide
  | Dup
  | Dxns           name : Word32
  | DxnsLate
  | Equals
  | EscXAttr
  | EscXElem
  | FindDef name : Word32
  | FindPropertyGlobalStrict name : Word32
  | FindPropertyGlobal name : Word32
  | FindProperty   name : Word32
  | FindPropStrict name : Word32
  | GetDescendants name : Word32
  | GetGlobalScope
  | GetGlobalSlot  slot : Word32
  | GetLex         name : Word32
  | GetLocal       reg  : Word32
  | GetLocal0
  | GetLocal1
  | GetLocal2
  | GetLocal3
  | GetOuterScope  name  : Word32
  | GetProperty    name  : Word32
  | GetScopeObject index : Word8
  | GetSlot        slot  : Word32
  | GetSuper       name  : Word32
  | GreaterEquals
  | GreaterThan
  | HasNext
  | HasNext2       objectReg : Word32  indexReg : Word32
  | IfEq           offset : Word32  -- note: S24   is offset with respect to the next instruction!
  | IfFalse        offset : Word32
  | IfGe           offset : Word32
  | IfGt           offset : Word32
  | IfLe           offset : Word32
  | IfLt           offset : Word32
  | IfNGe          offset : Word32    
  | IfNGt          offset : Word32
  | IfNLe          offset : Word32
  | IfNLt          offset : Word32
  | IfNe           offset : Word32
  | IfStrictEq     offset : Word32
  | IfStrictNe     offset : Word32
  | IfTrue         offset : Word32
  | In
  | IncLocal       reg : Word32
  | IncLocal_i     reg : Word32
  | Increment
  | Increment_i
  | InitProperty   name : Word32
  | InstanceOf
  | IsType         name : Word32
  | IsTypeLate
  | Jump           offset : Word32
  | Kill           reg : Word32
  | Label
  | LessEquals
  | LessThan
  | LoadFloat32
  | LoadFloat64
  | LoadIndirect8
  | LoadIndirect16
  | LoadIndirect32
  | LookupSwitch   defaultOffset : Word32    caseOffsets : CaseOffsets  -- offset with respect of start of this instruction!
  | Lshift
  | Modulo
  | Multiply
  | Multiply_i
  | Negate
  | Negate_i
  | NewActivation
  | NewArray       argCount : Word32
  | NewCatch       exception : Word32
  | NewClass       class : Word32
  | NewFunction    method : Word32
  | NewObject      argCount : Word32
  | NextName
  | NextValue
  | Nop
  | Not
  | Pop
  | PopScope
  | PushByte      val : Word8
  | PushDouble    name : Word32
  | PushFalse
  | PushInt       name : Word32
  | PushNamespace  name : Word32
  | PushNaN
  | PushNull
  | PushScope
  | PushShort      val : Word32
  | PushString     name : Word32
  | PushTrue
  | PushUInt       name : Word32
  | PushUndefined
  | PushWith
  | ReturnValue
  | ReturnVoid
  | Rshift
  | SetLocal       reg : Word32
  | SetLocal0
  | SetLocal1
  | SetLocal2
  | SetLocal3
  | SetGlobalSlot  slot : Word32
  | SetProperty    name : Word32
  | SetPropertyLate
  | SetSlot        slot : Word32
  | SetSuper       name : Word32
  | SignExtend1
  | SignExtend8
  | SignExtend16
  | StoreFloat32
  | StoreFloat64
  | StoreIndirect32
  | StoreIndirect16
  | StoreIndirect8
  | StrictEquals
  | Substract
  | Substract_i
  | Swap
  | Throw
  | Timestamp
  | TypeOf
  | Urshift

DATA Instruction  -- special instruction that represents location information
  | Location  index : Int   -- offset since start of the byte codes

DATA DebugType
  | Local

TYPE CaseOffsets = [Word32]

TYPE Exceptions = [Exception]

DATA Exception | Info
  from   : Word32
  to     : Word32
  target : Word32
  tp     : Word32
  name   : Word32