Do not compile tinycc more than twice.

parent 26c097f0
Pipeline #59278142 passed with stages
in 30 minutes and 57 seconds
......@@ -28,9 +28,11 @@ int recursively_compile() {
const char *files[1];
#if LEVEL == 1 && defined(RUN_IPXE)
#define ADD_TCC_SYMBOLS
files[0] = ASMC_PREFIX "/run_tcc_ipxe.c";
printf("I will now try to compile and execute tinycc, diverting to iPXE! (level %d)\n", LEVEL);
#elif LEVEL == 1 && defined(RUN_SINGLE_CREAM)
#define ADD_TCC_SYMBOLS
files[0] = ASMC_PREFIX "/run_tcc_sc.c";
printf("I will now try to compile and execute tinycc, diverting to single_cream! (level %d)\n", LEVEL);
#else
......@@ -45,6 +47,28 @@ int recursively_compile() {
sprintf(buf, "%d", LEVEL+1);
tcc_define_symbol(state, "LEVEL", buf);
#ifdef ADD_TCC_SYMBOLS
tcc_add_symbol(state, "tcc_new", tcc_new);
tcc_add_symbol(state, "tcc_delete", tcc_delete);
tcc_add_symbol(state, "tcc_set_lib_path", tcc_set_lib_path);
tcc_add_symbol(state, "tcc_set_error_func", tcc_set_error_func);
tcc_add_symbol(state, "tcc_set_options", tcc_set_options);
tcc_add_symbol(state, "tcc_add_include_path", tcc_add_include_path);
tcc_add_symbol(state, "tcc_add_sysinclude_path", tcc_add_sysinclude_path);
tcc_add_symbol(state, "tcc_define_symbol", tcc_define_symbol);
tcc_add_symbol(state, "tcc_undefine_symbol", tcc_undefine_symbol);
tcc_add_symbol(state, "tcc_add_file", tcc_add_file);
tcc_add_symbol(state, "tcc_compile_string", tcc_compile_string);
tcc_add_symbol(state, "tcc_set_output_type", tcc_set_output_type);
tcc_add_symbol(state, "tcc_add_library_path", tcc_add_library_path);
tcc_add_symbol(state, "tcc_add_library", tcc_add_library);
tcc_add_symbol(state, "tcc_add_symbol", tcc_add_symbol);
tcc_add_symbol(state, "tcc_output_file", tcc_output_file);
tcc_add_symbol(state, "tcc_run", tcc_run);
tcc_add_symbol(state, "tcc_relocate", tcc_relocate);
tcc_add_symbol(state, "tcc_get_symbol", tcc_get_symbol);
#endif
if (run_tinycc(state, sizeof(files) / sizeof(files[0]), files,
sizeof(includes) / sizeof(includes[0]), includes)) {
"tinycc invocation failed...\n";
......
#include "run_tcc.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -8,6 +6,8 @@
#include "coros.h"
#define TCC_TARGET_I386 1
#define __i386__ 1
#define USE_SOFTFLOAT 1
#define ONE_SOURCE 1
#include "tcc.h"
......@@ -18,6 +18,7 @@
#undef realloc
#undef strdup
#define ASMC_PREFIX "/disk1"
#define IPXE_PREFIX ASMC_PREFIX "/ipxe/src"
#define IPXE_TEMP "/ram/ipxe"
......@@ -252,6 +253,16 @@ void *pop_from_ipxe() {
return ipxe_list_pop(&ih, &ih.from_ipxe);
}
coro_t *coro_ipxe;
downloaded_file *download_file(const char *url) {
push_to_ipxe(strdup("download"));
push_to_ipxe(strdup(url));
coro_enter(coro_ipxe);
downloaded_file *df = pop_from_ipxe();
return df;
}
int main(int argc, char *argv[]) {
printf("Here is where we compile iPXE!\n");
......@@ -310,6 +321,8 @@ int main(int argc, char *argv[]) {
return 1;
}
printf(" done!\n");
// Start iPXE in a dedicated coroutine
void (*main_symb)(void*) = tcc_get_symbol(state, "pre_main");
if (!main_symb) {
printf("tcc_get_symbol() failed...\n");
......@@ -323,15 +336,13 @@ int main(int argc, char *argv[]) {
ih.free = free;
printf("Starting iPXE coroutine!\n");
coro_t *coro_ipxe = coro_init(main_symb, &ih);
coro_ipxe = coro_init(main_symb, &ih);
coro_enter(coro_ipxe);
// Download the continuation program
const char *url = "http://10.0.2.2:8080/continue.c";
printf("Request to download %s\n", url);
push_to_ipxe(strdup("download"));
push_to_ipxe(strdup(url));
coro_enter(coro_ipxe);
downloaded_file *df = pop_from_ipxe();
downloaded_file *df = download_file(url);
assert(df->size > 0);
printf("Received document of %d bytes!\n", df->size);
printf("---\n");
......@@ -355,5 +366,3 @@ int main(int argc, char *argv[]) {
return res;
}
#include "libtcc.c"
......@@ -6,6 +6,8 @@
#include <string.h>
#include <assert.h>
#define TCC_TARGET_I386 1
#define __i386__ 1
#define USE_SOFTFLOAT 1
#define ONE_SOURCE 1
#include "tcc.h"
......@@ -16,6 +18,7 @@
#undef realloc
#undef strdup
#define ASMC_PREFIX "/disk1"
#define SC_PREFIX ASMC_PREFIX "/sc/src"
#define SC_TEMP "/ram/sc"
......@@ -105,5 +108,3 @@ int main(int argc, char *argv[]) {
return res;
}
#include "libtcc.c"
#include <stdio.h>
int main() {
return 0;
printf("Hello, continuing world!\n");
return 0;
}
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