Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
210d11e
Precompute all assembly results
Sep 17, 2025
57291b3
Fix export issues
Sep 17, 2025
b0e9ab3
fix highlight for Tacky
JoudiAlakkad Sep 17, 2025
9c4c31f
bug fixes for highlighting
JoudiAlakkad Sep 17, 2025
8f41b48
generate the assembly based on optimized tacky
JoudiAlakkad Sep 17, 2025
94e5db5
debugging optimized assembly
JoudiAlakkad Sep 18, 2025
5197448
Fix optimization order
Sep 18, 2025
ef662de
Export instruction count for CFG results
Sep 21, 2025
93c3ea3
adjust the equal in TackyBinaryOP to ==
JoudiAlakkad Sep 21, 2025
29b6873
Setup test suite from "Writing a C Compiler" book
Sep 21, 2025
427a606
Update README.md
Sep 21, 2025
25e640a
Fix return statement bugs: add proper ret instructions and epilogue h…
JoudiAlakkad Sep 21, 2025
1c29393
Small change
Sep 22, 2025
4f8988a
fix: Detect unexpected characters in the lexer
Sep 24, 2025
b430e2f
Add exception names to messages
Sep 25, 2025
bca582b
Change order of optimizations to reduce iterations
Sep 27, 2025
462e71e
remove unused code
JoudiAlakkad Sep 27, 2025
240e171
fix: Remove edge to unreachable blocks when folding jumps
Sep 27, 2025
3806704
fix: Remove edge to next block only if truly unreachable
Sep 27, 2025
de23fd7
refactor: Add new wrapper for optimization results
Oct 3, 2025
ec387d7
fix: Propagate precomputed assembly correctly
Oct 3, 2025
7e587d9
Update README.md
Oct 3, 2025
e05c2f7
Fix parsing bugs: scopes, conditional statements
Oct 4, 2025
54147fe
Update README.md
Oct 4, 2025
d0d1e2a
Add line & col to every viewable exception
Oct 4, 2025
fe88e60
Code cleanup
Oct 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ parsing, and multiple other phases.
- ``jsMain``: contains the core compiler logic
- ``jsTest``: test directory for the main logic

These two packages are compiled to JS and used for production
These `js` packages are compiled to JavaScript and used for production.

- ``jvmMain`` and ``jvmTest``: generated automatically through building the project. These packages are copied versions of ``jsMain`` and ``jsTest`` without js-specific code and are used only to generate test coverage reports, since Kover (the plugin we use to generate test reports) only supports JVM-compatible Kotlin code.

Expand Down Expand Up @@ -39,4 +39,21 @@ To generate a test coverage report,

``./gradlew koverHtmlReport``

_\* These two commands are also part of the build command_
_All of these commands are also part of the build command_

More test cases are found in the test suite of the book "Writing a C Compiler" by Nora Sandler. The test suite is also included in this project and can be run by following the steps below.


1. Build the compiler

``./gradlew build``

2. Create a jar file

``./gradlew createCompilerJar``

3. Run the test script

``cd src/resources/write_a_c_compiler-tests ./test_compiler_kotlin.sh ../../../build/libs/compiler-1.0-SNAPSHOT.jar && cd ../../..``

For more information, see the [test suite's README](https://github.com/nlsandler/write_a_c_compiler/blob/master/README.md).
74 changes: 74 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,77 @@ tasks.named("build") {
tasks.named("koverHtmlReport") {
dependsOn("jsTest", "jvmTest")
}

// Task to create the main class
tasks.register<JavaCompile>("compileMainClass") {
group = "build"
description = "Compiles the main class for the JAR"
val tempDir = temporaryDir
val mainClassFile = File(tempDir, "CompilerMain.java")
// Create the main class file during configuration
val mainClassContent =
"""
package compiler;

import java.io.File;
import java.nio.file.Files;

public class CompilerMain {
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Usage: java -jar compiler.jar <input_file>");
System.exit(1);
}

File inputFile = new File(args[0]);
if (!inputFile.exists()) {
System.out.println("Error: File " + args[0] + " does not exist");
System.exit(1);
}

try {
String sourceCode = new String(Files.readAllBytes(inputFile.toPath()));
CompilerWorkflow.Companion.fullCompile(sourceCode);
System.exit(0);
} catch (Exception e) {
System.err.println("Exception: " + e.getMessage());
e.printStackTrace();
System.exit(1);
}
}
}
""".trimIndent()

mainClassFile.writeText(mainClassContent)

source = fileTree(tempDir) { include("**/*.java") }
destinationDirectory = file("$buildDir/classes/java/main")
classpath = kotlin.jvm().compilations["main"].runtimeDependencyFiles + files(kotlin.jvm().compilations["main"].output)

dependsOn("jvmMainClasses")
}

// Create executable JAR for JVM target
tasks.register<Jar>("createCompilerJar") {
group = "build"
description = "Creates an executable JAR for the JVM target"
from(kotlin.jvm().compilations["main"].output)
from("$buildDir/classes/java/main") {
include("compiler/CompilerMain.class")
}
archiveBaseName.set("compiler")
archiveClassifier.set("")
manifest {
attributes["Main-Class"] = "compiler.CompilerMain"
}
dependsOn("jvmMainClasses", "compileMainClass")
// Include all dependencies in the JAR
from(
kotlin
.jvm()
.compilations["main"]
.runtimeDependencyFiles
.map { if (it.isDirectory) it else zipTree(it) }
)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Mon Jul 21 19:49:00 CEST 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
47 changes: 32 additions & 15 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading