Skip to content

Instantly share code, notes, and snippets.

@xl1
Created February 21, 2014 16:19
Show Gist options
  • Save xl1/9137272 to your computer and use it in GitHub Desktop.
Save xl1/9137272 to your computer and use it in GitHub Desktop.
GLSL AST の絵をかく
fs = require 'fs'
tokenizer = require 'glsl-tokenizer'
parser = require 'glsl-parser'
through = require 'through'
{ exec } = require 'child_process'
transform = (node) ->
result = []
walk = (n, path) =>
path += '/' + n.id
result.push " \"#{path}\" [label = \"#{n.type}:#{n.token.data}\"];"
for child in n.children or []
if child.type is 'placeholder'
continue
result.push " \"#{path}\" -> \"#{path}/#{child.id}\";"
walk child, path
if (not node.parent) or node.parent.parent
return
result.push 'digraph {'
walk node, ''
result.push '}'
@queue result.join '\n'
main = ->
fs.createReadStream 'source.glsl', encoding: 'utf-8'
.pipe tokenizer()
.pipe parser()
.pipe through transform
.pipe fs.createWriteStream 'dest.dot', encoding: 'utf-8'
.on 'finish', -> exec 'dot -Tpng -oresult.png dest.dot', (e, out, err) ->
console.log out + err
main()
void main () {
vec3 black = vec3(0.0);
gl_FragColor = vec4(black, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment