Commit 489a41e3 authored by Lyude Paul's avatar Lyude Paul

more wip

parent 5816c901
......@@ -44,8 +44,9 @@ class ParsingException(Exception):
class Parser:
INLINE_COMMENT = re.compile(r'/\*[^\(\*/\)]*\*/')
def __init__(self, asm_file):
def __init__(self, asm_file, verbose):
self._file = asm_file
self._verbose = verbose
@property
def lines(self):
......@@ -57,6 +58,8 @@ class Parser:
s = self.INLINE_COMMENT.sub('', s).rstrip()
if s != '':
self.last_line = i, s
if self._verbose:
print('%d: %s' % (i, s))
yield (i, s)
......@@ -114,11 +117,21 @@ class Constants(dict):
self[src] = reg_num
return self[src]
class Register(int):
pass
class Register:
def __init__(self, idx):
assert isinstance(idx, int)
self.idx = idx
class Uniform(int):
pass
def __repr__(self):
return '<Register %d>' % self.idx
class Uniform:
def __init__(self, idx):
assert isinstance(idx, int)
self.idx = idx
def __repr__(self):
return '<Uniform %d>' % self.idx
class OpResult(Enum):
PREV_FMA = 'T0'
......@@ -194,24 +207,10 @@ def scan_src_arg(string):
if not match:
raise ParsingException('Invalid src %s' % string)
return (match.group(1), int(match.group(2)))
# type_ = match.group(1)
# if type_ == 'T':
# idx = match.group(2)
# if idx:
# if idx != '0':
# return (type_, 0)
# elif idx == '1':
# return (type_, 1)
# else:
# raise ParsingException("Invalid index for T: %s (index must be 0 or 1)" % (
# idx))
# else:
# return (type_, None)
# else:
# return (type_, int(match.group(2)))
if match.group(1) == 'R':
return Register(int(match.group(2)))
else: # == 'U'
return Uniform(int(match.group(2)))
def parse_op_dst(string):
if string is None:
......@@ -220,7 +219,7 @@ def parse_op_dst(string):
try:
if string[0] != 'R':
raise Exception()
return int(string[1:])
return Register(int(string[1:]))
except Exception as e:
raise ParsingException('Invalid op destination %s (should be a register or None)' % (string)) from e
......@@ -454,12 +453,15 @@ parser.add_argument('file', type=argparse.FileType())
parser.add_argument('-d', '--debug',
action='store_true',
help="Throw ParsingExceptions as-is, don't silence them")
parser.add_argument('-s', '--source',
action='store_true',
help='(debugging) Print src line before AST dump')
args = parser.parse_args()
COOKIE = re.compile(r'^([A-Z0-9_]{4}|\t+.*)$')
# FIXME Do we even need this to be an object?
p = Parser(args.file)
p = Parser(args.file, args.source)
pp = pprint.PrettyPrinter(indent=4)
itr = iter(p.lines)
try:
......@@ -481,14 +483,13 @@ try:
raise ParsingException('Unexpected line after clause header: ' + l)
instructions = []
# TODO: accumulate constants, and assign them to cR0-5
# TODO: after that, continue building code for building register files
inst_stages = []
cycle_consts = Constants()
print('Clause #%s contents:' % clause_id)
for i, l in itr:
if l == '}':
pp.pprint(instructions)
print('End clause')
break
......@@ -508,7 +509,6 @@ try:
srcs[idx] = cycle_consts.assign(src)
# Process uniforms, registers, and special srcs (like location:)
# elif isinstance(src, tuple):
inst_stages.append((inst, dst, srcs))
if current_stage is add:
......@@ -518,7 +518,6 @@ try:
if len(inst_stages) != 0:
raise ParsingException('FMA without matching ADD')
pp.pprint(instructions)
unexpected_eof = False
except StopIteration as e:
if unexpected_eof:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment