Skip to content
Snippets Groups Projects
Commit ab593905 authored by Julien Lopez's avatar Julien Lopez
Browse files

Update to new QIR version

parent 584ba1e0
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,7 @@ import java.util.Map; ...@@ -33,6 +33,7 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import com.oracle.truffle.api.frame.Frame; import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.frame.FrameSlot; import com.oracle.truffle.api.frame.FrameSlot;
import com.oracle.truffle.api.source.Source; import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection; import com.oracle.truffle.api.source.SourceSection;
...@@ -45,7 +46,7 @@ import com.oracle.truffle.r.runtime.env.REnvironment; ...@@ -45,7 +46,7 @@ import com.oracle.truffle.r.runtime.env.REnvironment;
import qir.ast.*; import qir.ast.*;
import qir.ast.data.*; import qir.ast.data.*;
import qir.ast.value.*; import qir.ast.expression.*;
import qir.driver.sql.OracleDriver; import qir.driver.sql.OracleDriver;
import qir.driver.sql.PostgreSQLDriver; import qir.driver.sql.PostgreSQLDriver;
import qir.driver.ConnectionData; import qir.driver.ConnectionData;
...@@ -106,9 +107,9 @@ public final class QIRInterface { ...@@ -106,9 +107,9 @@ public final class QIRInterface {
for (Map<String, QIRVariable> fvs = QIRDriver.getFreeVars(query); !fvs.isEmpty(); fvs = QIRDriver.getFreeVars(query)) for (Map<String, QIRVariable> fvs = QIRDriver.getFreeVars(query); !fvs.isEmpty(); fvs = QIRDriver.getFreeVars(query))
for (final QIRVariable fv : fvs.values()) { for (final QIRVariable fv : fvs.values()) {
final String varName = fv.getId(); final String varName = fv.id;
final FrameSlot varSlot = frame.getFrameDescriptor().findFrameSlot(varName); final FrameSlot varSlot = frame.getFrameDescriptor().findFrameSlot(varName);
query = new QIRApply(dummy, new QIRLambda(dummy, null, new QIRVariable(dummy, varName, varSlot), query), query = new QIRApply(dummy, new QIRLambda(dummy, null, new QIRVariable(dummy, varName, varSlot), query, new FrameDescriptor()),
RToQIRType(fv.sourceSection, varSlot != null ? frame.getValue(varSlot) : RContext.lookupBuiltin(varName))); RToQIRType(fv.sourceSection, varSlot != null ? frame.getValue(varSlot) : RContext.lookupBuiltin(varName)));
} }
return query; return query;
...@@ -205,7 +206,7 @@ public final class QIRInterface { ...@@ -205,7 +206,7 @@ public final class QIRInterface {
if (value instanceof Double) if (value instanceof Double)
return new QIRDouble(src, (Double) value); return new QIRDouble(src, (Double) value);
if (value instanceof Boolean) if (value instanceof Boolean)
return (Boolean) value ? QIRBoolean.qirTrue : QIRBoolean.qirFalse; return QIRBoolean.create((Boolean) value);
if (value instanceof String) if (value instanceof String)
return new QIRString(src, (String) value); return new QIRString(src, (String) value);
if (value instanceof REnvironment) { if (value instanceof REnvironment) {
...@@ -236,16 +237,16 @@ public final class QIRInterface { ...@@ -236,16 +237,16 @@ public final class QIRInterface {
if (fun.isBuiltin()) if (fun.isBuiltin())
switch (fun.getName()) { switch (fun.getName()) {
case "new.env": case "new.env":
return new QIRLambda(src, "new.env", new QIRVariable(null, "_", null), QIRTnil.instance); return new QIRLambda(src, "new.env", new QIRVariable(null, "_", null), QIRTnil.instance, new FrameDescriptor());
case "return": case "return":
case "(": { case "(": {
final QIRVariable x = new QIRVariable(null, "x", null); final QIRVariable x = new QIRVariable(null, "x", null);
return new QIRLambda(src, "identity", x, x); return new QIRLambda(src, "identity", x, x, new FrameDescriptor());
} }
case "c": { case "c": {
// TODO: This works only for lists with one element // TODO: This works only for lists with one element
final QIRVariable x = new QIRVariable(null, "x", null); final QIRVariable x = new QIRVariable(null, "x", null);
return new QIRLambda(src, "lcons", x, new QIRLcons(null, x, QIRLnil.instance)); return new QIRLambda(src, "lcons", x, new QIRLcons(null, x, QIRLnil.instance), new FrameDescriptor());
} }
case "sum": case "sum":
return new QIRBuiltin(src, "sum"); return new QIRBuiltin(src, "sum");
...@@ -257,15 +258,15 @@ public final class QIRInterface { ...@@ -257,15 +258,15 @@ public final class QIRInterface {
throw new RuntimeException("Unsupported value: " + value); throw new RuntimeException("Unsupported value: " + value);
} }
private static final <T> QIRNode RFunctionToQIRType(final SourceSection src, final String funName, final FunctionDefinitionNode fun) { private static final QIRNode RFunctionToQIRType(final SourceSection src, final String funName, final FunctionDefinitionNode fun) {
try { try {
QIRNode res = ((FunctionDefinitionNode) fun.getCallTarget().getRootNode()).getBody().accept(QIRTranslateVisitor.instance); QIRNode res = ((FunctionDefinitionNode) fun.getCallTarget().getRootNode()).getBody().accept(QIRTranslateVisitor.instance);
final String[] args = ((FunctionDefinitionNode) fun.getCallTarget().getRootNode()).getSignature().getNames(); final String[] args = ((FunctionDefinitionNode) fun.getCallTarget().getRootNode()).getSignature().getNames();
if (args.length == 0) if (args.length == 0)
return new QIRLambda(src, funName, null, res); return new QIRLambda(src, funName, null, res, new FrameDescriptor());
for (int i = 0; i < args.length; i++) for (int i = 0; i < args.length; i++)
res = new QIRLambda(src, funName, new QIRVariable(null, args[i], null), res); res = new QIRLambda(src, funName, new QIRVariable(null, args[i], null), res, new FrameDescriptor());
return res; return res;
} catch (UnsupportedOperationException e) { } catch (UnsupportedOperationException e) {
final SourceSection funSrc = fun.getCallTarget().getRootNode().getSourceSection(); final SourceSection funSrc = fun.getCallTarget().getRootNode().getSourceSection();
......
...@@ -4,6 +4,7 @@ import java.util.Arrays; ...@@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.source.Source; import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection; import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.r.nodes.RSyntaxNodeVisitor; import com.oracle.truffle.r.nodes.RSyntaxNodeVisitor;
...@@ -23,18 +24,11 @@ import com.oracle.truffle.r.runtime.nodes.RNode; ...@@ -23,18 +24,11 @@ import com.oracle.truffle.r.runtime.nodes.RNode;
import com.oracle.truffle.r.runtime.nodes.RSyntaxNode; import com.oracle.truffle.r.runtime.nodes.RSyntaxNode;
import qir.ast.*; import qir.ast.*;
import qir.ast.data.QIRTcons; import qir.ast.data.*;
import qir.ast.data.QIRTdestr; import qir.ast.expression.QIRNull;
import qir.ast.expression.arithmetic.QIRDiv; import qir.ast.expression.arithmetic.*;
import qir.ast.expression.arithmetic.QIRMinus; import qir.ast.expression.logic.*;
import qir.ast.expression.arithmetic.QIRPlus; import qir.ast.expression.relational.*;
import qir.ast.expression.arithmetic.QIRStar;
import qir.ast.expression.logic.QIRAnd;
import qir.ast.expression.logic.QIRNot;
import qir.ast.expression.logic.QIROr;
import qir.ast.expression.relational.QIREqual;
import qir.ast.expression.relational.QIRLowerOrEqual;
import qir.ast.expression.relational.QIRLowerThan;
import qir.ast.operator.*; import qir.ast.operator.*;
/** /**
...@@ -88,7 +82,7 @@ public final class QIRTranslateVisitor implements RSyntaxNodeVisitor<QIRNode> { ...@@ -88,7 +82,7 @@ public final class QIRTranslateVisitor implements RSyntaxNodeVisitor<QIRNode> {
final RNode value = ((WriteLocalFrameVariableNode) child).getRhs(); final RNode value = ((WriteLocalFrameVariableNode) child).getRhs();
// If the assignment value reads an argument, then we translate to a lambda. // If the assignment value reads an argument, then we translate to a lambda.
result = new QIRLambda(dummy, null, new QIRVariable(dummy, (String) ((WriteLocalFrameVariableNode) child).getName(), null), result); result = new QIRLambda(dummy, null, new QIRVariable(dummy, (String) ((WriteLocalFrameVariableNode) child).getName(), null), result, new FrameDescriptor());
// Else we apply STRAD-ASSIGN-ID normally // Else we apply STRAD-ASSIGN-ID normally
if (!(value instanceof AccessArgumentNode)) if (!(value instanceof AccessArgumentNode))
result = new QIRApply(dummy, result, value.asRSyntaxNode().accept(this)); result = new QIRApply(dummy, result, value.asRSyntaxNode().accept(this));
...@@ -96,7 +90,7 @@ public final class QIRTranslateVisitor implements RSyntaxNodeVisitor<QIRNode> { ...@@ -96,7 +90,7 @@ public final class QIRTranslateVisitor implements RSyntaxNodeVisitor<QIRNode> {
final RNode value = ((ReplacementDispatchNode) child).rhs; final RNode value = ((ReplacementDispatchNode) child).rhs;
// If the assignment value reads an argument, then we translate to a lambda. // If the assignment value reads an argument, then we translate to a lambda.
result = new QIRLambda(dummy, null, new QIRVariable(dummy, ((ReadVariableNode) ((ReplacementDispatchNode) child).lhs).getIdentifier(), null), result); result = new QIRLambda(dummy, null, new QIRVariable(dummy, ((ReadVariableNode) ((ReplacementDispatchNode) child).lhs).getIdentifier(), null), result, new FrameDescriptor());
// Else we apply STRAD-ASSIGN-ID normally // Else we apply STRAD-ASSIGN-ID normally
if (!(value instanceof AccessArgumentNode)) if (!(value instanceof AccessArgumentNode))
result = new QIRApply(dummy, result, value.asRSyntaxNode().accept(this)); result = new QIRApply(dummy, result, value.asRSyntaxNode().accept(this));
...@@ -109,7 +103,7 @@ public final class QIRTranslateVisitor implements RSyntaxNodeVisitor<QIRNode> { ...@@ -109,7 +103,7 @@ public final class QIRTranslateVisitor implements RSyntaxNodeVisitor<QIRNode> {
final ReadVariableNode receiver = (ReadVariableNode) lhs.getSyntaxArguments()[0]; final ReadVariableNode receiver = (ReadVariableNode) lhs.getSyntaxArguments()[0];
final ConstantNode eid = (ConstantNode) lhs.getSyntaxArguments()[1]; final ConstantNode eid = (ConstantNode) lhs.getSyntaxArguments()[1];
final RNode value = repl.rhs; final RNode value = repl.rhs;
result = new QIRApply(dummy, new QIRLambda(dummy, null, new QIRVariable(dummy, receiver.getIdentifier(), null), result), result = new QIRApply(dummy, new QIRLambda(dummy, null, new QIRVariable(dummy, receiver.getIdentifier(), null), result, new FrameDescriptor()),
new QIRTcons(dummy, (String) eid.getValue(), value.asRSyntaxNode().accept(this), receiver.accept(this))); new QIRTcons(dummy, (String) eid.getValue(), value.asRSyntaxNode().accept(this), receiver.accept(this)));
} else } else
throw new UnsupportedOperationException("Cannot translate \"" + block.getSourceSection() + "\" to QIR: untranslatable sequence."); throw new UnsupportedOperationException("Cannot translate \"" + block.getSourceSection() + "\" to QIR: untranslatable sequence.");
...@@ -160,31 +154,31 @@ public final class QIRTranslateVisitor implements RSyntaxNodeVisitor<QIRNode> { ...@@ -160,31 +154,31 @@ public final class QIRTranslateVisitor implements RSyntaxNodeVisitor<QIRNode> {
case "$": case "$":
return new QIRTdestr(dot.getSourceSection(), nodes.get(0), (String) ((ConstantNode) dot.getSyntaxArguments()[1]).getValue()); return new QIRTdestr(dot.getSourceSection(), nodes.get(0), (String) ((ConstantNode) dot.getSyntaxArguments()[1]).getValue());
case "+": case "+":
return new QIRPlus(dot.getSourceSection(), nodes.get(0), nodes.get(1)); return QIRPlusNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1));
case "-": case "-":
return new QIRMinus(dot.getSourceSection(), nodes.get(0), nodes.get(1)); return QIRMinusNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1));
case "*": case "*":
return new QIRStar(dot.getSourceSection(), nodes.get(0), nodes.get(1)); return QIRStarNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1));
case "/": case "/":
return new QIRDiv(dot.getSourceSection(), nodes.get(0), nodes.get(1)); return QIRDivNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1));
case "==": case "==":
return new QIREqual(dot.getSourceSection(), nodes.get(0), nodes.get(1)); return QIREqualNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1));
case "&": case "&":
case "&&": case "&&":
return new QIRAnd(dot.getSourceSection(), nodes.get(0), nodes.get(1)); return QIRAndNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1));
case "|": case "|":
case "||": case "||":
return new QIROr(dot.getSourceSection(), nodes.get(0), nodes.get(1)); return QIROrNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1));
case "<=": case "<=":
return new QIRLowerOrEqual(dot.getSourceSection(), nodes.get(0), nodes.get(1)); return QIRLowerOrEqualNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1));
case "<": case "<":
return new QIRLowerThan(dot.getSourceSection(), nodes.get(0), nodes.get(1)); return QIRLowerThanNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1));
case ">=": case ">=":
return new QIRNot(dot.getSourceSection(), new QIRLowerThan(dot.getSourceSection(), nodes.get(0), nodes.get(1))); return QIRNotNodeGen.create(dot.getSourceSection(), QIRLowerThanNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1)));
case ">": case ">":
return new QIRNot(dot.getSourceSection(), new QIRLowerOrEqual(dot.getSourceSection(), nodes.get(0), nodes.get(1))); return QIRNotNodeGen.create(dot.getSourceSection(), QIRLowerOrEqualNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1)));
case "!": case "!":
return new QIRNot(dot.getSourceSection(), nodes.get(0)); return QIRNotNodeGen.create(dot.getSourceSection(), nodes.get(0));
default: default:
throw new RuntimeException("Unknown call special node: " + name); throw new RuntimeException("Unknown call special node: " + name);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment