# bytecode reader

**URL:** <https://discourse.llvm.org/t/bytecode-reader/10781>\
**Category:** LLVM Dev List Archives\
**Created:** [June 24, 2008, 12:25am UTC](https://discourse.llvm.org/t/bytecode-reader/10781 "2008-06-24T00:25:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Le\_Anh\_Quang1](https://avatars.discourse-cdn.com/v4/letter/l/838e76/32.png) [@Le\_Anh\_Quang1](https://discourse.llvm.org/u/Le_Anh_Quang1)\
**Post date:** [June 24, 2008, 12:25am UTC](https://discourse.llvm.org/t/bytecode-reader/10781/1 "2008-06-24T00:25:20Z")

</div>

Hi,  
I currently write a tool to parse the LLVM bytecode file (.bc file). So I  
have some very basic questions:  
- First, about the Abbreviation ID ( "0"=END\_BLOCK, "1"=ENTER\_SUBBLOCK...):  
how to read these ID from the file stream ? I mean, I don't know, how many  
bit length they are. It doesn't exist on the document.  
- Second, how is the order to read the bytecode ?  
For example 4 bytes after the LLVM IR magic nr.: 21 0C 00 00 It describes  
the MODULE\_BLOCK with its parameters, actually. But I don't know how to  
extract them from those bytes.

I hope that somebody can help me answer these questions.

Thanks and Regards,  
Quang

---

<div class="post-metadata">

**Author:** ![void](https://sea1.discourse-cdn.com/flex021/user_avatar/discourse.llvm.org/void/32/13491_2.png) [@void](https://discourse.llvm.org/u/void)\
**Post date:** [June 24, 2008, 7:08am UTC](https://discourse.llvm.org/t/bytecode-reader/10781/2 "2008-06-24T07:08:44Z")

</div>

Hi Quang,

> I currently write a tool to parse the LLVM bytecode file (.bc file). So I  
> have some very basic questions:

I have to ask: Why are you doing this? There's already a bytecode file reader and writer that's part of LLVM and it's a library, so you can link it into your own app...

> - First, about the Abbreviation ID ( "0"=END\_BLOCK, "1"=ENTER\_SUBBLOCK...):  
> how to read these ID from the file stream ? I mean, I don't know, how many  
> bit length they are. It doesn't exist on the document.  
> - Second, how is the order to read the bytecode ?  
> For example 4 bytes after the LLVM IR magic nr.: 21 0C 00 00 It describes  
> the MODULE\_BLOCK with its parameters, actually. But I don't know how to  
> extract them from those bytes.
> 
> I hope that somebody can help me answer these questions.

The best thing to do, if you're not going to use the LLVM library, is to look at the source code to see what we're doing. Look at the appropriate files (probably .y) in the lib/AsmParser directory.

-bw
