Skip to content
Browse files

Remove Ruby-related parts.

  • Loading branch information...
1 parent 943456c commit 6264b79d71bc25d3031d519ae0e0dbcb40a992af @whitequark committed May 26, 2012
View
61 .rvmrc
@@ -1,61 +0,0 @@
-#!/usr/bin/env bash
-
-# This is an RVM Project .rvmrc file, used to automatically load the ruby
-# development environment upon cd'ing into the directory
-
-# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
-environment_id="rbx-head@furnace"
-
-#
-# Uncomment following line if you want options to be set only for given project.
-#
-# PROJECT_JRUBY_OPTS=( --1.9 )
-
-#
-# First we attempt to load the desired environment directly from the environment
-# file. This is very fast and efficient compared to running through the entire
-# CLI and selector. If you want feedback on which environment was used then
-# insert the word 'use' after --create as this triggers verbose mode.
-#
-if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
- && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
-then
- \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
-
- if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
- then
- . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
- fi
-else
- # If the environment file has not yet been created, use the RVM CLI to select.
- if ! rvm --create "$environment_id"
- then
- echo "Failed to create RVM environment '${environment_id}'."
- return 1
- fi
-fi
-
-#
-# If you use an RVM gemset file to install a list of gems (*.gems), you can have
-# it be automatically loaded. Uncomment the following and adjust the filename if
-# necessary.
-#
-# filename=".gems"
-# if [[ -s "$filename" ]]
-# then
-# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
-# fi
-
-# If you use bundler, this might be useful to you:
-# if command -v bundle && [[ -s Gemfile ]]
-# then
-# bundle install
-# fi
-
-if [[ $- == *i* ]] # check for interactive shells
-then
- echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
-else
- echo "Using: $GEM_HOME" # don't use colors in interactive shells
-fi
-
View
22 bin/furnace
@@ -1,22 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'furnace'
-
-load ARGV[0]
-
-pipeline = Furnace::Transform::Pipeline.new(*[
- Furnace::Transform::Rubinius::ASTBuild.new,
- Furnace::Transform::Rubinius::ASTNormalize.new,
-
- Furnace::Transform::Generic::LabelNormalize.new,
- Furnace::Transform::Generic::CFGBuild.new,
- Furnace::Transform::Generic::CFGNormalize.new,
-
- Furnace::Transform::Generic::ANFBuild.new,
-
- Furnace::Transform::Optimizing::FoldConstants.new,
-])
-
-cfg, = pipeline.run(method(:main).executable)
-
-puts cfg.to_graphviz
View
19 lib/furnace.rb
@@ -1,21 +1,12 @@
+module Furnace
+end
+
require "furnace/version"
require "furnace/ast"
require "furnace/cfg"
require "furnace/code"
-require "furnace/anf/node"
-require "furnace/anf/edge"
-require "furnace/anf/let_node"
-require "furnace/anf/in_node"
-require "furnace/anf/if_node"
-require "furnace/anf/return_node"
-require "furnace/anf/graph"
-
-require "furnace/transform"
-
-require "furnace/graphviz"
+require "furnace/transform/pipeline"
-if RUBY_ENGINE != "rbx"
- raise "Sorry, Furnace only works on Rubinius."
-end
+require "furnace/graphviz"
View
2 lib/furnace/ast.rb
@@ -1,4 +1,4 @@
-require "furnace/base"
+require "furnace"
require "furnace/ast/node"
require "furnace/ast/symbolic_node"
View
5 lib/furnace/base.rb
@@ -1,5 +0,0 @@
-module Furnace
-end
-
-require 'furnace/version'
-
View
2 lib/furnace/cfg.rb
@@ -1,6 +1,6 @@
require "set"
-require "furnace/base"
+require "furnace"
require "furnace/cfg/graph"
require "furnace/cfg/node"
View
5 lib/furnace/cfg/graph.rb
@@ -58,6 +58,11 @@ def merge_redundant!
target = node.targets[0]
next if target == @exit
+ # Skip explicitly non-redundant nodes
+ if node.cti && node.cti.metadata[:keep]
+ next
+ end
+
if node.targets.count == 1 &&
target.sources.count == 1 &&
node.exception == target.exception
View
2 lib/furnace/code.rb
@@ -1,6 +1,6 @@
require "set"
-require "furnace/base"
+require "furnace"
require "furnace/code/token"
require "furnace/code/terminal_token"
View
2 lib/furnace/graphviz.rb
@@ -1,4 +1,4 @@
-require 'furnace/base'
+require 'furnace'
class Furnace::Graphviz
def initialize
View
13 lib/furnace/transform.rb
@@ -1,13 +0,0 @@
-module Furnace::Transform
-end
-
-require "furnace/transform/pipeline"
-
-require "furnace/transform/rubinius/ast_build"
-require "furnace/transform/rubinius/ast_normalize"
-
-require "furnace/transform/generic/label_normalize"
-require "furnace/transform/generic/cfg_build"
-require "furnace/transform/generic/cfg_normalize"
-
-require "furnace/transform/optimizing/fold_constants"
View
89 lib/furnace/transform/generic/cfg_build.rb
@@ -1,89 +0,0 @@
-module Furnace
- module Transform
- module Generic
- class VariableTracer
- include AST::Visitor
-
- attr_reader :read_set, :write_set
-
- def initialize
- @read_set = Set.new
- @write_set = Set.new
- @conflict = false
- end
-
- def reset
- @read_set.clear
- @write_set.clear
- @conflict = false
- end
-
- def conflict?
- @conflict
- end
-
- def on_set_lvar(node)
- var = node.children.first
-
- @write_set.add var
- @conflict ||= @read_set.include?(var)
- end
-
- def on_get_lvar(node)
- var = node.children.first
-
- @read_set.add var
- @conflict ||= @write_set.include?(var)
- end
- end
-
- class CFGBuild
- def transform(ast, target_map, method)
- cfg = CFG::Graph.new
-
- tracer = VariableTracer.new
-
- ast.children.each do |child|
- label = child.metadata[:label]
-
- # Transfer control to the next operation directly if this
- # is a jump target.
- if target_map.include? label
- cfg.transfer({ nil => label })
- end
-
- # Our CFG must also be easily convertible to ANF/SSA.
- # Split blocks if a non-SSA variable operation is encountered.
- tracer.visit child
-
- if tracer.conflict?
- cfg.transfer({ nil => child.metadata[:label] })
- end
-
- # Expand current operation.
- cfg.expand label, child
-
- # Transfer control non-sequentaly if needed.
- if child.type == :jump
- cfg.transfer({ label => child.children[0] })
- elsif child.type == :jump_if
- cfg.transfer({ label => child.children[0],
- nil => child.next.metadata[:label] })
- elsif child.type == :return
- cfg.transfer({ })
- elsif tracer.conflict?
- # Reset tracer below.
- else
- next
- end
-
- # There was a conflict or a control transfer. Reset the tracer.
- tracer.reset
- end
-
- [ cfg, method ]
- end
- end
- end
- end
-end
View
41 lib/furnace/transform/generic/cfg_normalize.rb
@@ -1,41 +0,0 @@
-module Furnace
- module Transform
- module Generic
- class CFGNormalize
- def transform(cfg, method)
- cfg.nodes.each do |node|
- # If a last operation is an unconditional jump, optimize it out.
- last = node.operations.last
- if last.type == :jump
- edge = node.leaving_edge(last.metadata[:label])
-
- node.operations.delete last
-
- cfg.edges.delete edge
- cfg.edges.add CFG::Edge.new(cfg, nil, node.label, edge.target.label)
- end
-
- # Remove no-ops.
- node.operations.delete_if { |op| op.type == :nop }
- end
-
- # Remove empty nodes.
- cfg.nodes.delete_if do |node|
- if node.operations.empty?
- node.entering_edges.each do |edge|
- edge.target = node.default_leaving_edge.target
- end
- cfg.edges.subtract node.leaving_edges
-
- true
- else
- false
- end
- end
-
- [ cfg, method ]
- end
- end
- end
- end
-end
View
60 lib/furnace/transform/generic/label_normalize.rb
@@ -1,60 +0,0 @@
-module Furnace
- module Transform
- module Generic
- class LabelNormalize
- include AST::Visitor
-
- def transform(ast, method)
- # Find the minimal label in each operation sub-tree.
- # It's the operation entry point.
- visit ast
-
- # Traverse operations in reverse order and bypass all jump_target's,
- # recording the forwarded address in label_map.
- label_map = {}
-
- last_real_operation = nil
- ast.children.reverse.each do |child|
- if child.type == :jump_target
- label = last_real_operation
- else
- label = child.metadata[:label]
- last_real_operation = label
- end
-
- label_map[child.metadata[:label]] = label
- end
-
- # Remove jump_target's.
- ast.children.reject! { |c| c.type == :jump_target }
-
- # Find all jumpable labels and substitute the addresses to forward
- # through jump_target's.
- target_map = []
-
- ast.children.each do |child|
- if child.type == :jump || child.type == :jump_if
- forwarded_target = label_map[child.children[0]]
- child.children[0] = forwarded_target
-
- target_map << forwarded_target
- end
- end
-
- [ ast, target_map, method ]
- end
-
- def on_any(node)
- return if node.type == :root
-
- child_nodes = node.children.select { |c| c.is_a? AST::Node }
-
- new_label = child_nodes.map { |c| c.metadata[:label] }.compact.min
- node.metadata[:label] = new_label if new_label
-
- child_nodes.each { |c| c.metadata.delete :label }
- end
- end
- end
- end
-end
View
19 lib/furnace/transform/optimizing/fold_constants.rb
@@ -1,19 +0,0 @@
-module Furnace
- module Transform
- module Optimizing
- class FoldConstants
- def transform(anf, method)
- anf.nodes.each do |node|
- if node.is_a? ANF::LetNode
- node.try_propagate
- node.try_eliminate
- end
- end
- anf.eliminate_dead_code
-
- [ anf, method ]
- end
- end
- end
- end
-end
View
53 lib/furnace/transform/rubinius/ast_build.rb
@@ -1,53 +0,0 @@
-module Furnace
- module Transform
- module Rubinius
- class ASTBuild
- def transform(method)
- stack = []
- map = {}
- serial = 0
-
- ast = AST::Node.new(:root)
-
- method.decode.each do |opcode|
- ins = opcode.instruction
-
- node = AST::Node.new("rbx_#{ins.opcode}")
- node.metadata[:label] = opcode.ip
- node.children += opcode.args
-
- # Compute the real value of consumed values.
- case ins.stack_consumed
- when Fixnum
- consumed = ins.stack_consumed
- when Array
- #p ins.stack_consumed, opcode.args
- consumed = ins.stack_consumed[0] + opcode.args.last
- end
-
- # Pop consumed values and attach to current node.
- consumed.times.map { map[stack.pop] }.reverse.each do |child|
- child.parent = node
- node.children << child
- end
-
- # Push back and map the results.
- if ins.stack_produced == 0 || ins.opcode == :ret
- node.parent = ast
- ast.children << node
- elsif ins.stack_produced == 1
- map[serial] = node
- stack.push serial
-
- serial += 1
- else
- raise RuntimeError, "don't know what to do with opcode #{opcode.inspect}"
- end
- end
-
- [ ast, method ]
- end
- end
- end
- end
-end
View
170 lib/furnace/transform/rubinius/ast_normalize.rb
@@ -1,170 +0,0 @@
-module Furnace
- module Transform
- module Rubinius
- class ASTNormalize
- include AST::Visitor
-
- def transform(ast, method)
- @locals = method.local_names
- @literals = method.literals
-
- visit ast
-
- [ ast, method ]
- end
-
- # (rbx-meta-push-0) -> 0
- def on_rbx_meta_push_0(node)
- node.update(:fixnum, [0], :constant => true)
- end
-
- # (rbx-meta-push-1) -> 1
- def on_rbx_meta_push_1(node)
- node.update(:fixnum, [1], :constant => true)
- end
-
- # (rbx-meta-push-2) -> 2
- def on_rbx_meta_push_2(node)
- node.update(:fixnum, [2], :constant => true)
- end
-
- # (rbx-push-int f) -> f
- def on_rbx_push_int(node)
- node.update(:fixnum, nil, :constant => true)
- end
-
- # (rbx-push-literal l) -> l
- def on_rbx_push_literal(node)
- node.update(:literal, nil, :constant => true)
- end
-
- # (rbx-push-nil) -> (nil)
- def on_rbx_push_nil(node)
- node.update(:nil, nil, :constant => true)
- end
-
- # (rbx-string-dup s) -> (dup s)
- def on_rbx_string_dup(node)
- node.update(:dup)
- end
-
- # (rbx-pop x) -> x
- def on_rbx_pop(node)
- child = node.children.first
- child.update(:nop) if child.metadata[:constant]
-
- node.update(:expand, [
- child,
- AST::Node.new(:jump_target, [], node.metadata)
- ], nil)
- end
-
- # (rbx-*) -> .
- def make_jump_target(node)
- node.update(:jump_target)
- end
- alias :on_rbx_check_interrupts :make_jump_target
- alias :on_rbx_allow_private :make_jump_target
-
- # (rbx-push-self) -> (self)
- def on_rbx_push_self(node)
- node.update(:self)
- end
-
- # (rbx-push-local n) -> (get-local n)
- def on_rbx_push_local(node)
- node.update(:get_lvar, [ @locals[node.children.first] ])
- end
-
- # (rbx-set-local n v) -> (set-local n v)
- def on_rbx_set_local(node)
- node.update(:set_lvar, [ @locals[node.children.first], node.children.last ])
- end
-
- # (rbx-push-ivar n) -> (get-ivar n)
- def on_rbx_push_ivar(node)
- node.update(:get_ivar, [ @literals[node.children.first] ])
- end
-
- # (rbx-set-ivar n v) -> (set-ivar n v)
- def on_rbx_set_ivar(node)
- node.update(:set_ivar, [ @literals[node.children.first], node.children.last ])
- end
-
- # (rbx-push-const-fast n x) -> (const n)
- def on_rbx_push_const_fast(node)
- node.update(:const, [ node.children.first ])
- end
-
- # (rbx-find-const n c) -> (const n c)
- def on_rbx_find_const(node)
- node.update(:const, [ @literals[node.children.first], node.children.last ])
- end
-
- # (rbx-ret x) -> (return x)
- def on_rbx_ret(node)
- node.update(:return)
- end
-
- # (rbx-send-method msg receiver) -> (send msg receiver)
- def on_rbx_send_method(node)
- node.update(:send, [
- AST::MethodName.new(node.children[0]),
- node.children[1]
- ])
- end
-
- # (rbx-send-stack msg count receiver args...) -> (send msg receiver args...)
- def on_rbx_send_stack(node)
- node.update(:send, [
- AST::MethodName.new(node.children[0]), # message
- node.children[2], # receiver
- *node.children[3..-1] # args
- ])
- end
-
- # (rbx-send-stack-with-block msg count receiver args... block) -> (send-with-block msg receiver args... block)
- def on_rbx_send_stack_with_block(node)
- node.update(:send_with_block, [
- AST::MethodName.new(node.children[0]), # message
- node.children[2], # receiver
- *node.children[3..-1] # args
- ])
- end
-
- # (rbx-create-block block) -> (lambda block)
- def on_rbx_create_block(node)
- $block = node.children.first
- node.update(:lambda, [ "FAIL" ])
- end
-
- # (rbx-meta-* op receiver arg) -> (send op receiver arg)
- def on_rbx_send_op_any(node)
- node.update(:send, [
- AST::MethodName.new(node.children[0]),
- *node.children[1..-1]
- ])
- end
- alias :on_rbx_meta_send_op_plus :on_rbx_send_op_any
- alias :on_rbx_meta_send_op_minus :on_rbx_send_op_any
- alias :on_rbx_meta_send_op_gt :on_rbx_send_op_any
- alias :on_rbx_meta_send_op_lt :on_rbx_send_op_any
- alias :on_rbx_meta_to_s :on_rbx_send_op_any
-
- # (rbx-goto-if-* block condition) -> (jump-if block value condition)
- def on_rbx_goto_if_false(node)
- node.update(:jump_if, [ node.children[0], false, node.children[1] ])
- end
-
- def on_rbx_goto_if_true(node)
- node.update(:jump_if, [ node.children[0], true, node.children[1] ])
- end
-
- # (rbx-goto block) -> (jump block)
- def on_rbx_goto(node)
- node.update(:jump)
- end
- end
- end
- end
-end
View
2 lib/furnace/version.rb
@@ -1,3 +1,3 @@
module Furnace
- VERSION = "0.1.2"
+ VERSION = "0.2.0"
end

0 comments on commit 6264b79

Please sign in to comment.
Something went wrong with that request. Please try again.