Commit 06804dae authored by Connor Abbott's avatar Connor Abbott

bifrost/asm: Produce binary output

parent acce16bc
......@@ -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()))
continue
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):
quadword.byteswap()
quadword.tofile(f)
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:
clause.write(file)
# 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."),
type=argparse.FileType('wb'))
parser.add_argument('-d', '--debug',
help="Throw ParsingExceptions as-is, don't silence them",
action='store_true')
......@@ -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 "
"in."),
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:
clause.dump()
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