Created
March 16, 2014 13:34
-
-
Save weirdpercent/9583317 to your computer and use it in GitHub Desktop.
Dump YARV bytecode to an array or text based on http://stackoverflow.com/questions/14398964/ruby-2-0-bytecode-export-import
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
["YARVInstructionSequence/SimpleDataFormat", | |
2, | |
1, | |
1, | |
{:arg_size=>0, :local_size=>3, :stack_max=>2}, | |
"<main>", | |
"./example.rb", | |
"/home/someone/example.rb", | |
1, | |
:top, | |
[:j, :data], | |
0, | |
[], | |
[1, | |
[:trace, 1], | |
[:putself], | |
[:putstring, "multi_json"], | |
[:opt_send_simple, | |
{:mid=>:require, :flag=>264, :orig_argc=>1, :blockptr=>nil}], | |
[:pop], | |
3, | |
[:trace, 1], | |
[:putspecialobject, 3], | |
[:putnil], | |
[:defineclass, | |
:Jayson, | |
["YARVInstructionSequence/SimpleDataFormat", | |
2, | |
1, | |
1, | |
{:arg_size=>0, :local_size=>1, :stack_max=>4}, | |
"<class:Jayson>", | |
"./example.rb", | |
"/home/someone/example.rb", | |
3, | |
:class, | |
[], | |
0, | |
[], | |
[3, | |
[:trace, 2], | |
4, | |
[:trace, 1], | |
[:putspecialobject, 1], | |
[:putspecialobject, 2], | |
[:putobject, :to_json], | |
[:putiseq, | |
["YARVInstructionSequence/SimpleDataFormat", | |
2, | |
1, | |
1, | |
{:arg_size=>1, :local_size=>2, :stack_max=>2}, | |
"to_json", | |
"./example.rb", | |
"/home/someone/example.rb", | |
4, | |
:method, | |
[:data], | |
1, | |
[], | |
[4, | |
[:trace, 8], | |
5, | |
[:trace, 1], | |
[:getinlinecache, :label_11, 0], | |
[:getconstant, :MultiJson], | |
[:setinlinecache, 0], | |
:label_11, | |
[:getlocal_OP__WC__0, 2], | |
[:opt_send_simple, | |
{:mid=>:load, :flag=>256, :orig_argc=>1, :blockptr=>nil}], | |
[:dup], | |
[:setlocal_OP__WC__0, 2], | |
6, | |
[:trace, 16], | |
5, | |
[:leave]]]], | |
[:opt_send_simple, | |
{:mid=>:"core#define_method", | |
:flag=>256, | |
:orig_argc=>3, | |
:blockptr=>nil}], | |
7, | |
[:trace, 4], | |
4, | |
[:leave]]], | |
0], | |
[:pop], | |
8, | |
[:trace, 1], | |
[:getinlinecache, :label_27, 0], | |
[:getconstant, :Jayson], | |
[:setinlinecache, 0], | |
:label_27, | |
[:opt_send_simple, {:mid=>:new, :flag=>256, :orig_argc=>0, :blockptr=>nil}], | |
[:setlocal_OP__WC__0, 3], | |
9, | |
[:trace, 1], | |
[:putspecialobject, 1], | |
[:putobject, ["a", 1, "b", 2]], | |
[:opt_send_simple, | |
{:mid=>:"core#hash_from_ary", :flag=>256, :orig_argc=>1, :blockptr=>nil}], | |
[:setlocal_OP__WC__0, 2], | |
10, | |
[:trace, 1], | |
[:getlocal_OP__WC__0, 3], | |
[:getlocal_OP__WC__0, 2], | |
[:opt_send_simple, | |
{:mid=>:to_json, :flag=>256, :orig_argc=>1, :blockptr=>nil}], | |
[:leave]]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
== disasm: <RubyVM::InstructionSequence:<main>@./example.rb>============ | |
local table (size: 3, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, keyword: 0@4] s1) | |
[ 3] j [ 2] data | |
0000 trace 1 ( 1) | |
0002 putself | |
0003 putstring "multi_json" | |
0005 opt_send_simple <callinfo!mid:require, argc:1, FCALL|ARGS_SKIP> | |
0007 pop | |
0008 trace 1 ( 3) | |
0010 putspecialobject 3 | |
0012 putnil | |
0013 defineclass :Jayson, <class:Jayson>, 0 | |
0017 pop | |
0018 trace 1 ( 8) | |
0020 getinlinecache 27, <is:0> | |
0023 getconstant :Jayson | |
0025 setinlinecache <is:0> | |
0027 opt_send_simple <callinfo!mid:new, argc:0, ARGS_SKIP> | |
0029 setlocal_OP__WC__0 3 | |
0031 trace 1 ( 9) | |
0033 putspecialobject 1 | |
0035 putobject ["a", 1, "b", 2] | |
0037 opt_send_simple <callinfo!mid:core#hash_from_ary, argc:1, ARGS_SKIP> | |
0039 setlocal_OP__WC__0 2 | |
0041 trace 1 ( 10) | |
0043 getlocal_OP__WC__0 3 | |
0045 getlocal_OP__WC__0 2 | |
0047 opt_send_simple <callinfo!mid:to_json, argc:1, ARGS_SKIP> | |
0049 leave | |
== disasm: <RubyVM::InstructionSequence:<class:Jayson>@./example.rb>==== | |
0000 trace 2 ( 3) | |
0002 trace 1 ( 4) | |
0004 putspecialobject 1 | |
0006 putspecialobject 2 | |
0008 putobject :to_json | |
0010 putiseq to_json | |
0012 opt_send_simple <callinfo!mid:core#define_method, argc:3, ARGS_SKIP> | |
0014 trace 4 ( 7) | |
0016 leave ( 4) | |
== disasm: <RubyVM::InstructionSequence:to_json@./example.rb>=========== | |
local table (size: 2, argc: 1 [opts: 0, rest: -1, post: 0, block: -1, keyword: 0@3] s1) | |
[ 2] data<Arg> | |
0000 trace 8 ( 4) | |
0002 trace 1 ( 5) | |
0004 getinlinecache 11, <is:0> | |
0007 getconstant :MultiJson | |
0009 setinlinecache <is:0> | |
0011 getlocal_OP__WC__0 2 | |
0013 opt_send_simple <callinfo!mid:load, argc:1, ARGS_SKIP> | |
0015 dup | |
0016 setlocal_OP__WC__0 2 | |
0018 trace 16 ( 6) | |
0020 leave ( 5) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'multi_json' | |
class Jayson | |
def to_json (data) | |
data=MultiJson.load(data) | |
end | |
end | |
j=Jayson.new | |
data={'a' => 1, 'b' => 2} | |
j.to_json(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
seq = RubyVM::InstructionSequence.compile_file("./example.rb") | |
seq.to_a | |
seq.disassemble | |
File.write("out.dump", Marshal.dump(seq.to_a)) | |
arr = Marshal.load(File.read("out.dump")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment