compiler_x86.c 754 B

123456789101112131415161718192021222324252627282930313233343536
  1. Cell* execute_jitted(void* binary) {
  2. return (Cell*)((funcptr)binary)(0);
  3. }
  4. void memdump(void* start,uint32_t len,int raw);
  5. int compile_for_platform(Cell* expr, Cell** res) {
  6. int codesz = 8192;
  7. code = malloc(codesz);
  8. memset(code, 0, codesz);
  9. jit_init();
  10. register void* sp asm ("sp");
  11. Frame empty_frame = {NULL, 0, 0, sp};
  12. int success = compile_expr(expr, &empty_frame, TAG_ANY);
  13. jit_ret();
  14. if (success) {
  15. printf("<assembled at: %p>\r\n",code);
  16. memdump(code,64,0);
  17. /*if (bytes_read>codesz) {
  18. printf("<error: max assembly size of %d exhausted. aborting>\n",codesz);
  19. return 0;
  20. }*/
  21. *res = execute_jitted(code);
  22. printf("res: %p\r\n",res);
  23. success = 1;
  24. }
  25. return success;
  26. }