Skip to content

Commit

Permalink
Fix mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
Fidget-Spinner committed Jan 21, 2025
1 parent 2082537 commit 5cccb98
Showing 1 changed file with 0 additions and 105 deletions.
105 changes: 0 additions & 105 deletions Tools/cases_generator/labels_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,125 +7,20 @@

from analyzer import (
Analysis,
Instruction,
Uop,
Part,
analyze_files,
Skip,
Flush,
analysis_error,
StackItem,
)
from generators_common import (
DEFAULT_INPUT,
ROOT,
write_header,
type_and_null,
Emitter,
)
from cwriter import CWriter
from typing import TextIO
from stack import Local, Stack, StackError, get_stack_effect, Storage


DEFAULT_OUTPUT = ROOT / "Python/generated_labels.c.h"



def declare_variable(var: StackItem, out: CWriter) -> None:
type, null = type_and_null(var)
space = " " if type[-1].isalnum() else ""
if var.condition:
out.emit(f"{type}{space}{var.name} = {null};\n")
else:
out.emit(f"{type}{space}{var.name};\n")


def declare_variables(inst: Instruction, out: CWriter) -> None:
try:
stack = get_stack_effect(inst)
except StackError as ex:
raise analysis_error(ex.args[0], inst.where) from None
required = set(stack.defined)
required.discard("unused")
for part in inst.parts:
if not isinstance(part, Uop):
continue
for var in part.stack.inputs:
if var.name in required:
required.remove(var.name)
declare_variable(var, out)
for var in part.stack.outputs:
if var.name in required:
required.remove(var.name)
declare_variable(var, out)


def write_uop(
uop: Part,
emitter: Emitter,
offset: int,
stack: Stack,
inst: Instruction,
braces: bool,
) -> tuple[int, Stack]:
# out.emit(stack.as_comment() + "\n")
if isinstance(uop, Skip):
entries = "entries" if uop.size > 1 else "entry"
emitter.emit(f"/* Skip {uop.size} cache {entries} */\n")
return (offset + uop.size), stack
if isinstance(uop, Flush):
emitter.emit(f"// flush\n")
stack.flush(emitter.out)
return offset, stack
try:
locals: dict[str, Local] = {}
emitter.out.start_line()
if braces:
emitter.out.emit(f"// {uop.name}\n")
emitter.emit("{\n")
code_list, storage = Storage.for_uop(stack, uop)
emitter._print_storage(storage)
for code in code_list:
emitter.emit(code)

for cache in uop.caches:
if cache.name != "unused":
if cache.size == 4:
type = "PyObject *"
reader = "read_obj"
else:
type = f"uint{cache.size*16}_t "
reader = f"read_u{cache.size*16}"
emitter.emit(
f"{type}{cache.name} = {reader}(&this_instr[{offset}].cache);\n"
)
if inst.family is None:
emitter.emit(f"(void){cache.name};\n")
offset += cache.size

storage = emitter.emit_tokens(uop, storage, inst)
if braces:
emitter.out.start_line()
emitter.emit("}\n")
# emitter.emit(stack.as_comment() + "\n")
return offset, storage.stack
except StackError as ex:
raise analysis_error(ex.args[0], uop.body[0])


def uses_this(inst: Instruction) -> bool:
if inst.properties.needs_this:
return True
for uop in inst.parts:
if not isinstance(uop, Uop):
continue
for cache in uop.caches:
if cache.name != "unused":
return True
return False


def generate_labels(
filenames: list[str], analysis: Analysis, outfile: TextIO
) -> None:
Expand Down

0 comments on commit 5cccb98

Please sign in to comment.