Fixed incorrect OS detection
This commit is contained in:
parent
2ae8b04593
commit
7fb5c8407f
8 changed files with 65 additions and 25 deletions
|
@ -2,7 +2,6 @@ package compiler
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
|
@ -38,15 +37,15 @@ func (r *Result) finalize() ([]byte, []byte, dll.List) {
|
|||
final.Call("main.main")
|
||||
|
||||
switch config.TargetOS {
|
||||
case "linux":
|
||||
case config.Linux:
|
||||
final.RegisterNumber(asm.MOVE, x64.SyscallInputRegisters[0], LinuxExit)
|
||||
final.RegisterNumber(asm.MOVE, x64.SyscallInputRegisters[1], 0)
|
||||
final.Syscall()
|
||||
case "mac":
|
||||
case config.Mac:
|
||||
final.RegisterNumber(asm.MOVE, x64.SyscallInputRegisters[0], MacExit)
|
||||
final.RegisterNumber(asm.MOVE, x64.SyscallInputRegisters[1], 0)
|
||||
final.Syscall()
|
||||
case "windows":
|
||||
case config.Windows:
|
||||
final.RegisterNumber(asm.MOVE, x64.WindowsInputRegisters[0], 0)
|
||||
final.DLLCall("kernel32.ExitProcess")
|
||||
}
|
||||
|
@ -70,15 +69,15 @@ func (r *Result) finalize() ([]byte, []byte, dll.List) {
|
|||
final.Label(asm.LABEL, "_crash")
|
||||
|
||||
switch config.TargetOS {
|
||||
case "linux":
|
||||
case config.Linux:
|
||||
final.RegisterNumber(asm.MOVE, x64.SyscallInputRegisters[0], LinuxExit)
|
||||
final.RegisterNumber(asm.MOVE, x64.SyscallInputRegisters[1], 1)
|
||||
final.Syscall()
|
||||
case "mac":
|
||||
case config.Mac:
|
||||
final.RegisterNumber(asm.MOVE, x64.SyscallInputRegisters[0], MacExit)
|
||||
final.RegisterNumber(asm.MOVE, x64.SyscallInputRegisters[1], 1)
|
||||
final.Syscall()
|
||||
case "windows":
|
||||
case config.Windows:
|
||||
final.RegisterNumber(asm.MOVE, x64.WindowsInputRegisters[0], 1)
|
||||
final.DLLCall("kernel32.ExitProcess")
|
||||
}
|
||||
|
@ -155,14 +154,12 @@ func write(writer io.Writer, code []byte, data []byte, dlls dll.List) error {
|
|||
buffer := bufio.NewWriter(writer)
|
||||
|
||||
switch config.TargetOS {
|
||||
case "linux":
|
||||
case config.Linux:
|
||||
elf.Write(buffer, code, data)
|
||||
case "mac":
|
||||
case config.Mac:
|
||||
macho.Write(buffer, code, data)
|
||||
case "windows":
|
||||
case config.Windows:
|
||||
pe.Write(buffer, code, data, dlls)
|
||||
default:
|
||||
return fmt.Errorf("unsupported platform '%s'", config.TargetOS)
|
||||
}
|
||||
|
||||
return buffer.Flush()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue