Commit c7b87cd2 authored by Johann's avatar Johann Committed by Gerrit Code Review
Browse files

Merge "Ouput symbols as c header file."

parents 1c96e398 6f00a46d
...@@ -21,6 +21,7 @@ typedef enum { ...@@ -21,6 +21,7 @@ typedef enum {
OUTPUT_FMT_PLAIN, OUTPUT_FMT_PLAIN,
OUTPUT_FMT_RVDS, OUTPUT_FMT_RVDS,
OUTPUT_FMT_GAS, OUTPUT_FMT_GAS,
OUTPUT_FMT_C_HEADER,
} output_fmt_t; } output_fmt_t;
int log_msg(const char *fmt, ...) { int log_msg(const char *fmt, ...) {
...@@ -46,6 +47,9 @@ int print_macho_equ(output_fmt_t mode, uint8_t* name, int val) { ...@@ -46,6 +47,9 @@ int print_macho_equ(output_fmt_t mode, uint8_t* name, int val) {
case OUTPUT_FMT_GAS: case OUTPUT_FMT_GAS:
printf(".set %-40s, %5d\n", name, val); printf(".set %-40s, %5d\n", name, val);
return 0; return 0;
case OUTPUT_C_HEADER:
printf("#define %-40s %5d\n", name, val);
return 0;
default: default:
log_msg("Unsupported mode: %d", mode); log_msg("Unsupported mode: %d", mode);
return 1; return 1;
...@@ -491,6 +495,13 @@ int parse_elf(uint8_t *buf, size_t sz, output_fmt_t mode) { ...@@ -491,6 +495,13 @@ int parse_elf(uint8_t *buf, size_t sz, output_fmt_t mode) {
sym.st_name), sym.st_name),
val); val);
break; break;
case OUTPUT_FMT_C_HEADER:
printf("#define %-40s %5d\n",
parse_elf_string_table(&elf,
shdr.sh_link,
sym.st_name),
val);
break;
default: default:
printf("%s = %d\n", printf("%s = %d\n",
parse_elf_string_table(&elf, parse_elf_string_table(&elf,
...@@ -762,6 +773,7 @@ int main(int argc, char **argv) { ...@@ -762,6 +773,7 @@ int main(int argc, char **argv) {
fprintf(stderr, "Output Formats:\n"); fprintf(stderr, "Output Formats:\n");
fprintf(stderr, " gas - compatible with GNU assembler\n"); fprintf(stderr, " gas - compatible with GNU assembler\n");
fprintf(stderr, " rvds - compatible with armasm\n"); fprintf(stderr, " rvds - compatible with armasm\n");
fprintf(stderr, " cheader - c/c++ header file\n");
goto bail; goto bail;
} }
...@@ -771,6 +783,8 @@ int main(int argc, char **argv) { ...@@ -771,6 +783,8 @@ int main(int argc, char **argv) {
mode = OUTPUT_FMT_RVDS; mode = OUTPUT_FMT_RVDS;
else if (!strcmp(argv[1], "gas")) else if (!strcmp(argv[1], "gas"))
mode = OUTPUT_FMT_GAS; mode = OUTPUT_FMT_GAS;
else if (!strcmp(argv[1], "cheader"))
mode = OUTPUT_FMT_C_HEADER;
else else
f = argv[1]; f = argv[1];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment