How do I use libyasm?
Peter Johnson
peter at tortall.net
Tue Dec 6 23:14:05 PST 2005
On Tue, 6 Dec 2005, Cafe Alpha wrote:
> I'd like to play with using libyasm as the back end for a smalltalk
> compiler (that would be in-memory compiling and linking, not on disk)
> for I86 code.
>
> It doesn't look like the api calls are listed anywhere and distinguished
> from internal routines.
>
> I would appreciate a thumb nail scetch of what steps it would take to
> initialize the system, assemble an in-memory file, clean up and get
> ready to do the same again...
Josh,
There's two main references at the moment:
- <http://www.tortall.net/projects/yasm/reference/design.pdf> tries to
give a high-level view of the assembly process in yasm.. about as close as
we currently come to a "thumbnail sketch". It's definitely a WIP at the
moment, however.
- <http://www.tortall.net/projects/yasm/reference/> has links to HTML and
PDF versions of the full libyasm reference. All the functions documented
in this are the "public" api.
The other file to look at would be the frontends/yasm/yasm.c source code.
This is the main assembly driver and uses entirely libyasm functions.
The main difficulty you're going to run into is that the object formats
all expect to output into FILE *'s (yasm_objfmt_output takes a FILE *).
Doing it completely in-memory is going to be difficult to do portably
given this fact with the included object formats, but you could write a
custom objfmt to do this (and probably want to anyway, as you'll probably
want to have a custom objfmt that's easy for you to link).
Likewise, the included preprocs expect file input, but you should probably
bypass the parser/preproc anyway if you're generating output from a
tightly-coupled compiler: just call the libyasm functions directly to
create sections and bytecodes (bytecode.h functions for general bytecodes
and arch.h functions for x86 instructions).
Peter
More information about the yasm-devel
mailing list