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.6% of users enabled 2FA.

Commit 5230f706 authored by Kunshan Wang's avatar Kunshan Wang
Browse files

Updated UIR grammar.

parent 59a4acb4
...@@ -6,11 +6,10 @@ description := "The second reference implementation of MicroVM" ...@@ -6,11 +6,10 @@ description := "The second reference implementation of MicroVM"
licenses := Seq("CC BY-SA 4.0" -> url("https://creativecommons.org/licenses/by-sa/4.0/legalcode")) licenses := Seq("CC BY-SA 4.0" -> url("https://creativecommons.org/licenses/by-sa/4.0/legalcode"))
scalaVersion := "2.11.2" scalaVersion := "2.11.4"
libraryDependencies := Seq( libraryDependencies := Seq(
"org.antlr" % "antlr4" % "4.3", "org.antlr" % "antlr4" % "4.3",
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.2",
"org.scalatest" %% "scalatest" % "2.2.0" "org.scalatest" %% "scalatest" % "2.2.0"
) )
......
/* grammar UIR;
* defines uVM IR text form
*/
grammar uIR;
ir ir
: metaData* : topLevelDef*
; ;
metaData topLevelDef
: typeDef : typeDef
| funcSigDef | funcSigDef
| constDef | constDef
...@@ -18,252 +14,234 @@ metaData ...@@ -18,252 +14,234 @@ metaData
; ;
typeDef typeDef
: '.typedef' GLOBAL_ID '=' typeConstructor : '.typedef' nam=GLOBAL_NAME '=' ctor=typeConstructor
; ;
funcSigDef funcSigDef
: '.funcsig' GLOBAL_ID '=' funcSigConstructor : '.funcsig' nam=GLOBAL_NAME '=' ctor=funcSigConstructor
; ;
constDef constDef
: '.const' GLOBAL_ID '<' type '>' '=' constExpr : '.const' nam=GLOBAL_NAME '<' ty=type '>' '=' ctor=constConstructor
; ;
globalDef globalDef
: '.global' GLOBAL_ID '<' type '>' : '.global' nam=GLOBAL_NAME '<' ty=type '>'
; ;
funcDecl funcDecl
: '.funcdecl' GLOBAL_ID '<' funcSig '>' : '.funcdecl' nam=GLOBAL_NAME '<' sig=funcSig '>'
; ;
funcDef funcDef
: '.funcdef' GLOBAL_ID '<' funcSig '>' paramList funcBody : '.funcdef' nam=GLOBAL_NAME 'VERSION' ver=GLOBAL_NAME '<' sig=funcSig '>' params=paramList body=funcBody
;
type
: GLOBAL_ID # ReferencedType
| typeConstructor # InLineType
; ;
typeConstructor typeConstructor
: 'int' '<' intLiteral '>' # IntType : 'int' '<' length=intLiteral '>' # TypeInt
| 'float' # FloatType | 'float' # TypeFloat
| 'double' # DoubleType | 'double' # TypeDouble
| 'ref' '<' type '>' # RefType | 'ref' '<' type '>' # TypeRef
| 'iref' '<' type '>' # IRefType | 'iref' '<' type '>' # TypeIRef
| 'weakref' '<' type '>' # WeakRefType | 'weakref' '<' type '>' # TypeWeakRef
| 'struct' '<' type* '>' # StructType | 'struct' '<' type+ '>' # TypeStruct
| 'array' '<' type intLiteral '>' # ArrayType | 'array' '<' type length=intLiteral '>' # TypeArray
| 'hybrid' '<' type type '>' # HybridType | 'hybrid' '<' fixedTy=type varTy=type '>' # TypeHybrid
| 'void' # VoidType | 'void' # TypeVoid
| 'func' '<' funcSig '>' # FuncType | 'func' '<' funcSig '>' # TypeFunc
| 'thread' # ThreadType | 'thread' # TypeThread
| 'stack' # StackType | 'stack' # TypeStack
| 'tagref64' # TagRef64Type | 'tagref64' # TypeTagRef64
; | 'vector' '<' type length=intLiteral '>' # TypeVector
funcSig
: GLOBAL_ID # ReferencedFuncSig
| funcSigConstructor # InLineFuncSig
; ;
funcSigConstructor funcSigConstructor
: type '(' type* ')' : retTy=type '(' (paramTy=type*) ')'
; ;
constant constConstructor
: GLOBAL_ID # ReferencedConst : intLiteral # ConstInt
| constExpr # InLineConst | floatLiteral # ConstFloat
| doubleLiteral # ConstDouble
| '{' constant* '}' # ConstStruct
| 'NULL' # ConstNull
| 'VEC' '{' constant* '}' # ConstVector
; ;
constExpr type
: intLiteral # IntConst : GLOBAL_NAME
| floatLiteral # FloatConst
| doubleLiteral # DoubleConst
| '{' constant* '}' # StructConst
| 'NULL' # NullConst
; ;
paramList funcSig
: '(' LOCAL_ID* ')' : GLOBAL_NAME
; ;
funcBody constant
: '{' basicBlocks '}' : GLOBAL_NAME
; ;
basicBlocks paramList
: entryBlock regularBlock* : '(' name* ')'
; ;
entryBlock funcBody
: label? inst+ : '{' basicBlock* '}'
; ;
regularBlock basicBlock
: label inst+ : label inst+
; ;
label label
: LOCAL_ID ':' : name ':'
; ;
inst inst
: (LOCAL_ID '=')? instBody : (name '=')? instBody
; ;
instBody instBody
// Integer/FP Arithmetic // Integer/FP Arithmetic
: binops '<' type '>' value value # InstBinOp : binop '<' type '>' op1=value op2=value excClause # InstBinOp
// Integer/FP Comparison // Integer/FP Comparison
| cmpops '<' type '>' value value # InstCmp | cmpop '<' type '>' op1=value op2=value # InstCmp
// Conversions // Conversions
| convops '<' type type '>' value # InstConversion | convop '<' fromTy=type toTy=type '>' opnd=value # InstConversion
// Select // Select
| 'SELECT' '<' type '>' value value value # InstSelect | 'SELECT' '<' condTy=type resTy=type '>' cond=value ifTrue=value ifFalse=value # InstSelect
// Intra-function Control Flow // Intra-function Control Flow
| 'BRANCH' LOCAL_ID # InstBranch | 'BRANCH' bbName # InstBranch
| 'BRANCH2' value LOCAL_ID LOCAL_ID # InstBranch2 | 'BRANCH2' cond=value ifTrue=bbName ifFalse=bbName # InstBranch2
| 'SWITCH' '<' type '>' value LOCAL_ID '{' | 'SWITCH' '<' type '>' opnd=value defDest=bbName '{'
(value ':' LOCAL_ID ';')* '}' # InstSwitch (caseVal=value ':' caseDest=bbName ';')* '}' # InstSwitch
| 'PHI' '<' type '>' '{' | 'PHI' '<' type '>' '{'
(LOCAL_ID ':' value ';')* '}' # InstPhi (caseSrc=bbName ':' caseVal=value ';')* '}' # InstPhi
// Inter-function Control Flow // Inter-function Control Flow
| 'CALL' funcCallBody keepAlive? # InstCall | 'CALL' funcCallBody excClause keepAliveClause # InstCall
| 'INVOKE' funcCallBody LOCAL_ID LOCAL_ID keepAlive? # InstInvoke
| 'TAILCALL' funcCallBody # InstTailCall | 'TAILCALL' funcCallBody # InstTailCall
| 'RET' '<' type '>' value # InstRet | 'RET' '<' type '>' retVal=value # InstRet
| 'RETVOID' # InstRetVoid | 'RETVOID' # InstRetVoid
| 'THROW' value # InstThrow | 'THROW' exc=value # InstThrow
| 'LANDINGPAD' # InstLandingPad | 'LANDINGPAD' # InstLandingPad
// Aggregate Operations // Aggregate Operations
| 'EXTRACTVALUE' '<' type intLiteral '>' value # InstExtractValue | 'EXTRACTVALUE' '<' type intLiteral '>' opnd=value # InstExtractValue
| 'INSERTVALUE' '<' type intLiteral '>' value value # InstInsertValue | 'INSERTVALUE' '<' type intLiteral '>' opnd=value newVal=value # InstInsertValue
| 'EXTRACTELEMENT' '<' vecTy=type indTy=type '>' opnd=value index=value # InstExtractElement
| 'INSERTELEMENT' '<' vecTy=type indTy=type '>' opnd=value index=value opnd=value newVal=value # InstInsertElement
| 'SHUFFLEVECTOR' '<' vecTy=type maskTy=type '>' vec1=value vec2=value mask=value # InstShuffleVector
// Memory Operations // Memory Operations
| 'NEW' '<' type '>' # InstNew | 'NEW' '<' allocTy=type '>' excClause # InstNew
| 'NEWHYBRID' '<' type '>' value # InstNewHybrid | 'NEWHYBRID' '<' allocTy=type lenTy=type '>' length=value excClause # InstNewHybrid
| 'ALLOCA' '<' type '>' # InstAlloca | 'ALLOCA' '<' allocTy=type '>' excClause # InstAlloca
| 'ALLOCAHYBRID' '<' type '>' value # InstAllocaHybrid | 'ALLOCAHYBRID' '<' allocTy=type lenTy=type '>' length=value excClause # InstAllocaHybrid
| 'GETIREF' '<' type '>' value # InstGetIRef | 'GETIREF' '<' refTy=type '>' opnd=value # InstGetIRef
| 'GETFIELDIREF' '<' type intLiteral '>' value # InstGetFieldIRef | 'GETFIELDIREF' '<' refTy=type index=intLiteral '>' opnd=value # InstGetFieldIRef
| 'GETELEMIREF' '<' type '>' value value # InstGetElemIRef | 'GETELEMIREF' '<' refTy=type indTy=type '>' opnd=value index=value # InstGetElemIRef
| 'SHIFTIREF' '<' type '>' value value # InstShiftIRef | 'SHIFTIREF' '<' refTy=type offTy=type '>' opnd=value offset=value # InstShiftIRef
| 'GETFIXEDPARTIREF' '<' type '>' value # InstGetFixedPartIRef | 'GETFIXEDPARTIREF' '<' refTy=type '>' opnd=value # InstGetFixedPartIRef
| 'GETVARPARTIREF' '<' type '>' value # InstGetVarPartIRef | 'GETVARPARTIREF' '<' refTy=type '>' opnd=value # InstGetVarPartIRef
| 'LOAD' atomicord? '<' type '>' value # InstLoad | 'LOAD' memord? '<' type '>' loc=value excClause # InstLoad
| 'STORE' atomicord? '<' type '>' value value # InstStore | 'STORE' memord? '<' type '>' loc=value newVal=value excClause # InstStore
| 'CMPXCHG' atomicord atomicord | 'CMPXCHG' (isWeak='WEAK'?) ordSucc=memord ordFail=memord
'<' type '>' value value value # InstCmpXchg '<' type '>' loc=value expected=value desired=value excClause # InstCmpXchg
| 'ATOMICRMW' atomicord atomicrmwop | 'ATOMICRMW' memord atomicrmwop '<' type '>' loc=value opnd=value excClause # InstAtomicRMW
'<' type '>' value value # InstAtomicRMW
| 'FENCE' atomicord # InstFence | 'FENCE' memord # InstFence
// Trap // Trap
| 'TRAP' '<' type '>' | 'TRAP' '<' type '>' excClause keepAliveClause # InstTrap
LOCAL_ID LOCAL_ID keepAlive # InstTrap | 'WATCHPOINT' wpid=intLiteral '<' type '>'
| 'WATCHPOINT' intLiteral '<' type '>' dis=bbName ena=bbName ('WPEXC' '(' wpExc=bbName ')')? keepAliveClause # InstWatchPoint
LOCAL_ID LOCAL_ID LOCAL_ID keepAlive # InstWatchPoint
// Foreign Function Interface // Foreign Function Interface
| 'CCALL' callconv funcCallBody # InstCCall | 'CCALL' '<' type '>' callconv funcCallBody # InstCCall
// Thread and Stack Operations // Thread and Stack Operations
| 'NEWSTACK' funcCallBody # InstNewStack | 'NEWSTACK' funcCallBody excClause # InstNewStack
| 'SWAPSTACK' swappee=value curStackClause newStackClause excClause keepAliveClause # InstSwapStack
// Intrinsic Functions // Common Instructions
| 'ICALL' GLOBAL_ID args keepAlive? # InstICall | 'COMMINST' typeList? argList? excClause keepAliveClause # InstCommInst
| 'IINVOKE' GLOBAL_ID args
LOCAL_ID LOCAL_ID keepAlive? # InstIInvoke
; ;
funcCallBody bbName
: '<' funcSig '>' value args : name
; ;
args value
: '(' value* ')' : name
; ;
keepAlive funcCallBody
: 'KEEPALIVE' '(' value* ')' : '<' funcSig '>' callee=value argList
; ;
callconv : 'DEFAULT' ; excClause
: ('EXC' '(' nor=bbName exc=bbName ')')?
;
binops : ibinops | fbinops ; keepAliveClause
: ('KEEPALIVE' '(' value* ')')?
;
ibinops typeList
: 'ADD' : '<' type* '>'
| 'SUB'
| 'MUL'
| 'UDIV'
| 'SDIV'
| 'UREM'
| 'SREM'
| 'SHL'
| 'LSHR'
| 'ASHR'
| 'AND'
| 'OR'
| 'XOR'
; ;
fbinops argList
: 'FADD' | 'FSUB' | 'FMUL' | 'FDIV' | 'FREM' : '(' value* ')'
;
curStackClause
: 'RET_WITH' '<' type '>' # CurStackRetWith
| 'KILL_OLD' # CurStackKillOld
; ;
cmpops : icmpops | fcmpops ; newStackClause
: 'PASS_PARAM' '<' type '>' value # NewStackPassParam
| 'NO_PARAM' # NewStackNoParam
| 'THROW_EXC' exc=value # NewStackThrowExc
;
icmpops binop
: 'EQ' : 'ADD' | 'SUB' | 'MUL' | 'UDIV' | 'SDIV' | 'UREM' | 'SREM' | 'SHL' | 'LSHR' | 'ASHR' | 'AND' | 'OR' | 'XOR'
| 'NE' | 'FADD'| 'FSUB' | 'FMUL' | 'FDIV' | 'FREM'
| 'SGT'
| 'SLT'
| 'SGE'
| 'SLE'
| 'UGT'
| 'ULT'
| 'UGE'
| 'ULE'
; ;
fcmpops cmpop
: 'FTRUE' | 'FFALSE' : 'EQ' | 'NE' | 'SGT' | 'SLT' | 'SGE' | 'SLE' | 'UGT' | 'ULT' | 'UGE' | 'ULE'
| 'FTRUE' | 'FFALSE'
| 'FUNO' | 'FUEQ' | 'FUNE' | 'FUGT' | 'FULT' | 'FUGE' | 'FULE' | 'FUNO' | 'FUEQ' | 'FUNE' | 'FUGT' | 'FULT' | 'FUGE' | 'FULE'
| 'FORD' | 'FOEQ' | 'FONE' | 'FOGT' | 'FOLT' | 'FOGE' | 'FOLE' | 'FORD' | 'FOEQ' | 'FONE' | 'FOGT' | 'FOLT' | 'FOGE' | 'FOLE'
; ;
convops convop
: 'TRUNC' | 'ZEXT' | 'SEXT' | 'FPTRUNC' | 'FPEXT' : 'TRUNC' | 'ZEXT' | 'SEXT' | 'FPTRUNC' | 'FPEXT'
| 'FPTOUI' | 'FPTOSI' | 'UITOFP' | 'SITOFP' | 'BITCAST' | 'FPTOUI' | 'FPTOSI' | 'UITOFP' | 'SITOFP'
| 'REFCAST' | 'IREFCAST' | 'FUNCCAST' | 'BITCAST' | 'REFCAST'
; ;
atomicord memord
: 'NOT_ATOMIC' | 'UNORDERED' | 'MONOTONIC' | 'ACQUIRE' | 'RELEASE' : 'NOT_ATOMIC' | 'RELAXED' | 'CONSUME' | 'ACQUIRE' | 'RELEASE' | 'ACQ_REL' | 'SEQ_CST'
| 'ACQ_REL' | 'SEQ_CST'
; ;
atomicrmwop atomicrmwop
: 'XCHG' | 'ADD' | 'SUB' | 'AND' | 'NAND' | 'OR' | 'XOR' : 'XCHG' | 'ADD' | 'SUB' | 'AND' | 'NAND' | 'OR' | 'XOR' | 'MAX' | 'MIN' | 'UMAX' | 'UMIN'
| 'MAX' | 'MIN' | 'UMAX' | 'UMIN'
; ;
value
: identifier # ReferencedValue callconv
| constExpr # InlineConstValue : 'DEFAULT'
; ;
intLiteral intLiteral
...@@ -278,6 +256,7 @@ floatLiteral ...@@ -278,6 +256,7 @@ floatLiteral
| NAN 'f' # FloatNan | NAN 'f' # FloatNan
| 'bitsf' '(' intLiteral ')' # FloatBits | 'bitsf' '(' intLiteral ')' # FloatBits
; ;
doubleLiteral doubleLiteral
: FP_NUM 'd' # DoubleNumber : FP_NUM 'd' # DoubleNumber
| INF 'd' # DoubleInf | INF 'd' # DoubleInf
...@@ -285,9 +264,9 @@ doubleLiteral ...@@ -285,9 +264,9 @@ doubleLiteral
| 'bitsd' '(' intLiteral ')' # DoubleBits | 'bitsd' '(' intLiteral ')' # DoubleBits
; ;
identifier name
: GLOBAL_ID : GLOBAL_NAME
| LOCAL_ID | LOCAL_NAME
; ;
// LEXER // LEXER
...@@ -316,12 +295,12 @@ NAN ...@@ -316,12 +295,12 @@ NAN
: 'nan' : 'nan'
; ;
GLOBAL_ID GLOBAL_NAME
: GLOBAL_ID_PREFIX IDCHAR+ : GLOBAL_NAME_PREFIX IDCHAR+
; ;
LOCAL_ID LOCAL_NAME
: LOCAL_ID_PREFIX IDCHAR+ : LOCAL_NAME_PREFIX IDCHAR+
; ;
fragment fragment
...@@ -340,10 +319,10 @@ HEX_DIGIT ...@@ -340,10 +319,10 @@ HEX_DIGIT
; ;
fragment fragment
GLOBAL_ID_PREFIX: '@'; GLOBAL_NAME_PREFIX: '@';
fragment fragment
LOCAL_ID_PREFIX: '%'; LOCAL_NAME_PREFIX: '%';
fragment fragment
IDCHAR IDCHAR
......
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