Added wasm target
This commit is contained in:
@ -56,6 +56,8 @@ func buildExecutable(args []string) (*build.Build, error) {
|
||||
config.SetTargetArch(config.ARM)
|
||||
case "x86":
|
||||
config.SetTargetArch(config.X86)
|
||||
case "wasm":
|
||||
config.SetTargetArch(config.WASM)
|
||||
default:
|
||||
return b, &InvalidValueError{Value: args[i], Parameter: "arch"}
|
||||
}
|
||||
@ -72,6 +74,8 @@ func buildExecutable(args []string) (*build.Build, error) {
|
||||
config.TargetOS = config.Linux
|
||||
case "mac":
|
||||
config.TargetOS = config.Mac
|
||||
case "web":
|
||||
config.TargetOS = config.Web
|
||||
case "windows":
|
||||
config.TargetOS = config.Windows
|
||||
default:
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"git.urbach.dev/cli/q/src/elf"
|
||||
"git.urbach.dev/cli/q/src/macho"
|
||||
"git.urbach.dev/cli/q/src/pe"
|
||||
"git.urbach.dev/cli/q/src/wasm"
|
||||
)
|
||||
|
||||
// Write writes the executable to the given writer.
|
||||
@ -25,6 +26,8 @@ func write(writer io.Writer, code []byte, data []byte, dlls dll.List) error {
|
||||
elf.Write(buffer, code, data)
|
||||
case config.Mac:
|
||||
macho.Write(buffer, code, data)
|
||||
case config.Web:
|
||||
wasm.Write(buffer, code, data)
|
||||
case config.Windows:
|
||||
pe.Write(buffer, code, data, dlls)
|
||||
}
|
||||
|
@ -5,5 +5,6 @@ type Arch uint8
|
||||
const (
|
||||
UnknownArch Arch = iota
|
||||
ARM
|
||||
WASM
|
||||
X86
|
||||
)
|
||||
|
@ -26,6 +26,8 @@ func Reset() {
|
||||
SetTargetArch(X86)
|
||||
case "arm64":
|
||||
SetTargetArch(ARM)
|
||||
case "wasm":
|
||||
SetTargetArch(WASM)
|
||||
default:
|
||||
SetTargetArch(UnknownArch)
|
||||
}
|
||||
@ -35,6 +37,8 @@ func Reset() {
|
||||
TargetOS = Linux
|
||||
case "darwin":
|
||||
TargetOS = Mac
|
||||
case "js":
|
||||
TargetOS = Web
|
||||
case "windows":
|
||||
TargetOS = Windows
|
||||
default:
|
||||
|
@ -6,5 +6,6 @@ const (
|
||||
UnknownOS OS = iota
|
||||
Linux
|
||||
Mac
|
||||
Web
|
||||
Windows
|
||||
)
|
||||
|
@ -8,18 +8,21 @@ import (
|
||||
"git.urbach.dev/cli/q/src/fs"
|
||||
"git.urbach.dev/cli/q/src/register"
|
||||
"git.urbach.dev/cli/q/src/scope"
|
||||
"git.urbach.dev/cli/q/src/wasm"
|
||||
"git.urbach.dev/cli/q/src/x86"
|
||||
)
|
||||
|
||||
// NewFunction creates a new function.
|
||||
func NewFunction(pkg string, name string, file *fs.File) *Function {
|
||||
var cpu *cpu.CPU
|
||||
var c *cpu.CPU
|
||||
|
||||
switch config.TargetArch {
|
||||
case config.ARM:
|
||||
cpu = &arm.CPU
|
||||
c = &arm.CPU
|
||||
case config.WASM:
|
||||
c = &wasm.CPU
|
||||
case config.X86:
|
||||
cpu = &x86.CPU
|
||||
c = &x86.CPU
|
||||
}
|
||||
|
||||
return &Function{
|
||||
@ -34,7 +37,7 @@ func NewFunction(pkg string, name string, file *fs.File) *Function {
|
||||
Stack: scope.Stack{
|
||||
Scopes: []*scope.Scope{{}},
|
||||
},
|
||||
CPU: cpu,
|
||||
CPU: c,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
11
src/wasm/CPU.go
Normal file
11
src/wasm/CPU.go
Normal file
@ -0,0 +1,11 @@
|
||||
package wasm
|
||||
|
||||
import "git.urbach.dev/cli/q/src/cpu"
|
||||
|
||||
var (
|
||||
CPU = cpu.CPU{
|
||||
Input: []cpu.Register{0, 1, 2, 3, 4, 5},
|
||||
Output: []cpu.Register{0, 1, 2, 3, 4, 5},
|
||||
NumRegisters: 0,
|
||||
}
|
||||
)
|
13
src/wasm/WASM.go
Normal file
13
src/wasm/WASM.go
Normal file
@ -0,0 +1,13 @@
|
||||
package wasm
|
||||
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
const HeaderEnd = 8
|
||||
|
||||
// Write writes the WASM format to the given writer.
|
||||
func Write(writer io.Writer, codeBytes []byte, dataBytes []byte) {
|
||||
writer.Write([]byte{0x00, 0x61, 0x73, 0x6D})
|
||||
writer.Write([]byte{0x01, 0x00, 0x00, 0x00})
|
||||
}
|
Reference in New Issue
Block a user