2015-05-30 13:49:47 +02:00
|
|
|
module Virtual
|
|
|
|
|
|
|
|
# Remove all functions that are not called
|
|
|
|
# Not called is approximated by the fact that the method name doesn't show up
|
|
|
|
# in any function reachable from main
|
|
|
|
class Minimizer
|
|
|
|
def run
|
|
|
|
@gonners = []
|
|
|
|
Parfait::Space.object_space.classes.values.each do |c|
|
|
|
|
c.instance_methods.each do |f|
|
|
|
|
@gonners << f
|
|
|
|
end
|
|
|
|
end
|
2015-08-06 17:27:35 +02:00
|
|
|
keep Virtual.machine.space.get_init
|
|
|
|
remove_remaining
|
2015-05-30 13:49:47 +02:00
|
|
|
end
|
|
|
|
|
2015-08-06 17:27:35 +02:00
|
|
|
def keep function
|
2015-05-30 13:49:47 +02:00
|
|
|
index = @gonners.index function
|
|
|
|
unless index
|
2015-07-23 16:15:07 +02:00
|
|
|
puts "function was already removed #{function.name}"
|
2015-05-30 13:49:47 +02:00
|
|
|
return
|
|
|
|
end
|
2015-06-01 07:33:23 +02:00
|
|
|
#puts "stayer #{function.name}"
|
2015-05-30 13:49:47 +02:00
|
|
|
@gonners.delete function
|
2015-07-03 19:13:03 +02:00
|
|
|
function.source.blocks.each do |block|
|
2015-05-30 13:49:47 +02:00
|
|
|
block.codes.each do |code|
|
|
|
|
if code.is_a? Virtual::MessageSend
|
2015-07-23 16:15:07 +02:00
|
|
|
@gonners.dup.each do |stay|
|
2015-08-06 17:27:35 +02:00
|
|
|
keep stay if(stay.name == code.name)
|
2015-05-30 13:49:47 +02:00
|
|
|
end
|
|
|
|
end
|
2015-08-06 17:27:35 +02:00
|
|
|
keep code.method if code.is_a? Virtual::MethodCall
|
2015-05-30 13:49:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-06 17:27:35 +02:00
|
|
|
def remove_remaining
|
2015-05-31 10:07:49 +02:00
|
|
|
@gonners.each do |method|
|
2015-08-06 17:27:35 +02:00
|
|
|
next if(method.name == :plus)
|
2015-05-31 10:07:49 +02:00
|
|
|
method.for_class.remove_instance_method method
|
|
|
|
end
|
2015-05-30 13:49:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|