Skip to content

Commit

Permalink
Helper for creating benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinprasadme committed May 26, 2023
1 parent 9319c17 commit 1fd812b
Show file tree
Hide file tree
Showing 2 changed files with 5,083 additions and 0 deletions.
44 changes: 44 additions & 0 deletions scripts/get_identifiers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import ast
import symtable
from pathlib import Path


def describe_symtable(st, recursive=True, indent=0):
def print_d(s, *args):
prefix = " " * indent
print(prefix + s, *args)

assert isinstance(st, symtable.SymbolTable)
print_d("Symtable: type=%s, name=%s" % (st.get_type(), st.get_name()))
print_d(" identifiers:", list(st.get_identifiers()))

if recursive:
for child_st in st.get_children():
describe_symtable(child_st, recursive, indent + 5)


in_py_path = "../micro-benchmark"
for _file in sorted(Path(in_py_path).rglob("*.py")):
# Create a dictionary to store line numbers for identifiers
identifiers = {}
print(_file.parts[-4:])
describe_symtable(
symtable.symtable(_file.read_text(), _file.name, compile_type="exec")
)

# Parse the code into an AST (Abstract Syntax Tree)
tree = ast.parse(_file.read_text())

# Traverse the AST and extract line numbers for identifiers
for node in ast.walk(tree):
if isinstance(node, ast.Name):
identifier = node.id
lineno = node.lineno
if identifier in identifiers:
identifiers[identifier].append(lineno)
else:
identifiers[identifier] = [lineno]

print("\n")
print(identifiers)
print("\n\n###########################\n\n")
Loading

0 comments on commit 1fd812b

Please sign in to comment.