Skip to content

Commit

Permalink
Merge pull request #1144 from utwente-fmt/vcllvm
Browse files Browse the repository at this point in the history
Vcllvm
  • Loading branch information
pieter-bos authored Jan 25, 2024
2 parents 91ba3d0 + 5502336 commit 98281e6
Show file tree
Hide file tree
Showing 79 changed files with 3,245 additions and 3,513 deletions.
627 changes: 150 additions & 477 deletions build.sc

Large diffs are not rendered by default.

21 changes: 18 additions & 3 deletions mill-build/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import mill.util.Jvm
import scalalib._

object millbuild extends MillBuildRootModule {
def moduleDeps = Seq(structure)
def moduleDeps = Seq(structure, util)

def nodeSources = T.sources(
T.ctx().workspace / "src" / "col" / "vct" / "col" / "ast" / "Node.scala"
Expand Down Expand Up @@ -32,17 +32,32 @@ object millbuild extends MillBuildRootModule {

def compileResources = T { Seq.empty[PathRef] }

object util extends ScalaModule {
def scalaVersion = "2.13.12"
def ivyDeps = T {
Seq(
ivy"com.lihaoyi::mill-main:0.11.0",
ivy"com.lihaoyi::mill-main-api:0.11.0",
ivy"com.lihaoyi::mill-scalalib:0.11.0",
ivy"com.lihaoyi::mill-contrib-scalapblib:0.11.0",
ivy"me.pieterbos::mill-cpp_mill0.11::0.0.1",
)
}
def compileResources = T { Seq.empty[PathRef] }
def resources = T { Seq.empty[PathRef] }
}

object structure extends ScalaModule {
def scalaVersion = "2.13.12"
def ivyDeps = T { Seq(ivy"com.lihaoyi::upickle:3.1.3", ivy"com.lihaoyi::mill-main-define:0.11.4") }
def ivyDeps = T { Seq(ivy"com.lihaoyi::upickle:3.1.3", ivy"com.lihaoyi::os-lib:0.9.3") }
def compileResources = T { Seq.empty[PathRef] }
def resources = T { Seq.empty[PathRef] }
}

object analysis extends ScalaModule {
def scalaVersion = "2.13.12"
def moduleDeps = Seq(structure)
def ivyDeps = T { Seq(ivy"org.scalameta::scalameta:4.4.9") }
def ivyDeps = T { Seq(ivy"org.scalameta::scalameta:4.8.15", ivy"com.lihaoyi::os-lib:0.9.3") }
def compileResources = T { Seq.empty[PathRef] }
def resources = T { Seq.empty[PathRef] }
}
Expand Down
24 changes: 24 additions & 0 deletions mill-build/structure/src/Api.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package vct.col.ast.structure.api

import java.nio.file.Path

trait AllFamiliesGeneratorApi {
def generate(out: Path, declaredFamilies: String, structuralFamilies: String): Unit
}

trait AllNodesGeneratorApi {
def generate(out: Path, definitions: String): Unit
}

trait NodeGeneratorApi {
def generate(out: Path, node: String): Unit
}

trait FamilyGeneratorApi {
def generate(out: Path, family: String, kind: String, nodes: String): Unit
}

trait ImplTraitGeneratorApi {
def fix(p: Path, opsNames: String): Unit
def generate(p: Path, node: String, concrete: Boolean, family: Boolean): Unit
}
23 changes: 18 additions & 5 deletions mill-build/structure/src/Generator.scala
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
package vct.col.ast.structure

import vct.col.ast.structure.api._

import java.nio.file.Path
import upickle.default.read

trait AllFamiliesGenerator {
trait AllFamiliesGenerator extends AllFamiliesGeneratorApi {
override def generate(out: Path, declaredFamilies: String, structuralFamilies: String): Unit =
generate(out, read[Seq[Name]](declaredFamilies), read[Seq[Name]](structuralFamilies))
def generate(out: Path, declaredFamilies: Seq[Name], structuralFamilies: Seq[Name]): Unit
}

trait AllNodesGenerator {
trait AllNodesGenerator extends AllNodesGeneratorApi {
override def generate(out: Path, definitions: String): Unit =
generate(out, read[Seq[NodeDefinition]](definitions))
def generate(out: Path, definitions: Seq[NodeDefinition]): Unit
}

trait NodeGenerator {
trait NodeGenerator extends NodeGeneratorApi {
override def generate(out: Path, node: String): Unit =
generate(out, read[NodeDefinition](node))
def generate(out: Path, node: NodeDefinition): Unit
}

trait FamilyGenerator {
trait FamilyGenerator extends FamilyGeneratorApi {
override def generate(out: Path, family: String, kind: String, nodes: String): Unit =
generate(out, read[Name](family), read[NodeKind](kind), read[Seq[Name]](nodes))
def generate(out: Path, family: Name, kind: NodeKind, nodes: Seq[Name]): Unit
}

trait ImplTraitGenerator {
trait ImplTraitGenerator extends ImplTraitGeneratorApi {
override def fix(p: Path, opsNames: String): Unit =
fix(p, read[Seq[String]](opsNames))
def fix(p: Path, opsNames: Seq[String]): Unit
def generate(p: Path, node: String, concrete: Boolean, family: Boolean): Unit
}
1 change: 0 additions & 1 deletion mill-build/structure/src/Structure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ case class Name(parts: Seq[String]) {

object Name {
implicit val rw: RW[Name] = macroRW
implicit val segments: mill.define.Cross.ToSegments[Name] = new mill.define.Cross.ToSegments(n => n.parts.toList)
}

/**
Expand Down
23 changes: 23 additions & 0 deletions mill-build/util/src/settings.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import mill.{Agg, define}
import mill.scalalib.DepSyntax

package object settings {
val root = os.pwd
val src = root / "src"
val test = root / "test"
val res = root / "res"
val lib = root / "lib"
val docs = root / "docs"
val meta = root / "out" / "mill-build"

object deps {
val log = Agg(
ivy"com.typesafe.scala-logging::scala-logging:3.9.5",
ivy"ch.qos.logback:logback-classic:1.4.5",
)

val common = log ++ Agg(
ivy"org.scala-lang.modules::scala-parallel-collections:1.0.4",
)
}
}
57 changes: 57 additions & 0 deletions mill-build/util/src/util.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import mill._
import os.Path

package object util {
case class DataPoint(base: Path, coordinate: os.SubPath) {
lazy val mtime = os.mtime(base / coordinate)

override def equals(obj: Any): Boolean = obj match {
case other: DataPoint => coordinate == other.coordinate
}

private lazy val _hashCode = coordinate.hashCode()
override def hashCode(): Int = _hashCode

def copyTo(dest: Path): Unit = {
os.copy(base / coordinate, dest / coordinate, createFolders = true)
}

def copyOver(dest: Path): Unit =
if(DataPoint(dest, coordinate).mtime != mtime)
os.copy.over(base / coordinate, dest / coordinate)

def delete(): Unit =
os.remove(base / coordinate)
}

def quickCopy(target: Path, sourcePaths: Seq[PathRef]): Unit = {
val sources =
sourcePaths
.map(_.path)
.flatMap { base =>
os.walk.stream(base)
.filter(os.isFile(_))
.map(p => DataPoint(base, p.subRelativeTo(base)))
.toSeq
}
.toSet

val targets =
os.walk.stream(target)
.filter(os.isFile(_))
.map(p => DataPoint(target, p.subRelativeTo(target)))
.toSet

for(toRemove <- targets if !sources.contains(toRemove)) {
toRemove.delete()
}

for(toWrite <- sources if !targets.contains(toWrite)) {
toWrite.copyTo(target)
}

for(toWriteOver <- sources if targets.contains(toWriteOver)) {
toWriteOver.copyOver(target)
}
}
}
10 changes: 10 additions & 0 deletions mill-build/util/src/util/CppModule.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package util

import me.pieterbos.mill.cpp.{CppModule => BaseCppModule, CppExecutableModule => BaseCppExecutableModule, _}
import mill.T

trait CppModule extends BaseCppModule {
override def standard: T[options.CppStandard] = T[options.CppStandard] { options.CppStandard.Cpp20 }
}

trait CppExecutableModule extends BaseCppExecutableModule with CppModule
24 changes: 24 additions & 0 deletions mill-build/util/src/util/GitModule.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package util

import mill.{T, Module, pathReadWrite}

trait GitModule extends Module {
def url: T[String]

def commitish: T[String]

def fetchSubmodulesRecursively: T[Boolean] = false

def repo = T {
os.proc("git", "init", "-q").call(cwd = T.dest)
os.proc("git", "remote", "add", "origin", url()).call(cwd = T.dest)
os.proc("git", "fetch", "--depth", "1", "origin", commitish()).call(cwd = T.dest)
os.proc("git", "config", "advice.detachedHead", "false").call(cwd = T.dest)
os.proc("git", "checkout", "FETCH_HEAD").call(cwd = T.dest)
if(fetchSubmodulesRecursively())
os.proc("git", "submodule", "update", "--init", "--recursive").call(cwd = T.dest)
os.walk(T.dest).foreach(_.toIO.setWritable(true))
os.remove.all(T.dest / ".git")
T.dest
}
}
83 changes: 83 additions & 0 deletions mill-build/util/src/util/JavaModule.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package util

import mill._
import scalalib.{JavaModule => BaseJavaModule}

trait JavaModule extends BaseJavaModule {
// https://github.com/viperproject/silicon/issues/748
// 32MB is enough stack space for silicon, a 100% marco guarantee
override def forkArgs = Seq("-Xmx2G", "-Xss32m")

def classPathFileElements = T { runClasspath().map(_.path.toString) }

def unixClassPathArgumentFile = T {
val cpString = classPathFileElements().mkString(":")
val cpArg = "-cp " + cpString
os.write(T.dest / "classpath", cpArg)
T.dest / "classpath"
}

def strictOptionsFile = T.source {
settings.root / ".compile-strict"
}

def strictOptions: T[Boolean] = T {
os.exists(strictOptionsFile().path)
}

override def javacOptions = T {
val shared = Seq(
"--release", "17",
"-deprecation",
)

if(strictOptions()) {
Seq(
"-Werror",
) ++ shared
} else {
Seq (
// nothing here yet
) ++ shared
}
}

def windowsClassPathArgumentFile = T {
val cpString = classPathFileElements().mkString(";")
val cpArg = "-cp " + cpString
os.write(T.dest / "classpath", cpArg)
T.dest / "classpath"
}

def runScriptClasses = T {
Map(
"run" -> finalMainClass(),
)
}

def runScript = T {
// PB: this is nearly just Jvm.createLauncher, but you cannot set the filename, and uses a literal classpath instead of a file.
for((name, mainClass) <- runScriptClasses()) {
// thanks https://gist.github.com/lhns/ee821a5cd1b2031856b21a0e78e1ecc9
val quote = "\""
val header = "@ 2>/dev/null # 2>nul & echo off & goto BOF"
val unix = Seq(
":",
s"java ${forkArgs().mkString(" ")} @${unixClassPathArgumentFile()} $mainClass $quote$$@$quote",
"exit",
)
val batch = Seq(
":BOF",
s"java ${forkArgs().mkString(" ")} @${windowsClassPathArgumentFile()} $mainClass %*",
"exit /B %errorlevel%",
)
val script = header + "\r\n" + unix.mkString("\n") + "\n\r\n" + batch.mkString("\r\n") + "\r\n"
val isWin = scala.util.Properties.isWin
val wantBatch = isWin && !org.jline.utils.OSUtils.IS_CYGWIN && !org.jline.utils.OSUtils.IS_MSYSTEM
val fileName = if(wantBatch) name + ".bat" else name
os.write(T.dest / fileName, script)
if(!isWin) os.perms.set(T.dest / name, os.PermSet.fromString("rwxrwxr-x"))
}
T.dest
}
}
Loading

0 comments on commit 98281e6

Please sign in to comment.