GitLab will be upgraded on 30 Jan 2023 from 2.00 pm (AEDT) to 3.00 pm (AEDT). During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to us at N110 (b) CSIT building.

VMConf.scala 2.11 KB
Newer Older
Kunshan Wang's avatar
Kunshan Wang committed
1
2
3
4
5
6
7
8
9
10
/**
 * This class allows the MicroVM to be configured from a text string. It increases the flexibility of language bindings.
 * Other programming languages can set heap/global sizes and logging via this interface. It is less static than a fixed
 * MicroVM constructor signature, but more options can be added/removed without changing the C binding API.
 */
package uvm.refimpl

import uvm.refimpl.mem.TypeSizes._

object VMConf {
Kunshan Wang's avatar
Kunshan Wang committed
11
12
  val DEFAULT_CONF = new VMConf()
  
Kunshan Wang's avatar
Kunshan Wang committed
13
14
15
16
17
  val ReComment = """^\s*#.*$""".r
  val ReBlank = """^\s*$""".r
  val ReConf = """^\s*(\w+)=(\w+)\s*$""".r

  def apply(confStr: String): VMConf = {
Kunshan Wang's avatar
Kunshan Wang committed
18
19
20
21
22
    var sosSize = DEFAULT_CONF.sosSize
    var losSize = DEFAULT_CONF.losSize
    var globalSize = DEFAULT_CONF.globalSize
    var stackSize = DEFAULT_CONF.stackSize
    var staticCheck = DEFAULT_CONF.staticCheck
Kunshan Wang's avatar
Kunshan Wang committed
23
24
25
26
27
28
29
30
31
    confStr.lines foreach {
      case ReComment() => 
      case ReBlank() =>
      case ReConf(key, value) => {
        key match {
          case "sosSize" => sosSize = value.toLong
          case "losSize" => losSize = value.toLong
          case "globalSize" => globalSize = value.toLong
          case "stackSize" => stackSize = value.toLong
Kunshan Wang's avatar
Kunshan Wang committed
32
          case "staticCheck" => staticCheck = value.toLowerCase().toBoolean
33
          case "vmLog" => setLog("uvm", value)
Kunshan Wang's avatar
Kunshan Wang committed
34
35
36
37
38
          case "gcLog" => setLog("uvm.refimpl.mem", value)
          case _ => throw new UvmRefImplException("Unrecognized option %s".format(key))
        }
      }
    }
Kunshan Wang's avatar
Kunshan Wang committed
39
    new VMConf(sosSize, losSize, globalSize, stackSize, staticCheck)
Kunshan Wang's avatar
Kunshan Wang committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  }
  
  def setLog(name: String, levelStr: String): Unit = {
    import org.slf4j.LoggerFactory
    import org.slf4j.{ Logger => SLogger }
    import ch.qos.logback.classic.{ Logger => LLogger, Level }
    import ch.qos.logback.classic.Level._

    val level = Level.toLevel(levelStr)

    LoggerFactory.getLogger(name).asInstanceOf[LLogger].setLevel(level)
  }
}

class VMConf(
  val sosSize: Word = MicroVM.DEFAULT_SOS_SIZE,
  val losSize: Word = MicroVM.DEFAULT_LOS_SIZE,
  val globalSize: Word = MicroVM.DEFAULT_GLOBAL_SIZE,
Kunshan Wang's avatar
Kunshan Wang committed
58
59
  val stackSize: Word = MicroVM.DEFAULT_STACK_SIZE,
  val staticCheck: Boolean = true)
Kunshan Wang's avatar
Kunshan Wang committed
60