-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#19 [asmik] rewrote asmik emit using tafka listener
- Loading branch information
Showing
9 changed files
with
199 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,20 @@ | ||
from .emit import AsmikUnit, asmik_emit | ||
from sleepy.asmik.argument import Integer, Register | ||
from sleepy.asmik.data import IntegerData | ||
from sleepy.asmik.instruction import ( | ||
Addi, | ||
Addim, | ||
Andb, | ||
Brn, | ||
Divi, | ||
Hlt, | ||
Instruction, | ||
Load, | ||
Muli, | ||
Orb, | ||
Remi, | ||
Slti, | ||
Stor, | ||
Xorb, | ||
) | ||
|
||
from .unit import AsmikUnit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from dataclasses import dataclass | ||
|
||
from sleepy.tafka import TafkaUnit, TafkaWalker | ||
|
||
from .argument import Integer, Unassigned | ||
from .emit import AsmikEmitListener | ||
from .instruction import Addim | ||
from .memory import Memory | ||
|
||
|
||
@dataclass | ||
class AsmikUnit: | ||
memory: Memory | ||
|
||
@staticmethod | ||
def emited_from(tafka: TafkaUnit) -> "AsmikUnit": | ||
def resolve_addresses(asmik: AsmikEmitListener) -> None: | ||
for instr in asmik.memory.instr: | ||
if ( | ||
isinstance(instr, Addim) # | ||
and isinstance(instr.rhs, Unassigned) | ||
): | ||
label = instr.rhs.label | ||
instr.rhs = Integer(asmik.resolved[label]) | ||
|
||
asmik = AsmikEmitListener() | ||
walker = TafkaWalker(asmik) | ||
|
||
walker.explore_block(tafka.main) | ||
for proc in tafka.procedures: | ||
walker.explore_procedure(proc) | ||
|
||
resolve_addresses(asmik) | ||
|
||
return AsmikUnit(asmik.memory) | ||
|
||
def to_text(self) -> str: | ||
text = "" | ||
|
||
text += "memory stack\n" | ||
for addr, data in sorted(self.memory.stack.items()): | ||
text += f"{addr:04d}: {data!r}\n" | ||
|
||
text += "memory instr\n" | ||
for i, instruction in enumerate(self.memory.instr): | ||
text += f"{(i * 4):04d}: {instruction!r}\n" | ||
|
||
return text |
Oops, something went wrong.