Post by bartcPost by m***@gmail.comPost by bartcIs this still for Seed7 sources (rather than Seed7-generated C)? As I
said before, it will be more effective for me to whizz through the
sources. I've tried it once but didn't know what files are supposed to
compile, and which shouldn't, but I can try again and use gcc as a guide.
Yes, this is still for Seed7. I created a makefile for mcc64 (mk_mcc64.mak)
and a small frontend for mcc64. The frontend (mcc.c) calls mcc64, nasm (to
produce an .obj) and gcc (to link it together to an executable). Executing
chkccomp.c succeeds. There are several hickups with chkccomp.c, E.g.: I am
currently not sure if system() succeeds in calling mcc.exe. But I get an
version.h file, such that I can compile the sources of the Seed7 interpreter
afterwards. There I get errors about missing functions, etc. (see above for
the most obvious findings). All of this is very experimental. Therefore it
is currently not part of the Seed7 release.
That sounds promising. As I said, I'll do another pass through the
sources later. (Compiling the 170Kloc sqlite.c, using my own headers
rather than another compiler's as I've used for that, is another qood
way of picking up missing elements of headers.)
But with other test programs that I have managed to compile and run (eg.
Lua, Tiny C, Tex) they execute, but then diverge in behaviour from the
same program built with a solid compiler like gcc. This might be a
subtle difference, or it might be not so subtle.
I'm still looking for an approach to help track down those code
generator problems that doesn't involve delving deeply into the source
code of the applications, as that is hopelessly impractical.
A test suite is helpful to find weaknesses systematically.
Probably a C test suite would be the best solution.
For Seed7 I have a test suite. So, if compiling Seed7 succeeds,
mcc64 can be tested indirectly.
I found more missing things in the header files of mcc64.c.
When I compile and run chkccomp.c it shows me that some functions are
missings:
_wchdir
_wgetcwd
_wmkdir
_wrmdir
_wchmod
_wremove
_wrename
_wsystem
_wfopen
Additionally a definition of struct utimbuf is missing from utime.h.
You can try it yourself with the newest release of Seed7
(seed7_05_20170702.tgz). To compile Seed7 with mcc64 I use make7,
which is also part of the Seed7 package. Any other make utility is
also possible.
To get the executable of make7 you need to compile Seed7 with gcc.
Afterwards you can compile make7 with: s7c make7 and save the
executable make7.exe away to some directory in the path.
To compile Seed7 with mcc64 you need the makefile mk_mcc64w.mak,
which follows:
-------------------- begin mk_mcc64w.mak --------------------
# Makefile for make7 and gcc from MinGW. Commands executed by: cmd.exe
# To compile use a Windows console and call:
# ..\bin\make7 -f mk_mingc.mak depend
# ..\bin\make7 -f mk_mingc.mak
# When your make utility uses Unix commands, you should use mk_msys.mak instead.
# When the nmake utility from Windows is available, you can use mk_nmake.mak instead.
# When you are using the MSYS console from MinGW you should use mk_msys.mak instead.
# CFLAGS = -O2 -fomit-frame-pointer -funroll-loops -Wall
# CFLAGS = -O2 -fomit-frame-pointer -Wall -Wstrict-prototypes -Winline -Wconversion -Wshadow -Wpointer-arith
# CFLAGS = -O2 -g -ffunction-sections -fdata-sections $(INCLUDE_OPTIONS) -Wall -Wstrict-prototypes -Winline -Wconversion -Wshadow -Wpointer-arith
CFLAGS = $(INCLUDE_OPTIONS)
# CFLAGS = -O2 -g -pg -Wall -Wstrict-prototypes -Winline -Wconversion -Wshadow -Wpointer-arith
# CFLAGS = -O2 -Wall -Wstrict-prototypes -Winline -Wconversion -Wshadow -Wpointer-arith
# CFLAGS = -O2 -pg -Wall -Wstrict-prototypes -Winline -Wconversion -Wshadow -Wpointer-arith
# CFLAGS = -O2 -funroll-loops -Wall -pg
LDFLAGS =
# LDFLAGS = -Wl,--gc-sections,--stack,8388608,--subsystem,windows
# LDFLAGS = -pg
# LDFLAGS = -pg -lc_p
SYSTEM_LIBS = -lm -lws2_32
# SYSTEM_LIBS = -lm -lws2_32 -lgmp
SYSTEM_CONSOLE_LIBS =
SYSTEM_DRAW_LIBS = -lgdi32
SEED7_LIB = seed7_05.a
CONSOLE_LIB = s7_con.a
DRAW_LIB = s7_draw.a
COMP_DATA_LIB = s7_data.a
COMPILER_LIB = s7_comp.a
ALL_S7_LIBS = ..\bin\$(COMPILER_LIB) ..\bin\$(COMP_DATA_LIB) ..\bin\$(DRAW_LIB) ..\bin\$(CONSOLE_LIB) ..\bin\$(SEED7_LIB)
# CC = g++
CC = mcc
GET_CC_VERSION_INFO = $(CC) --version >
BIGINT_LIB_DEFINE = USE_BIG_RTL_LIBRARY
BIGINT_LIB = big_rtl
# BIGINT_LIB_DEFINE = USE_BIG_GMP_LIBRARY
# BIGINT_LIB = big_gmp
MOBJ = s7.obj
POBJ = runerr.obj option.obj primitiv.obj
LOBJ = actlib.obj arrlib.obj biglib.obj binlib.obj blnlib.obj bstlib.obj chrlib.obj cmdlib.obj conlib.obj dcllib.obj \
drwlib.obj enulib.obj fillib.obj fltlib.obj hshlib.obj intlib.obj itflib.obj kbdlib.obj lstlib.obj pcslib.obj \
pollib.obj prclib.obj prglib.obj reflib.obj rfllib.obj sctlib.obj setlib.obj soclib.obj sqllib.obj strlib.obj \
timlib.obj typlib.obj ut8lib.obj
EOBJ = exec.obj doany.obj objutl.obj
AOBJ = act_comp.obj prg_comp.obj analyze.obj syntax.obj token.obj parser.obj name.obj type.obj \
expr.obj atom.obj object.obj scanner.obj literal.obj numlit.obj findid.obj \
error.obj infile.obj libpath.obj symbol.obj info.obj stat.obj fatal.obj match.obj
GOBJ = syvarutl.obj traceutl.obj actutl.obj executl.obj blockutl.obj \
entutl.obj identutl.obj chclsutl.obj arrutl.obj
ROBJ = arr_rtl.obj bln_rtl.obj bst_rtl.obj chr_rtl.obj cmd_rtl.obj con_rtl.obj dir_rtl.obj drw_rtl.obj fil_rtl.obj \
flt_rtl.obj hsh_rtl.obj int_rtl.obj itf_rtl.obj pcs_rtl.obj set_rtl.obj soc_rtl.obj sql_rtl.obj str_rtl.obj \
tim_rtl.obj ut8_rtl.obj heaputl.obj numutl.obj sigutl.obj striutl.obj \
sql_base.obj sql_lite.obj sql_my.obj sql_oci.obj sql_odbc.obj sql_post.obj
DOBJ = $(BIGINT_LIB).obj cmd_win.obj dir_win.obj dll_win.obj fil_win.obj pcs_win.obj pol_sel.obj stat_win.obj tim_win.obj
OBJ = $(MOBJ)
SEED7_LIB_OBJ = $(ROBJ) $(DOBJ)
DRAW_LIB_OBJ = gkb_rtl.obj drw_win.obj gkb_win.obj
CONSOLE_LIB_OBJ = kbd_rtl.obj con_win.obj
COMP_DATA_LIB_OBJ = typ_data.obj rfl_data.obj ref_data.obj listutl.obj flistutl.obj typeutl.obj datautl.obj
COMPILER_LIB_OBJ = $(POBJ) $(LOBJ) $(EOBJ) $(AOBJ) $(GOBJ)
MSRC = s7.c
PSRC = runerr.c option.c primitiv.c
LSRC = actlib.c arrlib.c biglib.c binlib.c blnlib.c bstlib.c chrlib.c cmdlib.c conlib.c dcllib.c \
drwlib.c enulib.c fillib.c fltlib.c hshlib.c intlib.c itflib.c kbdlib.c lstlib.c pcslib.c \
pollib.c prclib.c prglib.c reflib.c rfllib.c sctlib.c setlib.c soclib.c sqllib.c strlib.c \
timlib.c typlib.c ut8lib.c
ESRC = exec.c doany.c objutl.c
ASRC = act_comp.c prg_comp.c analyze.c syntax.c token.c parser.c name.c type.c \
expr.c atom.c object.c scanner.c literal.c numlit.c findid.c \
error.c infile.c libpath.c symbol.c info.c stat.c fatal.c match.c
GSRC = syvarutl.c traceutl.c actutl.c executl.c blockutl.c \
entutl.c identutl.c chclsutl.c arrutl.c
RSRC = arr_rtl.c bln_rtl.c bst_rtl.c chr_rtl.c cmd_rtl.c con_rtl.c dir_rtl.c drw_rtl.c fil_rtl.c \
flt_rtl.c hsh_rtl.c int_rtl.c itf_rtl.c pcs_rtl.c set_rtl.c soc_rtl.c sql_rtl.c str_rtl.c \
tim_rtl.c ut8_rtl.c heaputl.c numutl.c sigutl.c striutl.c \
sql_base.c sql_lite.c sql_my.c sql_oci.c sql_odbc.c sql_post.c
DSRC = $(BIGINT_LIB).c cmd_win.c dir_win.c dll_win.c fil_win.c pcs_win.c pol_sel.c stat_win.c tim_win.c
SRC = $(MSRC)
SEED7_LIB_SRC = $(RSRC) $(DSRC)
DRAW_LIB_SRC = gkb_rtl.c drw_win.c gkb_win.c
CONSOLE_LIB_SRC = kbd_rtl.c con_win.c
COMP_DATA_LIB_SRC = typ_data.c rfl_data.c ref_data.c listutl.c flistutl.c typeutl.c datautl.c
COMPILER_LIB_SRC = $(PSRC) $(LSRC) $(ESRC) $(ASRC) $(GSRC)
s7: ..\bin\s7.exe ..\prg\s7.exe
..\bin\s7 -l ..\lib level
@echo.
@echo Use 'make s7c' (with your make command) to create the compiler.
@echo.
s7c: ..\bin\s7c.exe ..\prg\s7c.exe
@echo.
@echo Use 'make test' (with your make command) to check Seed7.
@echo.
..\bin\s7.exe: $(OBJ) $(ALL_S7_LIBS)
$(CC) $(LDFLAGS) $(OBJ) $(ALL_S7_LIBS) $(SYSTEM_DRAW_LIBS) $(SYSTEM_CONSOLE_LIBS) $(SYSTEM_LIBS) $(SYSTEM_DB_LIBS) -o ..\bin\s7
..\prg\s7.exe: ..\bin\s7.exe
copy ..\bin\s7.exe ..\prg /Y
..\bin\s7c.exe: ..\prg\s7c.exe
copy ..\prg\s7c.exe ..\bin /Y
..\prg\s7c.exe: ..\prg\s7c.sd7 $(ALL_S7_LIBS)
..\bin\s7 -l ..\lib ..\prg\s7c -l ..\lib -b ..\bin -O2 ..\prg\s7c
clear: clean
clean:
del mcc64.exe
del mcc.exe
del *.obj
del *.asm
del ..\bin\*.a
del ..\bin\s7.exe
del ..\bin\s7c.exe
del ..\prg\s7.exe
del ..\prg\s7c.exe
del depend
del macros
del chkccomp.h
del version.h
del setwpath.exe
del wrdepend.exe
del sudo.exe
@echo.
@echo Use 'make depend' (with your make command) to create the dependencies.
@echo.
distclean: clean
copy level_bk.h level.h /Y
test:
..\bin\s7 -l ..\lib ..\prg\chk_all build
@echo.
@echo Use 'sudo make install' (with your make command) to install Seed7.
@echo Or open a console as administrator, go to the directory seed7/src
@echo and use 'make install' (with your make command) to install Seed7.
@echo.
install: setwpath.exe
.\setwpath.exe add ..\bin
uninstall: setwpath.exe
.\setwpath.exe remove ..\bin
dep: depend
strip:
strip ..\bin\s7.exe
mcc64.exe: mcc64.c
gcc -m64 -O3 mcc64.c -o mcc64.exe
mcc.exe: mcc.c mcc64.exe
mcc64 mcc.c
nasm -fwin64 mcc.asm
gcc -o mcc.exe mcc.obj
chkccomp.h:
echo #define LIST_DIRECTORY_CONTENTS "dir" >> chkccomp.h
echo #define STAT_MISSING >> chkccomp.h
echo #define MYSQL_DLL "libmariadb.dll", "libmysql.dll" >> chkccomp.h
echo #define MYSQL_USE_DLL >> chkccomp.h
echo #define SQLITE_DLL "sqlite3.dll" >> chkccomp.h
echo #define SQLITE_USE_DLL >> chkccomp.h
echo #define POSTGRESQL_DLL "libpq.dll" >> chkccomp.h
echo #define POSTGRESQL_USE_DLL >> chkccomp.h
echo #define ODBC_LIBS "-lodbc32" >> chkccomp.h
echo #define ODBC_DLL "odbc32.dll" >> chkccomp.h
echo #define ODBC_USE_LIB >> chkccomp.h
echo #define OCI_DLL "oci.dll" >> chkccomp.h
echo #define OCI_USE_DLL >> chkccomp.h
version.h: chkccomp.h mcc.exe
echo #define PATH_DELIMITER '\\' > version.h
echo #define SEARCH_PATH_DELIMITER ';' >> version.h
echo #define NULL_DEVICE "NUL:" >> version.h
echo #define WITH_SQL >> version.h
echo #define CONSOLE_WCHAR >> version.h
echo #define OS_STRI_WCHAR >> version.h
echo #define os_fstat _fstati64 >> version.h
echo #define DEFINE_WSTATI64_EXT >> version.h
echo #define os_lstat wstati64Ext >> version.h
echo #define os_stat wstati64Ext >> version.h
echo #define os_stat_orig _wstati64 >> version.h
echo #define os_stat_struct struct _stati64 >> version.h
echo #define os_fseek fseeko64 >> version.h
echo #define os_ftell ftello64 >> version.h
echo #define os_off_t off64_t >> version.h
echo #define os_environ _wenviron >> version.h
echo #define os_putenv _wputenv >> version.h
echo #define os_getch _getwch >> version.h
echo #define QUOTE_WHOLE_SHELL_COMMAND >> version.h
echo #define USE_WINSOCK >> version.h
echo #define $(BIGINT_LIB_DEFINE) >> version.h
echo #define OBJECT_FILE_EXTENSION ".obj" >> version.h
echo #define LIBRARY_FILE_EXTENSION ".a" >> version.h
echo #define EXECUTABLE_FILE_EXTENSION ".exe" >> version.h
echo #define C_COMPILER "$(CC)" >> version.h
echo #define GET_CC_VERSION_INFO_OPTIONS "--version >" >> version.h
echo #define CC_OPT_DEBUG_INFO "-g" >> version.h
echo #define CC_OPT_NO_WARNINGS "-w" >> version.h
echo #define CC_FLAGS "" >> version.h
echo #define CC_ERROR_FILDES 2 >> version.h
echo #define LINKER_OPT_NO_DEBUG_INFO "-Wl,--strip-debug" >> version.h
echo #define LINKER_OPT_OUTPUT_FILE "-o " >> version.h
echo #define LINKER_FLAGS "$(LDFLAGS)" >> version.h
echo #define SYSTEM_LIBS "$(SYSTEM_LIBS)" >> version.h
echo #define SYSTEM_CONSOLE_LIBS "$(SYSTEM_CONSOLE_LIBS)" >> version.h
echo #define SYSTEM_DRAW_LIBS "$(SYSTEM_DRAW_LIBS)" >> version.h
$(GET_CC_VERSION_INFO) cc_vers.txt
$(CC) chkccomp.c -lm -o chkccomp
.\chkccomp.exe version.h
del chkccomp.exe
del cc_vers.txt
echo #define SEED7_LIB "$(SEED7_LIB)" >> version.h
echo #define CONSOLE_LIB "$(CONSOLE_LIB)" >> version.h
echo #define DRAW_LIB "$(DRAW_LIB)" >> version.h
echo #define COMP_DATA_LIB "$(COMP_DATA_LIB)" >> version.h
echo #define COMPILER_LIB "$(COMPILER_LIB)" >> version.h
$(CC) -o setpaths setpaths.c
.\setpaths.exe "S7_LIB_DIR=$(S7_LIB_DIR)" "SEED7_LIBRARY=$(SEED7_LIBRARY)" >> version.h
del setpaths.exe
$(CC) setwpath.c -o setwpath
$(CC) wrdepend.c -o wrdepend
$(CC) sudo.c -w -o sudo
depend: version.h
.\wrdepend.exe $(CFLAGS) -M $(SRC) "> depend"
.\wrdepend.exe $(CFLAGS) -M $(SEED7_LIB_SRC) ">> depend"
.\wrdepend.exe $(CFLAGS) -M $(CONSOLE_LIB_SRC) ">> depend"
.\wrdepend.exe $(CFLAGS) -M $(DRAW_LIB_SRC) ">> depend"
.\wrdepend.exe $(CFLAGS) -M $(COMP_DATA_LIB_SRC) ">> depend"
.\wrdepend.exe $(CFLAGS) -M $(COMPILER_LIB_SRC) ">> depend"
@echo.
@echo Use 'make' (with your make command) to create the interpreter.
@echo.
level.h:
..\bin\s7 -l ..\lib level
..\bin\$(SEED7_LIB): $(SEED7_LIB_OBJ)
..\bin\call_ar r ..\bin\$(SEED7_LIB) $(SEED7_LIB_OBJ)
..\bin\$(CONSOLE_LIB): $(CONSOLE_LIB_OBJ)
..\bin\call_ar r ..\bin\$(CONSOLE_LIB) $(CONSOLE_LIB_OBJ)
..\bin\$(DRAW_LIB): $(DRAW_LIB_OBJ)
..\bin\call_ar r ..\bin\$(DRAW_LIB) $(DRAW_LIB_OBJ)
..\bin\$(COMP_DATA_LIB): $(COMP_DATA_LIB_OBJ)
..\bin\call_ar r ..\bin\$(COMP_DATA_LIB) $(COMP_DATA_LIB_OBJ)
..\bin\$(COMPILER_LIB): $(COMPILER_LIB_OBJ)
..\bin\call_ar r ..\bin\$(COMPILER_LIB) $(COMPILER_LIB_OBJ)
..\bin\%.exe: ..\prg\%.sd7 ..\bin\s7c.exe
..\bin\s7c.exe -l ..\lib -b ..\bin -O2 $<
move /Y $(<:.sd7=.exe) ..\bin
bas7: ..\bin\bas7.exe
calc7: ..\bin\calc7.exe
cat: ..\bin\cat.exe
comanche: ..\bin\comanche.exe
diff7: ..\bin\diff7.exe
find7: ..\bin\find7.exe
ftp7: ..\bin\ftp7.exe
ftpserv: ..\bin\ftpserv.exe
hd: ..\bin\hd.exe
make7: ..\bin\make7.exe
sql7: ..\bin\sql7.exe
sydir7: ..\bin\sydir7.exe
tar7: ..\bin\tar7.exe
toutf8: ..\bin\toutf8.exe
which: ..\bin\which.exe
utils: ..\bin\bas7.exe ..\bin\calc7.exe ..\bin\cat.exe ..\bin\comanche.exe ..\bin\diff7.exe \
..\bin\find7.exe ..\bin\ftp7.exe ..\bin\ftpserv.exe ..\bin\hd.exe ..\bin\make7.exe \
..\bin\sql7.exe ..\bin\sydir7.exe ..\bin\tar7.exe ..\bin\toutf8.exe ..\bin\which.exe
wc: $(SRC)
echo SRC:
wc $(SRC)
echo SEED7_LIB_SRC:
wc $(SEED7_LIB_SRC)
echo CONSOLE_LIB_SRC:
wc $(CONSOLE_LIB_SRC)
echo DRAW_LIB_SRC:
wc $(DRAW_LIB_SRC)
echo COMP_DATA_LIB_SRC:
wc $(COMP_DATA_LIB_SRC)
echo COMPILER_LIB_SRC:
wc $(COMPILER_LIB_SRC)
lint: $(SRC)
lint -p $(SRC) $(SYSTEM_DRAW_LIBS) $(SYSTEM_CONSOLE_LIBS) $(SYSTEM_LIBS) $(SYSTEM_DB_LIBS)
lint2: $(SRC)
lint -Zn2048 $(SRC) $(SYSTEM_DRAW_LIBS) $(SYSTEM_CONSOLE_LIBS) $(SYSTEM_LIBS) $(SYSTEM_DB_LIBS)
ifeq (depend,$(wildcard depend))
include depend
endif
ifeq (macros,$(wildcard macros))
include macros
endif
-------------------- end mk_mcc64w.mak --------------------
The makefile mk_mcc64w.mak assumes that mcc64.c and mcc.c are in the seed7/src
directory. The program mcc.c, which is a driver for mcc64.c follows:
-------------------- begin mcc.c --------------------
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define COMMAND_SIZE 1024
int main (int argc, char *argv[])
{
int pos;
size_t len;
char *source = NULL;
char *assembler = NULL;
char *obj = NULL;
char *output = NULL;
char *includeDir = NULL;
int doLink = 1;
char command[COMMAND_SIZE];
for (pos = 1; pos < argc; pos++) {
if (argv[pos][0] == '-') {
switch (argv[pos][1]) {
case 'o':
if (argv[pos][2] != '\0') {
output = &argv[pos][2];
} else if (pos < argc - 1) {
pos++;
output = argv[pos];
} else {
printf(" ***** Option %s without required value.\n", argv[pos]);
} /* if */
break;
case 'c':
doLink = 0;
break;
case 'I':
if (argv[pos][2] != '\0') {
includeDir = &argv[pos][2];
} else if (pos < argc - 1) {
pos++;
includeDir = argv[pos];
} else {
printf(" ***** Option %s without required value.\n", argv[pos]);
} /* if */
break;
default:
printf(" ***** Unknown option: %s\n", argv[pos]);
break;
} /* switch */
} else {
len = strlen(argv[pos]);
if (len >= 3 && strcmp(&argv[pos][len - 2], ".c") == 0) {
source = argv[pos];
assembler = malloc(len + 5);
strcpy(assembler, source);
strcpy(&assembler[len - 2], ".asm");
obj = malloc(len + 3);
strcpy(obj, source);
strcpy(&obj[len - 2], ".obj");
} else {
printf(" ***** Unknown parameter: %s\n", argv[pos]);
} /* if */
} /* if */
} /* for */
if (source != NULL) {
if (includeDir != NULL) {
len = strlen(includeDir);
if (len > 1 && (includeDir[len - 1] == '/' ||
includeDir[len - 1] == '\\')) {
sprintf(command, "mcc64 -i:%s %s", includeDir, source);
} else {
sprintf(command, "mcc64 -i:%s/ %s", includeDir, source);
} /* if */
} else {
sprintf(command, "mcc64 %s", source);
} /* if */
printf("%s\n", command);
system(command);
sprintf(command, "nasm -fwin64 %s", assembler);
printf("%s\n", command);
system(command);
if (doLink) {
if (output != NULL) {
sprintf(command, "gcc -o %s %s", output, obj);
printf("%s\n", command);
system(command);
} else {
sprintf(command, "gcc %s", obj);
printf("%s\n", command);
system(command);
} /* if */
} /* if */
} else {
printf(" ***** No input files.\n");
} /* if */
return 0;
}
-------------------- end mcc.c --------------------
Both (mk_mcc64w.mak and mcc.c) are experimental.
I hope that helps to compile Seed7 with mcc64.c.
Regards,
Thomas Mertes
--
Seed7 Homepage: http://seed7.sourceforge.net
Seed7 - The extensible programming language: User defined statements
and operators, abstract data types, templates without special
syntax, OO with interfaces and multiple dispatch, statically typed,
interpreted or compiled, portable, runs under linux/unix/windows.