1
0

Version field

This commit is contained in:
Jon Michael Aanes 2024-07-10 01:19:26 +02:00
parent ab5f4e623b
commit 228efae55b
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
6 changed files with 47 additions and 17 deletions

View File

@ -70,13 +70,17 @@ class AsciiPainter:
state.append({'state': 'none', 'val': ''}) state.append({'state': 'none', 'val': ''})
def getWidthOfColumns( def getWidthOfColumns(
self, number_states: int, number_states_per_block: int, number_state_vars: int, self,
number_states: int,
number_states_per_block: int,
number_state_vars: int,
) -> list[int]: ) -> list[int]:
widths = [0 for i in range(0, number_states_per_block)] widths = [0 for i in range(0, number_states_per_block)]
for base_state in range(0, number_states, number_states_per_block): for base_state in range(0, number_states, number_states_per_block):
for var_i in range(0, number_state_vars): for var_i in range(0, number_state_vars):
for state_i in range( for state_i in range(
0, min(number_states_per_block, number_states - base_state), 0,
min(number_states_per_block, number_states - base_state),
): ):
width = len(str(self.states[base_state + state_i][var_i]['val'])) width = len(str(self.states[base_state + state_i][var_i]['val']))
widths[state_i] = max(widths[state_i], width) widths[state_i] = max(widths[state_i], width)
@ -101,7 +105,9 @@ class AsciiPainter:
column_fmt = [ column_fmt = [
'{}{:>' + str(width) + '} ' '{}{:>' + str(width) + '} '
for width in self.getWidthOfColumns( for width in self.getWidthOfColumns(
number_states, number_states_per_block, number_state_vars, number_states,
number_states_per_block,
number_state_vars,
) )
] ]
@ -110,12 +116,15 @@ class AsciiPainter:
for var_i in range(0, number_state_vars): for var_i in range(0, number_state_vars):
output.append(name_fmt.format(NORMAL_COLOR, self.nameOfVar(var_i - 4))) output.append(name_fmt.format(NORMAL_COLOR, self.nameOfVar(var_i - 4)))
for state_i in range( for state_i in range(
0, min(number_states_per_block, number_states - base_state), 0,
min(number_states_per_block, number_states - base_state),
): ):
var = self.states[base_state + state_i][var_i] var = self.states[base_state + state_i][var_i]
output.append( output.append(
column_fmt[state_i].format( column_fmt[state_i].format(
REG_STATUS_TO_COLOR[var['state']], var['val'], NORMAL_COLOR, REG_STATUS_TO_COLOR[var['state']],
var['val'],
NORMAL_COLOR,
), ),
) )
output.append('\n') output.append('\n')

View File

@ -121,14 +121,16 @@ class Emulator:
self.registers['%rsp'] -= 1 self.registers['%rsp'] -= 1
self.stack[self.registers['%rsp']] = new_element self.stack[self.registers['%rsp']] = new_element
self.changedRegisters( self.changedRegisters(
('%rsp', 'change'), ('m' + str(self.registers['%rsp']), 'insert'), ('%rsp', 'change'),
('m' + str(self.registers['%rsp']), 'insert'),
) )
self.max_stack_size = max(self.registers['%rsp'], self.max_stack_size) self.max_stack_size = max(self.registers['%rsp'], self.max_stack_size)
def popFromStack(self): def popFromStack(self):
temp = self.stack[self.registers['%rsp']] temp = self.stack[self.registers['%rsp']]
self.changedRegisters( self.changedRegisters(
('%rsp', 'change'), ('m' + str(self.registers['%rsp']), 'remove'), ('%rsp', 'change'),
('m' + str(self.registers['%rsp']), 'remove'),
) )
self.registers['%rsp'] += 1 self.registers['%rsp'] += 1
return temp return temp

View File

@ -15,7 +15,11 @@ DEFAULT_OPTIONS = """register_node/.style={rectangle, draw=black!30,
class TikzPainter: class TikzPainter:
def __init__( def __init__(
self, registers=None, max_stack_size=8, stack_draw_mode='up', options=None, self,
registers=None,
max_stack_size=8,
stack_draw_mode='up',
options=None,
): ):
self.registers = registers if registers else REGISTERS self.registers = registers if registers else REGISTERS
self.text = [] self.text = []
@ -53,7 +57,10 @@ class TikzPainter:
) )
if base_pointer == index: if base_pointer == index:
self.addText( self.addText(
'\t\\draw ({0},{2}) -- ({1},{2});\n', x - 1.1, x + 1.1, pos - 0.25, '\t\\draw ({0},{2}) -- ({1},{2});\n',
x - 1.1,
x + 1.1,
pos - 0.25,
) )
base_pointer = emu.stack[base_pointer] base_pointer = emu.stack[base_pointer]
pos -= 0.5 pos -= 0.5
@ -62,7 +69,8 @@ class TikzPainter:
def drawStackDownward(self, pos, emu, x): def drawStackDownward(self, pos, emu, x):
pos -= 1 pos -= 1
for index in range( for index in range(
emu.getVal('%rsp') - 8, max(emu.last_sp, emu.getVal('%rsp')), emu.getVal('%rsp') - 8,
max(emu.last_sp, emu.getVal('%rsp')),
): ):
reg_state = emu.regState('m' + str(index)) reg_state = emu.regState('m' + str(index))
reg_dect = 'register_node, fill=' + self.getRegColor(reg_state) + '!10' reg_dect = 'register_node, fill=' + self.getRegColor(reg_state) + '!10'
@ -109,7 +117,10 @@ class TikzPainter:
signature = emu.getLineSignature(line_nr) signature = emu.getLineSignature(line_nr)
for token in signature: for token in signature:
self.addText( self.addText(
'\t\\node[text_node]() at ({}, {}){{{}}};\n', x - 1.25, pos, token, '\t\\node[text_node]() at ({}, {}){{{}}};\n',
x - 1.25,
pos,
token,
) )
pos -= 0.5 pos -= 0.5
@ -118,7 +129,10 @@ class TikzPainter:
pos = 0 pos = 0
for reg_name in self.registers: for reg_name in self.registers:
self.addText( self.addText(
'\t\\node[text_node]() at ({}, {}){{{}}};\n', x, pos, reg_name[1:], '\t\\node[text_node]() at ({}, {}){{{}}};\n',
x,
pos,
reg_name[1:],
) )
pos -= 0.5 pos -= 0.5
@ -135,7 +149,10 @@ class TikzPainter:
for index in range(1, self.max_stack_size): for index in range(1, self.max_stack_size):
pos -= 0.5 pos -= 0.5
self.addText( self.addText(
'\t\\node[text_node]() at ({}, {}){{TOS-{}}};\n', x, pos, index, '\t\\node[text_node]() at ({}, {}){{TOS-{}}};\n',
x,
pos,
index,
) )
def to_string(self, emu): def to_string(self, emu):

View File

@ -15,3 +15,7 @@ Compiling the LaTeX requires both a LaTeX compiler, and packages
Please ignore the `/tests` folder. It is very old, and unsupported, Please ignore the `/tests` folder. It is very old, and unsupported,
but kept for archival purposes. but kept for archival purposes.
""" """
__all__ = ['__version__']
from ._version import __version__

View File

@ -0,0 +1 @@
__version__ = '0.3.0'

View File

@ -41,10 +41,7 @@ this stuff is worth it, you can buy me a beer in return.
Jon Michael Aanes Jon Michael Aanes
```""" ```"""
PACKAGE_DESCRIPTION_SHORT = ( PACKAGE_DESCRIPTION_SHORT='Simple interpreter and stack tracer for the AMD x86-64 ABI.'
'Simple interpreter and stack tracer for the AMD x86-64 ABI.'
)
def parse_version_file(text: str) -> str: def parse_version_file(text: str) -> str:
match = re.match(r'^__version__\s*=\s*(["\'])([\d\.]+)\1$', text) match = re.match(r'^__version__\s*=\s*(["\'])([\d\.]+)\1$', text)