Verified Commit bfc12636 authored by Camil Staps's avatar Camil Staps 🚀

Generate the implementation of instructions (so that we can also generate wasm later on)

parent 8a6d8935
Pipeline #19276 passed with stages
in 11 minutes and 44 seconds
*.s
*.a
*.o
*.obj
*.exe
a.out
*.prj
*.abc
......@@ -15,5 +13,3 @@ a.out
*.bc
*.graph
examples/compiler/compiler
CLM:=clm
CLMFLAGS:=\
-I ../../src\
-I ../../lib\
-IL ArgEnv\
-IL Platform\
-IL GraphCopy\
......
......@@ -22,7 +22,6 @@ import code from "interpret."
import code from "mark."
import code from "parse."
import code from "strip."
import code from "traps."
import code from "util."
import code from library "msvcrt_library"
import code from library "kernel32_library"
......
......@@ -5,7 +5,6 @@ bcstrip
debug
interpret
graph_copy_with_names.dcl
graph_copy_with_names.icl
interpret_instructions.h
!interface.*.s
......@@ -96,11 +96,11 @@ SRC_INTERPRET:=\
gc/mark.c\
interpret.c\
parse.c\
traps.c\
util.c
DEP_INTERPRET:=$(subst .c,.h,$(SRC_INTERPRET))\
gc/util.h\
interpret_instructions.h\
interpret_instructions_interworking.h\
settings.h
SRC_INTERPRET_LIB:=$(SRC_INTERPRET)\
......@@ -114,6 +114,7 @@ OBJ_INTERPRET_LIB:=$(subst .c,.o,$(SRC_INTERPRET_LIB))
DEP_INTERPRET_LIB:=$(subst .c,.h,$(SRC_INTERPRET_LIB))\
gc/util.h\
interpret_instructions.h\
interpret_instructions_interworking.h\
settings.h
ifneq ($(OS),Windows_NT)
......@@ -145,7 +146,7 @@ $(INTERP): $(SRC_INTERPRET) $(DEP_INTERPRET)
$(CC) $(CFLAGS) $(CLIBS) -DINTERPRETER $(SRC_INTERPRET) -o $@
library: $(OBJ_INTERPRET_LIB) interface.o
cp $^ Clean\ System\ Files
cp $^ ../lib/Clean\ System\ Files
$(OBJ_INTERPRET_LIB): %.o: %.s
$(AS) $(ASFLAGS) $< -o $@
......@@ -159,6 +160,10 @@ ifeq ($(OS),Mac)
sed -i '' -f mac_fix_underscores.sed $@
endif
interpret_instructions.h: .FORCE
$(MAKE) -C ../tools interpretergenc
../tools/interpretergenc > $@
debug: $(SRC_INTERPRET) $(DEP_INTERPRET) debug_curses.c debug_curses.h
$(CC) $(CFLAGS) $(CLIBS) -UCOMPUTED_GOTOS -DINTERPRETER -DDEBUG_CURSES -lcurses $(SRC_INTERPRET) debug_curses.c -o $@
......@@ -169,7 +174,12 @@ AUXILIARIES:=$(INTERPRET_LIB)\
clean:
$(RM) $(BINARIES) $(AUXILIARIES)
find . -name '*.abc' -delete -or -name '*.obc' -delete -or -name '*.o' -delete
find . \
-name '*.abc' -delete \
-or -name '*.o' -delete -or -name '*.obj' -delete \
-or -name '*.prp' -delete \
-or -name '*.obc' -delete -or -name '*.bc' -delete \
-or -name 'Clean System Files' -empty -delete
.FORCE:
.PHONY: all clean library optimized
......@@ -35,7 +35,10 @@ ByteCodeStripper.exe: .FORCE
util.c \
/link /out:ByteCodeStripper.exe
library:
library: .FORCE
cd ..\tools && copy /Y interpretergenc.prj.default interpretergenc.prj && cpm.exe project interpretergenc.prj build
..\tools\interpretergenc > interpret_instructions.h
cl /nologo /c /O2 /GS- \
/DINTERPRETER /DLINK_CLEAN_RUNTIME /DWINDOWS /DMICROSOFT_C \
abc_instructions.c \
......@@ -50,25 +53,22 @@ library:
interpret.c \
parse.c \
strip.c \
traps.c \
util.c
ml64 /nologo /c /Fo interface.obj interface.windows64.asm
if exist "Clean System Files\*.*" \
(del /S "Clean System Files\*.abc" "Clean System Files\*.o" "Clean System Files\*.obj")
move abc_instructions.obj "Clean System Files" >nul
move bcgen_instructions.obj "Clean System Files" >nul
move bytecode.obj "Clean System Files" >nul
move copy_host_to_interpreter.obj "Clean System Files" >nul
move copy_interpreter_to_host.obj "Clean System Files" >nul
move finalizers.obj "Clean System Files" >nul
move gc.obj "Clean System Files" >nul
move copy.obj "Clean System Files" >nul
move mark.obj "Clean System Files" >nul
move interface.obj "Clean System Files" >nul
move interpret.obj "Clean System Files" >nul
move parse.obj "Clean System Files" >nul
move strip.obj "Clean System Files" >nul
move traps.obj "Clean System Files" >nul
move util.obj "Clean System Files" >nul
move abc_instructions.obj "..\lib\Clean System Files" >nul
move bcgen_instructions.obj "..\lib\Clean System Files" >nul
move bytecode.obj "..\lib\Clean System Files" >nul
move copy_host_to_interpreter.obj "..\lib\Clean System Files" >nul
move copy_interpreter_to_host.obj "..\lib\Clean System Files" >nul
move finalizers.obj "..\lib\Clean System Files" >nul
move gc.obj "..\lib\Clean System Files" >nul
move copy.obj "..\lib\Clean System Files" >nul
move mark.obj "..\lib\Clean System Files" >nul
move interface.obj "..\lib\Clean System Files" >nul
move interpret.obj "..\lib\Clean System Files" >nul
move parse.obj "..\lib\Clean System Files" >nul
move strip.obj "..\lib\Clean System Files" >nul
move util.obj "..\lib\Clean System Files" >nul
.FORCE:
......@@ -280,7 +280,6 @@ const char *instruction_type (BC_WORD i) {
case Cjsr_eval1: return "";
case Cjsr_eval2: return "";
case Cjsr_eval3: return "";
case Cjesr: return "n";
case ClnR: return "";
case Cload_i: return "i";
case Cload_si16: return "i";
......@@ -308,6 +307,7 @@ const char *instruction_type (BC_WORD i) {
case Cprint_char: return "";
case Cprint_int: return "";
case Cprint_real: return "";
case Cprint_string: return "";
case Cprint_symbol_sc: return "n";
case CpushA_a: return "n";
case CpushBFALSE: return "";
......@@ -487,6 +487,7 @@ const char *instruction_type (BC_WORD i) {
case CshiftrI: return "";
case CshiftrU: return "";
case CsinR: return "";
case CsliceAC: return "";
case CsubI: return "";
case CsubIo: return "";
case CsubLU: return "";
......@@ -530,6 +531,7 @@ const char *instruction_type (BC_WORD i) {
case Cupdate_b: return "nn";
case CxorI: return "";
case CCtoAC: return "";
case CItoAC: return "";
case CItoC: return "";
case CItoR: return "";
case CRtoI: return "";
......@@ -537,18 +539,68 @@ const char *instruction_type (BC_WORD i) {
case Cswap_a2: return "";
case Cswap_a3: return "";
case Cswap_a: return "n";
case Cjsr_ap: return "n";
case Cjsr_ap1: return "";
case Cjsr_ap2: return "";
case Cjsr_ap3: return "";
case Cjsr_ap4: return "";
case Cjsr_ap5: return "";
case Cjmp_ap: return "n";
case Cjmp_ap1: return "";
case Cjsr_ap1: return "";
case Cjmp_ap2: return "";
case Cjsr_ap2: return "";
case Cjmp_ap3: return "";
case Cjsr_ap3: return "";
case Cjmp_ap4: return "";
case Cjsr_ap4: return "";
case Cjmp_ap5: return "";
case Cjsr_ap5: return "";
case Cjmp_ap6: return "";
case Cjsr_ap6: return "";
case Cjmp_ap7: return "";
case Cjsr_ap7: return "";
case Cjmp_ap8: return "";
case Cjsr_ap8: return "";
case Cjmp_ap9: return "";
case Cjsr_ap9: return "";
case Cjmp_ap10: return "";
case Cjsr_ap10: return "";
case Cjmp_ap11: return "";
case Cjsr_ap11: return "";
case Cjmp_ap12: return "";
case Cjsr_ap12: return "";
case Cjmp_ap13: return "";
case Cjsr_ap13: return "";
case Cjmp_ap14: return "";
case Cjsr_ap14: return "";
case Cjmp_ap15: return "";
case Cjsr_ap15: return "";
case Cjmp_ap16: return "";
case Cjsr_ap16: return "";
case Cjmp_ap17: return "";
case Cjsr_ap17: return "";
case Cjmp_ap18: return "";
case Cjsr_ap18: return "";
case Cjmp_ap19: return "";
case Cjmp_ap20: return "";
case Cjsr_ap20: return "";
case Cjmp_ap21: return "";
case Cjsr_ap21: return "";
case Cjmp_ap22: return "";
case Cjsr_ap22: return "";
case Cjmp_ap23: return "";
case Cjsr_ap23: return "";
case Cjmp_ap24: return "";
case Cjsr_ap24: return "";
case Cjmp_ap25: return "";
case Cjsr_ap25: return "";
case Cjmp_ap26: return "";
case Cjsr_ap26: return "";
case Cjmp_ap27: return "";
case Cjsr_ap27: return "";
case Cjmp_ap28: return "";
case Cjsr_ap28: return "";
case Cjmp_ap29: return "";
case Cjmp_ap30: return "";
case Cjsr_ap30: return "";
case Cjmp_ap31: return "";
case Cjsr_ap31: return "";
case Cjmp_ap32: return "";
case Cjsr_ap32: return "";
case Cadd_arg0: return "";
case Cadd_arg1: return "";
case Cadd_arg2: return "";
......
......@@ -255,7 +255,6 @@ enum {
INSTRUCTION(incI)
INSTRUCTION(instruction)
INSTRUCTION(is_record)
INSTRUCTION(jesr)
INSTRUCTION(jmp)
INSTRUCTION(jmp_eval)
INSTRUCTION(jmp_eval_upd)
......@@ -294,6 +293,7 @@ enum {
INSTRUCTION(print_char)
INSTRUCTION(print_int)
INSTRUCTION(print_real)
INSTRUCTION(print_string)
INSTRUCTION(print_symbol_sc)
INSTRUCTION(pushcaf)
INSTRUCTION(pushcaf10)
......@@ -474,6 +474,7 @@ enum {
INSTRUCTION(shiftrI)
INSTRUCTION(shiftrU)
INSTRUCTION(sinR)
INSTRUCTION(sliceAC)
INSTRUCTION(subI)
INSTRUCTION(subIo)
INSTRUCTION(subLU)
......@@ -516,21 +517,74 @@ enum {
INSTRUCTION(update_r3b)
INSTRUCTION(xorI)
INSTRUCTION(CtoAC)
INSTRUCTION(ItoAC)
INSTRUCTION(ItoC)
INSTRUCTION(ItoR)
INSTRUCTION(RtoI)
INSTRUCTION(jsr_ap5)
INSTRUCTION(jmp_ap5)
INSTRUCTION(jsr_ap4)
INSTRUCTION(jmp_ap4)
INSTRUCTION(jsr_ap3)
INSTRUCTION(jmp_ap3)
INSTRUCTION(jsr_ap2)
INSTRUCTION(jmp_ap2)
INSTRUCTION(jsr_ap1)
INSTRUCTION(jmp_ap1)
INSTRUCTION(jsr_ap)
INSTRUCTION(jmp_ap)
INSTRUCTION(jsr_ap1)
INSTRUCTION(jmp_ap2)
INSTRUCTION(jsr_ap2)
INSTRUCTION(jmp_ap3)
INSTRUCTION(jsr_ap3)
INSTRUCTION(jmp_ap4)
INSTRUCTION(jsr_ap4)
INSTRUCTION(jmp_ap5)
INSTRUCTION(jsr_ap5)
INSTRUCTION(jmp_ap6)
INSTRUCTION(jsr_ap6)
INSTRUCTION(jmp_ap7)
INSTRUCTION(jsr_ap7)
INSTRUCTION(jmp_ap8)
INSTRUCTION(jsr_ap8)
INSTRUCTION(jmp_ap9)
INSTRUCTION(jsr_ap9)
INSTRUCTION(jmp_ap10)
INSTRUCTION(jsr_ap10)
INSTRUCTION(jmp_ap11)
INSTRUCTION(jsr_ap11)
INSTRUCTION(jmp_ap12)
INSTRUCTION(jsr_ap12)
INSTRUCTION(jmp_ap13)
INSTRUCTION(jsr_ap13)
INSTRUCTION(jmp_ap14)
INSTRUCTION(jsr_ap14)
INSTRUCTION(jmp_ap15)
INSTRUCTION(jsr_ap15)
INSTRUCTION(jmp_ap16)
INSTRUCTION(jsr_ap16)
INSTRUCTION(jmp_ap17)
INSTRUCTION(jsr_ap17)
INSTRUCTION(jmp_ap18)
INSTRUCTION(jsr_ap18)
INSTRUCTION(jmp_ap19)
INSTRUCTION(jsr_ap19)
INSTRUCTION(jmp_ap20)
INSTRUCTION(jsr_ap20)
INSTRUCTION(jmp_ap21)
INSTRUCTION(jsr_ap21)
INSTRUCTION(jmp_ap22)
INSTRUCTION(jsr_ap22)
INSTRUCTION(jmp_ap23)
INSTRUCTION(jsr_ap23)
INSTRUCTION(jmp_ap24)
INSTRUCTION(jsr_ap24)
INSTRUCTION(jmp_ap25)
INSTRUCTION(jsr_ap25)
INSTRUCTION(jmp_ap26)
INSTRUCTION(jsr_ap26)
INSTRUCTION(jmp_ap27)
INSTRUCTION(jsr_ap27)
INSTRUCTION(jmp_ap28)
INSTRUCTION(jsr_ap28)
INSTRUCTION(jmp_ap29)
INSTRUCTION(jsr_ap29)
INSTRUCTION(jmp_ap30)
INSTRUCTION(jsr_ap30)
INSTRUCTION(jmp_ap31)
INSTRUCTION(jsr_ap31)
INSTRUCTION(jmp_ap32)
INSTRUCTION(jsr_ap32)
INSTRUCTION(add_arg0)
INSTRUCTION(add_arg1)
INSTRUCTION(add_arg2)
......
......@@ -820,13 +820,51 @@ void add_instruction_w_internal_label_label(int16_t i,int32_t n1,struct label *l
store_code_label_value(label_name,0);
}
void add_jesr_instruction(int lib_function_n) {
switch (lib_function_n) {
case 0: add_instruction(CeqAC); break;
case 1: add_instruction(CcatAC); break;
case 11: add_instruction(CcmpAC); break;
static char *specialized_jsr_labels[] = {
/* 0*/ "eqAC",
/* 1*/ "cmpAC",
/* 2*/ "catAC",
/* 3*/ "sliceAC",
/* 4*/ "ItoAC",
/* 5*/ "BtoAC",
/* 6*/ "print__string__",
/* 7*/ "openF",
/* 8*/ "stdioF",
/* 9*/ "closeF",
/*10*/ "readLineF",
/*11*/ "endF",
/*12*/ "writeFI",
/*13*/ "writeFS",
/*14*/ "writeFC",
/*15*/ "openSF"
};
static int get_specialized_jsr_label_n(char label_name[]) {
int i,n;
n = sizeof(specialized_jsr_labels) / sizeof (char*);
for(i=0; i<n; ++i)
if (!strcmp (label_name,specialized_jsr_labels[i]))
return i;
return -1;
}
void add_specialized_jsr_instruction(unsigned int n) {
switch (n) {
case 0: add_instruction(CeqAC); return;
case 1: add_instruction(CcmpAC); return;
case 2: add_instruction(CcatAC); return;
case 3: add_instruction(CsliceAC); return;
case 4: add_instruction(CItoAC); return;
case 6: add_instruction(Cprint_string); return;
default:
add_instruction_w(Cjesr,lib_function_n);
if (n < sizeof(specialized_jsr_labels)/sizeof(char*)) {
fprintf(stderr,"Warning: jsr %s is not supported by the interpreter\n",specialized_jsr_labels[n]);
} else {
fprintf(stderr,"internal error in add_specialized_jsr_instruction: %d\n",n);
exit(1);
}
}
}
......@@ -1032,6 +1070,7 @@ void code_buildC_b(int b_offset) {
}
void code_buildF_b(int b_offset) {
unsupported_instruction_warning(CbuildF_b);
add_instruction_w(CbuildF_b,b_offset);
}
......@@ -2050,6 +2089,7 @@ void code_fillC_b(int b_offset,int a_offset) {
}
void code_fillF_b(int b_offset,int a_offset) {
unsupported_instruction_warning(CfillF_b);
add_instruction_w_w(CfillF_b,-a_offset,b_offset);
}
......@@ -2199,13 +2239,41 @@ void code_jmp(char label_name[]) {
void code_jmp_ap(int n_apply_args) {
switch (n_apply_args) {
case 1: add_instruction(Cjmp_ap1); break;
case 2: add_instruction(Cjmp_ap2); break;
case 3: add_instruction(Cjmp_ap3); break;
case 4: add_instruction(Cjmp_ap4); break;
case 5: add_instruction(Cjmp_ap5); break;
default: add_instruction_w(Cjmp_ap,n_apply_args); break;
}
case 1: add_instruction(Cjmp_ap1); return;
case 2: add_instruction(Cjmp_ap2); return;
case 3: add_instruction(Cjmp_ap3); return;
case 4: add_instruction(Cjmp_ap4); return;
case 5: add_instruction(Cjmp_ap5); return;
case 6: add_instruction(Cjmp_ap6); return;
case 7: add_instruction(Cjmp_ap7); return;
case 8: add_instruction(Cjmp_ap8); return;
case 9: add_instruction(Cjmp_ap9); return;
case 10: add_instruction(Cjmp_ap10); return;
case 11: add_instruction(Cjmp_ap11); return;
case 12: add_instruction(Cjmp_ap12); return;
case 13: add_instruction(Cjmp_ap13); return;
case 14: add_instruction(Cjmp_ap14); return;
case 15: add_instruction(Cjmp_ap15); return;
case 16: add_instruction(Cjmp_ap16); return;
case 17: add_instruction(Cjmp_ap17); return;
case 18: add_instruction(Cjmp_ap18); return;
case 19: add_instruction(Cjmp_ap19); return;
case 20: add_instruction(Cjmp_ap20); return;
case 21: add_instruction(Cjmp_ap21); return;
case 22: add_instruction(Cjmp_ap22); return;
case 23: add_instruction(Cjmp_ap23); return;
case 24: add_instruction(Cjmp_ap24); return;
case 25: add_instruction(Cjmp_ap25); return;
case 26: add_instruction(Cjmp_ap26); return;
case 27: add_instruction(Cjmp_ap27); return;
case 28: add_instruction(Cjmp_ap28); return;
case 29: add_instruction(Cjmp_ap29); return;
case 30: add_instruction(Cjmp_ap30); return;
case 31: add_instruction(Cjmp_ap31); return;
case 32: add_instruction(Cjmp_ap32); return;
}
fprintf(stderr, "Error: jmp_ap %d not yet implemented\n",n_apply_args);
exit(1);
}
void code_jmp_eval(void) {
......@@ -2224,34 +2292,6 @@ void code_jmp_true(char label_name[]) {
add_instruction_label(Cjmp_true,label_name);
}
char *lib_functions[] = {
/*0*/ "eqAC", /* CeqAC */
/*1*/ "catAC",
/*2*/ "sliceAC",
/*3*/ "ItoAC", "BtoAC",
/*5*/ "print__string__",
/*6*/ "openF", "stdioF",
/*8*/ "closeF",
/*9*/ "readLineF",
/*10*/ "endF",
/*11*/ "cmpAC",
/*12*/ "writeFI",
/*13*/ "writeFS",
/*14*/ "writeFC",
"openSF"
};
static int get_lib_function_n(char label_name[]) {
int lib_function_n,n_lib_functions;
n_lib_functions = sizeof(lib_functions) / sizeof (char*);
for(lib_function_n=0; lib_function_n<n_lib_functions; ++lib_function_n)
if (!strcmp (label_name,lib_functions[lib_function_n]))
return lib_function_n;
return -1;
}
void code_jsr(char label_name[]) {
int lib_function_n;
......@@ -2265,10 +2305,10 @@ void code_jsr(char label_name[]) {
last_d=0;
}
lib_function_n = get_lib_function_n(label_name);
lib_function_n = get_specialized_jsr_label_n(label_name);
if (lib_function_n>=0) {
add_jesr_instruction(lib_function_n);
add_specialized_jsr_instruction(lib_function_n);
last_jsr_with_d=0;
return;
}
......@@ -2278,13 +2318,41 @@ void code_jsr(char label_name[]) {
void code_jsr_ap(int n_apply_args) {
switch (n_apply_args) {
case 1: add_instruction(Cjsr_ap1); return;
case 2: add_instruction(Cjsr_ap2); return;
case 3: add_instruction(Cjsr_ap3); return;
case 4: add_instruction(Cjsr_ap4); return;
case 5: add_instruction(Cjsr_ap5); return;
default: add_instruction_w(Cjsr_ap,n_apply_args); return;
}
case 1: add_instruction(Cjsr_ap1); return;
case 2: add_instruction(Cjsr_ap2); return;
case 3: add_instruction(Cjsr_ap3); return;
case 4: add_instruction(Cjsr_ap4); return;
case 5: add_instruction(Cjsr_ap5); return;
case 6: add_instruction(Cjsr_ap6); return;
case 7: add_instruction(Cjsr_ap7); return;
case 8: add_instruction(Cjsr_ap8); return;
case 9: add_instruction(Cjsr_ap9); return;
case 10: add_instruction(Cjsr_ap10); return;
case 11: add_instruction(Cjsr_ap11); return;
case 12: add_instruction(Cjsr_ap12); return;
case 13: add_instruction(Cjsr_ap13); return;
case 14: add_instruction(Cjsr_ap14); return;
case 15: add_instruction(Cjsr_ap15); return;
case 16: add_instruction(Cjsr_ap16); return;
case 17: add_instruction(Cjsr_ap17); return;
case 18: add_instruction(Cjsr_ap18); return;
case 19: add_instruction(Cjsr_ap19); return;
case 20: add_instruction(Cjsr_ap20); return;
case 21: add_instruction(Cjsr_ap21); return;
case 22: add_instruction(Cjsr_ap22); return;
case 23: add_instruction(Cjsr_ap23); return;
case 24: add_instruction(Cjsr_ap24); return;
case 25: add_instruction(Cjsr_ap25); return;
case 26: add_instruction(Cjsr_ap26); return;
case 27: add_instruction(Cjsr_ap27); return;
case 28: add_instruction(Cjsr_ap28); return;
case 29: add_instruction(Cjsr_ap29); return;
case 30: add_instruction(Cjsr_ap30); return;
case 31: add_instruction(Cjsr_ap31); return;
case 32: add_instruction(Cjsr_ap32); return;
}
fprintf(stderr, "Error: jsr_ap %d not yet implemented\n",n_apply_args);
exit(1);
}
void code_jsr_eval(int a_offset) {
......@@ -2492,6 +2560,7 @@ void code_pushD_a(int a_offset) {
}
void code_pushF_a(int a_offset) {
unsupported_instruction_warning(CpushF_a);
add_instruction_w(CpushF_a,-a_offset);
}
......@@ -3395,11 +3464,11 @@ void code_buildh0_put_a_jsr(char descriptor_name[],int a_offset,char label_name[
last_d=0;
}
lib_function_n = get_lib_function_n(label_name);
lib_function_n = get_specialized_jsr_label_n(label_name);
if (lib_function_n>=0) {
code_buildh0_put_a(descriptor_name,a_offset);
add_jesr_instruction(lib_function_n);
add_specialized_jsr_instruction(lib_function_n);
last_jsr_with_d=0;
return;
}
......@@ -3597,11 +3666,11 @@ void code_pop_a_jsr(int n,char label_name[]) {
last_d=0;
}
lib_function_n = get_lib_function_n(label_name);
lib_function_n = get_specialized_jsr_label_n(label_name);
if (lib_function_n>=0) {
code_pop_a(n);
add_jesr_instruction(lib_function_n);
add_specialized_jsr_instruction(lib_function_n);
last_jsr_with_d=0;
return;
}
......@@ -3640,11 +3709,11 @@ void code_pop_b_jsr(int n,char label_name[]) {