Skip to content
This repository has been archived by the owner on Nov 2, 2019. It is now read-only.

Commit

Permalink
Added method bodies.
Browse files Browse the repository at this point in the history
  • Loading branch information
grindars committed Jan 8, 2012
1 parent e6caab3 commit cb66f87
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 16 deletions.
6 changes: 5 additions & 1 deletion bin/disasm
Expand Up @@ -28,4 +28,8 @@ File.open(opts[:input]) do |file|
abc = AVM2::ABC::File.read(file)
end

p abc
p abc

File.open("out.abc", "w") do |file|
abc.write(file)
end
3 changes: 3 additions & 0 deletions lib/avm2/abc.rb
Expand Up @@ -47,4 +47,7 @@ class Record < BinData::Record

require "avm2/abc/metadata/script_info"

require "avm2/abc/metadata/exception_info"
require "avm2/abc/metadata/method_body_info"

require "avm2/abc/metadata/file"
9 changes: 9 additions & 0 deletions lib/avm2/abc/metadata/exception_info.rb
@@ -0,0 +1,9 @@
module AVM2::ABC
class ExceptionInfo < BinData::Record
vuint30 :from
vuint30 :to
vuint30 :target
vuint30 :exc_type
vuint30 :name
end
end
28 changes: 14 additions & 14 deletions lib/avm2/abc/metadata/file.rb
@@ -1,24 +1,24 @@
module AVM2::ABC
class File < Record
uint16 :minor_version
uint16 :major_version
uint16 :minor_version
uint16 :major_version

const_pool_info :constant_pool
const_pool_info :constant_pool

vuint30 :klass_method_count, :value => lambda { klass_methods.count }
array :klass_methods, :type => :method_info, :initial_length => :klass_method_count
vuint30 :klass_method_count, :value => lambda { klass_methods.count }
array :klass_methods, :type => :method_info, :initial_length => :klass_method_count

vuint30 :metadata_count, :value => lambda { metadata.count }
array :metadata, :type => :metadata_info, :initial_length => :metadata_count
vuint30 :metadata_count, :value => lambda { metadata.count }
array :metadata, :type => :metadata_info, :initial_length => :metadata_count

vuint30 :klass_count, :value => lambda { instances.count }
array :instances, :type => :instance_info, :initial_length => :klass_count
array :klasses, :type => :klass_info, :initial_length => :klass_count
vuint30 :klass_count, :value => lambda { instances.count }
array :instances, :type => :instance_info, :initial_length => :klass_count
array :klasses, :type => :klass_info, :initial_length => :klass_count

vuint30 :script_count, :value => lambda { scripts.count }
array :scripts, :type => :script_info, :initial_length => :script_count
vuint30 :script_count, :value => lambda { scripts.count }
array :scripts, :type => :script_info, :initial_length => :script_count

# uint30 :method_body_count, :value => lambda { method_bodies.count }
# method_body_info :method_bodies, :initial_length => :method_body_count
vuint30 :method_body_count, :value => lambda { method_bodies.count }
array :method_bodies, :type => :method_body_info, :initial_length => :method_body_count
end
end
18 changes: 18 additions & 0 deletions lib/avm2/abc/metadata/method_body_info.rb
@@ -0,0 +1,18 @@
module AVM2::ABC
class MethodBodyInfo < BinData::Record
vuint30 :method_name
vuint30 :max_stack
vuint30 :local_count
vuint30 :init_scope_depth
vuint30 :max_scope_depth

vuint30 :code_length, :value => lambda { code.length }
string :code, :read_length => :code_length

vuint30 :exception_count, :value => lambda { exceptions.count }
array :exceptions, :type => :exception_info, :initial_length => :exception_count

vuint30 :trait_count, :value => lambda { traits.count }
array :traits, :type => :traits_info, :initial_length => :trait_count
end
end
2 changes: 1 addition & 1 deletion lib/avm2/abc/metadata/script_info.rb
Expand Up @@ -2,7 +2,7 @@ module AVM2::ABC
class ScriptInfo < Record
vuint30 :init

vuint30 :trait_count, :value => lambda { traits.count() }
vuint30 :trait_count, :value => lambda { traits.count }
array :traits, :type => :traits_info, :initial_length => :trait_count
end
end

0 comments on commit cb66f87

Please sign in to comment.