113 Commits

Author SHA1 Message Date
David Given
f07c6e4d6a Rename branch.
--HG--
branch : dtrg-videocore-branch-branch
2015-06-18 23:39:25 +02:00
David Given
171f16d7b8 Rename branch.
--HG--
branch : dtrg-videocore-branch
2015-06-18 23:38:50 +02:00
David Given
62cc636f10 Merge.
--HG--
branch : dtrg-videocore
2015-03-23 00:15:42 +01:00
David Given
e36d739fa4 Add (largely untested) float/int conversion.
--HG--
branch : dtrg-videocore
2013-07-01 13:05:36 +01:00
David Given
8b6951dac0 Fix incorrect offset encoding in lea (sp) instructions.
--HG--
branch : dtrg-videocore
2013-06-29 00:35:07 +01:00
David Given
edb174da8d Fix incorrect encoding of 'push lr' and 'pop pc'.
--HG--
branch : dtrg-videocore
2013-06-29 00:32:39 +01:00
David Given
29af6f1adb ISA change: clz has been renamed to log2.
--HG--
branch : dtrg-videocore
2013-06-27 11:25:50 +01:00
David Given
2b3f95de0b Fix jump range checking in the addcmpb family of instructions.
--HG--
branch : dtrg-videocore
2013-06-26 23:32:54 +01:00
David Given
c72eaef8ee Add routine to set the Raspberry Pi clock to 250MHz (loads faster than the default 19.2MHz).
--HG--
branch : dtrg-videocore
rename : plat/rpi/libsys/pi_user_to_phys.s => plat/rpi/libsys/pi_fast_mode.s
2013-06-24 23:57:27 +01:00
David Given
d94c1c8150 Updated distr files.
--HG--
branch : dtrg-videocore
rename : mach/i80/.distr => mach/vc4/.distr
rename : plat/cpm/.distr => plat/rpi/.distr
2013-06-21 23:38:21 +01:00
David Given
2be811bac2 Updated VC4 docs.
--HG--
branch : dtrg-videocore
2013-06-21 23:21:08 +01:00
David Given
fd2360be0f Ship assembler man pages.
--HG--
branch : dtrg-videocore
rename : man/8080_as.6 => man/i80_as.6
rename : man/m68k2_as.6 => man/m68020_as.6
2013-06-21 23:20:50 +01:00
David Given
55be35a68a Add a stub malloc.h.
--HG--
branch : dtrg-videocore
rename : lang/cem/libcc.ansi/headers/stdlib.h => lang/cem/libcc.ansi/headers/malloc.h
2013-06-20 00:15:14 +01:00
David Given
052dd9bfc0 Actually remember to set the stack pointer on startup. Reduce to stack from 16kB to a much more reasonable 1kB.
--HG--
branch : dtrg-videocore
2013-06-20 00:14:55 +01:00
David Given
eaf4339cd6 Implement a very crude busy-wait based select() mechanism for consol input.
--HG--
branch : dtrg-videocore
rename : plat/rpi/include/ack/config.h => plat/rpi/include/sys/select.h
rename : plat/rpi/libsys/time.c => plat/rpi/libsys/select.c
2013-06-09 22:16:30 +01:00
David Given
bbd4b46850 Fix stack corruption when adjusting SP. Be a bit more rigorous about clearing the pseudostack on branch/labels.
--HG--
branch : dtrg-videocore
2013-06-07 21:25:38 +01:00
David Given
ed6c4a85d1 Change the size of the SRAM area to 128kB (to reflect reality).
--HG--
branch : dtrg-videocore
2013-06-06 00:05:48 +01:00
David Given
3e0123ca03 Fix treatment of out-of-range values in switch csa.
--HG--
branch : dtrg-videocore
2013-06-05 23:57:23 +01:00
David Given
86c6fa2f1e Implement NOT...
--HG--
branch : dtrg-videocore
2013-05-30 23:50:19 +01:00
David Given
d5a112dbfd Some more termios compatibility options.
--HG--
branch : dtrg-videocore
2013-05-30 23:25:22 +01:00
David Given
2054618e75 Add basic termios to the rpi platform to allow echoing/newline translation to be controlled.
--HG--
branch : dtrg-videocore
rename : plat/rpi/include/unistd.h => plat/rpi/include/termios.h
rename : plat/rpi/libsys/write.c => plat/rpi/libsys/tcgetattr.c
rename : plat/rpi/libsys/write.c => plat/rpi/libsys/tcsetattr.c
2013-05-30 23:19:55 +01:00
David Given
074b42aa97 Add some missing libc functions: setenv, unsetenv, strdup.
--HG--
branch : dtrg-videocore
rename : lang/cem/libcc.ansi/stdlib/getenv.c => lang/cem/libcc.ansi/stdlib/setenv.c
rename : lang/cem/libcc.ansi/string/strlen.c => lang/cem/libcc.ansi/string/strdup.c
2013-05-29 21:41:58 +01:00
David Given
69953d016c Add support for snprintf and vsnprintf. Try and make the return value a bit
more standards-compliant.

--HG--
branch : dtrg-videocore
2013-05-29 17:10:58 +01:00
David Given
d3e3e72860 Update from trunk.
--HG--
branch : dtrg-videocore
2013-05-29 15:03:48 +01:00
David Given
6fff2d45fe Attempt to fix 64-bitness error in ashow. Deprecate the structure format macros in h/out.h because they make no sense on 64-bit platforms. 2013-05-29 14:48:51 +01:00
David Given
e0c121d6e6 Use relocation enumerations rather than hard-coded values for relocation types
(these were causing problems due to the enumeration values having changed).
2013-05-29 14:11:04 +01:00
David Given
1f36370d87 Implement nop (the C compiler sometimes generates this!).
--HG--
branch : dtrg-videocore
2013-05-26 22:54:53 +01:00
David Given
ae993b1eb2 Add a crude README.
--HG--
branch : dtrg-videocore
2013-05-26 19:54:22 +01:00
David Given
38e4726f5c Boot code now works properly in both kernel and bare-metal mode.
--HG--
branch : dtrg-videocore
2013-05-26 19:41:37 +01:00
David Given
ef25c53c9c Fix bug in ine/dee.
--HG--
branch : dtrg-videocore
2013-05-26 18:59:19 +01:00
David Given
e01f00e320 Allow reading from the mini UART. Add a check to not touch the UART unless it's been initialised (in case of accidents when running in kernel mode).
--HG--
branch : dtrg-videocore
2013-05-26 18:58:54 +01:00
David Given
366cd10194 Remainders are calculated correctly. printf now works.
--HG--
branch : dtrg-videocore
2013-05-26 13:13:58 +01:00
David Given
510888e6d5 .csb now works.
--HG--
branch : dtrg-videocore
rename : mach/vc4/libem/csa.s => mach/vc4/libem/csb.s
2013-05-26 13:06:25 +01:00
David Given
6284512b37 Fix erroneous section check (symbols may not have a defined section in pass 1).
--HG--
branch : dtrg-videocore
2013-05-26 00:35:15 +01:00
David Given
bd9497be77 Renamed the pi-specific functions to be a bit cleaner.
--HG--
branch : dtrg-videocore
rename : plat/rpi/libsys/phys_to_user.s => plat/rpi/libsys/pi_phys_to_user.s
rename : plat/rpi/libsys/uart.s => plat/rpi/libsys/pi_uart.s
rename : plat/rpi/libsys/user_to_phys.s => plat/rpi/libsys/pi_user_to_phys.s
2013-05-26 00:22:39 +01:00
David Given
308d41e083 Added triple-quad load and store (used by the signal stuff).
--HG--
branch : dtrg-videocore
2013-05-26 00:22:08 +01:00
David Given
e299cc3bcf stdio (output only) now works.
--HG--
branch : dtrg-videocore
2013-05-25 23:59:31 +01:00
David Given
8c21a2ef9b Stop fighting the terrible code and remove the regvar support --- it didn't help much and was a pain.
--HG--
branch : dtrg-videocore
2013-05-25 23:58:35 +01:00
David Given
6a672d5e96 Heap allocations now works.
--HG--
branch : dtrg-videocore
2013-05-25 23:28:47 +01:00
David Given
3b07fee160 Major bugfix where instructions weren't being shrunk correctly. (Turns out there's built-in support for doing this, which I hadn't found.)
--HG--
branch : dtrg-videocore
2013-05-25 23:26:10 +01:00
David Given
b6680a48cc Disable register variables. The code is a bit worse, but having two stackable registers makes things much easier to understand.
--HG--
branch : dtrg-videocore
2013-05-25 13:31:58 +01:00
David Given
d7efb0a32c Implement .csa.
--HG--
branch : dtrg-videocore
rename : mach/vc4/libem/dummy.s => mach/vc4/libem/csa.s
2013-05-25 13:31:27 +01:00
David Given
2ee79ab0b2 Encode comparing branch correctly.
--HG--
branch : dtrg-videocore
2013-05-25 13:31:01 +01:00
David Given
ec25fec145 Build binaries that will run bare metal. Add enough syscall library to init the uart and write text.
--HG--
branch : dtrg-videocore
rename : plat/rpi/libsys/libsys.h => plat/rpi/libsys/libsysasm.h
rename : plat/rpi/libsys/_sys_rawread.s => plat/rpi/libsys/phys_to_user.s
rename : plat/rpi/libsys/_sys_rawread.s => plat/rpi/libsys/uart.s
rename : plat/rpi/libsys/_sys_rawread.s => plat/rpi/libsys/user_to_phys.s
2013-05-25 00:35:29 +01:00
David Given
472f778342 Don't write out constant data as big-endian! Some other cleanups.
--HG--
branch : dtrg-videocore
2013-05-25 00:33:38 +01:00
David Given
98e745d04c Fix awful bug where uint32_t was sometimes defined as a short.
--HG--
branch : dtrg-videocore
2013-05-25 00:33:01 +01:00
David Given
98a51732ab Various codegen tweaks.
--HG--
branch : dtrg-videocore
2013-05-24 17:04:29 +01:00
David Given
2c7ee27206 Double-quads can be loaded and stored (more) correctly.
--HG--
branch : dtrg-videocore
2013-05-22 23:55:23 +01:00
David Given
6cbe6e1c4e Better treatment of sign extension.
--HG--
branch : dtrg-videocore
2013-05-22 23:12:48 +01:00
David Given
8f338f9b44 Now actually runs on real hardware.
--HG--
branch : dtrg-videocore
2013-05-22 22:46:10 +01:00
David Given
7537c85e0a Generate adds instructions when a shift-and-add is seen (useful for array indexing).
--HG--
branch : dtrg-videocore
2013-05-22 21:37:48 +01:00
David Given
b5e5df4a63 Allocate a user stack to run code in.
--HG--
branch : dtrg-videocore
2013-05-22 18:25:30 +01:00
David Given
cdce394b6c Generate ld rd, (rs) instructions properly.
--HG--
branch : dtrg-videocore
2013-05-22 11:02:46 +01:00
David Given
9e556d8b7b Optimise direct access to globals, and incrementing and decrementing locals.
--HG--
branch : dtrg-videocore
2013-05-22 10:55:13 +01:00
David Given
0068952bd1 Build the Raspberry Pi code.
--HG--
branch : dtrg-videocore
2013-05-22 09:47:22 +01:00
David Given
6b5316dcfa More typo fixes.
--HG--
branch : dtrg-videocore
2013-05-22 00:52:58 +01:00
David Given
08c4334224 Typo fixes.
--HG--
branch : dtrg-videocore
2013-05-22 00:44:04 +01:00
David Given
72542288cd Adjust bootstrap code to build kernels that work with the mailbox test app.
--HG--
branch : dtrg-videocore
2013-05-22 00:16:59 +01:00
David Given
f904465e9c Fix signedness problem that was showing up on ARM.
--HG--
branch : dtrg-videocore
2013-05-22 00:16:16 +01:00
David Given
5e9102955c Reworked VC4 relocations and some of the instruction encoding to be actually correct. Now generating what could be real code!
--HG--
branch : dtrg-videocore
2013-05-21 23:17:30 +01:00
David Given
1312fe298b Now compiles (incorrectly) the entire libc, libpc, libm2 and libbasic!
--HG--
branch : dtrg-videocore
2013-05-21 20:05:26 +01:00
David Given
92817a6ad7 Allow platforms to specify size of long double; seperate alignment from size.
--HG--
branch : dtrg-videocore
2013-05-21 19:18:11 +01:00
David Given
877e06ed89 Lots more opcodes including float support. Define float and double to be the
same thing (as the VC4 seems not to have double-precision float support).

--HG--
branch : dtrg-videocore
2013-05-21 18:16:30 +01:00
David Given
6cdea73e84 Add a lot more opcodes.
--HG--
branch : dtrg-videocore
2013-05-20 23:27:45 +01:00
David Given
d6565f4d5b Fix typo.
--HG--
branch : dtrg-videocore
2013-05-20 23:27:31 +01:00
David Given
e5341e4167 Remember to clear ackflags on reset.
--HG--
branch : dtrg-videocore
2013-05-20 22:41:27 +01:00
David Given
970f2bae62 Major revamp to simplify and use 2op instructions. Better code. Now looks like it may work one day.
--HG--
branch : dtrg-videocore
2013-05-20 22:35:12 +01:00
David Given
5082b2a5d7 Add lea instruction. Fix dependency issues.
--HG--
branch : dtrg-videocore
2013-05-20 19:56:33 +01:00
David Given
11890026db Push/pop are the right way round. Don't corrup short-form ALU instructions. Correct encoding of push/pop register ranges.
--HG--
branch : dtrg-videocore
2013-05-19 23:34:42 +01:00
David Given
76ba0bf6b3 First steps towards a code generator.
--HG--
branch : dtrg-videocore
2013-05-19 23:33:42 +01:00
David Given
61bff18082 Added skeleton bootstrap code.
--HG--
branch : dtrg-videocore
rename : plat/pc86/boot.s => plat/rpi/boot.s
2013-05-19 23:33:29 +01:00
David Given
80f85001fa Correctly emit constants in some ALU instructions.
--HG--
branch : dtrg-videocore
2013-05-19 23:19:10 +01:00
David Given
a46ee91859 Fix warning.
--HG--
branch : dtrg-videocore
2013-05-19 23:18:36 +01:00
David Given
4f15423d63 Add compare-and-branch instructions.
--HG--
branch : dtrg-videocore
2013-05-19 18:40:19 +01:00
David Given
80afe75c9b Added memory operations that work on fixed up addresses.
--HG--
branch : dtrg-videocore
2013-05-19 13:03:53 +01:00
David Given
febe8ca937 Add register offset and postincrement memory operations.
--HG--
branch : dtrg-videocore
2013-05-19 12:39:35 +01:00
David Given
fc2833d456 Add most vanilla memory load/store instructions.
--HG--
branch : dtrg-videocore
2013-05-19 00:56:56 +01:00
David Given
fc1b3672a3 Reapply bugfix to sbrk() which got dropped during the move from linx386/libsys
to liblinux. Set errno correctly.
2013-05-18 13:00:37 +01:00
David Given
c18a82ec40 Apply build system fixes for OpenBSD contributed by George Koehler. 2013-05-18 12:15:53 +01:00
David Given
26877d3c4f Add a whole bunch of VC4 opcodes.
--HG--
branch : dtrg-videocore
2013-05-17 23:30:49 +01:00
David Given
5378e3fe53 Add special relocation type for VC4 jump instructions.
--HG--
branch : dtrg-videocore
2013-05-17 22:40:50 +01:00
David Given
5b4aa07dee Merge fixes from trunk.
--HG--
branch : dtrg-videocore
2013-05-17 15:28:04 +01:00
David Given
9a513e8ef3 Fix warning. 2013-05-17 00:04:54 +01:00
David Given
e7c2029c9c Dependency fixes. 2013-05-17 00:04:37 +01:00
David Given
32ebc502c8 Skeleton of VideoCore IV support for the Raspberry Pi.
--HG--
branch : dtrg-videocore
rename : mach/powerpc/as/.distr => mach/vc4/as/.distr
rename : mach/powerpc/as/mach0.c => mach/vc4/as/mach0.c
rename : mach/powerpc/as/mach1.c => mach/vc4/as/mach1.c
rename : mach/powerpc/as/mach2.c => mach/vc4/as/mach2.c
rename : mach/powerpc/as/mach3.c => mach/vc4/as/mach3.c
rename : mach/powerpc/as/mach4.c => mach/vc4/as/mach4.c
rename : mach/powerpc/as/mach5.c => mach/vc4/as/mach5.c
rename : mach/i86/build.mk => mach/vc4/build.mk
rename : mach/powerpc/libem/powerpc.h => mach/vc4/libem/videocore.h
rename : mach/i86/libend/.distr => mach/vc4/libend/.distr
rename : mach/i86/libend/edata.s => mach/vc4/libend/edata.s
rename : mach/i86/libend/em_end.s => mach/vc4/libend/em_end.s
rename : mach/i86/libend/end.s => mach/vc4/libend/end.s
rename : mach/i86/libend/etext.s => mach/vc4/libend/etext.s
rename : mach/powerpc/ncg/.distr => mach/vc4/ncg/.distr
rename : mach/powerpc/ncg/mach.c => mach/vc4/ncg/mach.c
rename : mach/powerpc/ncg/mach.h => mach/vc4/ncg/mach.h
rename : mach/powerpc/ncg/table => mach/vc4/ncg/table
rename : plat/pc86/descr => plat/rpi/descr
2013-05-17 00:03:38 +01:00
David Given
e5f6d5acfa Fix buffer overrun looking up type information for op_lab pseudoops (as
they're not EM opcodes, we shouldn't look them up in em_flags!).
2013-05-16 22:02:59 +01:00
David Given
f70f78b6e4 Correctly generate dependency information. 2013-05-16 22:02:00 +01:00
David Given
84f81a442c Merge in build system changes. 2013-05-16 14:33:19 +01:00
David Given
24ef1627ec A few last build tweaks.
--HG--
branch : dtrg-buildsystem
2013-05-16 14:20:58 +01:00
David Given
11377070fd Update distribution files.
--HG--
branch : dtrg-buildsystem
2013-05-15 23:46:15 +01:00
David Given
8fbce949f5 Now describe the make-based build system in the README.
--HG--
branch : dtrg-buildsystem
2013-05-15 23:12:05 +01:00
David Given
aaa3f14a79 Fix build error in opt which was causing all code, everywhere, to be broken.
Remember to build opt2 too.

--HG--
branch : dtrg-buildsystem
2013-05-15 22:09:28 +01:00
David Given
e9233b4712 Build ego.
--HG--
branch : dtrg-buildsystem
rename : util/arch/build.mk => util/ego/build.mk
2013-05-15 21:14:06 +01:00
David Given
f6c43b95ef Modula-2 now works.
--HG--
branch : dtrg-buildsystem
rename : lang/pc/build.mk => lang/m2/build.mk
rename : lang/pc/libpc/build.mk => lang/m2/comp/build.mk
rename : lang/pc/libpc/build.mk => lang/m2/libm2/build.mk
2013-05-14 22:24:38 +01:00
David Given
66aebcdd91 Pascal compiler now runs.
--HG--
branch : dtrg-buildsystem
rename : lang/basic/build.mk => lang/pc/build.mk
rename : lang/cem/cemcom.ansi/build.mk => lang/pc/comp/build.mk
rename : lang/basic/lib/build.mk => lang/pc/libpc/build.mk
2013-05-14 20:47:04 +01:00
David Given
a6ebaeabd0 Basic compiler now runs.
--HG--
branch : dtrg-buildsystem
2013-05-14 18:01:38 +01:00
David Given
d5f0107746 Build the Basic run-time library (after some modernisation).
--HG--
branch : dtrg-buildsystem
2013-05-14 16:11:29 +01:00
David Given
a68b117e96 Add missing dependency.
--HG--
branch : dtrg-buildsystem
2013-05-14 14:55:29 +01:00
David Given
07453d184a Top, topgen, aelflod. Moved the libraries back into the platform-specific
directories --- wrangling descr files was too hard. C programs can be built
for cpm, pc86, linux386, linux68k!

--HG--
branch : dtrg-buildsystem
rename : util/ack/build.mk => util/led/build.mk
rename : util/LLgen/build.mk => util/topgen/build.mk
2013-05-13 23:26:15 +01:00
David Given
442306d557 Split off some of the platform-independent stuff (such as as and ncg).
--HG--
branch : dtrg-buildsystem
rename : plat/pc86/build.mk => mach/i386/build.mk
rename : plat/pc86/build.mk => mach/i80/build.mk
rename : plat/pc86/build.mk => mach/i86/build.mk
rename : plat/pc86/build.mk => mach/m68020/build.mk
rename : plat/pc86/build.mk => mach/powerpc/build.mk
2013-05-13 22:12:46 +01:00
David Given
81778b603f Merge updates from trunk.
--HG--
branch : dtrg-buildsystem
2013-05-13 12:37:27 +01:00
David Given
af0dedeb6e Fix typo.
--HG--
branch : dtrg-buildsystem
2013-05-13 11:14:10 +01:00
David Given
b0c238eb5d Made a start on building the runtimes for each platform and language; the
Linuxes all build.

--HG--
branch : dtrg-buildsystem
rename : modules/src/em_mes/build.mk => modules/src/read_em/build.mk
rename : plat/pc86/build.mk => plat/linux386/build.mk
rename : plat/pc86/build.mk => plat/linux68k/build.mk
rename : plat/pc86/build.mk => plat/linuxppc/build.mk
rename : util/ack/build.mk => util/misc/build.mk
2013-05-12 23:51:55 +01:00
David Given
c1aca7dae5 First milestone of replacing the build system.
--HG--
branch : dtrg-buildsystem
rename : lang/cem/cpp.ansi/Parameters => lang/cem/cpp.ansi/parameters.h
2013-05-12 20:45:55 +01:00
David Given
d89f172841 Change fatal() and error() to use varargs. 2013-05-10 12:04:21 +01:00
David Given
d91a1dc1a6 Merge changes from branch: linux68k platform, linuxppc platform (partially
working), and miscellaneous changes to support these.
2013-05-09 18:14:16 +01:00
David Given
b9b808e01a Apply George Koehler's aelflod fix for generating non-EM_386 binaries.
Adjust platforms to use it. Fix some bugs in the linux386 platform.

--HG--
branch : dtrg-experimental-powerpc
2013-05-09 15:54:23 +01:00
David Given
99d7f513f2 Properly error out if something goes wrong rather than ploughing ahead
anyway.

--HG--
branch : dtrg-experimental-powerpc
2013-05-09 11:20:36 +01:00
David Given
bcfb3d802f Add pmfile for m68020 libend.
--HG--
branch : dtrg-experimental-powerpc
2013-05-09 00:58:35 +01:00
David Given
8e2d027c49 Add pmfile for m68020 libem.
--HG--
branch : dtrg-experimental-powerpc
2013-05-09 00:57:47 +01:00
David Given
8d0261473d Add missing linux68k platform and liblinux support library.
--HG--
branch : dtrg-experimental-powerpc
2013-05-09 00:56:10 +01:00
David Given
c93cb69959 Check in incomplete Linux PowerPC and M68K work.
--HG--
branch : dtrg-experimental-powerpc
2013-05-08 00:48:48 +01:00
George Koehler
c8fdcff960 Some fixes for aelflod and aslod.
Copy rhead() and rsect() from aslod to aelflod, so aelflod can work
for machine with 64-bit long.

In aelflod, fix ELF header so file(1) no longer reports "corrupted
section header size".
2013-04-24 19:57:23 -04:00
958 changed files with 19100 additions and 17756 deletions

17
.distr
View File

@@ -1,9 +1,7 @@
README
CHANGES
Copyright
pm
pmfile
config.pm
Makefile
h
modules/h
@@ -13,7 +11,7 @@ util/data
util/LLgen
modules/src/alloc
modules/src/assert
#modules/src/assert
modules/src/system
modules/src/string
modules/src/read_em
@@ -31,7 +29,7 @@ util/ack
lib/descr/fe
util/arch
#util/cpp
util/cgg
#util/cgg
util/ncgg
util/misc
util/opt
@@ -43,15 +41,22 @@ lang/cem
lang/pc
lang/m2
#lang/occam
#lang/basic
lang/basic
mach/proto
mach/i80
mach/i86
mach/i386
mach/m68020
mach/vc4
plat
plat/cpm
plat/pc86
plat/linux
plat/linux386
plat/linux68k
plat/rpi
examples
man

5
.gitignore vendored
View File

@@ -1,5 +0,0 @@
*~
*.o
.*
-.gitignore
/pattern.c

View File

@@ -1 +0,0 @@
LICENSE

32
Copyright Normal file
View File

@@ -0,0 +1,32 @@
Copyright (c) 1987, 1990, 1993, 2005 Vrije Universiteit, Amsterdam, The Netherlands.
All rights reserved.
Redistribution and use of the Amsterdam Compiler Kit in source and
binary forms, with or without modification, are permitted provided
that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Vrije Universiteit nor the names of the
software authors or contributors may be used to endorse or
promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND
CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL VRIJE UNIVERSITEIT OR ANY AUTHORS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

32
LICENSE
View File

@@ -1,32 +0,0 @@
Copyright (c) 1987, 1990, 1993, 2005 Vrije Universiteit, Amsterdam, The Netherlands.
All rights reserved.
Redistribution and use of the Amsterdam Compiler Kit in source and
binary forms, with or without modification, are permitted provided
that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Vrije Universiteit nor the names of the
software authors or contributors may be used to endorse or
promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND
CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL VRIJE UNIVERSITEIT OR ANY AUTHORS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

146
Makefile Normal file
View File

@@ -0,0 +1,146 @@
# ======================================================================= #
# ACK CONFIGURATION #
# (Edit this before building) #
# ======================================================================= #
# What platform to build for by default?
DEFAULT_PLATFORM = pc86
# Where should the ACK put its temporary files?
ACK_TEMP_DIR = /tmp
# Where is the ACK going to be installed, eventually?
PREFIX = /usr/local
# Where do you want to put the object files used when building?
BUILDDIR = $(ACK_TEMP_DIR)/ack-build
# What build flags do you want to use?
CFLAGS = -g
LDFLAGS = -s
# ======================================================================= #
# END OF CONFIGURATION #
# ======================================================================= #
#
# You shouldn't need to change anything below this point unless you are
# actually developing ACK.
OBJDIR = $(BUILDDIR)/obj
BINDIR = $(BUILDDIR)/bin
LIBDIR = $(BUILDDIR)/lib
INCDIR = $(BUILDDIR)/include
INSDIR = $(BUILDDIR)/staging
PLATIND = $(INSDIR)/share/ack
PLATDEP = $(INSDIR)/lib/ack
CC = gcc
AR = ar
RM = rm -f
CP = cp
hide = @
CFLAGS += \
-I$(INCDIR) \
-Imodules/h \
-Ih
LDFLAGS +=
ACKFLAGS = -Ih
all: installables
.DELETE_ON_ERROR:
include first/core.mk
include modules/src/object/build.mk
include modules/src/alloc/build.mk
include modules/src/input/build.mk
include modules/src/idf/build.mk
include modules/src/system/build.mk
include modules/src/string/build.mk
include modules/src/print/build.mk
include modules/src/flt_arith/build.mk
include modules/src/em_code/build.mk
include modules/src/em_mes/build.mk
include modules/src/read_em/build.mk
include util/amisc/build.mk
include util/cmisc/build.mk
include util/ack/build.mk
include util/LLgen/build.mk
include util/data/build.mk
include util/opt/build.mk
include util/ncgg/build.mk
include util/arch/build.mk
include util/misc/build.mk
include util/led/build.mk
include util/topgen/build.mk
include util/ego/build.mk
include lang/cem/build.mk
include lang/basic/build.mk
include lang/pc/build.mk
include lang/m2/build.mk
include mach/proto/as/build.mk
include mach/proto/ncg/build.mk
include mach/proto/top/build.mk
include plat/linux/liblinux/build.mk
include mach/i80/build.mk
include mach/i386/build.mk
include mach/i86/build.mk
include mach/m68020/build.mk
# include mach/powerpc/build.mk
include mach/vc4/build.mk
include plat/build.mk
include plat/pc86/build.mk
include plat/cpm/build.mk
include plat/linux386/build.mk
include plat/linux68k/build.mk
# include plat/linuxppc/build.mk
include plat/rpi/build.mk
.PHONY: installables
installables: $(INSTALLABLES)
@echo ""
@echo "Build completed successfully."
.PHONY: install
install: installables
@echo INSTALLING into $(PREFIX)
$(hide) tar cf - -C $(INSDIR) . | tar xvf - -C $(PREFIX)
.PHONY: clean
clean:
@echo CLEAN
$(hide) $(RM) $(CLEANABLES)
$(INCDIR)/local.h:
@echo LOCAL
@mkdir -p $(dir $@)
$(hide) echo '#define VERSION 3' > $@
$(hide) echo '#define ACKM "$(DEFAULT_PLATFORM)"' >> $@
$(hide) echo '#define BIGMACHINE 1' >> $@
$(hide) echo '#define SYS_5' >> $@
$(INCDIR)/em_path.h:
@echo EM_PATH
@mkdir -p $(dir $@)
$(hide) echo '#define TMP_DIR "$(ACK_TEMP_DIR)"' > $@
$(hide) echo '#define EM_DIR "$(PREFIX)"' >> $@
$(hide) echo '#define ACK_PATH "share/ack/descr"' >> $@
-include $(DEPENDS)

108
README
View File

@@ -1,8 +1,9 @@
THE AMSTERDAM COMPILER KIT V6.0pre4
===================================
THE AMSTERDAM COMPILER KIT V6.0pre5
===================================
© 1987-2005 Vrije Universiteit, Amsterdam
2013-05-15
© 1987-2005 Vrije Universiteit, Amsterdam 2010-08-08
© 2013-2014 Manoel Trapier, Paris
INTRODUCTION
============
@@ -17,82 +18,69 @@ lot is supported, the build mechanism needs work, and a lot of things are
probably broken. However, what's there should be sufficient to get things
done and to evaluate how the full 6.0 release should work.
This is a fork from the original repository found on sourceforge. This
fork exist for three reason, the first is I strongly prefere git than
mercurial (this is a personal preference) and second I want to make it
work on Mac OS X but the OSX clang/gcc does not really like the K&R
syntax, so I take into the process of ANSIfy it. The third reason is why
I want to use the ACK, it support old CPU, like the 6502 or i8080, i8086
and it is open source unlike a lot of compiler we can found nowadays for
such targets, and it support more than C that is a wonderfull bonus!
I have plan to add targets like the NES, add support for the 65c816 and
add the SNES target, add the WonderSwan as a target and so on. I see in
this compiler kit a wonderfull project for all sort of old computer that
are still used nowadays and used CPU that are no longuer targeted by
modern compilers.
I plan to push my changes on the original version, at least for the new
targets and cpu.
SUPPORT
=======
Languages:
ANSI C, Pascal, Modula 2. K&R is supported via the ANSI C compiler.
ANSI C, Pascal, Modula 2, Basic. K&R is supported via the ANSI C compiler.
Platforms:
pc86 produces bootable floppy disk images for 8086 PCs
linux386 produces ELF executables for PC Linux systems
linux68k produces ELF executables for m68020 Linux systems
cpm produces i80 CP/M .COM files
rpi produces Raspberry Pi GPU binaries
INSTALLATION
============
The version 6.0 build mechanism has been completely rewritten and is based
around the Prime Mover build tool (see http://primemover.sf.net for more
information). Installation ought to be fairly straightforward.
The version 5.0 build mechanism has been completely rewritten. Installation
ought to be fairly straightforward.
Requirements:
- an ANSI C compiler. Currently, I'm afraid, it's hard-coded to use gcc.
To change, try changing the variable definitions in first/c.pm. This also
needs to be available as 'cc' from the shell.
- about 20MB free in /tmp (or some other temporary directory).
- an ANSI C compiler. This defaults to gcc. You can change this by setting
the CC make variable.
- flex and yacc.
- GNU make.
- about 40MB free in /tmp (or some other temporary directory).
- about 6MB in the target directory.
Instructions:
- edit config.pm. There's a small section at the top containing some editable
variables. Probably the only one you may want to edit is PREFIX, which
changes where the ACK installs to.
- edit the Makefile. There's a small section at the top where you can change
the configuration. Probably the only one you may want to edit is PREFIX,
which changes where the ACK installs to.
- Run:
./pm configure
...from the command line. This will write out a configuration file.
make # or gmake
...from the command line. This will do the build.
The make system is fully parallelisable. If you have a multicore system,
you probably want to do:
make -j8 # or gmake -j8
...instead (substituting the right number of cores, of course). You can
also shave a few seconds of the build time by using the -r flag.
- Run:
./pm
...from the command line. This will actually do the build. This takes
about two minutes on my 1.6GHz Athlon Linux machine and about 30 on my
166MHz Pentium OpenBSD machine.
- Run:
sudo make install
...from the command line. This will install the ACK in your PREFIX
directory (by default, /usr/local).
./pm install
...from the command line (possibly with sudo). This will install the built
ACK into whatever directory you nominated in PREFIX.
The ACK should now be ready to use.
@@ -110,8 +98,9 @@ Some useful options include:
-o <file> specifies the output file
-c produce a .o file
-c.s produce a .s assembly file
-O enable optimisation
-O enable optimisation (optimisation levels go up to 6)
-ansi compile ANSI C (when using the C compiler)
-v be more verbose (repeatable)
<file> build file
ack figures out which language to use from the file extension:
@@ -123,6 +112,7 @@ ack figures out which language to use from the file extension:
.p Pascal
.o object files
.s assembly files
.e ACK intermediate code assembly files
For further information, see the man page (which actually does get
installed, but is rather out of date).
@@ -133,12 +123,13 @@ A sample command line is:
ack -mlinux386 -O examples/paranoia.c
GOTCHAS
=======
There are some things you should be aware of.
- Look at plat/<PLATFORMNAME>/README for information about the two supported
- Look at plat/<PLATFORMNAME>/README for information about the supported
platforms.
- The library support is fairly limited; for C, it's at roughly the ANSI C
@@ -171,19 +162,12 @@ more welcome.
The ACK is licensed under a BSD-like license. Please see the 'Copyright' file
for the full text.
You will find this "ANSI Fork" on github:
http://github.com/Godzil/ack
You can find the ACK mailing list and the original project's web site:
You can find the mailing list on the project's web site:
http://tack.sourceforge.net/
Please enjoy.
Manoel Trapier (aka godzil) for the ANSI-fication port
David Given (dtrg on Sourceforge)
dg@cowlark.com
2010-08-08
2013-05-13

View File

@@ -1 +0,0 @@
README

View File

@@ -13,7 +13,7 @@ ACK_TEMP_DIR = "/tmp"
-- Where is the ACK going to be installed, eventually?
PREFIX = "/usr/local"
PREFIX = "/tmp/ack-temp/staging"
-- ======================================================================= --
-- BROKEN ACK CONFIGURATION --

View File

@@ -143,7 +143,7 @@ echo ""
if [ -e $destdir ]; then
if [ "$delete" = "yes" ]; then
echo "Press RETURN to erase $destdir and its contents, or CTRL+C to abort."
read
read _ _
echo "Erasing..."
rm -rf "$destdir"
else

View File

@@ -1,9 +1,4 @@
ack.pm
ack-custom.pm
c.pm
llgen.pm
yacc.pm
core.mk
#create_dir
#cp_dir
#em_path.h.src

View File

@@ -25,7 +25,7 @@ CXXPROGRAM = "%CXXCOMPILER% %CBUILDFLAGS% %CLINKFLAGS% %CEXTRAFLAGS% -o %out% %i
CLIBRARY = "rm -f %out% && ar cr %out% %in% && ranlib %out%"
CBUILDFLAGS = {"-g", "-Werror", "-std=c89"}
CBUILDFLAGS = {"-g"}
CINCLUDES = EMPTY
CDEFINES = EMPTY
CEXTRAFLAGS = EMPTY

199
first/core.mk Normal file
View File

@@ -0,0 +1,199 @@
define reset
$(eval q :=)
$(eval o :=)
$(eval s :=)
$(eval cflags :=)
$(eval ackflags :=)
$(eval ldflags :=)
$(eval objdir :=)
endef
# --- Host compiler
define cfile-rule
$o: $s
@echo CC $o
@mkdir -p $(dir $o)
@$(CC) $(CFLAGS) $(cflags) -MM -MQ $o -o $d $s
$(hide) $(CC) $(CFLAGS) $(cflags) -c -o $o $s
endef
define cfile
$(eval s := $1)
$(eval o := $(OBJDIR)/$(objdir)/$(1:.c=.o))
$(eval d := $(OBJDIR)/$(objdir)/$(1:.c=.d))
$(eval DEPENDS += $d)
$(eval CLEANABLES += $o $d)
$(eval q += $o)
$(eval $(cfile-rule))
endef
# --- ACK compiler
define ackfile-rule
$o: $s $(ACK) \
$(CCOMPILER) \
$(PLATFORM_$(PLATFORM)) \
$(ACK_CORE_TOOLS)
@echo ACK $o
@mkdir -p $(dir $o)
$(hide) ACKDIR=$(INSDIR) $(ACK) $(ACKFLAGS) $(ackflags) -m$(PLATFORM) -c -o $o $s
endef
define ackfile
$(eval s := $1)
$(eval o := $(OBJDIR)/$(objdir)/$(basename $1).o)
$(eval d := $(OBJDIR)/$(objdir)/$(basename $1).d)
$(eval DEPENDS += $d)
$(eval CLEANABLES += $o $d)
$(eval q += $o)
$(eval $(ackfile-rule))
endef
# --- Add a raw to the queue
define file
$(eval q += $1)
endef
# --- Host compiler linking
define cprogram-rule
$o: $s
@echo CPROGRAM $o
@mkdir -p $(dir $o)
$(hide) $(CC) $(CFLAGS) $(cflags) $(LDFLAGS) $(ldflags) -o $o $s
endef
define cprogram
$(eval o := $1)
$(eval s := $q)
$(eval CLEANABLES += $o)
$(eval q := $o)
$(eval $(cprogram-rule))
endef
# --- Host library linking
define clibrary-rule
$o: $s
@echo CLIBRARY $o
@mkdir -p $(dir $o)
@$(RM) $o
$(hide) $(AR) qsc $o $s
endef
define clibrary
$(eval o := $1)
$(eval s := $q)
$(eval CLEANABLES += $o)
$(eval q := $o)
$(eval $(clibrary-rule))
endef
# --- ACK library linking
define acklibrary-rule
$o: $s $(AAL)
@echo ACKLIBRARY $o
@mkdir -p $(dir $o)
@$(RM) $o
$(hide) $(AAL) q $o $s
endef
define acklibrary
$(eval o := $1)
$(eval s := $q)
$(eval CLEANABLES += $o)
$(eval q := $o)
$(eval $(acklibrary-rule))
endef
# --- Copies a file.
define copyto-rule
$o: $s
@echo CP $o
@mkdir -p $(dir $o)
$(hide) $(CP) $s $o
endef
define copyto
$(eval o := $1)
$(eval s := $q)
$(eval CLEANABLES += $o)
$(eval q := $o)
$(eval $(copyto-rule))
endef
# --- Installs a file (copies it and adds it to INSTALLABLES).
define installto-rule
$o: $s
@echo INSTALL $o
@mkdir -p $(dir $o)
$(hide) $(CP) $s $o
endef
define installto
$(eval o := $1)
$(eval s := $q)
$(eval CLEANABLES += $o)
$(eval INSTALLABLES += $o)
$(eval q := $o)
$(eval $(installto-rule))
endef
# --- Adds a dependency for the last object file
define dependson
$(eval $o: $1)
endef
# --- Runs yacc.
# $1: directory to put output files
# $2: input files
#
# Output files are compiled via cfile and queued.
define yacc-impl
$(eval o := $1/y.tab.c)
$(eval CLEANABLES += $o $1/y.tab.h)
$o: $2
@echo YACC $o
@mkdir -p $(dir $o)
$(hide) yacc -t -b $1/y -d $2
$(call cfile, $o)
$1/y.tab.h: $o
endef
yacc = $(eval $(call yacc-impl,$1,$2))
# --- Runs flex.
# $1: directory to put output files
# $2: input files
#
# Output files are compiled via cfile and queued.
define flex-impl
$(eval o := $1/lex.yy.c)
$(eval CLEANABLES += $o)
$o: $2
@echo FLEX $o
@mkdir -p $(dir $o)
$(hide) flex -s -t $2 > $o
$(call cfile, $o)
endef
flex = $(eval $(call flex-impl,$1,$2))

View File

@@ -3,7 +3,7 @@ yacc = simple {
outputs = {"%U%/%I%.c"},
command = {
"byacc -t -b %out[1]:dirname%/y -d %in%",
"yacc -t -b %out[1]:dirname%/y -d %in%",
"mv %out[1]:dirname%/y.tab.c %out[1]%"
}
}

View File

@@ -4,9 +4,6 @@
*/
/* $Id$ */
#ifndef H_CGG_CG_H
#define H_CGG_CG_H
/* offsets of interesting fields in EM-pattern */
#define PO_HASH 0
@@ -168,5 +165,3 @@ typedef struct { /* one to one coercions */
if ((a=((*(b)++)&BMASK)) >= 128) {\
a = ((a-128)<<BSHIFT) | (*(b)++&BMASK); \
}
#endif /* H_CGG_CG_H */

View File

@@ -55,7 +55,10 @@
+ (FL_MSB_AT_LOW_ADDRESS ? 1 : 0))
#ifndef USE_FLT
static int float_cst(char *str, int sz, char *buf)
static int
float_cst(str, sz, buf)
char *str, *buf;
int sz;
{
int i;
char *p;
@@ -84,7 +87,10 @@ static int float_cst(char *str, int sz, char *buf)
#include <ctype.h>
#include <flt_arith.h>
int float_cst(char *str, int sz, char *buf)
int
float_cst(str, sz, buf)
char *str, *buf;
int sz;
{
int overflow = 0;
flt_arith e;
@@ -231,7 +237,7 @@ int float_cst(char *str, int sz, char *buf)
#endif /* USE_FLT */
#ifdef CODE_GENERATOR
void con_float()
con_float()
{
char buf[8];
int rval = float_cst(str, (int)argval, buf);
@@ -254,7 +260,9 @@ void con_float()
#endif /* CODE_GENERATOR */
#ifdef CODE_EXPANDER
void con_float(char *str, arith argval)
con_float(str, argval)
char *str;
arith argval;
{
char buf[8];
int rval = float_cst(str, (int)argval, buf);

View File

@@ -1,29 +0,0 @@
#ifndef H_MISSING_PROTO_H
#define H_MISSING_PROTO_H
#ifdef NOSBRK
void *sbrk(__intptr_t increment);
void *brk(void * addr);
#endif
#ifdef NOMKTEMP
char *mktemp(char *template);
#endif
#ifdef EMULATE_BRK
void *sbrk_emu(int increment);
void *brk_emu(const void * addr);
#ifdef sbrk
#undef sbrk
#endif
#ifdef brk
#undef brk
#endif
#define sbrk sbrk_emu
#define brk brk_emu
#endif
#endif /* H_MISSING_H */

14
h/out.h
View File

@@ -61,7 +61,11 @@ struct outname {
#define RELSZ 0x07 /* relocation length */
#define RELO1 1 /* 1 byte */
#define RELO2 2 /* 2 bytes */
#define RELO4 4 /* 4 bytes */
#define RELO4 3 /* 4 bytes */
#define RELOPPC 4 /* PowerPC 26-bit address */
#define RELOH2 5 /* write top 2 bytes of 4 byte word */
#define RELOVC4 6 /* VideoCore IV address in 32-bit instruction */
#define RELPC 0x08 /* pc relative */
#define RELBR 0x10 /* High order byte lowest address. */
#define RELWR 0x20 /* High order word lowest address. */
@@ -97,13 +101,19 @@ struct outname {
/*
* structure format strings
*/
#if 0
/* The following strings only make sense on 32-bit platforms, so we're going
* to try and deprecate them. */
#define SF_HEAD "22222244"
#define SF_SECT "44444"
#define SF_RELO "1124"
#define SF_NAME "4224"
#endif
/*
* structure sizes (bytes in file; add digits in SF_*)
* structure sizes on disk (bytes in file; add digits in SF_*)
* Note! These are NOT the sizes in memory (64-bit architectures will have
* a different layout).
*/
#define SZ_HEAD 20
#define SZ_SECT 20

View File

@@ -1,15 +0,0 @@
/*
* The Amsterdam Compiler Kit
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef H_SYMBOL2STR_H
#define H_SYMBOL2STR_H
/* A lot of component use a version of this function, there is currently no header file
* that contain it, and all use the same prototype as they are all generated from the same
* generator.
*/
char *symbol2str(int tok);
#endif

View File

@@ -1,3 +1,3 @@
pmfile
build.mk
src
lib

3
lang/basic/build.mk Normal file
View File

@@ -0,0 +1,3 @@
include lang/basic/lib/build.mk
include lang/basic/src/build.mk

View File

@@ -1,4 +1,4 @@
pmfile
build.mk
abs.c
asc.c
asrt.c

View File

@@ -7,62 +7,7 @@
/* $Id$ */
#define __NO_DEFS
#include <math.h>
double
_atn(x)
double x;
{
/* Algorithm and coefficients from:
"Software manual for the elementary functions"
by W.J. Cody and W. Waite, Prentice-Hall, 1980
*/
double _atn(double x) { return atan(x); }
static double p[] = {
-0.13688768894191926929e+2,
-0.20505855195861651981e+2,
-0.84946240351320683534e+1,
-0.83758299368150059274e+0
};
static double q[] = {
0.41066306682575781263e+2,
0.86157349597130242515e+2,
0.59578436142597344465e+2,
0.15024001160028576121e+2,
1.0
};
static double a[] = {
0.0,
0.52359877559829887307710723554658381, /* pi/6 */
M_PI_2,
1.04719755119659774615421446109316763 /* pi/3 */
};
int neg = x < 0;
int n;
double g;
if (neg) {
x = -x;
}
if (x > 1.0) {
x = 1.0/x;
n = 2;
}
else n = 0;
if (x > 0.26794919243112270647) { /* 2-sqtr(3) */
n = n + 1;
x = (((0.73205080756887729353*x-0.5)-0.5)+x)/
(1.73205080756887729353+x);
}
/* ??? avoid underflow ??? */
g = x * x;
x += x * g * POLYNOM3(g, p) / POLYNOM4(g, q);
if (n > 1) x = -x;
x += a[n];
return neg ? -x : x;
}

48
lang/basic/lib/build.mk Normal file
View File

@@ -0,0 +1,48 @@
define build-runtime-libbasic-impl
$(call reset)
$(eval objdir := $(PLATFORM))
$(call ackfile, lang/basic/lib/fif.e)
$(call ackfile, lang/basic/lib/fef.e)
$(call ackfile, lang/basic/lib/setline.e)
$(call ackfile, lang/basic/lib/abs.c)
$(call ackfile, lang/basic/lib/asc.c)
$(call ackfile, lang/basic/lib/asrt.c)
$(call ackfile, lang/basic/lib/atn.c)
$(call ackfile, lang/basic/lib/chr.c)
$(call ackfile, lang/basic/lib/conversion.c)
$(call ackfile, lang/basic/lib/error.c)
$(call ackfile, lang/basic/lib/exp.c)
$(call ackfile, lang/basic/lib/file.c)
$(call ackfile, lang/basic/lib/hlt.c)
$(call ackfile, lang/basic/lib/io.c)
$(call ackfile, lang/basic/lib/log.c)
$(call ackfile, lang/basic/lib/mki.c)
$(call ackfile, lang/basic/lib/oct.c)
$(call ackfile, lang/basic/lib/peek.c)
$(call ackfile, lang/basic/lib/power.c)
$(call ackfile, lang/basic/lib/print.c)
$(call ackfile, lang/basic/lib/random.c)
$(call ackfile, lang/basic/lib/read.c)
$(call ackfile, lang/basic/lib/return.c)
$(call ackfile, lang/basic/lib/salloc.c)
$(call ackfile, lang/basic/lib/sgn.c)
$(call ackfile, lang/basic/lib/sin.c)
$(call ackfile, lang/basic/lib/sqt.c)
$(call ackfile, lang/basic/lib/stop.c)
$(call ackfile, lang/basic/lib/string.c)
$(call ackfile, lang/basic/lib/swap.c)
$(call ackfile, lang/basic/lib/trace.c)
$(call ackfile, lang/basic/lib/trap.c)
$(call ackfile, lang/basic/lib/write.c)
$(call acklibrary, $(LIBDIR)/$(PLATFORM)/libbasic.a)
$(call installto, $(PLATIND)/$(PLATFORM)/libbasic.a)
endef
build-runtime-libbasic = $(eval $(build-runtime-libbasic-impl))
$(eval RUNTIMES += libbasic)

View File

@@ -1,4 +1,5 @@
/* $Id$ */
#include <stdlib.h>
#include <stdio.h>
/* error takes an error value in the range of 0-255 */
/* and generates a trap */

View File

@@ -10,88 +10,7 @@
#define __NO_DEFS
#include <math.h>
static double
ldexp(fl,exp)
double fl;
int exp;
double _exp(double x)
{
extern double _fef();
int sign = 1;
int currexp;
if (fl<0) {
fl = -fl;
sign = -1;
}
fl = _fef(fl,&currexp);
exp += currexp;
if (exp > 0) {
while (exp>30) {
fl *= (double) (1L << 30);
exp -= 30;
}
fl *= (double) (1L << exp);
}
else {
while (exp<-30) {
fl /= (double) (1L << 30);
exp += 30;
}
fl /= (double) (1L << -exp);
}
return sign * fl;
}
double
_exp(x)
double x;
{
/* Algorithm and coefficients from:
"Software manual for the elementary functions"
by W.J. Cody and W. Waite, Prentice-Hall, 1980
*/
static double p[] = {
0.25000000000000000000e+0,
0.75753180159422776666e-2,
0.31555192765684646356e-4
};
static double q[] = {
0.50000000000000000000e+0,
0.56817302698551221787e-1,
0.63121894374398503557e-3,
0.75104028399870046114e-6
};
double xn, g;
int n;
int negative = x < 0;
if (x <= M_LN_MIN_D) {
return M_MIN_D;
}
if (x >= M_LN_MAX_D) {
if (x > M_LN_MAX_D) error(3);
return M_MAX_D;
}
if (negative) x = -x;
/* ??? avoid underflow ??? */
n = x * M_LOG2E + 0.5; /* 1/ln(2) = log2(e), 0.5 added for rounding */
xn = n;
{
double x1 = (long) x;
double x2 = x - x1;
g = ((x1-xn*0.693359375)+x2) - xn*(-2.1219444005469058277e-4);
}
if (negative) {
g = -g;
n = -n;
}
xn = g * g;
x = g * POLYNOM2(xn, p);
n += 1;
return (ldexp(0.5 + x/(POLYNOM3(xn, q) - x), n));
return exp(x);
}

View File

@@ -1,4 +1,4 @@
/* $Id$ */
#include <stdlib.h>
_hlt(nr)
int nr;

View File

@@ -1,9 +1,8 @@
#include "bc_io.h"
#include <sgtty.h>
/* $Id$ */
struct sgttyb _ttydef;
/* dtrg --- this originally used sgtty.h to do clever tty manipulation.
* Strictly this should be converted to use termios, but for simplicity
* we're going to stick with plain stdio for now. */
/* BASIC has some nasty io characteristics */
@@ -65,9 +64,6 @@ char *buf;
if( _chann == -1)
{
pos= _pos;
gtty(0,_ttydef);
_ttydef.sg_flags &= ~ECHO;
stty(0,_ttydef);
}else pos= _fdtable[_chann].pos;
c= buf;
while( (holder = fgetc(_chanrd)) != EOF && holder != '\n'){
@@ -79,8 +75,6 @@ char *buf;
if( _chann== -1)
{
_pos=pos;
_ttydef.sg_flags |= ECHO;
stty(0,_ttydef);
} else _fdtable[_chann].pos= pos;
}
_tab(x)

View File

@@ -10,48 +10,7 @@
#define __NO_DEFS
#include <math.h>
double
_log(x)
double x;
double _log(double x)
{
/* Algorithm and coefficients from:
"Software manual for the elementary functions"
by W.J. Cody and W. Waite, Prentice-Hall, 1980
*/
static double a[] = {
-0.64124943423745581147e2,
0.16383943563021534222e2,
-0.78956112887491257267e0
};
static double b[] = {
-0.76949932108494879777e3,
0.31203222091924532844e3,
-0.35667977739034646171e2,
1.0
};
extern double _fef();
double znum, zden, z, w;
int exponent;
if (x <= 0) {
error(3);
return -HUGE;
}
x = _fef(x, &exponent);
if (x > M_1_SQRT2) {
znum = (x - 0.5) - 0.5;
zden = x * 0.5 + 0.5;
}
else {
znum = x - 0.5;
zden = znum * 0.5 + 0.5;
exponent--;
}
z = znum/zden; w = z * z;
x = z + z * w * (POLYNOM2(w,a)/POLYNOM3(w,b));
z = exponent;
x += z * (-2.121944400546905827679e-4);
return x + z * 0.693359375;
return log(x);
}

View File

@@ -1,3 +1,5 @@
#include <stdlib.h>
#include <stdio.h>
#include "bc_string.h"
/* $Id$ */

View File

@@ -1,32 +1,4 @@
/* $Id$ */
#include <math.h>
/*
computes a^b.
uses log and exp
*/
double _power(double x, double y) { return pow(x, y); }
double _log(), _exp();
double
_power(base,pownr)
double pownr, base;
{
double temp;
long l;
if(pownr <= 0.0) {
if(pownr == 0.0) {
if(base <= 0.0)
error(3);
return(0.0);
}
l = base;
if(l != base)
error(3);
temp = _exp(base * _log(-pownr));
if(l & 1)
temp = -temp;
return(temp);
}
return(_exp(base * _log(pownr)));
}

View File

@@ -1,3 +1,5 @@
#include <stdlib.h>
#include <stdio.h>
#include "bc_string.h"
#include "bc_io.h"

View File

@@ -1,4 +1,5 @@
/* $Id$ */
#include <stdlib.h>
#include <stdio.h>
#if !defined(EM_WSIZE)
#define EM_WSIZE _EM_WSIZE

View File

@@ -1,6 +1,4 @@
/* $Id$ */
extern char *malloc() ;
#include <stdlib.h>
char * salloc(length)
unsigned length;

View File

@@ -10,96 +10,7 @@
#define __NO_DEFS
#include <math.h>
static double
sinus(x, cos_flag)
double x;
{
/* Algorithm and coefficients from:
"Software manual for the elementary functions"
by W.J. Cody and W. Waite, Prentice-Hall, 1980
*/
double _sin(double x) { return sin(x); }
double _cos(double x) { return cos(x); }
double _tan(double x) { return tan(x); }
static double r[] = {
-0.16666666666666665052e+0,
0.83333333333331650314e-2,
-0.19841269841201840457e-3,
0.27557319210152756119e-5,
-0.25052106798274584544e-7,
0.16058936490371589114e-9,
-0.76429178068910467734e-12,
0.27204790957888846175e-14
};
double xsqr;
double y;
int neg = 0;
if (x < 0) {
x = -x;
neg = 1;
}
if (cos_flag) {
neg = 0;
y = M_PI_2 + x;
}
else y = x;
/* ??? avoid loss of significance, if y is too large, error ??? */
y = y * M_1_PI + 0.5;
/* Use extended precision to calculate reduced argument.
Here we used 12 bits of the mantissa for a1.
Also split x in integer part x1 and fraction part x2.
*/
#define A1 3.1416015625
#define A2 -8.908910206761537356617e-6
{
double x1, x2;
extern double _fif();
_fif(y, 1.0, &y);
if (_fif(y, 0.5, &x1)) neg = !neg;
if (cos_flag) y -= 0.5;
x2 = _fif(x, 1.0, &x1);
x = x1 - y * A1;
x += x2;
x -= y * A2;
#undef A1
#undef A2
}
if (x < 0) {
neg = !neg;
x = -x;
}
/* ??? avoid underflow ??? */
y = x * x;
x += x * y * POLYNOM7(y, r);
return neg ? -x : x;
}
double
_sin(x)
double x;
{
return sinus(x, 0);
}
double
_cos(x)
double x;
{
if (x < 0) x = -x;
return sinus(x, 1);
}
/* EXTENSION */
double
_tan(x)
double x;
{
return _sin(x)/_cos(x);
}

View File

@@ -10,62 +10,5 @@
#define __NO_DEFS
#include <math.h>
#define NITER 5
double _sqt(double x) { return sqrt(x); }
static double
ldexp(fl,exp)
double fl;
int exp;
{
extern double _fef();
int sign = 1;
int currexp;
if (fl<0) {
fl = -fl;
sign = -1;
}
fl = _fef(fl,&currexp);
exp += currexp;
if (exp > 0) {
while (exp>30) {
fl *= (double) (1L << 30);
exp -= 30;
}
fl *= (double) (1L << exp);
}
else {
while (exp<-30) {
fl /= (double) (1L << 30);
exp += 30;
}
fl /= (double) (1L << -exp);
}
return sign * fl;
}
double
_sqt(x)
double x;
{
extern double _fef();
int exponent;
double val;
if (x <= 0) {
if (x < 0) error(3);
return 0;
}
val = _fef(x, &exponent);
if (exponent & 1) {
exponent--;
val *= 2;
}
val = ldexp(val + 1.0, exponent/2 - 1);
/* was: val = (val + 1.0)/2.0; val = ldexp(val, exponent/2); */
for (exponent = NITER - 1; exponent >= 0; exponent--) {
val = (val + x / val) / 2.0;
}
return val;
}

View File

@@ -1,4 +1,5 @@
/* $Id$ */
#include <stdlib.h>
#include <stdio.h>
_stop()
{

View File

@@ -1,3 +1,5 @@
#include <stdlib.h>
#include <string.h>
#include "bc_string.h"
/* $Id$ */

View File

@@ -1,3 +1,5 @@
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <setjmp.h>

View File

@@ -1,4 +1,4 @@
pmfile
build.mk
basic.g
basic.lex
bem.c

View File

@@ -237,7 +237,7 @@ File *stream;
extern char *strchr();
getline()
getinputline()
{
/* get next input line */

44
lang/basic/src/build.mk Normal file
View File

@@ -0,0 +1,44 @@
D := lang/basic/src
define build-bem-impl
$(call reset)
$(eval cflags += -I$(OBJDIR)/$D -I$D)
$(call cfile, $D/bem.c)
$(call cfile, $D/symbols.c)
$(call cfile, $D/initialize.c)
$(call cfile, $D/compile.c)
$(call cfile, $D/parsepar.c)
$(call cfile, $D/gencode.c)
$(call cfile, $D/util.c)
$(call cfile, $D/graph.c)
$(call cfile, $D/eval.c)
$(call cfile, $D/func.c)
$(call llgen, $(OBJDIR)/$D, $D/basic.g)
$(eval g := $(OBJDIR)/$D/tokentab.h)
$(eval $q: $g)
$(eval CLEANABLES += $g)
$g: $D/maketokentab $(OBJDIR)/$D/Lpars.h
@echo TOKENTAB $$@
@mkdir -p $$(dir $$@)
$(hide) cd $(OBJDIR)/$D && $(abspath $$^)
$(eval $q: $(OBJDIR)/$D/Lpars.h)
$(eval $q: $(INCDIR)/print.h)
$(call file, $(LIBEM_MES))
$(call file, $(LIBEMK))
$(call file, $(LIBEM_DATA))
$(call file, $(LIBALLOC))
$(call file, $(LIBPRINT))
$(call file, $(LIBSTRING))
$(call file, $(LIBSYSTEM))
$(call cprogram, $(BINDIR)/em_bem)
$(call installto, $(PLATDEP)/em_bem)
endef
$(eval $(build-bem-impl))

View File

@@ -23,7 +23,7 @@ compileprogram()
prolog2(); /* Some statements are moved from prolog2 to
epilogcode in the new version of the compiler */
while( basicline = 0, getline())
while( basicline = 0, getinputline())
(void) LLparse();
epilogcode();
sys_close(yyin);

View File

@@ -644,7 +644,7 @@ prolog2()
C_loi((arith) BEMPTRSIZE);
C_exa_dnam("trpbuf");
C_lae_dnam("trpbuf",(arith)0);
C_cal("setjmp");
C_cal("__setjmp");
C_df_ilb(l);
C_asp((arith)(BEMPTRSIZE+BEMPTRSIZE));
C_lfr((arith)BEMINTSIZE);

View File

@@ -1,4 +1,4 @@
pmfile
build.mk
cemcom.ansi
cpp.ansi
libcc.ansi

6
lang/cem/build.mk Normal file
View File

@@ -0,0 +1,6 @@
include lang/cem/cpp.ansi/build.mk
include lang/cem/cemcom.ansi/build.mk
include lang/cem/libcc.ansi/build.mk
$(eval CCOMPILER := $(CPPANSI) $(CEMCOMANSI) $(LIBCCANSIHEADERS))

View File

@@ -1,4 +1,4 @@
pmfile
build.mk
LLlex.c
LLlex.h
LLmessage.c

View File

@@ -1,5 +1,5 @@
!File: lint.h
/*#define LINT 1*/ /* if defined, 'lint' is produced */
/*#define LINT 1 /* if defined, 'lint' is produced */
!File: pathlength.h
@@ -75,7 +75,7 @@
!File: botch_free.h
/*#define BOTCH_FREE 1*/ /* when defined, botch freed memory, as a check */
/*#define BOTCH_FREE 1 /* when defined, botch freed memory, as a check */
!File: dataflow.h
@@ -83,7 +83,7 @@
!File: debug.h
/*#define DEBUG 1*/ /* perform various self-tests */
/*#define DEBUG 1 /* perform various self-tests */
#define NDEBUG 1 /* disable assertions */
@@ -112,17 +112,17 @@
!File: nopp.h
/*#define NOPP 1*/ /* if NOT defined, use built-int preprocessor */
/*#define NOPP 1 /* if NOT defined, use built-int preprocessor */
!File: nobitfield.h
/*#define NOBITFIELD 1*/ /* if NOT defined, implement bitfields */
/*#define NOBITFIELD 1 /* if NOT defined, implement bitfields */
!File: spec_arith.h
/* describes internal compiler arithmetics */
#undef SPECIAL_ARITHMETICS /* something different from native long */
/*#define UNSIGNED_ARITH unsigned arith*/ /* if it is supported */
/*#define UNSIGNED_ARITH unsigned arith /* if it is supported */
!File: static.h
@@ -130,11 +130,11 @@
!File: nocross.h
/*#define NOCROSS 1*/ /* if NOT defined, cross compiler */
/*#define NOCROSS 1 /* if NOT defined, cross compiler */
!File: regcount.h
/*#define REGCOUNT 1*/ /* count occurrences for register messages */
/*#define REGCOUNT 1 /* count occurrences for register messages */
!File: dbsymtab.h

View File

@@ -5,13 +5,8 @@
/* $Id$ */
/* L E X I C A L A N A L Y Z E R */
#include "debug.h"
#include "lint.h"
#include <alloc.h>
#include "idfsize.h"
#include "numsize.h"
#include "strsize.h"
#include "nopp.h"
#include "parameters.h"
#include "input.h"
#include "arith.h"
#include "def.h"
@@ -22,9 +17,6 @@
#include "class.h"
#include "assert.h"
#include "sizes.h"
#include "error.h"
#include "domacro.h"
#include "replace_loc.h"
#include "specials.h" /* registration of special identifiers */
/* Data about the token yielded */
@@ -65,7 +57,7 @@ static LexSP = 0;
E.g. at the invocation of a sub-parser that uses LLlex(), the
state of the current parser should be saved.
*/
void PushLex()
PushLex()
{
ASSERT(LexSP < MAX_LL_DEPTH);
ASSERT(ASIDE == 0); /* ASIDE = 0; */
@@ -73,14 +65,15 @@ void PushLex()
LexStack[LexSP++] = dot;
}
void PopLex()
PopLex()
{
ASSERT(LexSP > 0);
dot = LexStack[--LexSP];
}
#endif /* NOPP */
int LLlex()
int
LLlex()
{
/* LLlex() plays the role of Lexical Analyzer for the C parser.
The look-ahead and putting aside of tokens are taken into
@@ -110,13 +103,12 @@ int LLlex()
}
char *string_token(char *nm, int stop_char, int *plen);
arith char_constant(char *nm);
void skipcomment();
void strint2tok(char intbuf[], struct token *ptok);
void strflt2tok(char fltbuf[], struct token *ptok);
char *string_token();
arith char_constant();
int GetToken(struct token *ptok)
int
GetToken(ptok)
register struct token *ptok;
{
/* GetToken() is the actual token recognizer. It calls the
control line interpreter if it encounters a "\n{w}*#"
@@ -124,7 +116,7 @@ int GetToken(struct token *ptok)
needed.
*/
char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1];
int ch, nch;
register int ch, nch;
token_nmb++;
@@ -230,7 +222,8 @@ garbage:
case '<':
if (AccFileSpecifier) {
UnGetChar(); /* pushback nch */
ptok->tk_bts = string_token("file specifier", '>', &(ptok->tk_len));
ptok->tk_bts = string_token("file specifier",
'>', &(ptok->tk_len));
return ptok->tk_symb = FILESPECIFIER;
}
if (nch == '<') {
@@ -314,10 +307,10 @@ garbage:
/* fallthrough */
case STIDF:
{
char *tg = &buf[0];
int pos = -1;
struct idf *idef;
extern int idfsize;
register char *tg = &buf[0];
register int pos = -1;
register struct idf *idef;
extern int idfsize; /* ??? */
#ifndef NOPP
int NoExpandNext = 0;
@@ -363,8 +356,8 @@ garbage:
}
case STNUM: /* a numeric constant */
{
int siz_left = NUMSIZE - 1;
char *np = &buf[0];
register int siz_left = NUMSIZE - 1;
register char *np = &buf[0];
int flags = 0;
#define store(ch) if (--siz_left >= 0) \
@@ -446,11 +439,10 @@ garbage:
crash("bad class for char 0%o", ch);
}
/*NOTREACHED*/
return 0;
}
#ifndef NOPP
void skipcomment()
skipcomment()
{
/* The last character read has been the '*' of '/_*'. The
characters, except NL and EOI, between '/_*' and the first
@@ -462,7 +454,7 @@ void skipcomment()
EOI is returned by LoadChar only on encountering EOF of the
top-level file...
*/
int c, oldc = '\0';
register int c, oldc = '\0';
NoUnstack++;
c = GetChar();
@@ -504,10 +496,12 @@ void skipcomment()
}
#endif /* NOPP */
arith char_constant(char *nm)
arith
char_constant(nm)
char *nm;
{
arith val = 0;
int ch;
register arith val = 0;
register int ch;
int size = 0;
ch = GetChar();
@@ -535,12 +529,15 @@ arith char_constant(char *nm)
return val;
}
char *string_token(char *nm, int stop_char, int *plen)
char *
string_token(nm, stop_char, plen)
char *nm;
int *plen;
{
int ch;
int str_size;
char *str = Malloc((unsigned) (str_size = ISTRSIZE));
int pos = 0;
register int ch;
register int str_size;
register char *str = Malloc((unsigned) (str_size = ISTRSIZE));
register int pos = 0;
ch = GetChar();
while (ch != stop_char) {
@@ -565,7 +562,9 @@ char *string_token(char *nm, int stop_char, int *plen)
return str;
}
int quoted(int ch)
int
quoted(ch)
register int ch;
{
/* quoted() replaces an escaped character sequence by the
character meant.
@@ -624,7 +623,9 @@ int quoted(int ch)
}
int hex_val(int ch)
int
hex_val(ch)
register int ch;
{
return is_dig(ch) ? ch - '0'
: is_hex(ch) ? (ch - 'a' + 10) & 017
@@ -632,12 +633,13 @@ int hex_val(int ch)
}
int GetChar()
int
GetChar()
{
/* The routines GetChar and trigraph parses the trigraph
sequences and removes occurences of \\\n.
*/
int ch;
register int ch;
#ifndef NOPP
again:
@@ -664,9 +666,10 @@ again:
}
#ifndef NOPP
int trigraph()
int
trigraph()
{
int ch;
register int ch;
LoadChar(ch);
if (ch == '?') {
@@ -710,22 +713,24 @@ int trigraph()
/* strflt2tok only checks the syntax of the floating-point number and
* selects the right type for the number.
*/
void strflt2tok(char fltbuf[], struct token *ptok)
strflt2tok(fltbuf, ptok)
char fltbuf[];
struct token *ptok;
{
char *cp = fltbuf;
register char *cp = fltbuf;
int malformed = 0;
while (is_dig(*(unsigned char *)cp)) cp++;
while (is_dig(*cp)) cp++;
if (*cp == '.') {
cp++;
while (is_dig(*(unsigned char *)cp)) cp++;
while (is_dig(*cp)) cp++;
}
if (*cp == 'e' || *cp == 'E') {
cp++;
if (*cp == '+' || *cp == '-')
cp++;
if (!is_dig(*(unsigned char *)cp)) malformed++;
while (is_dig(*(unsigned char *)cp)) cp++;
if (!is_dig(*cp)) malformed++;
while (is_dig(*cp)) cp++;
}
if (*cp == 'f' || *cp == 'F') {
if (*(cp + 1)) malformed++;
@@ -747,9 +752,11 @@ void strflt2tok(char fltbuf[], struct token *ptok)
}
}
void strint2tok(char intbuf[], struct token *ptok)
strint2tok(intbuf, ptok)
char intbuf[];
struct token *ptok;
{
char *cp = intbuf;
register char *cp = intbuf;
int base = 10;
arith val = 0, dig, ubound;
int uns_flg = 0, lng_flg = 0, malformed = 0, ovfl = 0;
@@ -769,8 +776,8 @@ void strint2tok(char intbuf[], struct token *ptok)
*/
ubound = max_arith / (base / 2);
while (is_hex(*(unsigned char *)cp)) {
dig = hex_val(*(unsigned char *)cp);
while (is_hex(*cp)) {
dig = hex_val(*cp);
if (dig >= base) {
malformed++; /* ignore */
}

View File

@@ -1,5 +1,3 @@
#ifndef LANG_CEM_CEMCOM_ANSI_LLLEX_H
#define LANG_CEM_CEMCOM_ANSI_LLLEX_H
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
@@ -13,7 +11,6 @@
*/
#include "file_info.h"
#include "nopp.h"
/* the structure of a token: */
struct token {
@@ -65,21 +62,3 @@ extern int err_occurred; /* "error.c" */
#define ASIDE aside.tk_symb
#define EOF (-1)
/* lang/cem/cemcom.ansi/LLlex.c */
void PushLex(void);
void PopLex(void);
int LLlex(void);
int GetToken(struct token *ptok);
void skipcomment(void);
arith char_constant(char *nm);
char *string_token(char *nm, int stop_char, int *plen);
int quoted(int ch);
int hex_val(int ch);
int GetChar(void);
int trigraph(void);
void strflt2tok(char fltbuf[], struct token *ptok);
void strint2tok(char intbuf[], struct token *ptok);
#endif /* LANG_CEM_CEMCOM_ANSI_LLLEX_H */

View File

@@ -10,14 +10,10 @@
#include "arith.h"
#include "LLlex.h"
#include "Lpars.h"
#include "error.h"
#include <symbol2str.h>
extern char *symbol2str();
void insert_token(int tk);
void LLmessage(tk)
{
LLmessage(tk) {
err_occurred = 1;
if (tk < 0) {
error("end of file expected");
@@ -38,7 +34,8 @@ void LLmessage(tk)
tk_nmb_at_last_syn_err = token_nmb;
}
void insert_token(int tk)
insert_token(tk)
int tk;
{
aside = dot;

View File

@@ -1,5 +1,5 @@
!File: lint.h
/*#define LINT 1*/ /* if defined, 'lint' is produced */
/*#define LINT 1 /* if defined, 'lint' is produced */
!File: pathlength.h
@@ -75,24 +75,24 @@
!File: botch_free.h
/*#define BOTCH_FREE 1*/ /* when defined, botch freed memory, as a check */
/*#define BOTCH_FREE 1 /* when defined, botch freed memory, as a check */
!File: dataflow.h
/*#define DATAFLOW 1*/ /* produce some compile-time xref */
/*#define DATAFLOW 1 /* produce some compile-time xref */
!File: debug.h
/*#define DEBUG 1*/ /* perform various self-tests */
/*#define DEBUG 1 /* perform various self-tests */
#define NDEBUG 1 /* disable assertions */
!File: use_tmp.h
/*#define PREPEND_SCOPES 1*/ /* collect exa, exp, ina and inp commands
/*#define PREPEND_SCOPES 1 /* collect exa, exp, ina and inp commands
and if USE_TMP is defined let them
precede the rest of the generated
compact code */
/*#define USE_TMP 1*/ /* use C_insertpart, C_endpart mechanism
/*#define USE_TMP 1 /* use C_insertpart, C_endpart mechanism
to generate EM-code in the order needed
for the code-generators. If not defined,
the old-style peephole optimizer is
@@ -108,7 +108,7 @@
!File: inputtype.h
/*#define INP_READ_IN_ONE 1*/ /* read input file in one */
/*#define INP_READ_IN_ONE 1 /* read input file in one */
!File: nopp.h
@@ -116,13 +116,13 @@
!File: nobitfield.h
/*#define NOBITFIELD 1*/ /* if NOT defined, implement bitfields */
/*#define NOBITFIELD 1 /* if NOT defined, implement bitfields */
!File: spec_arith.h
/* describes internal compiler arithmetics */
#undef SPECIAL_ARITHMETICS /* something different from native long */
/*#define UNSIGNED_ARITH unsigned arith*/ /* if it is supported */
/*#define UNSIGNED_ARITH unsigned arith /* if it is supported */
!File: static.h
@@ -130,14 +130,14 @@
!File: nocross.h
/*#define NOCROSS 1*/ /* if NOT defined, cross compiler */
/*#define NOCROSS 1 /* if NOT defined, cross compiler */
!File: regcount.h
/*#define REGCOUNT 1*/ /* count occurrences for register messages */
/*#define REGCOUNT 1 /* count occurrences for register messages */
!File: dbsymtab.h
/*#define DBSYMTAB 1*/ /* ability to produce symbol table for debugger */
/*#define DBSYMTAB 1 /* ability to produce symbol table for debugger */

View File

@@ -5,8 +5,7 @@
/* $Id$ */
/* A L I G N M E N T D E F I N I T I O N S */
#include "nocross.h"
#include "trgt_sizes.h"
#include "parameters.h"
#ifndef NOCROSS
extern int

View File

@@ -11,11 +11,8 @@
semantics of C is a mess.
*/
#include "parameters.h"
#include <alloc.h>
#include "debug.h"
#include "lint.h"
#include "nobitfield.h"
#include "idf.h"
#include <flt_arith.h>
#include "arith.h"
#include "sizes.h"
@@ -27,19 +24,15 @@
#include "field.h"
#include "mes.h"
#include "assert.h"
#include "ch3.h"
#include "ch3bin.h"
#include "code_c.h"
#include "conversion.h"
#include "cstoper.h"
#include "expr_loc.h"
#include "error.h"
#include <symbol2str.h>
extern char *symbol2str();
extern char options[];
extern arith flt_flt2arith();
extern label code_string();
void arithbalance(struct expr **e1p, int oper, struct expr **e2p) /* 3.1.2.5 */
arithbalance(e1p, oper, e2p) /* 3.1.2.5 */
register struct expr **e1p, **e2p;
int oper;
{
/* The expressions *e1p and *e2p are balanced to be operands
of the arithmetic operator oper.
@@ -48,16 +41,16 @@ void arithbalance(struct expr **e1p, int oper, struct expr **e2p) /* 3.1.2.5 */
have a floating type, in which case the flags shouldn't
travel upward in the expression tree.
*/
int t1, t2, u1, u2;
register int t1, t2, u1, u2;
int shifting = (oper == LEFT || oper == RIGHT
|| oper == LEFTAB || oper == RIGHTAB);
|| oper == LEFTAB || oper == RIGHTAB);
int ptrdiff = 0;
t1 = any2arith(e1p, oper);
t2 = any2arith(e2p, oper);
if (int_size != pointer_size) {
if ((ptrdiff = ((*e1p)->ex_flags & EX_PTRDIFF))
if (ptrdiff = ((*e1p)->ex_flags & EX_PTRDIFF)
|| ((*e2p)->ex_flags & EX_PTRDIFF)) {
if (!((*e1p)->ex_flags & EX_PTRDIFF) && t1 == LONG)
ptrdiff = 0;
@@ -86,16 +79,10 @@ void arithbalance(struct expr **e1p, int oper, struct expr **e2p) /* 3.1.2.5 */
return;
} else if (t2 == LNGDBL) {
if (t1 != LNGDBL)
{
if (t1 == DOUBLE || t1 == FLOAT)
{
float2float(e1p, lngdbl_type);
}
else
{
int2float(e1p, lngdbl_type);
}
}
if (t1 == DOUBLE || t1 == FLOAT)
float2float(e1p, lngdbl_type);
else
int2float(e1p, lngdbl_type);
return;
}
@@ -183,7 +170,8 @@ void arithbalance(struct expr **e1p, int oper, struct expr **e2p) /* 3.1.2.5 */
}
}
void relbalance(struct expr **e1p, int oper, struct expr **e2p)
relbalance(e1p, oper, e2p)
register struct expr **e1p, **e2p;
{
/* The expressions *e1p and *e2p are balanced to be operands
of the relational operator oper, or the ':'.
@@ -192,7 +180,7 @@ void relbalance(struct expr **e1p, int oper, struct expr **e2p)
allows assignments of a null-pointer to a function
pointer.
*/
struct expr *e1 = *e1p, *e2 = *e2p;
register struct expr *e1 = *e1p, *e2 = *e2p;
struct expr *tmpexpr;
if (e1->ex_type->tp_fund == POINTER
@@ -215,13 +203,15 @@ void relbalance(struct expr **e1p, int oper, struct expr **e2p)
arithbalance(e1p, oper, e2p);
}
void ch3pointer(struct expr **expp, int oper, struct type *tp)
ch3pointer(expp, oper, tp)
struct expr **expp;
register struct type *tp;
{
/* Checks whether *expp may be compared to tp using oper,
as described in chapter 3.3.8 and 3.3.9.
tp is known to be a pointer.
*/
struct expr *exp = *expp;
register struct expr *exp = *expp;
if (exp->ex_type->tp_fund == POINTER) {
if (exp->ex_type != tp)
@@ -246,7 +236,10 @@ void ch3pointer(struct expr **expp, int oper, struct type *tp)
}
}
int any2arith(struct expr **expp, int oper)
int
any2arith(expp, oper)
register struct expr **expp;
register int oper;
{
/* Turns any expression into int_type, long_type,
float_type, double_type or lngdbl_type.
@@ -301,7 +294,8 @@ int any2arith(struct expr **expp, int oper)
return (*expp)->ex_type->tp_fund;
}
void erroneous2int(struct expr **expp)
erroneous2int(expp)
struct expr **expp;
{
/* the (erroneous) expression *expp is replaced by an
int expression
@@ -315,12 +309,16 @@ void erroneous2int(struct expr **expp)
*expp = exp;
}
struct expr *arith2arith(struct type *tp, int oper, struct expr *expr)
struct expr *
arith2arith(tp, oper, expr)
struct type *tp;
int oper;
register struct expr *expr;
{
/* arith2arith constructs a new expression containing a
run-time conversion between some arithmetic types.
*/
struct expr *new = new_expr();
register struct expr *new = new_expr();
new->ex_file = expr->ex_file;
new->ex_line = expr->ex_line;
@@ -329,15 +327,18 @@ struct expr *arith2arith(struct type *tp, int oper, struct expr *expr)
return new_oper(tp, new, oper, expr);
}
int int2int(struct expr **expp, struct type *tp)
int
int2int(expp, tp)
struct expr **expp;
register struct type *tp;
{
/* The expression *expp, which is of some integral type, is
converted to the integral type tp.
*/
struct expr *exp = *expp;
register struct expr *exp = *expp;
if (is_cp_cst(exp)) {
struct type *tp1 = exp->ex_type;
register struct type *tp1 = exp->ex_type;
exp->ex_type = tp;
if (! tp1->tp_unsigned && tp->tp_unsigned) {
@@ -367,12 +368,14 @@ int int2int(struct expr **expp, struct type *tp)
/* With compile-time constants, we don't set fp_used, since this is done
* only when necessary in eval.c.
*/
void int2float(struct expr **expp, struct type *tp)
int2float(expp, tp)
register struct expr **expp;
struct type *tp;
{
/* The expression *expp, which is of some integral type, is
converted to the floating type tp.
*/
struct expr *exp = *expp;
register struct expr *exp = *expp;
int uns = exp->ex_type->tp_unsigned;
if (is_cp_cst(exp)) {
@@ -386,12 +389,14 @@ void int2float(struct expr **expp, struct type *tp)
}
}
void float2int(struct expr **expp, struct type *tp)
float2int(expp, tp)
struct expr **expp;
struct type *tp;
{
/* The expression *expp, which is of some floating type, is
converted to the integral type tp.
*/
struct expr *ex = *expp;
register struct expr *ex = *expp;
if (is_fp_cst(ex)) {
arith ar = flt_flt2arith(&ex->FL_ARITH, tp->tp_unsigned);
@@ -412,7 +417,9 @@ void float2int(struct expr **expp, struct type *tp)
}
}
void float2float(struct expr**expp, struct type *tp)
float2float(expp, tp)
register struct expr **expp;
struct type *tp;
{
/* The expression *expp, which is of some floating type, is
converted to the floating type tp.
@@ -428,7 +435,8 @@ void float2float(struct expr**expp, struct type *tp)
}
}
void array2pointer(struct expr *exp)
array2pointer(exp)
register struct expr *exp;
{
/* The expression, which must be an array, is converted
to a pointer.
@@ -438,7 +446,8 @@ void array2pointer(struct expr *exp)
, (arith)0, NO_PROTO);
}
void function2pointer(struct expr *exp)
function2pointer(exp)
register struct expr *exp;
{
/* The expression, which must be a function, is converted
to a pointer to the function.
@@ -447,7 +456,8 @@ void function2pointer(struct expr *exp)
(arith)0, NO_PROTO);
}
void string2pointer(struct expr *ex)
string2pointer(ex)
register struct expr *ex;
{
/* The expression, which must be a string constant, is converted
to a pointer to the string-containing area.
@@ -461,9 +471,11 @@ void string2pointer(struct expr *ex)
ex->VL_VALUE = (arith)0;
}
void opnd2integral(struct expr **expp, int oper)
opnd2integral(expp, oper)
register struct expr **expp;
int oper;
{
int fund = (*expp)->ex_type->tp_fund;
register int fund = (*expp)->ex_type->tp_fund;
if (fund != INT && fund != LONG) {
expr_error(*expp, "%s operand to %s",
@@ -473,7 +485,9 @@ void opnd2integral(struct expr **expp, int oper)
}
}
void opnd2logical(struct expr **expp, int oper)
opnd2logical(expp, oper)
register struct expr **expp;
int oper;
{
int fund = (*expp)->ex_type->tp_fund;
@@ -509,7 +523,8 @@ void opnd2logical(struct expr **expp, int oper)
}
}
void opnd2test(struct expr **expp, int oper)
opnd2test(expp, oper)
register struct expr **expp;
{
opnd2logical(expp, oper);
if ((*expp)->ex_class == Oper) {
@@ -533,7 +548,8 @@ void opnd2test(struct expr **expp, int oper)
ch3bin(expp, NOTEQUAL, intexpr((arith)0, INT));
}
void any2opnd(struct expr **expp, int oper)
any2opnd(expp, oper)
register struct expr **expp;
{
if (!*expp)
return;
@@ -544,9 +560,7 @@ void any2opnd(struct expr **expp, int oper)
case CHAR:
case SHORT:
case ENUM:
#if 0
case FLOAT: /* not necessary anymore */
#endif
/* case FLOAT: /* not necessary anymore */
any2arith(expp, oper);
break;
case ARRAY:
@@ -567,7 +581,8 @@ void any2opnd(struct expr **expp, int oper)
}
}
void any2parameter(struct expr **expp)
any2parameter(expp)
register struct expr **expp;
{
/* To handle default argument promotions
*/
@@ -580,13 +595,14 @@ void any2parameter(struct expr **expp)
}
#ifndef NOBITFIELD
void field2arith(struct expr **expp)
field2arith(expp)
register struct expr **expp;
{
/* The expression to extract the bitfield value from the
memory word is put in the tree.
*/
struct type *tp = (*expp)->ex_type->tp_up;
struct field *fd = (*expp)->ex_type->tp_field;
register struct type *tp = (*expp)->ex_type->tp_up;
register struct field *fd = (*expp)->ex_type->tp_field;
(*expp)->ex_type = word_type;
@@ -611,7 +627,8 @@ void field2arith(struct expr **expp)
/* switch_sign_fp() negates the given floating constant expression,
* and frees the string representing the old value.
*/
void switch_sign_fp(struct expr *expr)
switch_sign_fp(expr)
register struct expr *expr;
{
flt_umin(&(expr->FL_ARITH));
}

View File

@@ -1,5 +1,3 @@
#ifndef LANG_CEM_CEMCOM_ANSI_ARITH_H
#define LANG_CEM_CEMCOM_ANSI_ARITH_H
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
@@ -15,7 +13,7 @@
be handy.
*/
#include "spec_arith.h"
#include "parameters.h"
#ifndef SPECIAL_ARITHMETICS
@@ -25,40 +23,10 @@
/* All preprocessor arithmetic should be done in longs.
*/
#include <stdint.h>
typedef int32_t arith; /* dummy */
#define arith long /* dummy */
#endif /* SPECIAL_ARITHMETICS */
#define arith_size (sizeof(arith))
#define arith_sign ((arith) 1 << (arith_size * 8 - 1))
#define max_arith (~arith_sign)
struct expr;
struct type;
/* lang/cem/cemcom.ansi/arith.c */
void arithbalance(struct expr **e1p, int oper, struct expr **e2p);
void relbalance(struct expr **e1p, int oper, struct expr **e2p);
void ch3pointer(struct expr **expp, int oper, struct type *tp);
int any2arith(struct expr **expp, int oper);
void erroneous2int(struct expr **expp);
struct expr *arith2arith(struct type *tp, int oper, struct expr *expr);
int int2int(struct expr **expp, struct type *tp);
void int2float(struct expr **expp, struct type *tp);
void float2int(struct expr **expp, struct type *tp);
void float2float(struct expr **expp, struct type *tp);
void array2pointer(struct expr *exp);
void function2pointer(struct expr *exp);
void string2pointer(struct expr *ex);
void opnd2integral(struct expr **expp, int oper);
void opnd2logical(struct expr **expp, int oper);
void opnd2test(struct expr **expp, int oper);
void any2opnd(struct expr **expp, int oper);
void any2parameter(struct expr **expp);
void field2arith(struct expr **expp);
void switch_sign_fp(struct expr *expr);
#endif /* LANG_CEM_CEMCOM_ANSI_ARITH_H */

View File

@@ -1,5 +1,6 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Id$ */
@@ -10,7 +11,8 @@
there is no reasonable method to prove that a program is 100%
correct, these assertions are needed in some places.
*/
#include "debug.h" /* UF */
#include "parameters.h"
#ifdef DEBUG
/* Note: this macro uses parameter substitution inside strings */

View File

@@ -5,7 +5,7 @@
/* $Id$ */
/* B L O C K S T O R I N G A N D L O A D I N G */
#include "lint.h"
#include "parameters.h"
#ifndef LINT
#include <em.h>
@@ -18,16 +18,9 @@
#include "label.h"
#include "stack.h"
#include "Lpars.h"
#include "util_loc.h"
#include "error.h"
#include "idf_loc.h"
#include "def.h"
extern arith NewLocal();
#define LocalPtrVar() NewLocal(pointer_size, pointer_align, reg_pointer, REGISTER)
#define LocalIntVar() NewLocal(int_size, int_align, reg_any, REGISTER)
static void copy_loop(arith sz, arith src, arith dst);
#endif /* STB */
/* Because EM does not support the loading and storing of
@@ -59,7 +52,9 @@ static void copy_loop(arith sz, arith src, arith dst);
while we need a loop to store the stack block into a memory object.
*/
static int suitable_sz(arith sz, int al)
suitable_sz(sz, al)
arith sz;
int al;
{
return ((int)sz % (int)word_size == 0 && al % word_align == 0) ||
(
@@ -69,7 +64,9 @@ static int suitable_sz(arith sz, int al)
);
}
void store_block(arith sz, int al)
store_block(sz, al)
arith sz;
int al;
{
if (suitable_sz(sz, al))
C_sti(sz);
@@ -105,7 +102,9 @@ void store_block(arith sz, int al)
}
}
void load_block(arith sz, int al)
load_block(sz, al)
arith sz;
int al;
{
if (suitable_sz(sz, al))
@@ -139,7 +138,9 @@ void load_block(arith sz, int al)
}
}
void copy_block(arith sz, int al)
copy_block(sz, al)
arith sz;
int al;
{
if (suitable_sz(sz, al))
@@ -166,7 +167,8 @@ void copy_block(arith sz, int al)
}
#ifndef STB
static void copy_loop(arith sz, arith src, arith dst)
copy_loop(sz, src, dst)
arith sz, src, dst;
{
/* generate inline byte-copy loop */
label l_cont = text_label(), l_stop = text_label();

View File

@@ -1,8 +0,0 @@
#ifndef LANG_CEM_CEMCOM_ANSI_BLOCKS_H
#define LANG_CEM_CEMCOM_ANSI_BLOCKS_H
void store_block(arith sz, int al);
void load_block(arith sz, int al);
void copy_block(arith sz, int al);
#endif

View File

@@ -0,0 +1,156 @@
D := lang/cem/cemcom.ansi
define build-cemcom-ansi-allocd-header
$(eval g := $(OBJDIR)/$D/$(strip $1).h)
$g: $D/$(strip $1).str $D/make.allocd
@echo ALLOCD $$@
@mkdir -p $$(dir $$@)
$(hide) $D/make.allocd < $$^ > $$@
$(eval CLEANABLES += $g)
$(eval $q: $g)
endef
define build-cemcom-ansi-next
$(eval CLEANABLES += $(OBJDIR)/$D/next.c)
$(OBJDIR)/$D/next.c: $D/make.next $1
@echo NEXT $$@
@mkdir -p $$(dir $$@)
$(hide) $$^ > $$@
$(call cfile, $(OBJDIR)/$D/next.c)
$(foreach f, $1, $(call build-cemcom-ansi-allocd-header, \
$(basename $(notdir $f))))
endef
define build-cemcom-ansi-impl
$(call reset)
$(eval cflags += -I$(OBJDIR)/$D -I$D)
$(call cfile, $D/arith.c)
$(call dependson, $(INCDIR)/flt_arith.h)
$(call cfile, $D/blocks.c)
$(call dependson, $(INCDIR)/em_codeEK.h)
$(call cfile, $D/LLlex.c)
$(call cfile, $D/LLmessage.c)
$(call cfile, $D/ch3.c)
$(call cfile, $D/ch3bin.c)
$(call cfile, $D/ch3mon.c)
$(call cfile, $D/code.c)
$(call cfile, $D/conversion.c)
$(call cfile, $D/cstoper.c)
$(call cfile, $D/dataflow.c)
$(call cfile, $D/declarator.c)
$(call cfile, $D/decspecs.c)
$(call cfile, $D/domacro.c)
$(call cfile, $D/dumpidf.c)
$(call cfile, $D/error.c)
$(call cfile, $D/eval.c)
$(call cfile, $D/expr.c)
$(call cfile, $D/field.c)
$(call cfile, $D/fltcstoper.c)
$(call cfile, $D/idf.c)
$(call cfile, $D/init.c)
$(call cfile, $D/input.c)
$(call cfile, $D/l_comment.c)
$(call cfile, $D/l_ev_ord.c)
$(call cfile, $D/l_lint.c)
$(call cfile, $D/l_misc.c)
$(call cfile, $D/l_outdef.c)
$(call cfile, $D/l_states.c)
$(call cfile, $D/label.c)
$(call cfile, $D/main.c)
$(call cfile, $D/options.c)
$(call cfile, $D/pragma.c)
$(call cfile, $D/proto.c)
$(call cfile, $D/replace.c)
$(call cfile, $D/skip.c)
$(call cfile, $D/stab.c)
$(call cfile, $D/stack.c)
$(call cfile, $D/struct.c)
$(call cfile, $D/switch.c)
$(call cfile, $D/tokenname.c)
$(call cfile, $D/type.c)
$(call cfile, $D/util.c)
$(call llgen, $(OBJDIR)/$D, \
$(OBJDIR)/$D/tokenfile.g \
$D/program.g \
$D/declar.g \
$D/expression.g \
$D/statement.g \
$D/ival.g)
$(eval CLEANABLES += $(OBJDIR)/$D/tokenfile.g)
$(OBJDIR)/$D/tokenfile.g: $D/make.tokfile $D/tokenname.c
@echo TOKENFILE $$@
@mkdir -p $$(dir $$@)
$(hide) sh $D/make.tokfile < $D/tokenname.c > $$@
$(call tabgen, $D/char.tab)
$(eval $q: $(OBJDIR)/$D/parameters.h)
$(eval CLEANABLES += $(OBJDIR)/$D/parameters.h)
$(OBJDIR)/$D/parameters.h: $D/BigPars
@echo PARAMETERS $$@
@mkdir -p $$(dir $$@)
$(hide) echo '#ifndef PARAMETERS_H' > $$@
$(hide) echo '#define PARAMETERS_H' >> $$@
$(hide) grep -v '^!' < $D/BigPars >> $$@
$(hide) echo '#endif' >> $$@
$(eval CLEANABLES += $(OBJDIR)/$D/symbol2str.c)
$(OBJDIR)/$D/symbol2str.c: $D/make.tokcase $D/tokenname.c
@echo TOKCASE $$@
@mkdir -p $$(dir $$@)
$(hide) $D/make.tokcase < $D/tokenname.c > $$@
$(call cfile, $(OBJDIR)/$D/symbol2str.c)
$(call build-cemcom-ansi-next, \
$D/code.str \
$D/declar.str \
$D/def.str \
$D/expr.str \
$D/field.str \
$D/estack.str \
$D/util.str \
$D/proto.str \
$D/replace.str \
$D/idf.str \
$D/macro.str \
$D/stack.str \
$D/stmt.str \
$D/struct.str \
$D/switch.str \
$D/type.str \
$D/l_brace.str \
$D/l_state.str \
$D/l_outdef.str)
$(eval $q: $(OBJDIR)/$D/Lpars.h)
$(call file, $(LIBEM_MES))
$(call file, $(LIBEMK))
$(call file, $(LIBEM_DATA))
$(call file, $(LIBINPUT))
$(call file, $(LIBASSERT))
$(call file, $(LIBALLOC))
$(call file, $(LIBFLT_ARITH))
$(call file, $(LIBPRINT))
$(call file, $(LIBSYSTEM))
$(call file, $(LIBSTRING))
$(call cprogram, $(BINDIR)/cemcom.ansi)
$(call installto, $(PLATDEP)/em_cemcom.ansi)
$(eval CEMCOMANSI := $o)
$(call reset)
$(eval q := $D/cemcom.ansi.1)
$(call installto, $(INSDIR)/share/man/man1/cemcom.6)
endef
$(eval $(build-cemcom-ansi-impl))

View File

@@ -5,12 +5,10 @@
/* $Id$ */
/* S E M A N T I C A N A L Y S I S -- C H A P T E R 3.3 */
#include "debug.h"
#include "lint.h"
#include "nobitfield.h"
#include "idf.h"
#include "parameters.h"
#include <flt_arith.h>
#include "arith.h"
#include "idf.h"
#include "proto.h"
#include "type.h"
#include "struct.h"
@@ -20,35 +18,26 @@
#include "Lpars.h"
#include "assert.h"
#include "file_info.h"
#include "ch3.h"
#include "ch3bin.h"
#include "decspecs.h"
#include "conversion.h"
#include "error.h"
#include "idf_loc.h"
#include "expr_loc.h"
#include <symbol2str.h>
extern char options[];
static int check_pseudoproto(struct proto *pl, struct proto *opl, int diag);
static int legal_mixture(struct type *tp, struct type *otp, int diag);
static int equal_proto(struct proto *pl, struct proto *opl, int diag);
static int is_arith_type(struct type *tp);
extern char *symbol2str();
extern struct type *qualifier_type();
/* Most expression-handling routines have a pointer to a
(struct type *) as first parameter. The object under the pointer
gets updated in the process.
*/
void ch3sel(struct expr **expp, int oper, struct idf *idf)
ch3sel(expp, oper, idf)
struct expr **expp;
struct idf *idf;
{
/* The selector idf is applied to *expp; oper may be '.' or
ARROW.
*/
struct expr *exp;
struct type *tp;
struct sdef *sd;
register struct expr *exp;
register struct type *tp;
register struct sdef *sd;
any2opnd(expp, oper);
exp = *expp;
@@ -171,7 +160,8 @@ void ch3sel(struct expr **expp, int oper, struct idf *idf)
*expp = exp;
}
void ch3incr(struct expr **expp, int oper)
ch3incr(expp, oper)
struct expr **expp;
{
/* The monadic prefix/postfix incr/decr operator oper is
applied to *expp.
@@ -179,15 +169,17 @@ void ch3incr(struct expr **expp, int oper)
ch3asgn(expp, oper, intexpr((arith)1, INT));
}
void ch3cast(struct expr **expp, int oper, struct type *tp)
ch3cast(expp, oper, tp)
register struct expr **expp;
register struct type *tp;
{
/* The expression *expp is cast to type tp; the cast is
caused by the operator oper. If the cast has
to be passed on to run time, its left operand will be an
expression of class Type.
*/
struct type *oldtp;
struct expr *exp = *expp;
register struct type *oldtp;
register struct expr *exp = *expp;
int qual_lev, ascompat = 0;
if (oper == RETURN && tp->tp_fund == VOID) {
@@ -416,7 +408,9 @@ void ch3cast(struct expr **expp, int oper, struct type *tp)
/* Determine whether two types are equal.
*/
int equal_type(struct type *tp, struct type *otp, int qual_lev, int diag)
equal_type(tp, otp, qual_lev, diag)
register struct type *tp, *otp;
int qual_lev, diag;
{
if (tp == otp)
return 1;
@@ -477,7 +471,8 @@ int equal_type(struct type *tp, struct type *otp, int qual_lev, int diag)
}
}
static int check_pseudoproto(struct proto *pl, struct proto *opl, int diag)
check_pseudoproto(pl, opl, diag)
register struct proto *pl, *opl;
{
int retval = 1;
@@ -520,11 +515,13 @@ static int check_pseudoproto(struct proto *pl, struct proto *opl, int diag)
return retval;
}
static int legal_mixture(struct type *tp, struct type *otp, int diag)
legal_mixture(tp, otp, diag)
struct type *tp, *otp;
int diag;
{
struct proto *pl = tp->tp_proto, *opl = otp->tp_proto;
int retval = 1;
struct proto *prot;
register struct proto *prot;
int fund;
ASSERT( (pl != 0) ^ (opl != 0));
@@ -561,7 +558,9 @@ static int legal_mixture(struct type *tp, struct type *otp, int diag)
return retval;
}
static int equal_proto(struct proto *pl, struct proto *opl, int diag)
equal_proto(pl, opl, diag)
register struct proto *pl, *opl;
int diag;
{
if (pl == opl)
return 1;
@@ -583,9 +582,11 @@ static int equal_proto(struct proto *pl, struct proto *opl, int diag)
}
/* check if a type has a consqualified member */
int recurqual(struct type *tp, int qual)
recurqual(tp, qual)
struct type *tp;
int qual;
{
struct sdef *sdf;
register struct sdef *sdf;
ASSERT(tp);
@@ -605,7 +606,9 @@ int recurqual(struct type *tp, int qual)
return 0;
}
void ch3asgn(struct expr **expp, int oper, struct expr *expr)
ch3asgn(expp, oper, expr)
struct expr **expp;
struct expr *expr;
{
/* The assignment operators.
"f op= e" should be interpreted as
@@ -620,7 +623,7 @@ void ch3asgn(struct expr **expp, int oper, struct expr *expr)
f (typeof (f op e))e
EVAL should however take care of evaluating (typeof (f op e))f
*/
struct expr *exp = *expp;
register struct expr *exp = *expp;
int fund = exp->ex_type->tp_fund;
struct type *tp;
char *oper_string = symbol2str(oper);
@@ -680,7 +683,9 @@ void ch3asgn(struct expr **expp, int oper, struct expr *expr)
/* Some interesting (?) questions answered.
*/
int is_integral_type(struct type *tp)
int
is_integral_type(tp)
register struct type *tp;
{
switch (tp->tp_fund) {
case CHAR:
@@ -698,7 +703,9 @@ int is_integral_type(struct type *tp)
}
}
static int is_arith_type(struct type *tp)
int
is_arith_type(tp)
register struct type *tp;
{
switch (tp->tp_fund) {
case CHAR:

View File

@@ -1,17 +0,0 @@
/*
* The Amsterdam Compiler Kit
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef LANG_CEM_CEMCOM_ANSI_CH3_H
#define LANG_CEM_CEMCOM_ANSI_CH3_H
void ch3cast(struct expr **expp, int oper, struct type *tp);
void ch3sel(struct expr **expp, int oper, struct idf *idf);
void ch3incr(struct expr **expp, int oper);
int equal_type(struct type *tp, struct type *otp, int qual_lev, int diag);
int recurqual(struct type *tp, int qual);
void ch3asgn(struct expr **expp, int oper, struct expr *expr);
int is_integral_type(struct type *tp);
#endif

View File

@@ -5,11 +5,8 @@
/* $Id$ */
/* SEMANTIC ANALYSIS (CHAPTER 3.3) -- BINARY OPERATORS */
#include "botch_free.h"
#include "debug.h"
#include "parameters.h"
#include <alloc.h>
#include "lint.h"
#include "idf.h"
#include <flt_arith.h>
#include "arith.h"
#include "type.h"
@@ -18,24 +15,9 @@
#include "expr.h"
#include "Lpars.h"
#include "sizes.h"
#include "ch3.h"
#include "ch3bin.h"
#include "ch3mon.h"
#include "cstoper.h"
#include "error.h"
#include "expr_loc.h"
#include "struct_loc.h"
#include "fltcstoper.h"
#include <symbol2str.h>
extern char options[];
static void pntminuspnt(struct expr **expp, int oper, struct expr *expr);
static int arg_switched(int oper);
static void mk_binop(struct expr **expp, int oper, struct expr *expr, int commutative);
static void pointer_arithmetic(struct expr **expp1, int oper, struct expr **expp2);
static void pointer_binary(struct expr **expp, int oper, struct expr *expr);
extern char *symbol2str();
/* This chapter asks for the repeated application of code to handle
an operation that may be executed at compile time or at run time,
@@ -50,7 +32,9 @@ static void pointer_binary(struct expr **expp, int oper, struct expr *expr);
#define commutative_binop(expp, oper, expr) mk_binop(expp, oper, expr, 1)
#define non_commutative_relop(expp, oper, expr) mk_binop(expp, oper, expr, 1)
void ch3bin(struct expr **expp, int oper, struct expr *expr)
ch3bin(expp, oper, expr)
register struct expr **expp;
struct expr *expr;
{
/* apply binary operator oper between *expp and expr.
NB: don't swap operands if op is one of the op= operators!!!
@@ -308,7 +292,8 @@ void ch3bin(struct expr **expp, int oper, struct expr *expr)
}
}
static void pntminuspnt(struct expr **expp, int oper, struct expr *expr)
pntminuspnt(expp, oper, expr)
register struct expr **expp, *expr;
{
/* Subtracting two pointers is so complicated it merits a
routine of its own.
@@ -339,7 +324,8 @@ static void pntminuspnt(struct expr **expp, int oper, struct expr *expr)
* when the arguments are switched. This is special for some relational
* operators.
*/
static int arg_switched(int oper)
int
arg_switched(oper)
{
switch (oper) {
case '<': return '>';
@@ -350,7 +336,9 @@ static int arg_switched(int oper)
}
}
static void mk_binop(struct expr **expp, int oper, struct expr *expr, int commutative)
mk_binop(expp, oper, expr, commutative)
struct expr **expp;
register struct expr *expr;
{
/* Constructs in *expp the operation indicated by the operands.
"commutative" indicates whether "oper" is a commutative
@@ -374,7 +362,8 @@ static void mk_binop(struct expr **expp, int oper, struct expr *expr, int commut
}
}
static void pointer_arithmetic(struct expr **expp1, int oper, struct expr **expp2)
pointer_arithmetic(expp1, oper, expp2)
register struct expr **expp1, **expp2;
{
int typ;
/* prepares the integral expression expp2 in order to
@@ -394,7 +383,8 @@ static void pointer_arithmetic(struct expr **expp1, int oper, struct expr **expp
);
}
static void pointer_binary(struct expr **expp, int oper, struct expr *expr)
pointer_binary(expp, oper, expr)
register struct expr **expp, *expr;
{
/* constructs the pointer arithmetic expression out of
a pointer expression, a binary operator and an integral

View File

@@ -1,11 +0,0 @@
/*
* The Amsterdam Compiler Kit
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef LANG_CEM_CEMCOM_ANSI_CH3BIN_H
#define LANG_CEM_CEMCOM_ANSI_CH3BIN_H
void ch3bin(struct expr **expp, int oper, struct expr *expr);
#endif

View File

@@ -5,35 +5,24 @@
/* $Id$ */
/* SEMANTIC ANALYSIS (CHAPTER 3.3) -- MONADIC OPERATORS */
#include "botch_free.h"
#include "debug.h"
#include "parameters.h"
#include <alloc.h>
#include "nobitfield.h"
#include "Lpars.h"
#include <flt_arith.h>
#include "idf.h"
#include "arith.h"
#include "type.h"
#include "label.h"
#include "expr.h"
#include "idf.h"
#include "def.h"
#include "sizes.h"
#include "ch3.h"
#include "ch3mon.h"
#include "error.h"
#include "expr_loc.h"
#include "stab.h"
#include "util.h"
#include "struct_loc.h"
#include "dataflow.h"
#include <symbol2str.h>
extern char options[];
extern arith full_mask[/*MAXSIZE + 1*/]; /* cstoper.c */
char *symbol2str();
void ch3mon(int oper, struct expr **expp)
ch3mon(oper, expp)
register struct expr **expp;
{
/* The monadic prefix operator oper is applied to *expp.
*/

View File

@@ -1,11 +0,0 @@
/*
* The Amsterdam Compiler Kit
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef LANG_CEM_CEMCOM_ANSI_CH3MON_H
#define LANG_CEM_CEMCOM_ANSI_CH3MON_H
void ch3mon(int oper, struct expr **expp);
#endif

View File

@@ -7,23 +7,18 @@
#include <stdlib.h>
#include <string.h>
#include "lint.h"
#include "debug.h"
#include "dbsymtab.h"
#include "parameters.h"
#ifndef LINT
#include <em.h>
#else
#include "l_em.h"
#include "l_lint.h"
#endif /* LINT */
#include "botch_free.h"
#include <alloc.h>
#include "dataflow.h"
#include "use_tmp.h"
#include <flt_arith.h>
#include "idf.h"
#include "arith.h"
#include "type.h"
#include "idf.h"
#include "label.h"
#include "code.h"
#include "stmt.h"
@@ -40,21 +35,6 @@
#include "assert.h"
#include "LLlex.h"
#include "align.h"
#include "blocks.h"
#include "code_c.h"
#include "conversion.h"
#include "util_loc.h"
#include "stab.h"
#include "error.h"
#include "struct_loc.h"
#include "ch3.h"
#include "idf_loc.h"
#include "expr_loc.h"
#include "ival.h"
#include "eval.h"
#include <symbol2str.h>
#ifdef LINT
#include "l_lint.h"
#endif /* LINT */
@@ -66,6 +46,7 @@ label lab_count = 1;
label datlab_count = 1;
int fp_used;
extern arith NewLocal(); /* util.c */
/* global function info */
char *func_name;
@@ -80,14 +61,12 @@ static int pro_id;
#endif /* USE_TMP */
extern char options[];
extern char *symbol2str();
extern char *source;
static void def_strings(struct string_cst *sc);
static void prc_entry(char *name);
static void prc_exit();
#ifndef LINT
void init_code(char *dst_file)
init_code(dst_file)
char *dst_file;
{
/* init_code() initialises the output file on which the
compact EM code is written
@@ -124,7 +103,10 @@ void init_code(char *dst_file)
struct string_cst *str_list = 0;
label code_string(char *val, int len)
label
code_string(val, len)
char *val;
int len;
{
register struct string_cst *sc = new_string_cst();
label dlb = data_label();
@@ -138,7 +120,8 @@ label code_string(char *val, int len)
return dlb;
}
static void def_strings(struct string_cst *sc)
def_strings(sc)
register struct string_cst *sc;
{
while (sc) {
struct string_cst *sc1 = sc;
@@ -152,8 +135,7 @@ static void def_strings(struct string_cst *sc)
}
/* flush_strings() is called from program.g after each external definition */
void flush_strings()
{
flush_strings() {
if (str_list) {
def_strings(str_list);
str_list = 0;
@@ -161,7 +143,7 @@ void flush_strings()
}
#ifndef LINT
void end_code()
end_code()
{
/* end_code() performs the actions to be taken when closing
the output stream.
@@ -176,19 +158,19 @@ void end_code()
#endif /* LINT */
#ifdef PREPEND_SCOPES
void prepend_scopes()
prepend_scopes()
{
/* prepend_scopes() runs down the list of global idf's
and generates those exa's, exp's, ina's and inp's
that superior hindsight has provided.
*/
struct stack_entry *se = local_level->sl_entry;
register struct stack_entry *se = local_level->sl_entry;
#ifdef USE_TMP
C_beginpart(tmp_id);
#endif /* USE_TMP */
while (se != 0) {
struct def *df = se->se_idf->id_def;
register struct def *df = se->se_idf->id_def;
if (df && (df->df_initialized || df->df_used || df->df_alloc)) {
code_scope(se->se_idf->id_text, df);
@@ -201,7 +183,9 @@ void prepend_scopes()
}
#endif /* PREPEND_SCOPES */
void code_scope(char *text, struct def *def)
code_scope(text, def)
char *text;
register struct def *def;
{
/* generates code for one name, text, of the storage class
as given by def, if meaningful.
@@ -232,8 +216,9 @@ static int struct_return;
static char *last_fn_given = (char *)0;
static label file_name_label;
/* to be called when entering a procedure */
void begin_proc(struct decspecs *ds, struct idf *idf)
begin_proc(ds, idf) /* to be called when entering a procedure */
struct decspecs *ds;
struct idf *idf;
{
/* begin_proc() is called at the entrance of a new function
and performs the necessary code generation:
@@ -243,8 +228,8 @@ void begin_proc(struct decspecs *ds, struct idf *idf)
does not fit in the return area
- a fil pseudo instruction
*/
char *name = idf->id_text;
struct def *def = idf->id_def;
register char *name = idf->id_text;
register struct def *def = idf->id_def;
/* idf->id_def does not indicate the right def structure
* when the function being defined has a parameter of the
@@ -330,7 +315,8 @@ void begin_proc(struct decspecs *ds, struct idf *idf)
#endif
}
void end_proc(arith fbytes)
end_proc(fbytes)
arith fbytes;
{
/* end_proc() deals with the code to be generated at the end of
a function, as there is:
@@ -400,7 +386,7 @@ void end_proc(arith fbytes)
options['n'] = optionsn;
}
void do_return()
do_return()
{
/* do_return handles the case of a return without expression.
This version branches to the return label, which is
@@ -413,7 +399,8 @@ void do_return()
C_bra(return2_label);
}
void do_return_expr(struct expr *expr)
do_return_expr(expr)
struct expr *expr;
{
/* do_return_expr() generates the expression and the jump for
a return statement with an expression.
@@ -428,12 +415,11 @@ void do_return_expr(struct expr *expr)
return_expr_occurred = 1;
}
/* struct idf *idf idf to be declared
* struct expr *expr initialisation; NULL if absent
* int lvl declaration level
* int sc storage class, as in the declaration
*/
void code_declaration(struct idf *idf, struct expr *expr, int lvl, int sc)
code_declaration(idf, expr, lvl, sc)
register struct idf *idf; /* idf to be declared */
struct expr *expr; /* initialisation; NULL if absent */
int lvl; /* declaration level */
int sc; /* storage class, as in the declaration */
{
/* code_declaration() does the actual declaration of the
variable indicated by "idf" on declaration level "lvl".
@@ -454,8 +440,8 @@ void code_declaration(struct idf *idf, struct expr *expr, int lvl, int sc)
The sc is the actual storage class, as given in the
declaration.
*/
struct def *def = idf->id_def;
arith size = def->df_type->tp_size;
register struct def *def = idf->id_def;
register arith size = def->df_type->tp_size;
int fund = def->df_type->tp_fund;
int def_sc = def->df_sc;
@@ -541,15 +527,17 @@ void code_declaration(struct idf *idf, struct expr *expr, int lvl, int sc)
}
}
void loc_init(struct expr *expr, struct idf *id)
loc_init(expr, id)
struct expr *expr;
struct idf *id;
{
/* loc_init() generates code for the assignment of
expression expr to the local variable described by id.
It frees the expression afterwards.
*/
struct expr *e = expr;
struct def *df = id->id_def;
struct type *tp = df->df_type;
register struct expr *e = expr;
register struct def *df = id->id_def;
register struct type *tp = df->df_type;
static arith tmpoffset = 0;
static arith unknownsize = 0;
@@ -617,11 +605,12 @@ void loc_init(struct expr *expr, struct idf *id)
}
}
void bss(struct idf *idf)
bss(idf)
register struct idf *idf;
{
/* bss() allocates bss space for the global idf.
*/
struct def *df = idf->id_def;
register struct def *df = idf->id_def;
#ifndef PREPEND_SCOPES
code_scope(idf->id_text, df);
@@ -647,13 +636,15 @@ void bss(struct idf *idf)
}
}
void formal_cvt(int hasproto, struct def *df)
formal_cvt(hasproto,df)
int hasproto;
register struct def *df;
{
/* formal_cvt() converts a formal parameter of type char or
short from int to that type. It also converts a formal
parameter of type float from a double to a float.
*/
struct type *tp = df->df_type;
register struct type *tp = df->df_type;
if (tp->tp_size != int_size &&
(tp->tp_fund == CHAR || tp->tp_fund == SHORT)
@@ -677,7 +668,9 @@ void formal_cvt(int hasproto, struct def *df)
#ifdef LINT
/*ARGSUSED*/
#endif /* LINT */
void code_expr(struct expr *expr, int val, int code, label tlbl, label flbl)
code_expr(expr, val, code, tlbl, flbl)
struct expr *expr;
label tlbl, flbl;
{
/* code_expr() is the parser's interface to the expression code
generator. If line number trace is wanted, it generates a
@@ -710,9 +703,9 @@ static struct stmt_block *stmt_stack; /* top of statement stack */
which are the only ones that are stacked, only the top of
the stack is interesting.
*/
void code_break()
code_break()
{
struct stmt_block *stmt_block = stmt_stack;
register struct stmt_block *stmt_block = stmt_stack;
#ifdef DBSYMTAB
if (options['g']) db_line(dot.tk_file, dot.tk_line);
@@ -728,9 +721,9 @@ void code_break()
it generates a branch instruction to the continue label of the
innermost statement in which continue has a meaning.
*/
void code_continue()
code_continue()
{
struct stmt_block *stmt_block = stmt_stack;
register struct stmt_block *stmt_block = stmt_stack;
while (stmt_block) {
if (stmt_block->st_continue) {
@@ -745,9 +738,10 @@ void code_continue()
error("continue not inside for, while or do");
}
void stack_stmt(label break_label, label cont_label)
stack_stmt(break_label, cont_label)
label break_label, cont_label;
{
struct stmt_block *stmt_block = new_stmt_block();
register struct stmt_block *stmt_block = new_stmt_block();
stmt_block->next = stmt_stack;
stmt_block->st_break = break_label;
@@ -755,7 +749,7 @@ void stack_stmt(label break_label, label cont_label)
stmt_stack = stmt_block;
}
void unstack_stmt()
unstack_stmt()
{
/* unstack_stmt() unstacks the data of a statement
which may contain break or continue
@@ -767,7 +761,8 @@ void unstack_stmt()
static label prc_name;
static void prc_entry(char *name)
prc_entry(name)
char *name;
{
if (options['p']) {
C_df_dlb(prc_name = data_label());
@@ -778,7 +773,7 @@ static void prc_entry(char *name)
}
}
static void prc_exit()
prc_exit()
{
if (options['p']) {
C_lae_dlb(prc_name, (arith) 0);
@@ -788,7 +783,9 @@ static void prc_exit()
}
#ifdef DBSYMTAB
void db_line(char *file, unsigned int line)
db_line(file, line)
char *file;
unsigned int line;
{
static unsigned oldline;
static char *oldfile;

View File

@@ -1,42 +0,0 @@
/*
* The Amsterdam Compiler Kit
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef LANG_CEM_CEMCOM_ANSI_CODE_H
#define LANG_CEM_CEMCOM_ANSI_CODE_H
struct decspecs;
void init_code(char *dst_file);
label code_string(char *val, int len);
void flush_strings();
void code_scope(char *text, struct def *def);
void begin_proc(struct decspecs *ds, struct idf *idf);
void end_proc(arith fbytes);
void do_return();
void do_return_expr(struct expr *expr);
void code_declaration(struct idf *idf, struct expr *expr, int lvl, int sc);
void loc_init(struct expr *expr, struct idf *id);
void bss(struct idf *idf);
void code_expr(struct expr *expr, int val, int code, label tlbl, label flbl);
void code_break();
void code_continue();
void stack_stmt(label break_label, label cont_label);
void unstack_stmt();
void formal_cvt(int hasproto, struct def *df);
#ifdef DBSYMTAB
void db_line(char *file, unsigned int line);
#endif
#ifdef PREPEND_SCOPES
void prepend_scopes();
#endif
#ifndef LINT
void end_code();
#endif
#endif

View File

@@ -5,7 +5,7 @@
/* $Id$ */
/* C O N V E R S I O N - C O D E G E N E R A T O R */
#include "lint.h"
#include "parameters.h"
#ifndef LINT
#include <em.h>
@@ -13,7 +13,6 @@
#include "type.h"
#include "sizes.h"
#include "Lpars.h"
#include "error.h"
#define T_SIGNED 1
#define T_UNSIGNED 2
@@ -28,12 +27,13 @@
C??
*/
static int convtype(struct type *tp);
static int convtype();
void conversion(struct type *from_type, struct type *to_type)
conversion(from_type, to_type)
register struct type *from_type, *to_type;
{
arith from_size = from_type->tp_size;
arith to_size = to_type->tp_size;
register arith from_size = from_type->tp_size;
register arith to_size = to_type->tp_size;
int from_cnvtype = convtype(from_type);
int to_cnvtype = convtype(to_type);
@@ -126,7 +126,9 @@ void conversion(struct type *from_type, struct type *to_type)
/* convtype() returns in which category a given type falls:
signed, unsigned or floating
*/
static int convtype(struct type *tp)
static int
convtype(tp)
register struct type *tp;
{
switch (tp->tp_fund) {
case CHAR:

View File

@@ -1,8 +0,0 @@
#ifndef LANG_CEM_CEMCOM_ANSI_CONVERSION_H
#define LANG_CEM_CEMCOM_ANSI_CONVERSION_H
struct type;
void conversion(struct type *from_type, struct type *to_type);
#endif

View File

@@ -5,8 +5,7 @@
/* $Id$ */
/* C O N S T A N T E X P R E S S I O N H A N D L I N G */
#include "trgt_sizes.h"
#include "idf.h"
#include "parameters.h"
#include <flt_arith.h>
#include "arith.h"
#include "type.h"
@@ -15,9 +14,6 @@
#include "sizes.h"
#include "Lpars.h"
#include "assert.h"
#include "cstoper.h"
#include "error.h"
#include "expr_loc.h"
/* full_mask[1] == 0XFF, full_mask[2] == 0XFFFF, .. */
arith full_mask[MAXSIZE + 1];
@@ -27,14 +23,15 @@ arith max_unsigned; /* maximum unsigned on target machine */
#endif /* NOCROSS */
extern int ResultKnown;
void cstbin(struct expr **expp, int oper, struct expr *expr)
cstbin(expp, oper, expr)
register struct expr **expp, *expr;
{
/* The operation oper is performed on the constant
expressions *expp(ld) and expr(ct), and the result restored in
*expp.
*/
arith o1 = (*expp)->VL_VALUE;
arith o2 = expr->VL_VALUE;
register arith o1 = (*expp)->VL_VALUE;
register arith o2 = expr->VL_VALUE;
int uns = (*expp)->ex_type->tp_unsigned;
ASSERT(is_ld_cst(*expp) && is_cp_cst(expr));
@@ -207,12 +204,13 @@ void cstbin(struct expr **expp, int oper, struct expr *expr)
free_expression(expr);
}
void cut_size(struct expr *expr)
cut_size(expr)
register struct expr *expr;
{
/* The constant value of the expression expr is made to
conform to the size of the type of the expression.
*/
arith o1 = expr->VL_VALUE;
register arith o1 = expr->VL_VALUE;
int uns = expr->ex_type->tp_unsigned;
int size = (int) expr->ex_type->tp_size;
@@ -242,10 +240,10 @@ void cut_size(struct expr *expr)
expr->VL_VALUE = o1;
}
void init_cst()
init_cst()
{
int i = 0;
arith bt = (arith)0;
register int i = 0;
register arith bt = (arith)0;
while (!(bt < 0)) {
bt = (bt << 8) + 0377, i++;

View File

@@ -1,8 +0,0 @@
#ifndef LANG_CEM_CEMCOM_ANSI_CSTOPER_H
#define LANG_CEM_CEMCOM_ANSI_CSTOPER_H
void cstbin(struct expr **expp, int oper, struct expr *expr);
void cut_size(struct expr *expr);
void init_cst();
#endif

View File

@@ -9,7 +9,7 @@
Use the compiler option --d.
*/
#include "dataflow.h" /* UF */
#include "parameters.h" /* UF */
#ifdef DATAFLOW
char *CurrentFunction = 0;

View File

@@ -1,11 +0,0 @@
/*
* The Amsterdam Compiler Kit
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef LANG_CEM_CEMCOM_ANSI_DATAFLOW_H
#define LANG_CEM_CEMCOM_ANSI_DATAFLOW_H
/* lang/cem/cemcom.ansi/dataflow.c */
#endif /* LANG_CEM_CEMCOM_ANSI_DATAFLOW_H */

View File

@@ -6,38 +6,25 @@
/* DECLARATION SYNTAX PARSER */
{
#include "lint.h"
#include "dbsymtab.h"
#include "parameters.h"
#include <alloc.h>
#include "nobitfield.h"
#include "debug.h"
#include <flt_arith.h>
#include "idf.h"
#include "arith.h"
#include "LLlex.h"
#include "label.h"
#include "code.h"
#include "idf.h"
#include "idf_loc.h"
#include "type.h"
#include "type_loc.h"
#include "proto.h"
#include "proto_loc.h"
#include "struct.h"
#include "struct_loc.h"
#include "field.h"
#include "decspecs.h"
#include "def.h"
#include "declar.h"
#include "label.h"
#include "expr.h"
#include "expr_loc.h"
#include "sizes.h"
#include "level.h"
#include "code_c.h"
#include "error.h"
#include "stab.h"
#include "declarator.h"
#ifdef LINT
#include "l_lint.h"
#endif /* LINT */
@@ -722,7 +709,7 @@ parameter_declarator(register struct declarator *dc;)
primary_parameter_declarator(register struct declarator *dc;)
:
[%if ((AHEAD == ')' || first_of_parameter_type_list(AHEAD))
[%if (AHEAD == ')' || first_of_parameter_type_list(AHEAD)
&& (AHEAD != IDENTIFIER))
/* empty */
|

View File

@@ -4,8 +4,6 @@
*/
/* $Id$ */
/* DEFINITION OF DECLARATOR DESCRIPTORS */
#ifndef LANG_CEM_CEMCOM_ANSI_DECLARE_STR
#define LANG_CEM_CEMCOM_ANSI_DECLARE_STR
/* A 'declarator' consists of an idf and a linked list of
language-defined unary operations: *, [] and (), called
@@ -41,5 +39,3 @@ struct decl_unary {
extern struct type *declare_type();
extern struct declarator null_declarator;
#endif /* LANG_CEM_CEMCOM_ANSI_DECLARE_STR */

View File

@@ -5,8 +5,7 @@
/* $Id$ */
/* D E C L A R A T O R M A N I P U L A T I O N */
#include "debug.h"
#include "botch_free.h"
#include "parameters.h"
#include <alloc.h>
#include <flt_arith.h>
#include "arith.h"
@@ -15,19 +14,18 @@
#include "Lpars.h"
#include "declar.h"
#include "def.h"
#include "idf.h"
#include "label.h"
#include "expr.h"
#include "sizes.h"
#include "level.h"
#include "error.h"
#include "idf_loc.h"
#include "proto_loc.h"
extern char options[];
struct declarator null_declarator;
struct type *declare_type(struct type *tp, struct declarator *dc)
struct type *
declare_type(tp, dc)
struct type *tp;
struct declarator *dc;
{
/* Applies the decl_unary list starting at dc->dc_decl_unary
to the type tp and returns the result.
@@ -35,7 +33,7 @@ struct type *declare_type(struct type *tp, struct declarator *dc)
are purely prototypes. Simply add the type list to the
function node.
*/
struct decl_unary *du = dc->dc_decl_unary;
register struct decl_unary *du = dc->dc_decl_unary;
while (du) {
tp = construct_type(du->du_fund, tp, du->du_typequal,
@@ -45,13 +43,18 @@ struct type *declare_type(struct type *tp, struct declarator *dc)
return tp;
}
void add_decl_unary(struct declarator *dc, int fund, int qual, arith count, struct formal *fm, struct proto *pl)
add_decl_unary(dc, fund, qual, count, fm, pl)
register struct declarator *dc;
int qual;
arith count;
struct formal *fm;
struct proto *pl;
{
/* A decl_unary describing a constructor with fundamental
type fund and with size count is inserted in front of the
declarator dc.
*/
struct decl_unary *new = new_decl_unary();
register struct decl_unary *new = new_decl_unary();
new->next = dc->dc_decl_unary;
new->du_fund = fund;
@@ -72,12 +75,13 @@ void add_decl_unary(struct declarator *dc, int fund, int qual, arith count, stru
dc->dc_decl_unary = new;
}
void remove_declarator(struct declarator *dc)
remove_declarator(dc)
struct declarator *dc;
{
/* The decl_unary list starting at dc->dc_decl_unary is
removed.
*/
struct decl_unary *du = dc->dc_decl_unary;
register struct decl_unary *du = dc->dc_decl_unary;
while (du) {
struct decl_unary *old_du = du;
@@ -87,14 +91,15 @@ void remove_declarator(struct declarator *dc)
}
}
void reject_params(struct declarator *dc)
reject_params(dc)
register struct declarator *dc;
{
/* The declarator is checked to have no parameters, if it
is an old-style function. If it is a new-style function,
the identifiers are removed. The function is not called in
case of a function definition.
*/
struct decl_unary *du = dc->dc_decl_unary;
register struct decl_unary *du = dc->dc_decl_unary;
int err_given = 0;
if (dc->dc_formal) {
@@ -115,7 +120,8 @@ void reject_params(struct declarator *dc)
}
}
void check_array_subscript(struct expr *expr)
check_array_subscript(expr)
register struct expr *expr;
{
arith size = expr->VL_VALUE;

View File

@@ -1,16 +0,0 @@
/*
* The Amsterdam Compiler Kit
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef LANG_CEM_CEMCOM_ANSI_DECLARATOR_H
#define LANG_CEM_CEMCOM_ANSI_DECLARATOR_H
/* lang/cem/cemcom.ansi/declarator.c */
struct type *declare_type(struct type *tp, struct declarator *dc);
void add_decl_unary(struct declarator *dc, int fund, int qual, arith count, struct formal *fm, struct proto *pl);
void remove_declarator(struct declarator *dc);
void reject_params(struct declarator *dc);
void check_array_subscript(struct expr *expr);
#endif /* LANG_CEM_CEMCOM_ANSI_DECLARATOR_H */

View File

@@ -12,21 +12,21 @@
#include "type.h"
#include "level.h"
#include "def.h"
#include "error.h"
#include <symbol2str.h>
extern char options[];
extern int level;
extern char *symbol2str();
extern struct type *qualifier_type();
struct decspecs null_decspecs;
void do_decspecs(struct decspecs *ds)
do_decspecs(ds)
register struct decspecs *ds;
{
/* The provisional decspecs ds as obtained from the program
is turned into a legal consistent decspecs.
*/
struct type *tp = ds->ds_type;
register struct type *tp = ds->ds_type;
ASSERT(level != L_FORMAL1);
@@ -67,7 +67,7 @@ void do_decspecs(struct decspecs *ds)
tp = int_type;
}
if (ds->ds_size) {
int ds_isshort = (ds->ds_size == SHORT);
register int ds_isshort = (ds->ds_size == SHORT);
if (ds->ds_typedef) goto SIZE_ERROR; /* yes */
if (tp == int_type) {
@@ -82,7 +82,7 @@ void do_decspecs(struct decspecs *ds)
ds->ds_notypegiven = 0;
}
if (ds->ds_unsigned) {
int ds_isunsigned = (ds->ds_unsigned == UNSIGNED);
register int ds_isunsigned = (ds->ds_unsigned == UNSIGNED);
if (ds->ds_typedef) goto SIGN_ERROR; /* yes */
/*
@@ -113,10 +113,13 @@ void do_decspecs(struct decspecs *ds)
In case of a complex type the top of the type list will be
replaced by a qualified version.
*/
struct type *qualifier_type(struct type *tp, int typequal)
struct type *
qualifier_type(tp, typequal)
register struct type *tp;
int typequal;
{
struct type *dtp = tp;
int fund = tp->tp_fund;
register struct type *dtp = tp;
register int fund = tp->tp_fund;
while (dtp && dtp->tp_typequal != typequal)
dtp = dtp->next;

View File

@@ -1,5 +1,3 @@
#ifndef LANG_CEM_CEMCOM_ANSI_DECSPECS_H
#define LANG_CEM_CEMCOM_ANSI_DECSPECS_H
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
@@ -19,11 +17,5 @@ struct decspecs {
int ds_typequal; /* type qualifiers - see type.str */
};
extern struct type *qualifier_type();
extern struct decspecs null_decspecs;
/* lang/cem/cemcom.ansi/decspecs.c */
void do_decspecs(struct decspecs *ds);
struct type *qualifier_type(struct type *tp, int typequal);
#endif /* LANG_CEM_CEMCOM_ANSI_DECSPECS_H */

View File

@@ -4,10 +4,8 @@
*/
/* $Id$ */
/* IDENTIFIER DEFINITION DESCRIPTOR */
#ifndef LANG_CEM_CEMCOM_ANSI_DEF_STR
#define LANG_CEM_CEMCOM_ANSI_DEF_STR
#include "lint.h"
#include "parameters.h"
struct def { /* for ordinary tags */
struct def *next;
@@ -40,6 +38,3 @@ struct def { /* for ordinary tags */
#define REG_BONUS 10 /* register candidate, declared as such */
/* ALLOCDEF "def" 50 */
#endif /* LANG_CEM_CEMCOM_ANSI_DEF_STR */

View File

@@ -5,40 +5,20 @@
/* $Id$ */
/* PREPROCESSOR: CONTROLLINE INTERPRETER */
#include <stdlib.h>
#include <string.h>
#include "debug.h"
#include "specials.h"
#include <stdlib.h>
#include "parameters.h"
#include "idf.h"
#include "arith.h"
#include "LLlex.h"
#include "Lpars.h"
#include "idf.h"
#include "input.h"
#include "nopp.h"
#include "lint.h"
#include "skip.h"
#include "domacro.h"
#include "error.h"
#include "pragma.h"
#include "program.h"
#include "main.h"
#include "replace_loc.h"
#include "replace.h"
#ifndef NOPP
#include "ifdepth.h"
#include "botch_free.h"
#include "nparams.h"
#include "parbufsize.h"
#include "textsize.h"
#include "idfsize.h"
#include "assert.h"
#include <alloc.h>
#include "class.h"
#include "macro.h"
#include "macbuf.h"
#include "replace.h"
#include "dbsymtab.h"
#ifdef DBSYMTAB
#include <stb.h>
#include <em.h>
@@ -47,15 +27,16 @@ int IncludeLevel = 0;
extern char options[];
extern char **inctable; /* list of include directories */
extern char *getwdir();
char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */
/* 1 if a corresponding ELSE has been */
/* encountered. */
int nestlevel = -1;
extern char *getwdir();
/* skiponerr -> skip the rest of the line on error */
struct idf *GetIdentifier(int skiponerr)
struct idf *
GetIdentifier(skiponerr)
int skiponerr; /* skip the rest of the line on error */
{
/* returns a pointer to the descriptor of the identifier that is
read from the input stream. When the input doe not contain
@@ -86,7 +67,7 @@ struct idf *GetIdentifier(int skiponerr)
An error message is produced when the token is not recognized,
i.e. it is not one of "define" .. "undef" , integer or newline.
*/
void domacro()
domacro()
{
struct token tk; /* the token itself */
int toknum;
@@ -136,9 +117,6 @@ void domacro()
case K_ERROR: /* "error" */
do_error();
break;
case K_WARNING: /* "warning" */
do_warning();
break;
case K_PRAGMA: /* "pragma" */
do_pragma();
break;
@@ -167,7 +145,8 @@ void domacro()
int lint_skip_comment;
#endif
void skip_block(int to_endif)
skip_block(to_endif)
int to_endif;
{
/* skip_block() skips the input from
1) a false #if, #ifdef, #ifndef or #elif until the
@@ -177,8 +156,8 @@ void skip_block(int to_endif)
#ifndef or #elif until the corresponding #endif is
seen.
*/
int ch;
int skiplevel = nestlevel; /* current nesting level */
register int ch;
register int skiplevel = nestlevel; /* current nesting level */
struct token tk;
int toknum;
@@ -301,7 +280,7 @@ void skip_block(int to_endif)
}
int ifexpr()
ifexpr()
{
/* ifexpr() returns whether the restricted constant
expression following #if or #elif evaluates to true. This
@@ -323,7 +302,7 @@ int ifexpr()
return (errors == err_occurred) && (ifval != (arith)0);
}
void do_include()
do_include()
{
/* do_include() performs the inclusion of a file.
*/
@@ -368,7 +347,7 @@ void do_include()
}
}
void do_define()
do_define()
{
/* do_define() interprets a #define control line.
*/
@@ -407,7 +386,7 @@ void do_define()
LineNumber++;
}
void push_if()
push_if()
{
if (nestlevel >= IFDEPTH)
fatal("too many nested #if/#ifdef/#ifndef");
@@ -415,7 +394,7 @@ void push_if()
ifstack[++nestlevel] = 0;
}
void do_elif()
do_elif()
{
if (nestlevel <= nestlow) {
lexerror("#elif without corresponding #if");
@@ -432,7 +411,7 @@ void do_elif()
}
}
void do_else()
do_else()
{
if (SkipToNewLine())
if (!options['o'])
@@ -448,7 +427,7 @@ void do_else()
}
}
void do_endif()
do_endif()
{
if (SkipToNewLine()) {
if (!options['o'])
@@ -460,16 +439,16 @@ void do_endif()
else nestlevel--;
}
void do_if()
do_if()
{
push_if();
if (!ifexpr()) /* a false #if/#elif expression */
skip_block(0);
}
void do_ifdef(how)
do_ifdef(how)
{
struct idf *id;
register struct idf *id;
/* how == 1 : ifdef; how == 0 : ifndef
*/
@@ -489,9 +468,10 @@ void do_ifdef(how)
}
/* argidf != NULL when the undef came from a -U option */
void do_undef(struct idf *argidf)
do_undef(argidf)
struct idf *argidf;
{
struct idf *id = argidf;
register struct idf *id = argidf;
/* Forget a macro definition. */
if (id || (id = GetIdentifier(1))) {
@@ -514,7 +494,7 @@ void do_undef(struct idf *argidf)
lexerror("illegal #undef construction");
}
void do_error()
do_error()
{
int len;
char *get_text();
@@ -525,18 +505,10 @@ void do_error()
LineNumber++;
}
void do_warning()
{
int len;
char *get_text();
char *bp = get_text((char **) 0, &len);
lexwarning("user warning: %s", bp);
free(bp);
LineNumber++;
}
int getparams(char *buf[], char parbuf[])
int
getparams(buf, parbuf)
char *buf[];
char parbuf[];
{
/* getparams() reads the formal parameter list of a macro
definition.
@@ -548,10 +520,10 @@ int getparams(char *buf[], char parbuf[])
Note that the '(' has already been eaten.
The names of the formal parameters are stored into parbuf.
*/
char **pbuf = &buf[0];
int c;
char *ptr = &parbuf[0];
char **pbuf2;
register char **pbuf = &buf[0];
register int c;
register char *ptr = &parbuf[0];
register char **pbuf2;
c = GetChar();
c = skipspaces(c,0);
@@ -602,9 +574,11 @@ int getparams(char *buf[], char parbuf[])
/*NOTREACHED*/
}
void macro_def(struct idf *id, char *text, int nformals, int length, int flags)
macro_def(id, text, nformals, length, flags)
register struct idf *id;
char *text;
{
struct macro *newdef = id->id_macro;
register struct macro *newdef = id->id_macro;
/* macro_def() puts the contents and information of a macro
definition into a structure and stores it into the symbol
@@ -626,13 +600,15 @@ void macro_def(struct idf *id, char *text, int nformals, int length, int flags)
newdef->mc_flag = flags; /* special flags */
}
int find_name(char *nm, char *index[])
int
find_name(nm, index)
char *nm, *index[];
{
/* find_name() returns the index of "nm" in the namelist
"index" if it can be found there. 0 is returned if it is
not there.
*/
char **ip = &index[0];
register char **ip = &index[0];
while (*ip)
if (strcmp(nm, *ip++) == 0)
@@ -643,7 +619,10 @@ int find_name(char *nm, char *index[])
#define BLANK(ch) ((ch == ' ') || (ch == '\t'))
char *get_text(char *formals[], int *length)
char *
get_text(formals, length)
char *formals[];
int *length;
{
/* get_text() copies the replacement text of a macro
definition with zero, one or more parameters, thereby
@@ -667,9 +646,9 @@ char *get_text(char *formals[], int *length)
4- comment, same as for 1
Other tokens will not be seen as such.
*/
int c;
register int c;
struct repl repls;
struct repl *repl = &repls;
register struct repl *repl = &repls;
int blank = 0;
c = GetChar();
@@ -684,7 +663,7 @@ char *get_text(char *formals[], int *length)
}
if (c == '\'' || c == '"') {
int delim = c;
register int delim = c;
if (blank) {
blank = 0;
@@ -717,7 +696,7 @@ char *get_text(char *formals[], int *length)
} else if (formals
&& (class(c) == STIDF || class(c) == STELL)) {
char id_buf[IDFSIZE + 1];
char *idp = id_buf;
register char *idp = id_buf;
int n;
/* read identifier: it may be a formal parameter */
@@ -734,7 +713,7 @@ char *get_text(char *formals[], int *length)
add2repl(repl, ' ');
}
/* construct the formal parameter mark or identifier */
if ((n = find_name(id_buf, formals)))
if (n = find_name(id_buf, formals))
add2repl(repl, FORMALP | (char) n);
else {
idp = id_buf;
@@ -783,7 +762,8 @@ char *get_text(char *formals[], int *length)
as strings, without taking care of the leading and trailing
blanks (spaces and tabs).
*/
int macroeq(char *s, char *t)
macroeq(s, t)
register char *s, *t;
{
/* skip leading spaces */
@@ -806,8 +786,9 @@ int macroeq(char *s, char *t)
}
#else /* NOPP */
/* skiponerr -> skip the rest of the line on error */
struct idf *GetIdentifier(int skiponerr)
struct idf *
GetIdentifier(skiponerr)
int skiponerr; /* skip the rest of the line on error */
{
/* returns a pointer to the descriptor of the identifier that is
read from the input stream. When the input does not contain
@@ -826,7 +807,7 @@ struct idf *GetIdentifier(int skiponerr)
return tk.tk_idf;
}
void domacro()
domacro()
{
int tok;
struct token tk;
@@ -850,7 +831,8 @@ void domacro()
#endif /* NOPP */
void do_line(unsigned int l)
do_line(l)
unsigned int l;
{
struct token tk;
int t = GetToken(&tk);

View File

@@ -1,31 +0,0 @@
/*
* The Amsterdam Compiler Kit
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef LANG_CEM_CEMCOM_ANSI_DOMACRO_H
#define LANG_CEM_CEMCOM_ANSI_DOMACRO_H
/* lang/cem/cemcom.ansi/domacro.c */
struct idf *GetIdentifier(int skiponerr);
void domacro(void);
void skip_block(int to_endif);
int ifexpr(void);
void do_include(void);
void do_define(void);
void push_if(void);
void do_elif(void);
void do_else(void);
void do_endif(void);
void do_if(void);
void do_ifdef(int how);
void do_undef(struct idf *argidf);
void do_error(void);
void do_warning(void);
int getparams(char *buf[], char parbuf[]);
void macro_def(struct idf *id, char *text, int nformals, int length, int flags);
int find_name(char *nm, char *index[]);
char *get_text(char *formals[], int *length);
int macroeq(char *s, char *t);
void do_line(unsigned int l);
#endif /* LANG_CEM_CEMCOM_ANSI_DOMACRO_H */

View File

@@ -5,16 +5,13 @@
/* $Id$ */
/* DUMP ROUTINES */
#include "debug.h"
#ifdef DEBUG
#include "parameters.h"
#include <alloc.h>
#include "nopp.h"
#include "nobitfield.h"
#include <flt_arith.h>
#include "arith.h"
#include "stack.h"
#include "idf.h"
#include "def.h"
#include "type.h"
#include "proto.h"

View File

@@ -5,9 +5,8 @@
/* $Id$ */
/* E R R O R A N D D I A G N O S T I C R O U T I N E S */
#include "lint.h"
#include "parameters.h"
#if __STDC__
#include <stdio.h>
#include <stdarg.h>
#else
#include <varargs.h>
@@ -19,12 +18,6 @@
#include "l_em.h"
#endif /* LINT */
#include "debug.h"
#include "lint.h"
#include "nopp.h"
#include "errout.h"
#include "print.h"
#include "tokenname.h"
#include <flt_arith.h>
#include "arith.h"
@@ -32,13 +25,11 @@
#include "expr.h"
#include "def.h"
#include "LLlex.h"
#include "error.h"
/* This file contains the error-message and diagnostic
functions. Beware, they are called with a variable number of
arguments!
*/
static void _error(int class, char *fn, unsigned int ln, char *fmt, va_list ap);
/* error classes */
#define STRICT 1
@@ -66,9 +57,11 @@ extern char loptions[];
expression, whereas other errors use the information in the token.
*/
static _error();
#if __STDC__
/*VARARGS*/
void error(char *fmt, ...)
error(char *fmt, ...)
{
va_list ap;
@@ -80,7 +73,7 @@ void error(char *fmt, ...)
}
/*VARARGS*/
void expr_error(struct expr *expr, char *fmt, ...)
expr_error(struct expr *expr, char *fmt, ...)
{
va_list ap;
@@ -96,7 +89,7 @@ void expr_error(struct expr *expr, char *fmt, ...)
}
/*VARARGS*/
void lexstrict(char *fmt, ...)
lexstrict(char *fmt, ...)
{
va_list ap;
@@ -108,7 +101,7 @@ void lexstrict(char *fmt, ...)
}
/*VARARGS*/
void strict(char *fmt, ...)
strict(char *fmt, ...)
{
va_list ap;
@@ -120,7 +113,7 @@ void strict(char *fmt, ...)
}
/*VARARGS*/
void expr_strict(struct expr *expr, char *fmt, ...)
expr_strict(struct expr *expr, char *fmt, ...)
{
va_list ap;
@@ -136,7 +129,7 @@ void expr_strict(struct expr *expr, char *fmt, ...)
#ifdef DEBUG
/*VARARGS*/
void debug(char *fmt, ...)
debug(char *fmt, ...)
{
va_list ap;
@@ -149,7 +142,7 @@ void debug(char *fmt, ...)
#endif /* DEBUG */
/*VARARGS*/
void warning(char *fmt, ...)
warning(char *fmt, ...)
{
va_list ap;
@@ -161,7 +154,7 @@ void warning(char *fmt, ...)
}
/*VARARGS*/
void expr_warning(struct expr *expr, char *fmt, ...)
expr_warning(struct expr *expr, char *fmt, ...)
{
va_list ap;
@@ -178,7 +171,7 @@ void expr_warning(struct expr *expr, char *fmt, ...)
#ifdef LINT
/*VARARGS*/
void def_warning(struct def *def, char *fmt, ...)
def_warning(struct def *def, char *fmt, ...)
{
va_list ap;
@@ -191,7 +184,7 @@ void def_warning(struct def *def, char *fmt, ...)
/*VARARGS*/
void hwarning(char *fmt, ...)
hwarning(char *fmt, ...)
{
va_list ap;
@@ -204,7 +197,7 @@ void hwarning(char *fmt, ...)
}
/*VARARGS*/
void awarning(char *fmt, ...)
awarning(char *fmt, ...)
{
va_list ap;
@@ -219,7 +212,7 @@ void awarning(char *fmt, ...)
#endif /* LINT */
/*VARARGS*/
void lexerror(char *fmt, ...)
lexerror(char *fmt, ...)
{
va_list ap;
@@ -231,7 +224,7 @@ void lexerror(char *fmt, ...)
}
/*VARARGS*/
void lexwarning(char *fmt, ...)
lexwarning(char *fmt, ...)
{
va_list ap;
@@ -243,7 +236,7 @@ void lexwarning(char *fmt, ...)
}
/*VARARGS*/
void crash(char *fmt, ...)
crash(char *fmt, ...)
{
va_list ap;
@@ -263,7 +256,7 @@ void crash(char *fmt, ...)
}
/*VARARGS*/
void fatal(char *fmt, ...)
fatal(char *fmt, ...)
{
va_list ap;
@@ -528,9 +521,15 @@ fatal(va_alist) /* fmt, args */
}
#endif
static void _error(int class, char *fn, unsigned int ln, char *fmt, va_list ap)
static
_error(class, fn, ln, fmt, ap)
int class;
char *fn;
unsigned int ln;
char *fmt;
va_list ap;
{
char *remark = NULL;
char *remark;
/* check visibility of message */
switch (class) {
@@ -615,9 +614,9 @@ static void _error(int class, char *fn, unsigned int ln, char *fmt, va_list ap)
#endif /* LINT */
if (fn)
fprintf(stderr, "\"%s\", line %u: ", fn, ln);
fprint(ERROUT, "\"%s\", line %u: ", fn, ln);
if (remark)
fprintf(stderr, "%s ", remark);
fprint(ERROUT, "%s ", remark);
doprnt(ERROUT, fmt, ap); /* contents of error */
fprintf(stderr, "\n");
fprint(ERROUT, "\n");
}

View File

@@ -1,22 +0,0 @@
/*
* The Amsterdam Compiler Kit
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef LANG_CEM_CEMCOM_ANSI_ERROR_H
#define LANG_CEM_CEMCOM_ANSI_ERROR_H
/* lang/cem/cemcom.ansi/error.c */
void error(char *fmt, ...);
void expr_error(struct expr *expr, char *fmt, ...);
void lexstrict(char *fmt, ...);
void strict(char *fmt, ...);
void expr_strict(struct expr *expr, char *fmt, ...);
void warning(char *fmt, ...);
void expr_warning(struct expr *expr, char *fmt, ...);
void lexerror(char *fmt, ...);
void lexwarning(char *fmt, ...);
void crash(char *fmt, ...);
void fatal(char *fmt, ...);
#endif /* LANG_CEM_CEMCOM_ANSI_ERROR_H */

View File

@@ -5,10 +5,6 @@
/* $Id$ */
/* EXPRESSION STACK */
/* Used for global initializations */
#ifndef LANG_CEM_CEMCOM_ANSI_ESTACK_STR
#define LANG_CEM_CEMCOM_ANSI_ESTACK_STR
struct e_stack {
struct e_stack *next;
arith s_cnt1, s_cnt2;
@@ -23,5 +19,3 @@ struct e_stack {
#define last_offset s_cnt2
#define elem_count s_cnt1
#define nelem s_cnt2
#endif /* LANG_CEM_CEMCOM_ANSI_ESTACK_STR */

View File

@@ -5,21 +5,16 @@
/* $Id$ */
/* EXPRESSION-CODE GENERATOR */
#include "lint.h"
#include "parameters.h"
#ifndef LINT
#include <em.h>
#include <em_reg.h>
#include <alloc.h>
#include "debug.h"
#include "nobitfield.h"
#include "dataflow.h"
#include <flt_arith.h>
#include <system.h>
#include "print.h"
#include "idf.h"
#include "arith.h"
#include "type.h"
#include "idf.h"
#include "label.h"
#include "code.h"
#include "assert.h"
@@ -32,25 +27,18 @@
#include "align.h"
#include "mes.h"
#include "atw.h"
#include "blocks.h"
#include "conversion.h"
#include "specials.h"
#include "ch3.h"
#include "eval.h"
#include "error.h"
#include "field_loc.h"
#include "struct_loc.h"
#include "util_loc.h"
#include <symbol2str.h>
#define CRASH() crash("EVAL: CRASH at line %u", __LINE__)
char *symbol2str();
char *long2str();
arith NewLocal(); /* util.c */
#define LocalPtrVar() NewLocal(pointer_size, pointer_align, reg_pointer, REGISTER)
extern int err_occurred; /* error.c */
/* EVAL() is the main expression-tree evaluator, which turns
any legal expression tree into EM code. Parameters:
any legal expression tree into EM code. parameters.h:
struct expr *expr
pointer to root of the expression tree to be evaluated
@@ -75,10 +63,13 @@ extern int err_occurred; /* error.c */
labels, in case they are specified (i.e. are non-zero)
*/
void EVAL(struct expr *expr, int val, int code, label true_label, label false_label)
EVAL(expr, val, code, true_label, false_label)
register struct expr *expr;
int val, code;
label true_label, false_label;
{
int vol = (code != TRUE && recurqual(expr->ex_type, TQ_VOLATILE));
int gencode = code == TRUE;
register int gencode = code == TRUE;
if (err_occurred) return;
switch (expr->ex_class) {
@@ -120,9 +111,9 @@ void EVAL(struct expr *expr, int val, int code, label true_label, label false_la
case Oper: /* compound expression */
{
int oper = expr->OP_OPER;
struct expr *left = expr->OP_LEFT;
struct expr *right = expr->OP_RIGHT;
struct type *tp = expr->OP_TYPE;
register struct expr *left = expr->OP_LEFT;
register struct expr *right = expr->OP_RIGHT;
register struct type *tp = expr->OP_TYPE;
switch (oper) {
case '+':
@@ -261,44 +252,26 @@ void EVAL(struct expr *expr, int val, int code, label true_label, label false_la
operands(expr, gencode);
ASSERT(tp->tp_fund==INT || tp->tp_fund==LONG);
if (gencode)
{
if (tp->tp_unsigned)
{
C_rmu(tp->tp_size);
}
else
{
C_rmi(tp->tp_size);
}
}
break;
case LEFT:
operands(expr, gencode);
if (gencode)
{
if (tp->tp_unsigned)
{
C_slu(tp->tp_size);
}
else
{
C_sli(tp->tp_size);
}
}
break;
case RIGHT:
operands(expr, gencode);
if (gencode)
{
if (tp->tp_unsigned)
{
C_sru(tp->tp_size);
}
else
{
C_sri(tp->tp_size);
}
}
break;
case '<':
case LESSEQ:
@@ -496,7 +469,7 @@ void EVAL(struct expr *expr, int val, int code, label true_label, label false_la
}
case '(':
{
struct expr *ex;
register struct expr *ex;
arith ParSize = (arith)0;
label setjmp_label = 0;
arith retspace = 0;
@@ -682,7 +655,9 @@ void EVAL(struct expr *expr, int val, int code, label true_label, label false_la
}
/* compare() serves as an auxiliary function of EVAL */
void compare(int relop, label lbl)
compare(relop, lbl)
int relop;
label lbl;
{
switch (relop) {
case '<':
@@ -709,7 +684,8 @@ void compare(int relop, label lbl)
}
/* truthvalue() serves as an auxiliary function of EVAL */
void truthvalue(int relop)
truthvalue(relop)
int relop;
{
switch (relop) {
case '<':
@@ -737,10 +713,12 @@ void truthvalue(int relop)
/* assop() generates the opcode of an assignment operators op= */
void assop(struct type *type, int oper)
assop(type, oper)
register struct type *type;
int oper;
{
arith size;
int uns = type->tp_unsigned;
register arith size;
register uns = type->tp_unsigned;
if ((int)(size = type->tp_size) < (int)word_size)
size = word_size;
@@ -840,7 +818,8 @@ void assop(struct type *type, int oper)
}
}
void ptr_add(arith size)
ptr_add(size)
arith size;
{
if (size != pointer_size) {
C_loc(size);
@@ -857,10 +836,12 @@ void ptr_add(arith size)
- into a local static variable
- absolute addressing
*/
void store_val(struct value *vl, struct type *tp)
store_val(vl, tp)
register struct value *vl;
register struct type *tp;
{
int inword = 0;
int indword = 0;
register int inword = 0;
register int indword = 0;
arith val = vl->vl_value;
if (vl->vl_class == Const) { /* absolute addressing */
@@ -873,8 +854,8 @@ void store_val(struct value *vl, struct type *tp)
else if (tp->tp_size == dword_size) indword = 1;
}
if (vl->vl_class == Name) {
struct idf *id = vl->vl_data.vl_idf;
struct def *df = id->id_def;
register struct idf *id = vl->vl_data.vl_idf;
register struct def *df = id->id_def;
/* if (df->df_level == L_GLOBAL) { // } ??? re-examine */
if (df->df_sc == GLOBAL
@@ -926,15 +907,14 @@ void store_val(struct value *vl, struct type *tp)
- static variable
- local variable
*/
/* expr -> expression containing the value
rlval -> generate either LVAL or RVAL
*/
void load_val(struct expr *expr, int rlval)
load_val(expr, rlval)
register struct expr *expr; /* expression containing the value */
int rlval; /* generate either LVAL or RVAL */
{
struct type *tp = expr->ex_type;
register struct type *tp = expr->ex_type;
int rvalue = (rlval == RVAL && expr->ex_lvalue != 0);
int inword = 0, indword = 0;
arith val = expr->VL_VALUE;
register int inword = 0, indword = 0;
register arith val = expr->VL_VALUE;
if (expr->ex_type->tp_fund == FLOAT
|| expr->ex_type->tp_fund == DOUBLE
@@ -974,8 +954,8 @@ void load_val(struct expr *expr, int rlval)
}
}
else {
struct idf *id = expr->VL_IDF;
struct def *df = id->id_def;
register struct idf *id = expr->VL_IDF;
register struct def *df = id->id_def;
int fund = df->df_type->tp_fund;
ASSERT(ISNAME(expr));
@@ -1026,7 +1006,8 @@ void load_val(struct expr *expr, int rlval)
}
}
void load_cst(arith val, arith siz)
load_cst(val, siz)
arith val, siz;
{
if ((int)siz <= (int)word_size)
C_loc(val);
@@ -1043,7 +1024,8 @@ void load_cst(arith val, arith siz)
}
}
void operands(struct expr *expr, int gencode)
operands(expr, gencode)
register struct expr *expr;
{
EVAL(expr->OP_LEFT, RVAL, gencode, NO_LABEL, NO_LABEL);
EVAL(expr->OP_RIGHT, RVAL, gencode, NO_LABEL, NO_LABEL);

View File

@@ -1,20 +0,0 @@
/*
* The Amsterdam Compiler Kit
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef LANG_CEM_CEMCOM_ANSI_EVAL_H
#define LANG_CEM_CEMCOM_ANSI_EVAL_H
/* lang/cem/cemcom.ansi/eval.c */
void EVAL(struct expr *expr, int val, int code, label true_label, label false_label);
void compare(int relop, label lbl);
void truthvalue(int relop);
void assop(struct type *type, int oper);
void ptr_add(arith size);
void store_val(struct value *vl, struct type *tp);
void load_val(struct expr *expr, int rlval);
void load_cst(arith val, arith siz);
void operands(struct expr *expr, int gencode);
#endif /* LANG_CEM_CEMCOM_ANSI_EVAL_H */

View File

@@ -5,15 +5,12 @@
/* $Id$ */
/* EXPRESSION TREE HANDLING */
#include <stdlib.h>
#include "lint.h"
#include "debug.h"
#include <stdlib.h>
#include "parameters.h"
#include "assert.h"
#include "botch_free.h"
#include <alloc.h>
#include "idf.h"
#include <flt_arith.h>
#include "idf.h"
#include "arith.h"
#include "def.h"
#include "type.h"
@@ -25,17 +22,14 @@
#include "declar.h"
#include "sizes.h"
#include "level.h"
#include "use_tmp.h"
#include "cstoper.h"
#include "idf_loc.h"
#include "expr_loc.h"
#include "error.h"
#include <symbol2str.h>
extern char *symbol2str();
extern char options[];
extern int InSizeof;
int rank_of(int oper)
int
rank_of(oper)
int oper;
{
/* The rank of the operator oper is returned.
*/
@@ -104,12 +98,13 @@ int rank_of(int oper)
/*NOTREACHED*/
}
void dot2expr(struct expr **expp)
dot2expr(expp)
struct expr **expp;
{
/* The token in dot is converted into an expression, a
pointer to which is stored in *expp.
*/
struct expr *ex = new_expr();
register struct expr *ex = new_expr();
*expp = ex;
ex->ex_file = dot.tk_file;
@@ -130,15 +125,16 @@ void dot2expr(struct expr **expp)
}
}
void idf2expr(struct expr *expr)
idf2expr(expr)
register struct expr *expr;
{
/* Dot contains an identifier which is turned into an
expression.
Note that this constitutes an applied occurrence of
the identifier.
*/
struct idf *idf = dot.tk_idf; /* != 0*/
struct def *def = idf->id_def;
register struct idf *idf = dot.tk_idf; /* != 0*/
register struct def *def = idf->id_def;
if (def == 0) {
if (AHEAD == '(') {
@@ -199,12 +195,15 @@ void idf2expr(struct expr *expr)
}
}
void string2expr(struct expr **expp, char *str, int len)
string2expr(expp, str, len)
register struct expr **expp;
int len;
char *str;
{
/* The string in the argument is converted into an expression,
a pointer to which is stored in *expp.
*/
struct expr *ex = new_expr();
register struct expr *ex = new_expr();
*expp = ex;
ex->ex_file = dot.tk_file;
@@ -218,7 +217,8 @@ void string2expr(struct expr **expp, char *str, int len)
ex->SG_LEN = len;
}
void int2expr(struct expr *expr)
int2expr(expr)
struct expr *expr;
{
/* Dot contains an integer constant which is turned
into an expression.
@@ -226,12 +226,13 @@ void int2expr(struct expr *expr)
fill_int_expr(expr, dot.tk_ival, dot.tk_fund);
}
void float2expr(struct expr *expr)
float2expr(expr)
register struct expr *expr;
{
/* Dot contains a floating point constant which is turned
into an expression.
*/
int fund;
register int fund;
fund = dot.tk_fund;
switch (fund) {
@@ -255,12 +256,15 @@ void float2expr(struct expr *expr)
expr_warning(expr,"internal floating point overflow");
}
struct expr *intexpr(arith ivalue, int fund)
struct expr*
intexpr(ivalue, fund)
arith ivalue;
int fund;
{
/* The value ivalue is turned into an integer expression of
the size indicated by fund.
*/
struct expr *expr = new_expr();
register struct expr *expr = new_expr();
expr->ex_file = dot.tk_file;
expr->ex_line = dot.tk_line;
@@ -268,7 +272,10 @@ struct expr *intexpr(arith ivalue, int fund)
return expr;
}
void fill_int_expr(struct expr *ex, arith ivalue, int fund)
fill_int_expr(ex, ivalue, fund)
register struct expr *ex;
arith ivalue;
int fund;
{
/* Details derived from ivalue and fund are put into the
constant integer expression ex.
@@ -296,7 +303,10 @@ void fill_int_expr(struct expr *ex, arith ivalue, int fund)
cut_size(ex);
}
struct expr *new_oper(struct type *tp, struct expr *e1, int oper, struct expr *e2)
struct expr *
new_oper(tp, e1, oper, e2)
struct type *tp;
register struct expr *e1, *e2;
{
/* A new expression is constructed which consists of the
operator oper which has e1 and e2 as operands; for a
@@ -304,11 +314,11 @@ struct expr *new_oper(struct type *tp, struct expr *e1, int oper, struct expr *e
During the construction of the right recursive initialisation
tree it is possible for e2 to be NILEXPR.
*/
struct expr *expr = new_expr();
struct oper *op;
register struct expr *expr = new_expr();
register struct oper *op;
if (e2) {
struct expr *e = e2;
register struct expr *e = e2;
while (e->ex_class == Oper && e->OP_LEFT)
e = e->OP_LEFT;
@@ -317,7 +327,7 @@ struct expr *new_oper(struct type *tp, struct expr *e1, int oper, struct expr *e
}
else
if (e1) {
struct expr *e = e1;
register struct expr *e = e1;
while (e->ex_class == Oper && e->OP_RIGHT)
e = e->OP_RIGHT;
@@ -359,7 +369,8 @@ struct expr *new_oper(struct type *tp, struct expr *e1, int oper, struct expr *e
return expr;
}
void chk_cst_expr(struct expr **expp)
chk_cst_expr(expp)
struct expr **expp;
{
/* The expression expr is checked for constancy.
@@ -381,7 +392,7 @@ void chk_cst_expr(struct expr **expp)
Special problems (of which there is only one, sizeof in
Preprocessor #if) have to be dealt with locally
*/
struct expr *expr = *expp;
register struct expr *expr = *expp;
#ifdef DEBUG
print_expr("constant_expression", expr);
@@ -404,7 +415,9 @@ void chk_cst_expr(struct expr **expp)
erroneous2int(expp);
}
void init_expression(struct expr ***eppp, struct expr *expr)
init_expression(eppp, expr)
register struct expr ***eppp;
struct expr *expr;
{
/* The expression expr is added to the tree designated
indirectly by **eppp.
@@ -422,7 +435,9 @@ void init_expression(struct expr ***eppp, struct expr *expr)
*eppp = &(**eppp)->OP_RIGHT;
}
int is_ld_cst(struct expr *expr)
int
is_ld_cst(expr)
register struct expr *expr;
{
/* An expression is a `load-time constant' if it is of the form
<idf> +/- <integral> or <integral>.
@@ -434,7 +449,9 @@ int is_ld_cst(struct expr *expr)
return expr->ex_lvalue == 0 && expr->ex_class == Value;
}
int is_cp_cst(struct expr *expr)
int
is_cp_cst(expr)
struct expr *expr;
{
/* An expression is a `compile-time constant' if it is a
load-time constant, and the idf is not there.
@@ -442,7 +459,9 @@ int is_cp_cst(struct expr *expr)
return is_ld_cst(expr) && expr->VL_CLASS == Const;
}
int is_fp_cst(struct expr *expr)
int
is_fp_cst(expr)
struct expr *expr;
{
/* An expression is a `floating-point constant' if it consists
of the float only.
@@ -450,7 +469,9 @@ int is_fp_cst(struct expr *expr)
return expr->ex_class == Float;
}
int is_zero_cst(struct expr *expr)
int
is_zero_cst(expr)
register struct expr *expr;
{
flt_arith var;
@@ -462,10 +483,10 @@ int is_zero_cst(struct expr *expr)
return flt_cmp(&var, &(expr->FL_ARITH)) == 0;
}
/*NOTREACHED*/
return 0;
}
void free_expression(struct expr *expr)
free_expression(expr)
register struct expr *expr;
{
/* The expression expr is freed recursively.
*/

View File

@@ -9,14 +9,6 @@
a union of various goodies, we define them first; so be patient.
*/
#ifndef LANG_CEM_CEMCOM_ANSI_EXPR_STR
#define LANG_CEM_CEMCOM_ANSI_EXPR_STR
#include "idf.h"
#include "arith.h"
#include <em_label.h>
#include <flt_arith.h>
/* classes of value */
#define Const 1
#define Name 2
@@ -105,4 +97,3 @@ extern struct expr *intexpr(), *new_oper();
/* ALLOCDEF "expr" 20 */
#endif /* LANG_CEM_CEMCOM_ANSI_EXPR_STR */

View File

@@ -1,27 +0,0 @@
/*
* The Amsterdam Compiler Kit
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef LANG_CEM_CEMCOM_ANSI_EXPR_H
#define LANG_CEM_CEMCOM_ANSI_EXPR_H
/* lang/cem/cemcom.ansi/expr.c */
int rank_of(int oper);
void dot2expr(struct expr **expp);
void idf2expr(struct expr *expr);
void string2expr(struct expr **expp, char *str, int len);
void int2expr(struct expr *expr);
void float2expr(struct expr *expr);
struct expr *intexpr(arith ivalue, int fund);
void fill_int_expr(struct expr *ex, arith ivalue, int fund);
struct expr *new_oper(struct type *tp, struct expr *e1, int oper, struct expr *e2);
void chk_cst_expr(struct expr **expp);
void init_expression(struct expr ***eppp, struct expr *expr);
int is_ld_cst(struct expr *expr);
int is_cp_cst(struct expr *expr);
int is_fp_cst(struct expr *expr);
int is_zero_cst(struct expr *expr);
void free_expression(struct expr *expr);
#endif /* LANG_CEM_CEMCOM_ANSI_EXPR_H */

View File

@@ -7,27 +7,17 @@
{
#include <alloc.h>
#include "lint.h"
#include "debug.h"
#include "parameters.h"
#include <flt_arith.h>
#include "arith.h"
#include "LLlex.h"
#include "type.h"
#include "idf.h"
#include "decspecs.h"
#include "declar.h"
#include "declarator.h"
#include "label.h"
#include "expr.h"
#include "expr_loc.h"
#include "proto_loc.h"
#include "code.h"
#include "sizes.h"
#include "ch3.h"
#include "ch3bin.h"
#include "ch3mon.h"
#include "error.h"
extern struct expr *intexpr();
int InSizeof = 0; /* inside a sizeof- expression */
int ResultKnown = 0; /* result of the expression is already known */
@@ -39,7 +29,7 @@ int ResultKnown = 0; /* result of the expression is already known */
}
/* 3.3.1 */
primary(struct expr **expp;) :
primary(register struct expr **expp;) :
IDENTIFIER
{dot2expr(expp);}
|
@@ -56,10 +46,10 @@ primary(struct expr **expp;) :
* are concatenated into a single character string
* literal.
*/
string(struct expr **expp;)
{ int i, len;
char *str;
int fund;
string(register struct expr **expp;)
{ register int i, len;
register char *str;
register int fund;
}
:
STRING
@@ -86,7 +76,7 @@ string(struct expr **expp;)
;
/* 3.3.2 */
postfix_expression(struct expr **expp;)
postfix_expression(register struct expr **expp;)
{ int oper;
struct expr *e1 = 0;
struct idf *idf;
@@ -128,7 +118,7 @@ parameter_list(struct expr **expp;)
%first first_of_type_specifier, type_specifier;
/* 3.3.3 & 3.3.4 */
unary(struct expr **expp;)
unary(register struct expr **expp;)
{struct type *tp; int oper;}
:
%if (first_of_type_specifier(AHEAD) && AHEAD != IDENTIFIER)
@@ -151,7 +141,7 @@ unary(struct expr **expp;)
* mark it as used.
* extern int i; .... sizeof(i) .... need not have a definition for i
*/
size_of(struct expr **expp;)
size_of(register struct expr **expp;)
{struct type *tp;}
:
SIZEOF { InSizeof++; } /* handle (sizeof(sizeof(int))) too */
@@ -330,7 +320,7 @@ binop(int *oper;) :
{*oper = DOT;}
;
asgnop(int *oper;):
asgnop(register int *oper;):
[ '=' | PLUSAB | MINAB | TIMESAB | DIVAB | MODAB
| LEFTAB | RIGHTAB | ANDAB | XORAB | ORAB ]
{ *oper = DOT; }

View File

@@ -5,19 +5,16 @@
/* $Id$ */
/* BITFIELD EXPRESSION EVALUATOR */
#include "lint.h"
#include "parameters.h"
#ifndef LINT
#include "nobitfield.h"
#ifndef NOBITFIELD
#include <em.h>
#include <em_reg.h>
#include "debug.h"
#include <flt_arith.h>
#include "arith.h"
#include "type.h"
#include "idf.h"
#include "label.h"
#include "code.h"
#include "assert.h"
@@ -26,11 +23,8 @@
#include "align.h"
#include "Lpars.h"
#include "field.h"
#include "field_loc.h"
#include "eval.h"
#include "util_loc.h"
#include "conversion.h"
arith NewLocal(); /* util.c */
extern arith full_mask[]; /* cstoper.c */
/* Eval_field() evaluates expressions involving bit fields.
@@ -45,12 +39,14 @@ extern arith full_mask[]; /* cstoper.c */
[3] atype: the type in which the bitfield arithmetic is done;
and in which bitfields are stored!
*/
void eval_field(struct expr *expr, int code)
eval_field(expr, code)
struct expr *expr;
int code;
{
int op = expr->OP_OPER;
struct expr *leftop = expr->OP_LEFT;
struct expr *rightop = expr->OP_RIGHT;
struct field *fd = leftop->ex_type->tp_field;
register struct expr *leftop = expr->OP_LEFT;
register struct expr *rightop = expr->OP_RIGHT;
register struct field *fd = leftop->ex_type->tp_field;
struct type *tp = leftop->ex_type->tp_up;
arith tmpvar = 0;
struct type *atype = ( tp->tp_unsigned
@@ -119,7 +115,7 @@ void eval_field(struct expr *expr, int code)
retrieval) is on top of stack.
*/
if (tp->tp_unsigned == 0) { /* sign extension */
arith shift = (int)word_size * 8 - fd->fd_width;
register arith shift = (int)word_size * 8 - fd->fd_width;
C_loc(shift);
C_sli(word_size);
@@ -130,7 +126,12 @@ void eval_field(struct expr *expr, int code)
}
}
void store_field(struct field *fd, int uns, int code, struct expr *leftop, arith tmpvar)
store_field(fd, uns, code, leftop, tmpvar)
register struct field *fd;
int uns;
int code;
register struct expr *leftop;
arith tmpvar;
{
C_loc(fd->fd_mask);
C_and(word_size);

View File

@@ -1,13 +0,0 @@
/*
* The Amsterdam Compiler Kit
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef LANG_CEM_CEMCOM_ANSI_FIELD_H
#define LANG_CEM_CEMCOM_ANSI_FIELD_H
/* lang/cem/cemcom.ansi/field.c */
void eval_field(struct expr *expr, int code);
void store_field(struct field *fd, int uns, int code, struct expr *leftop, arith tmpvar);
#endif /* LANG_CEM_CEMCOM_ANSI_FIELD_H */

View File

@@ -6,11 +6,9 @@
/* C O N S T A N T E X P R E S S I O N H A N D L I N G */
/* F O R F L O A T I N G P O I N T N U M B E R S */
#include "debug.h"
#include "parameters.h"
#include "assert.h"
#include <alloc.h>
#include "trgt_sizes.h"
#include "idf.h"
#include <flt_arith.h>
#include "arith.h"
#include "type.h"
@@ -18,16 +16,12 @@
#include "expr.h"
#include "sizes.h"
#include "Lpars.h"
#include "cstoper.h"
#include "fltcstoper.h"
#include "error.h"
#include "expr_loc.h"
#include <symbol2str.h>
extern int ResultKnown;
extern char *symbol2str();
void fltcstbin(struct expr **expp, int oper, struct expr *expr)
fltcstbin(expp, oper, expr)
register struct expr **expp, *expr;
{
/* The operation oper is performed on the constant
expressions *expp(ld) and expr(ct), and the result restored in

View File

@@ -1,12 +0,0 @@
/*
* The Amsterdam Compiler Kit
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef LANG_CEM_CEMCOM_ANSI_FLTCSTOPER_H
#define LANG_CEM_CEMCOM_ANSI_FLTCSTOPER_H
/* lang/cem/cemcom.ansi/fltcstoper.c */
void fltcstbin(register struct expr **expp, int oper, register struct expr *expr);
#endif /* LANG_CEM_CEMCOM_ANSI_FLTCSTOPER_H */

View File

@@ -7,21 +7,15 @@
#include <stdlib.h>
#include <string.h>
#include "system.h"
#include "lint.h"
#include "parameters.h"
#include <em_reg.h>
#include "debug.h"
#include "idfsize.h"
#include "botch_free.h"
#include "nopp.h"
#include "nparams.h"
#include <alloc.h>
#include "idf.h"
#include "arith.h"
#include "align.h"
#include "LLlex.h"
#include "level.h"
#include "stack.h"
#include "idf.h"
#include "label.h"
#include "def.h"
#include "type.h"
@@ -32,21 +26,10 @@
#include "sizes.h"
#include "Lpars.h"
#include "assert.h"
#include "ch3.h"
#include "code_c.h"
#include "conversion.h"
#include "print.h"
#include "idf_loc.h"
#include "struct_loc.h"
#include "proto_loc.h"
#include "util_loc.h"
#include "error.h"
#include "stab.h"
#include "stack_loc.h"
#include <symbol2str.h>
extern char options[];
extern arith NewLocal();
extern char *symbol2str();
#ifdef DEBUG
#define IDF_DEBUG
@@ -54,7 +37,8 @@ extern char options[];
#include <idf_pkg.body>
struct idf *gen_idf()
struct idf *
gen_idf()
{
/* A new idf is created out of nowhere, to serve as an
anonymous name.
@@ -68,12 +52,16 @@ struct idf *gen_idf()
return str2idf(s, 0);
}
int is_anon_idf(struct idf *idf)
int
is_anon_idf(idf)
struct idf *idf;
{
return idf->id_text[0] == '#';
}
void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl)
declare_idf(ds, dc, lvl)
struct decspecs *ds;
struct declarator *dc;
{
/* The identifier inside dc is declared on the level lvl, with
properties deduced from the decspecs ds and the declarator
@@ -83,14 +71,14 @@ void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl)
This routine implements the rich semantics of C
declarations.
*/
struct idf *idf = dc->dc_idf;
int sc = ds->ds_sc;
register struct idf *idf = dc->dc_idf;
register int sc = ds->ds_sc;
/* This local copy is essential:
char b(), c;
makes b GLOBAL and c AUTO.
*/
struct def *def = idf->id_def; /* may be NULL */
struct type *type;
register struct def *def = idf->id_def; /* may be NULL */
register struct type *type;
struct stack_level *stl = stack_level_of(lvl);
char formal_array = 0;
@@ -104,8 +92,8 @@ void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl)
else {
/* combine the decspecs and the declarator into one type */
type = declare_type(ds->ds_type, dc);
if ( (type->tp_size <= (arith)0) &&
actual_declaration(sc, type)) {
if (type->tp_size <= (arith)0 &&
actual_declaration(sc, type)) {
if (type->tp_size == (arith) -1) {
/* the type is not yet known,
but it has to be:
@@ -211,7 +199,7 @@ void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl)
def->df_line = idf->id_line;
}
else { /* fill in the def block */
struct def *newdef = new_def();
register struct def *newdef = new_def();
newdef->next = def;
newdef->df_level = lvl;
@@ -260,11 +248,13 @@ void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl)
}
}
int actual_declaration(int sc, struct type *tp)
actual_declaration(sc, tp)
int sc;
struct type *tp;
{
/* An actual_declaration needs space, right here and now.
*/
int fund = tp->tp_fund;
register int fund = tp->tp_fund;
if (sc == ENUM || sc == TYPEDEF) /* virtual declarations */
return 0;
@@ -279,7 +269,9 @@ int actual_declaration(int sc, struct type *tp)
return 1;
}
void global_redecl(struct idf *idf, int new_sc, struct type *tp)
global_redecl(idf, new_sc, tp)
register struct idf *idf;
struct type *tp;
{
/* A global identifier may be declared several times,
provided the declarations do not conflict; they might
@@ -287,7 +279,7 @@ void global_redecl(struct idf *idf, int new_sc, struct type *tp)
an array) or they might conflict or supplement each other
in storage class.
*/
struct def *def = idf->id_def;
register struct def *def = idf->id_def;
while (def->df_level != L_GLOBAL) def = def->next;
if (!equal_type(tp, def->df_type, 0, 1)) {
@@ -371,7 +363,10 @@ void global_redecl(struct idf *idf, int new_sc, struct type *tp)
}
}
int good_formal(struct def *def, struct idf *idf)
int
good_formal(def, idf)
register struct def *def;
register struct idf *idf;
{
/* Succeeds if def is a proper L_FORMAL1 definition and
gives an error message otherwise.
@@ -385,11 +380,12 @@ int good_formal(struct def *def, struct idf *idf)
return 1;
}
void declare_params(struct declarator *dc)
declare_params(dc)
struct declarator *dc;
{
/* Declares the formal parameters if they exist.
*/
struct formal *fm = dc->dc_formal;
register struct formal *fm = dc->dc_formal;
while (fm) {
declare_parameter(fm->fm_idf);
@@ -397,11 +393,12 @@ void declare_params(struct declarator *dc)
}
}
void idf_initialized(struct idf *idf)
idf_initialized(idf)
register struct idf *idf;
{
/* The topmost definition of idf is set to initialized.
*/
struct def *def = idf->id_def; /* the topmost */
register struct def *def = idf->id_def; /* the topmost */
while (def->df_level <= L_PROTO) def = def->next;
if (def->df_initialized)
@@ -413,14 +410,18 @@ void idf_initialized(struct idf *idf)
def->df_initialized = 1;
}
void declare_parameter(struct idf *idf)
declare_parameter(idf)
struct idf *idf;
{
/* idf is declared as a formal.
*/
add_def(idf, FORMAL, int_type, level);
}
void declare_enum(struct type *tp, struct idf *idf, arith l)
declare_enum(tp, idf, l)
struct type *tp;
struct idf *idf;
arith l;
{
/* idf is declared as an enum constant with value l.
*/
@@ -428,11 +429,13 @@ void declare_enum(struct type *tp, struct idf *idf, arith l)
idf->id_def->df_address = l;
}
void check_formals(struct idf *idf, struct declarator *dc)
check_formals(idf, dc)
struct idf *idf;
struct declarator *dc;
{
struct formal *fm = dc->dc_formal;
struct proto *pl = idf->id_def->df_type->tp_proto;
struct decl_unary *du = dc->dc_decl_unary;
register struct formal *fm = dc->dc_formal;
register struct proto *pl = idf->id_def->df_type->tp_proto;
register struct decl_unary *du = dc->dc_decl_unary;
if (!du) { /* error or typdef'ed function */
error("illegal definition of %s", idf->id_text);
@@ -475,7 +478,7 @@ void check_formals(struct idf *idf, struct declarator *dc)
error("incorrect number of parameters");
}
} else { /* make a pseudo-prototype */
struct proto *lpl = new_proto();
register struct proto *lpl = new_proto();
if (!options['o'])
warning("'%s' old-fashioned function definition"
@@ -504,16 +507,18 @@ void check_formals(struct idf *idf, struct declarator *dc)
dc->dc_formal = 0;
}
void declare_formals(struct idf *idf, arith *fp)
declare_formals(idf, fp)
struct idf *idf;
arith *fp;
{
/* Declares those formals as int that haven't been declared
by the user.
An address is assigned to each formal parameter.
The total size of the formals is returned in *fp;
*/
struct stack_entry *se = stack_level_of(L_FORMAL1)->sl_entry;
register struct stack_entry *se = stack_level_of(L_FORMAL1)->sl_entry;
arith f_offset = (arith)0;
int nparams = 0;
register int nparams = 0;
int hasproto;
struct def *df = idf->id_def;
@@ -580,7 +585,9 @@ void declare_formals(struct idf *idf, arith *fp)
*fp = f_offset;
}
int regtype(struct type *tp)
int
regtype(tp)
struct type *tp;
{
switch(tp->tp_fund) {
case INT:
@@ -596,7 +603,11 @@ int regtype(struct type *tp)
return -1;
}
void add_def(struct idf *idf, int sc, struct type *tp, int lvl)
add_def(idf, sc, tp, lvl)
struct idf *idf;
struct type *tp;
int lvl;
int sc;
{
/* The identifier idf is declared on level lvl with storage
class sc and type tp, through a faked C declaration.
@@ -613,12 +624,13 @@ void add_def(struct idf *idf, int sc, struct type *tp, int lvl)
declare_idf(&Ds, &Dc, lvl);
}
void update_ahead(struct idf *idf)
update_ahead(idf)
register struct idf *idf;
{
/* The tk_symb of the token ahead is updated in the light of new
information about the identifier idf.
*/
int tk_symb = AHEAD;
register int tk_symb = AHEAD;
if ( (tk_symb == IDENTIFIER || tk_symb == TYPE_IDENTIFIER) &&
ahead.tk_idf == idf
@@ -627,7 +639,8 @@ void update_ahead(struct idf *idf)
TYPE_IDENTIFIER : IDENTIFIER;
}
void free_formals(struct formal *fm)
free_formals(fm)
register struct formal *fm;
{
while (fm) {
struct formal *tmp = fm->next;

View File

@@ -4,10 +4,8 @@
*/
/* $Id$ */
/* IDENTIFIER DESCRIPTOR */
#ifndef LANG_CEM_CEMCOM_ANSI_IDF_STR
#define LANG_CEM_CEMCOM_ANSI_IDF_STR
#include "nopp.h"
#include "parameters.h"
struct id_u {
#ifndef NOPP
@@ -49,5 +47,3 @@ struct dependency {
extern int level;
extern struct idf *gen_idf();
#endif /* LANG_CEM_CEMCOM_ANSI_IDF_STR */

View File

@@ -1,33 +0,0 @@
/*
* The Amsterdam Compiler Kit
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef LANG_CEM_CEMCOM_ANSI_IDF_H
#define LANG_CEM_CEMCOM_ANSI_IDF_H
#include "declar.h"
#include "decspecs.h"
#include "def.h"
/* lang/cem/cemcom.ansi/idf.c */
void init_idf(void);
struct idf *str2idf(char tg[], int cpy);
struct idf *gen_idf(void);
int is_anon_idf(struct idf *idf);
void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl);
int actual_declaration(int sc, struct type *tp);
void global_redecl(struct idf *idf, int new_sc, struct type *tp);
int good_formal(struct def *def, struct idf *idf);
void declare_params(struct declarator *dc);
void idf_initialized(struct idf *idf);
void declare_parameter(struct idf *idf);
void declare_enum(struct type *tp, struct idf *idf, arith l);
void check_formals(struct idf *idf, struct declarator *dc);
void declare_formals(struct idf *idf, arith *fp);
int regtype(struct type *tp);
void add_def(struct idf *idf, int sc, struct type *tp, int lvl);
void update_ahead(struct idf *idf);
void free_formals(struct formal *fm);
#endif /* LANG_CEM_CEMCOM_ANSI_IDF_H */

View File

@@ -7,23 +7,17 @@
#include <stdlib.h>
#include <string.h>
#include "nopp.h"
#include "parameters.h"
#ifndef NOPP
#include <system.h>
#include <alloc.h>
#include <time.h>
#include <flt_arith.h>
#include <em_label.h>
#include "idf.h"
#include "class.h"
#include "macro.h"
#include "idf.h"
#include "arith.h"
#include "print.h"
#include "expr.h"
#include "error.h"
#include "domacro.h"
extern char *sprint();
struct mkey {
char *mk_reserved;
@@ -34,7 +28,6 @@ struct mkey {
{"else", K_ELSE},
{"endif", K_ENDIF},
{"error", K_ERROR},
{"warning", K_WARNING},
{"if", K_IF},
{"ifdef", K_IFDEF},
{"ifndef", K_IFNDEF},
@@ -45,7 +38,7 @@ struct mkey {
{0, K_UNKNOWN}
};
void init_pp()
init_pp()
{
static char *months[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
@@ -62,10 +55,10 @@ void init_pp()
id_resmac field of the identifier.
*/
{
struct mkey *mk = &mkey[0];
register struct mkey *mk = &mkey[0];
while (mk->mk_reserved) {
struct idf *idf = str2idf(mk->mk_reserved, 0);
register struct idf *idf = str2idf(mk->mk_reserved, 0);
if (idf->id_resmac)
fatal("maximum identifier length insufficient");

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