Created
February 21, 2014 16:19
-
-
Save xl1/9137272 to your computer and use it in GitHub Desktop.
GLSL AST の絵をかく
This file contains 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
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() |
This file contains 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
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