Created
November 16, 2021 10:30
-
-
Save geor-kasapidi/2cb9341a76e4dc0e004905cfd84137df to your computer and use it in GitHub Desktop.
Metal AST
This file contains hidden or 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
import sys | |
import os | |
import clang.cindex | |
shaders_file = sys.argv[1] | |
assert(shaders_file.endswith(“.metal”)) | |
ast_file = shaders_file.rstrip(“.metal”) + “.ast” | |
os.system(f”xcrun metal -emit-ast {shaders_file}“) | |
xcode_path = os.popen(“xcode-select -p”).read().rstrip() | |
clang.cindex.Config.set_library_file(f”{xcode_path}/Toolchains/XcodeDefault.xctoolchain/usr/metal/macos/lib/metalfe/libmetal.dylib”) | |
index = clang.cindex.Index.create() | |
tu = index.read(ast_file) | |
print(‘Translation unit:’, tu.spelling) | |
# for i in tu.get_tokens(extent=tu.cursor.extent): | |
# print(i.kind) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment