mirror of
https://github.com/fluencelabs/asmble
synced 2025-07-03 16:31:37 +00:00
Compare commits
2 Commits
documentat
...
lateinit_f
Author | SHA1 | Date | |
---|---|---|---|
58cf836b76 | |||
56c2c8d672 |
28
build.gradle
28
build.gradle
@ -21,7 +21,7 @@ buildscript {
|
|||||||
allprojects {
|
allprojects {
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
group 'com.github.cretz.asmble'
|
group 'com.github.cretz.asmble'
|
||||||
version '0.4.0-fl'
|
version '0.4.0-fl-fix'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@ -143,17 +143,17 @@ project(':examples') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
project(':examples:go-simple') {
|
//project(':examples:go-simple') {
|
||||||
apply plugin: 'application'
|
// apply plugin: 'application'
|
||||||
ext.wasmCompiledClassName = 'asmble.generated.GoSimple'
|
// ext.wasmCompiledClassName = 'asmble.generated.GoSimple'
|
||||||
dependencies {
|
// dependencies {
|
||||||
compile files('build/wasm-classes')
|
// compile files('build/wasm-classes')
|
||||||
}
|
// }
|
||||||
compileJava {
|
// compileJava {
|
||||||
dependsOn compileGoWasm
|
// dependsOn compileGoWasm
|
||||||
}
|
// }
|
||||||
mainClassName = 'asmble.examples.gosimple.Main'
|
// mainClassName = 'asmble.examples.gosimple.Main'
|
||||||
}
|
//}
|
||||||
|
|
||||||
// todo temporary disable Rust regex, because some strings in wasm code exceed the size in 65353 bytes.
|
// todo temporary disable Rust regex, because some strings in wasm code exceed the size in 65353 bytes.
|
||||||
|
|
||||||
@ -231,10 +231,6 @@ def publishSettings(project, projectName, projectDescription) {
|
|||||||
|
|
||||||
bintray {
|
bintray {
|
||||||
|
|
||||||
if(!hasProperty("bintrayUser") || !hasProperty("bintrayKey")) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
user = bintrayUser
|
user = bintrayUser
|
||||||
key = bintrayKey
|
key = bintrayKey
|
||||||
publications = ['MyPublication']
|
publications = ['MyPublication']
|
||||||
|
@ -184,7 +184,7 @@ sealed class Node {
|
|||||||
interface Const<out T : Number> : Args { val value: T }
|
interface Const<out T : Number> : Args { val value: T }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Control instructions [https://www.w3.org/TR/wasm-core-1/#control-instructions]
|
// Control instructions [https://www.w3.org/TR/2018/WD-wasm-core-1-20180215/#control-instructions]
|
||||||
|
|
||||||
object Unreachable : Instr(), Args.None
|
object Unreachable : Instr(), Args.None
|
||||||
object Nop : Instr(), Args.None
|
object Nop : Instr(), Args.None
|
||||||
@ -209,12 +209,12 @@ sealed class Node {
|
|||||||
override val reserved: Boolean
|
override val reserved: Boolean
|
||||||
) : Instr(), Args.ReservedIndex
|
) : Instr(), Args.ReservedIndex
|
||||||
|
|
||||||
// Parametric instructions [https://www.w3.org/TR/wasm-core-1/#parametric-instructions]
|
// Parametric instructions [https://www.w3.org/TR/2018/WD-wasm-core-1-20180215/#parametric-instructions]
|
||||||
|
|
||||||
object Drop : Instr(), Args.None
|
object Drop : Instr(), Args.None
|
||||||
object Select : Instr(), Args.None
|
object Select : Instr(), Args.None
|
||||||
|
|
||||||
// Variable instructions [https://www.w3.org/TR/wasm-core-1/#variable-instructions]
|
// Variable instructions [https://www.w3.org/TR/2018/WD-wasm-core-1-20180215/#variable-instructions]
|
||||||
|
|
||||||
data class GetLocal(override val index: Int) : Instr(), Args.Index
|
data class GetLocal(override val index: Int) : Instr(), Args.Index
|
||||||
data class SetLocal(override val index: Int) : Instr(), Args.Index
|
data class SetLocal(override val index: Int) : Instr(), Args.Index
|
||||||
@ -222,7 +222,7 @@ sealed class Node {
|
|||||||
data class GetGlobal(override val index: Int) : Instr(), Args.Index
|
data class GetGlobal(override val index: Int) : Instr(), Args.Index
|
||||||
data class SetGlobal(override val index: Int) : Instr(), Args.Index
|
data class SetGlobal(override val index: Int) : Instr(), Args.Index
|
||||||
|
|
||||||
// Memory instructions [https://www.w3.org/TR/wasm-core-1/#memory-instructions]
|
// Memory instructions [https://www.w3.org/TR/2018/WD-wasm-core-1-20180215/#memory-instructions]
|
||||||
|
|
||||||
data class I32Load(override val align: Int, override val offset: Long) : Instr(), Args.AlignOffset
|
data class I32Load(override val align: Int, override val offset: Long) : Instr(), Args.AlignOffset
|
||||||
data class I64Load(override val align: Int, override val offset: Long) : Instr(), Args.AlignOffset
|
data class I64Load(override val align: Int, override val offset: Long) : Instr(), Args.AlignOffset
|
||||||
@ -250,7 +250,7 @@ sealed class Node {
|
|||||||
data class MemorySize(override val reserved: Boolean) : Instr(), Args.Reserved
|
data class MemorySize(override val reserved: Boolean) : Instr(), Args.Reserved
|
||||||
data class MemoryGrow(override val reserved: Boolean) : Instr(), Args.Reserved
|
data class MemoryGrow(override val reserved: Boolean) : Instr(), Args.Reserved
|
||||||
|
|
||||||
// Numeric instructions [https://www.w3.org/TR/wasm-core-1/#numeric-instructions]
|
// Numeric instructions [https://www.w3.org/TR/2018/WD-wasm-core-1-20180215/#numeric-instructions]
|
||||||
|
|
||||||
// Constants operators
|
// Constants operators
|
||||||
data class I32Const(override val value: Int) : Instr(), Args.Const<Int>
|
data class I32Const(override val value: Int) : Instr(), Args.Const<Int>
|
||||||
|
@ -56,7 +56,10 @@ abstract class ScriptCommand<T> : Command<T>() {
|
|||||||
// if input file is class file
|
// if input file is class file
|
||||||
"class" -> ctx.classLoader.addClass(File(inFile).readBytes()).let { ctx }
|
"class" -> ctx.classLoader.addClass(File(inFile).readBytes()).let { ctx }
|
||||||
// if input file is wasm file
|
// if input file is wasm file
|
||||||
else -> Translate.also { it.logger = logger }.inToAst(inFile, inFile.substringAfterLast('.')).let { inAst ->
|
else -> {
|
||||||
|
val translateCmd = Translate
|
||||||
|
translateCmd.logger = this.logger
|
||||||
|
translateCmd.inToAst(inFile, inFile.substringAfterLast('.')).let { inAst ->
|
||||||
val (mod, name) = (inAst.commands.singleOrNull() as? Script.Cmd.Module) ?:
|
val (mod, name) = (inAst.commands.singleOrNull() as? Script.Cmd.Module) ?:
|
||||||
error("Input file must only contain a single module")
|
error("Input file must only contain a single module")
|
||||||
val className = name?.javaIdent?.capitalize() ?:
|
val className = name?.javaIdent?.capitalize() ?:
|
||||||
@ -69,6 +72,7 @@ abstract class ScriptCommand<T> : Command<T>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
throw Exception("Failed loading $inFile - ${e.message}", e)
|
throw Exception("Failed loading $inFile - ${e.message}", e)
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ open class Translate : Command<Translate.Args>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"wasm" ->
|
"wasm" ->
|
||||||
Script(listOf(Script.Cmd.Module(BinaryToAst(logger = logger).toModule(
|
Script(listOf(Script.Cmd.Module(BinaryToAst(logger = this.logger).toModule(
|
||||||
ByteReader.InputStream(inBytes.inputStream())), null)))
|
ByteReader.InputStream(inBytes.inputStream())), null)))
|
||||||
else -> error("Unknown in format '$inFormat'")
|
else -> error("Unknown in format '$inFormat'")
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,13 @@ import asmble.ast.Node
|
|||||||
import asmble.util.Logger
|
import asmble.util.Logger
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Jvm context of the function execution.
|
* Jvm context of execution a function.
|
||||||
*
|
*
|
||||||
* @param cls class execution context
|
* @param cls Class execution context
|
||||||
* @param node Ast of this function
|
* @param node Ast of this function
|
||||||
* @param insns instructions list
|
* @param insns A list of instructions
|
||||||
* @param memIsLocalVar true if function uses only local variables and doesn't load
|
* @param memIsLocalVar If true then function use only local variables and don't load
|
||||||
* or store to/from memory.
|
* and store from memory.
|
||||||
*/
|
*/
|
||||||
data class FuncContext(
|
data class FuncContext(
|
||||||
val cls: ClsContext,
|
val cls: ClsContext,
|
||||||
|
@ -2,12 +2,11 @@ package asmble.io
|
|||||||
|
|
||||||
import asmble.ast.Node
|
import asmble.ast.Node
|
||||||
import asmble.util.*
|
import asmble.util.*
|
||||||
import java.io.ByteArrayInputStream
|
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
|
|
||||||
open class BinaryToAst(
|
open class BinaryToAst(
|
||||||
val version: Long = 1L,
|
val version: Long = 1L,
|
||||||
val logger: Logger = Logger.Print(Logger.Level.OFF),
|
val logger: Logger = Logger.Print(Logger.Level.WARN),
|
||||||
val includeNameSection: Boolean = true
|
val includeNameSection: Boolean = true
|
||||||
) : Logger by logger {
|
) : Logger by logger {
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ rootProject.name = 'asmble'
|
|||||||
include 'annotations',
|
include 'annotations',
|
||||||
'compiler',
|
'compiler',
|
||||||
'examples:c-simple',
|
'examples:c-simple',
|
||||||
'examples:go-simple',
|
// 'examples:go-simple',
|
||||||
'examples:rust-regex',
|
// 'examples:rust-regex', // todo will be enabled when the problem with string max size will be solved
|
||||||
'examples:rust-simple',
|
'examples:rust-simple',
|
||||||
'examples:rust-string'
|
'examples:rust-string'
|
Reference in New Issue
Block a user