MCPcopy Index your code
hub / github.com/python/cpython / analyze_forest

Function analyze_forest

Tools/cases_generator/analyzer.py:1314–1364  ·  view source on GitHub ↗
(forest: list[parser.AstNode])

Source from the content-addressed store, hash-verified

1312
1313
1314def analyze_forest(forest: list[parser.AstNode]) -> Analysis:
1315 instructions: dict[str, Instruction] = {}
1316 uops: dict[str, Uop] = {}
1317 families: dict[str, Family] = {}
1318 pseudos: dict[str, PseudoInstruction] = {}
1319 labels: dict[str, Label] = {}
1320 for node in forest:
1321 match node:
1322 case parser.InstDef(name):
1323 if node.kind == "inst":
1324 desugar_inst(node, instructions, uops)
1325 else:
1326 assert node.kind == "op"
1327 add_op(node, uops)
1328 case parser.Macro():
1329 pass
1330 case parser.Family():
1331 pass
1332 case parser.Pseudo():
1333 pass
1334 case parser.LabelDef():
1335 pass
1336 case _:
1337 assert False
1338 for node in forest:
1339 if isinstance(node, parser.Macro):
1340 add_macro(node, instructions, uops)
1341 for node in forest:
1342 match node:
1343 case parser.Family():
1344 add_family(node, instructions, families)
1345 case parser.Pseudo():
1346 add_pseudo(node, instructions, pseudos)
1347 case parser.LabelDef():
1348 add_label(node, labels)
1349 case _:
1350 pass
1351 for uop in uops.values():
1352 uop.instruction_size = get_instruction_size_for_uop(instructions, uop)
1353 # Special case BINARY_OP_INPLACE_ADD_UNICODE
1354 # BINARY_OP_INPLACE_ADD_UNICODE is not a normal family member,
1355 # as it is the wrong size, but we need it to maintain an
1356 # historical optimization.
1357 if "BINARY_OP_INPLACE_ADD_UNICODE" in instructions:
1358 inst = instructions["BINARY_OP_INPLACE_ADD_UNICODE"]
1359 inst.family = families["BINARY_OP"]
1360 families["BINARY_OP"].members.append(inst)
1361 opmap, first_arg, min_instrumented = assign_opcodes(instructions, families, pseudos)
1362 return Analysis(
1363 instructions, uops, families, pseudos, labels, opmap, first_arg, min_instrumented
1364 )
1365
1366
1367#Simple heuristic for size to avoid too much stencil duplication

Callers 1

analyze_filesFunction · 0.85

Calls 11

desugar_instFunction · 0.85
add_opFunction · 0.85
add_macroFunction · 0.85
add_familyFunction · 0.85
add_pseudoFunction · 0.85
add_labelFunction · 0.85
assign_opcodesFunction · 0.85
AnalysisClass · 0.70
valuesMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…