Skip to content

Commit

Permalink
get rid of nasm in docs and configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
avan1235 committed Mar 7, 2023
1 parent 6ad627e commit 4e60a6c
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-native.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ jobs:
platform: i686
- uses: ilammy/[email protected]
- uses: microsoft/setup-msbuild@v1
with:
vs-version: '[7.1,7.2)'
- name: Build with Gradle
run: ./gradlew.bat --no-daemon clean nativeImage
shell: powershell
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
distribution: 'adopt'
cache: gradle
- name: Make Gradle executable and prepare env
run: chmod u+x ./gradlew && sudo apt-get install -y gcc-multilib nasm
run: chmod u+x ./gradlew && sudo apt-get install -y gcc-multilib
- name: Test with Gradle
run: ./gradlew clean test
- name: Cleanup Gradle Cache
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Latte Compiler
[![Tests badge](https://img.shields.io/github/workflow/status/avan1235/latte-compiler/Test?label=Tests)](https://github.com/avan1235/latte-compiler/actions/workflows/test.yaml)
[![Build badge](https://img.shields.io/github/workflow/status/avan1235/latte-compiler/Build%20Native?label=Build)](https://github.com/avan1235/latte-compiler/actions/workflows/build-native.yaml)
[![Github All Releases](https://img.shields.io/github/downloads/avan1235/latte-compiler/total.svg?label=Downloads)](https://github.com/avan1235/latte-compiler/releases/latest)
[![Tests badge](https://img.shields.io/github/actions/workflow/status/avan1235/latte-compiler/test.yaml?branch=master)](https://img.shields.io/github/actions/workflow/status/avan1235/latte-compiler/test.yaml?branch=master)
[![Build badge](https://img.shields.io/github/actions/workflow/status/avan1235/latte-compiler/build-native.yaml?branch=master)](https://img.shields.io/github/actions/workflow/status/avan1235/latte-compiler/build-native.yaml?branch=master)
[![Github All Releases](https://img.shields.io/github/downloads/avan1235/latte-compiler/total.svg?label=downloads)](https://github.com/avan1235/latte-compiler/releases/latest)

[Latte](https://latte-lang.org/) is originally a JVM language that is fully interoperable with Java.
This project implements a native x64 compiler for this language with no support for interoperability with other languages
but tries to provide an optimized version of native version of this language.
This project implements a native x86 compiler for this language with no support for interoperability with other
languages but tries to provide an optimized version of native version of this language.

## Building project

Expand All @@ -15,7 +15,6 @@ To build project you need:

- [Java 11](https://adoptopenjdk.net/) to build compiler from Kotlin sources and run Gradle in Java 11 environment
- [gcc](https://gcc.gnu.org/) with `gcc-multilib` to compile [runtime.c](./lib/runtime.c) library file in x86 version
- [nasm](https://www.nasm.us/) to run tests that require compiling program from generated assembly

### Build commands

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/ml/dev/kotlin/latte/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ml.dev.kotlin.latte
import ml.dev.kotlin.latte.asm.AllocatorStrategy
import ml.dev.kotlin.latte.asm.AllocatorStrategyProducer
import ml.dev.kotlin.latte.asm.compile
import ml.dev.kotlin.latte.asm.nasm
import ml.dev.kotlin.latte.asm.asm
import ml.dev.kotlin.latte.quadruple.optimize
import ml.dev.kotlin.latte.quadruple.printInstructions
import ml.dev.kotlin.latte.quadruple.toIR
Expand All @@ -20,7 +20,7 @@ fun main(args: Array<String>): Unit = args.takeIf { it.isNotEmpty() }?.forEach {
val asmCode = inputFile.runCompiler()
val asmFile = inputFile.withExtension(".s")
asmFile.writeText(asmCode)
nasm(asmFile).run { oFile.delete() }
asm(asmFile).run { oFile.delete() }
exit("OK", exitCode = 0)
} catch (e: LatteException) {
exit("ERROR", e.userMessage, exitCode = 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ml.dev.kotlin.latte.util.*
import java.io.File
import java.nio.file.Files

fun nasm(assembly: File, libFile: File = DEFAULT_LIB_FILE): CompilationResult {
fun asm(assembly: File, libFile: File = DEFAULT_LIB_FILE): CompilationResult {
val o = assembly.withExtension(".o")
val result = assembly.withExtension("")
withLibFile(libFile) { lib ->
Expand Down Expand Up @@ -33,9 +33,9 @@ private fun withLibFile(libFile: File, action: (File) -> Unit) {

private fun createTempLibFromResources(): File {
val file = Files.createTempFile(exeFile().dir.toPath(), "temp-runtime-", ".o").toFile()
Nasm.javaClass.getResourceAsStream("runtime.o")?.let { file.writeBytes(it.readBytes()) }
Asm.javaClass.getResourceAsStream("runtime.o")?.let { file.writeBytes(it.readBytes()) }
?: throw LatteIllegalStateException("No runtime.o file in resources to use as backup".msg)
return file
}

private object Nasm
private object Asm
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ private fun testCompilerWithAllocatorStrategy(
val inputFile = input?.let { programFile.withExtension(".input", it.trimIndent()) }
val compiled = programFile.runCompiler(strategy = allocator.strategy)
val asmFile = programFile.withExtension(".s", compiled)
val (o, exe) = nasm(asmFile, libFile = File("lib/runtime.o"))
val (o, exe) = asm(asmFile, libFile = File("lib/runtime.o"))
val outFile = programFile.withExtension(".outputTest")
val errFile = programFile.withExtension(".errorTest")
exe.absolutePath(inputFile, outFile, errFile).zeroCode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private fun testCompilerWithAllocatorStrategy(
val inputFile = input.withExtension(".input").takeIf { it.exists() }
val compiled = input.runCompiler(strategy = allocator.strategy)
val asmFile = input.withExtension(".${shortcut}.s").apply { writeText(compiled) }
val (o, exe) = nasm(asmFile, libFile = File("lib/runtime.o"))
val (o, exe) = asm(asmFile, libFile = File("lib/runtime.o"))
val outFile = input.withExtension(".${shortcut}.outputTest").apply { createNewFile() }
val errFile = input.withExtension(".${shortcut}.errorTest").apply { createNewFile() }
exe.absolutePath(inputFile, outFile, errFile).zeroCode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private fun configuredRunCompiler(
val inputFile = input?.let { programFile.withExtension(".input", it.trimIndent()) }
val code = programFile.runCompiler(true, propagateConstants, simplifyExpr, true, lcse, gcse)
val asmFile = programFile.withExtension(".s", code)
val (o, exe) = nasm(asmFile, libFile = File("lib/runtime.o"))
val (o, exe) = asm(asmFile, libFile = File("lib/runtime.o"))
val outFile = programFile.withExtension(".outputTest")
val errFile = programFile.withExtension(".errorTest")
exe.absolutePath(inputFile, outFile, errFile).zeroCode()
Expand Down

0 comments on commit 4e60a6c

Please sign in to comment.