Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ab25cq committed Nov 15, 2018
1 parent dacc3ce commit b54a004
Show file tree
Hide file tree
Showing 13 changed files with 1,975 additions and 3,566 deletions.
273 changes: 125 additions & 148 deletions Makefile.in

Large diffs are not rendered by default.

5,080 changes: 1,726 additions & 3,354 deletions configure

Large diffs are not rendered by default.

27 changes: 16 additions & 11 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,12 @@ CLASS_NAME=${1%.*}
echo "bitcompile $CLASS_NAME"
if test ! -e $CLASS_NAME.s || test $CLASS_NAME.bc -nt $CLASS_NAME.s
then
if test -e ./cclover2; then ./cclover2 -jit $CLASS_NAME.oclcl; else cclover2 -jit $CLASS_NAME.oclcl; fi
/usr/bin/llvm-dis-6.0 $CLASS_NAME.bc
/usr/bin/llc-6.0 -relocation-model=pic $CLASS_NAME.bc
/usr/bin/clang -o $CLASS_NAME.o -c $CLASS_NAME.s
/usr/bin/gcc -shared -Wl,-soname=lib$CLASS_NAME.so.1 -o lib$CLASS_NAME.so.1.0.0 $CLASS_NAME.o
ln -fs lib$CLASS_NAME.so.1.0.0 lib$CLASS_NAME.so
/usr/bin/gcc -shared -Wl,-soname=$CLASS_NAME.so.1 -o $CLASS_NAME.so.1.0.0 $CLASS_NAME.o
ln -fs $CLASS_NAME.so.1.0.0 $CLASS_NAME.so
fi
EOF
chmod 755 bclover2
Expand All @@ -338,11 +339,12 @@ CLASS_NAME=${1%.*}
echo "bitcompile $CLASS_NAME"
if test ! -e $CLASS_NAME.s || test $CLASS_NAME.bc -nt $CLASS_NAME.s
then
if test -e ./cclover2; then ./cclover2 -jit $CLASS_NAME.oclcl; else cclover2 -jit $CLASS_NAME.oclcl; fi
/usr/bin/llvm-dis-5.0 $CLASS_NAME.bc
/usr/bin/llc-5.0 -relocation-model=pic $CLASS_NAME.bc
/usr/bin/clang -o $CLASS_NAME.o -c $CLASS_NAME.s
/usr/bin/gcc -shared -Wl,-soname=lib$CLASS_NAME.so.1 -o lib$CLASS_NAME.so.1.0.0 $CLASS_NAME.o
ln -fs lib$CLASS_NAME.so.1.0.0 lib$CLASS_NAME.so
/usr/bin/gcc -shared -Wl,-soname=$CLASS_NAME.so.1 -o $CLASS_NAME.so.1.0.0 $CLASS_NAME.o
ln -fs $CLASS_NAME.so.1.0.0 $CLASS_NAME.so
fi
EOF
chmod 755 bclover2
Expand All @@ -362,11 +364,12 @@ CLASS_NAME=${1%.*}
echo "bitcompile $CLASS_NAME"
if test ! -e $CLASS_NAME.s || test $CLASS_NAME.bc -nt $CLASS_NAME.s
then
if test -e ./cclover2; then ./cclover2 -jit $CLASS_NAME.oclcl; else cclover2 -jit $CLASS_NAME.oclcl; fi
/usr/bin/llvm-dis-4.0 $CLASS_NAME.bc
/usr/bin/llc-4.0 -relocation-model=pic $CLASS_NAME.bc
/usr/bin/clang -o $CLASS_NAME.o -c $CLASS_NAME.s
/usr/bin/gcc -shared -Wl,-soname=lib$CLASS_NAME.so.1 -o lib$CLASS_NAME.so.1.0.0 $CLASS_NAME.o
ln -fs lib$CLASS_NAME.so.1.0.0 lib$CLASS_NAME.so
/usr/bin/gcc -shared -Wl,-soname=CLASS_NAME.so.1 -o $CLASS_NAME.so.1.0.0 $CLASS_NAME.o
ln -fs $CLASS_NAME.so.1.0.0 $CLASS_NAME.so
fi
EOF

Expand All @@ -387,17 +390,17 @@ CLASS_NAME=${1%.*}
echo "bitcompile $CLASS_NAME"
if test ! -e $CLASS_NAME.s || test $CLASS_NAME.bc -nt $CLASS_NAME.s
then
if test -e ./cclover2; then ./cclover2 -jit $CLASS_NAME.oclcl; else cclover2 -jit $CLASS_NAME.oclcl; fi
/usr/bin/llvm-dis-3.8 $CLASS_NAME.bc
/usr/bin/llc-3.8 -relocation-model=pic $CLASS_NAME.bc
/usr/bin/clang -o $CLASS_NAME.o -c $CLASS_NAME.s
/usr/bin/gcc -shared -Wl,-soname=lib$CLASS_NAME.so.1 -o lib$CLASS_NAME.so.1.0.0 $CLASS_NAME.o
ln -fs lib$CLASS_NAME.so.1.0.0 lib$CLASS_NAME.so
/usr/bin/gcc -shared -Wl,-soname=CLASS_NAME.so.1 -o $CLASS_NAME.so.1.0.0 $CLASS_NAME.o
ln -fs $CLASS_NAME.so.1.0.0 $CLASS_NAME.so
fi
EOF
chmod 755 bclover2

else
chmod 755 bclover2
if test $DEBUGGING = 1
then
CXXFLAGS='`llvm-config --cxxflags --ldflags --system-libs --libs all` -lffi -DMDEBUG -g'" $CXXFLAGS"
Expand All @@ -411,12 +414,14 @@ CLASS_NAME=${1%.*}
echo "bitcompile $CLASS_NAME"
if test ! -e $CLASS_NAME.s || test $CLASS_NAME.bc -nt $CLASS_NAME.s
then
if test -e ./cclover2; then ./cclover2 -jit $CLASS_NAME.oclcl; else cclover2 -jit $CLASS_NAME.oclcl; fi
/usr/bin/llvm-dis $CLASS_NAME.bc
/usr/bin/llc -relocation-model=pic $CLASS_NAME.bc
/usr/bin/clang -o $CLASS_NAME.o -c $CLASS_NAME.s
/usr/bin/gcc -shared -Wl,-soname=lib$CLASS_NAME.so.1 -o lib$CLASS_NAME.so.1.0.0 $CLASS_NAME.o
ln -fs lib$CLASS_NAME.so.1.0.0 lib$CLASS_NAME.so
/usr/bin/gcc -shared -Wl,-soname=$CLASS_NAME.so.1 -o $CLASS_NAME.so.1.0.0 $CLASS_NAME.o
ln -fs CLASS_NAME.so.1.0.0 $CLASS_NAME.so
fi
chmod 755 bclover2
EOF

fi
Expand Down
2 changes: 1 addition & 1 deletion src/cast.c
Original file line number Diff line number Diff line change
Expand Up @@ -3023,4 +3023,4 @@ void cast_right_type_to_left_type(sNodeType* left_type, sNodeType** right_type,
boxing_to_lapper_class(right_type, info);
}
}
}
}
1 change: 1 addition & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -2484,6 +2484,7 @@ BOOL compile_jit_method(sCLClass* klass, sCLMethod* method);
void jit_init_on_runtime();
void jit_final_on_runtime();
BOOL load_bc_file(sCLClass* klass);
BOOL jit_compile_class(sCLClass* klass);
#endif

/// class_parser.c ///
Expand Down
52 changes: 43 additions & 9 deletions src/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ static BOOL compiler(char* fname)
return TRUE;
}

#ifdef ENABLE_JIT
static BOOL jit_class_compiler(char* class_name)
{
sCLClass* klass = get_class_with_load(class_name);
if(!jit_compile_class(klass)) {
fprintf(stderr, "faield in jit compile\n");
return FALSE;
}

return TRUE;
}
#endif

static BOOL class_compiler(char* fname)
{
Expand Down Expand Up @@ -125,15 +137,6 @@ static BOOL class_compiler(char* fname)

write_all_modified_modules();

#ifdef ENABLE_JIT
if(!jit_compile_all_classes()) {
fprintf(stderr, "faield in jit compile\n");
MFREE(source.mBuf);
MFREE(source2.mBuf);
return FALSE;
}
#endif

MFREE(source.mBuf);
MFREE(source2.mBuf);

Expand Down Expand Up @@ -163,6 +166,7 @@ int main(int argc, char** argv)
BOOL clcl_compile = FALSE;
char sname[PATH_MAX];
xstrncpy(sname, "", PATH_MAX);
BOOL jit_compile = FALSE;

for(i=1; i<argc; i++) {
if(strcmp(argv[i], "-no-load-fundamental-classes") == 0) {
Expand All @@ -175,6 +179,9 @@ int main(int argc, char** argv)
else if(strcmp(argv[i], "-class") == 0) {
clcl_compile = TRUE;
}
else if(strcmp(argv[i], "-jit") == 0) {
jit_compile = TRUE;
}
else if(strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "-V") == 0)
{
printf("clover2 version %s\n", gVersion);
Expand Down Expand Up @@ -217,6 +224,33 @@ int main(int argc, char** argv)
return 1;
}
}
#ifdef ENABLE_JIT
else if(jit_compile) {
char* p = sname + strlen(sname);

while(p >= sname) {
if(*p == '.') {
break;
}
else {
p--;
}
}

if(p != sname) {
*p = '\0';
}

printf("sname %s\n", sname);

if(!jit_class_compiler(sname)) {
fprintf(stderr, "cclover2 can't compile %s\n", argv[i]);
clover2_final();
compiler_final();
return 1;
}
}
#endif
else {
if(!compiler(sname)) {
fprintf(stderr, "cclover2 can't compile %s\n", argv[i]);
Expand Down
14 changes: 7 additions & 7 deletions src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ static int mgetmaxx()
{
struct winsize ws;
ioctl(1, TIOCGWINSZ, &ws);

return ws.ws_col;
}

static int mgetmaxy()
{
struct winsize ws;
ioctl(1, TIOCGWINSZ, &ws);

return ws.ws_row;
}

Expand All @@ -45,11 +45,11 @@ void display_candidates(char** candidates)
int maxx;
int cols;
int n;

p = candidates;

max_len = -1;

while((candidate = *p) != NULL) {
int len;

Expand All @@ -68,7 +68,7 @@ void display_candidates(char** candidates)
if(cols == 0) {
cols = 1;
}

n = 0;

puts("");
Expand Down Expand Up @@ -2479,4 +2479,4 @@ int main(int argc, char** argv)
CHECKML_END;

exit(0);
}
}
6 changes: 5 additions & 1 deletion src/jit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ BOOL compile_to_native_code(sByteCode* code, sConst* constant, sCLClass* klass,
unsigned int inst = *(unsigned int*)pc;
pc+=sizeof(int);

show_inst_in_jit(inst);

/*
if(inst != OP_HEAD_OF_EXPRESSION && inst != OP_SIGINT) {
call_show_inst_in_jit(inst);
Expand Down Expand Up @@ -270,14 +272,16 @@ call_show_inst_in_jit(inst);

case OP_GOTO: {
//int jump_value = *(int*)pc;
pc += sizeof(int);
//pc += sizeof(int);

int label_offset = *(int*)pc;
pc += sizeof(int);

char* label_name = CONS_str(constant, label_offset);
std::string label_name_string(label_name);

printf("label_name %s\n", label_name);

BasicBlock* label = TheLabels[label_name_string];
if(label == nullptr) {
label = BasicBlock::Create(TheContext, label_name, function);
Expand Down
1 change: 0 additions & 1 deletion src/jit_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ struct sPointerAndBoolResult {
char* result1;
BOOL result2;
};
BOOL jit_compile_all_classes();

extern LLVMContext TheContext;
extern IRBuilder<> Builder;
Expand Down
19 changes: 7 additions & 12 deletions src/jit_compile_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern "C"

static BOOL compile_jit_methods(sCLClass* klass)
{
printf("klass %s\n", CLASS_NAME(klass));
char module_name[PATH_MAX + 128];
snprintf(module_name, PATH_MAX, "Module %s", CLASS_NAME(klass));
TheModule = new Module(module_name, TheContext);
Expand Down Expand Up @@ -52,6 +53,8 @@ static BOOL compile_jit_methods(sCLClass* klass)
char method_path2[METHOD_NAME_MAX + 128];
create_method_path_for_jit(klass, method, method_path2, METHOD_NAME_MAX + 128);

printf("(%s)\n", method_path2);

sByteCode* code = &method->mByteCodes;
sConst* constant = &klass->mConst;

Expand Down Expand Up @@ -128,21 +131,13 @@ static BOOL compile_jit_methods(sCLClass* klass)
return TRUE;
}

BOOL jit_compile_all_classes()
BOOL jit_compile_class(sCLClass* klass)
{
jit_init();

sClassTable* p = gHeadClassTable;

while(p) {
sCLClass* klass = p->mItem;
if(klass->mFlags & CLASS_FLAGS_MODIFIED) {
if(!compile_jit_methods(klass)) {
jit_final();
return FALSE;
}
}
p = p->mNextClass;
if(!compile_jit_methods(klass)) {
jit_final();
return FALSE;
}

jit_final();
Expand Down
Loading

0 comments on commit b54a004

Please sign in to comment.