RUN: /usr/share/launchpad-buildd/slavebin/slave-prep Forking launchpad-buildd slave process... Kernel version: Linux lcy01-amd64-001 4.4.0-98-generic #121-Ubuntu SMP Tue Oct 10 14:24:03 UTC 2017 x86_64 Buildd toolchain package versions: launchpad-buildd_154 python-lpbuildd_154 sbuild_0.67.0-2ubuntu7.1 bzr-builder_0.7.3+bzr174~ppa13~ubuntu14.10.1 bzr_2.7.0-2ubuntu3.1 git-build-recipe_0.3.4~git201611291343.dcee459~ubuntu16.04.1 git_1:2.7.4-0ubuntu1.3 dpkg-dev_1.18.4ubuntu1.2 python-debian_0.1.27ubuntu2. Syncing the system clock with the buildd NTP service... 4 Nov 10:28:44 ntpdate[1784]: adjust time server 10.211.37.1 offset 0.002375 sec RUN: /usr/share/launchpad-buildd/slavebin/in-target unpack-chroot --backend=chroot --series=precise --arch=amd64 PACKAGEBUILD-13675837 /home/buildd/filecache-default/575690328fa1961d2fcee6c342de2e8e84a88778 Creating target for build PACKAGEBUILD-13675837 RUN: /usr/share/launchpad-buildd/slavebin/in-target mount-chroot --backend=chroot --series=precise --arch=amd64 PACKAGEBUILD-13675837 Starting target for build PACKAGEBUILD-13675837 RUN: /usr/share/launchpad-buildd/slavebin/in-target override-sources-list --backend=chroot --series=precise --arch=amd64 PACKAGEBUILD-13675837 'deb http://ppa.launchpad.net/tormodvolden/m6809/ubuntu precise main' 'deb http://ftpmaster.internal/ubuntu precise main restricted universe multiverse' 'deb http://ftpmaster.internal/ubuntu precise-security main restricted universe multiverse' 'deb http://ftpmaster.internal/ubuntu precise-updates main restricted universe multiverse' Overriding sources.list in build-PACKAGEBUILD-13675837 RUN: /usr/share/launchpad-buildd/slavebin/in-target add-trusted-keys --backend=chroot --series=precise --arch=amd64 PACKAGEBUILD-13675837 Adding trusted keys to build-PACKAGEBUILD-13675837 OK /etc/apt/trusted.gpg -------------------- pub 1024D/437D05B5 2004-09-12 uid Ubuntu Archive Automatic Signing Key sub 2048g/79164387 2004-09-12 pub 1024D/FBB75451 2004-12-30 uid Ubuntu CD Image Automatic Signing Key pub 1024R/96DD5C9A 2009-01-18 uid Launchpad PPA for Tormod Volden RUN: /usr/share/launchpad-buildd/slavebin/in-target update-debian-chroot --backend=chroot --series=precise --arch=amd64 PACKAGEBUILD-13675837 Updating target for build PACKAGEBUILD-13675837 Ign http://ftpmaster.internal precise InRelease Get:1 http://ppa.launchpad.net precise InRelease [13.3 kB] Get:2 http://ftpmaster.internal precise-security InRelease [55.7 kB] Get:3 http://ftpmaster.internal precise-updates InRelease [55.7 kB] Get:4 http://ftpmaster.internal precise Release.gpg [198 B] Get:5 http://ftpmaster.internal precise Release [49.6 kB] Get:6 http://ftpmaster.internal precise-security/main amd64 Packages [375 kB] Get:7 http://ftpmaster.internal precise-security/restricted amd64 Packages [10.9 kB] Get:8 http://ftpmaster.internal precise-security/universe amd64 Packages [145 kB] Get:9 http://ftpmaster.internal precise-security/multiverse amd64 Packages [3367 B] Get:10 http://ftpmaster.internal precise-security/main TranslationIndex [208 B] Get:11 http://ftpmaster.internal precise-security/multiverse TranslationIndex [199 B] Get:12 http://ftpmaster.internal precise-security/restricted TranslationIndex [202 B] Get:13 http://ftpmaster.internal precise-security/universe TranslationIndex [205 B] Get:14 http://ftpmaster.internal precise-updates/main amd64 Packages [741 kB] Get:15 http://ppa.launchpad.net precise/main amd64 Packages [1588 B] Get:16 http://ppa.launchpad.net precise/main TranslationIndex [199 B] Get:17 http://ftpmaster.internal precise-updates/restricted amd64 Packages [15.4 kB] Get:18 http://ftpmaster.internal precise-updates/universe amd64 Packages [288 kB] Get:19 http://ppa.launchpad.net precise/main Translation-en [1197 B] Get:20 http://ftpmaster.internal precise-updates/multiverse amd64 Packages [17.1 kB] Get:21 http://ftpmaster.internal precise-updates/main TranslationIndex [208 B] Get:22 http://ftpmaster.internal precise-updates/multiverse TranslationIndex [202 B] Get:23 http://ftpmaster.internal precise-updates/restricted TranslationIndex [202 B] Get:24 http://ftpmaster.internal precise-updates/universe TranslationIndex [205 B] Get:25 http://ftpmaster.internal precise/main amd64 Packages [1273 kB] Get:26 http://ftpmaster.internal precise/restricted amd64 Packages [8452 B] Get:27 http://ftpmaster.internal precise/universe amd64 Packages [4786 kB] Get:28 http://ftpmaster.internal precise/multiverse amd64 Packages [119 kB] Get:29 http://ftpmaster.internal precise/main TranslationIndex [3706 B] Get:30 http://ftpmaster.internal precise/multiverse TranslationIndex [2676 B] Get:31 http://ftpmaster.internal precise/restricted TranslationIndex [2596 B] Get:32 http://ftpmaster.internal precise/universe TranslationIndex [2922 B] Get:33 http://ftpmaster.internal precise-security/main Translation-en [188 kB] Get:34 http://ftpmaster.internal precise-security/multiverse Translation-en [1993 B] Get:35 http://ftpmaster.internal precise-security/restricted Translation-en [2802 B] Get:36 http://ftpmaster.internal precise-security/universe Translation-en [93.2 kB] Get:37 http://ftpmaster.internal precise-updates/main Translation-en [344 kB] Get:38 http://ftpmaster.internal precise-updates/multiverse Translation-en [10.1 kB] Get:39 http://ftpmaster.internal precise-updates/restricted Translation-en [3686 B] Get:40 http://ftpmaster.internal precise-updates/universe Translation-en [174 kB] Get:41 http://ftpmaster.internal precise/main Translation-en [726 kB] Get:42 http://ftpmaster.internal precise/multiverse Translation-en [93.4 kB] Get:43 http://ftpmaster.internal precise/restricted Translation-en [2395 B] Get:44 http://ftpmaster.internal precise/universe Translation-en [3341 kB] Fetched 13.0 MB in 3s (3369 kB/s) Reading package lists... Reading package lists... Building dependency tree... Reading state information... The following packages will be upgraded: apt apt-transport-https base-files bash binutils bsdutils build-essential busybox-initramfs ca-certificates coreutils cpio dpkg dpkg-dev e2fslibs e2fsprogs gnupg gpgv ifupdown initramfs-tools initramfs-tools-bin initscripts iproute libapt-pkg4.12 libasn1-8-heimdal libblkid1 libc-bin libc-dev-bin libc6 libc6-dev libcomerr2 libcurl3-gnutls libdbus-1-3 libdpkg-perl libdrm-intel1 libdrm-nouveau1a libdrm-radeon1 libdrm2 libelf1 libgcrypt11 libglib2.0-0 libgnutls26 libgssapi-krb5-2 libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal libhx509-5-heimdal libidn11 libk5crypto3 libkrb5-26-heimdal libkrb5-3 libkrb5support0 libldap-2.4-2 liblockfile-bin liblockfile1 libmount1 libnih-dbus1 libnih1 libpam-modules libpam-modules-bin libpam-runtime libpam0g libpciaccess0 libpcre3 libplymouth2 libpng12-0 libroken18-heimdal libsasl2-2 libsqlite3-0 libss2 libssl1.0.0 libtasn1-3 libudev0 libuuid1 libwind0-heimdal linux-libc-dev login lsb-base make makedev mount mountall multiarch-support openssl optipng passwd patch perl perl-base perl-modules pkg-create-dbgsym plymouth procps python-minimal python2.7-minimal sysv-rc sysvinit-utils tar tzdata ubuntu-keyring udev upstart util-linux 103 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 46.0 MB of archives. After this operation, 249 kB of additional disk space will be used. WARNING: The following packages cannot be authenticated! base-files bash dpkg coreutils sysv-rc plymouth libplymouth2 initramfs-tools-bin initramfs-tools mountall initscripts upstart libc-dev-bin libc6-dev libc-bin libc6 sysvinit-utils libdbus-1-3 libdrm2 libpciaccess0 libdrm-intel1 libdrm-nouveau1a libdrm-radeon1 libpcre3 libglib2.0-0 libudev0 busybox-initramfs cpio lsb-base tzdata util-linux procps udev libpng12-0 makedev libnih-dbus1 libnih1 mount libpam0g libpam-modules-bin libpam-modules passwd iproute ifupdown linux-libc-dev e2fslibs e2fsprogs login perl perl-base perl-modules tar bsdutils libssl1.0.0 python2.7-minimal python-minimal libapt-pkg4.12 ubuntu-keyring gpgv gnupg apt libuuid1 libblkid1 libcomerr2 libmount1 libss2 liblockfile-bin liblockfile1 libsqlite3-0 libelf1 libroken18-heimdal libasn1-8-heimdal libgcrypt11 libtasn1-3 libgnutls26 libk5crypto3 libgssapi-krb5-2 libkrb5-3 libkrb5support0 libidn11 libhcrypto4-heimdal libheimbase1-heimdal libwind0-heimdal libhx509-5-heimdal libkrb5-26-heimdal libheimntlm0-heimdal libgssapi3-heimdal libsasl2-2 libldap-2.4-2 openssl ca-certificates libcurl3-gnutls libpam-runtime multiarch-support apt-transport-https binutils make dpkg-dev libdpkg-perl patch build-essential optipng pkg-create-dbgsym Authentication warning overridden. Get:1 http://ftpmaster.internal/ubuntu/ precise-updates/main base-files amd64 6.5ubuntu6.8 [68.2 kB] Get:2 http://ftpmaster.internal/ubuntu/ precise-security/main bash amd64 4.2-2ubuntu2.6 [641 kB] Get:3 http://ftpmaster.internal/ubuntu/ precise-updates/main dpkg amd64 1.16.1.2ubuntu7.8 [1828 kB] Get:4 http://ftpmaster.internal/ubuntu/ precise-security/main coreutils amd64 8.13-3ubuntu3.3 [2234 kB] Get:5 http://ftpmaster.internal/ubuntu/ precise-updates/main sysv-rc all 2.88dsf-13.10ubuntu11.1 [44.6 kB] Get:6 http://ftpmaster.internal/ubuntu/ precise-updates/main plymouth amd64 0.8.2-2ubuntu31.1 [123 kB] Get:7 http://ftpmaster.internal/ubuntu/ precise-updates/main libplymouth2 amd64 0.8.2-2ubuntu31.1 [92.0 kB] Get:8 http://ftpmaster.internal/ubuntu/ precise-security/main initramfs-tools-bin amd64 0.99ubuntu13.5 [9782 B] Get:9 http://ftpmaster.internal/ubuntu/ precise-security/main initramfs-tools all 0.99ubuntu13.5 [49.0 kB] Get:10 http://ftpmaster.internal/ubuntu/ precise-updates/main mountall amd64 2.36.4ubuntu0.1 [67.5 kB] Get:11 http://ftpmaster.internal/ubuntu/ precise-updates/main initscripts amd64 2.88dsf-13.10ubuntu11.1 [28.1 kB] Get:12 http://ftpmaster.internal/ubuntu/ precise-updates/main upstart amd64 1.5-0ubuntu7.3 [309 kB] Get:13 http://ftpmaster.internal/ubuntu/ precise-security/main libc-dev-bin amd64 2.15-0ubuntu10.18 [84.5 kB] Get:14 http://ftpmaster.internal/ubuntu/ precise-security/main libc6-dev amd64 2.15-0ubuntu10.18 [2948 kB] Get:15 http://ftpmaster.internal/ubuntu/ precise-security/main libc-bin amd64 2.15-0ubuntu10.18 [1178 kB] Get:16 http://ftpmaster.internal/ubuntu/ precise-security/main libc6 amd64 2.15-0ubuntu10.18 [4646 kB] Get:17 http://ftpmaster.internal/ubuntu/ precise-updates/main sysvinit-utils amd64 2.88dsf-13.10ubuntu11.1 [60.2 kB] Get:18 http://ftpmaster.internal/ubuntu/ precise-security/main libdbus-1-3 amd64 1.4.18-1ubuntu1.8 [146 kB] Get:19 http://ftpmaster.internal/ubuntu/ precise-security/main libdrm2 amd64 2.4.52-1~precise2 [26.1 kB] Get:20 http://ftpmaster.internal/ubuntu/ precise-updates/main libpciaccess0 amd64 0.12.902-1ubuntu0.2 [20.8 kB] Get:21 http://ftpmaster.internal/ubuntu/ precise-security/main libdrm-intel1 amd64 2.4.52-1~precise2 [65.6 kB] Get:22 http://ftpmaster.internal/ubuntu/ precise-security/main libdrm-nouveau1a amd64 2.4.52-1~precise2 [14.0 kB] Get:23 http://ftpmaster.internal/ubuntu/ precise-security/main libdrm-radeon1 amd64 2.4.52-1~precise2 [27.8 kB] Get:24 http://ftpmaster.internal/ubuntu/ precise-security/main libpcre3 amd64 8.12-4ubuntu0.2 [149 kB] Get:25 http://ftpmaster.internal/ubuntu/ precise-updates/main libglib2.0-0 amd64 2.32.4-0ubuntu1 [1200 kB] Get:26 http://ftpmaster.internal/ubuntu/ precise-updates/main libudev0 amd64 175-0ubuntu9.10 [27.8 kB] Get:27 http://ftpmaster.internal/ubuntu/ precise-updates/main busybox-initramfs amd64 1:1.18.5-1ubuntu4.1 [183 kB] Get:28 http://ftpmaster.internal/ubuntu/ precise-security/main cpio amd64 2.11-7ubuntu3.2 [116 kB] Get:29 http://ftpmaster.internal/ubuntu/ precise-updates/main lsb-base all 4.0-0ubuntu20.3 [10.5 kB] Get:30 http://ftpmaster.internal/ubuntu/ precise-security/main tzdata all 2016j-0ubuntu0.12.04 [434 kB] Get:31 http://ftpmaster.internal/ubuntu/ precise-updates/main util-linux amd64 2.20.1-1ubuntu3.1 [596 kB] Get:32 http://ftpmaster.internal/ubuntu/ precise-updates/main procps amd64 1:3.2.8-11ubuntu6.4 [233 kB] Get:33 http://ftpmaster.internal/ubuntu/ precise-updates/main udev amd64 175-0ubuntu9.10 [324 kB] Get:34 http://ftpmaster.internal/ubuntu/ precise-security/main libpng12-0 amd64 1.2.46-3ubuntu4.2 [133 kB] Get:35 http://ftpmaster.internal/ubuntu/ precise-updates/main makedev all 2.3.1-89ubuntu3 [27.7 kB] Get:36 http://ftpmaster.internal/ubuntu/ precise-updates/main libnih-dbus1 amd64 1.0.3-4ubuntu9.1 [16.0 kB] Get:37 http://ftpmaster.internal/ubuntu/ precise-updates/main libnih1 amd64 1.0.3-4ubuntu9.1 [54.8 kB] Get:38 http://ftpmaster.internal/ubuntu/ precise-updates/main mount amd64 2.20.1-1ubuntu3.1 [166 kB] Get:39 http://ftpmaster.internal/ubuntu/ precise-security/main libpam0g amd64 1.1.3-7ubuntu2.3 [61.8 kB] Get:40 http://ftpmaster.internal/ubuntu/ precise-security/main libpam-modules-bin amd64 1.1.3-7ubuntu2.3 [42.4 kB] Get:41 http://ftpmaster.internal/ubuntu/ precise-security/main libpam-modules amd64 1.1.3-7ubuntu2.3 [276 kB] Get:42 http://ftpmaster.internal/ubuntu/ precise-updates/main passwd amd64 1:4.1.4.2+svn3283-3ubuntu5.1 [959 kB] Get:43 http://ftpmaster.internal/ubuntu/ precise-updates/main iproute amd64 20111117-1ubuntu2.3 [444 kB] Get:44 http://ftpmaster.internal/ubuntu/ precise-updates/main ifupdown amd64 0.7~beta2ubuntu11.1 [48.3 kB] Get:45 http://ftpmaster.internal/ubuntu/ precise-security/main linux-libc-dev amd64 3.2.0-126.169 [848 kB] Get:46 http://ftpmaster.internal/ubuntu/ precise-updates/main e2fslibs amd64 1.42-1ubuntu2.3 [188 kB] Get:47 http://ftpmaster.internal/ubuntu/ precise-updates/main e2fsprogs amd64 1.42-1ubuntu2.3 [965 kB] Get:48 http://ftpmaster.internal/ubuntu/ precise-updates/main login amd64 1:4.1.4.2+svn3283-3ubuntu5.1 [291 kB] Get:49 http://ftpmaster.internal/ubuntu/ precise-security/main perl amd64 5.14.2-6ubuntu2.5 [4412 kB] Get:50 http://ftpmaster.internal/ubuntu/ precise-security/main perl-base amd64 5.14.2-6ubuntu2.5 [1513 kB] Get:51 http://ftpmaster.internal/ubuntu/ precise-security/main perl-modules all 5.14.2-6ubuntu2.5 [3397 kB] Get:52 http://ftpmaster.internal/ubuntu/ precise-security/main tar amd64 1.26-4ubuntu1.1 [218 kB] Get:53 http://ftpmaster.internal/ubuntu/ precise-updates/main bsdutils amd64 1:2.20.1-1ubuntu3.1 [39.7 kB] Get:54 http://ftpmaster.internal/ubuntu/ precise-security/main libssl1.0.0 amd64 1.0.1-4ubuntu5.39 [1054 kB] Get:55 http://ftpmaster.internal/ubuntu/ precise-security/main python2.7-minimal amd64 2.7.3-0ubuntu3.9 [1745 kB] Get:56 http://ftpmaster.internal/ubuntu/ precise-updates/main python-minimal amd64 2.7.3-0ubuntu2.2 [29.7 kB] Get:57 http://ftpmaster.internal/ubuntu/ precise-updates/main libapt-pkg4.12 amd64 0.8.16~exp12ubuntu10.27 [934 kB] Get:58 http://ftpmaster.internal/ubuntu/ precise-updates/main ubuntu-keyring all 2011.11.21.1 [16.7 kB] Get:59 http://ftpmaster.internal/ubuntu/ precise-security/main gpgv amd64 1.4.11-3ubuntu2.10 [186 kB] Get:60 http://ftpmaster.internal/ubuntu/ precise-security/main gnupg amd64 1.4.11-3ubuntu2.10 [809 kB] Get:61 http://ftpmaster.internal/ubuntu/ precise-updates/main apt amd64 0.8.16~exp12ubuntu10.27 [1098 kB] Get:62 http://ftpmaster.internal/ubuntu/ precise-updates/main libuuid1 amd64 2.20.1-1ubuntu3.1 [12.8 kB] Get:63 http://ftpmaster.internal/ubuntu/ precise-updates/main libblkid1 amd64 2.20.1-1ubuntu3.1 [73.7 kB] Get:64 http://ftpmaster.internal/ubuntu/ precise-updates/main libcomerr2 amd64 1.42-1ubuntu2.3 [57.2 kB] Get:65 http://ftpmaster.internal/ubuntu/ precise-updates/main libmount1 amd64 2.20.1-1ubuntu3.1 [71.5 kB] Get:66 http://ftpmaster.internal/ubuntu/ precise-updates/main libss2 amd64 1.42-1ubuntu2.3 [62.3 kB] Get:67 http://ftpmaster.internal/ubuntu/ precise-updates/main liblockfile-bin amd64 1.09-3ubuntu0.1 [12.3 kB] Get:68 http://ftpmaster.internal/ubuntu/ precise-updates/main liblockfile1 amd64 1.09-3ubuntu0.1 [9232 B] Get:69 http://ftpmaster.internal/ubuntu/ precise-security/main libsqlite3-0 amd64 3.7.9-2ubuntu1.2 [349 kB] Get:70 http://ftpmaster.internal/ubuntu/ precise-security/main libelf1 amd64 0.152-1ubuntu3.1 [42.8 kB] Get:71 http://ftpmaster.internal/ubuntu/ precise-updates/main libroken18-heimdal amd64 1.6~git20120311.dfsg.1-2ubuntu0.1 [46.0 kB] Get:72 http://ftpmaster.internal/ubuntu/ precise-updates/main libasn1-8-heimdal amd64 1.6~git20120311.dfsg.1-2ubuntu0.1 [220 kB] Get:73 http://ftpmaster.internal/ubuntu/ precise-security/main libgcrypt11 amd64 1.5.0-3ubuntu0.6 [282 kB] Get:74 http://ftpmaster.internal/ubuntu/ precise-security/main libtasn1-3 amd64 2.10-1ubuntu1.5 [43.6 kB] Get:75 http://ftpmaster.internal/ubuntu/ precise-security/main libgnutls26 amd64 2.12.14-5ubuntu3.14 [461 kB] Get:76 http://ftpmaster.internal/ubuntu/ precise-security/main libk5crypto3 amd64 1.10+dfsg~beta1-2ubuntu0.7 [80.1 kB] Get:77 http://ftpmaster.internal/ubuntu/ precise-security/main libgssapi-krb5-2 amd64 1.10+dfsg~beta1-2ubuntu0.7 [119 kB] Get:78 http://ftpmaster.internal/ubuntu/ precise-security/main libkrb5-3 amd64 1.10+dfsg~beta1-2ubuntu0.7 [355 kB] Get:79 http://ftpmaster.internal/ubuntu/ precise-security/main libkrb5support0 amd64 1.10+dfsg~beta1-2ubuntu0.7 [24.9 kB] Get:80 http://ftpmaster.internal/ubuntu/ precise-security/main libidn11 amd64 1.23-2ubuntu0.1 [112 kB] Get:81 http://ftpmaster.internal/ubuntu/ precise-updates/main libhcrypto4-heimdal amd64 1.6~git20120311.dfsg.1-2ubuntu0.1 [103 kB] Get:82 http://ftpmaster.internal/ubuntu/ precise-updates/main libheimbase1-heimdal amd64 1.6~git20120311.dfsg.1-2ubuntu0.1 [33.1 kB] Get:83 http://ftpmaster.internal/ubuntu/ precise-updates/main libwind0-heimdal amd64 1.6~git20120311.dfsg.1-2ubuntu0.1 [77.8 kB] Get:84 http://ftpmaster.internal/ubuntu/ precise-updates/main libhx509-5-heimdal amd64 1.6~git20120311.dfsg.1-2ubuntu0.1 [125 kB] Get:85 http://ftpmaster.internal/ubuntu/ precise-updates/main libkrb5-26-heimdal amd64 1.6~git20120311.dfsg.1-2ubuntu0.1 [234 kB] Get:86 http://ftpmaster.internal/ubuntu/ precise-updates/main libheimntlm0-heimdal amd64 1.6~git20120311.dfsg.1-2ubuntu0.1 [16.0 kB] Get:87 http://ftpmaster.internal/ubuntu/ precise-updates/main libgssapi3-heimdal amd64 1.6~git20120311.dfsg.1-2ubuntu0.1 [108 kB] Get:88 http://ftpmaster.internal/ubuntu/ precise-updates/main libsasl2-2 amd64 2.1.25.dfsg1-3ubuntu0.1 [69.1 kB] Get:89 http://ftpmaster.internal/ubuntu/ precise-security/main libldap-2.4-2 amd64 2.4.28-1.1ubuntu4.6 [185 kB] Get:90 http://ftpmaster.internal/ubuntu/ precise-security/main openssl amd64 1.0.1-4ubuntu5.39 [524 kB] Get:91 http://ftpmaster.internal/ubuntu/ precise-security/main ca-certificates all 20160104ubuntu0.12.04.1 [208 kB] Get:92 http://ftpmaster.internal/ubuntu/ precise-security/main libcurl3-gnutls amd64 7.22.0-3ubuntu4.17 [228 kB] Get:93 http://ftpmaster.internal/ubuntu/ precise-security/main libpam-runtime all 1.1.3-7ubuntu2.3 [40.6 kB] Get:94 http://ftpmaster.internal/ubuntu/ precise-security/main multiarch-support amd64 2.15-0ubuntu10.18 [4482 B] Get:95 http://ftpmaster.internal/ubuntu/ precise-updates/main apt-transport-https amd64 0.8.16~exp12ubuntu10.27 [16.4 kB] Get:96 http://ftpmaster.internal/ubuntu/ precise-security/main binutils amd64 2.22-6ubuntu1.4 [2653 kB] Get:97 http://ftpmaster.internal/ubuntu/ precise-updates/main make amd64 3.81-8.1ubuntu1.1 [119 kB] Get:98 http://ftpmaster.internal/ubuntu/ precise-updates/main dpkg-dev all 1.16.1.2ubuntu7.8 [468 kB] Get:99 http://ftpmaster.internal/ubuntu/ precise-updates/main libdpkg-perl all 1.16.1.2ubuntu7.8 [181 kB] Get:100 http://ftpmaster.internal/ubuntu/ precise-security/main patch amd64 2.6.1-3ubuntu0.1 [80.0 kB] Get:101 http://ftpmaster.internal/ubuntu/ precise-updates/main build-essential amd64 11.5ubuntu2.1 [5816 B] Get:102 http://ftpmaster.internal/ubuntu/ precise-security/main optipng amd64 0.6.4-1ubuntu0.12.04.1 [89.2 kB] Get:103 http://ftpmaster.internal/ubuntu/ precise-security/main pkg-create-dbgsym all 0.50.2 [9520 B] debconf: delaying package configuration, since apt-utils is not installed Fetched 46.0 MB in 1s (35.1 MB/s) (Reading database ... 12243 files and directories currently installed.) Preparing to replace base-files 6.5ubuntu6 (using .../base-files_6.5ubuntu6.8_amd64.deb) ... Unpacking replacement base-files ... Setting up base-files (6.5ubuntu6.8) ... Installing new version of config file /etc/issue ... Installing new version of config file /etc/issue.net ... Installing new version of config file /etc/lsb-release ... (Reading database ... 12244 files and directories currently installed.) Preparing to replace bash 4.2-2ubuntu2 (using .../bash_4.2-2ubuntu2.6_amd64.deb) ... Unpacking replacement bash ... Setting up bash (4.2-2ubuntu2.6) ... update-alternatives: using /usr/share/man/man7/bash-builtins.7.gz to provide /usr/share/man/man7/builtins.7.gz (builtins.7.gz) in auto mode. (Reading database ... 12244 files and directories currently installed.) Preparing to replace dpkg 1.16.1.2ubuntu7 (using .../dpkg_1.16.1.2ubuntu7.8_amd64.deb) ... Unpacking replacement dpkg ... Setting up dpkg (1.16.1.2ubuntu7.8) ... (Reading database ... 12245 files and directories currently installed.) Preparing to replace coreutils 8.13-3ubuntu3 (using .../coreutils_8.13-3ubuntu3.3_amd64.deb) ... Unpacking replacement coreutils ... Setting up coreutils (8.13-3ubuntu3.3) ... (Reading database ... 12245 files and directories currently installed.) Preparing to replace sysv-rc 2.88dsf-13.10ubuntu11 (using .../sysv-rc_2.88dsf-13.10ubuntu11.1_all.deb) ... Unpacking replacement sysv-rc ... Preparing to replace plymouth 0.8.2-2ubuntu30 (using .../plymouth_0.8.2-2ubuntu31.1_amd64.deb) ... Unpacking replacement plymouth ... Preparing to replace libplymouth2 0.8.2-2ubuntu30 (using .../libplymouth2_0.8.2-2ubuntu31.1_amd64.deb) ... Unpacking replacement libplymouth2 ... Preparing to replace initramfs-tools-bin 0.99ubuntu13 (using .../initramfs-tools-bin_0.99ubuntu13.5_amd64.deb) ... Unpacking replacement initramfs-tools-bin ... Preparing to replace initramfs-tools 0.99ubuntu13 (using .../initramfs-tools_0.99ubuntu13.5_all.deb) ... Unpacking replacement initramfs-tools ... Preparing to replace mountall 2.36 (using .../mountall_2.36.4ubuntu0.1_amd64.deb) ... Unpacking replacement mountall ... Preparing to replace initscripts 2.88dsf-13.10ubuntu11 (using .../initscripts_2.88dsf-13.10ubuntu11.1_amd64.deb) ... Unpacking replacement initscripts ... Preparing to replace upstart 1.5-0ubuntu5 (using .../upstart_1.5-0ubuntu7.3_amd64.deb) ... Unpacking replacement upstart ... Preparing to replace libc-dev-bin 2.15-0ubuntu10 (using .../libc-dev-bin_2.15-0ubuntu10.18_amd64.deb) ... Unpacking replacement libc-dev-bin ... Preparing to replace libc6-dev 2.15-0ubuntu10 (using .../libc6-dev_2.15-0ubuntu10.18_amd64.deb) ... Unpacking replacement libc6-dev ... Preparing to replace libc-bin 2.15-0ubuntu10 (using .../libc-bin_2.15-0ubuntu10.18_amd64.deb) ... Unpacking replacement libc-bin ... Setting up libc-bin (2.15-0ubuntu10.18) ... (Reading database ... 12245 files and directories currently installed.) Preparing to replace libc6 2.15-0ubuntu10 (using .../libc6_2.15-0ubuntu10.18_amd64.deb) ... Unpacking replacement libc6 ... Setting up libc6 (2.15-0ubuntu10.18) ... Processing triggers for libc-bin ... ldconfig deferred processing now taking place (Reading database ... 12245 files and directories currently installed.) Preparing to replace sysvinit-utils 2.88dsf-13.10ubuntu11 (using .../sysvinit-utils_2.88dsf-13.10ubuntu11.1_amd64.deb) ... Unpacking replacement sysvinit-utils ... Preparing to replace libdbus-1-3 1.4.18-1ubuntu1 (using .../libdbus-1-3_1.4.18-1ubuntu1.8_amd64.deb) ... Unpacking replacement libdbus-1-3 ... Preparing to replace libdrm2 2.4.32-1ubuntu1 (using .../libdrm2_2.4.52-1~precise2_amd64.deb) ... Unpacking replacement libdrm2 ... Preparing to replace libpciaccess0 0.12.902-1 (using .../libpciaccess0_0.12.902-1ubuntu0.2_amd64.deb) ... Unpacking replacement libpciaccess0 ... Preparing to replace libdrm-intel1 2.4.32-1ubuntu1 (using .../libdrm-intel1_2.4.52-1~precise2_amd64.deb) ... Unpacking replacement libdrm-intel1 ... Preparing to replace libdrm-nouveau1a 2.4.32-1ubuntu1 (using .../libdrm-nouveau1a_2.4.52-1~precise2_amd64.deb) ... Unpacking replacement libdrm-nouveau1a ... Preparing to replace libdrm-radeon1 2.4.32-1ubuntu1 (using .../libdrm-radeon1_2.4.52-1~precise2_amd64.deb) ... Unpacking replacement libdrm-radeon1 ... Preparing to replace libpcre3 8.12-4 (using .../libpcre3_8.12-4ubuntu0.2_amd64.deb) ... Unpacking replacement libpcre3 ... Preparing to replace libglib2.0-0 2.32.1-0ubuntu2 (using .../libglib2.0-0_2.32.4-0ubuntu1_amd64.deb) ... Unpacking replacement libglib2.0-0 ... Preparing to replace libudev0 175-0ubuntu9 (using .../libudev0_175-0ubuntu9.10_amd64.deb) ... Unpacking replacement libudev0 ... Preparing to replace busybox-initramfs 1:1.18.5-1ubuntu4 (using .../busybox-initramfs_1%3a1.18.5-1ubuntu4.1_amd64.deb) ... Unpacking replacement busybox-initramfs ... Preparing to replace cpio 2.11-7ubuntu3 (using .../cpio_2.11-7ubuntu3.2_amd64.deb) ... Unpacking replacement cpio ... Preparing to replace lsb-base 4.0-0ubuntu20 (using .../lsb-base_4.0-0ubuntu20.3_all.deb) ... Unpacking replacement lsb-base ... Setting up lsb-base (4.0-0ubuntu20.3) ... (Reading database ... 12245 files and directories currently installed.) Preparing to replace tzdata 2012b-1 (using .../tzdata_2016j-0ubuntu0.12.04_all.deb) ... Unpacking replacement tzdata ... Setting up tzdata (2016j-0ubuntu0.12.04) ... Current default time zone: 'Etc/UTC' Local time is now: Sat Nov 4 10:28:59 UTC 2017. Universal Time is now: Sat Nov 4 10:28:59 UTC 2017. Run 'dpkg-reconfigure tzdata' if you wish to change it. (Reading database ... 12276 files and directories currently installed.) Preparing to replace util-linux 2.20.1-1ubuntu3 (using .../util-linux_2.20.1-1ubuntu3.1_amd64.deb) ... Unpacking replacement util-linux ... Setting up libdbus-1-3 (1.4.18-1ubuntu1.8) ... Setting up libudev0 (175-0ubuntu9.10) ... Setting up sysvinit-utils (2.88dsf-13.10ubuntu11.1) ... Setting up sysv-rc (2.88dsf-13.10ubuntu11.1) ... Setting up libdrm2 (2.4.52-1~precise2) ... Setting up libpciaccess0 (0.12.902-1ubuntu0.2) ... Setting up libdrm-intel1 (2.4.52-1~precise2) ... Setting up libdrm-nouveau1a (2.4.52-1~precise2) ... Setting up libdrm-radeon1 (2.4.52-1~precise2) ... Setting up libplymouth2 (0.8.2-2ubuntu31.1) ... Setting up initramfs-tools-bin (0.99ubuntu13.5) ... Setting up busybox-initramfs (1:1.18.5-1ubuntu4.1) ... Setting up cpio (2.11-7ubuntu3.2) ... Setting up upstart (1.5-0ubuntu7.3) ... Installing new version of config file /etc/logrotate.d/upstart ... Setting up util-linux (2.20.1-1ubuntu3.1) ... Setting up initramfs-tools (0.99ubuntu13.5) ... update-initramfs: deferring update (trigger activated) Setting up mountall (2.36.4ubuntu0.1) ... Installing new version of config file /etc/init/mounted-dev.conf ... Setting up initscripts (2.88dsf-13.10ubuntu11.1) ... Setting up plymouth (0.8.2-2ubuntu31.1) ... update-initramfs: deferring update (trigger activated) Processing triggers for libc-bin ... ldconfig deferred processing now taking place Processing triggers for initramfs-tools ... (Reading database ... 12276 files and directories currently installed.) Preparing to replace procps 1:3.2.8-11ubuntu6 (using .../procps_1%3a3.2.8-11ubuntu6.4_amd64.deb) ... invoke-rc.d: policy-rc.d denied execution of stop. Unpacking replacement procps ... Preparing to replace udev 175-0ubuntu9 (using .../udev_175-0ubuntu9.10_amd64.deb) ... Adding 'diversion of /sbin/udevadm to /sbin/udevadm.upgrade by fake-udev' Unpacking replacement udev ... Preparing to replace libpng12-0 1.2.46-3ubuntu4 (using .../libpng12-0_1.2.46-3ubuntu4.2_amd64.deb) ... Unpacking replacement libpng12-0 ... Preparing to replace makedev 2.3.1-89ubuntu2 (using .../makedev_2.3.1-89ubuntu3_all.deb) ... Unpacking replacement makedev ... Preparing to replace libnih-dbus1 1.0.3-4ubuntu9 (using .../libnih-dbus1_1.0.3-4ubuntu9.1_amd64.deb) ... Unpacking replacement libnih-dbus1 ... Preparing to replace libnih1 1.0.3-4ubuntu9 (using .../libnih1_1.0.3-4ubuntu9.1_amd64.deb) ... Unpacking replacement libnih1 ... Preparing to replace mount 2.20.1-1ubuntu3 (using .../mount_2.20.1-1ubuntu3.1_amd64.deb) ... Unpacking replacement mount ... Setting up mount (2.20.1-1ubuntu3.1) ... (Reading database ... 12284 files and directories currently installed.) Preparing to replace libpam0g 1.1.3-7ubuntu2 (using .../libpam0g_1.1.3-7ubuntu2.3_amd64.deb) ... Unpacking replacement libpam0g ... Setting up libpam0g (1.1.3-7ubuntu2.3) ... Processing triggers for libc-bin ... ldconfig deferred processing now taking place (Reading database ... 12284 files and directories currently installed.) Preparing to replace libpam-modules-bin 1.1.3-7ubuntu2 (using .../libpam-modules-bin_1.1.3-7ubuntu2.3_amd64.deb) ... Unpacking replacement libpam-modules-bin ... Setting up libpam-modules-bin (1.1.3-7ubuntu2.3) ... (Reading database ... 12284 files and directories currently installed.) Preparing to replace libpam-modules 1.1.3-7ubuntu2 (using .../libpam-modules_1.1.3-7ubuntu2.3_amd64.deb) ... Unpacking replacement libpam-modules ... Setting up libpam-modules (1.1.3-7ubuntu2.3) ... (Reading database ... 12284 files and directories currently installed.) Preparing to replace passwd 1:4.1.4.2+svn3283-3ubuntu5 (using .../passwd_1%3a4.1.4.2+svn3283-3ubuntu5.1_amd64.deb) ... Unpacking replacement passwd ... Setting up passwd (1:4.1.4.2+svn3283-3ubuntu5.1) ... (Reading database ... 12286 files and directories currently installed.) Preparing to replace iproute 20111117-1ubuntu2 (using .../iproute_20111117-1ubuntu2.3_amd64.deb) ... Unpacking replacement iproute ... Preparing to replace ifupdown 0.7~beta2ubuntu8 (using .../ifupdown_0.7~beta2ubuntu11.1_amd64.deb) ... Unpacking replacement ifupdown ... Preparing to replace linux-libc-dev 3.2.0-23.36 (using .../linux-libc-dev_3.2.0-126.169_amd64.deb) ... Unpacking replacement linux-libc-dev ... Preparing to replace e2fslibs 1.42-1ubuntu2 (using .../e2fslibs_1.42-1ubuntu2.3_amd64.deb) ... Unpacking replacement e2fslibs ... Setting up e2fslibs (1.42-1ubuntu2.3) ... Processing triggers for libc-bin ... ldconfig deferred processing now taking place (Reading database ... 12290 files and directories currently installed.) Preparing to replace e2fsprogs 1.42-1ubuntu2 (using .../e2fsprogs_1.42-1ubuntu2.3_amd64.deb) ... Unpacking replacement e2fsprogs ... Setting up e2fsprogs (1.42-1ubuntu2.3) ... (Reading database ... 12290 files and directories currently installed.) Preparing to replace login 1:4.1.4.2+svn3283-3ubuntu5 (using .../login_1%3a4.1.4.2+svn3283-3ubuntu5.1_amd64.deb) ... Unpacking replacement login ... Setting up login (1:4.1.4.2+svn3283-3ubuntu5.1) ... (Reading database ... 12290 files and directories currently installed.) Preparing to replace perl 5.14.2-6ubuntu2 (using .../perl_5.14.2-6ubuntu2.5_amd64.deb) ... Unpacking replacement perl ... Preparing to replace perl-base 5.14.2-6ubuntu2 (using .../perl-base_5.14.2-6ubuntu2.5_amd64.deb) ... Unpacking replacement perl-base ... Setting up perl-base (5.14.2-6ubuntu2.5) ... (Reading database ... 12290 files and directories currently installed.) Preparing to replace perl-modules 5.14.2-6ubuntu2 (using .../perl-modules_5.14.2-6ubuntu2.5_all.deb) ... Unpacking replacement perl-modules ... Preparing to replace tar 1.26-4ubuntu1 (using .../tar_1.26-4ubuntu1.1_amd64.deb) ... Unpacking replacement tar ... Setting up tar (1.26-4ubuntu1.1) ... (Reading database ... 12290 files and directories currently installed.) Preparing to replace bsdutils 1:2.20.1-1ubuntu3 (using .../bsdutils_1%3a2.20.1-1ubuntu3.1_amd64.deb) ... Unpacking replacement bsdutils ... Setting up bsdutils (1:2.20.1-1ubuntu3.1) ... (Reading database ... 12290 files and directories currently installed.) Preparing to replace libssl1.0.0 1.0.1-4ubuntu3 (using .../libssl1.0.0_1.0.1-4ubuntu5.39_amd64.deb) ... Unpacking replacement libssl1.0.0 ... Setting up libssl1.0.0 (1.0.1-4ubuntu5.39) ... Processing triggers for libc-bin ... ldconfig deferred processing now taking place (Reading database ... 12290 files and directories currently installed.) Preparing to replace python2.7-minimal 2.7.3-0ubuntu3 (using .../python2.7-minimal_2.7.3-0ubuntu3.9_amd64.deb) ... Unpacking replacement python2.7-minimal ... Setting up python2.7-minimal (2.7.3-0ubuntu3.9) ... (Reading database ... 12290 files and directories currently installed.) Preparing to replace python-minimal 2.7.3-0ubuntu2 (using .../python-minimal_2.7.3-0ubuntu2.2_amd64.deb) ... Unpacking replacement python-minimal ... Setting up python-minimal (2.7.3-0ubuntu2.2) ... (Reading database ... 12290 files and directories currently installed.) Preparing to replace libapt-pkg4.12 0.8.16~exp12ubuntu10 (using .../libapt-pkg4.12_0.8.16~exp12ubuntu10.27_amd64.deb) ... Unpacking replacement libapt-pkg4.12 ... Setting up libapt-pkg4.12 (0.8.16~exp12ubuntu10.27) ... Processing triggers for libc-bin ... ldconfig deferred processing now taking place (Reading database ... 12290 files and directories currently installed.) Preparing to replace ubuntu-keyring 2011.11.21 (using .../ubuntu-keyring_2011.11.21.1_all.deb) ... Unpacking replacement ubuntu-keyring ... Setting up ubuntu-keyring (2011.11.21.1) ... gpg: key 437D05B5: "Ubuntu Archive Automatic Signing Key " not changed gpg: key FBB75451: "Ubuntu CD Image Automatic Signing Key " not changed gpg: key C0B21F32: public key "Ubuntu Archive Automatic Signing Key (2012) " imported gpg: key EFE21092: public key "Ubuntu CD Image Automatic Signing Key (2012) " imported gpg: Total number processed: 4 gpg: imported: 2 (RSA: 2) gpg: unchanged: 2 gpg: no ultimately trusted keys found (Reading database ... 12290 files and directories currently installed.) Preparing to replace gpgv 1.4.11-3ubuntu2 (using .../gpgv_1.4.11-3ubuntu2.10_amd64.deb) ... Unpacking replacement gpgv ... Setting up gpgv (1.4.11-3ubuntu2.10) ... (Reading database ... 12290 files and directories currently installed.) Preparing to replace gnupg 1.4.11-3ubuntu2 (using .../gnupg_1.4.11-3ubuntu2.10_amd64.deb) ... Unpacking replacement gnupg ... Setting up gnupg (1.4.11-3ubuntu2.10) ... (Reading database ... 12290 files and directories currently installed.) Preparing to replace apt 0.8.16~exp12ubuntu10 (using .../apt_0.8.16~exp12ubuntu10.27_amd64.deb) ... Unpacking replacement apt ... Setting up apt (0.8.16~exp12ubuntu10.27) ... Installing new version of config file /etc/apt/apt.conf.d/01autoremove ... gpg: key 437D05B5: "Ubuntu Archive Automatic Signing Key " not changed gpg: key FBB75451: "Ubuntu CD Image Automatic Signing Key " not changed gpg: key C0B21F32: "Ubuntu Archive Automatic Signing Key (2012) " not changed gpg: key EFE21092: "Ubuntu CD Image Automatic Signing Key (2012) " not changed gpg: Total number processed: 4 gpg: unchanged: 4 No packages found matching linux-image-[0-9]*. (Reading database ... 12291 files and directories currently installed.) Preparing to replace libuuid1 2.20.1-1ubuntu3 (using .../libuuid1_2.20.1-1ubuntu3.1_amd64.deb) ... Unpacking replacement libuuid1 ... Setting up libuuid1 (2.20.1-1ubuntu3.1) ... Processing triggers for libc-bin ... ldconfig deferred processing now taking place (Reading database ... 12291 files and directories currently installed.) Preparing to replace libblkid1 2.20.1-1ubuntu3 (using .../libblkid1_2.20.1-1ubuntu3.1_amd64.deb) ... Unpacking replacement libblkid1 ... Setting up libblkid1 (2.20.1-1ubuntu3.1) ... Processing triggers for libc-bin ... ldconfig deferred processing now taking place (Reading database ... 12291 files and directories currently installed.) Preparing to replace libcomerr2 1.42-1ubuntu2 (using .../libcomerr2_1.42-1ubuntu2.3_amd64.deb) ... Unpacking replacement libcomerr2 ... Setting up libcomerr2 (1.42-1ubuntu2.3) ... Processing triggers for libc-bin ... ldconfig deferred processing now taking place (Reading database ... 12291 files and directories currently installed.) Preparing to replace libmount1 2.20.1-1ubuntu3 (using .../libmount1_2.20.1-1ubuntu3.1_amd64.deb) ... Unpacking replacement libmount1 ... Setting up libmount1 (2.20.1-1ubuntu3.1) ... Processing triggers for libc-bin ... ldconfig deferred processing now taking place (Reading database ... 12291 files and directories currently installed.) Preparing to replace libss2 1.42-1ubuntu2 (using .../libss2_1.42-1ubuntu2.3_amd64.deb) ... Unpacking replacement libss2 ... Setting up libss2 (1.42-1ubuntu2.3) ... Processing triggers for libc-bin ... ldconfig deferred processing now taking place (Reading database ... 12291 files and directories currently installed.) Preparing to replace liblockfile-bin 1.09-3 (using .../liblockfile-bin_1.09-3ubuntu0.1_amd64.deb) ... Unpacking replacement liblockfile-bin ... Preparing to replace liblockfile1 1.09-3 (using .../liblockfile1_1.09-3ubuntu0.1_amd64.deb) ... Unpacking replacement liblockfile1 ... Preparing to replace libsqlite3-0 3.7.9-2ubuntu1 (using .../libsqlite3-0_3.7.9-2ubuntu1.2_amd64.deb) ... Unpacking replacement libsqlite3-0 ... Preparing to replace libelf1 0.152-1ubuntu3 (using .../libelf1_0.152-1ubuntu3.1_amd64.deb) ... Unpacking replacement libelf1 ... Preparing to replace libroken18-heimdal 1.6~git20120311.dfsg.1-2 (using .../libroken18-heimdal_1.6~git20120311.dfsg.1-2ubuntu0.1_amd64.deb) ... Unpacking replacement libroken18-heimdal ... Preparing to replace libasn1-8-heimdal 1.6~git20120311.dfsg.1-2 (using .../libasn1-8-heimdal_1.6~git20120311.dfsg.1-2ubuntu0.1_amd64.deb) ... Unpacking replacement libasn1-8-heimdal ... Preparing to replace libgcrypt11 1.5.0-3 (using .../libgcrypt11_1.5.0-3ubuntu0.6_amd64.deb) ... Unpacking replacement libgcrypt11 ... Preparing to replace libtasn1-3 2.10-1ubuntu1 (using .../libtasn1-3_2.10-1ubuntu1.5_amd64.deb) ... Unpacking replacement libtasn1-3 ... Preparing to replace libgnutls26 2.12.14-5ubuntu3 (using .../libgnutls26_2.12.14-5ubuntu3.14_amd64.deb) ... Unpacking replacement libgnutls26 ... Preparing to replace libk5crypto3 1.10+dfsg~beta1-2 (using .../libk5crypto3_1.10+dfsg~beta1-2ubuntu0.7_amd64.deb) ... Unpacking replacement libk5crypto3 ... Preparing to replace libgssapi-krb5-2 1.10+dfsg~beta1-2 (using .../libgssapi-krb5-2_1.10+dfsg~beta1-2ubuntu0.7_amd64.deb) ... Unpacking replacement libgssapi-krb5-2 ... Preparing to replace libkrb5-3 1.10+dfsg~beta1-2 (using .../libkrb5-3_1.10+dfsg~beta1-2ubuntu0.7_amd64.deb) ... Unpacking replacement libkrb5-3 ... Preparing to replace libkrb5support0 1.10+dfsg~beta1-2 (using .../libkrb5support0_1.10+dfsg~beta1-2ubuntu0.7_amd64.deb) ... Unpacking replacement libkrb5support0 ... Preparing to replace libidn11 1.23-2 (using .../libidn11_1.23-2ubuntu0.1_amd64.deb) ... Unpacking replacement libidn11 ... Preparing to replace libhcrypto4-heimdal 1.6~git20120311.dfsg.1-2 (using .../libhcrypto4-heimdal_1.6~git20120311.dfsg.1-2ubuntu0.1_amd64.deb) ... Unpacking replacement libhcrypto4-heimdal ... Preparing to replace libheimbase1-heimdal 1.6~git20120311.dfsg.1-2 (using .../libheimbase1-heimdal_1.6~git20120311.dfsg.1-2ubuntu0.1_amd64.deb) ... Unpacking replacement libheimbase1-heimdal ... Preparing to replace libwind0-heimdal 1.6~git20120311.dfsg.1-2 (using .../libwind0-heimdal_1.6~git20120311.dfsg.1-2ubuntu0.1_amd64.deb) ... Unpacking replacement libwind0-heimdal ... Preparing to replace libhx509-5-heimdal 1.6~git20120311.dfsg.1-2 (using .../libhx509-5-heimdal_1.6~git20120311.dfsg.1-2ubuntu0.1_amd64.deb) ... Unpacking replacement libhx509-5-heimdal ... Preparing to replace libkrb5-26-heimdal 1.6~git20120311.dfsg.1-2 (using .../libkrb5-26-heimdal_1.6~git20120311.dfsg.1-2ubuntu0.1_amd64.deb) ... Unpacking replacement libkrb5-26-heimdal ... Preparing to replace libheimntlm0-heimdal 1.6~git20120311.dfsg.1-2 (using .../libheimntlm0-heimdal_1.6~git20120311.dfsg.1-2ubuntu0.1_amd64.deb) ... Unpacking replacement libheimntlm0-heimdal ... Preparing to replace libgssapi3-heimdal 1.6~git20120311.dfsg.1-2 (using .../libgssapi3-heimdal_1.6~git20120311.dfsg.1-2ubuntu0.1_amd64.deb) ... Unpacking replacement libgssapi3-heimdal ... Preparing to replace libsasl2-2 2.1.25.dfsg1-3 (using .../libsasl2-2_2.1.25.dfsg1-3ubuntu0.1_amd64.deb) ... Unpacking replacement libsasl2-2 ... Preparing to replace libldap-2.4-2 2.4.28-1.1ubuntu4 (using .../libldap-2.4-2_2.4.28-1.1ubuntu4.6_amd64.deb) ... Unpacking replacement libldap-2.4-2 ... Preparing to replace openssl 1.0.1-4ubuntu3 (using .../openssl_1.0.1-4ubuntu5.39_amd64.deb) ... Unpacking replacement openssl ... Preparing to replace ca-certificates 20111211 (using .../ca-certificates_20160104ubuntu0.12.04.1_all.deb) ... Unpacking replacement ca-certificates ... Preparing to replace libcurl3-gnutls 7.22.0-3ubuntu4 (using .../libcurl3-gnutls_7.22.0-3ubuntu4.17_amd64.deb) ... Unpacking replacement libcurl3-gnutls ... Preparing to replace libpam-runtime 1.1.3-7ubuntu2 (using .../libpam-runtime_1.1.3-7ubuntu2.3_all.deb) ... Unpacking replacement libpam-runtime ... Setting up libpam-runtime (1.1.3-7ubuntu2.3) ... (Reading database ... 12309 files and directories currently installed.) Preparing to replace multiarch-support 2.15-0ubuntu10 (using .../multiarch-support_2.15-0ubuntu10.18_amd64.deb) ... Unpacking replacement multiarch-support ... Setting up multiarch-support (2.15-0ubuntu10.18) ... (Reading database ... 12309 files and directories currently installed.) Preparing to replace apt-transport-https 0.8.16~exp12ubuntu10 (using .../apt-transport-https_0.8.16~exp12ubuntu10.27_amd64.deb) ... Unpacking replacement apt-transport-https ... Preparing to replace binutils 2.22-6ubuntu1 (using .../binutils_2.22-6ubuntu1.4_amd64.deb) ... Unpacking replacement binutils ... Preparing to replace make 3.81-8.1ubuntu1 (using .../make_3.81-8.1ubuntu1.1_amd64.deb) ... Unpacking replacement make ... Preparing to replace dpkg-dev 1.16.1.2ubuntu7 (using .../dpkg-dev_1.16.1.2ubuntu7.8_all.deb) ... Unpacking replacement dpkg-dev ... Preparing to replace libdpkg-perl 1.16.1.2ubuntu7 (using .../libdpkg-perl_1.16.1.2ubuntu7.8_all.deb) ... Unpacking replacement libdpkg-perl ... Preparing to replace patch 2.6.1-3 (using .../patch_2.6.1-3ubuntu0.1_amd64.deb) ... Unpacking replacement patch ... Preparing to replace build-essential 11.5ubuntu2 (using .../build-essential_11.5ubuntu2.1_amd64.deb) ... Unpacking replacement build-essential ... Preparing to replace optipng 0.6.4-1 (using .../optipng_0.6.4-1ubuntu0.12.04.1_amd64.deb) ... Unpacking replacement optipng ... Preparing to replace pkg-create-dbgsym 0.50 (using .../pkg-create-dbgsym_0.50.2_all.deb) ... Unpacking replacement pkg-create-dbgsym ... Setting up libc-dev-bin (2.15-0ubuntu10.18) ... Setting up linux-libc-dev (3.2.0-126.169) ... Setting up libc6-dev (2.15-0ubuntu10.18) ... Setting up libpcre3 (8.12-4ubuntu0.2) ... Setting up libglib2.0-0 (2.32.4-0ubuntu1) ... No schema files found: doing nothing. Setting up procps (1:3.2.8-11ubuntu6.4) ... invoke-rc.d: policy-rc.d denied execution of start. Setting up udev (175-0ubuntu9.10) ... Installing new version of config file /etc/init/udev-fallback-graphics.conf ... invoke-rc.d: policy-rc.d denied execution of restart. Removing 'diversion of /sbin/udevadm to /sbin/udevadm.upgrade by fake-udev' update-initramfs: deferring update (trigger activated) Setting up libpng12-0 (1.2.46-3ubuntu4.2) ... Setting up makedev (2.3.1-89ubuntu3) ... Setting up libnih1 (1.0.3-4ubuntu9.1) ... Setting up libnih-dbus1 (1.0.3-4ubuntu9.1) ... Setting up iproute (20111117-1ubuntu2.3) ... Setting up ifupdown (0.7~beta2ubuntu11.1) ... Installing new version of config file /etc/init/network-interface.conf ... Setting up liblockfile-bin (1.09-3ubuntu0.1) ... Setting up liblockfile1 (1.09-3ubuntu0.1) ... Setting up libsqlite3-0 (3.7.9-2ubuntu1.2) ... Setting up libelf1 (0.152-1ubuntu3.1) ... Setting up libroken18-heimdal (1.6~git20120311.dfsg.1-2ubuntu0.1) ... Setting up libasn1-8-heimdal (1.6~git20120311.dfsg.1-2ubuntu0.1) ... Setting up libgcrypt11 (1.5.0-3ubuntu0.6) ... Setting up libtasn1-3 (2.10-1ubuntu1.5) ... Setting up libgnutls26 (2.12.14-5ubuntu3.14) ... Setting up libkrb5support0 (1.10+dfsg~beta1-2ubuntu0.7) ... Setting up libk5crypto3 (1.10+dfsg~beta1-2ubuntu0.7) ... Setting up libkrb5-3 (1.10+dfsg~beta1-2ubuntu0.7) ... Setting up libgssapi-krb5-2 (1.10+dfsg~beta1-2ubuntu0.7) ... Setting up libidn11 (1.23-2ubuntu0.1) ... Setting up libhcrypto4-heimdal (1.6~git20120311.dfsg.1-2ubuntu0.1) ... Setting up libheimbase1-heimdal (1.6~git20120311.dfsg.1-2ubuntu0.1) ... Setting up libwind0-heimdal (1.6~git20120311.dfsg.1-2ubuntu0.1) ... Setting up libhx509-5-heimdal (1.6~git20120311.dfsg.1-2ubuntu0.1) ... Setting up libkrb5-26-heimdal (1.6~git20120311.dfsg.1-2ubuntu0.1) ... Setting up libheimntlm0-heimdal (1.6~git20120311.dfsg.1-2ubuntu0.1) ... Setting up libgssapi3-heimdal (1.6~git20120311.dfsg.1-2ubuntu0.1) ... Setting up libsasl2-2 (2.1.25.dfsg1-3ubuntu0.1) ... Setting up libldap-2.4-2 (2.4.28-1.1ubuntu4.6) ... Setting up openssl (1.0.1-4ubuntu5.39) ... Setting up ca-certificates (20160104ubuntu0.12.04.1) ... Updating certificates in /etc/ssl/certs... 56 added, 35 removed; done. Running hooks in /etc/ca-certificates/update.d....done. Setting up libcurl3-gnutls (7.22.0-3ubuntu4.17) ... Setting up apt-transport-https (0.8.16~exp12ubuntu10.27) ... Setting up binutils (2.22-6ubuntu1.4) ... Setting up make (3.81-8.1ubuntu1.1) ... Setting up patch (2.6.1-3ubuntu0.1) ... Setting up optipng (0.6.4-1ubuntu0.12.04.1) ... Setting up pkg-create-dbgsym (0.50.2) ... Setting up perl-modules (5.14.2-6ubuntu2.5) ... Setting up perl (5.14.2-6ubuntu2.5) ... Setting up libdpkg-perl (1.16.1.2ubuntu7.8) ... Setting up dpkg-dev (1.16.1.2ubuntu7.8) ... Setting up build-essential (11.5ubuntu2.1) ... Processing triggers for libc-bin ... ldconfig deferred processing now taking place Processing triggers for initramfs-tools ... RUN: /usr/share/launchpad-buildd/slavebin/sbuild-package PACKAGEBUILD-13675837 amd64 precise -c chroot:build-PACKAGEBUILD-13675837 --arch=amd64 --dist=precise --nolog 'cmoc_0.1.43-0~tormod1.dsc' Initiating build PACKAGEBUILD-13675837 with 4 jobs across 4 processor cores. Kernel reported to sbuild: 2.6.64-98-generic #121-Ubuntu SMP Tue Oct 10 14:24:03 UTC 2017 x86_64 sbuild (Debian sbuild) 0.67.0 (26 Dec 2015) on lcy01-amd64-001.buildd +==============================================================================+ | cmoc 0.1.43-0~tormod1 (amd64) 04 Nov 2017 10:29 | +==============================================================================+ Package: cmoc Version: 0.1.43-0~tormod1 Source Version: 0.1.43-0~tormod1 Distribution: precise Machine Architecture: amd64 Host Architecture: amd64 Build Architecture: amd64 I: NOTICE: Log filtering will replace 'build/cmoc-FmHxLu/cmoc-0.1.43' with '<>' I: NOTICE: Log filtering will replace 'build/cmoc-FmHxLu' with '<>' I: NOTICE: Log filtering will replace 'home/buildd/build-PACKAGEBUILD-13675837/chroot-autobuild' with '<>' +------------------------------------------------------------------------------+ | Fetch source files | +------------------------------------------------------------------------------+ Local sources ------------- cmoc_0.1.43-0~tormod1.dsc exists in .; copying to chroot Check architectures ------------------- Check dependencies ------------------ Merged Build-Depends: build-essential, fakeroot Filtered Build-Depends: build-essential, fakeroot dpkg-deb: building package `sbuild-build-depends-core-dummy' in `/<>/resolver-mt7q8o/apt_archive/sbuild-build-depends-core-dummy.deb'. Ign copy: ./ Release.gpg Get:1 copy: ./ Release [2119 B] Get:2 copy: ./ Sources [214 B] Get:3 copy: ./ Packages [526 B] Ign copy: ./ Translation-en Fetched 2859 B in 0s (0 B/s) Reading package lists... Reading package lists... +------------------------------------------------------------------------------+ | Install core build dependencies (apt-based resolver) | +------------------------------------------------------------------------------+ Installing build dependencies Reading package lists... Building dependency tree... Reading state information... The following NEW packages will be installed: sbuild-build-depends-core-dummy 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 710 B of archives. After this operation, 0 B of additional disk space will be used. WARNING: The following packages cannot be authenticated! sbuild-build-depends-core-dummy Authentication warning overridden. Get:1 copy:/<>/resolver-mt7q8o/apt_archive/ ./ sbuild-build-depends-core-dummy 0.invalid.0 [710 B] debconf: delaying package configuration, since apt-utils is not installed Fetched 710 B in 0s (0 B/s) Selecting previously unselected package sbuild-build-depends-core-dummy. (Reading database ... 12310 files and directories currently installed.) Unpacking sbuild-build-depends-core-dummy (from .../sbuild-build-depends-core-dummy_0.invalid.0_amd64.deb) ... Setting up sbuild-build-depends-core-dummy (0.invalid.0) ... Merged Build-Depends: debhelper (>= 9), autotools-dev, bison, flex, lwtools Filtered Build-Depends: debhelper (>= 9), autotools-dev, bison, flex, lwtools dpkg-deb: building package `sbuild-build-depends-cmoc-dummy' in `/<>/resolver-uQB8nA/apt_archive/sbuild-build-depends-cmoc-dummy.deb'. Ign copy: ./ Release.gpg Get:1 copy: ./ Release [2119 B] Get:2 copy: ./ Sources [228 B] Get:3 copy: ./ Packages [543 B] Ign copy: ./ Translation-en Fetched 2890 B in 0s (0 B/s) Reading package lists... Reading package lists... +------------------------------------------------------------------------------+ | Install cmoc build dependencies (apt-based resolver) | +------------------------------------------------------------------------------+ Installing build dependencies Reading package lists... Building dependency tree... Reading state information... The following extra packages will be installed: autotools-dev bison bsdmainutils debhelper dh-apparmor file flex gettext gettext-base groff-base html2text intltool-debian libbison-dev libcroco3 libfl-dev libgettextpo0 libmagic1 libpipeline1 libunistring0 libxml2 lwtools m4 man-db po-debconf Suggested packages: bison-doc wamerican wordlist whois vacation dh-make gettext-doc groff less www-browser libmail-box-perl Recommended packages: curl wget lynx-cur xml-core libmail-sendmail-perl The following NEW packages will be installed: autotools-dev bison bsdmainutils debhelper dh-apparmor file flex gettext gettext-base groff-base html2text intltool-debian libbison-dev libcroco3 libfl-dev libgettextpo0 libmagic1 libpipeline1 libunistring0 libxml2 lwtools m4 man-db po-debconf sbuild-build-depends-cmoc-dummy 0 upgraded, 25 newly installed, 0 to remove and 0 not upgraded. Need to get 6788 kB of archives. After this operation, 21.3 MB of additional disk space will be used. WARNING: The following packages cannot be authenticated! libpipeline1 libxml2 m4 libfl-dev flex libcroco3 libunistring0 libgettextpo0 libmagic1 file bsdmainutils gettext-base groff-base man-db autotools-dev libbison-dev bison html2text gettext intltool-debian po-debconf dh-apparmor debhelper lwtools sbuild-build-depends-cmoc-dummy Authentication warning overridden. Get:1 copy:/<>/resolver-uQB8nA/apt_archive/ ./ sbuild-build-depends-cmoc-dummy 0.invalid.0 [728 B] Get:2 http://ftpmaster.internal/ubuntu/ precise/main libpipeline1 amd64 1.2.1-1 [26.5 kB] Get:3 http://ftpmaster.internal/ubuntu/ precise-security/main libxml2 amd64 2.7.8.dfsg-5.1ubuntu4.17 [678 kB] Get:4 http://ftpmaster.internal/ubuntu/ precise/main m4 amd64 1.4.16-2ubuntu1 [200 kB] Get:5 http://ftpmaster.internal/ubuntu/ precise/main libfl-dev amd64 2.5.35-10ubuntu3 [18.9 kB] Get:6 http://ftpmaster.internal/ubuntu/ precise/main flex amd64 2.5.35-10ubuntu3 [232 kB] Get:7 http://ftpmaster.internal/ubuntu/ precise-updates/main libcroco3 amd64 0.6.5-1ubuntu0.1 [99.8 kB] Get:8 http://ftpmaster.internal/ubuntu/ precise/main libunistring0 amd64 0.9.3-5 [427 kB] Get:9 http://ftpmaster.internal/ubuntu/ precise/main libgettextpo0 amd64 0.18.1.1-5ubuntu3 [120 kB] Get:10 http://ftpmaster.internal/ubuntu/ precise-security/main libmagic1 amd64 5.09-2ubuntu0.6 [218 kB] Get:11 http://ppa.launchpad.net/tormodvolden/m6809/ubuntu/ precise/main lwtools amd64 4.14-0~tormod~precise [138 kB] Get:12 http://ftpmaster.internal/ubuntu/ precise-security/main file amd64 5.09-2ubuntu0.6 [20.0 kB] Get:13 http://ftpmaster.internal/ubuntu/ precise/main bsdmainutils amd64 8.2.3ubuntu1 [200 kB] Get:14 http://ftpmaster.internal/ubuntu/ precise/main gettext-base amd64 0.18.1.1-5ubuntu3 [80.0 kB] Get:15 http://ftpmaster.internal/ubuntu/ precise/main groff-base amd64 1.21-7 [1046 kB] Get:16 http://ftpmaster.internal/ubuntu/ precise-updates/main man-db amd64 2.6.1-2ubuntu2 [755 kB] Get:17 http://ftpmaster.internal/ubuntu/ precise/main autotools-dev all 20120210.1ubuntu1 [42.4 kB] Get:18 http://ftpmaster.internal/ubuntu/ precise/main libbison-dev amd64 1:2.5.dfsg-2.1 [33.3 kB] Get:19 http://ftpmaster.internal/ubuntu/ precise/main bison amd64 1:2.5.dfsg-2.1 [295 kB] Get:20 http://ftpmaster.internal/ubuntu/ precise/main html2text amd64 1.3.2a-15 [104 kB] Get:21 http://ftpmaster.internal/ubuntu/ precise/main gettext amd64 0.18.1.1-5ubuntu3 [1188 kB] Get:22 http://ftpmaster.internal/ubuntu/ precise/main intltool-debian all 0.35.0+20060710.1 [31.6 kB] Get:23 http://ftpmaster.internal/ubuntu/ precise/main po-debconf all 1.0.16+nmu2ubuntu1 [210 kB] Get:24 http://ftpmaster.internal/ubuntu/ precise-security/main dh-apparmor all 2.7.102-0ubuntu3.11 [8866 B] Get:25 http://ftpmaster.internal/ubuntu/ precise/main debhelper all 9.20120115ubuntu3 [616 kB] debconf: delaying package configuration, since apt-utils is not installed Fetched 6788 kB in 0s (33.8 MB/s) Selecting previously unselected package libpipeline1. (Reading database ... 12310 files and directories currently installed.) Unpacking libpipeline1 (from .../libpipeline1_1.2.1-1_amd64.deb) ... Selecting previously unselected package libxml2. Unpacking libxml2 (from .../libxml2_2.7.8.dfsg-5.1ubuntu4.17_amd64.deb) ... Selecting previously unselected package m4. Unpacking m4 (from .../m4_1.4.16-2ubuntu1_amd64.deb) ... Selecting previously unselected package libfl-dev. Unpacking libfl-dev (from .../libfl-dev_2.5.35-10ubuntu3_amd64.deb) ... Selecting previously unselected package flex. Unpacking flex (from .../flex_2.5.35-10ubuntu3_amd64.deb) ... Selecting previously unselected package libcroco3. Unpacking libcroco3 (from .../libcroco3_0.6.5-1ubuntu0.1_amd64.deb) ... Selecting previously unselected package libunistring0. Unpacking libunistring0 (from .../libunistring0_0.9.3-5_amd64.deb) ... Selecting previously unselected package libgettextpo0. Unpacking libgettextpo0 (from .../libgettextpo0_0.18.1.1-5ubuntu3_amd64.deb) ... Selecting previously unselected package libmagic1. Unpacking libmagic1 (from .../libmagic1_5.09-2ubuntu0.6_amd64.deb) ... Selecting previously unselected package file. Unpacking file (from .../file_5.09-2ubuntu0.6_amd64.deb) ... Selecting previously unselected package bsdmainutils. Unpacking bsdmainutils (from .../bsdmainutils_8.2.3ubuntu1_amd64.deb) ... Selecting previously unselected package gettext-base. Unpacking gettext-base (from .../gettext-base_0.18.1.1-5ubuntu3_amd64.deb) ... Selecting previously unselected package groff-base. Unpacking groff-base (from .../groff-base_1.21-7_amd64.deb) ... Selecting previously unselected package man-db. Unpacking man-db (from .../man-db_2.6.1-2ubuntu2_amd64.deb) ... Selecting previously unselected package autotools-dev. Unpacking autotools-dev (from .../autotools-dev_20120210.1ubuntu1_all.deb) ... Selecting previously unselected package libbison-dev. Unpacking libbison-dev (from .../libbison-dev_1%3a2.5.dfsg-2.1_amd64.deb) ... Selecting previously unselected package bison. Unpacking bison (from .../bison_1%3a2.5.dfsg-2.1_amd64.deb) ... Selecting previously unselected package html2text. Unpacking html2text (from .../html2text_1.3.2a-15_amd64.deb) ... Selecting previously unselected package gettext. Unpacking gettext (from .../gettext_0.18.1.1-5ubuntu3_amd64.deb) ... Selecting previously unselected package intltool-debian. Unpacking intltool-debian (from .../intltool-debian_0.35.0+20060710.1_all.deb) ... Selecting previously unselected package po-debconf. Unpacking po-debconf (from .../po-debconf_1.0.16+nmu2ubuntu1_all.deb) ... Selecting previously unselected package dh-apparmor. Unpacking dh-apparmor (from .../dh-apparmor_2.7.102-0ubuntu3.11_all.deb) ... Selecting previously unselected package debhelper. Unpacking debhelper (from .../debhelper_9.20120115ubuntu3_all.deb) ... Selecting previously unselected package lwtools. Unpacking lwtools (from .../lwtools_4.14-0~tormod~precise_amd64.deb) ... Selecting previously unselected package sbuild-build-depends-cmoc-dummy. Unpacking sbuild-build-depends-cmoc-dummy (from .../sbuild-build-depends-cmoc-dummy_0.invalid.0_amd64.deb) ... Setting up libpipeline1 (1.2.1-1) ... Setting up libxml2 (2.7.8.dfsg-5.1ubuntu4.17) ... Setting up m4 (1.4.16-2ubuntu1) ... Setting up libfl-dev (2.5.35-10ubuntu3) ... Setting up flex (2.5.35-10ubuntu3) ... Setting up libcroco3 (0.6.5-1ubuntu0.1) ... Setting up libunistring0 (0.9.3-5) ... Setting up libgettextpo0 (0.18.1.1-5ubuntu3) ... Setting up libmagic1 (5.09-2ubuntu0.6) ... Setting up file (5.09-2ubuntu0.6) ... Setting up bsdmainutils (8.2.3ubuntu1) ... update-alternatives: using /usr/bin/bsd-write to provide /usr/bin/write (write) in auto mode. update-alternatives: using /usr/bin/bsd-from to provide /usr/bin/from (from) in auto mode. Setting up gettext-base (0.18.1.1-5ubuntu3) ... Setting up groff-base (1.21-7) ... Setting up man-db (2.6.1-2ubuntu2) ... Building database of manual pages ... Setting up autotools-dev (20120210.1ubuntu1) ... Setting up libbison-dev (1:2.5.dfsg-2.1) ... Setting up bison (1:2.5.dfsg-2.1) ... update-alternatives: using /usr/bin/bison.yacc to provide /usr/bin/yacc (yacc) in auto mode. Setting up html2text (1.3.2a-15) ... Setting up gettext (0.18.1.1-5ubuntu3) ... Setting up intltool-debian (0.35.0+20060710.1) ... Setting up po-debconf (1.0.16+nmu2ubuntu1) ... Setting up dh-apparmor (2.7.102-0ubuntu3.11) ... Setting up debhelper (9.20120115ubuntu3) ... Setting up lwtools (4.14-0~tormod~precise) ... Setting up sbuild-build-depends-cmoc-dummy (0.invalid.0) ... Processing triggers for libc-bin ... ldconfig deferred processing now taking place +------------------------------------------------------------------------------+ | Build environment | +------------------------------------------------------------------------------+ Kernel: Linux 2.6.64-98-generic amd64 (x86_64) Toolchain package versions: binutils_2.22-6ubuntu1.4 dpkg-dev_1.16.1.2ubuntu7.8 g++-4.6_4.6.3-1ubuntu5 gcc-4.6_4.6.3-1ubuntu5 libc6-dev_2.15-0ubuntu10.18 libstdc++6_4.6.3-1ubuntu5 libstdc++6-4.6-dev_4.6.3-1ubuntu5 linux-libc-dev_3.2.0-126.169 Package versions: adduser_3.113ubuntu2 advancecomp_1.15-1 apt_0.8.16~exp12ubuntu10.27 apt-transport-https_0.8.16~exp12ubuntu10.27 autotools-dev_20120210.1ubuntu1 base-files_6.5ubuntu6.8 base-passwd_3.5.24 bash_4.2-2ubuntu2.6 binutils_2.22-6ubuntu1.4 bison_1:2.5.dfsg-2.1 bsdmainutils_8.2.3ubuntu1 bsdutils_1:2.20.1-1ubuntu3.1 build-essential_11.5ubuntu2.1 busybox-initramfs_1:1.18.5-1ubuntu4.1 bzip2_1.0.6-1 ca-certificates_20160104ubuntu0.12.04.1 coreutils_8.13-3ubuntu3.3 cpio_2.11-7ubuntu3.2 cpp_4:4.6.3-1ubuntu5 cpp-4.6_4.6.3-1ubuntu5 dash_0.5.7-2ubuntu2 debconf_1.5.42ubuntu1 debhelper_9.20120115ubuntu3 debianutils_4.2.1ubuntu2 dh-apparmor_2.7.102-0ubuntu3.11 diffutils_1:3.2-1ubuntu1 dpkg_1.16.1.2ubuntu7.8 dpkg-dev_1.16.1.2ubuntu7.8 e2fslibs_1.42-1ubuntu2.3 e2fsprogs_1.42-1ubuntu2.3 fakeroot_1.18.2-1 file_5.09-2ubuntu0.6 findutils_4.4.2-4ubuntu1 flex_2.5.35-10ubuntu3 g++_4:4.6.3-1ubuntu5 g++-4.6_4.6.3-1ubuntu5 gcc_4:4.6.3-1ubuntu5 gcc-4.6_4.6.3-1ubuntu5 gcc-4.6-base_4.6.3-1ubuntu5 gettext_0.18.1.1-5ubuntu3 gettext-base_0.18.1.1-5ubuntu3 gnupg_1.4.11-3ubuntu2.10 gpgv_1.4.11-3ubuntu2.10 grep_2.10-1 groff-base_1.21-7 gzip_1.4-1ubuntu2 hostname_3.06ubuntu1 html2text_1.3.2a-15 ifupdown_0.7~beta2ubuntu11.1 initramfs-tools_0.99ubuntu13.5 initramfs-tools-bin_0.99ubuntu13.5 initscripts_2.88dsf-13.10ubuntu11.1 insserv_1.14.0-2.1ubuntu2 intltool-debian_0.35.0+20060710.1 iproute_20111117-1ubuntu2.3 klibc-utils_1.5.25-1ubuntu2 libacl1_2.2.51-5ubuntu1 libapt-pkg4.11_0.8.16~exp5ubuntu14.2 libapt-pkg4.12_0.8.16~exp12ubuntu10.27 libasn1-8-heimdal_1.6~git20120311.dfsg.1-2ubuntu0.1 libattr1_1:2.4.46-5ubuntu1 libbison-dev_1:2.5.dfsg-2.1 libblkid1_2.20.1-1ubuntu3.1 libbz2-1.0_1.0.6-1 libc-bin_2.15-0ubuntu10.18 libc-dev-bin_2.15-0ubuntu10.18 libc6_2.15-0ubuntu10.18 libc6-dev_2.15-0ubuntu10.18 libclass-isa-perl_0.36-3 libcomerr2_1.42-1ubuntu2.3 libcroco3_0.6.5-1ubuntu0.1 libcurl3-gnutls_7.22.0-3ubuntu4.17 libdb5.1_5.1.25-11build1 libdbus-1-3_1.4.18-1ubuntu1.8 libdpkg-perl_1.16.1.2ubuntu7.8 libdrm-intel1_2.4.52-1~precise2 libdrm-nouveau1a_2.4.52-1~precise2 libdrm-radeon1_2.4.52-1~precise2 libdrm2_2.4.52-1~precise2 libelf1_0.152-1ubuntu3.1 libffi6_3.0.11~rc1-5 libfl-dev_2.5.35-10ubuntu3 libgcc1_1:4.6.3-1ubuntu5 libgcrypt11_1.5.0-3ubuntu0.6 libgdbm3_1.8.3-10 libgettextpo0_0.18.1.1-5ubuntu3 libglib2.0-0_2.32.4-0ubuntu1 libgmp10_2:5.0.2+dfsg-2ubuntu1 libgnutls26_2.12.14-5ubuntu3.14 libgomp1_4.6.3-1ubuntu5 libgpg-error0_1.10-2ubuntu1 libgssapi-krb5-2_1.10+dfsg~beta1-2ubuntu0.7 libgssapi3-heimdal_1.6~git20120311.dfsg.1-2ubuntu0.1 libhcrypto4-heimdal_1.6~git20120311.dfsg.1-2ubuntu0.1 libheimbase1-heimdal_1.6~git20120311.dfsg.1-2ubuntu0.1 libheimntlm0-heimdal_1.6~git20120311.dfsg.1-2ubuntu0.1 libhx509-5-heimdal_1.6~git20120311.dfsg.1-2ubuntu0.1 libidn11_1.23-2ubuntu0.1 libk5crypto3_1.10+dfsg~beta1-2ubuntu0.7 libkeyutils1_1.5.2-2 libklibc_1.5.25-1ubuntu2 libkrb5-26-heimdal_1.6~git20120311.dfsg.1-2ubuntu0.1 libkrb5-3_1.10+dfsg~beta1-2ubuntu0.7 libkrb5support0_1.10+dfsg~beta1-2ubuntu0.7 libldap-2.4-2_2.4.28-1.1ubuntu4.6 liblockfile-bin_1.09-3ubuntu0.1 liblockfile1_1.09-3ubuntu0.1 liblzma5_5.1.1alpha+20110809-3 libmagic1_5.09-2ubuntu0.6 libmount1_2.20.1-1ubuntu3.1 libmpc2_0.9-4 libmpfr4_3.1.0-3ubuntu2 libncurses5_5.9-4 libncursesw5_5.9-4 libnih-dbus1_1.0.3-4ubuntu9.1 libnih1_1.0.3-4ubuntu9.1 libp11-kit0_0.12-2ubuntu1 libpam-modules_1.1.3-7ubuntu2.3 libpam-modules-bin_1.1.3-7ubuntu2.3 libpam-runtime_1.1.3-7ubuntu2.3 libpam0g_1.1.3-7ubuntu2.3 libpciaccess0_0.12.902-1ubuntu0.2 libpcre3_8.12-4ubuntu0.2 libpipeline1_1.2.1-1 libplymouth2_0.8.2-2ubuntu31.1 libpng12-0_1.2.46-3ubuntu4.2 libquadmath0_4.6.3-1ubuntu5 libreadline6_6.2-8 libroken18-heimdal_1.6~git20120311.dfsg.1-2ubuntu0.1 librtmp0_2.4~20110711.gitc28f1bab-1 libsasl2-2_2.1.25.dfsg1-3ubuntu0.1 libselinux1_2.1.0-4.1ubuntu1 libslang2_2.2.4-3ubuntu1 libsqlite3-0_3.7.9-2ubuntu1.2 libss2_1.42-1ubuntu2.3 libssl1.0.0_1.0.1-4ubuntu5.39 libstdc++6_4.6.3-1ubuntu5 libstdc++6-4.6-dev_4.6.3-1ubuntu5 libswitch-perl_2.16-2 libtasn1-3_2.10-1ubuntu1.5 libtimedate-perl_1.2000-1 libtinfo5_5.9-4 libudev0_175-0ubuntu9.10 libunistring0_0.9.3-5 libusb-0.1-4_2:0.1.12-20 libuuid1_2.20.1-1ubuntu3.1 libwind0-heimdal_1.6~git20120311.dfsg.1-2ubuntu0.1 libxml2_2.7.8.dfsg-5.1ubuntu4.17 linux-libc-dev_3.2.0-126.169 locales_2.13+git20120306-3 lockfile-progs_0.1.16 login_1:4.1.4.2+svn3283-3ubuntu5.1 lsb-base_4.0-0ubuntu20.3 lwtools_4.14-0~tormod~precise m4_1.4.16-2ubuntu1 make_3.81-8.1ubuntu1.1 makedev_2.3.1-89ubuntu3 man-db_2.6.1-2ubuntu2 mawk_1.3.3-17 module-init-tools_3.16-1ubuntu2 mount_2.20.1-1ubuntu3.1 mountall_2.36.4ubuntu0.1 multiarch-support_2.15-0ubuntu10.18 ncurses-base_5.9-4 ncurses-bin_5.9-4 openssl_1.0.1-4ubuntu5.39 optipng_0.6.4-1ubuntu0.12.04.1 passwd_1:4.1.4.2+svn3283-3ubuntu5.1 patch_2.6.1-3ubuntu0.1 perl_5.14.2-6ubuntu2.5 perl-base_5.14.2-6ubuntu2.5 perl-modules_5.14.2-6ubuntu2.5 pkg-create-dbgsym_0.50.2 pkgbinarymangler_116 plymouth_0.8.2-2ubuntu31.1 po-debconf_1.0.16+nmu2ubuntu1 policyrcd-script-zg2_0.1-2 procps_1:3.2.8-11ubuntu6.4 python-minimal_2.7.3-0ubuntu2.2 python2.7-minimal_2.7.3-0ubuntu3.9 readline-common_6.2-8 sbuild-build-depends-cmoc-dummy_0.invalid.0 sbuild-build-depends-core-dummy_0.invalid.0 sed_4.2.1-9 sensible-utils_0.0.6ubuntu2 sysv-rc_2.88dsf-13.10ubuntu11.1 sysvinit-utils_2.88dsf-13.10ubuntu11.1 tar_1.26-4ubuntu1.1 tzdata_2016j-0ubuntu0.12.04 ubuntu-keyring_2011.11.21.1 udev_175-0ubuntu9.10 upstart_1.5-0ubuntu7.3 util-linux_2.20.1-1ubuntu3.1 xz-utils_5.1.1alpha+20110809-3 zlib1g_1:1.2.3.4.dfsg-3ubuntu4 +------------------------------------------------------------------------------+ | Build | +------------------------------------------------------------------------------+ Unpack source ------------- gpgv: Signature made Sat Nov 4 10:26:30 2017 UTC using DSA key ID BAF41D0C gpgv: Can't check signature: public key not found dpkg-source: warning: failed to verify signature on ./cmoc_0.1.43-0~tormod1.dsc dpkg-source: info: extracting cmoc in cmoc-0.1.43 dpkg-source: info: unpacking cmoc_0.1.43.orig.tar.gz dpkg-source: info: unpacking cmoc_0.1.43-0~tormod1.debian.tar.xz Check disc space ---------------- Sufficient free space for build User Environment ---------------- APT_CONFIG=/var/lib/sbuild/apt.conf DEB_BUILD_OPTIONS=noautodbgsym parallel=4 HOME=/sbuild-nonexistent LANG=C.UTF-8 LC_ALL=C.UTF-8 LOGNAME=buildd PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games SCHROOT_ALIAS_NAME=build-PACKAGEBUILD-13675837 SCHROOT_CHROOT_NAME=build-PACKAGEBUILD-13675837 SCHROOT_COMMAND=env SCHROOT_GID=2501 SCHROOT_GROUP=buildd SCHROOT_SESSION_ID=build-PACKAGEBUILD-13675837 SCHROOT_UID=2001 SCHROOT_USER=buildd SHELL=/bin/sh TERM=unknown USER=buildd V=1 dpkg-buildpackage ----------------- dpkg-buildpackage: source package cmoc dpkg-buildpackage: source version 0.1.43-0~tormod1 dpkg-source --before-build cmoc-0.1.43 dpkg-buildpackage: host architecture amd64 fakeroot debian/rules clean dh clean --with autotools-dev dh_testdir dh_auto_clean dh_autotools-dev_restoreconfig dh_clean debian/rules build dh build --with autotools-dev dh_testdir dh_autotools-dev_updateconfig dh_auto_configure configure: WARNING: unrecognized options: --disable-maintainer-mode checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... no checking for mawk... mawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking for g++... g++ checking whether the C++ compiler works... yes checking for C++ compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C++ compiler... yes checking whether g++ accepts -g... yes checking for style of include used by make... GNU checking dependency style of g++... none checking maximum warning verbosity option... -W -Wall for C++ checking for grep... grep checking for env... env checking for head... head checking for tail... tail checking for hexdump... hexdump checking for perl... perl checking for perl module strict... ok checking for Mac OS X... no: uname -a not recognized as Darwin checking for lwasm... lwasm checking lwasm --version... lwasm from lwtools 4.14 checking if lwasm accepts --pragma=forwardrefmax... yes checking for lwar... lwar checking lwar --version... lwar from lwtools 4.14 checking for lwlink... lwlink checking lwlink --version... lwlink from lwtools 4.14 checking for bison... bison -y checking for flex... flex checking lex output file root... lex.yy checking lex library... none needed checking whether yytext is a pointer... no checking for strcasecmp() while including ... found building writecocofile disk image tool: yes checking that generated files are newer than configure... done configure: creating ./config.status config.status: creating Makefile config.status: creating src/Makefile config.status: creating src/support/Makefile config.status: creating src/support/vectrex/Makefile config.status: creating src/stdlib/Makefile config.status: creating src/float/Makefile config.status: creating src/usim-0.91-cmoc/Makefile config.status: creating macros/Makefile config.status: creating doc/Makefile config.status: creating doc/cmoc.1 config.status: executing depfiles commands configure: WARNING: unrecognized options: --disable-maintainer-mode dh_auto_build make[1]: Entering directory `/<>' Making all in src make[2]: Entering directory `/<>/src' Making all in support make[3]: Entering directory `/<>/src/support' Making all in vectrex make[4]: Entering directory `/<>/src/support/vectrex' make[4]: Nothing to be done for `all'. make[4]: Leaving directory `/<>/src/support/vectrex' make[4]: Entering directory `/<>/src/support' make[4]: Nothing to be done for `all-am'. make[4]: Leaving directory `/<>/src/support' make[3]: Leaving directory `/<>/src/support' Making all in usim-0.91-cmoc make[3]: Entering directory `/<>/src/usim-0.91-cmoc' g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o main.o main.cc g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o mc6809.o mc6809.cc g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o mc6809in.o mc6809in.cc g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o misc.o misc.cc g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o term.o term.cc g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o usim.o usim.cc g++ -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -Wl,-Bsymbolic-functions -Wl,-z,relro -o usim main.o mc6809.o mc6809in.o misc.o term.o usim.o make[3]: Leaving directory `/<>/src/usim-0.91-cmoc' Making all in . make[3]: Entering directory `/<>/src' g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-TypeDesc.o `test -f 'TypeDesc.cpp' || echo './'`TypeDesc.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-TypeManager.o `test -f 'TypeManager.cpp' || echo './'`TypeManager.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-DeclarationSpecifierList.o `test -f 'DeclarationSpecifierList.cpp' || echo './'`DeclarationSpecifierList.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-util.o `test -f 'util.cpp' || echo './'`util.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-Tree.o `test -f 'Tree.cpp' || echo './'`Tree.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-ASMText.o `test -f 'ASMText.cpp' || echo './'`ASMText.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-parser.o `test -f 'parser.cc' || echo './'`parser.cc g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-lexer.o `test -f 'lexer.cc' || echo './'`lexer.cc g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-Declarator.o `test -f 'Declarator.cpp' || echo './'`Declarator.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-DeclarationSequence.o `test -f 'DeclarationSequence.cpp' || echo './'`DeclarationSequence.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-Declaration.o `test -f 'Declaration.cpp' || echo './'`Declaration.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-BinaryOpExpr.o `test -f 'BinaryOpExpr.cpp' || echo './'`BinaryOpExpr.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-UnaryOpExpr.o `test -f 'UnaryOpExpr.cpp' || echo './'`UnaryOpExpr.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-CastExpr.o `test -f 'CastExpr.cpp' || echo './'`CastExpr.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-IfStmt.o `test -f 'IfStmt.cpp' || echo './'`IfStmt.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-SwitchStmt.o `test -f 'SwitchStmt.cpp' || echo './'`SwitchStmt.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-LabeledStmt.o `test -f 'LabeledStmt.cpp' || echo './'`LabeledStmt.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-WhileStmt.o `test -f 'WhileStmt.cpp' || echo './'`WhileStmt.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-ForStmt.o `test -f 'ForStmt.cpp' || echo './'`ForStmt.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-JumpStmt.o `test -f 'JumpStmt.cpp' || echo './'`JumpStmt.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-StringLiteralExpr.o `test -f 'StringLiteralExpr.cpp' || echo './'`StringLiteralExpr.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-Scope.o `test -f 'Scope.cpp' || echo './'`Scope.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-FunctionDef.o `test -f 'FunctionDef.cpp' || echo './'`FunctionDef.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-SemanticsChecker.o `test -f 'SemanticsChecker.cpp' || echo './'`SemanticsChecker.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-ExpressionTypeSetter.o `test -f 'ExpressionTypeSetter.cpp' || echo './'`ExpressionTypeSetter.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-TranslationUnit.o `test -f 'TranslationUnit.cpp' || echo './'`TranslationUnit.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-TreeSequence.o `test -f 'TreeSequence.cpp' || echo './'`TreeSequence.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-FunctionCallExpr.o `test -f 'FunctionCallExpr.cpp' || echo './'`FunctionCallExpr.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-IdentifierExpr.o `test -f 'IdentifierExpr.cpp' || echo './'`IdentifierExpr.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-VariableExpr.o `test -f 'VariableExpr.cpp' || echo './'`VariableExpr.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-WordConstantExpr.o `test -f 'WordConstantExpr.cpp' || echo './'`WordConstantExpr.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-DWordConstantExpr.o `test -f 'DWordConstantExpr.cpp' || echo './'`DWordConstantExpr.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-RealConstantExpr.o `test -f 'RealConstantExpr.cpp' || echo './'`RealConstantExpr.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-CodeStatus.o `test -f 'CodeStatus.cpp' || echo './'`CodeStatus.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-FormalParameter.o `test -f 'FormalParameter.cpp' || echo './'`FormalParameter.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-AssemblerStmt.o `test -f 'AssemblerStmt.cpp' || echo './'`AssemblerStmt.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-ObjectMemberExpr.o `test -f 'ObjectMemberExpr.cpp' || echo './'`ObjectMemberExpr.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-ClassDef.o `test -f 'ClassDef.cpp' || echo './'`ClassDef.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-ConditionalExpr.o `test -f 'ConditionalExpr.cpp' || echo './'`ConditionalExpr.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-ScopeCreator.o `test -f 'ScopeCreator.cpp' || echo './'`ScopeCreator.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-Pragma.o `test -f 'Pragma.cpp' || echo './'`Pragma.cpp g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o cmoc-main.o `test -f 'main.cpp' || echo './'`main.cpp g++ -DPKGDATADIR=\"/usr/share/cmoc\" -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -Wl,-Bsymbolic-functions -Wl,-z,relro -o cmoc cmoc-TypeDesc.o cmoc-TypeManager.o cmoc-DeclarationSpecifierList.o cmoc-util.o cmoc-Tree.o cmoc-ASMText.o cmoc-parser.o cmoc-lexer.o cmoc-Declarator.o cmoc-DeclarationSequence.o cmoc-Declaration.o cmoc-BinaryOpExpr.o cmoc-UnaryOpExpr.o cmoc-CastExpr.o cmoc-IfStmt.o cmoc-SwitchStmt.o cmoc-LabeledStmt.o cmoc-WhileStmt.o cmoc-ForStmt.o cmoc-JumpStmt.o cmoc-StringLiteralExpr.o cmoc-Scope.o cmoc-FunctionDef.o cmoc-SemanticsChecker.o cmoc-ExpressionTypeSetter.o cmoc-TranslationUnit.o cmoc-TreeSequence.o cmoc-FunctionCallExpr.o cmoc-IdentifierExpr.o cmoc-VariableExpr.o cmoc-WordConstantExpr.o cmoc-DWordConstantExpr.o cmoc-RealConstantExpr.o cmoc-CodeStatus.o cmoc-FormalParameter.o cmoc-AssemblerStmt.o cmoc-ObjectMemberExpr.o cmoc-ClassDef.o cmoc-ConditionalExpr.o cmoc-ScopeCreator.o cmoc-Pragma.o cmoc-main.o g++ -DPACKAGE_NAME=\"cmoc\" -DPACKAGE_TARNAME=\"cmoc\" -DPACKAGE_VERSION=\"0.1.43\" -DPACKAGE_STRING=\"cmoc\ 0.1.43\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"cmoc\" -DVERSION=\"0.1.43\" -I. -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -c -o writecocofile.o writecocofile.cpp g++ -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -W -Wall -Wl,-Bsymbolic-functions -Wl,-z,relro -o writecocofile writecocofile.o make[3]: Leaving directory `/<>/src' Making all in stdlib make[3]: Entering directory `/<>/src/stdlib' lwasm -fobj -D_COCO_BASIC_ --output=addDWordDWord.ecb_o addDWordDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=addDWordInt.ecb_o addDWordInt.asm lwasm -fobj -D_COCO_BASIC_ --output=addDWordUnsignedInt.ecb_o addDWordUnsignedInt.asm lwasm -fobj -D_COCO_BASIC_ --output=_adddww.ecb_o _adddww.asm lwasm -fobj -D_COCO_BASIC_ --output=addIntDWord.ecb_o addIntDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=addUnsignedIntDWord.ecb_o addUnsignedIntDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=andDWordDWord.ecb_o andDWordDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=andDWordWord.ecb_o andDWordWord.asm lwasm -fobj -D_COCO_BASIC_ --output=_atoi.ecb_o _atoi.asm lwasm -fobj -D_COCO_BASIC_ --output=_atoui.ecb_o _atoui.asm lwasm -fobj -D_COCO_BASIC_ --output=ATOW.ecb_o ATOW.asm lwasm -fobj -D_COCO_BASIC_ --output=checknull.ecb_o checknull.asm lwasm -fobj -D_COCO_BASIC_ --output=checkstack.ecb_o checkstack.asm lwasm -fobj -D_COCO_BASIC_ --output=chrout.ecb_o chrout.asm lwasm -fobj -D_COCO_BASIC_ --output=cmpDWordDWord.ecb_o cmpDWordDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=cmpDWordSignedInt.ecb_o cmpDWordSignedInt.asm lwasm -fobj -D_COCO_BASIC_ --output=cmpDWordUnsignedInt.ecb_o cmpDWordUnsignedInt.asm lwasm -fobj -D_COCO_BASIC_ --output=_cmpdww.ecb_o _cmpdww.asm lwasm -fobj -D_COCO_BASIC_ --output=cmpSignedIntDWord.ecb_o cmpSignedIntDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=cmpUnsignedIntDWord.ecb_o cmpUnsignedIntDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=copyDWord.ecb_o copyDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=copyMem.ecb_o copyMem.asm lwasm -fobj -D_COCO_BASIC_ --output=copyWordToDWord.ecb_o copyWordToDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=crt.ecb_o crt.asm lwasm -fobj -D_COCO_BASIC_ --output=data.ecb_o data.asm lwasm -fobj -D_COCO_BASIC_ --output=decrementDWord.ecb_o decrementDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=_delay.ecb_o _delay.asm lwasm -fobj -D_COCO_BASIC_ --output=DIV16.ecb_o DIV16.asm lwasm -fobj -D_COCO_BASIC_ --output=DIV16BY10.ecb_o DIV16BY10.asm lwasm -fobj -D_COCO_BASIC_ --output=DIV32.ecb_o DIV32.asm lwasm -fobj -D_COCO_BASIC_ --output=DIV8.ecb_o DIV8.asm lwasm -fobj -D_COCO_BASIC_ --output=DIV8BY7.ecb_o DIV8BY7.asm lwasm -fobj -D_COCO_BASIC_ --output=_divdwb.ecb_o _divdwb.asm lwasm -fobj -D_COCO_BASIC_ --output=divDWordDWord.ecb_o divDWordDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=divDWordUnsignedInt.ecb_o divDWordUnsignedInt.asm lwasm -fobj -D_COCO_BASIC_ --output=_divdww.ecb_o _divdww.asm lwasm -fobj -D_COCO_BASIC_ --output=divModDWordDWord.ecb_o divModDWordDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=divModDWordUnsignedInt.ecb_o divModDWordUnsignedInt.asm lwasm -fobj -D_COCO_BASIC_ --output=divModUnsignedIntDWord.ecb_o divModUnsignedIntDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=divUnsignedIntDWord.ecb_o divUnsignedIntDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=dwtoa.ecb_o dwtoa.asm lwasm -fobj -D_COCO_BASIC_ --output=incrementDWord.ecb_o incrementDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=initByteFromDWord.ecb_o initByteFromDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=initDWordFromSignedWord.ecb_o initDWordFromSignedWord.asm lwasm -fobj -D_COCO_BASIC_ --output=initDWordFromUnsignedWord.ecb_o initDWordFromUnsignedWord.asm lwasm -fobj -D_COCO_BASIC_ --output=initSingleFromSingle.ecb_o initSingleFromSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=initWordFromDWord.ecb_o initWordFromDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=isDWordZero.ecb_o isDWordZero.asm lwasm -fobj -D_COCO_BASIC_ --output=leftShiftDWord.ecb_o leftShiftDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=leftShiftDWordAtXByB.ecb_o leftShiftDWordAtXByB.asm lwasm -fobj -D_COCO_BASIC_ --output=LINBUF.ecb_o LINBUF.asm lwasm -fobj -D_COCO_BASIC_ --output=_memcmp.ecb_o _memcmp.asm lwasm -fobj -D_COCO_BASIC_ --output=memcpy.ecb_o memcpy.asm lwasm -fobj -D_COCO_BASIC_ --output=_memset.ecb_o _memset.asm lwasm -fobj -D_COCO_BASIC_ --output=modDWordDWord.ecb_o modDWordDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=modDWordUnsignedInt.ecb_o modDWordUnsignedInt.asm lwasm -fobj -D_COCO_BASIC_ --output=modUnsignedIntDWord.ecb_o modUnsignedIntDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=MUL168_TO24.ecb_o MUL168_TO24.asm lwasm -fobj -D_COCO_BASIC_ --output=MUL168_TO32.ecb_o MUL168_TO32.asm lwasm -fobj -D_COCO_BASIC_ --output=MUL16.ecb_o MUL16.asm lwasm -fobj -D_COCO_BASIC_ --output=MUL32.ecb_o MUL32.asm lwasm -fobj -D_COCO_BASIC_ --output=mulDWordDWord.ecb_o mulDWordDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=mulDWordInt.ecb_o mulDWordInt.asm lwasm -fobj -D_COCO_BASIC_ --output=mulDWordUnsignedInt.ecb_o mulDWordUnsignedInt.asm lwasm -fobj -D_COCO_BASIC_ --output=mulIntDWord.ecb_o mulIntDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=mulUnsignedIntDWord.ecb_o mulUnsignedIntDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=negateDWord.ecb_o negateDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=orDWordDWord.ecb_o orDWordDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=orDWordWord.ecb_o orDWordWord.asm lwasm -fobj -D_COCO_BASIC_ --output=_printf.ecb_o _printf.asm lwasm -fobj -D_COCO_BASIC_ --output=push4ByteStruct.ecb_o push4ByteStruct.asm lwasm -fobj -D_COCO_BASIC_ --output=push5ByteStruct.ecb_o push5ByteStruct.asm lwasm -fobj -D_COCO_BASIC_ --output=pushStruct.ecb_o pushStruct.asm lwasm -fobj -D_COCO_BASIC_ --output=PUTCHR.ecb_o PUTCHR.asm lwasm -fobj -D_COCO_BASIC_ --output=putchar_a.ecb_o putchar_a.asm lwasm -fobj -D_COCO_BASIC_ --output=_putstr.ecb_o _putstr.asm lwasm -fobj -D_COCO_BASIC_ --output=_rand.ecb_o _rand.asm lwasm -fobj -D_COCO_BASIC_ --output=_readline.ecb_o _readline.asm lwasm -fobj -D_COCO_BASIC_ --output=_readword.ecb_o _readword.asm lwasm -fobj -D_COCO_BASIC_ --output=rightShiftDWord.ecb_o rightShiftDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=rightShiftDWordAtXByB.ecb_o rightShiftDWordAtXByB.asm lwasm -fobj -D_COCO_BASIC_ --output=_sbrk.ecb_o _sbrk.asm lwasm -fobj -D_COCO_BASIC_ --output=_sbrkmax.ecb_o _sbrkmax.asm lwasm -fobj -D_COCO_BASIC_ --output=SDIV16.ecb_o SDIV16.asm lwasm -fobj -D_COCO_BASIC_ --output=SDIV8.ecb_o SDIV8.asm lwasm -fobj -D_COCO_BASIC_ --output=seed.ecb_o seed.asm lwasm -fobj -D_COCO_BASIC_ --output=_setConsoleOutHook.ecb_o _setConsoleOutHook.asm lwasm -fobj -D_COCO_BASIC_ --output=shiftByteLeft.ecb_o shiftByteLeft.asm lwasm -fobj -D_COCO_BASIC_ --output=shiftByteRightSigned.ecb_o shiftByteRightSigned.asm lwasm -fobj -D_COCO_BASIC_ --output=shiftByteRightUnsigned.ecb_o shiftByteRightUnsigned.asm lwasm -fobj -D_COCO_BASIC_ --output=shiftLeft.ecb_o shiftLeft.asm lwasm -fobj -D_COCO_BASIC_ --output=shiftRightSigned.ecb_o shiftRightSigned.asm lwasm -fobj -D_COCO_BASIC_ --output=shiftRightUnsigned.ecb_o shiftRightUnsigned.asm lwasm -fobj -D_COCO_BASIC_ --output=signedDivDWordDWord.ecb_o signedDivDWordDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=signExtWordToDWord.ecb_o signExtWordToDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=_sprintf.ecb_o _sprintf.asm lwasm -fobj -D_COCO_BASIC_ --output=_srand.ecb_o _srand.asm lwasm -fobj -D_COCO_BASIC_ --output=_strcat.ecb_o _strcat.asm lwasm -fobj -D_COCO_BASIC_ --output=_strchr.ecb_o _strchr.asm lwasm -fobj -D_COCO_BASIC_ --output=_strcmp.ecb_o _strcmp.asm lwasm -fobj -D_COCO_BASIC_ --output=_strcpy.ecb_o _strcpy.asm lwasm -fobj -D_COCO_BASIC_ --output=_strlen.ecb_o _strlen.asm lwasm -fobj -D_COCO_BASIC_ --output=_strlwr.ecb_o _strlwr.asm lwasm -fobj -D_COCO_BASIC_ --output=_strncpy.ecb_o _strncpy.asm lwasm -fobj -D_COCO_BASIC_ --output=_strtoul.ecb_o _strtoul.asm lwasm -fobj -D_COCO_BASIC_ --output=_strupr.ecb_o _strupr.asm lwasm -fobj -D_COCO_BASIC_ --output=sub32.ecb_o sub32.asm lwasm -fobj -D_COCO_BASIC_ --output=sub32xu.ecb_o sub32xu.asm lwasm -fobj -D_COCO_BASIC_ --output=subDWordDWord.ecb_o subDWordDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=subDWordInt.ecb_o subDWordInt.asm lwasm -fobj -D_COCO_BASIC_ --output=subDWordUnsignedInt.ecb_o subDWordUnsignedInt.asm lwasm -fobj -D_COCO_BASIC_ --output=_subdww.ecb_o _subdww.asm lwasm -fobj -D_COCO_BASIC_ --output=subIntDWord.ecb_o subIntDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=subUnsignedIntDWord.ecb_o subUnsignedIntDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=testAndRemoveSignOnDWord.ecb_o testAndRemoveSignOnDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=testAndRemoveSignOnWord.ecb_o testAndRemoveSignOnWord.asm lwasm -fobj -D_COCO_BASIC_ --output=_tolower.ecb_o _tolower.asm lwasm -fobj -D_COCO_BASIC_ --output=_toupper.ecb_o _toupper.asm lwasm -fobj -D_COCO_BASIC_ --output=xorDWordDWord.ecb_o xorDWordDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=xorDWordWord.ecb_o xorDWordWord.asm lwasm -fobj -D_COCO_BASIC_ --output=_zerodw.ecb_o _zerodw.asm ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o atol.ecb_o atol.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o atoul.ecb_o atoul.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o strtol.ecb_o strtol.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o stdarg.ecb_o stdarg.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o atoff.ecb_o atoff.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o showPmode0.ecb_o showPmode0.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o showLowResTextAddress.ecb_o showLowResTextAddress.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o showPmode4.ecb_o showPmode4.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o showGraphicsAddress.ecb_o showGraphicsAddress.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o pcls.ecb_o pcls.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o setSAMRegisters.ecb_o setSAMRegisters.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o sleep.ecb_o sleep.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o setOutputDevice.ecb_o setOutputDevice.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o sound.ecb_o sound.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o readJoystickButtons.ecb_o readJoystickButtons.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o readJoystickPositions.ecb_o readJoystickPositions.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o isKeyPressed.ecb_o isKeyPressed.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o waitkey.ecb_o waitkey.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o inkey.ecb_o inkey.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o coldStart.ecb_o coldStart.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o setCaseFlag.ecb_o setCaseFlag.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o hset.ecb_o hset.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o hscreen.ecb_o hscreen.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o locate.ecb_o locate.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o attr.ecb_o attr.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o cls.ecb_o cls.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o getTextMode.ecb_o getTextMode.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o width.ecb_o width.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o setBorderColor.ecb_o setBorderColor.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o paletteRGB.ecb_o paletteRGB.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o palette.ecb_o palette.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o resetPalette.ecb_o resetPalette.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o setHighSpeed.ecb_o setHighSpeed.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o initCoCoSupport.ecb_o initCoCoSupport.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . -o disk.ecb_o disk.c lwar -c libcmoc-std-ecb.a addDWordDWord.ecb_o addDWordInt.ecb_o addDWordUnsignedInt.ecb_o _adddww.ecb_o addIntDWord.ecb_o addUnsignedIntDWord.ecb_o andDWordDWord.ecb_o andDWordWord.ecb_o _atoi.ecb_o _atoui.ecb_o ATOW.ecb_o checknull.ecb_o checkstack.ecb_o chrout.ecb_o cmpDWordDWord.ecb_o cmpDWordSignedInt.ecb_o cmpDWordUnsignedInt.ecb_o _cmpdww.ecb_o cmpSignedIntDWord.ecb_o cmpUnsignedIntDWord.ecb_o copyDWord.ecb_o copyMem.ecb_o copyWordToDWord.ecb_o crt.ecb_o data.ecb_o decrementDWord.ecb_o _delay.ecb_o DIV16.ecb_o DIV16BY10.ecb_o DIV32.ecb_o DIV8.ecb_o DIV8BY7.ecb_o _divdwb.ecb_o divDWordDWord.ecb_o divDWordUnsignedInt.ecb_o _divdww.ecb_o divModDWordDWord.ecb_o divModDWordUnsignedInt.ecb_o divModUnsignedIntDWord.ecb_o divUnsignedIntDWord.ecb_o dwtoa.ecb_o incrementDWord.ecb_o initByteFromDWord.ecb_o initDWordFromSignedWord.ecb_o initDWordFromUnsignedWord.ecb_o initSingleFromSingle.ecb_o initWordFromDWord.ecb_o isDWordZero.ecb_o leftShiftDWord.ecb_o leftShiftDWordAtXByB.ecb_o LINBUF.ecb_o _memcmp.ecb_o memcpy.ecb_o _memset.ecb_o modDWordDWord.ecb_o modDWordUnsignedInt.ecb_o modUnsignedIntDWord.ecb_o MUL168_TO24.ecb_o MUL168_TO32.ecb_o MUL16.ecb_o MUL32.ecb_o mulDWordDWord.ecb_o mulDWordInt.ecb_o mulDWordUnsignedInt.ecb_o mulIntDWord.ecb_o mulUnsignedIntDWord.ecb_o negateDWord.ecb_o orDWordDWord.ecb_o orDWordWord.ecb_o _printf.ecb_o push4ByteStruct.ecb_o push5ByteStruct.ecb_o pushStruct.ecb_o PUTCHR.ecb_o putchar_a.ecb_o _putstr.ecb_o _rand.ecb_o _readline.ecb_o _readword.ecb_o rightShiftDWord.ecb_o rightShiftDWordAtXByB.ecb_o _sbrk.ecb_o _sbrkmax.ecb_o SDIV16.ecb_o SDIV8.ecb_o seed.ecb_o _setConsoleOutHook.ecb_o shiftByteLeft.ecb_o shiftByteRightSigned.ecb_o shiftByteRightUnsigned.ecb_o shiftLeft.ecb_o shiftRightSigned.ecb_o shiftRightUnsigned.ecb_o signedDivDWordDWord.ecb_o signExtWordToDWord.ecb_o _sprintf.ecb_o _srand.ecb_o _strcat.ecb_o _strchr.ecb_o _strcmp.ecb_o _strcpy.ecb_o _strlen.ecb_o _strlwr.ecb_o _strncpy.ecb_o _strtoul.ecb_o _strupr.ecb_o sub32.ecb_o sub32xu.ecb_o subDWordDWord.ecb_o subDWordInt.ecb_o subDWordUnsignedInt.ecb_o _subdww.ecb_o subIntDWord.ecb_o subUnsignedIntDWord.ecb_o testAndRemoveSignOnDWord.ecb_o testAndRemoveSignOnWord.ecb_o _tolower.ecb_o _toupper.ecb_o xorDWordDWord.ecb_o xorDWordWord.ecb_o _zerodw.ecb_o atol.ecb_o atoul.ecb_o strtol.ecb_o stdarg.ecb_o atoff.ecb_o showPmode0.ecb_o showLowResTextAddress.ecb_o showPmode4.ecb_o showGraphicsAddress.ecb_o pcls.ecb_o setSAMRegisters.ecb_o sleep.ecb_o setOutputDevice.ecb_o sound.ecb_o readJoystickButtons.ecb_o readJoystickPositions.ecb_o isKeyPressed.ecb_o waitkey.ecb_o inkey.ecb_o coldStart.ecb_o setCaseFlag.ecb_o hset.ecb_o hscreen.ecb_o locate.ecb_o attr.ecb_o cls.ecb_o getTextMode.ecb_o width.ecb_o setBorderColor.ecb_o paletteRGB.ecb_o palette.ecb_o resetPalette.ecb_o setHighSpeed.ecb_o initCoCoSupport.ecb_o disk.ecb_o lwasm -fobj -DUSIM --output=addDWordDWord.usim_o addDWordDWord.asm lwasm -fobj -DUSIM --output=addDWordInt.usim_o addDWordInt.asm lwasm -fobj -DUSIM --output=addDWordUnsignedInt.usim_o addDWordUnsignedInt.asm lwasm -fobj -DUSIM --output=_adddww.usim_o _adddww.asm lwasm -fobj -DUSIM --output=addIntDWord.usim_o addIntDWord.asm lwasm -fobj -DUSIM --output=addUnsignedIntDWord.usim_o addUnsignedIntDWord.asm lwasm -fobj -DUSIM --output=andDWordDWord.usim_o andDWordDWord.asm lwasm -fobj -DUSIM --output=andDWordWord.usim_o andDWordWord.asm lwasm -fobj -DUSIM --output=_atoi.usim_o _atoi.asm lwasm -fobj -DUSIM --output=_atoui.usim_o _atoui.asm lwasm -fobj -DUSIM --output=ATOW.usim_o ATOW.asm lwasm -fobj -DUSIM --output=checknull.usim_o checknull.asm lwasm -fobj -DUSIM --output=checkstack.usim_o checkstack.asm lwasm -fobj -DUSIM --output=chrout.usim_o chrout.asm lwasm -fobj -DUSIM --output=cmpDWordDWord.usim_o cmpDWordDWord.asm lwasm -fobj -DUSIM --output=cmpDWordSignedInt.usim_o cmpDWordSignedInt.asm lwasm -fobj -DUSIM --output=cmpDWordUnsignedInt.usim_o cmpDWordUnsignedInt.asm lwasm -fobj -DUSIM --output=_cmpdww.usim_o _cmpdww.asm lwasm -fobj -DUSIM --output=cmpSignedIntDWord.usim_o cmpSignedIntDWord.asm lwasm -fobj -DUSIM --output=cmpUnsignedIntDWord.usim_o cmpUnsignedIntDWord.asm lwasm -fobj -DUSIM --output=copyDWord.usim_o copyDWord.asm lwasm -fobj -DUSIM --output=copyMem.usim_o copyMem.asm lwasm -fobj -DUSIM --output=copyWordToDWord.usim_o copyWordToDWord.asm lwasm -fobj -DUSIM --output=crt.usim_o crt.asm lwasm -fobj -DUSIM --output=data.usim_o data.asm lwasm -fobj -DUSIM --output=decrementDWord.usim_o decrementDWord.asm lwasm -fobj -DUSIM --output=_delay.usim_o _delay.asm lwasm -fobj -DUSIM --output=DIV16.usim_o DIV16.asm lwasm -fobj -DUSIM --output=DIV16BY10.usim_o DIV16BY10.asm lwasm -fobj -DUSIM --output=DIV32.usim_o DIV32.asm lwasm -fobj -DUSIM --output=DIV8.usim_o DIV8.asm lwasm -fobj -DUSIM --output=DIV8BY7.usim_o DIV8BY7.asm lwasm -fobj -DUSIM --output=_divdwb.usim_o _divdwb.asm lwasm -fobj -DUSIM --output=divDWordDWord.usim_o divDWordDWord.asm lwasm -fobj -DUSIM --output=divDWordUnsignedInt.usim_o divDWordUnsignedInt.asm lwasm -fobj -DUSIM --output=_divdww.usim_o _divdww.asm lwasm -fobj -DUSIM --output=divModDWordDWord.usim_o divModDWordDWord.asm lwasm -fobj -DUSIM --output=divModDWordUnsignedInt.usim_o divModDWordUnsignedInt.asm lwasm -fobj -DUSIM --output=divModUnsignedIntDWord.usim_o divModUnsignedIntDWord.asm lwasm -fobj -DUSIM --output=divUnsignedIntDWord.usim_o divUnsignedIntDWord.asm lwasm -fobj -DUSIM --output=dwtoa.usim_o dwtoa.asm lwasm -fobj -DUSIM --output=incrementDWord.usim_o incrementDWord.asm lwasm -fobj -DUSIM --output=initByteFromDWord.usim_o initByteFromDWord.asm lwasm -fobj -DUSIM --output=initDWordFromSignedWord.usim_o initDWordFromSignedWord.asm lwasm -fobj -DUSIM --output=initDWordFromUnsignedWord.usim_o initDWordFromUnsignedWord.asm lwasm -fobj -DUSIM --output=initSingleFromSingle.usim_o initSingleFromSingle.asm lwasm -fobj -DUSIM --output=initWordFromDWord.usim_o initWordFromDWord.asm lwasm -fobj -DUSIM --output=isDWordZero.usim_o isDWordZero.asm lwasm -fobj -DUSIM --output=leftShiftDWord.usim_o leftShiftDWord.asm lwasm -fobj -DUSIM --output=leftShiftDWordAtXByB.usim_o leftShiftDWordAtXByB.asm lwasm -fobj -DUSIM --output=LINBUF.usim_o LINBUF.asm lwasm -fobj -DUSIM --output=_memcmp.usim_o _memcmp.asm lwasm -fobj -DUSIM --output=memcpy.usim_o memcpy.asm lwasm -fobj -DUSIM --output=_memset.usim_o _memset.asm lwasm -fobj -DUSIM --output=modDWordDWord.usim_o modDWordDWord.asm lwasm -fobj -DUSIM --output=modDWordUnsignedInt.usim_o modDWordUnsignedInt.asm lwasm -fobj -DUSIM --output=modUnsignedIntDWord.usim_o modUnsignedIntDWord.asm lwasm -fobj -DUSIM --output=MUL168_TO24.usim_o MUL168_TO24.asm lwasm -fobj -DUSIM --output=MUL168_TO32.usim_o MUL168_TO32.asm lwasm -fobj -DUSIM --output=MUL16.usim_o MUL16.asm lwasm -fobj -DUSIM --output=MUL32.usim_o MUL32.asm lwasm -fobj -DUSIM --output=mulDWordDWord.usim_o mulDWordDWord.asm lwasm -fobj -DUSIM --output=mulDWordInt.usim_o mulDWordInt.asm lwasm -fobj -DUSIM --output=mulDWordUnsignedInt.usim_o mulDWordUnsignedInt.asm lwasm -fobj -DUSIM --output=mulIntDWord.usim_o mulIntDWord.asm lwasm -fobj -DUSIM --output=mulUnsignedIntDWord.usim_o mulUnsignedIntDWord.asm lwasm -fobj -DUSIM --output=negateDWord.usim_o negateDWord.asm lwasm -fobj -DUSIM --output=orDWordDWord.usim_o orDWordDWord.asm lwasm -fobj -DUSIM --output=orDWordWord.usim_o orDWordWord.asm lwasm -fobj -DUSIM --output=_printf.usim_o _printf.asm lwasm -fobj -DUSIM --output=push4ByteStruct.usim_o push4ByteStruct.asm lwasm -fobj -DUSIM --output=push5ByteStruct.usim_o push5ByteStruct.asm lwasm -fobj -DUSIM --output=pushStruct.usim_o pushStruct.asm lwasm -fobj -DUSIM --output=PUTCHR.usim_o PUTCHR.asm lwasm -fobj -DUSIM --output=putchar_a.usim_o putchar_a.asm lwasm -fobj -DUSIM --output=_putstr.usim_o _putstr.asm lwasm -fobj -DUSIM --output=_rand.usim_o _rand.asm lwasm -fobj -DUSIM --output=_readline.usim_o _readline.asm lwasm -fobj -DUSIM --output=_readword.usim_o _readword.asm lwasm -fobj -DUSIM --output=rightShiftDWord.usim_o rightShiftDWord.asm lwasm -fobj -DUSIM --output=rightShiftDWordAtXByB.usim_o rightShiftDWordAtXByB.asm lwasm -fobj -DUSIM --output=_sbrk.usim_o _sbrk.asm lwasm -fobj -DUSIM --output=_sbrkmax.usim_o _sbrkmax.asm lwasm -fobj -DUSIM --output=SDIV16.usim_o SDIV16.asm lwasm -fobj -DUSIM --output=SDIV8.usim_o SDIV8.asm lwasm -fobj -DUSIM --output=seed.usim_o seed.asm lwasm -fobj -DUSIM --output=_setConsoleOutHook.usim_o _setConsoleOutHook.asm lwasm -fobj -DUSIM --output=shiftByteLeft.usim_o shiftByteLeft.asm lwasm -fobj -DUSIM --output=shiftByteRightSigned.usim_o shiftByteRightSigned.asm lwasm -fobj -DUSIM --output=shiftByteRightUnsigned.usim_o shiftByteRightUnsigned.asm lwasm -fobj -DUSIM --output=shiftLeft.usim_o shiftLeft.asm lwasm -fobj -DUSIM --output=shiftRightSigned.usim_o shiftRightSigned.asm lwasm -fobj -DUSIM --output=shiftRightUnsigned.usim_o shiftRightUnsigned.asm lwasm -fobj -DUSIM --output=signedDivDWordDWord.usim_o signedDivDWordDWord.asm lwasm -fobj -DUSIM --output=signExtWordToDWord.usim_o signExtWordToDWord.asm lwasm -fobj -DUSIM --output=_sprintf.usim_o _sprintf.asm lwasm -fobj -DUSIM --output=_srand.usim_o _srand.asm lwasm -fobj -DUSIM --output=_strcat.usim_o _strcat.asm lwasm -fobj -DUSIM --output=_strchr.usim_o _strchr.asm lwasm -fobj -DUSIM --output=_strcmp.usim_o _strcmp.asm lwasm -fobj -DUSIM --output=_strcpy.usim_o _strcpy.asm lwasm -fobj -DUSIM --output=_strlen.usim_o _strlen.asm lwasm -fobj -DUSIM --output=_strlwr.usim_o _strlwr.asm lwasm -fobj -DUSIM --output=_strncpy.usim_o _strncpy.asm lwasm -fobj -DUSIM --output=_strtoul.usim_o _strtoul.asm lwasm -fobj -DUSIM --output=_strupr.usim_o _strupr.asm lwasm -fobj -DUSIM --output=sub32.usim_o sub32.asm lwasm -fobj -DUSIM --output=sub32xu.usim_o sub32xu.asm lwasm -fobj -DUSIM --output=subDWordDWord.usim_o subDWordDWord.asm lwasm -fobj -DUSIM --output=subDWordInt.usim_o subDWordInt.asm lwasm -fobj -DUSIM --output=subDWordUnsignedInt.usim_o subDWordUnsignedInt.asm lwasm -fobj -DUSIM --output=_subdww.usim_o _subdww.asm lwasm -fobj -DUSIM --output=subIntDWord.usim_o subIntDWord.asm lwasm -fobj -DUSIM --output=subUnsignedIntDWord.usim_o subUnsignedIntDWord.asm lwasm -fobj -DUSIM --output=testAndRemoveSignOnDWord.usim_o testAndRemoveSignOnDWord.asm lwasm -fobj -DUSIM --output=testAndRemoveSignOnWord.usim_o testAndRemoveSignOnWord.asm lwasm -fobj -DUSIM --output=_tolower.usim_o _tolower.asm lwasm -fobj -DUSIM --output=_toupper.usim_o _toupper.asm lwasm -fobj -DUSIM --output=xorDWordDWord.usim_o xorDWordDWord.asm lwasm -fobj -DUSIM --output=xorDWordWord.usim_o xorDWordWord.asm lwasm -fobj -DUSIM --output=_zerodw.usim_o _zerodw.asm ../cmoc -c -O2 -DNDEBUG -nostdinc -I . --usim -o atol.usim_o atol.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . --usim -o atoul.usim_o atoul.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . --usim -o strtol.usim_o strtol.c ../cmoc -c -O2 -DNDEBUG -nostdinc -I . --usim -o stdarg.usim_o stdarg.c lwar -c libcmoc-std-usim.a addDWordDWord.usim_o addDWordInt.usim_o addDWordUnsignedInt.usim_o _adddww.usim_o addIntDWord.usim_o addUnsignedIntDWord.usim_o andDWordDWord.usim_o andDWordWord.usim_o _atoi.usim_o _atoui.usim_o ATOW.usim_o checknull.usim_o checkstack.usim_o chrout.usim_o cmpDWordDWord.usim_o cmpDWordSignedInt.usim_o cmpDWordUnsignedInt.usim_o _cmpdww.usim_o cmpSignedIntDWord.usim_o cmpUnsignedIntDWord.usim_o copyDWord.usim_o copyMem.usim_o copyWordToDWord.usim_o crt.usim_o data.usim_o decrementDWord.usim_o _delay.usim_o DIV16.usim_o DIV16BY10.usim_o DIV32.usim_o DIV8.usim_o DIV8BY7.usim_o _divdwb.usim_o divDWordDWord.usim_o divDWordUnsignedInt.usim_o _divdww.usim_o divModDWordDWord.usim_o divModDWordUnsignedInt.usim_o divModUnsignedIntDWord.usim_o divUnsignedIntDWord.usim_o dwtoa.usim_o incrementDWord.usim_o initByteFromDWord.usim_o initDWordFromSignedWord.usim_o initDWordFromUnsignedWord.usim_o initSingleFromSingle.usim_o initWordFromDWord.usim_o isDWordZero.usim_o leftShiftDWord.usim_o leftShiftDWordAtXByB.usim_o LINBUF.usim_o _memcmp.usim_o memcpy.usim_o _memset.usim_o modDWordDWord.usim_o modDWordUnsignedInt.usim_o modUnsignedIntDWord.usim_o MUL168_TO24.usim_o MUL168_TO32.usim_o MUL16.usim_o MUL32.usim_o mulDWordDWord.usim_o mulDWordInt.usim_o mulDWordUnsignedInt.usim_o mulIntDWord.usim_o mulUnsignedIntDWord.usim_o negateDWord.usim_o orDWordDWord.usim_o orDWordWord.usim_o _printf.usim_o push4ByteStruct.usim_o push5ByteStruct.usim_o pushStruct.usim_o PUTCHR.usim_o putchar_a.usim_o _putstr.usim_o _rand.usim_o _readline.usim_o _readword.usim_o rightShiftDWord.usim_o rightShiftDWordAtXByB.usim_o _sbrk.usim_o _sbrkmax.usim_o SDIV16.usim_o SDIV8.usim_o seed.usim_o _setConsoleOutHook.usim_o shiftByteLeft.usim_o shiftByteRightSigned.usim_o shiftByteRightUnsigned.usim_o shiftLeft.usim_o shiftRightSigned.usim_o shiftRightUnsigned.usim_o signedDivDWordDWord.usim_o signExtWordToDWord.usim_o _sprintf.usim_o _srand.usim_o _strcat.usim_o _strchr.usim_o _strcmp.usim_o _strcpy.usim_o _strlen.usim_o _strlwr.usim_o _strncpy.usim_o _strtoul.usim_o _strupr.usim_o sub32.usim_o sub32xu.usim_o subDWordDWord.usim_o subDWordInt.usim_o subDWordUnsignedInt.usim_o _subdww.usim_o subIntDWord.usim_o subUnsignedIntDWord.usim_o testAndRemoveSignOnDWord.usim_o testAndRemoveSignOnWord.usim_o _tolower.usim_o _toupper.usim_o xorDWordDWord.usim_o xorDWordWord.usim_o _zerodw.usim_o atol.usim_o atoul.usim_o strtol.usim_o stdarg.usim_o make[3]: Leaving directory `/<>/src/stdlib' Making all in float make[3]: Entering directory `/<>/src/float' lwasm -fobj -D_COCO_BASIC_ --output=addFPA0FPA1.ecb_o addFPA0FPA1.asm lwasm -fobj -D_COCO_BASIC_ --output=addIntSingle.ecb_o addIntSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=addSignedDWordSingle.ecb_o addSignedDWordSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=addSingleInt.ecb_o addSingleInt.asm lwasm -fobj -D_COCO_BASIC_ --output=addSingleSignedDWord.ecb_o addSingleSignedDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=addSingleSingle.ecb_o addSingleSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=addSingleUnsignedDWord.ecb_o addSingleUnsignedDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=addSingleUnsignedInt.ecb_o addSingleUnsignedInt.asm lwasm -fobj -D_COCO_BASIC_ --output=addUnsignedDWordSingle.ecb_o addUnsignedDWordSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=addUnsignedIntSingle.ecb_o addUnsignedIntSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=binOpSingleSingle.ecb_o binOpSingleSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=cmpSignedIntSingle.ecb_o cmpSignedIntSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=cmpSingleSignedInt.ecb_o cmpSingleSignedInt.asm lwasm -fobj -D_COCO_BASIC_ --output=cmpSingleSingle.ecb_o cmpSingleSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=cmpSingleUnsignedInt.ecb_o cmpSingleUnsignedInt.asm lwasm -fobj -D_COCO_BASIC_ --output=cmpUnsignedIntSingle.ecb_o cmpUnsignedIntSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=copySingle.ecb_o copySingle.asm lwasm -fobj -D_COCO_BASIC_ --output=decrementSingle.ecb_o decrementSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=divByZeroSingle.ecb_o divByZeroSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=divIntSingle.ecb_o divIntSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=divSignedDWordSingle.ecb_o divSignedDWordSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=divSingleInt.ecb_o divSingleInt.asm lwasm -fobj -D_COCO_BASIC_ --output=divSingleSignedDWord.ecb_o divSingleSignedDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=divSingleSingle.ecb_o divSingleSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=divSingleUnsignedDWord.ecb_o divSingleUnsignedDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=divSingleUnsignedInt.ecb_o divSingleUnsignedInt.asm lwasm -fobj -D_COCO_BASIC_ --output=divUnsignedDWordSingle.ecb_o divUnsignedDWordSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=divUnsignedIntSingle.ecb_o divUnsignedIntSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=_ftoa.ecb_o _ftoa.asm lwasm -fobj -D_COCO_BASIC_ --output=incrementSingle.ecb_o incrementSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=initDWordFromSingle.ecb_o initDWordFromSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=initSignedByteFromSingle.ecb_o initSignedByteFromSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=initSignedWordFromSingle.ecb_o initSignedWordFromSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=initSingleFromDWord.ecb_o initSingleFromDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=initSingleFromSignedWord.ecb_o initSingleFromSignedWord.asm lwasm -fobj -D_COCO_BASIC_ --output=initSingleFromUnsignedWord.ecb_o initSingleFromUnsignedWord.asm lwasm -fobj -D_COCO_BASIC_ --output=initUnsignedByteFromSingle.ecb_o initUnsignedByteFromSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=initUnsignedWordFromSingle.ecb_o initUnsignedWordFromSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=isDWordZeroSpecial.ecb_o isDWordZeroSpecial.asm lwasm -fobj -D_COCO_BASIC_ --output=isSingleZero.ecb_o isSingleZero.asm lwasm -fobj -D_COCO_BASIC_ --output=loadSignedDWordInFPA0.ecb_o loadSignedDWordInFPA0.asm lwasm -fobj -D_COCO_BASIC_ --output=loadUnsignedDInFPA0.ecb_o loadUnsignedDInFPA0.asm lwasm -fobj -D_COCO_BASIC_ --output=loadUnsignedDWordInFPA0.ecb_o loadUnsignedDWordInFPA0.asm lwasm -fobj -D_COCO_BASIC_ --output=mulIntSingle.ecb_o mulIntSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=mulSignedDWordSingle.ecb_o mulSignedDWordSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=mulSingleInt.ecb_o mulSingleInt.asm lwasm -fobj -D_COCO_BASIC_ --output=mulSingleSignedDWord.ecb_o mulSingleSignedDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=mulSingleSingle.ecb_o mulSingleSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=mulSingleUnsignedDWord.ecb_o mulSingleUnsignedDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=mulSingleUnsignedInt.ecb_o mulSingleUnsignedInt.asm lwasm -fobj -D_COCO_BASIC_ --output=mulUnsignedDWordSingle.ecb_o mulUnsignedDWordSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=mulUnsignedIntSingle.ecb_o mulUnsignedIntSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=negateSingle.ecb_o negateSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=_strtof.ecb_o _strtof.asm lwasm -fobj -D_COCO_BASIC_ --output=subIntSingle.ecb_o subIntSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=subSignedDWordSingle.ecb_o subSignedDWordSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=subSingle_common.ecb_o subSingle_common.asm lwasm -fobj -D_COCO_BASIC_ --output=subSingleInt.ecb_o subSingleInt.asm lwasm -fobj -D_COCO_BASIC_ --output=subSingleSignedDWord.ecb_o subSingleSignedDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=subSingleSingle.ecb_o subSingleSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=subSingleUnsignedDWord.ecb_o subSingleUnsignedDWord.asm lwasm -fobj -D_COCO_BASIC_ --output=subSingleUnsignedInt.ecb_o subSingleUnsignedInt.asm lwasm -fobj -D_COCO_BASIC_ --output=subUnsignedDWordSingle.ecb_o subUnsignedDWordSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=subUnsignedIntSingle.ecb_o subUnsignedIntSingle.asm lwasm -fobj -D_COCO_BASIC_ --output=unpackXToFPA0AndDiv.ecb_o unpackXToFPA0AndDiv.asm lwasm -fobj -D_COCO_BASIC_ --output=unpackXtoFPA0AndPrep.ecb_o unpackXtoFPA0AndPrep.asm lwasm -fobj -D_COCO_BASIC_ --output=unpackXToFPA1AndMul.ecb_o unpackXToFPA1AndMul.asm lwar -c libcmoc-float-ecb.a addFPA0FPA1.ecb_o addIntSingle.ecb_o addSignedDWordSingle.ecb_o addSingleInt.ecb_o addSingleSignedDWord.ecb_o addSingleSingle.ecb_o addSingleUnsignedDWord.ecb_o addSingleUnsignedInt.ecb_o addUnsignedDWordSingle.ecb_o addUnsignedIntSingle.ecb_o binOpSingleSingle.ecb_o cmpSignedIntSingle.ecb_o cmpSingleSignedInt.ecb_o cmpSingleSingle.ecb_o cmpSingleUnsignedInt.ecb_o cmpUnsignedIntSingle.ecb_o copySingle.ecb_o decrementSingle.ecb_o divByZeroSingle.ecb_o divIntSingle.ecb_o divSignedDWordSingle.ecb_o divSingleInt.ecb_o divSingleSignedDWord.ecb_o divSingleSingle.ecb_o divSingleUnsignedDWord.ecb_o divSingleUnsignedInt.ecb_o divUnsignedDWordSingle.ecb_o divUnsignedIntSingle.ecb_o _ftoa.ecb_o incrementSingle.ecb_o initDWordFromSingle.ecb_o initSignedByteFromSingle.ecb_o initSignedWordFromSingle.ecb_o initSingleFromDWord.ecb_o initSingleFromSignedWord.ecb_o initSingleFromUnsignedWord.ecb_o initUnsignedByteFromSingle.ecb_o initUnsignedWordFromSingle.ecb_o isDWordZeroSpecial.ecb_o isSingleZero.ecb_o loadSignedDWordInFPA0.ecb_o loadUnsignedDInFPA0.ecb_o loadUnsignedDWordInFPA0.ecb_o mulIntSingle.ecb_o mulSignedDWordSingle.ecb_o mulSingleInt.ecb_o mulSingleSignedDWord.ecb_o mulSingleSingle.ecb_o mulSingleUnsignedDWord.ecb_o mulSingleUnsignedInt.ecb_o mulUnsignedDWordSingle.ecb_o mulUnsignedIntSingle.ecb_o negateSingle.ecb_o _strtof.ecb_o subIntSingle.ecb_o subSignedDWordSingle.ecb_o subSingle_common.ecb_o subSingleInt.ecb_o subSingleSignedDWord.ecb_o subSingleSingle.ecb_o subSingleUnsignedDWord.ecb_o subSingleUnsignedInt.ecb_o subUnsignedDWordSingle.ecb_o subUnsignedIntSingle.ecb_o unpackXToFPA0AndDiv.ecb_o unpackXtoFPA0AndPrep.ecb_o unpackXToFPA1AndMul.ecb_o lwasm -fobj -DUSIM --output=addFPA0FPA1.usim_o addFPA0FPA1.asm lwasm -fobj -DUSIM --output=addIntSingle.usim_o addIntSingle.asm lwasm -fobj -DUSIM --output=addSignedDWordSingle.usim_o addSignedDWordSingle.asm lwasm -fobj -DUSIM --output=addSingleInt.usim_o addSingleInt.asm lwasm -fobj -DUSIM --output=addSingleSignedDWord.usim_o addSingleSignedDWord.asm lwasm -fobj -DUSIM --output=addSingleSingle.usim_o addSingleSingle.asm lwasm -fobj -DUSIM --output=addSingleUnsignedDWord.usim_o addSingleUnsignedDWord.asm lwasm -fobj -DUSIM --output=addSingleUnsignedInt.usim_o addSingleUnsignedInt.asm lwasm -fobj -DUSIM --output=addUnsignedDWordSingle.usim_o addUnsignedDWordSingle.asm lwasm -fobj -DUSIM --output=addUnsignedIntSingle.usim_o addUnsignedIntSingle.asm lwasm -fobj -DUSIM --output=binOpSingleSingle.usim_o binOpSingleSingle.asm lwasm -fobj -DUSIM --output=cmpSignedIntSingle.usim_o cmpSignedIntSingle.asm lwasm -fobj -DUSIM --output=cmpSingleSignedInt.usim_o cmpSingleSignedInt.asm lwasm -fobj -DUSIM --output=cmpSingleSingle.usim_o cmpSingleSingle.asm lwasm -fobj -DUSIM --output=cmpSingleUnsignedInt.usim_o cmpSingleUnsignedInt.asm lwasm -fobj -DUSIM --output=cmpUnsignedIntSingle.usim_o cmpUnsignedIntSingle.asm lwasm -fobj -DUSIM --output=copySingle.usim_o copySingle.asm lwasm -fobj -DUSIM --output=decrementSingle.usim_o decrementSingle.asm lwasm -fobj -DUSIM --output=divByZeroSingle.usim_o divByZeroSingle.asm lwasm -fobj -DUSIM --output=divIntSingle.usim_o divIntSingle.asm lwasm -fobj -DUSIM --output=divSignedDWordSingle.usim_o divSignedDWordSingle.asm lwasm -fobj -DUSIM --output=divSingleInt.usim_o divSingleInt.asm lwasm -fobj -DUSIM --output=divSingleSignedDWord.usim_o divSingleSignedDWord.asm lwasm -fobj -DUSIM --output=divSingleSingle.usim_o divSingleSingle.asm lwasm -fobj -DUSIM --output=divSingleUnsignedDWord.usim_o divSingleUnsignedDWord.asm lwasm -fobj -DUSIM --output=divSingleUnsignedInt.usim_o divSingleUnsignedInt.asm lwasm -fobj -DUSIM --output=divUnsignedDWordSingle.usim_o divUnsignedDWordSingle.asm lwasm -fobj -DUSIM --output=divUnsignedIntSingle.usim_o divUnsignedIntSingle.asm lwasm -fobj -DUSIM --output=_ftoa.usim_o _ftoa.asm lwasm -fobj -DUSIM --output=incrementSingle.usim_o incrementSingle.asm lwasm -fobj -DUSIM --output=initDWordFromSingle.usim_o initDWordFromSingle.asm lwasm -fobj -DUSIM --output=initSignedByteFromSingle.usim_o initSignedByteFromSingle.asm lwasm -fobj -DUSIM --output=initSignedWordFromSingle.usim_o initSignedWordFromSingle.asm lwasm -fobj -DUSIM --output=initSingleFromDWord.usim_o initSingleFromDWord.asm lwasm -fobj -DUSIM --output=initSingleFromSignedWord.usim_o initSingleFromSignedWord.asm lwasm -fobj -DUSIM --output=initSingleFromUnsignedWord.usim_o initSingleFromUnsignedWord.asm lwasm -fobj -DUSIM --output=initUnsignedByteFromSingle.usim_o initUnsignedByteFromSingle.asm lwasm -fobj -DUSIM --output=initUnsignedWordFromSingle.usim_o initUnsignedWordFromSingle.asm lwasm -fobj -DUSIM --output=isDWordZeroSpecial.usim_o isDWordZeroSpecial.asm lwasm -fobj -DUSIM --output=isSingleZero.usim_o isSingleZero.asm lwasm -fobj -DUSIM --output=loadSignedDWordInFPA0.usim_o loadSignedDWordInFPA0.asm lwasm -fobj -DUSIM --output=loadUnsignedDInFPA0.usim_o loadUnsignedDInFPA0.asm lwasm -fobj -DUSIM --output=loadUnsignedDWordInFPA0.usim_o loadUnsignedDWordInFPA0.asm lwasm -fobj -DUSIM --output=mulIntSingle.usim_o mulIntSingle.asm lwasm -fobj -DUSIM --output=mulSignedDWordSingle.usim_o mulSignedDWordSingle.asm lwasm -fobj -DUSIM --output=mulSingleInt.usim_o mulSingleInt.asm lwasm -fobj -DUSIM --output=mulSingleSignedDWord.usim_o mulSingleSignedDWord.asm lwasm -fobj -DUSIM --output=mulSingleSingle.usim_o mulSingleSingle.asm lwasm -fobj -DUSIM --output=mulSingleUnsignedDWord.usim_o mulSingleUnsignedDWord.asm lwasm -fobj -DUSIM --output=mulSingleUnsignedInt.usim_o mulSingleUnsignedInt.asm lwasm -fobj -DUSIM --output=mulUnsignedDWordSingle.usim_o mulUnsignedDWordSingle.asm lwasm -fobj -DUSIM --output=mulUnsignedIntSingle.usim_o mulUnsignedIntSingle.asm lwasm -fobj -DUSIM --output=negateSingle.usim_o negateSingle.asm lwasm -fobj -DUSIM --output=_strtof.usim_o _strtof.asm lwasm -fobj -DUSIM --output=subIntSingle.usim_o subIntSingle.asm lwasm -fobj -DUSIM --output=subSignedDWordSingle.usim_o subSignedDWordSingle.asm lwasm -fobj -DUSIM --output=subSingle_common.usim_o subSingle_common.asm lwasm -fobj -DUSIM --output=subSingleInt.usim_o subSingleInt.asm lwasm -fobj -DUSIM --output=subSingleSignedDWord.usim_o subSingleSignedDWord.asm lwasm -fobj -DUSIM --output=subSingleSingle.usim_o subSingleSingle.asm lwasm -fobj -DUSIM --output=subSingleUnsignedDWord.usim_o subSingleUnsignedDWord.asm lwasm -fobj -DUSIM --output=subSingleUnsignedInt.usim_o subSingleUnsignedInt.asm lwasm -fobj -DUSIM --output=subUnsignedDWordSingle.usim_o subUnsignedDWordSingle.asm lwasm -fobj -DUSIM --output=subUnsignedIntSingle.usim_o subUnsignedIntSingle.asm lwasm -fobj -DUSIM --output=unpackXToFPA0AndDiv.usim_o unpackXToFPA0AndDiv.asm lwasm -fobj -DUSIM --output=unpackXtoFPA0AndPrep.usim_o unpackXtoFPA0AndPrep.asm lwasm -fobj -DUSIM --output=unpackXToFPA1AndMul.usim_o unpackXToFPA1AndMul.asm lwar -c libcmoc-float-usim.a addFPA0FPA1.usim_o addIntSingle.usim_o addSignedDWordSingle.usim_o addSingleInt.usim_o addSingleSignedDWord.usim_o addSingleSingle.usim_o addSingleUnsignedDWord.usim_o addSingleUnsignedInt.usim_o addUnsignedDWordSingle.usim_o addUnsignedIntSingle.usim_o binOpSingleSingle.usim_o cmpSignedIntSingle.usim_o cmpSingleSignedInt.usim_o cmpSingleSingle.usim_o cmpSingleUnsignedInt.usim_o cmpUnsignedIntSingle.usim_o copySingle.usim_o decrementSingle.usim_o divByZeroSingle.usim_o divIntSingle.usim_o divSignedDWordSingle.usim_o divSingleInt.usim_o divSingleSignedDWord.usim_o divSingleSingle.usim_o divSingleUnsignedDWord.usim_o divSingleUnsignedInt.usim_o divUnsignedDWordSingle.usim_o divUnsignedIntSingle.usim_o _ftoa.usim_o incrementSingle.usim_o initDWordFromSingle.usim_o initSignedByteFromSingle.usim_o initSignedWordFromSingle.usim_o initSingleFromDWord.usim_o initSingleFromSignedWord.usim_o initSingleFromUnsignedWord.usim_o initUnsignedByteFromSingle.usim_o initUnsignedWordFromSingle.usim_o isDWordZeroSpecial.usim_o isSingleZero.usim_o loadSignedDWordInFPA0.usim_o loadUnsignedDInFPA0.usim_o loadUnsignedDWordInFPA0.usim_o mulIntSingle.usim_o mulSignedDWordSingle.usim_o mulSingleInt.usim_o mulSingleSignedDWord.usim_o mulSingleSingle.usim_o mulSingleUnsignedDWord.usim_o mulSingleUnsignedInt.usim_o mulUnsignedDWordSingle.usim_o mulUnsignedIntSingle.usim_o negateSingle.usim_o _strtof.usim_o subIntSingle.usim_o subSignedDWordSingle.usim_o subSingle_common.usim_o subSingleInt.usim_o subSingleSignedDWord.usim_o subSingleSingle.usim_o subSingleUnsignedDWord.usim_o subSingleUnsignedInt.usim_o subUnsignedDWordSingle.usim_o subUnsignedIntSingle.usim_o unpackXToFPA0AndDiv.usim_o unpackXtoFPA0AndPrep.usim_o unpackXToFPA1AndMul.usim_o make[3]: Leaving directory `/<>/src/float' make[2]: Leaving directory `/<>/src' Making all in macros make[2]: Entering directory `/<>/macros' make[2]: Nothing to be done for `all'. make[2]: Leaving directory `/<>/macros' Making all in doc make[2]: Entering directory `/<>/doc' make[2]: Nothing to be done for `all'. make[2]: Leaving directory `/<>/doc' make[2]: Entering directory `/<>' make[2]: Nothing to be done for `all-am'. make[2]: Leaving directory `/<>' make[1]: Leaving directory `/<>' dh_auto_test make[1]: Entering directory `/<>' Making check in src make[2]: Entering directory `/<>/src' Making check in support make[3]: Entering directory `/<>/src/support' Making check in vectrex make[4]: Entering directory `/<>/src/support/vectrex' make[4]: Nothing to be done for `check'. make[4]: Leaving directory `/<>/src/support/vectrex' make[4]: Entering directory `/<>/src/support' make[4]: Nothing to be done for `check-am'. make[4]: Leaving directory `/<>/src/support' make[3]: Leaving directory `/<>/src/support' Making check in usim-0.91-cmoc make[3]: Entering directory `/<>/src/usim-0.91-cmoc' make[3]: Nothing to be done for `check'. make[3]: Leaving directory `/<>/src/usim-0.91-cmoc' Making check in . make[3]: Entering directory `/<>/src' make[3]: Nothing to be done for `check-am'. make[3]: Leaving directory `/<>/src' Making check in stdlib make[3]: Entering directory `/<>/src/stdlib' make[3]: Nothing to be done for `check'. make[3]: Leaving directory `/<>/src/stdlib' Making check in float make[3]: Entering directory `/<>/src/float' make[3]: Nothing to be done for `check'. make[3]: Leaving directory `/<>/src/float' ./writecocofile --version >/dev/null ./writecocofile --help >/dev/null perl -e 'print chr(255) x (35*18*256)' > ,check.dsk ./writecocofile -d ,check.dsk | grep -q '68 granule.s. free' echo FOOBAR > ,check.dat ./writecocofile --verbose ,check.dsk ,check.dat | grep -q 'Writing native file ,check.dat' ./writecocofile -d ,check.dsk | grep -q '67 granule.s. free' ./writecocofile -d ,check.dsk | grep -q ',CHECK .DAT data binary' ./writecocofile -s ,check.dsk ,check.dat | grep -q 'FOOBAR' ./writecocofile --verbose -k ,check.dsk ,check.dat | grep -q 'Freeing granule' ./writecocofile -d ,check.dsk | grep -q '68 granule.s. free' rm -f ,check.dsk ,check.dat perl -cw ./a09 ./a09 syntax OK perl -cw ./intelhex2cocobin ./intelhex2cocobin syntax OK perl -cw ./intelhex2srec ./intelhex2srec syntax OK ./a09 --version >/dev/null ./a09 --help >/dev/null test -x ./intelhex2cocobin test "`./intelhex2cocobin /dev/null ./cmoc --help >/dev/null rm -f ,check-prog.c ,check-prog.s ,check-prog.asm ,check-prog.i ,check-prog.lst ,check-prog.hex ,check-prog.bin echo "char g; int main() { return 0; }" >,check-prog.c env PATH=".:$PATH" ./cmoc -Lstdlib -Lfloat -o ,check-prog.xyz ,check-prog.c test ! -f ,check-prog.bin # fail if -o not applied rm ,check-prog.xyz # fail if file not there env PATH=".:$PATH" ./cmoc -Lstdlib -Lfloat --lwasm=`which lwasm` --lwlink=`which lwlink` ,check-prog.c rm ,check-prog.bin # fail if file not there env PATH=".:$PATH" ./cmoc --monolith --a09=./a09 -I ./support/ --srec --verbose ,check-prog.c | grep "Generating SREC" Generating SREC: 'intelhex2srec' --entry=2800 < ',check-prog.hex' > ',check-prog.srec' env PATH=".:$PATH" ./cmoc -Lstdlib -Lfloat --srec --verbose ,check-prog.c | grep ",check-prog.srec" Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-ecb -lcmoc-float-ecb ',check-prog.o' grep -q ^S1 ,check-prog.srec # data record test `grep -c ^S9 ,check-prog.srec` = 1 # starting address record (only one) test `grep -c ^: ,check-prog.srec` = 0 # not Intel HEX format env PATH=".:$PATH" ./cmoc -Lstdlib -Lfloat --org=4321 --data=6000 --intermediate --verbose ,check-prog.c 2>&1 Target platform: CoCo Disk Basic Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'/usr/share/cmoc/include' -D_COCO_BASIC_=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4321 (17185) Data address: $6000 (24576) Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=decb --output=',check-prog.bin' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-ecb -lcmoc-float-ecb ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 grep -q "Symbol: program_start (,check-prog.o) = 4321" ,check-prog.map grep -q "Section: rwdata .* load at 6000," ,check-prog.map env PATH=".:$PATH" ./cmoc --monolith --a09=./a09 -I ./support/ --org=4321 --verbose ,check-prog.c 2>&1 | grep -q "program_start .4321" env PATH=".:$PATH" ./cmoc -Lstdlib -Lfloat --org=2800 --limit=2810 ,check-prog.c 2>&1 | grep -q "program_end exceeds it" env PATH=".:$PATH" ./cmoc --monolith --a09=./a09 -I ./support/ --org=2800 --limit=2810 ,check-prog.c 2>&1 | grep -q "program_end exceeds it" env PATH=".:$PATH" ./cmoc -Lstdlib -Lfloat --dos ,check-prog.c hexdump -C ,check-prog.bin | head -1 | grep -q '^00000000 00 .. .. 26 00 4f 53' env PATH=".:$PATH" ./cmoc --monolith --a09=./a09 -I ./support/ --os9 --intermediate ,check-prog.c grep -q -w -i mod ,check-prog.asm grep -q -w -i emod ,check-prog.asm test -f ,check-prog rm -f ,check-prog rm -f ,check-prog.* perl -cw ./test-program-output.pl ./test-program-output.pl syntax OK perl -cw ./test-bad-programs.pl ./test-bad-programs.pl syntax OK perl -e 'print "#include \nint main() { move(0, 0); return 0; }\n"' >,check-prog.c rm -f ,check-prog.bin env PATH=".:$PATH" ./cmoc --monolith --a09=./a09 -I ./support/ --vectrex --intermediate ,check-prog.c test -f ,check-prog.bin grep -q -w '^_move' ,check-prog.asm grep -q -w 'vx_music_1' ,check-prog.asm rm -f ,check-prog.c ,check-prog.asm ,check-prog.s ,check-prog.i \ ,check-prog.lst ,check-prog.hex ,check-prog.srec \ ,check-prog.link ,check-prog.map ,check-prog.bin perl -e 'print qq[#include \nint main() { printf("\%u\\n", sbrkmax()); return 0; }\n]' >,check-prog.c env PATH=".:$PATH" ./cmoc -Lstdlib -Lfloat --usim -c -I ./stdlib ,check-prog.c env PATH=".:$PATH" ./cmoc -Lstdlib -Lfloat --usim --org=0 ,check-prog.o test `usim-0.91-cmoc/usim ,check-prog.srec` -ge 60000 env PATH=".:$PATH" ./cmoc -Lstdlib -Lfloat --usim -c -I ./stdlib --stack-space=30000 ,check-prog.c env PATH=".:$PATH" ./cmoc -Lstdlib -Lfloat --usim --org=0 ,check-prog.o test `usim-0.91-cmoc/usim ,check-prog.srec` -lt 34000 perl -e 'print qq[#pragma stack_space 15000\n#include \nint main() { printf("\%u\\n", sbrkmax()); return 0; }\n]' >,check-prog.c env PATH=".:$PATH" ./cmoc -Lstdlib -Lfloat --usim -c -I ./stdlib ,check-prog.c env PATH=".:$PATH" ./cmoc -Lstdlib -Lfloat --usim --org=0 ,check-prog.o test `usim-0.91-cmoc/usim ,check-prog.srec` -ge 48000 test `usim-0.91-cmoc/usim ,check-prog.srec` -lt 49000 rm -f ,check-prog.c ,check-prog.o ,check-prog.srec perl ./test-program-output.pl . ./test-program-output.pl: 157 programs to test. -------------------------------------------------------------------------------- --- Program # 0: Smallest legal program 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 int main() { return 0; } --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 1: Calling a built-in function 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 int main() { printf(""); return 0; } --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 2: printf() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 printf("Hello, world.\n"); 27 printf("A%sB\n", "\n"); 28 putstr("C\nD\n", 4); 29 putchar('\n'); 30 return 0; 31 } 32 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: Hello, world. A B C D --- Actual output: Hello, world. A B C D -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 3: Conversions between byte and word 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte f(byte x); 25 int main() 26 { 27 printf("%u\n", (byte) f((byte) 1000)); 28 assert_eq((byte) f((byte) 1000), 208); 29 byte boolean = ((byte) f((byte) 1000)) == 208; 30 assert(boolean); 31 word oneByteUnsignedWord = 208; 32 assert_eq(oneByteUnsignedWord, 208); 33 byte eightBitUnsignedByte = 208; 34 assert_eq(oneByteUnsignedWord, eightBitUnsignedByte); 35 char eightBitSignedByte = 208; // seen as -48 36 assert_ne(oneByteUnsignedWord, eightBitSignedByte); // as words, 208 != -48 37 38 word w = 0x1200 + 42; 39 byte b = (byte) w; 40 printf("%u\n", b); 41 assert_eq(b, 42); 42 word k = 256 - b; 43 printf("%u\n", k); 44 assert_eq(k, 214); 45 k = 50 - b; 46 printf("%u\n", k); 47 assert_eq(k, 8); 48 return 0; 49 } 50 byte f(byte x) { return (byte) (x + 1000); } 51 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: 208 42 214 8 --- Actual output: 208 42 214 8 -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 4: Shifts 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void checkLeftConst(); 25 void checkLeftVar(); 26 void checkRightConst(); 27 void checkRightVar(); 28 word checkCounter = 0; 29 #define check(actual, expected) _check(__LINE__, actual, expected) 30 void _check(int lineno, word actual, word expected); 31 #define scheck(actual, expected) _scheck(__LINE__, actual, expected) 32 void _scheck(int lineno, int actual, int expected); 33 void checkLeftVarW(word initVal, byte numBits, word expected); 34 void checkLeftVarB(byte initVal, byte numBits, byte expected); 35 void checkRightVarW(word initVal, byte numBits, word expected); 36 void checkRightVarB(byte initVal, byte numBits, byte expected); 37 void checkRightVarSW(sword initVal, byte numBits, sword expected); 38 void checkRightVarSB(sbyte initVal, byte numBits, sbyte expected); 39 40 word initStackPtr, finalStackPtr; 41 42 int main() 43 { 44 asm { sts initStackPtr }; 45 assert_eq(((int) 0xFFFF) >> 16, -1); 46 assert_eq(((int) 0xFFFF) >> 15, -1); 47 assert_eq(((char) 0xFF) >> 8, -1); 48 assert_eq(((char) 0xFF) >> 7, -1); 49 checkLeftConst(); 50 checkLeftVar(); 51 checkRightConst(); 52 checkRightVar(); 53 byte shift = 16; 54 assert_eq(0xFFFF >> shift, 0); 55 assert_eq(((int) 0xFFFF) >> shift, -1); 56 asm { sts finalStackPtr } 57 assert_eq(finalStackPtr, initStackPtr); 58 return 0; 59 } 60 61 void checkLeftConst() 62 { 63 word w = 1; 64 check(w << 0, 1); 65 check(w << 1, 2); 66 check(w << 4, 16); 67 check(w << 7, 128); 68 check(w << 8, 256); 69 check(w << 9, 512); 70 check(w << 15, 32768); 71 check(w << 16, 0); 72 73 w = 0xffff; 74 check(w << 0, 0xffff); 75 check(w << 1, 0xfffe); 76 check(w << 4, 0xfff0); 77 check(w << 7, 0xff80); 78 check(w << 8, 0xff00); 79 check(w << 9, 0xfe00); 80 check(w << 10, 0xfc00); 81 check(w << 15, 32768); 82 check(w << 16, 0); 83 84 byte b = 1; 85 check(b << 0, 1); 86 check(b << 1, 2); 87 check(b << 4, 16); 88 check(b << 7, 128); 89 check(b << 8, 0); 90 check(b << 15, 0); 91 check(b << 16, 0); 92 93 b = 0xff; 94 check(b << 0, 0xff); 95 check(b << 1, 0xfe); 96 check(b << 4, 0xf0); 97 check(b << 7, 0x80); 98 check(b << 8, 0); 99 check(b << 15, 0); 100 check(b << 16, 0); 101 } 102 103 void checkLeftVar() 104 { 105 word w = 1; 106 checkLeftVarW(w, 0, 1); 107 checkLeftVarW(w, 1, 2); 108 checkLeftVarW(w, 4, 16); 109 checkLeftVarW(w, 8, 256); 110 checkLeftVarW(w, 15, 32768); 111 checkLeftVarW(w, 16, 0); 112 113 w = 0xffff; 114 checkLeftVarW(w, 0, 0xffff); 115 checkLeftVarW(w, 1, 0xfffe); 116 checkLeftVarW(w, 4, 0xfff0); 117 checkLeftVarW(w, 8, 0xff00); 118 checkLeftVarW(w, 9, 0xfe00); 119 checkLeftVarW(w, 15, 32768); 120 checkLeftVarW(w, 16, 0); 121 122 byte b = 1; 123 checkLeftVarB(b, 0, 1); 124 checkLeftVarB(b, 1, 2); 125 checkLeftVarB(b, 4, 16); 126 checkLeftVarB(b, 8, 0); 127 checkLeftVarB(b, 15, 0); 128 checkLeftVarB(b, 16, 0); 129 130 b = 0xff; 131 checkLeftVarB(b, 0, 0xff); 132 checkLeftVarB(b, 1, 0xfe); 133 checkLeftVarB(b, 4, 0xf0); 134 checkLeftVarB(b, 8, 0); 135 checkLeftVarB(b, 15, 0); 136 checkLeftVarB(b, 16, 0); 137 } 138 139 void checkRightConst() 140 { 141 word w = 0x8000; 142 check(w >> 0, 0x8000); 143 check(w >> 1, 0x4000); 144 check(w >> 4, 0x0800); 145 check(w >> 7, 0x0100); 146 check(w >> 8, 0x0080); 147 check(w >> 15, 0x0001); 148 check(w >> 16, 0); 149 150 w = 0xffff; 151 check(w >> 0, 0xffff); 152 check(w >> 1, 0x7fff); 153 check(w >> 4, 0x0fff); 154 check(w >> 7, 0x01ff); 155 check(w >> 8, 0x00ff); 156 check(w >> 15, 0x0001); 157 check(w >> 16, 0); 158 159 byte b = 0x80; 160 check(b >> 0, 0x80); 161 check(b >> 1, 0x40); 162 check(b >> 4, 0x08); 163 check(b >> 7, 0x01); 164 check(b >> 8, 0); 165 check(b >> 15, 0); 166 check(b >> 16, 0); 167 168 b = 0xff; 169 check(b >> 0, 0xff); 170 check(b >> 1, 0x7f); 171 check(b >> 4, 0x0f); 172 check(b >> 7, 0x01); 173 check(b >> 8, 0); 174 check(b >> 15, 0); 175 check(b >> 16, 0); 176 177 // Signed cases: sign must be preserved. 178 // When shifting all bits, result must be all ones. 179 180 char sb = 0x55; 181 scheck(sb >> 0, 0x55); 182 scheck(sb >> 1, 0x2A); 183 scheck(sb >> 4, 0x05); 184 scheck(sb >> 7, 0); 185 scheck(sb >> 8, 0); 186 scheck(sb >> 15, 0); 187 scheck(sb >> 16, 0); 188 189 sb = 0xAA; // -86 decimal 190 scheck(sb >> 0, -86); 191 scheck(sb >> 1, -43); 192 scheck(sb >> 2, -22); 193 scheck(sb >> 3, -11); 194 scheck(sb >> 4, -6); 195 scheck(sb >> 5, -3); 196 scheck(sb >> 6, -2); 197 scheck(sb >> 7, -1); 198 scheck(sb >> 8, -1); 199 scheck(sb >> 15, -1); 200 scheck(sb >> 16, -1); 201 202 int sw = 0x5555; 203 scheck(sw >> 0, (int) 0x5555); 204 scheck(sw >> 1, (int) 0x2AAA); 205 scheck(sw >> 4, (int) 0x0555); 206 scheck(sw >> 7, (int) 0x00AA); 207 scheck(sw >> 8, (int) 0x0055); 208 scheck(sw >> 14, 1); 209 scheck(sw >> 15, 0); 210 scheck(sw >> 16, 0); 211 212 sw = (int) 0xAAAA; // -21846 decimal 213 scheck(sw >> 0, (int) 0xaaaa); 214 scheck(sw >> 1, (int) 0xd555); 215 scheck(sw >> 2, (int) 0xeaaa); 216 scheck(sw >> 3, (int) 0xf555); 217 scheck(sw >> 4, (int) 0xfaaa); 218 scheck(sw >> 5, (int) 0xfd55); 219 scheck(sw >> 6, (int) 0xfeaa); 220 scheck(sw >> 7, (int) 0xff55); 221 scheck(sw >> 8, (int) 0xffaa); 222 scheck(sw >> 9, (int) 0xffd5); 223 scheck(sw >> 10, (int) 0xffea); 224 scheck(sw >> 11, (int) 0xfff5); 225 scheck(sw >> 12, (int) 0xfffa); 226 scheck(sw >> 13, (int) 0xfffd); 227 scheck(sw >> 14, (int) 0xfffe); 228 scheck(sw >> 15, (int) 0xffff); 229 scheck(sw >> 16, (int) 0xffff); 230 } 231 232 void checkRightVar() 233 { 234 word w = 0x8000; 235 checkRightVarW(w, 0, 0x8000); 236 checkRightVarW(w, 1, 0x4000); 237 checkRightVarW(w, 4, 0x0800); 238 checkRightVarW(w, 7, 0x0100); 239 checkRightVarW(w, 8, 0x0080); 240 checkRightVarW(w, 15, 0x0001); 241 checkRightVarW(w, 16, 0); 242 243 w = 0xffff; 244 checkRightVarW(w, 0, 0xffff); 245 checkRightVarW(w, 1, 0x7fff); 246 checkRightVarW(w, 4, 0x0fff); 247 checkRightVarW(w, 7, 0x01ff); 248 checkRightVarW(w, 8, 0x00ff); 249 checkRightVarW(w, 15, 0x0001); 250 checkRightVarW(w, 16, 0); 251 252 byte b = 0x80; 253 checkRightVarB(b, 0, 0x80); 254 checkRightVarB(b, 1, 0x40); 255 checkRightVarB(b, 4, 0x08); 256 checkRightVarB(b, 7, 0x01); 257 checkRightVarB(b, 8, 0); 258 checkRightVarB(b, 15, 0); 259 checkRightVarB(b, 16, 0); 260 261 b = 0xff; 262 checkRightVarB(b, 0, 0xff); 263 checkRightVarB(b, 1, 0x7f); 264 checkRightVarB(b, 4, 0x0f); 265 checkRightVarB(b, 7, 0x01); 266 checkRightVarB(b, 8, 0); 267 checkRightVarB(b, 15, 0); 268 checkRightVarB(b, 16, 0); 269 270 // Signed cases: sign must be preserved. 271 // When shifting all bits, result must be all ones. 272 273 char sb = 0x55; 274 checkRightVarSB(sb, 0, 0x55); 275 checkRightVarSB(sb, 1, 0x2A); 276 checkRightVarSB(sb, 4, 0x05); 277 checkRightVarSB(sb, 7, 0); 278 checkRightVarSB(sb, 8, 0); 279 checkRightVarSB(sb, 15, 0); 280 checkRightVarSB(sb, 16, 0); 281 282 sb = 0xAA; // -86 decimal 283 checkRightVarSB(sb, 0, -86); 284 checkRightVarSB(sb, 1, -43); 285 checkRightVarSB(sb, 2, -22); 286 checkRightVarSB(sb, 3, -11); 287 checkRightVarSB(sb, 4, -6); 288 checkRightVarSB(sb, 5, -3); 289 checkRightVarSB(sb, 6, -2); 290 checkRightVarSB(sb, 7, -1); 291 checkRightVarSB(sb, 8, -1); 292 checkRightVarSB(sb, 15, -1); 293 checkRightVarSB(sb, 16, -1); 294 295 int sw = 0x5555; 296 checkRightVarSW(sw, 0, (int) 0x5555); 297 checkRightVarSW(sw, 1, (int) 0x2AAA); 298 checkRightVarSW(sw, 4, (int) 0x0555); 299 checkRightVarSW(sw, 7, (int) 0x00AA); 300 checkRightVarSW(sw, 8, (int) 0x0055); 301 checkRightVarSW(sw, 14, 1); 302 checkRightVarSW(sw, 15, 0); 303 checkRightVarSW(sw, 16, 0); 304 305 sw = (int) 0xAAAA; // -21846 decimal 306 checkRightVarSW(sw, 0, (int) 0xaaaa); 307 checkRightVarSW(sw, 1, (int) 0xd555); 308 checkRightVarSW(sw, 2, (int) 0xeaaa); 309 checkRightVarSW(sw, 3, (int) 0xf555); 310 checkRightVarSW(sw, 4, (int) 0xfaaa); 311 checkRightVarSW(sw, 5, (int) 0xfd55); 312 checkRightVarSW(sw, 6, (int) 0xfeaa); 313 checkRightVarSW(sw, 7, (int) 0xff55); 314 checkRightVarSW(sw, 8, (int) 0xffaa); 315 checkRightVarSW(sw, 9, (int) 0xffd5); 316 checkRightVarSW(sw, 10, (int) 0xffea); 317 checkRightVarSW(sw, 11, (int) 0xfff5); 318 checkRightVarSW(sw, 12, (int) 0xfffa); 319 checkRightVarSW(sw, 13, (int) 0xfffd); 320 checkRightVarSW(sw, 14, (int) 0xfffe); 321 checkRightVarSW(sw, 15, (int) 0xffff); 322 checkRightVarSW(sw, 16, (int) 0xffff); 323 } 324 325 void _check(int lineno, word actual, word expected) 326 { 327 ++checkCounter; 328 if (actual != expected) 329 { 330 printf("ERROR: check #%u at line %d: got %u ($%x), expected %u ($%x)\n", 331 checkCounter, lineno, actual, actual, expected, expected); 332 } 333 } 334 335 void _scheck(int lineno, int actual, int expected) 336 { 337 ++checkCounter; 338 if (actual != expected) 339 { 340 printf("ERROR: check #%u at line %d: got %d, expected %d\n", 341 checkCounter, lineno, actual, expected); 342 } 343 } 344 345 void checkLeftVarW(word initVal, byte numBits, word expected) 346 { 347 word actual = initVal << numBits; 348 ++checkCounter; 349 if (actual != expected) 350 { 351 printf("ERROR: checkLeftVarW #%u: %u << %u, got %u, expected %u\n", checkCounter, initVal, numBits, actual, expected); 352 } 353 } 354 355 void checkLeftVarB(byte initVal, byte numBits, byte expected) 356 { 357 asm { lda #0xFF } // put garbage in A, as a robustness test 358 byte actual = initVal << numBits; 359 ++checkCounter; 360 if (actual != expected) 361 { 362 printf("ERROR: checkLeftVarB #%u: %u << %u, got %u, expected %u\n", checkCounter, initVal, numBits, actual, expected); 363 } 364 } 365 366 void checkRightVarW(word initVal, byte numBits, word expected) 367 { 368 word actual = initVal >> numBits; 369 ++checkCounter; 370 if (actual != expected) 371 { 372 printf("ERROR: checkRightVarW #%u: %u >> %u, got %u, expected %u\n", checkCounter, initVal, numBits, actual, expected); 373 } 374 } 375 376 void checkRightVarB(byte initVal, byte numBits, byte expected) 377 { 378 asm { lda #0xFF } // put garbage in A, as a robustness test 379 byte actual = initVal >> numBits; 380 ++checkCounter; 381 if (actual != expected) 382 { 383 printf("ERROR: checkRightVarB #%u: %u >> %u, got %u, expected %u\n", checkCounter, initVal, numBits, actual, expected); 384 } 385 } 386 387 void checkRightVarSW(sword initVal, byte numBits, sword expected) 388 { 389 sword actual = initVal >> numBits; 390 ++checkCounter; 391 if (actual != expected) 392 { 393 printf("ERROR: checkRightVarSW #%u: %d >> %u, got %d, expected %u\n", checkCounter, initVal, numBits, actual, expected); 394 } 395 } 396 397 void checkRightVarSB(sbyte initVal, byte numBits, sbyte expected) 398 { 399 asm { lda #0xFF } // put garbage in A, as a robustness test 400 sbyte actual = initVal >> numBits; 401 ++checkCounter; 402 if (actual != expected) 403 { 404 printf("ERROR: checkRightVarSB #%u: %d >> %u, got %d, expected %u\n", checkCounter, initVal, numBits, actual, expected); 405 } 406 } 407 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 5: Short-circuited evaluation 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte false() { return 0; } 25 byte true() { return 1; } 26 byte must_not_be_called() 27 { 28 printf("ERROR: must_not_be_called() gets called\n"); 29 return 0; 30 } 31 int main() 32 { 33 if (false() && must_not_be_called()) 34 printf("ERROR: if with && succeeded\n"); 35 if (true() || must_not_be_called()) 36 ; 37 else 38 printf("ERROR: if with || failed\n"); 39 40 // Same with relation operators, to test optimization in BinaryOpExpr::emitConditionalJump(). 41 if (false() != 0 && must_not_be_called() != 0) 42 printf("ERROR: if with && succeeded\n"); 43 if (true() != 0 || must_not_be_called() != 0) 44 ; 45 else 46 printf("ERROR: if with || failed\n"); 47 48 // While case. 49 // 50 while (false() && must_not_be_called()) 51 printf("ERROR: while with && succeeded\n"); 52 byte b = 0; 53 while (true() || must_not_be_called()) 54 { 55 ++b; 56 break; 57 } 58 assert_eq(b, 1); // check that while body entered once 59 60 // Do while case. 61 b = 0; 62 do 63 ++b; 64 while (false() && must_not_be_called()); 65 assert_eq(b, 1); // check that do-while body entered once 66 67 b = 0; 68 do 69 if (++b == 5) 70 break; 71 while (true() || must_not_be_called()); 72 assert_eq(b, 5); // check that do-while body entered the correct number of times 73 74 75 // While case with rel ops. 76 // 77 while (false() != 0 && must_not_be_called() != 0) 78 printf("ERROR: while with && succeeded\n"); 79 b = 0; 80 while (true() != 0 || must_not_be_called() != 0) 81 { 82 ++b; 83 break; 84 } 85 assert_eq(b, 1); // check that while body entered once 86 87 // Do while case with rel ops. 88 b = 0; 89 do 90 ++b; 91 while (false() != 0 && must_not_be_called() != 0); 92 assert_eq(b, 1); // check that do-while body entered once 93 94 b = 0; 95 do 96 if (++b == 5) 97 break; 98 while (true() != 0 || must_not_be_called() != 0); 99 assert_eq(b, 5); // check that do-while body entered the correct number of times 100 101 return 0; 102 } 103 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 6: More short-circuited evaluation 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte f(byte c) 25 { 26 if (c != 32 && c != 40 && c != 80 && c != 100) 27 return 0; 28 return 1; 29 } 30 byte g(byte c) 31 { 32 if (c == 32 || c == 40 || c == 80 || c == 100) 33 return 1; 34 return 0; 35 } 36 int main() 37 { 38 assert_eq(f(32), 1); 39 assert_eq(f(40), 1); 40 assert_eq(f(80), 1); 41 assert_eq(f(0), 0); 42 assert_eq(f(132), 0); 43 assert_eq(f((byte) (32 + 256)), 1); 44 assert_eq(g(32), 1); 45 assert_eq(g(40), 1); 46 assert_eq(g(80), 1); 47 assert_eq(g(0), 0); 48 assert_eq(g(132), 0); 49 assert_eq(g((byte) (32 + 256)), 1); 50 return 0; 51 } 52 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 7: Returning byte from function of type word 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 word f() 25 { 26 asm("LDA", "#42"); // not supposed to affect return value 27 byte k = 1; 28 return k; // A must be cleared by this statement 29 } 30 word g() 31 { 32 asm("LDD", "#$ABCD"); // not supposed to affect return value 33 return 0x12; // A must be cleared by this statement 34 } 35 byte *getPtr() 36 { 37 asm("LDD", "#$4567"); // not supposed to affect return value 38 return 0; // A must be cleared by this statement 39 } 40 int fi() 41 { 42 char a = 255; 43 return a; 44 } 45 int main() 46 { 47 assert_eq(f(), 1); 48 assert_eq(g(), 0x12); 49 assert_eq(getPtr(), 0); 50 assert_eq(fi(), -1); 51 assert_eq((int) ((char) 255), -1); 52 char a = 255; 53 assert_eq((int) ((char) a), -1); 54 return 0; 55 } 56 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 8: Recursion 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 word fact(word n) 25 { 26 if (n <= 1) return 1; 27 return n * fact(n - 1); 28 } 29 int main() 30 { 31 assert_eq(fact(5), 120); 32 return 0; 33 } 34 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 9: More shifts 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 byte b0 = 3 << 3; 27 byte b1 = (3 << 3) + 2; 28 byte b2 = 3 << 3 + 2; 29 //printf("%u %u %u\n", b0, b1, b2); 30 assert_eq(b0, 24); 31 assert_eq(b1, 26); 32 assert_eq(b2, 96); 33 34 word w = 0x4321; 35 w <<= 8; 36 assert_eq(w, 0x2100); 37 w = 0x4321; 38 w <<= 5; 39 assert_eq(w, 0x6420); 40 41 return 0; 42 } 43 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 10: Integer (non-char) constants are words 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 word f(unsigned word n) { return n; } 25 int main() 26 { 27 assert_eq(f(600), 600); 28 assert_eq(f(60 * 10), 600); 29 byte a = 60, b = 10; 30 assert_eq(f(a * b), 88); // byte * byte done in byte, so bits lost 31 assert_eq(f((word) 60 * 10), 600); 32 assert_eq(f(60 * (word) 10), 600); 33 assert_eq(f((word) 60 * (word) 10), 600); 34 35 assert_eq(f(100 + 99), 199); 36 assert_eq(f(200 + 100), 300); 37 assert_eq(f(200 + (word) 100), 300); 38 return 0; 39 } 40 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 11: Taking address and dereferencing 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S { byte b; }; 25 void changeByte(unsigned char *pb) { *pb = 42; } 26 void changeWord(unsigned int *pw) { *pw = 1844; } 27 int main() 28 { 29 byte b = 0; 30 changeByte(&b); 31 word w = 0; 32 changeWord(&w); 33 struct S s; 34 s.b = 99; 35 assert_eq(s.b, 99); 36 struct S *ps = &s; 37 assert_eq(ps->b, 99); 38 byte *pb = &b; 39 byte **ppb = &pb; 40 word *pw = &w; 41 word **ppw = &pw; // address of T * is word * 42 //printf("%u %u %u %u\n", b, w, b + w, w + b); 43 assert_eq(b, 42); 44 assert_eq(w, 1844); 45 assert_eq(b + w, 1886); 46 assert_eq(w + b, 1886); 47 assert_eq(*pb, 42); 48 assert_eq(*pw, 1844); 49 assert_eq(**ppb, 42); 50 assert_eq(**ppw, 1844); 51 52 return 0; 53 } 54 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 12: strcmp(), memcmp(), strlen() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 assert_eq(strcmp("", ""), 0); 27 assert_eq(strcmp("", "x"), -1); 28 assert_eq(strcmp("x", ""), 1); 29 assert_eq(strcmp("x", "x"), 0); 30 assert_eq(strcmp("x", "xy"), -1); 31 assert_eq(strcmp("xy", "x"), 1); 32 assert_eq(strcmp("xy", "xyz"), -1); 33 assert_eq(strcmp("xyz", "xy"), 1); 34 assert_eq(strcmp("xyz", "xya"), 1); 35 assert_eq(strcmp("xyz", "xay"), 1); 36 assert_eq(strcmp("xyz", "axy"), 1); 37 assert_eq(strcmp("xya", "xyz"), -1); 38 assert_eq(strcmp("xay", "xyz"), -1); 39 assert_eq(strcmp("axy", "xyz"), -1); 40 41 assert_eq(memcmp(0, 0, 0), 0); 42 assert_eq(memcmp("aaa", "bbb", 3), -1); 43 assert_eq(memcmp("fgh", "feh", 3), 1); 44 assert_eq(memcmp("aca", "ada", 3), -1); 45 assert_eq(memcmp("ada", "ada", 3), 0); 46 47 assert_eq(strlen(""), 0); 48 assert_eq(strlen("foobar"), 6); 49 return 0; 50 } 51 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 13: byte *memcpy(byte *, byte *, word) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char globalBuffer[7]; 25 26 void check(char *buffer) 27 { 28 buffer[0] = 42; 29 memcpy(buffer, "____", 0); // must do nothing 30 assert_eq(buffer[0], 42); 31 32 void *out = memcpy(buffer, "foobar", 7); 33 assert_eq(out, buffer); 34 assert_eq(strcmp(buffer, "foobar"), 0); 35 } 36 37 int main() 38 { 39 char localBuffer[7]; 40 check(localBuffer); 41 check(globalBuffer); 42 check(localBuffer); 43 check(globalBuffer); 44 return 0; 45 } 46 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 14: byte *memset(byte *s, byte c, word n) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char globalBuffer[300]; 25 26 void check(char *buffer) 27 { 28 void *ret = memset(buffer, 42, 300); 29 assert_eq(ret, buffer); 30 for (int i = 0; i < 300; ++i) 31 assert_eq(buffer[i], 42); 32 } 33 34 int main() 35 { 36 char localBuffer[300]; 37 check(localBuffer); 38 check(globalBuffer); 39 check(localBuffer); 40 check(globalBuffer); 41 return 0; 42 } 43 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 15: strcpy(), strncpy(), strcat() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 #define BUFSIZ 11 25 char globalBuffer[BUFSIZ]; 26 27 void check(char *buffer) 28 { 29 assert(buffer); 30 31 buffer[0] = 42; 32 buffer[1] = 43; 33 char *out = strcpy(buffer, ""); // must copy NUL 34 assert_eq(out, buffer); 35 assert_eq(buffer[0], 0); // NUL terminator 36 assert_eq(buffer[1], 43); // unaffected by strcpy() call 37 38 char *out0 = strcpy(buffer, "foobar"); 39 assert_eq(out0, buffer); 40 char *out2 = strcat(buffer, ""); // must do nothing 41 assert_eq(out2, buffer); 42 char *out1 = strcat(buffer, "baz"); 43 assert_eq(out1, buffer); 44 assert_eq(strcmp(buffer, "foobarbaz"), 0); 45 46 buffer[0] = 0; 47 strcat(buffer, ""); 48 assert_eq(strlen(buffer), 0); 49 strcat(buffer, "quux"); 50 assert_eq(strlen(buffer), 4); 51 52 strncpy(buffer, "foo", BUFSIZ); 53 assert(!strcmp(buffer, "foo")); 54 for (char i = 3; i < BUFSIZ; ++i) 55 assert_eq(buffer[i], 0); 56 57 strncpy(buffer, "abcdefghij", BUFSIZ); 58 assert(!strcmp(buffer, "abcdefghij")); 59 60 strncpy(buffer, "Now is the time", 3); 61 assert_eq(buffer[0], 'N'); 62 assert_eq(buffer[1], 'o'); 63 assert_eq(buffer[2], 'w'); 64 65 strncpy(buffer, "ABCDEFGHIJKLMNOP", BUFSIZ); 66 assert_eq(buffer[BUFSIZ - 1], 'K'); 67 buffer[BUFSIZ - 1] = 0; 68 assert(!strcmp(buffer, "ABCDEFGHIJ")); 69 } 70 71 int main() 72 { 73 char localBuffer[BUFSIZ]; 74 check(localBuffer); 75 check(globalBuffer); 76 check(localBuffer); 77 check(globalBuffer); 78 return 0; 79 } 80 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 16: byte *strchr(byte *, byte) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 char *s0 = "foobar"; 27 char *foundAt = strchr(s0, 'b'); 28 assert_eq(foundAt, s0 + 3); 29 assert_eq(strchr(s0, 'f'), s0); 30 assert_eq(strchr(s0, 'o'), s0 + 1); 31 assert_eq(strchr(s0, '_'), 0); 32 assert_eq(strchr(s0, 0), s0 + 6); 33 char *empty = ""; 34 assert_eq(strchr(empty, 0), empty); 35 assert_eq(strchr(empty, '_'), 0); 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 17: char *strlwr(char *) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char globalBuffer[7]; 25 26 void check(char *buffer) 27 { 28 strcpy(buffer, ""); 29 strlwr(buffer); 30 assert_eq(strlen(buffer), 0); 31 32 strcpy(buffer, "FOOBAR"); 33 strlwr(buffer); 34 assert_eq(strlen(buffer), 6); 35 assert_eq(strcmp(buffer, "foobar"), 0); 36 37 strcpy(buffer, "foobar"); 38 strlwr(buffer); 39 assert_eq(strlen(buffer), 6); 40 assert_eq(strcmp(buffer, "foobar"), 0); 41 } 42 43 int main() 44 { 45 char localBuffer[7]; 46 check(localBuffer); 47 check(globalBuffer); 48 check(localBuffer); 49 check(globalBuffer); 50 return 0; 51 } 52 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 18: char *strupr(char *) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char globalBuffer[7]; 25 26 void check(char *buffer) 27 { 28 strcpy(buffer, ""); 29 strupr(buffer); 30 assert_eq(strlen(buffer), 0); 31 32 strcpy(buffer, "FOOBAR"); 33 strupr(buffer); 34 assert_eq(strlen(buffer), 6); 35 assert_eq(strcmp(buffer, "FOOBAR"), 0); 36 37 strcpy(buffer, "foobar"); 38 strupr(buffer); 39 assert_eq(strlen(buffer), 6); 40 assert_eq(strcmp(buffer, "FOOBAR"), 0); 41 } 42 43 int main() 44 { 45 char localBuffer[7]; 46 check(localBuffer); 47 check(globalBuffer); 48 return 0; 49 } 50 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 19: Conditional expression does not use the TST instruction 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 // The TST instruction does not affect the carry, so it is inappropriate 27 // for LBHI et al. 28 29 byte counter = 0; 30 word w = 1; 31 asm("orcc", "#1"); // force carry 32 while (w > 0) // this comparison assumed to reset carry, for LBHI 33 { 34 ++counter; 35 break; 36 } 37 assert_eq(counter, 1); 38 39 byte b = 1; 40 asm("orcc", "#1"); // force carry 41 while (b > 0) // this comparison assumed to reset carry, for LBHI 42 { 43 ++counter; 44 break; 45 } 46 assert_eq(counter, 2); 47 return 0; 48 } 49 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 20: Array name is address of 1st element 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 unsigned a[1]; 27 a[0] = '$'; 28 unsigned *p = a; 29 unsigned *q; 30 q = a; 31 assert_eq(p, a); 32 assert_eq(p, q); 33 34 char b[5]; 35 b[0] = 'a'; 36 * (unsigned *) (b + 1) = 0x6263; 37 b[3] = 'd'; 38 b[4] = 0; 39 assert_eq(strcmp(b, "abcd"), 0); 40 41 assert_eq((b - 1) + 1, b); 42 assert_eq((1 + b) - 1, b); 43 44 assert_eq(*b, 97); 45 46 assert_eq(a, &a[0]); 47 assert_eq(b, &b[0]); 48 49 // Address of T[] is of type T *. 50 unsigned *a1 = &a; 51 assert_eq(a1, a); 52 assert_eq(a1[0], a[0]); 53 char *b1 = &b; 54 assert_eq(b1, b); 55 assert_eq(b1[0], b[0]); 56 57 // Negate an array name. 58 char boolNegation = !b; 59 assert_eq(boolNegation, 0); 60 assert(!!b); 61 62 unsigned *nullPtr = 0; 63 boolNegation = !nullPtr; 64 assert_ne(boolNegation, 0); // not necessarily 1 65 return 0; 66 } 67 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 21: dwtoa(): double word to ASCII 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 char buffer[11]; 27 assert_eq(strcmp(dwtoa(buffer, 0, 0), "0"), 0); 28 assert_eq(strcmp(buffer, "0000000000"), 0); 29 assert_eq(strcmp(dwtoa(buffer, 0, 9), "9"), 0); 30 assert_eq(strcmp(buffer, "0000000009"), 0); 31 assert_eq(strcmp(dwtoa(buffer, 9, 0), "589824"), 0); 32 assert_eq(strcmp(dwtoa(buffer, 1, 1), "65537"), 0); 33 assert_eq(strcmp(buffer, "0000065537"), 0); 34 assert_eq(strcmp(dwtoa(buffer, 14882, 31661), "975338413"), 0); 35 assert_eq(strcmp(buffer, "0975338413"), 0); 36 37 assert_eq(strcmp(dwtoa(buffer, 55857, 33919), "3660678271"), 0); 38 assert_eq(strcmp(dwtoa(buffer, 4190, 26415), "274622255"), 0); 39 assert_eq(strcmp(dwtoa(buffer, 43262, 54960), "2835273392"), 0); 40 assert_eq(strcmp(dwtoa(buffer, 6658, 15199), "436353887"), 0); 41 assert_eq(strcmp(dwtoa(buffer, 20559, 4689), "1347359313"), 0); 42 assert_eq(strcmp(dwtoa(buffer, 5076, 54251), "332714987"), 0); 43 assert_eq(strcmp(dwtoa(buffer, 44962, 4995), "2946634627"), 0); 44 assert_eq(strcmp(dwtoa(buffer, 1896, 16326), "124272582"), 0); 45 assert_eq(strcmp(dwtoa(buffer, 18019, 7597), "1180900781"), 0); 46 assert_eq(strcmp(dwtoa(buffer, 49676, 49489), "3255615825"), 0); 47 assert_eq(strcmp(buffer, "3255615825"), 0); 48 return 0; 49 } 50 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 22: div328() (division of 32 bits by 8, unsigned) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 word counter = 0; 25 26 void check8(word hi, word lo, byte divisor, word expHi, word expLo) 27 { 28 ++counter; 29 30 word dividend[2] = { hi, lo }; // copy dividend here, which will be overwritten w/ quotient 31 32 divdwb(dividend, divisor); 33 34 word *actualQuotient = dividend; // new name, to clarify 35 if (actualQuotient[0] != expHi || actualQuotient[1] != expLo) 36 { 37 printf("ERROR: check8 #%2u: 0x%04x%04x / 0x%02x: got 0x%04x%04x, expected 0x%04x%04x\n", 38 counter, 39 hi, lo, divisor, 40 actualQuotient[0], actualQuotient[1], 41 expHi, expLo); 42 } 43 } 44 45 void check16(word hi, word lo, word divisor, word expHi, word expLo) 46 { 47 ++counter; 48 49 word dividend[2] = { hi, lo }; // copy dividend here, which will be overwritten w/ quotient 50 51 divdww(dividend, divisor); 52 53 word *actualQuotient = dividend; // new name, to clarify 54 if (actualQuotient[0] != expHi || actualQuotient[1] != expLo) 55 { 56 printf("ERROR: check16 #%2u: 0x%04x%04x / 0x%04x: got 0x%04x%04x, expected 0x%04x%04x\n", 57 counter, 58 hi, lo, divisor, 59 actualQuotient[0], actualQuotient[1], 60 expHi, expLo); 61 } 62 } 63 64 int main() 65 { 66 check8(0, 0, 1, 0, 0); 67 check8(0, 100, 1, 0, 100); 68 check8(0, 100, 10, 0, 10); 69 check8(0, 1000, 10, 0, 100); 70 check8(0, 10000, 10, 0, 1000); 71 check8(0x0001, 0x86a0, 10, 0, 10000); 72 check8(0xffff, 0xffff, 0xff, 0x0101, 0x0101); 73 check8(0x0001, 0x86a0, 0, 0x0001, 0x86a0); // nothing done on division by zero 74 75 check8(0x7079, 0x34e7, 0x01, 0x7079, 0x34e7); 76 check8(0x7079, 0x34e7, 0x02, 0x383c, 0x9a73); 77 check8(0x7079, 0x34e7, 0xd5, 0x0087, 0x2deb); 78 check8(0x5523, 0x0a32, 0x3f, 0x0159, 0xf3f8); 79 check8(0x1fb2, 0x380c, 0x5b, 0x0059, 0x2ad0); 80 check8(0x7436, 0x365b, 0x69, 0x011b, 0x55d9); 81 check8(0x353e, 0x1c6e, 0x09, 0x05ea, 0x74ef); 82 check8(0x0eed, 0x5e1c, 0x79, 0x001f, 0x94e0); 83 check8(0x1658, 0x508d, 0x36, 0x0069, 0xee87); 84 check8(0x1add, 0x1fbd, 0x99, 0x002c, 0xf2d2); 85 check8(0x7ab5, 0x31f8, 0x72, 0x0113, 0x8de9); 86 check8(0x2179, 0x7f99, 0x2e, 0x00ba, 0x4b1f); 87 check8(0x3c94, 0x103a, 0x4a, 0x00d1, 0x9184); 88 check8(0x34ad, 0x247d, 0x72, 0x0076, 0x4a6c); 89 check8(0x5cb2, 0x2e33, 0x07, 0x0d3e, 0x0699); 90 check8(0x4466, 0x176e, 0x94, 0x0076, 0x4fb9); 91 check8(0x4ef9, 0x7383, 0xe9, 0x0056, 0xc52a); 92 check8(0x4e52, 0x55e0, 0x11, 0x049b, 0x6e76); 93 check8(0x5a5e, 0x3dc7, 0x54, 0x0113, 0x685a); 94 check8(0x7b3f, 0x0ded, 0x18, 0x0522, 0xa094); 95 check8(0x6408, 0x6c79, 0x23, 0x02db, 0xab53); 96 check8(0x63ae, 0x2104, 0x09, 0x0b13, 0x5900); 97 check8(0x0a07, 0x1a4d, 0x6c, 0x0017, 0xc4fb); 98 check8(0x7ba4, 0x007f, 0xe3, 0x008b, 0x6fa6); 99 check8(0x697b, 0x3f16, 0x14, 0x0546, 0x298d); 100 check8(0x22f0, 0x3dfe, 0xc3, 0x002d, 0xde2f); 101 check8(0x1aa7, 0x6847, 0x2c, 0x009b, 0x13d3); 102 check8(0x5a24, 0x4b58, 0xa5, 0x008b, 0xdb38); 103 check8(0x081e, 0x7857, 0xc6, 0x000a, 0x7f50); 104 check8(0x23f5, 0x7f57, 0xc0, 0x002f, 0xf1ff); 105 check8(0x0d07, 0x71ce, 0xc8, 0x0010, 0xad5e); 106 check8(0x172e, 0x32d5, 0x4c, 0x004e, 0x14e1); 107 108 counter = 0; 109 110 check16(0, 0, 1, 0, 0); 111 check16(0, 100, 1, 0, 100); 112 check16(0, 100, 10, 0, 10); 113 check16(0, 1000, 10, 0, 100); 114 check16(0, 10000, 10, 0, 1000); 115 check16(0x0001, 0x86a0, 10, 0, 10000); 116 check16(0xffff, 0xffff, 0xff, 0x0101, 0x0101); 117 check16(0xffff, 0xffff, 0xffff, 0x0001, 0x0001); 118 check16(0x0001, 0x86a0, 0, 0x0001, 0x86a0); // nothing done on division by zero 119 120 check16(0xedc0, 0xbbaf, 0xe57d, 0x0001, 0x0938); 121 check16(0x41d5, 0x8708, 0x20e8, 0x0002, 0x002b); 122 check16(0x428b, 0xbbb5, 0x1d43, 0x0002, 0x462f); 123 check16(0xc5cd, 0x5506, 0x99e2, 0x0001, 0x4910); 124 check16(0xb738, 0x4cc9, 0x55e1, 0x0002, 0x222a); 125 check16(0xa676, 0x3203, 0x0d68, 0x000c, 0x6aae); 126 check16(0x0518, 0xa8ab, 0xdc57, 0x0000, 0x05eb); 127 check16(0x8ff2, 0xb487, 0x8e7c, 0x0001, 0x02a1); 128 check16(0xe671, 0x6eda, 0x4ba2, 0x0003, 0x0bff); 129 check16(0xe4c2, 0xe584, 0x0b65, 0x0014, 0x138f); 130 check16(0x080b, 0x33b8, 0x6cad, 0x0000, 0x12f2); 131 check16(0x398e, 0xb786, 0xe5e5, 0x0000, 0x4017); 132 check16(0xfb65, 0x6cc8, 0xcbc8, 0x0001, 0x3bd0); 133 check16(0x58c4, 0x3d29, 0x6d7b, 0x0000, 0xcf90); 134 check16(0xdc3b, 0x4e59, 0x2dbd, 0x0004, 0xd0a6); 135 check16(0x7e3e, 0x52ca, 0x8bb8, 0x0000, 0xe74f); 136 check16(0x7e00, 0x6e4a, 0x0db8, 0x0009, 0x2f44); 137 check16(0xfd3f, 0xaf80, 0x03a5, 0x0045, 0x7cc2); 138 check16(0x3a04, 0x4023, 0x003a, 0x0100, 0x12c2); 139 check16(0xc759, 0x914c, 0x00a1, 0x013c, 0xfa8a); 140 check16(0x6a48, 0xbe6b, 0x0d49, 0x0008, 0x000e); 141 check16(0xc094, 0x7890, 0x0f76, 0x000c, 0x74b6); 142 check16(0x6109, 0xd539, 0x0241, 0x002b, 0x0dae); 143 check16(0x97a4, 0xa6be, 0x088b, 0x0011, 0xc029); 144 check16(0x36b8, 0x620a, 0x0541, 0x000a, 0x6a47); 145 check16(0x0f5b, 0x5451, 0x01eb, 0x0008, 0x01bc); 146 check16(0x2104, 0xdcd5, 0x02cb, 0x000b, 0xd27a); 147 check16(0x9420, 0xd1ff, 0x0075, 0x0144, 0x1c0d); 148 check16(0x8ac2, 0xfe5b, 0x0bd0, 0x000b, 0xbf3c); 149 check16(0x5c53, 0x092f, 0x0307, 0x001e, 0x7f2f); 150 check16(0xc730, 0xf7c3, 0x040c, 0x0031, 0x3894); 151 check16(0xa027, 0x0fa8, 0x0df5, 0x000b, 0x7985); 152 153 return 0; 154 } 155 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 23: mulwb(): multiply word by byte, giving a 24-bit result 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 unsigned char hi; unsigned int lo; // declared in this order, so that hi is allocated before lo 27 28 lo = mulwb(&hi, 9 * 256, 68); 29 assert_eq(hi, 0x02); 30 assert_eq(lo, 0x6400); 31 32 char buffer[11]; 33 char *firstNonZeroChar = dwtoa(buffer, (word) hi, lo); 34 //printf("buffer=[%s], firstNonZeroChar=[%s]\n", buffer, firstNonZeroChar); 35 assert_eq(strcmp(firstNonZeroChar, "156672"), 0); 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 24: mulww(): multiply word by word, giving a 32-bit result 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 // u * v expected to give j:k. 25 void check(word u, word v, word j, word k) 26 { 27 word hi; word lo; // declared in this order, so that hi is allocated before lo 28 lo = mulww(&hi, u, v); 29 if (hi != j || lo != k) 30 printf("UNEXPECTED: 0x%04x * 0x%04x gives 0x%04x:0x%04x, expected 0x%04x:0x%04x\n", 31 u, v, hi, lo, j, k); 32 } 33 34 int main() 35 { 36 word hi; word lo; // declared in this order, so that hi is allocated before lo 37 38 lo = mulww(&hi, 10000, 20000); 39 //printf("0x%04x 0x%04x\n", hi, lo); 40 assert_eq(hi, 0x0BEB); 41 assert_eq(lo, 0xC200); 42 43 char buffer[11]; 44 char *p = dwtoa(buffer, hi, lo); 45 assert_eq(strcmp(p, "200000000"), 0); 46 47 check(0x0000, 0x0000, 0x0000, 0x0000); 48 check(0x0001, 0x0000, 0x0000, 0x0000); 49 check(0x0000, 0x0001, 0x0000, 0x0000); 50 check(0x0001, 0x0001, 0x0000, 0x0001); 51 check(0x0100, 0x0100, 0x0001, 0x0000); 52 check(0xffff, 0xffff, 0xfffe, 0x0001); 53 54 check(0xbf6f, 0x1428, 0x0f12, 0x9558); 55 check(0xbbf2, 0xacca, 0x7eda, 0xe4f4); 56 check(0x3459, 0x692c, 0x1581, 0x804c); 57 check(0x9cd9, 0x7b8e, 0x4bb3, 0x435e); 58 check(0xf349, 0x24b4, 0x22e1, 0x5354); 59 check(0xb951, 0x38f3, 0x2939, 0x9fe3); 60 check(0xd8ad, 0xc03b, 0xa2b3, 0xafdf); 61 check(0x2e50, 0x189b, 0x0473, 0x8a70); 62 check(0x1adf, 0x6818, 0x0aed, 0x1ce8); 63 check(0x1c1a, 0x3ee1, 0x06e6, 0xfeda); 64 check(0xf069, 0xea64, 0xdc1d, 0xe304); 65 check(0x1e40, 0xd984, 0x19b3, 0xd900); 66 check(0xd1e5, 0x5a57, 0x4a11, 0xd6d3); 67 check(0xde6a, 0xb155, 0x9a11, 0x2332); 68 check(0xba35, 0x8253, 0x5ecb, 0x492f); 69 check(0xa233, 0xf502, 0x9b3c, 0x1366); 70 check(0xe9b0, 0x0b9d, 0x0a99, 0xe0f0); 71 check(0x364d, 0x4495, 0x0e8c, 0x0ed1); 72 check(0xf4f0, 0x8a55, 0x845a, 0xb3b0); 73 check(0xdd9e, 0xb4c9, 0x9c81, 0x190e); 74 check(0xdb5f, 0x025a, 0x0203, 0xdd66); 75 check(0x6096, 0x7725, 0x2cf3, 0xafae); 76 check(0xa56d, 0xa715, 0x6bf7, 0xacf1); 77 check(0x2393, 0x928f, 0x145d, 0xb51d); 78 check(0x9438, 0x7894, 0x45cf, 0xf060); 79 check(0x6184, 0x0559, 0x0209, 0x7ae4); 80 check(0x4548, 0x6455, 0x1b27, 0x20e8); 81 check(0x9591, 0x5075, 0x2f01, 0xab45); 82 check(0xb226, 0xec08, 0xa440, 0x9930); 83 check(0x82ab, 0xb97c, 0x5eac, 0xddd4); 84 return 0; 85 } 86 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 25: zerodw, addddw, subdww, cmpdww 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 word dw[2]; 27 zerodw(dw); 28 //printf("0x%04x%04x\n", dw[0], dw[1]); 29 assert_eq(dw[0], 0); 30 assert_eq(dw[1], 0); 31 assert_eq(cmpdww(dw, 0), 0); 32 33 adddww(dw, 0); 34 //printf("0x%04x%04x\n", dw[0], dw[1]); 35 assert_eq(dw[0], 0); 36 assert_eq(dw[1], 0); 37 assert_eq(cmpdww(dw, 0), 0); 38 39 adddww(dw, 42); 40 //printf("0x%04x%04x\n", dw[0], dw[1]); 41 assert_eq(dw[0], 0); 42 assert_eq(dw[1], 42); 43 assert_eq(cmpdww(dw, 42), 0); 44 45 adddww(dw, 0xFFFF); 46 //printf("0x%04x%04x\n", dw[0], dw[1]); 47 assert_eq(dw[0], 1); 48 assert_eq(dw[1], 41); 49 assert_eq(cmpdww(dw, 1000), 1); 50 51 subdww(dw, 0xFFFF); 52 assert_eq(dw[0], 0); 53 assert_eq(dw[1], 42); 54 assert_eq(cmpdww(dw, 42), 0); 55 assert_eq(cmpdww(dw, 0), 1); 56 assert_eq(cmpdww(dw, 10), 1); 57 assert_eq(cmpdww(dw, 100), -1); 58 assert_eq(cmpdww(dw, 0xFFFF), -1); 59 60 subdww(dw, 42); 61 assert_eq(dw[0], 0); 62 assert_eq(dw[1], 0); 63 assert_eq(cmpdww(dw, 0), 0); 64 65 subdww(dw, 0); 66 assert_eq(dw[0], 0); 67 assert_eq(dw[1], 0); 68 assert_eq(cmpdww(dw, 0), 0); 69 70 return 0; 71 } 72 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 26: Optimization of adds and subs of constants 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 word w; 27 byte b; 28 w = 1000 + 2000; 29 assert(w == 3000); 30 w = 9000 - 3000; 31 assert(w == 6000); 32 w = 4 - 20; 33 assert(w == 0xfff0); 34 w = 65535 + 11; 35 assert(w == 10); 36 b = 10 + 20; 37 assert(b == 30); 38 b = 230 - 25; 39 assert(b == 205); 40 b = 5 - 20; 41 assert(b == 241); 42 b = (byte) (255 + 11); 43 assert(b == 10); 44 45 // Signed cases. 46 int i; 47 i = 4 - 20; 48 assert_eq(i, -16); 49 50 return 0; 51 } 52 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 27: printf's number and string field padding 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void asm hook() 25 { 26 asm { 27 sta $ff00 // assumes USim 28 lda #'?' // trash A to test printf() (re: zero-padding) 29 } 30 } 31 int main() 32 { 33 sbyte m1 = -1; 34 printf("[%2d]\n", m1); 35 printf("[%5d]\n", m1); 36 37 printf("[%1x]\n", 10); 38 printf("[%2x]\n", 10); 39 printf("[%5x]\n", 10); 40 printf("[%12x]\n", 10); 41 42 printf("[%1x]\n", 0xFED); 43 printf("[%2x]\n", 0xFED); 44 printf("[%5x]\n", 0xFED); 45 printf("[%12x]\n", 0xFED); 46 47 printf("[%1x]\n", 0xABCD); 48 printf("[%2x]\n", 0xABCD); 49 printf("[%5x]\n", 0xABCD); 50 printf("[%12x]\n", 0xABCD); 51 52 char *eightChars = "abcdefgh"; 53 printf("[%-8s]\n", eightChars); 54 55 printf("%s", ""); 56 byte a[2]; 57 a[0] = 'A'; a[1] = 0; 58 byte b[2]; 59 b[0] = 'B'; b[1] = 0; 60 printf("%s %s\n", a, b); 61 printf("[%12s]\n", "foo"); 62 printf("[%-12s]\n", "foo"); 63 printf("[%s]\n", "foo"); 64 printf("%03u %3u\n", 5, 6); 65 word w = 65535; 66 printf("%d\n", (sword) w); 67 68 // With redirected character output. 69 void *oldCHROOT = setConsoleOutHook(hook); 70 printf("0x%04X,%06u\n", 1, 2); 71 setConsoleOutHook(oldCHROOT); 72 73 return 0; 74 } 75 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: [-1] [ -1] [A] [ A] [ A] [ A] [FED] [FED] [ FED] [ FED] [ABCD] [ABCD] [ ABCD] [ ABCD] [abcdefgh] A B [ foo] [foo ] [foo] 005 6 -1 0x0001,000002 --- Actual output: [-1] [ -1] [A] [ A] [ A] [ A] [FED] [FED] [ FED] [ FED] [ABCD] [ABCD] [ ABCD] [ ABCD] [abcdefgh] A B [ foo] [foo ] [foo] 005 6 -1 0x0001,000002 -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 28: printf %x, %X and %p (hex digits always in upper-case) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 printf("%x\n", 65535); 27 printf("%X\n", 65535); 28 printf("%6X\n", 65535); 29 printf("%06X\n", 65535); 30 printf("%p\n", 65535); 31 printf("%p\n", 0xfff); 32 printf("%p\n", 0xff); 33 printf("%p\n", 0xf); 34 printf("%p\n", 0x0); 35 return 0; 36 } 37 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: FFFF FFFF FFFF 00FFFF $FFFF $0FFF $00FF $000F $0000 --- Actual output: FFFF FFFF FFFF 00FFFF $FFFF $0FFF $00FF $000F $0000 -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 29: toupper(), tolower() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 int c = toupper('a'); 27 assert_eq(c, 'A'); 28 c = toupper('z'); 29 assert_eq(c, 'Z'); 30 c = toupper('J'); 31 assert_eq(c, 'J'); 32 c = toupper('*'); 33 assert_eq(c, '*'); 34 35 c = tolower('A'); 36 assert_eq(c, 'a'); 37 c = tolower('Z'); 38 assert_eq(c, 'z'); 39 c = tolower('j'); 40 assert_eq(c, 'j'); 41 c = tolower('*'); 42 assert_eq(c, '*'); 43 return 0; 44 } 45 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 30: struct 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S 25 { 26 byte a; 27 word b; 28 byte *c; 29 word *d; 30 }; 31 struct Outer 32 { 33 word stuff; 34 struct S first; 35 struct S second; 36 }; 37 struct F 38 { 39 word w; 40 byte sec[16]; 41 }; 42 word diff(byte *after, byte *before) 43 { 44 return after - before; 45 } 46 #define sizeofVar(varName) (diff((byte *) (&(varName) + 1), (byte *) &(varName))) 47 48 void checkPtr(struct F *f) 49 { 50 //printf("f->w=0x%x, f->sec=0x%x, f=0x%x\n", (word) &f->w, (word) f->sec, (word) f); 51 //printf("%u\n", (word) f->sec - (word) f); 52 assert_eq((word) f->sec - (word) f, 2); 53 } 54 void check(struct S *p) 55 { 56 //printf("%u %u %u %u\n", p->a, p->b, *p->c, *p->d); 57 assert_eq(p->a, 43); 58 assert_eq(p->b, 1843); 59 assert_eq(*p->c, 43); 60 assert_eq(*p->d, 1843); 61 } 62 63 int main() 64 { 65 assert_eq(diff((byte *) 100, (byte *) 75), 25); 66 67 struct S s; 68 assert_eq(sizeofVar(s), 1 + 2 + 2 + 2); 69 70 s.a = 42; 71 s.b = 1844; 72 s.c = &s.a; 73 s.d = &s.b; 74 //printf("%u %u %u %u\n", s.a, s.b, *s.c, *s.d); 75 assert_eq(s.a, 42); 76 assert_eq(s.b, 1844); 77 assert_eq(*s.c, 42); 78 assert_eq(*s.d, 1844); 79 80 ++s.a; 81 --s.b; 82 //printf("%u %u %u %u\n", s.a, s.b, *s.c, *s.d); 83 assert_eq(s.a, 43); 84 assert_eq(s.b, 1843); 85 assert_eq(*s.c, 43); 86 assert_eq(*s.d, 1843); 87 88 //printf("%u\n", s.a + s.b); 89 assert_eq(s.a + s.b, 1886); 90 91 check(&s); 92 93 struct S *p = &s; 94 p->a++; 95 //printf("%u ", p->a); 96 assert_eq(p->a, 44); 97 ++p->a; 98 //printf("%u ", p->a); 99 assert_eq(p->a, 45); 100 p->b++; 101 //printf("%u ", p->b); 102 assert_eq(p->b, 1844); 103 ++p->b; 104 //printf("%u\n", p->b); 105 assert_eq(p->b, 1845); 106 107 struct F f; 108 assert_eq(sizeofVar(f), 2 + 16); 109 //printf("%u\n", (word) f.sec - (word) &f); 110 assert_eq((word) f.sec - (word) &f, 2); 111 checkPtr(&f); 112 113 struct Outer outer; 114 assert_eq(sizeofVar(outer), 2 + 7 + 7); 115 outer.first.b = 11; 116 outer.second.b = 22; 117 //printf("%u\n", outer.first.b + outer.second.b); 118 assert_eq(outer.first.b + outer.second.b, 33); 119 120 struct Outer *pOuter = &outer; 121 pOuter->first.b = 33; 122 pOuter->second.b = 44; 123 //printf("%u\n", pOuter->first.b + pOuter->second.b); 124 assert_eq(pOuter->first.b + pOuter->second.b, 77); 125 126 struct S *pFirst = &outer.first; 127 struct S *pSecond = &outer.second; 128 pFirst->b = 55; 129 pSecond->b = 66; 130 //printf("%u\n", pFirst->b + pSecond->b); 131 assert_eq(pFirst->b + pSecond->b, 55 + 66); 132 133 pFirst = &pOuter->first; 134 pSecond = &pOuter->second; 135 pFirst->b = 77; 136 pSecond->b = 88; 137 //printf("%u\n", pFirst->b + pSecond->b); 138 assert_eq(pFirst->b + pSecond->b, 77 + 88); 139 return 0; 140 } 141 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 31: struct with multi-member declaration 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S 25 { 26 char a, b; 27 int c, d; 28 char *e, f; // e is a pointer but f is a char 29 signed int g[2], h[3]; // two keyword to represent base type 30 unsigned i; 31 }; 32 int main() 33 { 34 struct S s; 35 assert_eq(sizeof(struct S), 1+1+2+2+2+1+2*2+2*3+2); 36 assert_eq(sizeof(s.f), 1); 37 assert_eq(sizeof(s.g), 4); // size of struct member of array type 38 assert_eq(sizeof(s.h), 6); 39 assert(&s.a < &s.b); // order in multi-member declaration is respected 40 assert(&s.b < &s.c); // order of declarations is respected 41 assert(&s.c < &s.d); 42 assert(&s.e < &s.f); 43 assert(&s.h < &s.i); 44 45 s.a = 'A'; 46 s.b = 'B'; 47 s.c = 1844; 48 s.d = -4418; 49 s.e = "foo"; 50 s.f = 'F'; 51 s.g[1] = 1111; 52 s.h[2] = -2222; 53 s.i = 3333; 54 55 assert_eq(s.a, 'A'); 56 assert_eq(s.b, 'B'); 57 assert_eq(s.c, 1844); 58 assert_eq(s.d, -4418); 59 assert_eq(s.c + s.d, 1844 - 4418); 60 assert_eq(strcmp(s.e, "foo"), 0); 61 assert_eq(s.f, 'F'); 62 assert_eq(s.g[1], 1111); 63 assert_eq(s.h[2], -2222); 64 assert_eq(s.i, 3333); 65 66 return 0; 67 } 68 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 32: Struct definition local to a function 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 struct S 27 { 28 int n; 29 char a[3]; 30 }; 31 struct S s; 32 s.n = 42; 33 s.a[0] = 'x'; 34 s.a[1] = 'y'; 35 s.a[2] = 0; 36 assert_eq(s.n, 42); 37 assert(!strcmp(s.a, "xy")); 38 return s.n; 39 } 40 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 33: Reference to array member of a struct 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct FileDesc 25 { 26 byte a; 27 byte curSector[256]; 28 byte b; 29 }; 30 struct FileDescW 31 { 32 word a; 33 word curSector[256]; 34 word b; 35 }; 36 int main() 37 { 38 struct FileDesc fd; 39 fd.b = 42; 40 assert_eq(fd.b, 42); 41 fd.curSector[17] = 217; 42 assert_eq(fd.curSector[17], 217); 43 assert_eq(&fd, &fd.a); 44 assert_eq((byte *) &fd + 1, fd.curSector); 45 assert_eq((byte *) &fd + 1 + 17, &fd.curSector[17]); 46 assert_eq((byte *) &fd + 257, &fd.b); 47 48 struct FileDescW fdw; 49 fdw.b = 9999; 50 assert_eq(fdw.b, 9999); 51 fdw.curSector[17] = 1844; 52 assert_eq(fdw.curSector[17], 1844); 53 assert_eq(&fdw, &fdw.a); 54 assert_eq((byte *) &fdw + 2, fdw.curSector); 55 assert_eq((byte *) &fdw + 2 + 17*2, &fdw.curSector[17]); 56 assert_eq((byte *) &fdw + 257*2, &fdw.b); 57 return 0; 58 } 59 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 34: Taking address of a function and calling it indirectly 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 // The name of a function, not followed by arguments, yields its address. 25 // Using & in front of the name is also supported. 26 // Calling through a pointer can be done as pf(...) or (*pf)(...). 27 28 struct Class 29 { 30 int dummy; 31 void *method; // CMOC requires void pointer to represent function pointer 32 }; 33 word add(word n) 34 { 35 return 0x4000 + n; 36 } 37 void delegate(void *funcPtr) 38 { 39 assert_eq((*funcPtr)(0x0987), 0x4987); 40 } 41 int main() 42 { 43 add; // function name by itself is OK; no need to assign it for stmt to be legal, although useless 44 45 void *pf = add; // CMOC requires void pointer to represent function pointer 46 assert(pf); 47 48 assert_eq(pf(16), 16400); 49 50 asm("ldd", "#0"); // to check that D gets loaded correctly 51 asm("ldx", "#0"); // same for X if needed 52 pf = add; 53 if (pf != add) 54 { 55 printf("ERROR: pf contains %p instead of address of add() function\n", pf); 56 return 1; 57 } 58 59 assert_eq(pf(116), 16500); 60 61 assert_eq(sizeof((*pf)()), 2); // return type of call through ptr is assumed to be int 62 assert_eq(sizeof(pf()), 2); // same assert with different notation 63 64 struct Class cl; 65 asm("ldd", "#0"); // to check that D gets loaded correctly 66 asm("ldx", "#0"); // same for X if needed 67 cl.method = add; 68 assert(cl.method); 69 if (cl.method != add) 70 { 71 printf("ERROR: cl.method contains %p instead of address of add() function\n", pf); 72 return 1; 73 } 74 word t = (word) cl.method(216); // always cast return value: compiler does not know return type 75 assert_eq(t, 16600); 76 77 pf = &add; // ampersand allowed but does not change meaning 78 assert_eq(pf(17), 16401); 79 assert_eq((*pf)(18), 16402); // cf FunctionCallExpr::check(), FunctionCallExpr::emitCode() 80 81 delegate(add); // pass add() address to a function that will call it 82 delegate(t ? add : add); 83 while (add) 84 break; 85 do { break; } while (add); 86 for ( ; add ; ) 87 break; 88 if (add) 89 ; 90 91 void *pfAmp = &add; 92 assert(pfAmp); 93 assert_eq(pfAmp(17), 16401); 94 95 return 0; 96 } 97 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 35: Assignment of word to byte variable, and of byte to word variable 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 word aw[2] = { 0xabcd, 0x1234 }; 25 int main() 26 { 27 byte b = 42; 28 29 b = aw[1]; // warning 30 assert_eq(b, 0x34); 31 32 word w = 0xeedd; 33 b = w; // warning 34 assert_eq(b, 0xDD); 35 36 w = b; 37 assert_eq(w, 0xDD); 38 39 byte o = '\0377'; 40 byte h = '\xff'; 41 assert_eq(o, 255); 42 assert_eq(h, 255); 43 o = 0; 44 h = 0; 45 o = '\0377'; 46 h = '\xff'; 47 assert_eq(o, 255); 48 assert_eq(h, 255); 49 50 b = 0xFEDC; // warning 51 assert_eq(b, 0xDC); 52 return 0; 53 } 54 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code ,check-prog.c:29: __warning__: assigning to `unsigned char' from larger type `unsigned int' ,check-prog.c:33: __warning__: assigning to `unsigned char' from larger type `unsigned int' ,check-prog.c:50: __warning__: assigning to `unsigned char' from larger constant of type `unsigned int' Assembly language filename: ,check-prog.s 0 error(s), 3 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 36: Assignment used as sub-expression 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte gb = 0; 25 word gw = 0; 26 byte fb(byte k) { gb = k; return gb; } 27 word fw(word k) { gw = k; return gw; } 28 byte *f() { return &gb; } 29 byte *g() { return &gb; } 30 byte h() { return 88; } 31 int main() 32 { 33 byte b; 34 byte c; 35 (b = 0) = (c = 7); 36 assert(b == 7); 37 assert(c == 7); 38 (b = 7) = (c = 0); 39 assert(b == 0); 40 assert(c == 0); 41 42 word w; 43 word z; 44 (w = 0) = (z = 7); 45 assert(w == 7); 46 assert(z == 7); 47 (w = 7) = (z = 0); 48 assert(w == 0); 49 assert(z == 0); 50 51 b = 100; 52 c = 200; 53 (b += 0) = (c += 7); 54 assert(b == 207); 55 assert(c == 207); 56 c = 150; 57 (b += 7) = (c += 0); 58 assert(b == 150); 59 assert(c == 150); 60 61 b = 0; 62 gb = 0; 63 (b = fb(33)) = 12; 64 assert(b == 12); 65 assert(gb == 33); 66 67 w = 0; 68 gw = 0; 69 (w = fw(3333)) = 1212; 70 assert(w == 1212); 71 assert(gw == 3333); 72 73 b = 0; 74 c = 0; 75 gb = 0; 76 c = (b = fb(44)); 77 assert(b == 44); 78 assert(c == 44); 79 assert(gb == 44); 80 81 c = b = fb(55); 82 assert(b == 55); 83 assert(c == 55); 84 assert(gb == 55); 85 86 // Test that second assignment is done before first one: 87 gb = 222; 88 *f() = *g() = h(); // this must print "hgf", reflecting right-to-left execution 89 assert(gb == 88); 90 return 0; 91 } 92 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 37: while() and do/while() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 byte n = 0; 27 do 28 ++n; 29 while (n < 5); 30 assert_eq(n, 5); 31 n = 0; 32 while (n < 5) 33 ++n; 34 assert_eq(n, 5); 35 36 n = 0; 37 do 38 { 39 ++n; 40 } while (n < 5); 41 assert_eq(n, 5); 42 n = 0; 43 while (n < 5) 44 { 45 ++n; 46 } 47 assert_eq(n, 5); 48 assert(1 == 1); 49 50 // Test always-false condition. 51 n = 5; 52 while (0) 53 n = 8; 54 assert_eq(n, 5); 55 do 56 n = 9; 57 while (0); 58 assert_eq(n, 9); 59 60 // Test always-true condition. 61 byte counter = 0; 62 while (1) 63 if (++counter == 10) 64 break; 65 assert_eq(counter, 10); 66 67 do 68 if (--counter == 3) 69 break; 70 while (1); 71 assert_eq(counter, 3); 72 return 0; 73 } 74 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 38: For loop 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void infiniteLoop() 25 { 26 for (;;) 27 ; 28 for (;1;) 29 ; 30 } 31 int main() 32 { 33 word n = 1; 34 for (byte i = 5; i--; ) 35 n *= 2; 36 assert_eq(n, 32); 37 38 n = 1; 39 for (word j = 5; j--; ) 40 n *= 2; 41 assert_eq(n, 32); 42 43 n = 1; 44 word j = 5; 45 for ( ; j--; ) 46 n *= 2; 47 assert_eq(n, 32); 48 49 n = 1; 50 j = 5; 51 for ( ; ; j--) 52 { 53 if (j == 0) 54 break; 55 n *= 2; 56 } 57 assert_eq(n, 32); 58 59 // Control variable wraps around. 60 n = 0; 61 for (byte x = 0; x < 256; ++x) 62 { 63 ++n; 64 if (n == 270) 65 break; 66 } 67 assert_eq(n, 270); 68 return 0; 69 } 70 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 39: Octal and hex codes in a string or integer literal 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void checkStr(char *str, char expectedValueFirstChar) 25 { 26 char actualFirstChar = str[0]; 27 if (actualFirstChar != expectedValueFirstChar) 28 { 29 printf("ERROR: checkStr(): expected char %u, got char %u\n", 30 (byte) expectedValueFirstChar, (byte) actualFirstChar); 31 } 32 if (str[1]) 33 { 34 printf("ERROR: checkStr(): expected single char string (char %u), got more: %u and %u\n", 35 (byte) expectedValueFirstChar, (byte) str[0], (byte) str[1]); 36 } 37 } 38 void checkChar(char actualFirstChar, char expectedValueFirstChar) 39 { 40 if (actualFirstChar != expectedValueFirstChar) 41 { 42 printf("ERROR: checkChar(): expected char %u, got char %u\n", 43 (byte) expectedValueFirstChar, (byte) actualFirstChar); 44 } 45 } 46 int main() 47 { 48 assert_eq(052, 42); 49 assert_eq(0377, 255); 50 assert_eq(03464, 1844); 51 assert_eq(0177777, 0xFFFF); 52 53 assert(!strcmp("\0101", "A")); 54 assert(!strcmp("\x42", "B")); 55 assert(!strcmp("\0101\x42\01018\x42z\n", "ABA8Bz\x0A")); 56 checkStr("\a", 7); 57 checkStr("\b", 8); 58 checkStr("\t", 9); 59 checkStr("\n", 10); 60 checkStr("\v", 11); 61 checkStr("\f", 12); 62 checkStr("\r", 13); 63 checkStr("\'", 39); 64 checkStr("\"", 34); 65 checkStr("\\", 92); // 4 backslashes because of Perl interpretation 66 checkStr("\x43", 64 + 3); 67 checkStr("\0", 0); 68 checkStr("\0377", (char) (3 * 8 * 8 + 7 * 8 + 7)); 69 checkChar('\a', 7); 70 checkChar('\b', 8); 71 checkChar('\t', 9); 72 checkChar('\n', 10); 73 checkChar('\v', 11); 74 checkChar('\f', 12); 75 checkChar('\r', 13); 76 checkChar('\'', 39); 77 checkChar('\"', 34); 78 checkChar('\\', 92); // 4 backslashes because of Perl interpretation 79 checkChar('\x43', 64 + 3); 80 checkChar('\0', 0); 81 checkChar('\0377', (char) (3 * 8 * 8 + 7 * 8 + 7)); 82 checkChar('\377', (char) (3 * 8 * 8 + 7 * 8 + 7)); 83 checkChar('\1', 1); 84 checkChar('\12', 10); 85 checkChar('\123', 64 + 16 + 3); 86 char *s = "a\\b"; // 4 backslashes because of Perl interpretation 87 assert(strlen(s) == 3); 88 assert(s[0] == 97); 89 assert(s[1] == 92); 90 assert(s[2] == 98); 91 92 // Check for an a09 bug where a 0x in a string literal gets replaced with $. 93 char *h = "0xEF"; 94 assert_eq(strlen(h), 4); 95 assert_eq(h[0], '0'); 96 assert_eq(h[1], 'x'); 97 assert_eq(h[2], 'E'); 98 assert_eq(h[3], 'F'); 99 char *H = "0XEF"; 100 assert_eq(strlen(H), 4); 101 assert_eq(H[0], '0'); 102 assert_eq(H[1], 'X'); 103 assert_eq(H[2], 'E'); 104 assert_eq(H[3], 'F'); 105 return 0; 106 } 107 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 40: Bitwise operators 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 { 27 byte n = 0x43; 28 byte m = 0xC9; 29 assert_eq(n | m, 0xCB); 30 assert_eq(n ^ m, 0x8A); 31 assert_eq(n & m, 0x41); 32 assert_eq(n & 3, 0x03); 33 } 34 { 35 word n = 0x4343; 36 word m = 0xC9C9; 37 assert_eq(n | m, 0xCBCB); 38 assert_eq(n ^ m, 0x8A8A); 39 assert_eq(n & m, 0x4141); 40 assert_eq(m & 0x0F71, 0x0941); 41 word k = 0xABCD; 42 assert_eq(((byte) k) & 0xF0, 0xC0); 43 } 44 return 0; 45 } 46 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 41: Array initializers 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 unsigned char b[4] = { 0x80, 0x40, 0x20, 0x10, }; // trailing comma accepted 25 word w[4] = { 0xaa80, 0xbb40, 0xcc20, 0xdd10 }; 26 word s[2] = { (word) "foo", (word) "bar" }; 27 char c[3] = { 'b', 'a', 'z' }; 28 char cc[] = { 'B', 'A', 'Z' }; // size of array taken from size of init list 29 char d[7]; 30 char e[4] = "baz"; 31 char buffer[] = "HELLO"; 32 int sc[] = { (char) 255 }; 33 34 void local() 35 { 36 unsigned char b_[4] = { 0x80, 0x40, 0x20, 0x10 }; 37 word w_[4] = { 0xaa80, 0xbb40, 0xcc20, 0xdd10 }; 38 word s_[2] = { (word) "foo", (word) "bar" }; 39 char c_[3] = { 'b', 'a', 'z' }; 40 char cc_[] = { 'B', 'A', 'Z' }; 41 char e_[4] = "BAZ"; 42 assert_eq(b_[0], 0x80); 43 assert_eq(b_[1], 0x40); 44 assert_eq(b_[2], 0x20); 45 assert_eq(b_[3], 0x10); 46 assert_eq(w_[0], 0xAA80); 47 assert_eq(w_[1], 0xBB40); 48 assert_eq(w_[2], 0xCC20); 49 assert_eq(w_[3], 0xDD10); 50 assert(!strcmp((char *) s_[0], "foo")); 51 assert(!strcmp((char *) s_[1], "bar")); 52 assert_eq(c_[0], 'b'); 53 assert_eq(c_[1], 'a'); 54 assert_eq(c_[2], 'z'); 55 assert_eq(cc_[0], 'B'); 56 assert_eq(cc_[1], 'A'); 57 assert_eq(cc_[2], 'Z'); 58 assert_eq(strcmp(e_, "BAZ"), 0); 59 assert_eq(e_[2], 'Z'); 60 assert_eq(e_[3], 0); 61 62 char buffer_[] = "PIZZA"; 63 assert_eq(strcmp(buffer_, "PIZZA"), 0); 64 65 int sc_[] = { (char) 255 }; 66 assert_eq(sc_[0], -1); 67 } 68 int main() 69 { 70 assert_eq(b[0], 0x80); 71 assert_eq(b[1], 0x40); 72 assert_eq(b[2], 0x20); 73 assert_eq(b[3], 0x10); 74 assert_eq(w[0], 0xAA80); 75 assert_eq(w[1], 0xBB40); 76 assert_eq(w[2], 0xCC20); 77 assert_eq(w[3], 0xDD10); 78 assert(!strcmp((char *) s[0], "foo")); 79 assert(!strcmp((char *) s[1], "bar")); 80 assert_eq(c[0], 'b'); 81 assert_eq(c[1], 'a'); 82 assert_eq(c[2], 'z'); 83 assert_eq(cc[0], 'B'); 84 assert_eq(cc[1], 'A'); 85 assert_eq(cc[2], 'Z'); 86 d[0] = 42; 87 d[6] = 71; 88 assert_eq(d[0], 42); 89 assert_eq(d[6], 71); 90 assert_eq(strcmp(e, "baz"), 0); 91 assert_eq(e[2], 'z'); 92 assert_eq(e[3], 0); 93 94 char buffer[] = "HELLO"; 95 assert_eq(strcmp(buffer, "HELLO"), 0); 96 97 assert_eq(sc[0], -1); 98 99 local(); 100 return 0; 101 } 102 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 42: Array arithmetic 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte byteArray[5]; 25 word wordArray[5]; 26 struct S { byte foo[40]; word bar; }; 27 struct S s; 28 struct S sArray[5]; 29 int main() 30 { 31 byte *pb = byteArray + 3; 32 word byteArrayDiff = pb - byteArray; 33 assert_eq(byteArrayDiff, 3); 34 35 word *pw = wordArray + 3; 36 word wordArrayDiff = pw - wordArray; 37 assert_eq(wordArrayDiff, 3); 38 byte *pwb = (byte *) pw; 39 byte *wab = (byte *) wordArray; 40 assert_eq(pwb - wab, 6); 41 42 s.bar = 42; 43 assert(s.bar == 42); 44 45 struct S *ps = sArray + 3; 46 assert((word) ps - (word) sArray == 3 * 42); 47 word sArrayDiff = ps - sArray; 48 //printf("sArrayDiff=%u\n", sArrayDiff); 49 assert_eq(sArrayDiff, 3); 50 byte *psb = (byte *) ps; 51 byte *sab = (byte *) sArray; 52 //printf("byte diff: %u\n", psb - sab); 53 assert_eq(psb - sab, 3 * 42); 54 55 ps = &s + 1; 56 //printf("%u, %u\n", &s, ps); 57 assert_eq((word) ps - (word) &s, 42); 58 ps = &s + 3; 59 assert_eq((word) ps - (word) &s, 3 * 42); 60 61 struct S *ps2 = &sArray[2]; 62 struct S *ps4 = &sArray[4]; 63 word byteDiff = (byte *) ps4 - (byte *) ps2; 64 assert_eq(byteDiff, 2 * 42); 65 66 word *bar2 = &ps2->bar; 67 word *bar4 = &ps4->bar; 68 byteDiff = (byte *) bar4 - (byte *) bar2; 69 assert_eq(byteDiff, 2 * 42); 70 71 *byteArray = 254; 72 assert_eq(byteArray[0], 254); 73 *wordArray = 0x4141; 74 assert_eq(wordArray[0], 0x4141); 75 76 // Check cases for which there are specialized optimizations. 77 78 word wa[3] = { 0x1122, 0x3344, 0x4455 }; 79 assert_eq(wa[2], 0x4455); // and not 0x3344 80 word wi = 2; 81 assert_eq(wa[wi], 0x4455); 82 byte bi = 2; 83 assert_eq(wa[bi], 0x4455); 84 85 word *wp = &wa[2]; 86 assert_eq(wp[-1], 0x3344); 87 signed int swi = -1; 88 assert_eq(wp[swi], 0x3344); 89 signed char sci = -2; 90 assert_eq(wp[sci], 0x1122); 91 92 return 0; 93 } 94 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 43: Bitwise NOT operator 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 byte b = 0x55; 27 word w = 0xaaaa; 28 assert_eq(~b, 0xAA); 29 assert_eq(~w, 0x5555); 30 return 0; 31 } 32 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 44: Additive assignment, etc 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 // +=, -= 27 28 byte *p = 0; 29 byte inc = 4; 30 byte dummy = 0x55; // this byte allocated after 'inc' 31 p += inc; 32 assert_eq(p, 4); 33 p -= inc; 34 assert_eq(p, 0); 35 36 byte b = 0; 37 word w = 0xabcd; 38 b += (byte) w; 39 assert_eq(b, 0xCD); 40 41 // Signed cases. 42 char c = 100; 43 c += 1; 44 assert_eq(c, 101); 45 c += -1; 46 assert_eq(c, 100); 47 c -= 1; 48 assert_eq(c, 99); 49 c -= -1; 50 assert_eq(c, 100); 51 52 int i = 1000; 53 i += 1; 54 assert_eq(i, 1001); 55 i += -1; 56 assert_eq(i, 1000); 57 i -= 1; 58 assert_eq(i, 999); 59 i -= -1; 60 assert_eq(i, 1000); 61 i += 100; 62 assert_eq(i, 1100); 63 i += -100; 64 assert_eq(i, 1000); 65 i -= 100; 66 assert_eq(i, 900); 67 i -= -100; 68 assert_eq(i, 1000); 69 70 // *= 71 72 word k = 0x3000; 73 k *= inc; 74 assert_eq(k, 0xC000); 75 76 byte m = 0x05; 77 word n = 0x1111; 78 m *= (byte) n; 79 assert_eq(m, 0x55); 80 81 // /= 82 83 assert_eq(inc, 4); 84 word z = 0x444; 85 z /= inc; 86 assert_eq(z, 0x111); 87 88 byte q = 0xcc; 89 word v = 0x2203; 90 q /= (byte) v; 91 assert_eq(q, 0x44); 92 93 // ^= 94 95 b = 0x5F; 96 b ^= 1; 97 w = 0x543F; 98 w ^= 1; 99 assert(b == 0x5E); 100 assert(w == 0x543E); 101 b ^= 1; 102 w ^= 1; 103 assert(b == 0x5F); 104 assert(w == 0x543F); 105 b ^= 0x81; 106 w ^= 0x801; 107 assert(b == 0xDE); 108 assert(w == 0x5C3E); 109 w ^= (byte) 0xff01; 110 assert(w == 0x5C3F); 111 112 // &= 113 114 b = 0x5F; 115 b &= 0xFE; 116 w = 0x543F; 117 w &= 0xFFFE; 118 assert(b == 0x5E); 119 assert(w == 0x543E); 120 b &= 0x0F; 121 w &= 0x4F0; 122 assert(b == 0x0E); 123 assert(w == 0x0430); 124 b &= 0x0C; 125 w &= 0x0220; 126 assert(b == 0x0C); 127 assert(w == 0x0020); 128 w &= (byte) 0xFF80; 129 assert(w == 0x0000); 130 131 * (byte *) 0x0400 = 0xfc; 132 assert_eq(* (byte *) 0x0400, 0xfc); 133 * (byte *) (0x0400 + 0x0032) = 0xfc; 134 assert_eq(* (byte *) 0x0432, 0xfc); 135 * (byte *) 0x0400 &= 7; 136 assert_eq(* (byte *) 0x0400, 4); 137 138 // |= 139 140 b = 0x08; 141 b |= 0x28; 142 w = 0x0100; 143 w |= 0x7155; 144 assert(b == 0x28); 145 assert(w == 0x7155); 146 b |= 0x80; 147 w |= 0x8080; 148 assert(b == 0xa8); 149 assert(w == 0xf1d5); 150 b |= 0x0C; 151 w |= 0x4220; 152 assert(b == 0xac); 153 assert(w == 0xf3f5); 154 w |= (byte) 0xFF02; 155 assert(w == 0xf3f7); 156 157 // %= 158 b = 123; 159 b %= 10; 160 assert(b == 3); 161 w = 1234; 162 w %= 500; 163 assert(w == 234); 164 w = 1234; 165 w %= 25; 166 assert(w == 9); 167 return 0; 168 } 169 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 45: Verbatim assembly language 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void f(int *p) 25 { 26 asm { 27 ldd #1844 28 std [p] // brackets are words by themselves 29 } 30 } 31 enum { FOO = 42 }; 32 int main() 33 { 34 word w = 0x1000; 35 byte x = 40; 36 asm("ldd", w); 37 asm { 38 addd #$234 // comment must start with "//" 39 exg a,b /* or use C-style comments */ 40 nop ; or start with a semi-colon 41 bra @localLabel 42 ; Next line tests that a colon in a semi-colon comment is not processed as a variableNameEscapeChar. 43 ; foo bar: 44 ; Next label tests that semi-colon comment lines are sent to the assembler. 45 ; @localLabel is local in LWASM. Semi-colon comment lines preserve the "local scope". 46 @localLabel 47 inca 48 incb 49 pshs x // register X 50 inc :x // C variable 'x' ("inc x" would refer to register, i.e., error) 51 puls x // register X 52 } 53 asm("std", w); 54 assert_eq(w, 0x3513); 55 assert_eq(x, 41); 56 57 int n = 0; 58 f(&n); 59 assert_eq(n, 1844); 60 61 byte m[2] = { 22, 33 }; 62 byte a[2] = { 44, 55 }; 63 asm { 64 ldb m 65 addb m[1] 66 stb m[0] 67 ldb :a 68 addb :a[1] 69 stb :a[0] 70 } 71 assert_eq(m[0], 22 + 33); 72 assert_eq(a[0], 44 + 55); 73 74 byte foo = 42; 75 asm { 76 ldb #1+:FOO*2 // escaped enumerated name 77 stb foo 78 } 79 assert_eq(foo, 85); 80 81 word d; 82 asm { 83 leax d,x // 'd' must refer to register D, not C variable 'd' 84 } 85 86 return 0; 87 } 88 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 46: Referring to variables from asm directive 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 word big = 0x1234; 27 byte small = 0xaa; 28 asm { 29 ldd big 30 coma 31 comb 32 std big 33 ldb small 34 comb 35 stb small 36 loop: // no white space allowed before a label 37 brn loop 38 } 39 assert_eq(big, 0xEDCB); 40 assert_eq(small, 0x55); 41 return 0; 42 } 43 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 47: Declaring two local variables with same name, in different blocks 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 byte *addr1; 27 byte *addr2; 28 { 29 byte b = 11; 30 assert_eq(b, 11); 31 addr1 = &b; 32 } 33 { 34 byte b = 22; 35 assert_eq(b, 22); 36 addr2 = &b; 37 } 38 assert_eq(addr1, addr2); // both b's expected to be at same address 39 return 0; 40 } 41 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 48: Conditional expression (cond ? foo : bar) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void foo(byte p) {} 25 byte returnByte(byte b) 26 { 27 asm { 28 lda #$DD // put dirt in A 29 } 30 return b; 31 } 32 int main() 33 { 34 assert((1 ? 2 : 3) == 2); 35 assert((0 ? 2 : 3) == 3); 36 foo(1 ? (byte) 2 : (byte) 3); 37 38 { 39 word cond = 1; 40 word t = 2; 41 word f = 3; 42 assert((cond ? t : f) == 2); 43 cond = 0; 44 assert((cond ? t : f) == 3); 45 } 46 47 { 48 byte cond = 1; 49 byte t = 2; 50 byte f = 3; 51 assert((cond ? t : f) == 2); 52 cond = 0; 53 assert((cond ? t : f) == 3); 54 t = (cond ? 4 : 5); // 4 and 5 are ints, but they fit in byte, so no error 55 } 56 57 { 58 asm { ldx #0 } // robustness check 59 word a = 4; 60 word b = 5; 61 word c = 1; 62 (c ? a : b) = 6; 63 assert_eq(a, 6); 64 assert(b == 5); 65 c = 0; 66 (c ? a : b) = 7; 67 assert(a == 6); 68 assert(b == 7); 69 } 70 71 { 72 byte a = 4; 73 byte b = 5; 74 byte c = 1; 75 (c ? a : b) = 6; 76 assert(a == 6); 77 assert(b == 5); 78 c = 0; 79 (c ? a : b) = 7; 80 assert(a == 6); 81 assert(b == 7); 82 } 83 84 { 85 byte *a = (byte *) 4; 86 byte *b = (byte *) 5; 87 byte *c = (byte *) 1; 88 (c ? a : b) = 6; 89 assert(a == 6); 90 assert(b == 5); 91 c = 0; 92 (c ? a : b) = 7; 93 assert(a == 6); 94 assert(b == 7); 95 } 96 97 // True and false expressions of different sizes. 98 { 99 unsigned u = 100; 100 u = (u > 99 ? 50 : u); // warning 101 assert_eq(u, 50); 102 byte b = 12; 103 u = (u > 66 ? u : returnByte(b)); // warning 104 assert_eq(u, 12); 105 u = 999; 106 u = (u < 2000 ? u : returnByte(b)); // warning 107 assert_eq(u, 999); 108 109 int a0[] = { 10 }, a1[] = { 11 }; 110 b = 50; 111 u = (b < 77 ? a0 : a1); 112 assert_eq(u, &a0); 113 } 114 115 return 0; 116 } 117 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code ,check-prog.c:100: __warning__: true and false expressions of conditional are not of the same type (int vs unsigned int); result is of type int ,check-prog.c:103: __warning__: true and false expressions of conditional are not of the same type (unsigned int vs unsigned char); result is of type unsigned int ,check-prog.c:106: __warning__: true and false expressions of conditional are not of the same type (unsigned int vs unsigned char); result is of type unsigned int Assembly language filename: ,check-prog.s 0 error(s), 3 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 49: Calling a with same name as local variable declared after the call 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte b = 0; 25 void func() { b = 77; } 26 int main() 27 { 28 assert_eq(b, 0); 29 func(); 30 assert_eq(b, 77); 31 word func = 0; 32 assert_eq(b, 77); 33 return 0; 34 } 35 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 50: Optimized increments and decrements 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 { 27 char buf[8]; 28 memcpy(buf, "xxxxxxxx", 8); 29 char *dest = buf; 30 unsigned char i = 0; 31 while (i < 8) 32 { 33 *dest++ = 'x'; // detect unsafe optimizations on this post-inc. 34 ++i; 35 } 36 assert_eq(memcmp(buf, "xxxxxxxx", 8), 0); 37 } 38 39 { 40 char b = 10; 41 b += 0; 42 assert_eq(b, 10); 43 b += 1; 44 assert_eq(b, 11); 45 b += 2; 46 assert_eq(b, 13); 47 b += -1; 48 assert_eq(b, 12); 49 b += -2; 50 assert_eq(b, 10); 51 asm("CLRB"); // to prove that += 0 still loads variable in register, for init of b1 52 char b1 = (b += 0); 53 assert_eq(b1, 10); 54 char b2 = (b += 4); 55 assert_eq(b2, 14); 56 } 57 58 { 59 int w = 10; 60 w += 0; 61 assert_eq(w, 10); 62 w += 1; 63 assert_eq(w, 11); 64 w += 2; 65 assert_eq(w, 13); 66 w += -1; 67 assert_eq(w, 12); 68 w += -2; 69 assert_eq(w, 10); 70 asm("CLRA"); // to prove that += 0 still loads variable in register, for init of w1 71 asm("CLRB"); 72 int w1 = (w += 0); 73 assert_eq(w1, 10); 74 int w2 = (w += 4); 75 assert_eq(w2, 14); 76 } 77 78 return 0; 79 } 80 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 51: Increment on word pointer 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 word *wp = (word *) 100; 27 wp += 16; 28 assert_eq(wp, 132); 29 wp = 100; 30 wp -= 16; 31 assert_eq(wp, 68); 32 33 wp = 1000; 34 wp += 0x80; // 1000 + 128 * 2 == 1256 35 assert_eq(wp, 1256); 36 wp = 2256; 37 wp -= 0x80; // 2256 - 128 * 2 == 2000 38 assert_eq(wp, 2000); 39 40 byte *bp = (byte *) 100; 41 bp += 16; 42 assert_eq(bp, 116); 43 bp = 100; 44 bp -= 16; 45 assert_eq(bp, 84); 46 47 word w = 200; 48 w += 16; 49 assert_eq(w, 216); 50 w = 200; 51 w -= 16; 52 assert_eq(w, 184); 53 54 byte b = 200; 55 b += 16; 56 assert_eq(b, 216); 57 b = 200; 58 b -= 16; 59 assert_eq(b, 184); 60 return 0; 61 } 62 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 52: Increment on struct pointer 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S { word a; word b; byte c; }; 25 void f(byte *start, byte *end) 26 { 27 assert_eq(end, start + 5 * sizeof(struct S)); 28 struct S *last = (struct S *) end - 1; 29 assert_eq(last, start + 4 * sizeof(struct S)); 30 struct S *p = last; 31 --p; 32 assert_eq(p, start + 3 * sizeof(struct S)); 33 p--; 34 assert_eq(p, start + 2 * sizeof(struct S)); 35 p = p - 1; 36 assert_eq(p, start + sizeof(struct S)); 37 ++p; 38 assert_eq(p, start + 2 * sizeof(struct S)); 39 p++; 40 assert_eq(p, start + 3 * sizeof(struct S)); 41 p = p + 1; 42 assert_eq(last, start + 4 * sizeof(struct S)); 43 } 44 int main() 45 { 46 assert_eq(sizeof(struct S), 5); 47 struct S a[5]; 48 struct S *p = a; 49 assert_eq(p, a); 50 assert_eq(p + 1, &a[1]); 51 ++p; 52 assert_eq(p, &a[1]); 53 assert_eq(p - 1, &a[0]); 54 byte *aCast = (byte *) a; 55 byte *pCast = (byte *) p; 56 assert_eq(pCast, aCast + sizeof(struct S)); 57 58 // For loop increment may be subject to optimization. 59 for (p = a; p < &a[5]; ++p) 60 assert_eq((p - a) * sizeof(struct S), (byte *) p - (byte *) a); 61 62 f((byte *) a, (byte *) (a + 5)); 63 64 return 0; 65 } 66 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 53: exit() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void h() { exit(0); } 25 void g() { h(); } 26 void f() { g(); } 27 int main() 28 { 29 f(); 30 printf("end\n"); 31 return 0; 32 } 33 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 54: if/while condition ending in == 0 or != 0. String literal sequence 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 #define BUFSIZ 200 25 char buffer[BUFSIZ]; 26 word index = 0; 27 void write(char *str) 28 { 29 word len = strlen(str); 30 assert(index + len < BUFSIZ); 31 strcpy(buffer + index, str); 32 index += len; 33 } 34 byte b0() { return 0; } 35 byte b1() { return 1; } 36 byte w0() { return 0; } 37 byte w1() { return 1; } 38 int main() 39 { 40 if (b0() == 0) 41 write("b0-eq-then\n"); 42 else 43 write("b0-eq-else\n"); 44 if (b1() == 0) 45 write("b1-eq-then\n"); 46 else 47 write("b1-eq-else\n"); 48 if (w0() == 0) 49 write("w0-eq-then\n"); 50 else 51 write("w0-eq-else\n"); 52 if (w1() == 0) 53 write("w1-eq-then\n"); 54 else 55 write("w1-eq-else\n"); 56 57 if (b0() != 0) 58 write("b0-ne-then\n"); 59 else 60 write("b0-ne-else\n"); 61 if (b1() != 0) 62 write("b1-ne-then\n"); 63 else 64 write("b1-ne-else\n"); 65 if (w0() != 0) 66 write("w0-ne-then\n"); 67 else 68 write("w0-ne-else\n"); 69 if (w1() != 0) 70 write("w1-ne-then\n"); 71 else 72 write("w1-ne-else\n"); 73 74 while (b0() == 0) 75 { 76 write("b0-eq-body\n"); 77 break; 78 } 79 while (b1() == 0) 80 { 81 write("b1-eq-body\n"); 82 break; 83 } 84 while (w0() == 0) 85 { 86 write("w0-eq-body\n"); 87 break; 88 } 89 while (w1() == 0) 90 { 91 write("w1-eq-body\n"); 92 break; 93 } 94 95 while (b0() != 0) 96 { 97 write("b0-eq-body\n"); 98 break; 99 } 100 while (b1() != 0) 101 { 102 write("b1-eq-body\n"); 103 break; 104 } 105 while (w0() != 0) 106 { 107 write("w0-eq-body\n"); 108 break; 109 } 110 while (w1() != 0) 111 { 112 write("w1-eq-body\n"); 113 break; 114 } 115 116 buffer[index] = 0; 117 118 // Test using a string literal sequence. 119 assert(!strcmp(buffer, "b0-eq-then\nb1-eq-else\nw0-eq-then\nw1-eq-else\n" 120 "b0-ne-else\nb1-ne-then\nw0-ne-else\nw1-ne-then\n" 121 "b0-eq-body\nw0-eq-body\n" 122 "b1-eq-body\nw1-eq-body\n")); 123 return 0; 124 } 125 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 55: Multiple declarators per var_decl 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 byte b0, b1; 27 byte b2 = 2, b3; 28 byte b4, b5 = 5; 29 byte b6 = 6, b7 = 7; 30 byte b8 = 8, b9 = 9, b10 = 10, b11 = 11, b12 = 12; 31 assert_eq(b2, 2); 32 assert_eq(b5, 5); 33 assert_eq(b6, 6); 34 assert_eq(b7, 7); 35 assert_eq(b8, 8); 36 assert_eq(b9, 9); 37 assert_eq(b10, 10); 38 assert_eq(b11, 11); 39 assert_eq(b12, 12); 40 41 word w0, w1; 42 word w2 = 2, w3; 43 word w4, w5 = 5; 44 word w6 = 6, w7 = 7; 45 word w8 = 8, w9 = 9, w10 = 10, w11 = 11, w12 = 12; 46 assert_eq(w2, 2); 47 assert_eq(w5, 5); 48 assert_eq(w6, 6); 49 assert_eq(w7, 7); 50 assert_eq(w8, 8); 51 assert_eq(w9, 9); 52 assert_eq(w10, 10); 53 assert_eq(w11, 11); 54 assert_eq(w12, 12); 55 56 byte b = 1, *pb = &b, bb = 99; 57 assert_eq(b, 1); 58 assert_eq(bb, 99); 59 assert(pb); 60 assert_eq(*pb, 1); 61 *pb = 42; 62 assert_eq(*pb, 42); 63 assert_eq(b, 42); 64 pb = &bb; 65 --*pb; 66 assert_eq(bb, 98); 67 68 word w = 1, *pw = &w, ww = 999; 69 assert_eq(w, 1); 70 assert_eq(ww, 999); 71 assert(pw); 72 assert_eq(*pw, 1); 73 *pw = 42; 74 assert_eq(*pw, 42); 75 assert_eq(w, 42); 76 pw = &ww; 77 --*pw; 78 assert_eq(ww, 998); 79 return 0; 80 } 81 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 56: Interrupt handler 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 word global = 0; 25 interrupt void isr() 26 { 27 global = 42; 28 } 29 int main() 30 { 31 assert_eq(global, 0); 32 33 // Simulate an IRQ. 34 void *isrAddr = isr; 35 byte *pushedX = 0, *restoredX = 0; 36 asm { 37 leax returnAddr,pcr 38 stx pushedX 39 pshs x // RTI will pop this into PC 40 orcc #$80 // set E flag (whole environment saved) 41 pshs u,y,x,dp,b,a,cc // save rest of environment 42 ldx isrAddr 43 jmp ,x 44 returnAddr: 45 stx restoredX 46 } 47 assert_eq(global, 42); 48 assert_eq(restoredX, pushedX); // X must have been restored by RTI 49 return 0; 50 } 51 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 57: Global variables 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte bytes[4] = { 11, 22, 33, 44 }; 25 word words[3]; 26 byte gb0 = 42; 27 byte gb1; 28 word gw0 = 7777; 29 word gw1; 30 31 word a = 4000; 32 word x = a + 2000; 33 word wa[] = { 42, 11000 - x, 17 }; 34 byte ba[] = { (byte) 0xd123 }; 35 36 int main() 37 { 38 gw1 = 2424; 39 words[2] = gw0; 40 gb1 = bytes[3]; 41 gb0++; 42 43 assert_eq(gw1, 2424); 44 assert_eq(words[2], 7777); 45 assert_eq(gb1, 44); 46 assert_eq(gb0, 43); 47 assert(bytes != words); 48 assert(gb0 != gb1); 49 assert(gw0 != gw1); 50 assert(gb0 != gw1); 51 assert(gb1 != gw0); 52 53 assert_eq(a, 4000); 54 assert_eq(x, 6000); 55 assert_eq(wa[0], 42); 56 assert_eq(wa[1], 5000); 57 assert_eq(wa[2], 17); 58 assert_eq(ba[0], 0x23); 59 60 return 0; 61 } 62 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 58: sizeof(type) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S1 25 { 26 char b[5]; 27 }; 28 struct S0 29 { 30 char b; 31 unsigned *pw; // no 2-byte alignment 32 char byteArray[9 + 1]; // non-trivial size expression tree (cf DeclaratorInfo::computeArraySize()) 33 struct S1 s1; 34 struct S0 *next; 35 }; 36 struct Empty 37 { 38 }; 39 int main() 40 { 41 assert_eq(sizeof(char), 1); 42 assert_eq(sizeof(word), 2); 43 assert_eq(sizeof(char *), 2); 44 assert_eq(sizeof(int *), 2); 45 46 assert_eq(sizeof(unsigned char), 1); 47 assert_eq(sizeof(signed char), 1); 48 assert_eq(sizeof(unsigned), 2); 49 assert_eq(sizeof(signed), 2); 50 assert_eq(sizeof(unsigned short), 2); 51 assert_eq(sizeof(signed short), 2); 52 assert_eq(sizeof(unsigned int), 2); 53 assert_eq(sizeof(signed int), 2); 54 assert_eq(sizeof(unsigned char *), 2); 55 assert_eq(sizeof(signed char *), 2); 56 assert_eq(sizeof(unsigned int *), 2); 57 assert_eq(sizeof(signed int *), 2); 58 59 assert_eq(sizeof(struct S1), 5); 60 assert_eq(sizeof(struct S0), 1 + 2 + 10 + 5 + 2); 61 assert_eq(sizeof(struct S0 *), 2); 62 assert_eq(sizeof(struct Empty), 0); 63 64 char b[8 + 2]; 65 assert_eq(sizeof(b), 10); 66 return 0; 67 } 68 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 59: sizeof(expr) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S1 25 { 26 byte b[5]; 27 }; 28 struct S0 29 { 30 byte b; 31 word *pw; // no 2-byte alignment 32 byte byteArray[10]; 33 struct S1 s1; 34 struct S0 *next; 35 }; 36 struct Empty 37 { 38 }; 39 int main() 40 { 41 byte b; 42 assert_eq(sizeof(b), 1); 43 word w; 44 assert_eq(sizeof(w), 2); 45 byte *pb; 46 assert_eq(sizeof(pb), 2); 47 word *pw; 48 assert_eq(sizeof(pw), 2); 49 struct S1 s1; 50 assert_eq(sizeof(s1), 5); 51 struct S0 s0; 52 assert_eq(sizeof(s0), 1 + 2 + 10 + 5 + 2); 53 assert_eq(sizeof(&s0), 2); 54 struct Empty empty; 55 assert_eq(sizeof(empty), 0); 56 57 byte ab[5]; 58 assert_eq(sizeof(ab[0]), 1); 59 assert_eq(sizeof(ab), 5); 60 61 word aw[5]; 62 assert_eq(sizeof(aw[0]), 2); 63 assert_eq(sizeof(aw), 5 * 2); 64 assert_eq(sizeof(aw) / sizeof(aw[0]), 5); // the division should be optimized out 65 66 word twoDim[5][3]; 67 assert_eq(sizeof(twoDim), 30); 68 assert_eq(sizeof(twoDim[0]), 6); 69 assert_eq(sizeof(twoDim) / sizeof(twoDim[0]), 5); 70 assert_eq(sizeof(twoDim[0][0]), 2); 71 assert_eq(sizeof(twoDim[18][44]), 2); // indices don't matter 72 73 word threeDim[5][3][4]; 74 assert_eq(sizeof(threeDim), 120); 75 assert_eq(sizeof(threeDim[0]), 24); 76 assert_eq(sizeof(threeDim) / sizeof(threeDim[0]), 5); 77 assert_eq(sizeof(threeDim[0][0]), 8); 78 assert_eq(sizeof(threeDim[0][0][0]), 2); 79 80 struct S1 as1[5]; 81 assert_eq(sizeof(as1), 5 * sizeof(struct S1)); 82 struct S0 as0[5]; 83 assert_eq(sizeof(as0), 5 * sizeof(struct S0)); 84 85 word arrayWithNoSize[] = { 1, 2, 3, 4, 5 }; 86 assert_eq(sizeof(arrayWithNoSize), 10); 87 88 assert_eq(sizeof(""), 1); 89 assert_eq(sizeof("foobar"), 7); 90 assert_eq(sizeof("\0\0\0"), 4); 91 char s[] = "quux"; 92 assert_eq(sizeof(s), 5); 93 94 return 0; 95 } 96 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 60: Empty statement 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void f() 25 { 26 ; 27 } 28 int main() 29 { 30 return 0; 31 } 32 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 61: Variadic function. va_list is a typedef for "word *" 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 25 #include 26 27 struct Object 28 { 29 byte b; 30 }; 31 void variadic(char *firstFixed, char *lastFixed, ...) 32 { 33 va_list ap; 34 assert_eq(sizeof(ap), 2); // va_list is a pointer 35 36 va_start(ap, lastFixed); 37 va_list orig = ap; 38 39 word w = va_arg(ap, word); 40 assert_eq(w, 17); 41 assert_eq(ap, orig + 2); // ap must be 2 bytes from start; va_list is a char * 42 43 byte b = va_arg(ap, byte); 44 assert_eq(b, 42); 45 assert_eq(ap, orig + 4); 46 47 char *s = va_arg(ap, char *); 48 assert(!strcmp(s, "foobar")); 49 assert_eq(ap, orig + 6); 50 51 struct Object *obj = va_arg(ap, struct Object *); 52 assert(obj); 53 assert_eq(obj->b, 99); 54 assert_eq(ap, orig + 8); 55 56 va_end(ap); 57 58 assert(!strcmp(firstFixed, "fixed1")); 59 assert(!strcmp(lastFixed, "fixed2")); 60 assert_eq(w, 17); 61 assert_eq(b, 42); 62 assert(!strcmp(s, "foobar")); 63 assert_eq(obj->b, 99); 64 } 65 int main() 66 { 67 struct Object obj; 68 obj.b = 99; 69 variadic("fixed1", "fixed2", 17, 1024 + 42, "foobar", &obj); 70 return 0; 71 } 72 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 62: rand(): Check that counters are filled quasi-uniformly 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 enum { BUCKETS = 32, // must be power of 2 25 ITERATIONS = 3200 }; 26 int main() 27 { 28 int n = rand(); 29 assert_eq(n, 256); // proves that SEED was init to 0 by INILIB 30 srand(42); 31 n = rand(); 32 assert_eq(n, 11071); // proves that SEED was affected by srand() 33 34 word counters[BUCKETS]; 35 memset(counters, 0, BUCKETS * sizeof(word)); 36 int mask = BUCKETS - 1; 37 for (word i = 0; i < ITERATIONS; ++i) 38 ++counters[rand() & mask]; 39 word expectedAverage = ITERATIONS / BUCKETS; 40 word low = expectedAverage * 95 / 100; 41 word high = expectedAverage * 105 / 100; 42 for (word b = 0; b < BUCKETS; ++b) 43 { 44 word c = counters[b]; 45 //printf("%4u. %5u\n", b, c); 46 assert(c >= low && c <= high); 47 } 48 return 0; 49 } 50 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 63: Double negation 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void dummy() 25 { 26 // Force "foobar" string to have address >= 0x0100. 27 char *b0 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 28 char *b1 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; 29 char *b2 = "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"; 30 char *b3 = "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"; 31 char *b4 = "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"; 32 } 33 int main() 34 { 35 char b = 0; 36 if (!(!"foobar")) 37 b = 1; 38 else 39 b = -1; 40 assert_eq(b, 1); 41 return 0; 42 } 43 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 64: Signed types 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char comparator(unsigned int w1, unsigned int w2) 25 { 26 char result; 27 if (w1 < w2) 28 result = -1; 29 else if (w1 > w2) 30 result = 1; 31 else 32 result = 0; 33 return result; 34 } 35 int main() 36 { 37 sbyte sb = 255; 38 assert_eq(sb, -1); 39 40 sword sw = 65535; 41 assert_eq(sw, -1); 42 43 // Argument promotion. 44 printf("sb=%d\n", sb); 45 46 // Comparison for jumps. 47 if (sb < 0) 48 printf("sb < 0\n"); 49 else 50 assert(!"sb < 0 failed"); 51 if (sb <= 0) 52 printf("sb <= 0\n"); 53 else 54 assert(!"sb <= 0 failed"); 55 56 if (sw < 0) 57 printf("sw < 0\n"); 58 else 59 assert(!"sw < 0 failed"); 60 if (sw <= 0) 61 printf("sw <= 0\n"); 62 else 63 assert(!"sw <= 0 failed"); 64 65 // Comparisons as integers. 66 if (!(sb < 0)) 67 assert(!"!(sb < 0) failed"); 68 else 69 printf("!!(sb < 0)\n"); 70 if (!(sb <= 0)) 71 assert(!"!(sb <= 0) failed"); 72 else 73 printf("!!(sb <= 0)\n"); 74 75 if (!(sw < 0)) 76 assert(!"!(sw < 0) failed"); 77 else 78 printf("!!(sw < 0)\n"); 79 if (!(sw <= 0)) 80 assert(!"!(sw <= 0) failed"); 81 else 82 printf("!!(sw <= 0)\n"); 83 84 // Comparisons as integers. 85 word bool0 = (sb < 0); 86 assert(bool0); 87 bool0 = (sb <= 0); 88 assert(bool0); 89 word bool1 = (sw < 0); 90 assert(bool1); 91 bool1 = (sw <= 0); 92 assert(bool1); 93 94 sbyte t = -1; 95 word comp = (t > 0); 96 assert_eq(comp, 0); 97 comp = (t >= 0); 98 assert_eq(comp, 0); 99 t = 1; 100 comp = (t < 0); 101 assert_eq(comp, 0); 102 comp = (t <= 0); 103 assert_eq(comp, 0); 104 105 assert(sb < 0); 106 assert(sb <= 0); 107 assert(sw < 0); 108 assert(sw <= 0); 109 assert(!(sb > 0)); 110 assert(!(sb >= 0)); 111 assert(!(sw > 0)); 112 assert(!(sw >= 0)); 113 114 assert(comparator(0, 1) < 0); 115 assert(comparator(2, 1) > 0); 116 assert(comparator(1, 1) == 0); 117 assert(comparator(30, 31) < 0); 118 assert(comparator(32, 31) > 0); 119 assert(comparator(31, 31) == 0); 120 121 sbyte minusOne = -1; 122 123 // Binary operand promotion. 124 assert(1000 + (sbyte) 255 == 999); 125 assert((sbyte) 255 + 1000 == 999); 126 assert(1000 + sb == 999); 127 assert(sb + 1000 == 999); 128 assert(1000 + sw == 999); 129 assert(sw + 1000 == 999); 130 131 assert(1000 - (sbyte) 255 == 1001); 132 assert((sbyte) 255 - 1000 == -1001); 133 assert(1000 - sb == 1001); 134 assert(sb - 1000 == -1001); 135 assert(1000 - sw == 1001); 136 assert(sw - 1000 == -1001); 137 138 assert_eq(sb * sb, 1); 139 assert_eq(sb / sb, 1); 140 assert_eq(-1 * -1, 1); 141 assert_eq(-1 / -1, 1); 142 assert_eq(-1000 * -5, 5000); 143 assert_eq(1000 * -5, -5000); 144 assert_eq(-5 * -1000, 5000); 145 assert_eq(-5 * 1000, -5000); 146 assert_eq(-1000 / -5, 200); 147 assert_eq(1000 / -5, -200); 148 assert_eq(-5 / -1000, 0); 149 assert_eq(-5 / 1000, 0); 150 151 sw = -1000; 152 sb = -5; 153 assert_eq(sb, -5); 154 assert_eq(sw * sb, 5000); 155 assert_eq(sb * sw, 5000); 156 assert_eq(sw / sb, 200); 157 158 sw *= -5; 159 assert_eq(sw, 5000); 160 sw /= -5; 161 sw /= -5; 162 assert_eq(sw, 200); 163 164 assert_eq( 23 % 10, 3); 165 assert_eq(-23 % 10, -3); 166 assert_eq(-23 % -10, -3); 167 assert_eq( 23 % -10, 3); 168 169 assert_eq(-1000 % 400, -200); 170 171 sw = -1000; 172 assert_eq(sw % 10, 0); 173 assert_eq(sw % 9, -1); 174 assert_eq(sw % 400, -200); 175 176 sw = 255; 177 assert_eq(sw * sw, 65025); 178 return 0; 179 } 180 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: sb=-1 sb < 0 sb <= 0 sw < 0 sw <= 0 !!(sb < 0) !!(sb <= 0) !!(sw < 0) !!(sw <= 0) --- Actual output: sb=-1 sb < 0 sb <= 0 sw < 0 sw <= 0 !!(sb < 0) !!(sb <= 0) !!(sw < 0) !!(sw <= 0) -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 65: sbrk(), sbrkmax() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int global1 = 0xAABB; 25 int main() 26 { 27 assert_eq(global1, 0xAABB); 28 unsigned initMax = sbrkmax(); 29 assert(initMax > 0); 30 31 // Count number of times 1k can be allocated. 32 unsigned counter = 0; 33 unsigned bufsiz = 1024; 34 void *prevAllocated = main; 35 void *newlyAllocated; 36 while ((newlyAllocated = sbrk(bufsiz)) != (void *) -1) 37 { 38 assert_eq(global1, 0xAABB); 39 ++counter; 40 assert((unsigned) newlyAllocated > (unsigned) prevAllocated); 41 prevAllocated = newlyAllocated; 42 43 memset(newlyAllocated, 0xEE, bufsiz); 44 assert_eq(global1, 0xAABB); 45 } 46 47 assert(counter > 0); 48 assert(counter < 64); 49 assert(counter * bufsiz <= initMax); 50 assert_eq(counter, initMax / bufsiz); 51 assert_eq(global1, 0xAABB); 52 53 unsigned finalMax = sbrkmax(); 54 assert_eq(global1, 0xAABB); 55 assert(finalMax < bufsiz); 56 assert(finalMax < initMax); 57 assert_eq(initMax - counter * bufsiz, finalMax); 58 59 //printf("%u; %u -> %u; %u\n", counter, initMax, finalMax, initMax / bufsiz); 60 return 0; 61 } 62 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 66: sbrkmax() vs #pragma stack_space 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 #pragma stack_space 32768 25 int global1 = 0xAABB; 26 int main() 27 { 28 assert_eq(global1, 0xAABB); 29 unsigned initMax = sbrkmax(); 30 //printf("initMax = %u\n", initMax); 31 assert(initMax > 12000 && initMax < 18000); // would be about 45000 without #pragma 32 return 0; 33 } 34 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 67: Casting signed byte value into 2-byte types 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S { word n; }; 25 int main() 26 { 27 assert_eq(sizeof((byte *) 0), 2); 28 assert_eq(sizeof((byte *) 100), 2); 29 assert_eq((byte *) -1, 0xFFFF); 30 assert_eq((word *) -1, 0xFFFF); 31 assert_eq((word) -1, 0xFFFF); 32 assert_eq((sword) -1, 0xFFFF); 33 assert_eq((byte) -1, 0xFF); 34 assert_eq((sbyte) -1, -1); 35 36 assert_eq((sbyte) -1, 0xFF); // byte operands not promoted to int, unl 37 38 // Cast to a struct pointer. 39 assert_eq((struct S *) -1, 0xFFFF); 40 byte buf[2]; 41 assert(buf); 42 struct S *ps = (struct S *) buf; 43 assert_eq(ps, buf); 44 ps->n = 1844; 45 assert_eq(* (word *) buf, 1844); 46 * (word *) buf = 4418; 47 assert_eq(ps->n, 4418); 48 49 int i = (char) -42; 50 assert_eq(i, -42); 51 52 return 0; 53 } 54 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 68: Casting to 2-keyword types 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S { char c; }; 25 int main() 26 { 27 unsigned char c; 28 c = (unsigned char) 42; 29 assert_eq(c, 42); 30 (signed int) 0xFFFF; 31 (unsigned short *) 0x1234; 32 (struct S *) 1; 33 (struct S ***) 3; 34 35 struct S s = { '$' }; 36 struct S *ps = &s; 37 struct S **pps = &ps; 38 struct S ***ppps = &pps; 39 unsigned short address = (unsigned short) ppps; 40 ppps = 0; 41 assert_eq(ppps, 0); 42 ppps = (struct S ***) address; 43 44 assert_eq(s.c, '$'); 45 assert_eq((*ps).c, '$'); 46 assert_eq((**pps).c, '$'); 47 assert_eq((***ppps).c, '$'); 48 49 return 0; 50 } 51 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 69: Right shift on a signed value must do an arithmetic shift, not a logical one 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void test() 25 { 26 word initStackPtr; 27 asm { sts initStackPtr }; 28 29 byte ub = 0x80; 30 assert_eq(ub >> 1, 0x40); // LSR 31 sbyte sb = 0x80; 32 assert_eq(sb >> 1, (sbyte) 0xC0); // ASR 33 word uw = 0x8000; 34 assert_eq(uw >> 1, 0x4000); // LSR 35 sword sw = 0x8000; 36 assert_eq(sw >> 1, (sword) 0xC000); // ASR 37 38 assert_eq( 128 >> 1, 0x40); // LSR 39 assert_eq( -64 >> 1, 0xFFE0); // ASR 40 assert_eq(((sbyte) -64) >> 1, 0xFFE0); // ASR: -64 starts as $FFC0, gets cast as $C0, right shift extends it to $FFC0, then shifts it 41 assert_eq( -128 >> 1, 0xFFC0); // ASR 42 assert_eq( -128 >> 1, (sbyte) 0xC0); // ASR 43 assert_eq( 32768 >> 1, 0x4000); // LSR 44 assert_eq(-16384 >> 1, (sword) 0xE000); // ASR 45 assert_eq(-32768 >> 1, (sword) 0xC000); // ASR 46 47 ub = 0x80; 48 ub >>= 2; 49 assert_eq(ub, 0x20); 50 sb = 0x80; 51 sb >>= 2; 52 assert_eq(sb, 0xE0); 53 54 asm { clrb } // to prove next line is compiled correctly 55 56 sbyte *psb = &(sb >>= 1); // shift-assignment as l-value expression 57 assert_eq(sb, 0xF0); 58 assert_eq(psb, &sb); 59 assert_eq(*psb, 0xF0); 60 61 uw = 0x8000; 62 uw >>= 2; 63 assert_eq(uw, 0x2000); 64 sw = 0x8000; 65 sw >>= 2; 66 assert_eq(sw, 0xE000); 67 68 word finalStackPtr; 69 asm { sts finalStackPtr }; 70 assert_eq(finalStackPtr, initStackPtr); 71 } 72 int main() 73 { 74 test(); 75 return 0; 76 } 77 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 70: Returning integer 0 allowed in pointer-returning function 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte *b() 25 { 26 return 0; 27 } 28 word *w() 29 { 30 return 0; 31 } 32 int main() 33 { 34 assert_eq(b(), 0); 35 assert_eq(w(), 0); 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 71: Struct array initializer. For loop increment on a struct pointer. Initializer with non-constant expression 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct SystemVar 25 { 26 char *name; 27 char *addr; 28 char type; 29 }; 30 struct SystemVar systemVars[] = 31 { 32 { "foo", 0x0019, 21 }, 33 { "bar", 0x0112, 25 }, 34 { "baz", 0x011A, 14 }, 35 { 0, 0, 0 } // marks the end 36 }; 37 struct CardBitmap 38 { 39 unsigned int rows[5]; 40 }; 41 struct CardBitmap cardBitmaps[] = 42 { 43 { { 1, 2, 3, 4, 5 } }, // outer {} for struct, inner for rows[] 44 { { 6, 7, 8, 9, 10 } }, 45 { { 11, 12, 13, 14, 15} }, 46 }; 47 int main() 48 { 49 word numElements = sizeof(systemVars) / sizeof(systemVars[0]) - 1; 50 assert_eq(numElements, 3); 51 char buffer[128]; 52 buffer[0] = 0; 53 word addrSum = 0; 54 word typeSum = 0; 55 for (struct SystemVar *p = systemVars; p->name; ++p) 56 { 57 strcat(buffer, p->name); 58 addrSum += (word) p->addr; 59 typeSum += p->type; 60 } 61 assert(!strcmp(buffer, "foobarbaz")); 62 assert_eq(addrSum, 0x0019 + 0x0112 + 0x011A); 63 assert_eq(typeSum, 21 + 25 + 14); 64 65 word wa[2] = { addrSum + 1, typeSum * 2 }; 66 assert_eq(wa[0], 0x0019 + 0x0112 + 0x011A + 1); 67 assert_eq(wa[1], (21 + 25 + 14) * 2); 68 69 assert_eq(cardBitmaps[0].rows[0], 1); 70 assert_eq(cardBitmaps[1].rows[2], 8); 71 assert_eq(cardBitmaps[2].rows[4], 15); 72 73 return 0; 74 } 75 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 72: Initializer for structs and arrays 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S 25 { 26 byte b; 27 word w; 28 }; 29 struct S global = 30 { 31 255, 32 12700 33 }; 34 struct StructWithArray 35 { 36 byte b; 37 word a[3]; 38 word w; 39 }; 40 struct StructWithArray globalWithArray = 41 { 42 77, { 2000, 21, 2002 }, 9988 43 }; 44 struct StructWithArray globalArrayOfStructWithArray[2] = 45 { 46 { 77, { 2000, 21, 2002 }, 9988 }, 47 { 177, { 2100, 22, 2102 }, 10088 }, 48 }; 49 struct StructWithByteArray 50 { 51 char str[7]; 52 }; 53 struct StructWithByteArray globalString = { "foobar" }; 54 55 struct A 56 { 57 byte byteField; 58 }; 59 struct A a = { 10 }; 60 struct B 61 { 62 struct A aMember; 63 }; 64 struct B b = { { 11 } }; 65 struct C 66 { 67 struct A aMemberArray[2]; 68 }; 69 struct C c = { { { 12 }, { 13 } } }; 70 71 int main() 72 { 73 assert_eq(global.b, 255); 74 assert_eq(global.w, 12700); 75 76 struct S local = 77 { 78 25, 79 1200 80 }; 81 assert_eq(local.b, 25); 82 assert_eq(local.w, 1200); 83 84 assert_eq(globalWithArray.b, 77); 85 assert_eq(globalWithArray.a[0], 2000); 86 assert_eq(globalWithArray.a[1], 21); 87 assert_eq(globalWithArray.a[2], 2002); 88 assert_eq(globalWithArray.w, 9988); 89 90 assert_eq(globalArrayOfStructWithArray[0].b, 77); 91 assert_eq(globalArrayOfStructWithArray[0].a[0], 2000); 92 assert_eq(globalArrayOfStructWithArray[0].a[1], 21); 93 assert_eq(globalArrayOfStructWithArray[0].a[2], 2002); 94 assert_eq(globalArrayOfStructWithArray[0].w, 9988); 95 96 assert_eq(globalArrayOfStructWithArray[1].b, 177); 97 assert_eq(globalArrayOfStructWithArray[1].a[0], 2100); 98 assert_eq(globalArrayOfStructWithArray[1].a[1], 22); 99 assert_eq(globalArrayOfStructWithArray[1].a[2], 2102); 100 assert_eq(globalArrayOfStructWithArray[1].w, 10088); 101 102 struct StructWithArray localArrayOfStructWithArray[2] = 103 { 104 { 77, { 2000, 21, 2002 }, 9988 }, 105 { 177, { 2100, 22, 2102 }, 10088 }, 106 }; 107 108 assert(!strcmp(globalString.str, "foobar")); 109 struct StructWithByteArray localString = { "FOOBAR" }; 110 assert(!strcmp(localString.str, "FOOBAR")); 111 112 assert_eq(a.byteField, 10); 113 assert_eq(b.aMember.byteField, 11); 114 assert_eq(c.aMemberArray[0].byteField, 12); 115 assert_eq(c.aMemberArray[1].byteField, 13); 116 117 return 0; 118 } 119 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 73: Pointer to pointer, array of pointers 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char *strings[] = { "foo", "bar", "baz", "abcdefghij" }; 25 char *moreStrings[][2] = { { "foo", "bar" }, { "baz", "abcdefghij" } }; 26 struct S { char b[2]; }; 27 void check(char **pba) 28 { 29 char *s = pba[0]; 30 assert(!strcmp(s, "foo")); 31 s = pba[1]; 32 assert(!strcmp(s, "bar")); 33 s = pba[2]; 34 assert(!strcmp(s, "baz")); 35 assert_eq(s[2], 'z'); 36 } 37 int main() 38 { 39 assert(!strcmp(strings[0], "foo")); 40 assert(!strcmp(strings[1], "bar")); 41 assert(!strcmp(strings[2], "baz")); 42 assert(!strcmp(strings[3], "abcdefghij")); 43 assert_eq(strings[3][7], 'h'); 44 45 char **ptrToByteArray = strings; 46 char *s = ptrToByteArray[0]; 47 assert(!strcmp(s, "foo")); 48 s = ptrToByteArray[1]; 49 assert(!strcmp(s, "bar")); 50 s = ptrToByteArray[2]; 51 assert(!strcmp(s, "baz")); 52 assert_eq(s[2], 'z'); 53 54 check(strings); 55 56 char *bytePtr = (char *) 0x1234; 57 word w = 0x9876; 58 * (char **) &w = bytePtr; 59 assert_eq(w, (word) bytePtr); 60 61 w = 0x6655; 62 ((struct S *) &w)->b[1] = 0x77; 63 assert_eq(w, 0x6677); 64 65 (* (struct S **) &w) = 0x5678; 66 assert_eq(w, 0x5678); 67 68 assert(!strcmp(moreStrings[0][0], "foo")); 69 assert(!strcmp(moreStrings[0][1], "bar")); 70 assert(!strcmp(moreStrings[1][0], "baz")); 71 assert(!strcmp(moreStrings[1][1], "abcdefghij")); 72 assert_eq(moreStrings[1][1][9], 'j'); 73 74 return 0; 75 } 76 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 74: Automatic conversion of an integer to a pointer, without a warning 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 byte *p = 0x123; 27 assert_eq(p, 0x123); 28 p = 0x456; 29 assert_eq(p, 0x456); 30 return 0; 31 } 32 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 75: char, short, signed, unsigned 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 word f(char ch, short sh, signed si, unsigned un) 25 { 26 return ch + sh + si + un; 27 } 28 int main() 29 { 30 char ch; 31 assert_eq(sizeof(ch), 1); 32 short sh; 33 assert_eq(sizeof(sh), 2); 34 signed si; 35 assert_eq(sizeof(si), 2); 36 unsigned un; 37 assert_eq(sizeof(un), 2); 38 assert_eq(f(-128, -300, -400, 10000), 9172); 39 40 signed char sch; 41 assert_eq(sizeof(sch), 1); 42 unsigned char uch; 43 assert_eq(sizeof(uch), 1); 44 signed short shint; 45 assert_eq(sizeof(shint), 2); 46 unsigned short unshint; 47 assert_eq(sizeof(unshint), 2); 48 signed int sint; 49 assert_eq(sizeof(sint), 2); 50 unsigned int unsint; 51 assert_eq(sizeof(unsint), 2); 52 return 0; 53 } 54 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 76: typedef 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 typedef unsigned short uint16_t; 25 typedef unsigned short *Ptr; 26 27 // Typedef for an array: 28 typedef unsigned Addr[2]; 29 Addr addr = { 0xAAAA, 0xBBBB }; 30 31 typedef char string10_t[10]; 32 typedef struct { 33     string10_t str1; 34     char str2[10]; 35     int str3[10]; 36 } test_t; 37 38 struct S { 39 string10_t grid[5]; 40 char c; 41 }; 42 43 typedef int TenInts[10]; 44 struct T { 45 TenInts tens[5]; 46 }; 47 48 void f1(char *a) {} 49 void f2(int *a) {} 50 unsigned diff(void *a, void *b) { return b - a; } 51 52 int main() 53 { 54 uint16_t u = 2014; 55 assert_eq(u, 2014); 56 Ptr p = &u; 57 assert_eq(*p, 2014); 58 59 assert_eq(addr[0], 0xAAAA); 60 assert_eq(addr[1], 0xBBBB); 61 addr[0] = 0x1111; 62 addr[1] = 0x2222; 63 assert_eq(addr[0], 0x1111); 64 assert_eq(addr[1], 0x2222); 65 66 Addr localAddr = { 1234, 2345 }; 67 assert_eq(localAddr[0] + localAddr[1], 3579); 68 ++localAddr[0]; 69 ++localAddr[1]; 70 assert_eq(localAddr[0] + localAddr[1], 3581); 71 72     string10_t str1; 73 assert_eq(sizeof(str1), 10); 74 assert_eq((str1 + 1) - str1, 1); 75 76 string10_t tens[5]; 77 assert_eq(sizeof(tens), 50); 78 assert_eq(sizeof(tens[2]), 10); 79 assert_eq(tens[4] - tens[3], 10); 80 assert_eq((tens + 1) - tens, 10); 81 82     char str2[10]; 83     test_t test; 84 assert_eq(sizeof(string10_t), 10); 85 assert_eq(sizeof(test.str1), 10); 86 assert_eq(sizeof(test.str2), 10); 87 assert_eq(sizeof(test.str3), 20); 88 assert_eq(sizeof(test), 40); 89 f1(str1); 90 f1(str2); 91 f1(test.str1); 92 f1(test.str2); 93 f2(test.str3); 94 assert_eq(diff( test.str1, test.str2), 10); 95 assert_eq(diff(&test.str1, test.str2), 10); 96 assert_eq(diff( test.str1, &test.str2), 10); 97 assert_eq(diff( test.str2, test.str3), 10); 98 assert_eq(diff(&test.str2, test.str3), 10); 99 assert_eq(diff( test.str2, &test.str3), 10); 100 101 struct S s; 102 assert_eq(sizeof(s.grid), 50); 103 assert_eq(sizeof(s.grid[2]), 10); 104 assert_eq(sizeof(s), 51); 105 assert_eq(diff(s.grid, &s.c), 50); 106 107 struct T t; 108 assert_eq(sizeof(TenInts), 10 * 2); 109 assert_eq(sizeof(t.tens), 50 * 2); 110 assert_eq(sizeof(t.tens[3]), 10 * 2); 111 112 // Initializers. 113 114 char str3[10] = "foobarbaz"; 115 assert_eq(strcmp(str3, "foobarbaz"), 0); 116 assert_eq(strlen(str3), 9); 117 string10_t str4 = "FOOBARBAZ"; 118 assert_eq(strcmp(str4, "FOOBARBAZ"), 0); 119 assert_eq(strlen(str4), 9); 120 121 string10_t strArray1[] = { "A", "B" }; 122 assert_eq(strArray1, strArray1[0]); 123 assert_ne(strArray1[0], strArray1[1]); 124 assert_eq(strcmp(strArray1[0], "A"), 0); 125 assert_eq(strcmp(strArray1[1], "B"), 0); 126 127 struct S s1 = { { "a", "b", "c", "d", "e" }, '$' }; 128 assert_eq(s1.grid, s1.grid[0]); 129 assert_ne(s1.grid, s1.grid[1]); 130 assert_ne(s1.grid, &s1.c); 131 assert_ne(s1.grid[4], &s1.c); 132 assert_eq(strcmp(s1.grid[0], "a"), 0); 133 assert_eq(strcmp(s1.grid[1], "b"), 0); 134 assert_eq(strcmp(s1.grid[2], "c"), 0); 135 assert_eq(strcmp(s1.grid[3], "d"), 0); 136 assert_eq(strcmp(s1.grid[4], "e"), 0); 137 assert_eq(s1.c, '$'); 138 139 struct S s2 = { { "f", { 'g', 0, 1, 2, 3, 4, 5, 6, 7, 8 }, "h", "i", "j" }, '%' }; 140 assert_eq(strcmp(s2.grid[0], "f"), 0); 141 assert_eq(strcmp(s2.grid[1], "g"), 0); 142 assert_eq(s2.grid[1][9], 8); 143 assert_eq(strcmp(s2.grid[2], "h"), 0); 144 assert_eq(strcmp(s2.grid[3], "i"), 0); 145 assert_eq(strcmp(s2.grid[4], "j"), 0); 146 assert_eq(s2.c, '%'); 147 148 return 0; 149 } 150 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 77: Multi-dimensional arrays 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int twoD[3][5]; 25 int threeD[4][3][5]; 26 int v[][2][3] = { 27 { { 10, 11, 12 }, { 13, 14, 15 } }, 28 { { 20, 21, 22 }, { 23, 24, 25 } }, 29 { { 30, 31, 32 }, { 33, 34, 35 } }, 30 { { 40, 41, 42 }, { 43, 44, 45 } }, 31 }; 32 unsigned char b[][2][3] = { // same as v, but 100 added to each row 33 { { 110, 11, 12 }, { 13, 14, 15 } }, 34 { { 20, 121, 22 }, { 23, 24, 25 } }, 35 { { 30, 31, 132 }, { 33, 34, 35 } }, 36 { { 40, 41, 42 }, { 143, 44, 45 } }, 37 }; 38 struct Point 39 { 40 int x; 41 int y; 42 int z; 43 }; 44 struct Point s[2][3] = { 45 { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, }, 46 { { 10, 11, 12 }, { 13, 14, 15 }, { 16, 17, 18 }, }, 47 }; 48 int computeSum(int v[2][3][4]) 49 { 50 int result = 0; 51 for (int i = 0; i < 2; ++i) 52 for (int j = 0; j < 3; ++j) 53 for (int k = 0; k < 4; ++k) 54 result += v[i][j][k]; 55 return result; 56 } 57 struct S 58 { 59 int a[2][3][4]; 60 }; 61 int main() 62 { 63 // 2 dimensions. 64 int *p = (int *) twoD; 65 for (int i = 0; i < 15; ++i) 66 p[i] = 100 + i; 67 for (int i = 0; i < 3; ++i) 68 for (int j = 0; j < 5; ++j) 69 { 70 int expected = 100 + i * 5 + j; 71 if (twoD[i][j] != expected) 72 { 73 printf("ERROR: line %d: twoD[%d][%d] == %d, expected %d\n", 74 __LINE__, i, j, twoD[i][j], expected); 75 exit(1); 76 } 77 } 78 79 // Constant indexes. 80 twoD[2][4] = 244; 81 assert_eq(twoD[2][4], 244); 82 83 for (int i = 0; i < 3; ++i) 84 for (int j = 0; j < 5; ++j) 85 twoD[i][j] = 200 - i * 5 - j; 86 for (int i = 0; i < 3; ++i) 87 for (int j = 0; j < 5; ++j) 88 { 89 int *actualAddress = &twoD[i][j]; 90 unsigned actualOffset = actualAddress - twoD; 91 assert_eq(actualOffset, i * 5 + j); 92 93 assert_eq(twoD[i][j], 200 - i * 5 - j); 94 } 95 96 int sum = 0; 97 98 // 3 dimensions. 99 p = (int *) threeD; 100 for (int i = 0; i < 60; ++i) 101 p[i] = 100 + i; 102 for (int i = 0; i < 4; ++i) 103 for (int j = 0; j < 3; ++j) 104 for (int k = 0; k < 5; ++k) 105 { 106 int *actualAddress = &threeD[i][j][k]; 107 unsigned actualOffset = actualAddress - threeD; 108 assert_eq(actualOffset, i * 15 + j * 5 + k); 109 110 int expected = 100 + i * 15 + j * 5 + k; 111 if (threeD[i][j][k] != expected) 112 { 113 printf("ERROR: line %d: threeD[%d][%d][%d] == %d, expected %d\n", 114 __LINE__, i, j, k, threeD[i][j][k], expected); 115 exit(1); 116 } 117 int temp = threeD[i][j][k]; 118 ++threeD[i][j][k]; 119 assert_eq(threeD[i][j][k], temp + 1); 120 } 121 122 // Constant indexes. 123 threeD[3][2][4] = 1000; 124 assert_eq(threeD[3][2][4], 1000); 125 126 // Size of first dimension specified by initializer. 127 sum = 0; 128 for (int i = 0; i < 4; ++i) 129 for (int j = 0; j < 2; ++j) 130 for (int k = 0; k < 3; ++k) 131 sum += v[i][j][k]; 132 assert_eq(sum, 660); 133 134 // Bytes. 135 sum = 0; 136 for (int i = 0; i < 4; ++i) 137 for (int j = 0; j < 2; ++j) 138 for (int k = 0; k < 3; ++k) 139 sum += b[i][j][k]; 140 assert_eq(sum, 660 + 400); 141 142 // Multi-dim. array of structs. 143 sum = 0; 144 for (int i = 0; i < 2; ++i) 145 for (int j = 0; j < 3; ++j) 146 sum += s[i][j].x + s[i][j].y + s[i][j].z; 147 assert_eq(sum, 171); 148 149 // Struct containing multi-dim array member. 150 struct S s; 151 assert_eq(sizeof(s), sizeof(int) * 2 * 3 * 4); 152 memset(&s, 0, sizeof(s)); 153 s.a[0][0][0] = 42; 154 assert_eq(s.a[0][0][0], 42); 155 s.a[1][2][3] = 1844; 156 assert_eq(s.a[1][2][3], 1844); 157 assert_eq(computeSum(s.a), 42 + 1844); 158 159 return 0; 160 } 161 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 78: Function parameter of array type (one or more dimensions) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int f(int a[], int i) 25 { 26 return a[i]; 27 } 28 int g(int a[][3], int i, int j) 29 { 30 return a[i][j]; 31 } 32 int h(int a[][3][3], int i, int j, int k) 33 { 34 return a[i][j][k]; 35 } 36 int *fptr(int a[], int i) 37 { 38 return &a[i]; 39 } 40 int *gptr(int a[][3], int i, int j) 41 { 42 return &a[i][j]; 43 } 44 int *hptr(int a[][3][3], int i, int j, int k) 45 { 46 return &a[i][j][k]; 47 } 48 int *getArray2(int a[][3], int i) 49 { 50 return a[i]; 51 } 52 int *getArray3(int a[][3][3], int i, int j) 53 { 54 return a[i][j]; 55 } 56 void checkConstIndexes(int a[][3]) 57 { 58 int *p = &a[4][2]; 59 assert_eq(p - a, 4 * 3 + 2); 60 61 int i = 2, j = 5; 62 p = &a[i][j]; 63 assert_eq(p - a, 2 * 3 + 5); 64 } 65 int main() 66 { 67 int v1[] = { 5, 6, 7, 8 }; 68 assert_eq(f(v1, 2), 7); 69 int v2[][3] = { { 9, 8, 7 }, { 99, 88, 77 }, { 66, 55, 44 } }; 70 assert_eq(f(v2[1], 2), 77); // v2[1] points to { 99, 88, 77 } 71 assert_eq(g(v2, 1, 2), 77); 72 int v3[][3][3] = 73 { 74 { 75 { 9, 8, 7 }, 76 { 99, 88, 77 }, 77 { 66, 55, 44 } 78 }, 79 { 80 { 19, 18, 17 }, 81 { 199, 188, 177 }, 82 { 166, 155, 144 } 83 } 84 }; 85 assert_eq(h(v3, 1, 2, 1), 155); 86 87 assert_eq(sizeof(v1), 2 * 4); 88 assert_eq(sizeof(v2), 2 * 3 * 3); 89 assert_eq(sizeof(v3), 2 * 2 * 3 * 3); 90 91 int sum; 92 93 sum = 0; 94 for (int i = 0; i < 4; ++i) 95 sum += f(v1, i); 96 assert_eq(sum, (int)5+6+7+8); 97 98 sum = 0; 99 for (int i = 0; i < 3; ++i) 100 for (int j = 0; j < 3; ++j) 101 sum += g(v2, i, j); 102 assert_eq(sum, (int)9+8+7 + (int)99+88+77 + (int)66+55+44); 103 104 sum = 0; 105 for (int i = 0; i < 2; ++i) 106 for (int j = 0; j < 3; ++j) 107 for (int k = 0; k < 3; ++k) 108 sum += h(v3, i, j, k); 109 assert_eq(sum, 1536); 110 111 // Test functions like f, g, h but that return pointers. 112 // 113 *fptr(v1, 2) = 4545; 114 assert_eq(f(v1, 2), 4545); 115 *gptr(v2, 1, 2) = 9876; 116 assert_eq(g(v2, 1, 2), 9876); 117 *hptr(v3, 1, 2, 1) = 1234; 118 assert_eq(h(v3, 1, 2, 1), 1234); 119 120 // Test functions that return an array. 121 // 122 assert_eq(getArray2(v2, 2)[1], 55); 123 assert_eq(getArray3(v3, 1, 1)[1], 188); 124 125 int aa[1][3] = { { 1, 2, 3 } }; 126 checkConstIndexes(aa); 127 128 return 0; 129 } 130 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 79: switch() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int testSwitch1(int n) 25 { 26 int ret = 7777; 27 switch (n) 28 { 29 case -3: 30 return 100; 31 case 0: 32 ret = 101; 33 break; 34 case 5: 35 ret = 102; 36 // FALLTHROUGH 37 case 2: 38 ret = 103; 39 break; 40 default: 41 ret = 999; 42 } 43 return ret; 44 } 45 int testSwitch2(int n) // default in the middle 46 { 47 int ret = 7777; 48 switch (n) 49 { 50 case -3: 51 return 100; 52 default: 53 ret = 999; 54 break; 55 case 0: 56 ret = 101; 57 break; 58 case 5: 59 ret = 102; 60 // FALLTHROUGH 61 case 2: 62 ret = 103; 63 } 64 return ret; 65 } 66 int testSwitch3(char n) // byte expression, default in the middle 67 { 68 int ret = 7777; 69 switch (n) 70 { 71 case -3: 72 return 100; 73 default: 74 ret = 999; 75 break; 76 case 0: 77 ret = 101; 78 break; 79 case 5: 80 ret = 102; 81 // FALLTHROUGH 82 case 2: 83 ret = 103; 84 85 } 86 87 return ret; 88 } 89 char testSwitch4(char n) 90 { 91 switch (n) 92 { 93 case 2: 94 case 8: 95 case 11: // jack 96 return 0; 97 default: 98 return 1; 99 } 100 } 101 int main() 102 { 103 assert_eq(testSwitch1(-3), 100); 104 assert_eq(testSwitch1( 0), 101); 105 assert_eq(testSwitch1( 5), 103); 106 assert_eq(testSwitch1( 2), 103); 107 assert_eq(testSwitch1(-9), 999); 108 109 assert_eq(testSwitch2(-3), 100); 110 assert_eq(testSwitch2( 0), 101); 111 assert_eq(testSwitch2( 5), 103); 112 assert_eq(testSwitch2( 2), 103); 113 assert_eq(testSwitch2(-9), 999); 114 115 assert_eq(testSwitch3(-3), 100); 116 assert_eq(testSwitch3( 0), 101); 117 assert_eq(testSwitch2( 5), 103); 118 assert_eq(testSwitch3( 2), 103); 119 assert_eq(testSwitch3(-9), 999); 120 121 assert_eq(testSwitch4(2), 0); 122 assert_eq(testSwitch4(8), 0); 123 assert_eq(testSwitch4(11), 0); 124 assert_eq(testSwitch4(13), 1); 125 126 // break inside an if(). 127 int n = 17; 128 switch (3) 129 { 130 case 3: 131 if (n == 17) 132 { 133 n = 88; 134 break; 135 } 136 case 4: 137 n = 99; 138 break; 139 } 140 assert_eq(n, 88); 141 142 return 0; 143 } 144 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 80: break vs. switch in a switch 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char testSwitchInASwitch(byte a, byte b) 25 { 26 //printf("testSwitchInASwitch(a=%u, b=%u): start\n", a, b); 27 byte iter = 0; 28 switch (a) 29 { 30 case 10: 31 //printf("case 10\n"); 32 switch (b) 33 { 34 case 22: 35 //printf("case 22\n"); 36 break; 37 default: 38 return 1; 39 } 40 //printf("iter=%u\n", iter); 41 if (++iter > 1) 42 return 2; 43 break; // With CMOC <= 0.1.22, we'd jump to end of inner switch(), 44 // causing infinite loop, which 'iter' detects. 45 // Cause: Missing call to popBreakableLabels() 46 // in SwitchStmt::emitCode(). 47 } 48 //printf("testSwitchInASwitch: end\n"); 49 return 0; // supposed to come here 50 } 51 int main() 52 { 53 byte result = testSwitchInASwitch(10, 22); 54 assert_eq(result, 0); 55 return 0; 56 } 57 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 81: break vs. switch in a loop 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char testSwitchInAFor(byte b) 25 { 26 byte iter = 0; 27 for (;;) 28 { 29 switch (b) 30 { 31 case 22: 32 //printf("case 22\n"); 33 break; 34 default: 35 return 1; 36 } 37 //printf("iter=%u\n", iter); 38 if (++iter > 1) 39 return 2; 40 break; 41 } 42 return 0; // supposed to come here 43 } 44 char testSwitchInAWhile(byte b) 45 { 46 byte iter = 0; 47 while (1) 48 { 49 switch (b) 50 { 51 case 22: 52 //printf("case 22\n"); 53 break; 54 default: 55 return 1; 56 } 57 //printf("iter=%u\n", iter); 58 if (++iter > 1) 59 return 2; 60 break; 61 } 62 return 0; // supposed to come here 63 } 64 char testSwitchInADoWhile(byte b) 65 { 66 byte iter = 0; 67 do 68 { 69 switch (b) 70 { 71 case 22: 72 //printf("case 22\n"); 73 break; 74 default: 75 return 1; 76 } 77 //printf("iter=%u\n", iter); 78 if (++iter > 1) 79 return 2; 80 break; 81 } while (1); 82 return 0; // supposed to come here 83 } 84 char testForInSwitch(byte b) 85 { 86 byte iter = 0; 87 switch (b) 88 { 89 case 22: 90 for (;;) 91 { 92 break; 93 } 94 if (++iter > 1) 95 return 2; 96 break; 97 default: 98 return 1; 99 } 100 return 0; // supposed to come here 101 } 102 int main() 103 { 104 byte result = testSwitchInAFor(22); 105 assert_eq(result, 0); 106 result = testSwitchInAWhile(22); 107 assert_eq(result, 0); 108 result = testSwitchInADoWhile(22); 109 assert_eq(result, 0); 110 result = testForInSwitch(22); 111 assert_eq(result, 0); 112 return 0; 113 } 114 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 82: Function pointer in an array or a struct 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int f() { return 99; } 25 struct S { 26 void *funcPtr; 27 }; 28 int main() 29 { 30 void *funcPtrs[] = { f }; 31 assert_eq(funcPtrs[0](), 99); 32 assert_eq((*funcPtrs[0])(), 99); 33 34 struct S s = { f }; 35 assert_eq(s.funcPtr, f); 36 assert_eq(s.funcPtr(), 99); 37 assert_eq((*s.funcPtr)(), 99); 38 return 0; 39 } 40 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 83: +=, -= 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 char a = 42; 27 char b = 11; 28 a += b; 29 assert_eq(a, 53); 30 a -= b; 31 assert_eq(a, 42); 32 33 int c = 4000; 34 int d = 123; 35 c += d; 36 assert_eq(c, 4123); 37 c -= d; 38 assert_eq(c, 4000); 39 40 return 0; 41 } 42 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 84: +=, -=, *= operators with right-hand side of pointer type 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 typedef unsigned char *FuncPtr; 25 int main() 26 { 27 FuncPtr origISR = 0xFEF7; 28 29 FuncPtr finalAddr = 0x0212; 30 finalAddr += 0xFEFA; 31 assert_eq(finalAddr, 0x010C); 32 33 finalAddr = 0x0212; 34 finalAddr += origISR + 3; 35 assert_eq(finalAddr, 0x010C); 36 37 finalAddr = 0x0212; 38 finalAddr += origISR; 39 assert_eq(finalAddr, 0x0109); 40 41 finalAddr = 0x0212; 42 origISR = 0x0101; 43 finalAddr -= origISR; 44 assert_eq(finalAddr, 0x0111); 45 46 finalAddr = 0x0212; 47 origISR = 3; 48 finalAddr *= origISR; 49 assert_eq(finalAddr, 0x0636); 50 51 finalAddr = 0x0212; 52 origISR = 2; 53 finalAddr /= origISR; 54 assert_eq(finalAddr, 0x0109); 55 56 return 0; 57 } 58 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 85: #pragma const_data 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 // Read-only globals go after 5C00. 25 // Writable globals go after 4F00. 26 char f() { return 99; } 27 int writable = 42; 28 char runTimeInit = f(); 29 #pragma const_data start 30 unsigned char readonly[] = { 9, 8, 7, 6 }; 31 #pragma const_data end 32 int main() 33 { 34 assert_eq(writable, 42); 35 assert_eq(runTimeInit, 99); 36 assert_eq(readonly[2], 7); 37 38 assert(&writable >= (void *) 0x4F00 && &writable < 0x5000); 39 assert(&runTimeInit >= (void *) 0x4F00 && &runTimeInit < 0x5000); 40 assert(readonly > (void *) 0x5C00); 41 42 return 0; 43 } 44 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror --org=5C00 --data=4F00 ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $5c00 (23552) Data address: $4f00 (20224) Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 86: #pragma exec_once 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 #pragma exec_once 25 int main() 26 { 27 char *_program_end; 28 char *_INITGL; 29 asm { 30 leax program_end,pcr 31 stx _program_end 32 leax INITGL,pcr 33 stx _INITGL 34 } 35 assert(_program_end == _INITGL); 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 87: Absence of #pragma exec_once 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 char *_program_end; 27 char *_INITGL; 28 asm { 29 leax program_end,pcr 30 stx _program_end 31 leax INITGL,pcr 32 stx _INITGL 33 } 34 assert(_program_end > _INITGL); 35 return 0; 36 } 37 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 88: --check-null option to detect null pointer accesses 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void nullPointerHandler(void *addressOfFailedCheck) 25 { 26 assert(addressOfFailedCheck >= 0x4000 && addressOfFailedCheck < 0x5000); 27 exit(1); 28 } 29 int main() 30 { 31 set_null_ptr_handler(nullPointerHandler); 32 char *p = 0; 33 char c = *p; // must trigger call to nullPointerHandler() 34 return 0; 35 } 36 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror --check-null ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 89: --check-stack option to detect stack overflows 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void stackOverflowHandler(void *addressOfFailedCheck, void *stackRegister) 25 { 26 //printf("[%p, %p]\n", addressOfFailedCheck, stackRegister); 27 assert(addressOfFailedCheck >= 0x4000 && addressOfFailedCheck < 0x5000); 28 assert(stackRegister >= 0xFA00 && stackRegister < 0xFE00); // 1k of stack space 29 exit(1); 30 } 31 void recurse() { recurse(); } 32 int main() 33 { 34 set_stack_overflow_handler(stackOverflowHandler); 35 recurse(); 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror --check-stack ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 90: Typical C copying idiom 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 char *str = "foobar"; 27 char *src; 28 for (src = str; *src++; ) 29 ; 30 assert_eq(src - str, 7); 31 32 for (src = str; *src; src++) 33 ; 34 assert_eq(src - str, 6); 35 36 char a[7]; 37 memset(a, 'X', sizeof(a)); 38 char *dest; 39 for (src = str, dest = a; *src; ) 40 *dest++ = *src++; 41 assert_eq(*dest, 'X'); 42 *dest = '\0'; 43 printf("%s\n", a); 44 assert_eq(strcmp(a, "foobar"), 0); 45 assert_eq(src - str, 6); 46 assert_eq(*src, 0); 47 return 0; 48 } 49 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: foobar --- Actual output: foobar -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 91: Adding a constant to an array address received as an argument 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char *f(char *p) 25 { 26 //printf("p=%p\n", p); 27 return p; 28 } 29 void g(char a[12]) 30 { 31 char *p0 = f(a); 32 char *p6 = f(a + 6); // bug was in BinaryOpExpr::emitAddImmediateToVariable() 33 assert_eq(p6 - p0, 6); 34 } 35 int main() 36 { 37 char v[12]; 38 g(v); 39 return 0; 40 } 41 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 92: sprintf(), putstr(), putchar() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 char buf[10]; 27 assert_eq(sizeof(buf), 10); 28 memset(buf, '#', sizeof(buf)); 29 putstr(buf, sizeof(buf)); 30 putchar('\n'); 31 32 sprintf(buf, "foo%s%u", "bar", 777); 33 printf("L1: [%s]\n", buf); 34 assert_eq(buf[sizeof(buf) - 1], 0); 35 assert_eq(strcmp(buf, "foobar777"), 0); 36 37 printf("L2\n"); 38 sprintf(buf, ""); 39 printf("L3: [%u]\n", strlen(buf)); 40 assert_eq(strlen(buf), 0); 41 42 // Field width > 255. 43 char temp[260]; 44 memset(temp, 'X', 260); 45 sprintf(temp, "%258s", ' '); // overwrite 0..258; don't overwrite last 'X' 46 assert(temp[258] == 0); 47 assert(temp[259] == 'X'); 48 for (int i = 0; i < 258; ++i) 49 assert(temp[i] == ' '); 50 return 0; 51 } 52 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: ########## L1: [foobar777] L2 L3: [0] --- Actual output: ########## L1: [foobar777] L2 L3: [0] -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 93: sprintf() without printf() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 char buf[2]; 27 sprintf(buf, "$"); 28 // We do not use an assert macro because it calls printf(). 29 if (buf[0] != '$') 30 putstr("ERR""OR: sprintf() did not write '$' in buf[].\n", 45); // error keyword cut to avoid false negative in smoke test 31 return 0; 32 } 33 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 94: Size of pointed type in the case of multi-dim array 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 // Size of pointed type, in the case of multi-dim array, 25 // is the product of array dimensions, ignoring the first dimension. 26 27 int a[5][7][13]; // pointed type here is int[7][13], i.e., a[i] designates 91 ints 28 unsigned char e[3][7]; 29 int main() 30 { 31 int *p0 = (int *) a[0]; 32 int *p1 = (int *) a[1]; 33 assert_eq(p1 - p0, 7 * 13); 34 35 char c = 34; 36 unsigned char *src = (unsigned char *) e + (c - ' ') * 7; 37 assert_eq(src - (unsigned char *) e, 14); 38 39 return 0; 40 } 41 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 95: Optimization of assignments of zero 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 unsigned char uc; 27 uc = 0; 28 assert_eq(uc, 0); 29 uc = 42; 30 assert_eq(uc, 42); 31 unsigned u; 32 u = 0; 33 assert_eq(u, 0); 34 u = 4242; 35 assert_eq(u, 4242); 36 37 // Signed cases. 38 char b; 39 b = 0; 40 assert_eq(b, 0); 41 b = -42; 42 assert_eq(b, -42); 43 int i; 44 i = 0; 45 assert_eq(i, 0); 46 i = -42; 47 assert_eq(i, -42); 48 i = -4242; 49 assert_eq(i, -4242); 50 return 0; 51 } 52 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 96: Multiplication 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char fc(char c) { return c; } 25 int fi(int n) { return n; } 26 int main() 27 { 28 { 29 byte b0 = 3; 30 byte b1 = 5; 31 byte b2 = b0 * b1; 32 assert_eq(b2, 15); 33 b2 = b0 * 6; 34 assert_eq(b2, 18); 35 b2 = 4 * b1; 36 assert_eq(b2, 20); 37 38 // Check that other binary operators accept an int constant and still return a byte. 39 b2 = b0 / 6; 40 b2 = b0 % 6; 41 b2 = b0 + 6; 42 b2 = b0 - 6; 43 b2 = 6 / b0; 44 b2 = 6 % b0; 45 b2 = 6 + b0; 46 b2 = 6 - b0; 47 48 b0 = 10; 49 assert_eq(b0 * 160, 64); // mul done in 8 bits 50 assert_eq((word) b0 * 160, 1600); 51 assert_eq(160 * (word) b0, 1600); 52 53 byte b = 3; 54 assert_eq(b * 2, 6); 55 assert_eq(b * 4, 12); 56 assert_eq(b * 8, 24); 57 assert_eq(b * 16, 48); 58 assert_eq(b * 32, 96); 59 assert_eq(b * 64, 192); 60 assert_eq(2 * b, 6); 61 assert_eq(4 * b, 12); 62 assert_eq(8 * b, 24); 63 assert_eq(16 * b, 48); 64 assert_eq(32 * b, 96); 65 assert_eq(64 * b, 192); 66 67 // Special cases: 68 assert_eq(b * 0, 0); 69 assert_eq(0 * b, 0); 70 assert_eq(b * 1, 3); 71 assert_eq(1 * b, 3); 72 73 // Mult. by shifting: 74 assert_eq(b * 2, 6); 75 assert_eq(2 * b, 6); 76 assert_eq(b * 4, 12); 77 assert_eq(4 * b, 12); 78 assert_eq(b * 32, 96); 79 assert_eq(32 * b, 96); 80 assert_eq(b * 64, 192); 81 assert_eq(64 * b, 192); 82 } 83 84 { 85 word w0 = 250; 86 word w1 = 251; 87 word w2 = w0 * w1; 88 assert_eq(w2, 62750); 89 w2 = w0 * 252; 90 assert_eq(w2, 63000); 91 w2 = 249 * w1; 92 assert_eq(w2, 62499); 93 } 94 95 // Signed cases. 96 { 97 char c0 = -3; 98 char c1 = 5; 99 char c2 = c0 * c1; 100 assert_eq(c2, -15); 101 c2 = c0 * 6; 102 assert_eq(c2, -18); 103 c2 = -4 * c1; 104 assert_eq(c2, -20); 105 c2 = c1 * -8; 106 assert_eq(c2, -40); 107 c2 = -4 * 5; 108 assert_eq(c2, -20); 109 c2 = 5 * -8; 110 assert_eq(c2, -40); 111 c2 = -6 * -8; 112 assert_eq(c2, +48); 113 c2 = -4 * c0; 114 assert_eq(c2, 12); 115 116 assert_eq(fc(-3) * fc(5), -15); 117 assert_eq(fc(-3) * fc(6), -18); 118 assert_eq(fc(-4) * fc(5), -20); 119 assert_eq(fc(-4) * fc(-3), 12); 120 121 c2 = -50 / c1; 122 assert_eq(c2, -10); 123 } 124 125 { 126 int i0 = -300; 127 int i1 = 100; 128 int i2 = i0 * i1; 129 assert_eq(i2, -30000); 130 i2 = i0 * 99; 131 assert_eq(i2, -29700); 132 i2 = i0 * -99; 133 assert_eq(i2, 29700); 134 i2 = -299 * i1; 135 assert_eq(i2, -29900); 136 137 assert_eq(fi(-300) * fi(100), -30000); 138 assert_eq(fi(-300) * fi(99), -29700); 139 assert_eq(fi(-299) * fi(100), -29900); 140 assert_eq(fi(-299) * fi(-100), 29900); 141 } 142 143 return 0; 144 } 145 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 97: Assembly-only function 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int global0 = 42; 25 int asm f(int m, int n) // no stack frame because of 'asm' modifier 26 { 27 // U not pushed, so 1st arg is at 2,s 28 asm { 29 ldd 2,s // load m 30 addd 4,s // add n, leave sum in D 31 } 32 asm { // more than one asm{} statement allowed, although not useful 33 nop 34 } 35 } 36 unsigned char asm g(int m, int n) 37 { 38 asm { 39 ldd 2,s 40 addd 4,s 41 inca // function returns byte, so trashing A must not matter 42 } 43 } 44 int asm h() 45 { 46 asm { 47 ldd global0 48 } 49 } 50 int asm q() 51 { 52 asm("ldd", global0); 53 } 54 int main() 55 { 56 assert_eq(f(3000, 1299), 4299); 57 assert_eq(g(3000, 1299), 4299 % 256); 58 assert_eq(4299 % 256, 203); 59 assert_eq(h(), 42); 60 assert_eq(q(), 42); 61 return 0; 62 } 63 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 98: Subtraction without spaces surrounding the minus sign 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 int k = 5; 27 int n = k-4; // k-4 must be seen as tokens 'k', '-', '4', not, 'k' and '-4' 28 assert_eq(n, 1); 29 assert_eq(99-88, 11); 30 return 0; 31 } 32 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 99: Draw lines of pixels in two diagonals across a 640x192 screen 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 word xx; 27 xx = 328; 28 assert_eq(xx * 100 / 333, (word) 98); 29 for(xx=0; xx<640; xx++) { 30 word y0 = ((xx+1)*100)/333 - 1; 31 word y1 = 191 - (((xx+1)*100)/333 - 1); 32 //printf("%5u %5u %5u\n", xx, y0, y1); 33 assert_range((int) y0, -1, 191); 34 assert_range(y1, 0, 192); 35 } 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 100: No sign extension when passing argument of form unsigned-byte-expr & 8-bit-const 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 // Correctly determine signedness of unsigned-byte-expression & 8-bit-constant, 25 // so that no sign extension is done on argument passing. 26 27 unsigned f(unsigned char b) 28 { 29 unsigned receivedWord; 30 asm { 31 ldd 4,u 32 std receivedWord 33 } 34 //printf("receivedWord=$%04X\n", receivedWord); 35 assert_eq(receivedWord & 0xFF00, 0); // no sign extension expected when passing argument to f() 36 assert_eq(b, 0x80); 37 return b; 38 } 39 int main() 40 { 41 unsigned w0 = 0x8A; 42 unsigned w1 = f((byte) (w0 & 0x80)); // 2-byte bitwise AND, result cast to byte 43 assert_eq(w1, 0x80); 44 45 // Operands of & are byte and word, but 0x80 fits in a byte, so is seen as byte. 46 // Sign of result of & is unsigned because operands have different signedness 47 // (unsigned on left, signed int on right). 48 unsigned w2 = f(((byte) w0) & 0x80); 49 assert_eq(w2, 0x80); 50 return 0; 51 } 52 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 101: Product of small positive integers can give negative 16-bit result 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 assert_eq(320 * 200, 0xFA00); 27 assert_eq(320 * 200, -1536); // mul is signed because operands are both signed 28 assert_eq(320 * 200 / 2, 0xFD00); // div is signed, so 0xFA00 gets ASR 29 assert_eq(320 * 200 / 2, -768); 30 assert_eq((unsigned) 320 * 200, 64000); 31 assert_eq((unsigned) 320 * 200 / 2, 32000); 32 return 0; 33 } 34 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 102: Redefining a function provided by stdlib.inc 1 2 // cmoc.h not included, so we need to declare this. 3 // Note unsigned instead of size_t, just for giggles. 4 void putstr(char *s, unsigned n); 5 void putchar(int i) 6 { 7 char a[] = { '[', (char) i, ']', '\n' }; 8 putstr(a, 4); 9 } 10 void rand(int a, int b) // different arguments than in stdlib.inc 11 { 12 putstr("rand(int, int)\n", 15); 13 } 14 int main() 15 { 16 putchar('C'); 17 rand(8, 9); 18 return 0; 19 } 20 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 cmoc: __warning__: multiple definitions of symbol _putchar in modules ,check-prog.o, putchar_a.usim_o --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: [C] rand(int, int) --- Actual output: [C] rand(int, int) -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 103: Signed multiplication, division, modulo 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int multiply(int dividend, int divisor) 25 { 26 return dividend * divisor; 27 } 28 int divide(int dividend, int divisor) 29 { 30 return dividend / divisor; 31 } 32 int modulo(int dividend, int divisor) 33 { 34 return dividend % divisor; 35 } 36 char multiplyc(char dividend, char divisor) 37 { 38 return dividend * divisor; 39 } 40 char dividec(char dividend, char divisor) 41 { 42 return dividend / divisor; 43 } 44 char moduloc(char dividend, char divisor) 45 { 46 return dividend % divisor; 47 } 48 byte multiplyuc(byte dividend, byte divisor) 49 { 50 return dividend * divisor; 51 } 52 byte divideuc(byte dividend, byte divisor) 53 { 54 return dividend / divisor; 55 } 56 byte modulouc(byte dividend, byte divisor) 57 { 58 return dividend % divisor; 59 } 60 int main() 61 { 62 // Test operations with non-constant operands, via function. 63 assert_eq(multiply(+1000, +25), +25000); 64 assert_eq(multiply(-1000, +25), -25000); 65 assert_eq(multiply(+1000, -25), -25000); 66 assert_eq(multiply(-1000, -25), +25000); 67 68 assert_eq(divide(+1000, +25), +40); 69 assert_eq(divide(-1000, +25), -40); 70 assert_eq(divide(+1000, -25), -40); 71 assert_eq(divide(-1000, -25), +40); 72 73 assert_eq(modulo(+1000, +33), +10); // 1000 - 10 == 990, which is divisible by 33 74 assert_eq(modulo(-1000, +33), -10); // -1000 - (-10) == -990, which is divisible by 33 75 assert_eq(modulo(+1000, -33), +10); // negative divisor gives same modulo as positive one 76 assert_eq(modulo(-1000, -33), -10); 77 78 // Test operations with constant operands (may get optimized). 79 assert_eq(+1000 * +25, +25000); 80 assert_eq(-1000 * +25, -25000); 81 assert_eq(+1000 * -25, -25000); 82 assert_eq(-1000 * -25, +25000); 83 84 assert_eq(+1000 / +25, +40); 85 assert_eq(-1000 / +25, -40); 86 assert_eq(+1000 / -25, -40); 87 assert_eq(-1000 / -25, +40); 88 89 assert_eq(+1000 % +33, +10); 90 assert_eq(-1000 % +33, -10); 91 assert_eq(+1000 % -33, +10); 92 assert_eq(-1000 % -33, -10); 93 94 // Test signed char operations with non-constant operands, via function. 95 assert_eq(multiplyc(+10, +5), +50); 96 assert_eq(multiplyc(-10, +5), -50); 97 assert_eq(multiplyc(+10, -5), -50); 98 assert_eq(multiplyc(-10, -5), +50); 99 100 assert_eq(dividec(+100, +25), +4); 101 assert_eq(dividec(-100, +25), -4); 102 assert_eq(dividec(+100, -25), -4); 103 assert_eq(dividec(-100, -25), +4); 104 105 assert_eq(moduloc(+100, +30), +10); // 100 - 10 == 90, which is divisible by 30 106 assert_eq(moduloc(-100, +30), -10); // -100 - (-10) == -90, which is divisible by 30 107 assert_eq(moduloc(+100, -30), +10); // negative divisor gives same modulo as positive one 108 assert_eq(moduloc(-100, -30), -10); 109 110 // Test unsigned char operations with non-constant operands, via function. 111 assert_eq(multiplyuc(+10, +25), +250); 112 assert_eq(divideuc(+200, +25), +8); 113 assert_eq(modulouc(+200, +30), +20); // 200 - 20 == 180, which is divisible by 30 114 115 // Special cases of byte division. 116 unsigned char uc = 250; 117 assert_eq(uc / (byte) 1, 250); 118 assert_eq(uc / (byte) 2, 125); 119 assert_eq(uc / (byte) 4, 62); 120 assert_eq(uc / (byte) 64, 3); 121 assert_eq(uc / (byte) 128, 1); 122 char sc = 125; 123 assert_eq(sc / (char) 1, 125); 124 assert_eq(sc / (char) 2, 62); 125 assert_eq(sc / (char) 4, 31); 126 assert_eq(sc / (char) 32, 3); 127 sc = -125; 128 assert_eq(sc / (char) 1, -125); 129 assert_eq(sc / (char) 2, -62); 130 assert_eq(sc / (char) 4, -31); 131 assert_eq(sc / (char) 32, -3); 132 133 // Special cases of byte modulo. 134 assert_eq(uc % (byte) 1, 0); 135 assert_eq(uc % (byte) 2, 0); 136 assert_eq(uc % (byte) 4, 2); 137 assert_eq(uc % (byte) 64, 58); 138 139 // Division of unsigned byte by 7 (LBSR DIV8BY7). 140 byte dividend = 0; 141 for (byte quotient = 0; quotient <= 36; ++quotient) 142 { 143 for (byte remainder = 0; remainder <= 6; ++remainder, ++dividend) 144 { 145 //printf("%3u / 7 = %2u remainder %u\n", dividend, quotient, remainder); 146 byte computedQuotient = dividend / 7; 147 assert_eq(computedQuotient, quotient); 148 byte computedRemainer = dividend % 7; 149 assert_eq(computedRemainer, remainder); 150 if (dividend == 255) 151 break; 152 } 153 if (dividend == 255) 154 break; 155 } 156 157 // Division of unsigned word by 10 (LBSR DIV16BY10). 158 { 159 word quotient = 0; 160 byte counter = 0; 161 for (word dividend = 0; ; ++dividend) 162 { 163 word computedQuotient = dividend / 10; 164 //printf("%5u / 10 = %5u\n", dividend, computedQuotient); 165 assert_eq(computedQuotient, quotient); 166 if (++counter == 10) 167 { 168 ++quotient; 169 counter = 0; 170 } 171 if (dividend == 0xFFFF) 172 break; 173 } 174 } 175 176 // Division of unsigned byte by 10. 177 { 178 byte quotient = 0; 179 byte counter = 0; 180 for (byte dividend = 0; ; ++dividend) 181 { 182 byte computedQuotient = dividend / 10; 183 //printf("%5u / 10 = %5u\n", dividend, computedQuotient); 184 assert_eq(computedQuotient, quotient); 185 if (++counter == 10) 186 { 187 ++quotient; 188 counter = 0; 189 } 190 if (dividend == 0xFF) 191 break; 192 } 193 } 194 195 // Division of signed word by 10 (does not use DIV16BY10). 196 { 197 signed quotient = -3276; 198 byte counter = 1; 199 for (signed dividend = -32768; ; ++dividend) 200 { 201 signed computedQuotient = dividend / 10; 202 //printf("%5d / 10 = %5d\n", dividend, computedQuotient); 203 assert_eq(computedQuotient, quotient); 204 if (++counter == 10) 205 { 206 if (dividend == 0) 207 counter = 1; 208 else 209 { 210 ++quotient; 211 counter = 0; 212 } 213 } 214 if (dividend == 32767) 215 break; 216 } 217 } 218 219 // Division of signed byte by 10. 220 { 221 char quotient = -12; 222 byte counter = 1; 223 for (char dividend = -128; ; ++dividend) 224 { 225 char computedQuotient = dividend / 10; 226 //printf("%5d / 10 = %5d\n", dividend, computedQuotient); 227 assert_eq(computedQuotient, quotient); 228 if (++counter == 10) 229 { 230 if (dividend == 0) 231 counter = 1; 232 else 233 { 234 ++quotient; 235 counter = 0; 236 } 237 } 238 if (dividend == 127) 239 break; 240 } 241 } 242 243 // Check optimization of non-var-non-const left side by 8. 244 byte b = 42; 245 byte n = (b + 7) / 8; 246 assert_eq(n, 6); 247 248 // Check optimization of word by power of 2. 249 word w = 42; 250 assert_eq(w / 2, 21); 251 w = 12800; 252 assert_eq(w / 128, 100); 253 assert_eq(w / 256, 50); // special case: TFR A,B; CLRA 254 w = 0xAAAA; 255 assert_eq(w / 4096, 0x000A); 256 257 // Mixed byte/word case. 258 b = 2; 259 assert_eq(w / b, 0x5555); 260 b = 200; 261 w = 8; 262 assert_eq(b / w, 25); 263 264 // Modulo. 265 byte card = 135; 266 byte v = (card - 1) % 13; 267 assert_eq(v, 4); 268 269 // Signed division by power of 2. 270 int i = 400; 271 int j = i / 2; 272 assert_eq(j, 200); 273 274 // Signed byte, 0..127. 275 char c; 276 for (c = 0; c >= 0; ++c) 277 { 278 char computed = c / 2; 279 char expected = c >> 1; 280 assert_eq(computed, expected); 281 } 282 // Signed byte, -1..-128. 283 for (c = -1; c != -128; --c) 284 { 285 char computed = c / 2; 286 char expected = -((-c) >> 1); 287 //printf("%d %d %d\n", c, computed, expected); 288 assert_eq(computed, expected); 289 } 290 assert_eq(c / 2, -64); 291 292 unsigned u0 = 0, u1 = 5; 293 assert_eq(u0 / u1, 0); 294 assert_eq(u1 / u0, 0xFFFF); // division by zero does not hang 295 296 return 0; 297 } 298 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 104: Check that a call to readline() compiles 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void f() { readline(); } 25 int main() 26 { 27 return 0; 28 } 29 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror --emit-uncalled ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 105: Check that calls to readword() and delay() compile 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void f() 25 { 26 readword(); 27 delay(42); 28 } 29 int main() 30 { 31 return 0; 32 } 33 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror --emit-uncalled ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 106: Uninitialized globals are grouped together 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int a[1]; 25 int b[1] = { 42 }; // we don't want 'b' to be emitted between 'a' and 'c' 26 int c[1]; 27 int *min(int *x, int *y) { return x < y ? x : y; } 28 int *max(int *x, int *y) { return x > y ? x : y; } 29 int main() 30 { 31 // Don't assume that 'a' is emitted before 'c'. 32 int *firstUninit = min(a, c); 33 int *secondUninit = max(a, c); 34 35 // If the two uninitialized variables are grouped together, 36 // that 'b' cannot be between them, i.e., 'b' had to be before 37 // the first or after the second. 38 assert(b < firstUninit || secondUninit < b); 39 return 0; 40 } 41 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 107: pushLoadDiscardAdd optimization (see ASMText.cpp) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte t() { return 1; } 25 byte f() { return 0; } 26 int main() 27 { 28 byte isUsersTurn = t(); 29 byte row = 30 + (isUsersTurn ? +24 : -24); // optimization on this line 30 assert_eq(row, 54); 31 isUsersTurn = f(); 32 row = 30 + (isUsersTurn ? +24 : -24); // optimization on this line 33 assert_eq(row, 6); 34 return 0; 35 } 36 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 108: pushLoadDLoadX optimization 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte f() { return 42; } 25 int main() 26 { 27 byte b = f(); 28 word w = (word) b * 32; // cast to ensure 16-bit multiplication 29 assert_eq(w, 1344); 30 word k = 10; 31 w = (word) b * k; 32 assert_eq(w, 420); 33 return 0; 34 } 35 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 109: Statement in compound statement with constant cast to void generates no code 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte t() { return 1; } 25 int main() 26 { 27 byte *bb, *aa; 28 asm { 29 before: 30 } 31 ((void) (1 + 2)); 32 asm { 33 after: 34 leax before,pcr 35 stx bb 36 leax after,pcr 37 stx aa 38 } 39 assert_eq(bb, aa); 40 return 0; 41 } 42 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 110: Optimization of complex boolean expressions 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte p1; 25 byte b1; 26 byte pend; 27 byte bend; 28 int f() 29 { 30 if (((p1 <= b1) && (pend >= b1)) 31 || ((b1 <= p1) && (bend >= p1))) 32 return 11; 33 return -11; 34 } 35 int main() 36 { 37 p1 = 10; b1 = 15; pend = 12; bend = 99; 38 assert_eq(f(), -11); // pend >= b1 fails 39 p1 = 17; 40 assert_eq(f(), 11); 41 bend = 3; 42 assert_eq(f(), -11); // p1 <= b1 fails then bend >= p1 fails 43 44 byte r = 0; 45 //printf("%u %u %u %u\n", p1, b1, bend, pend); 46 if (! (p1 < b1 || bend < pend)) 47 r = -1; 48 else 49 r = 1; 50 assert_eq(r, 1); 51 52 return 0; 53 } 54 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 111: Union 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S 25 { 26 char c; 27 int i; 28 }; 29 union Word 30 { 31 unsigned w; 32 unsigned char b[2]; 33 struct S s; 34 }; 35 int main() 36 { 37 union Word u; 38 u.w = 0x1234; 39 assert_eq(u.b[0], 0x12); 40 assert_eq(u.b[1], 0x34); 41 u.b[0] = 0x56; 42 assert_eq(u.w, 0x5634); 43 u.b[1] = 0x78; 44 assert_eq(u.w, 0x5678); 45 memcpy(u.b, "AB", 2); 46 assert_eq(u.w, 0x4142); 47 assert_eq(&u, &u.w); 48 assert_eq(&u, &u.b); 49 assert_eq(&u, &u.s); 50 assert_eq(&u, &u.s.c); 51 assert_eq((unsigned) &u + 1, &u.s.i); 52 53 assert_eq(u.w >> 8, (unsigned) u.s.c); 54 55 u.s.c = 0xAB; 56 u.s.i = 0xCDEF; 57 assert_eq(u.b[0], 0xAB); 58 assert_eq(u.b[1], 0xCD); 59 assert_eq(u.b[2], 0xEF); // reading beyond end of b[] 60 assert_eq(u.w, 0xABCD); 61 62 assert_eq(sizeof(union Word), 3); 63 assert_eq(sizeof(u), 3); 64 assert_eq(sizeof(u.w), 2); 65 assert_eq(sizeof(u.b), 2); 66 assert_eq(sizeof(u.s.c), 1); 67 assert_eq(sizeof(u.s.i), 2); 68 69 return 0; 70 } 71 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 112: Offset of members of a union 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 union U0 25 { 26 char a, b; 27 }; 28 struct S0 { int s[8]; }; 29 union U1 30 { 31 char m0; 32 int m1; 33 void *m2; 34 struct S0 m3; 35 union U0 m4; 36 }; 37 struct S1 38 { 39 int w; 40 union U0 u0; 41 union U1 u1; 42 }; 43 int main() 44 { 45 assert_eq(offsetof(union U0, a), 0); 46 assert_eq(offsetof(union U0, b), 0); 47 assert_eq(offsetof(union U1, m0), 0); 48 assert_eq(offsetof(union U1, m1), 0); 49 assert_eq(offsetof(union U1, m2), 0); 50 assert_eq(offsetof(union U1, m3), 0); 51 assert_eq(offsetof(union U1, m4), 0); 52 assert_eq(offsetof(union U1, m4.a), 0); 53 assert_eq(offsetof(union U1, m4.b), 0); 54 assert_eq(offsetof(struct S1, w), 0); 55 assert_eq(offsetof(struct S1, u0), 2); 56 assert_eq(offsetof(struct S1, u0.a), 2); 57 assert_eq(offsetof(struct S1, u0.b), 2); 58 assert_eq(offsetof(struct S1, u1), 3); 59 assert_eq(offsetof(struct S1, u1.m3), 3); 60 assert_eq(offsetof(struct S1, u1.m4), 3); 61 return 0; 62 } 63 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 113: Branch optimizations vs. inline assembly 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char f(int v) 25 { 26 char ret; 27 if (v) 28 { 29 asm 30 { 31 ldb #1 32 stb ret 33 } 34 } 35 else // optimizer must not remove branch over else clause 36 { 37 asm 38 { 39 clr ret 40 } 41 } 42 return ret; 43 } 44 int main() 45 { 46 assert_eq(f(0), 0); 47 assert_eq(f(5), 1); 48 return 0; 49 } 50 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 114: Avoid optimizing an add just because FFxx constant is a negative that fits a byte 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 byte slot = 12; 27 word p; 28 p = 0xffb0 + slot; // 16-bit operation because 0xffb0 is unsigned, there does not fit a byte 29 assert_eq(p, 0xffbc); 30 p = 65456 + slot; // same in decimal 31 assert_eq(p, 0xffbc); 32 p = -80 + slot; // 8-bit operation: -80 is represented internally as 0xffb0, but is signed, so fits a byte 33 assert_eq(p, -68); 34 return 0; 35 } 36 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 115: Character array in const_data section initialized with a string literal 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char writableText[] = "foo"; 25 26 #pragma const_data start 27 char constText[] = "bar"; 28 #pragma const_data end 29 30 char *p = "baz"; // would not be allowed in const_data: init of 'p' would have to be at run-time 31 char *q = "bar"; // uses same literal as constText[] 32 char *r = "foo"; // uses same literal as writableText[] 33 int main() 34 { 35 printf("writableText=[%s]\n", writableText); 36 printf("constText=[%s]\n", constText); 37 assert_eq(writableText[0], 'f'); 38 assert_eq(constText[2], 'r'); 39 assert_eq(p[2], 'z'); 40 assert_eq(strcmp(constText, "bar"), 0); 41 42 writableText[1] = 'X'; // modifies writableText's copy of "foo"; does not affect r 43 printf("writableText=[%s]\n", writableText); 44 assert_eq(strcmp(writableText, "fXo"), 0); 45 assert_eq(strcmp(r, "foo"), 0); 46 assert_eq(strcmp(q, "bar"), 0); 47 48 q[2] = 'Y'; // does not affect constText[], which has its own copy of "bar" 49 assert_eq(strcmp(q, "baY"), 0); 50 51 // Test constText is not affected. 52 // Do not test with string literal "bar", which is currently corrupted. 53 // (Modifying a string literal is generally a bad practice.) 54 // 55 //assert_eq(strcmp(constText, "bar"), 0); 56 printf("constText=[%s]\n", constText); 57 assert_eq(constText[0], 'b'); 58 assert_eq(constText[1], 'a'); 59 assert_eq(constText[2], 'r'); 60 assert_eq(constText[3], '\0'); 61 62 q[2] = 'r'; // restore literal "bar" (modifying a string literal is generally a bad practice) 63 printf("bar"); // test the restored literal 64 putchar('\n'); 65 66 char *local = "quux"; 67 printf("local=[%s]\n", local); 68 local = 0x1234; 69 assert_eq(local, 0x1234); 70 71 return 0; 72 } 73 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror --org=5000 --data=4C00 ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $5000 (20480) Data address: $4c00 (19456) Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: writableText=[foo] constText=[bar] writableText=[fXo] constText=[bar] bar local=[quux] --- Actual output: writableText=[foo] constText=[bar] writableText=[fXo] constText=[bar] bar local=[quux] -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 116: Promotion to int for comparisons 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int s1(char *e) 25 { 26 if (*e == (char) 0xFF) // *e compared with -1 27 return 1; 28 return 0; 29 } 30 int s2(char *e) 31 { 32 if (*e == 0xFFFF) // *e sign-extended, then compared to 0xFFFF 33 return 1; 34 return 0; 35 } 36 int u0(unsigned char *e) 37 { 38 if (*e == 0xFF) 39 return 1; 40 return 0; 41 } 42 int u1(unsigned char *e) 43 { 44 if (*e == (char) 0xFF) // *e is zero-extended, then compared with -1, i.e., 0xFFFF 45 return 1; 46 return 0; 47 } 48 int u2(unsigned char *e) 49 { 50 if (*e == 0xFFFF) // *e zero-extended, then compared to 0xFFFF 51 return 1; 52 return 0; 53 } 54 int main() 55 { 56 char c = (char) 0xFF; 57 assert_eq(s1(&c), 1); 58 assert_eq(s2(&c), 1); 59 unsigned char uc = 0xFF; 60 assert_eq(u0(&uc), 1); 61 assert_eq(u1(&uc), 0); 62 assert_eq(u2(&uc), 0); 63 return 0; 64 } 65 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 117: const_data initializer with non-trivial constant expression 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 #pragma const_data start 25 int a0[] = { 0, -1, 2 + 2, -(10 / 2) * 3 }; 26 char n = -42; 27 #pragma const_data end 28 int main() 29 { 30 assert_eq(a0[0], 0); 31 assert_eq(a0[1], -1); 32 assert_eq(a0[2], 4); 33 assert_eq(a0[3], -15); 34 assert_eq(sizeof(a0), 8); 35 assert_eq(n, -42); 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 118: Calling a C function from inline assembly 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char cFuncCalled = 0; 25 void cFunc() 26 { 27 ++cFuncCalled; 28 } 29 byte counter = 0; 30 asm byte condBranchToStart() 31 { 32 asm { 33 inc counter 34 ldb counter 35 cmpb #5 36 blo condBranchToStart 37 } 38 } 39 int main() 40 { 41 asm { 42 jsr cFunc 43 lbsr cFunc 44 leax cFunc 45 jsr ,x 46 47 // The next references to cFunc() don't call it, but we still test 48 // that the instructions are emitted correctly. 49 brn cFunc 50 lbrn cFunc 51 bra avoid 52 bra cFunc 53 lbra cFunc 54 avoid: 55 } 56 assert_eq(cFuncCalled, 3); 57 assert_eq(condBranchToStart(), 5); 58 return 0; 59 } 60 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 119: Emitting code for functon only called by LBSR in asm-only function 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char v = 99; 25 void g() { v = 42; } 26 void f() { g(); } 27 void asm asmOnly() 28 { 29 asm { 30 lbsr f 31 } 32 } 33 int main() 34 { 35 asmOnly(); 36 assert_eq(v, 42); 37 return 0; 38 } 39 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 120: Emitting code for functon only called by LBSR in non-asm-only function 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char v = 99; 25 void g() { v = 42; } 26 void f() { g(); } 27 void notAsmOnly() 28 { 29 asm { 30 lbsr f 31 } 32 } 33 int main() 34 { 35 notAsmOnly(); 36 assert_eq(v, 42); 37 return 0; 38 } 39 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 121: ASMText::optimize16BitStackOps1 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct FileDesc 25 { 26 byte drive; 27 byte firstGran; // 0..67 28 word numBytesLastSector; // 0..256 29 word length[2]; // 32-bit word giving length of file 30 byte curGran; // 0..67, 255 means at EOF 31 byte curSec; // 1..9 (relative to current granule) 32 word curGranLen; // 0..2304 33 word offset[2]; // 32-bit reading/writing offset 34 word secOffset; // 0..256: index into curSector[] (256 means beyond sector) 35 byte curSector[256]; 36 word curSectorAvailBytes; // number valid bytes in curSector[] (0..256) 37 }; 38 39 int main() 40 { 41 word offsetInLastGranule = 0x5678; 42 struct FileDesc object; 43 struct FileDesc *fd = &object; 44 fd->secOffset = offsetInLastGranule & 0xFF; // statement targeted by ASMText::optimize16BitStackOps1() 45 assert_eq(fd->secOffset, 0x78); 46 return 0; 47 } 48 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 122: ASMText::optimizeIndexedX 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct Parser 25 { 26 char *input; 27 }; 28 char buf[16]; 29 byte iter = 0; 30 void f(struct Parser *parser) 31 { 32 byte index = 0; // index in buf[] 33 for (;;++iter) // accumulate non-NUL chars in buf[] 34 { 35 byte curChar = *parser->input; 36 if (curChar) 37 { 38 if (index < sizeof(buf) - 1) // if room in buf[] 39 buf[index++] = curChar; // accept char 40 ++parser->input; // pass that char 41 } 42 else 43 break; // NUL seen: end of accumulation 44 if (iter == 10) // in case of infinite loop (3 iterations expected) 45 break; 46 } 47 assert_eq(index, 3); 48 assert_eq(buf[0], 'A'); 49 assert_eq(buf[1], 'B'); 50 assert_eq(buf[2], 'C'); 51 } 52 int main() 53 { 54 struct Parser parser; 55 char *text = "ABC"; 56 parser.input = text; 57 f(&parser); 58 assert_eq(parser.input, text + 3); 59 return 0; 60 } 61 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 123: Function pointer in member initializer of global struct instance 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S { void *fp; }; 25 byte n = 40; 26 int func() { return ++n; } 27 struct S g = { func }; 28 int main() 29 { 30 assert_eq((*g.fp)(), 41); 31 assert_eq(g.fp(), 42); 32 33 struct S loc = { func }; 34 assert_eq((*loc.fp)(), 43); 35 assert_eq(loc.fp(), 44); 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 124: Adding to a function pointer 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte n = 50; 25 void f() 26 { 27 n += 10; 28 } 29 void call0(void *fp) 30 { 31 void *fixed = fp - 42; 32 (*fixed)(); 33 } 34 void call1(void *fp) 35 { 36 void *fixed = fp + 42; 37 (*fixed)(); 38 } 39 int main() 40 { 41 call0(f + 42); 42 assert_eq(n, 60); 43 call0(42 + f); 44 assert_eq(n, 70); 45 call1(f - 42); 46 assert_eq(n, 80); 47 call1(-42 + f); 48 assert_eq(n, 90); 49 return 0; 50 } 51 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 125: Ternary expression vs. optimizer vs. LEAX 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 asm { ldx #0 } // robustness check 27 word a = 4; 28 word b = 5; 29 word c = 1; 30 (c ? a : b) = 6; 31 assert_eq(a, 6); 32 return 0; 33 } 34 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 126: optimizeStackOperations1 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct HeapBlock { 25 struct HeapBlock *prev; 26 unsigned size; 27 unsigned char b; 28 char free; 29 }; 30 31 int f() { return 1; } // must be 1 so that if() succeeds in free() 32 33 void free(struct HeapBlock *ptr) { 34 struct HeapBlock *block = ptr; 35 struct HeapBlock *next = ptr; 36 char nextIsFree = (char) f(); 37 if (f()) { 38 block->size += nextIsFree ? next->size : (unsigned) 0; // problematic line 39 } else { // else clause needed 40 f(); 41 } 42 } 43 44 void free8(struct HeapBlock *ptr) { 45 struct HeapBlock *block = ptr; 46 struct HeapBlock *next = ptr; 47 char nextIsFree = (char) f(); 48 if (f()) { 49 block->b += nextIsFree ? next->b : (unsigned char) 0; 50 } else { // else clause needed 51 f(); 52 } 53 } 54 55 int main() { 56 struct HeapBlock hb = { 0, 1000, 77, 42 }; 57 assert_eq(hb.size, 1000); 58 free(&hb); // expected to add 'size' field to itself 59 assert_eq(hb.size, 2000); 60 61 assert_eq(hb.b, 77); 62 free8(&hb); 63 assert_eq(hb.b, 154); 64 65 return 0; 66 } 67 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 127: Local asm block labels 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 asm unsigned f1() 25 { 26 asm { 27 @foo 28 leax @foo,pcr 29 tfr x,d 30 } 31 } 32 asm unsigned f2() 33 { 34 asm { 35 @foo 36 leax @foo,pcr 37 tfr x,d 38 } 39 } 40 asm void *f3() 41 { 42 asm { 43 @f1 44 leax @f1,pcr 45 tfr x,d 46 } 47 } 48 asm void f4() 49 { 50 asm { 51 leax f1 // take address of function f1() 52 tfr x,d 53 } 54 } 55 int main() 56 { 57 //printf("%p %p %p\n", f1(), f2(), f3()); 58 assert_ne(f1(), f2()); 59 assert_ne(f3(), f1); // label f1 in f3() must not refer to function f1() 60 61 f4(); 62 void *retval; 63 asm { std :retval } 64 assert_eq(retval, f1); 65 66 return 0; 67 } 68 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 128: optimize16BitStackOps1 and optimize8BitStackOps 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void f() {} 25 char c; 26 char *left = &c; 27 char store99() 28 { 29 int x, seg = 0; 30 31 f(); // this separates basic blocks 32 x = 99; // value to be put in left[0] 33 f(); // this separates basic blocks 34 35 // Problematic statement: the right side of this assignment 36 // loaded variable x with LDB using the address of the high byte 37 // instead of the low byte. 38 // 39 left[seg] = (char) x; 40 41 return 0; 42 } 43 int main() 44 { 45 store99(); 46 //printf("%d\n", left[0]); 47 assert_eq(left[0], 99); 48 return 0; 49 } 50 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 129: 2016-06-08 optimization fixes 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct Vect { 25 int x; 26 }; 27 28 struct BigVect { 29 struct Vect x; 30 }; 31 32 void test1() { 33 int vals[10]; 34 int ii; 35 unsigned char bvals[10]; 36 for(ii=0; ii> shift_amount) & (byte)(0xff << shift_amount)); 64 65 assert_eq(val, 0x81); 66 } 67 68 int main() { 69 test1(); 70 test2(); 71 test3(); 72 return 0; 73 } 74 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 130: No-argument function declared with (void) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int noArg(void) 25 { 26 return 42; 27 } 28 int main(void) 29 { 30 assert_eq(noArg(), 42); 31 return 0; 32 } 33 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 131: Function pointer syntax 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char counter; 25 void unnamedArgFunc(int) 26 { 27 ++counter; 28 } 29 void unnamedPointerArgFunc(int *) 30 { 31 ++counter; 32 } 33 void unnamedArrayArgFunc(int []) 34 { 35 ++counter; 36 } 37 void unnamed2DArrayArgFunc(int [][5]) 38 { 39 ++counter; 40 } 41 void unnamedFuncPtrArgFunc(int (*)()) 42 { 43 ++counter; 44 } 45 struct S { int n; }; 46 void unnamedStructArgFunc(struct S *) 47 { 48 ++counter; 49 } 50 void unnamedStructArrayArgFunc(struct S []) 51 { 52 ++counter; 53 } 54 int mix2(int, int b) // an unnamed arg does not prevent using a named arg 55 { 56 return b + 1; 57 } 58 int fi0() 59 { 60 return 42; 61 } 62 int fi2(int i, char c) 63 { 64 return i + c; 65 } 66 int invokeCallbackNoArgRetInt(int (*cb)()) 67 { 68 return cb(); 69 } 70 int invokeCallback2ArgsRetInt(int (*cb)(int, char c)) 71 { 72 return (*cb)(1000, -5); 73 } 74 char fc0() 75 { 76 char c = '$'; 77 asm { 78 lda #$EE // put garbage in A 79 } 80 return c; // only LDB emitted since function returns byte 81 } 82 int main() 83 { 84 int (*funcPtr0)() = fi0; 85 assert_eq((*funcPtr0)(), 42); 86 assert_eq(funcPtr0(), 42); 87 assert_eq(invokeCallbackNoArgRetInt(fi0), 42); 88 89 assert_eq((fi0)(), 42); // ordinary call, but with name in () 90 91 int (*funcPtr2)(int i, char) = fi2; 92 assert_eq((*funcPtr2)(10, 2), 12); 93 assert_eq(funcPtr2(30, 7), 37); 94 assert_eq(invokeCallback2ArgsRetInt(fi2), 995); 95 96 int (*funcPtr0c)() = fc0; 97 assert_eq((char) funcPtr0c(), '$'); // cast necessary under CMOC, which assumes return type is int 98 99 // Call the unnamed argument functions: 100 counter = 0; 101 int i = 42; 102 unnamedArgFunc(i); 103 unnamedPointerArgFunc(&i); 104 int a[] = { 9, 8, 7 }; 105 unnamedArrayArgFunc(a); 106 int aa[][5] = { { 5, 4, 3, 2, 1 }, { 55, 44, 33, 22, 11 } }; 107 unnamed2DArrayArgFunc(aa); 108 unnamedFuncPtrArgFunc(fi0); 109 struct S s = { 42 }; 110 unnamedStructArgFunc(&s); 111 struct S as[2] = { { 43 }, { 44 } }; 112 unnamedStructArrayArgFunc(as); 113 114 assert_eq(counter, 7); 115 116 assert_eq(mix2(4, 7), 8); 117 118 return 0; 119 } 120 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 132: Anonymous struct 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct 25 { 26 int n; 27 } a; 28 struct S 29 { 30 struct 31 { 32 char c; 33 } cc; 34 struct 35 { 36 int w[2]; 37 } ww; 38 int m; 39 }; 40 int main() 41 { 42 a.n = 42; 43 assert_eq(a.n, 42); 44 45 struct S s; 46 s.cc.c = '#'; 47 s.ww.w[0] = 2000; 48 s.ww.w[1] = 3000; 49 s.m = 1000; 50 assert_eq(s.cc.c, '#'); 51 assert_eq(s.m, 1000); 52 assert_eq(s.ww.w[0] + s.ww.w[1], 5000); 53 54 return 0; 55 } 56 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 133: Register keyword ignored 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 register int n = 1844; 27 assert_eq(n, 1844); 28 return 0; 29 } 30 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 134: goto statement 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 char c = 0; 27 here: 28 ++c; 29 if (c < 5) 30 goto here; 31 assert_eq(c, 5); 32 33 goto there; 34 assert(0); 35 there: 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 135: Extern declaration gets ignored 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 extern int g; 25 int g; // not seen as a redeclaration 26 27 typedef unsigned T1; 28 typedef T1 T2; 29 extern T2 t; 30 T2 t; 31 32 typedef unsigned Addr[2]; 33 extern Addr addr; 34 Addr addr = { 0xAAAA, 0xBBBB }; 35 36 int main() 37 { 38 g = 1234; 39 assert_eq(g, 1234); 40 41 t = 5678; 42 assert_eq(t, 5678); 43 44 addr[0] = 0x1111; 45 addr[1] = 0x2222; 46 assert_eq(addr[0] + addr[1], 0x3333); 47 48 return 0; 49 } 50 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 136: Static keyword ignored, declaration still processed 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 static int g; 25 26 int main() 27 { 28 g = 1234; 29 assert_eq(g, 1234); 30 return 0; 31 } 32 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 137: Reference to undefined struct 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S *f(); 25 struct T *h(); // T is never defined 26 27 struct S 28 { 29 int n; 30 }; 31 32 struct S g; 33 34 struct S *f() 35 { 36 return &g; 37 } 38 39 struct T *h() 40 { 41 return 0; 42 } 43 44 int main() 45 { 46 struct S *p = f(); 47 assert_eq(p, &g); 48 assert_eq(h(), 0); 49 return 0; 50 } 51 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 138: Struct assignment 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S 25 { 26 int i; 27 char c; 28 }; 29 int main() 30 { 31 struct S s0 = { 1000, 10 }; 32 struct S s1 = s0; 33 assert_eq(s1.i, s0.i); 34 assert_eq(s1.c, s0.c); 35 36 struct S s2; 37 s2.i = s2.c = 88; 38 s2 = s0; 39 assert_eq(s2.i, s0.i); 40 assert_eq(s2.c, s0.c); 41 42 s1.i = s1.c = 77; 43 s2.i = s2.c = 99; 44 s2 = s1 = s0; 45 assert_eq(s1.i, s0.i); 46 assert_eq(s1.c, s0.c); 47 assert_eq(s2.i, s0.i); 48 assert_eq(s2.c, s0.c); 49 50 return 0; 51 } 52 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 139: Function prototypes 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int f(int, int); 25 int h(int someName); 26 int main() 27 { 28 int c = f(1, 2); 29 assert_eq(c, 3); 30 31 assert_eq(h(41), 42); 32 33 return 0; 34 } 35 int f(int a, int b) 36 { 37 return a + b; 38 } 39 int h(int someOtherName) 40 { 41 return someOtherName + 1; 42 } 43 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 140: enum 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 enum 25 { 26 FOO, 27 BAR, 28 BAZ, // trailing comma allowed 29 }; 30 31 enum 32 { 33 QUUX, 34 WALDO = 1000, 35 WALDO_PLUS_ONE 36 } gVar0 = QUUX; 37 // Here, the 3 enumerated names must be registered via TypeManager::declareEnumerationList() 38 // before the "gVar0 = QUUX" parts gets parsed, so that "= QUUX" can be recognized as a 39 // reference to the enumerated name, rather than a reference to an undefined variable. 40 41 enum A { a0, a1, aBig = 2222 }; 42 enum A aVar0 = a1; // declare variable of previously defined enum 43 44 int f0(enum A aParam) { return aParam; } // function parameter of type enum (previously defined) 45 46 enum A f1() { return a1; } 47 48 enum B { b0 = 41, b1 } bVar0 = b0, bVar1; // named enum with enumerated names, used to declare variables 49 extern enum A aExtVar0 = a1; // ignored line 50 extern enum { EXT0 = 55 } aExtVar0 = EXT0; // ignored line 51 52 static enum A aStaticVar0 = aBig; // 'static' keyword ignored, variable declared 53 static enum { STATIC0 = 66 } aStaticVar1 = STATIC0; // 'static' keyword ignored, variable declared 54 55 typedef enum { T0 = 77, T1 } TEnum; 56 TEnum t0 = T1; 57 typedef enum A EnumA; 58 59 enum Indices 60 { 61 ZERO, ONE, TWO, THREE, SEVEN = 7, EIGHT = 8, FIFTEEN = 15 62 }; 63 enum Bits 64 { 65 B0 = 1 << ZERO, 66 B1 = 1 << ONE, 67 B2 = 1 << TWO, 68 B3 = 1 << THREE, 69 B7 = 1 << SEVEN, 70 B8 = 1 << EIGHT, 71 B15 = 1 << FIFTEEN 72 }; 73 74 enum 75 { 76 THIRTY_TWO = 1 << 5, 77 INDEPENDENT = 5, 78 DEPENDENT_ON_PREVIOUS = 1 << INDEPENDENT, 79 }; 80 81 #define STR "foobar" 82 enum 83 { 84 SIZE_OF_STR = sizeof(STR), 85 SIZE_OF_STR_PLUS_ONE = sizeof(STR) + 1 86 }; 87 88 int main() 89 { 90 assert_eq(FOO, 0); 91 assert_eq(BAR, 1); 92 assert_eq(BAZ, 2); 93 assert_eq(sizeof(FOO), 2); 94 95 assert_eq(aVar0, a1); 96 aVar0 = aBig; 97 assert_eq(aVar0, aBig); 98 assert_eq(f0(aBig), aBig); 99 assert_eq(f1(), a1); 100 101 assert_eq(sizeof(gVar0), 2); 102 assert_eq(gVar0, QUUX); 103 gVar0 = WALDO; 104 assert_eq(gVar0, WALDO); 105 gVar0 = WALDO_PLUS_ONE; 106 assert_eq(gVar0, 1001); 107 108 assert_eq(bVar0, b0); 109 bVar0 = b1; 110 assert_eq(bVar0, b1); 111 112 assert_eq(aStaticVar0, aBig); 113 assert_eq(aStaticVar1, STATIC0); 114 115 assert_eq(t0, 78); 116 assert_eq(sizeof(t0), 2); 117 assert_eq(sizeof(TEnum), 2); 118 119 EnumA a = aBig; 120 assert_eq(a, aBig); 121 assert_eq(sizeof(EnumA), 2); 122 assert_eq(sizeof(enum A), 2); 123 124 assert_eq(B0, 0x0001); 125 assert_eq(B1, 0x0002); 126 assert_eq(B2, 0x0004); 127 assert_eq(B3, 0x0008); 128 assert_eq(B7, 0x0080); 129 assert_eq(B8, 0x0100); 130 assert_eq(B15, 0x8000); 131 132 assert_eq(THIRTY_TWO, 32); 133 assert_eq(DEPENDENT_ON_PREVIOUS, 32); 134 135 // Local variable name can hide enum name. 136 char *THIRTY_TWO = 0x1234; 137 assert_eq(THIRTY_TWO, 0x1234); 138 139 // Hide an enumerated name with a local variable. 140 assert_eq(FIFTEEN, 15); 141 int FIFTEEN = 999; 142 assert_eq(FIFTEEN, 999); 143 144 assert_eq(SIZE_OF_STR, 7); 145 assert_eq(SIZE_OF_STR_PLUS_ONE, 8); 146 147 unsigned k0 = 22222, k1 = 22222; 148 asm { 149 ldd #WALDO 150 std k0 151 ldd #WALDO+234 152 std k1 153 } 154 assert_eq(k0, 1000); 155 assert_eq(k1, 1234); 156 157 return 0; 158 } 159 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 141: Multiplication of members of a struct 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 typedef struct { 25 int x, y; 26 } test_t; 27 int test1(test_t* v) 28 { 29 return v->x * v->y; // removeUselessLdx() would mishandle this 30 } 31 int main() 32 { 33 test_t a0 = { 240, 250 }; 34 assert_eq(test1(&a0), 60000); 35 return 0; 36 } 37 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 142: atoui() and atoi() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 assert_eq(atoui("0"), 0); 27 assert_eq(atoui("1"), 1); 28 assert_eq(atoui("543"), 543); 29 assert_eq(atoui("65535"), 65535); 30 assert_eq(atoi("0"), 0); 31 assert_eq(atoi("1"), 1); 32 assert_eq(atoi("543"), 543); 33 assert_eq(atoi("32767"), 32767); 34 assert_eq(atoi("-1"), -1); 35 assert_eq(atoi("-543"), -543); 36 assert_eq(atoi("-32768"), -32768); 37 return 0; 38 } 39 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 143: Assignment operators on a struct field 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 typedef struct { 25 int _dummy, value; 26 } WordValue; 27 28 typedef struct { 29 int _dummy; 30 char value; 31 } ByteValue; 32 33 void test1div_ww(WordValue* t) 34 { 35 t->value /= 2; 36 } 37 38 void test1div_bw(ByteValue* t) 39 { 40 t->value /= 2; 41 } 42 43 void test1mod_ww(WordValue* t) 44 { 45 t->value %= 100; 46 } 47 48 void test1mod_bw(ByteValue* t) 49 { 50 t->value %= 14; 51 } 52 53 void test1sl_ww(WordValue* t) 54 { 55 t->value <<= 1; 56 } 57 58 void test1sl_bw(ByteValue* t) 59 { 60 t->value <<= 1; 61 } 62 63 unsigned one() { return 1; } 64 void test1sl_nonConstRightSide(WordValue* t) 65 { 66 t->value <<= one(); 67 } 68 69 void test1sr_ww(WordValue* t) 70 { 71 t->value >>= 1; 72 } 73 74 void test1sr_bw(ByteValue* t) 75 { 76 t->value >>= 1; 77 } 78 79 void test2div(WordValue* t) 80 { 81 t->value = t->value / 2; 82 } 83 84 void test2mod(WordValue* t) 85 { 86 t->value = t->value % 100; 87 } 88 89 void test2sl(WordValue* t) 90 { 91 t->value = t->value << 1; 92 } 93 94 void test2sr(WordValue* t) 95 { 96 t->value = t->value >> 1; 97 } 98 99 void testWithWordAsLeftSide() 100 { 101 WordValue s0 = { 1111, 0 }; 102 103 s0.value = 4444; 104 test1div_ww(&s0); 105 assert_eq(s0.value, 2222); 106 107 s0.value = 12345; 108 test1mod_ww(&s0); 109 assert_eq(s0.value, 45); 110 111 s0.value = 333; 112 test1sl_ww(&s0); 113 assert_eq(s0.value, 666); 114 115 assert_eq(&(s0.value /= 2), &s0.value); 116 assert_eq(&(s0.value %= 2), &s0.value); 117 assert_eq(&(s0.value >>= 1), &s0.value); 118 assert_eq(&(s0.value <<= 1), &s0.value); 119 120 s0.value = 333; 121 test1sl_nonConstRightSide(&s0); 122 assert_eq(s0.value, 666); 123 124 s0.value = 444; 125 test1sr_ww(&s0); 126 assert_eq(s0.value, 222); 127 128 s0.value <<= 10; 129 assert_eq(s0.value, 0x7800); 130 s0.value >>= 10; 131 assert_eq(s0.value, 30); 132 133 s0.value = 4444; 134 test2div(&s0); 135 assert_eq(s0.value, 2222); 136 137 s0.value = 12345; 138 test2mod(&s0); 139 assert_eq(s0.value, 45); 140 141 s0.value = 333; 142 test2sl(&s0); 143 assert_eq(s0.value, 666); 144 145 s0.value = 444; 146 test2sr(&s0); 147 assert_eq(s0.value, 222); 148 } 149 150 void testWithByteAsLeftSide() 151 { 152 ByteValue s0 = { 1111, 0 }; 153 154 s0.value = 44; 155 test1div_bw(&s0); 156 assert_eq(s0.value, 22); 157 158 s0.value = 123; 159 test1mod_bw(&s0); 160 assert_eq(s0.value, 11); 161 162 s0.value = 33; 163 test1sl_bw(&s0); 164 assert_eq(s0.value, 66); 165 166 assert_eq(&(s0.value /= 2), &s0.value); 167 assert_eq(&(s0.value %= 2), &s0.value); 168 assert_eq(&(s0.value >>= 1), &s0.value); 169 assert_eq(&(s0.value <<= 1), &s0.value); 170 171 s0.value = 44; 172 test1sr_bw(&s0); 173 assert_eq(s0.value, 22); 174 175 s0.value <<= 10; 176 assert_eq(s0.value, 0); 177 s0.value = 255; 178 s0.value >>= 10; 179 assert_eq(s0.value, -1); // because 'value' is signed 180 } 181 182 int main() 183 { 184 testWithWordAsLeftSide(); 185 testWithByteAsLeftSide(); 186 return 0; 187 } 188 189 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 144: Optimizaton on boolean negation and disjunction 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int test(void *a, void *b) 25 { 26 return !a || !b; 27 } 28 int main() 29 { 30 assert(test((void *) 0, (void *) 0)); 31 assert(test((void *) 1, (void *) 0)); 32 assert(test((void *) 0, (void *) 1)); 33 assert(!test((void *) 1, (void *) 1)); 34 return 0; 35 } 36 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 145: Avoid over-optimizing when byte constant cast to word 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 byte b = 99; 27 word w = b * (word) 100; 28 assert_eq(w, 9900); 29 30 char sb = 99; 31 int sw = sb * (int) 100; 32 assert_eq(sw, 9900); 33 34 sb = -98; 35 sw = sb * (int) -100; 36 assert_eq(sw, 9800); 37 38 sb = -97; 39 sw = (int) -100 * sb; 40 assert_eq(sw, 9700); 41 42 sb = -97; 43 sw = (int) 100 * sb; 44 assert_eq(sw, -9700); 45 46 return 0; 47 } 48 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 146: removeUselessLdx optimization 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S 25 { 26 word a, b, c, d; 27 byte buffer[512]; 28 }; 29 void g(void *dst, void *src, word n) 30 { 31 //printf("%p %p %u\n", dst, src, n); 32 assert_eq(dst + 256, src); 33 } 34 void f(struct S *data) 35 { 36 g(data->buffer, data->buffer + 256, data->d); 37 } 38 int main() 39 { 40 struct S data; 41 data.d = 157; 42 f(&data); 43 return 0; 44 } 45 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 147: __FUNCTION__ and __func__ 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char *g0 = __FUNCTION__, *g1 = __func__; 25 void someFunction() 26 { 27 printf("%s\n", __FUNCTION__); 28 assert_eq(strcmp(__FUNCTION__, "someFunction"), 0); 29 assert_eq(strcmp(__func__, "someFunction"), 0); 30 } 31 int main() 32 { 33 printf("%s\n", __FUNCTION__); 34 assert_eq(strcmp(__FUNCTION__, "main"), 0); 35 assert_eq(strcmp(__func__, "main"), 0); 36 someFunction(); 37 printf("%s\n", g0); 38 printf("%s\n", g1); 39 assert_eq(strcmp(g0, ""), 0); 40 assert_eq(strcmp(g1, ""), 0); 41 return 0; 42 } 43 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: main someFunction --- Actual output: main someFunction -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 148: Optimizer bug in ASMText::removeAndOrMulAddSub() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 unsigned char a[] = { 11, 22, 33 }; 25 int main() 26 { 27 unsigned char *ptr = a; 28 int start = 52 + (ptr[1] << 8) + ptr[2]; // note: shift is done on 8 bits, not 16 as in Standard C 29 assert_eq(start, 85); 30 start = 52 + ((unsigned) ptr[1] << 8) + ptr[2]; // force shift on 16 bits 31 assert_eq(start, 5717); 32 return 0; 33 } 34 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 149: Enumerators defined with other enumerators 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 enum 25 { 26 STACK_SPACE = 2 * 1024, 27 GRAPHICS_SPACE = 4 * 1536, 28 RAM_END = 0xFE00, 29 STACK_START = RAM_END - STACK_SPACE, 30 GRAPHICS_START = STACK_START - GRAPHICS_SPACE, 31 }; 32 int main() 33 { 34 assert_eq(STACK_SPACE, 0x800); 35 assert_eq(GRAPHICS_SPACE, 6144); 36 assert_eq(RAM_END, 0xFE00); 37 assert_eq(STACK_START, 0xF600); 38 assert_eq(GRAPHICS_START, 0xDE00); 39 return 0; 40 } 41 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 150: Process a declarator that represents a function pointer 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 typedef char (*FuncPtrType)(); // TypeManager::addTypeDef() used to be buggy (<= 0.1.38) on this line; 25 // It would define FuncPtrType as char instead of void *. 26 struct S0 27 { 28 FuncPtrType funcPtr; 29 }; 30 char f(char n) { return n + 1; } // of type FuncPtrType 31 FuncPtrType global = f; 32 int main() 33 { 34 struct S0 s0 = { f }; 35 assert_eq((*s0.funcPtr)('A'), 'B'); 36 assert_eq((*global)('C'), 'D'); 37 FuncPtrType local = f; 38 assert_eq((*local)('E'), 'F'); 39 return 0; 40 } 41 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 151: Typedef of struct registers struct S as a type 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 typedef struct S { int m; } S; 25 struct A { int m; }; 26 typedef struct A AA; 27 28 struct S g_s = { 42 }; 29 struct A g_a = { 1844 }; 30 AA g_aa = { 123 }; 31 32 int main() 33 { 34 struct S s = { 42 }; 35 assert_eq(s.m, 42); 36 struct A a = { 1844 }; 37 assert_eq(a.m, 1844); 38 AA aa = { 123 }; 39 assert_eq(aa.m, 123); 40 41 assert_eq(g_s.m, 42); 42 assert_eq(g_a.m, 1844); 43 assert_eq(g_aa.m, 123); 44 return 0; 45 } 46 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 152: Empty struct 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct Empty {}; 25 int main() 26 { 27 struct Empty e; 28 assert_ne(&e, 0); // check that 'e' really is on the stack 29 return 0; 30 } 31 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 153: Passing a struct or union by value to a function 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 #include 25 26 struct S { int a, b; char c; }; // size of struct is odd number 27 int f(struct S s, int x, char y) 28 { 29 int sum = s.a + s.b + s.c + x + y; 30 ++s.b; // only modifies the local copy of the struct 31 --s.c; // ditto 32 return sum; 33 } 34 35 union U { unsigned n; unsigned char c; }; 36 unsigned getInt(union U u) { return u.n; } 37 unsigned getChar(union U u) { return u.c; } 38 39 void v(struct S first, ...) 40 { 41 assert_eq(first.c, '#'); 42 va_list ap; 43 va_start(ap, first); 44 struct S s = va_arg(ap, struct S); 45 assert_eq(s.c, '$'); 46 char charAfter = va_arg(ap, char); 47 assert_eq(charAfter, '%'); 48 unsigned unsignedAfter = va_arg(ap, unsigned); 49 assert_eq(unsignedAfter, 0xFEDC); 50 va_end(ap); 51 } 52 53 struct OneByte { unsigned char b; }; 54 55 void receiveOneByteStruct(struct OneByte ob) 56 { 57 assert_eq(ob.b, 0xAA); 58 } 59 void receiveOneByteStructViaEllipsis(int n, ...) 60 { 61 assert_eq(n, 4242); 62 va_list ap; 63 va_start(ap, n); 64 struct OneByte ob = va_arg(ap, struct OneByte); 65 assert_eq(ob.b, 0xAA); 66 char c = va_arg(ap, char); 67 assert_eq(c, '*'); 68 va_end(ap); 69 } 70 void receiveOneByteStructViaEllipsis2(struct OneByte first, ...) 71 { 72 assert_eq(first.b, '-'); 73 va_list ap; 74 va_start(ap, first); 75 struct OneByte ob = va_arg(ap, struct OneByte); 76 assert_eq(ob.b, 0xAA); 77 char c = va_arg(ap, char); 78 assert_eq(c, '*'); 79 va_end(ap); 80 } 81 82 int main() 83 { 84 struct S instance = { 1000, 2000, 30 }; 85 assert_eq(sizeof(struct S), 5); 86 assert_eq(sizeof(instance), 5); 87 int result = f(instance, 4000, 99); 88 assert_eq(instance.a, 1000); 89 assert_eq(instance.b, 2000); 90 assert_eq(instance.c, 30); 91 assert_eq(result, 7129); 92 93 union U u0; 94 u0.n = 0xABCD; 95 assert_eq(getInt(u0), 0xABCD); 96 assert_eq(getChar(u0), 0xAB); // 6809 is big endian 97 98 instance.c = '$'; 99 struct S first = { 1111, 2222, '#' }; 100 v(first, instance, '%', 0xFEDC); 101 102 struct OneByte ob0 = { 0xAA }; 103 104 asm { clra } 105 receiveOneByteStruct(ob0); 106 107 asm { clra } 108 receiveOneByteStructViaEllipsis(4242, ob0, '*'); 109 110 struct OneByte ob1 = { '-' }; 111 asm { clra } 112 receiveOneByteStructViaEllipsis2(ob1, ob0, '*'); 113 114 return 0; 115 } 116 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 154: Function returning a struct or union by value 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S { unsigned a, b; unsigned char c; }; 25 struct S makeS(unsigned a, unsigned b, unsigned char c) 26 { 27 struct S ret = { a, b, c }; 28 return ret; 29 } 30 struct S inc(struct S s) 31 { 32 assert_eq(s.a, 1000); 33 assert_eq(s.b, 2000); 34 assert_eq(s.c, 'A'); 35 ++s.a; 36 ++s.b; 37 ++s.c; 38 return s; 39 } 40 int main() 41 { 42 struct S s0 = makeS(1000, 2000, 'A'); 43 assert_eq(s0.a, 1000); 44 assert_eq(s0.b, 2000); 45 assert_eq(s0.c, 'A'); 46 unsigned b = makeS(1234, 5678, 'B').b; 47 assert_eq(b, 5678); 48 s0 = inc(s0); 49 assert_eq(s0.a, 1001); 50 assert_eq(s0.b, 2001); 51 assert_eq(s0.c, 'B'); 52 struct S s1 = makeS(1000, 2000, 'A'); 53 inc(s1); // not receiving the return value 54 return 0; 55 } 56 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembly language filename: ,check-prog.s 0 error(s), 0 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 155: Argument too large for function parameter 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char takeChar(char x) { return x; } 25 unsigned char takeUnsignedChar(unsigned char x) { return x; } 26 int main() 27 { 28 char c = takeChar(0x1234); 29 assert_eq(c, 0x34); 30 c = takeChar(0x12F0); 31 assert_eq(c, (int) -16); 32 unsigned char uc = takeUnsignedChar(0x1256); 33 assert_eq(uc, 0x56); 34 uc = takeUnsignedChar(0x12F8); 35 assert_eq(uc, (int) 248); 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code ,check-prog.c:28: __warning__: passing `int' argument as `char' parameter 1 ('x') of function takeChar() ,check-prog.c:30: __warning__: passing `int' argument as `char' parameter 1 ('x') of function takeChar() ,check-prog.c:32: __warning__: passing `int' argument as `unsigned char' parameter 1 ('x') of function takeUnsignedChar() ,check-prog.c:34: __warning__: passing `int' argument as `unsigned char' parameter 1 ('x') of function takeUnsignedChar() Assembly language filename: ,check-prog.s 0 error(s), 4 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 156: Declaration with initializer larger than variable 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void f(int i, unsigned u) 25 { 26 char c0 = i; 27 assert_eq(c0, -32); 28 char c1 = u; 29 assert_eq(c1, -48); 30 unsigned char uc0 = i; 31 assert_eq(uc0, (unsigned char) -32); 32 unsigned char uc1 = u; 33 assert_eq(uc1, 208); 34 int i0 = u; 35 assert_eq(i0, -24624); 36 unsigned u0 = i; 37 assert_eq(u0, 0x7fe0); 38 } 39 int main() 40 { 41 f(0x7fe0, 0x9fd0); 42 return 0; 43 } 44 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate -Lstdlib/ -L float -I './support' ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code ,check-prog.c:26: __warning__: initializing char with expression of type int ,check-prog.c:28: __warning__: initializing char with expression of type unsigned int ,check-prog.c:30: __warning__: initializing unsigned char with expression of type int ,check-prog.c:32: __warning__: initializing unsigned char with expression of type unsigned int Assembly language filename: ,check-prog.s 0 error(s), 4 warning(s). Assembler command: lwasm -fobj --pragma=forwardrefmax --output=',check-prog.o' --list=',check-prog.lst' ',check-prog.s' Exit code from assembler command: 0 Linker command: lwlink --format=srec --output=',check-prog.srec' --script=',check-prog.link' --map=',check-prog.map' -L'stdlib/' -L'float' -L/usr/share/cmoc/lib -lcmoc-std-usim ',check-prog.o' Exit code from linker command: 0 Number of error messages from linker: 0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.srec 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- Cleaning up: erasing ,check-prog.c erasing ,check-prog.s erasing ,check-prog.lst erasing ,check-prog.srec erasing ,check-prog.map erasing ,check-prog.link erasing ,check-prog.o ./test-program-output.pl: ALL 157 tests PASSED ### # # ### ### ##### ### ### # # # # # # # # # # # # # # # # # # # # # ### # # # # ### ### ### # # # # # # # # # # # # # # # # # # # # # ### ### ### ### ##### ### ### perl ./test-bad-programs.pl . -------------------------------------------------------------------------------- --- Program # 0: Empty source file This test is suspended. ### ls ,check-prog.*: ls: cannot access ,check-prog.*: No such file or directory ### -------------------------------------------------------------------------------- --- Program # 1: Using a local variable before declaring it 1 2 int main() 3 { 4 a = 1; 5 int a; 6 return 0; 7 } --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: undeclared identifier `a' 2 ,check-prog.c:4: __error__: left side of operator = is of type void --- Expected compilation errors: 1 ,check-prog.c:4: __error__: undeclared identifier `a' 2 ,check-prog.c:4: __error__: left side of operator = is of type void ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 2: Using a global variable before declaring it 1 2 void f() 3 { 4 g = 1; 5 } 6 int g; 7 int main() 8 { 9 f(); 10 return g; 11 } --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: global variable `g' undeclared --- Expected compilation errors: 1 ,check-prog.c:4: __error__: global variable `g' undeclared ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 3: Non-void not returning a value 1 2 int main() { return 0; } 3 int f() {} 4 int g() { f(); } 5 void h() { return 42; } 6 int i() { return; } 7 asm int a() { asm { ldd #1844 } } // OK because function is asm only 8 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:3: __error__: function 'f' is not void but does not have any return statement 2 ,check-prog.c:4: __error__: function 'g' is not void but does not have any return statement 3 ,check-prog.c:5: __error__: returning expression of type int, which differs from function's return type (void) 4 ,check-prog.c:6: __error__: return without argument in a non-void function --- Expected compilation errors: 1 ,check-prog.c:3: __error__: function 'f' is not void but does not have any return statement 2 ,check-prog.c:4: __error__: function 'g' is not void but does not have any return statement 3 ,check-prog.c:5: __error__: returning expression of type int, which differs from function's return type (void) 4 ,check-prog.c:6: __error__: return without argument in a non-void function ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 4: Initializing pointer from non-zero constant 1 2 int main() 3 { 4 char *p0 = -42; 5 char *p1 = 42; 6 char *p2 = f(); 7 return 0; 8 } 9 int f() { return 0; } --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __warning__: initializing pointer 'p0' from negative constant 2 ,check-prog.c:6: __warning__: initializing pointer 'p2' from integer expression 3 ,check-prog.c:6: __error__: calling undeclared function f() --- Expected compilation errors: 1 ,check-prog.c:4: __warning__: initializing pointer 'p0' from negative constant 2 ,check-prog.c:6: __warning__: initializing pointer 'p2' from integer expression 3 ,check-prog.c:6: __error__: calling undeclared function f() ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 5: Declaring a variable with a name that is already used 1 2 int foo; 3 int foo; 4 int main() 5 { 6 char a; 7 int a; 8 return 0; 9 } 10 void f0(int n) 11 { 12 int n = 42; // fails b/c C views function param as part of function scope, not separate scope 13 } 14 void f1(int n) 15 { 16 { 17 int n = 42; // OK b/c inner braces create separate scope 18 } 19 } 20 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:3: __error__: global variable `foo' already declared at global scope at ,check-prog.c:2 2 ,check-prog.c:7: __error__: variable `a' already declared in this scope at ,check-prog.c:6 3 ,check-prog.c:12: __error__: variable `n' already declared in this scope at ,check-prog.c:10 --- Expected compilation errors: 1 ,check-prog.c:3: __error__: global variable `foo' already declared at global scope at ,check-prog.c:2 2 ,check-prog.c:7: __error__: variable `a' already declared in this scope at ,check-prog.c:6 3 ,check-prog.c:12: __error__: variable `n' already declared in this scope at ,check-prog.c:10 ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 6: Detect invalid subtractions 1 2 void f(int x) {} 3 int main() 4 { 5 char *p; 6 f((int) (4 - p)); 7 return 0; 8 } 9 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:6: __error__: subtraction of pointer or array from integral --- Expected compilation errors: 1 ,check-prog.c:6: __error__: subtraction of pointer or array from integral ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 7: Illegal array operations 1 2 int main() 3 { 4 int w[2]; 5 w = 0; 6 w += 0; 7 ++w; 8 w--; 9 *w = 0; 10 return 0; 11 } 12 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: cannot assign to array name 2 ,check-prog.c:6: __error__: cannot assign to array name 3 ,check-prog.c:7: __error__: cannot increment array name 4 ,check-prog.c:8: __error__: cannot decrement array name --- Expected compilation errors: 1 ,check-prog.c:5: __error__: cannot assign to array name 2 ,check-prog.c:6: __error__: cannot assign to array name 3 ,check-prog.c:7: __error__: cannot increment array name 4 ,check-prog.c:8: __error__: cannot decrement array name ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 8: Passing undefined struct by value to a function 1 2 struct Foobar { char b; }; 3 void f(struct Foobar s) 4 { 5 } 6 void f1(struct Foobar) 7 { 8 } 9 void f2(struct Undefined) 10 { 11 } 12 struct Quux {}; union U { char u; }; 13 void f3(struct Quux) {} 14 int main() 15 { 16 struct Foobar foobar; 17 f(foobar); 18 f1(foobar); 19 f3(foobar); 20 int n = foobar; 21 n += foobar; 22 n = -foobar; 23 union U u0; 24 n = -u0; 25 return 0; 26 } 27 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:9: __error__: argument 1 of f2() receives undefined `struct Undefined' by value 2 ,check-prog.c:19: __error__: `struct Foobar' used as parameter 1 of function f3() which is `struct Quux' 3 ,check-prog.c:21: __error__: invalid use of += on a struct or union 4 ,check-prog.c:22: __error__: invalid use of arithmetic negation on a struct 5 ,check-prog.c:24: __error__: invalid use of arithmetic negation on a union 6 ,check-prog.c:20: __error__: initializing int with expression of type struct Foobar --- Expected compilation errors: 1 ,check-prog.c:9: __error__: argument 1 of f2() receives undefined `struct Undefined' by value 2 ,check-prog.c:19: __error__: `struct Foobar' used as parameter 1 of function f3() which is `struct Quux' 3 ,check-prog.c:21: __error__: invalid use of += on a struct or union 4 ,check-prog.c:22: __error__: invalid use of arithmetic negation on a struct 5 ,check-prog.c:24: __error__: invalid use of arithmetic negation on a union 6 ,check-prog.c:20: __error__: initializing int with expression of type struct Foobar ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 9: Forbid requesting a struct by value from va_arg(). Detect use of unknown struct name 1 2 3 #include 4 5 struct S { char b; }; 6 void f(char *a, ...) 7 { 8 va_list ap; 9 va_start(ap, a); // ok 10 va_arg(ap, struct S); // passes but will not work 11 va_arg(ap, struct S *); // ok 12 va_arg(ap, struct Unknown *); // ok because sizeof gives 2, regard of unknown struct name 13 va_arg(ap, void); // error 14 va_arg(ap, char); // ok 15 va_arg(ap, char *); // ok 16 va_arg(ap, char **); // ok 17 va_arg(ap, char *****); // ok 18 va_end(ap); 19 } 20 int main() 21 { 22 f(0); 23 return 0; 24 } 25 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:13: __error__: indirection of a pointer to void 2 ,check-prog.c:13: __error__: cannot take sizeof(void) --- Expected compilation errors: 1 ,check-prog.c:13: __error__: indirection of a pointer to void 2 ,check-prog.c:13: __error__: cannot take sizeof(void) ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 10: Do-while lacks terminating semi-colon.. 1 2 void f() 3 { 4 do {} while (1) 5 } 6 int main() 7 { 8 return 0; 9 } 10 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: syntax error: } --- Expected compilation errors: 1 ,check-prog.c:5: __error__: syntax error: } ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 11: Global variable too large 1 2 int w[50000]; 3 int main() 4 { 5 return 0; 6 } 7 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: invalid dimensions for array w --- Expected compilation errors: 1 ,check-prog.c:2: __error__: invalid dimensions for array w ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 12: Local variable too large 1 2 int main() 3 { 4 char b[40000]; 5 return 0; 6 } 7 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: invalid dimensions for array b --- Expected compilation errors: 1 ,check-prog.c:4: __error__: invalid dimensions for array b ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 13: Number of arguments of built-in functions 1 2 #include 3 int main() 4 { 5 putstr("foo"); 6 int w; 7 toupper(w); 8 char *s0; 9 strchr(s0, 256 + 'f'); 10 printf(); 11 printf(s0); 12 sprintf(); 13 sprintf("x"); 14 sprintf("%d %d", 1, 2); 15 sprintf(w, "x"); 16 char temp[64]; 17 sprintf(temp, "%d %d", 1); 18 sprintf(temp, "%d %d", 1, 2); // OK 19 sprintf(temp, "%d %d", 1, 2, 3); 20 printf("%d %d", 1); 21 printf("%d %d", 1, 2); // OK 22 printf("%d %d", 1, 2, 3); 23 printf(w); 24 return 0; 25 } 26 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: call to putstr() passes 1 argument(s) but function expects 2 2 ,check-prog.c:10: __error__: call to printf() passes 0 argument(s) but function expects at least 1 3 ,check-prog.c:11: __warning__: format argument of printf() is not a string literal 4 ,check-prog.c:12: __error__: call to sprintf() passes 0 argument(s) but function expects at least 2 5 ,check-prog.c:13: __error__: call to sprintf() passes 1 argument(s) but function expects at least 2 6 ,check-prog.c:14: __warning__: first argument of sprintf() is a string literal 7 ,check-prog.c:15: __warning__: passing non-pointer/array (int) as parameter 1 of function sprintf(), which is char * 8 ,check-prog.c:15: __warning__: first argument of sprintf() should be pointer or array instead of `int' 9 ,check-prog.c:17: __warning__: not enough arguments to sprintf() to match its format string 10 ,check-prog.c:19: __warning__: too many arguments for sprintf() format string 11 ,check-prog.c:20: __warning__: not enough arguments to printf() to match its format string 12 ,check-prog.c:22: __warning__: too many arguments for printf() format string 13 ,check-prog.c:23: __warning__: passing non-pointer/array (int) as parameter 1 of function printf(), which is char * 14 ,check-prog.c:23: __warning__: format argument of printf() is not a string literal --- Expected compilation errors: 1 ,check-prog.c:5: __error__: call to putstr() passes 1 argument(s) but function expects 2 2 ,check-prog.c:10: __error__: call to printf() passes 0 argument(s) but function expects at least 1 3 ,check-prog.c:11: __warning__: format argument of printf() is not a string literal 4 ,check-prog.c:12: __error__: call to sprintf() passes 0 argument(s) but function expects at least 2 5 ,check-prog.c:13: __error__: call to sprintf() passes 1 argument(s) but function expects at least 2 6 ,check-prog.c:14: __warning__: first argument of sprintf() is a string literal 7 ,check-prog.c:15: __warning__: passing non-pointer/array (int) as parameter 1 of function sprintf(), which is char * 8 ,check-prog.c:15: __warning__: first argument of sprintf() should be pointer or array instead of `int' 9 ,check-prog.c:17: __warning__: not enough arguments to sprintf() to match its format string 10 ,check-prog.c:19: __warning__: too many arguments for sprintf() format string 11 ,check-prog.c:20: __warning__: not enough arguments to printf() to match its format string 12 ,check-prog.c:22: __warning__: too many arguments for printf() format string 13 ,check-prog.c:23: __warning__: passing non-pointer/array (int) as parameter 1 of function printf(), which is char * 14 ,check-prog.c:23: __warning__: format argument of printf() is not a string literal ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 14: Detect change in signedness when passing an argument to a function 1 2 #include 3 void fsb(char x) {} 4 void fsw(int x) {} 5 void fub(unsigned char x) {} 6 void fuw(unsigned x) {} 7 int main() 8 { 9 char sb; 10 int sw; 11 unsigned char ub; 12 unsigned uw; 13 fsb(ub); 14 fsw(uw); 15 fub(sb); 16 fuw(sw); 17 memset((unsigned char *) 0, sb, sw); 18 fsw(sw + ub); // no warning because sum is signed int (see ExpressionTypeSetter::processBinOp()) 19 return 0; 20 } 21 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: --- Expected compilation errors: ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 15: Return value type vs. function's return type 1 2 unsigned char *b1() { return 1; } 3 unsigned char *bm1() { return -1; } 4 unsigned char *b1000() { return 1000; } 5 unsigned char *bm1000() { return -1000; } 6 unsigned *w1() { return 1; } 7 unsigned *wm1() { return -1; } 8 unsigned *w1000() { return 1000; } 9 unsigned *wm1000() { return -1000; } 10 int main() 11 { 12 return 0; 13 } 14 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: returning expression of type int, which differs from function's return type (unsigned char *) 2 ,check-prog.c:3: __error__: returning expression of type int, which differs from function's return type (unsigned char *) 3 ,check-prog.c:4: __error__: returning expression of type int, which differs from function's return type (unsigned char *) 4 ,check-prog.c:5: __error__: returning expression of type int, which differs from function's return type (unsigned char *) 5 ,check-prog.c:6: __error__: returning expression of type int, which differs from function's return type (unsigned int *) 6 ,check-prog.c:7: __error__: returning expression of type int, which differs from function's return type (unsigned int *) 7 ,check-prog.c:8: __error__: returning expression of type int, which differs from function's return type (unsigned int *) 8 ,check-prog.c:9: __error__: returning expression of type int, which differs from function's return type (unsigned int *) --- Expected compilation errors: 1 ,check-prog.c:2: __error__: returning expression of type int, which differs from function's return type (unsigned char *) 2 ,check-prog.c:3: __error__: returning expression of type int, which differs from function's return type (unsigned char *) 3 ,check-prog.c:4: __error__: returning expression of type int, which differs from function's return type (unsigned char *) 4 ,check-prog.c:5: __error__: returning expression of type int, which differs from function's return type (unsigned char *) 5 ,check-prog.c:6: __error__: returning expression of type int, which differs from function's return type (unsigned int *) 6 ,check-prog.c:7: __error__: returning expression of type int, which differs from function's return type (unsigned int *) 7 ,check-prog.c:8: __error__: returning expression of type int, which differs from function's return type (unsigned int *) 8 ,check-prog.c:9: __error__: returning expression of type int, which differs from function's return type (unsigned int *) ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 16: Return type of main() must be int 1 2 void main() 3 { 4 } 5 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: return type of main() must be int --- Expected compilation errors: 1 ,check-prog.c:2: __error__: return type of main() must be int ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 17: printf() format warnings 1 2 #include 3 int main() 4 { 5 int sw; 6 unsigned uw; 7 char sb; 8 unsigned char ub; 9 unsigned char *bp; 10 printf("%u %d %5u %% %d %u %3d %p\n", sw, uw, sb, ub, bp, bp); 11 printf("%"); 12 printf("foo %123"); 13 printf("%u %u", 1, 2, 3); 14 printf(""); 15 obligatory_error; 16 printf("%d", -1); // no warning expected 17 printf("%u", 1); // no warning expected 18 return 0; 19 } 20 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:15: __error__: undeclared identifier `obligatory_error' 2 ,check-prog.c:10: __warning__: not enough arguments to printf() to match its format string 3 ,check-prog.c:11: __warning__: no letter follows last % in printf() format string 4 ,check-prog.c:12: __warning__: no letter follows last % in printf() format string 5 ,check-prog.c:13: __warning__: too many arguments for printf() format string --- Expected compilation errors: 1 ,check-prog.c:15: __error__: undeclared identifier `obligatory_error' 2 ,check-prog.c:10: __warning__: not enough arguments to printf() to match its format string 3 ,check-prog.c:11: __warning__: no letter follows last % in printf() format string 4 ,check-prog.c:12: __warning__: no letter follows last % in printf() format string 5 ,check-prog.c:13: __warning__: too many arguments for printf() format string ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 18: Declaration type vs. initializer type 1 2 int main() 3 { 4 unsigned w = 1844; 5 unsigned *pw0 = &w; 6 unsigned *pw1 = &pw0; // unsigned ** assigned to unsigned * 7 char b0 = -129; 8 char b1 = -128; 9 char b2 = 255; 10 char b3 = 256; 11 return 0; 12 } 13 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:6: __error__: initializing unsigned int * with expression of type unsigned int ** 2 ,check-prog.c:7: __warning__: initializing char with expression of type int 3 ,check-prog.c:10: __warning__: initializing char with expression of type int --- Expected compilation errors: 1 ,check-prog.c:6: __error__: initializing unsigned int * with expression of type unsigned int ** 2 ,check-prog.c:7: __warning__: initializing char with expression of type int 3 ,check-prog.c:10: __warning__: initializing char with expression of type int ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 19: Byte array initialized with non-byte expressions 1 2 char strings[] = { "foo", "bar", "baz" }; 3 int main() 4 { 5 return 0; 6 } 7 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: initializing char with expression of type char[] 2 ,check-prog.c:2: __error__: initializing char with expression of type char[] 3 ,check-prog.c:2: __error__: initializing char with expression of type char[] --- Expected compilation errors: 1 ,check-prog.c:2: __error__: initializing char with expression of type char[] 2 ,check-prog.c:2: __error__: initializing char with expression of type char[] 3 ,check-prog.c:2: __error__: initializing char with expression of type char[] ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 20: Invalid array initializer 1 2 struct A { char byteField; }; 3 struct A structArray[3] = { { 42 }, "foo", { 44 } }; 4 int v0[4] = "foo"; 5 int v1[] = { 9999 }; 6 int v2[] = &v1; 7 int main() 8 { 9 return 0; 10 } 11 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:6: __error__: invalid initializer --- Expected compilation errors: 1 ,check-prog.c:6: __error__: invalid initializer ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 21: Array whose initializer contains expressions of types that do not match the element type 1 2 struct A { char byteField; }; 3 struct A structArray[3] = { { 42 }, "foo", { 44 } }; 4 int v0[4] = "foo"; 5 int main() 6 { 7 return 0; 8 } 9 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:3: __error__: initializer for struct A is of type `char[]': must be list, or struct of same type 2 ,check-prog.c:4: __error__: initializer for array `v0' is invalid --- Expected compilation errors: 1 ,check-prog.c:3: __error__: initializer for struct A is of type `char[]': must be list, or struct of same type 2 ,check-prog.c:4: __error__: initializer for array `v0' is invalid ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 22: Re: Declaration::checkClassInitializer() 1 2 struct A 3 { 4 char b; 5 }; 6 struct A a = { "foo" }; 7 struct B 8 { 9 struct A aMember; 10 }; 11 struct B b = { { "bar" } }; 12 struct C 13 { 14 struct A aMemberArray[2]; 15 }; 16 struct C c = { { 17 { "baz" }, 18 { "quux" } 19 } }; 20 int main() 21 { 22 return 0; 23 } 24 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:6: __error__: initializing char with expression of type char[] 2 ,check-prog.c:11: __error__: initializing char with expression of type char[] 3 ,check-prog.c:17: __error__: initializing char with expression of type char[] 4 ,check-prog.c:18: __error__: initializing char with expression of type char[] --- Expected compilation errors: 1 ,check-prog.c:6: __error__: initializing char with expression of type char[] 2 ,check-prog.c:11: __error__: initializing char with expression of type char[] 3 ,check-prog.c:17: __error__: initializing char with expression of type char[] 4 ,check-prog.c:18: __error__: initializing char with expression of type char[] ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 23: var_decl containing a type_specifier but no declarator_list, unless it defines a struct 1 2 struct S { char b; }; // ok 3 unsigned n = 42; // ok 4 unsigned x; // ok: declarator without initializer 5 unsigned; // fail 6 int main() 7 { 8 return 0; 9 } 10 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: declaration specifies a type but no variable name --- Expected compilation errors: 1 ,check-prog.c:5: __error__: declaration specifies a type but no variable name ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 24: Reject returning an array from an int function 1 2 int i = 0; 3 int f(int *p) 4 { 5 return p; 6 } 7 int g(int p[][3]) 8 { 9 return p[i]; 10 } 11 int h(int p[][3][3]) 12 { 13 return p[i][i]; 14 } 15 int h2(int p[][3][3]) 16 { 17 return p[i]; 18 } 19 int main() 20 { 21 return 0; 22 } 23 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: returning expression of type int *, which differs from function's return type (int) 2 ,check-prog.c:9: __error__: returning expression of type int[], which differs from function's return type (int) 3 ,check-prog.c:13: __error__: returning expression of type int[], which differs from function's return type (int) 4 ,check-prog.c:17: __error__: returning expression of type int[][], which differs from function's return type (int) --- Expected compilation errors: 1 ,check-prog.c:5: __error__: returning expression of type int *, which differs from function's return type (int) 2 ,check-prog.c:9: __error__: returning expression of type int[], which differs from function's return type (int) 3 ,check-prog.c:13: __error__: returning expression of type int[], which differs from function's return type (int) 4 ,check-prog.c:17: __error__: returning expression of type int[][], which differs from function's return type (int) ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 25: Calling an undeclared function, mismatching function prototype, wrong number of parameters, etc. 1 2 void f2(); 3 void f3(int n); 4 void f3(); 5 void f4(); 6 int main() 7 { 8 f0(); 9 f1(); 10 11 12 return 0; 13 } 14 void f1() 15 { 16 } 17 void f4(int n) 18 { 19 } 20 void f5(int a); 21 void f5(int a, ...); 22 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: formal parameters for f3() are different from previously declared at ,check-prog.c:3 2 ,check-prog.c:17: __error__: formal parameters for f4() are different from previously declared at ,check-prog.c:5 3 ,check-prog.c:21: __error__: formal parameters for f5() are different from previously declared at ,check-prog.c:20 4 ,check-prog.c:8: __error__: undeclared identifier `f0' 5 ,check-prog.c:8: __error__: calling undeclared function f0() 6 ,check-prog.c:9: __error__: calling undeclared function f1() --- Expected compilation errors: 1 ,check-prog.c:4: __error__: formal parameters for f3() are different from previously declared at ,check-prog.c:3 2 ,check-prog.c:17: __error__: formal parameters for f4() are different from previously declared at ,check-prog.c:5 3 ,check-prog.c:21: __error__: formal parameters for f5() are different from previously declared at ,check-prog.c:20 4 ,check-prog.c:8: __error__: undeclared identifier `f0' 5 ,check-prog.c:8: __error__: calling undeclared function f0() 6 ,check-prog.c:9: __error__: calling undeclared function f1() ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 26: Unknown member of a struct 1 2 struct S0 3 { 4 int a; 5 }; 6 int main() 7 { 8 struct S0 s0; 9 s0.b = 1; 10 return 0; 11 } 12 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:9: __error__: struct S0 has no member named b 2 ,check-prog.c:9: __error__: left side of operator = is of type void --- Expected compilation errors: 1 ,check-prog.c:9: __error__: struct S0 has no member named b 2 ,check-prog.c:9: __error__: left side of operator = is of type void ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 27: Warnings on dubious function calls 1 2 void f() {} 3 int main() 4 { 5 int f; 6 f(); 7 int pf = f; 8 pf(); 9 return 0; 10 } 11 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:6: __warning__: calling 'f', which is both a variable and a function name 2 ,check-prog.c:8: __warning__: variable 'pf' used as function pointer without being of type void * --- Expected compilation errors: 1 ,check-prog.c:6: __warning__: calling 'f', which is both a variable and a function name 2 ,check-prog.c:8: __warning__: variable 'pf' used as function pointer without being of type void * ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 28: switch() 1 2 int f() { return 99; } 3 int main() 4 { 5 switch (1) return 42; 6 switch (1) { case f(): return 0; } 7 switch (1) { return 1; case 5: return 0; } 8 char c = 1; 9 switch (c) { case 500: return 1; } 10 unsigned char uc = 1; 11 switch (uc) { case 500: return 1; } 12 switch (1) { default: break; case 5: break; default: ; } 13 switch (1) { case 5: continue; } 14 switch (1) 15 { 16 case 3: 17 ; 18 case 3: // duplicate case value 19 ; 20 } 21 return 0; 22 } 23 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: switch() statement has no `case' or `default' statement 2 ,check-prog.c:6: __error__: case statement has a variable expression 3 ,check-prog.c:7: __error__: statement in switch precedes first `case' or `default' statement 4 ,check-prog.c:9: __warning__: switch expression is signed char but case value is not in range -128..127 5 ,check-prog.c:11: __warning__: switch expression is unsigned char but case value is not in range 0..255 6 ,check-prog.c:12: __error__: more than one default statement in switch 7 ,check-prog.c:18: __error__: duplicate case value (first used at ,check-prog.c:16) --- Expected compilation errors: 1 ,check-prog.c:5: __error__: switch() statement has no `case' or `default' statement 2 ,check-prog.c:6: __error__: case statement has a variable expression 3 ,check-prog.c:7: __error__: statement in switch precedes first `case' or `default' statement 4 ,check-prog.c:9: __warning__: switch expression is signed char but case value is not in range -128..127 5 ,check-prog.c:11: __warning__: switch expression is unsigned char but case value is not in range 0..255 6 ,check-prog.c:12: __error__: more than one default statement in switch 7 ,check-prog.c:18: __error__: duplicate case value (first used at ,check-prog.c:16) ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 29: Continue in a switch (not supported) 1 2 int f() { return 42; } 3 int main() 4 { 5 switch (1) { case 1: continue; } // error 6 switch (1) { case 1: while (1) continue; } // ok 7 return 0; 8 } 9 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: continue statement is not supported in a switch --- Expected compilation errors: 1 ,check-prog.c:5: __error__: continue statement is not supported in a switch ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 30: Invalid usage of "#pragma org" 1 2 #pragma org pizza 3 int main() 4 { 5 return 0; 6 } 7 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: invalid pragma directive: org pizza --- Expected compilation errors: 1 ,check-prog.c:2: __error__: invalid pragma directive: org pizza ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 31: Passing a wrong type to a function expecting a non-void pointer 1 2 struct S {}; 3 void f(struct S *p) {} 4 struct T {}; union U {}; 5 int main() 6 { 7 f(0); // OK: null pointer 8 f(3); // tolerated, unless -Wpass-const-for-func-pointer is passed 9 f(-4); // ditto 10 int n; 11 f(&n); // error: wrong type of pointer 12 struct T t; 13 f(&t); // error: ditto 14 struct S s; 15 f(&s); // OK 16 union U u; 17 f(&u); 18 return 0; 19 } 20 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:11: __error__: pointer type mismatch: passing int * as parameter 1 of function f(), which is a struct S * 2 ,check-prog.c:13: __error__: pointer type mismatch: passing struct T * as parameter 1 of function f(), which is a struct S * 3 ,check-prog.c:17: __error__: pointer type mismatch: passing union U * as parameter 1 of function f(), which is a struct S * --- Expected compilation errors: 1 ,check-prog.c:11: __error__: pointer type mismatch: passing int * as parameter 1 of function f(), which is a struct S * 2 ,check-prog.c:13: __error__: pointer type mismatch: passing struct T * as parameter 1 of function f(), which is a struct S * 3 ,check-prog.c:17: __error__: pointer type mismatch: passing union U * as parameter 1 of function f(), which is a struct S * ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 32: #pragma const_data 1 2 int f() { return 42; } 3 #pragma const_data start 4 int lacksInitializer; 5 int nonConstInitializer = f(); 6 int ok = 6809; 7 #pragma const_data end 8 int main() 9 { 10 return 0; 11 } 12 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: global variable 'lacksInitializer' declared in const_data section but has no initializer 2 ,check-prog.c:5: __error__: global variable 'nonConstInitializer' declared in const_data section but has a run-time initializer --- Expected compilation errors: 1 ,check-prog.c:4: __error__: global variable 'lacksInitializer' declared in const_data section but has no initializer 2 ,check-prog.c:5: __error__: global variable 'nonConstInitializer' declared in const_data section but has a run-time initializer ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 33: Referring to a member of an undefined struct 1 2 int main() 3 { 4 struct S *p = 0; 5 p->n = 42; 6 return 0; 7 } 8 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: reference to member `n' of undefined class `S' 2 ,check-prog.c:5: __error__: left side of operator = is of type void --- Expected compilation errors: 1 ,check-prog.c:5: __error__: reference to member `n' of undefined class `S' 2 ,check-prog.c:5: __error__: left side of operator = is of type void ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 34: Indirection of a pointer to a struct used as an r-value 1 2 struct S { int field; }; 3 struct T { struct S *ps; }; 4 int main() 5 { 6 struct S *ps = (struct S *) 100; 7 if (*ps) // bad 8 ; 9 if ((*ps).field == 0) // ok 10 ; 11 struct T *pt = (struct T *) 200; 12 if (*(*pt).ps) // bad 13 ; 14 if ((*(*pt).ps).field) // ok 15 ; 16 return 0; 17 } 18 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:7: __error__: invalid use of struct as condition of if statement 2 ,check-prog.c:12: __error__: invalid use of struct as condition of if statement --- Expected compilation errors: 1 ,check-prog.c:7: __error__: invalid use of struct as condition of if statement 2 ,check-prog.c:12: __error__: invalid use of struct as condition of if statement ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 35: Initializing from incompatible pointer type 1 2 int a[5][7][13]; 3 char n; 4 int main() 5 { 6 int *p0 = a; 7 p0 = a; 8 int *p1 = a + n; 9 p1 = a + n; 10 int *p2 = a + 1; 11 p2 = a + 1; 12 int *p2 = n; 13 p0 = n; 14 p0 = -1; 15 return 0; 16 } 17 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:12: __error__: variable `p2' already declared in this scope at ,check-prog.c:10 2 ,check-prog.c:7: __warning__: assigning pointer to int with incompatible int[][][] 3 ,check-prog.c:9: __warning__: assigning pointer to int with incompatible int[][][] 4 ,check-prog.c:11: __warning__: assigning pointer to int with incompatible int[][][] 5 ,check-prog.c:13: __warning__: assigning pointer with integer expression 6 ,check-prog.c:14: __warning__: assigning pointer with negative constant 7 ,check-prog.c:6: __warning__: initializing pointer to int 'p0' from incompatible int[][][] 8 ,check-prog.c:8: __warning__: initializing pointer to int 'p1' from incompatible int[][][] 9 ,check-prog.c:10: __warning__: initializing pointer to int 'p2' from incompatible int[][][] 10 ,check-prog.c:12: __warning__: initializing pointer 'p2' from integer expression --- Expected compilation errors: 1 ,check-prog.c:12: __error__: variable `p2' already declared in this scope at ,check-prog.c:10 2 ,check-prog.c:7: __warning__: assigning pointer to int with incompatible int[][][] 3 ,check-prog.c:9: __warning__: assigning pointer to int with incompatible int[][][] 4 ,check-prog.c:11: __warning__: assigning pointer to int with incompatible int[][][] 5 ,check-prog.c:13: __warning__: assigning pointer with integer expression 6 ,check-prog.c:14: __warning__: assigning pointer with negative constant 7 ,check-prog.c:6: __warning__: initializing pointer to int 'p0' from incompatible int[][][] 8 ,check-prog.c:8: __warning__: initializing pointer to int 'p1' from incompatible int[][][] 9 ,check-prog.c:10: __warning__: initializing pointer to int 'p2' from incompatible int[][][] 10 ,check-prog.c:12: __warning__: initializing pointer 'p2' from integer expression ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 36: Assembly-only function containing non-asm statement 1 2 int asm f() 3 { 4 int foo; // only asm{} allowed in asm function 5 asm {} 6 } 7 int asm g() 8 { 9 asm {} 10 return 42; // only asm{} allowed in asm function 11 } 12 int asm h(int m, char n, char *s) 13 { 14 asm { 15 ldb n 16 } 17 asm { 18 ldb s[12] 19 ldd m 20 ldb n 21 ldd m 22 tfr s,x // OK: s refers to register, not to C variable 23 } 24 asm("clr", n); 25 } 26 int global0 = 42; 27 void q() 28 { 29 asm("ldd", global0); // OK: variable is global 30 asm { 31 ldd global0 // ditto 32 } 33 } 34 int main() 35 { 36 int z; 37 asm { nop } // OK: no 'asm' modifier on this function 38 asm("clr", z); // ditto 39 return 0; 40 } 41 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: body of function f() contains statement(s) other than inline assembly 2 ,check-prog.c:10: __error__: body of function g() contains statement(s) other than inline assembly 3 ,check-prog.c:14: __error__: assembly-only function refers to local C variable `n' 4 ,check-prog.c:17: __error__: assembly-only function refers to local C variables `m', `n', `s' 5 ,check-prog.c:24: __error__: assembly-only function refers to local C variable `n' --- Expected compilation errors: 1 ,check-prog.c:4: __error__: body of function f() contains statement(s) other than inline assembly 2 ,check-prog.c:10: __error__: body of function g() contains statement(s) other than inline assembly 3 ,check-prog.c:14: __error__: assembly-only function refers to local C variable `n' 4 ,check-prog.c:17: __error__: assembly-only function refers to local C variables `m', `n', `s' 5 ,check-prog.c:24: __error__: assembly-only function refers to local C variable `n' ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 37: asm modifier used on non-function declarations 1 2 int asm globalVar0; // modifier only legal on a function 3 4 typedef int asm Bad; 5 int main() 6 { 7 int asm localVar; 8 return 0; 9 } 10 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: illegal modifier used on declaration of variable `globalVar0' 2 ,check-prog.c:4: __error__: illegal modifier used on typedef 3 ,check-prog.c:7: __error__: illegal modifier used on declaration of variable `localVar' --- Expected compilation errors: 1 ,check-prog.c:2: __error__: illegal modifier used on declaration of variable `globalVar0' 2 ,check-prog.c:4: __error__: illegal modifier used on typedef 3 ,check-prog.c:7: __error__: illegal modifier used on declaration of variable `localVar' ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 38: Illegal modifier used on declaration of variable 1 2 int interrupt globalVar1; 3 interrupt void isr() {} 4 int main() 5 { 6 int interrupt localVar; 7 isr(); 8 return 0; 9 } 10 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: illegal modifier used on declaration of variable `globalVar1' 2 ,check-prog.c:6: __error__: illegal modifier used on declaration of variable `localVar' --- Expected compilation errors: 1 ,check-prog.c:2: __error__: illegal modifier used on declaration of variable `globalVar1' 2 ,check-prog.c:6: __error__: illegal modifier used on declaration of variable `localVar' ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 39: Calling interrupt service routine 1 2 interrupt void isr() {} 3 int main() 4 { 5 isr(); 6 return 0; 7 } 8 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: calling function isr() is forbidden because it is an interrupt service routine --- Expected compilation errors: 1 ,check-prog.c:5: __error__: calling function isr() is forbidden because it is an interrupt service routine ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 40: Struct with field of undefined struct 1 2 struct Outer 3 { 4 struct Inner i; 5 }; 6 int main() 7 { 8 return 0; 9 } 10 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: member `i' of `Outer' is of undefined type `Inner' --- Expected compilation errors: 1 ,check-prog.c:4: __error__: member `i' of `Outer' is of undefined type `Inner' ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 41: union vs. struct 1 2 union U 3 { 4 int i; 5 }; 6 struct S 7 { 8 int i; 9 }; 10 struct Cell; 11 struct List 12 { 13 struct Cell *a, *b; 14 }; 15 union UndefUnion; 16 struct Cell fc(); 17 int main() 18 { 19 struct U u; 20 union S s; 21 struct Cell c; 22 union UndefUnion uu; 23 struct Cell *pc; // OK 24 union UndefUnion *puu; // OK 25 return 0; 26 } 27 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:16: __error__: declaring `fc' of undefined type struct `Cell' 2 ,check-prog.c:19: __error__: referring to U as a struct, but it is a union 3 ,check-prog.c:20: __error__: referring to S as a union, but it is a struct 4 ,check-prog.c:21: __error__: declaring `c' of undefined type struct `Cell' 5 ,check-prog.c:22: __error__: declaring `uu' of undefined type struct `UndefUnion' --- Expected compilation errors: 1 ,check-prog.c:16: __error__: declaring `fc' of undefined type struct `Cell' 2 ,check-prog.c:19: __error__: referring to U as a struct, but it is a union 3 ,check-prog.c:20: __error__: referring to S as a union, but it is a struct 4 ,check-prog.c:21: __error__: declaring `c' of undefined type struct `Cell' 5 ,check-prog.c:22: __error__: declaring `uu' of undefined type struct `UndefUnion' ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 42: Receiving an undefined aggregate type by value 1 2 struct Cell; 3 union U; 4 void fc1(struct Cell c); 5 void fc2(struct Cell c) {} 6 void fc3(union U u); 7 void fc4(union U u) {} 8 int main() 9 { 10 return 0; 11 } 12 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: argument 1 of fc1() receives undefined `struct Cell' by value 2 ,check-prog.c:5: __error__: argument 1 of fc2() receives undefined `struct Cell' by value 3 ,check-prog.c:6: __error__: argument 1 of fc3() receives undefined `union U' by value 4 ,check-prog.c:7: __error__: argument 1 of fc4() receives undefined `union U' by value --- Expected compilation errors: 1 ,check-prog.c:4: __error__: argument 1 of fc1() receives undefined `struct Cell' by value 2 ,check-prog.c:5: __error__: argument 1 of fc2() receives undefined `struct Cell' by value 3 ,check-prog.c:6: __error__: argument 1 of fc3() receives undefined `union U' by value 4 ,check-prog.c:7: __error__: argument 1 of fc4() receives undefined `union U' by value ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 43: Forbid --org and --data when targeting Vectrex 1 2 int main() 3 { 4 return 0; 5 } 6 --- Compilation command: ./cmoc --vectrex -Lstdlib -Lfloat -I './support' --org=0x300 --data=0x400 --monolith ,check-prog.c --- Actual compilation errors: 1 cmoc: --org and --data are not permitted for Vectrex --- Expected compilation errors: 1 cmoc: --org and --data are not permitted for Vectrex ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 44: Forbid code and data positioning pragmas when targeting Vectrex 1 2 #pragma org 0x100 3 #pragma data 0x200 4 int main() 5 { 6 return 0; 7 } 8 --- Compilation command: ./cmoc --vectrex -Lstdlib -Lfloat -I './support' --monolith ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: #pragma org is not permitted for Vectrex 2 ,check-prog.c:3: __error__: #pragma data is not permitted for Vectrex --- Expected compilation errors: 1 ,check-prog.c:2: __error__: #pragma org is not permitted for Vectrex 2 ,check-prog.c:3: __error__: #pragma data is not permitted for Vectrex ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 45: Function prototype local to a function body 1 2 void f() {} 3 int g() 4 { 5 char *f(); 6 return 1; // check that this JumpStmt is seen as inside g() 7 } 8 int main() 9 { 10 return 0; 11 } 12 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: invalid declaration --- Expected compilation errors: 1 ,check-prog.c:5: __error__: invalid declaration ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 46: Correct line number in error message when using function address to initialize char 1 2 char f() { return 42; } 3 int main() 4 { 5 char b = f; 6 return 0; 7 } 8 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: initializing char with expression of type void * --- Expected compilation errors: 1 ,check-prog.c:5: __error__: initializing char with expression of type void * ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 47: sizeof on an unknown struct name 1 2 struct S {}; 3 unsigned g0 = sizeof(struct Foo); 4 unsigned g1 = sizeof(struct S); 5 int main() 6 { 7 unsigned a = sizeof(struct Foo); 8 unsigned b; 9 b = sizeof(struct Foo); 10 b = sizeof(struct S); 11 b = sizeof(struct Bar); 12 return 0; 13 } 14 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:3: __error__: cannot take sizeof unknown struct or union 'Foo' 2 ,check-prog.c:7: __error__: cannot take sizeof unknown struct or union 'Foo' 3 ,check-prog.c:9: __error__: cannot take sizeof unknown struct or union 'Foo' 4 ,check-prog.c:11: __error__: cannot take sizeof unknown struct or union 'Bar' --- Expected compilation errors: 1 ,check-prog.c:3: __error__: cannot take sizeof unknown struct or union 'Foo' 2 ,check-prog.c:7: __error__: cannot take sizeof unknown struct or union 'Foo' 3 ,check-prog.c:9: __error__: cannot take sizeof unknown struct or union 'Foo' 4 ,check-prog.c:11: __error__: cannot take sizeof unknown struct or union 'Bar' ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 48: sizeof on an unknown array name, used twice in a binary expression 1 2 int main() 3 { 4 unsigned n = sizeof(a) / sizeof(a[0]); 5 return 0; 6 } 7 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: undeclared identifier `a' 2 ,check-prog.c:4: __error__: undeclared identifier `a' 3 ,check-prog.c:4: __error__: argument of sizeof operator is of type void 4 ,check-prog.c:4: __error__: left side of operator [] is of type void 5 ,check-prog.c:4: __error__: array reference on non array or pointer 6 ,check-prog.c:4: __error__: argument of sizeof operator is of type void 7 ,check-prog.c:4: __error__: cannot take sizeof(void) 8 ,check-prog.c:4: __error__: cannot take sizeof(void) 9 ,check-prog.c:4: __error__: lvalue required as left operand of array reference --- Expected compilation errors: 1 ,check-prog.c:4: __error__: undeclared identifier `a' 2 ,check-prog.c:4: __error__: undeclared identifier `a' 3 ,check-prog.c:4: __error__: argument of sizeof operator is of type void 4 ,check-prog.c:4: __error__: left side of operator [] is of type void 5 ,check-prog.c:4: __error__: array reference on non array or pointer 6 ,check-prog.c:4: __error__: argument of sizeof operator is of type void 7 ,check-prog.c:4: __error__: cannot take sizeof(void) 8 ,check-prog.c:4: __error__: cannot take sizeof(void) 9 ,check-prog.c:4: __error__: lvalue required as left operand of array reference ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 49: Passing integer for pointer parameter 1 2 int g() { return 42; } 3 void f(int *p) {} 4 int main() 5 { 6 f(g()); 7 return 0; 8 } 9 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:6: __warning__: passing non-pointer/array (int) as parameter 1 of function f(), which is int * --- Expected compilation errors: 1 ,check-prog.c:6: __warning__: passing non-pointer/array (int) as parameter 1 of function f(), which is int * ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 50: Invalid numerical constant 1 2 unsigned f0() { return 0777777; } 3 unsigned f1() { return 0xFFFFF; } 4 unsigned f2() { return 99999; } 5 int f3() { return -99999; } 6 int main() 7 { 8 return (int) (f0() + f1() + f2() + f3()); 9 } 10 This test is suspended. ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 51: Dereferencing a void pointer 1 2 void g(int n) {} 3 void f(void *p) 4 { 5 g(*p); 6 } 7 int main() 8 { 9 f(0); 10 return 0; 11 } 12 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: indirection of a pointer to void --- Expected compilation errors: 1 ,check-prog.c:5: __error__: indirection of a pointer to void ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 52: Use of a struct as an r-value 1 2 struct Inner { int n; }; 3 struct Outer { struct Inner i; }; 4 int main() 5 { 6 struct Outer obj; 7 if (obj) 8 return 1; 9 while (obj) 10 return 4; 11 for ( ; obj ; ) {} 12 if (obj.i) 13 return 2; 14 while (obj.i) 15 return 5; 16 if (!obj.i) 17 return 3; 18 while (!obj.i) 19 return 6; 20 return 0; 21 } 22 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:16: __error__: invalid use of boolean negation on a struct 2 ,check-prog.c:18: __error__: invalid use of boolean negation on a struct 3 ,check-prog.c:7: __error__: invalid use of struct as condition of if statement 4 ,check-prog.c:9: __error__: invalid use of struct as condition of while statement 5 ,check-prog.c:11: __error__: invalid use of struct as condition of for statement 6 ,check-prog.c:12: __error__: invalid use of struct as condition of if statement 7 ,check-prog.c:14: __error__: invalid use of struct as condition of while statement --- Expected compilation errors: 1 ,check-prog.c:16: __error__: invalid use of boolean negation on a struct 2 ,check-prog.c:18: __error__: invalid use of boolean negation on a struct 3 ,check-prog.c:7: __error__: invalid use of struct as condition of if statement 4 ,check-prog.c:9: __error__: invalid use of struct as condition of while statement 5 ,check-prog.c:11: __error__: invalid use of struct as condition of for statement 6 ,check-prog.c:12: __error__: invalid use of struct as condition of if statement 7 ,check-prog.c:14: __error__: invalid use of struct as condition of while statement ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 53: Anonymous struct 1 2 struct { int n; } a; 3 int main() 4 { 5 int *pi = &a; 6 return 0; 7 } 8 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: initializing int * with expression of type struct AnonStruct_,check-prog.c:2 * --- Expected compilation errors: 1 ,check-prog.c:5: __error__: initializing int * with expression of type struct AnonStruct_,check-prog.c:2 * ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 54: goto and ID-labeled statements 1 2 void f() 3 { 4 foo: ; // ok 5 bar: ; 6 } 7 int main() 8 { 9 foo: 10 foo: 11 f(); 12 goto bar; 13 goto imaginary; 14 return 0; 15 } 16 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:10: __error__: label `foo' already defined at ,check-prog.c:9 2 ,check-prog.c:12: __error__: goto targets label `bar' which is unknown to function main() 3 ,check-prog.c:13: __error__: goto targets label `imaginary' which is unknown to function main() --- Expected compilation errors: 1 ,check-prog.c:10: __error__: label `foo' already defined at ,check-prog.c:9 2 ,check-prog.c:12: __error__: goto targets label `bar' which is unknown to function main() 3 ,check-prog.c:13: __error__: goto targets label `imaginary' which is unknown to function main() ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 55: Conditional with incompatible types 1 2 void g(int) {} 3 int main() 4 { 5 char *p; 6 int i; 7 g(i > 0 ? p : i); 8 g(i > 0 ? (char) 0x12 : i); 9 unsigned char ub = 42; 10 g(i > 0 ? 256 : ub); // warning because 256 is signed 11 unsigned ui = 4242; 12 g(i > 0 ? 256U : ui); // no warning 13 return 0; 14 } 15 char a[] = { 1, 2, 3 }; 16 char *getArray() { return a; } 17 char f(char condition) 18 { 19 char *p = (condition ? getArray() : a); // OK because char * and char[] are close enough 20 return *p; 21 } 22 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:7: __error__: true and false expressions of conditional are of incompatible types (char * vs int) 2 ,check-prog.c:8: __warning__: true and false expressions of conditional are not of the same type (char vs int); result is of type int 3 ,check-prog.c:10: __warning__: true and false expressions of conditional are not of the same type (int vs unsigned char); result is of type int --- Expected compilation errors: 1 ,check-prog.c:7: __error__: true and false expressions of conditional are of incompatible types (char * vs int) 2 ,check-prog.c:8: __warning__: true and false expressions of conditional are not of the same type (char vs int); result is of type int 3 ,check-prog.c:10: __warning__: true and false expressions of conditional are not of the same type (int vs unsigned char); result is of type int ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 56: Automatic type conversions 1 2 unsigned char returnByte(unsigned char b) 3 { 4 return b; 5 } 6 int main() 7 { 8 int i = 1000; 9 char c; 10 c = i; 11 c = 2000; 12 unsigned u = 1001; 13 unsigned char uc; 14 uc = u; 15 uc = 2001; 16 17 u = 100; 18 u = (u > 99 ? 50 : u); 19 unsigned char b = 12; 20 u = (u > 66 ? u : returnByte(b)); 21 u = 999; 22 u = (u < 2000 ? u : returnByte(b)); 23 return 0; 24 } 25 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:10: __warning__: assigning to `char' from larger type `int' 2 ,check-prog.c:11: __warning__: assigning to `char' from larger constant of type `int' 3 ,check-prog.c:14: __warning__: assigning to `unsigned char' from larger type `unsigned int' 4 ,check-prog.c:15: __warning__: assigning to `unsigned char' from larger constant of type `int' 5 ,check-prog.c:18: __warning__: true and false expressions of conditional are not of the same type (int vs unsigned int); result is of type int 6 ,check-prog.c:20: __warning__: true and false expressions of conditional are not of the same type (unsigned int vs unsigned char); result is of type unsigned int 7 ,check-prog.c:22: __warning__: true and false expressions of conditional are not of the same type (unsigned int vs unsigned char); result is of type unsigned int --- Expected compilation errors: 1 ,check-prog.c:10: __warning__: assigning to `char' from larger type `int' 2 ,check-prog.c:11: __warning__: assigning to `char' from larger constant of type `int' 3 ,check-prog.c:14: __warning__: assigning to `unsigned char' from larger type `unsigned int' 4 ,check-prog.c:15: __warning__: assigning to `unsigned char' from larger constant of type `int' 5 ,check-prog.c:18: __warning__: true and false expressions of conditional are not of the same type (int vs unsigned int); result is of type int 6 ,check-prog.c:20: __warning__: true and false expressions of conditional are not of the same type (unsigned int vs unsigned char); result is of type unsigned int 7 ,check-prog.c:22: __warning__: true and false expressions of conditional are not of the same type (unsigned int vs unsigned char); result is of type unsigned int ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 57: Wrong use of assignment operator with structs 1 2 struct S { int i; }; 3 struct Other {} other; 4 void f(char *, ...) {} 5 int main() 6 { 7 struct S s, t; 8 int i; 9 s = 'x'; 10 s = i; 11 s = &i; 12 i = s; 13 s += t; 14 f("", s = t); 15 struct S u = 42; 16 struct S v = other; 17 struct S w = &other; 18 return 0; 19 } 20 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:9: __error__: cannot assign `char' to `struct S' 2 ,check-prog.c:10: __error__: cannot assign `int' to `struct S' 3 ,check-prog.c:11: __error__: cannot assign `int *' to `struct S' 4 ,check-prog.c:12: __error__: cannot assign `struct S' to `int' 5 ,check-prog.c:13: __error__: invalid use of += on a struct or union 6 ,check-prog.c:15: __error__: initializer for struct S is of type `int': must be list, or struct of same type 7 ,check-prog.c:16: __error__: initializer for struct S is of type `struct Other': must be list, or struct of same type 8 ,check-prog.c:17: __error__: initializer for struct S is of type `struct Other *': must be list, or struct of same type --- Expected compilation errors: 1 ,check-prog.c:9: __error__: cannot assign `char' to `struct S' 2 ,check-prog.c:10: __error__: cannot assign `int' to `struct S' 3 ,check-prog.c:11: __error__: cannot assign `int *' to `struct S' 4 ,check-prog.c:12: __error__: cannot assign `struct S' to `int' 5 ,check-prog.c:13: __error__: invalid use of += on a struct or union 6 ,check-prog.c:15: __error__: initializer for struct S is of type `int': must be list, or struct of same type 7 ,check-prog.c:16: __error__: initializer for struct S is of type `struct Other': must be list, or struct of same type 8 ,check-prog.c:17: __error__: initializer for struct S is of type `struct Other *': must be list, or struct of same type ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 58: Static keyword 1 2 static int g0; // equivalent to "int g0;" 3 int g0; // duplicates previous declaration 4 int g1; 5 static int g1; // duplicates previous declaration 6 static int g2; 7 extern int g2; // no problem: entire line is ignored 8 int main() 9 { 10 extern int g3; // ignored 11 static int g4; // local static not supported 12 g4 = 1; 13 return 0; 14 } 15 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:3: __error__: global variable `g0' already declared at global scope at ,check-prog.c:2 2 ,check-prog.c:5: __error__: global variable `g1' already declared at global scope at ,check-prog.c:4 3 ,check-prog.c:11: __error__: local static variables are not supported --- Expected compilation errors: 1 ,check-prog.c:3: __error__: global variable `g0' already declared at global scope at ,check-prog.c:2 2 ,check-prog.c:5: __error__: global variable `g1' already declared at global scope at ,check-prog.c:4 3 ,check-prog.c:11: __error__: local static variables are not supported ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 59: More than one formal parameter with same name 1 2 void f1(int a, int b, int a); 3 void f2(int a, int b, int a) {} 4 void f3(int a, int, char a) {} 5 void f4(int, int, char); // OK 6 int main() 7 { 8 return 0; 9 } 10 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: function f1() has more than one formal parameter named 'a' 2 ,check-prog.c:3: __error__: function f2() has more than one formal parameter named 'a' 3 ,check-prog.c:4: __error__: function f3() has more than one formal parameter named 'a' --- Expected compilation errors: 1 ,check-prog.c:2: __error__: function f1() has more than one formal parameter named 'a' 2 ,check-prog.c:3: __error__: function f2() has more than one formal parameter named 'a' 3 ,check-prog.c:4: __error__: function f3() has more than one formal parameter named 'a' ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 60: Returning wrong struct pointer type 1 2 struct A {}; 3 struct B {} b; 4 struct A *f() 5 { 6 return &b; 7 } 8 int main() 9 { 10 return f() != 0; 11 } 12 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:6: __error__: returning expression of type struct B *, which differs from function's return type (struct A *) --- Expected compilation errors: 1 ,check-prog.c:6: __error__: returning expression of type struct B *, which differs from function's return type (struct A *) ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 61: Bad type specifier combinations 1 2 int main() 3 { 4 int char x; 5 signed void p; 6 return 0; 7 } 8 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: combining type specifiers is not supported 2 ,check-prog.c:5: __error__: signed and unsigned modifiers can only be applied to integral type --- Expected compilation errors: 1 ,check-prog.c:4: __error__: combining type specifiers is not supported 2 ,check-prog.c:5: __error__: signed and unsigned modifiers can only be applied to integral type ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 62: Typedef local to a function 1 2 int main() 3 { 4 typedef int Integer; 5 Integer n = 42; 6 return n; 7 } 8 This test is suspended. ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 63: enum 1 2 enum A { A0 }; 3 enum A { A1 }; // error: 'A' already used 4 5 enum B { DuplicateEnumeratedName }; 6 7 8 void f0(enum { EnumNameInFunctionParam } e) {} // error: enumerator in formal param not supported 9 void f5(enum { OtherEnumNameInFunctionParam } e); // error: same, but on prototype 10 11 enum { EnumNameInReturnType } f1() { return 0; } // error: enumerator in return type 12 enum { OtherEnumNameInReturnType } f2(); // error: same, but on prototype 13 14 enum D { D0 }; 15 enum D f3() { return D0; } // ok 16 enum D f4(); // ok 17 18 signed enum F { F0 } f0; 19 20 void funcTakingA(enum A a) {} 21 22 int main() 23 { 24 enum { X } localEnumVar; 25 enum E { E0 } otherLocalEnumVar; 26 funcTakingA(A0); // ok 27 funcTakingA(5); // error: 5 not member of enum A 28 funcTakingA(D0); // error: D0 not member of enum A 29 return 0; 30 } 31 enum C { DuplicateEnumeratedName }; // error re: enum B 32 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:3: __error__: enum `A' already defined at ,check-prog.c:2 2 ,check-prog.c:8: __error__: enum with enumerated names is not supported in a function's formal parameter 3 ,check-prog.c:9: __error__: enum with enumerated names is not supported in a function's formal parameter 4 ,check-prog.c:11: __error__: enum with enumerated names is not supported in a function's return type 5 ,check-prog.c:12: __error__: enum with enumerated names is not supported in a function prototype's return type 6 ,check-prog.c:18: __error__: signed and unsigned modifiers cannot be applied to an enum 7 ,check-prog.c:31: __error__: enumerated name `DuplicateEnumeratedName' already defined at ,check-prog.c:5 --- Expected compilation errors: 1 ,check-prog.c:3: __error__: enum `A' already defined at ,check-prog.c:2 2 ,check-prog.c:8: __error__: enum with enumerated names is not supported in a function's formal parameter 3 ,check-prog.c:9: __error__: enum with enumerated names is not supported in a function's formal parameter 4 ,check-prog.c:11: __error__: enum with enumerated names is not supported in a function's return type 5 ,check-prog.c:12: __error__: enum with enumerated names is not supported in a function prototype's return type 6 ,check-prog.c:18: __error__: signed and unsigned modifiers cannot be applied to an enum 7 ,check-prog.c:31: __error__: enumerated name `DuplicateEnumeratedName' already defined at ,check-prog.c:5 ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 64: enum, bis 1 2 enum A { A0 }; 3 4 enum D { D0 }; 5 enum D f3() { return D0; } // ok 6 enum D f4(); // ok 7 8 void funcTakingA(enum A a) {} 9 10 int main() 11 { 12 enum { X } localEnumVar; 13 enum E { E0 } otherLocalEnumVar; 14 funcTakingA(A0); // ok 15 funcTakingA(5); // error: 5 not member of enum A 16 funcTakingA(D0); // error: D0 not member of enum A 17 return 0; 18 } 19 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:15: __error__: parameter 1 of function funcTakingA() must be a member of enum A 2 ,check-prog.c:16: __error__: `D0' used as parameter 1 of function funcTakingA() but is not a member of enum A 3 ,check-prog.c:12: __error__: non-global enum not supported 4 ,check-prog.c:13: __error__: non-global enum not supported --- Expected compilation errors: 1 ,check-prog.c:15: __error__: parameter 1 of function funcTakingA() must be a member of enum A 2 ,check-prog.c:16: __error__: `D0' used as parameter 1 of function funcTakingA() but is not a member of enum A 3 ,check-prog.c:12: __error__: non-global enum not supported 4 ,check-prog.c:13: __error__: non-global enum not supported ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 65: Declaring an enum variable without the enum keyword 1 2 enum E { E0 }; 3 E e; // error 4 int main() 5 { 6 return 0; 7 } 8 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:3: __error__: syntax error: E --- Expected compilation errors: 1 ,check-prog.c:3: __error__: syntax error: E ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 66: String numerical escape sequence out of range 1 2 int main() 3 { 4 char *s0 = "\x80bomber"; // error: $80b > 255 5 char *s1 = "zzz\0777zzz"; // error: 0777 > 255 6 return 0; 7 } 8 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __warning__: hex escape sequence out of range 2 ,check-prog.c:5: __warning__: octal escape sequence out of range --- Expected compilation errors: 1 ,check-prog.c:4: __warning__: hex escape sequence out of range 2 ,check-prog.c:5: __warning__: octal escape sequence out of range ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 67: Named argument required before ellipsis of variadic function declaration or definition 1 2 void functionWithNoNamedArg(...) {} 3 void prototypeWithNoNamedArg(...); 4 int main() 5 { 6 return 0; 7 } 8 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: function functionWithNoNamedArg() uses `...' but has no named argument before it 2 ,check-prog.c:3: __error__: prototype prototypeWithNoNamedArg() uses `...' but has no named argument before it --- Expected compilation errors: 1 ,check-prog.c:2: __error__: function functionWithNoNamedArg() uses `...' but has no named argument before it 2 ,check-prog.c:3: __error__: prototype prototypeWithNoNamedArg() uses `...' but has no named argument before it ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 68: Named argument required before ellipsis of variadic function pointer variable 1 2 int main() 3 { 4 void (*fp)(...); 5 return 0; 6 } 7 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: named argument is required before `...' --- Expected compilation errors: 1 ,check-prog.c:4: __error__: named argument is required before `...' ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 69: l-value required for some operators 1 2 void f(unsigned *n) {} 3 char g() { return 1; } 4 int *h() { return 0; } 5 int main() 6 { 7 unsigned n = 891; 8 f(&(n >> 1)); 9 ++(n >> 1); 10 --(n >> 1); 11 (n >> 1)++; 12 (n >> 1)--; 13 char a, b; 14 (g() ? a : b) = 42; // OK because both alternatives are l-values 15 (g() ? a : 99) = 42; 16 (g() ? 99 : b) = 42; 17 h()[0] = 0; // OK 18 *h() = 0; // OK 19 ((int *) 0x400)[32] = 0; // OK 20 return 0; 21 } 22 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:8: __error__: lvalue required as operand of address-of 2 ,check-prog.c:9: __error__: lvalue required as operand of pre-increment 3 ,check-prog.c:10: __error__: lvalue required as operand of pre-decrement 4 ,check-prog.c:11: __error__: lvalue required as operand of post-increment 5 ,check-prog.c:12: __error__: lvalue required as operand of post-decrement 6 ,check-prog.c:15: __error__: lvalue required as left operand of assignment 7 ,check-prog.c:16: __error__: lvalue required as left operand of assignment --- Expected compilation errors: 1 ,check-prog.c:8: __error__: lvalue required as operand of address-of 2 ,check-prog.c:9: __error__: lvalue required as operand of pre-increment 3 ,check-prog.c:10: __error__: lvalue required as operand of pre-decrement 4 ,check-prog.c:11: __error__: lvalue required as operand of post-increment 5 ,check-prog.c:12: __error__: lvalue required as operand of post-decrement 6 ,check-prog.c:15: __error__: lvalue required as left operand of assignment 7 ,check-prog.c:16: __error__: lvalue required as left operand of assignment ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 70: Various array errors 1 2 int main() 3 { 4 int a0[]; 5 int a1[5][]; 6 int a3["foo"]; 7 int n = 5; 8 int a4[n]; 9 return 0; 10 } 11 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: array a0: no size of first dimension, no initialization expression 2 ,check-prog.c:5: __error__: array a1: dimension other than first one is unspecified 3 ,check-prog.c:6: __error__: pointer or array expression used for size of array 'a3' 4 ,check-prog.c:8: __error__: invalid size expression for dimension 1 array 'a4' --- Expected compilation errors: 1 ,check-prog.c:4: __error__: array a0: no size of first dimension, no initialization expression 2 ,check-prog.c:5: __error__: array a1: dimension other than first one is unspecified 3 ,check-prog.c:6: __error__: pointer or array expression used for size of array 'a3' 4 ,check-prog.c:8: __error__: invalid size expression for dimension 1 array 'a4' ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 71: -Wsign-compare 1 2 char f(unsigned char uc, signed char sc) 3 { 4 if (uc < sc) 5 return 1; 6 if (uc <= sc) 7 return 2; 8 if (uc > sc) 9 return 3; 10 if (uc >= sc) 11 return 4; 12 if (sc < uc) 13 return 1; 14 if (sc <= uc) 15 return 2; 16 if (sc > uc) 17 return 3; 18 if (sc >= uc) 19 return 4; 20 if (uc >= uc) 21 return 5; 22 if (sc >= sc) 23 return 5; 24 return 0; 25 } 26 int main() 27 { 28 f(0, 0); 29 return 0; 30 } 31 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' -Wsign-compare ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __warning__: comparison of integers of different signs (`unsigned char' vs `char'); using unsigned comparison 2 ,check-prog.c:6: __warning__: comparison of integers of different signs (`unsigned char' vs `char'); using unsigned comparison 3 ,check-prog.c:8: __warning__: comparison of integers of different signs (`unsigned char' vs `char'); using unsigned comparison 4 ,check-prog.c:10: __warning__: comparison of integers of different signs (`unsigned char' vs `char'); using unsigned comparison 5 ,check-prog.c:12: __warning__: comparison of integers of different signs (`char' vs `unsigned char'); using unsigned comparison 6 ,check-prog.c:14: __warning__: comparison of integers of different signs (`char' vs `unsigned char'); using unsigned comparison 7 ,check-prog.c:16: __warning__: comparison of integers of different signs (`char' vs `unsigned char'); using unsigned comparison 8 ,check-prog.c:18: __warning__: comparison of integers of different signs (`char' vs `unsigned char'); using unsigned comparison --- Expected compilation errors: 1 ,check-prog.c:4: __warning__: comparison of integers of different signs (`unsigned char' vs `char'); using unsigned comparison 2 ,check-prog.c:6: __warning__: comparison of integers of different signs (`unsigned char' vs `char'); using unsigned comparison 3 ,check-prog.c:8: __warning__: comparison of integers of different signs (`unsigned char' vs `char'); using unsigned comparison 4 ,check-prog.c:10: __warning__: comparison of integers of different signs (`unsigned char' vs `char'); using unsigned comparison 5 ,check-prog.c:12: __warning__: comparison of integers of different signs (`char' vs `unsigned char'); using unsigned comparison 6 ,check-prog.c:14: __warning__: comparison of integers of different signs (`char' vs `unsigned char'); using unsigned comparison 7 ,check-prog.c:16: __warning__: comparison of integers of different signs (`char' vs `unsigned char'); using unsigned comparison 8 ,check-prog.c:18: __warning__: comparison of integers of different signs (`char' vs `unsigned char'); using unsigned comparison ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 72: Without -Wsign-compare 1 2 char f(unsigned char uc, signed char sc) 3 { 4 if (uc < sc) 5 return 1; 6 if (uc <= sc) 7 return 2; 8 if (uc > sc) 9 return 3; 10 if (uc >= sc) 11 return 4; 12 return 0; 13 } 14 int main() 15 { 16 f(0, 0); 17 return 0; 18 } 19 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: --- Expected compilation errors: ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 73: Invalid use of void expression 1 2 void f(int n) {} 3 int main() 4 { 5 char *cp; 6 cp[5] = 0; 7 void *vp; 8 vp[5] = 0; 9 *vp = 0; 10 f(vp[7]); 11 f(*vp); 12 return 0; 13 } 14 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:8: __error__: left side of operator = is of type void 2 ,check-prog.c:9: __error__: left side of operator = is of type void 3 ,check-prog.c:8: __error__: invalid use of void expression 4 ,check-prog.c:9: __error__: indirection of a pointer to void 5 ,check-prog.c:10: __error__: invalid use of void expression 6 ,check-prog.c:11: __error__: indirection of a pointer to void --- Expected compilation errors: 1 ,check-prog.c:8: __error__: left side of operator = is of type void 2 ,check-prog.c:9: __error__: left side of operator = is of type void 3 ,check-prog.c:8: __error__: invalid use of void expression 4 ,check-prog.c:9: __error__: indirection of a pointer to void 5 ,check-prog.c:10: __error__: invalid use of void expression 6 ,check-prog.c:11: __error__: indirection of a pointer to void ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 74: Too many or not enough elements in array initializer 1 2 struct S { int a[3]; char c; }; 3 int main() 4 { 5 int a0[3] = { 99, 88, 77, 66 }; 6 int a1[3] = { 99, 88 }; 7 char a2[3] = "foo"; // no room for terminating \0: error 8 char a3[3] = "foobar"; // worse 9 char a4[3] = "x"; // v2[2] not initialized: no warning 10 struct S s0 = { { 55, 44, 33, 22 }, '$' }; // too many ints: error 11 struct S s1 = { { 55, 44 }, '$' }; // not enough ints: warning 12 return 0; 13 } 14 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: too many elements (4) in initializer for array of 3 element(s) 2 ,check-prog.c:6: __warning__: only 2 element(s) in initializer for array of 3 element(s) 3 ,check-prog.c:7: __error__: too many characters (4) in string literal initializer for array of 3 character(s) 4 ,check-prog.c:8: __error__: too many characters (7) in string literal initializer for array of 3 character(s) 5 ,check-prog.c:10: __error__: too many elements (4) in initializer for array of 3 element(s) 6 ,check-prog.c:11: __warning__: only 2 element(s) in initializer for array of 3 element(s) --- Expected compilation errors: 1 ,check-prog.c:5: __error__: too many elements (4) in initializer for array of 3 element(s) 2 ,check-prog.c:6: __warning__: only 2 element(s) in initializer for array of 3 element(s) 3 ,check-prog.c:7: __error__: too many characters (4) in string literal initializer for array of 3 character(s) 4 ,check-prog.c:8: __error__: too many characters (7) in string literal initializer for array of 3 character(s) 5 ,check-prog.c:10: __error__: too many elements (4) in initializer for array of 3 element(s) 6 ,check-prog.c:11: __warning__: only 2 element(s) in initializer for array of 3 element(s) ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 75: Warning option for when assing a numerical constant for a function's pointer parameter 1 2 void f(char *p) {} 3 int main() 4 { 5 f(42); 6 f(0); // no warning 7 return 0; 8 } 9 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' -Wpass-const-for-func-pointer ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __warning__: passing constant as parameter 1 of function f(), which is char * --- Expected compilation errors: 1 ,check-prog.c:5: __warning__: passing constant as parameter 1 of function f(), which is char * ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 76: No warning by default when assing a numerical constant for a function's pointer parameter 1 2 void f(char *p) {} 3 int main() 4 { 5 f(42); 6 f(0); 7 return 0; 8 } 9 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: --- Expected compilation errors: ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 77: Unknown enumerator name used to define an enumerator 1 2 enum { B = A + 1 }; 3 int main() 4 { 5 return B; 6 } 7 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: unknown enumerator `A' --- Expected compilation errors: 1 ,check-prog.c:2: __error__: unknown enumerator `A' ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 78: Return value of a void function must be ignored 1 2 void f() {} 3 int main() 4 { 5 if (f() == 0) 6 return 1; 7 if (0 == f()) 8 return 1; 9 if (- f()) 10 return 1; 11 if (! f()) 12 return 1; 13 if (* f()) 14 return 1; 15 if (& f()) 16 return 1; 17 if (~ f()) 18 return 1; 19 return f(); 20 } 21 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: left side of operator == is of type void 2 ,check-prog.c:7: __error__: right side of operator == is of type void 3 ,check-prog.c:9: __error__: argument of arithmetic negation operator is of type void 4 ,check-prog.c:11: __error__: argument of boolean negation operator is of type void 5 ,check-prog.c:13: __error__: argument of indirection operator is of type void 6 ,check-prog.c:15: __error__: argument of address-of operator is of type void 7 ,check-prog.c:17: __error__: argument of bitwise not operator is of type void 8 ,check-prog.c:19: __error__: returning expression of type void, which differs from function's return type (int) --- Expected compilation errors: 1 ,check-prog.c:5: __error__: left side of operator == is of type void 2 ,check-prog.c:7: __error__: right side of operator == is of type void 3 ,check-prog.c:9: __error__: argument of arithmetic negation operator is of type void 4 ,check-prog.c:11: __error__: argument of boolean negation operator is of type void 5 ,check-prog.c:13: __error__: argument of indirection operator is of type void 6 ,check-prog.c:15: __error__: argument of address-of operator is of type void 7 ,check-prog.c:17: __error__: argument of bitwise not operator is of type void 8 ,check-prog.c:19: __error__: returning expression of type void, which differs from function's return type (int) ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 79: Function name used where function pointer pointer expected 1 2 typedef char (*FuncPtrType)(); 3 struct S1 4 { 5 FuncPtrType *funcPtrPtr; // pointer to pointer to function 6 }; 7 char f() { return 0; } // of type FuncPtrType 8 int main() 9 { 10 struct S1 s1 = { f }; // error: assigning void * to pointer to pointer to function 11 return 0; 12 } 13 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:10: __error__: initializing void ** with expression of type void * --- Expected compilation errors: 1 ,check-prog.c:10: __error__: initializing void ** with expression of type void * ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 80: Array of function pointers 1 2 char (*f0)()[]; 3 char (*f1)()[2]; 4 char (*f2)()[2][3]; 5 char (*g0[])(); 6 char (*g1[2])(); 7 char (*g2[2][3])(); 8 int main() 9 { 10 return 0; 11 } 12 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: subscript on function pointer declarator not supported 2 ,check-prog.c:3: __error__: subscript on function pointer declarator not supported 3 ,check-prog.c:4: __error__: subscript on function pointer declarator not supported 4 ,check-prog.c:4: __error__: subscript on function pointer declarator not supported 5 ,check-prog.c:5: __error__: subscript on function pointer declarator not supported 6 ,check-prog.c:6: __error__: subscript on function pointer declarator not supported 7 ,check-prog.c:7: __error__: subscript on function pointer declarator not supported --- Expected compilation errors: 1 ,check-prog.c:2: __error__: subscript on function pointer declarator not supported 2 ,check-prog.c:3: __error__: subscript on function pointer declarator not supported 3 ,check-prog.c:4: __error__: subscript on function pointer declarator not supported 4 ,check-prog.c:4: __error__: subscript on function pointer declarator not supported 5 ,check-prog.c:5: __error__: subscript on function pointer declarator not supported 6 ,check-prog.c:6: __error__: subscript on function pointer declarator not supported 7 ,check-prog.c:7: __error__: subscript on function pointer declarator not supported ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 81: Instruction argument refers to undeclared variable or enumerator 1 2 int main() 3 { 4 for (;;) // check that asm{} works in a sub-scope of the function scope 5 { 6 char *pc; 7 asm { 8 stu :y // error: y not defined 9 stu :foo // error: foo not defined 10 std :pc // no error: variable 'pc' declared 11 inc : // error: variable name is empty 12 } 13 break; 14 } 15 asm { clr :ch } // error: ch not declared yet 16 char ch; 17 return 0; 18 } 19 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:7: __error__: undeclared identifier `' in assembly language statement 2 ,check-prog.c:7: __error__: undeclared identifier `foo' in assembly language statement 3 ,check-prog.c:7: __error__: undeclared identifier `y' in assembly language statement 4 ,check-prog.c:15: __error__: undeclared identifier `ch' in assembly language statement --- Expected compilation errors: 1 ,check-prog.c:7: __error__: undeclared identifier `' in assembly language statement 2 ,check-prog.c:7: __error__: undeclared identifier `foo' in assembly language statement 3 ,check-prog.c:7: __error__: undeclared identifier `y' in assembly language statement 4 ,check-prog.c:15: __error__: undeclared identifier `ch' in assembly language statement ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 82: Function without formal parameters 1 2 void f {} 3 int main 4 { 5 return 0; 6 } 7 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: function f() has no formal parameter list 2 ,check-prog.c:3: __error__: function main() has no formal parameter list --- Expected compilation errors: 1 ,check-prog.c:2: __error__: function f() has no formal parameter list 2 ,check-prog.c:3: __error__: function main() has no formal parameter list ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 83: Argument too large for function parameter 1 2 char takeChar(char x) { return x; } 3 unsigned char takeUnsignedChar(unsigned char x) { return x; } 4 int main() 5 { 6 char c = takeChar(0x1234); 7 c = takeChar(0x12F0); 8 unsigned char uc = takeUnsignedChar(0x1256); 9 uc = takeUnsignedChar(0x12F8); 10 return 0; 11 } 12 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:6: __warning__: passing `int' argument as `char' parameter 1 ('x') of function takeChar() 2 ,check-prog.c:7: __warning__: passing `int' argument as `char' parameter 1 ('x') of function takeChar() 3 ,check-prog.c:8: __warning__: passing `int' argument as `unsigned char' parameter 1 ('x') of function takeUnsignedChar() 4 ,check-prog.c:9: __warning__: passing `int' argument as `unsigned char' parameter 1 ('x') of function takeUnsignedChar() --- Expected compilation errors: 1 ,check-prog.c:6: __warning__: passing `int' argument as `char' parameter 1 ('x') of function takeChar() 2 ,check-prog.c:7: __warning__: passing `int' argument as `char' parameter 1 ('x') of function takeChar() 3 ,check-prog.c:8: __warning__: passing `int' argument as `unsigned char' parameter 1 ('x') of function takeUnsignedChar() 4 ,check-prog.c:9: __warning__: passing `int' argument as `unsigned char' parameter 1 ('x') of function takeUnsignedChar() ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 84: Float 1 2 int main() 3 { 4 float f; // warning on 'float' when compiling for USim 5 double d; 6 float *pf; 7 f = pf; 8 pf = f; 9 f = (float) pf; 10 pf = (float *) f; 11 return 0; 12 } 13 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __warning__: floating-point arithmetic is not supported on this platform 2 ,check-prog.c:5: __warning__: `double' is an alias for `float' for this compiler 3 ,check-prog.c:7: __error__: cannot assign `float *' to `float' 4 ,check-prog.c:8: __error__: cannot assign `float' to `float *' 5 ,check-prog.c:9: __error__: cannot cast `float *' to `float' 6 ,check-prog.c:10: __error__: cannot cast `float' to `float *' --- Expected compilation errors: 1 ,check-prog.c:4: __warning__: floating-point arithmetic is not supported on this platform 2 ,check-prog.c:5: __warning__: `double' is an alias for `float' for this compiler 3 ,check-prog.c:7: __error__: cannot assign `float *' to `float' 4 ,check-prog.c:8: __error__: cannot assign `float' to `float *' 5 ,check-prog.c:9: __error__: cannot cast `float *' to `float' 6 ,check-prog.c:10: __error__: cannot cast `float' to `float *' ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 85: Floating-point arithmetic 1 2 int main() 3 { 4 signed float sf; 5 unsigned float uf; 6 signed double sd; 7 unsigned double ud; 8 return 0; 9 } 10 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __warning__: floating-point arithmetic is not supported on this platform 2 ,check-prog.c:4: __error__: signed and unsigned modifiers can only be applied to integral type 3 ,check-prog.c:5: __error__: signed and unsigned modifiers can only be applied to integral type 4 ,check-prog.c:6: __warning__: `double' is an alias for `float' for this compiler 5 ,check-prog.c:6: __error__: signed and unsigned modifiers can only be applied to integral type 6 ,check-prog.c:7: __error__: signed and unsigned modifiers can only be applied to integral type --- Expected compilation errors: 1 ,check-prog.c:4: __warning__: floating-point arithmetic is not supported on this platform 2 ,check-prog.c:4: __error__: signed and unsigned modifiers can only be applied to integral type 3 ,check-prog.c:5: __error__: signed and unsigned modifiers can only be applied to integral type 4 ,check-prog.c:6: __warning__: `double' is an alias for `float' for this compiler 5 ,check-prog.c:6: __error__: signed and unsigned modifiers can only be applied to integral type 6 ,check-prog.c:7: __error__: signed and unsigned modifiers can only be applied to integral type ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 86: Uncalled static function 1 2 static void used() {} 3 static void unused() {} // warning expected 4 void usedButExported() {} // no warning expected 5 int main() 6 { 7 used(); 8 return 0; 9 } 10 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:3: __warning__: static function unused() is not called --- Expected compilation errors: 1 ,check-prog.c:3: __warning__: static function unused() is not called ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 87: Function with both static and extern modifiers 1 2 extern static void f() {} 3 int main() 4 { 5 f(); 6 return 0; 7 } 8 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: function definition must not be both static and extern --- Expected compilation errors: 1 ,check-prog.c:2: __error__: function definition must not be both static and extern ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### -------------------------------------------------------------------------------- --- Program # 88: static main() 1 2 static int main() 3 { 4 return 0; 5 } 6 --- Compilation command: ./cmoc --usim -Lstdlib -Lfloat -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: main() must not be static --- Expected compilation errors: 1 ,check-prog.c:2: __error__: main() must not be static ### ls ,check-prog.*: ,check-prog.c ,check-prog.srec ### Cleaning up: erasing ,check-prog.c erasing ,check-prog.srec ./test-bad-programs.pl: ALL 89 tests PASSED ### # # ### ### ##### ### ### # # # # # # # # # # # # # # # # # # # # # ### # # # # ### ### ### # # # # # # # # # # # # # # # # # # # # # ### ### ### ### ##### ### ### test-bad-programs.pl: 0 error(s), 0 warnings(s). perl ./test-program-output.pl --monolith . ./test-program-output.pl: 157 programs to test. -------------------------------------------------------------------------------- --- Program # 0: Smallest legal program 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 int main() { return 0; } --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $41D9 writable_globals_start $4099 writable_globals_end $409F --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 1: Calling a built-in function 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 int main() { printf(""); return 0; } --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $46C1 writable_globals_start $40A5 writable_globals_end $40AD --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 2: printf() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 printf("Hello, world.\n"); 27 printf("A%sB\n", "\n"); 28 putstr("C\nD\n", 4); 29 putchar('\n'); 30 return 0; 31 } 32 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_putchar --need=_putstr --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_putchar_ -D_CMOC_NEED_putstr_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_putchar_ -D_CMOC_NEED_putstr_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $471A writable_globals_start $40E9 writable_globals_end $40F1 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: Hello, world. A B C D --- Actual output: Hello, world. A B C D -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 3: Conversions between byte and word 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte f(byte x); 25 int main() 26 { 27 printf("%u\n", (byte) f((byte) 1000)); 28 assert_eq((byte) f((byte) 1000), 208); 29 byte boolean = ((byte) f((byte) 1000)) == 208; 30 assert(boolean); 31 word oneByteUnsignedWord = 208; 32 assert_eq(oneByteUnsignedWord, 208); 33 byte eightBitUnsignedByte = 208; 34 assert_eq(oneByteUnsignedWord, eightBitUnsignedByte); 35 char eightBitSignedByte = 208; // seen as -48 36 assert_ne(oneByteUnsignedWord, eightBitSignedByte); // as words, 208 != -48 37 38 word w = 0x1200 + 42; 39 byte b = (byte) w; 40 printf("%u\n", b); 41 assert_eq(b, 42); 42 word k = 256 - b; 43 printf("%u\n", k); 44 assert_eq(k, 214); 45 k = 50 - b; 46 printf("%u\n", k); 47 assert_eq(k, 8); 48 return 0; 49 } 50 byte f(byte x) { return (byte) (x + 1000); } 51 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4956 writable_globals_start $433A writable_globals_end $4342 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: 208 42 214 8 --- Actual output: 208 42 214 8 -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 4: Shifts 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void checkLeftConst(); 25 void checkLeftVar(); 26 void checkRightConst(); 27 void checkRightVar(); 28 word checkCounter = 0; 29 #define check(actual, expected) _check(__LINE__, actual, expected) 30 void _check(int lineno, word actual, word expected); 31 #define scheck(actual, expected) _scheck(__LINE__, actual, expected) 32 void _scheck(int lineno, int actual, int expected); 33 void checkLeftVarW(word initVal, byte numBits, word expected); 34 void checkLeftVarB(byte initVal, byte numBits, byte expected); 35 void checkRightVarW(word initVal, byte numBits, word expected); 36 void checkRightVarB(byte initVal, byte numBits, byte expected); 37 void checkRightVarSW(sword initVal, byte numBits, sword expected); 38 void checkRightVarSB(sbyte initVal, byte numBits, sbyte expected); 39 40 word initStackPtr, finalStackPtr; 41 42 int main() 43 { 44 asm { sts initStackPtr }; 45 assert_eq(((int) 0xFFFF) >> 16, -1); 46 assert_eq(((int) 0xFFFF) >> 15, -1); 47 assert_eq(((char) 0xFF) >> 8, -1); 48 assert_eq(((char) 0xFF) >> 7, -1); 49 checkLeftConst(); 50 checkLeftVar(); 51 checkRightConst(); 52 checkRightVar(); 53 byte shift = 16; 54 assert_eq(0xFFFF >> shift, 0); 55 assert_eq(((int) 0xFFFF) >> shift, -1); 56 asm { sts finalStackPtr } 57 assert_eq(finalStackPtr, initStackPtr); 58 return 0; 59 } 60 61 void checkLeftConst() 62 { 63 word w = 1; 64 check(w << 0, 1); 65 check(w << 1, 2); 66 check(w << 4, 16); 67 check(w << 7, 128); 68 check(w << 8, 256); 69 check(w << 9, 512); 70 check(w << 15, 32768); 71 check(w << 16, 0); 72 73 w = 0xffff; 74 check(w << 0, 0xffff); 75 check(w << 1, 0xfffe); 76 check(w << 4, 0xfff0); 77 check(w << 7, 0xff80); 78 check(w << 8, 0xff00); 79 check(w << 9, 0xfe00); 80 check(w << 10, 0xfc00); 81 check(w << 15, 32768); 82 check(w << 16, 0); 83 84 byte b = 1; 85 check(b << 0, 1); 86 check(b << 1, 2); 87 check(b << 4, 16); 88 check(b << 7, 128); 89 check(b << 8, 0); 90 check(b << 15, 0); 91 check(b << 16, 0); 92 93 b = 0xff; 94 check(b << 0, 0xff); 95 check(b << 1, 0xfe); 96 check(b << 4, 0xf0); 97 check(b << 7, 0x80); 98 check(b << 8, 0); 99 check(b << 15, 0); 100 check(b << 16, 0); 101 } 102 103 void checkLeftVar() 104 { 105 word w = 1; 106 checkLeftVarW(w, 0, 1); 107 checkLeftVarW(w, 1, 2); 108 checkLeftVarW(w, 4, 16); 109 checkLeftVarW(w, 8, 256); 110 checkLeftVarW(w, 15, 32768); 111 checkLeftVarW(w, 16, 0); 112 113 w = 0xffff; 114 checkLeftVarW(w, 0, 0xffff); 115 checkLeftVarW(w, 1, 0xfffe); 116 checkLeftVarW(w, 4, 0xfff0); 117 checkLeftVarW(w, 8, 0xff00); 118 checkLeftVarW(w, 9, 0xfe00); 119 checkLeftVarW(w, 15, 32768); 120 checkLeftVarW(w, 16, 0); 121 122 byte b = 1; 123 checkLeftVarB(b, 0, 1); 124 checkLeftVarB(b, 1, 2); 125 checkLeftVarB(b, 4, 16); 126 checkLeftVarB(b, 8, 0); 127 checkLeftVarB(b, 15, 0); 128 checkLeftVarB(b, 16, 0); 129 130 b = 0xff; 131 checkLeftVarB(b, 0, 0xff); 132 checkLeftVarB(b, 1, 0xfe); 133 checkLeftVarB(b, 4, 0xf0); 134 checkLeftVarB(b, 8, 0); 135 checkLeftVarB(b, 15, 0); 136 checkLeftVarB(b, 16, 0); 137 } 138 139 void checkRightConst() 140 { 141 word w = 0x8000; 142 check(w >> 0, 0x8000); 143 check(w >> 1, 0x4000); 144 check(w >> 4, 0x0800); 145 check(w >> 7, 0x0100); 146 check(w >> 8, 0x0080); 147 check(w >> 15, 0x0001); 148 check(w >> 16, 0); 149 150 w = 0xffff; 151 check(w >> 0, 0xffff); 152 check(w >> 1, 0x7fff); 153 check(w >> 4, 0x0fff); 154 check(w >> 7, 0x01ff); 155 check(w >> 8, 0x00ff); 156 check(w >> 15, 0x0001); 157 check(w >> 16, 0); 158 159 byte b = 0x80; 160 check(b >> 0, 0x80); 161 check(b >> 1, 0x40); 162 check(b >> 4, 0x08); 163 check(b >> 7, 0x01); 164 check(b >> 8, 0); 165 check(b >> 15, 0); 166 check(b >> 16, 0); 167 168 b = 0xff; 169 check(b >> 0, 0xff); 170 check(b >> 1, 0x7f); 171 check(b >> 4, 0x0f); 172 check(b >> 7, 0x01); 173 check(b >> 8, 0); 174 check(b >> 15, 0); 175 check(b >> 16, 0); 176 177 // Signed cases: sign must be preserved. 178 // When shifting all bits, result must be all ones. 179 180 char sb = 0x55; 181 scheck(sb >> 0, 0x55); 182 scheck(sb >> 1, 0x2A); 183 scheck(sb >> 4, 0x05); 184 scheck(sb >> 7, 0); 185 scheck(sb >> 8, 0); 186 scheck(sb >> 15, 0); 187 scheck(sb >> 16, 0); 188 189 sb = 0xAA; // -86 decimal 190 scheck(sb >> 0, -86); 191 scheck(sb >> 1, -43); 192 scheck(sb >> 2, -22); 193 scheck(sb >> 3, -11); 194 scheck(sb >> 4, -6); 195 scheck(sb >> 5, -3); 196 scheck(sb >> 6, -2); 197 scheck(sb >> 7, -1); 198 scheck(sb >> 8, -1); 199 scheck(sb >> 15, -1); 200 scheck(sb >> 16, -1); 201 202 int sw = 0x5555; 203 scheck(sw >> 0, (int) 0x5555); 204 scheck(sw >> 1, (int) 0x2AAA); 205 scheck(sw >> 4, (int) 0x0555); 206 scheck(sw >> 7, (int) 0x00AA); 207 scheck(sw >> 8, (int) 0x0055); 208 scheck(sw >> 14, 1); 209 scheck(sw >> 15, 0); 210 scheck(sw >> 16, 0); 211 212 sw = (int) 0xAAAA; // -21846 decimal 213 scheck(sw >> 0, (int) 0xaaaa); 214 scheck(sw >> 1, (int) 0xd555); 215 scheck(sw >> 2, (int) 0xeaaa); 216 scheck(sw >> 3, (int) 0xf555); 217 scheck(sw >> 4, (int) 0xfaaa); 218 scheck(sw >> 5, (int) 0xfd55); 219 scheck(sw >> 6, (int) 0xfeaa); 220 scheck(sw >> 7, (int) 0xff55); 221 scheck(sw >> 8, (int) 0xffaa); 222 scheck(sw >> 9, (int) 0xffd5); 223 scheck(sw >> 10, (int) 0xffea); 224 scheck(sw >> 11, (int) 0xfff5); 225 scheck(sw >> 12, (int) 0xfffa); 226 scheck(sw >> 13, (int) 0xfffd); 227 scheck(sw >> 14, (int) 0xfffe); 228 scheck(sw >> 15, (int) 0xffff); 229 scheck(sw >> 16, (int) 0xffff); 230 } 231 232 void checkRightVar() 233 { 234 word w = 0x8000; 235 checkRightVarW(w, 0, 0x8000); 236 checkRightVarW(w, 1, 0x4000); 237 checkRightVarW(w, 4, 0x0800); 238 checkRightVarW(w, 7, 0x0100); 239 checkRightVarW(w, 8, 0x0080); 240 checkRightVarW(w, 15, 0x0001); 241 checkRightVarW(w, 16, 0); 242 243 w = 0xffff; 244 checkRightVarW(w, 0, 0xffff); 245 checkRightVarW(w, 1, 0x7fff); 246 checkRightVarW(w, 4, 0x0fff); 247 checkRightVarW(w, 7, 0x01ff); 248 checkRightVarW(w, 8, 0x00ff); 249 checkRightVarW(w, 15, 0x0001); 250 checkRightVarW(w, 16, 0); 251 252 byte b = 0x80; 253 checkRightVarB(b, 0, 0x80); 254 checkRightVarB(b, 1, 0x40); 255 checkRightVarB(b, 4, 0x08); 256 checkRightVarB(b, 7, 0x01); 257 checkRightVarB(b, 8, 0); 258 checkRightVarB(b, 15, 0); 259 checkRightVarB(b, 16, 0); 260 261 b = 0xff; 262 checkRightVarB(b, 0, 0xff); 263 checkRightVarB(b, 1, 0x7f); 264 checkRightVarB(b, 4, 0x0f); 265 checkRightVarB(b, 7, 0x01); 266 checkRightVarB(b, 8, 0); 267 checkRightVarB(b, 15, 0); 268 checkRightVarB(b, 16, 0); 269 270 // Signed cases: sign must be preserved. 271 // When shifting all bits, result must be all ones. 272 273 char sb = 0x55; 274 checkRightVarSB(sb, 0, 0x55); 275 checkRightVarSB(sb, 1, 0x2A); 276 checkRightVarSB(sb, 4, 0x05); 277 checkRightVarSB(sb, 7, 0); 278 checkRightVarSB(sb, 8, 0); 279 checkRightVarSB(sb, 15, 0); 280 checkRightVarSB(sb, 16, 0); 281 282 sb = 0xAA; // -86 decimal 283 checkRightVarSB(sb, 0, -86); 284 checkRightVarSB(sb, 1, -43); 285 checkRightVarSB(sb, 2, -22); 286 checkRightVarSB(sb, 3, -11); 287 checkRightVarSB(sb, 4, -6); 288 checkRightVarSB(sb, 5, -3); 289 checkRightVarSB(sb, 6, -2); 290 checkRightVarSB(sb, 7, -1); 291 checkRightVarSB(sb, 8, -1); 292 checkRightVarSB(sb, 15, -1); 293 checkRightVarSB(sb, 16, -1); 294 295 int sw = 0x5555; 296 checkRightVarSW(sw, 0, (int) 0x5555); 297 checkRightVarSW(sw, 1, (int) 0x2AAA); 298 checkRightVarSW(sw, 4, (int) 0x0555); 299 checkRightVarSW(sw, 7, (int) 0x00AA); 300 checkRightVarSW(sw, 8, (int) 0x0055); 301 checkRightVarSW(sw, 14, 1); 302 checkRightVarSW(sw, 15, 0); 303 checkRightVarSW(sw, 16, 0); 304 305 sw = (int) 0xAAAA; // -21846 decimal 306 checkRightVarSW(sw, 0, (int) 0xaaaa); 307 checkRightVarSW(sw, 1, (int) 0xd555); 308 checkRightVarSW(sw, 2, (int) 0xeaaa); 309 checkRightVarSW(sw, 3, (int) 0xf555); 310 checkRightVarSW(sw, 4, (int) 0xfaaa); 311 checkRightVarSW(sw, 5, (int) 0xfd55); 312 checkRightVarSW(sw, 6, (int) 0xfeaa); 313 checkRightVarSW(sw, 7, (int) 0xff55); 314 checkRightVarSW(sw, 8, (int) 0xffaa); 315 checkRightVarSW(sw, 9, (int) 0xffd5); 316 checkRightVarSW(sw, 10, (int) 0xffea); 317 checkRightVarSW(sw, 11, (int) 0xfff5); 318 checkRightVarSW(sw, 12, (int) 0xfffa); 319 checkRightVarSW(sw, 13, (int) 0xfffd); 320 checkRightVarSW(sw, 14, (int) 0xfffe); 321 checkRightVarSW(sw, 15, (int) 0xffff); 322 checkRightVarSW(sw, 16, (int) 0xffff); 323 } 324 325 void _check(int lineno, word actual, word expected) 326 { 327 ++checkCounter; 328 if (actual != expected) 329 { 330 printf("ERROR: check #%u at line %d: got %u ($%x), expected %u ($%x)\n", 331 checkCounter, lineno, actual, actual, expected, expected); 332 } 333 } 334 335 void _scheck(int lineno, int actual, int expected) 336 { 337 ++checkCounter; 338 if (actual != expected) 339 { 340 printf("ERROR: check #%u at line %d: got %d, expected %d\n", 341 checkCounter, lineno, actual, expected); 342 } 343 } 344 345 void checkLeftVarW(word initVal, byte numBits, word expected) 346 { 347 word actual = initVal << numBits; 348 ++checkCounter; 349 if (actual != expected) 350 { 351 printf("ERROR: checkLeftVarW #%u: %u << %u, got %u, expected %u\n", checkCounter, initVal, numBits, actual, expected); 352 } 353 } 354 355 void checkLeftVarB(byte initVal, byte numBits, byte expected) 356 { 357 asm { lda #0xFF } // put garbage in A, as a robustness test 358 byte actual = initVal << numBits; 359 ++checkCounter; 360 if (actual != expected) 361 { 362 printf("ERROR: checkLeftVarB #%u: %u << %u, got %u, expected %u\n", checkCounter, initVal, numBits, actual, expected); 363 } 364 } 365 366 void checkRightVarW(word initVal, byte numBits, word expected) 367 { 368 word actual = initVal >> numBits; 369 ++checkCounter; 370 if (actual != expected) 371 { 372 printf("ERROR: checkRightVarW #%u: %u >> %u, got %u, expected %u\n", checkCounter, initVal, numBits, actual, expected); 373 } 374 } 375 376 void checkRightVarB(byte initVal, byte numBits, byte expected) 377 { 378 asm { lda #0xFF } // put garbage in A, as a robustness test 379 byte actual = initVal >> numBits; 380 ++checkCounter; 381 if (actual != expected) 382 { 383 printf("ERROR: checkRightVarB #%u: %u >> %u, got %u, expected %u\n", checkCounter, initVal, numBits, actual, expected); 384 } 385 } 386 387 void checkRightVarSW(sword initVal, byte numBits, sword expected) 388 { 389 sword actual = initVal >> numBits; 390 ++checkCounter; 391 if (actual != expected) 392 { 393 printf("ERROR: checkRightVarSW #%u: %d >> %u, got %d, expected %u\n", checkCounter, initVal, numBits, actual, expected); 394 } 395 } 396 397 void checkRightVarSB(sbyte initVal, byte numBits, sbyte expected) 398 { 399 asm { lda #0xFF } // put garbage in A, as a robustness test 400 sbyte actual = initVal >> numBits; 401 ++checkCounter; 402 if (actual != expected) 403 { 404 printf("ERROR: checkRightVarSB #%u: %d >> %u, got %d, expected %u\n", checkCounter, initVal, numBits, actual, expected); 405 } 406 } 407 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --need=shiftByteLeft --need=shiftByteRightSigned --need=shiftByteRightUnsigned --need=shiftLeft --need=shiftRightSigned --need=shiftRightUnsigned --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_shiftByteLeft_ -D_CMOC_NEED_shiftByteRightSigned_ -D_CMOC_NEED_shiftByteRightUnsigned_ -D_CMOC_NEED_shiftLeft_ -D_CMOC_NEED_shiftRightSigned_ -D_CMOC_NEED_shiftRightUnsigned_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_shiftByteLeft_ -D_CMOC_NEED_shiftByteRightSigned_ -D_CMOC_NEED_shiftByteRightUnsigned_ -D_CMOC_NEED_shiftLeft_ -D_CMOC_NEED_shiftRightSigned_ -D_CMOC_NEED_shiftRightUnsigned_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $5DA6 writable_globals_start $56A4 writable_globals_end $56B2 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 5: Short-circuited evaluation 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte false() { return 0; } 25 byte true() { return 1; } 26 byte must_not_be_called() 27 { 28 printf("ERROR: must_not_be_called() gets called\n"); 29 return 0; 30 } 31 int main() 32 { 33 if (false() && must_not_be_called()) 34 printf("ERROR: if with && succeeded\n"); 35 if (true() || must_not_be_called()) 36 ; 37 else 38 printf("ERROR: if with || failed\n"); 39 40 // Same with relation operators, to test optimization in BinaryOpExpr::emitConditionalJump(). 41 if (false() != 0 && must_not_be_called() != 0) 42 printf("ERROR: if with && succeeded\n"); 43 if (true() != 0 || must_not_be_called() != 0) 44 ; 45 else 46 printf("ERROR: if with || failed\n"); 47 48 // While case. 49 // 50 while (false() && must_not_be_called()) 51 printf("ERROR: while with && succeeded\n"); 52 byte b = 0; 53 while (true() || must_not_be_called()) 54 { 55 ++b; 56 break; 57 } 58 assert_eq(b, 1); // check that while body entered once 59 60 // Do while case. 61 b = 0; 62 do 63 ++b; 64 while (false() && must_not_be_called()); 65 assert_eq(b, 1); // check that do-while body entered once 66 67 b = 0; 68 do 69 if (++b == 5) 70 break; 71 while (true() || must_not_be_called()); 72 assert_eq(b, 5); // check that do-while body entered the correct number of times 73 74 75 // While case with rel ops. 76 // 77 while (false() != 0 && must_not_be_called() != 0) 78 printf("ERROR: while with && succeeded\n"); 79 b = 0; 80 while (true() != 0 || must_not_be_called() != 0) 81 { 82 ++b; 83 break; 84 } 85 assert_eq(b, 1); // check that while body entered once 86 87 // Do while case with rel ops. 88 b = 0; 89 do 90 ++b; 91 while (false() != 0 && must_not_be_called() != 0); 92 assert_eq(b, 1); // check that do-while body entered once 93 94 b = 0; 95 do 96 if (++b == 5) 97 break; 98 while (true() != 0 || must_not_be_called() != 0); 99 assert_eq(b, 5); // check that do-while body entered the correct number of times 100 101 return 0; 102 } 103 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $49AB writable_globals_start $438F writable_globals_end $4397 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 6: More short-circuited evaluation 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte f(byte c) 25 { 26 if (c != 32 && c != 40 && c != 80 && c != 100) 27 return 0; 28 return 1; 29 } 30 byte g(byte c) 31 { 32 if (c == 32 || c == 40 || c == 80 || c == 100) 33 return 1; 34 return 0; 35 } 36 int main() 37 { 38 assert_eq(f(32), 1); 39 assert_eq(f(40), 1); 40 assert_eq(f(80), 1); 41 assert_eq(f(0), 0); 42 assert_eq(f(132), 0); 43 assert_eq(f((byte) (32 + 256)), 1); 44 assert_eq(g(32), 1); 45 assert_eq(g(40), 1); 46 assert_eq(g(80), 1); 47 assert_eq(g(0), 0); 48 assert_eq(g(132), 0); 49 assert_eq(g((byte) (32 + 256)), 1); 50 return 0; 51 } 52 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4A4F writable_globals_start $4433 writable_globals_end $443B --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 7: Returning byte from function of type word 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 word f() 25 { 26 asm("LDA", "#42"); // not supposed to affect return value 27 byte k = 1; 28 return k; // A must be cleared by this statement 29 } 30 word g() 31 { 32 asm("LDD", "#$ABCD"); // not supposed to affect return value 33 return 0x12; // A must be cleared by this statement 34 } 35 byte *getPtr() 36 { 37 asm("LDD", "#$4567"); // not supposed to affect return value 38 return 0; // A must be cleared by this statement 39 } 40 int fi() 41 { 42 char a = 255; 43 return a; 44 } 45 int main() 46 { 47 assert_eq(f(), 1); 48 assert_eq(g(), 0x12); 49 assert_eq(getPtr(), 0); 50 assert_eq(fi(), -1); 51 assert_eq((int) ((char) 255), -1); 52 char a = 255; 53 assert_eq((int) ((char) a), -1); 54 return 0; 55 } 56 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $484C writable_globals_start $4230 writable_globals_end $4238 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 8: Recursion 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 word fact(word n) 25 { 26 if (n <= 1) return 1; 27 return n * fact(n - 1); 28 } 29 int main() 30 { 31 assert_eq(fact(5), 120); 32 return 0; 33 } 34 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=MUL16 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $478A writable_globals_start $4156 writable_globals_end $415E --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 9: More shifts 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 byte b0 = 3 << 3; 27 byte b1 = (3 << 3) + 2; 28 byte b2 = 3 << 3 + 2; 29 //printf("%u %u %u\n", b0, b1, b2); 30 assert_eq(b0, 24); 31 assert_eq(b1, 26); 32 assert_eq(b2, 96); 33 34 word w = 0x4321; 35 w <<= 8; 36 assert_eq(w, 0x2100); 37 w = 0x4321; 38 w <<= 5; 39 assert_eq(w, 0x6420); 40 41 return 0; 42 } 43 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $47FA writable_globals_start $41DE writable_globals_end $41E6 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 10: Integer (non-char) constants are words 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 word f(unsigned word n) { return n; } 25 int main() 26 { 27 assert_eq(f(600), 600); 28 assert_eq(f(60 * 10), 600); 29 byte a = 60, b = 10; 30 assert_eq(f(a * b), 88); // byte * byte done in byte, so bits lost 31 assert_eq(f((word) 60 * 10), 600); 32 assert_eq(f(60 * (word) 10), 600); 33 assert_eq(f((word) 60 * (word) 10), 600); 34 35 assert_eq(f(100 + 99), 199); 36 assert_eq(f(200 + 100), 300); 37 assert_eq(f(200 + (word) 100), 300); 38 return 0; 39 } 40 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $498F writable_globals_start $4373 writable_globals_end $437B --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 11: Taking address and dereferencing 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S { byte b; }; 25 void changeByte(unsigned char *pb) { *pb = 42; } 26 void changeWord(unsigned int *pw) { *pw = 1844; } 27 int main() 28 { 29 byte b = 0; 30 changeByte(&b); 31 word w = 0; 32 changeWord(&w); 33 struct S s; 34 s.b = 99; 35 assert_eq(s.b, 99); 36 struct S *ps = &s; 37 assert_eq(ps->b, 99); 38 byte *pb = &b; 39 byte **ppb = &pb; 40 word *pw = &w; 41 word **ppw = &pw; // address of T * is word * 42 //printf("%u %u %u %u\n", b, w, b + w, w + b); 43 assert_eq(b, 42); 44 assert_eq(w, 1844); 45 assert_eq(b + w, 1886); 46 assert_eq(w + b, 1886); 47 assert_eq(*pb, 42); 48 assert_eq(*pw, 1844); 49 assert_eq(**ppb, 42); 50 assert_eq(**ppw, 1844); 51 52 return 0; 53 } 54 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $492F writable_globals_start $4313 writable_globals_end $431B --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 12: strcmp(), memcmp(), strlen() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 assert_eq(strcmp("", ""), 0); 27 assert_eq(strcmp("", "x"), -1); 28 assert_eq(strcmp("x", ""), 1); 29 assert_eq(strcmp("x", "x"), 0); 30 assert_eq(strcmp("x", "xy"), -1); 31 assert_eq(strcmp("xy", "x"), 1); 32 assert_eq(strcmp("xy", "xyz"), -1); 33 assert_eq(strcmp("xyz", "xy"), 1); 34 assert_eq(strcmp("xyz", "xya"), 1); 35 assert_eq(strcmp("xyz", "xay"), 1); 36 assert_eq(strcmp("xyz", "axy"), 1); 37 assert_eq(strcmp("xya", "xyz"), -1); 38 assert_eq(strcmp("xay", "xyz"), -1); 39 assert_eq(strcmp("axy", "xyz"), -1); 40 41 assert_eq(memcmp(0, 0, 0), 0); 42 assert_eq(memcmp("aaa", "bbb", 3), -1); 43 assert_eq(memcmp("fgh", "feh", 3), 1); 44 assert_eq(memcmp("aca", "ada", 3), -1); 45 assert_eq(memcmp("ada", "ada", 3), 0); 46 47 assert_eq(strlen(""), 0); 48 assert_eq(strlen("foobar"), 6); 49 return 0; 50 } 51 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_memcmp --need=_printf --need=_strcmp --need=_strlen --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memcmp_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strlen_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memcmp_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strlen_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4E55 writable_globals_start $47EF writable_globals_end $47F7 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 13: byte *memcpy(byte *, byte *, word) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char globalBuffer[7]; 25 26 void check(char *buffer) 27 { 28 buffer[0] = 42; 29 memcpy(buffer, "____", 0); // must do nothing 30 assert_eq(buffer[0], 42); 31 32 void *out = memcpy(buffer, "foobar", 7); 33 assert_eq(out, buffer); 34 assert_eq(strcmp(buffer, "foobar"), 0); 35 } 36 37 int main() 38 { 39 char localBuffer[7]; 40 check(localBuffer); 41 check(globalBuffer); 42 check(localBuffer); 43 check(globalBuffer); 44 return 0; 45 } 46 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_memcpy --need=_printf --need=_strcmp --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4840 writable_globals_start $41F8 writable_globals_end $4207 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 14: byte *memset(byte *s, byte c, word n) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char globalBuffer[300]; 25 26 void check(char *buffer) 27 { 28 void *ret = memset(buffer, 42, 300); 29 assert_eq(ret, buffer); 30 for (int i = 0; i < 300; ++i) 31 assert_eq(buffer[i], 42); 32 } 33 34 int main() 35 { 36 char localBuffer[300]; 37 check(localBuffer); 38 check(globalBuffer); 39 check(localBuffer); 40 check(globalBuffer); 41 return 0; 42 } 43 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_memset --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memset_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memset_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4919 writable_globals_start $41B3 writable_globals_end $42E7 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 15: strcpy(), strncpy(), strcat() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 #define BUFSIZ 11 25 char globalBuffer[BUFSIZ]; 26 27 void check(char *buffer) 28 { 29 assert(buffer); 30 31 buffer[0] = 42; 32 buffer[1] = 43; 33 char *out = strcpy(buffer, ""); // must copy NUL 34 assert_eq(out, buffer); 35 assert_eq(buffer[0], 0); // NUL terminator 36 assert_eq(buffer[1], 43); // unaffected by strcpy() call 37 38 char *out0 = strcpy(buffer, "foobar"); 39 assert_eq(out0, buffer); 40 char *out2 = strcat(buffer, ""); // must do nothing 41 assert_eq(out2, buffer); 42 char *out1 = strcat(buffer, "baz"); 43 assert_eq(out1, buffer); 44 assert_eq(strcmp(buffer, "foobarbaz"), 0); 45 46 buffer[0] = 0; 47 strcat(buffer, ""); 48 assert_eq(strlen(buffer), 0); 49 strcat(buffer, "quux"); 50 assert_eq(strlen(buffer), 4); 51 52 strncpy(buffer, "foo", BUFSIZ); 53 assert(!strcmp(buffer, "foo")); 54 for (char i = 3; i < BUFSIZ; ++i) 55 assert_eq(buffer[i], 0); 56 57 strncpy(buffer, "abcdefghij", BUFSIZ); 58 assert(!strcmp(buffer, "abcdefghij")); 59 60 strncpy(buffer, "Now is the time", 3); 61 assert_eq(buffer[0], 'N'); 62 assert_eq(buffer[1], 'o'); 63 assert_eq(buffer[2], 'w'); 64 65 strncpy(buffer, "ABCDEFGHIJKLMNOP", BUFSIZ); 66 assert_eq(buffer[BUFSIZ - 1], 'K'); 67 buffer[BUFSIZ - 1] = 0; 68 assert(!strcmp(buffer, "ABCDEFGHIJ")); 69 } 70 71 int main() 72 { 73 char localBuffer[BUFSIZ]; 74 check(localBuffer); 75 check(globalBuffer); 76 check(localBuffer); 77 check(globalBuffer); 78 return 0; 79 } 80 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strcat --need=_strcmp --need=_strcpy --need=_strlen --need=_strncpy --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcat_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strcpy_ -D_CMOC_NEED_strlen_ -D_CMOC_NEED_strncpy_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcat_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strcpy_ -D_CMOC_NEED_strlen_ -D_CMOC_NEED_strncpy_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4C3F writable_globals_start $45A2 writable_globals_end $45B5 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 16: byte *strchr(byte *, byte) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 char *s0 = "foobar"; 27 char *foundAt = strchr(s0, 'b'); 28 assert_eq(foundAt, s0 + 3); 29 assert_eq(strchr(s0, 'f'), s0); 30 assert_eq(strchr(s0, 'o'), s0 + 1); 31 assert_eq(strchr(s0, '_'), 0); 32 assert_eq(strchr(s0, 0), s0 + 6); 33 char *empty = ""; 34 assert_eq(strchr(empty, 0), empty); 35 assert_eq(strchr(empty, '_'), 0); 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strchr --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strchr_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strchr_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4954 writable_globals_start $4322 writable_globals_end $432A --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 17: char *strlwr(char *) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char globalBuffer[7]; 25 26 void check(char *buffer) 27 { 28 strcpy(buffer, ""); 29 strlwr(buffer); 30 assert_eq(strlen(buffer), 0); 31 32 strcpy(buffer, "FOOBAR"); 33 strlwr(buffer); 34 assert_eq(strlen(buffer), 6); 35 assert_eq(strcmp(buffer, "foobar"), 0); 36 37 strcpy(buffer, "foobar"); 38 strlwr(buffer); 39 assert_eq(strlen(buffer), 6); 40 assert_eq(strcmp(buffer, "foobar"), 0); 41 } 42 43 int main() 44 { 45 char localBuffer[7]; 46 check(localBuffer); 47 check(globalBuffer); 48 check(localBuffer); 49 check(globalBuffer); 50 return 0; 51 } 52 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strcmp --need=_strcpy --need=_strlen --need=_strlwr --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strcpy_ -D_CMOC_NEED_strlen_ -D_CMOC_NEED_strlwr_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strcpy_ -D_CMOC_NEED_strlen_ -D_CMOC_NEED_strlwr_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4931 writable_globals_start $42BF writable_globals_end $42CE --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 18: char *strupr(char *) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char globalBuffer[7]; 25 26 void check(char *buffer) 27 { 28 strcpy(buffer, ""); 29 strupr(buffer); 30 assert_eq(strlen(buffer), 0); 31 32 strcpy(buffer, "FOOBAR"); 33 strupr(buffer); 34 assert_eq(strlen(buffer), 6); 35 assert_eq(strcmp(buffer, "FOOBAR"), 0); 36 37 strcpy(buffer, "foobar"); 38 strupr(buffer); 39 assert_eq(strlen(buffer), 6); 40 assert_eq(strcmp(buffer, "FOOBAR"), 0); 41 } 42 43 int main() 44 { 45 char localBuffer[7]; 46 check(localBuffer); 47 check(globalBuffer); 48 return 0; 49 } 50 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strcmp --need=_strcpy --need=_strlen --need=_strtoul --need=_strupr --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strcpy_ -D_CMOC_NEED_strlen_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_strupr_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strcpy_ -D_CMOC_NEED_strlen_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_strupr_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $491D writable_globals_start $42AB writable_globals_end $42BA --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 19: Conditional expression does not use the TST instruction 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 // The TST instruction does not affect the carry, so it is inappropriate 27 // for LBHI et al. 28 29 byte counter = 0; 30 word w = 1; 31 asm("orcc", "#1"); // force carry 32 while (w > 0) // this comparison assumed to reset carry, for LBHI 33 { 34 ++counter; 35 break; 36 } 37 assert_eq(counter, 1); 38 39 byte b = 1; 40 asm("orcc", "#1"); // force carry 41 while (b > 0) // this comparison assumed to reset carry, for LBHI 42 { 43 ++counter; 44 break; 45 } 46 assert_eq(counter, 2); 47 return 0; 48 } 49 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4784 writable_globals_start $4168 writable_globals_end $4170 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 20: Array name is address of 1st element 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 unsigned a[1]; 27 a[0] = '$'; 28 unsigned *p = a; 29 unsigned *q; 30 q = a; 31 assert_eq(p, a); 32 assert_eq(p, q); 33 34 char b[5]; 35 b[0] = 'a'; 36 * (unsigned *) (b + 1) = 0x6263; 37 b[3] = 'd'; 38 b[4] = 0; 39 assert_eq(strcmp(b, "abcd"), 0); 40 41 assert_eq((b - 1) + 1, b); 42 assert_eq((1 + b) - 1, b); 43 44 assert_eq(*b, 97); 45 46 assert_eq(a, &a[0]); 47 assert_eq(b, &b[0]); 48 49 // Address of T[] is of type T *. 50 unsigned *a1 = &a; 51 assert_eq(a1, a); 52 assert_eq(a1[0], a[0]); 53 char *b1 = &b; 54 assert_eq(b1, b); 55 assert_eq(b1[0], b[0]); 56 57 // Negate an array name. 58 char boolNegation = !b; 59 assert_eq(boolNegation, 0); 60 assert(!!b); 61 62 unsigned *nullPtr = 0; 63 boolNegation = !nullPtr; 64 assert_ne(boolNegation, 0); // not necessarily 1 65 return 0; 66 } 67 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strcmp --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4AB2 writable_globals_start $4471 writable_globals_end $4479 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 21: dwtoa(): double word to ASCII 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 char buffer[11]; 27 assert_eq(strcmp(dwtoa(buffer, 0, 0), "0"), 0); 28 assert_eq(strcmp(buffer, "0000000000"), 0); 29 assert_eq(strcmp(dwtoa(buffer, 0, 9), "9"), 0); 30 assert_eq(strcmp(buffer, "0000000009"), 0); 31 assert_eq(strcmp(dwtoa(buffer, 9, 0), "589824"), 0); 32 assert_eq(strcmp(dwtoa(buffer, 1, 1), "65537"), 0); 33 assert_eq(strcmp(buffer, "0000065537"), 0); 34 assert_eq(strcmp(dwtoa(buffer, 14882, 31661), "975338413"), 0); 35 assert_eq(strcmp(buffer, "0975338413"), 0); 36 37 assert_eq(strcmp(dwtoa(buffer, 55857, 33919), "3660678271"), 0); 38 assert_eq(strcmp(dwtoa(buffer, 4190, 26415), "274622255"), 0); 39 assert_eq(strcmp(dwtoa(buffer, 43262, 54960), "2835273392"), 0); 40 assert_eq(strcmp(dwtoa(buffer, 6658, 15199), "436353887"), 0); 41 assert_eq(strcmp(dwtoa(buffer, 20559, 4689), "1347359313"), 0); 42 assert_eq(strcmp(dwtoa(buffer, 5076, 54251), "332714987"), 0); 43 assert_eq(strcmp(dwtoa(buffer, 44962, 4995), "2946634627"), 0); 44 assert_eq(strcmp(dwtoa(buffer, 1896, 16326), "124272582"), 0); 45 assert_eq(strcmp(dwtoa(buffer, 18019, 7597), "1180900781"), 0); 46 assert_eq(strcmp(dwtoa(buffer, 49676, 49489), "3255615825"), 0); 47 assert_eq(strcmp(buffer, "3255615825"), 0); 48 return 0; 49 } 50 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_dwtoa --need=_printf --need=_strcmp --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_dwtoa_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_dwtoa_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $5071 writable_globals_start $4A30 writable_globals_end $4A38 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 22: div328() (division of 32 bits by 8, unsigned) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 word counter = 0; 25 26 void check8(word hi, word lo, byte divisor, word expHi, word expLo) 27 { 28 ++counter; 29 30 word dividend[2] = { hi, lo }; // copy dividend here, which will be overwritten w/ quotient 31 32 divdwb(dividend, divisor); 33 34 word *actualQuotient = dividend; // new name, to clarify 35 if (actualQuotient[0] != expHi || actualQuotient[1] != expLo) 36 { 37 printf("ERROR: check8 #%2u: 0x%04x%04x / 0x%02x: got 0x%04x%04x, expected 0x%04x%04x\n", 38 counter, 39 hi, lo, divisor, 40 actualQuotient[0], actualQuotient[1], 41 expHi, expLo); 42 } 43 } 44 45 void check16(word hi, word lo, word divisor, word expHi, word expLo) 46 { 47 ++counter; 48 49 word dividend[2] = { hi, lo }; // copy dividend here, which will be overwritten w/ quotient 50 51 divdww(dividend, divisor); 52 53 word *actualQuotient = dividend; // new name, to clarify 54 if (actualQuotient[0] != expHi || actualQuotient[1] != expLo) 55 { 56 printf("ERROR: check16 #%2u: 0x%04x%04x / 0x%04x: got 0x%04x%04x, expected 0x%04x%04x\n", 57 counter, 58 hi, lo, divisor, 59 actualQuotient[0], actualQuotient[1], 60 expHi, expLo); 61 } 62 } 63 64 int main() 65 { 66 check8(0, 0, 1, 0, 0); 67 check8(0, 100, 1, 0, 100); 68 check8(0, 100, 10, 0, 10); 69 check8(0, 1000, 10, 0, 100); 70 check8(0, 10000, 10, 0, 1000); 71 check8(0x0001, 0x86a0, 10, 0, 10000); 72 check8(0xffff, 0xffff, 0xff, 0x0101, 0x0101); 73 check8(0x0001, 0x86a0, 0, 0x0001, 0x86a0); // nothing done on division by zero 74 75 check8(0x7079, 0x34e7, 0x01, 0x7079, 0x34e7); 76 check8(0x7079, 0x34e7, 0x02, 0x383c, 0x9a73); 77 check8(0x7079, 0x34e7, 0xd5, 0x0087, 0x2deb); 78 check8(0x5523, 0x0a32, 0x3f, 0x0159, 0xf3f8); 79 check8(0x1fb2, 0x380c, 0x5b, 0x0059, 0x2ad0); 80 check8(0x7436, 0x365b, 0x69, 0x011b, 0x55d9); 81 check8(0x353e, 0x1c6e, 0x09, 0x05ea, 0x74ef); 82 check8(0x0eed, 0x5e1c, 0x79, 0x001f, 0x94e0); 83 check8(0x1658, 0x508d, 0x36, 0x0069, 0xee87); 84 check8(0x1add, 0x1fbd, 0x99, 0x002c, 0xf2d2); 85 check8(0x7ab5, 0x31f8, 0x72, 0x0113, 0x8de9); 86 check8(0x2179, 0x7f99, 0x2e, 0x00ba, 0x4b1f); 87 check8(0x3c94, 0x103a, 0x4a, 0x00d1, 0x9184); 88 check8(0x34ad, 0x247d, 0x72, 0x0076, 0x4a6c); 89 check8(0x5cb2, 0x2e33, 0x07, 0x0d3e, 0x0699); 90 check8(0x4466, 0x176e, 0x94, 0x0076, 0x4fb9); 91 check8(0x4ef9, 0x7383, 0xe9, 0x0056, 0xc52a); 92 check8(0x4e52, 0x55e0, 0x11, 0x049b, 0x6e76); 93 check8(0x5a5e, 0x3dc7, 0x54, 0x0113, 0x685a); 94 check8(0x7b3f, 0x0ded, 0x18, 0x0522, 0xa094); 95 check8(0x6408, 0x6c79, 0x23, 0x02db, 0xab53); 96 check8(0x63ae, 0x2104, 0x09, 0x0b13, 0x5900); 97 check8(0x0a07, 0x1a4d, 0x6c, 0x0017, 0xc4fb); 98 check8(0x7ba4, 0x007f, 0xe3, 0x008b, 0x6fa6); 99 check8(0x697b, 0x3f16, 0x14, 0x0546, 0x298d); 100 check8(0x22f0, 0x3dfe, 0xc3, 0x002d, 0xde2f); 101 check8(0x1aa7, 0x6847, 0x2c, 0x009b, 0x13d3); 102 check8(0x5a24, 0x4b58, 0xa5, 0x008b, 0xdb38); 103 check8(0x081e, 0x7857, 0xc6, 0x000a, 0x7f50); 104 check8(0x23f5, 0x7f57, 0xc0, 0x002f, 0xf1ff); 105 check8(0x0d07, 0x71ce, 0xc8, 0x0010, 0xad5e); 106 check8(0x172e, 0x32d5, 0x4c, 0x004e, 0x14e1); 107 108 counter = 0; 109 110 check16(0, 0, 1, 0, 0); 111 check16(0, 100, 1, 0, 100); 112 check16(0, 100, 10, 0, 10); 113 check16(0, 1000, 10, 0, 100); 114 check16(0, 10000, 10, 0, 1000); 115 check16(0x0001, 0x86a0, 10, 0, 10000); 116 check16(0xffff, 0xffff, 0xff, 0x0101, 0x0101); 117 check16(0xffff, 0xffff, 0xffff, 0x0001, 0x0001); 118 check16(0x0001, 0x86a0, 0, 0x0001, 0x86a0); // nothing done on division by zero 119 120 check16(0xedc0, 0xbbaf, 0xe57d, 0x0001, 0x0938); 121 check16(0x41d5, 0x8708, 0x20e8, 0x0002, 0x002b); 122 check16(0x428b, 0xbbb5, 0x1d43, 0x0002, 0x462f); 123 check16(0xc5cd, 0x5506, 0x99e2, 0x0001, 0x4910); 124 check16(0xb738, 0x4cc9, 0x55e1, 0x0002, 0x222a); 125 check16(0xa676, 0x3203, 0x0d68, 0x000c, 0x6aae); 126 check16(0x0518, 0xa8ab, 0xdc57, 0x0000, 0x05eb); 127 check16(0x8ff2, 0xb487, 0x8e7c, 0x0001, 0x02a1); 128 check16(0xe671, 0x6eda, 0x4ba2, 0x0003, 0x0bff); 129 check16(0xe4c2, 0xe584, 0x0b65, 0x0014, 0x138f); 130 check16(0x080b, 0x33b8, 0x6cad, 0x0000, 0x12f2); 131 check16(0x398e, 0xb786, 0xe5e5, 0x0000, 0x4017); 132 check16(0xfb65, 0x6cc8, 0xcbc8, 0x0001, 0x3bd0); 133 check16(0x58c4, 0x3d29, 0x6d7b, 0x0000, 0xcf90); 134 check16(0xdc3b, 0x4e59, 0x2dbd, 0x0004, 0xd0a6); 135 check16(0x7e3e, 0x52ca, 0x8bb8, 0x0000, 0xe74f); 136 check16(0x7e00, 0x6e4a, 0x0db8, 0x0009, 0x2f44); 137 check16(0xfd3f, 0xaf80, 0x03a5, 0x0045, 0x7cc2); 138 check16(0x3a04, 0x4023, 0x003a, 0x0100, 0x12c2); 139 check16(0xc759, 0x914c, 0x00a1, 0x013c, 0xfa8a); 140 check16(0x6a48, 0xbe6b, 0x0d49, 0x0008, 0x000e); 141 check16(0xc094, 0x7890, 0x0f76, 0x000c, 0x74b6); 142 check16(0x6109, 0xd539, 0x0241, 0x002b, 0x0dae); 143 check16(0x97a4, 0xa6be, 0x088b, 0x0011, 0xc029); 144 check16(0x36b8, 0x620a, 0x0541, 0x000a, 0x6a47); 145 check16(0x0f5b, 0x5451, 0x01eb, 0x0008, 0x01bc); 146 check16(0x2104, 0xdcd5, 0x02cb, 0x000b, 0xd27a); 147 check16(0x9420, 0xd1ff, 0x0075, 0x0144, 0x1c0d); 148 check16(0x8ac2, 0xfe5b, 0x0bd0, 0x000b, 0xbf3c); 149 check16(0x5c53, 0x092f, 0x0307, 0x001e, 0x7f2f); 150 check16(0xc730, 0xf7c3, 0x040c, 0x0031, 0x3894); 151 check16(0xa027, 0x0fa8, 0x0df5, 0x000b, 0x7985); 152 153 return 0; 154 } 155 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_divdwb --need=_divdww --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_divdwb_ -D_CMOC_NEED_divdww_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_divdwb_ -D_CMOC_NEED_divdww_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $5252 writable_globals_start $4B86 writable_globals_end $4B90 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 23: mulwb(): multiply word by byte, giving a 24-bit result 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 unsigned char hi; unsigned int lo; // declared in this order, so that hi is allocated before lo 27 28 lo = mulwb(&hi, 9 * 256, 68); 29 assert_eq(hi, 0x02); 30 assert_eq(lo, 0x6400); 31 32 char buffer[11]; 33 char *firstNonZeroChar = dwtoa(buffer, (word) hi, lo); 34 //printf("buffer=[%s], firstNonZeroChar=[%s]\n", buffer, firstNonZeroChar); 35 assert_eq(strcmp(firstNonZeroChar, "156672"), 0); 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_dwtoa --need=_mulwb --need=_printf --need=_strcmp --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_dwtoa_ -D_CMOC_NEED_mulwb_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_dwtoa_ -D_CMOC_NEED_mulwb_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $482A writable_globals_start $41B5 writable_globals_end $41BD --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 24: mulww(): multiply word by word, giving a 32-bit result 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 // u * v expected to give j:k. 25 void check(word u, word v, word j, word k) 26 { 27 word hi; word lo; // declared in this order, so that hi is allocated before lo 28 lo = mulww(&hi, u, v); 29 if (hi != j || lo != k) 30 printf("UNEXPECTED: 0x%04x * 0x%04x gives 0x%04x:0x%04x, expected 0x%04x:0x%04x\n", 31 u, v, hi, lo, j, k); 32 } 33 34 int main() 35 { 36 word hi; word lo; // declared in this order, so that hi is allocated before lo 37 38 lo = mulww(&hi, 10000, 20000); 39 //printf("0x%04x 0x%04x\n", hi, lo); 40 assert_eq(hi, 0x0BEB); 41 assert_eq(lo, 0xC200); 42 43 char buffer[11]; 44 char *p = dwtoa(buffer, hi, lo); 45 assert_eq(strcmp(p, "200000000"), 0); 46 47 check(0x0000, 0x0000, 0x0000, 0x0000); 48 check(0x0001, 0x0000, 0x0000, 0x0000); 49 check(0x0000, 0x0001, 0x0000, 0x0000); 50 check(0x0001, 0x0001, 0x0000, 0x0001); 51 check(0x0100, 0x0100, 0x0001, 0x0000); 52 check(0xffff, 0xffff, 0xfffe, 0x0001); 53 54 check(0xbf6f, 0x1428, 0x0f12, 0x9558); 55 check(0xbbf2, 0xacca, 0x7eda, 0xe4f4); 56 check(0x3459, 0x692c, 0x1581, 0x804c); 57 check(0x9cd9, 0x7b8e, 0x4bb3, 0x435e); 58 check(0xf349, 0x24b4, 0x22e1, 0x5354); 59 check(0xb951, 0x38f3, 0x2939, 0x9fe3); 60 check(0xd8ad, 0xc03b, 0xa2b3, 0xafdf); 61 check(0x2e50, 0x189b, 0x0473, 0x8a70); 62 check(0x1adf, 0x6818, 0x0aed, 0x1ce8); 63 check(0x1c1a, 0x3ee1, 0x06e6, 0xfeda); 64 check(0xf069, 0xea64, 0xdc1d, 0xe304); 65 check(0x1e40, 0xd984, 0x19b3, 0xd900); 66 check(0xd1e5, 0x5a57, 0x4a11, 0xd6d3); 67 check(0xde6a, 0xb155, 0x9a11, 0x2332); 68 check(0xba35, 0x8253, 0x5ecb, 0x492f); 69 check(0xa233, 0xf502, 0x9b3c, 0x1366); 70 check(0xe9b0, 0x0b9d, 0x0a99, 0xe0f0); 71 check(0x364d, 0x4495, 0x0e8c, 0x0ed1); 72 check(0xf4f0, 0x8a55, 0x845a, 0xb3b0); 73 check(0xdd9e, 0xb4c9, 0x9c81, 0x190e); 74 check(0xdb5f, 0x025a, 0x0203, 0xdd66); 75 check(0x6096, 0x7725, 0x2cf3, 0xafae); 76 check(0xa56d, 0xa715, 0x6bf7, 0xacf1); 77 check(0x2393, 0x928f, 0x145d, 0xb51d); 78 check(0x9438, 0x7894, 0x45cf, 0xf060); 79 check(0x6184, 0x0559, 0x0209, 0x7ae4); 80 check(0x4548, 0x6455, 0x1b27, 0x20e8); 81 check(0x9591, 0x5075, 0x2f01, 0xab45); 82 check(0xb226, 0xec08, 0xa440, 0x9930); 83 check(0x82ab, 0xb97c, 0x5eac, 0xddd4); 84 return 0; 85 } 86 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_dwtoa --need=_mulww --need=_printf --need=_strcmp --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_dwtoa_ -D_CMOC_NEED_mulww_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_dwtoa_ -D_CMOC_NEED_mulww_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4C50 writable_globals_start $45B9 writable_globals_end $45C1 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 25: zerodw, addddw, subdww, cmpdww 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 word dw[2]; 27 zerodw(dw); 28 //printf("0x%04x%04x\n", dw[0], dw[1]); 29 assert_eq(dw[0], 0); 30 assert_eq(dw[1], 0); 31 assert_eq(cmpdww(dw, 0), 0); 32 33 adddww(dw, 0); 34 //printf("0x%04x%04x\n", dw[0], dw[1]); 35 assert_eq(dw[0], 0); 36 assert_eq(dw[1], 0); 37 assert_eq(cmpdww(dw, 0), 0); 38 39 adddww(dw, 42); 40 //printf("0x%04x%04x\n", dw[0], dw[1]); 41 assert_eq(dw[0], 0); 42 assert_eq(dw[1], 42); 43 assert_eq(cmpdww(dw, 42), 0); 44 45 adddww(dw, 0xFFFF); 46 //printf("0x%04x%04x\n", dw[0], dw[1]); 47 assert_eq(dw[0], 1); 48 assert_eq(dw[1], 41); 49 assert_eq(cmpdww(dw, 1000), 1); 50 51 subdww(dw, 0xFFFF); 52 assert_eq(dw[0], 0); 53 assert_eq(dw[1], 42); 54 assert_eq(cmpdww(dw, 42), 0); 55 assert_eq(cmpdww(dw, 0), 1); 56 assert_eq(cmpdww(dw, 10), 1); 57 assert_eq(cmpdww(dw, 100), -1); 58 assert_eq(cmpdww(dw, 0xFFFF), -1); 59 60 subdww(dw, 42); 61 assert_eq(dw[0], 0); 62 assert_eq(dw[1], 0); 63 assert_eq(cmpdww(dw, 0), 0); 64 65 subdww(dw, 0); 66 assert_eq(dw[0], 0); 67 assert_eq(dw[1], 0); 68 assert_eq(cmpdww(dw, 0), 0); 69 70 return 0; 71 } 72 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_adddww --need=_cmpdww --need=_printf --need=_strtoul --need=_subdww --need=_zerodw --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_adddww_ -D_CMOC_NEED_cmpdww_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_subdww_ -D_CMOC_NEED_zerodw_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_adddww_ -D_CMOC_NEED_cmpdww_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_subdww_ -D_CMOC_NEED_zerodw_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4CCD writable_globals_start $466E writable_globals_end $4676 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 26: Optimization of adds and subs of constants 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 word w; 27 byte b; 28 w = 1000 + 2000; 29 assert(w == 3000); 30 w = 9000 - 3000; 31 assert(w == 6000); 32 w = 4 - 20; 33 assert(w == 0xfff0); 34 w = 65535 + 11; 35 assert(w == 10); 36 b = 10 + 20; 37 assert(b == 30); 38 b = 230 - 25; 39 assert(b == 205); 40 b = 5 - 20; 41 assert(b == 241); 42 b = (byte) (255 + 11); 43 assert(b == 10); 44 45 // Signed cases. 46 int i; 47 i = 4 - 20; 48 assert_eq(i, -16); 49 50 return 0; 51 } 52 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $482A writable_globals_start $420E writable_globals_end $4216 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 27: printf's number and string field padding 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void asm hook() 25 { 26 asm { 27 sta $ff00 // assumes USim 28 lda #'?' // trash A to test printf() (re: zero-padding) 29 } 30 } 31 int main() 32 { 33 sbyte m1 = -1; 34 printf("[%2d]\n", m1); 35 printf("[%5d]\n", m1); 36 37 printf("[%1x]\n", 10); 38 printf("[%2x]\n", 10); 39 printf("[%5x]\n", 10); 40 printf("[%12x]\n", 10); 41 42 printf("[%1x]\n", 0xFED); 43 printf("[%2x]\n", 0xFED); 44 printf("[%5x]\n", 0xFED); 45 printf("[%12x]\n", 0xFED); 46 47 printf("[%1x]\n", 0xABCD); 48 printf("[%2x]\n", 0xABCD); 49 printf("[%5x]\n", 0xABCD); 50 printf("[%12x]\n", 0xABCD); 51 52 char *eightChars = "abcdefgh"; 53 printf("[%-8s]\n", eightChars); 54 55 printf("%s", ""); 56 byte a[2]; 57 a[0] = 'A'; a[1] = 0; 58 byte b[2]; 59 b[0] = 'B'; b[1] = 0; 60 printf("%s %s\n", a, b); 61 printf("[%12s]\n", "foo"); 62 printf("[%-12s]\n", "foo"); 63 printf("[%s]\n", "foo"); 64 printf("%03u %3u\n", 5, 6); 65 word w = 65535; 66 printf("%d\n", (sword) w); 67 68 // With redirected character output. 69 void *oldCHROOT = setConsoleOutHook(hook); 70 printf("0x%04X,%06u\n", 1, 2); 71 setConsoleOutHook(oldCHROOT); 72 73 return 0; 74 } 75 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_setConsoleOutHook --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_setConsoleOutHook_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_setConsoleOutHook_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $48F5 writable_globals_start $42D0 writable_globals_end $42D8 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: [-1] [ -1] [A] [ A] [ A] [ A] [FED] [FED] [ FED] [ FED] [ABCD] [ABCD] [ ABCD] [ ABCD] [abcdefgh] A B [ foo] [foo ] [foo] 005 6 -1 0x0001,000002 --- Actual output: [-1] [ -1] [A] [ A] [ A] [ A] [FED] [FED] [ FED] [ FED] [ABCD] [ABCD] [ ABCD] [ ABCD] [abcdefgh] A B [ foo] [foo ] [foo] 005 6 -1 0x0001,000002 -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 28: printf %x, %X and %p (hex digits always in upper-case) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 printf("%x\n", 65535); 27 printf("%X\n", 65535); 28 printf("%6X\n", 65535); 29 printf("%06X\n", 65535); 30 printf("%p\n", 65535); 31 printf("%p\n", 0xfff); 32 printf("%p\n", 0xff); 33 printf("%p\n", 0xf); 34 printf("%p\n", 0x0); 35 return 0; 36 } 37 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $475B writable_globals_start $413F writable_globals_end $4147 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: FFFF FFFF FFFF 00FFFF $FFFF $0FFF $00FF $000F $0000 --- Actual output: FFFF FFFF FFFF 00FFFF $FFFF $0FFF $00FF $000F $0000 -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 29: toupper(), tolower() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 int c = toupper('a'); 27 assert_eq(c, 'A'); 28 c = toupper('z'); 29 assert_eq(c, 'Z'); 30 c = toupper('J'); 31 assert_eq(c, 'J'); 32 c = toupper('*'); 33 assert_eq(c, '*'); 34 35 c = tolower('A'); 36 assert_eq(c, 'a'); 37 c = tolower('Z'); 38 assert_eq(c, 'z'); 39 c = tolower('j'); 40 assert_eq(c, 'j'); 41 c = tolower('*'); 42 assert_eq(c, '*'); 43 return 0; 44 } 45 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=_tolower --need=_toupper --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_tolower_ -D_CMOC_NEED_toupper_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_tolower_ -D_CMOC_NEED_toupper_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $48BC writable_globals_start $4286 writable_globals_end $428E --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 30: struct 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S 25 { 26 byte a; 27 word b; 28 byte *c; 29 word *d; 30 }; 31 struct Outer 32 { 33 word stuff; 34 struct S first; 35 struct S second; 36 }; 37 struct F 38 { 39 word w; 40 byte sec[16]; 41 }; 42 word diff(byte *after, byte *before) 43 { 44 return after - before; 45 } 46 #define sizeofVar(varName) (diff((byte *) (&(varName) + 1), (byte *) &(varName))) 47 48 void checkPtr(struct F *f) 49 { 50 //printf("f->w=0x%x, f->sec=0x%x, f=0x%x\n", (word) &f->w, (word) f->sec, (word) f); 51 //printf("%u\n", (word) f->sec - (word) f); 52 assert_eq((word) f->sec - (word) f, 2); 53 } 54 void check(struct S *p) 55 { 56 //printf("%u %u %u %u\n", p->a, p->b, *p->c, *p->d); 57 assert_eq(p->a, 43); 58 assert_eq(p->b, 1843); 59 assert_eq(*p->c, 43); 60 assert_eq(*p->d, 1843); 61 } 62 63 int main() 64 { 65 assert_eq(diff((byte *) 100, (byte *) 75), 25); 66 67 struct S s; 68 assert_eq(sizeofVar(s), 1 + 2 + 2 + 2); 69 70 s.a = 42; 71 s.b = 1844; 72 s.c = &s.a; 73 s.d = &s.b; 74 //printf("%u %u %u %u\n", s.a, s.b, *s.c, *s.d); 75 assert_eq(s.a, 42); 76 assert_eq(s.b, 1844); 77 assert_eq(*s.c, 42); 78 assert_eq(*s.d, 1844); 79 80 ++s.a; 81 --s.b; 82 //printf("%u %u %u %u\n", s.a, s.b, *s.c, *s.d); 83 assert_eq(s.a, 43); 84 assert_eq(s.b, 1843); 85 assert_eq(*s.c, 43); 86 assert_eq(*s.d, 1843); 87 88 //printf("%u\n", s.a + s.b); 89 assert_eq(s.a + s.b, 1886); 90 91 check(&s); 92 93 struct S *p = &s; 94 p->a++; 95 //printf("%u ", p->a); 96 assert_eq(p->a, 44); 97 ++p->a; 98 //printf("%u ", p->a); 99 assert_eq(p->a, 45); 100 p->b++; 101 //printf("%u ", p->b); 102 assert_eq(p->b, 1844); 103 ++p->b; 104 //printf("%u\n", p->b); 105 assert_eq(p->b, 1845); 106 107 struct F f; 108 assert_eq(sizeofVar(f), 2 + 16); 109 //printf("%u\n", (word) f.sec - (word) &f); 110 assert_eq((word) f.sec - (word) &f, 2); 111 checkPtr(&f); 112 113 struct Outer outer; 114 assert_eq(sizeofVar(outer), 2 + 7 + 7); 115 outer.first.b = 11; 116 outer.second.b = 22; 117 //printf("%u\n", outer.first.b + outer.second.b); 118 assert_eq(outer.first.b + outer.second.b, 33); 119 120 struct Outer *pOuter = &outer; 121 pOuter->first.b = 33; 122 pOuter->second.b = 44; 123 //printf("%u\n", pOuter->first.b + pOuter->second.b); 124 assert_eq(pOuter->first.b + pOuter->second.b, 77); 125 126 struct S *pFirst = &outer.first; 127 struct S *pSecond = &outer.second; 128 pFirst->b = 55; 129 pSecond->b = 66; 130 //printf("%u\n", pFirst->b + pSecond->b); 131 assert_eq(pFirst->b + pSecond->b, 55 + 66); 132 133 pFirst = &pOuter->first; 134 pSecond = &pOuter->second; 135 pFirst->b = 77; 136 pSecond->b = 88; 137 //printf("%u\n", pFirst->b + pSecond->b); 138 assert_eq(pFirst->b + pSecond->b, 77 + 88); 139 return 0; 140 } 141 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=MUL16 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4EEF writable_globals_start $48BB writable_globals_end $48C3 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 31: struct with multi-member declaration 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S 25 { 26 char a, b; 27 int c, d; 28 char *e, f; // e is a pointer but f is a char 29 signed int g[2], h[3]; // two keyword to represent base type 30 unsigned i; 31 }; 32 int main() 33 { 34 struct S s; 35 assert_eq(sizeof(struct S), 1+1+2+2+2+1+2*2+2*3+2); 36 assert_eq(sizeof(s.f), 1); 37 assert_eq(sizeof(s.g), 4); // size of struct member of array type 38 assert_eq(sizeof(s.h), 6); 39 assert(&s.a < &s.b); // order in multi-member declaration is respected 40 assert(&s.b < &s.c); // order of declarations is respected 41 assert(&s.c < &s.d); 42 assert(&s.e < &s.f); 43 assert(&s.h < &s.i); 44 45 s.a = 'A'; 46 s.b = 'B'; 47 s.c = 1844; 48 s.d = -4418; 49 s.e = "foo"; 50 s.f = 'F'; 51 s.g[1] = 1111; 52 s.h[2] = -2222; 53 s.i = 3333; 54 55 assert_eq(s.a, 'A'); 56 assert_eq(s.b, 'B'); 57 assert_eq(s.c, 1844); 58 assert_eq(s.d, -4418); 59 assert_eq(s.c + s.d, 1844 - 4418); 60 assert_eq(strcmp(s.e, "foo"), 0); 61 assert_eq(s.f, 'F'); 62 assert_eq(s.g[1], 1111); 63 assert_eq(s.h[2], -2222); 64 assert_eq(s.i, 3333); 65 66 return 0; 67 } 68 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strcmp --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4ADB writable_globals_start $449A writable_globals_end $44A2 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 32: Struct definition local to a function 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 struct S 27 { 28 int n; 29 char a[3]; 30 }; 31 struct S s; 32 s.n = 42; 33 s.a[0] = 'x'; 34 s.a[1] = 'y'; 35 s.a[2] = 0; 36 assert_eq(s.n, 42); 37 assert(!strcmp(s.a, "xy")); 38 return s.n; 39 } 40 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strcmp --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $47C2 writable_globals_start $4181 writable_globals_end $4189 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 33: Reference to array member of a struct 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct FileDesc 25 { 26 byte a; 27 byte curSector[256]; 28 byte b; 29 }; 30 struct FileDescW 31 { 32 word a; 33 word curSector[256]; 34 word b; 35 }; 36 int main() 37 { 38 struct FileDesc fd; 39 fd.b = 42; 40 assert_eq(fd.b, 42); 41 fd.curSector[17] = 217; 42 assert_eq(fd.curSector[17], 217); 43 assert_eq(&fd, &fd.a); 44 assert_eq((byte *) &fd + 1, fd.curSector); 45 assert_eq((byte *) &fd + 1 + 17, &fd.curSector[17]); 46 assert_eq((byte *) &fd + 257, &fd.b); 47 48 struct FileDescW fdw; 49 fdw.b = 9999; 50 assert_eq(fdw.b, 9999); 51 fdw.curSector[17] = 1844; 52 assert_eq(fdw.curSector[17], 1844); 53 assert_eq(&fdw, &fdw.a); 54 assert_eq((byte *) &fdw + 2, fdw.curSector); 55 assert_eq((byte *) &fdw + 2 + 17*2, &fdw.curSector[17]); 56 assert_eq((byte *) &fdw + 257*2, &fdw.b); 57 return 0; 58 } 59 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4A62 writable_globals_start $4446 writable_globals_end $444E --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 34: Taking address of a function and calling it indirectly 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 // The name of a function, not followed by arguments, yields its address. 25 // Using & in front of the name is also supported. 26 // Calling through a pointer can be done as pf(...) or (*pf)(...). 27 28 struct Class 29 { 30 int dummy; 31 void *method; // CMOC requires void pointer to represent function pointer 32 }; 33 word add(word n) 34 { 35 return 0x4000 + n; 36 } 37 void delegate(void *funcPtr) 38 { 39 assert_eq((*funcPtr)(0x0987), 0x4987); 40 } 41 int main() 42 { 43 add; // function name by itself is OK; no need to assign it for stmt to be legal, although useless 44 45 void *pf = add; // CMOC requires void pointer to represent function pointer 46 assert(pf); 47 48 assert_eq(pf(16), 16400); 49 50 asm("ldd", "#0"); // to check that D gets loaded correctly 51 asm("ldx", "#0"); // same for X if needed 52 pf = add; 53 if (pf != add) 54 { 55 printf("ERROR: pf contains %p instead of address of add() function\n", pf); 56 return 1; 57 } 58 59 assert_eq(pf(116), 16500); 60 61 assert_eq(sizeof((*pf)()), 2); // return type of call through ptr is assumed to be int 62 assert_eq(sizeof(pf()), 2); // same assert with different notation 63 64 struct Class cl; 65 asm("ldd", "#0"); // to check that D gets loaded correctly 66 asm("ldx", "#0"); // same for X if needed 67 cl.method = add; 68 assert(cl.method); 69 if (cl.method != add) 70 { 71 printf("ERROR: cl.method contains %p instead of address of add() function\n", pf); 72 return 1; 73 } 74 word t = (word) cl.method(216); // always cast return value: compiler does not know return type 75 assert_eq(t, 16600); 76 77 pf = &add; // ampersand allowed but does not change meaning 78 assert_eq(pf(17), 16401); 79 assert_eq((*pf)(18), 16402); // cf FunctionCallExpr::check(), FunctionCallExpr::emitCode() 80 81 delegate(add); // pass add() address to a function that will call it 82 delegate(t ? add : add); 83 while (add) 84 break; 85 do { break; } while (add); 86 for ( ; add ; ) 87 break; 88 if (add) 89 ; 90 91 void *pfAmp = &add; 92 assert(pfAmp); 93 assert_eq(pfAmp(17), 16401); 94 95 return 0; 96 } 97 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4B24 writable_globals_start $4508 writable_globals_end $4510 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 35: Assignment of word to byte variable, and of byte to word variable 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 word aw[2] = { 0xabcd, 0x1234 }; 25 int main() 26 { 27 byte b = 42; 28 29 b = aw[1]; // warning 30 assert_eq(b, 0x34); 31 32 word w = 0xeedd; 33 b = w; // warning 34 assert_eq(b, 0xDD); 35 36 w = b; 37 assert_eq(w, 0xDD); 38 39 byte o = '\0377'; 40 byte h = '\xff'; 41 assert_eq(o, 255); 42 assert_eq(h, 255); 43 o = 0; 44 h = 0; 45 o = '\0377'; 46 h = '\xff'; 47 assert_eq(o, 255); 48 assert_eq(h, 255); 49 50 b = 0xFEDC; // warning 51 assert_eq(b, 0xDC); 52 return 0; 53 } 54 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code ,check-prog.c:29: __warning__: assigning to `unsigned char' from larger type `unsigned int' ,check-prog.c:33: __warning__: assigning to `unsigned char' from larger type `unsigned int' ,check-prog.c:50: __warning__: assigning to `unsigned char' from larger constant of type `unsigned int' Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 3 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $485D writable_globals_start $423D writable_globals_end $4249 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 36: Assignment used as sub-expression 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte gb = 0; 25 word gw = 0; 26 byte fb(byte k) { gb = k; return gb; } 27 word fw(word k) { gw = k; return gw; } 28 byte *f() { return &gb; } 29 byte *g() { return &gb; } 30 byte h() { return 88; } 31 int main() 32 { 33 byte b; 34 byte c; 35 (b = 0) = (c = 7); 36 assert(b == 7); 37 assert(c == 7); 38 (b = 7) = (c = 0); 39 assert(b == 0); 40 assert(c == 0); 41 42 word w; 43 word z; 44 (w = 0) = (z = 7); 45 assert(w == 7); 46 assert(z == 7); 47 (w = 7) = (z = 0); 48 assert(w == 0); 49 assert(z == 0); 50 51 b = 100; 52 c = 200; 53 (b += 0) = (c += 7); 54 assert(b == 207); 55 assert(c == 207); 56 c = 150; 57 (b += 7) = (c += 0); 58 assert(b == 150); 59 assert(c == 150); 60 61 b = 0; 62 gb = 0; 63 (b = fb(33)) = 12; 64 assert(b == 12); 65 assert(gb == 33); 66 67 w = 0; 68 gw = 0; 69 (w = fw(3333)) = 1212; 70 assert(w == 1212); 71 assert(gw == 3333); 72 73 b = 0; 74 c = 0; 75 gb = 0; 76 c = (b = fb(44)); 77 assert(b == 44); 78 assert(c == 44); 79 assert(gb == 44); 80 81 c = b = fb(55); 82 assert(b == 55); 83 assert(c == 55); 84 assert(gb == 55); 85 86 // Test that second assignment is done before first one: 87 gb = 222; 88 *f() = *g() = h(); // this must print "hgf", reflecting right-to-left execution 89 assert(gb == 88); 90 return 0; 91 } 92 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4A0A writable_globals_start $43E1 writable_globals_end $43EC --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 37: while() and do/while() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 byte n = 0; 27 do 28 ++n; 29 while (n < 5); 30 assert_eq(n, 5); 31 n = 0; 32 while (n < 5) 33 ++n; 34 assert_eq(n, 5); 35 36 n = 0; 37 do 38 { 39 ++n; 40 } while (n < 5); 41 assert_eq(n, 5); 42 n = 0; 43 while (n < 5) 44 { 45 ++n; 46 } 47 assert_eq(n, 5); 48 assert(1 == 1); 49 50 // Test always-false condition. 51 n = 5; 52 while (0) 53 n = 8; 54 assert_eq(n, 5); 55 do 56 n = 9; 57 while (0); 58 assert_eq(n, 9); 59 60 // Test always-true condition. 61 byte counter = 0; 62 while (1) 63 if (++counter == 10) 64 break; 65 assert_eq(counter, 10); 66 67 do 68 if (--counter == 3) 69 break; 70 while (1); 71 assert_eq(counter, 3); 72 return 0; 73 } 74 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $48D0 writable_globals_start $42B4 writable_globals_end $42BC --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 38: For loop 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void infiniteLoop() 25 { 26 for (;;) 27 ; 28 for (;1;) 29 ; 30 } 31 int main() 32 { 33 word n = 1; 34 for (byte i = 5; i--; ) 35 n *= 2; 36 assert_eq(n, 32); 37 38 n = 1; 39 for (word j = 5; j--; ) 40 n *= 2; 41 assert_eq(n, 32); 42 43 n = 1; 44 word j = 5; 45 for ( ; j--; ) 46 n *= 2; 47 assert_eq(n, 32); 48 49 n = 1; 50 j = 5; 51 for ( ; ; j--) 52 { 53 if (j == 0) 54 break; 55 n *= 2; 56 } 57 assert_eq(n, 32); 58 59 // Control variable wraps around. 60 n = 0; 61 for (byte x = 0; x < 256; ++x) 62 { 63 ++n; 64 if (n == 270) 65 break; 66 } 67 assert_eq(n, 270); 68 return 0; 69 } 70 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=MUL16 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $48AC writable_globals_start $4278 writable_globals_end $4280 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 39: Octal and hex codes in a string or integer literal 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void checkStr(char *str, char expectedValueFirstChar) 25 { 26 char actualFirstChar = str[0]; 27 if (actualFirstChar != expectedValueFirstChar) 28 { 29 printf("ERROR: checkStr(): expected char %u, got char %u\n", 30 (byte) expectedValueFirstChar, (byte) actualFirstChar); 31 } 32 if (str[1]) 33 { 34 printf("ERROR: checkStr(): expected single char string (char %u), got more: %u and %u\n", 35 (byte) expectedValueFirstChar, (byte) str[0], (byte) str[1]); 36 } 37 } 38 void checkChar(char actualFirstChar, char expectedValueFirstChar) 39 { 40 if (actualFirstChar != expectedValueFirstChar) 41 { 42 printf("ERROR: checkChar(): expected char %u, got char %u\n", 43 (byte) expectedValueFirstChar, (byte) actualFirstChar); 44 } 45 } 46 int main() 47 { 48 assert_eq(052, 42); 49 assert_eq(0377, 255); 50 assert_eq(03464, 1844); 51 assert_eq(0177777, 0xFFFF); 52 53 assert(!strcmp("\0101", "A")); 54 assert(!strcmp("\x42", "B")); 55 assert(!strcmp("\0101\x42\01018\x42z\n", "ABA8Bz\x0A")); 56 checkStr("\a", 7); 57 checkStr("\b", 8); 58 checkStr("\t", 9); 59 checkStr("\n", 10); 60 checkStr("\v", 11); 61 checkStr("\f", 12); 62 checkStr("\r", 13); 63 checkStr("\'", 39); 64 checkStr("\"", 34); 65 checkStr("\\", 92); // 4 backslashes because of Perl interpretation 66 checkStr("\x43", 64 + 3); 67 checkStr("\0", 0); 68 checkStr("\0377", (char) (3 * 8 * 8 + 7 * 8 + 7)); 69 checkChar('\a', 7); 70 checkChar('\b', 8); 71 checkChar('\t', 9); 72 checkChar('\n', 10); 73 checkChar('\v', 11); 74 checkChar('\f', 12); 75 checkChar('\r', 13); 76 checkChar('\'', 39); 77 checkChar('\"', 34); 78 checkChar('\\', 92); // 4 backslashes because of Perl interpretation 79 checkChar('\x43', 64 + 3); 80 checkChar('\0', 0); 81 checkChar('\0377', (char) (3 * 8 * 8 + 7 * 8 + 7)); 82 checkChar('\377', (char) (3 * 8 * 8 + 7 * 8 + 7)); 83 checkChar('\1', 1); 84 checkChar('\12', 10); 85 checkChar('\123', 64 + 16 + 3); 86 char *s = "a\\b"; // 4 backslashes because of Perl interpretation 87 assert(strlen(s) == 3); 88 assert(s[0] == 97); 89 assert(s[1] == 92); 90 assert(s[2] == 98); 91 92 // Check for an a09 bug where a 0x in a string literal gets replaced with $. 93 char *h = "0xEF"; 94 assert_eq(strlen(h), 4); 95 assert_eq(h[0], '0'); 96 assert_eq(h[1], 'x'); 97 assert_eq(h[2], 'E'); 98 assert_eq(h[3], 'F'); 99 char *H = "0XEF"; 100 assert_eq(strlen(H), 4); 101 assert_eq(H[0], '0'); 102 assert_eq(H[1], 'X'); 103 assert_eq(H[2], 'E'); 104 assert_eq(H[3], 'F'); 105 return 0; 106 } 107 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strcmp --need=_strlen --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strlen_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strlen_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4E83 writable_globals_start $4842 writable_globals_end $484A --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 40: Bitwise operators 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 { 27 byte n = 0x43; 28 byte m = 0xC9; 29 assert_eq(n | m, 0xCB); 30 assert_eq(n ^ m, 0x8A); 31 assert_eq(n & m, 0x41); 32 assert_eq(n & 3, 0x03); 33 } 34 { 35 word n = 0x4343; 36 word m = 0xC9C9; 37 assert_eq(n | m, 0xCBCB); 38 assert_eq(n ^ m, 0x8A8A); 39 assert_eq(n & m, 0x4141); 40 assert_eq(m & 0x0F71, 0x0941); 41 word k = 0xABCD; 42 assert_eq(((byte) k) & 0xF0, 0xC0); 43 } 44 return 0; 45 } 46 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4926 writable_globals_start $430A writable_globals_end $4312 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 41: Array initializers 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 unsigned char b[4] = { 0x80, 0x40, 0x20, 0x10, }; // trailing comma accepted 25 word w[4] = { 0xaa80, 0xbb40, 0xcc20, 0xdd10 }; 26 word s[2] = { (word) "foo", (word) "bar" }; 27 char c[3] = { 'b', 'a', 'z' }; 28 char cc[] = { 'B', 'A', 'Z' }; // size of array taken from size of init list 29 char d[7]; 30 char e[4] = "baz"; 31 char buffer[] = "HELLO"; 32 int sc[] = { (char) 255 }; 33 34 void local() 35 { 36 unsigned char b_[4] = { 0x80, 0x40, 0x20, 0x10 }; 37 word w_[4] = { 0xaa80, 0xbb40, 0xcc20, 0xdd10 }; 38 word s_[2] = { (word) "foo", (word) "bar" }; 39 char c_[3] = { 'b', 'a', 'z' }; 40 char cc_[] = { 'B', 'A', 'Z' }; 41 char e_[4] = "BAZ"; 42 assert_eq(b_[0], 0x80); 43 assert_eq(b_[1], 0x40); 44 assert_eq(b_[2], 0x20); 45 assert_eq(b_[3], 0x10); 46 assert_eq(w_[0], 0xAA80); 47 assert_eq(w_[1], 0xBB40); 48 assert_eq(w_[2], 0xCC20); 49 assert_eq(w_[3], 0xDD10); 50 assert(!strcmp((char *) s_[0], "foo")); 51 assert(!strcmp((char *) s_[1], "bar")); 52 assert_eq(c_[0], 'b'); 53 assert_eq(c_[1], 'a'); 54 assert_eq(c_[2], 'z'); 55 assert_eq(cc_[0], 'B'); 56 assert_eq(cc_[1], 'A'); 57 assert_eq(cc_[2], 'Z'); 58 assert_eq(strcmp(e_, "BAZ"), 0); 59 assert_eq(e_[2], 'Z'); 60 assert_eq(e_[3], 0); 61 62 char buffer_[] = "PIZZA"; 63 assert_eq(strcmp(buffer_, "PIZZA"), 0); 64 65 int sc_[] = { (char) 255 }; 66 assert_eq(sc_[0], -1); 67 } 68 int main() 69 { 70 assert_eq(b[0], 0x80); 71 assert_eq(b[1], 0x40); 72 assert_eq(b[2], 0x20); 73 assert_eq(b[3], 0x10); 74 assert_eq(w[0], 0xAA80); 75 assert_eq(w[1], 0xBB40); 76 assert_eq(w[2], 0xCC20); 77 assert_eq(w[3], 0xDD10); 78 assert(!strcmp((char *) s[0], "foo")); 79 assert(!strcmp((char *) s[1], "bar")); 80 assert_eq(c[0], 'b'); 81 assert_eq(c[1], 'a'); 82 assert_eq(c[2], 'z'); 83 assert_eq(cc[0], 'B'); 84 assert_eq(cc[1], 'A'); 85 assert_eq(cc[2], 'Z'); 86 d[0] = 42; 87 d[6] = 71; 88 assert_eq(d[0], 42); 89 assert_eq(d[6], 71); 90 assert_eq(strcmp(e, "baz"), 0); 91 assert_eq(e[2], 'z'); 92 assert_eq(e[3], 0); 93 94 char buffer[] = "HELLO"; 95 assert_eq(strcmp(buffer, "HELLO"), 0); 96 97 assert_eq(sc[0], -1); 98 99 local(); 100 return 0; 101 } 102 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_memcpy --need=_printf --need=_strcmp --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $5094 writable_globals_start $4A1A writable_globals_end $4A4B --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 42: Array arithmetic 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte byteArray[5]; 25 word wordArray[5]; 26 struct S { byte foo[40]; word bar; }; 27 struct S s; 28 struct S sArray[5]; 29 int main() 30 { 31 byte *pb = byteArray + 3; 32 word byteArrayDiff = pb - byteArray; 33 assert_eq(byteArrayDiff, 3); 34 35 word *pw = wordArray + 3; 36 word wordArrayDiff = pw - wordArray; 37 assert_eq(wordArrayDiff, 3); 38 byte *pwb = (byte *) pw; 39 byte *wab = (byte *) wordArray; 40 assert_eq(pwb - wab, 6); 41 42 s.bar = 42; 43 assert(s.bar == 42); 44 45 struct S *ps = sArray + 3; 46 assert((word) ps - (word) sArray == 3 * 42); 47 word sArrayDiff = ps - sArray; 48 //printf("sArrayDiff=%u\n", sArrayDiff); 49 assert_eq(sArrayDiff, 3); 50 byte *psb = (byte *) ps; 51 byte *sab = (byte *) sArray; 52 //printf("byte diff: %u\n", psb - sab); 53 assert_eq(psb - sab, 3 * 42); 54 55 ps = &s + 1; 56 //printf("%u, %u\n", &s, ps); 57 assert_eq((word) ps - (word) &s, 42); 58 ps = &s + 3; 59 assert_eq((word) ps - (word) &s, 3 * 42); 60 61 struct S *ps2 = &sArray[2]; 62 struct S *ps4 = &sArray[4]; 63 word byteDiff = (byte *) ps4 - (byte *) ps2; 64 assert_eq(byteDiff, 2 * 42); 65 66 word *bar2 = &ps2->bar; 67 word *bar4 = &ps4->bar; 68 byteDiff = (byte *) bar4 - (byte *) bar2; 69 assert_eq(byteDiff, 2 * 42); 70 71 *byteArray = 254; 72 assert_eq(byteArray[0], 254); 73 *wordArray = 0x4141; 74 assert_eq(wordArray[0], 0x4141); 75 76 // Check cases for which there are specialized optimizations. 77 78 word wa[3] = { 0x1122, 0x3344, 0x4455 }; 79 assert_eq(wa[2], 0x4455); // and not 0x3344 80 word wi = 2; 81 assert_eq(wa[wi], 0x4455); 82 byte bi = 2; 83 assert_eq(wa[bi], 0x4455); 84 85 word *wp = &wa[2]; 86 assert_eq(wp[-1], 0x3344); 87 signed int swi = -1; 88 assert_eq(wp[swi], 0x3344); 89 signed char sci = -2; 90 assert_eq(wp[sci], 0x1122); 91 92 return 0; 93 } 94 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=DIV16 --need=MUL16 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_DIV16_ -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_DIV16_ -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4D3C writable_globals_start $45D2 writable_globals_end $46E5 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 43: Bitwise NOT operator 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 byte b = 0x55; 27 word w = 0xaaaa; 28 assert_eq(~b, 0xAA); 29 assert_eq(~w, 0x5555); 30 return 0; 31 } 32 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4774 writable_globals_start $4158 writable_globals_end $4160 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 44: Additive assignment, etc 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 // +=, -= 27 28 byte *p = 0; 29 byte inc = 4; 30 byte dummy = 0x55; // this byte allocated after 'inc' 31 p += inc; 32 assert_eq(p, 4); 33 p -= inc; 34 assert_eq(p, 0); 35 36 byte b = 0; 37 word w = 0xabcd; 38 b += (byte) w; 39 assert_eq(b, 0xCD); 40 41 // Signed cases. 42 char c = 100; 43 c += 1; 44 assert_eq(c, 101); 45 c += -1; 46 assert_eq(c, 100); 47 c -= 1; 48 assert_eq(c, 99); 49 c -= -1; 50 assert_eq(c, 100); 51 52 int i = 1000; 53 i += 1; 54 assert_eq(i, 1001); 55 i += -1; 56 assert_eq(i, 1000); 57 i -= 1; 58 assert_eq(i, 999); 59 i -= -1; 60 assert_eq(i, 1000); 61 i += 100; 62 assert_eq(i, 1100); 63 i += -100; 64 assert_eq(i, 1000); 65 i -= 100; 66 assert_eq(i, 900); 67 i -= -100; 68 assert_eq(i, 1000); 69 70 // *= 71 72 word k = 0x3000; 73 k *= inc; 74 assert_eq(k, 0xC000); 75 76 byte m = 0x05; 77 word n = 0x1111; 78 m *= (byte) n; 79 assert_eq(m, 0x55); 80 81 // /= 82 83 assert_eq(inc, 4); 84 word z = 0x444; 85 z /= inc; 86 assert_eq(z, 0x111); 87 88 byte q = 0xcc; 89 word v = 0x2203; 90 q /= (byte) v; 91 assert_eq(q, 0x44); 92 93 // ^= 94 95 b = 0x5F; 96 b ^= 1; 97 w = 0x543F; 98 w ^= 1; 99 assert(b == 0x5E); 100 assert(w == 0x543E); 101 b ^= 1; 102 w ^= 1; 103 assert(b == 0x5F); 104 assert(w == 0x543F); 105 b ^= 0x81; 106 w ^= 0x801; 107 assert(b == 0xDE); 108 assert(w == 0x5C3E); 109 w ^= (byte) 0xff01; 110 assert(w == 0x5C3F); 111 112 // &= 113 114 b = 0x5F; 115 b &= 0xFE; 116 w = 0x543F; 117 w &= 0xFFFE; 118 assert(b == 0x5E); 119 assert(w == 0x543E); 120 b &= 0x0F; 121 w &= 0x4F0; 122 assert(b == 0x0E); 123 assert(w == 0x0430); 124 b &= 0x0C; 125 w &= 0x0220; 126 assert(b == 0x0C); 127 assert(w == 0x0020); 128 w &= (byte) 0xFF80; 129 assert(w == 0x0000); 130 131 * (byte *) 0x0400 = 0xfc; 132 assert_eq(* (byte *) 0x0400, 0xfc); 133 * (byte *) (0x0400 + 0x0032) = 0xfc; 134 assert_eq(* (byte *) 0x0432, 0xfc); 135 * (byte *) 0x0400 &= 7; 136 assert_eq(* (byte *) 0x0400, 4); 137 138 // |= 139 140 b = 0x08; 141 b |= 0x28; 142 w = 0x0100; 143 w |= 0x7155; 144 assert(b == 0x28); 145 assert(w == 0x7155); 146 b |= 0x80; 147 w |= 0x8080; 148 assert(b == 0xa8); 149 assert(w == 0xf1d5); 150 b |= 0x0C; 151 w |= 0x4220; 152 assert(b == 0xac); 153 assert(w == 0xf3f5); 154 w |= (byte) 0xFF02; 155 assert(w == 0xf3f7); 156 157 // %= 158 b = 123; 159 b %= 10; 160 assert(b == 3); 161 w = 1234; 162 w %= 500; 163 assert(w == 234); 164 w = 1234; 165 w %= 25; 166 assert(w == 9); 167 return 0; 168 } 169 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=DIV16 --need=MUL16 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_DIV16_ -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_DIV16_ -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4EFD writable_globals_start $489E writable_globals_end $48A6 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 45: Verbatim assembly language 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void f(int *p) 25 { 26 asm { 27 ldd #1844 28 std [p] // brackets are words by themselves 29 } 30 } 31 enum { FOO = 42 }; 32 int main() 33 { 34 word w = 0x1000; 35 byte x = 40; 36 asm("ldd", w); 37 asm { 38 addd #$234 // comment must start with "//" 39 exg a,b /* or use C-style comments */ 40 nop ; or start with a semi-colon 41 bra @localLabel 42 ; Next line tests that a colon in a semi-colon comment is not processed as a variableNameEscapeChar. 43 ; foo bar: 44 ; Next label tests that semi-colon comment lines are sent to the assembler. 45 ; @localLabel is local in LWASM. Semi-colon comment lines preserve the "local scope". 46 @localLabel 47 inca 48 incb 49 pshs x // register X 50 inc :x // C variable 'x' ("inc x" would refer to register, i.e., error) 51 puls x // register X 52 } 53 asm("std", w); 54 assert_eq(w, 0x3513); 55 assert_eq(x, 41); 56 57 int n = 0; 58 f(&n); 59 assert_eq(n, 1844); 60 61 byte m[2] = { 22, 33 }; 62 byte a[2] = { 44, 55 }; 63 asm { 64 ldb m 65 addb m[1] 66 stb m[0] 67 ldb :a 68 addb :a[1] 69 stb :a[0] 70 } 71 assert_eq(m[0], 22 + 33); 72 assert_eq(a[0], 44 + 55); 73 74 byte foo = 42; 75 asm { 76 ldb #1+:FOO*2 // escaped enumerated name 77 stb foo 78 } 79 assert_eq(foo, 85); 80 81 word d; 82 asm { 83 leax d,x // 'd' must refer to register D, not C variable 'd' 84 } 85 86 return 0; 87 } 88 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4853 writable_globals_start $4237 writable_globals_end $423F --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 46: Referring to variables from asm directive 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 word big = 0x1234; 27 byte small = 0xaa; 28 asm { 29 ldd big 30 coma 31 comb 32 std big 33 ldb small 34 comb 35 stb small 36 loop: // no white space allowed before a label 37 brn loop 38 } 39 assert_eq(big, 0xEDCB); 40 assert_eq(small, 0x55); 41 return 0; 42 } 43 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4773 writable_globals_start $4157 writable_globals_end $415F --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 47: Declaring two local variables with same name, in different blocks 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 byte *addr1; 27 byte *addr2; 28 { 29 byte b = 11; 30 assert_eq(b, 11); 31 addr1 = &b; 32 } 33 { 34 byte b = 22; 35 assert_eq(b, 22); 36 addr2 = &b; 37 } 38 assert_eq(addr1, addr2); // both b's expected to be at same address 39 return 0; 40 } 41 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4787 writable_globals_start $416B writable_globals_end $4173 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 48: Conditional expression (cond ? foo : bar) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void foo(byte p) {} 25 byte returnByte(byte b) 26 { 27 asm { 28 lda #$DD // put dirt in A 29 } 30 return b; 31 } 32 int main() 33 { 34 assert((1 ? 2 : 3) == 2); 35 assert((0 ? 2 : 3) == 3); 36 foo(1 ? (byte) 2 : (byte) 3); 37 38 { 39 word cond = 1; 40 word t = 2; 41 word f = 3; 42 assert((cond ? t : f) == 2); 43 cond = 0; 44 assert((cond ? t : f) == 3); 45 } 46 47 { 48 byte cond = 1; 49 byte t = 2; 50 byte f = 3; 51 assert((cond ? t : f) == 2); 52 cond = 0; 53 assert((cond ? t : f) == 3); 54 t = (cond ? 4 : 5); // 4 and 5 are ints, but they fit in byte, so no error 55 } 56 57 { 58 asm { ldx #0 } // robustness check 59 word a = 4; 60 word b = 5; 61 word c = 1; 62 (c ? a : b) = 6; 63 assert_eq(a, 6); 64 assert(b == 5); 65 c = 0; 66 (c ? a : b) = 7; 67 assert(a == 6); 68 assert(b == 7); 69 } 70 71 { 72 byte a = 4; 73 byte b = 5; 74 byte c = 1; 75 (c ? a : b) = 6; 76 assert(a == 6); 77 assert(b == 5); 78 c = 0; 79 (c ? a : b) = 7; 80 assert(a == 6); 81 assert(b == 7); 82 } 83 84 { 85 byte *a = (byte *) 4; 86 byte *b = (byte *) 5; 87 byte *c = (byte *) 1; 88 (c ? a : b) = 6; 89 assert(a == 6); 90 assert(b == 5); 91 c = 0; 92 (c ? a : b) = 7; 93 assert(a == 6); 94 assert(b == 7); 95 } 96 97 // True and false expressions of different sizes. 98 { 99 unsigned u = 100; 100 u = (u > 99 ? 50 : u); // warning 101 assert_eq(u, 50); 102 byte b = 12; 103 u = (u > 66 ? u : returnByte(b)); // warning 104 assert_eq(u, 12); 105 u = 999; 106 u = (u < 2000 ? u : returnByte(b)); // warning 107 assert_eq(u, 999); 108 109 int a0[] = { 10 }, a1[] = { 11 }; 110 b = 50; 111 u = (b < 77 ? a0 : a1); 112 assert_eq(u, &a0); 113 } 114 115 return 0; 116 } 117 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code ,check-prog.c:100: __warning__: true and false expressions of conditional are not of the same type (int vs unsigned int); result is of type int ,check-prog.c:103: __warning__: true and false expressions of conditional are not of the same type (unsigned int vs unsigned char); result is of type unsigned int ,check-prog.c:106: __warning__: true and false expressions of conditional are not of the same type (unsigned int vs unsigned char); result is of type unsigned int Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 3 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4B52 writable_globals_start $4536 writable_globals_end $453E --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 49: Calling a with same name as local variable declared after the call 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte b = 0; 25 void func() { b = 77; } 26 int main() 27 { 28 assert_eq(b, 0); 29 func(); 30 assert_eq(b, 77); 31 word func = 0; 32 assert_eq(b, 77); 33 return 0; 34 } 35 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $47A3 writable_globals_start $4182 writable_globals_end $418B --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 50: Optimized increments and decrements 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 { 27 char buf[8]; 28 memcpy(buf, "xxxxxxxx", 8); 29 char *dest = buf; 30 unsigned char i = 0; 31 while (i < 8) 32 { 33 *dest++ = 'x'; // detect unsafe optimizations on this post-inc. 34 ++i; 35 } 36 assert_eq(memcmp(buf, "xxxxxxxx", 8), 0); 37 } 38 39 { 40 char b = 10; 41 b += 0; 42 assert_eq(b, 10); 43 b += 1; 44 assert_eq(b, 11); 45 b += 2; 46 assert_eq(b, 13); 47 b += -1; 48 assert_eq(b, 12); 49 b += -2; 50 assert_eq(b, 10); 51 asm("CLRB"); // to prove that += 0 still loads variable in register, for init of b1 52 char b1 = (b += 0); 53 assert_eq(b1, 10); 54 char b2 = (b += 4); 55 assert_eq(b2, 14); 56 } 57 58 { 59 int w = 10; 60 w += 0; 61 assert_eq(w, 10); 62 w += 1; 63 assert_eq(w, 11); 64 w += 2; 65 assert_eq(w, 13); 66 w += -1; 67 assert_eq(w, 12); 68 w += -2; 69 assert_eq(w, 10); 70 asm("CLRA"); // to prove that += 0 still loads variable in register, for init of w1 71 asm("CLRB"); 72 int w1 = (w += 0); 73 assert_eq(w1, 10); 74 int w2 = (w += 4); 75 assert_eq(w2, 14); 76 } 77 78 return 0; 79 } 80 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_memcmp --need=_memcpy --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memcmp_ -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memcmp_ -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4A24 writable_globals_start $43E3 writable_globals_end $43EB --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 51: Increment on word pointer 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 word *wp = (word *) 100; 27 wp += 16; 28 assert_eq(wp, 132); 29 wp = 100; 30 wp -= 16; 31 assert_eq(wp, 68); 32 33 wp = 1000; 34 wp += 0x80; // 1000 + 128 * 2 == 1256 35 assert_eq(wp, 1256); 36 wp = 2256; 37 wp -= 0x80; // 2256 - 128 * 2 == 2000 38 assert_eq(wp, 2000); 39 40 byte *bp = (byte *) 100; 41 bp += 16; 42 assert_eq(bp, 116); 43 bp = 100; 44 bp -= 16; 45 assert_eq(bp, 84); 46 47 word w = 200; 48 w += 16; 49 assert_eq(w, 216); 50 w = 200; 51 w -= 16; 52 assert_eq(w, 184); 53 54 byte b = 200; 55 b += 16; 56 assert_eq(b, 216); 57 b = 200; 58 b -= 16; 59 assert_eq(b, 184); 60 return 0; 61 } 62 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $48E5 writable_globals_start $42C9 writable_globals_end $42D1 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 52: Increment on struct pointer 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S { word a; word b; byte c; }; 25 void f(byte *start, byte *end) 26 { 27 assert_eq(end, start + 5 * sizeof(struct S)); 28 struct S *last = (struct S *) end - 1; 29 assert_eq(last, start + 4 * sizeof(struct S)); 30 struct S *p = last; 31 --p; 32 assert_eq(p, start + 3 * sizeof(struct S)); 33 p--; 34 assert_eq(p, start + 2 * sizeof(struct S)); 35 p = p - 1; 36 assert_eq(p, start + sizeof(struct S)); 37 ++p; 38 assert_eq(p, start + 2 * sizeof(struct S)); 39 p++; 40 assert_eq(p, start + 3 * sizeof(struct S)); 41 p = p + 1; 42 assert_eq(last, start + 4 * sizeof(struct S)); 43 } 44 int main() 45 { 46 assert_eq(sizeof(struct S), 5); 47 struct S a[5]; 48 struct S *p = a; 49 assert_eq(p, a); 50 assert_eq(p + 1, &a[1]); 51 ++p; 52 assert_eq(p, &a[1]); 53 assert_eq(p - 1, &a[0]); 54 byte *aCast = (byte *) a; 55 byte *pCast = (byte *) p; 56 assert_eq(pCast, aCast + sizeof(struct S)); 57 58 // For loop increment may be subject to optimization. 59 for (p = a; p < &a[5]; ++p) 60 assert_eq((p - a) * sizeof(struct S), (byte *) p - (byte *) a); 61 62 f((byte *) a, (byte *) (a + 5)); 63 64 return 0; 65 } 66 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=DIV16 --need=MUL16 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_DIV16_ -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_DIV16_ -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4B02 writable_globals_start $44A3 writable_globals_end $44AB --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 53: exit() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void h() { exit(0); } 25 void g() { h(); } 26 void f() { g(); } 27 int main() 28 { 29 f(); 30 printf("end\n"); 31 return 0; 32 } 33 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_exit --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_exit_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_exit_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $46DA writable_globals_start $40BE writable_globals_end $40C6 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 54: if/while condition ending in == 0 or != 0. String literal sequence 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 #define BUFSIZ 200 25 char buffer[BUFSIZ]; 26 word index = 0; 27 void write(char *str) 28 { 29 word len = strlen(str); 30 assert(index + len < BUFSIZ); 31 strcpy(buffer + index, str); 32 index += len; 33 } 34 byte b0() { return 0; } 35 byte b1() { return 1; } 36 byte w0() { return 0; } 37 byte w1() { return 1; } 38 int main() 39 { 40 if (b0() == 0) 41 write("b0-eq-then\n"); 42 else 43 write("b0-eq-else\n"); 44 if (b1() == 0) 45 write("b1-eq-then\n"); 46 else 47 write("b1-eq-else\n"); 48 if (w0() == 0) 49 write("w0-eq-then\n"); 50 else 51 write("w0-eq-else\n"); 52 if (w1() == 0) 53 write("w1-eq-then\n"); 54 else 55 write("w1-eq-else\n"); 56 57 if (b0() != 0) 58 write("b0-ne-then\n"); 59 else 60 write("b0-ne-else\n"); 61 if (b1() != 0) 62 write("b1-ne-then\n"); 63 else 64 write("b1-ne-else\n"); 65 if (w0() != 0) 66 write("w0-ne-then\n"); 67 else 68 write("w0-ne-else\n"); 69 if (w1() != 0) 70 write("w1-ne-then\n"); 71 else 72 write("w1-ne-else\n"); 73 74 while (b0() == 0) 75 { 76 write("b0-eq-body\n"); 77 break; 78 } 79 while (b1() == 0) 80 { 81 write("b1-eq-body\n"); 82 break; 83 } 84 while (w0() == 0) 85 { 86 write("w0-eq-body\n"); 87 break; 88 } 89 while (w1() == 0) 90 { 91 write("w1-eq-body\n"); 92 break; 93 } 94 95 while (b0() != 0) 96 { 97 write("b0-eq-body\n"); 98 break; 99 } 100 while (b1() != 0) 101 { 102 write("b1-eq-body\n"); 103 break; 104 } 105 while (w0() != 0) 106 { 107 write("w0-eq-body\n"); 108 break; 109 } 110 while (w1() != 0) 111 { 112 write("w1-eq-body\n"); 113 break; 114 } 115 116 buffer[index] = 0; 117 118 // Test using a string literal sequence. 119 assert(!strcmp(buffer, "b0-eq-then\nb1-eq-else\nw0-eq-then\nw1-eq-else\n" 120 "b0-ne-else\nb1-ne-then\nw0-ne-else\nw1-ne-then\n" 121 "b0-eq-body\nw0-eq-body\n" 122 "b1-eq-body\nw1-eq-body\n")); 123 return 0; 124 } 125 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strcmp --need=_strcpy --need=_strlen --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strcpy_ -D_CMOC_NEED_strlen_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strcpy_ -D_CMOC_NEED_strlen_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4B70 writable_globals_start $444F writable_globals_end $4521 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 55: Multiple declarators per var_decl 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 byte b0, b1; 27 byte b2 = 2, b3; 28 byte b4, b5 = 5; 29 byte b6 = 6, b7 = 7; 30 byte b8 = 8, b9 = 9, b10 = 10, b11 = 11, b12 = 12; 31 assert_eq(b2, 2); 32 assert_eq(b5, 5); 33 assert_eq(b6, 6); 34 assert_eq(b7, 7); 35 assert_eq(b8, 8); 36 assert_eq(b9, 9); 37 assert_eq(b10, 10); 38 assert_eq(b11, 11); 39 assert_eq(b12, 12); 40 41 word w0, w1; 42 word w2 = 2, w3; 43 word w4, w5 = 5; 44 word w6 = 6, w7 = 7; 45 word w8 = 8, w9 = 9, w10 = 10, w11 = 11, w12 = 12; 46 assert_eq(w2, 2); 47 assert_eq(w5, 5); 48 assert_eq(w6, 6); 49 assert_eq(w7, 7); 50 assert_eq(w8, 8); 51 assert_eq(w9, 9); 52 assert_eq(w10, 10); 53 assert_eq(w11, 11); 54 assert_eq(w12, 12); 55 56 byte b = 1, *pb = &b, bb = 99; 57 assert_eq(b, 1); 58 assert_eq(bb, 99); 59 assert(pb); 60 assert_eq(*pb, 1); 61 *pb = 42; 62 assert_eq(*pb, 42); 63 assert_eq(b, 42); 64 pb = &bb; 65 --*pb; 66 assert_eq(bb, 98); 67 68 word w = 1, *pw = &w, ww = 999; 69 assert_eq(w, 1); 70 assert_eq(ww, 999); 71 assert(pw); 72 assert_eq(*pw, 1); 73 *pw = 42; 74 assert_eq(*pw, 42); 75 assert_eq(w, 42); 76 pw = &ww; 77 --*pw; 78 assert_eq(ww, 998); 79 return 0; 80 } 81 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4C80 writable_globals_start $4664 writable_globals_end $466C --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 56: Interrupt handler 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 word global = 0; 25 interrupt void isr() 26 { 27 global = 42; 28 } 29 int main() 30 { 31 assert_eq(global, 0); 32 33 // Simulate an IRQ. 34 void *isrAddr = isr; 35 byte *pushedX = 0, *restoredX = 0; 36 asm { 37 leax returnAddr,pcr 38 stx pushedX 39 pshs x // RTI will pop this into PC 40 orcc #$80 // set E flag (whole environment saved) 41 pshs u,y,x,dp,b,a,cc // save rest of environment 42 ldx isrAddr 43 jmp ,x 44 returnAddr: 45 stx restoredX 46 } 47 assert_eq(global, 42); 48 assert_eq(restoredX, pushedX); // X must have been restored by RTI 49 return 0; 50 } 51 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $47B9 writable_globals_start $4195 writable_globals_end $419F --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 57: Global variables 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte bytes[4] = { 11, 22, 33, 44 }; 25 word words[3]; 26 byte gb0 = 42; 27 byte gb1; 28 word gw0 = 7777; 29 word gw1; 30 31 word a = 4000; 32 word x = a + 2000; 33 word wa[] = { 42, 11000 - x, 17 }; 34 byte ba[] = { (byte) 0xd123 }; 35 36 int main() 37 { 38 gw1 = 2424; 39 words[2] = gw0; 40 gb1 = bytes[3]; 41 gb0++; 42 43 assert_eq(gw1, 2424); 44 assert_eq(words[2], 7777); 45 assert_eq(gb1, 44); 46 assert_eq(gb0, 43); 47 assert(bytes != words); 48 assert(gb0 != gb1); 49 assert(gw0 != gw1); 50 assert(gb0 != gw1); 51 assert(gb1 != gw0); 52 53 assert_eq(a, 4000); 54 assert_eq(x, 6000); 55 assert_eq(wa[0], 42); 56 assert_eq(wa[1], 5000); 57 assert_eq(wa[2], 17); 58 assert_eq(ba[0], 0x23); 59 60 return 0; 61 } 62 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4A0C writable_globals_start $439D writable_globals_end $43C0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 58: sizeof(type) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S1 25 { 26 char b[5]; 27 }; 28 struct S0 29 { 30 char b; 31 unsigned *pw; // no 2-byte alignment 32 char byteArray[9 + 1]; // non-trivial size expression tree (cf DeclaratorInfo::computeArraySize()) 33 struct S1 s1; 34 struct S0 *next; 35 }; 36 struct Empty 37 { 38 }; 39 int main() 40 { 41 assert_eq(sizeof(char), 1); 42 assert_eq(sizeof(word), 2); 43 assert_eq(sizeof(char *), 2); 44 assert_eq(sizeof(int *), 2); 45 46 assert_eq(sizeof(unsigned char), 1); 47 assert_eq(sizeof(signed char), 1); 48 assert_eq(sizeof(unsigned), 2); 49 assert_eq(sizeof(signed), 2); 50 assert_eq(sizeof(unsigned short), 2); 51 assert_eq(sizeof(signed short), 2); 52 assert_eq(sizeof(unsigned int), 2); 53 assert_eq(sizeof(signed int), 2); 54 assert_eq(sizeof(unsigned char *), 2); 55 assert_eq(sizeof(signed char *), 2); 56 assert_eq(sizeof(unsigned int *), 2); 57 assert_eq(sizeof(signed int *), 2); 58 59 assert_eq(sizeof(struct S1), 5); 60 assert_eq(sizeof(struct S0), 1 + 2 + 10 + 5 + 2); 61 assert_eq(sizeof(struct S0 *), 2); 62 assert_eq(sizeof(struct Empty), 0); 63 64 char b[8 + 2]; 65 assert_eq(sizeof(b), 10); 66 return 0; 67 } 68 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4B04 writable_globals_start $44E8 writable_globals_end $44F0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 59: sizeof(expr) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S1 25 { 26 byte b[5]; 27 }; 28 struct S0 29 { 30 byte b; 31 word *pw; // no 2-byte alignment 32 byte byteArray[10]; 33 struct S1 s1; 34 struct S0 *next; 35 }; 36 struct Empty 37 { 38 }; 39 int main() 40 { 41 byte b; 42 assert_eq(sizeof(b), 1); 43 word w; 44 assert_eq(sizeof(w), 2); 45 byte *pb; 46 assert_eq(sizeof(pb), 2); 47 word *pw; 48 assert_eq(sizeof(pw), 2); 49 struct S1 s1; 50 assert_eq(sizeof(s1), 5); 51 struct S0 s0; 52 assert_eq(sizeof(s0), 1 + 2 + 10 + 5 + 2); 53 assert_eq(sizeof(&s0), 2); 54 struct Empty empty; 55 assert_eq(sizeof(empty), 0); 56 57 byte ab[5]; 58 assert_eq(sizeof(ab[0]), 1); 59 assert_eq(sizeof(ab), 5); 60 61 word aw[5]; 62 assert_eq(sizeof(aw[0]), 2); 63 assert_eq(sizeof(aw), 5 * 2); 64 assert_eq(sizeof(aw) / sizeof(aw[0]), 5); // the division should be optimized out 65 66 word twoDim[5][3]; 67 assert_eq(sizeof(twoDim), 30); 68 assert_eq(sizeof(twoDim[0]), 6); 69 assert_eq(sizeof(twoDim) / sizeof(twoDim[0]), 5); 70 assert_eq(sizeof(twoDim[0][0]), 2); 71 assert_eq(sizeof(twoDim[18][44]), 2); // indices don't matter 72 73 word threeDim[5][3][4]; 74 assert_eq(sizeof(threeDim), 120); 75 assert_eq(sizeof(threeDim[0]), 24); 76 assert_eq(sizeof(threeDim) / sizeof(threeDim[0]), 5); 77 assert_eq(sizeof(threeDim[0][0]), 8); 78 assert_eq(sizeof(threeDim[0][0][0]), 2); 79 80 struct S1 as1[5]; 81 assert_eq(sizeof(as1), 5 * sizeof(struct S1)); 82 struct S0 as0[5]; 83 assert_eq(sizeof(as0), 5 * sizeof(struct S0)); 84 85 word arrayWithNoSize[] = { 1, 2, 3, 4, 5 }; 86 assert_eq(sizeof(arrayWithNoSize), 10); 87 88 assert_eq(sizeof(""), 1); 89 assert_eq(sizeof("foobar"), 7); 90 assert_eq(sizeof("\0\0\0"), 4); 91 char s[] = "quux"; 92 assert_eq(sizeof(s), 5); 93 94 return 0; 95 } 96 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_memcpy --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4CF3 writable_globals_start $46D7 writable_globals_end $46DF --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 60: Empty statement 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void f() 25 { 26 ; 27 } 28 int main() 29 { 30 return 0; 31 } 32 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $41DA writable_globals_start $409A writable_globals_end $40A0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 61: Variadic function. va_list is a typedef for "word *" 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 25 #include 26 27 struct Object 28 { 29 byte b; 30 }; 31 void variadic(char *firstFixed, char *lastFixed, ...) 32 { 33 va_list ap; 34 assert_eq(sizeof(ap), 2); // va_list is a pointer 35 36 va_start(ap, lastFixed); 37 va_list orig = ap; 38 39 word w = va_arg(ap, word); 40 assert_eq(w, 17); 41 assert_eq(ap, orig + 2); // ap must be 2 bytes from start; va_list is a char * 42 43 byte b = va_arg(ap, byte); 44 assert_eq(b, 42); 45 assert_eq(ap, orig + 4); 46 47 char *s = va_arg(ap, char *); 48 assert(!strcmp(s, "foobar")); 49 assert_eq(ap, orig + 6); 50 51 struct Object *obj = va_arg(ap, struct Object *); 52 assert(obj); 53 assert_eq(obj->b, 99); 54 assert_eq(ap, orig + 8); 55 56 va_end(ap); 57 58 assert(!strcmp(firstFixed, "fixed1")); 59 assert(!strcmp(lastFixed, "fixed2")); 60 assert_eq(w, 17); 61 assert_eq(b, 42); 62 assert(!strcmp(s, "foobar")); 63 assert_eq(obj->b, 99); 64 } 65 int main() 66 { 67 struct Object obj; 68 obj.b = 99; 69 variadic("fixed1", "fixed2", 17, 1024 + 42, "foobar", &obj); 70 return 0; 71 } 72 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strcmp --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4A7F writable_globals_start $443E writable_globals_end $4446 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 62: rand(): Check that counters are filled quasi-uniformly 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 enum { BUCKETS = 32, // must be power of 2 25 ITERATIONS = 3200 }; 26 int main() 27 { 28 int n = rand(); 29 assert_eq(n, 256); // proves that SEED was init to 0 by INILIB 30 srand(42); 31 n = rand(); 32 assert_eq(n, 11071); // proves that SEED was affected by srand() 33 34 word counters[BUCKETS]; 35 memset(counters, 0, BUCKETS * sizeof(word)); 36 int mask = BUCKETS - 1; 37 for (word i = 0; i < ITERATIONS; ++i) 38 ++counters[rand() & mask]; 39 word expectedAverage = ITERATIONS / BUCKETS; 40 word low = expectedAverage * 95 / 100; 41 word high = expectedAverage * 105 / 100; 42 for (word b = 0; b < BUCKETS; ++b) 43 { 44 word c = counters[b]; 45 //printf("%4u. %5u\n", b, c); 46 assert(c >= low && c <= high); 47 } 48 return 0; 49 } 50 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=DIV16 --need=MUL16 --need=_memset --need=_printf --need=_rand --need=_srand --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_DIV16_ -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_memset_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_rand_ -D_CMOC_NEED_srand_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_DIV16_ -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_memset_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_rand_ -D_CMOC_NEED_srand_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $48E3 writable_globals_start $422F writable_globals_end $4239 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 63: Double negation 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void dummy() 25 { 26 // Force "foobar" string to have address >= 0x0100. 27 char *b0 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 28 char *b1 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; 29 char *b2 = "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"; 30 char *b3 = "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"; 31 char *b4 = "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"; 32 } 33 int main() 34 { 35 char b = 0; 36 if (!(!"foobar")) 37 b = 1; 38 else 39 b = -1; 40 assert_eq(b, 1); 41 return 0; 42 } 43 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $48C4 writable_globals_start $42A8 writable_globals_end $42B0 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 64: Signed types 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char comparator(unsigned int w1, unsigned int w2) 25 { 26 char result; 27 if (w1 < w2) 28 result = -1; 29 else if (w1 > w2) 30 result = 1; 31 else 32 result = 0; 33 return result; 34 } 35 int main() 36 { 37 sbyte sb = 255; 38 assert_eq(sb, -1); 39 40 sword sw = 65535; 41 assert_eq(sw, -1); 42 43 // Argument promotion. 44 printf("sb=%d\n", sb); 45 46 // Comparison for jumps. 47 if (sb < 0) 48 printf("sb < 0\n"); 49 else 50 assert(!"sb < 0 failed"); 51 if (sb <= 0) 52 printf("sb <= 0\n"); 53 else 54 assert(!"sb <= 0 failed"); 55 56 if (sw < 0) 57 printf("sw < 0\n"); 58 else 59 assert(!"sw < 0 failed"); 60 if (sw <= 0) 61 printf("sw <= 0\n"); 62 else 63 assert(!"sw <= 0 failed"); 64 65 // Comparisons as integers. 66 if (!(sb < 0)) 67 assert(!"!(sb < 0) failed"); 68 else 69 printf("!!(sb < 0)\n"); 70 if (!(sb <= 0)) 71 assert(!"!(sb <= 0) failed"); 72 else 73 printf("!!(sb <= 0)\n"); 74 75 if (!(sw < 0)) 76 assert(!"!(sw < 0) failed"); 77 else 78 printf("!!(sw < 0)\n"); 79 if (!(sw <= 0)) 80 assert(!"!(sw <= 0) failed"); 81 else 82 printf("!!(sw <= 0)\n"); 83 84 // Comparisons as integers. 85 word bool0 = (sb < 0); 86 assert(bool0); 87 bool0 = (sb <= 0); 88 assert(bool0); 89 word bool1 = (sw < 0); 90 assert(bool1); 91 bool1 = (sw <= 0); 92 assert(bool1); 93 94 sbyte t = -1; 95 word comp = (t > 0); 96 assert_eq(comp, 0); 97 comp = (t >= 0); 98 assert_eq(comp, 0); 99 t = 1; 100 comp = (t < 0); 101 assert_eq(comp, 0); 102 comp = (t <= 0); 103 assert_eq(comp, 0); 104 105 assert(sb < 0); 106 assert(sb <= 0); 107 assert(sw < 0); 108 assert(sw <= 0); 109 assert(!(sb > 0)); 110 assert(!(sb >= 0)); 111 assert(!(sw > 0)); 112 assert(!(sw >= 0)); 113 114 assert(comparator(0, 1) < 0); 115 assert(comparator(2, 1) > 0); 116 assert(comparator(1, 1) == 0); 117 assert(comparator(30, 31) < 0); 118 assert(comparator(32, 31) > 0); 119 assert(comparator(31, 31) == 0); 120 121 sbyte minusOne = -1; 122 123 // Binary operand promotion. 124 assert(1000 + (sbyte) 255 == 999); 125 assert((sbyte) 255 + 1000 == 999); 126 assert(1000 + sb == 999); 127 assert(sb + 1000 == 999); 128 assert(1000 + sw == 999); 129 assert(sw + 1000 == 999); 130 131 assert(1000 - (sbyte) 255 == 1001); 132 assert((sbyte) 255 - 1000 == -1001); 133 assert(1000 - sb == 1001); 134 assert(sb - 1000 == -1001); 135 assert(1000 - sw == 1001); 136 assert(sw - 1000 == -1001); 137 138 assert_eq(sb * sb, 1); 139 assert_eq(sb / sb, 1); 140 assert_eq(-1 * -1, 1); 141 assert_eq(-1 / -1, 1); 142 assert_eq(-1000 * -5, 5000); 143 assert_eq(1000 * -5, -5000); 144 assert_eq(-5 * -1000, 5000); 145 assert_eq(-5 * 1000, -5000); 146 assert_eq(-1000 / -5, 200); 147 assert_eq(1000 / -5, -200); 148 assert_eq(-5 / -1000, 0); 149 assert_eq(-5 / 1000, 0); 150 151 sw = -1000; 152 sb = -5; 153 assert_eq(sb, -5); 154 assert_eq(sw * sb, 5000); 155 assert_eq(sb * sw, 5000); 156 assert_eq(sw / sb, 200); 157 158 sw *= -5; 159 assert_eq(sw, 5000); 160 sw /= -5; 161 sw /= -5; 162 assert_eq(sw, 200); 163 164 assert_eq( 23 % 10, 3); 165 assert_eq(-23 % 10, -3); 166 assert_eq(-23 % -10, -3); 167 assert_eq( 23 % -10, 3); 168 169 assert_eq(-1000 % 400, -200); 170 171 sw = -1000; 172 assert_eq(sw % 10, 0); 173 assert_eq(sw % 9, -1); 174 assert_eq(sw % 400, -200); 175 176 sw = 255; 177 assert_eq(sw * sw, 65025); 178 return 0; 179 } 180 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=MUL16 --need=SDIV16 --need=SDIV8 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_SDIV16_ -D_CMOC_NEED_SDIV8_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_SDIV16_ -D_CMOC_NEED_SDIV8_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $549B writable_globals_start $4DB4 writable_globals_end $4DBC --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: sb=-1 sb < 0 sb <= 0 sw < 0 sw <= 0 !!(sb < 0) !!(sb <= 0) !!(sw < 0) !!(sw <= 0) --- Actual output: sb=-1 sb < 0 sb <= 0 sw < 0 sw <= 0 !!(sb < 0) !!(sb <= 0) !!(sw < 0) !!(sw <= 0) -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 65: sbrk(), sbrkmax() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int global1 = 0xAABB; 25 int main() 26 { 27 assert_eq(global1, 0xAABB); 28 unsigned initMax = sbrkmax(); 29 assert(initMax > 0); 30 31 // Count number of times 1k can be allocated. 32 unsigned counter = 0; 33 unsigned bufsiz = 1024; 34 void *prevAllocated = main; 35 void *newlyAllocated; 36 while ((newlyAllocated = sbrk(bufsiz)) != (void *) -1) 37 { 38 assert_eq(global1, 0xAABB); 39 ++counter; 40 assert((unsigned) newlyAllocated > (unsigned) prevAllocated); 41 prevAllocated = newlyAllocated; 42 43 memset(newlyAllocated, 0xEE, bufsiz); 44 assert_eq(global1, 0xAABB); 45 } 46 47 assert(counter > 0); 48 assert(counter < 64); 49 assert(counter * bufsiz <= initMax); 50 assert_eq(counter, initMax / bufsiz); 51 assert_eq(global1, 0xAABB); 52 53 unsigned finalMax = sbrkmax(); 54 assert_eq(global1, 0xAABB); 55 assert(finalMax < bufsiz); 56 assert(finalMax < initMax); 57 assert_eq(initMax - counter * bufsiz, finalMax); 58 59 //printf("%u; %u -> %u; %u\n", counter, initMax, finalMax, initMax / bufsiz); 60 return 0; 61 } 62 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=DIV16 --need=MUL16 --need=_memset --need=_printf --need=_sbrk --need=_sbrkmax --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_DIV16_ -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_memset_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_sbrk_ -D_CMOC_NEED_sbrkmax_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_DIV16_ -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_memset_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_sbrk_ -D_CMOC_NEED_sbrkmax_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4A35 writable_globals_start $4385 writable_globals_end $438F --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 66: sbrkmax() vs #pragma stack_space 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 #pragma stack_space 32768 25 int global1 = 0xAABB; 26 int main() 27 { 28 assert_eq(global1, 0xAABB); 29 unsigned initMax = sbrkmax(); 30 //printf("initMax = %u\n", initMax); 31 assert(initMax > 12000 && initMax < 18000); // would be about 45000 without #pragma 32 return 0; 33 } 34 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=32768 --need=_printf --need=_sbrkmax --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=32768 -D_CMOC_NEED_printf_ -D_CMOC_NEED_sbrkmax_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=32768 -D_CMOC_NEED_printf_ -D_CMOC_NEED_sbrkmax_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $479B writable_globals_start $4169 writable_globals_end $4173 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 67: Casting signed byte value into 2-byte types 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S { word n; }; 25 int main() 26 { 27 assert_eq(sizeof((byte *) 0), 2); 28 assert_eq(sizeof((byte *) 100), 2); 29 assert_eq((byte *) -1, 0xFFFF); 30 assert_eq((word *) -1, 0xFFFF); 31 assert_eq((word) -1, 0xFFFF); 32 assert_eq((sword) -1, 0xFFFF); 33 assert_eq((byte) -1, 0xFF); 34 assert_eq((sbyte) -1, -1); 35 36 assert_eq((sbyte) -1, 0xFF); // byte operands not promoted to int, unl 37 38 // Cast to a struct pointer. 39 assert_eq((struct S *) -1, 0xFFFF); 40 byte buf[2]; 41 assert(buf); 42 struct S *ps = (struct S *) buf; 43 assert_eq(ps, buf); 44 ps->n = 1844; 45 assert_eq(* (word *) buf, 1844); 46 * (word *) buf = 4418; 47 assert_eq(ps->n, 4418); 48 49 int i = (char) -42; 50 assert_eq(i, -42); 51 52 return 0; 53 } 54 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $49DD writable_globals_start $43C1 writable_globals_end $43C9 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 68: Casting to 2-keyword types 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S { char c; }; 25 int main() 26 { 27 unsigned char c; 28 c = (unsigned char) 42; 29 assert_eq(c, 42); 30 (signed int) 0xFFFF; 31 (unsigned short *) 0x1234; 32 (struct S *) 1; 33 (struct S ***) 3; 34 35 struct S s = { '$' }; 36 struct S *ps = &s; 37 struct S **pps = &ps; 38 struct S ***ppps = &pps; 39 unsigned short address = (unsigned short) ppps; 40 ppps = 0; 41 assert_eq(ppps, 0); 42 ppps = (struct S ***) address; 43 44 assert_eq(s.c, '$'); 45 assert_eq((*ps).c, '$'); 46 assert_eq((**pps).c, '$'); 47 assert_eq((***ppps).c, '$'); 48 49 return 0; 50 } 51 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $485F writable_globals_start $4243 writable_globals_end $424B --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 69: Right shift on a signed value must do an arithmetic shift, not a logical one 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void test() 25 { 26 word initStackPtr; 27 asm { sts initStackPtr }; 28 29 byte ub = 0x80; 30 assert_eq(ub >> 1, 0x40); // LSR 31 sbyte sb = 0x80; 32 assert_eq(sb >> 1, (sbyte) 0xC0); // ASR 33 word uw = 0x8000; 34 assert_eq(uw >> 1, 0x4000); // LSR 35 sword sw = 0x8000; 36 assert_eq(sw >> 1, (sword) 0xC000); // ASR 37 38 assert_eq( 128 >> 1, 0x40); // LSR 39 assert_eq( -64 >> 1, 0xFFE0); // ASR 40 assert_eq(((sbyte) -64) >> 1, 0xFFE0); // ASR: -64 starts as $FFC0, gets cast as $C0, right shift extends it to $FFC0, then shifts it 41 assert_eq( -128 >> 1, 0xFFC0); // ASR 42 assert_eq( -128 >> 1, (sbyte) 0xC0); // ASR 43 assert_eq( 32768 >> 1, 0x4000); // LSR 44 assert_eq(-16384 >> 1, (sword) 0xE000); // ASR 45 assert_eq(-32768 >> 1, (sword) 0xC000); // ASR 46 47 ub = 0x80; 48 ub >>= 2; 49 assert_eq(ub, 0x20); 50 sb = 0x80; 51 sb >>= 2; 52 assert_eq(sb, 0xE0); 53 54 asm { clrb } // to prove next line is compiled correctly 55 56 sbyte *psb = &(sb >>= 1); // shift-assignment as l-value expression 57 assert_eq(sb, 0xF0); 58 assert_eq(psb, &sb); 59 assert_eq(*psb, 0xF0); 60 61 uw = 0x8000; 62 uw >>= 2; 63 assert_eq(uw, 0x2000); 64 sw = 0x8000; 65 sw >>= 2; 66 assert_eq(sw, 0xE000); 67 68 word finalStackPtr; 69 asm { sts finalStackPtr }; 70 assert_eq(finalStackPtr, initStackPtr); 71 } 72 int main() 73 { 74 test(); 75 return 0; 76 } 77 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4AD3 writable_globals_start $44B7 writable_globals_end $44BF --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 70: Returning integer 0 allowed in pointer-returning function 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte *b() 25 { 26 return 0; 27 } 28 word *w() 29 { 30 return 0; 31 } 32 int main() 33 { 34 assert_eq(b(), 0); 35 assert_eq(w(), 0); 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $475F writable_globals_start $4143 writable_globals_end $414B --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 71: Struct array initializer. For loop increment on a struct pointer. Initializer with non-constant expression 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct SystemVar 25 { 26 char *name; 27 char *addr; 28 char type; 29 }; 30 struct SystemVar systemVars[] = 31 { 32 { "foo", 0x0019, 21 }, 33 { "bar", 0x0112, 25 }, 34 { "baz", 0x011A, 14 }, 35 { 0, 0, 0 } // marks the end 36 }; 37 struct CardBitmap 38 { 39 unsigned int rows[5]; 40 }; 41 struct CardBitmap cardBitmaps[] = 42 { 43 { { 1, 2, 3, 4, 5 } }, // outer {} for struct, inner for rows[] 44 { { 6, 7, 8, 9, 10 } }, 45 { { 11, 12, 13, 14, 15} }, 46 }; 47 int main() 48 { 49 word numElements = sizeof(systemVars) / sizeof(systemVars[0]) - 1; 50 assert_eq(numElements, 3); 51 char buffer[128]; 52 buffer[0] = 0; 53 word addrSum = 0; 54 word typeSum = 0; 55 for (struct SystemVar *p = systemVars; p->name; ++p) 56 { 57 strcat(buffer, p->name); 58 addrSum += (word) p->addr; 59 typeSum += p->type; 60 } 61 assert(!strcmp(buffer, "foobarbaz")); 62 assert_eq(addrSum, 0x0019 + 0x0112 + 0x011A); 63 assert_eq(typeSum, 21 + 25 + 14); 64 65 word wa[2] = { addrSum + 1, typeSum * 2 }; 66 assert_eq(wa[0], 0x0019 + 0x0112 + 0x011A + 1); 67 assert_eq(wa[1], (21 + 25 + 14) * 2); 68 69 assert_eq(cardBitmaps[0].rows[0], 1); 70 assert_eq(cardBitmaps[1].rows[2], 8); 71 assert_eq(cardBitmaps[2].rows[4], 15); 72 73 return 0; 74 } 75 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=MUL16 --need=_printf --need=_strcat --need=_strcmp --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcat_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcat_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4A22 writable_globals_start $4320 writable_globals_end $435A --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 72: Initializer for structs and arrays 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S 25 { 26 byte b; 27 word w; 28 }; 29 struct S global = 30 { 31 255, 32 12700 33 }; 34 struct StructWithArray 35 { 36 byte b; 37 word a[3]; 38 word w; 39 }; 40 struct StructWithArray globalWithArray = 41 { 42 77, { 2000, 21, 2002 }, 9988 43 }; 44 struct StructWithArray globalArrayOfStructWithArray[2] = 45 { 46 { 77, { 2000, 21, 2002 }, 9988 }, 47 { 177, { 2100, 22, 2102 }, 10088 }, 48 }; 49 struct StructWithByteArray 50 { 51 char str[7]; 52 }; 53 struct StructWithByteArray globalString = { "foobar" }; 54 55 struct A 56 { 57 byte byteField; 58 }; 59 struct A a = { 10 }; 60 struct B 61 { 62 struct A aMember; 63 }; 64 struct B b = { { 11 } }; 65 struct C 66 { 67 struct A aMemberArray[2]; 68 }; 69 struct C c = { { { 12 }, { 13 } } }; 70 71 int main() 72 { 73 assert_eq(global.b, 255); 74 assert_eq(global.w, 12700); 75 76 struct S local = 77 { 78 25, 79 1200 80 }; 81 assert_eq(local.b, 25); 82 assert_eq(local.w, 1200); 83 84 assert_eq(globalWithArray.b, 77); 85 assert_eq(globalWithArray.a[0], 2000); 86 assert_eq(globalWithArray.a[1], 21); 87 assert_eq(globalWithArray.a[2], 2002); 88 assert_eq(globalWithArray.w, 9988); 89 90 assert_eq(globalArrayOfStructWithArray[0].b, 77); 91 assert_eq(globalArrayOfStructWithArray[0].a[0], 2000); 92 assert_eq(globalArrayOfStructWithArray[0].a[1], 21); 93 assert_eq(globalArrayOfStructWithArray[0].a[2], 2002); 94 assert_eq(globalArrayOfStructWithArray[0].w, 9988); 95 96 assert_eq(globalArrayOfStructWithArray[1].b, 177); 97 assert_eq(globalArrayOfStructWithArray[1].a[0], 2100); 98 assert_eq(globalArrayOfStructWithArray[1].a[1], 22); 99 assert_eq(globalArrayOfStructWithArray[1].a[2], 2102); 100 assert_eq(globalArrayOfStructWithArray[1].w, 10088); 101 102 struct StructWithArray localArrayOfStructWithArray[2] = 103 { 104 { 77, { 2000, 21, 2002 }, 9988 }, 105 { 177, { 2100, 22, 2102 }, 10088 }, 106 }; 107 108 assert(!strcmp(globalString.str, "foobar")); 109 struct StructWithByteArray localString = { "FOOBAR" }; 110 assert(!strcmp(localString.str, "FOOBAR")); 111 112 assert_eq(a.byteField, 10); 113 assert_eq(b.aMember.byteField, 11); 114 assert_eq(c.aMemberArray[0].byteField, 12); 115 assert_eq(c.aMemberArray[1].byteField, 13); 116 117 return 0; 118 } 119 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strcmp --need=_strncpy --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strncpy_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strncpy_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4D70 writable_globals_start $4680 writable_globals_end $46B1 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 73: Pointer to pointer, array of pointers 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char *strings[] = { "foo", "bar", "baz", "abcdefghij" }; 25 char *moreStrings[][2] = { { "foo", "bar" }, { "baz", "abcdefghij" } }; 26 struct S { char b[2]; }; 27 void check(char **pba) 28 { 29 char *s = pba[0]; 30 assert(!strcmp(s, "foo")); 31 s = pba[1]; 32 assert(!strcmp(s, "bar")); 33 s = pba[2]; 34 assert(!strcmp(s, "baz")); 35 assert_eq(s[2], 'z'); 36 } 37 int main() 38 { 39 assert(!strcmp(strings[0], "foo")); 40 assert(!strcmp(strings[1], "bar")); 41 assert(!strcmp(strings[2], "baz")); 42 assert(!strcmp(strings[3], "abcdefghij")); 43 assert_eq(strings[3][7], 'h'); 44 45 char **ptrToByteArray = strings; 46 char *s = ptrToByteArray[0]; 47 assert(!strcmp(s, "foo")); 48 s = ptrToByteArray[1]; 49 assert(!strcmp(s, "bar")); 50 s = ptrToByteArray[2]; 51 assert(!strcmp(s, "baz")); 52 assert_eq(s[2], 'z'); 53 54 check(strings); 55 56 char *bytePtr = (char *) 0x1234; 57 word w = 0x9876; 58 * (char **) &w = bytePtr; 59 assert_eq(w, (word) bytePtr); 60 61 w = 0x6655; 62 ((struct S *) &w)->b[1] = 0x77; 63 assert_eq(w, 0x6677); 64 65 (* (struct S **) &w) = 0x5678; 66 assert_eq(w, 0x5678); 67 68 assert(!strcmp(moreStrings[0][0], "foo")); 69 assert(!strcmp(moreStrings[0][1], "bar")); 70 assert(!strcmp(moreStrings[1][0], "baz")); 71 assert(!strcmp(moreStrings[1][1], "abcdefghij")); 72 assert_eq(moreStrings[1][1][9], 'j'); 73 74 return 0; 75 } 76 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strcmp --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4BBA writable_globals_start $4529 writable_globals_end $4541 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 74: Automatic conversion of an integer to a pointer, without a warning 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 byte *p = 0x123; 27 assert_eq(p, 0x123); 28 p = 0x456; 29 assert_eq(p, 0x456); 30 return 0; 31 } 32 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4768 writable_globals_start $414C writable_globals_end $4154 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 75: char, short, signed, unsigned 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 word f(char ch, short sh, signed si, unsigned un) 25 { 26 return ch + sh + si + un; 27 } 28 int main() 29 { 30 char ch; 31 assert_eq(sizeof(ch), 1); 32 short sh; 33 assert_eq(sizeof(sh), 2); 34 signed si; 35 assert_eq(sizeof(si), 2); 36 unsigned un; 37 assert_eq(sizeof(un), 2); 38 assert_eq(f(-128, -300, -400, 10000), 9172); 39 40 signed char sch; 41 assert_eq(sizeof(sch), 1); 42 unsigned char uch; 43 assert_eq(sizeof(uch), 1); 44 signed short shint; 45 assert_eq(sizeof(shint), 2); 46 unsigned short unshint; 47 assert_eq(sizeof(unshint), 2); 48 signed int sint; 49 assert_eq(sizeof(sint), 2); 50 unsigned int unsint; 51 assert_eq(sizeof(unsint), 2); 52 return 0; 53 } 54 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $498D writable_globals_start $4371 writable_globals_end $4379 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 76: typedef 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 typedef unsigned short uint16_t; 25 typedef unsigned short *Ptr; 26 27 // Typedef for an array: 28 typedef unsigned Addr[2]; 29 Addr addr = { 0xAAAA, 0xBBBB }; 30 31 typedef char string10_t[10]; 32 typedef struct { 33     string10_t str1; 34     char str2[10]; 35     int str3[10]; 36 } test_t; 37 38 struct S { 39 string10_t grid[5]; 40 char c; 41 }; 42 43 typedef int TenInts[10]; 44 struct T { 45 TenInts tens[5]; 46 }; 47 48 void f1(char *a) {} 49 void f2(int *a) {} 50 unsigned diff(void *a, void *b) { return b - a; } 51 52 int main() 53 { 54 uint16_t u = 2014; 55 assert_eq(u, 2014); 56 Ptr p = &u; 57 assert_eq(*p, 2014); 58 59 assert_eq(addr[0], 0xAAAA); 60 assert_eq(addr[1], 0xBBBB); 61 addr[0] = 0x1111; 62 addr[1] = 0x2222; 63 assert_eq(addr[0], 0x1111); 64 assert_eq(addr[1], 0x2222); 65 66 Addr localAddr = { 1234, 2345 }; 67 assert_eq(localAddr[0] + localAddr[1], 3579); 68 ++localAddr[0]; 69 ++localAddr[1]; 70 assert_eq(localAddr[0] + localAddr[1], 3581); 71 72     string10_t str1; 73 assert_eq(sizeof(str1), 10); 74 assert_eq((str1 + 1) - str1, 1); 75 76 string10_t tens[5]; 77 assert_eq(sizeof(tens), 50); 78 assert_eq(sizeof(tens[2]), 10); 79 assert_eq(tens[4] - tens[3], 10); 80 assert_eq((tens + 1) - tens, 10); 81 82     char str2[10]; 83     test_t test; 84 assert_eq(sizeof(string10_t), 10); 85 assert_eq(sizeof(test.str1), 10); 86 assert_eq(sizeof(test.str2), 10); 87 assert_eq(sizeof(test.str3), 20); 88 assert_eq(sizeof(test), 40); 89 f1(str1); 90 f1(str2); 91 f1(test.str1); 92 f1(test.str2); 93 f2(test.str3); 94 assert_eq(diff( test.str1, test.str2), 10); 95 assert_eq(diff(&test.str1, test.str2), 10); 96 assert_eq(diff( test.str1, &test.str2), 10); 97 assert_eq(diff( test.str2, test.str3), 10); 98 assert_eq(diff(&test.str2, test.str3), 10); 99 assert_eq(diff( test.str2, &test.str3), 10); 100 101 struct S s; 102 assert_eq(sizeof(s.grid), 50); 103 assert_eq(sizeof(s.grid[2]), 10); 104 assert_eq(sizeof(s), 51); 105 assert_eq(diff(s.grid, &s.c), 50); 106 107 struct T t; 108 assert_eq(sizeof(TenInts), 10 * 2); 109 assert_eq(sizeof(t.tens), 50 * 2); 110 assert_eq(sizeof(t.tens[3]), 10 * 2); 111 112 // Initializers. 113 114 char str3[10] = "foobarbaz"; 115 assert_eq(strcmp(str3, "foobarbaz"), 0); 116 assert_eq(strlen(str3), 9); 117 string10_t str4 = "FOOBARBAZ"; 118 assert_eq(strcmp(str4, "FOOBARBAZ"), 0); 119 assert_eq(strlen(str4), 9); 120 121 string10_t strArray1[] = { "A", "B" }; 122 assert_eq(strArray1, strArray1[0]); 123 assert_ne(strArray1[0], strArray1[1]); 124 assert_eq(strcmp(strArray1[0], "A"), 0); 125 assert_eq(strcmp(strArray1[1], "B"), 0); 126 127 struct S s1 = { { "a", "b", "c", "d", "e" }, '$' }; 128 assert_eq(s1.grid, s1.grid[0]); 129 assert_ne(s1.grid, s1.grid[1]); 130 assert_ne(s1.grid, &s1.c); 131 assert_ne(s1.grid[4], &s1.c); 132 assert_eq(strcmp(s1.grid[0], "a"), 0); 133 assert_eq(strcmp(s1.grid[1], "b"), 0); 134 assert_eq(strcmp(s1.grid[2], "c"), 0); 135 assert_eq(strcmp(s1.grid[3], "d"), 0); 136 assert_eq(strcmp(s1.grid[4], "e"), 0); 137 assert_eq(s1.c, '$'); 138 139 struct S s2 = { { "f", { 'g', 0, 1, 2, 3, 4, 5, 6, 7, 8 }, "h", "i", "j" }, '%' }; 140 assert_eq(strcmp(s2.grid[0], "f"), 0); 141 assert_eq(strcmp(s2.grid[1], "g"), 0); 142 assert_eq(s2.grid[1][9], 8); 143 assert_eq(strcmp(s2.grid[2], "h"), 0); 144 assert_eq(strcmp(s2.grid[3], "i"), 0); 145 assert_eq(strcmp(s2.grid[4], "j"), 0); 146 assert_eq(s2.c, '%'); 147 148 return 0; 149 } 150 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_memcpy --need=_printf --need=_strcmp --need=_strlen --need=_strncpy --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strlen_ -D_CMOC_NEED_strncpy_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strlen_ -D_CMOC_NEED_strncpy_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $5877 writable_globals_start $520A writable_globals_end $5216 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 77: Multi-dimensional arrays 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int twoD[3][5]; 25 int threeD[4][3][5]; 26 int v[][2][3] = { 27 { { 10, 11, 12 }, { 13, 14, 15 } }, 28 { { 20, 21, 22 }, { 23, 24, 25 } }, 29 { { 30, 31, 32 }, { 33, 34, 35 } }, 30 { { 40, 41, 42 }, { 43, 44, 45 } }, 31 }; 32 unsigned char b[][2][3] = { // same as v, but 100 added to each row 33 { { 110, 11, 12 }, { 13, 14, 15 } }, 34 { { 20, 121, 22 }, { 23, 24, 25 } }, 35 { { 30, 31, 132 }, { 33, 34, 35 } }, 36 { { 40, 41, 42 }, { 143, 44, 45 } }, 37 }; 38 struct Point 39 { 40 int x; 41 int y; 42 int z; 43 }; 44 struct Point s[2][3] = { 45 { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, }, 46 { { 10, 11, 12 }, { 13, 14, 15 }, { 16, 17, 18 }, }, 47 }; 48 int computeSum(int v[2][3][4]) 49 { 50 int result = 0; 51 for (int i = 0; i < 2; ++i) 52 for (int j = 0; j < 3; ++j) 53 for (int k = 0; k < 4; ++k) 54 result += v[i][j][k]; 55 return result; 56 } 57 struct S 58 { 59 int a[2][3][4]; 60 }; 61 int main() 62 { 63 // 2 dimensions. 64 int *p = (int *) twoD; 65 for (int i = 0; i < 15; ++i) 66 p[i] = 100 + i; 67 for (int i = 0; i < 3; ++i) 68 for (int j = 0; j < 5; ++j) 69 { 70 int expected = 100 + i * 5 + j; 71 if (twoD[i][j] != expected) 72 { 73 printf("ERROR: line %d: twoD[%d][%d] == %d, expected %d\n", 74 __LINE__, i, j, twoD[i][j], expected); 75 exit(1); 76 } 77 } 78 79 // Constant indexes. 80 twoD[2][4] = 244; 81 assert_eq(twoD[2][4], 244); 82 83 for (int i = 0; i < 3; ++i) 84 for (int j = 0; j < 5; ++j) 85 twoD[i][j] = 200 - i * 5 - j; 86 for (int i = 0; i < 3; ++i) 87 for (int j = 0; j < 5; ++j) 88 { 89 int *actualAddress = &twoD[i][j]; 90 unsigned actualOffset = actualAddress - twoD; 91 assert_eq(actualOffset, i * 5 + j); 92 93 assert_eq(twoD[i][j], 200 - i * 5 - j); 94 } 95 96 int sum = 0; 97 98 // 3 dimensions. 99 p = (int *) threeD; 100 for (int i = 0; i < 60; ++i) 101 p[i] = 100 + i; 102 for (int i = 0; i < 4; ++i) 103 for (int j = 0; j < 3; ++j) 104 for (int k = 0; k < 5; ++k) 105 { 106 int *actualAddress = &threeD[i][j][k]; 107 unsigned actualOffset = actualAddress - threeD; 108 assert_eq(actualOffset, i * 15 + j * 5 + k); 109 110 int expected = 100 + i * 15 + j * 5 + k; 111 if (threeD[i][j][k] != expected) 112 { 113 printf("ERROR: line %d: threeD[%d][%d][%d] == %d, expected %d\n", 114 __LINE__, i, j, k, threeD[i][j][k], expected); 115 exit(1); 116 } 117 int temp = threeD[i][j][k]; 118 ++threeD[i][j][k]; 119 assert_eq(threeD[i][j][k], temp + 1); 120 } 121 122 // Constant indexes. 123 threeD[3][2][4] = 1000; 124 assert_eq(threeD[3][2][4], 1000); 125 126 // Size of first dimension specified by initializer. 127 sum = 0; 128 for (int i = 0; i < 4; ++i) 129 for (int j = 0; j < 2; ++j) 130 for (int k = 0; k < 3; ++k) 131 sum += v[i][j][k]; 132 assert_eq(sum, 660); 133 134 // Bytes. 135 sum = 0; 136 for (int i = 0; i < 4; ++i) 137 for (int j = 0; j < 2; ++j) 138 for (int k = 0; k < 3; ++k) 139 sum += b[i][j][k]; 140 assert_eq(sum, 660 + 400); 141 142 // Multi-dim. array of structs. 143 sum = 0; 144 for (int i = 0; i < 2; ++i) 145 for (int j = 0; j < 3; ++j) 146 sum += s[i][j].x + s[i][j].y + s[i][j].z; 147 assert_eq(sum, 171); 148 149 // Struct containing multi-dim array member. 150 struct S s; 151 assert_eq(sizeof(s), sizeof(int) * 2 * 3 * 4); 152 memset(&s, 0, sizeof(s)); 153 s.a[0][0][0] = 42; 154 assert_eq(s.a[0][0][0], 42); 155 s.a[1][2][3] = 1844; 156 assert_eq(s.a[1][2][3], 1844); 157 assert_eq(computeSum(s.a), 42 + 1844); 158 159 return 0; 160 } 161 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=MUL16 --need=_exit --need=_memset --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_exit_ -D_CMOC_NEED_memset_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_exit_ -D_CMOC_NEED_memset_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $52C2 writable_globals_start $4B6E writable_globals_end $4C78 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 78: Function parameter of array type (one or more dimensions) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int f(int a[], int i) 25 { 26 return a[i]; 27 } 28 int g(int a[][3], int i, int j) 29 { 30 return a[i][j]; 31 } 32 int h(int a[][3][3], int i, int j, int k) 33 { 34 return a[i][j][k]; 35 } 36 int *fptr(int a[], int i) 37 { 38 return &a[i]; 39 } 40 int *gptr(int a[][3], int i, int j) 41 { 42 return &a[i][j]; 43 } 44 int *hptr(int a[][3][3], int i, int j, int k) 45 { 46 return &a[i][j][k]; 47 } 48 int *getArray2(int a[][3], int i) 49 { 50 return a[i]; 51 } 52 int *getArray3(int a[][3][3], int i, int j) 53 { 54 return a[i][j]; 55 } 56 void checkConstIndexes(int a[][3]) 57 { 58 int *p = &a[4][2]; 59 assert_eq(p - a, 4 * 3 + 2); 60 61 int i = 2, j = 5; 62 p = &a[i][j]; 63 assert_eq(p - a, 2 * 3 + 5); 64 } 65 int main() 66 { 67 int v1[] = { 5, 6, 7, 8 }; 68 assert_eq(f(v1, 2), 7); 69 int v2[][3] = { { 9, 8, 7 }, { 99, 88, 77 }, { 66, 55, 44 } }; 70 assert_eq(f(v2[1], 2), 77); // v2[1] points to { 99, 88, 77 } 71 assert_eq(g(v2, 1, 2), 77); 72 int v3[][3][3] = 73 { 74 { 75 { 9, 8, 7 }, 76 { 99, 88, 77 }, 77 { 66, 55, 44 } 78 }, 79 { 80 { 19, 18, 17 }, 81 { 199, 188, 177 }, 82 { 166, 155, 144 } 83 } 84 }; 85 assert_eq(h(v3, 1, 2, 1), 155); 86 87 assert_eq(sizeof(v1), 2 * 4); 88 assert_eq(sizeof(v2), 2 * 3 * 3); 89 assert_eq(sizeof(v3), 2 * 2 * 3 * 3); 90 91 int sum; 92 93 sum = 0; 94 for (int i = 0; i < 4; ++i) 95 sum += f(v1, i); 96 assert_eq(sum, (int)5+6+7+8); 97 98 sum = 0; 99 for (int i = 0; i < 3; ++i) 100 for (int j = 0; j < 3; ++j) 101 sum += g(v2, i, j); 102 assert_eq(sum, (int)9+8+7 + (int)99+88+77 + (int)66+55+44); 103 104 sum = 0; 105 for (int i = 0; i < 2; ++i) 106 for (int j = 0; j < 3; ++j) 107 for (int k = 0; k < 3; ++k) 108 sum += h(v3, i, j, k); 109 assert_eq(sum, 1536); 110 111 // Test functions like f, g, h but that return pointers. 112 // 113 *fptr(v1, 2) = 4545; 114 assert_eq(f(v1, 2), 4545); 115 *gptr(v2, 1, 2) = 9876; 116 assert_eq(g(v2, 1, 2), 9876); 117 *hptr(v3, 1, 2, 1) = 1234; 118 assert_eq(h(v3, 1, 2, 1), 1234); 119 120 // Test functions that return an array. 121 // 122 assert_eq(getArray2(v2, 2)[1], 55); 123 assert_eq(getArray3(v3, 1, 1)[1], 188); 124 125 int aa[1][3] = { { 1, 2, 3 } }; 126 checkConstIndexes(aa); 127 128 return 0; 129 } 130 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=MUL16 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4F29 writable_globals_start $48F5 writable_globals_end $48FD --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 79: switch() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int testSwitch1(int n) 25 { 26 int ret = 7777; 27 switch (n) 28 { 29 case -3: 30 return 100; 31 case 0: 32 ret = 101; 33 break; 34 case 5: 35 ret = 102; 36 // FALLTHROUGH 37 case 2: 38 ret = 103; 39 break; 40 default: 41 ret = 999; 42 } 43 return ret; 44 } 45 int testSwitch2(int n) // default in the middle 46 { 47 int ret = 7777; 48 switch (n) 49 { 50 case -3: 51 return 100; 52 default: 53 ret = 999; 54 break; 55 case 0: 56 ret = 101; 57 break; 58 case 5: 59 ret = 102; 60 // FALLTHROUGH 61 case 2: 62 ret = 103; 63 } 64 return ret; 65 } 66 int testSwitch3(char n) // byte expression, default in the middle 67 { 68 int ret = 7777; 69 switch (n) 70 { 71 case -3: 72 return 100; 73 default: 74 ret = 999; 75 break; 76 case 0: 77 ret = 101; 78 break; 79 case 5: 80 ret = 102; 81 // FALLTHROUGH 82 case 2: 83 ret = 103; 84 85 } 86 87 return ret; 88 } 89 char testSwitch4(char n) 90 { 91 switch (n) 92 { 93 case 2: 94 case 8: 95 case 11: // jack 96 return 0; 97 default: 98 return 1; 99 } 100 } 101 int main() 102 { 103 assert_eq(testSwitch1(-3), 100); 104 assert_eq(testSwitch1( 0), 101); 105 assert_eq(testSwitch1( 5), 103); 106 assert_eq(testSwitch1( 2), 103); 107 assert_eq(testSwitch1(-9), 999); 108 109 assert_eq(testSwitch2(-3), 100); 110 assert_eq(testSwitch2( 0), 101); 111 assert_eq(testSwitch2( 5), 103); 112 assert_eq(testSwitch2( 2), 103); 113 assert_eq(testSwitch2(-9), 999); 114 115 assert_eq(testSwitch3(-3), 100); 116 assert_eq(testSwitch3( 0), 101); 117 assert_eq(testSwitch2( 5), 103); 118 assert_eq(testSwitch3( 2), 103); 119 assert_eq(testSwitch3(-9), 999); 120 121 assert_eq(testSwitch4(2), 0); 122 assert_eq(testSwitch4(8), 0); 123 assert_eq(testSwitch4(11), 0); 124 assert_eq(testSwitch4(13), 1); 125 126 // break inside an if(). 127 int n = 17; 128 switch (3) 129 { 130 case 3: 131 if (n == 17) 132 { 133 n = 88; 134 break; 135 } 136 case 4: 137 n = 99; 138 break; 139 } 140 assert_eq(n, 88); 141 142 return 0; 143 } 144 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4D34 writable_globals_start $4718 writable_globals_end $4720 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 80: break vs. switch in a switch 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char testSwitchInASwitch(byte a, byte b) 25 { 26 //printf("testSwitchInASwitch(a=%u, b=%u): start\n", a, b); 27 byte iter = 0; 28 switch (a) 29 { 30 case 10: 31 //printf("case 10\n"); 32 switch (b) 33 { 34 case 22: 35 //printf("case 22\n"); 36 break; 37 default: 38 return 1; 39 } 40 //printf("iter=%u\n", iter); 41 if (++iter > 1) 42 return 2; 43 break; // With CMOC <= 0.1.22, we'd jump to end of inner switch(), 44 // causing infinite loop, which 'iter' detects. 45 // Cause: Missing call to popBreakableLabels() 46 // in SwitchStmt::emitCode(). 47 } 48 //printf("testSwitchInASwitch: end\n"); 49 return 0; // supposed to come here 50 } 51 int main() 52 { 53 byte result = testSwitchInASwitch(10, 22); 54 assert_eq(result, 0); 55 return 0; 56 } 57 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4772 writable_globals_start $4156 writable_globals_end $415E --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 81: break vs. switch in a loop 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char testSwitchInAFor(byte b) 25 { 26 byte iter = 0; 27 for (;;) 28 { 29 switch (b) 30 { 31 case 22: 32 //printf("case 22\n"); 33 break; 34 default: 35 return 1; 36 } 37 //printf("iter=%u\n", iter); 38 if (++iter > 1) 39 return 2; 40 break; 41 } 42 return 0; // supposed to come here 43 } 44 char testSwitchInAWhile(byte b) 45 { 46 byte iter = 0; 47 while (1) 48 { 49 switch (b) 50 { 51 case 22: 52 //printf("case 22\n"); 53 break; 54 default: 55 return 1; 56 } 57 //printf("iter=%u\n", iter); 58 if (++iter > 1) 59 return 2; 60 break; 61 } 62 return 0; // supposed to come here 63 } 64 char testSwitchInADoWhile(byte b) 65 { 66 byte iter = 0; 67 do 68 { 69 switch (b) 70 { 71 case 22: 72 //printf("case 22\n"); 73 break; 74 default: 75 return 1; 76 } 77 //printf("iter=%u\n", iter); 78 if (++iter > 1) 79 return 2; 80 break; 81 } while (1); 82 return 0; // supposed to come here 83 } 84 char testForInSwitch(byte b) 85 { 86 byte iter = 0; 87 switch (b) 88 { 89 case 22: 90 for (;;) 91 { 92 break; 93 } 94 if (++iter > 1) 95 return 2; 96 break; 97 default: 98 return 1; 99 } 100 return 0; // supposed to come here 101 } 102 int main() 103 { 104 byte result = testSwitchInAFor(22); 105 assert_eq(result, 0); 106 result = testSwitchInAWhile(22); 107 assert_eq(result, 0); 108 result = testSwitchInADoWhile(22); 109 assert_eq(result, 0); 110 result = testForInSwitch(22); 111 assert_eq(result, 0); 112 return 0; 113 } 114 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4876 writable_globals_start $425A writable_globals_end $4262 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 82: Function pointer in an array or a struct 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int f() { return 99; } 25 struct S { 26 void *funcPtr; 27 }; 28 int main() 29 { 30 void *funcPtrs[] = { f }; 31 assert_eq(funcPtrs[0](), 99); 32 assert_eq((*funcPtrs[0])(), 99); 33 34 struct S s = { f }; 35 assert_eq(s.funcPtr, f); 36 assert_eq(s.funcPtr(), 99); 37 assert_eq((*s.funcPtr)(), 99); 38 return 0; 39 } 40 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4830 writable_globals_start $4214 writable_globals_end $421C --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 83: +=, -= 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 char a = 42; 27 char b = 11; 28 a += b; 29 assert_eq(a, 53); 30 a -= b; 31 assert_eq(a, 42); 32 33 int c = 4000; 34 int d = 123; 35 c += d; 36 assert_eq(c, 4123); 37 c -= d; 38 assert_eq(c, 4000); 39 40 return 0; 41 } 42 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $47D0 writable_globals_start $41B4 writable_globals_end $41BC --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 84: +=, -=, *= operators with right-hand side of pointer type 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 typedef unsigned char *FuncPtr; 25 int main() 26 { 27 FuncPtr origISR = 0xFEF7; 28 29 FuncPtr finalAddr = 0x0212; 30 finalAddr += 0xFEFA; 31 assert_eq(finalAddr, 0x010C); 32 33 finalAddr = 0x0212; 34 finalAddr += origISR + 3; 35 assert_eq(finalAddr, 0x010C); 36 37 finalAddr = 0x0212; 38 finalAddr += origISR; 39 assert_eq(finalAddr, 0x0109); 40 41 finalAddr = 0x0212; 42 origISR = 0x0101; 43 finalAddr -= origISR; 44 assert_eq(finalAddr, 0x0111); 45 46 finalAddr = 0x0212; 47 origISR = 3; 48 finalAddr *= origISR; 49 assert_eq(finalAddr, 0x0636); 50 51 finalAddr = 0x0212; 52 origISR = 2; 53 finalAddr /= origISR; 54 assert_eq(finalAddr, 0x0109); 55 56 return 0; 57 } 58 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=DIV16 --need=MUL16 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_DIV16_ -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_DIV16_ -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $489A writable_globals_start $423B writable_globals_end $4243 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 85: #pragma const_data 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 // Read-only globals go after 5C00. 25 // Writable globals go after 4F00. 26 char f() { return 99; } 27 int writable = 42; 28 char runTimeInit = f(); 29 #pragma const_data start 30 unsigned char readonly[] = { 9, 8, 7, 6 }; 31 #pragma const_data end 32 int main() 33 { 34 assert_eq(writable, 42); 35 assert_eq(runTimeInit, 99); 36 assert_eq(readonly[2], 7); 37 38 assert(&writable >= (void *) 0x4F00 && &writable < 0x5000); 39 assert(&runTimeInit >= (void *) 0x4F00 && &runTimeInit < 0x5000); 40 assert(readonly > (void *) 0x5C00); 41 42 return 0; 43 } 44 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror --org=5C00 --data=4F00 ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $5c00 (23552) Data address: $4f00 (20224) Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=5c00 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=5c00 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $5C00 program_end $6426 writable_globals_start $4F00 writable_globals_end $4F0B --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 86: #pragma exec_once 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 #pragma exec_once 25 int main() 26 { 27 char *_program_end; 28 char *_INITGL; 29 asm { 30 leax program_end,pcr 31 stx _program_end 32 leax INITGL,pcr 33 stx _INITGL 34 } 35 assert(_program_end == _INITGL); 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $46FE writable_globals_start $40E4 writable_globals_end $40EC --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 87: Absence of #pragma exec_once 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 char *_program_end; 27 char *_INITGL; 28 asm { 29 leax program_end,pcr 30 stx _program_end 31 leax INITGL,pcr 32 stx _INITGL 33 } 34 assert(_program_end > _INITGL); 35 return 0; 36 } 37 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4700 writable_globals_start $40E4 writable_globals_end $40EC --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 88: --check-null option to detect null pointer accesses 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void nullPointerHandler(void *addressOfFailedCheck) 25 { 26 assert(addressOfFailedCheck >= 0x4000 && addressOfFailedCheck < 0x5000); 27 exit(1); 28 } 29 int main() 30 { 31 set_null_ptr_handler(nullPointerHandler); 32 char *p = 0; 33 char c = *p; // must trigger call to nullPointerHandler() 34 return 0; 35 } 36 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror --check-null ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --check-null --stack-space=1024 --need=_exit --need=_printf --need=_set_null_ptr_handler --need=_strtoul --need=check_null_ptr_x --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -D_CMOC_CHECK_NULL_POINTERS_=1 -Dstack_space=1024 -D_CMOC_NEED_exit_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_set_null_ptr_handler_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_check_null_ptr_x_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -D_CMOC_CHECK_NULL_POINTERS_=1 -Dstack_space=1024 -D_CMOC_NEED_exit_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_set_null_ptr_handler_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_check_null_ptr_x_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $474F writable_globals_start $410D writable_globals_end $4117 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 89: --check-stack option to detect stack overflows 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void stackOverflowHandler(void *addressOfFailedCheck, void *stackRegister) 25 { 26 //printf("[%p, %p]\n", addressOfFailedCheck, stackRegister); 27 assert(addressOfFailedCheck >= 0x4000 && addressOfFailedCheck < 0x5000); 28 assert(stackRegister >= 0xFA00 && stackRegister < 0xFE00); // 1k of stack space 29 exit(1); 30 } 31 void recurse() { recurse(); } 32 int main() 33 { 34 set_stack_overflow_handler(stackOverflowHandler); 35 recurse(); 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror --check-stack ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --check-stack --stack-space=1024 --need=_exit --need=_printf --need=_set_stack_overflow_handler --need=_strtoul --need=check_stack_overflow --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -D_CMOC_CHECK_STACK_OVERFLOW_=1 -Dstack_space=1024 -D_CMOC_NEED_exit_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_set_stack_overflow_handler_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_check_stack_overflow_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -D_CMOC_CHECK_STACK_OVERFLOW_=1 -Dstack_space=1024 -D_CMOC_NEED_exit_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_set_stack_overflow_handler_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_check_stack_overflow_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $478F writable_globals_start $412D writable_globals_end $4137 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 90: Typical C copying idiom 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 char *str = "foobar"; 27 char *src; 28 for (src = str; *src++; ) 29 ; 30 assert_eq(src - str, 7); 31 32 for (src = str; *src; src++) 33 ; 34 assert_eq(src - str, 6); 35 36 char a[7]; 37 memset(a, 'X', sizeof(a)); 38 char *dest; 39 for (src = str, dest = a; *src; ) 40 *dest++ = *src++; 41 assert_eq(*dest, 'X'); 42 *dest = '\0'; 43 printf("%s\n", a); 44 assert_eq(strcmp(a, "foobar"), 0); 45 assert_eq(src - str, 6); 46 assert_eq(*src, 0); 47 return 0; 48 } 49 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_memset --need=_printf --need=_strcmp --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memset_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memset_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4904 writable_globals_start $42A5 writable_globals_end $42AD --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: foobar --- Actual output: foobar -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 91: Adding a constant to an array address received as an argument 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char *f(char *p) 25 { 26 //printf("p=%p\n", p); 27 return p; 28 } 29 void g(char a[12]) 30 { 31 char *p0 = f(a); 32 char *p6 = f(a + 6); // bug was in BinaryOpExpr::emitAddImmediateToVariable() 33 assert_eq(p6 - p0, 6); 34 } 35 int main() 36 { 37 char v[12]; 38 g(v); 39 return 0; 40 } 41 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $477B writable_globals_start $415F writable_globals_end $4167 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 92: sprintf(), putstr(), putchar() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 char buf[10]; 27 assert_eq(sizeof(buf), 10); 28 memset(buf, '#', sizeof(buf)); 29 putstr(buf, sizeof(buf)); 30 putchar('\n'); 31 32 sprintf(buf, "foo%s%u", "bar", 777); 33 printf("L1: [%s]\n", buf); 34 assert_eq(buf[sizeof(buf) - 1], 0); 35 assert_eq(strcmp(buf, "foobar777"), 0); 36 37 printf("L2\n"); 38 sprintf(buf, ""); 39 printf("L3: [%u]\n", strlen(buf)); 40 assert_eq(strlen(buf), 0); 41 42 // Field width > 255. 43 char temp[260]; 44 memset(temp, 'X', 260); 45 sprintf(temp, "%258s", ' '); // overwrite 0..258; don't overwrite last 'X' 46 assert(temp[258] == 0); 47 assert(temp[259] == 'X'); 48 for (int i = 0; i < 258; ++i) 49 assert(temp[i] == ' '); 50 return 0; 51 } 52 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_memset --need=_printf --need=_putchar --need=_putstr --need=_sprintf --need=_strcmp --need=_strlen --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memset_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_putchar_ -D_CMOC_NEED_putstr_ -D_CMOC_NEED_sprintf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strlen_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memset_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_putchar_ -D_CMOC_NEED_putstr_ -D_CMOC_NEED_sprintf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strlen_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4A01 writable_globals_start $4353 writable_globals_end $4361 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: ########## L1: [foobar777] L2 L3: [0] --- Actual output: ########## L1: [foobar777] L2 L3: [0] -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 93: sprintf() without printf() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 char buf[2]; 27 sprintf(buf, "$"); 28 // We do not use an assert macro because it calls printf(). 29 if (buf[0] != '$') 30 putstr("ERR""OR: sprintf() did not write '$' in buf[].\n", 45); // error keyword cut to avoid false negative in smoke test 31 return 0; 32 } 33 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_putstr --need=_sprintf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_putstr_ -D_CMOC_NEED_sprintf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_putstr_ -D_CMOC_NEED_sprintf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4764 writable_globals_start $40FB writable_globals_end $4109 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 94: Size of pointed type in the case of multi-dim array 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 // Size of pointed type, in the case of multi-dim array, 25 // is the product of array dimensions, ignoring the first dimension. 26 27 int a[5][7][13]; // pointed type here is int[7][13], i.e., a[i] designates 91 ints 28 unsigned char e[3][7]; 29 int main() 30 { 31 int *p0 = (int *) a[0]; 32 int *p1 = (int *) a[1]; 33 assert_eq(p1 - p0, 7 * 13); 34 35 char c = 34; 36 unsigned char *src = (unsigned char *) e + (c - ' ') * 7; 37 assert_eq(src - (unsigned char *) e, 14); 38 39 return 0; 40 } 41 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4B61 writable_globals_start $41A2 writable_globals_end $454D --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 95: Optimization of assignments of zero 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 unsigned char uc; 27 uc = 0; 28 assert_eq(uc, 0); 29 uc = 42; 30 assert_eq(uc, 42); 31 unsigned u; 32 u = 0; 33 assert_eq(u, 0); 34 u = 4242; 35 assert_eq(u, 4242); 36 37 // Signed cases. 38 char b; 39 b = 0; 40 assert_eq(b, 0); 41 b = -42; 42 assert_eq(b, -42); 43 int i; 44 i = 0; 45 assert_eq(i, 0); 46 i = -42; 47 assert_eq(i, -42); 48 i = -4242; 49 assert_eq(i, -4242); 50 return 0; 51 } 52 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4872 writable_globals_start $4256 writable_globals_end $425E --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 96: Multiplication 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char fc(char c) { return c; } 25 int fi(int n) { return n; } 26 int main() 27 { 28 { 29 byte b0 = 3; 30 byte b1 = 5; 31 byte b2 = b0 * b1; 32 assert_eq(b2, 15); 33 b2 = b0 * 6; 34 assert_eq(b2, 18); 35 b2 = 4 * b1; 36 assert_eq(b2, 20); 37 38 // Check that other binary operators accept an int constant and still return a byte. 39 b2 = b0 / 6; 40 b2 = b0 % 6; 41 b2 = b0 + 6; 42 b2 = b0 - 6; 43 b2 = 6 / b0; 44 b2 = 6 % b0; 45 b2 = 6 + b0; 46 b2 = 6 - b0; 47 48 b0 = 10; 49 assert_eq(b0 * 160, 64); // mul done in 8 bits 50 assert_eq((word) b0 * 160, 1600); 51 assert_eq(160 * (word) b0, 1600); 52 53 byte b = 3; 54 assert_eq(b * 2, 6); 55 assert_eq(b * 4, 12); 56 assert_eq(b * 8, 24); 57 assert_eq(b * 16, 48); 58 assert_eq(b * 32, 96); 59 assert_eq(b * 64, 192); 60 assert_eq(2 * b, 6); 61 assert_eq(4 * b, 12); 62 assert_eq(8 * b, 24); 63 assert_eq(16 * b, 48); 64 assert_eq(32 * b, 96); 65 assert_eq(64 * b, 192); 66 67 // Special cases: 68 assert_eq(b * 0, 0); 69 assert_eq(0 * b, 0); 70 assert_eq(b * 1, 3); 71 assert_eq(1 * b, 3); 72 73 // Mult. by shifting: 74 assert_eq(b * 2, 6); 75 assert_eq(2 * b, 6); 76 assert_eq(b * 4, 12); 77 assert_eq(4 * b, 12); 78 assert_eq(b * 32, 96); 79 assert_eq(32 * b, 96); 80 assert_eq(b * 64, 192); 81 assert_eq(64 * b, 192); 82 } 83 84 { 85 word w0 = 250; 86 word w1 = 251; 87 word w2 = w0 * w1; 88 assert_eq(w2, 62750); 89 w2 = w0 * 252; 90 assert_eq(w2, 63000); 91 w2 = 249 * w1; 92 assert_eq(w2, 62499); 93 } 94 95 // Signed cases. 96 { 97 char c0 = -3; 98 char c1 = 5; 99 char c2 = c0 * c1; 100 assert_eq(c2, -15); 101 c2 = c0 * 6; 102 assert_eq(c2, -18); 103 c2 = -4 * c1; 104 assert_eq(c2, -20); 105 c2 = c1 * -8; 106 assert_eq(c2, -40); 107 c2 = -4 * 5; 108 assert_eq(c2, -20); 109 c2 = 5 * -8; 110 assert_eq(c2, -40); 111 c2 = -6 * -8; 112 assert_eq(c2, +48); 113 c2 = -4 * c0; 114 assert_eq(c2, 12); 115 116 assert_eq(fc(-3) * fc(5), -15); 117 assert_eq(fc(-3) * fc(6), -18); 118 assert_eq(fc(-4) * fc(5), -20); 119 assert_eq(fc(-4) * fc(-3), 12); 120 121 c2 = -50 / c1; 122 assert_eq(c2, -10); 123 } 124 125 { 126 int i0 = -300; 127 int i1 = 100; 128 int i2 = i0 * i1; 129 assert_eq(i2, -30000); 130 i2 = i0 * 99; 131 assert_eq(i2, -29700); 132 i2 = i0 * -99; 133 assert_eq(i2, 29700); 134 i2 = -299 * i1; 135 assert_eq(i2, -29900); 136 137 assert_eq(fi(-300) * fi(100), -30000); 138 assert_eq(fi(-300) * fi(99), -29700); 139 assert_eq(fi(-299) * fi(100), -29900); 140 assert_eq(fi(-299) * fi(-100), 29900); 141 } 142 143 return 0; 144 } 145 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=DIV8 --need=MUL16 --need=SDIV8 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_DIV8_ -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_SDIV8_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_DIV8_ -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_SDIV8_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $5464 writable_globals_start $4DE9 writable_globals_end $4DF1 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 97: Assembly-only function 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int global0 = 42; 25 int asm f(int m, int n) // no stack frame because of 'asm' modifier 26 { 27 // U not pushed, so 1st arg is at 2,s 28 asm { 29 ldd 2,s // load m 30 addd 4,s // add n, leave sum in D 31 } 32 asm { // more than one asm{} statement allowed, although not useful 33 nop 34 } 35 } 36 unsigned char asm g(int m, int n) 37 { 38 asm { 39 ldd 2,s 40 addd 4,s 41 inca // function returns byte, so trashing A must not matter 42 } 43 } 44 int asm h() 45 { 46 asm { 47 ldd global0 48 } 49 } 50 int asm q() 51 { 52 asm("ldd", global0); 53 } 54 int main() 55 { 56 assert_eq(f(3000, 1299), 4299); 57 assert_eq(g(3000, 1299), 4299 % 256); 58 assert_eq(4299 % 256, 203); 59 assert_eq(h(), 42); 60 assert_eq(q(), 42); 61 return 0; 62 } 63 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4852 writable_globals_start $422D writable_globals_end $4237 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 98: Subtraction without spaces surrounding the minus sign 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 int k = 5; 27 int n = k-4; // k-4 must be seen as tokens 'k', '-', '4', not, 'k' and '-4' 28 assert_eq(n, 1); 29 assert_eq(99-88, 11); 30 return 0; 31 } 32 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4772 writable_globals_start $4156 writable_globals_end $415E --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 99: Draw lines of pixels in two diagonals across a 640x192 screen 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 word xx; 27 xx = 328; 28 assert_eq(xx * 100 / 333, (word) 98); 29 for(xx=0; xx<640; xx++) { 30 word y0 = ((xx+1)*100)/333 - 1; 31 word y1 = 191 - (((xx+1)*100)/333 - 1); 32 //printf("%5u %5u %5u\n", xx, y0, y1); 33 assert_range((int) y0, -1, 191); 34 assert_range(y1, 0, 192); 35 } 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=DIV16 --need=MUL16 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_DIV16_ -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_DIV16_ -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $48DC writable_globals_start $427D writable_globals_end $4285 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 100: No sign extension when passing argument of form unsigned-byte-expr & 8-bit-const 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 // Correctly determine signedness of unsigned-byte-expression & 8-bit-constant, 25 // so that no sign extension is done on argument passing. 26 27 unsigned f(unsigned char b) 28 { 29 unsigned receivedWord; 30 asm { 31 ldd 4,u 32 std receivedWord 33 } 34 //printf("receivedWord=$%04X\n", receivedWord); 35 assert_eq(receivedWord & 0xFF00, 0); // no sign extension expected when passing argument to f() 36 assert_eq(b, 0x80); 37 return b; 38 } 39 int main() 40 { 41 unsigned w0 = 0x8A; 42 unsigned w1 = f((byte) (w0 & 0x80)); // 2-byte bitwise AND, result cast to byte 43 assert_eq(w1, 0x80); 44 45 // Operands of & are byte and word, but 0x80 fits in a byte, so is seen as byte. 46 // Sign of result of & is unsigned because operands have different signedness 47 // (unsigned on left, signed int on right). 48 unsigned w2 = f(((byte) w0) & 0x80); 49 assert_eq(w2, 0x80); 50 return 0; 51 } 52 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $47D6 writable_globals_start $41BA writable_globals_end $41C2 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 101: Product of small positive integers can give negative 16-bit result 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 assert_eq(320 * 200, 0xFA00); 27 assert_eq(320 * 200, -1536); // mul is signed because operands are both signed 28 assert_eq(320 * 200 / 2, 0xFD00); // div is signed, so 0xFA00 gets ASR 29 assert_eq(320 * 200 / 2, -768); 30 assert_eq((unsigned) 320 * 200, 64000); 31 assert_eq((unsigned) 320 * 200 / 2, 32000); 32 return 0; 33 } 34 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $481D writable_globals_start $4201 writable_globals_end $4209 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 102: Redefining a function provided by stdlib.inc 1 2 // cmoc.h not included, so we need to declare this. 3 // Note unsigned instead of size_t, just for giggles. 4 void putstr(char *s, unsigned n); 5 void putchar(int i) 6 { 7 char a[] = { '[', (char) i, ']', '\n' }; 8 putstr(a, 4); 9 } 10 void rand(int a, int b) // different arguments than in stdlib.inc 11 { 12 putstr("rand(int, int)\n", 15); 13 } 14 int main() 15 { 16 putchar('C'); 17 rand(8, 9); 18 return 0; 19 } 20 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_putstr --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_putstr_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_putstr_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $40BA writable_globals_start $4079 writable_globals_end $4081 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: [C] rand(int, int) --- Actual output: [C] rand(int, int) -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 103: Signed multiplication, division, modulo 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int multiply(int dividend, int divisor) 25 { 26 return dividend * divisor; 27 } 28 int divide(int dividend, int divisor) 29 { 30 return dividend / divisor; 31 } 32 int modulo(int dividend, int divisor) 33 { 34 return dividend % divisor; 35 } 36 char multiplyc(char dividend, char divisor) 37 { 38 return dividend * divisor; 39 } 40 char dividec(char dividend, char divisor) 41 { 42 return dividend / divisor; 43 } 44 char moduloc(char dividend, char divisor) 45 { 46 return dividend % divisor; 47 } 48 byte multiplyuc(byte dividend, byte divisor) 49 { 50 return dividend * divisor; 51 } 52 byte divideuc(byte dividend, byte divisor) 53 { 54 return dividend / divisor; 55 } 56 byte modulouc(byte dividend, byte divisor) 57 { 58 return dividend % divisor; 59 } 60 int main() 61 { 62 // Test operations with non-constant operands, via function. 63 assert_eq(multiply(+1000, +25), +25000); 64 assert_eq(multiply(-1000, +25), -25000); 65 assert_eq(multiply(+1000, -25), -25000); 66 assert_eq(multiply(-1000, -25), +25000); 67 68 assert_eq(divide(+1000, +25), +40); 69 assert_eq(divide(-1000, +25), -40); 70 assert_eq(divide(+1000, -25), -40); 71 assert_eq(divide(-1000, -25), +40); 72 73 assert_eq(modulo(+1000, +33), +10); // 1000 - 10 == 990, which is divisible by 33 74 assert_eq(modulo(-1000, +33), -10); // -1000 - (-10) == -990, which is divisible by 33 75 assert_eq(modulo(+1000, -33), +10); // negative divisor gives same modulo as positive one 76 assert_eq(modulo(-1000, -33), -10); 77 78 // Test operations with constant operands (may get optimized). 79 assert_eq(+1000 * +25, +25000); 80 assert_eq(-1000 * +25, -25000); 81 assert_eq(+1000 * -25, -25000); 82 assert_eq(-1000 * -25, +25000); 83 84 assert_eq(+1000 / +25, +40); 85 assert_eq(-1000 / +25, -40); 86 assert_eq(+1000 / -25, -40); 87 assert_eq(-1000 / -25, +40); 88 89 assert_eq(+1000 % +33, +10); 90 assert_eq(-1000 % +33, -10); 91 assert_eq(+1000 % -33, +10); 92 assert_eq(-1000 % -33, -10); 93 94 // Test signed char operations with non-constant operands, via function. 95 assert_eq(multiplyc(+10, +5), +50); 96 assert_eq(multiplyc(-10, +5), -50); 97 assert_eq(multiplyc(+10, -5), -50); 98 assert_eq(multiplyc(-10, -5), +50); 99 100 assert_eq(dividec(+100, +25), +4); 101 assert_eq(dividec(-100, +25), -4); 102 assert_eq(dividec(+100, -25), -4); 103 assert_eq(dividec(-100, -25), +4); 104 105 assert_eq(moduloc(+100, +30), +10); // 100 - 10 == 90, which is divisible by 30 106 assert_eq(moduloc(-100, +30), -10); // -100 - (-10) == -90, which is divisible by 30 107 assert_eq(moduloc(+100, -30), +10); // negative divisor gives same modulo as positive one 108 assert_eq(moduloc(-100, -30), -10); 109 110 // Test unsigned char operations with non-constant operands, via function. 111 assert_eq(multiplyuc(+10, +25), +250); 112 assert_eq(divideuc(+200, +25), +8); 113 assert_eq(modulouc(+200, +30), +20); // 200 - 20 == 180, which is divisible by 30 114 115 // Special cases of byte division. 116 unsigned char uc = 250; 117 assert_eq(uc / (byte) 1, 250); 118 assert_eq(uc / (byte) 2, 125); 119 assert_eq(uc / (byte) 4, 62); 120 assert_eq(uc / (byte) 64, 3); 121 assert_eq(uc / (byte) 128, 1); 122 char sc = 125; 123 assert_eq(sc / (char) 1, 125); 124 assert_eq(sc / (char) 2, 62); 125 assert_eq(sc / (char) 4, 31); 126 assert_eq(sc / (char) 32, 3); 127 sc = -125; 128 assert_eq(sc / (char) 1, -125); 129 assert_eq(sc / (char) 2, -62); 130 assert_eq(sc / (char) 4, -31); 131 assert_eq(sc / (char) 32, -3); 132 133 // Special cases of byte modulo. 134 assert_eq(uc % (byte) 1, 0); 135 assert_eq(uc % (byte) 2, 0); 136 assert_eq(uc % (byte) 4, 2); 137 assert_eq(uc % (byte) 64, 58); 138 139 // Division of unsigned byte by 7 (LBSR DIV8BY7). 140 byte dividend = 0; 141 for (byte quotient = 0; quotient <= 36; ++quotient) 142 { 143 for (byte remainder = 0; remainder <= 6; ++remainder, ++dividend) 144 { 145 //printf("%3u / 7 = %2u remainder %u\n", dividend, quotient, remainder); 146 byte computedQuotient = dividend / 7; 147 assert_eq(computedQuotient, quotient); 148 byte computedRemainer = dividend % 7; 149 assert_eq(computedRemainer, remainder); 150 if (dividend == 255) 151 break; 152 } 153 if (dividend == 255) 154 break; 155 } 156 157 // Division of unsigned word by 10 (LBSR DIV16BY10). 158 { 159 word quotient = 0; 160 byte counter = 0; 161 for (word dividend = 0; ; ++dividend) 162 { 163 word computedQuotient = dividend / 10; 164 //printf("%5u / 10 = %5u\n", dividend, computedQuotient); 165 assert_eq(computedQuotient, quotient); 166 if (++counter == 10) 167 { 168 ++quotient; 169 counter = 0; 170 } 171 if (dividend == 0xFFFF) 172 break; 173 } 174 } 175 176 // Division of unsigned byte by 10. 177 { 178 byte quotient = 0; 179 byte counter = 0; 180 for (byte dividend = 0; ; ++dividend) 181 { 182 byte computedQuotient = dividend / 10; 183 //printf("%5u / 10 = %5u\n", dividend, computedQuotient); 184 assert_eq(computedQuotient, quotient); 185 if (++counter == 10) 186 { 187 ++quotient; 188 counter = 0; 189 } 190 if (dividend == 0xFF) 191 break; 192 } 193 } 194 195 // Division of signed word by 10 (does not use DIV16BY10). 196 { 197 signed quotient = -3276; 198 byte counter = 1; 199 for (signed dividend = -32768; ; ++dividend) 200 { 201 signed computedQuotient = dividend / 10; 202 //printf("%5d / 10 = %5d\n", dividend, computedQuotient); 203 assert_eq(computedQuotient, quotient); 204 if (++counter == 10) 205 { 206 if (dividend == 0) 207 counter = 1; 208 else 209 { 210 ++quotient; 211 counter = 0; 212 } 213 } 214 if (dividend == 32767) 215 break; 216 } 217 } 218 219 // Division of signed byte by 10. 220 { 221 char quotient = -12; 222 byte counter = 1; 223 for (char dividend = -128; ; ++dividend) 224 { 225 char computedQuotient = dividend / 10; 226 //printf("%5d / 10 = %5d\n", dividend, computedQuotient); 227 assert_eq(computedQuotient, quotient); 228 if (++counter == 10) 229 { 230 if (dividend == 0) 231 counter = 1; 232 else 233 { 234 ++quotient; 235 counter = 0; 236 } 237 } 238 if (dividend == 127) 239 break; 240 } 241 } 242 243 // Check optimization of non-var-non-const left side by 8. 244 byte b = 42; 245 byte n = (b + 7) / 8; 246 assert_eq(n, 6); 247 248 // Check optimization of word by power of 2. 249 word w = 42; 250 assert_eq(w / 2, 21); 251 w = 12800; 252 assert_eq(w / 128, 100); 253 assert_eq(w / 256, 50); // special case: TFR A,B; CLRA 254 w = 0xAAAA; 255 assert_eq(w / 4096, 0x000A); 256 257 // Mixed byte/word case. 258 b = 2; 259 assert_eq(w / b, 0x5555); 260 b = 200; 261 w = 8; 262 assert_eq(b / w, 25); 263 264 // Modulo. 265 byte card = 135; 266 byte v = (card - 1) % 13; 267 assert_eq(v, 4); 268 269 // Signed division by power of 2. 270 int i = 400; 271 int j = i / 2; 272 assert_eq(j, 200); 273 274 // Signed byte, 0..127. 275 char c; 276 for (c = 0; c >= 0; ++c) 277 { 278 char computed = c / 2; 279 char expected = c >> 1; 280 assert_eq(computed, expected); 281 } 282 // Signed byte, -1..-128. 283 for (c = -1; c != -128; --c) 284 { 285 char computed = c / 2; 286 char expected = -((-c) >> 1); 287 //printf("%d %d %d\n", c, computed, expected); 288 assert_eq(computed, expected); 289 } 290 assert_eq(c / 2, -64); 291 292 unsigned u0 = 0, u1 = 5; 293 assert_eq(u0 / u1, 0); 294 assert_eq(u1 / u0, 0xFFFF); // division by zero does not hang 295 296 return 0; 297 } 298 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=DIV16 --need=DIV16BY10 --need=DIV8 --need=DIV8BY7 --need=MUL16 --need=SDIV16 --need=SDIV8 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_DIV16_ -D_CMOC_NEED_DIV16BY10_ -D_CMOC_NEED_DIV8_ -D_CMOC_NEED_DIV8BY7_ -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_SDIV16_ -D_CMOC_NEED_SDIV8_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_DIV16_ -D_CMOC_NEED_DIV16BY10_ -D_CMOC_NEED_DIV8_ -D_CMOC_NEED_DIV8BY7_ -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_SDIV16_ -D_CMOC_NEED_SDIV8_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $5E04 writable_globals_start $56BD writable_globals_end $56C5 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 104: Check that a call to readline() compiles 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void f() { readline(); } 25 int main() 26 { 27 return 0; 28 } 29 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror --emit-uncalled ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_readline --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_readline_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_readline_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $42FD writable_globals_start $409D writable_globals_end $40A3 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 105: Check that calls to readword() and delay() compile 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void f() 25 { 26 readword(); 27 delay(42); 28 } 29 int main() 30 { 31 return 0; 32 } 33 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror --emit-uncalled ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_delay --need=_readword --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_delay_ -D_CMOC_NEED_readword_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_delay_ -D_CMOC_NEED_readword_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $434F writable_globals_start $40A7 writable_globals_end $40AD --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 106: Uninitialized globals are grouped together 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int a[1]; 25 int b[1] = { 42 }; // we don't want 'b' to be emitted between 'a' and 'c' 26 int c[1]; 27 int *min(int *x, int *y) { return x < y ? x : y; } 28 int *max(int *x, int *y) { return x > y ? x : y; } 29 int main() 30 { 31 // Don't assume that 'a' is emitted before 'c'. 32 int *firstUninit = min(a, c); 33 int *secondUninit = max(a, c); 34 35 // If the two uninitialized variables are grouped together, 36 // that 'b' cannot be between them, i.e., 'b' had to be before 37 // the first or after the second. 38 assert(b < firstUninit || secondUninit < b); 39 return 0; 40 } 41 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4762 writable_globals_start $4140 writable_globals_end $414E --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 107: pushLoadDiscardAdd optimization (see ASMText.cpp) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte t() { return 1; } 25 byte f() { return 0; } 26 int main() 27 { 28 byte isUsersTurn = t(); 29 byte row = 30 + (isUsersTurn ? +24 : -24); // optimization on this line 30 assert_eq(row, 54); 31 isUsersTurn = f(); 32 row = 30 + (isUsersTurn ? +24 : -24); // optimization on this line 33 assert_eq(row, 6); 34 return 0; 35 } 36 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4783 writable_globals_start $4167 writable_globals_end $416F --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 108: pushLoadDLoadX optimization 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte f() { return 42; } 25 int main() 26 { 27 byte b = f(); 28 word w = (word) b * 32; // cast to ensure 16-bit multiplication 29 assert_eq(w, 1344); 30 word k = 10; 31 w = (word) b * k; 32 assert_eq(w, 420); 33 return 0; 34 } 35 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=MUL16 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4799 writable_globals_start $4165 writable_globals_end $416D --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 109: Statement in compound statement with constant cast to void generates no code 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte t() { return 1; } 25 int main() 26 { 27 byte *bb, *aa; 28 asm { 29 before: 30 } 31 ((void) (1 + 2)); 32 asm { 33 after: 34 leax before,pcr 35 stx bb 36 leax after,pcr 37 stx aa 38 } 39 assert_eq(bb, aa); 40 return 0; 41 } 42 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4743 writable_globals_start $4127 writable_globals_end $412F --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 110: Optimization of complex boolean expressions 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte p1; 25 byte b1; 26 byte pend; 27 byte bend; 28 int f() 29 { 30 if (((p1 <= b1) && (pend >= b1)) 31 || ((b1 <= p1) && (bend >= p1))) 32 return 11; 33 return -11; 34 } 35 int main() 36 { 37 p1 = 10; b1 = 15; pend = 12; bend = 99; 38 assert_eq(f(), -11); // pend >= b1 fails 39 p1 = 17; 40 assert_eq(f(), 11); 41 bend = 3; 42 assert_eq(f(), -11); // p1 <= b1 fails then bend >= p1 fails 43 44 byte r = 0; 45 //printf("%u %u %u %u\n", p1, b1, bend, pend); 46 if (! (p1 < b1 || bend < pend)) 47 r = -1; 48 else 49 r = 1; 50 assert_eq(r, 1); 51 52 return 0; 53 } 54 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $483E writable_globals_start $421E writable_globals_end $422A --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 111: Union 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S 25 { 26 char c; 27 int i; 28 }; 29 union Word 30 { 31 unsigned w; 32 unsigned char b[2]; 33 struct S s; 34 }; 35 int main() 36 { 37 union Word u; 38 u.w = 0x1234; 39 assert_eq(u.b[0], 0x12); 40 assert_eq(u.b[1], 0x34); 41 u.b[0] = 0x56; 42 assert_eq(u.w, 0x5634); 43 u.b[1] = 0x78; 44 assert_eq(u.w, 0x5678); 45 memcpy(u.b, "AB", 2); 46 assert_eq(u.w, 0x4142); 47 assert_eq(&u, &u.w); 48 assert_eq(&u, &u.b); 49 assert_eq(&u, &u.s); 50 assert_eq(&u, &u.s.c); 51 assert_eq((unsigned) &u + 1, &u.s.i); 52 53 assert_eq(u.w >> 8, (unsigned) u.s.c); 54 55 u.s.c = 0xAB; 56 u.s.i = 0xCDEF; 57 assert_eq(u.b[0], 0xAB); 58 assert_eq(u.b[1], 0xCD); 59 assert_eq(u.b[2], 0xEF); // reading beyond end of b[] 60 assert_eq(u.w, 0xABCD); 61 62 assert_eq(sizeof(union Word), 3); 63 assert_eq(sizeof(u), 3); 64 assert_eq(sizeof(u.w), 2); 65 assert_eq(sizeof(u.b), 2); 66 assert_eq(sizeof(u.s.c), 1); 67 assert_eq(sizeof(u.s.i), 2); 68 69 return 0; 70 } 71 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_memcpy --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4B1D writable_globals_start $4501 writable_globals_end $4509 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 112: Offset of members of a union 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 union U0 25 { 26 char a, b; 27 }; 28 struct S0 { int s[8]; }; 29 union U1 30 { 31 char m0; 32 int m1; 33 void *m2; 34 struct S0 m3; 35 union U0 m4; 36 }; 37 struct S1 38 { 39 int w; 40 union U0 u0; 41 union U1 u1; 42 }; 43 int main() 44 { 45 assert_eq(offsetof(union U0, a), 0); 46 assert_eq(offsetof(union U0, b), 0); 47 assert_eq(offsetof(union U1, m0), 0); 48 assert_eq(offsetof(union U1, m1), 0); 49 assert_eq(offsetof(union U1, m2), 0); 50 assert_eq(offsetof(union U1, m3), 0); 51 assert_eq(offsetof(union U1, m4), 0); 52 assert_eq(offsetof(union U1, m4.a), 0); 53 assert_eq(offsetof(union U1, m4.b), 0); 54 assert_eq(offsetof(struct S1, w), 0); 55 assert_eq(offsetof(struct S1, u0), 2); 56 assert_eq(offsetof(struct S1, u0.a), 2); 57 assert_eq(offsetof(struct S1, u0.b), 2); 58 assert_eq(offsetof(struct S1, u1), 3); 59 assert_eq(offsetof(struct S1, u1.m3), 3); 60 assert_eq(offsetof(struct S1, u1.m4), 3); 61 return 0; 62 } 63 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4A09 writable_globals_start $43ED writable_globals_end $43F5 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 113: Branch optimizations vs. inline assembly 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char f(int v) 25 { 26 char ret; 27 if (v) 28 { 29 asm 30 { 31 ldb #1 32 stb ret 33 } 34 } 35 else // optimizer must not remove branch over else clause 36 { 37 asm 38 { 39 clr ret 40 } 41 } 42 return ret; 43 } 44 int main() 45 { 46 assert_eq(f(0), 0); 47 assert_eq(f(5), 1); 48 return 0; 49 } 50 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $47A2 writable_globals_start $4186 writable_globals_end $418E --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 114: Avoid optimizing an add just because FFxx constant is a negative that fits a byte 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 byte slot = 12; 27 word p; 28 p = 0xffb0 + slot; // 16-bit operation because 0xffb0 is unsigned, there does not fit a byte 29 assert_eq(p, 0xffbc); 30 p = 65456 + slot; // same in decimal 31 assert_eq(p, 0xffbc); 32 p = -80 + slot; // 8-bit operation: -80 is represented internally as 0xffb0, but is signed, so fits a byte 33 assert_eq(p, -68); 34 return 0; 35 } 36 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $479E writable_globals_start $4182 writable_globals_end $418A --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 115: Character array in const_data section initialized with a string literal 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char writableText[] = "foo"; 25 26 #pragma const_data start 27 char constText[] = "bar"; 28 #pragma const_data end 29 30 char *p = "baz"; // would not be allowed in const_data: init of 'p' would have to be at run-time 31 char *q = "bar"; // uses same literal as constText[] 32 char *r = "foo"; // uses same literal as writableText[] 33 int main() 34 { 35 printf("writableText=[%s]\n", writableText); 36 printf("constText=[%s]\n", constText); 37 assert_eq(writableText[0], 'f'); 38 assert_eq(constText[2], 'r'); 39 assert_eq(p[2], 'z'); 40 assert_eq(strcmp(constText, "bar"), 0); 41 42 writableText[1] = 'X'; // modifies writableText's copy of "foo"; does not affect r 43 printf("writableText=[%s]\n", writableText); 44 assert_eq(strcmp(writableText, "fXo"), 0); 45 assert_eq(strcmp(r, "foo"), 0); 46 assert_eq(strcmp(q, "bar"), 0); 47 48 q[2] = 'Y'; // does not affect constText[], which has its own copy of "bar" 49 assert_eq(strcmp(q, "baY"), 0); 50 51 // Test constText is not affected. 52 // Do not test with string literal "bar", which is currently corrupted. 53 // (Modifying a string literal is generally a bad practice.) 54 // 55 //assert_eq(strcmp(constText, "bar"), 0); 56 printf("constText=[%s]\n", constText); 57 assert_eq(constText[0], 'b'); 58 assert_eq(constText[1], 'a'); 59 assert_eq(constText[2], 'r'); 60 assert_eq(constText[3], '\0'); 61 62 q[2] = 'r'; // restore literal "bar" (modifying a string literal is generally a bad practice) 63 printf("bar"); // test the restored literal 64 putchar('\n'); 65 66 char *local = "quux"; 67 printf("local=[%s]\n", local); 68 local = 0x1234; 69 assert_eq(local, 0x1234); 70 71 return 0; 72 } 73 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror --org=5000 --data=4C00 ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $5000 (20480) Data address: $4c00 (19456) Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=5000 --target=USIM --stack-space=1024 --need=_printf --need=_putchar --need=_strcmp --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_putchar_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_putchar_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=5000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $5000 program_end $5B41 writable_globals_start $4C00 writable_globals_end $4C12 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: writableText=[foo] constText=[bar] writableText=[fXo] constText=[bar] bar local=[quux] --- Actual output: writableText=[foo] constText=[bar] writableText=[fXo] constText=[bar] bar local=[quux] -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 116: Promotion to int for comparisons 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int s1(char *e) 25 { 26 if (*e == (char) 0xFF) // *e compared with -1 27 return 1; 28 return 0; 29 } 30 int s2(char *e) 31 { 32 if (*e == 0xFFFF) // *e sign-extended, then compared to 0xFFFF 33 return 1; 34 return 0; 35 } 36 int u0(unsigned char *e) 37 { 38 if (*e == 0xFF) 39 return 1; 40 return 0; 41 } 42 int u1(unsigned char *e) 43 { 44 if (*e == (char) 0xFF) // *e is zero-extended, then compared with -1, i.e., 0xFFFF 45 return 1; 46 return 0; 47 } 48 int u2(unsigned char *e) 49 { 50 if (*e == 0xFFFF) // *e zero-extended, then compared to 0xFFFF 51 return 1; 52 return 0; 53 } 54 int main() 55 { 56 char c = (char) 0xFF; 57 assert_eq(s1(&c), 1); 58 assert_eq(s2(&c), 1); 59 unsigned char uc = 0xFF; 60 assert_eq(u0(&uc), 1); 61 assert_eq(u1(&uc), 0); 62 assert_eq(u2(&uc), 0); 63 return 0; 64 } 65 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $48DC writable_globals_start $42C0 writable_globals_end $42C8 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 117: const_data initializer with non-trivial constant expression 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 #pragma const_data start 25 int a0[] = { 0, -1, 2 + 2, -(10 / 2) * 3 }; 26 char n = -42; 27 #pragma const_data end 28 int main() 29 { 30 assert_eq(a0[0], 0); 31 assert_eq(a0[1], -1); 32 assert_eq(a0[2], 4); 33 assert_eq(a0[3], -15); 34 assert_eq(sizeof(a0), 8); 35 assert_eq(n, -42); 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4834 writable_globals_start $4212 writable_globals_end $421A --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 118: Calling a C function from inline assembly 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char cFuncCalled = 0; 25 void cFunc() 26 { 27 ++cFuncCalled; 28 } 29 byte counter = 0; 30 asm byte condBranchToStart() 31 { 32 asm { 33 inc counter 34 ldb counter 35 cmpb #5 36 blo condBranchToStart 37 } 38 } 39 int main() 40 { 41 asm { 42 jsr cFunc 43 lbsr cFunc 44 leax cFunc 45 jsr ,x 46 47 // The next references to cFunc() don't call it, but we still test 48 // that the instructions are emitted correctly. 49 brn cFunc 50 lbrn cFunc 51 bra avoid 52 bra cFunc 53 lbra cFunc 54 avoid: 55 } 56 assert_eq(cFuncCalled, 3); 57 assert_eq(condBranchToStart(), 5); 58 return 0; 59 } 60 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $47A0 writable_globals_start $417A writable_globals_end $4184 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 119: Emitting code for functon only called by LBSR in asm-only function 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char v = 99; 25 void g() { v = 42; } 26 void f() { g(); } 27 void asm asmOnly() 28 { 29 asm { 30 lbsr f 31 } 32 } 33 int main() 34 { 35 asmOnly(); 36 assert_eq(v, 42); 37 return 0; 38 } 39 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4751 writable_globals_start $412E writable_globals_end $4137 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 120: Emitting code for functon only called by LBSR in non-asm-only function 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char v = 99; 25 void g() { v = 42; } 26 void f() { g(); } 27 void notAsmOnly() 28 { 29 asm { 30 lbsr f 31 } 32 } 33 int main() 34 { 35 notAsmOnly(); 36 assert_eq(v, 42); 37 return 0; 38 } 39 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4751 writable_globals_start $412E writable_globals_end $4137 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 121: ASMText::optimize16BitStackOps1 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct FileDesc 25 { 26 byte drive; 27 byte firstGran; // 0..67 28 word numBytesLastSector; // 0..256 29 word length[2]; // 32-bit word giving length of file 30 byte curGran; // 0..67, 255 means at EOF 31 byte curSec; // 1..9 (relative to current granule) 32 word curGranLen; // 0..2304 33 word offset[2]; // 32-bit reading/writing offset 34 word secOffset; // 0..256: index into curSector[] (256 means beyond sector) 35 byte curSector[256]; 36 word curSectorAvailBytes; // number valid bytes in curSector[] (0..256) 37 }; 38 39 int main() 40 { 41 word offsetInLastGranule = 0x5678; 42 struct FileDesc object; 43 struct FileDesc *fd = &object; 44 fd->secOffset = offsetInLastGranule & 0xFF; // statement targeted by ASMText::optimize16BitStackOps1() 45 assert_eq(fd->secOffset, 0x78); 46 return 0; 47 } 48 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $475D writable_globals_start $4141 writable_globals_end $4149 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 122: ASMText::optimizeIndexedX 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct Parser 25 { 26 char *input; 27 }; 28 char buf[16]; 29 byte iter = 0; 30 void f(struct Parser *parser) 31 { 32 byte index = 0; // index in buf[] 33 for (;;++iter) // accumulate non-NUL chars in buf[] 34 { 35 byte curChar = *parser->input; 36 if (curChar) 37 { 38 if (index < sizeof(buf) - 1) // if room in buf[] 39 buf[index++] = curChar; // accept char 40 ++parser->input; // pass that char 41 } 42 else 43 break; // NUL seen: end of accumulation 44 if (iter == 10) // in case of infinite loop (3 iterations expected) 45 break; 46 } 47 assert_eq(index, 3); 48 assert_eq(buf[0], 'A'); 49 assert_eq(buf[1], 'B'); 50 assert_eq(buf[2], 'C'); 51 } 52 int main() 53 { 54 struct Parser parser; 55 char *text = "ABC"; 56 parser.input = text; 57 f(&parser); 58 assert_eq(parser.input, text + 3); 59 return 0; 60 } 61 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4884 writable_globals_start $4253 writable_globals_end $426C --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 123: Function pointer in member initializer of global struct instance 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S { void *fp; }; 25 byte n = 40; 26 int func() { return ++n; } 27 struct S g = { func }; 28 int main() 29 { 30 assert_eq((*g.fp)(), 41); 31 assert_eq(g.fp(), 42); 32 33 struct S loc = { func }; 34 assert_eq((*loc.fp)(), 43); 35 assert_eq(loc.fp(), 44); 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $481F writable_globals_start $41F2 writable_globals_end $41FD --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 124: Adding to a function pointer 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 byte n = 50; 25 void f() 26 { 27 n += 10; 28 } 29 void call0(void *fp) 30 { 31 void *fixed = fp - 42; 32 (*fixed)(); 33 } 34 void call1(void *fp) 35 { 36 void *fixed = fp + 42; 37 (*fixed)(); 38 } 39 int main() 40 { 41 call0(f + 42); 42 assert_eq(n, 60); 43 call0(42 + f); 44 assert_eq(n, 70); 45 call1(f - 42); 46 assert_eq(n, 80); 47 call1(-42 + f); 48 assert_eq(n, 90); 49 return 0; 50 } 51 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4835 writable_globals_start $4212 writable_globals_end $421B --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 125: Ternary expression vs. optimizer vs. LEAX 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 asm { ldx #0 } // robustness check 27 word a = 4; 28 word b = 5; 29 word c = 1; 30 (c ? a : b) = 6; 31 assert_eq(a, 6); 32 return 0; 33 } 34 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $475C writable_globals_start $4140 writable_globals_end $4148 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 126: optimizeStackOperations1 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct HeapBlock { 25 struct HeapBlock *prev; 26 unsigned size; 27 unsigned char b; 28 char free; 29 }; 30 31 int f() { return 1; } // must be 1 so that if() succeeds in free() 32 33 void free(struct HeapBlock *ptr) { 34 struct HeapBlock *block = ptr; 35 struct HeapBlock *next = ptr; 36 char nextIsFree = (char) f(); 37 if (f()) { 38 block->size += nextIsFree ? next->size : (unsigned) 0; // problematic line 39 } else { // else clause needed 40 f(); 41 } 42 } 43 44 void free8(struct HeapBlock *ptr) { 45 struct HeapBlock *block = ptr; 46 struct HeapBlock *next = ptr; 47 char nextIsFree = (char) f(); 48 if (f()) { 49 block->b += nextIsFree ? next->b : (unsigned char) 0; 50 } else { // else clause needed 51 f(); 52 } 53 } 54 55 int main() { 56 struct HeapBlock hb = { 0, 1000, 77, 42 }; 57 assert_eq(hb.size, 1000); 58 free(&hb); // expected to add 'size' field to itself 59 assert_eq(hb.size, 2000); 60 61 assert_eq(hb.b, 77); 62 free8(&hb); 63 assert_eq(hb.b, 154); 64 65 return 0; 66 } 67 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $484F writable_globals_start $4233 writable_globals_end $423B --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 127: Local asm block labels 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 asm unsigned f1() 25 { 26 asm { 27 @foo 28 leax @foo,pcr 29 tfr x,d 30 } 31 } 32 asm unsigned f2() 33 { 34 asm { 35 @foo 36 leax @foo,pcr 37 tfr x,d 38 } 39 } 40 asm void *f3() 41 { 42 asm { 43 @f1 44 leax @f1,pcr 45 tfr x,d 46 } 47 } 48 asm void f4() 49 { 50 asm { 51 leax f1 // take address of function f1() 52 tfr x,d 53 } 54 } 55 int main() 56 { 57 //printf("%p %p %p\n", f1(), f2(), f3()); 58 assert_ne(f1(), f2()); 59 assert_ne(f3(), f1); // label f1 in f3() must not refer to function f1() 60 61 f4(); 62 void *retval; 63 asm { std :retval } 64 assert_eq(retval, f1); 65 66 return 0; 67 } 68 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4818 writable_globals_start $41FC writable_globals_end $4204 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 128: optimize16BitStackOps1 and optimize8BitStackOps 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void f() {} 25 char c; 26 char *left = &c; 27 char store99() 28 { 29 int x, seg = 0; 30 31 f(); // this separates basic blocks 32 x = 99; // value to be put in left[0] 33 f(); // this separates basic blocks 34 35 // Problematic statement: the right side of this assignment 36 // loaded variable x with LDB using the address of the high byte 37 // instead of the low byte. 38 // 39 left[seg] = (char) x; 40 41 return 0; 42 } 43 int main() 44 { 45 store99(); 46 //printf("%d\n", left[0]); 47 assert_eq(left[0], 99); 48 return 0; 49 } 50 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4779 writable_globals_start $4152 writable_globals_end $415D --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 129: 2016-06-08 optimization fixes 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct Vect { 25 int x; 26 }; 27 28 struct BigVect { 29 struct Vect x; 30 }; 31 32 void test1() { 33 int vals[10]; 34 int ii; 35 unsigned char bvals[10]; 36 for(ii=0; ii> shift_amount) & (byte)(0xff << shift_amount)); 64 65 assert_eq(val, 0x81); 66 } 67 68 int main() { 69 test1(); 70 test2(); 71 test3(); 72 return 0; 73 } 74 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --need=shiftLeft --need=shiftRightSigned --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_shiftLeft_ -D_CMOC_NEED_shiftRightSigned_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_shiftLeft_ -D_CMOC_NEED_shiftRightSigned_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $490E writable_globals_start $42A2 writable_globals_end $42AA --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 130: No-argument function declared with (void) 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int noArg(void) 25 { 26 return 42; 27 } 28 int main(void) 29 { 30 assert_eq(noArg(), 42); 31 return 0; 32 } 33 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $473C writable_globals_start $4120 writable_globals_end $4128 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 131: Function pointer syntax 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char counter; 25 void unnamedArgFunc(int) 26 { 27 ++counter; 28 } 29 void unnamedPointerArgFunc(int *) 30 { 31 ++counter; 32 } 33 void unnamedArrayArgFunc(int []) 34 { 35 ++counter; 36 } 37 void unnamed2DArrayArgFunc(int [][5]) 38 { 39 ++counter; 40 } 41 void unnamedFuncPtrArgFunc(int (*)()) 42 { 43 ++counter; 44 } 45 struct S { int n; }; 46 void unnamedStructArgFunc(struct S *) 47 { 48 ++counter; 49 } 50 void unnamedStructArrayArgFunc(struct S []) 51 { 52 ++counter; 53 } 54 int mix2(int, int b) // an unnamed arg does not prevent using a named arg 55 { 56 return b + 1; 57 } 58 int fi0() 59 { 60 return 42; 61 } 62 int fi2(int i, char c) 63 { 64 return i + c; 65 } 66 int invokeCallbackNoArgRetInt(int (*cb)()) 67 { 68 return cb(); 69 } 70 int invokeCallback2ArgsRetInt(int (*cb)(int, char c)) 71 { 72 return (*cb)(1000, -5); 73 } 74 char fc0() 75 { 76 char c = '$'; 77 asm { 78 lda #$EE // put garbage in A 79 } 80 return c; // only LDB emitted since function returns byte 81 } 82 int main() 83 { 84 int (*funcPtr0)() = fi0; 85 assert_eq((*funcPtr0)(), 42); 86 assert_eq(funcPtr0(), 42); 87 assert_eq(invokeCallbackNoArgRetInt(fi0), 42); 88 89 assert_eq((fi0)(), 42); // ordinary call, but with name in () 90 91 int (*funcPtr2)(int i, char) = fi2; 92 assert_eq((*funcPtr2)(10, 2), 12); 93 assert_eq(funcPtr2(30, 7), 37); 94 assert_eq(invokeCallback2ArgsRetInt(fi2), 995); 95 96 int (*funcPtr0c)() = fc0; 97 assert_eq((char) funcPtr0c(), '$'); // cast necessary under CMOC, which assumes return type is int 98 99 // Call the unnamed argument functions: 100 counter = 0; 101 int i = 42; 102 unnamedArgFunc(i); 103 unnamedPointerArgFunc(&i); 104 int a[] = { 9, 8, 7 }; 105 unnamedArrayArgFunc(a); 106 int aa[][5] = { { 5, 4, 3, 2, 1 }, { 55, 44, 33, 22, 11 } }; 107 unnamed2DArrayArgFunc(aa); 108 unnamedFuncPtrArgFunc(fi0); 109 struct S s = { 42 }; 110 unnamedStructArgFunc(&s); 111 struct S as[2] = { { 43 }, { 44 } }; 112 unnamedStructArrayArgFunc(as); 113 114 assert_eq(counter, 7); 115 116 assert_eq(mix2(4, 7), 8); 117 118 return 0; 119 } 120 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4B1C writable_globals_start $44FF writable_globals_end $4508 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 132: Anonymous struct 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct 25 { 26 int n; 27 } a; 28 struct S 29 { 30 struct 31 { 32 char c; 33 } cc; 34 struct 35 { 36 int w[2]; 37 } ww; 38 int m; 39 }; 40 int main() 41 { 42 a.n = 42; 43 assert_eq(a.n, 42); 44 45 struct S s; 46 s.cc.c = '#'; 47 s.ww.w[0] = 2000; 48 s.ww.w[1] = 3000; 49 s.m = 1000; 50 assert_eq(s.cc.c, '#'); 51 assert_eq(s.m, 1000); 52 assert_eq(s.ww.w[0] + s.ww.w[1], 5000); 53 54 return 0; 55 } 56 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4810 writable_globals_start $41F2 writable_globals_end $41FC --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 133: Register keyword ignored 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 register int n = 1844; 27 assert_eq(n, 1844); 28 return 0; 29 } 30 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $473D writable_globals_start $4121 writable_globals_end $4129 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 134: goto statement 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 char c = 0; 27 here: 28 ++c; 29 if (c < 5) 30 goto here; 31 assert_eq(c, 5); 32 33 goto there; 34 assert(0); 35 there: 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4767 writable_globals_start $414B writable_globals_end $4153 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 135: Extern declaration gets ignored 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 extern int g; 25 int g; // not seen as a redeclaration 26 27 typedef unsigned T1; 28 typedef T1 T2; 29 extern T2 t; 30 T2 t; 31 32 typedef unsigned Addr[2]; 33 extern Addr addr; 34 Addr addr = { 0xAAAA, 0xBBBB }; 35 36 int main() 37 { 38 g = 1234; 39 assert_eq(g, 1234); 40 41 t = 5678; 42 assert_eq(t, 5678); 43 44 addr[0] = 0x1111; 45 addr[1] = 0x2222; 46 assert_eq(addr[0] + addr[1], 0x3333); 47 48 return 0; 49 } 50 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $47C8 writable_globals_start $41A4 writable_globals_end $41B4 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 136: Static keyword ignored, declaration still processed 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 static int g; 25 26 int main() 27 { 28 g = 1234; 29 assert_eq(g, 1234); 30 return 0; 31 } 32 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $473F writable_globals_start $4121 writable_globals_end $412B --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 137: Reference to undefined struct 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S *f(); 25 struct T *h(); // T is never defined 26 27 struct S 28 { 29 int n; 30 }; 31 32 struct S g; 33 34 struct S *f() 35 { 36 return &g; 37 } 38 39 struct T *h() 40 { 41 return 0; 42 } 43 44 int main() 45 { 46 struct S *p = f(); 47 assert_eq(p, &g); 48 assert_eq(h(), 0); 49 return 0; 50 } 51 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $477A writable_globals_start $415C writable_globals_end $4166 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 138: Struct assignment 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S 25 { 26 int i; 27 char c; 28 }; 29 int main() 30 { 31 struct S s0 = { 1000, 10 }; 32 struct S s1 = s0; 33 assert_eq(s1.i, s0.i); 34 assert_eq(s1.c, s0.c); 35 36 struct S s2; 37 s2.i = s2.c = 88; 38 s2 = s0; 39 assert_eq(s2.i, s0.i); 40 assert_eq(s2.c, s0.c); 41 42 s1.i = s1.c = 77; 43 s2.i = s2.c = 99; 44 s2 = s1 = s0; 45 assert_eq(s1.i, s0.i); 46 assert_eq(s1.c, s0.c); 47 assert_eq(s2.i, s0.i); 48 assert_eq(s2.c, s0.c); 49 50 return 0; 51 } 52 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=copyMem --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_copyMem_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_copyMem_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $48E0 writable_globals_start $42AD writable_globals_end $42B5 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 139: Function prototypes 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int f(int, int); 25 int h(int someName); 26 int main() 27 { 28 int c = f(1, 2); 29 assert_eq(c, 3); 30 31 assert_eq(h(41), 42); 32 33 return 0; 34 } 35 int f(int a, int b) 36 { 37 return a + b; 38 } 39 int h(int someOtherName) 40 { 41 return someOtherName + 1; 42 } 43 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $47A2 writable_globals_start $4186 writable_globals_end $418E --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 140: enum 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 enum 25 { 26 FOO, 27 BAR, 28 BAZ, // trailing comma allowed 29 }; 30 31 enum 32 { 33 QUUX, 34 WALDO = 1000, 35 WALDO_PLUS_ONE 36 } gVar0 = QUUX; 37 // Here, the 3 enumerated names must be registered via TypeManager::declareEnumerationList() 38 // before the "gVar0 = QUUX" parts gets parsed, so that "= QUUX" can be recognized as a 39 // reference to the enumerated name, rather than a reference to an undefined variable. 40 41 enum A { a0, a1, aBig = 2222 }; 42 enum A aVar0 = a1; // declare variable of previously defined enum 43 44 int f0(enum A aParam) { return aParam; } // function parameter of type enum (previously defined) 45 46 enum A f1() { return a1; } 47 48 enum B { b0 = 41, b1 } bVar0 = b0, bVar1; // named enum with enumerated names, used to declare variables 49 extern enum A aExtVar0 = a1; // ignored line 50 extern enum { EXT0 = 55 } aExtVar0 = EXT0; // ignored line 51 52 static enum A aStaticVar0 = aBig; // 'static' keyword ignored, variable declared 53 static enum { STATIC0 = 66 } aStaticVar1 = STATIC0; // 'static' keyword ignored, variable declared 54 55 typedef enum { T0 = 77, T1 } TEnum; 56 TEnum t0 = T1; 57 typedef enum A EnumA; 58 59 enum Indices 60 { 61 ZERO, ONE, TWO, THREE, SEVEN = 7, EIGHT = 8, FIFTEEN = 15 62 }; 63 enum Bits 64 { 65 B0 = 1 << ZERO, 66 B1 = 1 << ONE, 67 B2 = 1 << TWO, 68 B3 = 1 << THREE, 69 B7 = 1 << SEVEN, 70 B8 = 1 << EIGHT, 71 B15 = 1 << FIFTEEN 72 }; 73 74 enum 75 { 76 THIRTY_TWO = 1 << 5, 77 INDEPENDENT = 5, 78 DEPENDENT_ON_PREVIOUS = 1 << INDEPENDENT, 79 }; 80 81 #define STR "foobar" 82 enum 83 { 84 SIZE_OF_STR = sizeof(STR), 85 SIZE_OF_STR_PLUS_ONE = sizeof(STR) + 1 86 }; 87 88 int main() 89 { 90 assert_eq(FOO, 0); 91 assert_eq(BAR, 1); 92 assert_eq(BAZ, 2); 93 assert_eq(sizeof(FOO), 2); 94 95 assert_eq(aVar0, a1); 96 aVar0 = aBig; 97 assert_eq(aVar0, aBig); 98 assert_eq(f0(aBig), aBig); 99 assert_eq(f1(), a1); 100 101 assert_eq(sizeof(gVar0), 2); 102 assert_eq(gVar0, QUUX); 103 gVar0 = WALDO; 104 assert_eq(gVar0, WALDO); 105 gVar0 = WALDO_PLUS_ONE; 106 assert_eq(gVar0, 1001); 107 108 assert_eq(bVar0, b0); 109 bVar0 = b1; 110 assert_eq(bVar0, b1); 111 112 assert_eq(aStaticVar0, aBig); 113 assert_eq(aStaticVar1, STATIC0); 114 115 assert_eq(t0, 78); 116 assert_eq(sizeof(t0), 2); 117 assert_eq(sizeof(TEnum), 2); 118 119 EnumA a = aBig; 120 assert_eq(a, aBig); 121 assert_eq(sizeof(EnumA), 2); 122 assert_eq(sizeof(enum A), 2); 123 124 assert_eq(B0, 0x0001); 125 assert_eq(B1, 0x0002); 126 assert_eq(B2, 0x0004); 127 assert_eq(B3, 0x0008); 128 assert_eq(B7, 0x0080); 129 assert_eq(B8, 0x0100); 130 assert_eq(B15, 0x8000); 131 132 assert_eq(THIRTY_TWO, 32); 133 assert_eq(DEPENDENT_ON_PREVIOUS, 32); 134 135 // Local variable name can hide enum name. 136 char *THIRTY_TWO = 0x1234; 137 assert_eq(THIRTY_TWO, 0x1234); 138 139 // Hide an enumerated name with a local variable. 140 assert_eq(FIFTEEN, 15); 141 int FIFTEEN = 999; 142 assert_eq(FIFTEEN, 999); 143 144 assert_eq(SIZE_OF_STR, 7); 145 assert_eq(SIZE_OF_STR_PLUS_ONE, 8); 146 147 unsigned k0 = 22222, k1 = 22222; 148 asm { 149 ldd #WALDO 150 std k0 151 ldd #WALDO+234 152 std k1 153 } 154 assert_eq(k0, 1000); 155 assert_eq(k1, 1234); 156 157 return 0; 158 } 159 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4E79 writable_globals_start $4829 writable_globals_end $483F --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 141: Multiplication of members of a struct 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 typedef struct { 25 int x, y; 26 } test_t; 27 int test1(test_t* v) 28 { 29 return v->x * v->y; // removeUselessLdx() would mishandle this 30 } 31 int main() 32 { 33 test_t a0 = { 240, 250 }; 34 assert_eq(test1(&a0), 60000); 35 return 0; 36 } 37 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=MUL16 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4789 writable_globals_start $4155 writable_globals_end $415D --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 142: atoui() and atoi() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 assert_eq(atoui("0"), 0); 27 assert_eq(atoui("1"), 1); 28 assert_eq(atoui("543"), 543); 29 assert_eq(atoui("65535"), 65535); 30 assert_eq(atoi("0"), 0); 31 assert_eq(atoi("1"), 1); 32 assert_eq(atoi("543"), 543); 33 assert_eq(atoi("32767"), 32767); 34 assert_eq(atoi("-1"), -1); 35 assert_eq(atoi("-543"), -543); 36 assert_eq(atoi("-32768"), -32768); 37 return 0; 38 } 39 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_atoi --need=_atoui --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_atoi_ -D_CMOC_NEED_atoui_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_atoi_ -D_CMOC_NEED_atoui_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4A4B writable_globals_start $440F writable_globals_end $4417 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 143: Assignment operators on a struct field 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 typedef struct { 25 int _dummy, value; 26 } WordValue; 27 28 typedef struct { 29 int _dummy; 30 char value; 31 } ByteValue; 32 33 void test1div_ww(WordValue* t) 34 { 35 t->value /= 2; 36 } 37 38 void test1div_bw(ByteValue* t) 39 { 40 t->value /= 2; 41 } 42 43 void test1mod_ww(WordValue* t) 44 { 45 t->value %= 100; 46 } 47 48 void test1mod_bw(ByteValue* t) 49 { 50 t->value %= 14; 51 } 52 53 void test1sl_ww(WordValue* t) 54 { 55 t->value <<= 1; 56 } 57 58 void test1sl_bw(ByteValue* t) 59 { 60 t->value <<= 1; 61 } 62 63 unsigned one() { return 1; } 64 void test1sl_nonConstRightSide(WordValue* t) 65 { 66 t->value <<= one(); 67 } 68 69 void test1sr_ww(WordValue* t) 70 { 71 t->value >>= 1; 72 } 73 74 void test1sr_bw(ByteValue* t) 75 { 76 t->value >>= 1; 77 } 78 79 void test2div(WordValue* t) 80 { 81 t->value = t->value / 2; 82 } 83 84 void test2mod(WordValue* t) 85 { 86 t->value = t->value % 100; 87 } 88 89 void test2sl(WordValue* t) 90 { 91 t->value = t->value << 1; 92 } 93 94 void test2sr(WordValue* t) 95 { 96 t->value = t->value >> 1; 97 } 98 99 void testWithWordAsLeftSide() 100 { 101 WordValue s0 = { 1111, 0 }; 102 103 s0.value = 4444; 104 test1div_ww(&s0); 105 assert_eq(s0.value, 2222); 106 107 s0.value = 12345; 108 test1mod_ww(&s0); 109 assert_eq(s0.value, 45); 110 111 s0.value = 333; 112 test1sl_ww(&s0); 113 assert_eq(s0.value, 666); 114 115 assert_eq(&(s0.value /= 2), &s0.value); 116 assert_eq(&(s0.value %= 2), &s0.value); 117 assert_eq(&(s0.value >>= 1), &s0.value); 118 assert_eq(&(s0.value <<= 1), &s0.value); 119 120 s0.value = 333; 121 test1sl_nonConstRightSide(&s0); 122 assert_eq(s0.value, 666); 123 124 s0.value = 444; 125 test1sr_ww(&s0); 126 assert_eq(s0.value, 222); 127 128 s0.value <<= 10; 129 assert_eq(s0.value, 0x7800); 130 s0.value >>= 10; 131 assert_eq(s0.value, 30); 132 133 s0.value = 4444; 134 test2div(&s0); 135 assert_eq(s0.value, 2222); 136 137 s0.value = 12345; 138 test2mod(&s0); 139 assert_eq(s0.value, 45); 140 141 s0.value = 333; 142 test2sl(&s0); 143 assert_eq(s0.value, 666); 144 145 s0.value = 444; 146 test2sr(&s0); 147 assert_eq(s0.value, 222); 148 } 149 150 void testWithByteAsLeftSide() 151 { 152 ByteValue s0 = { 1111, 0 }; 153 154 s0.value = 44; 155 test1div_bw(&s0); 156 assert_eq(s0.value, 22); 157 158 s0.value = 123; 159 test1mod_bw(&s0); 160 assert_eq(s0.value, 11); 161 162 s0.value = 33; 163 test1sl_bw(&s0); 164 assert_eq(s0.value, 66); 165 166 assert_eq(&(s0.value /= 2), &s0.value); 167 assert_eq(&(s0.value %= 2), &s0.value); 168 assert_eq(&(s0.value >>= 1), &s0.value); 169 assert_eq(&(s0.value <<= 1), &s0.value); 170 171 s0.value = 44; 172 test1sr_bw(&s0); 173 assert_eq(s0.value, 22); 174 175 s0.value <<= 10; 176 assert_eq(s0.value, 0); 177 s0.value = 255; 178 s0.value >>= 10; 179 assert_eq(s0.value, -1); // because 'value' is signed 180 } 181 182 int main() 183 { 184 testWithWordAsLeftSide(); 185 testWithByteAsLeftSide(); 186 return 0; 187 } 188 189 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=SDIV16 --need=_printf --need=_strtoul --need=memcpy --need=shiftLeft --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_SDIV16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_shiftLeft_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_SDIV16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_shiftLeft_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4F16 writable_globals_start $4868 writable_globals_end $4870 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 144: Optimizaton on boolean negation and disjunction 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int test(void *a, void *b) 25 { 26 return !a || !b; 27 } 28 int main() 29 { 30 assert(test((void *) 0, (void *) 0)); 31 assert(test((void *) 1, (void *) 0)); 32 assert(test((void *) 0, (void *) 1)); 33 assert(!test((void *) 1, (void *) 1)); 34 return 0; 35 } 36 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $477F writable_globals_start $4163 writable_globals_end $416B --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 145: Avoid over-optimizing when byte constant cast to word 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 int main() 25 { 26 byte b = 99; 27 word w = b * (word) 100; 28 assert_eq(w, 9900); 29 30 char sb = 99; 31 int sw = sb * (int) 100; 32 assert_eq(sw, 9900); 33 34 sb = -98; 35 sw = sb * (int) -100; 36 assert_eq(sw, 9800); 37 38 sb = -97; 39 sw = (int) -100 * sb; 40 assert_eq(sw, 9700); 41 42 sb = -97; 43 sw = (int) 100 * sb; 44 assert_eq(sw, -9700); 45 46 return 0; 47 } 48 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=MUL16 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_MUL16_ -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $483F writable_globals_start $420B writable_globals_end $4213 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 146: removeUselessLdx optimization 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S 25 { 26 word a, b, c, d; 27 byte buffer[512]; 28 }; 29 void g(void *dst, void *src, word n) 30 { 31 //printf("%p %p %u\n", dst, src, n); 32 assert_eq(dst + 256, src); 33 } 34 void f(struct S *data) 35 { 36 g(data->buffer, data->buffer + 256, data->d); 37 } 38 int main() 39 { 40 struct S data; 41 data.d = 157; 42 f(&data); 43 return 0; 44 } 45 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4788 writable_globals_start $416C writable_globals_end $4174 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 147: __FUNCTION__ and __func__ 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char *g0 = __FUNCTION__, *g1 = __func__; 25 void someFunction() 26 { 27 printf("%s\n", __FUNCTION__); 28 assert_eq(strcmp(__FUNCTION__, "someFunction"), 0); 29 assert_eq(strcmp(__func__, "someFunction"), 0); 30 } 31 int main() 32 { 33 printf("%s\n", __FUNCTION__); 34 assert_eq(strcmp(__FUNCTION__, "main"), 0); 35 assert_eq(strcmp(__func__, "main"), 0); 36 someFunction(); 37 printf("%s\n", g0); 38 printf("%s\n", g1); 39 assert_eq(strcmp(g0, ""), 0); 40 assert_eq(strcmp(g1, ""), 0); 41 return 0; 42 } 43 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strcmp --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strcmp_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4999 writable_globals_start $4344 writable_globals_end $4350 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: main someFunction --- Actual output: main someFunction -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 148: Optimizer bug in ASMText::removeAndOrMulAddSub() 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 unsigned char a[] = { 11, 22, 33 }; 25 int main() 26 { 27 unsigned char *ptr = a; 28 int start = 52 + (ptr[1] << 8) + ptr[2]; // note: shift is done on 8 bits, not 16 as in Standard C 29 assert_eq(start, 85); 30 start = 52 + ((unsigned) ptr[1] << 8) + ptr[2]; // force shift on 16 bits 31 assert_eq(start, 5717); 32 return 0; 33 } 34 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $478C writable_globals_start $416D writable_globals_end $4178 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 149: Enumerators defined with other enumerators 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 enum 25 { 26 STACK_SPACE = 2 * 1024, 27 GRAPHICS_SPACE = 4 * 1536, 28 RAM_END = 0xFE00, 29 STACK_START = RAM_END - STACK_SPACE, 30 GRAPHICS_START = STACK_START - GRAPHICS_SPACE, 31 }; 32 int main() 33 { 34 assert_eq(STACK_SPACE, 0x800); 35 assert_eq(GRAPHICS_SPACE, 6144); 36 assert_eq(RAM_END, 0xFE00); 37 assert_eq(STACK_START, 0xF600); 38 assert_eq(GRAPHICS_START, 0xDE00); 39 return 0; 40 } 41 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $47EF writable_globals_start $41D3 writable_globals_end $41DB --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 150: Process a declarator that represents a function pointer 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 typedef char (*FuncPtrType)(); // TypeManager::addTypeDef() used to be buggy (<= 0.1.38) on this line; 25 // It would define FuncPtrType as char instead of void *. 26 struct S0 27 { 28 FuncPtrType funcPtr; 29 }; 30 char f(char n) { return n + 1; } // of type FuncPtrType 31 FuncPtrType global = f; 32 int main() 33 { 34 struct S0 s0 = { f }; 35 assert_eq((*s0.funcPtr)('A'), 'B'); 36 assert_eq((*global)('C'), 'D'); 37 FuncPtrType local = f; 38 assert_eq((*local)('E'), 'F'); 39 return 0; 40 } 41 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4815 writable_globals_start $41EF writable_globals_end $41F9 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 151: Typedef of struct registers struct S as a type 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 typedef struct S { int m; } S; 25 struct A { int m; }; 26 typedef struct A AA; 27 28 struct S g_s = { 42 }; 29 struct A g_a = { 1844 }; 30 AA g_aa = { 123 }; 31 32 int main() 33 { 34 struct S s = { 42 }; 35 assert_eq(s.m, 42); 36 struct A a = { 1844 }; 37 assert_eq(a.m, 1844); 38 AA aa = { 123 }; 39 assert_eq(aa.m, 123); 40 41 assert_eq(g_s.m, 42); 42 assert_eq(g_a.m, 1844); 43 assert_eq(g_aa.m, 123); 44 return 0; 45 } 46 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4843 writable_globals_start $420C writable_globals_end $421A --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 152: Empty struct 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct Empty {}; 25 int main() 26 { 27 struct Empty e; 28 assert_ne(&e, 0); // check that 'e' really is on the stack 29 return 0; 30 } 31 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $473B writable_globals_start $411F writable_globals_end $4127 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 153: Passing a struct or union by value to a function 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 #include 25 26 struct S { int a, b; char c; }; // size of struct is odd number 27 int f(struct S s, int x, char y) 28 { 29 int sum = s.a + s.b + s.c + x + y; 30 ++s.b; // only modifies the local copy of the struct 31 --s.c; // ditto 32 return sum; 33 } 34 35 union U { unsigned n; unsigned char c; }; 36 unsigned getInt(union U u) { return u.n; } 37 unsigned getChar(union U u) { return u.c; } 38 39 void v(struct S first, ...) 40 { 41 assert_eq(first.c, '#'); 42 va_list ap; 43 va_start(ap, first); 44 struct S s = va_arg(ap, struct S); 45 assert_eq(s.c, '$'); 46 char charAfter = va_arg(ap, char); 47 assert_eq(charAfter, '%'); 48 unsigned unsignedAfter = va_arg(ap, unsigned); 49 assert_eq(unsignedAfter, 0xFEDC); 50 va_end(ap); 51 } 52 53 struct OneByte { unsigned char b; }; 54 55 void receiveOneByteStruct(struct OneByte ob) 56 { 57 assert_eq(ob.b, 0xAA); 58 } 59 void receiveOneByteStructViaEllipsis(int n, ...) 60 { 61 assert_eq(n, 4242); 62 va_list ap; 63 va_start(ap, n); 64 struct OneByte ob = va_arg(ap, struct OneByte); 65 assert_eq(ob.b, 0xAA); 66 char c = va_arg(ap, char); 67 assert_eq(c, '*'); 68 va_end(ap); 69 } 70 void receiveOneByteStructViaEllipsis2(struct OneByte first, ...) 71 { 72 assert_eq(first.b, '-'); 73 va_list ap; 74 va_start(ap, first); 75 struct OneByte ob = va_arg(ap, struct OneByte); 76 assert_eq(ob.b, 0xAA); 77 char c = va_arg(ap, char); 78 assert_eq(c, '*'); 79 va_end(ap); 80 } 81 82 int main() 83 { 84 struct S instance = { 1000, 2000, 30 }; 85 assert_eq(sizeof(struct S), 5); 86 assert_eq(sizeof(instance), 5); 87 int result = f(instance, 4000, 99); 88 assert_eq(instance.a, 1000); 89 assert_eq(instance.b, 2000); 90 assert_eq(instance.c, 30); 91 assert_eq(result, 7129); 92 93 union U u0; 94 u0.n = 0xABCD; 95 assert_eq(getInt(u0), 0xABCD); 96 assert_eq(getChar(u0), 0xAB); // 6809 is big endian 97 98 instance.c = '$'; 99 struct S first = { 1111, 2222, '#' }; 100 v(first, instance, '%', 0xFEDC); 101 102 struct OneByte ob0 = { 0xAA }; 103 104 asm { clra } 105 receiveOneByteStruct(ob0); 106 107 asm { clra } 108 receiveOneByteStructViaEllipsis(4242, ob0, '*'); 109 110 struct OneByte ob1 = { '-' }; 111 asm { clra } 112 receiveOneByteStructViaEllipsis2(ob1, ob0, '*'); 113 114 return 0; 115 } 116 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=copyMem --need=memcpy --need=push5ByteStruct --need=pushStruct --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_copyMem_ -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_push5ByteStruct_ -D_CMOC_NEED_pushStruct_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_copyMem_ -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_push5ByteStruct_ -D_CMOC_NEED_pushStruct_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4CBB writable_globals_start $4661 writable_globals_end $4669 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 154: Function returning a struct or union by value 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 struct S { unsigned a, b; unsigned char c; }; 25 struct S makeS(unsigned a, unsigned b, unsigned char c) 26 { 27 struct S ret = { a, b, c }; 28 return ret; 29 } 30 struct S inc(struct S s) 31 { 32 assert_eq(s.a, 1000); 33 assert_eq(s.b, 2000); 34 assert_eq(s.c, 'A'); 35 ++s.a; 36 ++s.b; 37 ++s.c; 38 return s; 39 } 40 int main() 41 { 42 struct S s0 = makeS(1000, 2000, 'A'); 43 assert_eq(s0.a, 1000); 44 assert_eq(s0.b, 2000); 45 assert_eq(s0.c, 'A'); 46 unsigned b = makeS(1234, 5678, 'B').b; 47 assert_eq(b, 5678); 48 s0 = inc(s0); 49 assert_eq(s0.a, 1001); 50 assert_eq(s0.b, 2001); 51 assert_eq(s0.c, 'B'); 52 struct S s1 = makeS(1000, 2000, 'A'); 53 inc(s1); // not receiving the return value 54 return 0; 55 } 56 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' -Werror ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 0 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=copyMem --need=memcpy --need=push5ByteStruct --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_copyMem_ -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_push5ByteStruct_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_copyMem_ -D_CMOC_NEED_memcpy_ -D_CMOC_NEED_push5ByteStruct_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $49D7 writable_globals_start $4397 writable_globals_end $439F --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 155: Argument too large for function parameter 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 char takeChar(char x) { return x; } 25 unsigned char takeUnsignedChar(unsigned char x) { return x; } 26 int main() 27 { 28 char c = takeChar(0x1234); 29 assert_eq(c, 0x34); 30 c = takeChar(0x12F0); 31 assert_eq(c, (int) -16); 32 unsigned char uc = takeUnsignedChar(0x1256); 33 assert_eq(uc, 0x56); 34 uc = takeUnsignedChar(0x12F8); 35 assert_eq(uc, (int) 248); 36 return 0; 37 } 38 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code ,check-prog.c:28: __warning__: passing `int' argument as `char' parameter 1 ('x') of function takeChar() ,check-prog.c:30: __warning__: passing `int' argument as `char' parameter 1 ('x') of function takeChar() ,check-prog.c:32: __warning__: passing `int' argument as `unsigned char' parameter 1 ('x') of function takeUnsignedChar() ,check-prog.c:34: __warning__: passing `int' argument as `unsigned char' parameter 1 ('x') of function takeUnsignedChar() Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 4 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $47E3 writable_globals_start $41C7 writable_globals_end $41CF --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- Program # 156: Declaration with initializer larger than variable 1 #include 2 3 typedef unsigned char byte; 4 typedef signed char sbyte; 5 typedef unsigned int word; 6 typedef signed int sword; 7 #define assert(cond) do { if (!(cond)) printf("ERROR: assert failed: line %d\n", __LINE__); } while (0) 8 #define assert_eq(actual, expected) \ 9 do { if ((actual) != (expected)) \ 10 printf("ERROR: assert_eq failed: line %d: should be equal: got %u ($%x), expected %u ($%x)\n", \ 11 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 12 } while (0) 13 #define assert_ne(actual, expected) \ 14 do { if ((actual) == (expected)) \ 15 printf("ERROR: assert_ne failed: line %d: should be different: got %u ($%x), expected %u ($%x)\n", \ 16 __LINE__, (word) (actual), (word) (actual), (word) (expected), (word) (expected)); \ 17 } while (0) 18 #define assert_range(actual, expectedMin, expectedMax) \ 19 do { if ((actual) < (expectedMin) && (actual) > (expectedMax)) \ 20 printf("ERROR: assert_range failed: line %d: out of range: got %u ($%x), expected %u..%u ($%x..$%x)\n", \ 21 __LINE__, (word) (actual), (word) (actual), (word) (expectedMin), (word) (expectedMax), (word) (expectedMin), (word) (expectedMax)); \ 22 } while (0) 23 24 void f(int i, unsigned u) 25 { 26 char c0 = i; 27 assert_eq(c0, -32); 28 char c1 = u; 29 assert_eq(c1, -48); 30 unsigned char uc0 = i; 31 assert_eq(uc0, (unsigned char) -32); 32 unsigned char uc1 = u; 33 assert_eq(uc1, 208); 34 int i0 = u; 35 assert_eq(i0, -24624); 36 unsigned u0 = i; 37 assert_eq(u0, 0x7fe0); 38 } 39 int main() 40 { 41 f(0x7fe0, 0x9fd0); 42 return 0; 43 } 44 --- Compilation command: ./cmoc --usim --verbose -nostdinc -O2 --org=4000 --intermediate --monolith --a09='./a09' -I './support' ,check-prog.c Target platform: USim Preprocessing: ,check-prog.c Preprocessor command: cpp -xc++ -I'./support' -DUSIM=1 -DCMOC_MONOLITH -U__GNUC__ -nostdinc -undef ,check-prog.c Compiling... Code address: $4000 (16384) Data address: after the code ,check-prog.c:26: __warning__: initializing char with expression of type int ,check-prog.c:28: __warning__: initializing char with expression of type unsigned int ,check-prog.c:30: __warning__: initializing unsigned char with expression of type int ,check-prog.c:32: __warning__: initializing unsigned char with expression of type unsigned int Assembler: ./a09 Assembly language filename: ,check-prog.asm 0 error(s), 4 warning(s). Assembling: ./a09 --includedir='./support' --entry=4000 --target=USIM --stack-space=1024 --need=_printf --need=_strtoul --need=memcpy --verbose ,check-prog.asm Preprocessor command: cat ,check-prog.asm | cpp -P -traditional -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ Assembler command: lwasm --pragma=forwardrefmax --list=,check-prog.lst --symbols -I'./support' -I'./support' -DUSIM=1 -Dstack_space=1024 -D_CMOC_NEED_printf_ -D_CMOC_NEED_strtoul_ -D_CMOC_NEED_memcpy_ --format=ihex --output=,check-prog.hex ,check-prog.i Generating BIN file: 'intelhex2cocobin' --entry=4000 < ',check-prog.hex' > ',check-prog.bin' Notable addresses: program_start $4000 program_end $4815 writable_globals_start $41F9 writable_globals_end $4201 --- Execution command: './usim-0.91-cmoc/usim' ,check-prog.hex 0 --- Expected output: --- Actual output: -------------------------------------------------------------------------------- Cleaning up: erasing ,check-prog.c erasing ,check-prog.asm erasing ,check-prog.i erasing ,check-prog.lst erasing ,check-prog.hex erasing ,check-prog.bin ./test-program-output.pl: ALL 157 tests PASSED ### # # ### ### ##### ### ### # # # # # # # # # # # # # # # # # # # # # ### # # # # ### ### ### # # # # # # # # # # # # # # # # # # # # # ### ### ### ### ##### ### ### perl ./test-bad-programs.pl --monolith . -------------------------------------------------------------------------------- --- Program # 0: Empty source file This test is suspended. ### ls ,check-prog.*: ls: cannot access ,check-prog.*: No such file or directory ### -------------------------------------------------------------------------------- --- Program # 1: Using a local variable before declaring it 1 2 int main() 3 { 4 a = 1; 5 int a; 6 return 0; 7 } --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: undeclared identifier `a' 2 ,check-prog.c:4: __error__: left side of operator = is of type void --- Expected compilation errors: 1 ,check-prog.c:4: __error__: undeclared identifier `a' 2 ,check-prog.c:4: __error__: left side of operator = is of type void ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 2: Using a global variable before declaring it 1 2 void f() 3 { 4 g = 1; 5 } 6 int g; 7 int main() 8 { 9 f(); 10 return g; 11 } --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: global variable `g' undeclared --- Expected compilation errors: 1 ,check-prog.c:4: __error__: global variable `g' undeclared ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 3: Non-void not returning a value 1 2 int main() { return 0; } 3 int f() {} 4 int g() { f(); } 5 void h() { return 42; } 6 int i() { return; } 7 asm int a() { asm { ldd #1844 } } // OK because function is asm only 8 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:3: __error__: function 'f' is not void but does not have any return statement 2 ,check-prog.c:4: __error__: function 'g' is not void but does not have any return statement 3 ,check-prog.c:5: __error__: returning expression of type int, which differs from function's return type (void) 4 ,check-prog.c:6: __error__: return without argument in a non-void function --- Expected compilation errors: 1 ,check-prog.c:3: __error__: function 'f' is not void but does not have any return statement 2 ,check-prog.c:4: __error__: function 'g' is not void but does not have any return statement 3 ,check-prog.c:5: __error__: returning expression of type int, which differs from function's return type (void) 4 ,check-prog.c:6: __error__: return without argument in a non-void function ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 4: Initializing pointer from non-zero constant 1 2 int main() 3 { 4 char *p0 = -42; 5 char *p1 = 42; 6 char *p2 = f(); 7 return 0; 8 } 9 int f() { return 0; } --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __warning__: initializing pointer 'p0' from negative constant 2 ,check-prog.c:6: __warning__: initializing pointer 'p2' from integer expression 3 ,check-prog.c:6: __error__: calling undeclared function f() --- Expected compilation errors: 1 ,check-prog.c:4: __warning__: initializing pointer 'p0' from negative constant 2 ,check-prog.c:6: __warning__: initializing pointer 'p2' from integer expression 3 ,check-prog.c:6: __error__: calling undeclared function f() ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 5: Declaring a variable with a name that is already used 1 2 int foo; 3 int foo; 4 int main() 5 { 6 char a; 7 int a; 8 return 0; 9 } 10 void f0(int n) 11 { 12 int n = 42; // fails b/c C views function param as part of function scope, not separate scope 13 } 14 void f1(int n) 15 { 16 { 17 int n = 42; // OK b/c inner braces create separate scope 18 } 19 } 20 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:3: __error__: global variable `foo' already declared at global scope at ,check-prog.c:2 2 ,check-prog.c:7: __error__: variable `a' already declared in this scope at ,check-prog.c:6 3 ,check-prog.c:12: __error__: variable `n' already declared in this scope at ,check-prog.c:10 --- Expected compilation errors: 1 ,check-prog.c:3: __error__: global variable `foo' already declared at global scope at ,check-prog.c:2 2 ,check-prog.c:7: __error__: variable `a' already declared in this scope at ,check-prog.c:6 3 ,check-prog.c:12: __error__: variable `n' already declared in this scope at ,check-prog.c:10 ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 6: Detect invalid subtractions 1 2 void f(int x) {} 3 int main() 4 { 5 char *p; 6 f((int) (4 - p)); 7 return 0; 8 } 9 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:6: __error__: subtraction of pointer or array from integral --- Expected compilation errors: 1 ,check-prog.c:6: __error__: subtraction of pointer or array from integral ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 7: Illegal array operations 1 2 int main() 3 { 4 int w[2]; 5 w = 0; 6 w += 0; 7 ++w; 8 w--; 9 *w = 0; 10 return 0; 11 } 12 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: cannot assign to array name 2 ,check-prog.c:6: __error__: cannot assign to array name 3 ,check-prog.c:7: __error__: cannot increment array name 4 ,check-prog.c:8: __error__: cannot decrement array name --- Expected compilation errors: 1 ,check-prog.c:5: __error__: cannot assign to array name 2 ,check-prog.c:6: __error__: cannot assign to array name 3 ,check-prog.c:7: __error__: cannot increment array name 4 ,check-prog.c:8: __error__: cannot decrement array name ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 8: Passing undefined struct by value to a function 1 2 struct Foobar { char b; }; 3 void f(struct Foobar s) 4 { 5 } 6 void f1(struct Foobar) 7 { 8 } 9 void f2(struct Undefined) 10 { 11 } 12 struct Quux {}; union U { char u; }; 13 void f3(struct Quux) {} 14 int main() 15 { 16 struct Foobar foobar; 17 f(foobar); 18 f1(foobar); 19 f3(foobar); 20 int n = foobar; 21 n += foobar; 22 n = -foobar; 23 union U u0; 24 n = -u0; 25 return 0; 26 } 27 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:9: __error__: argument 1 of f2() receives undefined `struct Undefined' by value 2 ,check-prog.c:19: __error__: `struct Foobar' used as parameter 1 of function f3() which is `struct Quux' 3 ,check-prog.c:21: __error__: invalid use of += on a struct or union 4 ,check-prog.c:22: __error__: invalid use of arithmetic negation on a struct 5 ,check-prog.c:24: __error__: invalid use of arithmetic negation on a union 6 ,check-prog.c:20: __error__: initializing int with expression of type struct Foobar --- Expected compilation errors: 1 ,check-prog.c:9: __error__: argument 1 of f2() receives undefined `struct Undefined' by value 2 ,check-prog.c:19: __error__: `struct Foobar' used as parameter 1 of function f3() which is `struct Quux' 3 ,check-prog.c:21: __error__: invalid use of += on a struct or union 4 ,check-prog.c:22: __error__: invalid use of arithmetic negation on a struct 5 ,check-prog.c:24: __error__: invalid use of arithmetic negation on a union 6 ,check-prog.c:20: __error__: initializing int with expression of type struct Foobar ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 9: Forbid requesting a struct by value from va_arg(). Detect use of unknown struct name 1 2 3 #include 4 5 struct S { char b; }; 6 void f(char *a, ...) 7 { 8 va_list ap; 9 va_start(ap, a); // ok 10 va_arg(ap, struct S); // passes but will not work 11 va_arg(ap, struct S *); // ok 12 va_arg(ap, struct Unknown *); // ok because sizeof gives 2, regard of unknown struct name 13 va_arg(ap, void); // error 14 va_arg(ap, char); // ok 15 va_arg(ap, char *); // ok 16 va_arg(ap, char **); // ok 17 va_arg(ap, char *****); // ok 18 va_end(ap); 19 } 20 int main() 21 { 22 f(0); 23 return 0; 24 } 25 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:13: __error__: indirection of a pointer to void 2 ,check-prog.c:13: __error__: cannot take sizeof(void) --- Expected compilation errors: 1 ,check-prog.c:13: __error__: indirection of a pointer to void 2 ,check-prog.c:13: __error__: cannot take sizeof(void) ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 10: Do-while lacks terminating semi-colon.. 1 2 void f() 3 { 4 do {} while (1) 5 } 6 int main() 7 { 8 return 0; 9 } 10 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: syntax error: } --- Expected compilation errors: 1 ,check-prog.c:5: __error__: syntax error: } ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 11: Global variable too large 1 2 int w[50000]; 3 int main() 4 { 5 return 0; 6 } 7 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: invalid dimensions for array w --- Expected compilation errors: 1 ,check-prog.c:2: __error__: invalid dimensions for array w ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 12: Local variable too large 1 2 int main() 3 { 4 char b[40000]; 5 return 0; 6 } 7 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: invalid dimensions for array b --- Expected compilation errors: 1 ,check-prog.c:4: __error__: invalid dimensions for array b ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 13: Number of arguments of built-in functions 1 2 #include 3 int main() 4 { 5 putstr("foo"); 6 int w; 7 toupper(w); 8 char *s0; 9 strchr(s0, 256 + 'f'); 10 printf(); 11 printf(s0); 12 sprintf(); 13 sprintf("x"); 14 sprintf("%d %d", 1, 2); 15 sprintf(w, "x"); 16 char temp[64]; 17 sprintf(temp, "%d %d", 1); 18 sprintf(temp, "%d %d", 1, 2); // OK 19 sprintf(temp, "%d %d", 1, 2, 3); 20 printf("%d %d", 1); 21 printf("%d %d", 1, 2); // OK 22 printf("%d %d", 1, 2, 3); 23 printf(w); 24 return 0; 25 } 26 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: call to putstr() passes 1 argument(s) but function expects 2 2 ,check-prog.c:10: __error__: call to printf() passes 0 argument(s) but function expects at least 1 3 ,check-prog.c:11: __warning__: format argument of printf() is not a string literal 4 ,check-prog.c:12: __error__: call to sprintf() passes 0 argument(s) but function expects at least 2 5 ,check-prog.c:13: __error__: call to sprintf() passes 1 argument(s) but function expects at least 2 6 ,check-prog.c:14: __warning__: first argument of sprintf() is a string literal 7 ,check-prog.c:15: __warning__: passing non-pointer/array (int) as parameter 1 of function sprintf(), which is char * 8 ,check-prog.c:15: __warning__: first argument of sprintf() should be pointer or array instead of `int' 9 ,check-prog.c:17: __warning__: not enough arguments to sprintf() to match its format string 10 ,check-prog.c:19: __warning__: too many arguments for sprintf() format string 11 ,check-prog.c:20: __warning__: not enough arguments to printf() to match its format string 12 ,check-prog.c:22: __warning__: too many arguments for printf() format string 13 ,check-prog.c:23: __warning__: passing non-pointer/array (int) as parameter 1 of function printf(), which is char * 14 ,check-prog.c:23: __warning__: format argument of printf() is not a string literal --- Expected compilation errors: 1 ,check-prog.c:5: __error__: call to putstr() passes 1 argument(s) but function expects 2 2 ,check-prog.c:10: __error__: call to printf() passes 0 argument(s) but function expects at least 1 3 ,check-prog.c:11: __warning__: format argument of printf() is not a string literal 4 ,check-prog.c:12: __error__: call to sprintf() passes 0 argument(s) but function expects at least 2 5 ,check-prog.c:13: __error__: call to sprintf() passes 1 argument(s) but function expects at least 2 6 ,check-prog.c:14: __warning__: first argument of sprintf() is a string literal 7 ,check-prog.c:15: __warning__: passing non-pointer/array (int) as parameter 1 of function sprintf(), which is char * 8 ,check-prog.c:15: __warning__: first argument of sprintf() should be pointer or array instead of `int' 9 ,check-prog.c:17: __warning__: not enough arguments to sprintf() to match its format string 10 ,check-prog.c:19: __warning__: too many arguments for sprintf() format string 11 ,check-prog.c:20: __warning__: not enough arguments to printf() to match its format string 12 ,check-prog.c:22: __warning__: too many arguments for printf() format string 13 ,check-prog.c:23: __warning__: passing non-pointer/array (int) as parameter 1 of function printf(), which is char * 14 ,check-prog.c:23: __warning__: format argument of printf() is not a string literal ### ls ,check-prog.*: ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 14: Detect change in signedness when passing an argument to a function 1 2 #include 3 void fsb(char x) {} 4 void fsw(int x) {} 5 void fub(unsigned char x) {} 6 void fuw(unsigned x) {} 7 int main() 8 { 9 char sb; 10 int sw; 11 unsigned char ub; 12 unsigned uw; 13 fsb(ub); 14 fsw(uw); 15 fub(sb); 16 fuw(sw); 17 memset((unsigned char *) 0, sb, sw); 18 fsw(sw + ub); // no warning because sum is signed int (see ExpressionTypeSetter::processBinOp()) 19 return 0; 20 } 21 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: --- Expected compilation errors: ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 15: Return value type vs. function's return type 1 2 unsigned char *b1() { return 1; } 3 unsigned char *bm1() { return -1; } 4 unsigned char *b1000() { return 1000; } 5 unsigned char *bm1000() { return -1000; } 6 unsigned *w1() { return 1; } 7 unsigned *wm1() { return -1; } 8 unsigned *w1000() { return 1000; } 9 unsigned *wm1000() { return -1000; } 10 int main() 11 { 12 return 0; 13 } 14 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: returning expression of type int, which differs from function's return type (unsigned char *) 2 ,check-prog.c:3: __error__: returning expression of type int, which differs from function's return type (unsigned char *) 3 ,check-prog.c:4: __error__: returning expression of type int, which differs from function's return type (unsigned char *) 4 ,check-prog.c:5: __error__: returning expression of type int, which differs from function's return type (unsigned char *) 5 ,check-prog.c:6: __error__: returning expression of type int, which differs from function's return type (unsigned int *) 6 ,check-prog.c:7: __error__: returning expression of type int, which differs from function's return type (unsigned int *) 7 ,check-prog.c:8: __error__: returning expression of type int, which differs from function's return type (unsigned int *) 8 ,check-prog.c:9: __error__: returning expression of type int, which differs from function's return type (unsigned int *) --- Expected compilation errors: 1 ,check-prog.c:2: __error__: returning expression of type int, which differs from function's return type (unsigned char *) 2 ,check-prog.c:3: __error__: returning expression of type int, which differs from function's return type (unsigned char *) 3 ,check-prog.c:4: __error__: returning expression of type int, which differs from function's return type (unsigned char *) 4 ,check-prog.c:5: __error__: returning expression of type int, which differs from function's return type (unsigned char *) 5 ,check-prog.c:6: __error__: returning expression of type int, which differs from function's return type (unsigned int *) 6 ,check-prog.c:7: __error__: returning expression of type int, which differs from function's return type (unsigned int *) 7 ,check-prog.c:8: __error__: returning expression of type int, which differs from function's return type (unsigned int *) 8 ,check-prog.c:9: __error__: returning expression of type int, which differs from function's return type (unsigned int *) ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 16: Return type of main() must be int 1 2 void main() 3 { 4 } 5 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: return type of main() must be int --- Expected compilation errors: 1 ,check-prog.c:2: __error__: return type of main() must be int ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 17: printf() format warnings 1 2 #include 3 int main() 4 { 5 int sw; 6 unsigned uw; 7 char sb; 8 unsigned char ub; 9 unsigned char *bp; 10 printf("%u %d %5u %% %d %u %3d %p\n", sw, uw, sb, ub, bp, bp); 11 printf("%"); 12 printf("foo %123"); 13 printf("%u %u", 1, 2, 3); 14 printf(""); 15 obligatory_error; 16 printf("%d", -1); // no warning expected 17 printf("%u", 1); // no warning expected 18 return 0; 19 } 20 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:15: __error__: undeclared identifier `obligatory_error' 2 ,check-prog.c:10: __warning__: not enough arguments to printf() to match its format string 3 ,check-prog.c:11: __warning__: no letter follows last % in printf() format string 4 ,check-prog.c:12: __warning__: no letter follows last % in printf() format string 5 ,check-prog.c:13: __warning__: too many arguments for printf() format string --- Expected compilation errors: 1 ,check-prog.c:15: __error__: undeclared identifier `obligatory_error' 2 ,check-prog.c:10: __warning__: not enough arguments to printf() to match its format string 3 ,check-prog.c:11: __warning__: no letter follows last % in printf() format string 4 ,check-prog.c:12: __warning__: no letter follows last % in printf() format string 5 ,check-prog.c:13: __warning__: too many arguments for printf() format string ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 18: Declaration type vs. initializer type 1 2 int main() 3 { 4 unsigned w = 1844; 5 unsigned *pw0 = &w; 6 unsigned *pw1 = &pw0; // unsigned ** assigned to unsigned * 7 char b0 = -129; 8 char b1 = -128; 9 char b2 = 255; 10 char b3 = 256; 11 return 0; 12 } 13 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:6: __error__: initializing unsigned int * with expression of type unsigned int ** 2 ,check-prog.c:7: __warning__: initializing char with expression of type int 3 ,check-prog.c:10: __warning__: initializing char with expression of type int --- Expected compilation errors: 1 ,check-prog.c:6: __error__: initializing unsigned int * with expression of type unsigned int ** 2 ,check-prog.c:7: __warning__: initializing char with expression of type int 3 ,check-prog.c:10: __warning__: initializing char with expression of type int ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 19: Byte array initialized with non-byte expressions 1 2 char strings[] = { "foo", "bar", "baz" }; 3 int main() 4 { 5 return 0; 6 } 7 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: initializing char with expression of type char[] 2 ,check-prog.c:2: __error__: initializing char with expression of type char[] 3 ,check-prog.c:2: __error__: initializing char with expression of type char[] --- Expected compilation errors: 1 ,check-prog.c:2: __error__: initializing char with expression of type char[] 2 ,check-prog.c:2: __error__: initializing char with expression of type char[] 3 ,check-prog.c:2: __error__: initializing char with expression of type char[] ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 20: Invalid array initializer 1 2 struct A { char byteField; }; 3 struct A structArray[3] = { { 42 }, "foo", { 44 } }; 4 int v0[4] = "foo"; 5 int v1[] = { 9999 }; 6 int v2[] = &v1; 7 int main() 8 { 9 return 0; 10 } 11 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:6: __error__: invalid initializer --- Expected compilation errors: 1 ,check-prog.c:6: __error__: invalid initializer ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 21: Array whose initializer contains expressions of types that do not match the element type 1 2 struct A { char byteField; }; 3 struct A structArray[3] = { { 42 }, "foo", { 44 } }; 4 int v0[4] = "foo"; 5 int main() 6 { 7 return 0; 8 } 9 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:3: __error__: initializer for struct A is of type `char[]': must be list, or struct of same type 2 ,check-prog.c:4: __error__: initializer for array `v0' is invalid --- Expected compilation errors: 1 ,check-prog.c:3: __error__: initializer for struct A is of type `char[]': must be list, or struct of same type 2 ,check-prog.c:4: __error__: initializer for array `v0' is invalid ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 22: Re: Declaration::checkClassInitializer() 1 2 struct A 3 { 4 char b; 5 }; 6 struct A a = { "foo" }; 7 struct B 8 { 9 struct A aMember; 10 }; 11 struct B b = { { "bar" } }; 12 struct C 13 { 14 struct A aMemberArray[2]; 15 }; 16 struct C c = { { 17 { "baz" }, 18 { "quux" } 19 } }; 20 int main() 21 { 22 return 0; 23 } 24 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:6: __error__: initializing char with expression of type char[] 2 ,check-prog.c:11: __error__: initializing char with expression of type char[] 3 ,check-prog.c:17: __error__: initializing char with expression of type char[] 4 ,check-prog.c:18: __error__: initializing char with expression of type char[] --- Expected compilation errors: 1 ,check-prog.c:6: __error__: initializing char with expression of type char[] 2 ,check-prog.c:11: __error__: initializing char with expression of type char[] 3 ,check-prog.c:17: __error__: initializing char with expression of type char[] 4 ,check-prog.c:18: __error__: initializing char with expression of type char[] ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 23: var_decl containing a type_specifier but no declarator_list, unless it defines a struct 1 2 struct S { char b; }; // ok 3 unsigned n = 42; // ok 4 unsigned x; // ok: declarator without initializer 5 unsigned; // fail 6 int main() 7 { 8 return 0; 9 } 10 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: declaration specifies a type but no variable name --- Expected compilation errors: 1 ,check-prog.c:5: __error__: declaration specifies a type but no variable name ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 24: Reject returning an array from an int function 1 2 int i = 0; 3 int f(int *p) 4 { 5 return p; 6 } 7 int g(int p[][3]) 8 { 9 return p[i]; 10 } 11 int h(int p[][3][3]) 12 { 13 return p[i][i]; 14 } 15 int h2(int p[][3][3]) 16 { 17 return p[i]; 18 } 19 int main() 20 { 21 return 0; 22 } 23 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: returning expression of type int *, which differs from function's return type (int) 2 ,check-prog.c:9: __error__: returning expression of type int[], which differs from function's return type (int) 3 ,check-prog.c:13: __error__: returning expression of type int[], which differs from function's return type (int) 4 ,check-prog.c:17: __error__: returning expression of type int[][], which differs from function's return type (int) --- Expected compilation errors: 1 ,check-prog.c:5: __error__: returning expression of type int *, which differs from function's return type (int) 2 ,check-prog.c:9: __error__: returning expression of type int[], which differs from function's return type (int) 3 ,check-prog.c:13: __error__: returning expression of type int[], which differs from function's return type (int) 4 ,check-prog.c:17: __error__: returning expression of type int[][], which differs from function's return type (int) ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 25: Calling an undeclared function, mismatching function prototype, wrong number of parameters, etc. 1 2 void f2(); 3 void f3(int n); 4 void f3(); 5 void f4(); 6 int main() 7 { 8 f0(); 9 f1(); 10 11 12 return 0; 13 } 14 void f1() 15 { 16 } 17 void f4(int n) 18 { 19 } 20 void f5(int a); 21 void f5(int a, ...); 22 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: formal parameters for f3() are different from previously declared at ,check-prog.c:3 2 ,check-prog.c:17: __error__: formal parameters for f4() are different from previously declared at ,check-prog.c:5 3 ,check-prog.c:21: __error__: formal parameters for f5() are different from previously declared at ,check-prog.c:20 4 ,check-prog.c:8: __error__: undeclared identifier `f0' 5 ,check-prog.c:8: __error__: calling undeclared function f0() 6 ,check-prog.c:9: __error__: calling undeclared function f1() --- Expected compilation errors: 1 ,check-prog.c:4: __error__: formal parameters for f3() are different from previously declared at ,check-prog.c:3 2 ,check-prog.c:17: __error__: formal parameters for f4() are different from previously declared at ,check-prog.c:5 3 ,check-prog.c:21: __error__: formal parameters for f5() are different from previously declared at ,check-prog.c:20 4 ,check-prog.c:8: __error__: undeclared identifier `f0' 5 ,check-prog.c:8: __error__: calling undeclared function f0() 6 ,check-prog.c:9: __error__: calling undeclared function f1() ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 26: Unknown member of a struct 1 2 struct S0 3 { 4 int a; 5 }; 6 int main() 7 { 8 struct S0 s0; 9 s0.b = 1; 10 return 0; 11 } 12 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:9: __error__: struct S0 has no member named b 2 ,check-prog.c:9: __error__: left side of operator = is of type void --- Expected compilation errors: 1 ,check-prog.c:9: __error__: struct S0 has no member named b 2 ,check-prog.c:9: __error__: left side of operator = is of type void ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 27: Warnings on dubious function calls 1 2 void f() {} 3 int main() 4 { 5 int f; 6 f(); 7 int pf = f; 8 pf(); 9 return 0; 10 } 11 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:6: __warning__: calling 'f', which is both a variable and a function name 2 ,check-prog.c:8: __warning__: variable 'pf' used as function pointer without being of type void * --- Expected compilation errors: 1 ,check-prog.c:6: __warning__: calling 'f', which is both a variable and a function name 2 ,check-prog.c:8: __warning__: variable 'pf' used as function pointer without being of type void * ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 28: switch() 1 2 int f() { return 99; } 3 int main() 4 { 5 switch (1) return 42; 6 switch (1) { case f(): return 0; } 7 switch (1) { return 1; case 5: return 0; } 8 char c = 1; 9 switch (c) { case 500: return 1; } 10 unsigned char uc = 1; 11 switch (uc) { case 500: return 1; } 12 switch (1) { default: break; case 5: break; default: ; } 13 switch (1) { case 5: continue; } 14 switch (1) 15 { 16 case 3: 17 ; 18 case 3: // duplicate case value 19 ; 20 } 21 return 0; 22 } 23 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: switch() statement has no `case' or `default' statement 2 ,check-prog.c:6: __error__: case statement has a variable expression 3 ,check-prog.c:7: __error__: statement in switch precedes first `case' or `default' statement 4 ,check-prog.c:9: __warning__: switch expression is signed char but case value is not in range -128..127 5 ,check-prog.c:11: __warning__: switch expression is unsigned char but case value is not in range 0..255 6 ,check-prog.c:12: __error__: more than one default statement in switch 7 ,check-prog.c:18: __error__: duplicate case value (first used at ,check-prog.c:16) --- Expected compilation errors: 1 ,check-prog.c:5: __error__: switch() statement has no `case' or `default' statement 2 ,check-prog.c:6: __error__: case statement has a variable expression 3 ,check-prog.c:7: __error__: statement in switch precedes first `case' or `default' statement 4 ,check-prog.c:9: __warning__: switch expression is signed char but case value is not in range -128..127 5 ,check-prog.c:11: __warning__: switch expression is unsigned char but case value is not in range 0..255 6 ,check-prog.c:12: __error__: more than one default statement in switch 7 ,check-prog.c:18: __error__: duplicate case value (first used at ,check-prog.c:16) ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 29: Continue in a switch (not supported) 1 2 int f() { return 42; } 3 int main() 4 { 5 switch (1) { case 1: continue; } // error 6 switch (1) { case 1: while (1) continue; } // ok 7 return 0; 8 } 9 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: continue statement is not supported in a switch --- Expected compilation errors: 1 ,check-prog.c:5: __error__: continue statement is not supported in a switch ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 30: Invalid usage of "#pragma org" 1 2 #pragma org pizza 3 int main() 4 { 5 return 0; 6 } 7 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: invalid pragma directive: org pizza --- Expected compilation errors: 1 ,check-prog.c:2: __error__: invalid pragma directive: org pizza ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 31: Passing a wrong type to a function expecting a non-void pointer 1 2 struct S {}; 3 void f(struct S *p) {} 4 struct T {}; union U {}; 5 int main() 6 { 7 f(0); // OK: null pointer 8 f(3); // tolerated, unless -Wpass-const-for-func-pointer is passed 9 f(-4); // ditto 10 int n; 11 f(&n); // error: wrong type of pointer 12 struct T t; 13 f(&t); // error: ditto 14 struct S s; 15 f(&s); // OK 16 union U u; 17 f(&u); 18 return 0; 19 } 20 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:11: __error__: pointer type mismatch: passing int * as parameter 1 of function f(), which is a struct S * 2 ,check-prog.c:13: __error__: pointer type mismatch: passing struct T * as parameter 1 of function f(), which is a struct S * 3 ,check-prog.c:17: __error__: pointer type mismatch: passing union U * as parameter 1 of function f(), which is a struct S * --- Expected compilation errors: 1 ,check-prog.c:11: __error__: pointer type mismatch: passing int * as parameter 1 of function f(), which is a struct S * 2 ,check-prog.c:13: __error__: pointer type mismatch: passing struct T * as parameter 1 of function f(), which is a struct S * 3 ,check-prog.c:17: __error__: pointer type mismatch: passing union U * as parameter 1 of function f(), which is a struct S * ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 32: #pragma const_data 1 2 int f() { return 42; } 3 #pragma const_data start 4 int lacksInitializer; 5 int nonConstInitializer = f(); 6 int ok = 6809; 7 #pragma const_data end 8 int main() 9 { 10 return 0; 11 } 12 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: global variable 'lacksInitializer' declared in const_data section but has no initializer 2 ,check-prog.c:5: __error__: global variable 'nonConstInitializer' declared in const_data section but has a run-time initializer --- Expected compilation errors: 1 ,check-prog.c:4: __error__: global variable 'lacksInitializer' declared in const_data section but has no initializer 2 ,check-prog.c:5: __error__: global variable 'nonConstInitializer' declared in const_data section but has a run-time initializer ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 33: Referring to a member of an undefined struct 1 2 int main() 3 { 4 struct S *p = 0; 5 p->n = 42; 6 return 0; 7 } 8 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: reference to member `n' of undefined class `S' 2 ,check-prog.c:5: __error__: left side of operator = is of type void --- Expected compilation errors: 1 ,check-prog.c:5: __error__: reference to member `n' of undefined class `S' 2 ,check-prog.c:5: __error__: left side of operator = is of type void ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 34: Indirection of a pointer to a struct used as an r-value 1 2 struct S { int field; }; 3 struct T { struct S *ps; }; 4 int main() 5 { 6 struct S *ps = (struct S *) 100; 7 if (*ps) // bad 8 ; 9 if ((*ps).field == 0) // ok 10 ; 11 struct T *pt = (struct T *) 200; 12 if (*(*pt).ps) // bad 13 ; 14 if ((*(*pt).ps).field) // ok 15 ; 16 return 0; 17 } 18 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:7: __error__: invalid use of struct as condition of if statement 2 ,check-prog.c:12: __error__: invalid use of struct as condition of if statement --- Expected compilation errors: 1 ,check-prog.c:7: __error__: invalid use of struct as condition of if statement 2 ,check-prog.c:12: __error__: invalid use of struct as condition of if statement ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 35: Initializing from incompatible pointer type 1 2 int a[5][7][13]; 3 char n; 4 int main() 5 { 6 int *p0 = a; 7 p0 = a; 8 int *p1 = a + n; 9 p1 = a + n; 10 int *p2 = a + 1; 11 p2 = a + 1; 12 int *p2 = n; 13 p0 = n; 14 p0 = -1; 15 return 0; 16 } 17 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:12: __error__: variable `p2' already declared in this scope at ,check-prog.c:10 2 ,check-prog.c:7: __warning__: assigning pointer to int with incompatible int[][][] 3 ,check-prog.c:9: __warning__: assigning pointer to int with incompatible int[][][] 4 ,check-prog.c:11: __warning__: assigning pointer to int with incompatible int[][][] 5 ,check-prog.c:13: __warning__: assigning pointer with integer expression 6 ,check-prog.c:14: __warning__: assigning pointer with negative constant 7 ,check-prog.c:6: __warning__: initializing pointer to int 'p0' from incompatible int[][][] 8 ,check-prog.c:8: __warning__: initializing pointer to int 'p1' from incompatible int[][][] 9 ,check-prog.c:10: __warning__: initializing pointer to int 'p2' from incompatible int[][][] 10 ,check-prog.c:12: __warning__: initializing pointer 'p2' from integer expression --- Expected compilation errors: 1 ,check-prog.c:12: __error__: variable `p2' already declared in this scope at ,check-prog.c:10 2 ,check-prog.c:7: __warning__: assigning pointer to int with incompatible int[][][] 3 ,check-prog.c:9: __warning__: assigning pointer to int with incompatible int[][][] 4 ,check-prog.c:11: __warning__: assigning pointer to int with incompatible int[][][] 5 ,check-prog.c:13: __warning__: assigning pointer with integer expression 6 ,check-prog.c:14: __warning__: assigning pointer with negative constant 7 ,check-prog.c:6: __warning__: initializing pointer to int 'p0' from incompatible int[][][] 8 ,check-prog.c:8: __warning__: initializing pointer to int 'p1' from incompatible int[][][] 9 ,check-prog.c:10: __warning__: initializing pointer to int 'p2' from incompatible int[][][] 10 ,check-prog.c:12: __warning__: initializing pointer 'p2' from integer expression ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 36: Assembly-only function containing non-asm statement 1 2 int asm f() 3 { 4 int foo; // only asm{} allowed in asm function 5 asm {} 6 } 7 int asm g() 8 { 9 asm {} 10 return 42; // only asm{} allowed in asm function 11 } 12 int asm h(int m, char n, char *s) 13 { 14 asm { 15 ldb n 16 } 17 asm { 18 ldb s[12] 19 ldd m 20 ldb n 21 ldd m 22 tfr s,x // OK: s refers to register, not to C variable 23 } 24 asm("clr", n); 25 } 26 int global0 = 42; 27 void q() 28 { 29 asm("ldd", global0); // OK: variable is global 30 asm { 31 ldd global0 // ditto 32 } 33 } 34 int main() 35 { 36 int z; 37 asm { nop } // OK: no 'asm' modifier on this function 38 asm("clr", z); // ditto 39 return 0; 40 } 41 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: body of function f() contains statement(s) other than inline assembly 2 ,check-prog.c:10: __error__: body of function g() contains statement(s) other than inline assembly 3 ,check-prog.c:14: __error__: assembly-only function refers to local C variable `n' 4 ,check-prog.c:17: __error__: assembly-only function refers to local C variables `m', `n', `s' 5 ,check-prog.c:24: __error__: assembly-only function refers to local C variable `n' --- Expected compilation errors: 1 ,check-prog.c:4: __error__: body of function f() contains statement(s) other than inline assembly 2 ,check-prog.c:10: __error__: body of function g() contains statement(s) other than inline assembly 3 ,check-prog.c:14: __error__: assembly-only function refers to local C variable `n' 4 ,check-prog.c:17: __error__: assembly-only function refers to local C variables `m', `n', `s' 5 ,check-prog.c:24: __error__: assembly-only function refers to local C variable `n' ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 37: asm modifier used on non-function declarations 1 2 int asm globalVar0; // modifier only legal on a function 3 4 typedef int asm Bad; 5 int main() 6 { 7 int asm localVar; 8 return 0; 9 } 10 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: illegal modifier used on declaration of variable `globalVar0' 2 ,check-prog.c:4: __error__: illegal modifier used on typedef 3 ,check-prog.c:7: __error__: illegal modifier used on declaration of variable `localVar' --- Expected compilation errors: 1 ,check-prog.c:2: __error__: illegal modifier used on declaration of variable `globalVar0' 2 ,check-prog.c:4: __error__: illegal modifier used on typedef 3 ,check-prog.c:7: __error__: illegal modifier used on declaration of variable `localVar' ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 38: Illegal modifier used on declaration of variable 1 2 int interrupt globalVar1; 3 interrupt void isr() {} 4 int main() 5 { 6 int interrupt localVar; 7 isr(); 8 return 0; 9 } 10 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: illegal modifier used on declaration of variable `globalVar1' 2 ,check-prog.c:6: __error__: illegal modifier used on declaration of variable `localVar' --- Expected compilation errors: 1 ,check-prog.c:2: __error__: illegal modifier used on declaration of variable `globalVar1' 2 ,check-prog.c:6: __error__: illegal modifier used on declaration of variable `localVar' ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 39: Calling interrupt service routine 1 2 interrupt void isr() {} 3 int main() 4 { 5 isr(); 6 return 0; 7 } 8 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: calling function isr() is forbidden because it is an interrupt service routine --- Expected compilation errors: 1 ,check-prog.c:5: __error__: calling function isr() is forbidden because it is an interrupt service routine ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 40: Struct with field of undefined struct 1 2 struct Outer 3 { 4 struct Inner i; 5 }; 6 int main() 7 { 8 return 0; 9 } 10 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: member `i' of `Outer' is of undefined type `Inner' --- Expected compilation errors: 1 ,check-prog.c:4: __error__: member `i' of `Outer' is of undefined type `Inner' ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 41: union vs. struct 1 2 union U 3 { 4 int i; 5 }; 6 struct S 7 { 8 int i; 9 }; 10 struct Cell; 11 struct List 12 { 13 struct Cell *a, *b; 14 }; 15 union UndefUnion; 16 struct Cell fc(); 17 int main() 18 { 19 struct U u; 20 union S s; 21 struct Cell c; 22 union UndefUnion uu; 23 struct Cell *pc; // OK 24 union UndefUnion *puu; // OK 25 return 0; 26 } 27 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:16: __error__: declaring `fc' of undefined type struct `Cell' 2 ,check-prog.c:19: __error__: referring to U as a struct, but it is a union 3 ,check-prog.c:20: __error__: referring to S as a union, but it is a struct 4 ,check-prog.c:21: __error__: declaring `c' of undefined type struct `Cell' 5 ,check-prog.c:22: __error__: declaring `uu' of undefined type struct `UndefUnion' --- Expected compilation errors: 1 ,check-prog.c:16: __error__: declaring `fc' of undefined type struct `Cell' 2 ,check-prog.c:19: __error__: referring to U as a struct, but it is a union 3 ,check-prog.c:20: __error__: referring to S as a union, but it is a struct 4 ,check-prog.c:21: __error__: declaring `c' of undefined type struct `Cell' 5 ,check-prog.c:22: __error__: declaring `uu' of undefined type struct `UndefUnion' ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 42: Receiving an undefined aggregate type by value 1 2 struct Cell; 3 union U; 4 void fc1(struct Cell c); 5 void fc2(struct Cell c) {} 6 void fc3(union U u); 7 void fc4(union U u) {} 8 int main() 9 { 10 return 0; 11 } 12 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: argument 1 of fc1() receives undefined `struct Cell' by value 2 ,check-prog.c:5: __error__: argument 1 of fc2() receives undefined `struct Cell' by value 3 ,check-prog.c:6: __error__: argument 1 of fc3() receives undefined `union U' by value 4 ,check-prog.c:7: __error__: argument 1 of fc4() receives undefined `union U' by value --- Expected compilation errors: 1 ,check-prog.c:4: __error__: argument 1 of fc1() receives undefined `struct Cell' by value 2 ,check-prog.c:5: __error__: argument 1 of fc2() receives undefined `struct Cell' by value 3 ,check-prog.c:6: __error__: argument 1 of fc3() receives undefined `union U' by value 4 ,check-prog.c:7: __error__: argument 1 of fc4() receives undefined `union U' by value ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 43: Forbid --org and --data when targeting Vectrex 1 2 int main() 3 { 4 return 0; 5 } 6 --- Compilation command: ./cmoc --vectrex --monolith --a09='./a09' -I './support' --org=0x300 --data=0x400 --monolith ,check-prog.c --- Actual compilation errors: 1 cmoc: --org and --data are not permitted for Vectrex --- Expected compilation errors: 1 cmoc: --org and --data are not permitted for Vectrex ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 44: Forbid code and data positioning pragmas when targeting Vectrex 1 2 #pragma org 0x100 3 #pragma data 0x200 4 int main() 5 { 6 return 0; 7 } 8 --- Compilation command: ./cmoc --vectrex --monolith --a09='./a09' -I './support' --monolith ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: #pragma org is not permitted for Vectrex 2 ,check-prog.c:3: __error__: #pragma data is not permitted for Vectrex --- Expected compilation errors: 1 ,check-prog.c:2: __error__: #pragma org is not permitted for Vectrex 2 ,check-prog.c:3: __error__: #pragma data is not permitted for Vectrex ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 45: Function prototype local to a function body 1 2 void f() {} 3 int g() 4 { 5 char *f(); 6 return 1; // check that this JumpStmt is seen as inside g() 7 } 8 int main() 9 { 10 return 0; 11 } 12 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: invalid declaration --- Expected compilation errors: 1 ,check-prog.c:5: __error__: invalid declaration ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 46: Correct line number in error message when using function address to initialize char 1 2 char f() { return 42; } 3 int main() 4 { 5 char b = f; 6 return 0; 7 } 8 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: initializing char with expression of type void * --- Expected compilation errors: 1 ,check-prog.c:5: __error__: initializing char with expression of type void * ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 47: sizeof on an unknown struct name 1 2 struct S {}; 3 unsigned g0 = sizeof(struct Foo); 4 unsigned g1 = sizeof(struct S); 5 int main() 6 { 7 unsigned a = sizeof(struct Foo); 8 unsigned b; 9 b = sizeof(struct Foo); 10 b = sizeof(struct S); 11 b = sizeof(struct Bar); 12 return 0; 13 } 14 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:3: __error__: cannot take sizeof unknown struct or union 'Foo' 2 ,check-prog.c:7: __error__: cannot take sizeof unknown struct or union 'Foo' 3 ,check-prog.c:9: __error__: cannot take sizeof unknown struct or union 'Foo' 4 ,check-prog.c:11: __error__: cannot take sizeof unknown struct or union 'Bar' --- Expected compilation errors: 1 ,check-prog.c:3: __error__: cannot take sizeof unknown struct or union 'Foo' 2 ,check-prog.c:7: __error__: cannot take sizeof unknown struct or union 'Foo' 3 ,check-prog.c:9: __error__: cannot take sizeof unknown struct or union 'Foo' 4 ,check-prog.c:11: __error__: cannot take sizeof unknown struct or union 'Bar' ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 48: sizeof on an unknown array name, used twice in a binary expression 1 2 int main() 3 { 4 unsigned n = sizeof(a) / sizeof(a[0]); 5 return 0; 6 } 7 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: undeclared identifier `a' 2 ,check-prog.c:4: __error__: undeclared identifier `a' 3 ,check-prog.c:4: __error__: argument of sizeof operator is of type void 4 ,check-prog.c:4: __error__: left side of operator [] is of type void 5 ,check-prog.c:4: __error__: array reference on non array or pointer 6 ,check-prog.c:4: __error__: argument of sizeof operator is of type void 7 ,check-prog.c:4: __error__: cannot take sizeof(void) 8 ,check-prog.c:4: __error__: cannot take sizeof(void) 9 ,check-prog.c:4: __error__: lvalue required as left operand of array reference --- Expected compilation errors: 1 ,check-prog.c:4: __error__: undeclared identifier `a' 2 ,check-prog.c:4: __error__: undeclared identifier `a' 3 ,check-prog.c:4: __error__: argument of sizeof operator is of type void 4 ,check-prog.c:4: __error__: left side of operator [] is of type void 5 ,check-prog.c:4: __error__: array reference on non array or pointer 6 ,check-prog.c:4: __error__: argument of sizeof operator is of type void 7 ,check-prog.c:4: __error__: cannot take sizeof(void) 8 ,check-prog.c:4: __error__: cannot take sizeof(void) 9 ,check-prog.c:4: __error__: lvalue required as left operand of array reference ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 49: Passing integer for pointer parameter 1 2 int g() { return 42; } 3 void f(int *p) {} 4 int main() 5 { 6 f(g()); 7 return 0; 8 } 9 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:6: __warning__: passing non-pointer/array (int) as parameter 1 of function f(), which is int * --- Expected compilation errors: 1 ,check-prog.c:6: __warning__: passing non-pointer/array (int) as parameter 1 of function f(), which is int * ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 50: Invalid numerical constant 1 2 unsigned f0() { return 0777777; } 3 unsigned f1() { return 0xFFFFF; } 4 unsigned f2() { return 99999; } 5 int f3() { return -99999; } 6 int main() 7 { 8 return (int) (f0() + f1() + f2() + f3()); 9 } 10 This test is suspended. ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 51: Dereferencing a void pointer 1 2 void g(int n) {} 3 void f(void *p) 4 { 5 g(*p); 6 } 7 int main() 8 { 9 f(0); 10 return 0; 11 } 12 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: indirection of a pointer to void --- Expected compilation errors: 1 ,check-prog.c:5: __error__: indirection of a pointer to void ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 52: Use of a struct as an r-value 1 2 struct Inner { int n; }; 3 struct Outer { struct Inner i; }; 4 int main() 5 { 6 struct Outer obj; 7 if (obj) 8 return 1; 9 while (obj) 10 return 4; 11 for ( ; obj ; ) {} 12 if (obj.i) 13 return 2; 14 while (obj.i) 15 return 5; 16 if (!obj.i) 17 return 3; 18 while (!obj.i) 19 return 6; 20 return 0; 21 } 22 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:16: __error__: invalid use of boolean negation on a struct 2 ,check-prog.c:18: __error__: invalid use of boolean negation on a struct 3 ,check-prog.c:7: __error__: invalid use of struct as condition of if statement 4 ,check-prog.c:9: __error__: invalid use of struct as condition of while statement 5 ,check-prog.c:11: __error__: invalid use of struct as condition of for statement 6 ,check-prog.c:12: __error__: invalid use of struct as condition of if statement 7 ,check-prog.c:14: __error__: invalid use of struct as condition of while statement --- Expected compilation errors: 1 ,check-prog.c:16: __error__: invalid use of boolean negation on a struct 2 ,check-prog.c:18: __error__: invalid use of boolean negation on a struct 3 ,check-prog.c:7: __error__: invalid use of struct as condition of if statement 4 ,check-prog.c:9: __error__: invalid use of struct as condition of while statement 5 ,check-prog.c:11: __error__: invalid use of struct as condition of for statement 6 ,check-prog.c:12: __error__: invalid use of struct as condition of if statement 7 ,check-prog.c:14: __error__: invalid use of struct as condition of while statement ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 53: Anonymous struct 1 2 struct { int n; } a; 3 int main() 4 { 5 int *pi = &a; 6 return 0; 7 } 8 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: initializing int * with expression of type struct AnonStruct_,check-prog.c:2 * --- Expected compilation errors: 1 ,check-prog.c:5: __error__: initializing int * with expression of type struct AnonStruct_,check-prog.c:2 * ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 54: goto and ID-labeled statements 1 2 void f() 3 { 4 foo: ; // ok 5 bar: ; 6 } 7 int main() 8 { 9 foo: 10 foo: 11 f(); 12 goto bar; 13 goto imaginary; 14 return 0; 15 } 16 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:10: __error__: label `foo' already defined at ,check-prog.c:9 2 ,check-prog.c:12: __error__: goto targets label `bar' which is unknown to function main() 3 ,check-prog.c:13: __error__: goto targets label `imaginary' which is unknown to function main() --- Expected compilation errors: 1 ,check-prog.c:10: __error__: label `foo' already defined at ,check-prog.c:9 2 ,check-prog.c:12: __error__: goto targets label `bar' which is unknown to function main() 3 ,check-prog.c:13: __error__: goto targets label `imaginary' which is unknown to function main() ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 55: Conditional with incompatible types 1 2 void g(int) {} 3 int main() 4 { 5 char *p; 6 int i; 7 g(i > 0 ? p : i); 8 g(i > 0 ? (char) 0x12 : i); 9 unsigned char ub = 42; 10 g(i > 0 ? 256 : ub); // warning because 256 is signed 11 unsigned ui = 4242; 12 g(i > 0 ? 256U : ui); // no warning 13 return 0; 14 } 15 char a[] = { 1, 2, 3 }; 16 char *getArray() { return a; } 17 char f(char condition) 18 { 19 char *p = (condition ? getArray() : a); // OK because char * and char[] are close enough 20 return *p; 21 } 22 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:7: __error__: true and false expressions of conditional are of incompatible types (char * vs int) 2 ,check-prog.c:8: __warning__: true and false expressions of conditional are not of the same type (char vs int); result is of type int 3 ,check-prog.c:10: __warning__: true and false expressions of conditional are not of the same type (int vs unsigned char); result is of type int --- Expected compilation errors: 1 ,check-prog.c:7: __error__: true and false expressions of conditional are of incompatible types (char * vs int) 2 ,check-prog.c:8: __warning__: true and false expressions of conditional are not of the same type (char vs int); result is of type int 3 ,check-prog.c:10: __warning__: true and false expressions of conditional are not of the same type (int vs unsigned char); result is of type int ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 56: Automatic type conversions 1 2 unsigned char returnByte(unsigned char b) 3 { 4 return b; 5 } 6 int main() 7 { 8 int i = 1000; 9 char c; 10 c = i; 11 c = 2000; 12 unsigned u = 1001; 13 unsigned char uc; 14 uc = u; 15 uc = 2001; 16 17 u = 100; 18 u = (u > 99 ? 50 : u); 19 unsigned char b = 12; 20 u = (u > 66 ? u : returnByte(b)); 21 u = 999; 22 u = (u < 2000 ? u : returnByte(b)); 23 return 0; 24 } 25 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:10: __warning__: assigning to `char' from larger type `int' 2 ,check-prog.c:11: __warning__: assigning to `char' from larger constant of type `int' 3 ,check-prog.c:14: __warning__: assigning to `unsigned char' from larger type `unsigned int' 4 ,check-prog.c:15: __warning__: assigning to `unsigned char' from larger constant of type `int' 5 ,check-prog.c:18: __warning__: true and false expressions of conditional are not of the same type (int vs unsigned int); result is of type int 6 ,check-prog.c:20: __warning__: true and false expressions of conditional are not of the same type (unsigned int vs unsigned char); result is of type unsigned int 7 ,check-prog.c:22: __warning__: true and false expressions of conditional are not of the same type (unsigned int vs unsigned char); result is of type unsigned int --- Expected compilation errors: 1 ,check-prog.c:10: __warning__: assigning to `char' from larger type `int' 2 ,check-prog.c:11: __warning__: assigning to `char' from larger constant of type `int' 3 ,check-prog.c:14: __warning__: assigning to `unsigned char' from larger type `unsigned int' 4 ,check-prog.c:15: __warning__: assigning to `unsigned char' from larger constant of type `int' 5 ,check-prog.c:18: __warning__: true and false expressions of conditional are not of the same type (int vs unsigned int); result is of type int 6 ,check-prog.c:20: __warning__: true and false expressions of conditional are not of the same type (unsigned int vs unsigned char); result is of type unsigned int 7 ,check-prog.c:22: __warning__: true and false expressions of conditional are not of the same type (unsigned int vs unsigned char); result is of type unsigned int ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 57: Wrong use of assignment operator with structs 1 2 struct S { int i; }; 3 struct Other {} other; 4 void f(char *, ...) {} 5 int main() 6 { 7 struct S s, t; 8 int i; 9 s = 'x'; 10 s = i; 11 s = &i; 12 i = s; 13 s += t; 14 f("", s = t); 15 struct S u = 42; 16 struct S v = other; 17 struct S w = &other; 18 return 0; 19 } 20 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:9: __error__: cannot assign `char' to `struct S' 2 ,check-prog.c:10: __error__: cannot assign `int' to `struct S' 3 ,check-prog.c:11: __error__: cannot assign `int *' to `struct S' 4 ,check-prog.c:12: __error__: cannot assign `struct S' to `int' 5 ,check-prog.c:13: __error__: invalid use of += on a struct or union 6 ,check-prog.c:15: __error__: initializer for struct S is of type `int': must be list, or struct of same type 7 ,check-prog.c:16: __error__: initializer for struct S is of type `struct Other': must be list, or struct of same type 8 ,check-prog.c:17: __error__: initializer for struct S is of type `struct Other *': must be list, or struct of same type --- Expected compilation errors: 1 ,check-prog.c:9: __error__: cannot assign `char' to `struct S' 2 ,check-prog.c:10: __error__: cannot assign `int' to `struct S' 3 ,check-prog.c:11: __error__: cannot assign `int *' to `struct S' 4 ,check-prog.c:12: __error__: cannot assign `struct S' to `int' 5 ,check-prog.c:13: __error__: invalid use of += on a struct or union 6 ,check-prog.c:15: __error__: initializer for struct S is of type `int': must be list, or struct of same type 7 ,check-prog.c:16: __error__: initializer for struct S is of type `struct Other': must be list, or struct of same type 8 ,check-prog.c:17: __error__: initializer for struct S is of type `struct Other *': must be list, or struct of same type ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 58: Static keyword 1 2 static int g0; // equivalent to "int g0;" 3 int g0; // duplicates previous declaration 4 int g1; 5 static int g1; // duplicates previous declaration 6 static int g2; 7 extern int g2; // no problem: entire line is ignored 8 int main() 9 { 10 extern int g3; // ignored 11 static int g4; // local static not supported 12 g4 = 1; 13 return 0; 14 } 15 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:3: __error__: global variable `g0' already declared at global scope at ,check-prog.c:2 2 ,check-prog.c:5: __error__: global variable `g1' already declared at global scope at ,check-prog.c:4 3 ,check-prog.c:11: __error__: local static variables are not supported --- Expected compilation errors: 1 ,check-prog.c:3: __error__: global variable `g0' already declared at global scope at ,check-prog.c:2 2 ,check-prog.c:5: __error__: global variable `g1' already declared at global scope at ,check-prog.c:4 3 ,check-prog.c:11: __error__: local static variables are not supported ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 59: More than one formal parameter with same name 1 2 void f1(int a, int b, int a); 3 void f2(int a, int b, int a) {} 4 void f3(int a, int, char a) {} 5 void f4(int, int, char); // OK 6 int main() 7 { 8 return 0; 9 } 10 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: function f1() has more than one formal parameter named 'a' 2 ,check-prog.c:3: __error__: function f2() has more than one formal parameter named 'a' 3 ,check-prog.c:4: __error__: function f3() has more than one formal parameter named 'a' --- Expected compilation errors: 1 ,check-prog.c:2: __error__: function f1() has more than one formal parameter named 'a' 2 ,check-prog.c:3: __error__: function f2() has more than one formal parameter named 'a' 3 ,check-prog.c:4: __error__: function f3() has more than one formal parameter named 'a' ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 60: Returning wrong struct pointer type 1 2 struct A {}; 3 struct B {} b; 4 struct A *f() 5 { 6 return &b; 7 } 8 int main() 9 { 10 return f() != 0; 11 } 12 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:6: __error__: returning expression of type struct B *, which differs from function's return type (struct A *) --- Expected compilation errors: 1 ,check-prog.c:6: __error__: returning expression of type struct B *, which differs from function's return type (struct A *) ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 61: Bad type specifier combinations 1 2 int main() 3 { 4 int char x; 5 signed void p; 6 return 0; 7 } 8 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: combining type specifiers is not supported 2 ,check-prog.c:5: __error__: signed and unsigned modifiers can only be applied to integral type --- Expected compilation errors: 1 ,check-prog.c:4: __error__: combining type specifiers is not supported 2 ,check-prog.c:5: __error__: signed and unsigned modifiers can only be applied to integral type ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 62: Typedef local to a function 1 2 int main() 3 { 4 typedef int Integer; 5 Integer n = 42; 6 return n; 7 } 8 This test is suspended. ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 63: enum 1 2 enum A { A0 }; 3 enum A { A1 }; // error: 'A' already used 4 5 enum B { DuplicateEnumeratedName }; 6 7 8 void f0(enum { EnumNameInFunctionParam } e) {} // error: enumerator in formal param not supported 9 void f5(enum { OtherEnumNameInFunctionParam } e); // error: same, but on prototype 10 11 enum { EnumNameInReturnType } f1() { return 0; } // error: enumerator in return type 12 enum { OtherEnumNameInReturnType } f2(); // error: same, but on prototype 13 14 enum D { D0 }; 15 enum D f3() { return D0; } // ok 16 enum D f4(); // ok 17 18 signed enum F { F0 } f0; 19 20 void funcTakingA(enum A a) {} 21 22 int main() 23 { 24 enum { X } localEnumVar; 25 enum E { E0 } otherLocalEnumVar; 26 funcTakingA(A0); // ok 27 funcTakingA(5); // error: 5 not member of enum A 28 funcTakingA(D0); // error: D0 not member of enum A 29 return 0; 30 } 31 enum C { DuplicateEnumeratedName }; // error re: enum B 32 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:3: __error__: enum `A' already defined at ,check-prog.c:2 2 ,check-prog.c:8: __error__: enum with enumerated names is not supported in a function's formal parameter 3 ,check-prog.c:9: __error__: enum with enumerated names is not supported in a function's formal parameter 4 ,check-prog.c:11: __error__: enum with enumerated names is not supported in a function's return type 5 ,check-prog.c:12: __error__: enum with enumerated names is not supported in a function prototype's return type 6 ,check-prog.c:18: __error__: signed and unsigned modifiers cannot be applied to an enum 7 ,check-prog.c:31: __error__: enumerated name `DuplicateEnumeratedName' already defined at ,check-prog.c:5 --- Expected compilation errors: 1 ,check-prog.c:3: __error__: enum `A' already defined at ,check-prog.c:2 2 ,check-prog.c:8: __error__: enum with enumerated names is not supported in a function's formal parameter 3 ,check-prog.c:9: __error__: enum with enumerated names is not supported in a function's formal parameter 4 ,check-prog.c:11: __error__: enum with enumerated names is not supported in a function's return type 5 ,check-prog.c:12: __error__: enum with enumerated names is not supported in a function prototype's return type 6 ,check-prog.c:18: __error__: signed and unsigned modifiers cannot be applied to an enum 7 ,check-prog.c:31: __error__: enumerated name `DuplicateEnumeratedName' already defined at ,check-prog.c:5 ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 64: enum, bis 1 2 enum A { A0 }; 3 4 enum D { D0 }; 5 enum D f3() { return D0; } // ok 6 enum D f4(); // ok 7 8 void funcTakingA(enum A a) {} 9 10 int main() 11 { 12 enum { X } localEnumVar; 13 enum E { E0 } otherLocalEnumVar; 14 funcTakingA(A0); // ok 15 funcTakingA(5); // error: 5 not member of enum A 16 funcTakingA(D0); // error: D0 not member of enum A 17 return 0; 18 } 19 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:15: __error__: parameter 1 of function funcTakingA() must be a member of enum A 2 ,check-prog.c:16: __error__: `D0' used as parameter 1 of function funcTakingA() but is not a member of enum A 3 ,check-prog.c:12: __error__: non-global enum not supported 4 ,check-prog.c:13: __error__: non-global enum not supported --- Expected compilation errors: 1 ,check-prog.c:15: __error__: parameter 1 of function funcTakingA() must be a member of enum A 2 ,check-prog.c:16: __error__: `D0' used as parameter 1 of function funcTakingA() but is not a member of enum A 3 ,check-prog.c:12: __error__: non-global enum not supported 4 ,check-prog.c:13: __error__: non-global enum not supported ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 65: Declaring an enum variable without the enum keyword 1 2 enum E { E0 }; 3 E e; // error 4 int main() 5 { 6 return 0; 7 } 8 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:3: __error__: syntax error: E --- Expected compilation errors: 1 ,check-prog.c:3: __error__: syntax error: E ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 66: String numerical escape sequence out of range 1 2 int main() 3 { 4 char *s0 = "\x80bomber"; // error: $80b > 255 5 char *s1 = "zzz\0777zzz"; // error: 0777 > 255 6 return 0; 7 } 8 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __warning__: hex escape sequence out of range 2 ,check-prog.c:5: __warning__: octal escape sequence out of range --- Expected compilation errors: 1 ,check-prog.c:4: __warning__: hex escape sequence out of range 2 ,check-prog.c:5: __warning__: octal escape sequence out of range ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 67: Named argument required before ellipsis of variadic function declaration or definition 1 2 void functionWithNoNamedArg(...) {} 3 void prototypeWithNoNamedArg(...); 4 int main() 5 { 6 return 0; 7 } 8 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: function functionWithNoNamedArg() uses `...' but has no named argument before it 2 ,check-prog.c:3: __error__: prototype prototypeWithNoNamedArg() uses `...' but has no named argument before it --- Expected compilation errors: 1 ,check-prog.c:2: __error__: function functionWithNoNamedArg() uses `...' but has no named argument before it 2 ,check-prog.c:3: __error__: prototype prototypeWithNoNamedArg() uses `...' but has no named argument before it ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 68: Named argument required before ellipsis of variadic function pointer variable 1 2 int main() 3 { 4 void (*fp)(...); 5 return 0; 6 } 7 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: named argument is required before `...' --- Expected compilation errors: 1 ,check-prog.c:4: __error__: named argument is required before `...' ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 69: l-value required for some operators 1 2 void f(unsigned *n) {} 3 char g() { return 1; } 4 int *h() { return 0; } 5 int main() 6 { 7 unsigned n = 891; 8 f(&(n >> 1)); 9 ++(n >> 1); 10 --(n >> 1); 11 (n >> 1)++; 12 (n >> 1)--; 13 char a, b; 14 (g() ? a : b) = 42; // OK because both alternatives are l-values 15 (g() ? a : 99) = 42; 16 (g() ? 99 : b) = 42; 17 h()[0] = 0; // OK 18 *h() = 0; // OK 19 ((int *) 0x400)[32] = 0; // OK 20 return 0; 21 } 22 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:8: __error__: lvalue required as operand of address-of 2 ,check-prog.c:9: __error__: lvalue required as operand of pre-increment 3 ,check-prog.c:10: __error__: lvalue required as operand of pre-decrement 4 ,check-prog.c:11: __error__: lvalue required as operand of post-increment 5 ,check-prog.c:12: __error__: lvalue required as operand of post-decrement 6 ,check-prog.c:15: __error__: lvalue required as left operand of assignment 7 ,check-prog.c:16: __error__: lvalue required as left operand of assignment --- Expected compilation errors: 1 ,check-prog.c:8: __error__: lvalue required as operand of address-of 2 ,check-prog.c:9: __error__: lvalue required as operand of pre-increment 3 ,check-prog.c:10: __error__: lvalue required as operand of pre-decrement 4 ,check-prog.c:11: __error__: lvalue required as operand of post-increment 5 ,check-prog.c:12: __error__: lvalue required as operand of post-decrement 6 ,check-prog.c:15: __error__: lvalue required as left operand of assignment 7 ,check-prog.c:16: __error__: lvalue required as left operand of assignment ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 70: Various array errors 1 2 int main() 3 { 4 int a0[]; 5 int a1[5][]; 6 int a3["foo"]; 7 int n = 5; 8 int a4[n]; 9 return 0; 10 } 11 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __error__: array a0: no size of first dimension, no initialization expression 2 ,check-prog.c:5: __error__: array a1: dimension other than first one is unspecified 3 ,check-prog.c:6: __error__: pointer or array expression used for size of array 'a3' 4 ,check-prog.c:8: __error__: invalid size expression for dimension 1 array 'a4' --- Expected compilation errors: 1 ,check-prog.c:4: __error__: array a0: no size of first dimension, no initialization expression 2 ,check-prog.c:5: __error__: array a1: dimension other than first one is unspecified 3 ,check-prog.c:6: __error__: pointer or array expression used for size of array 'a3' 4 ,check-prog.c:8: __error__: invalid size expression for dimension 1 array 'a4' ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 71: -Wsign-compare 1 2 char f(unsigned char uc, signed char sc) 3 { 4 if (uc < sc) 5 return 1; 6 if (uc <= sc) 7 return 2; 8 if (uc > sc) 9 return 3; 10 if (uc >= sc) 11 return 4; 12 if (sc < uc) 13 return 1; 14 if (sc <= uc) 15 return 2; 16 if (sc > uc) 17 return 3; 18 if (sc >= uc) 19 return 4; 20 if (uc >= uc) 21 return 5; 22 if (sc >= sc) 23 return 5; 24 return 0; 25 } 26 int main() 27 { 28 f(0, 0); 29 return 0; 30 } 31 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' -Wsign-compare ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __warning__: comparison of integers of different signs (`unsigned char' vs `char'); using unsigned comparison 2 ,check-prog.c:6: __warning__: comparison of integers of different signs (`unsigned char' vs `char'); using unsigned comparison 3 ,check-prog.c:8: __warning__: comparison of integers of different signs (`unsigned char' vs `char'); using unsigned comparison 4 ,check-prog.c:10: __warning__: comparison of integers of different signs (`unsigned char' vs `char'); using unsigned comparison 5 ,check-prog.c:12: __warning__: comparison of integers of different signs (`char' vs `unsigned char'); using unsigned comparison 6 ,check-prog.c:14: __warning__: comparison of integers of different signs (`char' vs `unsigned char'); using unsigned comparison 7 ,check-prog.c:16: __warning__: comparison of integers of different signs (`char' vs `unsigned char'); using unsigned comparison 8 ,check-prog.c:18: __warning__: comparison of integers of different signs (`char' vs `unsigned char'); using unsigned comparison --- Expected compilation errors: 1 ,check-prog.c:4: __warning__: comparison of integers of different signs (`unsigned char' vs `char'); using unsigned comparison 2 ,check-prog.c:6: __warning__: comparison of integers of different signs (`unsigned char' vs `char'); using unsigned comparison 3 ,check-prog.c:8: __warning__: comparison of integers of different signs (`unsigned char' vs `char'); using unsigned comparison 4 ,check-prog.c:10: __warning__: comparison of integers of different signs (`unsigned char' vs `char'); using unsigned comparison 5 ,check-prog.c:12: __warning__: comparison of integers of different signs (`char' vs `unsigned char'); using unsigned comparison 6 ,check-prog.c:14: __warning__: comparison of integers of different signs (`char' vs `unsigned char'); using unsigned comparison 7 ,check-prog.c:16: __warning__: comparison of integers of different signs (`char' vs `unsigned char'); using unsigned comparison 8 ,check-prog.c:18: __warning__: comparison of integers of different signs (`char' vs `unsigned char'); using unsigned comparison ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 72: Without -Wsign-compare 1 2 char f(unsigned char uc, signed char sc) 3 { 4 if (uc < sc) 5 return 1; 6 if (uc <= sc) 7 return 2; 8 if (uc > sc) 9 return 3; 10 if (uc >= sc) 11 return 4; 12 return 0; 13 } 14 int main() 15 { 16 f(0, 0); 17 return 0; 18 } 19 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: --- Expected compilation errors: ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 73: Invalid use of void expression 1 2 void f(int n) {} 3 int main() 4 { 5 char *cp; 6 cp[5] = 0; 7 void *vp; 8 vp[5] = 0; 9 *vp = 0; 10 f(vp[7]); 11 f(*vp); 12 return 0; 13 } 14 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:8: __error__: left side of operator = is of type void 2 ,check-prog.c:9: __error__: left side of operator = is of type void 3 ,check-prog.c:8: __error__: invalid use of void expression 4 ,check-prog.c:9: __error__: indirection of a pointer to void 5 ,check-prog.c:10: __error__: invalid use of void expression 6 ,check-prog.c:11: __error__: indirection of a pointer to void --- Expected compilation errors: 1 ,check-prog.c:8: __error__: left side of operator = is of type void 2 ,check-prog.c:9: __error__: left side of operator = is of type void 3 ,check-prog.c:8: __error__: invalid use of void expression 4 ,check-prog.c:9: __error__: indirection of a pointer to void 5 ,check-prog.c:10: __error__: invalid use of void expression 6 ,check-prog.c:11: __error__: indirection of a pointer to void ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 74: Too many or not enough elements in array initializer 1 2 struct S { int a[3]; char c; }; 3 int main() 4 { 5 int a0[3] = { 99, 88, 77, 66 }; 6 int a1[3] = { 99, 88 }; 7 char a2[3] = "foo"; // no room for terminating \0: error 8 char a3[3] = "foobar"; // worse 9 char a4[3] = "x"; // v2[2] not initialized: no warning 10 struct S s0 = { { 55, 44, 33, 22 }, '$' }; // too many ints: error 11 struct S s1 = { { 55, 44 }, '$' }; // not enough ints: warning 12 return 0; 13 } 14 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: too many elements (4) in initializer for array of 3 element(s) 2 ,check-prog.c:6: __warning__: only 2 element(s) in initializer for array of 3 element(s) 3 ,check-prog.c:7: __error__: too many characters (4) in string literal initializer for array of 3 character(s) 4 ,check-prog.c:8: __error__: too many characters (7) in string literal initializer for array of 3 character(s) 5 ,check-prog.c:10: __error__: too many elements (4) in initializer for array of 3 element(s) 6 ,check-prog.c:11: __warning__: only 2 element(s) in initializer for array of 3 element(s) --- Expected compilation errors: 1 ,check-prog.c:5: __error__: too many elements (4) in initializer for array of 3 element(s) 2 ,check-prog.c:6: __warning__: only 2 element(s) in initializer for array of 3 element(s) 3 ,check-prog.c:7: __error__: too many characters (4) in string literal initializer for array of 3 character(s) 4 ,check-prog.c:8: __error__: too many characters (7) in string literal initializer for array of 3 character(s) 5 ,check-prog.c:10: __error__: too many elements (4) in initializer for array of 3 element(s) 6 ,check-prog.c:11: __warning__: only 2 element(s) in initializer for array of 3 element(s) ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 75: Warning option for when assing a numerical constant for a function's pointer parameter 1 2 void f(char *p) {} 3 int main() 4 { 5 f(42); 6 f(0); // no warning 7 return 0; 8 } 9 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' -Wpass-const-for-func-pointer ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __warning__: passing constant as parameter 1 of function f(), which is char * --- Expected compilation errors: 1 ,check-prog.c:5: __warning__: passing constant as parameter 1 of function f(), which is char * ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 76: No warning by default when assing a numerical constant for a function's pointer parameter 1 2 void f(char *p) {} 3 int main() 4 { 5 f(42); 6 f(0); 7 return 0; 8 } 9 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: --- Expected compilation errors: ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 77: Unknown enumerator name used to define an enumerator 1 2 enum { B = A + 1 }; 3 int main() 4 { 5 return B; 6 } 7 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: unknown enumerator `A' --- Expected compilation errors: 1 ,check-prog.c:2: __error__: unknown enumerator `A' ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 78: Return value of a void function must be ignored 1 2 void f() {} 3 int main() 4 { 5 if (f() == 0) 6 return 1; 7 if (0 == f()) 8 return 1; 9 if (- f()) 10 return 1; 11 if (! f()) 12 return 1; 13 if (* f()) 14 return 1; 15 if (& f()) 16 return 1; 17 if (~ f()) 18 return 1; 19 return f(); 20 } 21 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:5: __error__: left side of operator == is of type void 2 ,check-prog.c:7: __error__: right side of operator == is of type void 3 ,check-prog.c:9: __error__: argument of arithmetic negation operator is of type void 4 ,check-prog.c:11: __error__: argument of boolean negation operator is of type void 5 ,check-prog.c:13: __error__: argument of indirection operator is of type void 6 ,check-prog.c:15: __error__: argument of address-of operator is of type void 7 ,check-prog.c:17: __error__: argument of bitwise not operator is of type void 8 ,check-prog.c:19: __error__: returning expression of type void, which differs from function's return type (int) --- Expected compilation errors: 1 ,check-prog.c:5: __error__: left side of operator == is of type void 2 ,check-prog.c:7: __error__: right side of operator == is of type void 3 ,check-prog.c:9: __error__: argument of arithmetic negation operator is of type void 4 ,check-prog.c:11: __error__: argument of boolean negation operator is of type void 5 ,check-prog.c:13: __error__: argument of indirection operator is of type void 6 ,check-prog.c:15: __error__: argument of address-of operator is of type void 7 ,check-prog.c:17: __error__: argument of bitwise not operator is of type void 8 ,check-prog.c:19: __error__: returning expression of type void, which differs from function's return type (int) ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 79: Function name used where function pointer pointer expected 1 2 typedef char (*FuncPtrType)(); 3 struct S1 4 { 5 FuncPtrType *funcPtrPtr; // pointer to pointer to function 6 }; 7 char f() { return 0; } // of type FuncPtrType 8 int main() 9 { 10 struct S1 s1 = { f }; // error: assigning void * to pointer to pointer to function 11 return 0; 12 } 13 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:10: __error__: initializing void ** with expression of type void * --- Expected compilation errors: 1 ,check-prog.c:10: __error__: initializing void ** with expression of type void * ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 80: Array of function pointers 1 2 char (*f0)()[]; 3 char (*f1)()[2]; 4 char (*f2)()[2][3]; 5 char (*g0[])(); 6 char (*g1[2])(); 7 char (*g2[2][3])(); 8 int main() 9 { 10 return 0; 11 } 12 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: subscript on function pointer declarator not supported 2 ,check-prog.c:3: __error__: subscript on function pointer declarator not supported 3 ,check-prog.c:4: __error__: subscript on function pointer declarator not supported 4 ,check-prog.c:4: __error__: subscript on function pointer declarator not supported 5 ,check-prog.c:5: __error__: subscript on function pointer declarator not supported 6 ,check-prog.c:6: __error__: subscript on function pointer declarator not supported 7 ,check-prog.c:7: __error__: subscript on function pointer declarator not supported --- Expected compilation errors: 1 ,check-prog.c:2: __error__: subscript on function pointer declarator not supported 2 ,check-prog.c:3: __error__: subscript on function pointer declarator not supported 3 ,check-prog.c:4: __error__: subscript on function pointer declarator not supported 4 ,check-prog.c:4: __error__: subscript on function pointer declarator not supported 5 ,check-prog.c:5: __error__: subscript on function pointer declarator not supported 6 ,check-prog.c:6: __error__: subscript on function pointer declarator not supported 7 ,check-prog.c:7: __error__: subscript on function pointer declarator not supported ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 81: Instruction argument refers to undeclared variable or enumerator 1 2 int main() 3 { 4 for (;;) // check that asm{} works in a sub-scope of the function scope 5 { 6 char *pc; 7 asm { 8 stu :y // error: y not defined 9 stu :foo // error: foo not defined 10 std :pc // no error: variable 'pc' declared 11 inc : // error: variable name is empty 12 } 13 break; 14 } 15 asm { clr :ch } // error: ch not declared yet 16 char ch; 17 return 0; 18 } 19 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:7: __error__: undeclared identifier `' in assembly language statement 2 ,check-prog.c:7: __error__: undeclared identifier `foo' in assembly language statement 3 ,check-prog.c:7: __error__: undeclared identifier `y' in assembly language statement 4 ,check-prog.c:15: __error__: undeclared identifier `ch' in assembly language statement --- Expected compilation errors: 1 ,check-prog.c:7: __error__: undeclared identifier `' in assembly language statement 2 ,check-prog.c:7: __error__: undeclared identifier `foo' in assembly language statement 3 ,check-prog.c:7: __error__: undeclared identifier `y' in assembly language statement 4 ,check-prog.c:15: __error__: undeclared identifier `ch' in assembly language statement ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 82: Function without formal parameters 1 2 void f {} 3 int main 4 { 5 return 0; 6 } 7 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: function f() has no formal parameter list 2 ,check-prog.c:3: __error__: function main() has no formal parameter list --- Expected compilation errors: 1 ,check-prog.c:2: __error__: function f() has no formal parameter list 2 ,check-prog.c:3: __error__: function main() has no formal parameter list ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 83: Argument too large for function parameter 1 2 char takeChar(char x) { return x; } 3 unsigned char takeUnsignedChar(unsigned char x) { return x; } 4 int main() 5 { 6 char c = takeChar(0x1234); 7 c = takeChar(0x12F0); 8 unsigned char uc = takeUnsignedChar(0x1256); 9 uc = takeUnsignedChar(0x12F8); 10 return 0; 11 } 12 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:6: __warning__: passing `int' argument as `char' parameter 1 ('x') of function takeChar() 2 ,check-prog.c:7: __warning__: passing `int' argument as `char' parameter 1 ('x') of function takeChar() 3 ,check-prog.c:8: __warning__: passing `int' argument as `unsigned char' parameter 1 ('x') of function takeUnsignedChar() 4 ,check-prog.c:9: __warning__: passing `int' argument as `unsigned char' parameter 1 ('x') of function takeUnsignedChar() --- Expected compilation errors: 1 ,check-prog.c:6: __warning__: passing `int' argument as `char' parameter 1 ('x') of function takeChar() 2 ,check-prog.c:7: __warning__: passing `int' argument as `char' parameter 1 ('x') of function takeChar() 3 ,check-prog.c:8: __warning__: passing `int' argument as `unsigned char' parameter 1 ('x') of function takeUnsignedChar() 4 ,check-prog.c:9: __warning__: passing `int' argument as `unsigned char' parameter 1 ('x') of function takeUnsignedChar() ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 84: Float 1 2 int main() 3 { 4 float f; // warning on 'float' when compiling for USim 5 double d; 6 float *pf; 7 f = pf; 8 pf = f; 9 f = (float) pf; 10 pf = (float *) f; 11 return 0; 12 } 13 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __warning__: floating-point arithmetic is not supported on this platform 2 ,check-prog.c:5: __warning__: `double' is an alias for `float' for this compiler 3 ,check-prog.c:7: __error__: cannot assign `float *' to `float' 4 ,check-prog.c:8: __error__: cannot assign `float' to `float *' 5 ,check-prog.c:9: __error__: cannot cast `float *' to `float' 6 ,check-prog.c:10: __error__: cannot cast `float' to `float *' --- Expected compilation errors: 1 ,check-prog.c:4: __warning__: floating-point arithmetic is not supported on this platform 2 ,check-prog.c:5: __warning__: `double' is an alias for `float' for this compiler 3 ,check-prog.c:7: __error__: cannot assign `float *' to `float' 4 ,check-prog.c:8: __error__: cannot assign `float' to `float *' 5 ,check-prog.c:9: __error__: cannot cast `float *' to `float' 6 ,check-prog.c:10: __error__: cannot cast `float' to `float *' ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 85: Floating-point arithmetic 1 2 int main() 3 { 4 signed float sf; 5 unsigned float uf; 6 signed double sd; 7 unsigned double ud; 8 return 0; 9 } 10 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:4: __warning__: floating-point arithmetic is not supported on this platform 2 ,check-prog.c:4: __error__: signed and unsigned modifiers can only be applied to integral type 3 ,check-prog.c:5: __error__: signed and unsigned modifiers can only be applied to integral type 4 ,check-prog.c:6: __warning__: `double' is an alias for `float' for this compiler 5 ,check-prog.c:6: __error__: signed and unsigned modifiers can only be applied to integral type 6 ,check-prog.c:7: __error__: signed and unsigned modifiers can only be applied to integral type --- Expected compilation errors: 1 ,check-prog.c:4: __warning__: floating-point arithmetic is not supported on this platform 2 ,check-prog.c:4: __error__: signed and unsigned modifiers can only be applied to integral type 3 ,check-prog.c:5: __error__: signed and unsigned modifiers can only be applied to integral type 4 ,check-prog.c:6: __warning__: `double' is an alias for `float' for this compiler 5 ,check-prog.c:6: __error__: signed and unsigned modifiers can only be applied to integral type 6 ,check-prog.c:7: __error__: signed and unsigned modifiers can only be applied to integral type ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 86: Uncalled static function Test skipped because excluded from monolith mode ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 87: Function with both static and extern modifiers 1 2 extern static void f() {} 3 int main() 4 { 5 f(); 6 return 0; 7 } 8 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: function definition must not be both static and extern --- Expected compilation errors: 1 ,check-prog.c:2: __error__: function definition must not be both static and extern ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### -------------------------------------------------------------------------------- --- Program # 88: static main() 1 2 static int main() 3 { 4 return 0; 5 } 6 --- Compilation command: ./cmoc --usim --monolith --a09='./a09' -I './support' ,check-prog.c --- Actual compilation errors: 1 ,check-prog.c:2: __error__: main() must not be static --- Expected compilation errors: 1 ,check-prog.c:2: __error__: main() must not be static ### ls ,check-prog.*: ,check-prog.bin ,check-prog.c ### Cleaning up: erasing ,check-prog.c erasing ,check-prog.bin ./test-bad-programs.pl: ALL 89 tests PASSED ### # # ### ### ##### ### ### # # # # # # # # # # # # # # # # # # # # # ### # # # # ### ### ### # # # # # # # # # # # # # # # # # # # # # ### ### ### ### ##### ### ### test-bad-programs.pl: 0 error(s), 0 warnings(s). make[2]: Leaving directory `/<>/src' Making check in macros make[2]: Entering directory `/<>/macros' make[2]: Nothing to be done for `check'. make[2]: Leaving directory `/<>/macros' Making check in doc make[2]: Entering directory `/<>/doc' make[2]: Nothing to be done for `check'. make[2]: Leaving directory `/<>/doc' make[2]: Entering directory `/<>' make[2]: Nothing to be done for `check-am'. make[2]: Leaving directory `/<>' make[1]: Leaving directory `/<>' fakeroot debian/rules binary-arch dh binary-arch --with autotools-dev dh_testroot -a dh_prep -a dh_installdirs -a dh_auto_install -a make[1]: Entering directory `/<>' Making install in src make[2]: Entering directory `/<>/src' Making install in support make[3]: Entering directory `/<>/src/support' Making install in vectrex make[4]: Entering directory `/<>/src/support/vectrex' make[5]: Entering directory `/<>/src/support/vectrex' make[5]: Nothing to be done for `install-exec-am'. /bin/mkdir -p '/<>/debian/cmoc/usr/share/cmoc/vectrex' /usr/bin/install -c -m 644 bios.h stdlib.h '/<>/debian/cmoc/usr/share/cmoc/vectrex' make[5]: Leaving directory `/<>/src/support/vectrex' make[4]: Leaving directory `/<>/src/support/vectrex' make[4]: Entering directory `/<>/src/support' make[5]: Entering directory `/<>/src/support' make[5]: Nothing to be done for `install-exec-am'. /bin/mkdir -p '/<>/debian/cmoc/usr/share/cmoc' /usr/bin/install -c -m 644 stdlib.inc stdlib-data.inc float-ecb.inc cmoc.h assert.h stdarg.h coco.h disk.h vectrex.h '/<>/debian/cmoc/usr/share/cmoc' make[5]: Leaving directory `/<>/src/support' make[4]: Leaving directory `/<>/src/support' make[3]: Leaving directory `/<>/src/support' Making install in usim-0.91-cmoc make[3]: Entering directory `/<>/src/usim-0.91-cmoc' make[4]: Entering directory `/<>/src/usim-0.91-cmoc' make[4]: Nothing to be done for `install-exec-am'. make[4]: Nothing to be done for `install-data-am'. make[4]: Leaving directory `/<>/src/usim-0.91-cmoc' make[3]: Leaving directory `/<>/src/usim-0.91-cmoc' Making install in . make[3]: Entering directory `/<>/src' make[4]: Entering directory `/<>/src' /bin/mkdir -p '/<>/debian/cmoc/usr/bin' /usr/bin/install -c cmoc writecocofile '/<>/debian/cmoc/usr/bin' /bin/mkdir -p '/<>/debian/cmoc/usr/bin' /usr/bin/install -c intelhex2cocobin intelhex2srec install-coco-boot-loader '/<>/debian/cmoc/usr/bin' /bin/mkdir -p '/<>/debian/cmoc/usr/share/cmoc' /usr/bin/install -c a09 '/<>/debian/cmoc/usr/share/cmoc' make[4]: Leaving directory `/<>/src' make[3]: Leaving directory `/<>/src' Making install in stdlib make[3]: Entering directory `/<>/src/stdlib' make[4]: Entering directory `/<>/src/stdlib' make[4]: Nothing to be done for `install-exec-am'. /bin/mkdir -p '/<>/debian/cmoc/usr/share/cmoc/include' /usr/bin/install -c -m 644 assert.h cmoc.h coco.h disk.h stdarg.h vectrex.h '/<>/debian/cmoc/usr/share/cmoc/include' /bin/mkdir -p '/<>/debian/cmoc/usr/share/cmoc/lib' /usr/bin/install -c -m 644 libcmoc-std-ecb.a libcmoc-std-usim.a '/<>/debian/cmoc/usr/share/cmoc/lib' make[4]: Leaving directory `/<>/src/stdlib' make[3]: Leaving directory `/<>/src/stdlib' Making install in float make[3]: Entering directory `/<>/src/float' make[4]: Entering directory `/<>/src/float' make[4]: Nothing to be done for `install-exec-am'. /bin/mkdir -p '/<>/debian/cmoc/usr/share/cmoc/lib' /usr/bin/install -c -m 644 libcmoc-float-ecb.a libcmoc-float-usim.a '/<>/debian/cmoc/usr/share/cmoc/lib' make[4]: Leaving directory `/<>/src/float' make[3]: Leaving directory `/<>/src/float' make[2]: Leaving directory `/<>/src' Making install in macros make[2]: Entering directory `/<>/macros' make[3]: Entering directory `/<>/macros' make[3]: Nothing to be done for `install-exec-am'. make[3]: Nothing to be done for `install-data-am'. make[3]: Leaving directory `/<>/macros' make[2]: Leaving directory `/<>/macros' Making install in doc make[2]: Entering directory `/<>/doc' make[3]: Entering directory `/<>/doc' make[3]: Nothing to be done for `install-exec-am'. /bin/mkdir -p '/<>/debian/cmoc/usr/share/man/man1' /usr/bin/install -c -m 644 cmoc.1 '/<>/debian/cmoc/usr/share/man/man1' make[3]: Leaving directory `/<>/doc' make[2]: Leaving directory `/<>/doc' make[2]: Entering directory `/<>' make[3]: Entering directory `/<>' make[3]: Nothing to be done for `install-exec-am'. /bin/mkdir -p '/<>/debian/cmoc/usr/share/doc/cmoc' /usr/bin/install -c -m 644 AUTHORS COPYING NEWS README THANKS '/<>/debian/cmoc/usr/share/doc/cmoc' make[3]: Leaving directory `/<>' make[2]: Leaving directory `/<>' make[1]: Leaving directory `/<>' dh_install -a dh_installdocs -a dh_installchangelogs -a dh_installexamples -a dh_installman -a dh_installcatalogs -a dh_installcron -a dh_installdebconf -a dh_installemacsen -a dh_installifupdown -a dh_installinfo -a dh_installinit -a dh_installmenu -a dh_installmime -a dh_installmodules -a dh_installlogcheck -a dh_installlogrotate -a dh_installpam -a dh_installppp -a dh_installudev -a dh_installwm -a dh_installxfonts -a dh_installgsettings -a dh_bugfiles -a dh_ucf -a dh_lintian -a dh_gconf -a dh_icons -a dh_perl -a dh_usrlocal -a dh_link -a dh_compress -a dh_fixperms -a debian/rules override_dh_strip make[1]: Entering directory `/<>' dh_strip -Xcmoc/lib dh_strip debug symbol extraction: disabling for PPA build dh_strip debug symbol extraction: not doing anything since NO_PKG_MANGLE is given make[1]: Leaving directory `/<>' dh_makeshlibs -a dh_shlibdeps -a dh_installdeb -a dh_gencontrol -a dpkg-gencontrol: warning: package cmoc: unused substitution variable ${perl:Depends} dh_gencontrol debug symbol wrapper: all non-arch-all packages for this build platform amd64: cmoc dh_gencontrol debug symbol wrapper: packages to act on: cmoc dh_gencontrol debug symbol wrapper: ignored packages: dh_gencontrol debug symbol wrapper: no debian/cmoc-dbgsym, skipping package cmoc dh_md5sums -a dh_builddeb -a INFO: pkgstriptranslations version 116 INFO: Disabling pkgstriptranslations for PPA build INFO: Disabling pkgmaintainermangler for PPA build INFO: Disabling pkgstripfiles for PPA build dpkg-deb: building package `cmoc' in `../cmoc_0.1.43-0~tormod1_amd64.deb'. dpkg-genchanges -B -mLaunchpad Build Daemon >../cmoc_0.1.43-0~tormod1_amd64.changes dpkg-genchanges: arch-specific upload - not including arch-independent packages dpkg-genchanges: binary-only upload - not including any source code dpkg-source --after-build cmoc-0.1.43 dpkg-buildpackage: binary only upload (no source included) -------------------------------------------------------------------------------- Build finished at 20171104-1031 Finished -------- I: Built successfully +------------------------------------------------------------------------------+ | Post Build Chroot | +------------------------------------------------------------------------------+ +------------------------------------------------------------------------------+ | Changes | +------------------------------------------------------------------------------+ cmoc_0.1.43-0~tormod1_amd64.changes: ------------------------------------ Format: 1.8 Date: Sat, 04 Nov 2017 11:24:28 +0100 Source: cmoc Binary: cmoc Architecture: amd64 Version: 0.1.43-0~tormod1 Distribution: precise Urgency: medium Maintainer: Launchpad Build Daemon Changed-By: Tormod Volden Description: cmoc - 6809-generating cross-compiler for a subset of the C language Changes: cmoc (0.1.43-0~tormod1) precise; urgency=medium . * debian/rules: Do not attempt to strip 6809 libraries Checksums-Sha1: ef1e48c8a947d6e0e7f08c719afc565f79207c38 488880 cmoc_0.1.43-0~tormod1_amd64.deb Checksums-Sha256: 443bccf62be2434d873d216da476f966e6216a0f3c3db01c9d89d432639f3048 488880 cmoc_0.1.43-0~tormod1_amd64.deb Files: 277782bf10316255334baf2c6247db86 488880 otherosfs optional cmoc_0.1.43-0~tormod1_amd64.deb +------------------------------------------------------------------------------+ | Package contents | +------------------------------------------------------------------------------+ cmoc_0.1.43-0~tormod1_amd64.deb ------------------------------- new debian package, version 2.0. size 488880 bytes: control archive=1594 bytes. 633 bytes, 14 lines control 2185 bytes, 35 lines md5sums Package: cmoc Version: 0.1.43-0~tormod1 Architecture: amd64 Maintainer: Tormod Volden Installed-Size: 1269 Depends: libc6 (>= 2.14), libgcc1 (>= 1:4.1.1), libstdc++6 (>= 4.6), lwtools Section: otherosfs Priority: optional Homepage: http://sarrazip.com/dev/cmoc.html Description: 6809-generating cross-compiler for a subset of the C language cmoc produces assembler code for the Motorola 6809 processor in the Intel HEX and Color Computer .BIN executable binary formats. It runs under GNU/Linux and probably also other Unix-like environments. It requires the LWTOOLS assembler (lwasm), by William Astle. drwxr-xr-x root/root 0 2017-11-04 10:31 ./ drwxr-xr-x root/root 0 2017-11-04 10:31 ./usr/ drwxr-xr-x root/root 0 2017-11-04 10:31 ./usr/bin/ -rwxr-xr-x root/root 835104 2017-11-04 10:31 ./usr/bin/cmoc -rwxr-xr-x root/root 6450 2017-11-04 10:31 ./usr/bin/install-coco-boot-loader -rwxr-xr-x root/root 3987 2017-11-04 10:31 ./usr/bin/intelhex2cocobin -rwxr-xr-x root/root 2455 2017-11-04 10:31 ./usr/bin/intelhex2srec -rwxr-xr-x root/root 39832 2017-11-04 10:31 ./usr/bin/writecocofile drwxr-xr-x root/root 0 2017-11-04 10:31 ./usr/share/ drwxr-xr-x root/root 0 2017-11-04 10:31 ./usr/share/cmoc/ -rwxr-xr-x root/root 14405 2017-11-04 10:31 ./usr/share/cmoc/a09 -rw-r--r-- root/root 442 2017-11-04 10:31 ./usr/share/cmoc/assert.h -rw-r--r-- root/root 6414 2017-11-04 10:31 ./usr/share/cmoc/cmoc.h -rw-r--r-- root/root 16844 2017-11-04 10:31 ./usr/share/cmoc/coco.h -rw-r--r-- root/root 18864 2017-11-04 10:31 ./usr/share/cmoc/disk.h -rw-r--r-- root/root 36030 2017-11-04 10:31 ./usr/share/cmoc/float-ecb.inc drwxr-xr-x root/root 0 2017-11-04 10:31 ./usr/share/cmoc/include/ -rw-r--r-- root/root 442 2017-11-04 10:31 ./usr/share/cmoc/include/assert.h -rw-r--r-- root/root 6182 2017-11-04 10:31 ./usr/share/cmoc/include/cmoc.h -rw-r--r-- root/root 8403 2017-11-04 10:31 ./usr/share/cmoc/include/coco.h -rw-r--r-- root/root 4982 2017-11-04 10:31 ./usr/share/cmoc/include/disk.h -rw-r--r-- root/root 498 2017-11-04 10:31 ./usr/share/cmoc/include/stdarg.h -rw-r--r-- root/root 427 2017-11-04 10:31 ./usr/share/cmoc/include/vectrex.h drwxr-xr-x root/root 0 2017-11-04 10:31 ./usr/share/cmoc/lib/ -rw-r--r-- root/root 12613 2017-11-04 10:31 ./usr/share/cmoc/lib/libcmoc-float-ecb.a -rw-r--r-- root/root 12680 2017-11-04 10:31 ./usr/share/cmoc/lib/libcmoc-float-usim.a -rw-r--r-- root/root 39245 2017-11-04 10:31 ./usr/share/cmoc/lib/libcmoc-std-ecb.a -rw-r--r-- root/root 24377 2017-11-04 10:31 ./usr/share/cmoc/lib/libcmoc-std-usim.a -rw-r--r-- root/root 1171 2017-11-04 10:31 ./usr/share/cmoc/stdarg.h -rw-r--r-- root/root 1643 2017-11-04 10:31 ./usr/share/cmoc/stdlib-data.inc -rw-r--r-- root/root 108197 2017-11-04 10:31 ./usr/share/cmoc/stdlib.inc -rw-r--r-- root/root 427 2017-11-04 10:31 ./usr/share/cmoc/vectrex.h drwxr-xr-x root/root 0 2017-11-04 10:31 ./usr/share/cmoc/vectrex/ -rw-r--r-- root/root 12608 2017-11-04 10:31 ./usr/share/cmoc/vectrex/bios.h -rw-r--r-- root/root 411 2017-11-04 10:31 ./usr/share/cmoc/vectrex/stdlib.h drwxr-xr-x root/root 0 2017-11-04 10:31 ./usr/share/doc/ drwxr-xr-x root/root 0 2017-11-04 10:31 ./usr/share/doc/cmoc/ -rw-r--r-- root/root 203 2017-11-04 10:31 ./usr/share/doc/cmoc/AUTHORS -rw-r--r-- root/root 12223 2017-11-04 10:31 ./usr/share/doc/cmoc/COPYING.gz -rw-r--r-- root/root 14831 2017-11-02 23:52 ./usr/share/doc/cmoc/NEWS.gz -rw-r--r-- root/root 549 2015-11-14 18:58 ./usr/share/doc/cmoc/README -rw-r--r-- root/root 22 2017-11-04 10:31 ./usr/share/doc/cmoc/THANKS -rw-r--r-- root/root 648 2017-11-04 10:26 ./usr/share/doc/cmoc/changelog.Debian.gz -rw-r--r-- root/root 1098 2016-03-03 19:16 ./usr/share/doc/cmoc/copyright drwxr-xr-x root/root 0 2017-11-04 10:31 ./usr/share/man/ drwxr-xr-x root/root 0 2017-11-04 10:31 ./usr/share/man/man1/ -rw-r--r-- root/root 885 2017-11-04 10:31 ./usr/share/man/man1/cmoc.1.gz +------------------------------------------------------------------------------+ | Post Build | +------------------------------------------------------------------------------+ +------------------------------------------------------------------------------+ | Cleanup | +------------------------------------------------------------------------------+ Purging /<> Not removing build depends: as requested +------------------------------------------------------------------------------+ | Summary | +------------------------------------------------------------------------------+ Build Architecture: amd64 Build-Space: 53208 Build-Time: 116 Distribution: precise Host Architecture: amd64 Install-Time: 7 Job: cmoc_0.1.43-0~tormod1.dsc Machine Architecture: amd64 Package: cmoc Package-Time: 125 Source-Version: 0.1.43-0~tormod1 Space: 53208 Status: successful Version: 0.1.43-0~tormod1 -------------------------------------------------------------------------------- Finished at 20171104-1031 Build needed 00:02:05, 53208k disc space RUN: /usr/share/launchpad-buildd/slavebin/in-target scan-for-processes --backend=chroot --series=precise --arch=amd64 PACKAGEBUILD-13675837 Scanning for processes to kill in build PACKAGEBUILD-13675837 RUN: /usr/share/launchpad-buildd/slavebin/in-target umount-chroot --backend=chroot --series=precise --arch=amd64 PACKAGEBUILD-13675837 Stopping target for build PACKAGEBUILD-13675837 RUN: /usr/share/launchpad-buildd/slavebin/in-target remove-build --backend=chroot --series=precise --arch=amd64 PACKAGEBUILD-13675837 Removing build PACKAGEBUILD-13675837