From ec2ca2380bb599c74aa04f31de9a3f65194c0c21 Mon Sep 17 00:00:00 2001 From: "Gabriel G. de Brito" Date: Mon, 6 May 2024 17:24:41 -0300 Subject: [PATCH] Added internationalization support with intergo --- debugger.go | 110 +++++++++++----------- go.mod | 4 +- go.sum | 2 + internationalization.go | 198 ++++++++++++++++++++++++++++++++++++++++ machine/machine.go | 8 +- main.go | 42 +++++---- 6 files changed, 289 insertions(+), 75 deletions(-) create mode 100644 go.sum create mode 100644 internationalization.go diff --git a/debugger.go b/debugger.go index f2194f3..bed5ba5 100644 --- a/debugger.go +++ b/debugger.go @@ -14,7 +14,7 @@ import ( ) func debuggerHelp() { - help := `Commands: + help := machine.InterCtx.Get(`Commands: help Shows this help. @@ -69,7 +69,7 @@ running 'dump # file'. In the print command, # means "length instructions after addr". # is a shortcut to use with the current instruction address. -` +`) fmt.Print(help) } @@ -120,7 +120,7 @@ func getPrintHashExpr(m machine.Machine, sym []assembler.DebuggerToken, expr str l, err = strconv.ParseUint(sn, 0, 64) if err != nil { - return nil, fmt.Errorf("cannot parse %v as number: %v", sn, err) + return nil, fmt.Errorf(machine.InterCtx.Get("cannot parse %v as number: %v"), sn, err) } faddr = m.GetCurrentInstructionAddress() @@ -128,17 +128,17 @@ func getPrintHashExpr(m machine.Machine, sym []assembler.DebuggerToken, expr str var err error if sn == "" { - return nil, errors.New("length not supplied") + return nil, errors.New(machine.InterCtx.Get("length not supplied")) } faddr, err = strconv.ParseUint(fn, 0, 64) if err != nil { - return nil, fmt.Errorf("cannot parse %v as address", fn) + return nil, fmt.Errorf(machine.InterCtx.Get("cannot parse %v as address"), fn) } l, err = strconv.ParseUint(sn, 0, 64) if err != nil { - return nil, fmt.Errorf("%v a number", sn) + return nil, fmt.Errorf(machine.InterCtx.Get("%v is not a number"), sn) } } @@ -147,7 +147,7 @@ func getPrintHashExpr(m machine.Machine, sym []assembler.DebuggerToken, expr str })) if i == uint64(len(sym)) { - return nil, fmt.Errorf("no instruction at address 0x%x", faddr) + return nil, fmt.Errorf(machine.InterCtx.Get("no instruction at address 0x%x"), faddr) } l = l + i @@ -164,7 +164,7 @@ func getMemoryContentPrint(m machine.Machine, addr string, length string) ([]uin if err != nil { a, err = strconv.ParseUint(addr, 0, 64) if err != nil { - return nil, fmt.Errorf("%v is not a register or address", addr) + return nil, fmt.Errorf(machine.InterCtx.Get("%v is not a register or address"), addr) } } else { a, _ = m.GetRegister(reg) @@ -172,12 +172,12 @@ func getMemoryContentPrint(m machine.Machine, addr string, length string) ([]uin l, err := strconv.ParseUint(length, 0, 64) if err != nil { - return nil, fmt.Errorf("%v is not a number", length) + return nil, fmt.Errorf(machine.InterCtx.Get("%v is not a number"), length) } mem, err := m.GetMemoryChunk(a, l) if err != nil { - return nil, fmt.Errorf("cannot get memory content: %v", err) + return nil, fmt.Errorf(machine.InterCtx.Get("cannot get memory content: %v"), err) } // I hope this is somehow "optimized out" to a simple padded copy. @@ -197,7 +197,7 @@ func getPrintExpr(m machine.Machine, expr string, info *machine.ArchitectureInfo if !has_at { reg, err := m.GetRegisterNumber(addr) if err != nil { - return nil, fmt.Errorf("cannot get register content: %v", err) + return nil, fmt.Errorf(machine.InterCtx.Get("cannot get register content: %v"), err) } c, _ := m.GetRegister(reg) @@ -216,7 +216,7 @@ func getPrintExpr(m machine.Machine, expr string, info *machine.ArchitectureInfo arr, err := getMemoryContentPrint(m, addr, length) if err != nil { - return nil, fmt.Errorf("cannot get memory content: %v", err) + return nil, fmt.Errorf(machine.InterCtx.Get("cannot get memory content: %v"), err) } c := make([]string, len(arr)) @@ -229,7 +229,7 @@ func getPrintExpr(m machine.Machine, expr string, info *machine.ArchitectureInfo func debuggerPrint(m machine.Machine, sym []assembler.DebuggerToken, args []string, info *machine.ArchitectureInfo) { if len(args) < 1 { - fmt.Println("print expects one argument: [@] or []#[]") + fmt.Println(machine.InterCtx.Get("print expects one argument: [@] or []#[]")) return } @@ -282,11 +282,11 @@ func ioCall(m machine.Machine, call *machine.Call, in *bufio.Reader) { if call.Number == machine.SYS_READ { addr := call.Arg1 size := call.Arg2 - fmt.Printf("READ call for address 0x%x with %d bytes:\n", addr, size) + fmt.Printf(machine.InterCtx.Get("READ call for address 0x%x with %d bytes:\n"), addr, size) buf := make([]byte, size) _, err := in.Read(buf) if err != nil { - fmt.Printf("Error reading stdin: %v\n", err) + fmt.Printf(machine.InterCtx.Get("Error reading stdin: %v\n"), err) return } @@ -305,13 +305,13 @@ func printRegisters(m machine.Machine, info *machine.ArchitectureInfo, regs []ui if regs[i] != v { switch info.WordWidth { case 8: - fmt.Printf("Register %v: changed from 0x%02x to 0x%02x\n", r, regs[i], v) + fmt.Printf(machine.InterCtx.Get("Register %v: changed from 0x%02x to 0x%02x\n"), r, regs[i], v) case 16: - fmt.Printf("Register %v: changed from 0x%04x to 0x%04x\n", r, regs[i], v) + fmt.Printf(machine.InterCtx.Get("Register %v: changed from 0x%04x to 0x%04x\n"), r, regs[i], v) case 32: - fmt.Printf("Register %v: changed from 0x%08x to 0x%08x\n", r, regs[i], v) + fmt.Printf(machine.InterCtx.Get("Register %v: changed from 0x%08x to 0x%08x\n"), r, regs[i], v) default: - fmt.Printf("Register %v: changed from 0x%016x to 0x%016x\n", r, regs[i], v) + fmt.Printf(machine.InterCtx.Get("Register %v: changed from 0x%016x to 0x%016x\n"), r, regs[i], v) } regs[i] = v } @@ -322,14 +322,14 @@ func printRegisters(m machine.Machine, info *machine.ArchitectureInfo, regs []ui func debuggerNext(m machine.Machine, sym []assembler.DebuggerToken, in *bufio.Reader, info *machine.ArchitectureInfo, regs []uint64) []uint64 { call, err := m.NextInstruction() if err != nil { - fmt.Printf("instruction execution failed: %v", err) + fmt.Printf(machine.InterCtx.Get("Instruction execution failed: %v\n"), err) return regs } pc := m.GetCurrentInstructionAddress() if call != nil { if call.Number == machine.SYS_BREAK { - fmt.Printf("BREAK call while stepping at address 0x%x\n", pc) + fmt.Printf(machine.InterCtx.Get("BREAK call while stepping at address 0x%x\n"), pc) } else { ioCall(m, call, in) } @@ -344,14 +344,14 @@ func debuggerContinue(m machine.Machine, sym []assembler.DebuggerToken, breakpoi for { call, err := m.NextInstruction() if err != nil { - fmt.Printf("Instruction execution failed: %v\n", err) + fmt.Printf(machine.InterCtx.Get("Instruction execution failed: %v\n"), err) return regs } pc := m.GetCurrentInstructionAddress() if call != nil { if call.Number == machine.SYS_BREAK { - fmt.Printf("Stopped at BREAK call at address 0x%x\n", pc) + fmt.Printf(machine.InterCtx.Get("Stopped at BREAK call at address 0x%x\n"), pc) debuggerPrint(m, sym, []string{"#3"}, info) return printRegisters(m, info, regs) } else { @@ -373,7 +373,7 @@ func debuggerContinue(m machine.Machine, sym []assembler.DebuggerToken, breakpoi }) if brk { - fmt.Printf("Stopped at breakpoint at address 0x%x\n", pc) + fmt.Printf(machine.InterCtx.Get("Stopped at breakpoint at address 0x%x\n"), pc) debuggerPrint(m, sym, []string{"#3"}, info) return printRegisters(m, info, regs) } @@ -381,7 +381,7 @@ func debuggerContinue(m machine.Machine, sym []assembler.DebuggerToken, breakpoi } func printBreakpoints(breakpoints []uint64, info *machine.ArchitectureInfo) { - fmt.Println("Breakpoints:") + fmt.Println(machine.InterCtx.Get("Breakpoints:")) for _, b := range breakpoints { switch info.WordWidth { case 8: @@ -416,7 +416,7 @@ func debuggerBreakpoint(sym []assembler.DebuggerToken, breakpoints *[]uint64, ar var err error addr, err = strconv.ParseUint(args[0], 0, 64) if err != nil { - fmt.Printf("%v is not a number.\n", args[0]) + fmt.Printf(machine.InterCtx.Get("%v is not a number.\n"), args[0]) return } } @@ -428,7 +428,7 @@ func debuggerBreakpoint(sym []assembler.DebuggerToken, breakpoints *[]uint64, ar n_brks[i] = p brk_idx++ } else if p == addr { - fmt.Println("Breakpoint already exists") + fmt.Println(machine.InterCtx.Get("Breakpoint already exists.")) return } else { break @@ -444,13 +444,13 @@ func debuggerBreakpoint(sym []assembler.DebuggerToken, breakpoints *[]uint64, ar *breakpoints = n_brks - fmt.Printf("New breakpoint at address 0x%x\n", addr) + fmt.Printf(machine.InterCtx.Get("New breakpoint at address 0x%x\n"), addr) printBreakpoints(*breakpoints, info) } func debuggerRemove(sym []assembler.DebuggerToken, breakpoints *[]uint64, args []string, info *machine.ArchitectureInfo) { if len(args) < 1 { - fmt.Println("remove expects a breakpoint to remove: remove
") + fmt.Println(machine.InterCtx.Get("remove expects a breakpoint to remove: remove
")) return } @@ -464,7 +464,7 @@ func debuggerRemove(sym []assembler.DebuggerToken, breakpoints *[]uint64, args [ } } - fmt.Printf("Cannot parse %v as address.\n", args[0]) + fmt.Printf(machine.InterCtx.Get("Cannot parse %v as address.\n"), args[0]) return } FIND: @@ -476,7 +476,7 @@ FIND: } } - fmt.Printf("No breakpoint at address 0x%x\n", addr) + fmt.Printf(machine.InterCtx.Get("No breakpoint at address 0x%x\n"), addr) return FOUND: n_brks := make([]uint64, len(*breakpoints)-1) @@ -506,12 +506,12 @@ func getDumpExpr(m machine.Machine, expr string, prog []uint8) ([]uint8, error) of, err := strconv.ParseUint(offset, 0, 64) if err != nil { - return nil, fmt.Errorf("%v is not a number", offset) + return nil, fmt.Errorf(machine.InterCtx.Get("%v is not a number"), offset) } l, err := strconv.ParseUint(length, 0, 64) if err != nil { - return nil, fmt.Errorf("%v is not a number", length) + return nil, fmt.Errorf(machine.InterCtx.Get("%v is not a number"), length) } end := of + l @@ -523,7 +523,7 @@ func getDumpExpr(m machine.Machine, expr string, prog []uint8) ([]uint8, error) } else { addr, length, has_at := strings.Cut(expr, "@") if !has_at { - return nil, fmt.Errorf("cannot parse %v as a dump argument", expr) + return nil, fmt.Errorf(machine.InterCtx.Get("cannot parse %v as a dump argument"), expr) } addr = strings.TrimSpace(addr) @@ -531,16 +531,16 @@ func getDumpExpr(m machine.Machine, expr string, prog []uint8) ([]uint8, error) ad, err := strconv.ParseUint(addr, 0, 64) if err != nil { - return nil, fmt.Errorf("%v is not a number", addr) + return nil, fmt.Errorf(machine.InterCtx.Get("%v is not a number"), addr) } l, err := strconv.ParseUint(length, 0, 64) if err != nil { - return nil, fmt.Errorf("%v is not a number", length) + return nil, fmt.Errorf(machine.InterCtx.Get("%v is not a number"), length) } mem, err := m.GetMemoryChunk(ad, l) if err != nil { - return nil, fmt.Errorf("error getting memory chunk: %v", err) + return nil, fmt.Errorf(machine.InterCtx.Get("error getting memory chunk: %v"), err) } return mem, nil @@ -549,7 +549,7 @@ func getDumpExpr(m machine.Machine, expr string, prog []uint8) ([]uint8, error) func debuggerDump(m machine.Machine, args []string, prog []uint8) { if len(args) < 2 { - fmt.Println("dump expects two arguments: (@ or []#[]) ") + fmt.Println(machine.InterCtx.Get("dump expects two arguments: (@ or []#[]) ")) return } @@ -558,19 +558,19 @@ func debuggerDump(m machine.Machine, args []string, prog []uint8) { dump, err := getDumpExpr(m, expr, prog) if err != nil { - fmt.Printf("Cannot get content to dump: %v\n", err) + fmt.Printf(machine.InterCtx.Get("Cannot get content to dump: %v\n"), err) return } f, err := os.OpenFile(file, os.O_CREATE | os.O_WRONLY | os.O_TRUNC, 0644) if err != nil { - fmt.Printf("Cannot open %s for write: %v\n", file, err) + fmt.Printf(machine.InterCtx.Get("Cannot open %s for write: %v\n"), file, err) return } _, err = f.Write(dump) if err != nil { - fmt.Printf("Error while writing to %s: %v\n", file, err) + fmt.Printf(machine.InterCtx.Get("Error while writing to %s: %v\n"), file, err) } f.Close() @@ -579,9 +579,9 @@ func debuggerDump(m machine.Machine, args []string, prog []uint8) { func debuggerRewind(m machine.Machine, prog []uint8) { err := m.LoadProgram(prog) if err != nil { - fmt.Printf("Error while reloading machine: %v\n", err) + fmt.Printf(machine.InterCtx.Get("Error while reloading machine: %v\n"), err) } else { - fmt.Printf("Reloaded machine.\n") + fmt.Println(machine.InterCtx.Get("Reloaded machine.")) } } @@ -594,7 +594,7 @@ func getSetExpr(m machine.Machine, expr string) (uint64, uint64, error) { if !has_at { reg, err := m.GetRegisterNumber(addr) if err != nil { - return 0, 0, fmt.Errorf("cannot get register number: %v", err) + return 0, 0, fmt.Errorf(machine.InterCtx.Get("cannot get register number: %v"), err) } return reg, 0, nil } @@ -604,7 +604,7 @@ func getSetExpr(m machine.Machine, expr string) (uint64, uint64, error) { if err != nil { a, err = strconv.ParseUint(addr, 0, 64) if err != nil { - return 0, 0, fmt.Errorf("%v is not a register or address", addr) + return 0, 0, fmt.Errorf(machine.InterCtx.Get("%v is not a register or address"), addr) } } else { a, _ = m.GetRegister(reg) @@ -612,7 +612,7 @@ func getSetExpr(m machine.Machine, expr string) (uint64, uint64, error) { l, err := strconv.ParseUint(length, 0, 64) if err != nil { - return 0, 0, fmt.Errorf("%v is not a number", length) + return 0, 0, fmt.Errorf(machine.InterCtx.Get("%v is not a number"), length) } return a, l, nil @@ -620,7 +620,7 @@ func getSetExpr(m machine.Machine, expr string) (uint64, uint64, error) { func debuggerSet(m machine.Machine, args []string) { if len(args) < 2 { - fmt.Printf("set expects two arguments: [@] ") + fmt.Println(machine.InterCtx.Get("set expects two arguments: [@] ")) return } @@ -632,14 +632,14 @@ func debuggerSet(m machine.Machine, args []string) { value, err := strconv.ParseUint(args[1], 0, 64) if err != nil { - fmt.Printf("Cannot parse %v as number: %v", args[1], err) + fmt.Printf(machine.InterCtx.Get("Cannot parse %v as number: %v"), args[1], err) return } if length == 0 { err := m.SetRegister(addr, value) if err != nil { - fmt.Printf("Error while changing register content: %v\n", err) + fmt.Printf(machine.InterCtx.Get("Error while changing register content: %v\n"), err) } } else { arr := make([]uint8, length) @@ -652,17 +652,17 @@ func debuggerSet(m machine.Machine, args []string) { err := m.SetMemoryChunk(addr, arr) if err != nil { - fmt.Printf("Error while changing memory content: %v\n", err) + fmt.Printf(machine.InterCtx.Get("Error while changing memory content: %v\n"), err) } } } func debugMachine(m machine.Machine, sym []assembler.DebuggerToken, prog []uint8) { version() - fmt.Println("Type 'help' for a list of commands.") - + fmt.Println(machine.InterCtx.Get("Type 'help' for a list of commands.")) + info := m.ArchitectureInfo() - fmt.Println("Debugging", info.Name) + fmt.Println(machine.InterCtx.Get("Debugging"), info.Name) var breakpoints []uint64 in := bufio.NewReader(os.Stdin) @@ -714,7 +714,7 @@ func debugMachine(m machine.Machine, sym []assembler.DebuggerToken, prog []uint8 case "ping": fmt.Println("pong!") default: - fmt.Printf("no such command: %v\n", wsl[0]) + fmt.Printf(machine.InterCtx.Get("No such command: %v\n"), wsl[0]) } } else { fmt.Println("") @@ -726,5 +726,5 @@ func debugMachine(m machine.Machine, sym []assembler.DebuggerToken, prog []uint8 fmt.Println("") EXIT: - fmt.Println("bye!") + fmt.Println(machine.InterCtx.Get("bye!")) } diff --git a/go.mod b/go.mod index 2931e8d..20e45bd 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/gboncoffee/egg -go 1.19 +go 1.22 + +require github.com/gboncoffee/intergo v1.0.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7513154 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/gboncoffee/intergo v1.0.1 h1:4x9WVBYs6LkcYIVQNJaxJkvdS1CNzTCIwsKwarMLHGg= +github.com/gboncoffee/intergo v1.0.1/go.mod h1:9UkNADN1rn92EkVPSNk7bjIqoLrJP3v7W5TudLmk2hs= diff --git a/internationalization.go b/internationalization.go new file mode 100644 index 0000000..941adaa --- /dev/null +++ b/internationalization.go @@ -0,0 +1,198 @@ +package main + +var brazilian = map[string]string{ + + // + // main.go. + // + + // Infos. + `Currently supported architetures: +'riscv' - RISC-V IM, 32 bits +'mips' - Subset of MIPS32 (experimental) +'sagui' - Fantasy 8 bit RISC`: `Arquiteturas suportadas: +'riscv' - RISC-V IM, 32 bits +'mips' - Subconjunto de MIPS32 (experimental) +'sagui' - RISC fantasia de 8 bits`, + "EGG - Emulador Genérico do Gabriel - version ": "EGG - Emulador Genérico do Gabriel - versão ", + // Main execution loop. + "Instruction execution failed: %v\n": "Falha na execução da instrução: %v\n", + // Args. + "Select architeture to use.": "Seleciona a arquitetura a ser utilizada.", + "Select architeture to use (shorthand).": "Seleciona a arquitetura a ser utilizada (abrev.).", + "Lists currently supported architetures and quit.": "Lista arquiteturas suportadas e sai.", + "Lists currently supported architetures (shorthand).": "Lista arquiteturas suportadas e sai (abrev.).", + "Show current version and quit.": "Mostra a versão atual e sai.", + "Show current version and quit (shorthand).": "Mostra a versão atual e sai (abrev.).", + "Enter debugger upon startup.": "Entra no debugger após inicialização.", + "Enter debugger upon startup (shorthand).": "Entra no debugger após inicialização (abrev).", + // main(). + "Unknown architeture: %v\n": "Arquitetura desconhecida: %v\n", + "No Assembly file supplied.": "Nenhum arquivo Assembly providenciado.", + "Could not read supplied file %v\n": "Erro lendo o arquivo %v providenciado", + "Error assembling file %v: %v\n": "Erro montando o arquivo %v: %v\n", + "Error loading assembled program: %v\n": "Erro carregando o programa montado: %v\n", + "Debugging is not supported for the selected backend.": "Debugging não é suportado pelo backend selecionado.", + + // + // debugger.go. + // + + // Massive help string. + `Commands: + +help + Shows this help. + Shortcut: h +print [@] + Prints the content of registers and memory. + Shortcut: p +printall + Prints the content of all registers. + Shortcut: pall +next + Executes the next instruction, then pauses. + Shortcut: n +continue + Continue execution until a BREAK call or breakpoint. + Shortcut: c +break [expr] + With an argument, creates a new breakpoint. With no argument, shows all + breakpoints. Accepts numbers and Assembly labels. + Shortcut: b +remove + Removes a breakpoint. Accepts numbers and Assembly labels. + Shortcut: r +dump
@ + Dumps the content of memory to a file. + Shortcut: d +rewind + Reloads the machine, i.e., asks it to return to it's original state. + Shortcut: rew +set [@] + Changes the content of a register or memory. + Shortcut: s +exit + Terminate debugging session. + Shortcut: e +quit + Alias to exit. + Shortcut: q + +The print command generally follows this rules: +- If the expression is only a register (e.g., x1, t1, zero, ra, etc), it prints + it's contents; +- If the expression is a register with a length (e.g., t1@1, ra@7, etc), it + prints the content of the memory addressed by the content of the register. +The set command works the same way. + +The dump command also accepts registers, but always dereference them. + +Both print and dump commands accepts the special expression #, which means the +program itself. For example, you may dump the assembled program to a file by +running 'dump # file'. + +In the print command, # means "length instructions after addr". +# is a shortcut to use with the current instruction address. +`: `Comandos: + +help + Mostra esse texto de ajuda. + Abreviação: h +print [@] + Imprime o conteúdo de registradores e da memória. + Abreviação: p +printall + Imprime o conteúdo de todos os registradores. + Abreviação: pall +next + Executa a próxima instrução, então pausa. + Abreviação: n +continue + Continua a execução até uma chamada BREAK ou um ponto de parada + (breakpoint). +break [expr] + Com um argumento, cria um novo ponto de parada (breakpoint). Sem o + argumento, mostra todos os pontos de parada. Aceita números e etiquetas + Assembly. + Abreviação: b +remove + Remove um ponto de parada (breakpoint). Aceita números e etiquetas Assembly. + Abreviação: r +dump @ + Salva conteúdo da memória em um arquivo. + Abreviação: d +rewind + Recarrega a máquina, isso é, pede para que ela retorne ao estado original. + Abreviação: rew +set [@tamanho] + Muda o conteúdo de registradores ou da memória. + Abreviação: s +exit + Termina a sessão de debugging. + Abreviação: e +quit + Igual à exit. + Abreviação: q + +O comando print, de maneira geral, segue as seguintes regras: +- Se a expressão é somente um registrador (por exemplo, x1, t1, zero, ra, etc), + imprime seu conteúdo; +- Se a expressão é um registrador com um tamanho (por exemplo, x1@1, ra@7, etc), + imprime o conteúdo da memória endereçada pelo conteúdo do registrador. +O comando set funciona da mesma maneira. + +O comando dump também aceita registradores, porém sempre os utiliza como +endereços. + +Tanto print quanto dump também aceitam a expressão especial #, que representa o +programa em si. Por exemplo, é possível salvar o programa montado em um arquivo +com o comando 'dump # arquivo'. + +No comando print, #tamanho significa "tantas instruções após addr". +# é uma abreviação para usar o endereço da instrução atual. +`, + // Debugger functions. + "cannot parse %v as number: %v": "impossível converter %v para número", + "length not supplied": "tamanho não providenciado", + "cannot parse %v as address": "impossível converter %v para endereço", + "%v is not a number": "%v não é um número", + "no instruction at address 0x%x": "nenhuma instrução no endereço 0x%x", + "%v is not a register or address": "%v não é um registrador ou endereço", + "cannot get memory content: %v": "não foi possível ler o conteúdo da memória: %v", + "cannot get register content: %v": "não foi possível ler o conteúdo do registrador: %v", + "print expects one argument: [@] or []#[]": "print necessita de um argumento: [@] ou []#[]", + "READ call for address 0x%x with %d bytes:\n": "Chamada READ para o endereço 0x%x com %d bytes:\n", + "Error reading stdin: %v\n": "Erro lendo input padrão: %v\n", + "Register %v: changed from 0x%02x to 0x%02x\n": "Registrador %v: mudou de 0x%02x para 0x%02x\n", + "Register %v: changed from 0x%04x to 0x%04x\n": "Registrador %v: mudou de 0x%04x para 0x%04x\n", + "Register %v: changed from 0x%08x to 0x%08x\n": "Registrador %v: mudou de 0x%08x para 0x%08x\n", + "Register %v: changed from 0x%016x to 0x%016x\n": "Registrador %v: mudou de 0x%016x para 0x%016x\n", + "BREAK call while stepping at address 0x%x\n": "Chamada BREAK enquanto executando o endereço 0x%x\n", + "Stopped at BREAK call at address 0x%x\n": "Parado na chamada BREAK no endereço 0x%x\n", + "Stopped at breakpoint at address 0x%x\n": "Parado no ponto de parada (breakpoint) no endereço 0x%x\n", + "Breakpoints:": "Pontos de parada (breakpoints):", + "%v is not a number.\n": "%v não é um número.\n", + "Breakpoint already exists": "Ponto de parada (breakpoint) já existe.", + "New breakpoint at address 0x%x\n": "Novo ponto de parada (breakpoint) no endereço 0x%x\n", + "remove expects a breakpoint to remove: remove
": "remove necessita de um ponto de parada (breakpoint) para remover: remove ", + "Cannot parse %v as address.\n": "Impossível converter %v para endereço.\n", + "No breakpoint at address 0x%x\n": "Nenhum ponto de parada (breakpoint) no endereço 0x%x\n", + "cannot parse %v as a dump argument": "impossível converter %v para um argumento de dump", + "error getting memory chunk: %v": "erro lendo região da memória: %v", + "dump expects two arguments: (@ or []#[]) ": "dump necessita de dois argumentos: (@ ou []#[]) ", + "Cannot get content to dump: %v\n": "Não foi possível ler o conteúdo para o dump: %v\n", + "Cannot open %s for write: %v\n": "Não foi possível abrir %s para escrita: %v\n", + "Error while writing to %s: %v\n": "Erro enquanto escrevendo para %s: %v\n", + "Error while reloading machine: %v\n": "Erro enquanto recarregando a máquina: %v\n", + "Reloaded machine.": "Máquina recarregada.", + "cannot get register number: %v": "não foi possível encontrar o número do registrador: %v", + "set expects two arguments: [@] ": "set necessita de dois argumentos: [@] ", + "Cannot parse %v as number: %v": "Impossível converter %v para número: %v", + "Error while changing register content: %v\n": "Erro modificando o conteúdo do registrador: %v\n", + "Error while changing memory content: %v\n": "Erro modificando o conteúdo da memória", + "Type 'help' for a list of commands.": "Entre 'help' para ver uma lista de comandos", + "Debugging": "Debuggando", + "No such command: %v\n": "Comando inexistente: %v\n", + "bye!": "até mais!", +} diff --git a/machine/machine.go b/machine/machine.go index 174e0d5..6c95290 100644 --- a/machine/machine.go +++ b/machine/machine.go @@ -1,7 +1,10 @@ // Package egg/machine has the interface and syscall struct used by EGG backends. package machine -import "github.com/gboncoffee/egg/assembler" +import ( + "github.com/gboncoffee/egg/assembler" + "github.com/gboncoffee/intergo" +) type ArchitectureInfo struct { Name string @@ -84,3 +87,6 @@ type Call struct { Arg1 uint64 Arg2 uint64 } + +// Internationalization context available for architectures. +var InterCtx intergo.InterContext diff --git a/main.go b/main.go index adf92cf..f1296e7 100644 --- a/main.go +++ b/main.go @@ -14,23 +14,25 @@ import ( "github.com/gboncoffee/egg/sagui" ) +const VERSION = "2.2.0" + // Put new architetures here... (main.go:/switch architeture) func listArchs() { - fmt.Println(`Currently supported architetures: + fmt.Println(machine.InterCtx.Get(`Currently supported architetures: 'riscv' - RISC-V IM, 32 bits 'mips' - Subset of MIPS32 (experimental) -'sagui' - Fantasy 8 bit RISC`) +'sagui' - Fantasy 8 bit RISC`)) } func version() { - fmt.Println("EGG - Emulador Genérico do Gabriel - version 2.2.0") + fmt.Println(machine.InterCtx.Get("EGG - Emulador Genérico do Gabriel - version ") + VERSION) } func runMachine(m machine.Machine) { for { call, err := m.NextInstruction() if err != nil { - log.Printf("Instruction execution failed: %v\n", err) + log.Printf(machine.InterCtx.Get("Instruction execution failed: %v\n"), err) return } @@ -72,16 +74,20 @@ func main() { var ver bool var m machine.Machine + machine.InterCtx.Init() + machine.InterCtx.AddLocale("pt_BR", brazilian) + machine.InterCtx.AutoSetPreferedLocale() + log.SetFlags(0) - flag.StringVar(&architeture, "arch", "riscv", "Select architeture to use.") - flag.StringVar(&architeture, "a", "riscv", "Select architeture to use (shorthand).") - flag.BoolVar(&list, "list-archs", false, "Lists currently supported architetures and quit.") - flag.BoolVar(&list, "l", false, "Lists currently supported architetures (shorthand).") - flag.BoolVar(&ver, "version", false, "Show current version and quit.") - flag.BoolVar(&ver, "v", false, "Show current version and quit (shorthand).") - flag.BoolVar(&debug, "debug", false, "Enter debugger upon startup.") - flag.BoolVar(&debug, "d", false, "Enter debugger upon startup (shorthand).") + flag.StringVar(&architeture, "arch", "riscv", machine.InterCtx.Get("Select architeture to use.")) + flag.StringVar(&architeture, "a", "riscv", machine.InterCtx.Get("Select architeture to use (shorthand).")) + flag.BoolVar(&list, "list-archs", false, machine.InterCtx.Get("Lists currently supported architetures and quit.")) + flag.BoolVar(&list, "l", false, machine.InterCtx.Get("Lists currently supported architetures (shorthand).")) + flag.BoolVar(&ver, "version", false, machine.InterCtx.Get("Show current version and quit.")) + flag.BoolVar(&ver, "v", false, machine.InterCtx.Get("Show current version and quit (shorthand).")) + flag.BoolVar(&debug, "debug", false, machine.InterCtx.Get("Enter debugger upon startup.")) + flag.BoolVar(&debug, "d", false, machine.InterCtx.Get("Enter debugger upon startup (shorthand).")) flag.Parse() @@ -108,38 +114,38 @@ func main() { var r sagui.Sagui m = &r default: - log.Printf("Unknown architeture: %v", architeture) + log.Printf(machine.InterCtx.Get("Unknown architeture: %v\n"), architeture) listArchs() os.Exit(1) } file := flag.Arg(0) if file == "" { - log.Println("No Assembly file supplied.") + log.Println(machine.InterCtx.Get("No Assembly file supplied.")) os.Exit(1) } asm, err := readToString(file) if err != nil { - log.Printf("Could not read supplied file %v", file) + log.Printf(machine.InterCtx.Get("Could not read supplied file %v\n"), file) os.Exit(1) } code, sym, err := m.Assemble(asm) if err != nil { - log.Printf("Error assembling file %v: %v\n", file, err) + log.Printf(machine.InterCtx.Get("Error assembling file %v: %v\n"), file, err) os.Exit(1) } err = m.LoadProgram(code) if err != nil { - log.Printf("Error loading assembled program: %v\n", err) + log.Printf(machine.InterCtx.Get("Error loading assembled program: %v\n"), err) os.Exit(1) } if debug { if sym == nil { - log.Println("Debugging is not supported for the selected backend.") + log.Println(machine.InterCtx.Get("Debugging is not supported for the selected backend.")) os.Exit(1) } // Hello fellow Acme user. Plumb this: debugger.go:/debugMachine