Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 1.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ucbjrl committed Sep 10, 2019
2 parents e9a48c1 + 7929768 commit 575add3
Show file tree
Hide file tree
Showing 27 changed files with 125 additions and 159 deletions.
10 changes: 5 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.3"
// An explicit dependency on junit seems to alleviate this.
libraryDependencies += "junit" % "junit" % "4.12" % "test"

libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8" % "test"

libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.14.0" % "test"

libraryDependencies += "com.github.scopt" %% "scopt" % "3.7.0"
libraryDependencies += "com.github.scopt" %% "scopt" % "3.7.1"

libraryDependencies += "net.jcazevedo" %% "moultingyaml" % "0.4.0"
libraryDependencies += "net.jcazevedo" %% "moultingyaml" % "0.4.1"

libraryDependencies += "org.json4s" %% "json4s-native" % "3.6.1"
libraryDependencies += "org.json4s" %% "json4s-native" % "3.6.7"

libraryDependencies += "org.apache.commons" % "commons-text" % "1.6"
libraryDependencies += "org.apache.commons" % "commons-text" % "1.7"

// Java PB

Expand Down
5 changes: 1 addition & 4 deletions src/main/scala/firrtl/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ case class CircuitState(
def getEmittedCircuit: EmittedCircuit = emittedCircuitOption match {
case Some(emittedCircuit) => emittedCircuit
case None =>
throw new FIRRTLException(s"No EmittedCircuit found! Did you delete any annotations?\n$deletedAnnotations")
throw new FirrtlInternalException(s"No EmittedCircuit found! Did you delete any annotations?\n$deletedAnnotations")
}

/** Helper function for extracting emitted components from annotations */
Expand Down Expand Up @@ -315,9 +315,6 @@ trait Emitter extends Transform {
def outputSuffix: String
}

/** Wraps exceptions from CustomTransforms so they can be reported appropriately */
case class CustomTransformException(cause: Throwable) extends Exception("", cause)

object CompilerUtils extends LazyLogging {
/** Generates a sequence of [[Transform]]s to lower a Firrtl circuit
*
Expand Down
43 changes: 43 additions & 0 deletions src/main/scala/firrtl/FirrtlException.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// See LICENSE for license details.

package firrtl

import scala.util.control.NoStackTrace

@deprecated("External users should use either FirrtlUserException or their own hierarchy", "1.2")
object FIRRTLException {
def defaultMessage(message: String, cause: Throwable) = {
if (message != null) {
message
} else if (cause != null) {
cause.toString
} else {
null
}
}
}
@deprecated("External users should use either FirrtlUserException or their own hierarchy", "1.2")
class FIRRTLException(val str: String, cause: Throwable = null)
extends RuntimeException(FIRRTLException.defaultMessage(str, cause), cause)

/** Exception indicating user error
*
* These exceptions indicate a problem due to bad input and thus do not include a stack trace.
* This can be extended by custom transform writers.
*/
class FirrtlUserException(message: String, cause: Throwable = null)
extends RuntimeException(message, cause) with NoStackTrace

/** Wraps exceptions from CustomTransforms so they can be reported appropriately */
case class CustomTransformException(cause: Throwable) extends Exception("", cause)

/** Exception indicating something went wrong *within* Firrtl itself
*
* These exceptions indicate a problem inside the compiler and include a stack trace to help
* developers debug the issue.
*
* This class is private because these are issues within Firrtl itself. Exceptions thrown in custom
* transforms are treated differently and should thus have their own structure
*/
private[firrtl] class FirrtlInternalException(message: String, cause: Throwable = null)
extends Exception(message, cause)
2 changes: 1 addition & 1 deletion src/main/scala/firrtl/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import firrtl.ir._
import firrtl.Utils.time
import firrtl.antlr.{FIRRTLParser, _}

class ParserException(message: String) extends FIRRTLException(message)
class ParserException(message: String) extends FirrtlUserException(message)

case class ParameterNotSpecifiedException(message: String) extends ParserException(message)
case class ParameterRedefinedException(message: String) extends ParserException(message)
Expand Down
94 changes: 12 additions & 82 deletions src/main/scala/firrtl/PrimOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,12 @@ object PrimOps extends LazyLogging {
def c1 = IntWidth(e.consts.head)
def c2 = IntWidth(e.consts(1))
e copy (tpe = e.op match {
case Add => (t1, t2) match {
case Add | Sub => (t1, t2) match {
case (_: UIntType, _: UIntType) => UIntType(PLUS(MAX(w1, w2), IntWidth(1)))
case (_: SIntType, _: SIntType) => SIntType(PLUS(MAX(w1, w2), IntWidth(1)))
case (_: FixedType, _: FixedType) => FixedType(PLUS(PLUS(MAX(p1, p2), MAX(MINUS(w1, p1), MINUS(w2, p2))), IntWidth(1)), MAX(p1, p2))
case _ => UnknownType
}
case Sub => (t1, t2) match {
case (_: UIntType, _: UIntType) => UIntType(PLUS(MAX(w1, w2), IntWidth(1)))
case (_: SIntType, _: SIntType) => SIntType(PLUS(MAX(w1, w2), IntWidth(1)))
case (_: FixedType, _: FixedType) => FixedType(PLUS(PLUS(MAX(p1, p2),MAX(MINUS(w1, p1), MINUS(w2, p2))),IntWidth(1)), MAX(p1, p2))
case _ => UnknownType
}
case Mul => (t1, t2) match {
case (_: UIntType, _: UIntType) => UIntType(PLUS(w1, w2))
case (_: SIntType, _: SIntType) => SIntType(PLUS(w1, w2))
Expand All @@ -157,37 +151,7 @@ object PrimOps extends LazyLogging {
case (_: SIntType, _: SIntType) => SIntType(MIN(w1, w2))
case _ => UnknownType
}
case Lt => (t1, t2) match {
case (_: UIntType, _: UIntType) => Utils.BoolType
case (_: SIntType, _: SIntType) => Utils.BoolType
case (_: FixedType, _: FixedType) => Utils.BoolType
case _ => UnknownType
}
case Leq => (t1, t2) match {
case (_: UIntType, _: UIntType) => Utils.BoolType
case (_: SIntType, _: SIntType) => Utils.BoolType
case (_: FixedType, _: FixedType) => Utils.BoolType
case _ => UnknownType
}
case Gt => (t1, t2) match {
case (_: UIntType, _: UIntType) => Utils.BoolType
case (_: SIntType, _: SIntType) => Utils.BoolType
case (_: FixedType, _: FixedType) => Utils.BoolType
case _ => UnknownType
}
case Geq => (t1, t2) match {
case (_: UIntType, _: UIntType) => Utils.BoolType
case (_: SIntType, _: SIntType) => Utils.BoolType
case (_: FixedType, _: FixedType) => Utils.BoolType
case _ => UnknownType
}
case Eq => (t1, t2) match {
case (_: UIntType, _: UIntType) => Utils.BoolType
case (_: SIntType, _: SIntType) => Utils.BoolType
case (_: FixedType, _: FixedType) => Utils.BoolType
case _ => UnknownType
}
case Neq => (t1, t2) match {
case Lt | Leq | Gt | Geq | Eq | Neq => (t1, t2) match {
case (_: UIntType, _: UIntType) => Utils.BoolType
case (_: SIntType, _: SIntType) => Utils.BoolType
case (_: FixedType, _: FixedType) => Utils.BoolType
Expand All @@ -200,41 +164,26 @@ object PrimOps extends LazyLogging {
case _ => UnknownType
}
case AsUInt => t1 match {
case _: UIntType => UIntType(w1)
case _: SIntType => UIntType(w1)
case _: FixedType => UIntType(w1)
case (_: UIntType | _: SIntType | _: FixedType | _: AnalogType) => UIntType(w1)
case ClockType | AsyncResetType | ResetType => UIntType(IntWidth(1))
case AnalogType(w) => UIntType(w1)
case _ => UnknownType
}
case AsSInt => t1 match {
case _: UIntType => SIntType(w1)
case _: SIntType => SIntType(w1)
case _: FixedType => SIntType(w1)
case (_: UIntType | _: SIntType | _: FixedType | _: AnalogType) => SIntType(w1)
case ClockType | AsyncResetType | ResetType => SIntType(IntWidth(1))
case _: AnalogType => SIntType(w1)
case _ => UnknownType
}
case AsFixedPoint => t1 match {
case _: UIntType => FixedType(w1, c1)
case _: SIntType => FixedType(w1, c1)
case _: FixedType => FixedType(w1, c1)
case (_: UIntType | _: SIntType | _: FixedType | _: AnalogType) => FixedType(w1, c1)
case ClockType | AsyncResetType | ResetType => FixedType(IntWidth(1), c1)
case _: AnalogType => FixedType(w1, c1)
case _ => UnknownType
}
case AsClock => t1 match {
case _: UIntType => ClockType
case _: SIntType => ClockType
case ClockType | AsyncResetType | ResetType => ClockType
case _: AnalogType => ClockType
case (_: UIntType | _: SIntType | _: AnalogType | ClockType | AsyncResetType | ResetType) => ClockType
case _ => UnknownType
}
case AsAsyncReset => t1 match {
case _: UIntType => AsyncResetType
case _: SIntType => AsyncResetType
case ClockType | AsyncResetType | ResetType => AsyncResetType
case _: AnalogType => AsyncResetType
case (_: UIntType | _: SIntType | _: AnalogType | ClockType | AsyncResetType | ResetType) => AsyncResetType
case _ => UnknownType
}
case Shl => t1 match {
Expand Down Expand Up @@ -267,36 +216,18 @@ object PrimOps extends LazyLogging {
case _ => UnknownType
}
case Neg => t1 match {
case _: UIntType => SIntType(PLUS(w1, IntWidth(1)))
case _: SIntType => SIntType(PLUS(w1, IntWidth(1)))
case (_: UIntType | _: SIntType) => SIntType(PLUS(w1, IntWidth(1)))
case _ => UnknownType
}
case Not => t1 match {
case _: UIntType => UIntType(w1)
case _: SIntType => UIntType(w1)
case _ => UnknownType
}
case And => (t1, t2) match {
case (_: SIntType | _: UIntType, _: SIntType | _: UIntType) => UIntType(MAX(w1, w2))
case _ => UnknownType
}
case Or => (t1, t2) match {
case (_: SIntType | _: UIntType, _: SIntType | _: UIntType) => UIntType(MAX(w1, w2))
case (_: UIntType | _: SIntType) => UIntType(w1)
case _ => UnknownType
}
case Xor => (t1, t2) match {
case And | Or | Xor => (t1, t2) match {
case (_: SIntType | _: UIntType, _: SIntType | _: UIntType) => UIntType(MAX(w1, w2))
case _ => UnknownType
}
case Andr => t1 match {
case (_: UIntType | _: SIntType) => Utils.BoolType
case _ => UnknownType
}
case Orr => t1 match {
case (_: UIntType | _: SIntType) => Utils.BoolType
case _ => UnknownType
}
case Xorr => t1 match {
case Andr | Orr | Xorr => t1 match {
case (_: UIntType | _: SIntType) => Utils.BoolType
case _ => UnknownType
}
Expand All @@ -305,8 +236,7 @@ object PrimOps extends LazyLogging {
case (t1, t2) => UnknownType
}
case Bits => t1 match {
case (_: UIntType | _: SIntType) => UIntType(PLUS(MINUS(c1, c2), IntWidth(1)))
case _: FixedType => UIntType(PLUS(MINUS(c1, c2), IntWidth(1)))
case (_: UIntType | _: SIntType | _: FixedType) => UIntType(PLUS(MINUS(c1, c2), IntWidth(1)))
case _ => UnknownType
}
case Head => t1 match {
Expand Down
18 changes: 2 additions & 16 deletions src/main/scala/firrtl/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,6 @@ import scala.util.matching.Regex
import firrtl.annotations.{ReferenceTarget, TargetToken}
import _root_.logger.LazyLogging

object FIRRTLException {
def defaultMessage(message: String, cause: Throwable) = {
if (message != null) {
message
} else if (cause != null) {
cause.toString
} else {
null
}
}
}
class FIRRTLException(val str: String, cause: Throwable = null)
extends RuntimeException(FIRRTLException.defaultMessage(str, cause), cause)

object seqCat {
def apply(args: Seq[Expression]): Expression = args.length match {
case 0 => Utils.error("Empty Seq passed to seqcat")
Expand Down Expand Up @@ -434,7 +420,7 @@ object Utils extends LazyLogging {
}

// =================================
def error(str: String, cause: Throwable = null) = throw new FIRRTLException(str, cause)
def error(str: String, cause: Throwable = null) = throw new FirrtlInternalException(str, cause)

//// =============== EXPANSION FUNCTIONS ================
def get_size(t: Type): Int = t match {
Expand Down Expand Up @@ -632,7 +618,7 @@ object Utils extends LazyLogging {
case EmptyExpression => root
}

case class DeclarationNotFoundException(msg: String) extends FIRRTLException(msg)
case class DeclarationNotFoundException(msg: String) extends FirrtlUserException(msg)

/** Gets the root declaration of an expression
*
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/firrtl/annotations/AnnotationUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import firrtl.annotations.AnnotationYamlProtocol._

import firrtl.ir._

case class InvalidAnnotationFileException(file: File, cause: Throwable = null)
extends FIRRTLException(s"$file, see cause below", cause)
case class InvalidAnnotationJSONException(msg: String) extends FIRRTLException(msg)
case class AnnotationFileNotFoundException(file: File) extends FIRRTLException(
case class InvalidAnnotationFileException(file: File, cause: FirrtlUserException = null)
extends FirrtlUserException(s"$file", cause)
case class InvalidAnnotationJSONException(msg: String) extends FirrtlUserException(msg)
case class AnnotationFileNotFoundException(file: File) extends FirrtlUserException(
s"Annotation file $file not found!"
)
case class AnnotationClassNotFoundException(className: String) extends FIRRTLException(
case class AnnotationClassNotFoundException(className: String) extends FirrtlUserException(
s"Annotation class $className not found! Please check spelling and classpath"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ object AnnotationYamlProtocol extends DefaultYamlProtocol {
case annotationException: AnnotationException =>
Utils.error(
s"Error: ${annotationException.getMessage} while parsing annotation from yaml\n${yamlValue.prettyPrint}")
case annotationException: FIRRTLException =>
Utils.error(
s"Error: ${annotationException.getMessage} while parsing annotation from yaml\n${yamlValue.prettyPrint}")
}
}
def toTarget(string: String): Named = string.split("""\.""", -1).toSeq match {
Expand Down
7 changes: 4 additions & 3 deletions src/main/scala/firrtl/annotations/JsonProtocol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object JsonProtocol {
try {
Class.forName(s).asInstanceOf[Class[_ <: Transform]].newInstance()
} catch {
case e: java.lang.InstantiationException => throw new FIRRTLException(
case e: java.lang.InstantiationException => throw new FirrtlInternalException(
"NoSuchMethodException during construction of serialized Transform. Is your Transform an inner class?", e)
case t: Throwable => throw t
}},
Expand Down Expand Up @@ -113,10 +113,11 @@ object JsonProtocol {
// Translate some generic errors to specific ones
case e: java.lang.ClassNotFoundException =>
Failure(new AnnotationClassNotFoundException(e.getMessage))
case e: org.json4s.ParserUtil.ParseException =>
// Eat the stack traces of json4s exceptions
case e @ (_: org.json4s.ParserUtil.ParseException | _: org.json4s.MappingException) =>
Failure(new InvalidAnnotationJSONException(e.getMessage))
}.recoverWith { // If the input is a file, wrap in InvalidAnnotationFileException
case e => in match {
case e: FirrtlUserException => in match {
case FileInput(file) =>
Failure(new InvalidAnnotationFileException(file, e))
case _ => Failure(e)
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/firrtl/annotations/LoadMemoryAnnotation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package firrtl.annotations

import java.io.File

import firrtl.FIRRTLException
import firrtl.FirrtlUserException

/** Representation of the two types of `readmem` statements available in Verilog.
*/
Expand All @@ -21,7 +21,7 @@ object MemoryLoadFileType {
def deserialize(s: String): MemoryLoadFileType = s match {
case "h" => MemoryLoadFileType.Hex
case "b" => MemoryLoadFileType.Binary
case _ => throw new FIRRTLException(s"Unrecognized MemoryLoadFileType: $s")
case _ => throw new FirrtlUserException(s"Unrecognized MemoryLoadFileType: $s")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import firrtl.annotations.TargetToken.{Instance, OfModule}
import firrtl.annotations.analysis.DuplicationHelper
import firrtl.annotations._
import firrtl.ir._
import firrtl.{CircuitForm, CircuitState, FIRRTLException, HighForm, RenameMap, Transform, WDefInstance}
import firrtl.{CircuitForm, CircuitState, FirrtlInternalException, HighForm, RenameMap, Transform, WDefInstance}

import scala.collection.mutable

Expand All @@ -23,7 +23,7 @@ case class ResolvePaths(targets: Seq[CompleteTarget]) extends Annotation {
}
}

case class NoSuchTargetException(message: String) extends FIRRTLException(message)
case class NoSuchTargetException(message: String) extends FirrtlInternalException(message)

/** For a set of non-local targets, modify the instance/module hierarchy of the circuit such that
* the paths in each non-local target can be removed
Expand Down
3 changes: 3 additions & 0 deletions src/main/scala/firrtl/options/Exceptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ class OptionsException(val message: String, cause: Throwable = null) extends Ill
* out of order or if the compiler did not run things in the correct order.
*/
class PhasePrerequisiteException(message: String, cause: Throwable = null) extends PhaseException(message, cause)

/** Indicates that a [[Stage]] or [[Phase]] has run into a situation where it cannot continue. */
final class StageError(val code: ExitFailure = GeneralError, cause: Throwable = null) extends Error("", cause)
Loading

0 comments on commit 575add3

Please sign in to comment.