Skip to content

Commit

Permalink
add EPhysAccess to the AST. Only allowed for code gen purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
rachitnigam committed Jun 26, 2020
1 parent e89fc95 commit 4cbc16b
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object Compiler {
}

def codegen(ast: Prog, c: Config = emptyConf) = {
val rast = passes.RewriteView.rewriteProg(ast);
val rast = passes.RewriteView.rewrite(ast);
showDebug(rast, "Rewrite Views", c)

// Perform program lowering if needed.
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/backends/CppLike.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ object Cpp {
case EArrAccess(id, idxs) =>
id <> ssep(idxs.map(idx => brackets(emitExpr(idx))), emptyDoc)
case EArrLiteral(idxs) => braces(commaSep(idxs.map(idx => emitExpr(idx))))
case _: EPhysAccess =>
throw NotImplemented("Physical access code gen for cpp-like backends.")
case ERecAccess(rec, field) => rec <> dot <> field
case ERecLiteral(fs) =>
scope {
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/common/Checker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ object Checker {
case ECast(e, _) => checkE(e)
case ERecAccess(rec, _) => checkE(rec)
case EArrAccess(_, idxs) => checkESeq(idxs)
case EPhysAccess(_, bankIdxs) =>
checkESeq(bankIdxs.flatMap({ case (bank, idx) => List(bank, idx) }))
}

def checkLVal(e: Expr)(implicit env: Env): Env = checkE(e)
Expand Down
8 changes: 8 additions & 0 deletions src/main/scala/common/EnvHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,12 @@ object EnvHelpers {
def get(k: K): Option[V]
}

/**
* Definition of a trivial environment that doesn't track any
* information.
*/
final case class UnitEnv() extends ScopeManager[UnitEnv] {
def merge(that: UnitEnv) = this
}

}
16 changes: 16 additions & 0 deletions src/main/scala/common/Pretty.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ object Pretty {
)
else doc
}
case acc @ EPhysAccess(id, idxs) => {
val doc = id <>
ssep(
idxs.map({
case (bank, idx) =>
braces(emitExpr(bank)) <> brackets(emitExpr(idx))
}),
emptyDoc
)

if (debug)
brackets(
doc <> colon <+> acc.consumable.map(emitConsume).getOrElse(emptyDoc)
)
else doc
}
case EArrLiteral(idxs) => braces(commaSep(idxs.map(idx => emitExpr(idx))))
case ERecAccess(rec, field) => rec <> dot <> field
case ERecLiteral(fs) =>
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/common/Syntax.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ object Syntax {
case class EArrAccess(id: Id, idxs: List[Expr])
extends Expr
with ConsumableAnnotation
case class EPhsAccess(id: Id, bankIdxs: List[(Expr, Expr)])
case class EPhysAccess(id: Id, bankIdxs: List[(Expr, Expr)])
extends Expr
with ConsumableAnnotation
case class EArrLiteral(idxs: List[Expr]) extends Expr
Expand Down
18 changes: 10 additions & 8 deletions src/main/scala/common/Transformer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ object Transformer {
val (nidxs, env1) = rewriteESeq(idxs)
acc.copy(idxs = nidxs.toList) -> env1
}
case acc @ EPhysAccess(_, bankIdxs) => {
val init = (List[(Expr, Expr)](), env)
val (nBankIdxsReversed, nEnv) = bankIdxs.foldLeft(init)({
case ((nBankIdxs, env), (bank, idx)) =>
val (nBank, env1) = rewriteE(bank)(env)
val (nIdx, env2) = rewriteE(idx)(env1)
((nBank, nIdx) :: nBankIdxs, env2)
})
acc.copy(bankIdxs = nBankIdxsReversed.reverse.toList) -> nEnv
}
}

def rewriteLVal(e: Expr)(implicit env: Env): (Expr, Env) = rewriteE(e)
Expand Down Expand Up @@ -206,12 +216,4 @@ object Transformer {
def partialRewriteC: PF[(Command, Env), (Command, Env)] =
asPartial(super.rewriteC(_: Command)(_: Env))
}

/**
* Definition of a trivial environment that doesn't track any
* information.
*/
final case class UnitEnv() extends ScopeManager[UnitEnv] {
def merge(that: UnitEnv) = this
}
}
11 changes: 2 additions & 9 deletions src/main/scala/passes/BoundsCheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,11 @@ object BoundsChecker {

def check(p: Prog) = BCheck.check(p)

// Bounds checker environment doesn't need to track any information. Empty
// environment that just runs the commands.
private case class BEnv() extends ScopeManager[BEnv] {
// Neither environment contains anything.
def merge(that: BEnv): BEnv = this
}

private final case object BCheck extends PartialChecker {

type Env = BEnv
type Env = UnitEnv

val emptyEnv = BEnv()
val emptyEnv = UnitEnv()

/**
* Given a view with a known prefix length, check if it **might** cause an
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/passes/LowerForLoops.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fuselang.passes
import scala.{PartialFunction => PF}
import fuselang.common._
import Transformer._
import EnvHelpers._
import Syntax._
import CompilerError._

Expand Down
3 changes: 3 additions & 0 deletions src/main/scala/typechecker/AffineCheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ object AffineChecker {
}
}
}
case (_: EPhysAccess, _) => {
throw NotImplemented("Affine checking for physical accesses.")
}
}
}
}
4 changes: 4 additions & 0 deletions src/main/scala/typechecker/CapabilityChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import fuselang.common._
import Syntax._
import Syntax.Annotations._
import Errors._
import CompilerError._
import CapabilityEnv._
import Checker._

Expand Down Expand Up @@ -34,6 +35,9 @@ object CapabilityChecker {
acc.consumable = Some(consumableAnn)
nEnv.add(acc, cap)
}
case (_: EPhysAccess, _) => {
throw NotImplemented("Capability checking for physical accesses.")
}
}

override def myCheckC: PF[(Command, Env), Env] = {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/typechecker/TypeCheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ object TypeChecker {
typ -> env
}
}
case EPhsAccess(id, bankIdxs) =>
case EPhysAccess(id, bankIdxs) =>
env(id).matchOrError(expr.pos, "array access", s"array type") {
case TArray(typ, dims, _) => {
if (dims.length != bankIdxs.length) {
Expand Down

0 comments on commit 4cbc16b

Please sign in to comment.