First working commit of the new scaffold implementation.
A large commit consisting of a re-implementing of the scaffold
generation for modula-2. The changes allow the compiler
to be built, installed and hello world can be compiled and linked.
The default scaffold generated by modula-2 is propagated to M2RTS
via ctors. At runtime M2RTS resolves the dependency import graph
and calls each module init/fini code.
2022-06-20 Gaius Mulley <gaius.mulley@southwales.ac.uk>
gcc/ChangeLog:
* doc/gm2.texi: Replaced English spelling to American.
(-fscaffold-static) New option documented. (-fscaffold-dynamic)
New option documented. (-fscaffold-c) New option documented.
(-fscaffold-c++) New option documented.
gcc/m2/ChangeLog:
* Make-lang.in (stage1/m2/cc1gm2$(exeext)): M2LINK.o added.
(GM2-LIBS-BOOT-MODS) M2Dependent.mod added. (GM2-COMP-BOOT-MODS)
M2Scaffold.mod added. (GM2-LIBS-DEFS) M2Dependent.def added.
(GM2-LIBS-MODS) added. (GM2-COMP-DEFS) M2Scaffold.def added.
(GM2-COMP-MODS) M2Scaffold.mod added.
(m2/gm2-libs-boot/M2LINK.o) New rule. (stage1/m2/gm2l$(exeext))
added M2LINK.o. (stage1/m2/gm2lcc$(exeext)) added M2LINK.o
(stage1/m2/gm2lcc$(exeext)) added M2LINK.o.
(stage1/m2/gm2lgen$(exeext)) added M2LINK.o.
(stage1/m2/gm2lgen$(exeext)) added M2Link.o.
(stage1/m2/gm2lorder$(exeext)) added M2Link.o.
(stage1/m2/gm2m$(exeext)) added M2Link.o.
(MC-LIB-DEFS) M2LINK.def added. (MC-INTERFACE-C)
M2LINK.c added. (PPG-LIB-DEFS) M2Dependent.def added.
(PPG-LIB-MODS) M2Dependent.mod added.
(m2/gm2-ppg-boot/$(SRC_PREFIX)%.o) search m2/gm2-libs-boot.
(m2/ppg$(exeext)) added M2LINK.o.
(m2/gm2-pg-boot/$(SRC_PREFIX)%.o) added M2LINK.o.
(m2/gm2-pge-boot/$(SRC_PREFIX)%.o) added M2LINK.o.
* bnf/m2-1.bnf: Added production rules to record import
statements and module dependents.
* bnf/m2-2.bnf: Added production rules to record block
begin/end pairs.
* bnf/m2-3.bnf (ProgramModule): Call BuildScaffold.
(ImplementationModule) Call BuildScaffold.
* gm2-compiler/M2Base.mod: Reformatted.
* gm2-compiler/M2GCCDeclare.mod (DeclareProcedureToGcc):
Re-implemented. (DeclareModuleInit) re-implemented.
* gm2-compiler/M2GenGCC.mod (IsExportedGcc): Check IsPublic.
(CallInnerInit) get init function using GetModuleCtors
and build call to init. (CallInnerFinally) get fini
function using GetModuleCtors and build call to fini.
(CodeInitEnd) call GetModuleCtors and finish call to init.
(CodeFinallyStart) call GetModuleCtors and start function fini.
(CodeFinallyEnd) call GetModuleCtors and finish function fini.
Call DeclareM2linkGlobals to set the ScaffoldStatic and
ForcedModuleInitOrder variables in the main program.
(CodeKillLocalVar) test the procedure is a ctor if so call
DeclareModuleCtor and BuildModuleCtor.
(ConvertForComparison) Removed. (DetermineFieldOf) Removed.
* gm2-compiler/M2MetaError.mod: Added import of Storage.
* gm2-compiler/M2Options.def (ScaffoldDynamic): New procedure.
(ScaffoldStatic) New procedure. (SetScaffoldDynamic) New procedure.
(SetScaffoldStatic) New procedure. (SetScaffoldMain) New
procedure. (ScaffoldMain) New procedure.
(SetRuntimeModuleOverride) New procedure.
(GetRuntimeModuleOverride) New procedure.
* gm2-compiler/M2Options.mod: (ScaffoldDynamic): New procedure
implemented. (ScaffoldStatic) New procedure implemented.
(SetScaffoldDynamic) New procedure implemented.
(SetScaffoldStatic) New procedure implemented.
(SetScaffoldMain) New procedure implemented.
(ScaffoldMain) New procedure implemented.
(SetRuntimeModuleOverride) New procedure implemented.
(GetRuntimeModuleOverride) New procedure implemented.
* gm2-compiler/M2Quads.def (BuildScaffold) New procedure defined.
* gm2-compiler/M2Quads.mod (BuildScaffold) New procedure
implemented. (callRequestDependant) New procedure.
(ForeachImportedModuleDo) New procedure. (BuildM2DepFunction)
New procedure. (BuildM2MainFunction) New procedure.
(BuildM2InitFunction) New procedure. (BuildM2FiniFunction)
New procedure. (BuildM2CtorFunction) New procedure.
(BuildScaffold) New procedure. (GetQualidentImport) use %1a
rather than %Ea.
* gm2-compiler/P1SymBuild.def (BuildImportStatement): New
procedure definition. (AddImportToImportStatement) New
procedure definition.
* gm2-compiler/P1SymBuild.mod: (BuildImportStatement): New
procedure implementation. (AddImportToImportStatement) New
procedure implementation.
* gm2-compiler/P2SymBuild.def (BlockStart): New procedure
definition. (BlockEnd) New procedure definition.
(BlockBegin) New procedure definition. (BlockFinally)
New procedure definition.
* gm2-compiler/P2SymBuild.mod (BlockStart): New procedure
implementation. (BlockEnd) New procedure implementation.
(BlockBegin) New procedure implementation. (BlockFinally)
New procedure implementation.
* gm2-compiler/SymbolTable.def (MakeModuleCtor):
New procedure definition. (PutPublic) New procedure.
(IsPublic) New procedure. (PutCtor) New procedure.
(IsCtor) New procedure. (GetModuleCtors) New procedure.
(MakeModuleCtor) New procedure. (MakeImport) New procedure.
(MakeImportStatement) New procedure. (IsImport) New procedure.
(IsImportStatement) New procedure. (GetImportModule) New
procedure. (GetImportDeclared) New procedure.
(GetImportStatementList) New procedure.
(GetModuleDefImportStatementList) New procedure.
(GetModuleModImportStatementList) New procedure.
(AppendModuleImportStatement) New procedure.
(AppendModuleOnImportStatement) New procedure.
* gm2-compiler/SymbolTable.mod (MakeModuleCtor):
New procedure definition. (PutPublic) New procedure.
(IsPublic) New procedure. (PutCtor) New procedure.
(IsCtor) New procedure. (GetModuleCtors) New procedure.
(MakeModuleCtor) New procedure. (MakeImport) New procedure.
(MakeImportStatement) New procedure. (IsImport) New procedure.
(IsImportStatement) New procedure. (GetImportModule) New
procedure. (GetImportDeclared) New procedure.
(GetImportStatementList) New procedure.
(GetModuleDefImportStatementList) New procedure.
(GetModuleModImportStatementList) New procedure.
(AppendModuleImportStatement) New procedure.
(AppendModuleOnImportStatement) New procedure.
* gm2-gcc/m2decl.cc (DeclareM2linkGlobals) New function
implementation.
(BuildModuleCtor) New function implementation.
(DeclareModuleCtor) New function implementation.
* gm2-gcc/m2decl.def (DeclareM2linkGlobals) New function.
(BuildModuleCtor) New function. (DeclareModuleCtor)
New function.
* gm2-gcc/m2decl.h (DeclareM2linkGlobals) New function.
(BuildModuleCtor) New function. (DeclareModuleCtor)
New function.
* gm2-gcc/m2options.h (SetScaffoldStatic) New function.
(SetScaffoldDynamic) New function. (SetScaffoldMain)
New function. (SetRuntimeModuleOverride) New function.
* gm2-lang.cc (fscaffold_dynamic) Handle option.
(fscaffold_static) Handle option. (fscaffold_main)
Handle option. (fonlylink) Commented out.
* gm2-libs-iso/M2RTS.def (ConstructModules) New procedure.
(DeconstructModules) New procedure. (RegisterModule)
New procedure. (RequestDependant) New procedure.
* gm2-libs-iso/M2RTS.mod (ConstructModules) New procedure.
(DeconstructModules) New procedure. (RegisterModule)
New procedure. (RequestDependant) New procedure.
Replace termination and initial procedures using a dynamic
data structure. Call upon M2Dependent to solve module
dependencies.
* gm2-libs/M2RTS.def (ConstructModules) New procedure.
(DeconstructModules) New procedure. (RegisterModule)
New procedure. (RequestDependant) New procedure.
* gm2-libs/M2RTS.mod (ConstructModules) New procedure.
(DeconstructModules) New procedure. (RegisterModule)
New procedure. (RequestDependant) New procedure.
Replace termination and initial procedures using a dynamic
data structure. Call upon M2Dependent to solve module
dependencies.
* gm2spec.cc (check_gm2_root): Commented out.
(add_exec_prefix) Commented out. (fonlylink) Commented out.
(fmakeall) Commented out. (fmakeall0) Commented out.
(add_exec_prefix) Commented out. (lang_register_spec_functions)
body commented out.
* lang-specs.h (m2-link-support.h) no longer included.
(M2CPP) defined.
* lang.opt (fuselist) New description. (fmakelist)
New description. (fonlylink) removed. (fscaffold-static)
New option. (fscaffold-dynamic) New option. (ftarget-ranlib=)
Removed. (fscaffold-c) New option. (fscaffold-c++) New option.
(fscaffold-main) New option.
* mc-boot-ch/GM2LINK.c: New file.
* mc-boot/GAssertion.h: Rebuilt.
* mc-boot/GDynamicStrings.c: Rebuilt.
* mc-boot/GDynamicStrings.h: Rebuilt.
* mc-boot/GEnvironment.h: Rebuilt.
* mc-boot/GFIO.c: Rebuilt.
* mc-boot/GFIO.h: Rebuilt.
* mc-boot/GFormatStrings.h: Rebuilt.
* mc-boot/GIndexing.c: Rebuilt.
* mc-boot/GM2EXCEPTION.c: Rebuilt.
* mc-boot/GM2RTS.c: Rebuilt.
* mc-boot/GM2RTS.h: Rebuilt.
* mc-boot/GPushBackInput.c: Rebuilt.
* mc-boot/GRTExceptions.c: Rebuilt.
* mc-boot/GRTint.c: Rebuilt.
* mc-boot/GSYSTEM.h: Rebuilt.
* mc-boot/GStdIO.c: Rebuilt.
* mc-boot/GStringConvert.c: Rebuilt.
* mc-boot/GSysStorage.c:
* mc-boot/Gdecl.c: Rebuilt.
* mc-boot/Gkeyc.c: Rebuilt.
* mc-boot/GmcComment.c: Rebuilt.
* mc-boot/GmcComp.c: Rebuilt.
* mc-boot/GmcDebug.c: Rebuilt.
* mc-boot/GmcMetaError.c: Rebuilt.
* mc-boot/GmcStack.c: Rebuilt.
* mc-boot/GnameKey.c: Rebuilt.
* mc-boot/GsymbolKey.c: Rebuilt.
* mc/decl.mod (isLastStatement) Check if n = NIL
* mc/mcComp.mod: Change spelling to initialization.
and return FALSE.
* tools-src/makeSystem (MINIMAL): New variable.
Use MINIMAL when invoking gm2 to generate the SYSTEM exports.
libgm2/Changelog:
* libm2min/Makefile.am (libm2min_la_M2FLAGS):
Added -fno-scaffold-dynamic -fno-scaffold-main.
* libm2pim/Makefile.am (M2DEFS): Added M2LINK.def.
Signed-off-by: Gaius Mulley <gaius.mulley@southwales.ac.uk>