com
This commit is contained in:
commit
99a65d8e0c
43
Makefile
Normal file
43
Makefile
Normal file
|
@ -0,0 +1,43 @@
|
|||
CC = gcc
|
||||
|
||||
CFLAGS = -g
|
||||
LDFLAGS = -g
|
||||
LDLIBS = -ltcc
|
||||
INCLUDE_PATHS = -Iinclude
|
||||
|
||||
SRC_DIR = src
|
||||
OBJ_DIR = obj
|
||||
BIN_DIR = bin
|
||||
|
||||
|
||||
|
||||
EXE = $(BIN_DIR)/main
|
||||
|
||||
C_SRC := $(wildcard $(SRC_DIR)/*.c) #GET LIST OF ALL C FILES
|
||||
|
||||
#SRC := $(C_SRC) $(CPP_SCR)
|
||||
|
||||
|
||||
C_OBJ := $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(C_SRC)) #MAKE LIST OF ALL C OBJECT FILES THAT NEED TO BE BUILT
|
||||
|
||||
OBJ := $(C_OBJ)
|
||||
|
||||
|
||||
all: $(EXE)
|
||||
|
||||
$(EXE): $(OBJ) | $(BIN_DIR)
|
||||
$(CC) $(INCLUDE_PATHS) $(LDFLAGS) $^ $(LDLIBS) -o $@
|
||||
|
||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
|
||||
$(CC) $(INCLUDE_PATHS) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
||||
|
||||
|
||||
$(BIN_DIR) $(OBJ_DIR):
|
||||
mkdir -p $@
|
||||
|
||||
|
||||
clean:
|
||||
@$(RM) -rv $(BIN_DIR) $(OBJ_DIR)
|
||||
|
||||
.PHONY: all clean
|
||||
|
16
compile_commands.json
Normal file
16
compile_commands.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
[
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/gcc",
|
||||
"-g",
|
||||
"-Iinclude",
|
||||
"-c",
|
||||
"-o",
|
||||
"obj/main.o",
|
||||
"src/main.c"
|
||||
],
|
||||
"directory": "/home/inventorx/raytcc",
|
||||
"file": "/home/inventorx/raytcc/src/main.c",
|
||||
"output": "/home/inventorx/raytcc/obj/main.o"
|
||||
}
|
||||
]
|
30899
include/nuklear.h
Normal file
30899
include/nuklear.h
Normal file
File diff suppressed because it is too large
Load diff
5721
include/raygui.h
Normal file
5721
include/raygui.h
Normal file
File diff suppressed because it is too large
Load diff
2607
include/raylib-nuklear-font.h
Normal file
2607
include/raylib-nuklear-font.h
Normal file
File diff suppressed because it is too large
Load diff
1073
include/raylib-nuklear.h
Normal file
1073
include/raylib-nuklear.h
Normal file
File diff suppressed because it is too large
Load diff
99
src/main.c
Normal file
99
src/main.c
Normal file
|
@ -0,0 +1,99 @@
|
|||
#include <libtcc.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
void handle_error(void *opaque, const char *msg)
|
||||
{
|
||||
fprintf(opaque, "%s\n", msg);
|
||||
}
|
||||
|
||||
typedef char * (*codefn)();
|
||||
|
||||
TCCState * init_tcc() {
|
||||
TCCState *s;
|
||||
|
||||
s = tcc_new();
|
||||
if (!s) {
|
||||
printf("Tcc init err\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
tcc_set_error_func(s, stderr, handle_error);
|
||||
tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc <= 1) {
|
||||
printf("cpointerc: missing argument\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
FILE * file = fopen(argv[1], "r");
|
||||
if (file == NULL) {
|
||||
printf("%s:%s\n", argv[1], strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
|
||||
long fsize = ftell(file);
|
||||
|
||||
rewind(file);
|
||||
|
||||
char * layer1 = calloc(sizeof(char), fsize);
|
||||
|
||||
fread(layer1, sizeof(char), fsize, file);
|
||||
|
||||
fclose(file);
|
||||
|
||||
int i;
|
||||
|
||||
TCCState * s = init_tcc();
|
||||
|
||||
if (tcc_compile_string(s, layer1) == -1)
|
||||
return 1;
|
||||
|
||||
/* tcc_add_symbol(s, "add", add); */
|
||||
/* tcc_add_symbol(s, "hello", hello); */
|
||||
if (tcc_relocate(s) < 0)
|
||||
return 1;
|
||||
|
||||
/* get entry symbol */
|
||||
codefn layer1_entry = tcc_get_symbol(s, "entry");
|
||||
|
||||
if (!layer1_entry)
|
||||
return 1;
|
||||
|
||||
//printf("calling stage 1\n");
|
||||
char * mem = layer1_entry();
|
||||
|
||||
//printf("done stage 1\n");
|
||||
tcc_delete(s);
|
||||
s = init_tcc();
|
||||
|
||||
|
||||
//printf("compiling: \n%s\n", mem);
|
||||
if(tcc_compile_string(s, mem) == -1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (tcc_relocate(s) < 0) {
|
||||
return 1;
|
||||
}
|
||||
int (*newmn)() = tcc_get_symbol(s, "newmain");
|
||||
if (newmn == NULL) {
|
||||
printf("newmain err\n");
|
||||
return 1;
|
||||
}
|
||||
newmn();
|
||||
/* delete the state */
|
||||
tcc_delete(s);
|
||||
|
||||
return 0;
|
||||
}
|
9
test1.c
Normal file
9
test1.c
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char * entry(void) {
|
||||
char * out = calloc(sizeof(char), 500);
|
||||
strcpy(out, "#include <stdio.h>\n int newmain(void) { printf(\"Hello, World\\n\"); return 0; }");
|
||||
return out;
|
||||
}
|
28
test2.c
Normal file
28
test2.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
char * entry(void) {
|
||||
char * out = calloc(sizeof(char), 1780074);
|
||||
|
||||
short i = SHRT_MIN;
|
||||
size_t pos = 0;
|
||||
|
||||
pos += sprintf(&out[0], "#include<stdio.h>\n #include<stdbool.h>\n bool is_even(short i) { ");
|
||||
|
||||
do {
|
||||
pos += sprintf(&out[pos], "if (i == %d) {return %d;}", i, i % 2 == 0);
|
||||
//printf("%d\n", i);
|
||||
i++;
|
||||
} while (i != SHRT_MAX);
|
||||
|
||||
pos += sprintf(&out[pos], "return 0;\n");
|
||||
pos += sprintf(&out[pos], "}\n");
|
||||
|
||||
sprintf(&out[pos],"int newmain(void) { if (is_even(7)) {printf(\"even\\n\");} else {printf(\"odd\\n\");} return 0;}");
|
||||
//printf("%zu\n", pos);
|
||||
//strcpy(out, "#include <stdio.h>\n int newmain(void) { printf(\"Hello, World\\n\"); return 0; }");
|
||||
return out;
|
||||
}
|
Loading…
Reference in a new issue