use of org.apache.sysml.parser.LanguageException in project incubator-systemml by apache.
the class CommonSyntacticValidator method setAssignmentStatement.
protected void setAssignmentStatement(ParserRuleContext ctx, StatementInfo info, DataIdentifier target, Expression expression) {
try {
info.stmt = new AssignmentStatement(target, expression, ctx.start.getLine(), ctx.start.getCharPositionInLine(), ctx.start.getLine(), ctx.start.getCharPositionInLine());
setFileLineColumn(info.stmt, ctx);
} catch (LanguageException e) {
// TODO: extract more meaningful info from this exception.
notifyErrorListeners("invalid function call", ctx.start);
return;
}
}
use of org.apache.sysml.parser.LanguageException in project incubator-systemml by apache.
the class Connection method prepareScript.
/**
* Prepares (precompiles) a script, sets input parameter values, and registers input and output variables.
*
* @param script string representing the DML or PyDML script
* @param args map of input parameters ($) and their values
* @param inputs string array of input variables to register
* @param outputs string array of output variables to register
* @param parsePyDML {@code true} if PyDML, {@code false} if DML
* @return PreparedScript object representing the precompiled script
*/
public PreparedScript prepareScript(String script, Map<String, String> args, String[] inputs, String[] outputs, boolean parsePyDML) {
DMLScript.SCRIPT_TYPE = parsePyDML ? ScriptType.PYDML : ScriptType.DML;
// check for valid names of passed arguments
String[] invalidArgs = args.keySet().stream().filter(k -> k == null || !k.startsWith("$")).toArray(String[]::new);
if (invalidArgs.length > 0)
throw new LanguageException("Invalid argument names: " + Arrays.toString(invalidArgs));
// check for valid names of input and output variables
String[] invalidVars = UtilFunctions.asSet(inputs, outputs).stream().filter(k -> k == null || k.startsWith("$")).toArray(String[]::new);
if (invalidVars.length > 0)
throw new LanguageException("Invalid variable names: " + Arrays.toString(invalidVars));
setLocalConfigs();
// simplified compilation chain
Program rtprog = null;
try {
// parsing
ParserWrapper parser = ParserFactory.createParser(parsePyDML ? ScriptType.PYDML : ScriptType.DML);
DMLProgram prog = parser.parse(null, script, args);
// language validate
DMLTranslator dmlt = new DMLTranslator(prog);
dmlt.liveVariableAnalysis(prog);
dmlt.validateParseTree(prog);
// hop construct/rewrite
dmlt.constructHops(prog);
dmlt.rewriteHopsDAG(prog);
// rewrite persistent reads/writes
RewriteRemovePersistentReadWrite rewrite = new RewriteRemovePersistentReadWrite(inputs, outputs);
ProgramRewriter rewriter2 = new ProgramRewriter(rewrite);
rewriter2.rewriteProgramHopDAGs(prog);
// lop construct and runtime prog generation
dmlt.constructLops(prog);
rtprog = dmlt.getRuntimeProgram(prog, _dmlconf);
// final cleanup runtime prog
JMLCUtils.cleanupRuntimeProgram(rtprog, outputs);
} catch (ParseException pe) {
// don't chain ParseException (for cleaner error output)
throw pe;
} catch (Exception ex) {
throw new DMLException(ex);
}
// return newly create precompiled script
return new PreparedScript(rtprog, inputs, outputs, _dmlconf, _cconf);
}
use of org.apache.sysml.parser.LanguageException in project incubator-systemml by apache.
the class ScriptExecutor method rewritePersistentReadsAndWrites.
/**
* Replace persistent reads and writes with transient reads and writes in
* the symbol table.
*/
protected void rewritePersistentReadsAndWrites() {
LocalVariableMap symbolTable = script.getSymbolTable();
if (symbolTable != null) {
String[] inputs = (script.getInputVariables() == null) ? new String[0] : script.getInputVariables().toArray(new String[0]);
String[] outputs = (script.getOutputVariables() == null) ? new String[0] : script.getOutputVariables().toArray(new String[0]);
RewriteRemovePersistentReadWrite rewrite = new RewriteRemovePersistentReadWrite(inputs, outputs, script.getSymbolTable());
ProgramRewriter programRewriter = new ProgramRewriter(rewrite);
try {
programRewriter.rewriteProgramHopDAGs(dmlProgram);
} catch (LanguageException | HopsException e) {
throw new MLContextException("Exception occurred while rewriting persistent reads and writes", e);
}
}
}
use of org.apache.sysml.parser.LanguageException in project incubator-systemml by apache.
the class ScriptExecutor method liveVariableAnalysis.
/**
* Liveness analysis is performed on the program, obtaining sets of live-in
* and live-out variables by forward and backward passes over the program.
*/
protected void liveVariableAnalysis() {
try {
dmlTranslator = new DMLTranslator(dmlProgram);
dmlTranslator.liveVariableAnalysis(dmlProgram);
} catch (DMLRuntimeException e) {
throw new MLContextException("Exception occurred during live variable analysis", e);
} catch (LanguageException e) {
throw new MLContextException("Exception occurred during live variable analysis", e);
}
}
use of org.apache.sysml.parser.LanguageException in project incubator-systemml by apache.
the class CommonSyntacticValidator method exitAssignmentStatementHelper.
protected void exitAssignmentStatementHelper(ParserRuleContext ctx, String lhs, ExpressionInfo dataInfo, Token lhsStart, ExpressionInfo rhs, StatementInfo info) {
if (lhs.startsWith("$")) {
notifyErrorListeners("assignment of commandline parameters is not allowed. (Quickfix: try using someLocalVariable=ifdef(" + lhs + ", default value))", ctx.start);
return;
}
DataIdentifier target = null;
if (dataInfo.expr instanceof DataIdentifier) {
target = (DataIdentifier) dataInfo.expr;
Expression source = rhs.expr;
try {
info.stmt = new AssignmentStatement(ctx, target, source, currentFile);
} catch (LanguageException e) {
// TODO: extract more meaningful info from this exception.
notifyErrorListeners("invalid assignment", lhsStart);
return;
}
} else {
notifyErrorListeners("incorrect lvalue in assignment statement", lhsStart);
return;
}
}
Aggregations