Commit 9551ff05 authored by Kunshan Wang's avatar Kunshan Wang

WIP: HAIL parser.

parent 44e65e57
grammar HAIL;
hail
: topLevelDef*
;
topLevelDef
: fixedAlloc
| hybridAlloc
| memInit
;
fixedAlloc
: '.new' nam=HAIL_NAME '<' ty=type '>'
;
hybridAlloc
: '.newhybrid' nam=HAIL_NAME '<' ty=type '>' len=intExpr
;
memInit
: '.init' lv=lValue '=' rv=rValue
;
lValue
: nam=name (indices+=index)*
;
rValue
: GLOBAL_NAME # RVGlobal
| intLiteral # RVInt
| floatLiteral # RVFloat
| doubleLiteral # RVDouble
| 'NULL' # RVNull
| HAIL_NAME # RVHailRef
| '&' lValue # RVIRefOf
| list # RVList
;
list
: '{' rv+=rValue* '}'
;
index
: '[' intExpr ']'
;
intExpr
: intLiteral # IntLit
| GLOBAL_NAME # IntGlobal
;
type
: GLOBAL_NAME
;
name
: GLOBAL_NAME
| HAIL_NAME
;
intLiteral
: INT_DEC
| INT_OCT
| INT_HEX
;
floatLiteral
: FP_NUM 'f' # FloatNumber
| INF 'f' # FloatInf
| NAN 'f' # FloatNan
| 'bitsf' '(' intLiteral ')' # FloatBits
;
doubleLiteral
: FP_NUM 'd' # DoubleNumber
| INF 'd' # DoubleInf
| NAN 'd' # DoubleNan
| 'bitsd' '(' intLiteral ')' # DoubleBits
;
// LEXER
INT_DEC
: ('+'|'-')? DIGIT_NON_ZERO DIGIT*
;
INT_OCT
: ('+'|'-')? '0' OCT_DIGIT*
;
INT_HEX
: ('+'|'-')? '0x' HEX_DIGIT+
;
FP_NUM
: ('+'|'-')? DIGIT+ '.' DIGIT+ ('e' ('+'|'-')? DIGIT+)?
;
INF
: ('+'|'-') 'inf'
;
NAN
: 'nan'
;
GLOBAL_NAME
: GLOBAL_NAME_PREFIX IDCHAR+
;
HAIL_NAME
: HAIL_NAME_PREFIX IDCHAR+
;
fragment
DIGIT
: [0-9]
;
fragment
DIGIT_NON_ZERO
: [1-9]
;
fragment
OCT_DIGIT
: [0-7]
;
fragment
HEX_DIGIT
: [0-9a-fA-F]
;
fragment
GLOBAL_NAME_PREFIX: '@';
fragment
HAIL_NAME_PREFIX: '$';
fragment
IDCHAR
: [a-z]
| [A-Z]
| [0-9]
| '-'
| '_'
| '.'
;
WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines
LINE_COMMENT
: '//' ~[\r\n]* -> skip
;
package uvm.hail
import scala.collection.mutable.ArrayBuffer
import uvm.IdentifiedSettable
import uvm.types.Type
import uvm.ssavariables.GlobalVariable
import uvm.types.TypeHybrid
trait Locatable {
val line: Int
val col: Int
val span: Int
}
class HailScript {
val defs = new ArrayBuffer[HailDef]()
}
abstract class HailDef
abstract class HailAlloc extends HailDef with IdentifiedSettable
case class NewFixed(ty: Type) extends HailAlloc
case class NewHybrid(ty: TypeHybrid, len: Long) extends HailAlloc
case class Init(lv: LValue, rv: RValue) extends HailDef
case class LValue(base: Base, indices: Seq[Long])
abstract class Base
case class BaseGlobal(gv: GlobalVariable)
case class BaseHail(ha: HailAlloc)
abstract class RValue
case class RVGlobal(gv: GlobalVariable) extends RValue
case class RVInt(num: Long) extends RValue
case class RVFloat(num: Float) extends RValue
case class RVDouble(num: Double) extends RValue
case class RVNull() extends RValue
case class RVHailRef(ha: HailAlloc) extends RValue
case class RVIRefOf(lv: LValue) extends RValue
case class RVList(rvs: Seq[RValue]) extends RValue
package uvm.hail.textinput
class HailTextReader {
}
\ No newline at end of file
package uvm.refimpl.hail
import uvm.refimpl.MicroVM
import uvm.ir.textinput.gen.HAILParser.HailContext
class HailScriptLoader(implicit microVM: MicroVM) {
def loadHail(hailScript: String): Unit = {
???
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment