Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
06dec9c
{JsonParser,ToJson}.java: Started implementing serialize/deserialize …
Jun 18, 2019
333cc19
{JsonParser,ToJson}.java,outer.scala: Serializing work is done, deser…
Jun 19, 2019
ca9167e
kernel/.../{Kompile,KompileOptions}: `--input json` allows feeding in…
ehildenb Aug 22, 2019
d834935
kernel/.../{Kompile,KompileOptions}: `--emit-json` will dump JSON enc…
ehildenb Aug 22, 2019
dcf026c
k-distribution/regression-new: test that --emit-json works
ehildenb Aug 22, 2019
03bed22
JsonParser.java: Now uses FlatModule to assist in deseralizing defini…
Jul 2, 2019
d995f5c
kore/outer-ext, kernel/JsonParser: remove uneeded hasName
ehildenb Aug 23, 2019
bc20ed0
kore/outer.scala: remove unused functions
ehildenb Aug 23, 2019
691406c
kore/outer: simplify flatModules
ehildenb Aug 23, 2019
e4a8d02
kernel/ToJson: write FlatModule to Json, not Module
ehildenb Aug 23, 2019
a318f34
k-distribution/regression-new/imp-json: smaller definition
ehildenb Aug 23, 2019
581a92b
kernel/{ToJson,JsonParser}: use FLATMODULE key for flattened modules
ehildenb Aug 23, 2019
4c111a6
kernel/ToJson: simpler foreach iterators
ehildenb Aug 23, 2019
3439481
kernel/.../JsonParser: inline several definitions, prefer in-place it…
ehildenb Aug 23, 2019
4bcfebb
kernel/JsonParser: implement KSYNTAXASSOCIATIVITY
ehildenb Aug 23, 2019
bcabf8f
kernel/JsonParser: implment KCONFIGURATION, KBUBBLE, KSYNTAXSORT
ehildenb Aug 23, 2019
42cf0e6
kernel/ToJson: factor out toJson : ProductionItem -> JsonObject
ehildenb Aug 23, 2019
c63af1f
kernel/JsonParser: add case for KPRODUCTION
ehildenb Aug 23, 2019
e406959
kernel/Kompile: better error handling for unsupported input modes
ehildenb Aug 25, 2019
b44d0be
kernel/{Kompile,JsonParser}: parseDef => parseDefinition, more inform…
ehildenb Aug 25, 2019
e20e26d
kore/outer.scala: flattened module only has direct imports
ehildenb Aug 25, 2019
f0974fa
kernel/{JsonParser,ToJson}: entryModules => modules for modules in de…
ehildenb Aug 25, 2019
3978694
k-distribution/pyk/kastManip: add function splitConfigFrom for gettin…
ehildenb Sep 12, 2019
7f7f13e
k-distribution/pyk/__init__.py: much faster serialization of json to …
ehildenb Sep 12, 2019
e589766
kernel/{Kompile,KompileOptions}: remote --input option for now
ehildenb Sep 12, 2019
cf3360e
k-distribution/tests/regression-new/imp-json: shorter file
ehildenb Sep 12, 2019
a11bf45
kernel/{Kompile,KompileOptions}: move --emit-json to experimental opt…
ehildenb Sep 13, 2019
70b46ab
Merge branch 'master' into JsonDefinitions
ehildenb Sep 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions k-distribution/src/main/scripts/lib/pyk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ def kprove(definition, inputFile, kproveArgs = [], teeOutput = True, kRelease =

def kastJSON(definition, inputJSON, kastArgs = [], teeOutput = True, kRelease = None):
with tempfile.NamedTemporaryFile(mode = 'w') as tempf:
json.dump(inputJSON, tempf)
tempf.write(json.dumps(inputJSON))
tempf.flush()
return kast(definition, tempf.name, kastArgs = kastArgs, teeOutput = teeOutput, kRelease = kRelease)

def krunJSON(definition, inputJSON, krunArgs = [], teeOutput = True, kRelease = None):
with tempfile.NamedTemporaryFile(mode = 'w') as tempf:
json.dump(inputJSON, tempf)
tempf.write(json.dumps(inputJSON))
tempf.flush()
(rC, out, err) = krun(definition, tempf.name, krunArgs = krunArgs + ['--output', 'json', '--parser', 'cat'], teeOutput = teeOutput, kRelease = kRelease)
out = None if out == '' else json.loads(out)['term']
Expand Down
13 changes: 13 additions & 0 deletions k-distribution/src/main/scripts/lib/pyk/kastManip.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ def flattenLabel(label, kast):
return [ c for cs in constraints for c in cs ]
return [kast]

def splitConfigFrom(configuration):
initial_substitution = {}
_mkCellVar = lambda label: label.replace('-', '_').replace('<', '').replace('>', '').upper() + '_CELL'
def _replaceWithVar(k):
if pyk.isKApply(k) and pyk.isCellKLabel(k['label']):
if len(k['args']) == 1 and not (pyk.isKApply(k['args'][0]) and pyk.isCellKLabel(k['args'][0]['label'])):
config_var = _mkCellVar(k['label'])
initial_substitution[config_var] = k['args'][0]
return KApply(k['label'], [KVariable(config_var)])
return k
symbolic_config = pyk.traverseBottomUp(configuration, _replaceWithVar)
return (symbolic_config, initial_substitution)

def collapseDots(kast):
def _collapseDots(_kast):
if isKApply(_kast):
Expand Down
7 changes: 7 additions & 0 deletions k-distribution/tests/regression-new/imp-json/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DEF=imp
EXT=imp
TESTDIR=.
KOMPILE_BACKEND?=llvm
KOMPILE_FLAGS=--emit-json

include ../../../include/ktest.mak
68 changes: 68 additions & 0 deletions k-distribution/tests/regression-new/imp-json/imp.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) 2014-2019 K Team. All Rights Reserved.

module IMP-SYNTAX
imports DOMAINS-SYNTAX

syntax AExp ::= Int | Id
| "-" Int [format(%1%2)]
| AExp "/" AExp [left, strict, color(pink)]
> AExp "+" AExp [left, strict, color(pink)]
| "(" AExp ")" [bracket]
syntax BExp ::= Bool
| AExp "<=" AExp [seqstrict, latex({#1}\leq{#2}), color(pink)]
| "!" BExp [strict, color(pink)]
> BExp "&&" BExp [left, strict(1), color(pink)]
| "(" BExp ")" [bracket]
syntax Block ::= "{" "}"
| "{" Stmt "}" [format(%1%i%n%2%d%n%3)]
syntax Stmt ::= Block
| Id "=" AExp ";" [strict(2), color(pink), format(%1 %2 %3%4)]
| "if" "(" BExp ")"
Block "else" Block [strict(1), colors(yellow, white, white, yellow), format(%1 %2%3%4 %5 %6 %7)]
| "while" "(" BExp ")" Block [colors(yellow,white,white), format(%1 %2%3%4 %5)]
> Stmt Stmt [left, format(%1%n%2)]

syntax Pgm ::= "int" Ids ";" Stmt [format(%1 %2%3%n%4), colors(yellow,pink)]
syntax Ids ::= List{Id,","} [format(%1%2 %3)]
endmodule

module IMP
imports IMP-SYNTAX
imports INT
imports BOOL
imports MAP

syntax KResult ::= Int | Bool

configuration <T color="yellow">
<k color="green"> $PGM:Pgm </k>
<state color="red"> .Map </state>
</T>

rule <k> X:Id => I ...</k> <state>... X |-> I ...</state>

rule I1 / I2 => I1 /Int I2 requires I2 =/=Int 0
rule I1 + I2 => I1 +Int I2
rule - I1 => 0 -Int I1

rule I1 <= I2 => I1 <=Int I2
rule ! T => notBool T
rule true && B => B
rule false && _ => false

rule {} => . [structural]
rule {S} => S [structural]

rule <k> X = I:Int; => . ...</k> <state>... X |-> (_ => I) ...</state>

rule S1:Stmt S2:Stmt => S1 ~> S2 [structural]

rule if (true) S else _ => S
rule if (false) _ else S => S

rule while (B) S => if (B) {S while (B) S} else {} [structural]

rule <k> int (X,Xs => Xs);_ </k> <state> Rho:Map (.Map => X|->0) </state>
requires notBool (X in keys(Rho))
rule int .Ids; S => S [structural]
endmodule
11 changes: 11 additions & 0 deletions kernel/src/main/java/org/kframework/kompile/Kompile.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.kframework.kore.Sort;
import org.kframework.parser.concrete2kore.ParserUtils;
import org.kframework.parser.concrete2kore.generator.RuleGrammarGenerator;
import org.kframework.unparser.ToJson;
import org.kframework.utils.Stopwatch;
import org.kframework.utils.errorsystem.KEMException;
import org.kframework.utils.errorsystem.KExceptionManager;
Expand All @@ -31,6 +32,7 @@
import scala.Function1;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
Expand Down Expand Up @@ -126,6 +128,15 @@ public CompiledDefinition run(File definitionFile, String mainModuleName, String
files.saveToKompiled("compiled.txt", kompiledDefinition.toString());
sw.printIntermediate("Apply compile pipeline");

if (kompileOptions.experimental.emitJson) {
try {
files.saveToKompiled("parsed.json", new String(ToJson.apply(parsedDef), "UTF-8"));
files.saveToKompiled("compiled.json", new String(ToJson.apply(kompiledDefinition), "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw KEMException.criticalError("Unsupported encoding `UTF-8` when saving JSON definition.");
}
}

ConfigurationInfoFromModule configInfo = new ConfigurationInfoFromModule(kompiledDefinition.mainModule());

return new CompiledDefinition(kompileOptions, parsedDef, kompiledDefinition, files, kem, configInfo.getDefaultCell(configInfo.getRootCell()).klabel());
Expand Down
18 changes: 18 additions & 0 deletions kernel/src/main/java/org/kframework/kompile/KompileOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParametersDelegate;
import org.apache.commons.io.FilenameUtils;

import org.kframework.backend.Backends;
import org.kframework.main.GlobalOptions;
import org.kframework.unparser.OutputModes;
import org.kframework.utils.file.FileUtil;
import org.kframework.utils.inject.RequestScoped;
import org.kframework.utils.options.OuterParsingOptions;
import org.kframework.utils.options.SMTOptions;
import org.kframework.utils.options.BaseEnumConverter;
import org.kframework.utils.options.StringListConverter;

import java.io.Serializable;
Expand Down Expand Up @@ -83,6 +86,18 @@ public boolean isKore() {
return backend.equals("kore") || backend.equals("haskell") || backend.equals("llvm");
}

public static class OutputModeConverter extends BaseEnumConverter<OutputModes> {

public OutputModeConverter(String optionName) {
super(optionName);
}

@Override
public Class<OutputModes> enumClass() {
return OutputModes.class;
}
}

public static final class Experimental implements Serializable {

// Experimental options
Expand Down Expand Up @@ -112,5 +127,8 @@ public static final class Experimental implements Serializable {

@Parameter(names="--cache-file", description="Location of parse cache file. Default is $KOMPILED_DIR/cache.bin.")
public String cacheFile;

@Parameter(names="--emit-json", description="Emit JSON serialized version of parsed and kompiled definitions.")
public boolean emitJson = false;
}
}
Loading