diff options
author | Himbeer <himbeer@disroot.org> | 2024-08-30 18:58:41 +0200 |
---|---|---|
committer | Himbeer <himbeer@disroot.org> | 2024-08-30 18:58:41 +0200 |
commit | 56ccd1992d5a0e420200b36e394f9ee39458e9eb (patch) | |
tree | 3270ecf3ace1401d3bd2d51c944efb3d67412bfe | |
parent | fa461715a9a4fbca6bd012c0f2b8e35631ec12e8 (diff) |
Drop the incrementing name concept for variables
Since the stack can be written to any number of times it is not
necessary to abide by SSA rules. This significantly simplifies the IL
structure which can help with debugging IL generation.
-rw-r--r-- | decl.go | 25 | ||||
-rw-r--r-- | generate.go | 17 |
2 files changed, 2 insertions, 40 deletions
diff --git a/decl.go b/decl.go deleted file mode 100644 index 32adbae..0000000 --- a/decl.go +++ /dev/null @@ -1,25 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Himbeer <himbeer@disroot.org> -// -// SPDX-License-Identifier: GPL-3.0-or-later - -package main - -import ( - "fmt" -) - -type mutInfo struct { - id string - nameIndex int -} - -func (m mutInfo) name() string { - return fmt.Sprintf("%%%s%d", m.id, m.nameIndex-1) -} - -func (m *mutInfo) nextName() string { - defer func() { m.nameIndex++ }() - return fmt.Sprintf("%%%s%d", m.id, m.nameIndex) -} - -var locals = map[string]map[string]mutInfo{} diff --git a/generate.go b/generate.go index 432bd25..3fa09f7 100644 --- a/generate.go +++ b/generate.go @@ -11,8 +11,6 @@ import ( "strings" ) -var currentFunc string - var funcRegIndex int func allocReg() string { @@ -80,8 +78,6 @@ func generateToplevel(toplevel expression, w io.Writer) error { func generateFunction(function *functionExpr, w io.Writer) error { resetRegs() - currentFunc = function.name - locals[function.name] = map[string]mutInfo{} if function.link != defaultLinkage { fmt.Fprintf(w, "%s ", function.link) @@ -148,17 +144,8 @@ func generateMutStmt(stmt *mutStmt, toplevel bool, w io.Writer) error { return err } - if _, ok := locals[currentFunc][stmt.name]; ok { - return errAlreadyDeclared{name: stmt.name, line: stmt.line()} - } - - mutable := mutInfo{ - id: stmt.name, - } - locals[currentFunc][stmt.name] = mutable - - fmt.Fprintf(w, "%s =l alloc4 8\n", mutable.nextName()) - fmt.Fprintf(w, "storew %s, %s\n", value, mutable.name()) + fmt.Fprintf(w, "%%%s =l alloc4 4\n", stmt.name) + fmt.Fprintf(w, "storew %s, %%%s\n", value, stmt.name) return nil } |