Skip to content

Commit c9d4b40

Browse files
author
Guannan Wei
committed
minor refactor
1 parent b2afc58 commit c9d4b40

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

src/main/scala/wasm/AST.scala

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,6 @@ case object MemoryFill extends Instr
104104
case object MemoryCopy extends Instr
105105
case class MemoryInit(seg: Int) extends Instr
106106
// case class DataDrop(seg: Int) extends Instr
107-
// case class RefNull(ty: RefType) extends Instr
108-
// case class RefFunc(func: Int) extends Instr
109-
// case object RefIsNull extends Instr
110-
case class PushSym(name: String, concreteVal: Num) extends Instr
111-
case class Symbolic(ty: ValueType) extends Instr
112-
case object SymAssert extends Instr
113107
case class Const(num: Num) extends Instr
114108
case class Test(op: TestOp) extends Instr
115109
case class Compare(op: RelOp) extends Instr
@@ -132,17 +126,23 @@ case class Convert(op: CvtOp) extends Instr
132126
// case class VecExtract(op: VecExtractOp) extends Instr
133127
// case class VecReplace(op: VecReplaceOp) extends Instr
134128

129+
// Instructions for symbolic execution
130+
case class PushSym(name: String, concreteVal: Num) extends Instr
131+
case class Symbolic(ty: ValueType) extends Instr
132+
case object SymAssert extends Instr
133+
135134
// TODO: add wasmfx instructions
136135
// TODO: should I take care of the unresolved cases?
137-
case class Suspend(tag_id: Int) extends Instr
136+
case class Suspend(tag: Int) extends Instr
138137
// note that cont.new can only be called with a func type
139-
case class ContNew(ty_id: Int) extends Instr
138+
case class ContNew(ty: Int) extends Instr
139+
// case class RefNull(ty: RefType) extends Instr
140+
// case object RefIsNull extends Instr
140141
// note that ref.func can be called with any of the extended function type
141-
case class RefFunc(ty_id: Int) extends Instr
142-
143-
case class Resume(ty_id: Int, ons: List[Handler]) extends Instr
142+
case class RefFunc(ty: Int) extends Instr
143+
case class Resume(ty: Int, ons: List[Handler]) extends Instr
144144
// TODO: make sure this class wants to extend WIR
145-
case class Handler(tag_id: Int, label_id: Int) extends WIR
145+
case class Handler(tag: Int, label: Int) extends WIR
146146

147147
trait Unresolved
148148
case class CallUnresolved(name: String) extends Instr with Unresolved
@@ -266,7 +266,6 @@ case class ValBlockType(tipe: Option[ValueType]) extends BlockType;
266266
case class RTGlobal(ty: GlobalType, var value: Value)
267267

268268
// Values
269-
270269
abstract class Value extends WIR {
271270
def tipe: ValueType
272271
}

src/main/scala/wasm/Parser.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class GSWasmVisitor extends WatParserBaseVisitor[WIR] {
101101
Start(id.toInt)
102102
}
103103

104-
override def visitNumType(ctx: NumTypeContext): NumType = toNumType(ctx.VALUE_TYPE().getText)
104+
override def visitNumType(ctx: NumTypeContext): NumType = toNumType(ctx.VALUE_TYPE.getText)
105105

106106
override def visitVecType(ctx: VecTypeContext): VecType = VecType(V128Type)
107107

@@ -402,11 +402,11 @@ class GSWasmVisitor extends WatParserBaseVisitor[WIR] {
402402
} else if (ctx.FREE != null) {
403403
Free
404404
} else if (ctx.SUSPEND != null) {
405-
Suspend(getVar(ctx.idx(0)).toInt)
405+
Suspend(getVar(ctx.idx(0)).toInt)
406406
} else if (ctx.CONTNEW != null) {
407-
ContNew(getVar(ctx.idx(0)).toInt)
407+
ContNew(getVar(ctx.idx(0)).toInt)
408408
} else if (ctx.REFFUNC != null) {
409-
RefFunc(getVar(ctx.idx(0)).toInt)
409+
RefFunc(getVar(ctx.idx(0)).toInt)
410410
}
411411
else {
412412
println(s"unimplemented parser for: ${ctx.getText}")
@@ -444,12 +444,12 @@ class GSWasmVisitor extends WatParserBaseVisitor[WIR] {
444444

445445
override def visitResumeInstr(ctx: ResumeInstrContext): WIR = {
446446
val funcTypeId = getVar(ctx.idx).toInt
447-
val handlers = ctx.handlerInstr().asScala.map(visitHandlerInstr).toList
447+
val handlers = ctx.handlerInstr.asScala.map(visitHandlerInstr).toList
448448
Resume(funcTypeId, handlers)
449449
}
450450

451451
override def visitBlock(ctx: BlockContext): WIR = {
452-
val ty = visitBlockType(ctx.blockType())
452+
val ty = visitBlockType(ctx.blockType)
453453
val InstrList(instrs) = visit(ctx.instrList)
454454
Block(ty, instrs)
455455
}

0 commit comments

Comments
 (0)