GitLab will continue to be upgraded from 11.4.5-ce.0 on November 25th 2019 at 4.00pm (AEDT) to 5.00pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available.

Commit 7a1a6da7 authored by Kunshan Wang's avatar Kunshan Wang

IRReader now passes names to IDFactory

parent 1aaa1356
...@@ -22,7 +22,7 @@ import com.typesafe.scalalogging.Logger ...@@ -22,7 +22,7 @@ import com.typesafe.scalalogging.Logger
import uvm.ir.textinput.gen.UIRParser.StringLiteralContext import uvm.ir.textinput.gen.UIRParser.StringLiteralContext
import uvm.ir.textinput.gen.UIRParser.StringLiteralContext import uvm.ir.textinput.gen.UIRParser.StringLiteralContext
class UIRTextReader(val idFactory: IDFactory, val recordSourceInfo: Boolean = true) { class UIRTextReader(val defaultIDFactory: IDFactory, val recordSourceInfo: Boolean = true) {
import UIRTextReader._ import UIRTextReader._
def read(ir: java.io.Reader, globalBundle: GlobalBundle): TrantientBundle = { def read(ir: java.io.Reader, globalBundle: GlobalBundle): TrantientBundle = {
...@@ -60,6 +60,10 @@ class UIRTextReader(val idFactory: IDFactory, val recordSourceInfo: Boolean = tr ...@@ -60,6 +60,10 @@ class UIRTextReader(val idFactory: IDFactory, val recordSourceInfo: Boolean = tr
} }
def read(source: String, ais: ANTLRInputStream, globalBundle: GlobalBundle): TrantientBundle = { def read(source: String, ais: ANTLRInputStream, globalBundle: GlobalBundle): TrantientBundle = {
read(source, ais, globalBundle, defaultIDFactory)
}
def read(source: String, ais: ANTLRInputStream, globalBundle: GlobalBundle, idFactory: IDFactory): TrantientBundle = {
val ast = parse(source, ais) val ast = parse(source, ais)
logger.debug("Antlr parsed. Reading UIR AST into a Bundle...") logger.debug("Antlr parsed. Reading UIR AST into a Bundle...")
val instanceReader = new InstanceUIRTextReader(idFactory, source, ast, globalBundle, recordSourceInfo) val instanceReader = new InstanceUIRTextReader(idFactory, source, ast, globalBundle, recordSourceInfo)
...@@ -207,15 +211,17 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str ...@@ -207,15 +211,17 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
ir.topLevelDef.map(_.getChild(0)).foreach { ir.topLevelDef.map(_.getChild(0)).foreach {
case td: TypeDefContext => { case td: TypeDefContext => {
val ty = mkType(td.typeConstructor) val ty = mkType(td.typeConstructor)
ty.id = idFactory.getID() val name = td.nam
ty.name = Some(td.nam) ty.id = idFactory.getID(name)
addTy(ty, toSourceInfo(td.nam)) ty.name = Some(name)
addTy(ty, toSourceInfo(name))
} }
case fsd: FuncSigDefContext => { case fsd: FuncSigDefContext => {
val sig = mkSig(fsd.funcSigConstructor) val sig = mkSig(fsd.funcSigConstructor)
sig.id = idFactory.getID() val name = fsd.nam
sig.name = Some(fsd.nam) sig.id = idFactory.getID(name)
addSig(sig, toSourceInfo(fsd.nam)) sig.name = Some(name)
addSig(sig, toSourceInfo(name))
} }
case _ => case _ =>
} }
...@@ -263,7 +269,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str ...@@ -263,7 +269,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
def declFunc(n: String, s: FuncSigContext, sourceInfo: SourceInfo): Function = { def declFunc(n: String, s: FuncSigContext, sourceInfo: SourceInfo): Function = {
val sig = resSig(s) val sig = resSig(s)
val func = mkFunc(sig) val func = mkFunc(sig)
func.id = idFactory.getID() func.id = idFactory.getID(n)
func.name = Some(n) func.name = Some(n)
addFunc(func, sourceInfo) addFunc(func, sourceInfo)
...@@ -277,16 +283,18 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str ...@@ -277,16 +283,18 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
case cdctx: ConstDefContext => { case cdctx: ConstDefContext => {
val ty = resTy(cdctx.ty) val ty = resTy(cdctx.ty)
val con = mkConst(ty, cdctx.constConstructor) val con = mkConst(ty, cdctx.constConstructor)
con.id = idFactory.getID() val name = cdctx.nam
con.name = Some(cdctx.nam) con.id = idFactory.getID(name)
addConst(con, toSourceInfo(cdctx.nam)) con.name = Some(name)
addConst(con, toSourceInfo(name))
} }
case gdctx: GlobalDefContext => { case gdctx: GlobalDefContext => {
val ty = resTy(gdctx.ty) val ty = resTy(gdctx.ty)
val gc = mkGlobalCell(ty) val gc = mkGlobalCell(ty)
gc.id = idFactory.getID() val name = gdctx.nam
gc.name = Some(gdctx.nam) gc.id = idFactory.getID(name)
addGlobalCell(gc, toSourceInfo(gdctx.nam)) gc.name = Some(name)
addGlobalCell(gc, toSourceInfo(name))
} }
case fdecl: FuncDeclContext => { case fdecl: FuncDeclContext => {
val name = globalNameToString(fdecl.nam) val name = globalNameToString(fdecl.nam)
...@@ -303,9 +311,10 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str ...@@ -303,9 +311,10 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
} }
case edef: FuncExpDefContext => { case edef: FuncExpDefContext => {
val efun = mkExpo(edef) val efun = mkExpo(edef)
efun.id = idFactory.getID() val name = edef.nam
efun.name = Some(edef.nam) efun.id = idFactory.getID(name)
addExpFunc(efun, toSourceInfo(edef.nam)) efun.name = Some(name)
addExpFunc(efun, toSourceInfo(name))
} }
case _ => {} case _ => {}
} }
...@@ -318,7 +327,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str ...@@ -318,7 +327,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
logger.trace("Visiting function %s".format(func.name)) logger.trace("Visiting function %s".format(func.name))
val ver = new FuncVer(func) val ver = new FuncVer(func)
val verName = globalize(fDefCtx.ver, func.name.get) val verName = globalize(fDefCtx.ver, func.name.get)
ver.id = idFactory.getID() ver.id = idFactory.getID(verName)
ver.name = Some(verName) ver.name = Some(verName)
addFuncVer(ver, toSourceInfo(fDefCtx.ver)) addFuncVer(ver, toSourceInfo(fDefCtx.ver))
...@@ -344,7 +353,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str ...@@ -344,7 +353,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
val label = bbCtx.label() val label = bbCtx.label()
val bbName = globalize(label.name(), verName) val bbName = globalize(label.name(), verName)
val bb = new BasicBlock(ver) val bb = new BasicBlock(ver)
bb.id = idFactory.getID() bb.id = idFactory.getID(bbName)
bb.name = Some(bbName) bb.name = Some(bbName)
addBB(bb, toSourceInfo(bbCtx)) addBB(bb, toSourceInfo(bbCtx))
...@@ -355,14 +364,14 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str ...@@ -355,14 +364,14 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
def mkNorParam(ty: Type, name: String): NorParam = { def mkNorParam(ty: Type, name: String): NorParam = {
val param = NorParam(ty) val param = NorParam(ty)
param.id = idFactory.getID() param.id = idFactory.getID(name)
param.name = Some(globalize(name, bbName)) param.name = Some(globalize(name, bbName))
param param
} }
def mkExcParam(name: String): ExcParam = { def mkExcParam(name: String): ExcParam = {
val param = ExcParam() val param = ExcParam()
param.id = idFactory.getID() param.id = idFactory.getID(name)
param.name = Some(globalize(name, bbName)) param.name = Some(globalize(name, bbName))
param param
} }
...@@ -608,8 +617,13 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str ...@@ -608,8 +617,13 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
} }
} }
inst.id = idFactory.getID() val maybeInstName = Option(instDef.name).map(n => globalize(n.getText, bbName))
inst.name = Option(instDef.name).map(n => globalize(n.getText, bbName)) // When reading from regular text IR, instructions may or may not have names, but the IDFactory at this time
// is SequentialIDFactory. It ignores the name. But when reading from the boot image, everything must be
// named and must have a corresponding ID. The "poison" name below will let MappedIDFactory throw
// NoSuchElementException.
inst.id = idFactory.getID(maybeInstName.getOrElse("@uvm.this_instruction_does_not_have_a_name"))
inst.name = maybeInstName
addInst(inst, toSourceInfo(instDef)) addInst(inst, toSourceInfo(instDef))
...@@ -619,7 +633,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str ...@@ -619,7 +633,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
val resName = globalize(instResDef.getText, bbName) val resName = globalize(instResDef.getText, bbName)
val instRes = InstResult(inst, index) val instRes = InstResult(inst, index)
instRes.id = idFactory.getID() instRes.id = idFactory.getID(resName)
instRes.name = Some(resName) instRes.name = Some(resName)
addLocalVar(instRes, toSourceInfo(instResDef)) addLocalVar(instRes, toSourceInfo(instResDef))
......
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