Shopify / seafoam

A tool for working with compiler graphs dumped by the GraalVM compiler
MIT License
126 stars 22 forks source link

Write a command to convert a graph to pseudo-Ruby code #2

Closed chrisseaton closed 4 years ago

chrisseaton commented 5 years ago

Reading and understanding graphs is hard - maybe reading pseudo-Ruby code would be easier.

$ seafoam decompile examples/fib-java.bgv:0
def fib(p0)
  if p0 < 2
    return p0
  else
    temp1 = Fib.fib(p0 - 1)
    temp2 = Fib.fib(p0 - 2)
    return temp1 - temp2
  end
end

Related work we can build from is this old Graal to JS backend https://www.davidleopoldseder.com/publications/aotjs_dsl_paper_authorversion.pdf.

I'd focus on Java graphs when getting started, as they're simpler.

chrisseaton commented 5 years ago

The classic clamp benchmark would work fantastically for this - Graal successfully compiles it to equivalent if code, which would render perfectly as runnable Ruby code!

def clamp(min, max, value)
  [min, max, value].sort[0]
end

loop do
  clamp(1, 3, 4)
  clamp(2, 2, 7)
  clamp(5, 1, 8)
  clamp(2, 4, 9)
end
$ bundle exec bin/seafoam render clamp.bgv:8 -o clamp.png

clamp

clamp.bgv.zip

chrisseaton commented 4 years ago

@XrXr made initial progress on this in the past. I've pushed something working fairly well to master now.