WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

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

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