PR modula2/121856: New wideset implementation

The new wideset implementation uses an ARRAY OF BYTE (internally) to
represent large sets.  This replaces the huge struct of anonymous
fields created by the old implementation and results in quicker
declaration times for large set types.

gcc/ChangeLog:

	PR modula2/121856
	* doc/gm2.texi (Compiler options): New item -fwideset.

gcc/m2/ChangeLog:

	PR modula2/121856
	* Make-lang.in (GM2-LIBS-BOOT-DEFS): Add M2Diagnostic.def.
	Add Selective.def.
	(GM2-LIBS-BOOT-MODS): Add M2Diagnostic.mod.
	(GM2-LIBS-BOOT-C): Add Selective.c.
	(GM2-LIBS-DEFS): Add Selective.def.
	(GM2-LIBS-MODS): Add M2Diagnostic.mod.
	(MC-LIB-MODS): Add M2Diagnostic.mod.
	(m2/gm2-libs-boot/Selective.o): New rule.
	(BUILD-PGE-O): Add m2/pge-boot/GM2Diagnostic.o.
	Add m2/pge-boot/GM2Diagnostic.o.
	Add m2/pge-boot/GStringConvert.o.
	Add m2/pge-boot/Gdtoa.o.
	Add m2/pge-boot/Gldtoa.o.
	* Make-maintainer.in (PPG-LIB-DEFS): Add M2Diagnostic.def.
	Add StringConvert.def.
	(PPG-LIB-MODS): Add M2Diagnostic.mod.
	Add StringConvert.mod.
	(PGE-DEF): Add M2Diagnostic.def.
	(PGE-DEPS): Add GM2Diagnostic.cc.
	Add GM2Diagnostic.h.
	* gm2-compiler/FifoQueue.def (PutSetIntoFifoQueue): New
	procedure.
	(GetSetFromFifoQueue): New procedure function.
	* gm2-compiler/FifoQueue.mod (PutSetIntoFifoQueue): New
	procedure.
	(GetSetFromFifoQueue): New procedure function.
	* gm2-compiler/M2ALU.def (KillValue): New procedure.
	(PushSetTree): Rename parameter t to value.
	(ConstructSetConstant): Rewrite comment.
	* gm2-compiler/M2ALU.mod: Rewrite to use the new set type
	and introduce memory diagnostics.
	* gm2-compiler/M2Base.mod (InitBaseProcedures): Lookup M2WIDESET.
	* gm2-compiler/M2CaseList.mod (CheckCaseBoundsResolved): Change
	format specifier to allow the preceeding indefinite article to
	have a n concatenated providing the following string substitute
	begins with a vowel.
	(checkTypes): Ditto.
	* gm2-compiler/M2Check.mod (checkGenericUnboundedTyped): New
	procedure function.
	* gm2-compiler/M2Code.mod (OptimizationAnalysis): Replace with ...
	(ResourceAnalysis): ... this.
	* gm2-compiler/M2Comp.mod (PopulateResource): New procedure.
	(compile): Call PopulateResource.
	Call M2Diagnostic.Generate.
	* gm2-compiler/M2GCCDeclare.mod: Rewrite for new set type.
	* gm2-compiler/M2GenGCC.mod: Rewrite implementation for
	becomes, incl, excl, and, or, not, xor for the new set type.
	* gm2-compiler/M2MetaError.def: Extend comment documenting
	the v format specifier.
	* gm2-compiler/M2MetaError.mod (errorBlock): New field vowel.
	(initErrorBlock): Initialize field vowel.
	Reformat comments.
	(pop): Call checkVowel.
	(checkVowel): New procedure.
	(isVowel): New procedure function.
	(symDesc): Remove indefinite article.
	(op): Set vowel field in case clause.
	* gm2-compiler/M2Options.def (OptimizeSets): New global.
	(TimeReport): Ditto.
	(MemReport): Ditto.
	(SetMemReport): New procedure.
	(SetTimeReport): Ditto.
	(SetWideset): Ditto.
	(GetWideset): New procedure function.
	* gm2-compiler/M2Options.mod (SetOptimizing): Assign
	OptimizeSets depending upon the optimization level.
	(SetMemReport): New procedure.
	(SetTimeReport): Ditto.
	(SetWideset): Ditto.
	(GetWideset): New procedure function.
	(OptimizeSets): Initialize to FALSE.
	(TimeReport): Ditto.
	(MemReport): Ditto.
	* gm2-compiler/M2Quads.mod (M2Diagnostic): Import.
	(QuadsMemDiag): New global variable.
	(NewQuad): Bump QuadsMemDiag whenever a quad is allocated.
	(BuildAssignmentBoolean): New procedure.
	(doBuildAssignment): Ditto.
	Add v to the format specifier.
	(CheckCompatibleWithBecomes): Add v to the format specifier.
	(CheckProcTypeAndProcedure): Ditto.
	(BuildAddAdrFunction): Ditto.
	(BuildSubAdrFunction): Ditto.
	(BuildDifAdrFunction): Ditto.
	(BuildDesignatorArrayStaticDynamic): Ditto.
	(BuildDesignatorPointer): Ditto.
	(CheckVariableOrConstantOrProcedure): Ditto.
	(Init): Initialize QuadsMemDiag.
	* gm2-compiler/M2Range.mod (CodeTypeAssign): Add v to the
	format specifier.
	* gm2-compiler/M2Scaffold.mod (DeclareScaffoldFunctions):
	Generate more precise warning note.
	* gm2-compiler/M2SymInit.mod (PrintSymInit): Add record
	field warning.
	* gm2-compiler/M2System.mod
	(IsPseudoSystemFunctionConstExpression): Add TBitSize.
	* gm2-compiler/NameKey.mod: Add MemDiagnostic code
	commented out.
	* gm2-compiler/P1SymBuild.mod (StartBuildProcedure):
	Add v format specifier.
	* gm2-compiler/P2SymBuild.mod (BuildFieldRecord): Ditto.
	* gm2-compiler/P3Build.bnf (SetType): Reformat.
	* gm2-compiler/PathName.def (Copyright): Added.
	* gm2-compiler/PathName.mod: Remove blank line.
	* gm2-compiler/SymbolConversion.mod (gdbhook): New procedure.
	(BreakWhenSymBooked): Ditto.
	(CheckBook): Ditto.
	(Init): Rewrite.
	* gm2-compiler/SymbolTable.def (GetSetArray): New procedure.
	(PutSetArray): Ditto.
	(MakeSetArray): New procedure function.
	(PutSetInWord): New procedure.
	(GetSetInWord): New procedure function.
	(IsConstVar): Ditto.
	* gm2-compiler/SymbolTable.mod (SymSet): SetInWord new field.
	SetArray new field.
	Align new field.
	(SymMemDiag): New global variable.
	(Init): Initialize SymMemDiag.
	(IsConstVar): New procedure function.
	(IsVariableSSA): Replace InternalError with Return FALSE.
	(GetNthParamOrdered): Reimplement.
	(GetNthParamAnyClosest): Ditto.
	(GetOuterModuleScope): Ditto.
	(MakeSet): Ditto.
	(PutSetArray): New procedure.
	(GetSetArray): New procedure function.
	(MakeSetArray): Ditto.
	(PutSetInWord): New procedure.
	(GetSetInWord): New procedure function.
	* gm2-gcc/init.cc (_M2_M2Diagnostic_init): Define
	prototype.
	(init_FrontEndInit):Call _M2_M2Diagnostic_init.
	* gm2-gcc/m2block.cc (m2block_GetTotalConstants): New function.
	(m2block_GetGlobalTypes): Ditto.
	* gm2-gcc/m2block.def (GetTotalConstants): New procedure function.
	(GetGlobalTypes): New procedure function.
	* gm2-gcc/m2block.h (m2block_GetTotalConstants): New function
	prototype.
	(m2block_GetGlobalTypes): Ditto.
	* gm2-gcc/m2convert.cc (converting_ISO_generic): Reimplement.
	(m2convert_ToPIMByte): New function.
	* gm2-gcc/m2convert.def (ToLoc): New procedure function.
	(ToPIMByte): Ditto.
	* gm2-gcc/m2convert.h (m2convert_ToPIMByte): Ditto.
	* gm2-gcc/m2decl.h (m2decl_RememberVariables): Ditto.
	* gm2-gcc/m2expr.cc (m2expr_BuildLogicalShift): Reimplement.
	(m2expr_BuildLRotate): Ditto.
	(m2expr_BuildLRLn): Ditto.
	(m2expr_BuildLRRn): Ditto.
	(m2expr_BuildLogicalRotate): Ditto.
	(buildUnboundedArrayOf): Ditto.
	(BuildIfBitInSetLower): New function.
	(m2expr_BuildBinarySetDo): Reimplement.
	(m2expr_BuildIfInSet): Ditto.
	(m2expr_BuildIfNotInSet): New function.
	(m2expr_Build4LogicalOr): Reimplement.
	(m2expr_BuildSetNegate): Ditto.
	(m2expr_BuildLogicalOrAddress): Ditto.
	(m2expr_BuildLogicalOr): Ditto.
	(m2expr_BuildLogicalAnd): Ditto.
	(m2expr_BuildSymmetricDifference): Ditto.
	(m2expr_BuildLogicalDifference): Ditto.
	(boolean_enum_to_unsigned): Ditto.
	(m2expr_BuildIsSuperset): Ditto.
	(m2expr_BuildIsNotSuperset): Ditto.
	(m2expr_BuildIsSubset): Ditto.
	(m2expr_BuildIfBitInSetJump): Ditto.
	(m2expr_BuildIfNotConstInVar): Ditto.
	(m2expr_BuildIfVarInVar): Ditto.
	(m2expr_BuildIfNotVarInVar): Remove.
	(m2expr_BuildIfConstInVar): Remove.
	(m2expr_BuildForeachWordInSetDoIfExpr): Ditto.
	(m2expr_BuildBinaryForeachWordDo): Ditto.
	(m2expr_BuildIfInRangeGoto): Reimplement.
	(m2expr_BuildIfNotInRangeGoto): Ditto.
	(m2expr_SetAndNarrow): Ditto.
	(m2expr_GetBitsetZero): New function.
	(m2expr_GetRValue): Ditto.
	* gm2-gcc/m2expr.def (GetBitsetZero): New function.
	(BuildSetNegate): Ditto.
	(BuildLogicalOr): Reimplement.
	(BuildLogicalAnd): Ditto.
	(BuildSymmetricDifference): Ditto.
	(BuildLogicalDifference): Ditto.
	(BuildIfInSet): New procedure function.
	(BuildIfNotInSet): Ditto.
	(BuildEqualTo): Reimplement.
	(BuildNotEqualTo): Ditto.
	(BuildBinaryForeachWordDo): Remove.
	(BuildBinarySetDo): Ditto.
	(GetRValue): New procedure function.
	* gm2-gcc/m2expr.h (m2expr_BuildBinaryForeachWordDo): Remove.
	(m2expr_BuildForeachWordInSetDoIfExpr): Ditto.
	(m2expr_BuildIfNotVarInVar): Ditto.
	(m2expr_BuildIfVarInVar): Ditto.
	(m2expr_BuildIfNotConstInVar): Ditto.
	(m2expr_BuildIfConstInVar): Ditto.
	(m2expr_BuildLogicalDifference): Reimplement.
	(m2expr_BuildSymmetricDifference): Ditto.
	(m2expr_BuildLogicalAnd): Ditto.
	(m2expr_BuildLogicalOr): Ditto.
	(m2expr_BuildLogicalOrAddress): Ditto.
	(m2expr_BuildSetNegate): Ditto.
	(m2expr_GetBitsetZero): New function.
	(m2expr_GetRValue): Ditto.
	(m2expr_BuildIfInSet): Ditto.
	(m2expr_BuildIfNotInSet): Ditto.
	* gm2-gcc/m2options.h (M2Options_SetTimeReport): New function.
	(M2Options_SetMemReport): Ditto.
	(M2Options_SetWideset): Ditto.
	(M2Options_GetWideset): Ditto.
	* gm2-gcc/m2pp.cc (m2pp_shiftrotate_expr): New function.
	(m2pp_simple_expression): Ditto.
	* gm2-gcc/m2statement.cc (m2statement_BuildStartFunctionCode):
	Tidyup comments.
	(m2statement_BuildEndFunctionCode): Ditto.
	(m2statement_BuildPushFunctionContext): Ditto.
	(copy_array): Ditto.
	(CopyByField_Lower): Ditto.
	(m2statement_BuildGoto): Ditto.
	(m2statement_DeclareLabel): Ditto.
	(m2statement_BuildParam): Ditto.
	(nCount): Ditto.
	(m2statement_BuildProcedureCallTree): Ditto.
	(m2statement_BuildBuiltinCallTree): Ditto.
	(m2statement_BuildFunctValue): Ditto.
	(m2statement_BuildCall2): Ditto.
	(m2statement_BuildCall3): Ditto.
	(m2statement_BuildFunctionCallTree): Ditto.
	(m2statement_SetLastFunction): Ditto.
	(m2statement_SetParamList): Ditto.
	(m2statement_GetLastFunction): Ditto.
	(m2statement_GetParamList): Ditto.
	(m2statement_GetCurrentFunction): Ditto.
	(m2statement_GetParamTree): Ditto.
	(m2statement_BuildTryFinally): Ditto.
	(m2statement_BuildCleanUp): Ditto.
	(m2statement_BuildUnaryForeachWordDo): Remove.
	(m2statement_BuildExcludeVarConst): Ditto.
	(m2statement_BuildExcludeVarVar): Ditto.
	(m2statement_BuildIncludeVarConst): Ditto.
	(m2statement_BuildIncludeVarVar): Ditto.
	(m2statement_DoJump): Remove.
	(m2statement_IfExprJump): New function.
	(m2statement_IfBitInSetJump): Ditto.
	* gm2-gcc/m2statement.def (DoJump): Remove.
	(IfExprJump): New procedure function.
	(BuildUnaryForeachWordDo): Remove.
	(IfBitInSetJump): New procedure function.
	* gm2-gcc/m2statement.h (m2statement_BuildForeachWordDo): Remove.
	(m2statement_DoJump): Ditto.
	(m2statement_IfExprJump): New function.
	(m2statement_IfBitInSetJump): Ditto.
	* gm2-gcc/m2treelib.cc (m2treelib_do_jump_if_bit): Reimplement.
	(nCount): Replace with ...
	(m2treelib_nCount): ... this.
	(m2treelib_DoCall): Reimplement.
	(m2treelib_get_rvalue): Remove.
	* gm2-gcc/m2treelib.def (get_rvalue): Remove.
	(nCount): New procedure function.
	* gm2-gcc/m2treelib.h (m2treelib_get_rvalue): Remove.
	(m2treelib_nCount): New function.
	* gm2-gcc/m2type.cc (constructor_elements): Change type to vec.
	(m2type_BuildEndArrayType): Reformat.
	(build_m2_type_node_by_array): Ditto.
	(m2type_GetBooleanEnumList): New procedure function.
	(m2type_BuildEnumerator): Add const to char *.
	(m2type_BuildSetConstructorElement): Reimplement.
	(m2type_BuildEndSetConstructor): Ditto.
	(build_record_constructor): New function.
	(m2type_BuildEndRecordConstructor): Reimplement.
	(m2type_BuildRecordConstructorElement): Ditto.
	(m2type_BuildStartArrayConstructor): Reimplement.
	(m2type_BuildEndArrayConstructor): Remove blank lines.
	* gm2-gcc/m2type.def (BuildSetConstructorElement): Reimplement.
	(BuildEndArrayType): Reformat.
	(GetBooleanEnumList): New function.
	* gm2-gcc/m2type.h (m2type_BuildEnumerator): Add const to char *.
	(m2type_BuildSetConstructorElement): Reimplement.
	(m2type_GetBooleanEnumList): New procedure function.
	* gm2-lang.cc (OPT_fmem_report): New option.
	(OPT_ftime_report): Ditto.
	(OPT_fwideset): Ditto.
	* gm2-libs-coroutines/SYSTEM.def (ShiftVal): Remove.
	(ShiftLeft): Ditto.
	(ShiftRight): Ditto.
	(RotateVal): Ditto.
	(RotateLeft): Ditto.
	(RotateRight): Ditto.
	* gm2-libs-coroutines/SYSTEM.mod: Reimplement.
	* gm2-libs-iso/SYSTEM.def (ShiftVal): Remove.
	(ShiftLeft): Ditto.
	(ShiftRight): Ditto.
	(RotateVal): Ditto.
	(RotateLeft): Ditto.
	(RotateRight): Ditto.
	* gm2-libs-iso/SYSTEM.mod: Reimplement.
	* gm2-libs/SYSTEM.def (ShiftVal): Remove.
	(ShiftLeft): Ditto.
	(ShiftRight): Ditto.
	(RotateVal): Ditto.
	(RotateLeft): Ditto.
	(RotateRight): Ditto.
	* gm2-libs/SYSTEM.mod: Reimplement.
	* gm2-libs/SysStorage.def (DEALLOCATE): Improve comment.
	* gm2-libs/SysStorage.mod: Improve comment.
	* init/ppginit (M2Diagnostic): Add.
	(StringConvert): Add.
	* lang.opt (fmem-report): Add access to c.opt.
	(ftime-report): Ditto.
	(fwideset): New option.
	* pge-boot/main.cc (_M2_M2Diagnostic_init): New function.
	(_M2_M2Diagnostic_fini): Ditto.
	(_M2_StringConvert_init): Ditto.
	(_M2_StringConvert_fini): Ditto.
	(main): Call _M2_M2Diagnostic_init.
	Call _M2_StringConvert_init.
	Call _M2_M2Diagnostic_fini.
	Call _M2_StringConvert_fini.
	* tools-src/makeSystem: Add -gdb option.
	* gm2-libs/M2Diagnostic.def: New file.
	* gm2-libs/M2Diagnostic.mod: New file.
	* gm2-libs/M2WIDESET.def: New file.
	* gm2-libs/M2WIDESET.mod: New file.
	* mc-boot/GM2Diagnostic.cc: New file.
	* mc-boot/GM2Diagnostic.h: New file.
	* pge-boot/GM2Diagnostic.cc: New file.
	* pge-boot/GM2Diagnostic.h: New file.
	* pge-boot/GSelective.h: New file.
	* pge-boot/GStringConvert.cc: New file.

libgm2/ChangeLog:

	* libm2pim/Makefile.am (M2MODS): Add M2Diagnostic.mod.
	Add M2WIDESET.mod.
	(M2DEFS): Add M2Diagnostic.def.
	Add M2WIDESET.def.
	* libm2pim/Makefile.in: Regenerate.

gcc/testsuite/ChangeLog:

	* gm2/errors/fail/testbit2.mod: Rewrite.
	* gm2/iso/run/pass/shift4.mod: Rewrite adding more internal
	tests.
	* gm2/iso/run/pass/testsystem.mod (FindFirstElement): Add
	bounds check.
	* gm2/sets/run/pass/multisetrotate4.mod: Add more runtime
	error messages.
	* gm2/sets/run/pass/simplepacked.mod (testpset): Correct
	setname.
	* lib/gm2.exp (gm2_init_minx): Add -fno-wideset.
	* gm2/iso/run/pass/assigncons.mod: New test.
	* gm2/iso/run/pass/constructor3.mod: New test.
	* gm2/iso/run/pass/proc_test.mod: New test.
	* gm2/iso/run/pass/simplelarge2.mod: New test.
	* gm2/iso/run/pass/simplelarge3.mod: New test.
	* gm2/iso/run/pass/simplelarge4.mod: New test.
	* gm2/pimlib/wideset/run/pass/bitset.mod: New test.
	* gm2/pimlib/wideset/run/pass/bitset2.mod: New test.
	* gm2/pimlib/wideset/run/pass/colorset.mod: New test.
	* gm2/pimlib/wideset/run/pass/colorset2.mod: New test.
	* gm2/pimlib/wideset/run/pass/colorset3.mod: New test.
	* gm2/pimlib/wideset/run/pass/highbit.mod: New test.
	* gm2/pimlib/wideset/run/pass/highbit2.mod: New test.
	* gm2/sets/run/pass/multisetrotate5.mod: New test.
	* gm2/sets/run/pass/setcard.mod: New test.
	* gm2/sets/run/pass/setincl.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
This commit is contained in:
Gaius Mulley
2025-09-19 17:26:18 +01:00
parent cc0959221e
commit 273b53effb
101 changed files with 12535 additions and 3514 deletions
+6
View File
@@ -723,6 +723,12 @@ The option @samp{-Wall} will turn on this flag with
@samp{-Wuninit-variable-checking=known}.
The @samp{-Wuninit-variable-checking=all} will increase compile time.
@item -fwideset
turn on access to the runtime support library module @samp{M2WIDESET}.
By default this option is on.
Wideset provision can be disabled by @samp{-fno-wideset}
and no reference will be made to the run time @samp{M2WIDESET} library.
@c the following warning options are complete but need to be
@c regression tested against all other front ends
@c to ensure the options do not conflict.
+20
View File
@@ -681,6 +681,7 @@ GM2-LIBS-BOOT-DEFS = \
IO.def \
Indexing.def \
M2Dependent.def \
M2Diagnostic.def \
M2EXCEPTION.def \
M2RTS.def \
NumberIO.def \
@@ -690,6 +691,7 @@ GM2-LIBS-BOOT-DEFS = \
SEnvironment.def \
SFIO.def \
SYSTEM.def \
Selective.def \
Scan.def \
StdIO.def \
Storage.def \
@@ -726,6 +728,7 @@ GM2-LIBS-BOOT-MODS = \
IO.mod \
Indexing.mod \
M2Dependent.mod \
M2Diagnostic.mod \
M2EXCEPTION.mod \
M2RTS.mod \
NumberIO.mod \
@@ -747,6 +750,7 @@ GM2-LIBS-BOOT-MODS = \
# found in gm2-libs-ch.
GM2-LIBS-BOOT-C = \
Selective.c \
StdIO.c \
SysExceptions.c \
choosetemp.c \
@@ -954,6 +958,7 @@ GM2-LIBS-DEFS = \
LMathLib0.def \
LegacyReal.def \
M2Dependent.def \
M2Diagnostic.def \
M2EXCEPTION.def \
M2RTS.def \
MathLib0.def \
@@ -968,6 +973,7 @@ GM2-LIBS-DEFS = \
SMathLib0.def \
SYSTEM.def \
Scan.def \
Selective.def \
StdIO.def \
Storage.def \
StrCase.def \
@@ -1006,6 +1012,7 @@ GM2-LIBS-MODS = \
LMathLib0.mod \
LegacyReal.mod \
M2Dependent.mod \
M2Diagnostic.mod \
M2EXCEPTION.mod \
M2RTS.mod \
MathLib0.mod \
@@ -1246,6 +1253,7 @@ MC-LIB-DEFS = \
FpuIO.def \
IO.def \
M2Dependent.def \
M2Diagnostic.def \
M2EXCEPTION.def \
M2RTS.def \
MemUtils.def \
@@ -1293,6 +1301,7 @@ MC-LIB-MODS = \
FpuIO.mod \
IO.mod \
M2Dependent.mod \
M2Diagnostic.mod \
M2EXCEPTION.mod \
M2RTS.mod \
MemUtils.mod \
@@ -1558,6 +1567,12 @@ m2/gm2-libs-boot/SysStorage.o: $(srcdir)/m2/gm2-libs/SysStorage.mod $(MCDEPS) $(
m2/gm2-libs-boot/SysStorage.c -o m2/gm2-libs-boot/SysStorage.o
$(POSTCOMPILE)
m2/gm2-libs-boot/Selective.o: $(srcdir)/m2/gm2-libs-ch/Selective.c \
m2/gm2-libs-boot/$(SRC_PREFIX)Selective.h m2/gm2-libs/gm2-libs-host.h
-test -d $(@D)/$(DEPDIR) || $(mkinstalldirs) $(@D)/$(DEPDIR)
$(CXX) $(CM2DEP) -c $(CFLAGS) $(GM2_PICFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
$(POSTCOMPILE)
m2/gm2-compiler-boot/M2GCCDeclare.o: $(srcdir)/m2/gm2-compiler/M2GCCDeclare.mod $(MCDEPS) $(BUILD-BOOT-H)
-test -d $(@D)/$(DEPDIR) || $(mkinstalldirs) $(@D)/$(DEPDIR)
$(MC) $(MC_EXTENDED_OPAQUE) -o=m2/gm2-compiler-boot/M2GCCDeclare.c $<
@@ -1873,6 +1888,7 @@ BUILD-PGE-O = \
m2/pge-boot/GIO.o \
m2/pge-boot/GLists.o \
m2/pge-boot/GM2Dependent.o \
m2/pge-boot/GM2Diagnostic.o \
m2/pge-boot/GM2EXCEPTION.o \
m2/pge-boot/GM2RTS.o \
m2/pge-boot/GNameKey.o \
@@ -1882,9 +1898,11 @@ BUILD-PGE-O = \
m2/pge-boot/GPushBackInput.o \
m2/pge-boot/GRTExceptions.o \
m2/pge-boot/GSFIO.o \
m2/pge-boot/GSelective.o \
m2/pge-boot/GStdIO.o \
m2/pge-boot/GStorage.o \
m2/pge-boot/GStrCase.o \
m2/pge-boot/GStringConvert.o \
m2/pge-boot/GStrIO.o \
m2/pge-boot/GStrLib.o \
m2/pge-boot/GSymbolKey.o \
@@ -1896,6 +1914,8 @@ BUILD-PGE-O = \
m2/pge-boot/Gtermios.o \
m2/pge-boot/GSysExceptions.o \
m2/pge-boot/Gabort.o \
m2/pge-boot/Gdtoa.o \
m2/pge-boot/Gldtoa.o \
m2/pge-boot/Gmcrts.o \
m2/pge-boot/main.o
+7 -1
View File
@@ -41,10 +41,11 @@ PPG-DEFS = SymbolKey.def NameKey.def Lists.def bnflex.def Output.de
PPG-LIB-DEFS = Args.def Assertion.def ASCII.def Debug.def \
DynamicStrings.def FIO.def Indexing.def IO.def \
NumberIO.def PushBackInput.def \
M2Dependent.def \
M2Dependent.def M2Diagnostic.def \
M2EXCEPTION.def M2RTS.def \
RTExceptions.def \
StdIO.def SFIO.def StrIO.def StrLib.def \
StringConvert.def \
Storage.def StrCase.def SysStorage.def
# Core library implementation modules used by ppg found in the gm2-libs directory.
@@ -58,6 +59,7 @@ PPG-LIB-MODS = ASCII.mod \
IO.mod \
Indexing.mod \
M2Dependent.mod \
M2Diagnostic.mod \
M2EXCEPTION.mod \
M2RTS.mod \
NumberIO.mod \
@@ -69,6 +71,7 @@ PPG-LIB-MODS = ASCII.mod \
StrCase.mod \
StrIO.mod \
StrLib.mod \
StringConvert.mod \
SysStorage.mod
# Program module ppg.mod from which pge.mod is created. ppg.mod is
@@ -96,6 +99,7 @@ PGE-DEF = ASCII.def \
FpuIO.def \
IO.def \
M2Dependent.def \
M2Diagnostic.def \
M2EXCEPTION.def \
M2RTS.def \
MemUtils.def \
@@ -169,6 +173,8 @@ PGE-DEPS = Gabort.cc \
GLists.h \
GM2Dependent.cc \
GM2Dependent.h \
GM2Diagnostic.cc \
GM2Diagnostic.h \
GM2EXCEPTION.cc \
GM2EXCEPTION.h \
GM2RTS.cc \
+17 -7
View File
@@ -25,15 +25,25 @@ DEFINITION MODULE FifoQueue ;
Author : Gaius Mulley
Title : FifoQueue
Date : Tue Dec 12 16:23:22 GMT 1989
Description: FifoQueue provides a mechanism to and from which CARDINAL
numbers can be stored and retrieved from a FIFO queue.
Last update: Tue Dec 12 16:24:24 GMT 1989
Description: FifoQueue provides a fifo mechanism to allow symbols to be
stored and retrieved between passes in the same order.
*)
EXPORT QUALIFIED PutEnumerationIntoFifoQueue, GetEnumerationFromFifoQueue,
PutSubrangeIntoFifoQueue, GetSubrangeFromFifoQueue,
PutConstIntoFifoQueue, GetConstFromFifoQueue,
PutConstructorIntoFifoQueue, GetConstructorFromFifoQueue ;
(*
PutSetIntoFifoQueue - places a set symbol
into a fifo queue.
*)
PROCEDURE PutSetIntoFifoQueue (c: CARDINAL) ;
(*
GetSetFromFifoQueue - retrieves a set symbol
from a fifo queue.
*)
PROCEDURE GetSetFromFifoQueue (VAR c: CARDINAL) ;
(*
+24
View File
@@ -31,6 +31,7 @@ TYPE
VAR
const,
set,
subrange,
enumeration,
constructor: Fifo ;
@@ -149,6 +150,28 @@ BEGIN
END GetConstFromFifoQueue ;
(*
PutSetIntoFifoQueue - places a set symbol
into a fifo queue.
*)
PROCEDURE PutSetIntoFifoQueue (c: CARDINAL) ;
BEGIN
PutInto (set, c)
END PutSetIntoFifoQueue ;
(*
GetSetFromFifoQueue - retrieves a set symbol
from a fifo queue.
*)
PROCEDURE GetSetFromFifoQueue (VAR c: CARDINAL) ;
BEGIN
GetFrom (set, c)
END GetSetFromFifoQueue ;
(*
Init - initialize the fifo queue.
*)
@@ -164,6 +187,7 @@ END Init ;
BEGIN
Init(const) ;
Init(set) ;
Init(enumeration) ;
Init(subrange) ;
Init(constructor)
+10 -50
View File
@@ -35,52 +35,6 @@ FROM NameKey IMPORT Name ;
FROM M2GCCDeclare IMPORT WalkAction, IsAction ;
FROM gcctypes IMPORT tree ;
EXPORT QUALIFIED PtrToValue,
InitValue,
IsValueTypeNone,
IsValueTypeInteger,
IsValueTypeReal,
IsValueTypeComplex,
IsValueTypeSet,
IsValueTypeConstructor,
IsValueTypeArray,
IsValueTypeRecord,
PopInto, PushFrom,
PushIntegerTree, PopIntegerTree,
PushSetTree, PopSetTree,
PushRealTree, PopRealTree,
PushComplexTree, PopComplexTree,
PopConstructorTree,
PopChar,
PushCard,
PushInt,
PushChar,
PushString,
PushTypeOfTree,
CoerseLongRealToCard,
ConvertRealToInt,
ConvertToInt,
ConvertToType,
GetSetValueType,
IsSolved, IsValueConst,
PutConstructorSolved, EvaluateValue, TryEvaluateValue,
IsNulSet, IsGenericNulSet, PushNulSet, AddBitRange, AddBit, SubBit,
SetOr, SetAnd, SetIn,
SetDifference, SetSymmetricDifference,
SetNegate, SetShift, SetRotate,
Addn, Multn, Sub,
DivFloor, ModFloor, DivTrunc, ModTrunc,
Equ, NotEqu, Less, Gre, LessEqu, GreEqu,
GetValue, GetRange, ConstructSetConstant, BuildRange,
IsConstructorDependants, WalkConstructorDependants,
AddField, AddElements,
PushEmptyConstructor, PushEmptyArray, PushEmptyRecord,
ChangeToConstructor,
IsValueAndTreeKnown, CheckOrResetOverflow ;
TYPE
PtrToValue ;
@@ -93,6 +47,13 @@ TYPE
PROCEDURE InitValue () : PtrToValue ;
(*
KillValue - deconstructor for value. value is set to NIL upon return.
*)
PROCEDURE KillValue (VAR value: PtrToValue) ;
(*
IsValueTypeNone - returns TRUE if the value on the top stack has no value.
*)
@@ -208,8 +169,7 @@ PROCEDURE PopComplexTree () : tree ;
type (sym). Bit 0 maps onto MIN(sym).
*)
PROCEDURE PushSetTree (tokenno: CARDINAL;
t: tree; sym: CARDINAL) ;
PROCEDURE PushSetTree (tokenno: CARDINAL; value: tree; sym: CARDINAL) ;
(*
@@ -828,8 +788,8 @@ PROCEDURE GetRange (v: PtrToValue; n: CARDINAL; VAR low, high: CARDINAL) : BOOLE
(*
ConstructSetConstant - builds a struct of integers which represents the
set const, sym.
ConstructSetConstant - builds an array of BYTE which represents the
set const symbol.
*)
PROCEDURE ConstructSetConstant (tokenno: CARDINAL; v: PtrToValue) : tree ;
+184 -127
View File
@@ -52,7 +52,7 @@ FROM M2MetaError IMPORT MetaError0, MetaError1, MetaError2, MetaErrorStringT0,
FROM SymbolTable IMPORT NulSym, IsEnumeration, IsSubrange, IsValueSolved, PushValue,
ForeachFieldEnumerationDo, MakeTemporary, PutVar, PopValue, GetType,
MakeConstLit, GetArraySubscript,
MakeConstLit, GetArraySubscript, GetSetInWord,
IsSet, SkipType, IsRecord, IsArray, IsConst, IsConstructor,
IsConstString, SkipTypeAndSubrange, GetDeclaredMod,
GetSubrange, GetSymName, GetNth, GetString, GetStringLength,
@@ -70,7 +70,7 @@ FROM m2expr IMPORT BuildAdd, BuildSub, BuildMult,
GetWordOne, GetCardinalZero, TreeOverflow, RemoveOverflow,
GetCstInteger ;
FROM m2decl IMPORT GetBitsPerBitset, BuildIntegerConstant, BuildConstLiteralNumber ;
FROM m2decl IMPORT GetBitsPerUnit, GetBitsPerBitset, BuildIntegerConstant, BuildConstLiteralNumber ;
FROM m2misc IMPORT DebugTree ;
FROM m2type IMPORT RealToTree, Constructor, GetIntegerType, GetLongRealType,
@@ -80,12 +80,17 @@ FROM m2type IMPORT RealToTree, Constructor, GetIntegerType, GetLongRealType,
BuildArrayConstructorElement, BuildStartArrayConstructor, BuildEndArrayConstructor,
GetM2CharType ;
FROM m2convert IMPORT ConvertConstantAndCheck, ToWord, ToInteger, ToCardinal, ToBitset ;
FROM m2convert IMPORT ConvertConstantAndCheck, ToWord, ToInteger, ToCardinal,
ToBitset, ToLoc, ToPIMByte, BuildConvert ;
FROM m2block IMPORT RememberConstant ;
FROM m2expr IMPORT GetPointerZero, GetIntegerZero, GetIntegerOne,
CompareTrees, FoldAndStrip, AreRealOrComplexConstantsEqual, AreConstantsEqual ;
FROM M2Diagnostic IMPORT Diagnostic, InitMemDiagnostic, MemIncr, MemSet ;
TYPE
cellType = (none, integer, real, complex, set, constructor, array, record) ;
@@ -150,6 +155,9 @@ VAR
EnumerationField: CARDINAL ;
CurrentTokenNo : CARDINAL ;
(* WatchedValue : PtrToValue ; *)
StackMemDiag : Diagnostic ; (* Contains memory related statistics *)
RangeMemDiag : Diagnostic ; (* Contains memory related statistics *)
(*
@@ -162,7 +170,9 @@ VAR
BEGIN
IF FreeList=NIL
THEN
NEW (v)
NEW (v) ;
MemIncr (StackMemDiag, 1, 1) ;
MemIncr (StackMemDiag, 2, SIZE (v^))
ELSE
v := FreeList ;
FreeList := FreeList^.next
@@ -203,7 +213,9 @@ BEGIN
IF v=NIL
THEN
InternalError ('out of memory error')
END
END ;
MemIncr (RangeMemDiag, 1, 1) ;
MemIncr (RangeMemDiag, 2, SIZE (v^))
ELSE
v := RangeFreeList ;
RangeFreeList := RangeFreeList^.next
@@ -490,6 +502,17 @@ BEGIN
END InitValue ;
(*
KillValue - deconstructor for value. value is set to NIL upon return.
*)
PROCEDURE KillValue (VAR value: PtrToValue) ;
BEGIN
Dispose (value) ;
value := NIL
END KillValue ;
(*
IsValueTypeNone - returns TRUE if the value on the top stack has no value.
*)
@@ -818,49 +841,48 @@ END PopComplexTree ;
(*
PushSetTree - pushes a gcc tree onto the ALU stack.
The tree, t, is expected to contain a
word value. It is converted into a set
type (sym). Bit 0 maps onto MIN(sym).
The tree value is expected to contain a
word sized or less value. It is converted into a set
type (sym). Bit 0 maps onto MIN (sym).
*)
PROCEDURE PushSetTree (tokenno: CARDINAL;
t: tree; sym: CARDINAL) ;
value: tree; sym: CARDINAL) ;
VAR
v: PtrToValue ;
c,
i: INTEGER ;
r: listOfRange ;
l: location_t ;
newVal: PtrToValue ;
c, i : INTEGER ;
range : listOfRange ;
loc : location_t ;
BEGIN
l := TokenToLocation(tokenno) ;
r := NIL ;
loc := TokenToLocation (tokenno) ;
range := NIL ;
i := 0 ;
WHILE (i<GetBitsPerBitset()) AND
(CompareTrees(GetIntegerZero(l), t)#0) DO
IF CompareTrees(GetIntegerOne(l),
BuildLogicalAnd(l, t, GetIntegerOne(l), FALSE))=0
WHILE (i < GetBitsPerBitset ()) AND
(CompareTrees (GetIntegerZero (loc), value) # 0) DO
IF CompareTrees (GetIntegerOne (loc),
BuildLogicalAnd (loc, value, GetIntegerOne (loc))) = 0
THEN
PushCard(i) ;
c := Val(tokenno, SkipType(sym), PopIntegerTree()) ;
DeclareConstant(tokenno, c) ;
r := AddRange(r, c, c)
PushCard (i) ;
c := Val (tokenno, SkipType (sym), PopIntegerTree ()) ;
DeclareConstant (tokenno, c) ;
range := AddRange (range, c, c)
END ;
t := BuildLSR(l, t, GetIntegerOne(l), FALSE) ;
INC(i)
value := BuildLSR (loc, value, GetIntegerOne (loc), FALSE) ;
INC (i)
END ;
SortElements(tokenno, r) ;
CombineElements(tokenno, r) ;
v := New() ;
WITH v^ DO
location := l ;
SortElements (tokenno, range) ;
CombineElements (tokenno, range) ;
newVal := New () ;
WITH newVal^ DO
location := loc ;
type := set ;
constructorType := sym ;
areAllConstants := FALSE ;
solved := FALSE ;
setValue := r
setValue := range
END ;
Eval(tokenno, v) ;
Push(v)
Eval (tokenno, newVal) ;
Push (newVal)
END PushSetTree ;
@@ -1393,7 +1415,6 @@ BEGIN
END ConvertToType ;
(*
IsSolved - returns true if the memory cell indicated by v
has a known value.
@@ -4396,70 +4417,6 @@ BEGIN
END GetRange ;
(*
BuildStructBitset - v is the PtrToValue.
low and high are the limits of the subrange.
*)
PROCEDURE BuildStructBitset (tokenno: CARDINAL; v: PtrToValue; low, high: tree) : tree ;
VAR
BitsInSet : tree ;
bpw : CARDINAL ;
cons : Constructor ;
BEGIN
PushIntegerTree(low) ;
ConvertToInt ;
low := PopIntegerTree() ;
PushIntegerTree(high) ;
ConvertToInt ;
high := PopIntegerTree() ;
bpw := GetBitsPerBitset() ;
PushIntegerTree(high) ;
PushIntegerTree(low) ;
Sub ;
PushCard(1) ;
Addn ;
BitsInSet := PopIntegerTree() ;
cons := BuildStartSetConstructor(Mod2Gcc(v^.constructorType)) ;
PushIntegerTree(BitsInSet) ;
PushCard(0) ;
WHILE Gre(tokenno) DO
PushIntegerTree(BitsInSet) ;
PushCard(bpw-1) ;
IF GreEqu(tokenno)
THEN
PushIntegerTree(low) ;
PushCard(bpw-1) ;
Addn ;
BuildSetConstructorElement(cons, BuildBitset(tokenno, v, low, PopIntegerTree())) ;
PushIntegerTree(low) ;
PushCard(bpw) ;
Addn ;
low := PopIntegerTree() ;
PushIntegerTree(BitsInSet) ;
PushCard(bpw) ;
Sub ;
BitsInSet := PopIntegerTree()
ELSE
(* printf2('range is %a..%a\n', GetSymName(low), GetSymName(high)) ; *)
BuildSetConstructorElement(cons, BuildBitset(tokenno, v, low, high)) ;
PushCard(0) ;
BitsInSet := PopIntegerTree()
END ;
PushIntegerTree(BitsInSet) ;
PushCard(0)
END ;
RETURN( BuildEndSetConstructor(cons) )
END BuildStructBitset ;
(*
ConstructLargeOrSmallSet - generates a constant representing the set value of the symbol, sym.
We manufacture the constant by using a initialization
@@ -4469,35 +4426,98 @@ END BuildStructBitset ;
*)
PROCEDURE ConstructLargeOrSmallSet (tokenno: CARDINAL; v: PtrToValue; low, high: CARDINAL) : tree ;
VAR
settype: CARDINAL ;
BEGIN
PushValue(high) ;
ConvertToInt ;
PushValue(low) ;
ConvertToInt ;
Sub ;
PushCard(GetBitsPerBitset()) ;
IF Less(tokenno)
Assert (v^.constructorType # NulSym) ;
settype := SkipType (v^.constructorType) ;
Assert (IsSet (settype)) ;
IF GetSetInWord (settype)
THEN
(* small set *)
RETURN( BuildBitset(tokenno, v, Mod2Gcc(low), Mod2Gcc(high)) )
(* Narrow set. *)
RETURN BuildConvert (TokenToLocation (tokenno),
Mod2Gcc (settype),
BuildBitset (tokenno, v, Mod2Gcc (low), Mod2Gcc (high)),
FALSE)
ELSE
(* large set *)
RETURN( BuildStructBitset(tokenno, v, Mod2Gcc(low), Mod2Gcc(high)) )
(* Wide set. *)
RETURN BuildArrayByteset (tokenno, v, Mod2Gcc (low), Mod2Gcc (high))
END
END ConstructLargeOrSmallSet ;
(*
ConstructSetConstant - builds a struct of integers which represents the
set const as defined by, v.
BuildArrayByteset - v is the PtrToValue.
low and high are the limits of the subrange.
*)
PROCEDURE BuildArrayByteset (tokenno: CARDINAL; v: PtrToValue; low, high: tree) : tree ;
VAR
location : location_t ;
BitsInSet : tree ;
BitsPerByte: CARDINAL ;
cons : Constructor ;
BEGIN
location := TokenToLocation (tokenno) ;
PushIntegerTree (low) ;
ConvertToInt ;
low := PopIntegerTree () ;
PushIntegerTree (high) ;
ConvertToInt ;
high := PopIntegerTree () ;
BitsPerByte := GetBitsPerUnit () ;
PushIntegerTree (high) ;
PushIntegerTree (low) ;
Sub ;
PushCard (1) ;
Addn ;
BitsInSet := PopIntegerTree () ;
cons := BuildStartSetConstructor (Mod2Gcc (v^.constructorType)) ;
PushIntegerTree (BitsInSet) ;
PushCard (0) ;
WHILE Gre (tokenno) DO
PushIntegerTree (BitsInSet) ;
PushCard (BitsPerByte - 1) ;
IF GreEqu (tokenno)
THEN
PushIntegerTree (low) ;
PushCard (BitsPerByte - 1) ;
Addn ;
BuildSetConstructorElement (location,
cons, BuildByte (tokenno, v, low, PopIntegerTree ())) ;
PushIntegerTree (low) ;
PushCard (BitsPerByte) ;
Addn ;
low := PopIntegerTree () ;
PushIntegerTree (BitsInSet) ;
PushCard (BitsPerByte) ;
Sub ;
BitsInSet := PopIntegerTree ()
ELSE
BuildSetConstructorElement (location,
cons, BuildByte (tokenno, v, low, high)) ;
PushCard (0) ;
BitsInSet := PopIntegerTree ()
END ;
PushIntegerTree (BitsInSet) ;
PushCard (0)
END ;
RETURN BuildEndSetConstructor (cons)
END BuildArrayByteset ;
(*
ConstructSetConstant - builds an array of bytes which represents the
set const as defined by v.
*)
PROCEDURE ConstructSetConstant (tokenno: CARDINAL; v: PtrToValue) : tree ;
VAR
n1, n2 : Name ;
gccsym : tree ;
baseType,
high, low: CARDINAL ;
baseType: CARDINAL ;
BEGIN
WITH v^ DO
IF constructorType=NulSym
@@ -4511,14 +4531,7 @@ BEGIN
n2 := GetSymName(baseType) ;
printf2('ConstructSetConstant of type %a and baseType %a\n', n1, n2)
END ;
IF IsSubrange(baseType)
THEN
GetSubrange(baseType, high, low) ;
gccsym := ConstructLargeOrSmallSet(tokenno, v, low, high)
ELSE
gccsym := ConstructLargeOrSmallSet(tokenno, v, GetTypeMin(baseType), GetTypeMax(baseType))
END ;
RETURN( gccsym )
RETURN ConstructLargeOrSmallSet (tokenno, v, GetTypeMin (baseType), GetTypeMax (baseType))
END
END
END ConstructSetConstant ;
@@ -5074,7 +5087,7 @@ BEGIN
THEN
t := BuildLSL(location, GetWordOne(location), ToWord(location, i), FALSE)
ELSE
t := BuildLogicalOr(location, t, BuildLSL(location, GetWordOne(location), ToWord(location, i), FALSE), FALSE)
t := BuildLogicalOr (location, t, BuildLSL(location, GetWordOne(location), ToWord(location, i), FALSE))
END ;
PushIntegerTree(i) ;
PushIntegerTree(GetIntegerOne(location)) ;
@@ -5083,7 +5096,7 @@ BEGIN
PushIntegerTree(i) ;
PushIntegerTree(e2) ;
UNTIL Gre(tokenno) ;
RETURN( t )
RETURN t
END BuildRange ;
@@ -5115,7 +5128,7 @@ BEGIN
THEN
tl := ToCardinal(location, SubTree(MaxTree(tokenno, tl, low), low)) ;
th := ToCardinal(location, SubTree(MinTree(tokenno, th, high), low)) ;
t := BuildLogicalOr(location, t, BuildRange(tokenno, tl, th), FALSE)
t := BuildLogicalOr(location, t, BuildRange(tokenno, tl, th))
END ;
INC(n)
END ;
@@ -5123,6 +5136,42 @@ BEGIN
END BuildBitset ;
(*
BuildByte - given a set v construct the bitmask for its
constant value which lie in the range low..high.
*)
PROCEDURE BuildByte (tokenno: CARDINAL;
v: PtrToValue; low, high: tree) : tree ;
VAR
tl, th,
t : tree ;
n : CARDINAL ;
r1, r2 : CARDINAL ;
location: location_t ;
BEGIN
location := TokenToLocation (tokenno) ;
low := ToInteger (location, low) ;
high := ToInteger (location, high) ;
n := 1 ;
t := GetCardinalZero (location) ;
WHILE GetRange (v, n, r1, r2) DO
PushValue (r1) ;
tl := ToInteger (location, PopIntegerTree ()) ;
PushValue (r2) ;
th := ToInteger (location, PopIntegerTree ()) ;
IF IsIntersectionTree (tokenno, tl, th, low, high)
THEN
tl := ToCardinal (location, SubTree (MaxTree (tokenno, tl, low), low)) ;
th := ToCardinal (location, SubTree (MinTree (tokenno, th, high), low)) ;
t := BuildLogicalOr (location, t, BuildRange (tokenno, tl, th))
END ;
INC(n)
END ;
RETURN ToPIMByte (location, t)
END BuildByte ;
(*
IsValueAndTreeKnown - returns TRUE if the value is known and the gcc tree
is defined.
@@ -5309,7 +5358,15 @@ BEGIN
TopOfStack := NIL ;
RangeFreeList := NIL ;
FieldFreeList := NIL ;
ElementFreeList := NIL
ElementFreeList := NIL ;
StackMemDiag
:= InitMemDiagnostic
('M2ALU:Stack',
'{0N} total symbols {1d} consuming {2M} ram {0M} ({2P})') ;
RangeMemDiag
:= InitMemDiagnostic
('M2ALU:Range',
'{0N} total symbols {1d} consuming {2M} ram {0M} ({2P})')
END Init ;
+11 -2
View File
@@ -96,7 +96,7 @@ FROM M2Options IMPORT NilChecking,
IndexChecking, RangeChecking,
ReturnChecking, CaseElseChecking, Exceptions,
WholeValueChecking,
DebugBuiltins,
DebugBuiltins, GetWideset,
Iso, Pim, Pim2, Pim3 ;
FROM m2type IMPORT GetIntegerType,
@@ -150,6 +150,7 @@ VAR
Comp,
Expr,
Ass : CompatibilityArray ;
m2wideset,
Ord,
OrdS, OrdL,
Float,
@@ -222,7 +223,7 @@ BEGIN
InitSystem ;
MakeBitset ; (* We do this after SYSTEM has been created as BITSET
is dependant upon WORD. *)
is dependant upon WORD and BOOLEAN. *)
InitBaseConstants ;
InitBaseFunctions ;
@@ -635,6 +636,14 @@ BEGIN
(* PIM-2 Modula-2 *)
END ;
IF GetWideset ()
THEN
(* Ensure that M2WIDESET is available if needed by M2GenGCC.mod.
By default -fwideset is TRUE however the user may override using
-fno-wideset. *)
m2wideset := MakeDefinitionSource (BuiltinTokenNo, MakeKey('M2WIDESET'))
END ;
(*
The procedure HALT is a real procedure which
is defined in M2RTS. However to remain compatible
+4 -4
View File
@@ -326,9 +326,9 @@ BEGIN
ELSE
IF r^.high=NulSym
THEN
MetaError1('the CASE statement variant must be defined by a constant {%1Da:is a {%1d}}', r^.low)
MetaError1('the CASE statement variant must be defined by a constant {%1Da:is a {%1dv}}', r^.low)
ELSE
MetaError1('the CASE statement variant low value in a range must be defined by a constant {%1Da:is a {%1d}}',
MetaError1('the CASE statement variant low value in a range must be defined by a constant {%1Da:is a {%1dv}}',
r^.low)
END
END
@@ -343,7 +343,7 @@ BEGIN
RETURN( FALSE )
END
ELSE
MetaError1('the CASE statement variant high value in a range must be defined by a constant {%1Da:is a {%1d}}',
MetaError1('the CASE statement variant high value in a range must be defined by a constant {%1Da:is a {%1dv}}',
r^.high)
END
END ;
@@ -1306,7 +1306,7 @@ BEGIN
consttype := GetType (constant) ;
IF NOT IsExpressionCompatible (consttype, type)
THEN
MetaError2 ('the case statement variant tag {%1ad} must be type compatible with the constant {%2Da:is a {%2d}}',
MetaError2 ('the case statement variant tag {%1ad} must be type compatible with the constant {%2Da:is a {%2dv}}',
type, constant) ;
RETURN FALSE
END
+24 -1
View File
@@ -34,6 +34,7 @@ IMPLEMENTATION MODULE M2Check ;
FROM M2System IMPORT IsSystemType, IsGenericSystemType, IsSameSize, IsComplexN ;
FROM M2Base IMPORT IsParameterCompatible, IsAssignmentCompatible, IsExpressionCompatible, IsComparisonCompatible, IsBaseType, IsMathType, ZType, CType, RType, IsComplexType, Char ;
FROM M2Bitset IMPORT Bitset ;
FROM Indexing IMPORT Index, InitIndex, GetIndice, PutIndice, KillIndex, HighIndice, LowIndice, IncludeIndiceIntoIndex, ForeachIndiceInIndexDo ;
FROM M2Error IMPORT Error, InternalError, NewError, ErrorString, ChainError ;
@@ -456,7 +457,23 @@ END checkUnbounded ;
(*
checkArrayTypeEquivalence - check array and unbounded array type equivalence.
checkGenericUnboundedTyped - return TRUE if we have a match for
an unbounded generic type and a typed object
which is not a Z, R or C type.
*)
PROCEDURE checkGenericUnboundedTyped (unbounded, typed: CARDINAL) : BOOLEAN ;
BEGIN
RETURN (IsUnbounded (unbounded) AND
IsGenericSystemType (GetDType (unbounded)) AND
((NOT IsZRCType (typed)) OR
IsTyped (typed) AND (NOT IsZRCType (GetDType (typed)))))
END checkGenericUnboundedTyped ;
(*
checkArrayTypeEquivalence - check array and unbounded array type
equivalence.
*)
PROCEDURE checkArrayTypeEquivalence (result: status; tinfo: tInfo;
@@ -476,6 +493,12 @@ BEGIN
THEN
result := checkSubrange (result, tinfo, getSType (lSub), getSType (rSub))
END
ELSIF checkGenericUnboundedTyped (left, right) OR
checkGenericUnboundedTyped (right, left)
THEN
(* ARRAY OF BYTE (or WORD or LOC etc will be compatible with any typed
non ZRC type. *)
RETURN true
ELSIF IsUnbounded (left) AND (IsArray (right) OR IsUnbounded (right))
THEN
IF IsGenericSystemType (getSType (left)) OR IsGenericSystemType (getSType (right))
+6 -4
View File
@@ -78,6 +78,8 @@ FROM M2SSA IMPORT DiscoverSSA ;
FROM m2pp IMPORT CreateDumpGimple, CloseDumpGimple ;
FROM DynamicStrings IMPORT String, KillString ;
IMPORT M2Diagnostic ;
CONST
MaxOptimTimes = 10 ; (* upper limit of no of times we run through all optimization *)
@@ -119,10 +121,10 @@ END Percent ;
(*
OptimizationAnalysis - displays some simple front end optimization statistics.
ResourceAnalysis - displays resource analysis relating to the front end.
*)
PROCEDURE OptimizationAnalysis ;
PROCEDURE ResourceAnalysis ;
VAR
value: CARDINAL ;
BEGIN
@@ -146,7 +148,7 @@ BEGIN
FlushBuffer (StdOut)
END ;
DumpQuadruples ('after all front end optimization\n')
END OptimizationAnalysis ;
END ResourceAnalysis ;
(*
@@ -293,7 +295,7 @@ BEGIN
qprintf0 (' gcc trees given to the gcc backend\n') ;
EndGlobalContext ;
OptimizationAnalysis
ResourceAnalysis
END Code ;
+37 -4
View File
@@ -48,6 +48,7 @@ FROM P0SymBuild IMPORT P0Init, P1Init ;
FROM M2Debug IMPORT Assert ;
IMPORT m2flex ;
IMPORT m2block ;
IMPORT P0SyntaxCheck ;
IMPORT P1Build ;
IMPORT P2Build ;
@@ -56,6 +57,7 @@ IMPORT P3Build ;
IMPORT PHBuild ;
IMPORT PCSymBuild ;
IMPORT DynamicStrings ;
IMPORT M2Diagnostic ;
FROM M2Batch IMPORT GetSource, GetModuleNo, GetDefinitionModuleFile, GetModuleFile,
AssociateModule, AssociateDefinition, MakeImplementationSource,
@@ -70,6 +72,7 @@ FROM SymbolTable IMPORT GetSymName, IsDefImp, NulSym,
GetImportStatementList ;
FROM M2Search IMPORT FindSourceDefFile ;
FROM M2Diagnostic IMPORT Diagnostic, InitMemDiagnostic, MemIncr, MemSet ;
FROM FIO IMPORT File, StdErr, StdOut, Close, EOF, IsNoError, WriteLine,
WriteChar, FlushOutErr ;
@@ -80,8 +83,8 @@ FROM M2Printf IMPORT fprintf0, fprintf1 ;
FROM M2Quiet IMPORT qprintf0, qprintf1, qprintf2 ;
FROM M2Options IMPORT Verbose, GetM2Prefix, GetM, GetMM, GetDepTarget, GetMF, GetMP,
GetObj, PPonly, Statistics, Quiet, WholeProgram, GetMD, GetMMD,
ExtendedOpaque, GenModuleList ;
GetObj, PPonly, Quiet, WholeProgram, GetMD, GetMMD,
ExtendedOpaque, GenModuleList, TimeReport, MemReport ;
FROM PathName IMPORT DumpPathName ;
FROM Lists IMPORT List, NoOfItemsInList, GetItemFromList ;
@@ -92,6 +95,7 @@ FROM DynamicStrings IMPORT String, InitString, KillString, InitStringCharStar,
InitStringChar, RIndex, Slice, Equal, RemoveWhitePrefix ;
CONST
Debugging = FALSE ;
@@ -281,14 +285,43 @@ END Compile ;
PROCEDURE compile (filename: ADDRESS) ;
VAR
f: String ;
f, s: String ;
BEGIN
M2Diagnostic.Configure (TimeReport, MemReport) ;
f := InitStringCharStar (filename) ;
Compile (f) ;
f := KillString (f)
f := KillString (f) ;
PopulateResource ;
IF TimeReport OR MemReport
THEN
s := WriteS (StdOut, M2Diagnostic.Generate (FALSE)) ;
FlushOutErr ;
s := KillString (s)
END
END compile ;
(*
PopulateResource -
*)
PROCEDURE PopulateResource ;
VAR
StatsMemDiag: Diagnostic ;
BEGIN
IF MemReport
THEN
StatsMemDiag
:= InitMemDiagnostic
('M2Comp:statistics',
'total source lines {1d} total constants {2d} total types {3d}') ;
MemSet (StatsMemDiag, 1, m2flex.GetTotalLines ()) ;
MemSet (StatsMemDiag, 2, m2block.GetTotalConstants ()) ;
MemSet (StatsMemDiag, 3, m2block.GetGlobalTypes ())
END
END PopulateResource ;
(*
ExamineHeader - examines up until the ';', '[' or eof and determines if the source file
is a program, implementation/definition module.
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -43,7 +43,8 @@ FROM NameKey IMPORT Name ;
{%1Td} get the type of the first symbol and describe it.
{%1Sd} skip the type pseudonyms of the first symbol and describe it.
{%1ua} force no quotes after substituting the text.
{%1av} check name for starting with a vowel and if so append n to the
previous word.
{%1D} sets the error message to where symbol 1 was declared.
The declaration will choose the definition module, then
implementation (or program) module.
+44 -7
View File
@@ -44,7 +44,8 @@ FROM Indexing IMPORT Index, InitIndex, KillIndex, GetIndice, PutIndice,
FROM DynamicStrings IMPORT String, InitString, InitStringCharStar,
ConCat, ConCatChar, Mark, string, KillString,
Dup, char, Length, Mult, EqualArray, Equal ;
Dup, char, Length, Mult, EqualArray, Equal,
RemoveWhitePostfix ;
FROM SymbolTable IMPORT NulSym,
IsDefImp, IsModule, IsInnerModule,
@@ -88,6 +89,7 @@ TYPE
highplus1 : CARDINAL ;
len,
ini : INTEGER ;
vowel,
glyph,
chain,
root,
@@ -507,13 +509,14 @@ BEGIN
WITH eb DO
useError := TRUE ;
e := NIL ;
type := error ; (* default to the error color. *)
type := error ; (* Default to the error color. *)
out := InitString ('') ;
in := input ;
highplus1 := HIGH (sym) + 1 ;
len := Length (input) ;
ini := 0 ;
glyph := FALSE ; (* nothing to output yet. *)
glyph := FALSE ; (* Nothing to output yet. *)
vowel := FALSE ; (* Check for a vowel when outputing string? *)
quotes := TRUE ;
positive := TRUE ;
root := FALSE ;
@@ -542,7 +545,7 @@ END push ;
(*
pop - copies contents of oldblock into newblock. It only copies the error
pop - copies contents of fromblock into toblock. It only copies the error
handle if the toblock.e is NIL.
*)
@@ -550,6 +553,7 @@ PROCEDURE pop (VAR toblock, fromblock: errorBlock) ;
VAR
c: colorType ;
BEGIN
checkVowel (toblock, fromblock) ;
IF empty (fromblock)
THEN
toblock.stackPtr := fromblock.stackPtr ;
@@ -708,7 +712,7 @@ END killErrorBlock ;
)
=:
op := {'a'|'q'|'t'|'d'|'n'|'s'|'B'|'D'|'F'|'G'|'H'|'M'|'U'|'E'|'V'|'W'|'A'} then =:
op := {'a'|'q'|'t'|'d'|'n'|'s'|'v'|'B'|'D'|'F'|'G'|'H'|'M'|'U'|'E'|'V'|'W'|'A'} then =:
then := [ ':' ebnf ] =:
*)
@@ -972,6 +976,38 @@ BEGIN
END empty ;
(*
checkVowel - checks to see if the from block word starts with
a vowel and if so adds an n to the to block output.
*)
PROCEDURE checkVowel (VAR to: errorBlock; from: errorBlock) ;
BEGIN
IF from.vowel AND (NOT empty (from))
THEN
IF isVowel (char (from.out, 0))
THEN
IF Length (to.out) > 0
THEN
to.out := RemoveWhitePostfix (Mark (to.out)) ;
to.out := ConCat (to.out, Mark (InitString ('n '))) ;
from.vowel := FALSE
END
END
END
END checkVowel ;
(*
isVowel - returns TRUE if ch is a, e, i, o or u.
*)
PROCEDURE isVowel (ch: CHAR) : BOOLEAN ;
BEGIN
RETURN (ch = 'a') OR (ch = 'e') OR (ch = 'i') OR (ch = 'o') OR (ch = 'u')
END isVowel ;
(*
clear - remove the output string.
*)
@@ -1624,7 +1660,7 @@ BEGIN
RETURN InitString('set')
ELSIF IsUnknown(sym)
THEN
RETURN InitString('an unknown')
RETURN InitString('unknown')
ELSIF IsSubrange(sym)
THEN
RETURN InitString('subrange')
@@ -1676,7 +1712,7 @@ END copySym ;
(*
op := {'!'|'a'|'c'|'d'|'k'|'n'|'p'|'q'|'s'|'t'|'u'|
op := {'!'|'a'|'c'|'d'|'k'|'n'|'p'|'q'|'s'|'t'|'u'|'v'|
'A'|'B'|'C'|'D'|'E'|'F'|'G'|'H'|'K'|'M'|'N'|
'O'|'P'|'Q'|'R'|'S'|'T'|'U'|'V'|'W'|'X'|'Y'|'Z'} then =:
*)
@@ -1705,6 +1741,7 @@ BEGIN
's': doSkipType (eb, sym, bol) |
't': doType (eb, sym, bol) |
'u': eb.quotes := FALSE |
'v': eb.vowel := TRUE |
'A': eb.type := aborta ;
seenAbort := TRUE |
'B': declaredType (eb, sym, bol) |
+33 -3
View File
@@ -55,9 +55,10 @@ VAR
StyleChecking, (* -Wstudents checks for common student errs*)
UnboundedByReference, (* -funbounded-by-reference *)
VerboseUnbounded, (* -Wverbose-unbounded *)
OptimizeUncalledProcedures, (* -Ouncalled removes uncalled procedures *)
OptimizeBasicBlock, (* -Obb create basic blocks and optimize. *)
OptimizeCommonSubExpressions, (* -Ocse optimize common subexpressions *)
OptimizeUncalledProcedures, (* Removes uncalled procedures? *)
OptimizeBasicBlock, (* Create basic blocks and optimize? *)
OptimizeCommonSubExpressions, (* Optimize common subexpressions? *)
OptimizeSets, (* TRUE if -On when n>0. False for -Os. *)
WholeProgram, (* -fwhole-program optimization. *)
NilChecking, (* -fnil makes compiler test for pointer *)
(* NIL. *)
@@ -115,6 +116,7 @@ VAR
SharedFlag, (* -fshared indicating this module needs *)
(* the shared library version of the *)
(* scaffold. *)
TimeReport, MemReport, (* -ftime-report and -fmem-report values. *)
ForcedLocation,
GenerateStatementNote,
Optimizing,
@@ -1165,6 +1167,34 @@ PROCEDURE SetFileOffsetBits (value: BOOLEAN; bits: CARDINAL) : BOOLEAN ;
PROCEDURE GetFileOffsetBits () : CARDINAL ;
(*
SetMemReport - set MemReport to value.
*)
PROCEDURE SetMemReport (value: BOOLEAN) ;
(*
SetTimeReport - set TimeReport to value.
*)
PROCEDURE SetTimeReport (value: BOOLEAN) ;
(*
SetWideset - set the Wideset flag to value.
*)
PROCEDURE SetWideset (value: BOOLEAN) ;
(*
GetWideset - return the Wideset flag value.
*)
PROCEDURE GetWideset () : BOOLEAN ;
(*
FinaliseOptions - once all options have been parsed we set any inferred
values.
+49 -2
View File
@@ -85,6 +85,7 @@ VAR
DumpDecl, (* -fm2-dump=decl. *)
DumpGimple, (* -fm2-dump=gimple. *)
DumpQuad, (* -fq, -fm2-dump=quad dump quadruples. *)
WidesetFlag, (* -fwideset. *)
MFlag,
MMFlag,
MPFlag,
@@ -1326,12 +1327,14 @@ BEGIN
Optimizing := TRUE ;
OptimizeBasicBlock := TRUE ;
OptimizeUncalledProcedures := TRUE ;
OptimizeCommonSubExpressions := TRUE
OptimizeCommonSubExpressions := TRUE ;
OptimizeSets := TRUE
ELSE
Optimizing := FALSE ;
OptimizeBasicBlock := FALSE ;
OptimizeUncalledProcedures := FALSE ;
OptimizeCommonSubExpressions := FALSE
OptimizeCommonSubExpressions := FALSE ;
OptimizeSets := FALSE
END
END SetOptimizing ;
@@ -2074,6 +2077,46 @@ BEGIN
END GetFileOffsetBits ;
(*
SetMemReport - set MemReport to value.
*)
PROCEDURE SetMemReport (value: BOOLEAN) ;
BEGIN
MemReport := value
END SetMemReport ;
(*
SetTimeReport - set TimeReport to value.
*)
PROCEDURE SetTimeReport (value: BOOLEAN) ;
BEGIN
TimeReport := value
END SetTimeReport ;
(*
SetWideset - set the Wideset flag to value.
*)
PROCEDURE SetWideset (value: BOOLEAN) ;
BEGIN
WidesetFlag := value
END SetWideset ;
(*
GetWideset - return the Wideset flag value.
*)
PROCEDURE GetWideset () : BOOLEAN ;
BEGIN
RETURN WidesetFlag
END GetWideset ;
BEGIN
cflag := FALSE ; (* -c. *)
RuntimeModuleOverride := InitString (DefaultRuntimeModuleOverride) ;
@@ -2099,6 +2142,7 @@ BEGIN
OptimizeBasicBlock := FALSE ;
OptimizeUncalledProcedures := FALSE ;
OptimizeCommonSubExpressions := FALSE ;
OptimizeSets := FALSE ;
NilChecking := FALSE ;
WholeDivChecking := FALSE ;
WholeValueChecking := FALSE ;
@@ -2168,6 +2212,9 @@ BEGIN
DumpGimple := FALSE ;
M2Dump := NIL ;
M2DumpFilter := NIL ;
TimeReport := FALSE ;
MemReport := FALSE ;
EnableForward := TRUE ;
OffTBits := 0 ; (* Default to CSSIZE_T. *)
WidesetFlag := TRUE ;
END M2Options.
+87 -36
View File
@@ -57,6 +57,8 @@ FROM SymbolTable IMPORT ModeOfAddr, GetMode, PutMode, GetSymName, IsUnknown,
MakeConstString, MakeConstant, MakeConstVar,
MakeConstStringM2nul, MakeConstStringCnul,
Make2Tuple, IsTuple,
MakeSubrange, PutSubrange,
PutSetArray, MakeSetArray,
RequestSym, MakePointer, PutPointer,
SkipType,
GetDType, GetSType, GetLType,
@@ -109,6 +111,7 @@ FROM SymbolTable IMPORT ModeOfAddr, GetMode, PutMode, GetSymName, IsUnknown,
IsFieldEnumeration,
IsVar, IsProcType, IsType, IsSubrange, IsExported,
IsConst, IsConstString, IsModule, IsDefImp,
IsConstVar,
IsArray, IsUnbounded, IsProcedureNested,
IsParameterUnbounded,
IsPartialUnbounded, IsProcedureBuiltin,
@@ -150,7 +153,8 @@ FROM M2Batch IMPORT MakeDefinitionSource ;
FROM M2GCCDeclare IMPORT PutToBeSolvedByQuads ;
FROM FifoQueue IMPORT GetConstFromFifoQueue,
PutConstructorIntoFifoQueue, GetConstructorFromFifoQueue ;
PutConstructorIntoFifoQueue, GetConstructorFromFifoQueue,
GetSetFromFifoQueue ;
FROM M2Comp IMPORT CompilingImplementationModule,
CompilingProgramModule ;
@@ -280,6 +284,8 @@ FROM M2CaseList IMPORT PushCase, PopCase, AddRange, BeginCaseList, EndCaseList,
FROM PCSymBuild IMPORT SkipConst ;
FROM m2builtins IMPORT GetBuiltinTypeInfoType ;
FROM M2LangDump IMPORT IsDumpRequired ;
FROM SymbolConversion IMPORT GccKnowsAbout ;
FROM M2Diagnostic IMPORT Diagnostic, InitMemDiagnostic, MemIncr, MemSet ;
IMPORT M2Error, FIO, SFIO, DynamicStrings, StdIO ;
@@ -399,6 +405,7 @@ VAR
(* in order. *)
NoOfQuads : CARDINAL ; (* Number of used quadruples. *)
Head : CARDINAL ; (* Head of the list of quadruples. *)
QuadMemDiag : Diagnostic ; (* Contains memory related statistics. *)
BreakQuad : CARDINAL ; (* Stop when BreakQuad is created. *)
@@ -2063,7 +2070,9 @@ BEGIN
ELSE
INC (NoOfQuads) ;
PutIndice (QuadArray, QuadNo, f) ;
f^.NoOfTimesReferenced := 0
f^.NoOfTimesReferenced := 0 ;
MemSet (QuadMemDiag, 1, NoOfQuads) ;
MemIncr (QuadMemDiag, 2, SIZE (f^))
END
END ;
WITH f^ DO
@@ -3404,7 +3413,7 @@ BEGIN
IF IsPseudoBaseProcedure (expr) OR IsPseudoBaseFunction (expr)
THEN
MetaErrorT1 (exprtok,
'an assignment cannot assign a {%1d} {%1a}', expr)
'an assignment cannot assign a {%1dv} {%1a}', expr)
END
END CheckCompatibleWithBecomes ;
@@ -3812,25 +3821,24 @@ END BuildAssignConstant ;
(*
doBuildAssignment - subsiduary procedure of BuildAssignment.
It builds the assignment and optionally
checks the types are compatible.
BuildAssignmentBoolean - build the quadruples for a boolean variable or constant
which will be assigned to the result of a boolean expression.
For example:
foo := a = b ;
foo := a IN b ;
The boolean result is contained in the control flow
the true value will emerge from the quad path t.
The false value will emerge from the quad path f.
This procedure terminates both paths by backpatching
and assigns TRUE or FALSE to the variable/constant.
A variable maybe an L value so it will require dereferencing.
*)
PROCEDURE doBuildAssignment (becomesTokNo: CARDINAL; checkTypes, checkOverflow: BOOLEAN) ;
VAR
r, w,
t, f,
Array,
Des, Exp : CARDINAL ;
combinedtok,
destok, exptok: CARDINAL ;
PROCEDURE BuildAssignmentBoolean (becomesTokNo: CARDINAL; checkTypes, checkOverflow: BOOLEAN;
t, f: CARDINAL; Des: CARDINAL; destok: CARDINAL) ;
BEGIN
DisplayStack ;
IF IsBoolean (1)
THEN
PopBool (t, f) ;
PopTtok (Des, destok) ;
PutVarConditional (Des, TRUE) ; (* Des will contain the result of a boolean relop. *)
(* Conditional Boolean Assignment. *)
BackPatch (t, NextQuad) ;
@@ -3852,6 +3860,36 @@ BEGIN
ELSE
GenQuadO (becomesTokNo, BecomesOp, Des, NulSym, False, checkOverflow)
END
END BuildAssignmentBoolean ;
(*
doBuildAssignment - subsiduary procedure of BuildAssignment.
It builds the assignment and optionally
checks the types are compatible.
*)
PROCEDURE doBuildAssignment (becomesTokNo: CARDINAL; checkTypes, checkOverflow: BOOLEAN) ;
VAR
r, w,
t, f,
Array,
Des, Exp : CARDINAL ;
combinedtok,
destok, exptok: CARDINAL ;
BEGIN
DisplayStack ;
IF IsBoolean (1)
THEN
PopBool (t, f) ;
PopTtok (Des, destok) ;
IF IsVar (Des) OR IsConstVar (Des)
THEN
BuildAssignmentBoolean (becomesTokNo, checkTypes, checkOverflow,
t, f, Des, destok)
ELSE
MetaErrorT1 (destok, 'expecting the designator {%1Ead} to be a constant or a variable and not a {%1dv}', Des)
END
ELSE
PopTrwtok (Exp, r, exptok) ;
MarkAsRead (r) ;
@@ -5795,8 +5833,8 @@ BEGIN
WHILE i<=n DO
IF IsVarParamAny (ProcType, i) # IsVarParamAny (CheckedProcedure, i)
THEN
MetaError3 ('parameter {%3n} in {%1dD} causes a mismatch it was declared as a {%2d}', ProcType, GetNth (ProcType, i), i) ;
MetaError3 ('parameter {%3n} in {%1dD} causes a mismatch it was declared as a {%2d}', call, GetNth (call, i), i)
MetaError3 ('parameter {%3n} in {%1dD} causes a mismatch it was declared as a {%2dv}', ProcType, GetNth (ProcType, i), i) ;
MetaError3 ('parameter {%3n} in {%1dD} causes a mismatch it was declared as a {%2dv}', call, GetNth (call, i), i)
END ;
BuildRange (InitTypesParameterCheck (tokno, CheckedProcedure, i,
GetNthParamAnyClosest (CheckedProcedure, i, GetCurrentModule ()),
@@ -7863,9 +7901,9 @@ BEGIN
(* Error issue message and fake return stack. *)
IF Iso
THEN
MetaErrorT0 (functok, 'the only functions permissible in a constant expression are: {%kCAP}, {%kCHR}, {%kCMPLX}, {%kFLOAT}, {%kHIGH}, {%kIM}, {%kLENGTH}, {%kMAX}, {%kMIN}, {%kODD}, {%kORD}, {%kRE}, {%kSIZE}, {%kTSIZE}, {%kTRUNC}, {%kVAL} and gcc builtins')
MetaErrorT0 (functok, 'the only functions permissible in a constant expression are: {%kCAP}, {%kCHR}, {%kCMPLX}, {%kFLOAT}, {%kHIGH}, {%kIM}, {%kLENGTH}, {%kMAX}, {%kMIN}, {%kODD}, {%kORD}, {%kRE}, {%kSIZE}, {%kTSIZE}, {%kTBITSIZE}, {%kTRUNC}, {%kVAL} and gcc builtins')
ELSE
MetaErrorT0 (functok, 'the only functions permissible in a constant expression are: {%kCAP}, {%kCHR}, {%kFLOAT}, {%kHIGH}, {%kMAX}, {%kMIN}, {%kODD}, {%kORD}, {%kSIZE}, {%kTSIZE}, {%kTRUNC}, {%kVAL} and gcc builtins')
MetaErrorT0 (functok, 'the only functions permissible in a constant expression are: {%kCAP}, {%kCHR}, {%kFLOAT}, {%kHIGH}, {%kMAX}, {%kMIN}, {%kODD}, {%kORD}, {%kSIZE}, {%kTSIZE}, {%kTRUNC}, {%kTBITSIZE}, {%kVAL} and gcc builtins')
END ;
IF NoOfParam > 0
THEN
@@ -8212,7 +8250,7 @@ BEGIN
PushTFtok (ReturnVar, Address, combinedtok)
ELSE
MetaErrorT1 (functok,
'the first parameter to ADDADR {%1Ea} must be a variable of type ADDRESS or a {%EkPOINTER}, rather than a {%1Etsd}',
'the first parameter to ADDADR {%1Ea} must be a variable of type ADDRESS or a {%EkPOINTER}, rather than a {%1Etsdv}',
VarSym) ;
PushTFtok (MakeConstLit (combinedtok, MakeKey('0'), Address), Address, combinedtok)
END
@@ -8295,7 +8333,7 @@ BEGIN
PushTFtok (ReturnVar, Address, combinedtok)
ELSE
MetaErrorT1 (functok,
'the first parameter to {%EkSUBADR} {%1Ea} must be a variable of type ADDRESS or a {%EkPOINTER}, rather than a {%1Etsd}',
'the first parameter to {%EkSUBADR} {%1Ea} must be a variable of type ADDRESS or a {%EkPOINTER}, rather than a {%1Etsdv}',
VarSym) ;
PushTFtok (MakeConstLit (vartok, MakeKey('0'), Address), Address, vartok)
END
@@ -8394,13 +8432,13 @@ BEGIN
PushT (2) ; (* Two parameters *)
BuildConvertFunction (Convert, ConstExpr)
ELSE
MetaError1 ('the second parameter to {%EkDIFADR} {%1Ea} must be a variable of type ADDRESS or a {%EkPOINTER}, rather than a {%1Etsd}',
MetaError1 ('the second parameter to {%EkDIFADR} {%1Ea} must be a variable of type ADDRESS or a {%EkPOINTER}, rather than a {%1Etsdv}',
OperandSym) ;
PushTFtok (MakeConstLit (combinedtok, MakeKey ('0'), Integer), Integer, combinedtok)
END
ELSE
MetaErrorT1 (vartok,
'the first parameter to {%EkDIFADR} {%1Ea} must be a variable of type ADDRESS or a {%EkPOINTER}, rather than a {%1Etsd}',
'the first parameter to {%EkDIFADR} {%1Ea} must be a variable of type ADDRESS or a {%EkPOINTER}, rather than a {%1Etsdv}',
VarSym) ;
PushTFtok (MakeConstLit (combinedtok, MakeKey ('0'), Integer), Integer, combinedtok)
END
@@ -8615,7 +8653,7 @@ BEGIN
IF ConstExpr AND IsVar (Var)
THEN
MetaErrorT2 (optok,
'the procedure function {%1Ea} is being called from within a constant expression and therefore the parameter {%2a} must be a constant, seen a {%2da}',
'the procedure function {%1Ea} is being called from within a constant expression and therefore the parameter {%2a} must be a constant, seen a {%2dav}',
Func, Var) ;
RETURN TRUE
ELSE
@@ -9352,7 +9390,8 @@ BEGIN
PopTtok (varSet, vartok) ;
PopT (procSym) ;
combinedtok := MakeVirtualTok (functok, functok, exptok) ;
IF (GetSType (varSet) # NulSym) AND IsSet (GetDType (varSet))
IF (GetSType (varSet) # NulSym)
AND (IsSet (GetDType (varSet)) OR IsGenericSystemType (GetDType (varSet)))
THEN
derefExp := DereferenceLValue (exptok, Exp) ;
BuildRange (InitShiftCheck (varSet, derefExp)) ;
@@ -9427,7 +9466,8 @@ BEGIN
MarkAsRead (r) ;
PopTtok (varSet, vartok) ;
PopT (procSym) ;
IF (GetSType (varSet) # NulSym) AND IsSet (GetDType (varSet))
IF (GetSType (varSet) # NulSym)
AND (IsSet (GetDType (varSet)) OR IsGenericSystemType (GetDType (varSet)))
THEN
combinedtok := MakeVirtualTok (functok, functok, exptok) ;
derefExp := DereferenceLValue (exptok, Exp) ;
@@ -11609,7 +11649,7 @@ BEGIN
BuildStaticArray
ELSE
MetaErrorT1 (arrayTok,
'can only index static or dynamic arrays, {%1Ead} is not an array but a {%tad}',
'can only index static or dynamic arrays, {%1Ead} is not an array but a {%tadv}',
Sym) ;
BuildDesignatorError ('bad array access')
END
@@ -11971,7 +12011,7 @@ BEGIN
MarkAsRead (rw) ;
BuildDesignatorPointerError (Type1, rw, combinedtok, 'bad opaque pointer dereference')
ELSE
MetaError2 ('{%1Ead} is not a pointer type but a {%2d}', Sym1, Type1) ;
MetaError2 ('{%1Ead} is not a pointer type but a {%2dv}', Sym1, Type1) ;
MarkAsRead (rw) ;
BuildDesignatorPointerError (Type1, rw, combinedtok, 'bad pointer dereference')
END
@@ -13065,7 +13105,7 @@ BEGIN
WarnStringAt (s, OldPos) ;
s := InitString ('combined') ;
WarnStringAt (s, OperatorPos) ;
(* MetaErrorT1 (GetDeclaredMod (t), 'in binary with a {%1a}', t) *)
(* MetaErrorT1 (GetDeclaredMod (t), 'in binary with a {%1av}', t) *)
END ;
GenQuadOtok (OperatorPos, MakeOp (NewOp), value, left, right, checkOverflow,
OperatorPos, leftpos, rightpos)
@@ -13384,12 +13424,12 @@ BEGIN
THEN
MetaErrorsT1 (tokpos,
'{%1Ead} expected a variable, procedure, constant or expression',
'and it was declared as a {%1Dd}', sym) ;
'and it was declared as a {%1Ddv}', sym) ;
ELSIF (type#NulSym) AND IsArray(type)
THEN
MetaErrorsT1 (tokpos,
'{%1EU} not expecting an array variable as an operand for either comparison or binary operation',
'it was declared as a {%1Dd}', sym)
'it was declared as a {%1Ddv}', sym)
ELSIF IsConstString (sym) AND IsConstStringKnown (sym) AND (GetStringLength (tokpos, sym) > 1)
THEN
MetaErrorT1 (tokpos,
@@ -14014,9 +14054,12 @@ END ds ;
PROCEDURE DisplayQuad (QuadNo: CARDINAL) ;
BEGIN
IF QuadNo # 0
THEN
DSdbEnter ;
fprintf1 (GetDumpFile (), '%4d ', QuadNo) ; WriteQuad(QuadNo) ; fprintf0 (GetDumpFile (), '\n') ;
DSdbExit
END
END DisplayQuad ;
@@ -14337,7 +14380,11 @@ BEGIN
THEN
fprintf0 (GetDumpFile (), '[') ; WriteMode (GetMode (Sym)) ; fprintf0 (GetDumpFile (), ']')
END ;
fprintf1 (GetDumpFile (), '(%d)', Sym)
fprintf1 (GetDumpFile (), '(%d)', Sym) ;
IF GccKnowsAbout (Sym)
THEN
fprintf0 (GetDumpFile (), '[gcc]')
END
END
END WriteOperand ;
@@ -16173,6 +16220,10 @@ BEGIN
InitList(VarientFields) ;
VarientFieldNo := 0 ;
NoOfQuads := 0 ;
QuadMemDiag
:= InitMemDiagnostic
('M2Quad:Quadruples',
'{0N} total quadruples {1d} consuming {2M} ram {0M} ({2P})')
END Init ;
+2 -2
View File
@@ -1978,7 +1978,7 @@ BEGIN
IF NOT reportedError (r)
THEN
MetaErrorT2 (tokenNo,
'assignment designator {%1Ea} {%1ta:of type {%1ta}} {%1d:is a {%1d}} and expression {%2a} {%2tad:of type {%2tad}} are incompatible',
'assignment designator {%1Ea} {%1ta:of type {%1ta}} {%1d:is a {%1dv}} and expression {%2a} {%2tad:of type {%2tad}} are incompatible',
des, expr)
END ;
setReported (r)
@@ -2047,7 +2047,7 @@ BEGIN
ELSE
MetaErrorT2 (tokenNo,
'assignment designator {%1Ea} {%1ta:of type {%1ta}}' +
' {%1d:is a {%1d}} and expression {%2a}' +
' {%1d:is a {%1dv}} and expression {%2a}' +
' {%2tad:of type {%2tad}} are incompatible',
des, expr)
END ;
+1 -1
View File
@@ -580,7 +580,7 @@ BEGIN
ELSIF ScaffoldDynamic AND (NOT cflag)
THEN
MetaErrorT0 (tokenno,
'{%O}dynamic linking enabled but no module ctor list has been created, hint use -fuse-list=filename or -fgen-module-list=-')
'{%O}dynamic module registration enabled but no module ctor list has been created, hint use -fuse-list=filename or -fgen-module-list=-')
END ;
initFunction := MakeProcedure (tokenno, MakeKey ("_M2_init")) ;
+10 -5
View File
@@ -155,11 +155,16 @@ BEGIN
printf (" initialized\n") ;
IF (desc^.type # NulSym) AND IsRecord (desc^.type)
THEN
i := 1 ;
n := Indexing.HighIndice (desc^.rec.fieldDesc) ;
WHILE i <= n DO
PrintSymInit (Indexing.GetIndice (desc^.rec.fieldDesc, i)) ;
INC (i)
IF desc^.rec.fieldDesc = NIL
THEN
printf (" record field descriptor has not been initialized yet\n") ;
ELSE
i := 1 ;
n := Indexing.HighIndice (desc^.rec.fieldDesc) ;
WHILE i <= n DO
PrintSymInit (Indexing.GetIndice (desc^.rec.fieldDesc, i)) ;
INC (i)
END
END
END
END PrintSymInit ;
+2 -2
View File
@@ -509,8 +509,8 @@ END IsPseudoSystemFunction ;
PROCEDURE IsPseudoSystemFunctionConstExpression (sym: CARDINAL) : BOOLEAN ;
BEGIN
RETURN(
(sym=Size) OR (sym=TSize) OR (sym=Rotate) OR (sym=Shift) OR
(Iso AND ((sym=Cast) OR (sym=MakeAdr)))
(sym=Size) OR (sym=TSize) OR (sym=TBitSize) OR (sym=Rotate) OR (sym=Shift) OR
(Iso AND ((sym=Cast) OR (sym=MakeAdr) OR (sym=TBitSize)))
)
END IsPseudoSystemFunctionConstExpression ;
+37 -7
View File
@@ -31,6 +31,7 @@ FROM NumberIO IMPORT WriteCard ;
FROM StrLib IMPORT StrLen ;
FROM libc IMPORT strlen ;
FROM ASCII IMPORT nul ;
(* FROM M2Diagnostic IMPORT Diagnostic, InitMemDiagnostic, MemIncr, MemDecr, MemSet ; *)
TYPE
@@ -50,6 +51,10 @@ VAR
BinaryTree: NameNode ;
KeyIndex : Index ;
LastIndice: CARDINAL ;
(*
NameKeyTreeMemDiag,
NameKeyWordMemDiag: Diagnostic ;
*)
(*
@@ -144,11 +149,19 @@ BEGIN
IF result=less
THEN
NEW(child) ;
father^.Left := child
father^.Left := child ;
(*
MemIncr (NameKeyTreeMemDiag, 1, 1) ;
MemIncr (NameKeyTreeMemDiag, 2, SIZE (child^))
*)
ELSIF result=greater
THEN
NEW(child) ;
father^.Right := child
father^.Right := child ;
(*
MemIncr (NameKeyTreeMemDiag, 1, 1) ;
MemIncr (NameKeyTreeMemDiag, 2, SIZE (child^))
*)
END ;
WITH child^ DO
Right := NIL ;
@@ -161,7 +174,11 @@ BEGIN
k := LastIndice
ELSE
DEALLOCATE(n, higha+1) ;
k := child^.Key
k := child^.Key ;
(*
MemDecr (NameKeyWordMemDiag, 1, 1) ;
MemDecr (NameKeyWordMemDiag, 2, higha + 1)
*)
END ;
RETURN( k )
END DoMakeKey ;
@@ -182,9 +199,13 @@ VAR
BEGIN
higha := StrLen(a) ;
ALLOCATE(p, higha+1) ;
(*
MemIncr (NameKeyWordMemDiag, 1, 1) ;
MemIncr (NameKeyWordMemDiag, 2, higha + 1) ;
*)
IF p=NIL
THEN
HALT (* out of memory error *)
HALT (* Out of memory error. *)
ELSE
n := p ;
i := 0 ;
@@ -194,7 +215,6 @@ BEGIN
INC(p)
END ;
p^ := nul ;
RETURN( DoMakeKey(n, higha) )
END
END MakeKey ;
@@ -223,7 +243,7 @@ BEGIN
ALLOCATE(p, higha+1) ;
IF p=NIL
THEN
HALT (* out of memory error *)
HALT (* Out of memory error. *)
ELSE
n := p ;
pa := a ;
@@ -413,8 +433,18 @@ END CharKey ;
BEGIN
(*
NameKeyWordMemDiag
:= InitMemDiagnostic
('NameKey:Words',
'{0N} total words {1d} consuming {2M} ({2P})') ;
NameKeyTreeMemDiag
:= InitMemDiagnostic
('NameKey:Tree',
'{0N} total tree nodes {1d} consuming {2M} ({2P})') ;
*)
LastIndice := 0 ;
KeyIndex := InitIndex(1) ;
NEW(BinaryTree) ;
BinaryTree^.Left := NIL
BinaryTree^.Left := NIL ;
END NameKey.
+1 -1
View File
@@ -914,7 +914,7 @@ BEGIN
EndBuildForward. *)
PutDeclared (tokno, ProcSym)
ELSE
MetaError1 ('expecting a procedure name and symbol {%1Ea} has been declared as a {%1d}', ProcSym) ;
MetaError1 ('expecting a procedure name and symbol {%1Ea} has been declared as a {%1dv}', ProcSym) ;
PushT (ProcSym) ;
RETURN
END ;
+1 -1
View File
@@ -2589,7 +2589,7 @@ BEGIN
Field := PutFieldRecord(Record, OperandT(NoOfPragmas*2+NoOfFields+3-i), Type, Varient) ;
HandleRecordFieldPragmas(Record, Field, NoOfPragmas)
ELSE
MetaErrors2('record field {%1ad} has already been declared inside a {%2Dd} {%2a}',
MetaErrors2('record field {%1ad} has already been declared inside a {%2Ddv} {%2a}',
'attempting to declare a duplicate record field', fsym, Parent)
END ;
(* adjust the location of declaration to the one on the stack (rather than GetTokenNo). *)
+2 -1
View File
@@ -1041,7 +1041,8 @@ SilentExpList := SilentConstExpression { "," SilentConstExpression } =:
-- end of the Silent constant rules
SetType := ( "SET" | "PACKEDSET" ) "OF" SimpleType =:
SetType := ( "SET" | "PACKEDSET" ) "OF" SimpleType
=:
PointerType := "POINTER" "TO"
Type
+21 -9
View File
@@ -1,13 +1,25 @@
DEFINITION MODULE PathName ;
(* PathName.def maintains a dictionary of named paths.
(*
Title : PathName
Author : Gaius Mulley
System : GNU Modula-2
Date : Wed Feb 8 09:59:46 2023
Revision : $Version$
Description: maintains a dictionary of named paths.
*)
Copyright (C) 2001-2023 Free Software Foundation, Inc.
Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
This file is part of GNU Modula-2.
GNU Modula-2 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Modula-2 is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Modula-2; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. *)
DEFINITION MODULE PathName ;
FROM DynamicStrings IMPORT String ;
FROM DynamicPath IMPORT PathList ;
-1
View File
@@ -1,5 +1,4 @@
(* M2PathName.mod maintain a dictionary of named paths.
Copyright (C) 2023-2025 Free Software Foundation, Inc.
Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
+46 -1
View File
@@ -39,7 +39,7 @@ FROM SYSTEM IMPORT ADDRESS ;
CONST
USEPOISON = TRUE ;
GGCPOISON = 0A5A5A5A5H ; (* poisoned memory contains this code *)
GGCPOISON = 0A5A5A5A5H ; (* Poisoned memory contains this code. *)
TYPE
PtrToCardinal = POINTER TO CARDINAL ;
@@ -47,6 +47,38 @@ TYPE
VAR
mod2gcc : Index ;
PoisonedSymbol: ADDRESS ;
BookSym : CARDINAL ; (* Allows interactive debugging. *)
(*
gdbhook - a debugger convenience hook.
*)
PROCEDURE gdbhook ;
END gdbhook ;
(*
BreakWhenSymBooked - to be called interactively by gdb.
*)
PROCEDURE BreakWhenSymBooked (sym: CARDINAL) ;
BEGIN
BookSym := sym
END BreakWhenSymBooked ;
(*
CheckBook - if sym = BookSym then call gdbhook.
*)
PROCEDURE CheckBook (sym: CARDINAL) ;
BEGIN
IF sym = BookSym
THEN
gdbhook
END
END CheckBook ;
(*
@@ -117,6 +149,7 @@ VAR
old: tree ;
t : PtrToCardinal ;
BEGIN
CheckBook (sym) ;
IF gcc=GetErrorNode()
THEN
InternalError ('error node generated during symbol conversion')
@@ -258,6 +291,18 @@ END Poison ;
PROCEDURE Init ;
BEGIN
BreakWhenSymBooked (NulSym) ; (* Disable the intereactive sym watch. *)
(* To examine when a symbol is double booked run cc1gm2 from gdb
and set a break point on gdbhook.
(gdb) break gdbhook
(gdb) run
Now below interactively call BreakWhenSymBooked with the symbol
under investigation. *)
gdbhook ;
(* Now is the time to interactively call gdb, for example:
(gdb) print BreakWhenSymBooked (1234)
(gdb) cont
and you will arrive at gdbhook when this symbol is booked. *)
mod2gcc := InitIndexTuned (1, 1024*1024 DIV 16, 16) ;
ALLOCATE (PoisonedSymbol, 1)
END Init ;
+51
View File
@@ -580,6 +580,41 @@ PROCEDURE MakeSubrange (tok: CARDINAL; SubrangeName: Name) : CARDINAL ;
PROCEDURE MakeSet (tok: CARDINAL; SetName: Name) : CARDINAL ;
(*
GetSetArray - return the set array for a large set.
*)
PROCEDURE GetSetArray (sym: CARDINAL) : CARDINAL ;
(*
PutSetArray - places array into the setarray field.
*)
PROCEDURE PutSetArray (Sym: CARDINAL; array: CARDINAL) ;
(*
MakeSetArray - create an ARRAY simpletype OF BOOLEAN.
*)
PROCEDURE MakeSetArray (token: CARDINAL; subrangetype: CARDINAL) : CARDINAL ;
(*
PutSetInWord - set the SetInWord boolean to value.
*)
PROCEDURE PutSetInWord (sym: CARDINAL; value: BOOLEAN) ;
(*
GetSetInWord - return SetInWord.
*)
PROCEDURE GetSetInWord (sym: CARDINAL) : BOOLEAN ;
(*
MakeArray - makes an Array symbol with name ArrayName.
*)
@@ -3496,4 +3531,20 @@ PROCEDURE GetNthParamAnyClosest (sym: CARDINAL; ParamNo: CARDINAL;
currentmodule: CARDINAL) : CARDINAL ;
(*
IsConstVar - returns TRUE if sym is a const var. This is a
constant which might be assigned to TRUE or FALSE
depending upon the result of the quad stack control flow.
Typically used in CONST foo = (a AND b) or similar.
This symbol will only be assigned once with a value, but
will appear more than once as a designator to an assignment
in the quad table. However as the quad table is reduced
only one assignment will remain. If after reducing quads
two or more assignments remain, then there is an error
as sym should not have been declared a constant.
*)
PROCEDURE IsConstVar (sym: CARDINAL) : BOOLEAN ;
END SymbolTable.
+190 -28
View File
@@ -80,9 +80,9 @@ FROM SymbolKey IMPORT NulKey, SymbolTree, IsSymbol,
NoOfNodes ;
FROM M2Base IMPORT MixTypes, MixTypesDecl, InitBase, Char, Integer, LongReal,
Cardinal, LongInt, LongCard, ZType, RType ;
Cardinal, LongInt, LongCard, Boolean, ZType, RType ;
FROM M2System IMPORT Address ;
FROM M2System IMPORT Address, Byte ;
FROM m2expr IMPORT OverflowZType ;
FROM gcctypes IMPORT tree ;
FROM m2linemap IMPORT BuiltinsLocation ;
@@ -94,6 +94,7 @@ FROM M2Comp IMPORT CompilingDefinitionModule,
FROM FormatStrings IMPORT HandleEscape ;
FROM M2Scaffold IMPORT DeclareArgEnvParams ;
FROM M2Diagnostic IMPORT Diagnostic, InitMemDiagnostic, MemIncr, MemSet ;
FROM M2SymInit IMPORT InitDesc, InitSymInit, GetInitialized, ConfigSymInit,
SetInitialized, SetFieldInitialized, GetFieldInitialized,
@@ -107,6 +108,7 @@ CONST
DebugUnknownToken = FALSE ; (* If enabled it will generate a warning every
time a symbol is created with an unknown
location. *)
BreakNew = 97 ; (* -1 disables the break. *)
(*
The Unbounded is a pseudo type used within the compiler
@@ -653,6 +655,9 @@ TYPE
(* (subrange or enumeration). *)
packedInfo: PackedInfo ; (* the equivalent packed type *)
ispacked : BOOLEAN ;
SetInWord: BOOLEAN ; (* Is the set stored in a word? *)
SetArray : CARDINAL ; (* Array used for large sets. *)
Align : CARDINAL ; (* The alignment of this type *)
Size : PtrToValue ; (* Runtime size of symbol. *)
oafamily : CARDINAL ; (* The oafamily for this sym *)
Scope : CARDINAL ; (* Scope of declaration. *)
@@ -933,6 +938,7 @@ VAR
(* errors. *)
ConstLitArray : Indexing.Index ;
BreakSym : CARDINAL ; (* Allows interactive debugging. *)
SymMemDiag : Diagnostic ; (* Contains memory related statistics *)
(*
@@ -1080,7 +1086,9 @@ BEGIN
END ;
PutIndice(Symbols, sym, pSym) ;
CheckBreak (sym) ;
INC(FreeSymbol)
INC (FreeSymbol) ;
MemSet (SymMemDiag, 1, FreeSymbol-1) ;
MemIncr (SymMemDiag, 2, SIZE (pSym^))
END NewSym ;
@@ -1683,6 +1691,10 @@ PROCEDURE Init ;
VAR
pCall: PtrToCallFrame ;
BEGIN
SymMemDiag
:= InitMemDiagnostic
('SymbolTable:Symbols',
'{0N} total symbols {1d} consuming {2M} ram {0M} ({2P})') ;
BreakWhenSymCreated (NulSym) ; (* Disable the intereactive sym watch. *)
(* To examine the symbol table when a symbol is created run cc1gm2 from gdb
and set a break point on gdbhook.
@@ -5403,6 +5415,28 @@ BEGIN
END MakeConstVar ;
(*
IsConstVar - returns TRUE if sym is a const var. This is a
constant which might be assigned to TRUE or FALSE
depending upon the result of the quad stack control flow.
Typically used in CONST foo = (a AND b) or similar.
This symbol will only be assigned once with a value, but
will appear more than once as a designator to an assignment
in the quad table. However as the quad table is reduced
only one assignment will remain. If after reducing quads
two or more assignments remain, then there is an error
as sym should not have been declared a constant.
*)
PROCEDURE IsConstVar (sym: CARDINAL) : BOOLEAN ;
VAR
pSym: PtrToSymbol ;
BEGIN
pSym := GetPsym (sym) ;
RETURN( pSym^.SymbolType=ConstVarSym )
END IsConstVar ;
(*
InitConstString - initialize the constant string.
*)
@@ -5827,7 +5861,7 @@ BEGIN
VarSym: RETURN Var.IsSSA
ELSE
InternalError ('expecting a variable symbol')
RETURN FALSE
END
END
END IsVariableSSA ;
@@ -6391,8 +6425,8 @@ BEGIN
Size := InitValue() ; (* Size of array. *)
Offset := InitValue() ; (* Offset of array. *)
Type := NulSym ; (* The Array Type. ARRAY OF Type. *)
Align := NulSym ; (* Alignment of this type. *)
Large := FALSE ; (* is this array large? *)
Align := NulSym ; (* The alignment of this type. *)
oafamily := oaf ; (* The unbounded for this array *)
Scope := GetCurrentScope() ; (* Which scope created it *)
InitWhereDeclaredTok(tok, At) (* Declared here *)
@@ -6992,19 +7026,19 @@ END GetNthParamChoice ;
PROCEDURE GetNthParamOrdered (sym: CARDINAL; ParamNo: CARDINAL;
a, b, c: ProcedureKind) : CARDINAL ;
VAR
param: CARDINAL ;
BEGIN
param := GetNthParamChoice (sym, ParamNo, a) ;
IF param = NulSym
IF GetProcedureParametersDefined (sym, a)
THEN
param := GetNthParamChoice (sym, ParamNo, b) ;
IF param = NulSym
RETURN GetNthParamChoice (sym, ParamNo, a)
ELSIF GetProcedureParametersDefined (sym, b)
THEN
RETURN GetNthParamChoice (sym, ParamNo, b)
ELSIF GetProcedureParametersDefined (sym, c)
THEN
param := GetNthParamChoice (sym, ParamNo, c)
RETURN GetNthParamChoice (sym, ParamNo, c)
ELSE
RETURN NulSym
END
END ;
RETURN param
END GetNthParamOrdered ;
@@ -7023,6 +7057,10 @@ END GetNthParamOrdered ;
PROCEDURE GetNthParamAnyClosest (sym: CARDINAL; ParamNo: CARDINAL;
currentmodule: CARDINAL) : CARDINAL ;
BEGIN
IF IsUnknown (sym)
THEN
InternalError (__FILE__ + ":" + __FUNCTION__ + ":not expecting an unknown symbol")
END ;
IF GetOuterModuleScope (currentmodule) = GetOuterModuleScope (sym)
THEN
(* Same module. *)
@@ -7042,11 +7080,22 @@ END GetNthParamAnyClosest ;
PROCEDURE GetOuterModuleScope (sym: CARDINAL) : CARDINAL ;
BEGIN
WHILE NOT (IsDefImp (sym) OR
(IsModule (sym) AND (GetScope (sym) = NulSym))) DO
sym := GetScope (sym)
END ;
REPEAT
IF IsDefImp (sym)
THEN
(* Definition/implementation module. *)
RETURN sym
ELSIF IsModule (sym)
THEN
IF GetScope (sym) = NulSym
THEN
(* Outer module. *)
RETURN sym
END
END ;
sym := GetScope (sym)
UNTIL sym = NulSym ;
InternalError ('not expecting to reach an outer scope')
END GetOuterModuleScope ;
@@ -11857,10 +11906,6 @@ BEGIN
CASE SymbolType OF
ErrorSym : n := 0 |
(*
ArraySym ,
UnboundedSym : n := 1 | (* Standard language limitation *)
*)
EnumerationSym: n := pSym^.Enumeration.NoOfElements |
InterfaceSym : n := HighIndice(Interface.Parameters)
@@ -11995,6 +12040,10 @@ BEGIN
InitPacked(packedInfo) ; (* not packed and no *)
(* equivalent (yet). *)
ispacked := FALSE ; (* Not yet known to be packed. *)
SetInWord := TRUE ; (* Can the set be stored in a *)
(* single word? *)
SetArray := NulSym ; (* Set used for large sets. *)
Align := NulSym ;
oafamily := oaf ; (* The unbounded sym for this *)
Scope := GetCurrentScope() ; (* Which scope created it *)
InitWhereDeclaredTok(tok, At) (* Declared here *)
@@ -12031,6 +12080,46 @@ BEGIN
END PutSet ;
(*
PutSetArray - places array into the setarray field.
*)
PROCEDURE PutSetArray (Sym: CARDINAL; array: CARDINAL) ;
VAR
pSym: PtrToSymbol ;
BEGIN
pSym := GetPsym(Sym) ;
WITH pSym^ DO
CASE SymbolType OF
ErrorSym: |
SetSym: WITH Set DO
SetArray := array
END
ELSE
InternalError ('expecting a Set symbol')
END
END
END PutSetArray ;
(*
MakeSetArray - create an ARRAY simpletype OF BOOLEAN.
*)
PROCEDURE MakeSetArray (token: CARDINAL; subrangetype: CARDINAL) : CARDINAL ;
VAR
array, subscript: CARDINAL ;
BEGIN
array := MakeArray (token, NulSym) ;
PutArray (array, Byte) ;
subscript := MakeSubscript () ;
PutSubscript (subscript, subrangetype) ;
PutArraySubscript (array, subscript) ;
RETURN array
END MakeSetArray ;
(*
IsSet - returns TRUE if Sym is a set symbol.
*)
@@ -12059,6 +12148,77 @@ BEGIN
END IsSetPacked ;
(*
GetSetArray - return the set array for a large set.
*)
PROCEDURE GetSetArray (sym: CARDINAL) : CARDINAL ;
VAR
pSym: PtrToSymbol ;
BEGIN
AssertInRange (sym) ;
pSym := GetPsym (sym) ;
WITH pSym^ DO
CASE SymbolType OF
SetSym: RETURN Set.SetArray
ELSE
RETURN NulSym
END
END
END GetSetArray ;
(*
PutSetInWord - set the SetInWord boolean to value.
*)
PROCEDURE PutSetInWord (sym: CARDINAL; value: BOOLEAN) ;
VAR
pSym: PtrToSymbol ;
BEGIN
AssertInRange (sym) ;
pSym := GetPsym (sym) ;
WITH pSym^ DO
CASE SymbolType OF
SetSym: Set.SetInWord := value ;
IF value
THEN
Set.Align := MakeConstant (GetDeclaredMod (sym), 0) ;
Set.ispacked := TRUE
END
ELSE
InternalError ('expecting a set symbol')
END
END
END PutSetInWord ;
(*
GetSetInWord - return SetInWord.
*)
PROCEDURE GetSetInWord (sym: CARDINAL) : BOOLEAN ;
VAR
pSym: PtrToSymbol ;
BEGIN
AssertInRange (sym) ;
pSym := GetPsym (sym) ;
WITH pSym^ DO
CASE SymbolType OF
SetSym: RETURN Set.SetInWord
ELSE
InternalError ('expecting a Set symbol')
END
END
END GetSetInWord ;
(*
ForeachParameterDo -
*)
@@ -12742,9 +12902,9 @@ BEGIN
type := SkipType(GetType(subscript)) ;
IF IsAModula2Type(type)
THEN
(* ok all is good *)
(* Ok all is good. *)
ELSE
MetaError2('the array {%1Dad} must be declared with a simpletype in the [..] component rather than a {%2d}',
MetaError2('the array {%1Dad} must be declared with a simpletype in the [..] component rather than a {%2dv}',
sym, type)
END
END
@@ -15166,9 +15326,10 @@ BEGIN
RecordSym : Record.Align := align |
RecordFieldSym: RecordField.Align := align |
TypeSym : Type.Align := align |
ArraySym : Array.Align := align |
PointerSym : Pointer.Align := align |
SubrangeSym : Subrange.Align := align
SubrangeSym : Subrange.Align := align |
SetSym : Set.Align := align |
ArraySym : Array.Align := align
ELSE
InternalError ('expecting record, field, pointer, type, subrange or an array symbol')
@@ -15193,11 +15354,12 @@ BEGIN
RecordSym : RETURN( Record.Align ) |
RecordFieldSym : RETURN( RecordField.Align ) |
TypeSym : RETURN( Type.Align ) |
ArraySym : RETURN( Array.Align ) |
PointerSym : RETURN( Pointer.Align ) |
VarientFieldSym: RETURN( GetAlignment(VarientField.Parent) ) |
VarientSym : RETURN( GetAlignment(Varient.Parent) ) |
SubrangeSym : RETURN( Subrange.Align )
SubrangeSym : RETURN( Subrange.Align ) |
SetSym : RETURN( Set.Align ) |
ArraySym : RETURN( Array.Align )
ELSE
InternalError ('expecting record, field, pointer, type, subrange or an array symbol')
+2
View File
@@ -107,6 +107,7 @@ EXTERN void _M2_M2SSA_init (int argc, char *argv[], char *envp[]);
EXTERN void _M2_M2SymInit_init (int argc, char *argv[], char *envp[]);
EXTERN void _M2_M2StateCheck_init (int argc, char *argv[], char *envp[]);
EXTERN void _M2_P3Build_init (int argc, char *argv[], char *envp[]);
EXTERN void _M2_M2Diagnostic_init (int argc, char *argv[], char *envp[]);
EXTERN void exit (int);
EXTERN void M2Comp_compile (const char *filename);
EXTERN void RTExceptions_DefaultErrorCatch (void);
@@ -126,6 +127,7 @@ init_FrontEndInit (void)
_M2_M2Dependent_init (0, NULL, NULL);
_M2_M2RTS_init (0, NULL, NULL);
_M2_SysExceptions_init (0, NULL, NULL);
_M2_M2Diagnostic_init (0, NULL, NULL);
_M2_DynamicStrings_init (0, NULL, NULL);
_M2_Assertion_init (0, NULL, NULL);
_M2_FormatStrings_init (0, NULL, NULL);
+16
View File
@@ -115,6 +115,22 @@ typedef struct stmt_tree_s *stmt_tree_t;
static location_t pending_location;
static int pending_statement = false;
/* GetTotalConstants returns the number of global constants. */
int
m2block_GetTotalConstants (void)
{
return m2treelib_nCount (global_binding_level->constants);
}
/* GetGlobalTypes returns the number of global types. */
int
m2block_GetGlobalTypes (void)
{
return m2treelib_nCount (global_binding_level->types);
}
/* assert_global_names asserts that the global_binding_level->names
can be chained. */
+14
View File
@@ -220,4 +220,18 @@ PROCEDURE addStmtNote (location: location_t) ;
PROCEDURE removeStmtNote ;
(*
GetTotalConstants - returns the number of global constants.
*)
PROCEDURE GetTotalConstants () : CARDINAL ;
(*
GetGlobalTypes - returns the number of global types.
*)
PROCEDURE GetGlobalTypes () : CARDINAL ;
END m2block.
+2
View File
@@ -72,6 +72,8 @@ EXTERN void m2block_includeDecl (tree);
EXTERN tree m2block_add_stmt (location_t location, tree t);
EXTERN void m2block_addStmtNote (location_t location);
EXTERN void m2block_removeStmtNote (void);
EXTERN int m2block_GetTotalConstants (void);
EXTERN int m2block_GetGlobalTypes (void);
EXTERN void m2block_init (void);
+29 -3
View File
@@ -344,6 +344,17 @@ same_size_types (location_t location, tree t1, tree t2)
return m2expr_CompareTrees (n1, n2) == 0;
}
/* converting_ISO_generic attempts to convert value to type and returns true
if successful. This is a helper function to BuildConvert which will try
each generic data type in turn.
generic_type will be set to any of ISO BYTE, PIM BYTE WORD, etc.
If type == generic_type then specific conversion procedures
are applied. A constant will be converted via const_to_ISO_type
whereas non constants are converted by *(type *) &value.
Remember that in ISO M2 BYTE is an ARRAY [0..0] OF LOC. */
static int
converting_ISO_generic (location_t location, tree type, tree value,
tree generic_type, tree *result)
@@ -354,11 +365,17 @@ converting_ISO_generic (location_t location, tree type, tree value,
/* We let the caller deal with this. */
return false;
if ((TREE_CODE (value) == INTEGER_CST) && (type == generic_type))
if (TREE_CODE (value) == INTEGER_CST)
{
if (type == generic_type)
{
*result = const_to_ISO_type (location, value, generic_type);
return true;
}
/* We must not attempt to convert a constant by taking its
address below, so we bail out here. */
return false;
}
if (same_size_types (location, type, value_type))
{
@@ -382,8 +399,8 @@ converting_ISO_generic (location_t location, tree type, tree value,
return false;
}
/* convert_char_to_array - convert a single char, value, into an
type. The type will be array [..] of char. The array type
/* convert_char_to_array convert a single char value into a type.
The type will be array [..] of char. The array type
returned will have nuls appended to pad the single char to the
correct array length. */
@@ -638,6 +655,15 @@ m2convert_ToLoc (location_t location, tree expr)
false);
}
/* ToPIMByte - convert an expression expr to a PIM BYTE. */
tree
m2convert_ToPIMByte (location_t location, tree expr)
{
return m2convert_BuildConvert (location, m2type_GetByteType (), expr,
false);
}
/* GenericToType - converts, expr, into, type, providing that expr is
a generic system type (byte, word etc). Otherwise expr is
returned unaltered. */
+14
View File
@@ -53,6 +53,20 @@ PROCEDURE ToInteger (location: location_t; expr: tree) : tree ;
PROCEDURE ToBitset (location: location_t; expr: tree) : tree ;
(*
ToLoc - convert an expression, expr, to a LOC.
*)
PROCEDURE ToLoc (location: location_t; expr: tree) : tree ;
(*
ToPIMByte - convert an expression expr to a PIM BYTE.
*)
PROCEDURE ToPIMByte (location: location_t; expr: tree) : tree ;
(*
ConvertToPtr - convert an expression to a void *.
*)
+2
View File
@@ -47,6 +47,8 @@ EXTERN tree m2convert_ToInteger (location_t location, tree expr);
EXTERN tree m2convert_ToWord (location_t location, tree expr);
EXTERN tree m2convert_ToBitset (location_t location, tree expr);
EXTERN tree m2convert_ToLoc (location_t location, tree expr);
EXTERN tree m2convert_ToPIMByte (location_t location, tree expr);
EXTERN tree m2convert_GenericToType (location_t location, tree type,
tree expr);
-1
View File
@@ -51,7 +51,6 @@ EXTERN tree m2decl_BuildConstLiteralNumber (location_t location,
const char *str,
unsigned int base,
bool issueError);
EXTERN void m2decl_RememberVariables (tree l);
EXTERN tree m2decl_BuildEndFunctionDeclaration (
location_t location_begin, location_t location_end, const char *name,
+112 -456
View File
@@ -598,7 +598,7 @@ m2expr_BuildLogicalShift (location_t location, tree op1, tree op2, tree op3,
m2convert_ToInteger (location, op3),
m2expr_GetIntegerZero (location));
m2statement_DoJump (location, is_less, NULL, labelElseName);
m2statement_IfExprJump (location, is_less, labelElseName);
op2 = m2convert_ToWord (location, op2);
op3 = m2convert_ToWord (location, op3);
res = m2expr_BuildLSL (location, op2, op3, needconvert);
@@ -673,7 +673,7 @@ m2expr_BuildLRotate (location_t location, tree op1, tree nBits,
op1 = m2expr_FoldAndStrip (op1);
nBits = m2expr_FoldAndStrip (nBits);
nBits = m2convert_BuildConvert (location, TREE_TYPE (op1), nBits, needconvert);
nBits = m2convert_BuildConvert (location, TREE_TYPE (op1), nBits, needconvert);
t = m2expr_build_binary_op (location, LROTATE_EXPR, op1, nBits, needconvert);
return m2expr_FoldAndStrip (t);
}
@@ -724,15 +724,15 @@ m2expr_BuildLRLn (location_t location, tree op1, tree op2, tree nBits,
/* Make absolutely sure there are no high order bits lying around. */
op1 = m2expr_BuildLogicalAnd (location, op1, mask, needconvert);
op1 = m2expr_BuildLogicalAnd (location, op1, mask);
left = m2expr_BuildLSL (location, op1, op2min, needconvert);
left = m2expr_BuildLogicalAnd (location, left, mask, needconvert);
left = m2expr_BuildLogicalAnd (location, left, mask);
right = m2expr_BuildLSR (
location, op1,
m2expr_BuildSub (location, m2convert_ToCardinal (location, nBits),
op2min, needconvert),
needconvert);
return m2expr_BuildLogicalOr (location, left, right, needconvert);
return m2expr_BuildLogicalOr (location, left, right);
}
}
@@ -765,15 +765,15 @@ m2expr_BuildLRRn (location_t location, tree op1, tree op2, tree nBits,
/* Make absolutely sure there are no high order bits lying around. */
op1 = m2expr_BuildLogicalAnd (location, op1, mask, needconvert);
op1 = m2expr_BuildLogicalAnd (location, op1, mask);
right = m2expr_BuildLSR (location, op1, op2min, needconvert);
left = m2expr_BuildLSL (
location, op1,
m2expr_BuildSub (location, m2convert_ToCardinal (location, nBits),
op2min, needconvert),
needconvert);
left = m2expr_BuildLogicalAnd (location, left, mask, needconvert);
return m2expr_BuildLogicalOr (location, left, right, needconvert);
left = m2expr_BuildLogicalAnd (location, left, mask);
return m2expr_BuildLogicalOr (location, left, right);
}
}
@@ -807,7 +807,7 @@ m2expr_BuildLogicalRotate (location_t location, tree op1, tree op2, tree op3,
tree is_less = m2expr_BuildLessThan (location, rotateCount,
m2expr_GetIntegerZero (location));
m2statement_DoJump (location, is_less, NULL, labelElseName);
m2statement_IfExprJump (location, is_less, labelElseName);
res = m2expr_BuildLRLn (location, op2, rotateCount, nBits, needconvert);
m2statement_BuildAssignmentTree (location, op1, res);
m2statement_BuildGoto (location, labelEndName);
@@ -819,139 +819,43 @@ m2expr_BuildLogicalRotate (location_t location, tree op1, tree op2, tree op3,
}
}
/* buildUnboundedArrayOf construct an unbounded struct and returns
the gcc tree. The two fields of the structure are initialized to
contentsPtr and high. */
/* BuildIfBitInSetLower returns tree ((set >> bit) & 1). It converts set and bit to
type word prior to the bit test. */
static tree
buildUnboundedArrayOf (tree unbounded, tree contentsPtr, tree high)
BuildIfBitInSetLower (location_t location, enum tree_code code, tree set, tree bit)
{
tree fields = TYPE_FIELDS (unbounded);
tree field_list = NULL_TREE;
tree constructor;
field_list = tree_cons (fields, contentsPtr, field_list);
fields = TREE_CHAIN (fields);
field_list = tree_cons (fields, high, field_list);
constructor = build_constructor_from_list (unbounded, nreverse (field_list));
TREE_CONSTANT (constructor) = 0;
TREE_STATIC (constructor) = 0;
return constructor;
set = m2convert_ToWord (location, set);
bit = m2convert_ToWord (location, bit);
set = m2expr_BuildLSR (location, set, bit, false);
return m2expr_build_binary_op (location, code,
m2expr_build_binary_op (location,
BIT_AND_EXPR, set,
m2expr_GetWordOne (location), false),
m2expr_GetWordZero (location), FALSE);
}
/* BuildBinarySetDo if the size of the set is <= TSIZE(WORD) then op1
:= binop(op2, op3) else call m2rtsprocedure(op1, op2, op3). */
/* BuildIfInSet returns tree (bit IN set). */
void
m2expr_BuildBinarySetDo (location_t location, tree settype, tree op1, tree op2,
tree op3, void (*binop) (location_t, tree, tree, tree,
tree, bool),
bool is_op1lvalue, bool is_op2lvalue, bool is_op3lvalue,
tree nBits, tree unbounded, tree varproc,
tree leftproc, tree rightproc)
tree
m2expr_BuildIfInSet (location_t location, tree set, tree bit)
{
tree size = m2expr_GetSizeOf (location, settype);
bool is_const = false;
bool is_left = false;
m2assert_AssertLocation (location);
ASSERT_BOOL (is_op1lvalue);
ASSERT_BOOL (is_op2lvalue);
ASSERT_BOOL (is_op3lvalue);
if (m2expr_CompareTrees (
size, m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT))
<= 0)
/* Small set size <= TSIZE(WORD). */
(*binop) (location,
m2treelib_get_rvalue (location, op1, settype, is_op1lvalue),
m2treelib_get_rvalue (location, op2, settype, is_op2lvalue),
m2treelib_get_rvalue (location, op3, settype, is_op3lvalue),
nBits, false);
else
{
tree result;
tree high = m2expr_BuildSub (
location,
m2convert_ToCardinal (
location,
m2expr_BuildDivTrunc (
location, size,
m2expr_GetSizeOf (location, m2type_GetBitsetType ()),
false)),
m2expr_GetCardinalOne (location), false);
/* If op3 is constant then make op3 positive and remember which
direction we are shifting. */
op3 = m2tree_skip_const_decl (op3);
if (TREE_CODE (op3) == INTEGER_CST)
{
is_const = true;
if (tree_int_cst_sgn (op3) < 0)
op3 = m2expr_BuildNegate (location, op3, false);
else
is_left = true;
op3 = m2convert_BuildConvert (location, m2type_GetM2CardinalType (),
op3, false);
}
/* These parameters must match the prototypes of the procedures:
ShiftLeft, ShiftRight, ShiftVal, RotateLeft, RotateRight, RotateVal
inside gm2-iso/SYSTEM.mod. */
/* Remember we must build the parameters in reverse. */
/* Parameter 4 amount. */
m2statement_BuildParam (
location,
m2convert_BuildConvert (
location, m2type_GetM2IntegerType (),
m2treelib_get_rvalue (location, op3,
m2tree_skip_type_decl (TREE_TYPE (op3)),
is_op3lvalue),
false));
/* Parameter 3 nBits. */
m2statement_BuildParam (
location,
m2convert_BuildConvert (location, m2type_GetM2CardinalType (),
m2expr_FoldAndStrip (nBits), false));
/* Parameter 2 destination set. */
m2statement_BuildParam (
location,
buildUnboundedArrayOf (
unbounded,
m2treelib_get_set_address (location, op1, is_op1lvalue), high));
/* Parameter 1 source set. */
m2statement_BuildParam (
location,
buildUnboundedArrayOf (
unbounded,
m2treelib_get_set_address (location, op2, is_op2lvalue), high));
/* Now call the appropriate procedure inside SYSTEM.mod. */
if (is_const)
if (is_left)
result = m2statement_BuildProcedureCallTree (location, leftproc,
NULL_TREE);
else
result = m2statement_BuildProcedureCallTree (location, rightproc,
NULL_TREE);
else
result = m2statement_BuildProcedureCallTree (location, varproc,
NULL_TREE);
add_stmt (location, result);
}
return BuildIfBitInSetLower (location, NE_EXPR, set, bit);
}
/* Print a warning if a constant expression had overflow in folding.
/* BuildIfInSet returns tree (NOT (bit IN set)). */
tree
m2expr_BuildIfNotInSet (location_t location, tree set, tree bit)
{
m2assert_AssertLocation (location);
return BuildIfBitInSetLower (location, EQ_EXPR, set, bit);
}
/* Print a warning if a constant expression caused overflow in folding.
Invoke this function on every expression that the language requires
to be a constant expression. */
@@ -1463,11 +1367,11 @@ m2expr_Build4LogicalOr (location_t location, tree op1, tree op2, tree op3,
tree op4)
{
tree t1 = m2expr_FoldAndStrip (
m2expr_BuildLogicalOr (location, op1, op2, false));
m2expr_BuildLogicalOr (location, op1, op2));
tree t2
= m2expr_FoldAndStrip (m2expr_BuildLogicalOr (location, t1, op3, false));
= m2expr_FoldAndStrip (m2expr_BuildLogicalOr (location, t1, op3));
return m2expr_FoldAndStrip (
m2expr_BuildLogicalOr (location, t2, op4, false));
m2expr_BuildLogicalOr (location, t2, op4));
}
/* checkWholeMultOverflow - check to see whether i * j will overflow
@@ -2697,15 +2601,15 @@ m2expr_BuildNegate (location_t location, tree op1, bool needconvert)
/* BuildSetNegate build a set negate expression and returns the tree. */
tree
m2expr_BuildSetNegate (location_t location, tree op1, bool needconvert)
m2expr_BuildSetNegate (location_t location, tree value)
{
m2assert_AssertLocation (location);
return m2expr_build_binary_op (
location, BIT_XOR_EXPR,
m2convert_BuildConvert (location, m2type_GetWordType (),
m2expr_FoldAndStrip (op1), false),
set_full_complement, needconvert);
m2expr_FoldAndStrip (value), false),
set_full_complement, false);
}
/* BuildMult build a multiplication tree. */
@@ -2984,73 +2888,67 @@ m2expr_BuildOffset (location_t location, tree record, tree field,
/* BuildLogicalOrAddress build a logical or expressions and return the tree. */
tree
m2expr_BuildLogicalOrAddress (location_t location, tree op1, tree op2,
bool needconvert)
m2expr_BuildLogicalOrAddress (location_t location, tree op1, tree op2)
{
m2assert_AssertLocation (location);
return m2expr_build_binary_op (location, BIT_IOR_EXPR, op1, op2,
needconvert);
return m2expr_build_binary_op (location, BIT_IOR_EXPR, op1, op2, false);
}
/* BuildLogicalOr build a logical or expressions and return the tree. */
tree
m2expr_BuildLogicalOr (location_t location, tree op1, tree op2,
bool needconvert)
m2expr_BuildLogicalOr (location_t location, tree op1, tree op2)
{
m2assert_AssertLocation (location);
return m2expr_build_binary_op (
location, BIT_IOR_EXPR,
m2convert_BuildConvert (location, m2type_GetWordType (), op1, false),
m2convert_BuildConvert (location, m2type_GetWordType (), op2, false),
needconvert);
false);
}
/* BuildLogicalAnd build a logical and expression and return the tree. */
tree
m2expr_BuildLogicalAnd (location_t location, tree op1, tree op2,
bool needconvert)
m2expr_BuildLogicalAnd (location_t location, tree op1, tree op2)
{
m2assert_AssertLocation (location);
return m2expr_build_binary_op (
location, BIT_AND_EXPR,
m2convert_BuildConvert (location, m2type_GetWordType (), op1, false),
m2convert_BuildConvert (location, m2type_GetWordType (), op2, false),
needconvert);
false);
}
/* BuildSymmetricalDifference build a logical xor expression and return the
* tree. */
tree. */
tree
m2expr_BuildSymmetricDifference (location_t location, tree op1, tree op2,
bool needconvert)
m2expr_BuildSymmetricDifference (location_t location, tree left, tree right)
{
m2assert_AssertLocation (location);
return m2expr_build_binary_op (
location, BIT_XOR_EXPR,
m2convert_BuildConvert (location, m2type_GetWordType (), op1, false),
m2convert_BuildConvert (location, m2type_GetWordType (), op2, false),
needconvert);
m2convert_BuildConvert (location, m2type_GetWordType (), left, false),
m2convert_BuildConvert (location, m2type_GetWordType (), right, false),
false);
}
/* BuildLogicalDifference build a logical difference expression and
return the tree. (op1 and (not op2)). */
/* BuildLogicalDifference build a logical difference expression tree.
Return (left and (not right)). */
tree
m2expr_BuildLogicalDifference (location_t location, tree op1, tree op2,
bool needconvert)
m2expr_BuildLogicalDifference (location_t location, tree left, tree right)
{
m2assert_AssertLocation (location);
return m2expr_build_binary_op (
location, BIT_AND_EXPR,
m2convert_BuildConvert (location, m2type_GetWordType (), op1, false),
m2expr_BuildSetNegate (location, op2, needconvert), needconvert);
m2convert_BuildConvert (location, m2type_GetWordType (), left, false),
m2expr_BuildSetNegate (location, right), false);
}
/* base_type returns the base type of an ordinal subrange, or the
type itself if it is not a subrange. */
type itself if it is not a subrange. */
static tree
base_type (tree type)
@@ -3064,20 +2962,20 @@ base_type (tree type)
return TYPE_MAIN_VARIANT (type);
}
/* boolean_enum_to_unsigned convert a BOOLEAN_TYPE, t, or
/* boolean_enum_to_unsigned convert a BOOLEAN_TYPE value or
ENUMERAL_TYPE to an unsigned type. */
static tree
boolean_enum_to_unsigned (location_t location, tree t)
boolean_enum_to_unsigned (location_t location, tree value)
{
tree type = TREE_TYPE (t);
tree type = TREE_TYPE (value);
if (TREE_CODE (base_type (type)) == BOOLEAN_TYPE)
return m2convert_BuildConvert (location, unsigned_type_node, t, false);
return m2convert_BuildConvert (location, unsigned_type_node, value, false);
else if (TREE_CODE (base_type (type)) == ENUMERAL_TYPE)
return m2convert_BuildConvert (location, unsigned_type_node, t, false);
return m2convert_BuildConvert (location, unsigned_type_node, value, false);
else
return t;
return value;
}
/* check_for_comparison check to see if, op, is of type, badType. If
@@ -3190,7 +3088,7 @@ m2expr_BuildIsSuperset (location_t location, tree op1, tree op2)
{
m2assert_AssertLocation (location);
return m2expr_BuildEqualTo (
location, op2, m2expr_BuildLogicalAnd (location, op1, op2, false));
location, op2, m2expr_BuildLogicalAnd (location, op1, op2));
}
/* BuildIsNotSuperset return a tree which computes: op1 & op2 != op2. */
@@ -3200,7 +3098,7 @@ m2expr_BuildIsNotSuperset (location_t location, tree op1, tree op2)
{
m2assert_AssertLocation (location);
return m2expr_BuildNotEqualTo (
location, op2, m2expr_BuildLogicalAnd (location, op1, op2, false));
location, op2, m2expr_BuildLogicalAnd (location, op1, op2));
}
/* BuildIsSubset return a tree which computes: op1 & op2 == op1. */
@@ -3210,7 +3108,7 @@ m2expr_BuildIsSubset (location_t location, tree op1, tree op2)
{
m2assert_AssertLocation (location);
return m2expr_BuildEqualTo (
location, op1, m2expr_BuildLogicalAnd (location, op1, op2, false));
location, op1, m2expr_BuildLogicalAnd (location, op1, op2));
}
/* BuildIsNotSubset return a tree which computes: op1 & op2 != op1. */
@@ -3220,224 +3118,22 @@ m2expr_BuildIsNotSubset (location_t location, tree op1, tree op2)
{
m2assert_AssertLocation (location);
return m2expr_BuildNotEqualTo (
location, op1, m2expr_BuildLogicalAnd (location, op1, op2, false));
location, op1, m2expr_BuildLogicalAnd (location, op1, op2));
}
/* BuildIfConstInVar generates: if constel in varset then goto label. */
/* BuildIfBitInSetJump build and add a statement tree containing:
if (bit in setvalue) goto label. If invertCondition is true then
the tree created will take the form:
if not (bit in setvalue) goto label. */
void
m2expr_BuildIfConstInVar (location_t location, tree type, tree varset,
tree constel, bool is_lvalue, int fieldno,
char *label)
m2expr_BuildIfBitInSetJump (location_t location, bool invertCondition,
tree setvalue, tree bit, char *label)
{
tree size = m2expr_GetSizeOf (location, type);
m2assert_AssertLocation (location);
ASSERT_BOOL (is_lvalue);
if (m2expr_CompareTrees (
size, m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT))
<= 0)
/* Small set size <= TSIZE(WORD). */
m2treelib_do_jump_if_bit (
location, NE_EXPR,
m2treelib_get_rvalue (location, varset, type, is_lvalue), constel,
label);
if (invertCondition)
m2treelib_do_jump_if_bit (location, NE_EXPR, setvalue, bit, label);
else
{
tree fieldlist = TYPE_FIELDS (type);
tree field;
for (field = fieldlist; (field != NULL) && (fieldno > 0);
field = TREE_CHAIN (field))
fieldno--;
m2treelib_do_jump_if_bit (
location, NE_EXPR,
m2treelib_get_set_field_rhs (location, varset, field), constel,
label);
}
}
/* BuildIfConstInVar generates: if not (constel in varset) then goto label. */
void
m2expr_BuildIfNotConstInVar (location_t location, tree type, tree varset,
tree constel, bool is_lvalue, int fieldno,
char *label)
{
tree size = m2expr_GetSizeOf (location, type);
m2assert_AssertLocation (location);
ASSERT_BOOL (is_lvalue);
if (m2expr_CompareTrees (
size, m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT))
<= 0)
/* Small set size <= TSIZE(WORD). */
m2treelib_do_jump_if_bit (
location, EQ_EXPR,
m2treelib_get_rvalue (location, varset, type, is_lvalue), constel,
label);
else
{
tree fieldlist = TYPE_FIELDS (type);
tree field;
for (field = fieldlist; (field != NULL) && (fieldno > 0);
field = TREE_CHAIN (field))
fieldno--;
m2treelib_do_jump_if_bit (
location, EQ_EXPR,
m2treelib_get_set_field_rhs (location, varset, field), constel,
label);
}
}
/* BuildIfVarInVar generates: if varel in varset then goto label. */
void
m2expr_BuildIfVarInVar (location_t location, tree type, tree varset,
tree varel, bool is_lvalue, tree low,
tree high ATTRIBUTE_UNUSED, char *label)
{
tree size = m2expr_GetSizeOf (location, type);
/* Calculate the index from the first bit, ie bit 0 represents low value. */
tree index = m2expr_BuildSub (
location, m2convert_BuildConvert (location, m2type_GetIntegerType (),
varel, false),
m2convert_BuildConvert (location, m2type_GetIntegerType (), low, false),
false);
m2assert_AssertLocation (location);
if (m2expr_CompareTrees (
size, m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT))
<= 0)
/* Small set size <= TSIZE(WORD). */
m2treelib_do_jump_if_bit (
location, NE_EXPR,
m2treelib_get_rvalue (location, varset, type, is_lvalue), index,
label);
else
{
tree p1 = m2treelib_get_set_address (location, varset, is_lvalue);
/* Which word do we need to fetch? */
tree word_index = m2expr_FoldAndStrip (m2expr_BuildDivTrunc (
location, index, m2decl_BuildIntegerConstant (SET_WORD_SIZE),
false));
/* Calculate the bit in this word. */
tree offset_into_word = m2expr_FoldAndStrip (m2expr_BuildModTrunc (
location, index, m2decl_BuildIntegerConstant (SET_WORD_SIZE),
false));
tree p2 = m2expr_FoldAndStrip (m2expr_BuildMult (
location, word_index,
m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT), false));
/* Calculate the address of the word we are interested in. */
p1 = m2expr_BuildAddAddress (location,
m2convert_convertToPtr (location, p1), p2);
/* Fetch the word, extract the bit and test for != 0. */
m2treelib_do_jump_if_bit (
location, NE_EXPR,
m2expr_BuildIndirect (location, p1, m2type_GetBitsetType ()),
offset_into_word, label);
}
}
/* BuildIfNotVarInVar generates: if not (varel in varset) then goto label. */
void
m2expr_BuildIfNotVarInVar (location_t location, tree type, tree varset,
tree varel, bool is_lvalue, tree low,
tree high ATTRIBUTE_UNUSED, char *label)
{
tree size = m2expr_GetSizeOf (location, type);
/* Calculate the index from the first bit, ie bit 0 represents low value. */
tree index = m2expr_BuildSub (
location, m2convert_BuildConvert (location, m2type_GetIntegerType (),
m2expr_FoldAndStrip (varel), false),
m2convert_BuildConvert (location, m2type_GetIntegerType (),
m2expr_FoldAndStrip (low), false),
false);
index = m2expr_FoldAndStrip (index);
m2assert_AssertLocation (location);
if (m2expr_CompareTrees (
size, m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT))
<= 0)
/* Small set size <= TSIZE(WORD). */
m2treelib_do_jump_if_bit (
location, EQ_EXPR,
m2treelib_get_rvalue (location, varset, type, is_lvalue), index,
label);
else
{
tree p1 = m2treelib_get_set_address (location, varset, is_lvalue);
/* Calculate the index from the first bit. */
/* Which word do we need to fetch? */
tree word_index = m2expr_FoldAndStrip (m2expr_BuildDivTrunc (
location, index, m2decl_BuildIntegerConstant (SET_WORD_SIZE),
false));
/* Calculate the bit in this word. */
tree offset_into_word = m2expr_FoldAndStrip (m2expr_BuildModTrunc (
location, index, m2decl_BuildIntegerConstant (SET_WORD_SIZE),
false));
tree p2 = m2expr_FoldAndStrip (m2expr_BuildMult (
location, word_index,
m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT), false));
/* Calculate the address of the word we are interested in. */
p1 = m2expr_BuildAddAddress (location, p1, p2);
/* Fetch the word, extract the bit and test for == 0. */
m2treelib_do_jump_if_bit (
location, EQ_EXPR,
m2expr_BuildIndirect (location, p1, m2type_GetBitsetType ()),
offset_into_word, label);
}
}
/* BuildForeachWordInSetDoIfExpr foreach word in set, type, compute
the expression, expr, and if true goto label. */
void
m2expr_BuildForeachWordInSetDoIfExpr (location_t location, tree type, tree op1,
tree op2, bool is_op1lvalue,
bool is_op2lvalue, bool is_op1const,
bool is_op2const,
tree (*expr) (location_t, tree, tree),
char *label)
{
tree p1 = m2treelib_get_set_address_if_var (location, op1, is_op1lvalue,
is_op1const);
tree p2 = m2treelib_get_set_address_if_var (location, op2, is_op2lvalue,
is_op2const);
unsigned int fieldNo = 0;
tree field1 = m2treelib_get_field_no (type, op1, is_op1const, fieldNo);
tree field2 = m2treelib_get_field_no (type, op2, is_op2const, fieldNo);
m2assert_AssertLocation (location);
ASSERT_CONDITION (TREE_CODE (TREE_TYPE (op1)) == RECORD_TYPE);
ASSERT_CONDITION (TREE_CODE (TREE_TYPE (op2)) == RECORD_TYPE);
while (field1 != NULL && field2 != NULL)
{
m2statement_DoJump (
location,
(*expr) (location,
m2treelib_get_set_value (location, p1, field1, is_op1const,
is_op1lvalue, op1, fieldNo),
m2treelib_get_set_value (location, p2, field2, is_op2const,
is_op2lvalue, op2, fieldNo)),
NULL, label);
fieldNo++;
field1 = m2treelib_get_field_no (type, op1, is_op1const, fieldNo);
field2 = m2treelib_get_field_no (type, op2, is_op2const, fieldNo);
}
m2treelib_do_jump_if_bit (location, EQ_EXPR, setvalue, bit, label);
}
/* BuildIfInRangeGoto returns a tree containing if var is in the
@@ -3450,16 +3146,16 @@ m2expr_BuildIfInRangeGoto (location_t location, tree var, tree low, tree high,
m2assert_AssertLocation (location);
if (m2expr_CompareTrees (low, high) == 0)
m2statement_DoJump (location, m2expr_BuildEqualTo (location, var, low),
NULL, label);
m2statement_IfExprJump (location, m2expr_BuildEqualTo (location, var, low),
label);
else
m2statement_DoJump (
m2statement_IfExprJump (
location,
m2expr_build_binary_op (
location, TRUTH_ANDIF_EXPR,
m2expr_BuildGreaterThanOrEqual (location, var, low),
m2expr_BuildLessThanOrEqual (location, var, high), false),
NULL, label);
label);
}
/* BuildIfNotInRangeGoto returns a tree containing if var is not in
@@ -3472,15 +3168,15 @@ m2expr_BuildIfNotInRangeGoto (location_t location, tree var, tree low,
m2assert_AssertLocation (location);
if (m2expr_CompareTrees (low, high) == 0)
m2statement_DoJump (location, m2expr_BuildNotEqualTo (location, var, low),
NULL, label);
m2statement_IfExprJump (location, m2expr_BuildNotEqualTo (location, var, low),
label);
else
m2statement_DoJump (
m2statement_IfExprJump (
location, m2expr_build_binary_op (
location, TRUTH_ORIF_EXPR,
m2expr_BuildLessThan (location, var, low),
m2expr_BuildGreaterThan (location, var, high), false),
NULL, label);
label);
}
/* BuildArray - returns a tree which accesses array[index] given,
@@ -3829,75 +3525,18 @@ m2expr_BuildCmplx (location_t location, tree type, tree real, tree imag)
return build2 (COMPLEX_EXPR, type, real, imag);
}
/* BuildBinaryForeachWordDo implements the large set operators. Each
word of the set can be calculated by binop. This function runs along
each word of the large set invoking the binop. */
void
m2expr_BuildBinaryForeachWordDo (location_t location, tree type, tree op1,
tree op2, tree op3,
tree (*binop) (location_t, tree, tree, bool),
bool is_op1lvalue, bool is_op2lvalue,
bool is_op3lvalue, bool is_op1const,
bool is_op2const, bool is_op3const)
m2expr_SetAndNarrow (location_t location, tree settype,
tree op1, tree op2, tree op3,
bool is_op1lvalue, bool is_op2lvalue, bool is_op3lvalue)
{
tree size = m2expr_GetSizeOf (location, type);
m2assert_AssertLocation (location);
ASSERT_BOOL (is_op1lvalue);
ASSERT_BOOL (is_op2lvalue);
ASSERT_BOOL (is_op3lvalue);
ASSERT_BOOL (is_op1const);
ASSERT_BOOL (is_op2const);
ASSERT_BOOL (is_op3const);
if (m2expr_CompareTrees (
size, m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT))
<= 0)
/* Small set size <= TSIZE(WORD). */
m2statement_BuildAssignmentTree (
location, m2treelib_get_rvalue (location, op1, type, is_op1lvalue),
(*binop) (
location, m2treelib_get_rvalue (location, op2, type, is_op2lvalue),
m2treelib_get_rvalue (location, op3, type, is_op3lvalue), false));
else
{
/* Large set size > TSIZE(WORD). */
tree p2 = m2treelib_get_set_address_if_var (location, op2, is_op2lvalue,
is_op2const);
tree p3 = m2treelib_get_set_address_if_var (location, op3, is_op3lvalue,
is_op3const);
unsigned int fieldNo = 0;
tree field1 = m2treelib_get_field_no (type, op1, is_op1const, fieldNo);
tree field2 = m2treelib_get_field_no (type, op2, is_op2const, fieldNo);
tree field3 = m2treelib_get_field_no (type, op3, is_op3const, fieldNo);
if (is_op1const)
m2linemap_internal_error_at (
location,
"not expecting operand1 to be a constant set");
while (field1 != NULL && field2 != NULL && field3 != NULL)
{
m2statement_BuildAssignmentTree (
location, m2treelib_get_set_field_des (location, op1, field1),
(*binop) (
location,
m2treelib_get_set_value (location, p2, field2, is_op2const,
is_op2lvalue, op2, fieldNo),
m2treelib_get_set_value (location, p3, field3, is_op3const,
is_op3lvalue, op3, fieldNo),
false));
fieldNo++;
field1 = m2treelib_get_field_no (type, op1, is_op1const, fieldNo);
field2 = m2treelib_get_field_no (type, op2, is_op2const, fieldNo);
field3 = m2treelib_get_field_no (type, op3, is_op3const, fieldNo);
}
}
m2statement_BuildAssignmentTree (
location, m2expr_GetRValue (location, op1, settype, is_op1lvalue),
m2expr_BuildLogicalAnd (
location, m2expr_GetRValue (location, op2, settype, is_op2lvalue),
m2expr_GetRValue (location, op3, settype, is_op3lvalue)));
}
/* OverflowZType returns true if the ZTYPE str will exceed the
internal representation. This routine is much faster (at
least 2 orders of magnitude faster) than the char at a time overflow
@@ -4205,6 +3844,12 @@ m2expr_GetPointerOne (location_t location)
return m2convert_convertToPtr (location, integer_one_node);
}
tree
m2expr_GetBitsetZero (location_t location)
{
return m2convert_ToBitset (location, integer_zero_node);
}
/* build_set_full_complement return a word size value with all bits
set to one. */
@@ -4224,12 +3869,23 @@ build_set_full_complement (location_t location)
location, m2expr_GetWordOne (location),
m2convert_BuildConvert (location, m2type_GetWordType (),
m2decl_BuildIntegerConstant (i), false),
false),
false);
false));
}
return value;
}
/* GetRValue returns the rvalue of expr. The type is the object
type to be copied upon indirection. */
tree
m2expr_GetRValue (location_t location, tree expr, tree type, bool islvalue)
{
if (islvalue)
return m2expr_BuildIndirect (location, expr, type);
else
return expr;
}
/* GetCstInteger return the integer value of the cst tree. */
+32 -44
View File
@@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
along with GNU Modula-2; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. *)
DEFINITION MODULE FOR "C" m2expr ;
DEFINITION MODULE m2expr ;
FROM gcctypes IMPORT location_t, tree ;
FROM CDataTypes IMPORT CharStar, ConstCharStar ;
@@ -92,6 +92,9 @@ PROCEDURE GetCardinalOne (location: location_t) : tree ;
PROCEDURE GetCardinalZero (location: location_t) : tree ;
PROCEDURE GetBitsetZero (location: location_t) : tree ;
PROCEDURE GetSizeOfInBits (type: tree) : tree ;
@@ -365,7 +368,7 @@ PROCEDURE BuildNegateCheck (location: location_t; arg, lowest, min, max: tree) :
BuildSetNegate - builds a set negate expression and returns the tree.
*)
PROCEDURE BuildSetNegate (location: location_t; op1: tree; needconvert: BOOLEAN) : tree ;
PROCEDURE BuildSetNegate (location: location_t; op1: tree) : tree ;
(*
@@ -421,27 +424,32 @@ PROCEDURE BuildLogicalOrAddress (location: location_t; op1: tree; op2: tree; nee
BuildLogicalOr - build a logical or expressions and return the tree.
*)
PROCEDURE BuildLogicalOr (location: location_t; op1: tree; op2: tree; needconvert: BOOLEAN) : tree ;
PROCEDURE BuildLogicalOr (location: location_t; op1: tree; op2: tree) : tree ;
(*
BuildLogicalAnd - build a logical and expression and return the tree.
*)
PROCEDURE BuildLogicalAnd (location: location_t; op1: tree; op2: tree; needconvert: BOOLEAN) : tree ;
PROCEDURE BuildLogicalAnd (location: location_t; op1: tree; op2: tree) : tree ;
PROCEDURE BuildSymmetricDifference (location: location_t; op1: tree; op2: tree; needconvert: BOOLEAN) : tree ;
PROCEDURE BuildSymmetricDifference (location: location_t; op1: tree; op2: tree) : tree ;
(*
BuildLogicalDifference - build a logical difference expression and
return the tree.
(op1 and (not op2))
BuildLogicalDifference - build a logical difference expression tree.
Return (left and (not right)).
*)
PROCEDURE BuildLogicalDifference (location: location_t; op1: tree; op2: tree; needconvert: BOOLEAN) : tree ;
PROCEDURE BuildLogicalDifference (location: location_t;
left, right: tree) : tree ;
PROCEDURE BuildIfInSet (location: location_t; set, bit: tree) : tree ;
PROCEDURE BuildIfNotInSet (location: location_t; set, bit: tree) : tree ;
(*
@@ -473,14 +481,17 @@ PROCEDURE BuildGreaterThanOrEqual (location: location_t; op1: tree; op2: tree) :
(*
BuildEqualTo - return a tree which computes =
BuildEqualTo - return a tree which computes (left = right).
*)
PROCEDURE BuildEqualTo (location: location_t; op1: tree; op2: tree) : tree ;
PROCEDURE BuildEqualTo (location: location_t; left, right: tree) : tree ;
(*
BuildNotEqualTo - return a tree which computes (left # right).
*)
PROCEDURE BuildNotEqualTo (location: location_t; op1: tree; op2: tree) : tree ;
PROCEDURE BuildNotEqualTo (location: location_t; left, right: tree) : tree ;
(*
@@ -675,37 +686,6 @@ PROCEDURE BuildIm (op1: tree) : tree ;
PROCEDURE BuildCmplx (location: location_t; type: tree; real: tree; imag: tree) : tree ;
(*
BuildBinaryForeachWordDo - provides the large set operators. Each word
(or less) of the set can be calculated by binop.
This procedure runs along each word of the
large set invoking the binop.
*)
PROCEDURE BuildBinaryForeachWordDo (location: location_t;
type, op1, op2, op3: tree;
binop: BuildBinProcedure;
is_op1lvalue,
is_op2lvalue,
is_op3lvalue,
is_op1_const,
is_op2_const,
is_op3_const: BOOLEAN) ;
(*
BuildBinarySetDo - if the size of the set is <= TSIZE(WORD) then
op1 := binop(op2, op3)
else
call m2rtsprocedure(op1, op2, op3)
*)
PROCEDURE BuildBinarySetDo (location: location_t;
settype, op1, op2, op3: tree;
binop: BuildSetProcedure;
is_op1lvalue, is_op2lvalue, is_op3lvalue: BOOLEAN;
nBits, unbounded: tree;
varproc, leftproc, rightproc: tree) ;
(*
ConstantExpressionWarning - issue a warning if the constant has overflowed.
*)
@@ -744,6 +724,14 @@ PROCEDURE OverflowZType (location: location_t;
PROCEDURE BuildCondIfExpression (condition, type, left, right: tree) : tree ;
(*
GetRValue - returns the rvalue of expr. The type is the object
type to be copied upon indirection.
*)
PROCEDURE GetRValue (location: location_t; expr, type: tree;
islvalue: BOOLEAN) : tree ;
(*
BuildSystemTBitSize - return the minimum number of bits to represent type.
+11 -36
View File
@@ -40,11 +40,6 @@ EXTERN char m2expr_CSTIntToChar (tree t);
EXTERN char *m2expr_CSTIntToString (tree t);
EXTERN bool m2expr_StrToWideInt (location_t location, const char *str, unsigned int base,
widest_int &wval, bool issueError);
EXTERN void m2expr_BuildBinaryForeachWordDo (
location_t location, tree type, tree op1, tree op2, tree op3,
tree (*binop) (location_t, tree, tree, bool), bool is_op1lvalue,
bool is_op2lvalue, bool is_op3lvalue, bool is_op1const, bool is_op2const,
bool is_op3const);
EXTERN tree m2expr_BuildCmplx (location_t location, tree type, tree real,
tree imag);
EXTERN tree m2expr_BuildIm (tree op1);
@@ -65,25 +60,6 @@ EXTERN void m2expr_BuildIfNotInRangeGoto (location_t location, tree var,
tree low, tree high, char *label);
EXTERN void m2expr_BuildIfInRangeGoto (location_t location, tree var, tree low,
tree high, char *label);
EXTERN void m2expr_BuildForeachWordInSetDoIfExpr (
location_t location, tree type, tree op1, tree op2, bool is_op1lvalue,
bool is_op2lvalue, bool is_op1const, bool is_op2const,
tree (*expr) (location_t, tree, tree), char *label);
EXTERN void m2expr_BuildIfNotVarInVar (location_t location, tree type,
tree varset, tree varel, bool is_lvalue,
tree low, tree high ATTRIBUTE_UNUSED,
char *label);
EXTERN void m2expr_BuildIfVarInVar (location_t location, tree type,
tree varset, tree varel, bool is_lvalue,
tree low, tree high ATTRIBUTE_UNUSED,
char *label);
EXTERN void m2expr_BuildIfNotConstInVar (location_t location, tree type,
tree varset, tree constel,
bool is_lvalue, int fieldno,
char *label);
EXTERN void m2expr_BuildIfConstInVar (location_t location, tree type,
tree varset, tree constel, bool is_lvalue,
int fieldno, char *label);
EXTERN tree m2expr_BuildIsNotSubset (location_t location, tree op1, tree op2);
EXTERN tree m2expr_BuildIsSubset (location_t location, tree op1, tree op2);
EXTERN tree m2expr_BuildIsNotSuperset (location_t location, tree op1,
@@ -97,16 +73,11 @@ EXTERN tree m2expr_BuildLessThanOrEqual (location_t location, tree op1,
tree op2);
EXTERN tree m2expr_BuildGreaterThan (location_t location, tree op1, tree op2);
EXTERN tree m2expr_BuildLessThan (location_t location, tree op1, tree op2);
EXTERN tree m2expr_BuildLogicalDifference (location_t location, tree op1,
tree op2, bool needconvert);
EXTERN tree m2expr_BuildSymmetricDifference (location_t location, tree op1,
tree op2, bool needconvert);
EXTERN tree m2expr_BuildLogicalAnd (location_t location, tree op1, tree op2,
bool needconvert);
EXTERN tree m2expr_BuildLogicalOr (location_t location, tree op1, tree op2,
bool needconvert);
EXTERN tree m2expr_BuildLogicalOrAddress (location_t location, tree op1,
tree op2, bool needconvert);
EXTERN tree m2expr_BuildLogicalDifference (location_t location, tree op1, tree op2);
EXTERN tree m2expr_BuildSymmetricDifference (location_t location, tree op1, tree op2);
EXTERN tree m2expr_BuildLogicalAnd (location_t location, tree op1, tree op2);
EXTERN tree m2expr_BuildLogicalOr (location_t location, tree op1, tree op2);
EXTERN tree m2expr_BuildLogicalOrAddress (location_t location, tree op1, tree op2);
EXTERN tree m2expr_BuildOffset (location_t location, tree record, tree field,
bool needconvert ATTRIBUTE_UNUSED);
EXTERN tree m2expr_BuildOffset1 (location_t location, tree field,
@@ -115,8 +86,7 @@ EXTERN tree m2expr_BuildAddr (location_t location, tree op1, bool needconvert);
EXTERN tree m2expr_BuildSize (location_t location, tree op1,
bool needconvert ATTRIBUTE_UNUSED);
EXTERN tree m2expr_BuildTBitSize (location_t location, tree type);
EXTERN tree m2expr_BuildSetNegate (location_t location, tree op1,
bool needconvert);
EXTERN tree m2expr_BuildSetNegate (location_t location, tree value);
EXTERN tree m2expr_BuildNegate (location_t location, tree op1,
bool needconvert);
EXTERN tree m2expr_BuildNegateCheck (location_t location, tree arg,
@@ -224,6 +194,7 @@ EXTERN tree m2expr_GetWordZero (location_t location);
EXTERN tree m2expr_GetWordOne (location_t location);
EXTERN tree m2expr_GetPointerZero (location_t location);
EXTERN tree m2expr_GetPointerOne (location_t location);
EXTERN tree m2expr_GetBitsetZero (location_t location);
EXTERN int m2expr_CompareTrees (tree e1, tree e2);
EXTERN tree m2expr_build_unary_op (location_t location ATTRIBUTE_UNUSED,
@@ -246,6 +217,10 @@ EXTERN tree m2expr_calcNbits (location_t location, tree min, tree max);
EXTERN bool m2expr_OverflowZType (location_t location, const char *str,
unsigned int base, bool issueError);
EXTERN tree m2expr_BuildSystemTBitSize (location_t location, tree type);
EXTERN tree m2expr_GetRValue (location_t location, tree expr, tree type, bool islvalue);
EXTERN tree m2expr_BuildIfInSet (location_t location, tree set, tree bit);
EXTERN tree m2expr_BuildIfNotInSet (location_t location, tree set, tree bit);
EXTERN void m2expr_init (location_t location);
#undef EXTERN
+4
View File
@@ -168,6 +168,10 @@ EXTERN char *M2Options_GetM2DumpFilter (void);
EXTERN void M2Options_SetM2DebugTraceFilter (bool value, const char *arg);
EXTERN bool M2Options_SetM2Dump (bool value, const char *arg);
EXTERN bool M2Options_GetDumpGimple (void);
EXTERN void M2Options_SetTimeReport (bool value);
EXTERN void M2Options_SetMemReport (bool value);
EXTERN void M2Options_SetWideset (bool value);
EXTERN bool M2Options_GetWideset (void);
EXTERN void M2Options_SetStrictTypeAssignment (bool value);
EXTERN void M2Options_SetStrictTypeReason (bool value);
+22
View File
@@ -1961,6 +1961,22 @@ m2pp_binary_function (pretty *s, tree t, const char *funcname)
m2pp_print (s, ")");
}
static void
m2pp_shiftrotate_expr (pretty *s, tree t, const char *op)
{
tree left = TREE_OPERAND (t, 0);
tree right = TREE_OPERAND (t, 1);
m2pp_print (s, "(");
m2pp_expression (s, left);
m2pp_print (s, ")");
m2pp_needspace (s);
m2pp_print (s, op);
m2pp_needspace (s);
m2pp_print (s, "(");
m2pp_expression (s, right);
m2pp_print (s, ")");
}
/* m2pp_simple_expression handle GCC expression tree. */
static void
@@ -2117,6 +2133,12 @@ m2pp_simple_expression (pretty *s, tree t)
case TRUTH_ORIF_EXPR:
m2pp_truth_expr (s, t, "OR");
break;
case LSHIFT_EXPR:
m2pp_shiftrotate_expr (s, t, "<<");
break;
case RSHIFT_EXPR:
m2pp_shiftrotate_expr (s, t, ">>");
break;
case LROTATE_EXPR:
m2pp_binary_function (s, t, "LROTATE");
break;
+61 -350
View File
@@ -44,7 +44,7 @@ static GTY (()) tree param_list = NULL_TREE; /* Ready for the next time we
static GTY (()) tree last_function = NULL_TREE;
/* BuildStartFunctionCode - generate function entry code. */
/* BuildStartFunctionCode generate function entry code. */
void
m2statement_BuildStartFunctionCode (location_t location, tree fndecl,
@@ -86,7 +86,7 @@ m2statement_BuildStartFunctionCode (location_t location, tree fndecl,
DECL_DECLARED_INLINE_P (fndecl) = 0; /* isinline; */
}
/* BuildEndFunctionCode - generates the function epilogue. */
/* BuildEndFunctionCode generates the function epilogue. */
void
m2statement_BuildEndFunctionCode (location_t location, tree fndecl, bool nested)
@@ -123,7 +123,7 @@ m2statement_BuildEndFunctionCode (location_t location, tree fndecl, bool nested)
current_function_decl = NULL;
}
/* BuildPushFunctionContext - pushes the current function context.
/* BuildPushFunctionContext pushes the current function context.
Maps onto push_function_context in ../function.cc. */
void
@@ -132,7 +132,7 @@ m2statement_BuildPushFunctionContext (void)
push_function_context ();
}
/* BuildPopFunctionContext - pops the current function context. Maps
/* BuildPopFunctionContext pops the current function context. Maps
onto pop_function_context in ../function.cc. */
void
@@ -194,7 +194,7 @@ copy_array (location_t location, tree left, tree right)
idx = m2convert_BuildConvert (location, index_type, idx, false);
tree array_ref = build4_loc (location, ARRAY_REF, elt_type, left,
idx, low_indice, NULL_TREE);
m2statement_CopyByField (location, array_ref, value);
m2statement_CopyByField (location, array_ref, value);
}
}
@@ -253,7 +253,7 @@ CopyByField_Lower (location_t location,
else if (right_code == STRING_CST)
copy_strncpy (location, left, right);
else
m2statement_BuildAssignmentStatement (location, left, right);
m2statement_BuildAssignmentStatement (location, left, right);
}
/* CopyByField recursively checks each field to ensure GCC
@@ -321,7 +321,7 @@ m2statement_BuildGoto (location_t location, char *name)
add_stmt (location, build1 (GOTO_EXPR, void_type_node, label));
}
/* DeclareLabel - create a label, name. */
/* DeclareLabel create a label, name. */
void
m2statement_DeclareLabel (location_t location, char *name)
@@ -332,7 +332,7 @@ m2statement_DeclareLabel (location_t location, char *name)
add_stmt (location, build1 (LABEL_EXPR, void_type_node, label));
}
/* BuildParam - build a list of parameters, ready for a subsequent
/* BuildParam build a list of parameters, ready for a subsequent
procedure call. */
void
@@ -347,7 +347,7 @@ m2statement_BuildParam (location_t location, tree param)
param_list = chainon (build_tree_list (NULL_TREE, param), param_list);
}
/* nCount - return the number of chained tree nodes in list, t. */
/* nCount return the number of chained tree nodes in list, t. */
static int
nCount (tree t)
@@ -362,7 +362,7 @@ nCount (tree t)
return i;
}
/* BuildProcedureCallTree - creates a procedure call from a procedure
/* BuildProcedureCallTree creates a procedure call from a procedure
and parameter list and the return type, rettype. */
tree
@@ -419,7 +419,7 @@ m2statement_BuildProcedureCallTree (location_t location, tree procedure,
}
}
/* BuildIndirectProcedureCallTree - creates a procedure call from a
/* BuildIndirectProcedureCallTree creates a procedure call from a
procedure and parameter list and the return type, rettype. */
tree
@@ -486,8 +486,8 @@ m2statement_BuildBuiltinCallTree (tree func)
}
/* BuildFunctValue - generates code for value :=
last_function(foobar); */
/* BuildFunctValue generates code for
value := last_function (foobar). */
tree
m2statement_BuildFunctValue (location_t location, tree value)
@@ -505,10 +505,9 @@ m2statement_BuildFunctValue (location_t location, tree value)
TREE_USED (value) = true;
last_function = NULL_TREE;
return assign;
// return m2statement_BuildAssignmentTree (location, value, assign);
}
/* BuildCall2 - builds a tree representing: function (arg1, arg2). */
/* BuildCall2 builds a tree representing: function (arg1, arg2). */
tree
m2statement_BuildCall2 (location_t location, tree function, tree rettype,
@@ -522,8 +521,7 @@ m2statement_BuildCall2 (location_t location, tree function, tree rettype,
return m2statement_BuildProcedureCallTree (location, function, rettype);
}
/* BuildCall3 - builds a tree representing: function (arg1, arg2,
arg3). */
/* BuildCall3 builds a tree representing: function (arg1, arg2, arg3). */
tree
m2statement_BuildCall3 (location_t location, tree function, tree rettype,
@@ -538,7 +536,7 @@ m2statement_BuildCall3 (location_t location, tree function, tree rettype,
return m2statement_BuildProcedureCallTree (location, function, rettype);
}
/* BuildFunctionCallTree - creates a procedure function call from
/* BuildFunctionCallTree creates a procedure function call from
a procedure and parameter list and the return type, rettype.
No tree is returned as the tree is held in the last_function global
variable. It is expected the BuildFunctValue is to be called after
@@ -551,7 +549,7 @@ m2statement_BuildFunctionCallTree (location_t location, tree procedure,
m2statement_BuildProcedureCallTree (location, procedure, rettype);
}
/* SetLastFunction - assigns last_function to, t. */
/* SetLastFunction assigns last_function to, t. */
void
m2statement_SetLastFunction (tree t)
@@ -559,7 +557,7 @@ m2statement_SetLastFunction (tree t)
last_function = t;
}
/* SetParamList - assigns param_list to, t. */
/* SetParamList assigns param_list to, t. */
void
m2statement_SetParamList (tree t)
@@ -567,7 +565,7 @@ m2statement_SetParamList (tree t)
param_list = t;
}
/* GetLastFunction - returns, last_function. */
/* GetLastFunction returns, last_function. */
tree
m2statement_GetLastFunction (void)
@@ -575,7 +573,7 @@ m2statement_GetLastFunction (void)
return last_function;
}
/* GetParamList - returns, param_list. */
/* GetParamList returns, param_list. */
tree
m2statement_GetParamList (void)
@@ -583,7 +581,7 @@ m2statement_GetParamList (void)
return param_list;
}
/* GetCurrentFunction - returns the current_function. */
/* GetCurrentFunction returns the current_function. */
tree
m2statement_GetCurrentFunction (void)
@@ -591,7 +589,7 @@ m2statement_GetCurrentFunction (void)
return current_function_decl;
}
/* GetParamTree - return parameter, i. */
/* GetParamTree return parameter, i. */
tree
m2statement_GetParamTree (tree call, unsigned int i)
@@ -599,7 +597,7 @@ m2statement_GetParamTree (tree call, unsigned int i)
return CALL_EXPR_ARG (call, i);
}
/* BuildTryFinally - returns a TRY_FINALL_EXPR with the call and
/* BuildTryFinally returns a TRY_FINALL_EXPR with the call and
cleanups attached. */
tree
@@ -608,7 +606,7 @@ m2statement_BuildTryFinally (location_t location, tree call, tree cleanups)
return build_stmt (location, TRY_FINALLY_EXPR, call, cleanups);
}
/* BuildCleanUp - return a CLEANUP_POINT_EXPR which will clobber,
/* BuildCleanUp return a CLEANUP_POINT_EXPR which will clobber,
param. */
tree
@@ -619,7 +617,7 @@ m2statement_BuildCleanUp (tree param)
return build2 (MODIFY_EXPR, TREE_TYPE (param), param, clobber);
}
/* BuildAsm - generates an inline assembler instruction. */
/* BuildAsm generates an inline assembler instruction. */
void
m2statement_BuildAsm (location_t location, tree instr, bool isVolatile,
@@ -640,298 +638,7 @@ m2statement_BuildAsm (location_t location, tree instr, bool isVolatile,
add_stmt (location, args);
}
/* BuildUnaryForeachWordDo - provides the large set operators. Each
word (or less) of the set can be calculated by unop. This
procedure runs along each word of the large set invoking the unop. */
void
m2statement_BuildUnaryForeachWordDo (location_t location, tree type, tree op1,
tree op2,
tree (*unop) (location_t, tree, bool),
bool is_op1lvalue, bool is_op2lvalue,
bool is_op1const, bool is_op2const)
{
tree size = m2expr_GetSizeOf (location, type);
m2assert_AssertLocation (location);
ASSERT_BOOL (is_op1lvalue);
ASSERT_BOOL (is_op2lvalue);
ASSERT_BOOL (is_op1const);
ASSERT_BOOL (is_op2const);
if (m2expr_CompareTrees (
size, m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT))
<= 0)
/* Small set size <= TSIZE(WORD). */
m2statement_BuildAssignmentTree (
location, m2treelib_get_rvalue (location, op1, type, is_op1lvalue),
(*unop) (location,
m2treelib_get_rvalue (location, op2, type, is_op2lvalue),
false));
else
{
/* Large set size > TSIZE(WORD). */
unsigned int fieldNo = 0;
tree field1 = m2treelib_get_field_no (type, op1, is_op1const, fieldNo);
tree field2 = m2treelib_get_field_no (type, op2, is_op2const, fieldNo);
if (is_op1const)
error ("internal error: not expecting operand1 to be a constant set");
while (field1 != NULL && field2 != NULL)
{
m2statement_BuildAssignmentTree (
location, m2treelib_get_set_field_des (location, op1, field1),
(*unop) (location,
m2treelib_get_set_field_rhs (location, op2, field2),
false));
fieldNo++;
field1 = m2treelib_get_field_no (type, op1, is_op1const, fieldNo);
field2 = m2treelib_get_field_no (type, op2, is_op2const, fieldNo);
}
}
}
/* BuildExcludeVarConst - builds the EXCL(op1, 1<<op2) operation for
a small sets. Large sets call this routine to exclude the bit in
the particular word. op2 is a constant. */
void
m2statement_BuildExcludeVarConst (location_t location, tree type, tree op1,
tree op2, bool is_lvalue, int fieldno)
{
tree size = m2expr_GetSizeOf (location, type);
m2assert_AssertLocation (location);
ASSERT_BOOL (is_lvalue);
if (m2expr_CompareTrees (
size, m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT))
<= 0)
{
/* Small set size <= TSIZE(WORD). */
m2statement_BuildAssignmentTree (
location, m2treelib_get_rvalue (location, op1, type, is_lvalue),
m2expr_BuildLogicalAnd (
location, m2treelib_get_rvalue (location, op1, type, is_lvalue),
m2expr_BuildSetNegate (
location,
m2expr_BuildLSL (location, m2expr_GetWordOne (location), op2,
false),
false),
false));
}
else
{
tree fieldlist = TYPE_FIELDS (type);
tree field;
for (field = fieldlist; (field != NULL) && (fieldno > 0);
field = TREE_CHAIN (field))
fieldno--;
m2statement_BuildAssignmentTree (
location, m2treelib_get_set_field_des (location, op1, field),
m2expr_BuildLogicalAnd (
location, m2treelib_get_set_field_rhs (location, op1, field),
m2expr_BuildSetNegate (
location,
m2expr_BuildLSL (location, m2expr_GetWordOne (location), op2,
false),
false),
false));
}
}
/* BuildExcludeVarVar - builds the EXCL(varset, 1<<varel) operation
for a small and large sets. varel is a variable. */
void
m2statement_BuildExcludeVarVar (location_t location, tree type, tree varset,
tree varel, bool is_lvalue, tree low)
{
tree size = m2expr_GetSizeOf (location, type);
m2assert_AssertLocation (location);
ASSERT_BOOL (is_lvalue);
/* Calculate the index from the first bit, ie bit 0 represents low value. */
tree index
= m2expr_BuildSub (location, m2convert_ToInteger (location, varel),
m2convert_ToInteger (location, low), false);
if (m2expr_CompareTrees (
size, m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT))
<= 0)
/* Small set size <= TSIZE(WORD). */
m2statement_BuildAssignmentTree (
location, m2treelib_get_rvalue (location, varset, type, is_lvalue),
m2expr_BuildLogicalAnd (
location, m2treelib_get_rvalue (location, varset, type, is_lvalue),
m2expr_BuildSetNegate (
location,
m2expr_BuildLSL (location, m2expr_GetWordOne (location),
m2convert_ToWord (location, index), false),
false),
false));
else
{
tree p1 = m2treelib_get_set_address (location, varset, is_lvalue);
/* Calculate the index from the first bit. */
/* Which word do we need to fetch? */
tree word_index = m2expr_BuildDivTrunc (
location, index, m2decl_BuildIntegerConstant (SET_WORD_SIZE), false);
/* Calculate the bit in this word. */
tree offset_into_word = m2expr_BuildModTrunc (
location, index, m2decl_BuildIntegerConstant (SET_WORD_SIZE), false);
tree v1;
/* Calculate the address of the word we are interested in. */
p1 = m2expr_BuildAddAddress (
location, m2convert_convertToPtr (location, p1),
m2expr_BuildMult (
location, word_index,
m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT),
false));
v1 = m2expr_BuildLogicalAnd (
location,
m2expr_BuildIndirect (location, p1, m2type_GetBitsetType ()),
m2expr_BuildSetNegate (
location,
m2expr_BuildLSL (location, m2expr_GetWordOne (location),
m2convert_ToWord (location, offset_into_word),
false),
false),
false);
/* Set bit offset_into_word within the word pointer at by p1. */
m2statement_BuildAssignmentTree (
location,
m2expr_BuildIndirect (location, p1, m2type_GetBitsetType ()),
m2convert_ToBitset (location, v1));
}
}
/* BuildIncludeVarConst - builds the INCL(op1, 1<<op2) operation for
a small sets. Large sets call this routine to include the bit in
the particular word. op2 is a constant. */
void
m2statement_BuildIncludeVarConst (location_t location, tree type, tree op1,
tree op2, bool is_lvalue, int fieldno)
{
tree size = m2expr_GetSizeOf (location, type);
m2assert_AssertLocation (location);
ASSERT_BOOL (is_lvalue);
if (m2expr_CompareTrees (
size, m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT))
<= 0)
{
/* Small set size <= TSIZE(WORD). */
m2statement_BuildAssignmentTree (
location, m2treelib_get_rvalue (location, op1, type, is_lvalue),
m2expr_BuildLogicalOr (
location, m2treelib_get_rvalue (location, op1, type, is_lvalue),
m2expr_BuildLSL (location, m2expr_GetWordOne (location),
m2convert_ToWord (location, op2), false),
false));
}
else
{
tree fieldlist = TYPE_FIELDS (type);
tree field;
for (field = fieldlist; (field != NULL) && (fieldno > 0);
field = TREE_CHAIN (field))
fieldno--;
m2statement_BuildAssignmentTree (
location,
/* Would like to use: m2expr_BuildComponentRef (location, p, field)
but strangely we have to take the address of the field and
dereference it to satify the gimplifier. See
testsuite/gm2/pim/pass/timeio?.mod for testcases. */
m2treelib_get_set_field_des (location, op1, field),
m2expr_BuildLogicalOr (
location, m2treelib_get_set_field_rhs (location, op1, field),
m2expr_BuildLSL (location, m2expr_GetWordOne (location),
m2convert_ToWord (location, op2), false),
false));
}
}
/* BuildIncludeVarVar - builds the INCL(varset, 1<<varel) operation
for a small and large sets. op2 is a variable. */
void
m2statement_BuildIncludeVarVar (location_t location, tree type, tree varset,
tree varel, bool is_lvalue, tree low)
{
tree size = m2expr_GetSizeOf (location, type);
m2assert_AssertLocation (location);
ASSERT_BOOL (is_lvalue);
/* Calculate the index from the first bit, ie bit 0 represents low value. */
tree index
= m2expr_BuildSub (location, m2convert_ToInteger (location, varel),
m2convert_ToInteger (location, low), false);
tree indexw = m2convert_ToWord (location, index);
if (m2expr_CompareTrees (
size, m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT))
<= 0)
/* Small set size <= TSIZE(WORD). */
m2statement_BuildAssignmentTree (
location, m2treelib_get_rvalue (location, varset, type, is_lvalue),
m2convert_ToBitset (
location,
m2expr_BuildLogicalOr (
location,
m2treelib_get_rvalue (location, varset, type, is_lvalue),
m2expr_BuildLSL (location, m2expr_GetWordOne (location),
indexw, false),
false)));
else
{
tree p1 = m2treelib_get_set_address (location, varset, is_lvalue);
/* Which word do we need to fetch? */
tree word_index = m2expr_BuildDivTrunc (
location, index, m2decl_BuildIntegerConstant (SET_WORD_SIZE), false);
/* Calculate the bit in this word. */
tree offset_into_word = m2convert_BuildConvert (
location, m2type_GetWordType (),
m2expr_BuildModTrunc (location, index,
m2decl_BuildIntegerConstant (SET_WORD_SIZE),
false),
false);
tree v1;
/* Calculate the address of the word we are interested in. */
p1 = m2expr_BuildAddAddress (
location, m2convert_convertToPtr (location, p1),
m2expr_BuildMult (
location, word_index,
m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT),
false));
v1 = m2expr_BuildLogicalOr (
location,
m2expr_BuildIndirect (location, p1, m2type_GetBitsetType ()),
m2convert_ToBitset (location,
m2expr_BuildLSL (location,
m2expr_GetWordOne (location),
offset_into_word, false)),
false);
/* Set bit offset_into_word within the word pointer at by p1. */
m2statement_BuildAssignmentTree (
location,
m2expr_BuildIndirect (location, p1, m2type_GetBitsetType ()),
m2convert_ToBitset (location, v1));
}
}
/* BuildStart - creates a module initialization function. We make
/* BuildStart creates a module initialization function. We make
this function public if it is not an inner module. The linker
will create a call list for all linked modules which determines
the initialization sequence for all modules. */
@@ -967,7 +674,7 @@ m2statement_BuildStart (location_t location, char *name, bool inner_module)
return fndecl;
}
/* BuildEnd - complete the initialization function for this module. */
/* BuildEnd complete the initialization function for this module. */
void
m2statement_BuildEnd (location_t location, tree fndecl, bool nested)
@@ -977,7 +684,7 @@ m2statement_BuildEnd (location_t location, tree fndecl, bool nested)
set_cfun (NULL);
}
/* BuildCallInner - call the inner module function. It has no
/* BuildCallInner call the inner module function. It has no
parameters and no return value. */
void
@@ -990,7 +697,7 @@ m2statement_BuildCallInner (location_t location, tree fndecl)
}
/* BuildIfThenDoEnd - returns a tree which will only execute
/* BuildIfThenDoEnd returns a tree which will only execute
statement, s, if, condition, is true. */
tree
@@ -1003,7 +710,7 @@ m2statement_BuildIfThenDoEnd (tree condition, tree then_block)
alloc_stmt_list ());
}
/* BuildIfThenElseEnd - returns a tree which will execute then_block
/* BuildIfThenElseEnd returns a tree which will execute then_block
or else_block depending upon, condition. */
tree
@@ -1017,8 +724,8 @@ m2statement_BuildIfThenElseEnd (tree condition, tree then_block,
else_block);
}
/* BuildReturnValueCode - generates the code associated with: RETURN(
value ) */
/* BuildReturnValueCode generates the code associated with:
RETURN ( value ). */
void
m2statement_BuildReturnValueCode (location_t location, tree fndecl, tree value)
@@ -1037,41 +744,45 @@ m2statement_BuildReturnValueCode (location_t location, tree fndecl, tree value)
add_stmt (location, ret_stmt);
}
/* DoJump - jump to the appropriate label depending whether result of
the expression is true or false. */
/* IfExprJump if expr then jump to the label. */
void
m2statement_DoJump (location_t location, tree exp, char *falselabel,
char *truelabel)
m2statement_IfExprJump (location_t location, tree exp, char *label)
{
tree c = NULL_TREE;
tree if_jump;
m2assert_AssertLocation (location);
if (TREE_CODE (TREE_TYPE (exp)) != BOOLEAN_TYPE)
exp = convert_loc (location, m2type_GetBooleanType (), exp);
if ((falselabel != NULL) && (truelabel == NULL))
{
m2block_push_statement_list (m2block_begin_statement_list ());
m2block_push_statement_list (m2block_begin_statement_list ());
m2statement_BuildGoto (location, label);
if_jump = build3 (COND_EXPR, void_type_node, exp,
m2block_pop_statement_list (),
alloc_stmt_list ());
add_stmt (location, if_jump);
}
m2statement_BuildGoto (location, falselabel);
c = build3 (COND_EXPR, void_type_node, exp,
m2block_pop_statement_list (),
alloc_stmt_list ());
}
else if ((falselabel == NULL) && (truelabel != NULL))
{
m2block_push_statement_list (m2block_begin_statement_list ());
m2statement_BuildGoto (location, truelabel);
c = build3 (COND_EXPR, void_type_node, exp,
m2block_pop_statement_list (),
alloc_stmt_list ());
}
else
error_at (location, "expecting one and only one label to be declared");
if (c != NULL_TREE)
add_stmt (location, c);
/* IfBitInSetJump if bit in set jump to label. */
void
m2statement_IfBitInSetJump (location_t location, bool invertCondition,
tree setvalue, tree bit, char *label)
{
tree condition;
condition = m2expr_BuildNotEqualTo (location,
m2expr_BuildLogicalAnd (location,
m2expr_BuildLSL (location,
m2expr_GetWordOne (location),
bit, false),
setvalue),
m2expr_GetWordZero (location)) ;
if (invertCondition)
condition = m2expr_BuildEqualTo (location, condition,
m2type_GetBooleanFalse ());
m2statement_IfExprJump (location, condition, label);
}
#include "gt-m2-m2statement.h"
+11 -16
View File
@@ -24,14 +24,14 @@ DEFINITION MODULE FOR "C" m2statement ;
FROM gcctypes IMPORT location_t, tree ;
FROM CDataTypes IMPORT CharStar ;
FROM m2expr IMPORT BuildUnarySetFunction ;
FROM SYSTEM IMPORT ADDRESS ;
(*
DoJump - jump to the appropriate label depending whether
result of the expression is TRUE or FALSE.
IfExprJump - if expr then jump to the label.
*)
PROCEDURE DoJump (location: location_t; exp: tree; falselabel, truelabel: CharStar) ;
PROCEDURE IfExprJump (location: location_t; exp: tree; label: ADDRESS) ;
(*
@@ -221,19 +221,6 @@ PROCEDURE BuildAsm (location: location_t; instr: tree;
inputs: tree; outputs: tree; trash: tree; labels: tree) ;
(*
BuildUnaryForeachWordDo - provides the large set operators.
Each word (or less) of the set can be
calculated by unop.
This procedure iterates over each word
of the large set invoking the unop.
*)
PROCEDURE BuildUnaryForeachWordDo (location: location_t; type: tree; op1: tree; op2: tree;
unop: BuildUnarySetFunction;
is_op1lvalue, is_op2lvalue, is_op1const, is_op2const: BOOLEAN) ;
(*
BuildExcludeVarConst - builds the EXCL(op1, 1<<op2) operation for a small sets. Large
sets call this routine to exclude the bit in the particular word.
@@ -326,4 +313,12 @@ PROCEDURE BuildBuiltinCallTree (func: tree) : tree ;
PROCEDURE CopyByField (location: location_t; des, expr: tree) ;
(*
IfBitInSetJump - if bit in set jump to label.
*)
PROCEDURE IfBitInSetJump (location: location_t; invertCondition: BOOLEAN;
setvalue, bit: tree; label: ADDRESS) ;
END m2statement.
+3 -6
View File
@@ -52,10 +52,6 @@ EXTERN void m2statement_BuildExcludeVarVar (location_t location, tree type,
EXTERN void m2statement_BuildExcludeVarConst (location_t location, tree type,
tree op1, tree op2,
bool is_lvalue, int fieldno);
EXTERN void m2statement_BuildUnaryForeachWordDo (
location_t location, tree type, tree op1, tree op2,
tree (*unop) (location_t, tree, bool), bool is_op1lvalue, bool is_op2lvalue,
bool is_op1const, bool is_op2const);
EXTERN void m2statement_BuildAsm (location_t location, tree instr,
bool isVolatile, bool isSimple, tree inputs,
tree outputs, tree trash, tree labels);
@@ -88,8 +84,7 @@ EXTERN void m2statement_BuildEndFunctionCode (location_t location, tree fndecl,
EXTERN void m2statement_BuildStartFunctionCode (location_t location,
tree fndecl, bool isexported,
bool isinline);
EXTERN void m2statement_DoJump (location_t location, tree exp,
char *falselabel, char *truelabel);
EXTERN void m2statement_IfExprJump (location_t location, tree exp, char *label);
EXTERN tree m2statement_BuildCall2 (location_t location, tree function,
tree rettype, tree arg1, tree arg2);
EXTERN tree m2statement_BuildCall3 (location_t location, tree function,
@@ -108,6 +103,8 @@ EXTERN tree m2statement_BuildBuiltinCallTree (tree func);
EXTERN tree m2statement_BuildTryFinally (location_t location, tree call,
tree cleanups);
EXTERN tree m2statement_BuildCleanUp (tree param);
EXTERN void m2statement_IfBitInSetJump (location_t location, bool invertCondition,
tree setvalue, tree bit, char *label);
EXTERN void m2statement_CopyByField (location_t location, tree des, tree expr);
#undef EXTERN
+5 -17
View File
@@ -45,7 +45,7 @@ m2treelib_do_jump_if_bit (location_t location, enum tree_code code, tree word,
{
word = m2convert_ToWord (location, word);
bit = m2convert_ToWord (location, bit);
m2statement_DoJump (
m2statement_IfExprJump (
location,
m2expr_build_binary_op (
location, code,
@@ -55,7 +55,7 @@ m2treelib_do_jump_if_bit (location_t location, enum tree_code code, tree word,
FALSE),
FALSE),
m2expr_GetWordZero (location), FALSE),
NULL, label);
label);
}
/* build_modify_expr - taken from c-typeck.cc and heavily pruned.
@@ -147,8 +147,8 @@ m2treelib_build_modify_expr (location_t location, tree des,
/* nCount - return the number of trees chained on, t. */
static int
nCount (tree t)
int
m2treelib_nCount (tree t)
{
int i = 0;
@@ -167,7 +167,7 @@ tree
m2treelib_DoCall (location_t location, tree rettype, tree funcptr,
tree param_list)
{
int n = nCount (param_list);
int n = m2treelib_nCount (param_list);
tree *argarray = XALLOCAVEC (tree, n);
tree l = param_list;
int i;
@@ -229,18 +229,6 @@ m2treelib_DoCall3 (location_t location, tree rettype, tree funcptr, tree arg0,
return build_call_array_loc (location, rettype, funcptr, 3, argarray);
}
/* get_rvalue - returns the rvalue of t. The, type, is the object
type to be copied upon indirection. */
tree
m2treelib_get_rvalue (location_t location, tree t, tree type, bool is_lvalue)
{
if (is_lvalue)
return m2expr_BuildIndirect (location, t, type);
else
return t;
}
/* get_field_no - returns the field no for, op. The, op, is either a
constructor or a variable of type record. If, op, is a
constructor (a set constant in GNU Modula-2) then this function is
+7 -8
View File
@@ -78,14 +78,6 @@ PROCEDURE get_set_value (location: location_t; p: tree; field: tree; is_const: B
PROCEDURE get_field_no (type: tree; op: tree; is_const: BOOLEAN; fieldNo: CARDINAL) : tree ;
(*
get_rvalue - returns the rvalue of t. The, type, is the object type to be
copied upon indirection.
*)
PROCEDURE get_rvalue (location: location_t; t: tree; type: tree; is_lvalue: BOOLEAN) : tree ;
(*
DoCall - build a call tree arranging the parameter list as a vector.
*)
@@ -105,4 +97,11 @@ PROCEDURE build_modify_expr (location: location_t; des: tree; modifycode: tree_c
PROCEDURE do_jump_if_bit (location: location_t; code: tree_code; word: tree; bit: tree; label: ADDRESS) ;
(*
nCount - return the number of trees chained.
*)
PROCEDURE nCount (t: tree) : INTEGER ;
END m2treelib.
+1 -2
View File
@@ -41,8 +41,6 @@ EXTERN tree m2treelib_DoCall2 (location_t location, tree rettype, tree funcptr,
tree arg0, tree arg1);
EXTERN tree m2treelib_DoCall3 (location_t location, tree rettype, tree funcptr,
tree arg0, tree arg1, tree arg2);
EXTERN tree m2treelib_get_rvalue (location_t location, tree t, tree type,
bool is_lvalue);
EXTERN tree m2treelib_get_field_no (tree type, tree op, bool is_const,
unsigned int fieldNo);
EXTERN tree m2treelib_get_set_value (location_t location, tree p, tree field,
@@ -61,6 +59,7 @@ EXTERN tree m2treelib_get_set_field_des (location_t location, tree p,
EXTERN tree add_stmt (location_t location, tree t);
EXTERN tree build_stmt (location_t loc, enum tree_code code, ...);
EXTERN int m2treelib_nCount (tree t);
#undef EXTERN
#endif /* m2treelib_h. */
+80 -58
View File
@@ -50,12 +50,11 @@ struct GTY (()) struct_constructor
/* Constructor_fields, the list of fields belonging to
constructor_type. Used by SET and RECORD constructors. */
tree GTY ((skip (""))) constructor_fields;
/* Constructor_element_list, the list of constants used by SET and
RECORD constructors. */
tree GTY ((skip (""))) constructor_element_list;
/* Constructor_elements, used by an ARRAY initializer all elements
are held in reverse order. */
/* Constructor_elements, used by an ARRAY, RECORD and SET initializer
all elements are held in reverse order. */
vec<constructor_elt, va_gc> *constructor_elements;
/* The next byte_index to be used when adding set bytes to an array. */
int byte_index;
/* Level, the next level down in the constructor stack. */
struct struct_constructor *level;
};
@@ -243,8 +242,9 @@ m2type_BuildEndArrayType (tree arraytype, tree elementtype, tree indextype,
return gm2_finish_build_array_type (arraytype, ptr_type_node, indextype,
type);
else
return gm2_finish_build_array_type (
arraytype, m2tree_skip_type_decl (elementtype), indextype, type);
return gm2_finish_build_array_type (arraytype,
m2tree_skip_type_decl (elementtype),
indextype, type);
}
/* gm2_build_array_type returns a type which is an array indexed by
@@ -330,7 +330,8 @@ static tree
build_m2_type_node_by_array (tree arrayType, tree low, tree high, int fetype)
{
return gm2_build_array_type (arrayType,
m2type_BuildArrayIndexType (low, high), fetype);
m2type_BuildArrayIndexType (low, high),
fetype);
}
/* build_m2_word16_type_node build an ISO 16 bit word as an ARRAY
@@ -893,6 +894,17 @@ m2type_GetBooleanType (void)
#endif /* !USE_BOOLEAN */
}
/* GetBooleanEnumList return a list containing boolean fields true and false. */
tree
m2type_GetBooleanEnumList (location_t location)
{
tree list = NULL;
m2type_BuildEnumerator (location, "TRUE", m2type_GetBooleanTrue (), &list);
m2type_BuildEnumerator (location, "FALSE", m2type_GetBooleanTrue (), &list);
return list;
}
/* GetCardinalAddressType returns the internal data type for
computing binary arithmetic upon the ADDRESS datatype. */
@@ -1892,7 +1904,7 @@ m2type_GetDefaultType (location_t location, char *name, tree type)
}
/* IsGccRealType return true if type is a GCC realtype. */
static
bool
IsGccRealType (tree type)
@@ -1935,7 +1947,7 @@ m2type_GetMinFrom (location_t location, tree type)
return TYPE_MIN_VALUE (m2tree_skip_type_decl (type));
}
static
static
tree
do_max_real (tree type)
{
@@ -2201,7 +2213,7 @@ gm2_build_enumerator (location_t location, tree name, tree value)
enumvalues, list. It returns a copy of the value. */
tree
m2type_BuildEnumerator (location_t location, char *name, tree value,
m2type_BuildEnumerator (location_t location, const char *name, tree value,
tree *enumvalues)
{
tree id = get_identifier (name);
@@ -2274,8 +2286,8 @@ pop_constructor (struct struct_constructor *p)
top_constructor = top_constructor->level;
}
/* BuildStartSetConstructor starts to create a set constant.
Remember that type is really a record type. */
/* BuildStartSetConstructor starts to create a wide set constant.
A wide set type will be implemented as an array type (array [0..max] OF BYTE). */
void *
m2type_BuildStartSetConstructor (tree type)
@@ -2285,36 +2297,32 @@ m2type_BuildStartSetConstructor (tree type)
type = m2tree_skip_type_decl (type);
layout_type (type);
p->constructor_type = type;
p->constructor_fields = TYPE_FIELDS (type);
p->constructor_element_list = NULL_TREE;
p->constructor_fields = TREE_TYPE (type);
p->byte_index = 0;
vec_alloc (p->constructor_elements, 1);
return (void *)p;
}
/* BuildSetConstructorElement adds, value, to the
constructor_element_list. */
/* BuildSetConstructorElement adds value to the constructor_elements. */
void
m2type_BuildSetConstructorElement (void *p, tree value)
m2type_BuildSetConstructorElement (location_t location, void *p, tree value)
{
struct struct_constructor *c = (struct struct_constructor *)p;
constructor_elt celt;
if (value == NULL_TREE)
if (c->constructor_fields == NULL_TREE)
{
internal_error ("set type cannot be initialized with a %qs",
"NULL_TREE");
internal_error ("set type must be initialized");
return;
}
if (c->constructor_fields == NULL)
{
internal_error ("set type does not take another integer value");
return;
}
c->constructor_element_list
= tree_cons (c->constructor_fields, value, c->constructor_element_list);
c->constructor_fields = TREE_CHAIN (c->constructor_fields);
value = m2convert_BuildConvert (location, c->constructor_fields,
value, FALSE);
celt.index = m2decl_BuildIntegerConstant (c->byte_index);
celt.value = value;
c->byte_index++;
vec_safe_push (c->constructor_elements, celt);
}
/* BuildEndSetConstructor finishes building a set constant. */
@@ -2322,24 +2330,13 @@ m2type_BuildSetConstructorElement (void *p, tree value)
tree
m2type_BuildEndSetConstructor (void *p)
{
tree constructor;
tree link;
struct struct_constructor *c = (struct struct_constructor *)p;
tree constructor =
build_constructor (c->constructor_type, c->constructor_elements);
for (link = c->constructor_element_list; link; link = TREE_CHAIN (link))
{
tree field = TREE_PURPOSE (link);
DECL_SIZE (field) = bitsize_int (SET_WORD_SIZE);
DECL_BIT_FIELD (field) = 1;
}
constructor = build_constructor_from_list (
c->constructor_type, nreverse (c->constructor_element_list));
TREE_CONSTANT (constructor) = 1;
TREE_STATIC (constructor) = 1;
TREE_CONSTANT (constructor) = true;
TREE_STATIC (constructor) = true;
pop_constructor (c);
return constructor;
}
@@ -2355,11 +2352,30 @@ m2type_BuildStartRecordConstructor (tree type)
layout_type (type);
p->constructor_type = type;
p->constructor_fields = TYPE_FIELDS (type);
p->constructor_element_list = NULL_TREE;
vec_alloc (p->constructor_elements, 1);
return (void *)p;
}
/* build_record_constructor build and return a record constructor of type
record_type from the ordered values in vals. */
static
tree
build_record_constructor (tree record_type, vec<constructor_elt, va_gc> *vals)
{
tree field_init;
unsigned int i;
vec<constructor_elt, va_gc> *v = NULL;
tree field_type = first_field (record_type);
FOR_EACH_CONSTRUCTOR_VALUE (vals, i, field_init)
{
CONSTRUCTOR_APPEND_ELT (v, field_type, field_init);
field_type = DECL_CHAIN (field_type);
}
return build_constructor (record_type, v);
}
/* BuildEndRecordConstructor returns a tree containing the record
compound literal. */
@@ -2367,23 +2383,32 @@ tree
m2type_BuildEndRecordConstructor (void *p)
{
struct struct_constructor *c = (struct struct_constructor *)p;
tree constructor = build_constructor_from_list (
c->constructor_type, nreverse (c->constructor_element_list));
TREE_CONSTANT (constructor) = 1;
TREE_STATIC (constructor) = 1;
tree constructor = build_record_constructor (c->constructor_type,
c->constructor_elements);
TREE_CONSTANT (constructor) = true;
TREE_STATIC (constructor) = true;
pop_constructor (c);
return constructor;
}
/* BuildRecordConstructorElement adds, value, to the
constructor_element_list. */
constructor_elements. */
void
m2type_BuildRecordConstructorElement (void *p, tree value)
{
m2type_BuildSetConstructorElement (p, value);
struct struct_constructor *c = (struct struct_constructor *)p;
constructor_elt celt;
if (c->constructor_fields == NULL_TREE)
{
internal_error ("record type must be initialized");
return;
}
celt.index = m2decl_BuildIntegerConstant (c->byte_index);
celt.value = value;
c->byte_index++;
vec_safe_push (c->constructor_elements, celt);
}
/* BuildStartArrayConstructor initializes an array compound
@@ -2398,7 +2423,6 @@ m2type_BuildStartArrayConstructor (tree type)
layout_type (type);
p->constructor_type = type;
p->constructor_fields = TREE_TYPE (type);
p->constructor_element_list = NULL_TREE;
vec_alloc (p->constructor_elements, 1);
return (void *)p;
}
@@ -2416,14 +2440,12 @@ m2type_BuildEndArrayConstructor (void *p)
= build_constructor (c->constructor_type, c->constructor_elements);
TREE_CONSTANT (constructor) = true;
TREE_STATIC (constructor) = true;
pop_constructor (c);
return constructor;
}
/* BuildArrayConstructorElement adds, value, to the
constructor_element_list. */
constructor_elements. */
void
m2type_BuildArrayConstructorElement (void *p, tree value, tree indice)
+11 -3
View File
@@ -136,7 +136,7 @@ PROCEDURE BuildEndSetConstructor (p: Constructor) : tree ;
BuildSetConstructorElement - adds, value, to the constructor_element_list.
*)
PROCEDURE BuildSetConstructorElement (p: Constructor; value: tree) ;
PROCEDURE BuildSetConstructorElement (location: location_t; p: Constructor; value: tree) ;
(*
@@ -796,7 +796,7 @@ PROCEDURE BuildArrayStringConstructor (location: location_t; arrayType: tree; st
(*
RealToTree - convert a real number into a Tree.
RealToTree - convert a real number into a tree.
*)
PROCEDURE RealToTree (name: CharStar) : tree ;
@@ -962,7 +962,8 @@ PROCEDURE GetArrayNoOfElements (location: location_t; arraytype: tree) : tree ;
and which has ElementType elements.
*)
PROCEDURE BuildEndArrayType (arraytype: tree; elementtype: tree; indextype: tree; type: INTEGER) : tree ;
PROCEDURE BuildEndArrayType (arraytype: tree; elementtype: tree;
indextype: tree; type: INTEGER) : tree ;
(*
@@ -1004,4 +1005,11 @@ PROCEDURE SameRealType (a, b: tree) : BOOLEAN ;
PROCEDURE IsGccStrictTypeEquivalent (left, right: tree) : BOOLEAN ;
(*
GetBooleanEnumList - return a list containing boolean fields true and false.
*)
PROCEDURE GetBooleanEnumList (location: location_t) : tree ;
END m2type.
+3 -2
View File
@@ -183,14 +183,14 @@ EXTERN tree m2type_BuildStartEnumeration (location_t location, char *name,
bool ispacked);
EXTERN tree m2type_BuildEndEnumeration (location_t location, tree enumtype,
tree enumvalues);
EXTERN tree m2type_BuildEnumerator (location_t location, char *name,
EXTERN tree m2type_BuildEnumerator (location_t location, const char *name,
tree value, tree *enumvalues);
EXTERN tree m2type_BuildPointerType (tree totype);
EXTERN tree m2type_BuildConstPointerType (tree totype);
EXTERN tree m2type_BuildSetType (location_t location, char *name, tree type,
tree lowval, tree highval, bool ispacked);
EXTERN void *m2type_BuildStartSetConstructor (tree type);
EXTERN void m2type_BuildSetConstructorElement (void *p, tree value);
EXTERN void m2type_BuildSetConstructorElement (location_t location, void *p, tree value);
EXTERN tree m2type_BuildEndSetConstructor (void *p);
EXTERN void *m2type_BuildStartRecordConstructor (tree type);
EXTERN tree m2type_BuildEndRecordConstructor (void *p);
@@ -214,6 +214,7 @@ EXTERN bool m2type_IsAddress (tree type);
EXTERN tree m2type_GetCardinalAddressType (void);
EXTERN bool m2type_SameRealType (tree a, tree b);
EXTERN bool m2type_IsGccStrictTypeEquivalent (tree left, tree right);
EXTERN tree m2type_GetBooleanEnumList (location_t location);
#undef EXTERN
#endif /* m2type_h */
+11
View File
@@ -692,6 +692,12 @@ gm2_langhook_handle_option (
case OPT_fgen_module_list_:
M2Options_SetGenModuleList (value, arg);
return 1;
case OPT_fmem_report:
M2Options_SetMemReport (value);
return 1;
case OPT_ftime_report:
M2Options_SetTimeReport (value);
return 1;
case OPT_fnil:
M2Options_SetNilCheck (value);
return 1;
@@ -915,6 +921,11 @@ gm2_langhook_handle_option (
case OPT_fm2_whole_program:
M2Options_SetWholeProgram (value);
return 1;
break;
case OPT_fwideset:
M2Options_SetWideset (value);
return 1;
break;
#ifdef OPT_mabi_ibmlongdouble
case OPT_mabi_ibmlongdouble:
M2Options_SetIBMLongDouble (value);
+1 -87
View File
@@ -41,10 +41,7 @@ EXPORT QUALIFIED (* the following are built into the compiler: *)
(* The rest are implemented in SYSTEM.mod. *)
PROCESS, TRANSFER, NEWPROCESS, IOTRANSFER,
LISTEN,
ListenLoop, TurnInterrupts,
(* Internal GM2 compiler functions. *)
ShiftVal, ShiftLeft, ShiftRight,
RotateVal, RotateLeft, RotateRight ;
ListenLoop, TurnInterrupts ;
TYPE
@@ -192,87 +189,4 @@ PROCEDURE TBITSIZE (<type>) : CARDINAL ;
*)
*)
(* The following procedures are invoked by GNU Modula-2 to
shift non word sized set types. They are not strictly part
of the core PIM Modula-2, however they are used
to implement the SHIFT procedure defined above,
which are in turn used by the Logitech compatible libraries.
Users will access these procedures by using the procedure
SHIFT above and GNU Modula-2 will map SHIFT onto one of
the following procedures.
*)
(*
ShiftVal - is a runtime procedure whose job is to implement
the SHIFT procedure of ISO SYSTEM. GNU Modula-2 will
inline a SHIFT of a single WORD sized set and will
only call this routine for larger sets.
*)
PROCEDURE ShiftVal (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
ShiftCount: INTEGER) ;
(*
ShiftLeft - performs the shift left for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at
compile time.
*)
PROCEDURE ShiftLeft (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
ShiftCount: CARDINAL) ;
(*
ShiftRight - performs the shift left for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at
compile time.
*)
PROCEDURE ShiftRight (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
ShiftCount: CARDINAL) ;
(*
RotateVal - is a runtime procedure whose job is to implement
the ROTATE procedure of ISO SYSTEM. GNU Modula-2 will
inline a ROTATE of a single WORD (or less)
sized set and will only call this routine for
larger sets.
*)
PROCEDURE RotateVal (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
RotateCount: INTEGER) ;
(*
RotateLeft - performs the rotate left for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known
at compile time.
*)
PROCEDURE RotateLeft (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
RotateCount: CARDINAL) ;
(*
RotateRight - performs the rotate right for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at
compile time.
*)
PROCEDURE RotateRight (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
RotateCount: CARDINAL) ;
END SYSTEM.
+8 -243
View File
@@ -27,9 +27,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
IMPLEMENTATION MODULE SYSTEM ;
FROM RTco IMPORT init, initThread, transfer, currentThread, turnInterrupts ;
FROM RTint IMPORT Listen, AttachVector,
IncludeVector, ExcludeVector ;
FROM RTint IMPORT Listen, AttachVector, IncludeVector, ExcludeVector ;
IMPORT RTint ;
@@ -60,8 +58,6 @@ VAR
*)
PROCEDURE TRANSFER (VAR p1: PROCESS; p2: PROCESS) ;
VAR
r: INTEGER ;
BEGIN
localMain (p1) ;
IF p1.context=p2.context
@@ -104,14 +100,13 @@ END NEWPROCESS ;
PROCEDURE IOTRANSFER (VAR First, Second: PROCESS; InterruptNo: CARDINAL) ;
VAR
p: IOTransferState ;
l: POINTER TO IOTransferState ;
iots: IOTransferState ;
BEGIN
localMain (First) ;
WITH p DO
WITH iots DO
ptrToFirst := ADR (First) ;
ptrToSecond := ADR (Second) ;
next := AttachVector (InterruptNo, ADR (p))
next := AttachVector (InterruptNo, ADR (iots))
END ;
IncludeVector (InterruptNo) ;
TRANSFER (First, Second)
@@ -124,18 +119,18 @@ END IOTRANSFER ;
PROCEDURE IOTransferHandler (InterruptNo: CARDINAL;
Priority: CARDINAL ;
l: PtrToIOTransferState) ;
piots: PtrToIOTransferState) ;
VAR
old: PtrToIOTransferState ;
BEGIN
IF l=NIL
IF piots = NIL
THEN
Halt ('no processes attached to this interrupt vector which is associated with IOTRANSFER',
__FILE__, __FUNCTION__, __LINE__)
ELSE
WITH l^ DO
WITH piots^ DO
old := AttachVector (InterruptNo, next) ;
IF old#l
IF old # piots
THEN
Halt ('inconsistancy of return result',
__FILE__, __FUNCTION__, __LINE__)
@@ -250,236 +245,6 @@ BEGIN
END localMain ;
(*
Max - returns the maximum of a and b.
*)
PROCEDURE Max (a, b: CARDINAL) : CARDINAL ;
BEGIN
IF a > b
THEN
RETURN a
ELSE
RETURN b
END
END Max ;
(*
Min - returns the minimum of a and b.
*)
PROCEDURE Min (a, b: CARDINAL) : CARDINAL ;
BEGIN
IF a < b
THEN
RETURN a
ELSE
RETURN b
END
END Min ;
(*
ShiftVal - is a runtime procedure whose job is to implement
the SHIFT procedure of ISO SYSTEM. GNU Modula-2 will
inline a SHIFT of a single WORD sized set and will only
call this routine for larger sets.
*)
PROCEDURE ShiftVal (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
ShiftCount: INTEGER) ;
VAR
a: ADDRESS ;
BEGIN
IF ShiftCount>0
THEN
ShiftCount := ShiftCount MOD VAL(INTEGER, SetSizeInBits) ;
ShiftLeft (s, d, SetSizeInBits, ShiftCount)
ELSIF ShiftCount<0
THEN
ShiftCount := (-ShiftCount) MOD VAL(INTEGER, SetSizeInBits) ;
ShiftRight (s, d, SetSizeInBits, ShiftCount)
ELSE
a := memcpy (ADR (d), ADR (s), (HIGH (d) + 1) * SIZE (BITSET))
END
END ShiftVal ;
(*
ShiftLeft - performs the shift left for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at compile
time.
*)
PROCEDURE ShiftLeft (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
ShiftCount: CARDINAL) ;
VAR
lo, hi : BITSET ;
i, j, h: CARDINAL ;
a : ADDRESS ;
BEGIN
h := HIGH(s)+1 ;
IF ShiftCount MOD BitsPerBitset=0
THEN
i := ShiftCount DIV BitsPerBitset ;
a := ADR (d[i]) ;
a := memcpy (a, ADR (s), (h-i) * SIZE (BITSET)) ;
a := memset (ADR (d), 0, i * SIZE (BITSET))
ELSE
i := h ;
WHILE i>0 DO
DEC (i) ;
lo := SHIFT (s[i], ShiftCount MOD BitsPerBitset) ;
hi := SHIFT (s[i], -(BitsPerBitset - (ShiftCount MOD BitsPerBitset))) ;
d[i] := BITSET{} ;
j := i + ShiftCount DIV BitsPerBitset ;
IF j<h
THEN
d[j] := d[j] + lo ;
INC(j) ;
IF j<h
THEN
d[j] := d[j] + hi
END
END
END
END
END ShiftLeft ;
(*
ShiftRight - performs the shift left for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at compile
time.
*)
PROCEDURE ShiftRight (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
ShiftCount: CARDINAL) ;
VAR
lo, hi : BITSET ;
j, i, h: INTEGER ;
a : ADDRESS ;
BEGIN
h := HIGH (s) + 1 ;
IF ShiftCount MOD BitsPerBitset=0
THEN
i := ShiftCount DIV BitsPerBitset ;
a := ADR (s[i]) ;
j := h-i ;
a := memcpy (ADR (d), a, j * VAL (INTEGER, SIZE(BITSET))) ;
a := ADR (d[j]) ;
a := memset (a, 0, i * VAL (INTEGER, SIZE(BITSET)))
ELSE
i := 0 ;
WHILE i<h DO
lo := SHIFT(s[i], BitsPerBitset - (ShiftCount MOD BitsPerBitset)) ;
hi := SHIFT(s[i], -(ShiftCount MOD BitsPerBitset)) ;
d[i] := BITSET{} ;
j := i - VAL(INTEGER, ShiftCount DIV BitsPerBitset) ;
IF j>=0
THEN
d[j] := d[j] + hi ;
DEC(j) ;
IF j>=0
THEN
d[j] := d[j] + lo
END
END ;
INC(i)
END
END
END ShiftRight ;
(*
RotateVal - is a runtime procedure whose job is to implement
the ROTATE procedure of ISO SYSTEM. GNU Modula-2 will
inline a ROTATE of a single WORD (or less)
sized set and will only call this routine for larger sets.
*)
PROCEDURE RotateVal (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
RotateCount: INTEGER) ;
VAR
a: ADDRESS ;
BEGIN
IF RotateCount>0
THEN
RotateLeft(s, d, SetSizeInBits, RotateCount)
ELSIF RotateCount<0
THEN
RotateRight(s, d, SetSizeInBits, -RotateCount)
ELSE
a := memcpy(ADR(d), ADR(s), (HIGH(d)+1)*SIZE(BITSET))
END
END RotateVal ;
(*
RotateLeft - performs the rotate left for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at compile
time.
*)
PROCEDURE RotateLeft (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
RotateCount: CARDINAL) ;
VAR
lo, hi : BITSET ;
b, i, j, h: CARDINAL ;
BEGIN
h := HIGH(s) ;
(* firstly we set d := {} *)
i := 0 ;
WHILE i<=h DO
d[i] := BITSET{} ;
INC(i)
END ;
i := h+1 ;
RotateCount := RotateCount MOD SetSizeInBits ;
b := SetSizeInBits MOD BitsPerBitset ;
IF b=0
THEN
b := BitsPerBitset
END ;
WHILE i>0 DO
DEC(i) ;
lo := SHIFT(s[i], RotateCount MOD BitsPerBitset) ;
hi := SHIFT(s[i], -(b - (RotateCount MOD BitsPerBitset))) ;
j := ((i*BitsPerBitset + RotateCount) MOD
SetSizeInBits) DIV BitsPerBitset ;
d[j] := d[j] + lo ;
j := (((i+1)*BitsPerBitset + RotateCount) MOD
SetSizeInBits) DIV BitsPerBitset ;
d[j] := d[j] + hi ;
b := BitsPerBitset
END
END RotateLeft ;
(*
RotateRight - performs the rotate right for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at compile
time.
*)
PROCEDURE RotateRight (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
RotateCount: CARDINAL) ;
BEGIN
RotateLeft(s, d, SetSizeInBits, SetSizeInBits-RotateCount)
END RotateRight ;
BEGIN
initGTh := FALSE ;
initMain := FALSE
-80
View File
@@ -20,10 +20,7 @@ EXPORT QUALIFIED BITSPERLOC, LOCSPERWORD,
LOC, BYTE, WORD, ADDRESS, CSIZE_T, CSSIZE_T, COFF_T, (* @SYSTEM_DATATYPES@ *)
ADDADR, SUBADR, DIFADR, MAKEADR, ADR, ROTATE,
SHIFT, CAST, TSIZE,
(* Internal GM2 compiler functions *)
ShiftVal, ShiftLeft, ShiftRight,
RotateVal, RotateLeft, RotateRight,
THROW, TBITSIZE ;
CONST
@@ -155,81 +152,4 @@ PROCEDURE TBITSIZE (<type>) : CARDINAL ;
*)
*)
(* The following procedures are invoked by GNU Modula-2 to
shift non word set types. They are not part of ISO Modula-2
but are used to implement the SHIFT procedure defined above. *)
(*
ShiftVal - is a runtime procedure whose job is to implement
the SHIFT procedure of ISO SYSTEM. GNU Modula-2 will
inline a SHIFT of a single WORD sized set and will only
call this routine for larger sets.
*)
PROCEDURE ShiftVal (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
ShiftCount: INTEGER) ;
(*
ShiftLeft - performs the shift left for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at
compile time.
*)
PROCEDURE ShiftLeft (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
ShiftCount: CARDINAL) ;
(*
ShiftRight - performs the shift left for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at
compile time.
*)
PROCEDURE ShiftRight (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
ShiftCount: CARDINAL) ;
(*
RotateVal - is a runtime procedure whose job is to implement
the ROTATE procedure of ISO SYSTEM. GNU Modula-2 will
inline a ROTATE of a single WORD (or less)
sized set and will only call this routine for larger
sets.
*)
PROCEDURE RotateVal (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
RotateCount: INTEGER) ;
(*
RotateLeft - performs the rotate left for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at
compile time.
*)
PROCEDURE RotateLeft (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
RotateCount: CARDINAL) ;
(*
RotateRight - performs the rotate right for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at
compile time.
*)
PROCEDURE RotateRight (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
RotateCount: CARDINAL) ;
END SYSTEM.
-244
View File
@@ -26,248 +26,4 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
IMPLEMENTATION MODULE SYSTEM ;
FROM libc IMPORT memcpy, memset ;
CONST
BitsPerBitset = MAX(BITSET)+1 ;
(*
Max - returns the maximum of a and b.
*)
PROCEDURE Max (a, b: CARDINAL) : CARDINAL ;
BEGIN
IF a>b
THEN
RETURN a
ELSE
RETURN b
END
END Max ;
(*
Min - returns the minimum of a and b.
*)
PROCEDURE Min (a, b: CARDINAL) : CARDINAL ;
BEGIN
IF a<b
THEN
RETURN a
ELSE
RETURN b
END
END Min ;
(*
ShiftVal - is a runtime procedure whose job is to implement
the SHIFT procedure of ISO SYSTEM. GNU Modula-2 will
inline a SHIFT of a single WORD sized set and will only
call this routine for larger sets.
*)
PROCEDURE ShiftVal (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
ShiftCount: INTEGER) ;
VAR
a: ADDRESS ;
BEGIN
IF ShiftCount>0
THEN
ShiftCount := ShiftCount MOD VAL(INTEGER, SetSizeInBits) ;
ShiftLeft(s, d, SetSizeInBits, ShiftCount)
ELSIF ShiftCount<0
THEN
ShiftCount := (-ShiftCount) MOD VAL(INTEGER, SetSizeInBits) ;
ShiftRight(s, d, SetSizeInBits, ShiftCount)
ELSE
a := memcpy(ADR(d), ADR(s), (HIGH(d)+1)*SIZE(BITSET))
END
END ShiftVal ;
(*
ShiftLeft - performs the shift left for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at compile
time.
*)
PROCEDURE ShiftLeft (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
ShiftCount: CARDINAL) ;
VAR
lo, hi : BITSET ;
i, j, h: CARDINAL ;
a : ADDRESS ;
BEGIN
h := HIGH(s)+1 ;
IF ShiftCount MOD BitsPerBitset=0
THEN
i := ShiftCount DIV BitsPerBitset ;
a := ADR(d[i]) ;
a := memcpy(a, ADR(s), (h-i)*SIZE(BITSET)) ;
a := memset(ADR(d), 0, i*SIZE(BITSET))
ELSE
i := h ;
WHILE i>0 DO
DEC(i) ;
lo := SHIFT(s[i], ShiftCount MOD BitsPerBitset) ;
hi := SHIFT(s[i], -(BitsPerBitset - (ShiftCount MOD BitsPerBitset))) ;
d[i] := BITSET{} ;
j := i + ShiftCount DIV BitsPerBitset ;
IF j<h
THEN
d[j] := d[j] + lo ;
INC(j) ;
IF j<h
THEN
d[j] := d[j] + hi
END
END
END
END
END ShiftLeft ;
(*
ShiftRight - performs the shift left for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at compile
time.
*)
PROCEDURE ShiftRight (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
ShiftCount: CARDINAL) ;
VAR
lo, hi : BITSET ;
j, i, h: INTEGER ;
a : ADDRESS ;
BEGIN
h := HIGH(s)+1 ;
IF ShiftCount MOD BitsPerBitset=0
THEN
i := ShiftCount DIV BitsPerBitset ;
a := ADR(s[i]) ;
j := h-i ;
a := memcpy(ADR(d), a, j * VAL (INTEGER, SIZE (BITSET))) ;
a := ADR(d[j]) ;
a := memset(a, 0, i * VAL (INTEGER, SIZE (BITSET)))
ELSE
i := 0 ;
WHILE i<h DO
lo := SHIFT(s[i], BitsPerBitset - (ShiftCount MOD BitsPerBitset)) ;
hi := SHIFT(s[i], -(ShiftCount MOD BitsPerBitset)) ;
d[i] := BITSET{} ;
j := i - VAL(INTEGER, ShiftCount DIV BitsPerBitset) ;
IF j>=0
THEN
d[j] := d[j] + hi ;
DEC(j) ;
IF j>=0
THEN
d[j] := d[j] + lo
END
END ;
INC(i)
END
END
END ShiftRight ;
(*
RotateVal - is a runtime procedure whose job is to implement
the ROTATE procedure of ISO SYSTEM. GNU Modula-2 will
inline a ROTATE of a single WORD (or less)
sized set and will only call this routine for larger sets.
*)
PROCEDURE RotateVal (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
RotateCount: INTEGER) ;
VAR
a: ADDRESS ;
BEGIN
IF RotateCount>0
THEN
RotateCount := RotateCount MOD VAL(INTEGER, SetSizeInBits)
ELSIF RotateCount<0
THEN
RotateCount := -VAL(INTEGER, VAL(CARDINAL, -RotateCount) MOD SetSizeInBits)
END ;
IF RotateCount>0
THEN
RotateLeft(s, d, SetSizeInBits, RotateCount)
ELSIF RotateCount<0
THEN
RotateRight(s, d, SetSizeInBits, -RotateCount)
ELSE
(* no rotate required, but we must copy source to dest. *)
a := memcpy(ADR(d), ADR(s), (HIGH(d)+1)*SIZE(BITSET))
END
END RotateVal ;
(*
RotateLeft - performs the rotate left for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at compile
time.
*)
PROCEDURE RotateLeft (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
RotateCount: CARDINAL) ;
VAR
lo, hi : BITSET ;
b, i, j, h: CARDINAL ;
BEGIN
h := HIGH(s) ;
(* firstly we set d := {} *)
i := 0 ;
WHILE i<=h DO
d[i] := BITSET{} ;
INC(i)
END ;
i := h+1 ;
RotateCount := RotateCount MOD SetSizeInBits ;
b := SetSizeInBits MOD BitsPerBitset ;
IF b=0
THEN
b := BitsPerBitset
END ;
WHILE i>0 DO
DEC(i) ;
lo := SHIFT(s[i], RotateCount MOD BitsPerBitset) ;
hi := SHIFT(s[i], -(b - (RotateCount MOD BitsPerBitset))) ;
j := ((i*BitsPerBitset + RotateCount) MOD
SetSizeInBits) DIV BitsPerBitset ;
d[j] := d[j] + lo ;
j := (((i+1)*BitsPerBitset + RotateCount) MOD
SetSizeInBits) DIV BitsPerBitset ;
d[j] := d[j] + hi ;
b := BitsPerBitset
END
END RotateLeft ;
(*
RotateRight - performs the rotate right for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at compile
time.
*)
PROCEDURE RotateRight (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
RotateCount: CARDINAL) ;
BEGIN
RotateLeft(s, d, SetSizeInBits, SetSizeInBits-RotateCount)
END RotateRight ;
END SYSTEM.
+182
View File
@@ -0,0 +1,182 @@
(* M2Diagnotic provides memory and time diagnosics to the user.
Copyright (C) 2024 Free Software Foundation, Inc.
Contributed by Gaius Mulley <gaiusmod2@gmail.com>.
This file is part of GNU Modula-2.
GNU Modula-2 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Modula-2 is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Modula-2; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. *)
DEFINITION MODULE M2Diagnostic ; (*!m2iso+gm2*)
(*
Title : M2Diagnotic
Author : Gaius Mulley
System : GNU Modula-2
Date : Thu Jan 4 10:38:53 2024
Revision : $Version$
Description: provides memory and time diagnosics to the user.
*)
FROM DynamicStrings IMPORT String ;
TYPE
Diagnostic ;
DiagProc = PROCEDURE (Diagnostic) ;
(*
InitTimeDiagnostic - create and return a time diagnostic.
The format string can be free form and may
contain {1T}, {1C} or {1P}.
{1T} will contain the time and
{1C} the count of the number of times the
code enters the time diagnostic code region.
{1P} generates the time as a percentage.
{0T} is the total time for the application.
{{ is rendered as a single {.
*)
PROCEDURE InitTimeDiagnostic (name, format: ARRAY OF CHAR) : Diagnostic ;
(*
EnterDiagnostic - attribute all execution time from now to TimeDiag.
*)
PROCEDURE EnterDiagnostic (TimeDiag: Diagnostic) ;
(*
ExitDiagnostic - stop attributing execution time to TimeDiag.
*)
PROCEDURE ExitDiagnostic (TimeDiag: Diagnostic) ;
(*
InitMemDiagnostic - create and return a memory diagnostic.
The format string can be free form and may
contain {1M} {1d} {1x} {1P}.
{1M} is replaced by the value of the first parameter
with memory size units.
{1d} unsigned decimal. {1x} unsigned hexadecimal.
{0M} is the global allocation (Storage.mod:ALLOCATE).
{1P} is the percentage of param 1 relative
to global memory.
*)
PROCEDURE InitMemDiagnostic (name, format: ARRAY OF CHAR) : Diagnostic ;
(*
MemIncr - allow the appropriate parameter to be incremented.
All parameters are initially set to zero and are stored
as LONGCARD.
*)
PROCEDURE MemIncr (MemDiag: Diagnostic; paramno: CARDINAL; incr: CARDINAL) ;
(*
MemDecr - allow the appropriate parameter to be decremented.
All parameters are initially set to zero and are stored
as LONGCARD.
*)
PROCEDURE MemDecr (MemDiag: Diagnostic; paramno: CARDINAL; decr: CARDINAL) ;
(*
MemSet - allow the appropriate parameter to be set to value.
All parameters are initially set to zero.
*)
PROCEDURE MemSet (MemDiag: Diagnostic; paramno: CARDINAL; value: CARDINAL) ;
(*
TotalHeapIncr - increments the total heap used.
*)
PROCEDURE TotalHeapIncr (incr: CARDINAL) ;
(*
TotalHeapDecr - decrements the total heap used.
*)
PROCEDURE TotalHeapDecr (incr: CARDINAL) ;
(*
SetEnable - set the enable flag in Diag to value.
*)
PROCEDURE SetEnable (Diag: Diagnostic; value: BOOLEAN) ;
(*
Lookup - returns the Diagnostic containing name or NIL
if it does not exist.
*)
PROCEDURE Lookup (name: ARRAY OF CHAR) : Diagnostic ;
(*
GetName - returns the name of Diag.
*)
PROCEDURE GetName (Diag: Diagnostic) : String ;
(*
ForeachDiagDo - for diag in global diag list do
dp (diag);
end
*)
PROCEDURE ForeachDiagDo (dp: DiagProc) ;
(*
SetDefaultConfig - force the Diag enable flag to the
time or mem global default.
*)
PROCEDURE SetDefaultConfig (Diag: Diagnostic) ;
(*
Configure - will turn on or off all the memory or time
instrumentation diagnostics and set the defaults
time and mem values.
*)
PROCEDURE Configure (time, mem: BOOLEAN) ;
(*
Generate - return a string containing the output from
all the diagnostics enabled. If hierarchical is TRUE
then the output is displayed in a hierarchical format
using the name and ':' separators to signify grouping.
*)
PROCEDURE Generate (hierarchical: BOOLEAN) : String ;
END M2Diagnostic.
File diff suppressed because it is too large Load Diff
+210
View File
@@ -0,0 +1,210 @@
(* M2WIDESET.def runtime support procedures for wide sets.
Copyright (C) 2025 Free Software Foundation, Inc.
Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
This file is part of GNU Modula-2.
GNU Modula-2 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Modula-2 is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. *)
DEFINITION MODULE M2WIDESET ;
(*
Title : M2WIDESET
Author : Gaius Mulley
System : GNU Modula-2
Date : Thu Nov 16 19:57:31 2023
Description: provides runtime capability for wide sets.
*)
FROM SYSTEM IMPORT BYTE ;
(*
Or - dest = left | right
implement OR for a wide set type.
*)
PROCEDURE Or (VAR dest: ARRAY OF BYTE; left, right: ARRAY OF BYTE;
highbit: CARDINAL) ;
(*
And - dest = left & right
implement AND for a wide set type.
*)
PROCEDURE And (VAR dest: ARRAY OF BYTE; left, right: ARRAY OF BYTE;
highbit: CARDINAL) ;
(*
Not - dest = ~ operand
implement AND for a wide set type.
*)
PROCEDURE Not (VAR dest: ARRAY OF BYTE; expr: ARRAY OF BYTE;
highbit: CARDINAL) ;
(*
Incl - dest |= bit
implement INCL for a wide set type.
*)
PROCEDURE Incl (VAR dest: ARRAY OF BYTE; bit: CARDINAL) ;
(*
Excl - dest &= (~ bit)
implement EXCL for a wide set type.
*)
PROCEDURE Excl (VAR dest: ARRAY OF BYTE; bit: CARDINAL) ;
(*
In - return bit IN expr.
*)
PROCEDURE In (VAR expr: ARRAY OF BYTE; bit: CARDINAL) : BOOLEAN ;
(*
Equal - return left = right.
*)
PROCEDURE Equal (VAR left, right: ARRAY OF BYTE; highbit: CARDINAL) : BOOLEAN ;
(*
Clear - dest = {}.
*)
PROCEDURE Clear (VAR dest: ARRAY OF BYTE; highbit: CARDINAL) ;
(*
Shift - dest := SHIFT (src, ShiftCount). This is a logical shift
all the new bit values will be zero.
*)
PROCEDURE Shift (VAR dest: ARRAY OF BYTE; src: ARRAY OF BYTE;
highbit: CARDINAL; ShiftCount: INTEGER) ;
(*
ArithShift - dest := ArithShift (dest, ShiftCount, carry). This is an
arithmetic shift all the new bit values will
be set to carry.
*)
PROCEDURE ArithShift (VAR dest: ARRAY OF BYTE;
highbit: CARDINAL; ShiftCount: INTEGER;
carry: BOOLEAN) ;
(*
Rotate - is a runtime procedure whose job is to implement
the ROTATE procedure of ISO SYSTEM.
*)
PROCEDURE Rotate (VAR dest: ARRAY OF BYTE; src: ARRAY OF BYTE;
highbit: CARDINAL; RotateCount: INTEGER) ;
(*
Less - performs the set comparison for a wide set.
Less returns ProperSubset (left, right, highbit).
*)
PROCEDURE Less (VAR left, right: ARRAY OF BYTE;
highbit: CARDINAL) : BOOLEAN ;
(*
LessEqu - performs the set comparison for a wide set.
LessEqu returns Equal (left, right, highbit) OR
ProperSubset (left, right, highbit).
*)
PROCEDURE LessEqu (VAR left, right: ARRAY OF BYTE;
highbit: CARDINAL) : BOOLEAN ;
(*
Gre - performs the set comparison for a wide set.
Gre returns the result of
ProperSuperet (left, right, highbit).
*)
PROCEDURE Gre (VAR left, right: ARRAY OF BYTE;
highbit: CARDINAL) : BOOLEAN ;
(*
GreEqu - performs the set comparison for a wide set.
GreEqu returns Equal (left, right, highbit) OR
ProperSuperet (left, right, highbit).
*)
PROCEDURE GreEqu (VAR left, right: ARRAY OF BYTE;
highbit: CARDINAL) : BOOLEAN ;
(*
ProperSubset - return TRUE if left is a proper subset of right.
If true the left set will have at least one element
less than set right.
*)
PROCEDURE ProperSubset (VAR left, right: ARRAY OF BYTE;
highbit: CARDINAL) : BOOLEAN ;
(*
ProperSuperset - return TRUE if left is a proper superset of right.
If true the left set will have at least one element
more than set right.
*)
PROCEDURE ProperSuperset (VAR left, right: ARRAY OF BYTE;
highbit: CARDINAL) : BOOLEAN ;
(*
LogicalDifference - build a logical difference expression tree.
dest := left and (not right).
*)
PROCEDURE LogicalDifference (VAR dest: ARRAY OF BYTE;
left, right: ARRAY OF BYTE;
highbit: CARDINAL) ;
(*
SymmetricDifference - build a logical difference expression tree.
dest := left xor right.
*)
PROCEDURE SymmetricDifference (VAR dest: ARRAY OF BYTE;
left, right: ARRAY OF BYTE;
highbit: CARDINAL) ;
END M2WIDESET.
File diff suppressed because it is too large Load Diff
-83
View File
@@ -111,87 +111,4 @@ PROCEDURE TBITSIZE (<type>) : CARDINAL ;
*)
*)
(* The following procedures are invoked by GNU Modula-2 to
shift non word sized set types. They are not strictly part
of the core PIM Modula-2, however they are used
to implement the SHIFT procedure defined above,
which are in turn used by the Logitech compatible libraries.
Users will access these procedures by using the procedure
SHIFT above and GNU Modula-2 will map SHIFT onto one of
the following procedures.
*)
(*
ShiftVal - is a runtime procedure whose job is to implement
the SHIFT procedure of ISO SYSTEM. GNU Modula-2 will
inline a SHIFT of a single WORD sized set and will only
call this routine for larger sets.
*)
PROCEDURE ShiftVal (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
ShiftCount: INTEGER) ;
(*
ShiftLeft - performs the shift left for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at
compile time.
*)
PROCEDURE ShiftLeft (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
ShiftCount: CARDINAL) ;
(*
ShiftRight - performs the shift left for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at
compile time.
*)
PROCEDURE ShiftRight (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
ShiftCount: CARDINAL) ;
(*
RotateVal - is a runtime procedure whose job is to implement
the ROTATE procedure of ISO SYSTEM. GNU Modula-2 will
inline a ROTATE of a single WORD (or less)
sized set and will only call this routine for larger
sets.
*)
PROCEDURE RotateVal (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
RotateCount: INTEGER) ;
(*
RotateLeft - performs the rotate left for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at
compile time.
*)
PROCEDURE RotateLeft (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
RotateCount: CARDINAL) ;
(*
RotateRight - performs the rotate right for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at
compile time.
*)
PROCEDURE RotateRight (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
RotateCount: CARDINAL) ;
END SYSTEM.
-244
View File
@@ -26,248 +26,4 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
IMPLEMENTATION MODULE SYSTEM ;
FROM libc IMPORT memcpy, memset ;
CONST
BitsPerBitset = MAX(BITSET)+1 ;
(*
Max - returns the maximum of a and b.
*)
PROCEDURE Max (a, b: CARDINAL) : CARDINAL ;
BEGIN
IF a>b
THEN
RETURN( a )
ELSE
RETURN( b )
END
END Max ;
(*
Min - returns the minimum of a and b.
*)
PROCEDURE Min (a, b: CARDINAL) : CARDINAL ;
BEGIN
IF a<b
THEN
RETURN( a )
ELSE
RETURN( b )
END
END Min ;
(*
ShiftVal - is a runtime procedure whose job is to implement
the SHIFT procedure of ISO SYSTEM. GNU Modula-2 will
inline a SHIFT of a single WORD sized set and will only
call this routine for larger sets.
*)
PROCEDURE ShiftVal (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
ShiftCount: INTEGER) ;
VAR
a: ADDRESS ;
BEGIN
IF ShiftCount>0
THEN
ShiftCount := ShiftCount MOD VAL(INTEGER, SetSizeInBits) ;
ShiftLeft(s, d, SetSizeInBits, ShiftCount)
ELSIF ShiftCount<0
THEN
ShiftCount := (-ShiftCount) MOD VAL(INTEGER, SetSizeInBits) ;
ShiftRight(s, d, SetSizeInBits, ShiftCount)
ELSE
a := memcpy(ADR(d), ADR(s), (HIGH(d)+1)*SIZE(BITSET))
END
END ShiftVal ;
(*
ShiftLeft - performs the shift left for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at compile
time.
*)
PROCEDURE ShiftLeft (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
ShiftCount: CARDINAL) ;
VAR
lo, hi : BITSET ;
i, j, h: CARDINAL ;
a : ADDRESS ;
BEGIN
h := HIGH(s)+1 ;
IF ShiftCount MOD BitsPerBitset=0
THEN
i := ShiftCount DIV BitsPerBitset ;
a := ADR(d[i]) ;
a := memcpy(a, ADR(s), (h-i)*SIZE(BITSET)) ;
a := memset(ADR(d), 0, i*SIZE(BITSET))
ELSE
i := h ;
WHILE i>0 DO
DEC(i) ;
lo := SHIFT(s[i], ShiftCount MOD BitsPerBitset) ;
hi := SHIFT(s[i], -(BitsPerBitset - (ShiftCount MOD BitsPerBitset))) ;
d[i] := BITSET{} ;
j := i + ShiftCount DIV BitsPerBitset ;
IF j<h
THEN
d[j] := d[j] + lo ;
INC(j) ;
IF j<h
THEN
d[j] := d[j] + hi
END
END
END
END
END ShiftLeft ;
(*
ShiftRight - performs the shift left for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at compile
time.
*)
PROCEDURE ShiftRight (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
ShiftCount: CARDINAL) ;
VAR
lo, hi : BITSET ;
j, i, h: INTEGER ;
a : ADDRESS ;
BEGIN
h := HIGH (s) + 1 ;
IF ShiftCount MOD BitsPerBitset = 0
THEN
i := ShiftCount DIV BitsPerBitset ;
a := ADR (s[i]) ;
j := h-i ;
a := memcpy (ADR (d), a, j * VAL (INTEGER, SIZE (BITSET))) ;
a := ADR (d[j]) ;
a := memset (a, 0, i * VAL (INTEGER, SIZE (BITSET)))
ELSE
i := 0 ;
WHILE i<h DO
lo := SHIFT(s[i], BitsPerBitset - (ShiftCount MOD BitsPerBitset)) ;
hi := SHIFT(s[i], -(ShiftCount MOD BitsPerBitset)) ;
d[i] := BITSET{} ;
j := i - VAL (INTEGER, ShiftCount DIV BitsPerBitset) ;
IF j>=0
THEN
d[j] := d[j] + hi ;
DEC(j) ;
IF j>=0
THEN
d[j] := d[j] + lo
END
END ;
INC(i)
END
END
END ShiftRight ;
(*
RotateVal - is a runtime procedure whose job is to implement
the ROTATE procedure of ISO SYSTEM. GNU Modula-2 will
inline a ROTATE of a single WORD (or less)
sized set and will only call this routine for larger sets.
*)
PROCEDURE RotateVal (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
RotateCount: INTEGER) ;
VAR
a: ADDRESS ;
BEGIN
IF RotateCount>0
THEN
RotateCount := RotateCount MOD VAL(INTEGER, SetSizeInBits)
ELSIF RotateCount<0
THEN
RotateCount := -VAL(INTEGER, VAL(CARDINAL, -RotateCount) MOD SetSizeInBits)
END ;
IF RotateCount>0
THEN
RotateLeft(s, d, SetSizeInBits, RotateCount)
ELSIF RotateCount<0
THEN
RotateRight(s, d, SetSizeInBits, -RotateCount)
ELSE
(* no rotate required, but we must copy source to dest. *)
a := memcpy(ADR(d), ADR(s), (HIGH(d)+1)*SIZE(BITSET))
END
END RotateVal ;
(*
RotateLeft - performs the rotate left for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at compile
time.
*)
PROCEDURE RotateLeft (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
RotateCount: CARDINAL) ;
VAR
lo, hi : BITSET ;
b, i, j, h: CARDINAL ;
BEGIN
h := HIGH(s) ;
(* firstly we set d := {} *)
i := 0 ;
WHILE i<=h DO
d[i] := BITSET{} ;
INC(i)
END ;
i := h+1 ;
RotateCount := RotateCount MOD SetSizeInBits ;
b := SetSizeInBits MOD BitsPerBitset ;
IF b=0
THEN
b := BitsPerBitset
END ;
WHILE i>0 DO
DEC(i) ;
lo := SHIFT(s[i], RotateCount MOD BitsPerBitset) ;
hi := SHIFT(s[i], -(b - (RotateCount MOD BitsPerBitset))) ;
j := ((i*BitsPerBitset + RotateCount) MOD
SetSizeInBits) DIV BitsPerBitset ;
d[j] := d[j] + lo ;
j := (((i+1)*BitsPerBitset + RotateCount) MOD
SetSizeInBits) DIV BitsPerBitset ;
d[j] := d[j] + hi ;
b := BitsPerBitset
END
END RotateLeft ;
(*
RotateRight - performs the rotate right for a multi word set.
This procedure might be called by the back end of
GNU Modula-2 depending whether amount is known at compile
time.
*)
PROCEDURE RotateRight (VAR s, d: ARRAY OF BITSET;
SetSizeInBits: CARDINAL;
RotateCount: CARDINAL) ;
BEGIN
RotateLeft(s, d, SetSizeInBits, SetSizeInBits-RotateCount)
END RotateRight ;
END SYSTEM.
+8 -1
View File
@@ -28,7 +28,9 @@ DEFINITION MODULE SysStorage ;
(* Provides dynamic allocation for the system components.
This allows the application to use the traditional Storage module
which can be handled differently. *)
which can be handled differently.
ALLOCATE and DEALLOCATE will call M2Diagnostic to adjust the
global tracking of the application heap. *)
FROM SYSTEM IMPORT ADDRESS ;
EXPORT QUALIFIED ALLOCATE, DEALLOCATE, REALLOCATE, Available, Init ;
@@ -56,6 +58,11 @@ PROCEDURE DEALLOCATE (VAR a: ADDRESS ; size: CARDINAL) ;
is called, or alternatively it should have already
been initialized by ALLOCATE. The allocated storage
is resized accordingly.
Note that this procedure does not adjust the
M2Diagnostic.TotalHeap it is expected that the caller
must track the reallocation differences and call
M2Diagnostic.TotalHeapIncr or M2Diagnostic.TotalHeapDecr
as appropriate.
*)
PROCEDURE REALLOCATE (VAR a: ADDRESS; size: CARDINAL) ;
+10 -1
View File
@@ -30,6 +30,8 @@ FROM libc IMPORT malloc, free, realloc, memset, getenv, printf ;
FROM Debug IMPORT Halt ;
FROM SYSTEM IMPORT ADR ;
IMPORT M2Diagnostic ;
CONST
enableDeallocation = TRUE ;
@@ -55,7 +57,8 @@ BEGIN
printf ("<DEBUG-CALL> %d SysStorage.ALLOCATE (0x%x, %d bytes)\n", callno, a, size) ;
printf ("<MEM-ALLOC> %ld %d\n", a, size);
INC (callno)
END
END ;
M2Diagnostic.TotalHeapIncr (size)
END ALLOCATE ;
@@ -87,6 +90,7 @@ BEGIN
END ;
free (a)
END ;
M2Diagnostic.TotalHeapDecr (size) ;
a := NIL
END DEALLOCATE ;
@@ -97,6 +101,11 @@ END DEALLOCATE ;
is called, or alternatively it should have already
been initialized by ALLOCATE. The allocated storage
is resized accordingly.
Note that this procedure does not adjust the
M2Diagnostic.TotalHeap it is expected that the caller
must track the reallocation differences and call
M2Diagnostic.TotalHeapIncr or M2Diagnostic.TotalHeapDecr
as appropriate.
*)
PROCEDURE REALLOCATE (VAR a: ADDRESS; size: CARDINAL) ;
+2
View File
@@ -25,6 +25,7 @@ RTExceptions
M2EXCEPTION
M2RTS
SysExceptions
M2Diagnostic
StrLib
errno
termios
@@ -45,6 +46,7 @@ UnixArgs
FIO
SFIO
StrCase
StringConvert
bnflex
Lists
Args
+12
View File
@@ -206,6 +206,10 @@ fm2-whole-program
Modula-2
compile all implementation modules and program module at once
fmem-report
Modula-2
; Documented in c.opt
fmod=
Modula-2 Joined
recognize the specified suffix as implementation and module filenames
@@ -290,6 +294,10 @@ fswig
Modula-2
create a swig interface file for the module
ftime-report
Modula-2
; Documented in c.opt
funbounded-by-reference
Modula-2
optimize non var unbounded parameters by passing it by reference, providing it is not written to within the callee procedure.
@@ -302,6 +310,10 @@ fversion
Modula-2
; Documented in common.opt
fwideset
Modula-2
link against the module M2WIDESET to perform the wideset operator, the negative version of this option will generate a warning if this module is required
fwholediv
Modula-2
turns on all division and modulus by zero checking for ordinal values
File diff suppressed because it is too large Load Diff
+186
View File
@@ -0,0 +1,186 @@
/* do not edit automatically generated by mc from M2Diagnostic. */
/* M2Diagnotic provides memory and time diagnosics to the user.
Copyright (C) 2024 Free Software Foundation, Inc.
Contributed by Gaius Mulley <gaiusmod2@gmail.com>.
This file is part of GNU Modula-2.
GNU Modula-2 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Modula-2 is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Modula-2; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#if !defined (_M2Diagnostic_H)
# define _M2Diagnostic_H
#include "config.h"
#include "system.h"
# ifdef __cplusplus
extern "C" {
# endif
#include <stdbool.h>
# if !defined (PROC_D)
# define PROC_D
typedef void (*PROC_t) (void);
typedef struct { PROC_t proc; } PROC;
# endif
# include "GDynamicStrings.h"
# if defined (_M2Diagnostic_C)
# define EXTERN
# else
# define EXTERN extern
# endif
#if !defined (M2Diagnostic_Diagnostic_D)
# define M2Diagnostic_Diagnostic_D
typedef void *M2Diagnostic_Diagnostic;
#endif
typedef struct M2Diagnostic_DiagProc_p M2Diagnostic_DiagProc;
typedef void (*M2Diagnostic_DiagProc_t) (M2Diagnostic_Diagnostic);
struct M2Diagnostic_DiagProc_p { M2Diagnostic_DiagProc_t proc; };
/*
InitTimeDiagnostic - create and return a time diagnostic.
The format string can be free form and may
contain {1T}, {1C} or {1P}.
{1T} will contain the time and
{1C} the count of the number of times the
code enters the time diagnostic code region.
{1P} generates the time as a percentage.
{0T} is the total time for the application.
{{ is rendered as a single {.
*/
EXTERN M2Diagnostic_Diagnostic M2Diagnostic_InitTimeDiagnostic (const char *name_, unsigned int _name_high, const char *format_, unsigned int _format_high);
/*
EnterDiagnostic - attribute all execution time from now to TimeDiag.
*/
EXTERN void M2Diagnostic_EnterDiagnostic (M2Diagnostic_Diagnostic TimeDiag);
/*
ExitDiagnostic - stop attributing execution time to TimeDiag.
*/
EXTERN void M2Diagnostic_ExitDiagnostic (M2Diagnostic_Diagnostic TimeDiag);
/*
InitMemDiagnostic - create and return a memory diagnostic.
The format string can be free form and may
contain {1M} {1d} {1x} {1P}.
{1M} is replaced by the value of the first parameter
with memory size units.
{1d} unsigned decimal. {1x} unsigned hexadecimal.
{0M} is the global allocation (Storage.mod:ALLOCATE).
{1P} is the percentage of param 1 relative
to global memory.
*/
EXTERN M2Diagnostic_Diagnostic M2Diagnostic_InitMemDiagnostic (const char *name_, unsigned int _name_high, const char *format_, unsigned int _format_high);
/*
MemIncr - allow the appropriate parameter to be incremented.
All parameters are initially set to zero and are stored
as LONGCARD.
*/
EXTERN void M2Diagnostic_MemIncr (M2Diagnostic_Diagnostic MemDiag, unsigned int paramno, unsigned int incr);
/*
MemDecr - allow the appropriate parameter to be decremented.
All parameters are initially set to zero and are stored
as LONGCARD.
*/
EXTERN void M2Diagnostic_MemDecr (M2Diagnostic_Diagnostic MemDiag, unsigned int paramno, unsigned int decr);
/*
MemSet - allow the appropriate parameter to be set to value.
All parameters are initially set to zero.
*/
EXTERN void M2Diagnostic_MemSet (M2Diagnostic_Diagnostic MemDiag, unsigned int paramno, unsigned int value);
/*
TotalHeapIncr - increments the total heap used.
*/
EXTERN void M2Diagnostic_TotalHeapIncr (unsigned int incr);
/*
TotalHeapDecr - decrements the total heap used.
*/
EXTERN void M2Diagnostic_TotalHeapDecr (unsigned int incr);
/*
SetEnable - set the enable flag in Diag to value.
*/
EXTERN void M2Diagnostic_SetEnable (M2Diagnostic_Diagnostic Diag, bool value);
/*
Lookup - returns the Diagnostic containing name or NIL
if it does not exist.
*/
EXTERN M2Diagnostic_Diagnostic M2Diagnostic_Lookup (const char *name_, unsigned int _name_high);
/*
GetName - returns the name of Diag.
*/
EXTERN DynamicStrings_String M2Diagnostic_GetName (M2Diagnostic_Diagnostic Diag);
/*
ForeachDiagDo - for diag in global diag list do
dp (diag);
end
*/
EXTERN void M2Diagnostic_ForeachDiagDo (M2Diagnostic_DiagProc dp);
/*
SetDefaultConfig - force the Diag enable flag to the
time or mem global default.
*/
EXTERN void M2Diagnostic_SetDefaultConfig (M2Diagnostic_Diagnostic Diag);
/*
Configure - will turn on or off all the memory or time
instrumentation diagnostics and set the defaults
time and mem values.
*/
EXTERN void M2Diagnostic_Configure (bool time_, bool mem);
/*
Generate - return a string containing the output from
all the diagnostics enabled.
*/
EXTERN DynamicStrings_String M2Diagnostic_Generate (void);
# ifdef __cplusplus
}
# endif
# undef EXTERN
#endif
File diff suppressed because it is too large Load Diff
+186
View File
@@ -0,0 +1,186 @@
/* do not edit automatically generated by mc from M2Diagnostic. */
/* M2Diagnotic provides memory and time diagnosics to the user.
Copyright (C) 2024 Free Software Foundation, Inc.
Contributed by Gaius Mulley <gaiusmod2@gmail.com>.
This file is part of GNU Modula-2.
GNU Modula-2 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Modula-2 is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Modula-2; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#if !defined (_M2Diagnostic_H)
# define _M2Diagnostic_H
#include "config.h"
#include "system.h"
# ifdef __cplusplus
extern "C" {
# endif
#include <stdbool.h>
# if !defined (PROC_D)
# define PROC_D
typedef void (*PROC_t) (void);
typedef struct { PROC_t proc; } PROC;
# endif
# include "GDynamicStrings.h"
# if defined (_M2Diagnostic_C)
# define EXTERN
# else
# define EXTERN extern
# endif
#if !defined (M2Diagnostic_Diagnostic_D)
# define M2Diagnostic_Diagnostic_D
typedef void *M2Diagnostic_Diagnostic;
#endif
typedef struct M2Diagnostic_DiagProc_p M2Diagnostic_DiagProc;
typedef void (*M2Diagnostic_DiagProc_t) (M2Diagnostic_Diagnostic);
struct M2Diagnostic_DiagProc_p { M2Diagnostic_DiagProc_t proc; };
/*
InitTimeDiagnostic - create and return a time diagnostic.
The format string can be free form and may
contain {1T}, {1C} or {1P}.
{1T} will contain the time and
{1C} the count of the number of times the
code enters the time diagnostic code region.
{1P} generates the time as a percentage.
{0T} is the total time for the application.
{{ is rendered as a single {.
*/
EXTERN M2Diagnostic_Diagnostic M2Diagnostic_InitTimeDiagnostic (const char *name_, unsigned int _name_high, const char *format_, unsigned int _format_high);
/*
EnterDiagnostic - attribute all execution time from now to TimeDiag.
*/
EXTERN void M2Diagnostic_EnterDiagnostic (M2Diagnostic_Diagnostic TimeDiag);
/*
ExitDiagnostic - stop attributing execution time to TimeDiag.
*/
EXTERN void M2Diagnostic_ExitDiagnostic (M2Diagnostic_Diagnostic TimeDiag);
/*
InitMemDiagnostic - create and return a memory diagnostic.
The format string can be free form and may
contain {1M} {1d} {1x} {1P}.
{1M} is replaced by the value of the first parameter
with memory size units.
{1d} unsigned decimal. {1x} unsigned hexadecimal.
{0M} is the global allocation (Storage.mod:ALLOCATE).
{1P} is the percentage of param 1 relative
to global memory.
*/
EXTERN M2Diagnostic_Diagnostic M2Diagnostic_InitMemDiagnostic (const char *name_, unsigned int _name_high, const char *format_, unsigned int _format_high);
/*
MemIncr - allow the appropriate parameter to be incremented.
All parameters are initially set to zero and are stored
as LONGCARD.
*/
EXTERN void M2Diagnostic_MemIncr (M2Diagnostic_Diagnostic MemDiag, unsigned int paramno, unsigned int incr);
/*
MemDecr - allow the appropriate parameter to be decremented.
All parameters are initially set to zero and are stored
as LONGCARD.
*/
EXTERN void M2Diagnostic_MemDecr (M2Diagnostic_Diagnostic MemDiag, unsigned int paramno, unsigned int decr);
/*
MemSet - allow the appropriate parameter to be set to value.
All parameters are initially set to zero.
*/
EXTERN void M2Diagnostic_MemSet (M2Diagnostic_Diagnostic MemDiag, unsigned int paramno, unsigned int value);
/*
TotalHeapIncr - increments the total heap used.
*/
EXTERN void M2Diagnostic_TotalHeapIncr (unsigned int incr);
/*
TotalHeapDecr - decrements the total heap used.
*/
EXTERN void M2Diagnostic_TotalHeapDecr (unsigned int incr);
/*
SetEnable - set the enable flag in Diag to value.
*/
EXTERN void M2Diagnostic_SetEnable (M2Diagnostic_Diagnostic Diag, bool value);
/*
Lookup - returns the Diagnostic containing name or NIL
if it does not exist.
*/
EXTERN M2Diagnostic_Diagnostic M2Diagnostic_Lookup (const char *name_, unsigned int _name_high);
/*
GetName - returns the name of Diag.
*/
EXTERN DynamicStrings_String M2Diagnostic_GetName (M2Diagnostic_Diagnostic Diag);
/*
ForeachDiagDo - for diag in global diag list do
dp (diag);
end
*/
EXTERN void M2Diagnostic_ForeachDiagDo (M2Diagnostic_DiagProc dp);
/*
SetDefaultConfig - force the Diag enable flag to the
time or mem global default.
*/
EXTERN void M2Diagnostic_SetDefaultConfig (M2Diagnostic_Diagnostic Diag);
/*
Configure - will turn on or off all the memory or time
instrumentation diagnostics and set the defaults
time and mem values.
*/
EXTERN void M2Diagnostic_Configure (bool time_, bool mem);
/*
Generate - return a string containing the output from
all the diagnostics enabled.
*/
EXTERN DynamicStrings_String M2Diagnostic_Generate (void);
# ifdef __cplusplus
}
# endif
# undef EXTERN
#endif
+83
View File
@@ -0,0 +1,83 @@
/* do not edit automatically generated by mc from Selective. */
/* Selective.def provides Modula-2 with access to the select(2) primitive.
Copyright (C) 2001-2024 Free Software Foundation, Inc.
Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
This file is part of GNU Modula-2.
GNU Modula-2 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Modula-2 is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#if !defined (_Selective_H)
# define _Selective_H
#include "config.h"
#include "system.h"
# ifdef __cplusplus
extern "C" {
# endif
#include <stdbool.h>
# if !defined (PROC_D)
# define PROC_D
typedef void (*PROC_t) (void);
typedef struct { PROC_t proc; } PROC;
# endif
# include "GSYSTEM.h"
# if defined (_Selective_C)
# define EXTERN
# else
# define EXTERN extern
# endif
typedef void *Selective_SetOfFd;
typedef void *Selective_Timeval;
EXTERN int Selective_Select (unsigned int nooffds, Selective_SetOfFd readfds, Selective_SetOfFd writefds, Selective_SetOfFd exceptfds, Selective_Timeval timeout);
EXTERN Selective_Timeval Selective_InitTime (unsigned int sec, unsigned int usec);
EXTERN Selective_Timeval Selective_KillTime (Selective_Timeval t);
EXTERN void Selective_GetTime (Selective_Timeval t, unsigned int *sec, unsigned int *usec);
EXTERN void Selective_SetTime (Selective_Timeval t, unsigned int sec, unsigned int usec);
EXTERN Selective_SetOfFd Selective_InitSet (void);
EXTERN Selective_SetOfFd Selective_KillSet (Selective_SetOfFd s);
EXTERN void Selective_FdZero (Selective_SetOfFd s);
EXTERN void Selective_FdSet (int fd, Selective_SetOfFd s);
EXTERN void Selective_FdClr (int fd, Selective_SetOfFd s);
EXTERN bool Selective_FdIsSet (int fd, Selective_SetOfFd s);
EXTERN int Selective_MaxFdsPlusOne (int a, int b);
EXTERN void Selective_WriteCharRaw (int fd, char ch);
EXTERN char Selective_ReadCharRaw (int fd);
/*
GetTimeOfDay - fills in a record, Timeval, filled in with the
current system time in seconds and microseconds.
It returns zero (see man 3p gettimeofday)
*/
EXTERN int Selective_GetTimeOfDay (Selective_Timeval tv);
# ifdef __cplusplus
}
# endif
# undef EXTERN
#endif
File diff suppressed because it is too large Load Diff
+8
View File
@@ -6,6 +6,8 @@ extern "C" void _M2_M2RTS_init (int argc, char *argv[], char *envp[]);
extern "C" void _M2_M2RTS_fini (int argc, char *argv[], char *envp[]);
extern "C" void _M2_SysExceptions_init (int argc, char *argv[], char *envp[]);
extern "C" void _M2_SysExceptions_fini (int argc, char *argv[], char *envp[]);
extern "C" void _M2_M2Diagnostic_init (int argc, char *argv[], char *envp[]);
extern "C" void _M2_M2Diagnostic_fini (int argc, char *argv[], char *envp[]);
extern "C" void _M2_StrLib_init (int argc, char *argv[], char *envp[]);
extern "C" void _M2_StrLib_fini (int argc, char *argv[], char *envp[]);
extern "C" void _M2_errno_init (int argc, char *argv[], char *envp[]);
@@ -46,6 +48,8 @@ extern "C" void _M2_SFIO_init (int argc, char *argv[], char *envp[]);
extern "C" void _M2_SFIO_fini (int argc, char *argv[], char *envp[]);
extern "C" void _M2_StrCase_init (int argc, char *argv[], char *envp[]);
extern "C" void _M2_StrCase_fini (int argc, char *argv[], char *envp[]);
extern "C" void _M2_StringConvert_init (int argc, char *argv[], char *envp[]);
extern "C" void _M2_StringConvert_fini (int argc, char *argv[], char *envp[]);
extern "C" void _M2_bnflex_init (int argc, char *argv[], char *envp[]);
extern "C" void _M2_bnflex_fini (int argc, char *argv[], char *envp[]);
extern "C" void _M2_Lists_init (int argc, char *argv[], char *envp[]);
@@ -65,6 +69,7 @@ int main(int argc, char *argv[], char *envp[])
_M2_M2EXCEPTION_init (argc, argv, envp);
_M2_M2RTS_init (argc, argv, envp);
_M2_SysExceptions_init (argc, argv, envp);
_M2_M2Diagnostic_init (argc, argv, envp);
_M2_StrLib_init (argc, argv, envp);
_M2_errno_init (argc, argv, envp);
_M2_termios_init (argc, argv, envp);
@@ -85,6 +90,7 @@ int main(int argc, char *argv[], char *envp[])
_M2_FIO_init (argc, argv, envp);
_M2_SFIO_init (argc, argv, envp);
_M2_StrCase_init (argc, argv, envp);
_M2_StringConvert_init (argc, argv, envp);
_M2_bnflex_init (argc, argv, envp);
_M2_Lists_init (argc, argv, envp);
_M2_Args_init (argc, argv, envp);
@@ -95,6 +101,7 @@ int main(int argc, char *argv[], char *envp[])
_M2_Args_fini (argc, argv, envp);
_M2_Lists_fini (argc, argv, envp);
_M2_bnflex_fini (argc, argv, envp);
_M2_StringConvert_fini (argc, argv, envp);
_M2_StrCase_fini (argc, argv, envp);
_M2_SFIO_fini (argc, argv, envp);
_M2_FIO_fini (argc, argv, envp);
@@ -115,6 +122,7 @@ int main(int argc, char *argv[], char *envp[])
_M2_termios_fini (argc, argv, envp);
_M2_errno_fini (argc, argv, envp);
_M2_StrLib_fini (argc, argv, envp);
_M2_M2Diagnostic_fini (argc, argv, envp);
_M2_SysExceptions_fini (argc, argv, envp);
_M2_M2RTS_fini (argc, argv, envp);
_M2_M2EXCEPTION_fini (argc, argv, envp);
+15 -1
View File
@@ -23,7 +23,7 @@
Usage () {
echo "Usage: makesystem dialectflag SYSTEM.def SYSTEM.mod { librarypath } compiler"
echo "Usage: makesystem [-gdb] dialectflag SYSTEM.def SYSTEM.mod { librarypath } compiler"
}
if [ $# -lt 6 ] ; then
@@ -31,6 +31,12 @@ if [ $# -lt 6 ] ; then
exit 1
fi
if [ "$1" = "-gdb" ] ; then
DEBUG=$1
shift
else
DEBUG=""
fi
DIALECT=$1
SYSTEMDEF=$2
SYSTEMMOD=$3
@@ -101,6 +107,14 @@ displayEnd () {
MINIMAL="-fno-scaffold-main -fno-scaffold-dynamic -fno-scaffold-static -fno-m2-plugin"
rm -f ${OUTPUTFILE}
if [ "$DEBUG" != "" ] ; then
echo "entering gdb to debug cc1gm2 when using -fdump-system-exports"
${COMPILER} ${DIALECT} ${LIBRARY} ${MINIMAL} \
-c -fdump-system-exports ${SYSTEMMOD} -wrapper gdb,--args
exit $?
fi
${COMPILER} ${DIALECT} ${LIBRARY} ${MINIMAL} \
-S -fdump-system-exports ${SYSTEMMOD} -o /dev/null 2>&1 > /dev/null
res=$?
+5 -2
View File
@@ -19,11 +19,14 @@ MODULE testbit2 ;
FROM StrIO IMPORT WriteString, WriteLn ;
TYPE
index = CARDINAL ;
VAR
c : CARDINAL ;
c : index ;
a, b: BITSET ;
BEGIN
IF b IN b
IF c IN c
THEN
WriteString('hmm') ; WriteLn
END
@@ -0,0 +1,23 @@
MODULE assigncons ;
TYPE
rec = RECORD
x, y: CARDINAL ;
END ;
CONST
z = rec {1, 2} ;
PROCEDURE Init ;
VAR
r: rec ;
BEGIN
r := z
END Init ;
BEGIN
Init
END assigncons.
@@ -0,0 +1,42 @@
(* Copyright (C) 2008 Free Software Foundation, Inc. *)
(* This file is part of GNU Modula-2.
GNU Modula-2 is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with gm2; see the file COPYING. If not, write to the Free Software
Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
MODULE constructor3 ;
FROM libc IMPORT exit ;
VAR
f: position ;
TYPE
position = RECORD
x1, y1, x2, y2: CARDINAL ;
END ;
CONST
first = position{1,2,3,4} ;
BEGIN
f := first ;
IF (f.x1=1) AND (f.y1=2) AND (f.x2=3) AND (f.y2=4)
THEN
(* all ok *)
ELSE
exit(1)
END
END constructor3.
@@ -0,0 +1,10 @@
MODULE proc_test;
PROCEDURE Calc () : CARDINAL;
BEGIN
RETURN 2;
END Calc;
BEGIN
END proc_test.
+117 -6
View File
@@ -18,7 +18,39 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
MODULE shift4 ;
FROM libc IMPORT exit, printf ;
FROM SYSTEM IMPORT SHIFT, BITSPERLOC ;
FROM SYSTEM IMPORT SHIFT, BITSPERLOC, TBITSIZE, BYTE ;
CONST
EarlyFail = TRUE ;
Verbose = FALSE ;
(*
assert -
*)
PROCEDURE assert (condition: BOOLEAN) ;
BEGIN
IF NOT condition
THEN
printf ("assert failed\n");
exit (1)
END
END assert ;
(*
SanityCheck -
*)
PROCEDURE SanityCheck ;
BEGIN
assert (MIN (large) = 0) ;
assert (MAX (large) = 1023) ;
assert (TBITSIZE (BYTE) = 8) ;
END SanityCheck ;
TYPE
large = SET OF [0..1023] ;
@@ -27,37 +59,107 @@ VAR
i : INTEGER ;
b, c: large ;
BEGIN
SanityCheck ;
r := 0 ;
b := large{1, 2, 3, 1022} ;
b := SHIFT(b, 1) ;
IF b # large{1, 2, 3, 1022}
THEN
printf ("failed to assign a large set with a constant set\n");
exit (1)
END ;
b := SHIFT(b, 1) ; (* Shift left by 1 bit. *)
IF b#large{2, 3, 4, 1023}
THEN
printf ("failed (exit 1) as b#large{2, 3, 4, 1023}\n");
exit(1)
END ;
b := large{1, 2, 3, 1023} ;
b := SHIFT(b, -1) ;
b := SHIFT(b, -1) ; (* Shift right by 1 bit. *)
IF b#large{0, 1, 2, 1022}
THEN
printf ("failed (exit 2) as b#large{1, 2, 3, 1022}\n");
exit(2)
END ;
b := large{1+SIZE(BITSET)*BITSPERLOC} ;
b := SHIFT(b, -1) ;
IF b#large{SIZE(BITSET)*BITSPERLOC}
THEN
printf ("failed (exit 3)\n");
exit(3)
END ;
b := SHIFT(b, -1) ;
IF b#large{SIZE(BITSET)*BITSPERLOC-1}
THEN
printf ("failed (exit 4)\n");
exit(4)
END ;
printf ("test left shift on byte boundaries\n");
FOR i := 0 TO MAX(large) BY 8 DO
b := large{0} ;
b := SHIFT(b, i) ;
c := large{i} ;
IF b # c
THEN
printf("failed shift left in loop on iteration %d, failed to shift bit 0 left by %i bits\n", i, i) ;
IF EarlyFail
THEN
exit (5)
END ;
r := 5
END
END ;
IF r = 0
THEN
printf ("test left shift on byte boundaries passed\n")
ELSE
printf ("test left shift on byte boundaries failed\n")
END ;
printf ("test right shift on byte boundaries\n");
FOR i := 0 TO MAX(large) BY 8 DO
b := large{i} ;
b := SHIFT(b, -i) ;
c := large{0} ;
IF b = c
THEN
IF Verbose
THEN
printf ("success shifted large set right by %d bits\n", i)
END
ELSE
printf("failed shift right in loop on iteration %d\n", i) ;
IF EarlyFail
THEN
exit (6)
END ;
r := 6
END
END ;
IF r = 0
THEN
printf ("test right shift on byte boundaries passed\n")
ELSE
printf ("test right shift on byte boundaries failed\n")
END ;
printf ("test shift on each bit\n");
FOR i := 0 TO MAX(large) DO
b := large{0} ;
b := SHIFT(b, i) ;
c := large{i} ;
IF b#c
IF b = c
THEN
printf("failed shift left in loop on iteration %d\n", i) ;
IF Verbose
THEN
printf ("success shifted large set left by %d bits\n", i)
END
ELSE
printf("failed shift left in loop on iteration %d, failed to shift bit 0 left by %i bits\n", i, i) ;
IF EarlyFail
THEN
exit (5)
END ;
r := 5
END
END ;
@@ -65,9 +167,18 @@ BEGIN
b := large{i} ;
b := SHIFT(b, -i) ;
c := large{0} ;
IF b#c
IF b = c
THEN
IF Verbose
THEN
printf ("success shifted large set right by %d bits\n", i)
END
ELSE
printf("failed shift right in loop on iteration %d\n", i) ;
IF EarlyFail
THEN
exit (6)
END ;
r := 6
END
END ;
@@ -0,0 +1,99 @@
(* Copyright (C) 2014 Free Software Foundation, Inc. *)
(* This file is part of GNU Modula-2.
GNU Modula-2 is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with gm2; see the file COPYING. If not, write to the Free Software
Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
MODULE simplelarge2 ;
FROM STextIO IMPORT WriteString, WriteLn, WriteChar, ReadToken, SkipLine ;
FROM SWholeIO IMPORT WriteCard, WriteInt ;
FROM WholeStr IMPORT StrToCard, ConvResults ;
FROM SYSTEM IMPORT CARDINAL8 ;
FROM libc IMPORT printf ;
CONST
BoardX = 16 ;
BoardY = 16 ;
BoardSize = BoardX * BoardY ;
TYPE
Squares = [0..BoardSize-1] ;
SoS = SET OF Squares ;
Colour = (Blue, Red, Green, White) ;
VAR
homeBase: ARRAY [MIN(Colour)..MAX(Colour)] OF SoS ;
PROCEDURE dumpSet (c: Colour) ;
VAR
n: CARDINAL ;
BEGIN
printf ("inside dumpSet (%d)\n", ORD(c)) ;
printf (" : 0 2 4 6 8 a c e \n") ;
FOR n := MIN(Squares) TO MAX(Squares) DO
IF n MOD 16 = 0
THEN
printf ("\nrow %2d: ", n DIV 16)
END ;
IF n IN homeBase[c]
THEN
printf ("1")
ELSE
printf ("0")
END
END ;
printf ("\n")
END dumpSet ;
(*
assert -
*)
PROCEDURE assert (b: BOOLEAN) ;
BEGIN
IF NOT b
THEN
WriteString('assert failed') ; WriteLn ;
HALT
END
END assert ;
BEGIN
homeBase[Blue] := SoS {0, 1, 2, 3,
16, 17, 18, 19,
32, 33, 34,
48, 49} ;
dumpSet(Blue) ;
assert (0 IN homeBase[Blue]) ;
assert (1 IN homeBase[Blue]) ;
assert (2 IN homeBase[Blue]) ;
assert (3 IN homeBase[Blue]) ;
homeBase[Blue] := homeBase[Blue] + SoS {4, 20, 35, 50, 65, 64} ;
dumpSet(Blue) ;
assert (0 IN homeBase[Blue]) ;
assert (1 IN homeBase[Blue]) ;
assert (2 IN homeBase[Blue]) ;
assert (3 IN homeBase[Blue]) ;
assert (4 IN homeBase[Blue]) ;
assert (NOT (5 IN homeBase[Blue])) ;
assert (NOT (6 IN homeBase[Blue])) ;
END simplelarge2.
@@ -0,0 +1,88 @@
(* Copyright (C) 2014 Free Software Foundation, Inc. *)
(* This file is part of GNU Modula-2.
GNU Modula-2 is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with gm2; see the file COPYING. If not, write to the Free Software
Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
MODULE simplelarge3 ;
FROM STextIO IMPORT WriteString, WriteLn, WriteChar, ReadToken, SkipLine ;
FROM SWholeIO IMPORT WriteCard, WriteInt ;
FROM WholeStr IMPORT StrToCard, ConvResults ;
FROM SYSTEM IMPORT CARDINAL8 ;
FROM libc IMPORT printf ;
CONST
BoardX = 16 ;
BoardY = 16 ;
BoardSize = BoardX * BoardY ;
TYPE
Squares = [0..BoardSize-1] ;
SoS = SET OF Squares ;
Colour = (Blue, Red, Green, White) ;
VAR
homeBase: ARRAY [MIN(Colour)..MAX(Colour)] OF SoS ;
PROCEDURE dumpSet (c: Colour) ;
VAR
n: CARDINAL ;
BEGIN
printf ("inside dumpSet (%d)\n", ORD(c)) ;
printf (" : 0 2 4 6 8 a c e \n") ;
FOR n := MIN(Squares) TO MAX(Squares) DO
IF n MOD 16 = 0
THEN
printf ("\nrow %2d: ", n DIV 16)
END ;
IF n IN homeBase[c]
THEN
printf ("1")
ELSE
printf ("0")
END
END ;
printf ("\n")
END dumpSet ;
(*
assert -
*)
PROCEDURE assert (b: BOOLEAN) ;
BEGIN
IF NOT b
THEN
WriteString('assert failed') ; WriteLn ;
HALT
END
END assert ;
BEGIN
homeBase[Blue] := SoS {0, 1, 2, 3,
16, 17, 18, 19,
32, 33, 34,
48, 49} ;
dumpSet(Blue) ;
homeBase[Blue] := homeBase[Blue] + SoS {4, 20, 35, 50, 65, 64} ;
dumpSet(Blue) ;
assert (0 IN homeBase[Blue])
END simplelarge3.
@@ -0,0 +1,88 @@
(* Copyright (C) 2014 Free Software Foundation, Inc. *)
(* This file is part of GNU Modula-2.
GNU Modula-2 is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with gm2; see the file COPYING. If not, write to the Free Software
Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
MODULE simplelarge4 ;
FROM STextIO IMPORT WriteString, WriteLn, WriteChar, ReadToken, SkipLine ;
FROM SWholeIO IMPORT WriteCard, WriteInt ;
FROM WholeStr IMPORT StrToCard, ConvResults ;
FROM SYSTEM IMPORT CARDINAL8 ;
FROM libc IMPORT printf ;
CONST
BoardX = 16 ;
BoardY = 16 ;
BoardSize = BoardX * BoardY ;
TYPE
Squares = [0..BoardSize-1] ;
SoS = SET OF Squares ;
Colour = (Blue, Red, Green, White) ;
VAR
homeBase: SoS ;
PROCEDURE dumpSet (c: Colour) ;
VAR
n: CARDINAL ;
BEGIN
printf ("inside dumpSet (%d)\n", ORD(c)) ;
printf (" : 0 2 4 6 8 a c e \n") ;
FOR n := MIN(Squares) TO MAX(Squares) DO
IF n MOD 16 = 0
THEN
printf ("\nrow %2d: ", n DIV 16)
END ;
IF n IN homeBase
THEN
printf ("1")
ELSE
printf ("0")
END
END ;
printf ("\n")
END dumpSet ;
(*
assert -
*)
PROCEDURE assert (b: BOOLEAN) ;
BEGIN
IF NOT b
THEN
WriteString('assert failed') ; WriteLn ;
HALT
END
END assert ;
BEGIN
homeBase := SoS {0, 1, 2, 3,
16, 17, 18, 19,
32, 33, 34,
48, 49} ;
dumpSet(Blue) ;
homeBase := homeBase + SoS {4, 20, 35, 50, 65, 64} ;
dumpSet(Blue) ;
assert (0 IN homeBase)
END simplelarge4.
@@ -29,7 +29,7 @@ FROM FIO IMPORT Close, StdOut ;
PROCEDURE FindFirstElement (start: CARDINAL; s: LargeSet) : CARDINAL ;
BEGIN
WHILE NOT (start IN s) DO
WHILE (start < 1024) AND (NOT (start IN s)) DO
INC(start)
END ;
RETURN( start )
@@ -0,0 +1,46 @@
MODULE bitset ;
FROM libc IMPORT printf, exit ;
FROM M2WIDESET IMPORT Equal, Clear ;
TYPE
set = BITSET ;
CONST
HighBit = MAX (set) ;
(*
Assert -
*)
PROCEDURE Assert (bool: BOOLEAN; line: CARDINAL) ;
BEGIN
IF NOT bool
THEN
printf ("%s:%d:assert failed\n", __FILE__, line);
exit (1)
END
END Assert ;
(*
init -
*)
PROCEDURE init ;
VAR
left, right: set ;
BEGIN
left := set {} ;
right := set {1} ;
Assert (NOT Equal (left, right, HighBit), __LINE__) ;
Clear (right, HighBit) ;
Assert (Equal (left, right, HighBit), __LINE__) ;
printf ("All tests pass in %s\n", __FILE__)
END init ;
BEGIN
init
END bitset.
@@ -0,0 +1,43 @@
MODULE bitset ;
FROM libc IMPORT printf, exit ;
FROM M2WIDESET IMPORT Equal, Clear ;
CONST
HighBit = MAX (BITSET) ;
(*
Assert -
*)
PROCEDURE Assert (bool: BOOLEAN; line: CARDINAL) ;
BEGIN
IF NOT bool
THEN
printf ("%s:%d:assert failed\n", __FILE__, line);
exit (1)
END
END Assert ;
(*
init -
*)
PROCEDURE init ;
VAR
left, right: BITSET ;
BEGIN
left := BITSET {} ;
right := BITSET {1} ;
Assert (NOT Equal (left, right, HighBit), __LINE__) ;
Clear (right, HighBit) ;
Assert (Equal (left, right, HighBit), __LINE__) ;
printf ("All tests pass in %s\n", __FILE__)
END init ;
BEGIN
init
END bitset.
@@ -0,0 +1,47 @@
MODULE colorset ;
FROM libc IMPORT printf, exit ;
FROM M2WIDESET IMPORT Equal, Clear ;
TYPE
color = SET OF (red, green, blue) ;
set = color ;
CONST
HighBit = MAX (set) ;
(*
Assert -
*)
PROCEDURE Assert (bool: BOOLEAN; line: CARDINAL) ;
BEGIN
IF NOT bool
THEN
printf ("%s:%d:assert failed\n", __FILE__, line);
exit (1)
END
END Assert ;
(*
init -
*)
PROCEDURE init ;
VAR
left, right: set ;
BEGIN
left := set {} ;
right := set {green} ;
Assert (NOT Equal (left, right, HighBit), __LINE__) ;
Clear (right, HighBit) ;
Assert (Equal (left, right, HighBit), __LINE__) ;
printf ("All tests pass in %s\n", __FILE__)
END init ;
BEGIN
init
END colorset.
@@ -0,0 +1,72 @@
MODULE colorset2 ;
FROM libc IMPORT printf, exit ;
FROM M2WIDESET IMPORT Equal, Clear, Shift, Rotate ;
TYPE
color = SET OF (red, green, blue) ;
set = color ;
CONST
HighBit = MAX (set) ;
(*
Assert -
*)
PROCEDURE Assert (bool: BOOLEAN; line: CARDINAL) ;
BEGIN
IF NOT bool
THEN
printf ("%s:%d:assert failed\n", __FILE__, line);
exit (1)
END
END Assert ;
(*
init -
*)
PROCEDURE init ;
VAR
left, right: set ;
BEGIN
left := set {} ;
right := set {green} ;
Assert (NOT Equal (left, right, HighBit), __LINE__) ;
Clear (right, HighBit) ;
Assert (Equal (left, right, HighBit), __LINE__) ;
left := set {red} ;
right := set {green} ;
Assert (NOT Equal (left, right, HighBit), __LINE__) ;
Shift (right, right, MAX (set), -1) ;
Assert (Equal (left, right, HighBit), __LINE__) ;
left := set {red} ;
right := set {green} ;
Shift (left, left, MAX (set), 1) ;
Assert (Equal (left, right, HighBit), __LINE__) ;
left := set {red} ;
right := set {green} ;
Rotate (left, left, MAX (set), 1) ;
Assert (Equal (left, right, HighBit), __LINE__) ;
left := set {green} ;
right := set {red} ;
Rotate (left, left, MAX (set), -1) ;
Assert (Equal (left, right, HighBit), __LINE__) ;
left := set {red} ;
right := set {blue} ;
Rotate (left, left, MAX (set), -1) ;
Assert (Equal (left, right, HighBit), __LINE__) ;
printf ("All tests pass in %s\n", __FILE__)
END init ;
BEGIN
init
END colorset2.
@@ -0,0 +1,46 @@
MODULE colorset3 ;
FROM libc IMPORT printf, exit ;
FROM M2WIDESET IMPORT Equal, Clear, Shift, Rotate ;
TYPE
color = SET OF (red, green, blue) ;
set = color ;
CONST
HighBit = MAX (set) ;
(*
Assert -
*)
PROCEDURE Assert (bool: BOOLEAN; line: CARDINAL) ;
BEGIN
IF NOT bool
THEN
printf ("%s:%d:assert failed\n", __FILE__, line);
exit (1)
END
END Assert ;
(*
init -
*)
PROCEDURE init ;
VAR
left, right: set ;
BEGIN
left := set {green} ;
right := set {red} ;
Rotate (left, left, MAX (set), -1) ;
Assert (Equal (left, right, HighBit), __LINE__) ;
printf ("All tests pass in %s\n", __FILE__)
END init ;
BEGIN
init
END colorset3.
@@ -0,0 +1,13 @@
MODULE highbit ;
FROM libc IMPORT printf ;
TYPE
set = BITSET ;
CONST
HighBit = MAX (set) ;
BEGIN
printf ("the MAX (set) = %d\n", HighBit)
END highbit.
@@ -0,0 +1,13 @@
MODULE highbit2 ;
FROM libc IMPORT printf ;
TYPE
set = BITSET ;
CONST
HighBit = MAX (BITSET) ;
BEGIN
printf ("the MAX (BITSET) = %d\n", HighBit)
END highbit2.
@@ -18,7 +18,7 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
MODULE multisetrotate4 ;
FROM libc IMPORT printf, exit ;
FROM SYSTEM IMPORT ROTATE, WORD, BITSPERLOC ;
FROM SYSTEM IMPORT ROTATE, WORD, BITSPERLOC, TBITSIZE ;
TYPE
multi = SET OF [0..SIZE (WORD) * 2 * BITSPERLOC-1] ;
@@ -29,12 +29,21 @@ VAR
BEGIN
set := multi {1} ;
bits := SIZE (multi) * BITSPERLOC ;
IF bits # TBITSIZE (set)
THEN
printf ("test code is invalid, set must match TBITSIZE\n");
exit (3)
END ;
IF ROTATE (set, bits-1) # multi {0}
THEN
printf ("rotate %d on a set type of %d bits failed\n",
bits-1, bits) ;
exit (1)
END ;
IF ROTATE (set, -(bits - 1)) # multi {2}
THEN
printf ("rotate %d on a set type of %d bits failed\n",
- (bits-1), bits) ;
exit (2)
END ;
exit (0)
@@ -0,0 +1,70 @@
(* Copyright (C) 2025 Free Software Foundation, Inc. *)
(* This file is part of GNU Modula-2.
GNU Modula-2 is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with gm2; see the file COPYING. If not, write to the Free Software
Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
MODULE multisetrotate5 ;
FROM libc IMPORT printf, exit ;
FROM SYSTEM IMPORT ROTATE, WORD, BITSPERLOC ;
TYPE
multi = SET OF [0..SIZE (WORD) * 2 * BITSPERLOC-1] ;
(*
dump -
*)
PROCEDURE dump (s: multi) ;
VAR
bits, i: CARDINAL ;
BEGIN
bits := SIZE (multi) * BITSPERLOC -1;
FOR i := 0 TO bits DO
printf (" %2d", i)
END ;
printf ("\n") ;
FOR i := 0 TO bits DO
IF i IN s
THEN
printf (" X")
ELSE
printf (" ")
END
END ;
printf ("\n")
END dump ;
VAR
set : multi ;
bits: INTEGER ;
BEGIN
dump (multi {1}) ;
dump (multi {2}) ;
set := multi {2} ;
dump (set) ;
set := multi {1} ;
dump (set) ;
IF ROTATE (set, 1) = multi {2}
THEN
exit (0)
END ;
set := multi {2} ;
set := ROTATE (set, 1) ;
dump (set) ;
exit (1)
END multisetrotate5.
@@ -0,0 +1,18 @@
MODULE setcard ;
FROM libc IMPORT exit ;
TYPE
large = SET OF CARDINAL ;
VAR
set: large ;
BEGIN
set := large {} ;
INCL (set, 2) ;
IF 2 IN set
THEN
exit (0)
ELSE
exit (1)
END
END setcard.
@@ -0,0 +1,51 @@
(* Copyright (C) 2024 Free Software Foundation, Inc. *)
(* This file is part of GNU Modula-2.
GNU Modula-2 is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with gm2; see the file COPYING. If not, write to the Free Software
Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
MODULE setincl ;
FROM libc IMPORT printf, exit ;
FROM SYSTEM IMPORT ROTATE ;
PROCEDURE incl (VAR set: BITSET; bit: CARDINAL) ;
BEGIN
INCL (set, bit)
END incl ;
PROCEDURE excl (VAR set: BITSET; bit: CARDINAL) ;
BEGIN
EXCL (set, bit)
END excl ;
VAR
set: BITSET ;
BEGIN
set := BITSET {} ;
incl (set, 1) ;
IF set # BITSET {1}
THEN
exit (1)
END ;
excl (set, 1) ;
IF set # BITSET {}
THEN
exit (2)
END ;
exit (0)
END setincl.
@@ -57,7 +57,7 @@ BEGIN
assert (ROTATE (psettype {1}, 1) = ROTATE (psettype {1}, 1), __LINE__, "comparision between constant rotated packed sets") ;
assert (ROTATE (psettype {1}, 1) # ROTATE (psettype {2}, 1), __LINE__, "comparision between constant rotated packed sets") ;
assert (ROTATE (a, 1) = psettype {2}, __LINE__, "comparision between rotated variable and constant packed sets") ;
assert (ROTATE (a, -1) = settype {0}, __LINE__, "comparision between rotated variable and constant packed sets") ;
assert (ROTATE (a, -1) = psettype {0}, __LINE__, "comparision between rotated variable and constant packed sets") ;
END testpset ;
+1
View File
@@ -633,6 +633,7 @@ proc gm2_init_minx { dialect paths args } {
gm2_link_lib "m2min"
lappend args -fno-exceptions
lappend args -fno-libs=-
lappend args -fno-wideset
gm2_init {*}${theIpath} {*}${dialect} {*}${theLpath} {*}${args}
}
+4
View File
@@ -99,6 +99,8 @@ toolexeclib_LTLIBRARIES = libm2pim.la
M2MODS = ASCII.mod IO.mod \
Args.mod M2RTS.mod \
M2Dependent.mod \
M2Diagnostic.mod \
M2WIDESET.mod \
Assertion.mod NumberIO.mod \
Break.mod SYSTEM.mod \
CmdArgs.mod Scan.mod \
@@ -142,8 +144,10 @@ M2DEFS = Args.def ASCII.def \
LegacyReal.def libc.def \
libm.def LMathLib0.def \
M2Dependent.def \
M2Diagnostic.def \
M2EXCEPTION.def \
M2RTS.def \
M2WIDESET.def \
MathLib0.def MemUtils.def \
NumberIO.def PushBackInput.def \
RTExceptions.def RTint.def \

Some files were not shown because too many files have changed in this diff Show More