83 static void usage(
void);
97 int main(
int argc,
char *argv[])
107 program = strrchr(argv[0],
'/');
114 while ((opt =
getopt(argc, argv,
"cfnh")) != EOF) {
125 print_function_names =
WS_TRUE;
134 printf(
"Try `%s -h' for a complete list of options.\n",
140 for (i =
optind; i < argc; i++) {
147 if (stat(argv[i], &stat_st) < 0) {
148 fprintf(stderr,
"%s: could not access `%s': %s\n",
149 program, argv[i], strerror(errno));
152 data_len = stat_st.st_size;
156 fprintf(stderr,
"%s: out of memory: %s\n",
161 fp = fopen(argv[i],
"rb");
163 fprintf(stderr,
"%s: could not open input file `%s': %s\n",
164 program, argv[i], strerror(errno));
168 if (fread(data, 1, data_len, fp) != data_len) {
169 fprintf(stderr,
"%s: could not read file `%s': %s\n",
170 program, argv[i], strerror(errno));
178 fprintf(stderr,
"%s: invalid byte-code file `%s'\n",
184 printf(
"\n%s:\t%lu bytes\n\n", argv[i], (
unsigned long) data_len);
186 if (print_constants) {
187 printf(
"Disassembly of section Constants:\n\n");
204 printf(
"+infinity\n");
208 printf(
"-infinity\n");
222 printf(
"\\%02lx", ch);
224 }
else if (ch <= 0xff) {
225 printf(
"%c", (
unsigned char) ch);
228 printf(
"\\u%04lx", ch);
247 if (print_function_names) {
248 printf(
"Disassembly of section Function names:\n\n");
250 printf(
" %-40.40s%8d\n",
255 if (print_functions) {
258 printf(
"Disassembly of section Functions:\n");
263 printf(
"\nFunction %u", (
unsigned int) k);
266 printf(
" <%s>",
name);
277 if (!print_constants && !print_function_names && !print_functions) {
282 Function names\t%8d\n\ 300 printf(
"Usage: %s OPTION... FILE...\n\ 302 -c print constants\n\ 303 -f disassemble functions\n\ 304 -n print function names\n\ 305 -h print this help message and exit successfully\n\
WsCompilerPtr ws_create(WsCompilerParams *params)
WsBcFunctionName * function_names
int getopt(int argc, char **argv, char *opts)
WsUInt8 num_function_names
void ws_destroy(WsCompilerPtr compiler)
void ws_bc_free(WsBc *bc)
int main(int argc, char *argv[])
void ws_asm_dasm(WsCompilerPtr compiler, const unsigned char *code, size_t len)
int ws_utf8_get_char(const WsUtf8String *string, unsigned long *ch_return, size_t *posp)
union WsBcConstantRec::@116 u
const char * lookup_function(WsBc *bc, WsUInt8 index)
void * ws_malloc(size_t size)
WsBc * ws_bc_decode(const unsigned char *data, size_t data_len)