Files
jvm_emulator/test_parser.c
T
2026-03-30 19:20:11 +00:00

29 lines
762 B
C

#include <stdio.h>
#include "classfile.h"
int execute(ClassFile *cf, Method *m, int *args, int argc);
int main(int argc, char *argv[]) {
if (argc < 2) {
fprintf(stderr, "usage: %s <file.class>\n", argv[0]);
return 1;
}
/* step 1 - load the class file */
ClassFile *cf = classfile_load(argv[1]);
if (!cf) return 1;
/* step 2 - find the main method */
Method *m = classfile_find_method(cf, "main", "([Ljava/lang/String;)V");
if (!m) m = classfile_find_method(cf, "startApp", "()V");
if (!m) {
fprintf(stderr, "no main or startApp method found\n");
return 1;
}
/* step 3 - execute it */
execute(cf, m, NULL, 0);
classfile_free(cf);
return 0;
}