scair

package scair

Members list

Packages

package scair.EnumAttr
package scair.clair

Clair is a Scala library for creating custom IRs. It provides the end-user with a way to define custom IRs packaged in a Dialect (MLIR word for DSL) using Scala syntax and then generate the IR code in a target language (currently limited to Scala).

Clair is a Scala library for creating custom IRs. It provides the end-user with a way to define custom IRs packaged in a Dialect (MLIR word for DSL) using Scala syntax and then generate the IR code in a target language (currently limited to Scala).

To define a custom Dialect, the user needs to define an IR and package it into a Dialect object as shown in the code below with the Sample dialect example:

import scair.ir.{DataAttribute, AttributeObject}

/*≡≡=---=≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡=---=≡≡*\
||   defining a custom data attribute   ||
\*≡==----=≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡=----==≡*/

object SampleData extends AttributeObject {
 override def name: String = "sample"
}

case class SampleData(val d: String)
   extends DataAttribute[String]("sample", d)

/*≡≡=---=≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡=---=≡≡*\
||   defining a custom attribute   ||
\*≡==----=≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡=----==≡*/

case class SampleAttribute(
   e1: Operand[IntegerAttr]
) extends AttributeFE

/*≡≡=---=≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡=---=≡≡*\
||   defining a custom type attribute   ||
\*≡==----=≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡=----==≡*/

case class SampleType(
   e1: Operand[IntegerAttr]
) extends TypeAttributeFE

/*≡≡=---=≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡=---=≡≡*\
||   defining custom operations   ||
\*≡==----=≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡=----==≡*/

case class SampOp1(
   e1: Variadic[Operand[IntegerAttr]],
   e2: Result[AnyAttribute],
   e3: Region
) extends OperationFE

case class SampOp2(
   e1: Variadic[Operand[Complex]],
   e2: Result[AnyAttribute]
) extends OperationFE

/*≡≡=---=≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡=---=≡≡*\
||   packaging into a dialect   ||
\*≡==----=≡≡≡≡≡≡≡≡≡≡≡≡≡≡=----==≡*/

object Sample {
 val opHatches = Seq()
 val attrHatches = Seq(new AttrEscapeHatch[SampleData])

 val generator =
   summonDialect[(SampleAttribute, SampOp1, SampOp2)](
     "Sample",
     opHatches,
     attrHatches
   )

}

/*≡≡=---=≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡=---=≡≡*\
||   print the generated code   ||
\*≡==----≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡=----==≡*/

def main(args: Array[String]): Unit = {
 println(CMath.generator.print(0))
}

To include the defined Dialect in ScaIR, the user should put the file into the dialects directory in the scair project, and package it appropriately.

Attributes

See also
package scair.dialects
package scair.ir
package scair.scairdl
package scair.traits
package scair.utils

Type members

Classlikes

class AttrParser(val ctx: MLContext)

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Parser
class MLContext()

Attributes

Supertypes
class Object
trait Matchable
class Any
object Parser

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
Parser.type
class Parser(val context: MLContext, val args: Args) extends AttrParser

Attributes

Companion
object
Supertypes
class AttrParser
class Object
trait Matchable
class Any
class Printer(val strictly_generic: Boolean)

Attributes

Supertypes
class Object
trait Matchable
class Any

Attributes

Supertypes
class Object
trait Matchable
class Any