not logged in | [Login]
DynASM is a Dynamic Assembler for code generation engines. DynASM has been developed primarily as a tool for LuaJIT, but might be useful for other projects, too.
If you are writing a just-in-time compiler or need to generate code on the fly (e.g. for high-performance graphics or other CPU-intensive computations), DynASM might be just what you are looking for.
DynASM is Copyright © 2005-2013 Mike Pall. DynASM is free software, released under the MIT license.
DynASM is a very well-designed tool that provides a very useful framework for generating dynamic code during program execution. One of DynASM's strengths is that it allows intermixing C and assembly code in the same source file in a natural and free-form manner. Unfortunately, DynASM is rather weak in the documentation department. Figuring out feature use often requires "reverse-engineering" its usage example from the LuaJIT source, which seriously hinders DynASM's accessibility to potential new users.
This wiki entry is here to change that by providing a central repository for the community to help document DynASM's features along with simple example usage.
Initialize and free DynASM state
DASM_FDEF void dasm_init(Dst_DECL, int maxsection);
DASM_FDEF void dasm_free(Dst_DECL);
Setup global array. Must be called before dasm_setup()
DASM_FDEF void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl);
Grow PC label array. Can be called after dasm_setup()
DASM_FDEF void dasm_growpc(Dst_DECL, unsigned int maxpc);
Setup encoder
DASM_FDEF void dasm_setup(Dst_DECL, const void *actionlist);
Feed encoder with actions. Calls are generated by pre-processor
DASM_FDEF void dasm_put(Dst_DECL, int start, ...);
Link sections and return the resulting size
DASM_FDEF int dasm_link(Dst_DECL, size_t *szp);
Encode sections into buffer
DASM_FDEF int dasm_encode(Dst_DECL, void *buffer);
Get PC label offset
DASM_FDEF int dasm_getpclabel(Dst_DECL, unsigned int pc);