1 /*********************************************************************
3 Gazelle: a system for building fast, reusable grammars
7 This is a very simple utility for dumping a Bitcode file literally,
8 without any recognition or processing of any of the data. It could
9 be extended to dump only selected parts, or to dump it in other,
12 Copyright (c) 2007 Joshua Haberman. See LICENSE for details.
14 *********************************************************************/
16 #include "bc_read_stream.h"
21 void check_error(struct bc_read_stream
*s
)
23 if(bc_rs_get_error(s
))
25 int err
= bc_rs_get_error(s
);
26 fprintf(stderr
, "There were stream errors!\n");
27 if(err
& BITCODE_ERR_VALUE_TOO_LARGE
)
28 fprintf(stderr
, " Value too large.\n");
29 if(err
& BITCODE_ERR_NO_SUCH_VALUE
)
30 fprintf(stderr
, " No such value.\n");
31 if(err
& BITCODE_ERR_IO
)
32 fprintf(stderr
, " IO error.\n");
33 if(err
& BITCODE_ERR_CORRUPT_INPUT
)
34 fprintf(stderr
, " Corrupt input.\n");
35 if(err
& BITCODE_ERR_INTERNAL
)
36 fprintf(stderr
, " Internal error.\n");
42 printf("bitcode_dump: dumps all of the records in a bitcode file\n");
43 printf("Usage: bitcode_dump <bitcode file>\n");
46 int main(int argc
, char *argv
[0])
50 if(argc
< 2 || strcmp(argv
[1], "--help") == 0)
56 struct bc_read_stream
*s
= bc_rs_open_file(argv
[1]);
59 printf("Failed to open bitcode file %s\n", argv
[1]);
65 struct record_info ri
= bc_rs_next_data_record(s
);
66 if(ri
.record_type
== DataRecord
)
68 for(int i
= 0; i
< nesting
; i
++)
71 printf("%u: ", ri
.id
);
72 for(int i
= 0; i
< bc_rs_get_record_size(s
); i
++)
73 printf("%llu ", bc_rs_read_64(s
, i
));
76 else if(ri
.record_type
== StartBlock
)
78 for(int i
= 0; i
< nesting
; i
++)
80 printf("-- (id=%u)\n", ri
.id
);
83 else if(ri
.record_type
== EndBlock
)
87 else if(ri
.record_type
== Eof
)
89 bc_rs_close_stream(s
);
92 else if(ri
.record_type
== Err
)
94 fprintf(stderr
, "Hit an error. :(\n");
104 * c-file-style: "bsd"
106 * indent-tabs-mode: nil