Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* k-distribution/pyk: pass symbol table through to recursive prettyPrintKast * kore/outer.scala: FlatModules should store localSentences, not all sentences * k-distribution/pyk/kast: add getAttribute function * k-distribution/pyk/kast: handle KProduction for addAttributes * k-distribution/pyk/kast: handle remaining cases for prettyPrintKast * pyk/__main__.py: add initial definition minimizer * pyk: move definition minimizer into place * k-distribution/pyk/__main__: switch to proper subcommand parsing * k-distribution/pyk/__main__: fix arguments for coverage command * k-distribution/tests/pyk: update coverage log test * k-distribution/pyk: working removal of log calls from rules * k-distribution/pyk: minimize rules too * k-distribution/tests/pyk: add test that definition minimization works * k-distribution/pyk: remove main interface to definition minimizer * k-distribution/pyk/definition: remove unneeded code Co-authored-by: rv-jenkins <admin@runtimeverification.com>
- Loading branch information
1 parent
4f0443a
commit 30db060
Showing
8 changed files
with
220 additions
and
73 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import subprocess | ||
|
||
from .kast import * | ||
from .kastManip import * | ||
from .kast import _notif, _warning, _fatal | ||
|
||
def ruleHasId(sentence, ruleIds): | ||
if isKRule(sentence): | ||
ruleId = getAttribute(sentence, 'UNIQUE_ID') | ||
return ruleId is not None and ruleId in ruleIds | ||
return True | ||
|
||
def syntaxHasKLabel(sentence, klabels): | ||
if isKProduction(sentence) and 'klabel' in sentence: | ||
return sentence['klabel'] in klabels | ||
return True | ||
|
||
def keepSentences(kOuter, filter): | ||
att = None if 'att' not in kOuter else kOuter['att'] | ||
if isKDefinition(kOuter): | ||
newModules = [ keepSentences(mod, filter) for mod in kOuter['modules'] ] | ||
requires = None if 'requires' not in kOuter else kOuter['requires'] | ||
return KDefinition(kOuter['mainModule'], newModules, requires = requires, att = att) | ||
elif isKFlatModule(kOuter): | ||
newSentences = [ sent for sent in kOuter['localSentences'] if filter(sent) ] | ||
return KFlatModule(kOuter['name'], kOuter['imports'], newSentences, att = att) | ||
else: | ||
return kOuter | ||
|
||
def collectKLabels(kast): | ||
labels = [] | ||
def _collectKLabels(_kast): | ||
if isKApply(_kast): | ||
labels.append(_kast['label']) | ||
collectBottomUp(kast, _collectKLabels) | ||
return labels | ||
|
||
def collectKLabelsFromRules(definition): | ||
used_labels = [] | ||
for module in definition['modules']: | ||
for sentence in module['localSentences']: | ||
if isKRule(sentence): | ||
used_labels += collectKLabels(sentence['body']) | ||
return used_labels | ||
|
||
def minimizeDefinition(definition, rulesList): | ||
new_definition = keepDefinitionModulesOnly(definition) | ||
new_definition = keepSentences(new_definition, lambda sent: ruleHasId(sent, rulesList)) | ||
used_labels = collectKLabelsFromRules(new_definition) | ||
new_definition = keepSentences(new_definition, lambda sent: syntaxHasKLabel(sent, used_labels)) | ||
return new_definition |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/kast-tests/*.gen | ||
/llvm | ||
/haskell | ||
/kpyk-tests/*.coverage |
Oops, something went wrong.