mirror of
https://github.com/RoBaertschi/tt.git
synced 2025-04-18 23:13:29 +00:00
continue cmd
This commit is contained in:
parent
ad486b7900
commit
28d464f318
@ -15,7 +15,7 @@ func toAsmOperand(op ttir.Operand) Operand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CgProgram(prog ttir.Program) Program {
|
func CgProgram(prog *ttir.Program) Program {
|
||||||
funcs := make([]Function, 0)
|
funcs := make([]Function, 0)
|
||||||
|
|
||||||
for _, f := range prog.Functions {
|
for _, f := range prog.Functions {
|
||||||
|
21
cmd/cmd.go
21
cmd/cmd.go
@ -8,9 +8,11 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"robaertschi.xyz/robaertschi/tt/asm/amd64"
|
||||||
"robaertschi.xyz/robaertschi/tt/lexer"
|
"robaertschi.xyz/robaertschi/tt/lexer"
|
||||||
"robaertschi.xyz/robaertschi/tt/parser"
|
"robaertschi.xyz/robaertschi/tt/parser"
|
||||||
"robaertschi.xyz/robaertschi/tt/token"
|
"robaertschi.xyz/robaertschi/tt/token"
|
||||||
|
"robaertschi.xyz/robaertschi/tt/ttir"
|
||||||
"robaertschi.xyz/robaertschi/tt/typechecker"
|
"robaertschi.xyz/robaertschi/tt/typechecker"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,6 +36,7 @@ func main() {
|
|||||||
if output == "" {
|
if output == "" {
|
||||||
output = strings.TrimRight(input, filepath.Ext(input))
|
output = strings.TrimRight(input, filepath.Ext(input))
|
||||||
}
|
}
|
||||||
|
asmOutputName := strings.TrimRight(input, filepath.Ext(input)) + ".asm"
|
||||||
|
|
||||||
file, err := os.Open(input)
|
file, err := os.Open(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -76,4 +79,22 @@ func main() {
|
|||||||
fmt.Printf("Typechecker failed with %e\n", err)
|
fmt.Printf("Typechecker failed with %e\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ir := ttir.EmitProgram(tprogram)
|
||||||
|
asm := amd64.CgProgram(ir)
|
||||||
|
|
||||||
|
asmOutput := asm.Emit()
|
||||||
|
|
||||||
|
asmOutputFile, err := os.Open(asmOutputName)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to open asm file %q because: %e", asmOutputName, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer asmOutputFile.Close()
|
||||||
|
|
||||||
|
_, err = asmOutputFile.WriteString(asmOutput)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to write to file %q because: %e", asmOutputName, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user