Extending Backends in LLVM-based projects

Hello everybody,

I'd like to know if there is way to extend an LLVM-backend outside the
LLVM-tree. I am working on a transformation system between time- and
event-triggered real-time systems and at some point I need to do a
WCET analysis. Herefore, I extended the AsmPrinter to give me the asm
code for every single basic block. This code then is analyzed by some
external tool and the analysis results are fed back into a high-level
WCET analysis (i.e. generating and solving the linear program).

Currently I just duplicated the backend in my project to provide a
custom asm printer that exactly does what I need. Duplicating code,
however, never is good solution, so I am looking for a better/nicer
one ... unfortunately the headers of the backends are not public,
otherwise it would be rather easy to derive from the asm printer

Any hints are welcome!

Ciao, Fabian