Commit fc3e3184 authored by Connor Abbott's avatar Connor Abbott Committed by Lyude Paul

bifrost/asm: Produce binary output

parent 227dbb54
......@@ -601,13 +601,13 @@ class Parser:
for i, s in enumerate(self._file.readlines()):
# Skip comments and cookies
if s.strip().startswith('#') or self.COOKIE.match(s):
if self._verbose >= 2:
if self._verbose >= 3:
print('%d*: %s' % (i, s.rstrip()))
if self._verbose:
if self._verbose >= 2:
print('%d%s: %s' % (
i, ' ' if self._verbose >= 2 else '', s.rstrip()))
i, ' ' if self._verbose >= 3 else '', s.rstrip()))
# Strip in-line comments /* like this */
s = self.INLINE_COMMENT.sub('', s).rstrip()
......@@ -1734,6 +1734,11 @@ class Clause:
return encoded
def write(self, f):
for quadword in self.encode().cut(128):
def dump(self):
print('Clause #%d' % self.idx)
......@@ -1979,9 +1984,20 @@ def scan_op_tokens(string):
return op, stage, dst, args, data_reg
def write_to_file(clauses, file):
for clause in clauses:
# The blob seems to always append 7 quadwords, or 112 bytes of padding to
# the end (perhaps to avoid pagefaults due to prefetching?). Do that here.
file.write(b'\x00' * (7 * 16))
if __name__ == '__main__':
parser = argparse.ArgumentParser('Bifrost Assembler')
parser.add_argument('file', type=argparse.FileType())
parser.add_argument('-o', '--output', default='a.out',
help=("The file to output the assembled blob to."),
parser.add_argument('-d', '--debug',
help="Throw ParsingExceptions as-is, don't silence them",
......@@ -1989,9 +2005,11 @@ if __name__ == '__main__':
help=("Be more verbose when parsing. May be specified "
"more than once to increase the verbosity level. "
"The first verbosity level will make the assembler "
"print all non-comment lines as they are parsed, "
"the second will make the assembler print all "
"lines that are being read in"),
"print a dump of the parsed clauses, the second "
"will make the assembler print all non-comment "
"lines as they are parsed, and the third will make "
"the assembler print all lines that are being read "
action='count', default=0)
args = parser.parse_args()
......@@ -2040,9 +2058,12 @@ if __name__ == '__main__':
unexpected_eof = False
if args.verbose:
for clause in clauses:
write_to_file(clauses, args.output)
except StopIteration as e:
if unexpected_eof:
raise ParsingException('Unexpected EOF') from e
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