Simplify, fixing an apparent bug in the process.

This commit is contained in:
Chris Pressey 2019-10-22 12:42:17 +01:00
parent 565f959ee2
commit 987974cc21
3 changed files with 8 additions and 6 deletions

View File

@ -141,11 +141,12 @@ class Analyzer(object):
def analyze_program(self, program):
assert isinstance(program, Program)
for routine in program.routines:
routine.called_routines = set()
context, type_ = self.analyze_routine(routine)
if type_:
routine.routine_type = type_
routine.encountered_gotos = list(context.encountered_gotos()) if context else []
routine.called_routines = list(context.called_routines) if context else []
routine.called_routines = list(routine.called_routines)
def analyze_routine(self, routine):
assert isinstance(routine, Routine)
@ -520,7 +521,9 @@ class Analyzer(object):
type_ = self.get_type(instr.location)
if not isinstance(type_, (RoutineType, VectorType)):
raise TypeMismatchError(instr, instr.location.name)
context.mark_as_called(instr.location, type_)
self.current_routine.called_routines.add((instr.location, type_))
if isinstance(type_, VectorType):
type_ = type_.of_type
for ref in type_.inputs:
@ -538,7 +541,8 @@ class Analyzer(object):
if not isinstance(type_, (RoutineType, VectorType)):
raise TypeMismatchError(instr, location.name)
context.mark_as_called(instr.location, type_)
self.current_routine.called_routines.add((instr.location, type_))
# assert that the dest routine's inputs are all initialized
if isinstance(type_, VectorType):

View File

@ -36,6 +36,7 @@ def construct_callgraph(program):
}
# Reflexive closure
# (Note, this information isn't used anywhere yet)
for routine in program.routines:
potentially_called_by = []

View File

@ -329,6 +329,3 @@ class AnalysisContext(object):
return self.symtab.fetch_local_type(self.routine.name, ref.name).max_range
else:
return self.symtab.fetch_global_type(ref.name).max_range
def mark_as_called(self, location, type_):
self.called_routines.add((location, type_))