代码拉取完成,页面将自动刷新
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "image.h"
#include "vm.h"
#include "gc.h"
char* read_until_eof(FILE* f, uint32_t* len)
{
size_t cap = 4096;
size_t idx = 0;
char* buff = js_alloc(cap);
while(!feof(stdin)) {
idx += fread(buff + idx, 1, 4096, f);
if(idx >= cap) {
cap *= 2;
buff = js_realloc(buff, cap);
}
}
*len = idx;
return buff;
}
int main()
{
uint32_t dummy;
uint32_t len;
char* buff;
js_image_t* image;
uint32_t i, j, op;
double number;
js_gc_init(&dummy);
buff = read_until_eof(stdin, &len);
image = js_image_parse(buff, len);
printf("read %d sections\n", image->section_count);
for(i = 0; i < image->section_count; i++) {
printf("\nsection %d (flags %d, var count: %d):\n", i, image->sections[i].flags, image->sections[i].var_count);
for(j = 0; j < image->sections[i].instruction_count; j++) {
op = image->sections[i].instructions[j];
printf(" %04d %-12s", j, js_instruction(op)->name);
switch(js_instruction(op)->operand) {
case OPERAND_NONE:
printf("\n");
break;
case OPERAND_NUMBER:
number = *(double*)&image->sections[i].instructions[++j];
printf("%lf\n", number);
j++;
break;
case OPERAND_UINT32:
op = image->sections[i].instructions[++j];
printf("%u\n", op);
break;
case OPERAND_UINT32_UINT32:
op = image->sections[i].instructions[++j];
printf("%u, ", op);
op = image->sections[i].instructions[++j];
printf("%u\n", op);
break;
case OPERAND_STRING:
op = image->sections[i].instructions[++j];
printf("\"%s\" (%d)\n", image->strings[op]->buff, op);
break;
case OPERAND_UINT32_STRING:
op = image->sections[i].instructions[++j];
printf("%u, ", op);
op = image->sections[i].instructions[++j];
printf("\"%s\" (%d)\n", image->strings[op]->buff, op);
break;
}
}
}
printf("\nstrings:\n");
for(i = 0; i < image->string_count; i++) {
printf(" %04d \"%s\"\n", i, image->strings[i]->buff);
}
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。