<p>
        Hi, there.
</p>
<p>
        <br>
</p>
<p>
        I am working on a project about control flow checking. For some reasons, I have to instrument native assembly code.
</p>
<p>
        <br>
</p>
<p>
        I have read about the MC layer of LLVM. I'm trying to use it for native assembly instrumentation, but have not found a way to do so. From the source code of the llvm-mc tool, I can see the source file is opened and added to the SourceMgr, which is in turn used to construct a MCContext object. At the end, I can see an AsmParser is constructed. However, it seems all work is actually done when the AsmParser is run. This appears to be very different from what I had in mind.
</p>
<p>
        <br>
</p>
<p>
        What I would like to do is:
</p>
<p>
        1. Parse a native assembly file into a MCContext, populating all internal data structures such as MCSection, MCFragment, MCInst, etc.
</p>
<p>
        2. Manipulate the data structures, adding instructions at points indicated by some labels.
</p>
<p>
        3. Write out the instrumented native assembly code to a text file.
</p>
<p>
        <br>
</p>
<p>
        Could you please tell me if the MC layer is a suitable tool for my work? If it is, would you give me some hints about how to use it?
</p>
<p>
        <br>
</p>
<p>
        Thank you!
</p>