Skip to content

Commit

Permalink
Fix for no sequence indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
sakehl committed Dec 8, 2023
1 parent 05ce6ad commit 79e3d97
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/col/vct/col/typerules/CoercionUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ case object CoercionUtils {
case (TResource(), TResourceVal()) => CoerceResourceResourceVal()
case (TResourceVal(), TResource()) => CoerceResourceValResource()
case (TBool(), TResource()) => CoerceBoolResource()
case (TBool(), TResourceVal()) => CoercionSequence(Seq(CoerceBoolResource(), CoerceResourceResourceVal()))


case (_, TAnyValue()) => CoerceSomethingAnyValue(source)

Expand Down
30 changes: 27 additions & 3 deletions src/rewrite/vct/rewrite/lang/LangCPPToCol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vct.rewrite.lang
import com.typesafe.scalalogging.LazyLogging
import hre.util.ScopedStack
import vct.col.ast.{CPPLocalDeclaration, Expr, InstanceField, Perm, TInt, _}
import vct.col.ast.util.ExpressionEqualityCheck.isConstantInt
import vct.col.origin._
import vct.col.ref.Ref
import vct.col.resolve.NotApplicable
Expand Down Expand Up @@ -767,7 +768,13 @@ case class LangCPPToCol[Pre <: Generation](rw: LangSpecificToCol[Pre]) extends L
case _ => throw NotApplicable(inv)
}
case "sycl::range::get" => (classInstance, args) match {
case (Some(seq: LiteralSeq[Post]), Seq(arg)) => SeqSubscript(seq, rw.dispatch(arg))(SYCLRequestedRangeIndexOutOfBoundsBlame(seq, arg)) // Range coming from calling get_range() on a (local)accessor
case (Some(seq: LiteralSeq[Post]), Seq(arg)) =>

isConstantInt(arg) match {
case Some(i) if 0<= i && i < seq.values.size => seq.values(i.toInt)
case _ => ???
}
// SeqSubscript(seq, rw.dispatch(arg))(SYCLRequestedRangeIndexOutOfBoundsBlame(seq, arg)) // Range coming from calling get_range() on a (local)accessor
case _ => throw NotApplicable(inv)
}

Expand Down Expand Up @@ -1265,11 +1272,28 @@ case class LangCPPToCol[Pre <: Generation](rw: LangSpecificToCol[Pre]) extends L
}

private def getSimpleWorkItemId(inv: CPPInvocation[Pre], level: KernelScopeLevel) (implicit o: Origin) : Expr[Post] = {
SeqSubscript[Post](LiteralSeq(TInt(), currentDimensionIterVars(level).map(iterVar => iterVar.variable.get).toSeq), rw.dispatch(inv.args.head))(SYCLItemMethodSeqBoundFailureBlame(inv))
val dim = inv.args match {
case Seq(dim) => dim
case _ => ???
}
isConstantInt(dim) match {
case Some(i) if 0<= i && i < currentDimensionIterVars(level).size => currentDimensionIterVars(level)(i.toInt).variable.get
case _ => ???
}

// SeqSubscript[Post](LiteralSeq(TInt(), currentDimensionIterVars(level).map(iterVar => iterVar.variable.get).toSeq), rw.dispatch(inv.args.head))(SYCLItemMethodSeqBoundFailureBlame(inv))
}

private def getSimpleWorkItemRange(inv: CPPInvocation[Pre], level: KernelScopeLevel)(implicit o: Origin): Expr[Post] = {
SeqSubscript[Post](LiteralSeq(TInt(), currentDimensionIterVars(level).map(iterVar => iterVar.to).toSeq), rw.dispatch(inv.args.head))(SYCLItemMethodSeqBoundFailureBlame(inv))
val dim = inv.args match {
case Seq(dim) => dim
case _ => ???
}
isConstantInt(dim) match {
case Some(i) if 0<= i && i < currentDimensionIterVars(level).size => currentDimensionIterVars(level)(i.toInt).variable.get
case _ => ???
}
// SeqSubscript[Post](LiteralSeq(TInt(), currentDimensionIterVars(level).map(iterVar => iterVar.to).toSeq), rw.dispatch(inv.args.head))(SYCLItemMethodSeqBoundFailureBlame(inv))
}

private def getSimpleWorkItemLinearId(inv: CPPInvocation[Pre], level: KernelScopeLevel)(implicit o: Origin): Expr[Post] = {
Expand Down

0 comments on commit 79e3d97

Please sign in to comment.