Skip to content

Commit 6da032d

Browse files
committed
Relocate tool-generated source files to build/generated/sources
1 parent b520364 commit 6da032d

177 files changed

Lines changed: 113 additions & 13430 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/gradle.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ on:
1111
branches: [ "master" ]
1212
paths:
1313
- "src/**"
14-
- "build.gradle"
14+
- "build.gradle.kts"
1515
- "gradle/**"
1616
- ".github/workflows/gradle.yml"
1717
pull_request:
1818
branches: [ "master" ]
1919
paths:
2020
- "src/**"
21-
- "build.gradle"
21+
- "build.gradle.kts"
2222
- "gradle/**"
2323
- ".github/workflows/gradle.yml"
2424
permissions:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ MicroJava's single line comment starts with two forward slashes with no white sp
9393
To build and test this project you will need [Java 17](https://adoptium.net/temurin/) (the latest LTS release as of February 2023) and [Gradle 7.3](https://docs.gradle.org/current/userguide/userguide.html).
9494
Open command-line interpreter and type one of the following commands:
9595

96-
* `gradlew genLexer` (Windows) or `./gradlew genLexer` (macOS and Linux) — to generate lexer (tokenizer) implementation ([`MJLexer.java`](src/main/java/dev/askov/mjcompiler/MJLexer.java)) based on [lexer specification](src/main/spec/mjlexer.flex).
97-
* `gradlew genParser` (Windows) or `./gradlew genParser` (macOS and Linux) — to generate parser implementation ([`MJParser.java`](src/main/java/dev/askov/mjcompiler/MJParser.java), [`sym.java`](src/main/java/dev/askov/mjcompiler/sym.java)) and abstract syntax tree implementation (classes inside [`ast`](src/main/java/dev/askov/mjcompiler/ast) directory), based on [parser specification](src/main/spec/mjparser.cup).
96+
* `gradlew lexer` (Windows) or `./gradlew lexer` (macOS and Linux) — to generate lexer (tokenizer) implementation (`MJLexer.java`) based on [lexer specification](src/main/resources/mjlexer.flex).
97+
* `gradlew parser` (Windows) or `./gradlew parser` (macOS and Linux) — to generate parser implementation (`MJParser.java`, `sym.java`) and abstract syntax tree implementation (classes inside `ast` directory), based on [parser specification](src/main/resources/mjparser.cup).
9898
* `gradlew build` (Windows) or `./gradlew build` (macOS and Linux) — to build the project, test the compiler and run MicroJava VM. MicroJava Compiler will compile the test file [`simple_calculator.mj`](src/test/resources/simple_calculator.mj) and produce `simple_calculator.obj`. Then, the machine code inside `simple_calculator.obj` will be executed by MicroJava VM.
9999
Note that, for testing purposes, standard input has been substituted with a file named [`input_stream.txt`](src/test/resources/input_stream.txt).
100100
* `gradlew disassemble` (Windows) or `./gradlew disassemble` (macOS and Linux) — to disassemble `simple_calculator.obj` produced in the previous step, using [`rs.etf.pp1.mj.runtime.disasm`](libs/mj-runtime-1.1.jar).

build.gradle

Lines changed: 0 additions & 59 deletions
This file was deleted.

build.gradle.kts

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
plugins {
2+
java
3+
application
4+
}
5+
6+
group = "dev.askov.mjcompiler"
7+
version = "1.0"
8+
9+
java {
10+
toolchain {
11+
languageVersion.set(JavaLanguageVersion.of(25))
12+
}
13+
}
14+
15+
application {
16+
mainClass.set("dev.askov.mjcompiler.MJCompiler")
17+
}
18+
19+
repositories {
20+
mavenCentral()
21+
flatDir {
22+
dirs("libs")
23+
}
24+
}
25+
26+
dependencies {
27+
testImplementation("junit:junit:4.13.1")
28+
29+
// Using flatDir dependencies (lookup by name only)
30+
implementation(":JFlex")
31+
implementation(":cup_v10k")
32+
implementation(":log4j-1.2.17")
33+
implementation(":mj-runtime-1.1")
34+
implementation(":symboltable")
35+
}
36+
37+
tasks.test {
38+
testLogging {
39+
outputs.upToDateWhen { false }
40+
showStandardStreams = true
41+
}
42+
}
43+
44+
val jflexDir = layout.buildDirectory.dir("generated/sources/jflex/java/main").get()
45+
val cupDir = layout.buildDirectory.dir("generated/sources/cup/java/main").get()
46+
47+
sourceSets.main {
48+
java.srcDirs(jflexDir, cupDir)
49+
}
50+
51+
tasks.register<JavaExec>("lexer") {
52+
group = "generation"
53+
mainClass.set("JFlex.Main")
54+
classpath = sourceSets.main.get().compileClasspath
55+
56+
val outputFile = jflexDir.file("dev/askov/mjcompiler/MJLexer.java")
57+
58+
inputs.file("src/main/resources/mjlexer.flex")
59+
outputs.file(outputFile)
60+
61+
args("-d", outputFile.asFile.parent, "src/main/resources/mjlexer.flex")
62+
}
63+
64+
tasks.register<JavaExec>("parser") {
65+
group = "generation"
66+
dependsOn("lexer")
67+
mainClass.set("java_cup.Main")
68+
classpath = sourceSets.main.get().compileClasspath.minus(files("libs/JFlex.jar"))
69+
70+
val genSourceRoot = cupDir.asFile
71+
72+
workingDir = genSourceRoot
73+
74+
inputs.file("src/main/resources/mjparser.cup")
75+
outputs.dir(genSourceRoot)
76+
77+
doFirst {
78+
file("${cupDir.asFile.path}/dev/askov/mjcompiler").mkdirs()
79+
}
80+
81+
args(
82+
"-destdir", "dev/askov/mjcompiler",
83+
"-parser", "MJParser",
84+
"-ast", "dev.askov.mjcompiler.ast",
85+
"-buildtree",
86+
file("src/main/resources/mjparser.cup").absolutePath
87+
)
88+
}
89+
90+
tasks.compileJava {
91+
dependsOn("lexer", "parser")
92+
}
93+
94+
tasks.clean {
95+
delete(
96+
"src/main/java/dev/askov/mjcompiler/MJLexer.java",
97+
"src/main/java/dev/askov/mjcompiler/MJParser.java",
98+
"src/main/java/dev/askov/mjcompiler/sym.java",
99+
"src/main/java/dev/askov/mjcompiler/ast"
100+
)
101+
}
102+
103+
tasks.register<JavaExec>("disassemble") {
104+
group = "verification"
105+
106+
mainClass.set("rs.etf.pp1.mj.runtime.disasm")
107+
classpath = sourceSets.main.get().runtimeClasspath
108+
args("src/test/resources/simple_calculator.obj")
109+
}

0 commit comments

Comments
 (0)