Log. 13th August, 2013.
I've been pottering about with Flex & YACC (well, Bison) for a bit as a distraction - having been coding in C for more than 20 years and somehow always managing to avoid them, I reckoned it was time to give them a look. Starting with the basic examples that just evaluate expressions on the fly, the ins and outs of YACC began to click, and I got it to the point of building Abstract Syntax Trees storing arbitrarily complex expressions for later evaluation.
At this point, it dawned on me what I could actually use this for. A while ago, I wrote a really hacky 6809 assembler in Perl (still linked from /dragon/). It does its expression parsing by just building up big strings in Perl and eval()ing them (safely!). But it's really slow - I mean, it might take a few seconds to assemble a complex source file (this is known as FWP). Anyway, nearly everything I learn somehow manages to hang off the general "Dragon computer" hobby, so why should this be any exception? Writing the Perl one means I know how to make an assembler handle complex (well, as complex as things get in assembly) reference arithmetic (most assemblers either don't allow forward references, or have to be able to resolve everything after two passes), so I thought I might as well just start translating that into C.
So with a few evenings of work, I have. In the end, not much was translation - just the opcode table really - as I generally thought of better ways of breaking up the code. It's incomplete, but it reads in assembly source and spits out data in a variety of formats, generate listings and "symbol files". It's able to assemble all the projects I've written to identical object code, and it does it much faster. Nice.
At the moment the new assembler needs GLib (a pretty recent version, too), but having autoconfused the project anyway, I intend to pull a few bits of data structure handling out of Gnulib, so at some point it should build on more machines (and be more portable to Windows - I tried a static build of GLib, and Wine seemed to think it was hanging on threads) For now, here's a prerelease:
As ever, Valgrind has been invaluable. If you don't routinely exercise your code with that, you should start today. Seriously.
Tags: programming, 6809, assembly, flex, yacc, bison, autoconf