Mercurial > hg > CbC > CbC_gcc
changeset 69:1b10fe6932e1
merge 69
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 21 Aug 2011 07:53:12 +0900 |
parents | b362627d71ba (diff) 561a7518be6b (current diff) |
children | b81903832de2 |
files | .hgtags INSTALL/binaries.html INSTALL/build.html INSTALL/configure.html INSTALL/download.html INSTALL/finalinstall.html INSTALL/gfdl.html INSTALL/index.html INSTALL/old.html INSTALL/prerequisites.html INSTALL/specific.html INSTALL/test.html NEWS config/mh-ppc-darwin configure contrib/gccbug.el fixincludes/tests/base/sys/limits.h fixincludes/tests/base/wchar.h gcc/Makefile.in gcc/aclocal.m4 gcc/c-common.c gcc/c-common.def gcc/c-common.h gcc/c-cppbuiltin.c gcc/c-decl.c gcc/c-dump.c gcc/c-format.c gcc/c-format.h gcc/c-gimplify.c gcc/c-lex.c gcc/c-omp.c gcc/c-opts.c gcc/c-parser.c gcc/c-pch.c gcc/c-ppoutput.c gcc/c-pragma.c gcc/c-pragma.h gcc/c-pretty-print.c gcc/c-pretty-print.h gcc/c-semantics.c gcc/c-tree.h gcc/c-typeck.c gcc/c.opt gcc/calls.c gcc/cfgexpand.c gcc/config.in gcc/config/alpha/osf.h gcc/config/alpha/t-osf4 gcc/config/alpha/t-vms64 gcc/config/alpha/vms-cc.c gcc/config/alpha/vms-crt0-64.c gcc/config/alpha/vms-crt0.c gcc/config/alpha/vms-ld.c gcc/config/alpha/vms-psxcrt0-64.c gcc/config/alpha/vms-psxcrt0.c gcc/config/alpha/vms_tramp.asm gcc/config/alpha/x-vms gcc/config/alpha/xm-vms.h gcc/config/arm/eabi.h gcc/config/arm/eabi.opt gcc/config/arm/t-arm-coff gcc/config/frv/frv-abi.h gcc/config/gofast.h gcc/config/h8300/coff.h gcc/config/i386/biarch32.h gcc/config/i386/cygwin1.c gcc/config/i386/cygwin2.c gcc/config/i386/i386-aout.h gcc/config/i386/i386-coff.h gcc/config/i386/i386.c gcc/config/i386/i386.md gcc/config/i386/mach.h gcc/config/i386/mmintrin-common.h gcc/config/ia64/itanium1.md gcc/config/libgloss.h gcc/config/m68k/coff.h gcc/config/m68k/m68k-aout.h gcc/config/mips/dbxmdebug.h gcc/config/mips/iris.h gcc/config/mips/iris5.h gcc/config/mips/sdemtk.opt gcc/config/mips/t-gofast gcc/config/pdp11/2bsd.h gcc/config/rs6000/aix.opt gcc/config/rs6000/aix41.h gcc/config/rs6000/aix41.opt gcc/config/rs6000/rs6000.md gcc/config/rs6000/t-newas gcc/config/s390/fixdfdi.h gcc/config/s390/libgcc-glibc.ver gcc/config/s390/t-crtstuff gcc/config/s390/t-linux gcc/config/s390/t-tpf gcc/config/score/mul-div.S gcc/config/score/score3.c gcc/config/score/score3.h gcc/config/sh/coff.h gcc/config/sh/superh64.h gcc/config/sh/symbian.c gcc/config/sh/t-1e gcc/config/sh/t-mlib-sh1 gcc/config/sh/t-mlib-sh2 gcc/config/sh/t-mlib-sh2a gcc/config/sh/t-mlib-sh2a-nofpu gcc/config/sh/t-mlib-sh2a-single gcc/config/sh/t-mlib-sh2a-single-only gcc/config/sh/t-mlib-sh2e gcc/config/sh/t-mlib-sh3 gcc/config/sh/t-mlib-sh3e gcc/config/sh/t-mlib-sh4 gcc/config/sh/t-mlib-sh4-nofpu gcc/config/sh/t-mlib-sh4-single gcc/config/sh/t-mlib-sh4-single-only gcc/config/sh/t-mlib-sh4a gcc/config/sh/t-mlib-sh4a-nofpu gcc/config/sh/t-mlib-sh4a-single gcc/config/sh/t-mlib-sh4a-single-only gcc/config/sh/t-mlib-sh4al gcc/config/sh/t-mlib-sh5-32media gcc/config/sh/t-mlib-sh5-32media-nofpu gcc/config/sh/t-mlib-sh5-64media gcc/config/sh/t-mlib-sh5-64media-nofpu gcc/config/sh/t-mlib-sh5-compact gcc/config/sh/t-mlib-sh5-compact-nofpu gcc/config/sparc/sol2-gld.h gcc/config/svr4.h gcc/config/vms/t-vms64 gcc/config/vms/vms-crt0-64.c gcc/config/vms/vms-crt0.c gcc/config/vms/vms-psxcrt0-64.c gcc/config/vms/vms-psxcrt0.c gcc/configure gcc/configure.ac gcc/df-byte-scan.c gcc/doc/aot-compile.1 gcc/doc/c-tree.texi gcc/doc/cpp.1 gcc/doc/cpp.info gcc/doc/cppinternals.info gcc/doc/fsf-funding.7 gcc/doc/g++.1 gcc/doc/gc-analyze.1 gcc/doc/gcc.1 gcc/doc/gcc.info gcc/doc/gccinstall.info gcc/doc/gccint.info gcc/doc/gcj-dbtool.1 gcc/doc/gcj.1 gcc/doc/gcj.info gcc/doc/gcov.1 gcc/doc/gfdl.7 gcc/doc/gfortran.1 gcc/doc/gij.1 gcc/doc/gpl.7 gcc/doc/grmic.1 gcc/doc/jcf-dump.1 gcc/doc/jv-convert.1 gcc/doc/rebuild-gcj-db.1 gcc/dummy-checksum.c gcc/dwarf.h gcc/dwarf2.h gcc/fix-header.c gcc/fixproto gcc/function.c gcc/gcc.c gcc/gccbug.in gcc/gen-protos.c gcc/gengtype-lex.c gcc/gimple.c gcc/gimple.h gcc/gimplify.c gcc/graphite.h gcc/lambda-code.c gcc/lambda-mat.c gcc/lambda-trans.c gcc/lambda.h gcc/lto-wpa-fixup.c gcc/lto/lto-elf.c gcc/passes.c gcc/po/be.gmo gcc/po/da.gmo gcc/po/de.gmo gcc/po/el.gmo gcc/po/es.gmo gcc/po/fi.gmo gcc/po/fr.gmo gcc/po/id.gmo gcc/po/ja.gmo gcc/po/nl.gmo gcc/po/ru.gmo gcc/po/sr.gmo gcc/po/sv.gmo gcc/po/tr.gmo gcc/po/zh_CN.gmo gcc/po/zh_TW.gmo gcc/protoize.c gcc/rtl-factoring.c gcc/scan-decls.c gcc/scan-types.sh gcc/scan.c gcc/scan.h gcc/see.c gcc/sort-protos gcc/stub-objc.c gcc/sys-protos.h gcc/sys-types.h gcc/tree-loop-linear.c gcc/tree-ssa-operands.c gcc/tree-ssa-structalias.h gcc/tree-vect-analyze.c gcc/tree-vect-transform.c gcc/tree.c gcc/tree.h gcc/varray.c gcc/varray.h libcpp/makedepend.c libcpp/po/be.gmo libcpp/po/ca.gmo libcpp/po/da.gmo libcpp/po/de.gmo libcpp/po/el.gmo libcpp/po/es.gmo libcpp/po/fr.gmo libcpp/po/id.gmo libcpp/po/ja.gmo libcpp/po/nl.gmo libcpp/po/sv.gmo libcpp/po/tr.gmo libcpp/po/uk.gmo libcpp/po/vi.gmo libcpp/po/zh_CN.gmo libcpp/po/zh_TW.gmo libgomp/libgomp.info libgomp/testsuite/libgomp.graphite/pr4118.c libiberty/vmsbuild.com |
diffstat | 87 files changed, 19001 insertions(+), 10934 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,10 @@ +syntax: glob + +*.o +*.s +.*.swp +.*.swo +GTAGS +GRTAGS +GSYMS +GPATH
--- a/.hgtags Sun Aug 21 07:07:55 2011 +0900 +++ b/.hgtags Sun Aug 21 07:53:12 2011 +0900 @@ -1,5 +1,2 @@ -a06113de4d676b497759e6a9bf820a208b02e09b gcc-4.4.0 -855418dad1a3a87de4782b8184eef35cd8812e23 gcc-4.4.2 -ae3a4bfb450bd98011c4167c72bb1d5ad73cdd51 gcc-4.4.3 77e2b8dfacca7d714bc9daeb6169b88f9d7c35eb gcc-4.4.5 b7f97abdc51746370aa15065311ea13e56c08d1f gcc-4.6-20100522
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgtags.orig Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,1 @@ +77e2b8dfacca7d714bc9daeb6169b88f9d7c35eb gcc-4.4.5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-DEVEL Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,25 @@ +GCC 4.4.3 -> 4.5.0 へのアップデートの作業メモ + +オリジナルのgcc-core 4.5.0と mergeして、衝突は全て解決 + +make時にエラー,未解決 -> (CbC-MAKELOG にログがのってます) +関数/マクロの引数構成に変更 +) build_decl,c_finish_stmt_expr,, -> locationの追加 +) buid_modify_expr, build_external_ref -> 色々変更 + +# GCCのソース中の用法を見る。コメントを読む。 +# locationに関しては間違っても動く。 + +全てc-parser.c のcbc拡張の古い部分の変更 + +-- + +cbc-goto.hでエラー(消された関数を使用) -> targetm.calls.promote_funciton_return(funtype) + + gcc/ChangeLog より -- + (expand_call): When making sibcall decisions, use promote_function_mode. + Below, remove an if for targetm.calls.promote_function_return and + and use promote_function_mode. + -- + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-INSTALL Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,220 @@ + + * CbC on GCCのインストール方法 + +まずはMercurialリポジトリから取得 + hg clone ssh://one@firefly.cr/hg/CbC/GCC cbc-gcc +ビルド用ディレクトリへ + mkdir build-gcc; cd build-gcc +コンフィギュア +一般的には以下のconfigureでビルドできる + ../cbc-gcc/configure CFLAGS="-g3 -O0" + --prefix=$PWD/INSTALL_DIR --disable-nls \ + --disable-bootstrap --enable-languages=c \ + --enable-checking=tree,rtl,assert,types + + -g3: + gdbでmacroの展開を可能にする + -O0: + gdbでトレースしやすいように、最適化をカット + --prefix: + インストールするベースディレクトリ + --enbale-checking: + デバグ用の指定、browse_treeやdebug_rtx、assertもこれでonになる + --disable-bootstrap: + 通常、GCCは3回ビルドされる。それを最初の1回だけに限定 + --disable-nls: + gettextのl10nをoffにしよう + --enable-language: + 使用する言語 c|c++|ada ... もちろんCbCはcだけ + これもcbcを使えるようにしたい +ビルド +make && make install + + + + * PowerPC Macでのインストール + +最新のlibgmp, libmpfrをインストール +[gmp] + ./configure --enable-cxx --build=powerpc-apple-darwin9 --host=powerpc-apple-darwin9 + make && make install +[mpfr] + ./configure --build=powerpc-apple-darwin9 --host=powerpc-apple-darwin9 + make && make install +[CbC on GCC] + ../cbc-gcc/configure CFLAGS="-g3 -O0" --with-gmp=/usr/local + --with-mpfr=/usr/local --prefix=$PWD/INSTALL_DIR \ + --disable-nls --disable-bootstrap --enable-languages=c \ + --enable-checking=tree,rtl,assert,types + make && make install +もちろんインストール場所によってprefixは変更しよう + + + + + * PS3でのビルド + SPU + $ ../GCC/configure CFLAGS='-g -O0' --prefix=$PWD/INSTALL_DIR + --disable-nls --disable-shared --disable-threads + --enable-checking=tree,rtl,assert --with-system-zlib + --with-newlib --enable-languages=c + --enable-version-specific-runtime-libs --disable-libssp + --program-prefix=cbc-spu- --target=spu --disable-bootstrap + $ make && make install + $ cd INSTALL_DIR; ln -s /usr/spu; cd .. + で、動作確認のあと + $ sudo make prefix=/usr/local/cbc install + $ cd /usr/local/cbc; ln -s /usr/spu; cd - + + PPU + $ ../GCC/configure --prefix=$PWD/INSTALL_DIR + --host=ppc64-redhat-linux --build=ppc64-redhat-linux + --target=ppc64-redhat-linux --program-prefix=cbc- --disable-bootstrap + --enable-checking=tree,rtl,assert --disable-nls --enable-shared + --enable-thread=posix --enable-languages=c --with-system-zlib + --enable-__cxa_atexit --disable-libunwind-exceptions --disable-dssi + --enable-plugin --with-long-double-128 --with-gnu-as + --with-as=/usr/bin/as --with-gnu-ld --with-ld=/usr/bin/ld + --with-cpu=default32 + $ make && make install + 動作確認 + $ make prefix=/usr/local/cbc install + + + + * 琉球大学総合情報センターのSolarisサーバでのビルド (sparc) + +なぜかデフォルトのgccが自分のライブラリすら見てくれないのでパスを指定 + export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib/gcc:$HOME/opt/lib + export LIBRARY_PATH=/usr/local/lib:/usr/local/lib/gcc:$HOME/opt/lib +gmpのインストール + ./configure --prefix=$HOME/opt \ + --build=sparc-sun-solaris \ + --host=sparc-sun-solaris + make + make check + make install +libmpfrのインストール + ./configure --prefix=$HOME/opt/ \ + --with-gmp=$HOME/opt + --build=sparc-sun-solaris \ + --host=sparc-sun-solaris + make + make check + make install + # sparc-sun-solaris2.10の方がいいかもしれない +CbCをインストール + ../CbCGCC/configure --prefix=$PWD/INSTALL_DIR --disable-nls \ + --disable-bootstrap --enable-languages=c \ + --with-gmp=$HOME/opt --with-mpfr=$HOME/opt \ + --build=sparc-sun-solaris2.10 --target=sparc-sun-solaris2.10 \ + --host=sparc-sun-solaris2.10 --enable-shared \ + --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld + make + make install +ビルドは可能。 +ただし、実行は不能 goto cs();すら動かない +config/sparc/sparc.cのoutput_sibcall()でエラーが出る +gdbがインストールされてないので詳細は未調査 +もしかしてsibcallってあまり実装されてないんじゃ… + + + +___________________________________________________________ + PS3用のクロスコンパイラの作成 +----------------------------------------------------------- + +PS3でのGCCのビルドはメモリが少なすぎるためか、insn-*.cのコンパイルに膨 +大な時間がかかってしまう。 +なので別のマシンからPS3をターゲットとしたクロスコンパイラを作成する。 +ただしこれはCbConGCCの開発のためと考えた方が良い。実際にCbC言語を使っ +たプログラムをPS3で開発する際はちゃんとPS3上にノンクロスコンパイラを作 +成しよう。時間はかかるがビルドは可能。 + + * 必要なもの + o binutilsのソース + o gccのソース + o ターゲットマシンのlib*.{a,so}類 + o ターゲットマシンの.hファイル + ~/PS3CROSSにクロスコンパイラ環境を整えるとする + ~/PS3CROSS/cross-tools: クロスコンパイルに使うツールのインストール先 + ~/PS3CROSS/sources: ソース置き場、出来上がったら消してもいいよ + ~/PS3CROSS/target-env: ターゲット環境(libやinclude)が入ったディレクトリ + + * 準備 + $ CROSS=$HOME/PS3CROSS + $ cd $CROSS + $ mkdir sources cross-tools target-env + $ cd sources + $ wget ... binutilsとかgccのソースをダウンロード + + * binutilsのビルド + $ tar xvf binutils..tar.gz + $ mkdir PS3-binutils-build; cd !#1 + $ ../binutils-.../configure --prefix=$CROSS/cross-tools \ + --with-lib-path=$CROSS/target-env \ + --hosti686-pc-linux-gnu --build=i686-pc-linux-gnu \ + --target=ppc64-redhat-linux --enable-64-bit-bfd \ + --disable-nls --enable-shared --with-sysroot + $ make && make install + + * ターゲットマシンの環境をコピーする + $ cd $CROSS/target-env + $ mkdir include lib lib64 + $ ln -s . usr + ## 必要なライブラリはすべてコピー + $ cd lib + $ rsync -avl 'charles.cr:/lib/libc[.-_]*' ./ + $ rsync -avl 'charles.cr:/usr/lib/libc[.-_]*' ./ + $ rsync -avl 'charles.cr:/usr/lib/crt*' ./ + $ rsync -avl 'charles.cr:/lib/ld*' ./ + $ cd ../lib64 + $ ..... + ## ヘッダは軽いので全部コピー + $ cd ../include + $ rsync -avl 'charles.cr:/usr/include/*' ./ + + * GCCのビルド + $ cd $CROSS/sources + $ mkdir PS3-gcc-build; cd !#1 + $ ../.../configure --prefix=$CROSS/cross-tools + --host=i686-pc-linux-gnu --target=ppc64-redhat-linux + --with-sysroot=$CROSS/target-env --disable-nls + --disable-shared --disable-threads + --enable-languages=c --without-headers + --disable-bootstrap + $ make all-gcc + $ make ## エラーで終わるけど気にするな + $ make install-gcc + $ make install-target-libgcc + + * テスト + $ cat >test.c <<EOF + #include<stdio.h> + int + main(int argc, char **argv) + { + int a=0; + int i; + for (i=0; i<10; i++) { + a = i; + } + printf("hello world\n"); + printf("a = %d\n", a); + return a; + } + EOF + $ $CROSS/cross-tools/bin/gcc -m32 test.c -o test32 + $ $CROSS/cross-tools/bin/gcc -m64 test.c -o test64 + $ file test32 test64 + test32: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), not stripped + test64: ELF 64-bit MSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), not stripped + $ scp test{32,64} PS3Machine: + PS3Machine $ ./test32 + + + + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-REPOSITORY Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,57 @@ + + * CbC/GCCのリポジトリ管理方法 + +Continuation based C のGCC実装用には二つのリポジトリを仕様する + + o CbC/GCC + 実際にCbCを実装したGCCの本体 + o CbC/GCC_original + オリジナルのGCC。本家のgcc-core-4.x.yをそのままリポジトリ化。 + +GCC_origのほうはGCCがリリースされる度にバージョンアップさせ、コミットする。 +さらにその変更をCbC用のGCCリポジトリにpushする + + 本家 + release GCC_orig GCC + | | | + | 4.4.0 4.4.0-cbc + 4.4.1 up | | + | --> 4.4.1 push | + | | --> 4.4.1-cbc + | | | + 4.4.2 up | | + | --> 4.4.2 push | + | | --> 4.4.2-cbc + | | | + + + * 本家GCCのニューリリース時の対応 + +GCC_originalをアップデート + $ cd $HOME + $ wget ftp://gcc.gnu.org/pub/gcc/releases/gcc-4.4.1/gcc-core-4.x.y.tar.gz + $ tar xvf gcc-core-4.x.y.tar.gz + $ cd gcc-4.x.y + $ cd ${HG_REPO}/CbC/GCC_original + $ rm -rf * + $ mv ${HOME}/gcc-4.4.1/* ./ + $ hg commit + +GCC_originalが最新のGCCになったら、その変更をGCCにpushする +GCC_originalからGCCへのpush + $ cd ${HOME} + $ mkdir workspace;cd workspace # 作業ディレクトリ作成 + $ hg clone ${HG}/one/CbC/GCC # CbC用のGCCをクローン + $ cd GCC + $ hg incoming ${HG}/one/CbC/GCC_original # チェック + $ hg pull ${HG}/one/CbC/GCC_original # pull + +この時点で、場合によっては衝突が起こる。ほとんどはgcc/calls.cの中だと +思われる。また、expand_call関数が大幅に変更されたならgcc/cbc-goto.hも +同じように書き換える必要があるかもしれない。 +がんばって動くまで修正したら + $ hg commit + $ hg push ${HG}/one/CbC/GCC # push +これで最新版に更新される + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/.gdb_history Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,256 @@ +p debug_rtx(funexp) +run -O2 test_para2.c +p browse_tree (exp) +c +p browse_tree (exp) +n +p debug_rtx(funexp) +n +p debug_rtx(funexp) +n +p debug_rtx(get_last_insn()) +c +run -O2 test_csp1.c +p browse_tree (exp) +n +p debug_rtx(get_last_insn()) +c +b recog.c:2077 +run +c +p insn +p debug_rtx(insn) +backtrace +l +info b +del 2 +b recog.c:2078 +run +del 3 +b recog.c:2076 +c +l +p icode +c +p icode +c +c +p icode +n +c +n +c +c +c +c +run +c +p icode +backtrace +run +backtrace +info b +del 4 +b recog.c:2077 +run +backtrace +info b +disable 1 +info b +c +backtrace +quit +b expand_call +run -O2 test_para2.c +p browse_tree (exp) +c +p browse_tree (exp) +c +p browse_tree (exp) +c +p browse_tree (exp) +c +p browse_tree (exp) +c +p browse_tree (exp) +n +p browse_tree (fntype) +quit +b expand_call +run -O2 test04.c +p browse_tree (exp) +c +p browse_tree (exp) +n +p browse_tree (fntype ) +p browse_tree (fntype->type.values ) +p browse_tree (fntype->type.values->value ) +p browse_tree (fntype->type.values->type.value ) +p browse_tree (fntype->type.values->type.values ) +p browse_tree (fntype->type.values ) +p browse_tree (fntype->type.values->list.vlaue ) +p browse_tree (fntype->type.values->list.value ) +p browse_tree (fntype->type.values->common.chain ) +p browse_tree (fntype->type.value ) +p browse_tree (fntype->type.values ) +p browse_tree (fntype ) +l +p browse_tree (exp) +q +quit +b expand_call +run -O2 test04.c +p browse_tree (exp) +c +p browse_tree (exp) +p browse_tree (exp) +p browse_tree (exp) +p browse_tree (exp->exp.operands[1])) +p browse_tree (exp->exp.operands[1]) +p browse_tree (exp) +quit +b expand_call +run -O2 test_tailcall1.c +l +p browse_tree (exp) +c +p browse_tree (exp) +c +p browse_tree (exp) +n +p browse_tree (fndecl) +p fndecl +n +p browse_tree (fntype) +n +p pass +p try_tail_call +run +c +c +p browse_tree (exp) +p try_tail_call +l +info stack +n +p try_tail_call +n +p try_tail_call +n +p try_tail_call +n +p try_tail_call +n +l +l - +l - +p try_tail_call +n +n +p browse_tree (exp) +n +n +n +n +p pass +p try_tail_call +quit +b expand_call +run -O2 test_tailcall1.c +cc +c +c +p browse_tree (exp) +n +p try_tail_call +n +p tree +p p +n +p p +p addr +n +p addr +n +p fndecl +n +p fndecl +n +p fntype +n +n +p funtype +n +p funtype +n +p try_tail_call +n +p try_tail_call +quit +b expand_call +run -O2 test_tailcall1.c +c +c +p browse_tree (exp) +n +p try_tail_call +n +p try_tail_call +n +n +p try_tail_call +n +p pass +quit +b expand_call +run -O2 test_tailcall1.c +p browse_tree (exp) +c +c +p browse_tree (exp) +n +p try_tail_call +n +p try_tail_call +p fndecl +p targetm.function_ok_for_sibcall(fndecl,exp) +run +c +c +n +p browse_tree (exp) +n +s +l +p decl +p exp +p browse_tree(exp) +n +s +s +quit +run -O2 test03.c +b expand_call +run +n +p browse_tree (exp) +c +p browse_tree (exp) +c +p browse_tree (exp) +c +quit +b expand_call +run -O2 test_para2.c +p browse_tree (exp) +c +p browse_tree (exp) +c +p browse_tree (exp) +c +p browse_tree (exp) +n +s +n +p debug_rtx(get_last_insn()) +quit
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/bug.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,19 @@ +typedef void (*atexit_callback)(void); +typedef void (*cxa_atexit_callback)(void *); +struct one_atexit_routine +{ + int callback; +}; + + +static int +atexit_common (const struct one_atexit_routine *r, const void *dso) + + +{ + return 0; +} + +int main(){ + printf("hello\n"); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/code_segment_pointer_check/Makefile Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,25 @@ + +CbCC=../../../build_cbc44/INSTALL_DIR/bin/gcc + +#CC=gcc +CC=../../../build_cbc44/INSTALL_DIR/bin/gcc + + +# fastcall版では-O0,-O2は動作確認、-O3以上はだめ +CFLAGS=-g -O2 -fomit-frame-pointer +#CFLAGS=-g -O0 + +.SUFFIXES: .cbc .o + +all: code_segment_pointer_check2 + +.cbc.o: + $(CbCC) $(CFLAGS) -c -o $@ $< + +code_segment_pointer_check2: code_segment_pointer_check2.o + $(CC) $(CFLAGS) -o $@ $^ + + +clean: + rm -rf *.o *.s code_segment_pointer_check2 +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/code_segment_pointer_check/code_segment_check.cbc Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,57 @@ +#include<stdio.h> +#include<stdlib.h> +#define dprint(f, args...) \ + printf("in %s env=%p: "f, __FUNCTION__, __builtin_frame_address(1), ## args) + +/* + * コードセグメント間の遷移をテスト + * + */ + +__code end (int a); +__code cs0a (int a, double b, int c, float d, char e); +__code cs1a (char e, int a, double b, int c, float d); +__code cs2a (float d, char e, int a, double b, int c); +__code cs3a (int c, float d, char e, int a, double b); +__code cs4a (double b, int c, float d, char e, int a); +int main (); + +__code end(int a) { + dprint("exit code is %d\n",a); + exit(a); +} + +int i=0; +__code cs0a(int a, double b, int c, float d, char e) { + if ( i++ >= 10 ) { + dprint("int a=%d,double b=%2.3lf,int c=%d,float d=%2.3f,char e=%d\n", a, b, c, d, e); + goto end((int)(a*b*c*d*e)); + } + goto cs1a(e, a, b, c, d); +} +__code cs1a(char e, int a, double b, int c, float d) { + //dprint("int a=%d,double b=%2.3lf,int c=%d,float d=%2.3f,char e=%d\n", a, b, c, d, e); + goto cs2a(d, e, a, b, c); +} +__code cs2a(float d, char e, int a, double b, int c) { + //dprint("int a=%d,double b=%2.3lf,int c=%d,float d=%2.3f,char e=%d\n", a, b, c, d, e); + goto cs3a(c, d, e, a, b); +} +__code cs3a(int c, float d, char e, int a, double b) { + //dprint("int a=%d,double b=%2.3lf,int c=%d,float d=%2.3f,char e=%d\n", a, b, c, d, e); + goto cs4a(b, c, d, e, a); +} +__code cs4a(double b, int c, float d, char e, int a) { + //dprint("int a=%d,double b=%2.3lf,int c=%d,float d=%2.3f,char e=%d\n", a, b, c, d, e); + goto cs0a(a, b, c, d, e); +} + +__code starter(int a, double b, int c, float d, char e) { + dprint("exit code is expected to %d\n",(int)(a*b*c*d*e)); + dprint("int a=%d,double b=%2.3lf,int c=%d,float d=%2.3f,char e=%d\n", a, b, c, d, e); + goto cs0a(a,b,c,d,e); +} +int main() { + goto starter(11, 22.2, 33, 44.44, 55); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/code_segment_pointer_check/code_segment_pointer_check.cbc Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,120 @@ +#include<stdio.h> +#include<stdlib.h> +#define dprint(f, args...) \ + printf("in %s env=%p: "f, __FUNCTION__, __builtin_frame_address(0), ## args) + +/* + * コードセグメント間の遷移で + * + * + * + */ + +__code schedule (); +__code cs0a (); +__code cs1a (int a); +__code cs2a (int a, double b); +__code cs3a (int a, double b, int c); +__code cs4a (int a, double b, int c, float d); +__code cs0b (); +__code cs1b (int a); +__code cs2b (int a, double b); +__code cs3b (int a, double b, int c); +__code cs4b (int a, double b, int c, float d); + +/* defined in file code_segment_pointer_check.cbc at offset 1649 */ +int main (); + +__code end(int a) { + dprint("exit with code %d\n",a); + exit(a); +} + +__code (*cs0) (); +__code (*cs1) (int); +__code (*cs2) (int, double); +__code (*cs3) (int, double, int); +__code (*cs4) (int, double, int, float); +int i=0; +__code schedule() { + dprint("i=%d\n",i); + if ( i>=100 ) { + goto end(0); + } + switch (i++%5) { + case 0: + goto cs0(); + case 1: + goto cs1(i); + case 2: + goto cs2(i, i*1.3); + case 3: + goto cs3(i, i*1.3, 20*i); + case 4: + goto cs4(i, i*1.3, 20*i, i*0.8); + default: + exit(0); + } + dprint("code unreachable!\n"); +} + +__code cs0a() { + dprint("no args\n"); + cs0 = cs0b; + goto schedule(); +} +__code cs1a(int a) { + dprint("int a=%d\n", a); + cs1 = cs1b; + goto schedule(); +} +__code cs2a(int a, double b) { + dprint("int a=%d, double b=%lf\n", a, b); + cs2 = cs2b; + goto schedule(); +} +__code cs3a(int a, double b, int c) { + dprint("int a=%d, double b=%lf, int c=%d\n", a, b, c); + cs3 = cs3b; + goto schedule(); +} +__code cs4a(int a, double b, int c, float d) { + dprint("int a=%d, double b=%lf, int c=%d, float d=%f\n", a, b, c, d); + cs4 = cs4b; + goto schedule(); +} + +__code cs0b() { + dprint("no args\n"); + cs0 = cs0a; + goto schedule(); +} +__code cs1b(int a) { + dprint("int a=%d\n", a); + cs1 = cs1a; + goto schedule(); +} +__code cs2b(int a, double b) { + dprint("int a=%d, double b=%lf\n", a, b); + cs2 = cs2a; + goto schedule(); +} +__code cs3b(int a, double b, int c) { + dprint("int a=%d, double b=%lf, int c=%d\n", a, b, c); + cs3 = cs3a; + goto schedule(); +} +__code cs4b(int a, double b, int c, float d) { + dprint("int a=%d, double b=%lf, int c=%d, float d=%f\n", a, b, c, d); + cs4 = cs4a; + goto schedule(); +} + +int main() { + cs0 = cs0a; + cs1 = cs1a; + cs2 = cs2a; + cs3 = cs3a; + cs4 = cs4a; + goto schedule(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/code_segment_pointer_check/code_segment_pointer_check2.cbc Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,655 @@ +#include<stdio.h> +#include<stdlib.h> +#include"code_segment_pointer_check2.h" +#define dprint(f, args...) \ + printf("in %s env=%p: "f, __FUNCTION__, __builtin_frame_address(0), ## args) + +/* + * コードセグメント間の遷移をチェック + * + */ + +typedef __code (*CODEP)(int,int,int,int,int,int); +extern CODEP csps[]; +CODEP csps[] = { + //cs0,cs1 + cs0,cs1,cs2,cs3,cs4,cs5,cs6,cs7,cs8,cs9, + cs10,cs11,cs12,cs13,cs14,cs15,cs16,cs17,cs18,cs19, + cs20,cs21,cs22,cs23,cs24,cs25,cs26,cs27,cs28,cs29, + cs30,cs31,cs32,cs33,cs34,cs35,cs36,cs37,cs38,cs39, + cs40,cs41,cs42,cs43,cs44,cs45,cs46,cs47,cs48,cs49, + cs50,cs51,cs52,cs53,cs54,cs55,cs56,cs57,cs58,cs59, + cs60,cs61,cs62,cs63,cs64,cs65,cs66,cs67,cs68,cs69, + cs70,cs71,cs72,cs73,cs74,cs75,cs76,cs77,cs78,cs79, + cs80,cs81,cs82,cs83,cs84,cs85,cs86,cs87,cs88,cs89, + cs90,cs91,cs92,cs93,cs94,cs95,cs96,cs97,cs98,cs99, + cs100,cs101,cs102,cs103,cs104,cs105,cs106,cs107,cs108,cs109, + cs110,cs111,cs112,cs113,cs114,cs115,cs116,cs117,cs118,cs119 +}; + +__code end(int a, int b, int c, int d, int e) { + dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + exit(a); +} + +__code schedule(int i, int a, int b, int c, int d, int e) { + //CODEP p; + //p = csps[i%120]; + + if ( i>=1000 ) { + goto end(a, b, c, d, e); + } + + dprint("i=%d\n", i); + goto csps[i%120](i+1, a, b, c, d, e); + + dprint("code unreachable!\n"); +} + +int main() { + goto schedule(0, 11,22,33,44,55); +} + + + +/* created by script make_permutations.py. */ + +__code cs0(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,b,c,d,e); +} + +__code cs1(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,a,c,d,e); +} + +__code cs2(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,c,a,d,e); +} + +__code cs3(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,c,d,a,e); +} + +__code cs4(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,c,d,e,a); +} + +__code cs5(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,c,b,d,e); +} + +__code cs6(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,a,b,d,e); +} + +__code cs7(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,b,a,d,e); +} + +__code cs8(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,b,d,a,e); +} + +__code cs9(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,b,d,e,a); +} + +__code cs10(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,c,d,b,e); +} + +__code cs11(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,a,d,b,e); +} + +__code cs12(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,d,a,b,e); +} + +__code cs13(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,d,b,a,e); +} + +__code cs14(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,d,b,e,a); +} + +__code cs15(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,c,d,e,b); +} + +__code cs16(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,a,d,e,b); +} + +__code cs17(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,d,a,e,b); +} + +__code cs18(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,d,e,a,b); +} + +__code cs19(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,d,e,b,a); +} + +__code cs20(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,b,d,c,e); +} + +__code cs21(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,a,d,c,e); +} + +__code cs22(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,d,a,c,e); +} + +__code cs23(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,d,c,a,e); +} + +__code cs24(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,d,c,e,a); +} + +__code cs25(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,d,b,c,e); +} + +__code cs26(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,a,b,c,e); +} + +__code cs27(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,b,a,c,e); +} + +__code cs28(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,b,c,a,e); +} + +__code cs29(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,b,c,e,a); +} + +__code cs30(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,d,c,b,e); +} + +__code cs31(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,a,c,b,e); +} + +__code cs32(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,c,a,b,e); +} + +__code cs33(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,c,b,a,e); +} + +__code cs34(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,c,b,e,a); +} + +__code cs35(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,d,c,e,b); +} + +__code cs36(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,a,c,e,b); +} + +__code cs37(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,c,a,e,b); +} + +__code cs38(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,c,e,a,b); +} + +__code cs39(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,c,e,b,a); +} + +__code cs40(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,b,d,e,c); +} + +__code cs41(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,a,d,e,c); +} + +__code cs42(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,d,a,e,c); +} + +__code cs43(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,d,e,a,c); +} + +__code cs44(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,d,e,c,a); +} + +__code cs45(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,d,b,e,c); +} + +__code cs46(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,a,b,e,c); +} + +__code cs47(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,b,a,e,c); +} + +__code cs48(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,b,e,a,c); +} + +__code cs49(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,b,e,c,a); +} + +__code cs50(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,d,e,b,c); +} + +__code cs51(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,a,e,b,c); +} + +__code cs52(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,e,a,b,c); +} + +__code cs53(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,e,b,a,c); +} + +__code cs54(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,e,b,c,a); +} + +__code cs55(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,d,e,c,b); +} + +__code cs56(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,a,e,c,b); +} + +__code cs57(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,e,a,c,b); +} + +__code cs58(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,e,c,a,b); +} + +__code cs59(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, d,e,c,b,a); +} + +__code cs60(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,b,c,e,d); +} + +__code cs61(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,a,c,e,d); +} + +__code cs62(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,c,a,e,d); +} + +__code cs63(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,c,e,a,d); +} + +__code cs64(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,c,e,d,a); +} + +__code cs65(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,c,b,e,d); +} + +__code cs66(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,a,b,e,d); +} + +__code cs67(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,b,a,e,d); +} + +__code cs68(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,b,e,a,d); +} + +__code cs69(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,b,e,d,a); +} + +__code cs70(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,c,e,b,d); +} + +__code cs71(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,a,e,b,d); +} + +__code cs72(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,e,a,b,d); +} + +__code cs73(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,e,b,a,d); +} + +__code cs74(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,e,b,d,a); +} + +__code cs75(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,c,e,d,b); +} + +__code cs76(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,a,e,d,b); +} + +__code cs77(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,e,a,d,b); +} + +__code cs78(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,e,d,a,b); +} + +__code cs79(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, c,e,d,b,a); +} + +__code cs80(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,b,e,c,d); +} + +__code cs81(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,a,e,c,d); +} + +__code cs82(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,e,a,c,d); +} + +__code cs83(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,e,c,a,d); +} + +__code cs84(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,e,c,d,a); +} + +__code cs85(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,e,b,c,d); +} + +__code cs86(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,a,b,c,d); +} + +__code cs87(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,b,a,c,d); +} + +__code cs88(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,b,c,a,d); +} + +__code cs89(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,b,c,d,a); +} + +__code cs90(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,e,c,b,d); +} + +__code cs91(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,a,c,b,d); +} + +__code cs92(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,c,a,b,d); +} + +__code cs93(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,c,b,a,d); +} + +__code cs94(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,c,b,d,a); +} + +__code cs95(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,e,c,d,b); +} + +__code cs96(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,a,c,d,b); +} + +__code cs97(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,c,a,d,b); +} + +__code cs98(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,c,d,a,b); +} + +__code cs99(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,c,d,b,a); +} + +__code cs100(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,b,e,d,c); +} + +__code cs101(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,a,e,d,c); +} + +__code cs102(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,e,a,d,c); +} + +__code cs103(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,e,d,a,c); +} + +__code cs104(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, b,e,d,c,a); +} + +__code cs105(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,e,b,d,c); +} + +__code cs106(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,a,b,d,c); +} + +__code cs107(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,b,a,d,c); +} + +__code cs108(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,b,d,a,c); +} + +__code cs109(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,b,d,c,a); +} + +__code cs110(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,e,d,b,c); +} + +__code cs111(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,a,d,b,c); +} + +__code cs112(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,d,a,b,c); +} + +__code cs113(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,d,b,a,c); +} + +__code cs114(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,d,b,c,a); +} + +__code cs115(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, a,e,d,c,b); +} + +__code cs116(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,a,d,c,b); +} + +__code cs117(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,d,a,c,b); +} + +__code cs118(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,d,c,a,b); +} + +__code cs119(int i, int a, int b, int c, int d, int e) { + //dprint("a=%d,b=%d,c=%d,d=%d,e=%d\n", a, b, c, d, e); + goto schedule(i, e,d,c,b,a); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/code_segment_pointer_check/code_segment_pointer_check2.h Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,369 @@ +/* defined in file code_segment_pointer_check2.cbc at offset 987 */ +__code end (int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 1102 */ +__code schedule (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 1345 */ +int main (); + +/* defined in file code_segment_pointer_check2.cbc at offset 1398 */ +__code cs0 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 1542 */ +__code cs1 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 1686 */ +__code cs2 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 1830 */ +__code cs3 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 1974 */ +__code cs4 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 2118 */ +__code cs5 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 2262 */ +__code cs6 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 2406 */ +__code cs7 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 2550 */ +__code cs8 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 2694 */ +__code cs9 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 2838 */ +__code cs10 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 2983 */ +__code cs11 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 3128 */ +__code cs12 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 3273 */ +__code cs13 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 3418 */ +__code cs14 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 3563 */ +__code cs15 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 3708 */ +__code cs16 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 3853 */ +__code cs17 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 3998 */ +__code cs18 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 4143 */ +__code cs19 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 4288 */ +__code cs20 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 4433 */ +__code cs21 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 4578 */ +__code cs22 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 4723 */ +__code cs23 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 4868 */ +__code cs24 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 5013 */ +__code cs25 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 5158 */ +__code cs26 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 5303 */ +__code cs27 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 5448 */ +__code cs28 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 5593 */ +__code cs29 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 5738 */ +__code cs30 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 5883 */ +__code cs31 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 6028 */ +__code cs32 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 6173 */ +__code cs33 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 6318 */ +__code cs34 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 6463 */ +__code cs35 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 6608 */ +__code cs36 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 6753 */ +__code cs37 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 6898 */ +__code cs38 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 7043 */ +__code cs39 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 7188 */ +__code cs40 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 7333 */ +__code cs41 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 7478 */ +__code cs42 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 7623 */ +__code cs43 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 7768 */ +__code cs44 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 7913 */ +__code cs45 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 8058 */ +__code cs46 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 8203 */ +__code cs47 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 8348 */ +__code cs48 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 8493 */ +__code cs49 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 8638 */ +__code cs50 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 8783 */ +__code cs51 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 8928 */ +__code cs52 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 9073 */ +__code cs53 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 9218 */ +__code cs54 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 9363 */ +__code cs55 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 9508 */ +__code cs56 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 9653 */ +__code cs57 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 9798 */ +__code cs58 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 9943 */ +__code cs59 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 10088 */ +__code cs60 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 10233 */ +__code cs61 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 10378 */ +__code cs62 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 10523 */ +__code cs63 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 10668 */ +__code cs64 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 10813 */ +__code cs65 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 10958 */ +__code cs66 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 11103 */ +__code cs67 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 11248 */ +__code cs68 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 11393 */ +__code cs69 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 11538 */ +__code cs70 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 11683 */ +__code cs71 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 11828 */ +__code cs72 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 11973 */ +__code cs73 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 12118 */ +__code cs74 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 12263 */ +__code cs75 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 12408 */ +__code cs76 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 12553 */ +__code cs77 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 12698 */ +__code cs78 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 12843 */ +__code cs79 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 12988 */ +__code cs80 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 13133 */ +__code cs81 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 13278 */ +__code cs82 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 13423 */ +__code cs83 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 13568 */ +__code cs84 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 13713 */ +__code cs85 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 13858 */ +__code cs86 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 14003 */ +__code cs87 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 14148 */ +__code cs88 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 14293 */ +__code cs89 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 14438 */ +__code cs90 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 14583 */ +__code cs91 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 14728 */ +__code cs92 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 14873 */ +__code cs93 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 15018 */ +__code cs94 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 15163 */ +__code cs95 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 15308 */ +__code cs96 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 15453 */ +__code cs97 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 15598 */ +__code cs98 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 15743 */ +__code cs99 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 15888 */ +__code cs100 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 16034 */ +__code cs101 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 16180 */ +__code cs102 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 16326 */ +__code cs103 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 16472 */ +__code cs104 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 16618 */ +__code cs105 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 16764 */ +__code cs106 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 16910 */ +__code cs107 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 17056 */ +__code cs108 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 17202 */ +__code cs109 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 17348 */ +__code cs110 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 17494 */ +__code cs111 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 17640 */ +__code cs112 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 17786 */ +__code cs113 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 17932 */ +__code cs114 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 18078 */ +__code cs115 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 18224 */ +__code cs116 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 18370 */ +__code cs117 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 18516 */ +__code cs118 (int i, int a, int b, int c, int d, int e); + +/* defined in file code_segment_pointer_check2.cbc at offset 18662 */ +__code cs119 (int i, int a, int b, int c, int d, int e); +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/conv.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,92 @@ +#include "stdio.h" + +f0(int i) { + int k,j; + k = 3+i; + j = g0(i+3); + return k+4+j; +} + +g0(int i) { + return i+4; +} + + +typedef void *stack; + +__code f_g0(int i,int k,stack sp) ; + +struct cont_interface { // General Return Continuation + __code (*ret)(int, void*); +}; + +__code f(int i,stack sp) { + int k,j; + k = 3+i; + goto f_g0(i,k,sp); +} + +struct f_g0_interface { // Specialized Return Continuation + __code (*ret)(); + int i_,k_,j_; +}; + +__code f_g1(int j,stack sp); +__code g(int i,stack sp) ; + +__code f_g0(int i,int k,stack sp) { // Caller + struct f_g0_interface *c = + (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); + + c->ret = f_g1; + c->k_ = k; + c->i_ = i; + + goto g(i+3,sp); +} + +__code f_g1(int j,stack sp) { // Continuation + struct f_g0_interface *c = (struct f_g0_interface *)sp; + int k = c->k_; + sp += sizeof(struct f_g0_interface); + goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp); +} + +__code g(int i,stack sp) { + goto (( (struct cont_interface *)sp)->ret)(i+4,sp); +} + +struct main_continuation { // General Return Continuation + __code (*ret)(int, void*); + __code (*main_ret)(int, void*); + void *env; +}; + +__code main_return(int i,stack sp) { + printf("#0061:%d\n",i); + goto (( (struct main_continuation *)sp)->main_ret)(i, + ((struct main_continuation *)sp)->env); +} + +#define STACK_SIZE 2048 +char main_stack[STACK_SIZE]; +#define stack_last (&main_stack[STACK_SIZE]) + +typedef __code (*return_type)(int, void*); +int +main(int argc, char **argv) +{ + struct main_continuation *cont; + stack sp = stack_last; + + printf("#0075:%d\n",f0(233)); + + sp -= sizeof(*cont); + cont = (struct main_continuation *)sp; + cont->ret = main_return; + cont->main_ret = (return_type) _CbC_return; + cont->env = _CbC_environment; + goto f(233,sp); +} + +/* end */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/conv1.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,225 @@ +#include "stdio.h" + +static int loop; + +#if 1 // def __micro_c__ +#define CC_ONLY 0 +#else +#define CC_ONLY 1 +#endif + +/* classical function call case (0) */ + +f0(int i) { + int k,j; + k = 3+i; + j = g0(i+3); + return k+4+j; +} + +g0(int i) { + return h0(i+4)+i; +} + +h0(int i) { + return i+4; +} + +#if !CC_ONLY + +/* straight conversion case (1) */ + +typedef char *stack; + +struct cont_interface { // General Return Continuation + __code (*ret)(int, void *); +}; + +__code f(int i,stack sp) { + int k,j; + k = 3+i; + goto f_g0(i,k,sp); +} + +struct f_g0_interface { // Specialized Return Continuation + __code (*ret)(int, void *); + int i_,k_,j_; +}; + +__code f_g1(int j,stack sp); + +__code f_g0(int i,int k,stack sp) { // Caller + struct f_g0_interface *c = + (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); + + c->ret = f_g1; + c->k_ = k; + c->i_ = i; + + goto g(i+3,sp); +} + +__code f_g1(int j,stack sp) { // Continuation + struct f_g0_interface *c = (struct f_g0_interface *)sp; + int k = c->k_; + sp+=sizeof(struct f_g0_interface); + c = (struct f_g0_interface *)sp; + goto (c->ret)(k+4+j,sp); +} + +__code g_h1(int j,stack sp); + +__code g(int i,stack sp) { // Caller + struct f_g0_interface *c = + (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); + + c->ret = g_h1; + c->i_ = i; + + goto h(i+3,sp); +} + +__code g_h1(int j,stack sp) { // Continuation + struct f_g0_interface *c = (struct f_g0_interface *)sp; + int i = c->i_; + sp+=sizeof(struct f_g0_interface); + c = (struct f_g0_interface *)sp; + goto (c->ret)(j+i,sp); +} + +__code h(int i,stack sp) { + struct f_g0_interface *c = (struct f_g0_interface *)sp; + goto (c->ret)(i+4,sp); +} + +struct main_continuation { // General Return Continuation + __code (*ret)(); + __code (*main_ret)(); + void *env; +}; + +__code main_return(int i,stack sp) { + if (loop-->0) + goto f(233,sp); + printf("#0103:%d\n",i); + goto (( (struct main_continuation *)sp)->main_ret)(0, + ((struct main_continuation *)sp)->env); +} + +/* little optimzation without stack continuation (2) */ + +__code f2(int i,char *sp) { + int k,j; + k = 3+i; + goto g2(i,k,i+3,sp); +} + +__code g2(int i,int k,int j,char *sp) { + j = j+4; + goto h2(i,k+4+j,sp); +} + +__code h2_1(int i,int k,int j,char *sp) { + goto main_return2(i+j,sp); +} + +__code h2(int i,int k,char *sp) { + goto h2_1(i,k,i+4,sp); +} + +__code main_return2(int i,stack sp) { + if (loop-->0) + goto f2(233,sp); + printf("#0132:%d\n",i); + goto (( (struct main_continuation *)sp)->main_ret)(0, + ((struct main_continuation *)sp)->env); +} + +/* little optimizaed case (3) */ + +__code f2_1(int i,char *sp) { + int k,j; + k = 3+i; + goto g2_1(k,i+3,sp); +} + +__code g2_1(int k,int i,char *sp) { + goto h2_11(k,i+4,sp); +} + +__code f2_0_1(int k,int j,char *sp); +__code h2_1_1(int i,int k,int j,char *sp) { + goto f2_0_1(k,i+j,sp); +} + +__code h2_11(int i,int k,char *sp) { + goto h2_1_1(i,k,i+4,sp); +} + +__code f2_0_1(int k,int j,char *sp) { + goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp); +} + +__code main_return2_1(int i,stack sp) { + if (loop-->0) + goto f2_1(233,sp); + printf("#0165:%d\n",i); + goto (( (struct main_continuation *)sp)->main_ret)(0, + ((struct main_continuation *)sp)->env); +} + +#define STACK_SIZE 2048 +char main_stack[STACK_SIZE]; +#define stack_last (main_stack+STACK_SIZE) + +#endif + +#define LOOP_COUNT 10000000 + +main(int ac,char *av[]) +{ +#if !CC_ONLY + struct main_continuation *cont; + stack sp = stack_last; +#endif + int sw; + int j; + if (ac==2) sw = atoi(av[1]); + else sw=3; + + if (sw==0) { + for(loop=0;loop<LOOP_COUNT;loop++) { + j = f0(233); + } + printf("#0193:%d\n",j); +#if !CC_ONLY + } else if (sw==1) { + loop = LOOP_COUNT; + sp -= sizeof(*cont); + cont = (struct main_continuation *)sp; + cont->ret = main_return; + cont->main_ret = _CbC_return; + cont->env = _CbC_environment; + goto f(233,sp); + } else if (sw==2) { + loop = LOOP_COUNT; + sp -= sizeof(*cont); + cont = (struct main_continuation *)sp; + cont->ret = main_return2; + cont->main_ret = _CbC_return; + cont->env = _CbC_environment; + goto f2(233,sp); + } else if (sw==3) { + loop = LOOP_COUNT; + sp -= sizeof(*cont); + cont = (struct main_continuation *)sp; + cont->ret = main_return2_1; + cont->main_ret = _CbC_return; + cont->env = _CbC_environment; + goto f2_1(233,sp); +#endif + } +return 0; +} + +/* end */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/conv1/Makefile Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,11 @@ +CbCC = ../../../build_cbc44/INSTALL_DIR/libexec/gcc/i686-pc-linux-gnu/4.4.1/cc1 + + +time: + for exe in *; do \ + if [ -x $$exe ]; then \ + echo $$exe; \ + time ./$$exe; \ + fi; \ + done +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/conv1/conv1.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,227 @@ +#include <stdio.h> +static int loop; + +#if 1 // def __micro_c__ +#define CC_ONLY 0 +#else +#define CC_ONLY 1 +#endif + +typedef char *stack; +#include "conv1.h" + +/* classical function call case (0) */ + +f0(int i) { + int k,j; + k = 3+i; + j = g0(i+3); + return k+4+j; +} + +g0(int i) { + return h0(i+4)+i; +} + +h0(int i) { + return i+4; +} + +#if !CC_ONLY + +/* straight conversion case (1) */ + + +struct cont_interface { // General Return Continuation + __code (*ret)(); +}; + +__code f(int i,stack sp) { + int k,j; + k = 3+i; + goto f_g0(i,k,sp); +} + +struct f_g0_interface { // Specialized Return Continuation + __code (*ret)(); + int i_,k_,j_; +}; + +__code f_g1(int j,stack sp); + +__code f_g0(int i,int k,stack sp) { // Caller + struct f_g0_interface *c = + (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); + + c->ret = f_g1; + c->k_ = k; + c->i_ = i; + + goto g(i+3,sp); +} + +__code f_g1(int j,stack sp) { // Continuation + struct f_g0_interface *c = (struct f_g0_interface *)sp; + int k = c->k_; + sp+=sizeof(struct f_g0_interface); + c = (struct f_g0_interface *)sp; + goto (c->ret)(k+4+j,sp); +} + +__code g_h1(int j,stack sp); + +__code g(int i,stack sp) { // Caller + struct f_g0_interface *c = + (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); + + c->ret = g_h1; + c->i_ = i; + + goto h(i+3,sp); +} + +__code g_h1(int j,stack sp) { // Continuation + struct f_g0_interface *c = (struct f_g0_interface *)sp; + int i = c->i_; + sp+=sizeof(struct f_g0_interface); + c = (struct f_g0_interface *)sp; + goto (c->ret)(j+i,sp); +} + +__code h(int i,stack sp) { + struct f_g0_interface *c = (struct f_g0_interface *)sp; + goto (c->ret)(i+4,sp); +} + +struct main_continuation { // General Return Continuation + __code (*ret)(); + __code (*main_ret)(int,void*); + void *env; +}; + +__code main_return(int i,stack sp) { + if (loop-->0) + goto f(233,sp); + printf("#0103:%d\n",i); + goto (( (struct main_continuation *)sp)->main_ret)(0, + ((struct main_continuation *)sp)->env); +} + +/* little optimzation without stack continuation (2) */ + +__code f2(int i,char *sp) { + int k,j; + k = 3+i; + goto g2(i,k,i+3,sp); +} + +__code g2(int i,int k,int j,char *sp) { + j = j+4; + goto h2(i,k+4+j,sp); +} + +__code h2_1(int i,int k,int j,char *sp) { + goto main_return2(i+j,sp); +} + +__code h2(int i,int k,char *sp) { + goto h2_1(i,k,i+4,sp); +} + +__code main_return2(int i,stack sp) { + if (loop-->0) + goto f2(233,sp); + printf("#0132:%d\n",i); + goto (( (struct main_continuation *)sp)->main_ret)(0, + ((struct main_continuation *)sp)->env); +} + +/* little optimizaed case (3) */ + +__code f2_1(int i,char *sp) { + int k,j; + k = 3+i; + goto g2_1(k,i+3,sp); +} + +__code g2_1(int k,int i,char *sp) { + goto h2_11(k,i+4,sp); +} + +__code f2_0_1(int k,int j,char *sp); +__code h2_1_1(int i,int k,int j,char *sp) { + goto f2_0_1(k,i+j,sp); +} + +__code h2_11(int i,int k,char *sp) { + goto h2_1_1(i,k,i+4,sp); +} + +__code f2_0_1(int k,int j,char *sp) { + goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp); +} + +__code main_return2_1(int i,stack sp) { + if (loop-->0) + goto f2_1(233,sp); + printf("#0165:%d\n",i); + exit(0); + //goto (( (struct main_continuation *)sp)->main_ret)(0, + //((struct main_continuation *)sp)->env); +} + +#define STACK_SIZE 2048 +char main_stack[STACK_SIZE]; +#define stack_last (main_stack+STACK_SIZE) + +#endif + +#define LOOP_COUNT 500000000 +int +main(int ac,char *av[]) +{ +#if !CC_ONLY + struct main_continuation *cont; + stack sp = stack_last; +#endif + int sw; + int j; + if (ac==2) sw = atoi(av[1]); + else sw=3; + + if (sw==0) { + for(loop=0;loop<LOOP_COUNT;loop++) { + j = f0(233); + } + printf("#0193:%d\n",j); +#if !CC_ONLY + } else if (sw==1) { + loop = LOOP_COUNT; + sp -= sizeof(*cont); + cont = (struct main_continuation *)sp; + cont->ret = main_return; + cont->main_ret = _CbC_return; + cont->env = _CbC_environment; + goto f(233,sp); + } else if (sw==2) { + loop = LOOP_COUNT; + sp -= sizeof(*cont); + cont = (struct main_continuation *)sp; + cont->ret = main_return2; + cont->main_ret = _CbC_return; + cont->env = _CbC_environment; + goto f2(233,sp); + } else if (sw==3) { + loop = LOOP_COUNT; + sp -= sizeof(*cont); + cont = (struct main_continuation *)sp; + cont->ret = main_return2_1; + cont->main_ret = _CbC_return; + cont->env = _CbC_environment; + goto f2_1(233,sp); +#endif + } +return 0; +} + +/* end */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/conv1/conv1.h Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,54 @@ +/* defined in file conv1.c at offset 468 */ +__code f (int i,stack sp); + +/* defined in file conv1.c at offset 680 */ +__code f_g0 (int i,int k,stack sp); + +/* defined in file conv1.c at offset 897 */ +__code f_g1 (int j,stack sp); + +/* defined in file conv1.c at offset 1162 */ +__code g (int i,stack sp); + +/* defined in file conv1.c at offset 1355 */ +__code g_h1 (int j,stack sp); + +/* defined in file conv1.c at offset 1588 */ +__code h (int i,stack sp); + +/* defined in file conv1.c at offset 1838 */ +__code main_return (int i,stack sp); + +/* defined in file conv1.c at offset 2107 */ +__code f2 (int i,char *sp); + +/* defined in file conv1.c at offset 2189 */ +__code g2 (int i,int k,int j,char *sp); + +/* defined in file conv1.c at offset 2270 */ +__code h2_1 (int i,int k,int j,char *sp); + +/* defined in file conv1.c at offset 2346 */ +__code h2 (int i,int k,char *sp); + +/* defined in file conv1.c at offset 2410 */ +__code main_return2 (int i,stack sp); + +/* defined in file conv1.c at offset 2658 */ +__code f2_1 (int i,char *sp); + +/* defined in file conv1.c at offset 2742 */ +__code g2_1 (int k,int i,char *sp); + +/* defined in file conv1.c at offset 2844 */ +__code h2_1_1 (int i,int k,int j,char *sp); + +/* defined in file conv1.c at offset 2918 */ +__code h2_11 (int i,int k,char *sp); + +/* defined in file conv1.c at offset 2987 */ +__code f2_0_1 (int k,int j,char *sp); + +/* defined in file conv1.c at offset 3086 */ +__code main_return2_1 (int i,stack sp); +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/loto6.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,80 @@ +/* + * Nov 10, 2009 + * created by gongo. + * + * Nov 10, 2009 + * modified by kent. + */ + +#include <stdio.h> +#include <stdlib.h> + +(*ret)(int, void*); +void *env; + + +__code +print(int *numbers) +{ + printf("%d-%d-%d-%d-%d-%d\n", numbers[0], numbers[1], numbers[2], numbers[3], numbers[4], numbers[5]); + free(numbers); + goto ret(0, env); +} + + __code +take(int *array, int size, int length) +{ + int *taked = (int*)malloc(sizeof(int)*length); + + memcpy(taked, array, sizeof(int)*length); + free(array); + + goto print(taked); +} + +__code +shuffle(int *array, int size, int idx) +{ + int j = random() % size; + int tmp = array[idx]; + array[idx] = array[j]; + array[j] = tmp; + + if (++idx < size) { + goto shuffle(array, size, idx); + } else { + goto take(array, size, 6); + } +} + +__code +range_loop(int *array, int idx, int from, int to, int step, int size) +{ + array[idx] = from; + + if (from+step > to) { + goto shuffle(array, size, 0); + } else { + goto range_loop(array, idx+1, from+step, to, step, size); + } +} + +__code +range(int from, int to, int step) +{ + int size = (to-from+1)/step; + int *array = (int*)malloc(sizeof(int)*size); + + goto range_loop(array, 0, from, to, step, size); +} + +int +main() +{ + srand(time(NULL)); + ret = _CbC_return; + env = _CbC_environment; + + goto range(1, 43, 1); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/matrix/compute_power.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,107 @@ +#include <stdio.h> +#include "matrix.h" + +void compute(); +double ** create_identity_matrix(int size); +double ** multiply(double **a, double **b, int l, int m, int n); +void print_matrix(double **a, int row, int col); + +int +main(int argc, char **argv) +{ + compute(); + return 0; +} + +void +compute() +{ + double **A, **B, **C; + A = create_identity_matrix(4); + B = create_identity_matrix(4); + printf("A = \n"); + print_matrix(A, 4, 4); + printf("B = \n"); + print_matrix(B, 4, 4); + + C = multiply(A, B, 4,4,4); + printf("C = \n"); + print_matrix(C, 4, 4); + + + free(A); + free(B); + free(C); +} + +double ** +create_identity_matrix(int size) +{ + int i,j; + double **ret; + ret = create_matrix(sizeof(double), size, size); + + for (j=0; j<size; j++) { + for (i=0; i<size; i++) { + ret[j][i] = 0; + } + } + for (i=0; i<size; i++) { + ret[i][i] = 1.0f; + } + return ret; +} + +double ** +power_of_matrix(double **a, int n) +{ + int r,c,i; + double **result; + result = create_identity_matrix(n); + + for (r=0; r<l; r++) { + for (c=0; c<n; c++) { + result[r][c] = 0; + for (i=0; i<m; i++) { + result[r][c] += a[r][i] * b[i][c]; + } + } + } + return result; +} + +double ** +multiply(double **a, double **b, int l, int m, int n) +{ + int r,c,i; + double **result; + result = create_matrix(sizeof(double), l, n); + + for (r=0; r<l; r++) { + for (c=0; c<n; c++) { + result[r][c] = 0; + for (i=0; i<m; i++) { + result[r][c] += a[r][i] * b[i][c]; + } + } + } + return result; +} + +/** 表示用 */ +void +print_matrix(double **a, int row, int col) +{ + int i,j; + for( j=0; j<row; j++){ + printf("\t"); + for( i=0; i<col; i++){ + printf("%6.2f ", a[j][i]); + } + printf("\n"); + } +} + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/matrix/matrix.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,21 @@ +#include "matrix.h" + +void +*create_matrix(size_t size, int row, int col) +{ + int i; + void *body; + void **ret; + + ret = malloc( size*row*col + sizeof(void*)*row ); + if (ret==NULL) return NULL; + + body = (void*)(ret+row); + for( i=0; i<row; i++){ + ret[i] = body + size*col*i; + } + return ret; +} + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/matrix/matrix.h Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,3 @@ +#include "stdlib.h" + +void *create_matrix(size_t size, int row, int col);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/normal.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,26 @@ +#include<stdio.h> +#include<stdlib.h> + +//size_t size; +int size; +typedef int test_int; + +test_int ti; + +void end(){ + exit(0); +} + +int main(int argc, char **argv){ + size=0; + ti=10; + + printf("main: "); + printf("normal:%d\n", argc); + + size = 10; + printf("size = %d\n", size); + printf(" ti = %d\n", ti); + end(); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/normal2.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,65 @@ +//#include<stdio.h> +//#include<stdlib.h> + +struct abc { + int a; + double b; + char c; + double *d; +}; + +struct def { + int d; + struct abc e; + struct abc *f; +}; + +void print_abc(struct abc a){ + printf("\tstruct abc:\n"); + printf("\ta=%d, b=%lf, c=%d, d=%p\n", a.a, a.b, a.c, a.d); +} +void print_def(struct def b){ + printf("\tstruct def:\n"); + printf("\ta=%d, b=%p\n", b.d, b.f); + print_abc(b.e); +} + +void cs_exit(int a){ + printf("cs_exit : a=%d.\n", a); + exit(a); +} + +void cs0(struct abc a, struct def b, int c){ + printf("cs0 :\n"); + print_abc(a); + print_def(b); + return cs_exit( c*a.a+b.e.c ); +} + + +void cs_goto(int c, struct abc a, struct def b){ + printf("cs_return :\n"); + print_abc(a); + print_def(b); + return cs0(a, b, c); +} + +int main(int argc, char **argv){ + struct abc A; + struct def B; + //int a=10, b=20, c=30, d=40, e=50, f=60, g=70; + A.a = 10, A.b = 20.02, A.c = '\0', A.d = 0; + B.d = 30, B.f = &A; + B.e.a = 50, B.e.b = 60.06, B.e.c = '\1', B.e.d = 0; + + printf("main :\n"); + print_abc(A); + print_def(B); + //printf("20*%d + 30*%d + 40*%d + 50*%d =\n", a, b, c, d); + cs_goto(100, A, B); + return 0; +} + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/parallel_check/c-int-double.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,46 @@ +#include<stdio.h> +#include<math.h> + +#define dprint(f, args...) \ + printf("in %s env=%p: "f, __FUNCTION__, __builtin_frame_address(1), ## args) + +int +test(int a) +{ + return (int)pow(a, 2.0); +} + +int +callee(double a, double b, double c, int d) +{ + dprint("a=%d,b=%d,c=%d,d=%d\n", a,b,c,d); + return a+b+c+d; +} + +int +caller(int a, double b, double c, double d) +{ + int x; + double y,z,w; + //x = test(a); + //y = test(b); + //z = test(c); + //w = test(d); + x=a, y=b; + z=c, w=d; + + return callee(y,z,w,x); + //return callee(b,c,d, a); +} + +int +main (int argc, char **argv) +{ + int r; + r = caller(11,22,33,44); + //r = caller(11,22,33,44, 55,66,77,88); + printf("r = %d\n", r); +} + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/parallel_check/c-int.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,71 @@ +#include<stdio.h> +#define dprint(f, args...) \ + printf("in %s env=%p: "f, __FUNCTION__, __builtin_frame_address(1), ## args) + +void +callee(int a, int b, int c, int d) +{ + int r; + dprint("a=%d,b=%d,c=%d,d=%d\n", a,b,c,d); + r = a+b+c+d; + printf("r = %d\n", r); + return; +} + +void +caller1(int a, int b, int c, int d) +{ + int x,y,z,w; + x=a, y=b; + z=c, w=d; + + callee(x,y,z,w); + return; +} + +void +caller2(int a, int b, int c, int d) +{ + int x,y,z,w; + x=a, y=b; + z=c, w=d; + + callee(y,z,w,x); + return; +} + +void +caller3(int a, int b, int c, int d) +{ + callee(b,c,d,a); + return; +} + +void +caller4(int a, int b, int c, int d) +{ + callee(a+b,b+c,c+d,d+a); + return; +} + +void +caller5(int a, int b, int c, int d) +{ + int x,y,z,w; + x = a+b; + y = b+c; + z = c+d; + w = d+a; + + callee(x,y,z,w); + return; +} + +int +main (int argc, char **argv) +{ + int r; + caller(11,22,33,44); + //r = caller(11,22,33,44, 55,66,77,88); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/parallel_check/c-struct.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,51 @@ +#include<stdio.h> +#include<math.h> + +#define dprint(f, args...) \ + printf("in %s env=%p: "f, __FUNCTION__, __builtin_frame_address(1), ## args) + +typedef struct { + int a; + double b; + char *c; +} STRUCT; + +int +test(int a) +{ + return (int)pow(a, 2.0); +} + + +int +callee(int a, STRUCT s, int b) + /* |-|----|-| */ +{ + dprint("a=%d,b=%d\n", a,b); + dprint("s.a=%d,s.b=%lf,s.c=%s\n", s.a, s.b, s.c); + return a+b+ s.a; +} + +int +caller(STRUCT s, int a, double b) + /* |----|-|--| */ +{ + STRUCT s0;// = {44, 55.5, "aiueo2"}; + //int a0 = 55; + //a0 = a; + s0 = s; + + return callee(10, s0, 20); +} + +int +main (int argc, char **argv) +{ + int r; + STRUCT s = { 33, 44.4, "aiueo" }; + + r = caller(s, 11, 22.2); + //r = caller(11,22,33,44, 55,66,77,88); + printf("r = %d\n", r); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/quicksort/Makefile Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,39 @@ + +CbCC=../../BUILD/INSTALL_DIR/bin/gcc + +#CC=gcc +#CC=../../../build_gcc/INSTALL_DIR/bin/gcc +CC=../../BUILD/INSTALL_DIR/bin/gcc + +HEADERMAKER=../../CbC-scripts/make_headers.py2 + +# fastcall版では-O0,-O2は動作確認、-O3以上はだめ +#CFLAGS=-g -O2 -fomit-frame-pointer +#CFLAGS=-g -O2 +CFLAGS=-g -O0 +#CFLAGS=-g -Os # an error occurred. + +.SUFFIXES: .cbc .o + +all: quicksort_cbc quicksort_c quicksort_cbc2 + +.cbc.o: + $(CbCC) $(CFLAGS) -c -o $@ $< +.cbc.h: + $(HEADERMAKER) $^ > $@ + +quicksort_cbc.o: quicksort_cbc.h +quicksort_cbc2.o: quicksort_cbc2.h +quicksort_test.o: quicksort_test.h + +quicksort_cbc: quicksort_cbc.o quicksort_test.o + $(CC) $(CFLAGS) -o $@ $^ +quicksort_cbc2: quicksort_cbc2.o quicksort_test.o + $(CC) $(CFLAGS) -o $@ $^ + +quicksort_c: quicksort_c.o + $(CC) $(CFLAGS) -o $@ $^ + + +clean: + rm -rf *.o *.s quicksort_c quicksort_cbc quicksort_cbc2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/quicksort/benchmark.sh Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,44 @@ +#!/usr/bin/env zsh + +time=/usr/bin/time +QS=./quicksort_cbc +size=10000000 +seed=123456789 +num=10 + + +max=0 +min=99999 +count=0 +amount=0 + +echo "size of array = $size" +while [[ $count -lt $num ]]; do + usertime=$( $time -p $QS -n $size -s $seed 2>&1 >& - |grep '^user'|tr -s " "|cut -f2 -d" ") + #usertime=$(printf "%d" $usertime) + echo $usertime + + amount=$(($usertime+$amount)) + if [[ $usertime -lt $min ]]; then + min=$usertime + fi + if [[ $usertime -gt $max ]]; then + max=$usertime + fi + #seed=$seed[1,-2] + seed=$(($seed+10)) + count=$(($count+1)) +done + +echo "amount time = $amount" +echo "maxtime = $max" +echo "mintime = $min" + +amount=$(($amount - $max - $min)) +echo "amount time - mintime - maxtime = $amount" +count=$(($count-2)) +echo "count = $count" +averagetime=$(($amount/($count))) +echo "average time = $averagetime" + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/quicksort/mc/Makefile Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,39 @@ + +CbCC=../../../../device/mc + +#CC=gcc +CC=../../../../build_gcc/INSTALL_DIR/bin/gcc + +HEADERMAKER=../../../CbC-scripts/make_headers.py2 + +CFLAGS=-g -Wall + +.SUFFIXES: .cbc .o .s .c + +all: quicksort_cbc quicksort_c quicksort_cbc2 + +quicksort_c.c quicksort_cbc.cbc quicksort_cbc2.cbc quicksort_test.cbc benchmark.sh: + ln -s ../$@ + +.s.o: + $(CC) -c -o $@ $< +.cbc.s: + $(CbCC) $< +.cbc.h: + $(HEADERMAKER) $^ > $@ + +quicksort_cbc.o: quicksort_cbc.h +quicksort_cbc2.o: quicksort_cbc2.h +quicksort_test.o: quicksort_test.h + +quicksort_cbc: quicksort_cbc.o quicksort_test.o + $(CC) $(CFLAGS) -o $@ $^ +quicksort_cbc2: quicksort_cbc2.o quicksort_test.o + $(CC) $(CFLAGS) -o $@ $^ + +quicksort_c: quicksort_c.o + $(CC) $(CFLAGS) -o $@ $^ + + +clean: + rm -rf *.o *.s quicksort_c quicksort_cbc quicksort_cbc2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/quicksort/quicksort_c.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,183 @@ +#include<stdio.h> +#include<stdlib.h> +#include<unistd.h> +#include<assert.h> + +static inline void +SWAP (int *a, int *b) +{ + int tmp; + tmp = *a; + *a = *b; + *b = tmp; +} + +static inline int +mid_point(int a, int b, int c) +{ + if (a < b) { + if (b < c) + return b; + else if (a < c) + return c; + else + return a; + } else { + if (a < c) + return a; + else if (b < c) + return c; + else + return b; + } +} + +void +selectsort(int *v, int s0, int e0) +{ + int i,j; + int m; + int size = e0-s0+1; + v += s0; + for (i=0; i<size; i++) { + m = i; + for (j=i+1; j<size; j++) { + if (v[m] > v[j]) + m = j; + } + if (m!=i) + SWAP(&v[i],&v[m]); + } + return; +} + +void +quicksort(int *v, int s0, int e0) +{ + int p; + int s=s0, e=e0; +#if 0 + if (e<=s) return; + if (e-s<5) { + selectsort(v,s0,e0); + return; + } +#else + if (e<=s) return; +#endif + + //p = (v[s]+v[(s+e)/2]+v[e])/3; + p = mid_point(v[s],v[e],v[(s+e)/2]); + + while (1) { + while (v[s]<p) s++; + while (p<v[e]) e--; + + if (!(s<e)) break; + SWAP(&v[s], &v[e]); + s++; e--; + } + assert(e+1==s || s==e); + + quicksort(v, s0, e); + quicksort(v, e+1, e0); + return; +} + +static void +print_array(int *v, int size) +{ + int i; + printf("["); + for (i=0; i<size; i++) { + printf("%s%4d", (i%10==0)? "\n ":" ", v[i]); + } + printf("]\n"); +} + +static int +check_sort(int *v, int size) +{ + int i; + for (i=0; i<size-1; i++) { + if (v[i] > v[i+1]) + return 0; + } + return 1; +} + +void +random_initialize(int *v, int size, int min, int max) +{ + int i; + int diff = max-min+1; + + for (i=0; i<size; i++) { + v[i] = min+random()%diff; + } + return; +} + +int +start_sort(int size) +{ + int *target; + + target = (int*)malloc(sizeof(int)*size); + if (!target) { + perror("malloc"); + exit(1); + } + + random_initialize(target, size, 0, 1); + + //print_array(target, size); + quicksort(target, 0, size-1); + //selectsort(target, 0, size-1); + //print_array(target, size); + return check_sort(target, size); +} + +int +main(int argc, char **argv) +{ + //unsigned int seed= -1074072728; + unsigned int seed; + int size=101; + int loop=1; + int opt, i; + + while ((opt = getopt(argc, argv, "t:s:n:")) != -1) { + switch (opt) { + case 'n': + size = atoi(optarg); + break; + case 't': + loop = atoi(optarg); + break; + case 's': + seed = atoi(optarg); + break; + default: + fprintf(stderr, "Usage: %s [-t times] [-n sizeofarray] [-s seed]\n", argv[0]); + exit(1); + } + } + + printf("start seed = %u\n", seed); + printf("sort size = %d\n", size); + for (i=0; i<loop; i++) { + srandom(seed+i); + int b = start_sort(size); + if (b) { + printf("seed = %d+%u, success\n", i, seed); + } else { + fprintf(stderr, "sorting failure! seed=%u+%d\n", seed,i); + exit(1); + } + } + exit(0); +} + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/quicksort/quicksort_cbc.cbc Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,244 @@ +#include<stdio.h> +#include<stdlib.h> +#include<assert.h> + +typedef void *stack; +typedef struct { + int size; + void *interface; + __code (*ret)(void*, stack) ; +} frame, *framep; + +/* quickstart main routine. */ +typedef struct { + int *v; + int s; + int e; +} QS_IF ; +typedef __code (*RET)(void*); + +#include"quicksort_cbc.h" + +/* for check. */ +void *mustbefreed; + +__code returner(stack sp) +{ + framep fp = (framep)sp; + sp += fp->size; + goto fp->ret(fp->interface, sp); +} + +__code quicksort_start(void *arg, stack sp) +{ + QS_IF *recvif = arg; + int a,b,c,p; + a = recvif->v[recvif->s]; + b = recvif->v[recvif->e]; + c = recvif->v[(recvif->s+recvif->e)/2]; + + //printf("quicksort_start: s=%d,e=%d", recvif->s, recvif->e); + if (recvif->e <= recvif->s) goto returner(sp); + + if (a < b) { + if (b < c) + p = b; + else if (a < c) + p = c; + else + p = a; + } else { + if (a < c) + p = a; + else if (b < c) + p = c; + else + p = b; + } + + goto quicksort_divider (recvif, recvif->s, recvif->e, p, sp); +} +/* main routine end. */ + +/* divide routine. */ +__code quicksort_divider(QS_IF *recvif, int s, int e, int p, stack sp) +{ + goto quicksort_divider_s(recvif, s, e, p, sp); +} +__code quicksort_divider_s(QS_IF *recvif, int s, int e, int p, stack sp) +{ + if (recvif->v[s]<p) { + goto quicksort_divider_s(recvif, s+1, e, p, sp); + } else + goto quicksort_divider_e(recvif, s, e, p, sp); +} +__code quicksort_divider_e(QS_IF *recvif, int s, int e, int p, stack sp) +{ + if (p<recvif->v[e]) { + e--; + goto quicksort_divider_e(recvif, s, e, p, sp); + } else + goto quicksort_swapper(recvif, s, e, p, sp); +} +__code quicksort_swapper(QS_IF *recvif, int s, int e, int p, stack sp) +{ + if (s<e) { + int tmp; + tmp = recvif->v[s]; + recvif->v[s] = recvif->v[e]; + recvif->v[e] = tmp; + goto quicksort_divider(recvif, s+1, e-1, p, sp); + } else { + goto quicksort_treecall(recvif, s, e, sp); + } +} +/* divide routin end. */ + + +/* recursive call routine. */ +__code quicksort_treecall(QS_IF *recvif, int s, int e, stack sp) +{ + framep fp; + QS_IF *outif; + + /* interface for first quicksort_start this segment directly jump to. */ + outif = (sp-=sizeof(QS_IF)); + outif->v = recvif->v; + outif->s = recvif->s; + outif->e = e; + fp = (sp-=sizeof(frame)); + fp->ret = quicksort_start; + fp->interface = recvif; + fp->size = sizeof(frame)+sizeof(QS_IF); + + /* recvif is used by second quicksort_start. */ + recvif->s = e+1; + goto quicksort_start(outif, sp); +} +/* recursive call routine end. */ + +#define STACK_SIZE 10240 + +typedef struct { + __code (*ret)(void*); + void *ret_arg; + stack *sp; +} QS_FINISH; +__code +quicksort(int *v, int s, int e, RET ret, void *arg ) +{ + framep fp; + stack sp0, sp; + sp0 = mustbefreed = malloc(STACK_SIZE); + sp = sp0 + STACK_SIZE; + QS_FINISH *finish_if; + QS_IF *outif; + + /* interface for quicksort_finish. */ + finish_if = (sp -= sizeof(QS_FINISH)); + finish_if->ret = ret; + finish_if->ret_arg = arg; + finish_if->sp = sp0; + + /* interface for quicksort_start. */ + outif = (sp -= sizeof(QS_IF)); + outif->v = v; + outif->s = s; + outif->e = e; + /* frame for quicksort_finish. */ + fp = (sp -= sizeof(frame)); + fp->ret = quicksort_finish; + fp->interface = finish_if; + fp->size = sizeof(frame)+sizeof(QS_IF); + + goto quicksort_start(outif, sp); +} +__code +quicksort_finish(void *arg, stack sp) +{ + QS_FINISH interface; + interface = *(QS_FINISH*)arg; + //assert((void*)interface.sp==(void*)mustbefreed); + free(interface.sp); + goto interface.ret(interface.ret_arg); +} + + + +#if 0 +void +quicksort_c(int *v, int s0, int e0, stack sp) +{ + int p; + int s=s0, e=e0; + if (e<=s) return; + + //p = (v[s]+v[(s+e)/2]+v[e])/3; + p = mid_point(v[s],v[e],v[(s+e)/2]); + + while (1) { + while (v[s]<p) s++; + while (p<v[e]) e--; + + if (!(s<e)) break; + SWAP(&v[s], &v[e]); + s++; e--; + } + assert(e+1==s || s==e); + + quicksort(v, s0, e); + quicksort(v, e+1, e0); + return; +} + + + +/* -------------------- + * | args |fp| + * -------------------- + * + ↑ - + * sp + */ +/* ret segmentへgotoしたときのstack spの状態 + * + * sp が直接さすのは frame 構造体 + * frame.size: + * frame.ret: そのret segmentが終了した時にgotoすべきret segment. + * frame.interface: frame.retへgotoするときのinterface. + * このポインタが指すメモリ領域は stack + * 中にあっても良いしなくても良い。 + * ただしframe.retを登録した側で解放すべき。 + * sp+sizeof(frame)が指すのは実行中のret segmentのinterface(引数) + * これは実行中のret segmentがメモリ管理する + * 通常はこのret segmentが終了する際に sp+=frame.size とすればよい + */ +__code caller0(void *arg, stack sp) +{ + /* interface for caller_finish0. */ + double *finish_arg = (sp -= sizeof(double)); + + /* arg for quicksort_start. */ + outif = (sp -= sizeof(*outif)); + framep fp = (sp -= sizeof(frame)); + fp->ret = caller_finish; + fp->interface = NULL; + fp->size = sizeof(*outif)+sizeof(frame); + + goto quicksort_start(outif, sp); +} +__code caller_finish0(void *arg, stack sp) +{ +} + +__code __returner0(void *arg , stack sp) +{ + framep fp = sp; + sp += fp->size; + goto fp->ret(fp->interface, sp); +} + +#endif + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/quicksort/quicksort_cbc2.cbc Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,159 @@ +#include<stdio.h> +#include<stdlib.h> +#include<assert.h> + +typedef struct { + int *v; + int s; + int e; +} QS_IF; + +typedef void *stack; +typedef __code (*RET)(QS_IF, stack); +typedef struct { + int size; + QS_IF interface; + RET ret; +} frame, *framep; + +typedef __code (*RETTYPE)(void*); +typedef struct { + RETTYPE ret; + void *ret_arg; + stack *sp; +} QS_FINISH; +#define STACK_SIZE 10240 + +#include"quicksort_cbc2.h" + +__code returner(stack sp) +{ + framep fp = (framep)sp; + sp += fp->size; + goto fp->ret(fp->interface, sp); +} + +__code quicksort_start(QS_IF recvif, stack sp) +{ + int a,b,c,p; + a = recvif.v[recvif.s]; + b = recvif.v[recvif.e]; + c = recvif.v[(recvif.s+recvif.e)/2]; + + //printf("quicksort_start: s=%d,e=%d", recvif->s, recvif->e); + if (recvif.e <= recvif.s) goto returner(sp); + + if (a < b) { + if (b < c) + p = b; + else if (a < c) + p = c; + else + p = a; + } else { + if (a < c) + p = a; + else if (b < c) + p = c; + else + p = b; + } + + goto quicksort_divider (recvif, recvif.s, recvif.e, p, sp); +} +/* main routine end. */ + +/* divide routine. */ +__code quicksort_divider(QS_IF recvif, int s, int e, int p, stack sp) +{ + goto quicksort_divider_s(recvif, s, e, p, sp); +} +__code quicksort_divider_s(QS_IF recvif, int s, int e, int p, stack sp) +{ + if (recvif.v[s]<p) { + s++; + goto quicksort_divider_s(recvif, s, e, p, sp); + } else + goto quicksort_divider_e(recvif, s, e, p, sp); +} +__code quicksort_divider_e(QS_IF recvif, int s, int e, int p, stack sp) +{ + if (p<recvif.v[e]) { + e--; + goto quicksort_divider_e(recvif, s, e, p, sp); + } else + goto quicksort_swapper(recvif, s, e, p, sp); +} +__code quicksort_swapper(QS_IF recvif, int s, int e, int p, stack sp) +{ + if (s<e) { + int tmp; + tmp = recvif.v[s]; + recvif.v[s] = recvif.v[e]; + recvif.v[e] = tmp; + s++; + e--; + goto quicksort_divider(recvif, s, e, p, sp); + } else { + //assert(e+1==s || s==e); + goto quicksort_treecall(recvif, s, e, sp); + } +} +/* divide routin end. */ + + +/* recursive call routine. */ +__code quicksort_treecall(QS_IF recvif, int s, int e, stack sp) +{ + framep fp; + + /* interface for first quicksort_start this segment directly jump to. */ + fp = (sp-=sizeof(frame)); + fp->ret = quicksort_start; + fp->size = sizeof(frame); + fp->interface.v = recvif.v; + fp->interface.s = e+1; + fp->interface.e = recvif.e; + + /* recvif is used by second quicksort_start. */ + recvif.e = e; + goto quicksort_start(recvif, sp); +} +/* recursive call routine end. */ + +__code +quicksort(int *v, int s, int e, RETTYPE ret, void *arg ) +{ + framep fp; + stack sp0, sp; + sp0 = malloc(STACK_SIZE); + printf("allocate a stack %p\n", sp0); + sp = sp0 + STACK_SIZE; + QS_FINISH *finish_if; + + /* interface for quicksort_finish. */ + finish_if = (sp -= sizeof(*finish_if)); + finish_if->ret = ret; + finish_if->ret_arg = arg; + finish_if->sp = sp0; + + /* interface for quicksort_start. */ + /* frame for quicksort_finish. */ + fp = (sp -= sizeof(frame)); + fp->ret = quicksort_finish; + fp->size = sizeof(frame); + fp->interface.v = v; + fp->interface.s = s; + fp->interface.e = e; + + goto quicksort_start(fp->interface, sp); +} +__code +quicksort_finish(QS_IF recvif, stack sp) +{ + QS_FINISH *interface = (QS_FINISH*)sp; + free(interface->sp); + printf("free the stack %p\n", interface->sp); + goto interface->ret(interface->ret_arg); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/quicksort/quicksort_test.cbc Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,106 @@ +#include<stdio.h> +#include<stdlib.h> +#include<assert.h> +#include<unistd.h> + +#include"quicksort_test.h" + +extern __code quicksort(int *,int,int, __code (*)(void*), void*); + + +void +random_initialize(int *v, int size, int min, int max) +{ + int i; + int diff = max-min+1; + + for (i=0; i<size; i++) { + v[i] = min+random()%diff; + } + return; +} + +static void +print_array(int *v, int size) +{ + int i; + printf("["); + for (i=0; i<size; i++) { + printf("%s%4d", (i%10==0)? "\n ":" ", v[i]); + } + printf(" ]\n"); +} + +void +starter(int size) +{ + int *target; + + target = (int*)malloc(sizeof(int)*size); + if (!target) { + perror("malloc"); + exit(1); + } + + random_initialize(target, size, 0, 90); + + //print_array(target, size); + goto quicksort(target, 0, size-1, exit0, (void*)target); + + printf("bad region\n"); +} + +static int size=100; + +int +main(int argc, char **argv) +{ + unsigned int seed=0; + int opt; + + while ((opt = getopt(argc, argv, "s:n:")) != -1) { + switch (opt) { + case 's': + seed = atoi(optarg); + break; + case 'n': + size = atoi(optarg); + break; + default: + fprintf(stderr, "Usage: %s [-t times] [-n sizeofarray] [-s seed]\n", argv[0]); + exit(1); + } + } + + srandom(seed); + starter(size); + return 0; +} + +static int +check_sort(int *v, int size) +{ + int i; + for (i=0; i<size-1; i++) { + if (v[i] > v[i+1]) + return 0; + } + return 1; +} + +__code +exit0(void *arg) +{ + int *v = arg; + int b; + //print_array(arg, size); + b = check_sort(arg, size); + if (b) { + printf("sorting successful!\n"); + exit(EXIT_SUCCESS); + } else { + printf("sorting failure! \n"); + exit(EXIT_FAILURE); + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/regexp/dfareg.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,182 @@ +#include <stdio.h> + +#include <stdlib.h> + +__code state_20_21(char* s); +__code state_1(char* s); +__code state_3_8_9_13_23_24(char* s); +__code state_6_7(char* s); +__code state_2_3_9_13_23_24_25(char* s); +__code state_10_11(char* s); +__code state_18_19(char* s); +__code state_4_5(char* s); +__code state_14_15(char* s); +__code state_3_9_13_22_23_24(char* s); +__code state_3_9_12_13_23_24(char* s); +__code state_16_17(char* s); +__code accept(); +__code reject(); + +int main(int argc, char* argv[]) { + if (argc == 1) { + printf("usage: %s text\n", argv[0]); + exit(0); +} + + puts("regexp: P(erl|HP|ython)*"); + puts("number of state: 12"); + printf("string: %s\n", argv[1]); + goto state_1(argv[1]); + return 0; +} + +__code state_20_21(char* s) { + switch(*s++) { + case 'n': + goto state_3_9_13_22_23_24(s); + break; + default: goto reject(); + } +} + +__code state_1(char* s) { + switch(*s++) { + case 'P': + goto state_2_3_9_13_23_24_25(s); + break; + default: goto reject(); + } +} + +__code state_3_8_9_13_23_24(char* s) { + switch(*s++) { + case 'y': + goto state_14_15(s); + break; + case 'H': + goto state_10_11(s); + break; + case 'e': + goto state_4_5(s); + break; + case '\0': goto accept(); + break; + default: goto reject(); + } +} + +__code state_6_7(char* s) { + switch(*s++) { + case 'l': + goto state_3_8_9_13_23_24(s); + break; + default: goto reject(); + } +} + +__code state_2_3_9_13_23_24_25(char* s) { + switch(*s++) { + case 'y': + goto state_14_15(s); + break; + case 'H': + goto state_10_11(s); + break; + case 'e': + goto state_4_5(s); + break; + case '\0': goto accept(); + break; + default: goto reject(); + } +} + +__code state_10_11(char* s) { + switch(*s++) { + case 'P': + goto state_3_9_12_13_23_24(s); + break; + default: goto reject(); + } +} + +__code state_18_19(char* s) { + switch(*s++) { + case 'o': + goto state_20_21(s); + break; + default: goto reject(); + } +} + +__code state_4_5(char* s) { + switch(*s++) { + case 'r': + goto state_6_7(s); + break; + default: goto reject(); + } +} + +__code state_14_15(char* s) { + switch(*s++) { + case 't': + goto state_16_17(s); + break; + default: goto reject(); + } +} + +__code state_3_9_13_22_23_24(char* s) { + switch(*s++) { + case 'y': + goto state_14_15(s); + break; + case 'H': + goto state_10_11(s); + break; + case 'e': + goto state_4_5(s); + break; + case '\0': goto accept(); + break; + default: goto reject(); + } +} + +__code state_3_9_12_13_23_24(char* s) { + switch(*s++) { + case 'y': + goto state_14_15(s); + break; + case 'H': + goto state_10_11(s); + break; + case 'e': + goto state_4_5(s); + break; + case '\0': goto accept(); + break; + default: goto reject(); + } +} + +__code state_16_17(char* s) { + switch(*s++) { + case 'h': + goto state_18_19(s); + break; + default: goto reject(); + } +} + + +__code accept() { + printf("\nstring matches regexp. \n\n"); +} + + +__code reject() { + printf("\nstring does not match regexp. \n\n"); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/regexp/dfareg.py Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,414 @@ +#!/usr/bin/env python + +import copy +import sys + +class NondeterministicFiniteAutomaton(object): + def __init__(self, transition, start, accepts, map_): + self.transition = transition + self.start = start + self.accepts = accepts + self.map = map_ + + def epsilonExpand(self, set_): + que = set(set_) + done = set() + while que: + stat = que.pop() + nexts = self.transition(stat, "") + done.add(stat) + for nextStat in nexts: + if not nextStat in done: que.add(nextStat) + return frozenset(done) + +class DeterministicFiniteAutomaton(object): + def __init__(self, transition, start, accepts, map_): + self.transition = transition + self.start = start + self.accepts = accepts + self.map = map_ + def getRuntime(self): + return DFARuntime(self) + +class DFARuntime(object): + def __init__(self, DFA): + self.DFA = DFA + self.curState = self.DFA.start + + def doTransition(self, char): + self.curState = self.DFA.transition( + self.curState, char) + + def isAcceptState(self): + return self.curState in self.DFA.accepts + + def doesAccept(self, input): + for alphabet in input: + self.doTransition(alphabet) + return self.isAcceptState() + +class Token(object): + CHARACTER = 0 + OPE_UNION = 1 + OPE_STAR = 2 + LPAREN = 3 + RPAREN = 4 + EOF = 5 + + def __init__(self, value, kind): + self.value = value + self.kind = kind + + +class Lexer(object): + def __init__(self, str): + self.stringList = list(str) + + def scan(self): + if not self.stringList: + return Token(None, Token.EOF) + + ch = self.stringList.pop(0) + if ch == '\\': + return Token(self.stringList.pop(0), Token.CHARACTER) + elif ch == '|': + return Token(ch, Token.OPE_UNION) + elif ch == '(': + return Token(ch, Token.LPAREN) + elif ch == ')': + return Token(ch, Token.RPAREN) + elif ch == '*': + return Token(ch, Token.OPE_STAR) + else: + return Token(ch, Token.CHARACTER) + +""" + Context-free Grammer: + (A) expression -> subexpr EOF + (B) subexpr -> seq '|' subexpr | seq + (C) seq -> subseq | '' + (D) subseq -> star subseq | star + (E) star -> factor '*' | factor + (F) factor -> '(' subexpr ')' | CHARACTER +""" + +class Parser(object): + def __init__(self, lexer): + self.lexer = lexer + self.look = None + self.move() + + def match(self, tag): + if self.look.kind != tag: + raise Exeption("syntax error") + self.move() + + def move(self): + self.look = self.lexer.scan() + + def factor(self): + if self.look.kind == Token.LPAREN: + # factor -> '(' subexpr ')' + self.match(Token.LPAREN) + node = self.subexpr() + self.match(Token.RPAREN) + return node + else: + # factor -> CHARACTER + node = Character(self.look.value) + self.match(Token.CHARACTER) + return node + + def star(self): + # star -> factor '*' | factor + node = self.factor() + if self.look.kind == Token.OPE_STAR: + self.match(Token.OPE_STAR) + node = Star(node) + return node + + def seq(self): + if self.look.kind == Token.LPAREN \ + or self.look.kind == Token.CHARACTER: + # seq -> subseq + return self.subseq() + else: + # seq -> '' + return Character("") + + def subseq(self): + node1 = self.star() + if self.look.kind == Token.LPAREN \ + or self.look.kind == Token.CHARACTER: + # subseq -> star subseq + node2 = self.subseq() + node = Concat(node1, node2) + return node + else: + # subseq -> star + return node1 + + def subexpr(self): + node1 = self.seq() + if self.look.kind == Token.OPE_UNION: + self.match(Token.OPE_UNION) + # subexpr -> seq '|' subexpr + node2 = self.subexpr() + node = Union(node1, node2) + return node + else: + # subexpr -> seq + return node1 + + def expression(self): + # expression -> subexpr EOF + node = self.subexpr() + self.match(Token.EOF) + + # Create TREE, NFA + context = Context() + fragment = node.assemble(context) + return fragment.build() + +class Context(object): + def __init__(self): + self.stateCount = 0 + + def newState(self): + self.stateCount += 1 + return self.stateCount + +class NFAFragment(object): + def __init__(self): + self.start = None # integer + self.accepts = None # frozenset + self.map = dict() # transition + + def connect(self, from_, char, to): + slot = self.map.setdefault((from_, char), set()) + slot.add(to) + + def newSkelton(self): + # copy fragment (self), and it return + newFrag = NFAFragment(); + newFrag.map = copy.deepcopy(self.map) + return newFrag + + def __or__(self, frag): + newFrag = self.newSkelton() + for k, v in frag.map.iteritems(): + newFrag.map[k] = v.copy() + return newFrag + + def build(self): + map_ = self.map + def transition(state, char): + return frozenset(map_.get((state, char), [])) + + return NondeterministicFiniteAutomaton( + transition, + self.start, + self.accepts, + self.map + ) + +class Character(object): + def __init__(self, char): + self.char = char + + def assemble(self, context): + frag = NFAFragment() + s1 = context.newState() + s2 = context.newState() + frag.connect(s1, self.char, s2) + frag.start = s1 + frag.accepts = frozenset([s2]) + return frag + +class Union(object): + def __init__(self, op1, op2): + self.op1 = op1 + self.op2 = op2 + + def assemble(self, context): + frag1 = self.op1.assemble(context) + frag2 = self.op2.assemble(context) + frag = frag1 | frag2 + s = context.newState() + frag.connect(s, "", frag1.start) + frag.connect(s, "", frag2.start) + frag.start = s + frag.accepts = frag1.accepts | frag2.accepts + return frag + +class Concat(object): + def __init__(self, op1, op2): + self.op1 = op1 + self.op2 = op2 + + def assemble(self, context): + frag1 = self.op1.assemble(context) + frag2 = self.op2.assemble(context) + frag = frag1 | frag2 + + for state in frag1.accepts: + frag.connect(state, "", frag2.start) + + frag.start = frag1.start + frag.accepts = frag2.accepts + return frag + +class Star(object): + def __init__(self, op): + self.op = op + + def assemble(self, context): + fragOrig = self.op.assemble(context) + frag = fragOrig.newSkelton() + + for state in fragOrig.accepts: + frag.connect(state, "", fragOrig.start) + + s = context.newState() + frag.connect(s, "", fragOrig.start) + frag.start = s + frag.accepts = fragOrig.accepts | frozenset([s]) + return frag + +class NonDisjoinSets(object): + def __init__(self, sub): + self.sub = sub + def __contains__(self, a_set): + return a_set & self.sub + +def nfa2dfa(nfa): + def transition(set_, alpha): + ret = set() + for elem in set_: + ret |= nfa.transition(elem, alpha) + return nfa.epsilonExpand(frozenset(ret)) + + def stateSetTransition(stateSet, char): + trans = set() + for state in stateSet: + t = nfa.map.setdefault((state, char), None) + if not t == None: trans.update(nfa.epsilonExpand(t)) + return frozenset(trans) + + map_ = dict() + que = set(frozenset([nfa.epsilonExpand(set([nfa.start]))])) + done = set() + + while que: + stateSet = que.pop() + + for state in stateSet: + for k, v in nfa.map.iteritems(): + if state == k[0] and k[1] != '': + slot = map_.setdefault((stateSet, k[1]), set()) + slot.update(nfa.epsilonExpand(v)) + + done.add(stateSet) + + for v in map_.itervalues(): + if not v in done: + que.add(frozenset(v)) + + return DeterministicFiniteAutomaton( + transition, + nfa.epsilonExpand(frozenset([nfa.start])), + NonDisjoinSets(nfa.accepts), + map_ + ) + +# emit CbC-souce, from dfa +def dfa2CbC(dfa, regexp): + + # return state name from set + def set2name(set_): + l = list(set_) + l.sort() + return '_'.join(str(x) for x in l) + + funcMap = dict() + funcMap[dfa.start] = set() + + # dfa.map => {(frozenset([1, 15]), 'd'): frozenset([16]), ....} + # : frozenset(1, 15) x 'd' -> frozenset([16]) + + for v in dfa.map.itervalues(): + funcMap[frozenset(v)] = set() + + for key in dfa.map.iterkeys(): + slot = funcMap.setdefault(key[0], set()) + slot.add(key[1]) + + # emit cbc code + print "#include <stdio.h>\n" + print "#include <stdlib.h>\n" + for k in funcMap.iterkeys(): + print '__code state_' + set2name(k) + "(char* s);" + print '__code accept();' + print '__code reject();' + print """ +int main(int argc, char* argv[]) { +\tif (argc == 1) { +\t\tprintf(\"usage: %%s text\\n\", argv[0]); +\t\texit(0); +} + +\tputs(\"regexp: %s\"); +\tputs(\"number of state: %d\"); +\tprintf(\"string: %%s\\n\", argv[1]); +\tgoto state_%s(argv[1]); +\treturn 0; +}\n""" % (regexp, len(funcMap), set2name(dfa.start)) + + for k, v in funcMap.iteritems(): + print '__code state_' + set2name(k) + "(char* s) {" + print "\tswitch(*s++) {" + for case in v: + print "\t\tcase '%c': " % (case) + print "\t\t\tgoto state_%s(s);\n\t\t\tbreak;" % set2name(dfa.map[(frozenset(k), case)]) + if k in dfa.accepts: print "\t\tcase '\\0': goto accept();\n\t\t\tbreak;" + print "\t\tdefault: goto reject();\n\t}" + print "}\n" + + print """ +__code accept() { +\tprintf(\"\\nstring matches regexp. \\n\\n\"); +}\n""" + print """ +__code reject() { +\tprintf(\"\\nstring does not match regexp. \\n\\n\"); +}\n""" + +class Regexp(object): + def __init__(self, regexp): + self.regexp = regexp + self.nfa = None + self.dfa = None + self._compile() + + def _compile(self): + lexer_ = Lexer(self.regexp) + parser_ = Parser(lexer_) + self.nfa = parser_.expression() + self.dfa = nfa2dfa(self.nfa) + + def emitCbC(self): + dfa2CbC(self.dfa, self.regexp) + + def matches(self, string): + runtime = self.dfa.getRuntime() + return runtime.doesAccept(string) + +def compile(regexp): + return Regexp(regexp) + +def main(argv): + if len(argv) == 1 : exit("usage: dfareg.py regexp [> file]") + r = compile(argv[1]) + r.emitCbC() + +if __name__ == '__main__' : main(sys.argv)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/return_check/test_return.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,89 @@ +#include<stdio.h> + +#if 0 +typedef float testtype; +testtype good = 33.3f; +testtype bad = 0.0f; +void print_testtype(testtype t) +{ + printf("return value = %2.3f good=%2.3f,bad=%2.3f\n", t,good,bad); +} +#elif 1 +typedef char testtype; +testtype good = 33; +testtype bad = 0; +void print_testtype(testtype t) +{ + printf("return value = %d, good=%d,bad=%d\n", t,good,bad); +} +#elif 0 +typedef double testtype; +testtype good = 333.3; +testtype bad = 0.00; +void print_testtype(testtype t) +{ + printf("return value = %3.3lf, good=%3.3lf,bad=%3.3lf\n", t,good,bad); +} +#elif 0 +typedef +struct { + int a; + float b; + int c[4]; +} testtype; +testtype good = {33, 33.3, {4,4,4,4}}; +testtype bad = {0, 00.0, {0,0,0,0}}; +void print_testtype(testtype t) +{ + printf( "return value = {\n" + " a = %d\n" + " b = %2.3f\n" + " c = { %d, %d, %d, %d }" + "}\n", t.a, t.b, + t.c[0],t.c[1],t.c[2],t.c[3]); +} +#else +typedef int testtype; +testtype good = 33; +testtype bad = 0; +void print_testtype(testtype t) +{ + printf("return value = %d, good=%d,bad=%d\n", t,good,bad); +} +#endif + +typedef void (*RET_FUNC)(testtype, void *); + +void g(RET_FUNC func) +{ + func(good, NULL); +} + +testtype f_cbc() +{ + //__label__ _cbc_exit0; + //int retval; + void *ret; + + ret = _CbC_return; + + printf("f0: fp = %p\n", __builtin_frame_address(0)); + printf("__return_func = %p\n", ret); + g(ret); + + printf("not good\n"); + return bad; +//_cbc_exit0: + //printf("f1: fp = 0x%x\n", __builtin_frame_address(0)); + //return retval; +} + +int main(int argc, char **argv) +{ + testtype t; + printf("main before: fp = %p\n", __builtin_frame_address(0)); + t = f_cbc(); + print_testtype(t); + printf("main after: fp = %p\n", __builtin_frame_address(0)); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/return_check/typedeffed.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,89 @@ +#include<stdio.h> + +#if 0 +typedef float testtype; +testtype good = 33.3f; +testtype bad = 0.0f; +void print_testtype(testtype t) +{ + printf("return value = %2.3f good=%2.3f,bad=%2.3f\n", t,good,bad); +} +#elif 1 +typedef char testtype; +testtype good = 33; +testtype bad = 0; +void print_testtype(testtype t) +{ + printf("return value = %d, good=%d,bad=%d\n", t,good,bad); +} +#elif 0 +typedef double testtype; +testtype good = 333.3; +testtype bad = 0.00; +void print_testtype(testtype t) +{ + printf("return value = %3.3lf, good=%3.3lf,bad=%3.3lf\n", t,good,bad); +} +#elif 0 +typedef +struct { + int a; + float b; + int c[4]; +} testtype; +testtype good = {33, 33.3, {4,4,4,4}}; +testtype bad = {0, 00.0, {0,0,0,0}}; +void print_testtype(testtype t) +{ + printf( "return value = {\n" + " a = %d\n" + " b = %2.3f\n" + " c = { %d, %d, %d, %d }" + "}\n", t.a, t.b, + t.c[0],t.c[1],t.c[2],t.c[3]); +} +#else +typedef int testtype; +testtype good = 33; +testtype bad = 0; +void print_testtype(testtype t) +{ + printf("return value = %d, good=%d,bad=%d\n", t,good,bad); +} +#endif + +typedef void (*RET_FUNC)(testtype, void *); + +void g(RET_FUNC func) +{ + func(good, NULL); +} + +testtype f_cbc() +{ + //__label__ _cbc_exit0; + //int retval; + void *ret; + + ret = _CbC_return; + + printf("f0: fp = %p\n", __builtin_frame_address(0)); + printf("__return_func = %p\n", ret); + g(ret); + + printf("not good\n"); + return bad; +//_cbc_exit0: + //printf("f1: fp = 0x%x\n", __builtin_frame_address(0)); + //return retval; +} + +int main(int argc, char **argv) +{ + testtype t; + printf("main before: fp = %p\n", __builtin_frame_address(0)); + t = f_cbc(); + print_testtype(t); + printf("main after: fp = %p\n", __builtin_frame_address(0)); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/return_check/variable_return_type.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,196 @@ +#include<stdio.h> +#include<assert.h> + +#define dprint(f, args...) \ + fprintf(stdout, "in %s\t: "f, __FUNCTION__, ## args) + + +/* for integer. */ +int goodint = 33; +int badint = 0; +typedef void (*RETINT_FUNC)(int, void *); +void g_int(RETINT_FUNC func) +{ + func(goodint, NULL); +} +int f_int() +{ + void *ret; + + ret = _CbC_return; + + dprint("fp = %p\n", __builtin_frame_address(0)); + dprint("__return_func = %p\n", ret); + g_int(ret); + //goto g(ret); + + dprint("not good\n"); + return badint; +} + + +/* for double. */ +double gooddouble = 333.3; +double baddouble = 0.00; +typedef void (*RETDOUBLE_FUNC)(double, void *); +void g_double(RETDOUBLE_FUNC func) +{ + func(gooddouble, NULL); +} +double f_double() +{ + void *ret; + ret = _CbC_return; + + dprint("fp = %p\n", __builtin_frame_address(0)); + dprint("__return_func = %p\n", ret); + g_double(ret); + //goto g_double(ret); + + dprint("not good\n"); + return baddouble; +} + +/* for float. */ +float goodfloat = 33.3f; +float badfloat = 0.0f; +typedef void (*RETFLOAT_FUNC)(float, void *); +void g_float(RETFLOAT_FUNC func) +{ + func(goodfloat, NULL); +} +float f_float() +{ + void *ret; + ret = _CbC_return; + + dprint("fp = %p\n", __builtin_frame_address(0)); + dprint("__return_func = %p\n", ret); + g_float(ret); + //goto g_float(ret); + + dprint("not good\n"); + return badfloat; +} + +/* for char. */ +char goodchar = 33; +char badchar = 0; +typedef void (*RETCHAR_FUNC)(char, void *); +void g_char(RETCHAR_FUNC func) +{ + func(goodchar, NULL); +} +char f_char() +{ + void *ret; + + ret = _CbC_return; + + dprint("fp = %p\n", __builtin_frame_address(0)); + dprint("__return_func = %p\n", ret); + g_char(ret); + //goto g(ret); + + dprint("not good\n"); + return badchar; +} + + +/* for struct. */ +struct ifid { + int a; + float b; + int c[4]; + double d; +}; +struct ifid goodstruct = {33, 33.3, {4,4,4,4}, 333.333}; +struct ifid badstruct = {0, 00.0, {0,0,0,0}, 0.0}; +typedef void (*RETSTRUCT_FUNC)(struct ifid, void *); +void g_struct(RETSTRUCT_FUNC func) +{ + func(goodstruct, NULL); +} +struct ifid f_struct() +{ + void *ret; + + ret = _CbC_return; + + dprint("fp = %p\n", __builtin_frame_address(0)); + dprint("__return_func = %p\n", ret); + g_struct(ret); + //goto g(ret); + + dprint("not good\n"); + return badstruct; +} + +int main(int argc, char **argv) +{ + void *bptr; + int rint; + float rfloat; + double rdouble; + char rchar; + struct ifid rstruct; + + bptr = __builtin_frame_address(0); + + dprint("before int: fp = %p\n", __builtin_frame_address(0)); + rint = f_int(); + dprint("f_int = %d, good=%d,bad=%d\n", rint,goodint,badint); + + dprint("before float: fp = %p\n", __builtin_frame_address(0)); + rfloat = f_float(); + dprint("f_float = %3.3f, good=%3.3f,bad=%3.3f\n", rfloat,goodfloat,badfloat); + assert(bptr==__builtin_frame_address(0)); + + dprint("before double: fp = %p\n", __builtin_frame_address(0)); + rdouble = f_double(); + dprint("f_double = %3.3lf, good=%3.3lf,bad=%3.3lf\n", rdouble,gooddouble,baddouble); + assert(bptr==__builtin_frame_address(0)); + + dprint("before char: fp = %p\n", __builtin_frame_address(0)); + rchar = f_char(); + dprint("f_char = %d, good=%d,bad=%d\n", rchar,goodchar,badchar); + assert(bptr==__builtin_frame_address(0)); + + dprint("before struct: fp = %p\n", __builtin_frame_address(0)); + rstruct = f_struct(); + dprint( "return value = {\n" + " a = %d\n" + " b = %2.3f\n" + " c = { %d, %d, %d, %d }\n" + " d = %3.3f\n" + "}\n", rstruct.a, rstruct.b, + rstruct.c[0],rstruct.c[1],rstruct.c[2],rstruct.c[3], rstruct.d); + + + + dprint("end: fp = %p\n", __builtin_frame_address(0)); + + if (bptr!=__builtin_frame_address(0)) { + dprint("CbC_return failure!\n"); + return 1; + } + if ( rint!=goodint + || rchar!=goodchar + || (rfloat < goodfloat-0.01 || goodfloat+0.01 < rfloat) + || (rdouble < gooddouble-0.01 || gooddouble+0.01 < rdouble) + || rstruct.a!=goodstruct.a + || (rstruct.b < goodstruct.b-0.01 || goodstruct.b+0.01 < rstruct.b) + || (rstruct.d < goodstruct.d-0.01 || goodstruct.d+0.01 < rstruct.d) + || rstruct.c[0]!=goodstruct.c[0] + || rstruct.c[1]!=goodstruct.c[1] + || rstruct.c[2]!=goodstruct.c[2] + || rstruct.c[3]!=goodstruct.c[3] ) { + dprint("CbC_return failure!\n"); + return 1; + } + + + dprint("CbC_return successful!\n"); + return 0; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/stack1.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,126 @@ +/* + test for CbC converted __code from C + */ + +//#include <stdio.h> +#define NULL 0 + +extern void *malloc(int); + +typedef void *stack; + +void *stack0; /* size of void* == 1 */ + +struct cont_save { /* General Return Continuation */ + __code (*ret)(); +}; + + __code g(int,void *); + __code f_g0(int ,int ,void *); + __code f_g1(int,void *); + __code print(int i,int j,__code (*exit1)(),void*exit1env); + +struct f_g0_save { /* Specialized Return Continuation */ + __code (*ret)(); + int ii,kk,jj; +}; + +__code g(int i,void *sp) { + goto (* ((struct cont_save *)sp)->ret)(i+4,sp); +} + +__code __attribute__ ((fastcall)) f_g1(int j,void *sp) { /* Continuation */ + int k; + struct f_g0_save *c; + + c = sp; + k = c->kk; + sp += sizeof(struct f_g0_save); + goto (* ((struct cont_save *)sp)->ret)(k+4+j,sp); +} + +__code f(int i,void *sp) { + int k,j; + struct f_g0_save *c; +printf("#0042:f 0 sp: %x\n",sp-stack0); + + k = 3+i; + +printf("#0046:f 1 sp: %x\n",sp-stack0); + sp -= sizeof(struct f_g0_save); +printf("#0048:f 2 sp: %x\n",sp-stack0); + c = sp; + c->kk = k; + c->ii = i; + c->jj = j; + c->ret = f_g1; + goto g(i,sp); +} + + + +struct f0_save { /* Specialized Return Continuation */ + __code (*ret)(); + __code (*exit1)(); + void *exit1env; + int jj; +}; + +__code f1(int i,void *sp) ; +__code f0(int i,int j,__code(*exit2)(), void *exit2env,void *sp) +{ + struct f0_save *c; + printf("#0070:f0 1 sp: %x\n",sp-stack0); + sp -= sizeof(struct f0_save); + printf("#0072:f0 2 sp: %x\n",sp-stack0); + c = sp; + c->jj = j; + c->exit1 = exit2; + c->exit1env = exit2env; + c->ret = f1; + printf("#0078:f0 3 sp: %x\n",sp-stack0); + goto f(i,sp); +} + +__code f1(int i,void *sp) { + int j; + int *exit2env; + __code (*exit2)(); + struct f0_save *c; + + c = sp; + j = c->jj; + exit2 = c->exit1; + exit2env = c->exit1env; + + sp += sizeof(struct f0_save); + goto print(i,j,exit2,exit2env); +} + +int main(int ac, char*av[]){ + main0(ac,av); +} + +int main0( int ac, char *av[]) +{ + int i,j; + int *sp; + + // i = atoi(av[1]); + i = 1; + stack0 = ((char *)malloc(1024)+1024); + sp = stack0; + j = i; + + printf("#0108:sp: %x %x\n",sp-(int*)stack0,sizeof(*stack0)); + //goto f0(i,j,_CbC_return,_CbC_environment,sp); + goto f0(i,j,NULL,NULL,sp); +} + +__code print(int i,int j,__code (*exit1)(),void*exit1env) +{ + printf("#0114:%d %d\n",i,j); + //goto (*exit1)(0),exit1env; + exit(0); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test01.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,34 @@ +#include<stdio.h> + +int test_code(void){ + printf("\t\ttest_code: return 10\n"); + return 10; +} + +int test_goto(int a){ + printf("\ttest_goto: a = %d\n", a); + //return test_code(); + return test_code(); +} + +int main(int argc, char **argv){ + int ret; + printf("test code\n"); + ret = test_goto(20); + printf("main: ret = %d\n", ret); + + return test_goto2(10,20,30,40,50,60,70,80,90,100); + return 0; +} + +int test_code2(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j,int k){ + printf("\t\ttest_code: return 10\n"); + printf("a=%d,b=%d,c=%d,d=%d,e=%d,f=%d,g=%d,h=%d,i=%d,j=%d,k=%d\n",a,b,c,d,e,f,g,h,i,j,k ); + return a+b+c+d+e+f+g+h+i+j+k; +} + +int test_goto2(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j,int k){ + printf("\ttest_goto: a = %d\n", a); + //return test_code(); + return test_code2(a,b,c,d,e,f,g,h,i,j,k); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test02.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,22 @@ +#include<stdio.h> + +__code test_code(void){ + printf("\t\ttest_code: return 10\n"); + return; +} + +__code test_goto(int a){ + printf("\ttest_goto: a = %d\n", a); + //return test_code(); + goto test_code(); +} + +int main(int argc, char **argv){ + int ret=0; + printf("test code\n"); + test_goto(20); + printf("main: ret = %d\n", ret); + + return 0; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test03.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,26 @@ + +extern void test02() ; +extern void test03() ; + +extern int data; + +extern void +test01() { + test02(); +} + +extern void +test02() { + test03(); +} + +extern void +test03() { + data = 3; +} + +int +main() +{ + test01(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test04.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,33 @@ + +int test01(int a, double b, int *c){ + return a+b- *c; +} + +int test(int *a, double b){ + int c; + c = *a*b + 10; + printf("a = %x, *a = %d, b = %d\n", a, *a, b); + *a = test01( *a+b, 0.02, &c); + return *a+b; +} + + +int test02(int a, int b){ + int i,sum=0; + i = a; + while ( i <= b ) { + sum += i; + i++; + } + return sum - a*b; +} + +int main(int argc, char **argv){ + int a=10; + + printf("= %d\n", test02(0, 10)); + test( &a, 10.1); + return 0; +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test05.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,58 @@ +//#include<stdio.h> +#define dprint(f, args...) \ + printf("in %s: "f, __FUNCTION__, ## args) + +__code caller (int a); +void f01 (int a); +void f02 (int a, float b); +__code cs01 (int a); +__code cs02 (int a, float b); +int main (); + + +int g=0; +void (*funcp)(int); +__code (*csp)(int); + +__code caller(int a) { + f01(a+2); + f02(a+3, 13.2); + funcp(a+4); + goto csp(a+4); + dprint("\n"); +} + +__code end() { + dprint("\n"); + exit(0); +} + +void f01(int a) { + dprint("%d\n", a); + g += a; + return ; +} +void f02(int a, float b) { + dprint("%d, %f\n", a, b); + g -= a; + g += b*0.3; + return ; +} +__code cs01(int a) { + dprint("%d\n", a); + g += a; + goto end() ; +} +__code cs02(int a, float b) { + dprint("%d, %f\n", a, b); + g -= a; + g += b*0.3; + goto end() ; +} + +int main() { + funcp = f01; + csp = cs01; + caller(10); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test_array.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,17 @@ +//#include<stdio.h> +void print_array(int *, int); + +int main(int argc, char **argv){ + int array[10] = {10, 2, 3, 0, 7, 5}; + array[1] += array[2]+array[4]; + print_array(array, 10); + return 0; +} + +void print_array(int *a, int size){ + while( size-->0 ){ + printf(" %7d", *a++); + } + printf("\n"); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test_call.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,12 @@ + +int test(int a){ + printf("a = %d\n", a); + return 10*a; +} + +int main(){ + test(10); + return 0; +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test_cs.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,43 @@ +//#include<stdio.h> +//#include<stdlib.h> + +__code cs_exit(int , double , char ); +__code cs1(int, int, int, int); +__code cs2(double, double, int, double); +void test_goto(void); + +int main(int argc, char **argv){ + printf("main start\n"); + //goto cs2(2.22, 3.33, 4, 5.55); + test_goto(); + return 0; +} + +void test_goto(){ + goto cs1(10, 20, 30, 40); +} + +__code cs1(int a, int b, int c, int d){ + printf("%4d, %4d, %4d, %4d\n", a, b, c, d); + a += 40, b += 40, c += 40, d += 40; + goto cs2((double)a, (double)b, c, (double)d); +} + +__code cs2(double a, double b, int c, double d){ + printf("%4d, %4d, %4d, %4d\n", (int)a, (int)b, (int)c, (int)d); + a += 40, b += 40, c += 40, d += 40; + goto cs_exit((int)a, b, (char)c); +} + +__code cs_exit(int a, double b, char c){ + printf("%4d, %4d, %4d\n", (int)a, (int)b, (int)c); + printf("cs_exit was called!\n"); + exit(0); +} + + +void caller(int a, double b){ + cs2(b,20.0,a, 40.4); + cs1(10,20,30, 40); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test_csp1.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,60 @@ +#include<stdio.h> +#include<stdlib.h> + +//static __code (*csp)(int, int, int, int); + +__code cs_end (int a); +__code cs0 (int a, int b, int c, int d); +void* freturn (); +__code cs_goto (int a, int b, int c, int d); +int function (double a, float b, int c); +int main (int argc, char **argv); + + +__code cs_goto(int a, int b, int c, int d){ + __code (*csp)(int, int, int, int); + csp = freturn(); + printf("csp = %x.\n", csp); + + //printf("cs_goto : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d.\n", a, b, c, d, e, f, g); + //printf("cs_goto : a=%d, b=%d, c=%d, d=%d.\n", a, b, c, d); + //printf("cs_goto : a-4=%d, a-8=%d, a-12=%d, a-16=%d.\n", *(&a-4), *(&a-8), *(&a-12), *(&a-16)); + //printf("cs_goto : cs0(a, b, c, d)\n"); +#ifdef INDIRECT + goto csp(b+a, d+b, a+c, c+d); +#else + goto cs0(b+a, d+b, a+c, c+d); +#endif +} + +__code cs_end(int a){ + printf("cs_exit : a=%d.\n", a); + exit(a); + goto cs_end(a); +} + +__code cs0(int a, int b, int c, int d){ + //printf("cs0 : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d.\n", a, b, c, d, e, f, g); + printf("cs_cs0 : a=%d, b=%d, c=%d, d=%d.\n", a, b, c, d); + goto cs_end( (int)(20*a + 30*b + 40*c + 50*d) ); +} + + +void* freturn(){ + return cs0; +} + +int function(double a, float b, int c){ + + printf("function:\n"); + printf("a=%lf, b=%f, c=%d\n", a, b, c); + //goto cs_goto(10, 20, 30, 40); + goto cs_goto(10, 20, 30, 40); +} + +int main(int argc, char **argv){ + //csp = cs0; + function(10.01, 20.02, 30); + return 0; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test_env.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,68 @@ + +typedef void (*RET_FUNC)(int, void *); + +int main(int argc, char **argv) +{ + int r; + r = f(); + printf("%d\n", r); +} + +//void z(RET_FUNC ret, void *fp) +__code z(RET_FUNC ret, void *fp) +{ + printf("z: fp=0x%x\n", __builtin_frame_address(0)); + ret(5, fp); +} +__code i(RET_FUNC ret, void *fp) +{ + printf("i: fp=0x%x\n", __builtin_frame_address(0)); + goto z(ret, fp); +} +__code h(RET_FUNC ret, void *fp) +{ + printf("h: fp=0x%x\n", __builtin_frame_address(0)); + goto i(ret, fp); +} +__code g(RET_FUNC ret, void *fp) +{ + printf("g: fp=0x%x\n", __builtin_frame_address(0)); + goto h(ret, fp); +} + +int f() +{ + __label__ exit0; + int retval; + //void (*ret)(int retval_, void *fp); + + /* + ret = ({ + void __return_func(int retval_, void *fp){ + retval = retval_; + goto exit0; + } + __return_func; + }); + */ + printf("f0: fp = 0x%x\n", __builtin_frame_address(0)); + void __return_func(int retval_, void *fp){ + retval = retval_; + goto exit0; + } + //ret = __return_func; + + printf("f1: fp = 0x%x\n", __builtin_frame_address(0)); + + //g(__return_func, __builtin_frame_address(0)); + goto g(__return_func, __builtin_frame_address(0)); + + printf("bad\n"); + +exit0: + printf("f2: fp = 0x%x\n", __builtin_frame_address(0)); + return retval; +} + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test_func2code.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,43 @@ +#include<stdio.h> +#include<stdlib.h> + +#define DEBUG 1 +#ifdef DEBUG + #define log(f, args...) \ + fprintf(stderr, "in %s: "f, __FUNCTION__, ## args) +#else + #define log(f, args...) ; +#endif + +__code +exitter(int a) +{ + exit(0); +} + +__code +cs0(int x, int y) +{ + log("x = %d, y = %d.\n", x, y); + log("will exit with code %d.\n", x*y); + goto exitter(x*y); +} + +void +continuation(int a) +{ + log("go code segment cs0\n"); + goto cs0(a, a*20); + log("Error: continuation reachs bad region.\n"); +} + +int +main(int argc, char **argv) +{ + int a; + if (argc>2) { + a = atoi(argv[1]); + } + + continuation(20); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test_nest.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,50 @@ + +int printf(char *, ...); +typedef void (*RET_FUNC)(int, void *); + +void g(RET_FUNC func) +{ + func(33, 0); +} + +int f() +{ + void *ret; + ret = ({ + __label__ exit0; + int retval; + void __return_func(int retval_, void *fp){ + retval = retval_; + goto exit0; + } + if (0) { + exit0: + printf("f2: fp = 0x%x\n", __builtin_frame_address(0)); + return retval; + } + __return_func; + }); + + //g(__return_func, __builtin_frame_address(0)); + printf("f0: fp = 0x%x\n", __builtin_frame_address(0)); + printf("__return_func = %x\n", ret); + g(ret); + + printf("not good\n"); + return 0; + +//exit0: + //printf("f2: fp = 0x%x\n", __builtin_frame_address(0)); + //return retval; +} + +int main(int argc, char **argv) +{ + int t; + printf("main before: fp = 0x%x\n", __builtin_frame_address(0)); + t = f(); + printf("f = %d\n", t); + printf("main after: fp = 0x%x\n", __builtin_frame_address(0)); +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test_para.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,26 @@ +#include<stdio.h> +#include<stdlib.h> + +__code cs_exit(int a){ + printf("cs_exit was called: a=%d.\n", a); + exit(a); +} + +__code cs0(int a, double b, int c, int d){ + printf("cs0 was called: a=%d, b=%lf, c=%d, d=%d.\n", a, b, c, d); + goto cs_exit( (int)(20*a + 4.4*b + 2022/c + 28*d) ); +} + + +__code cs_goto(){ + goto cs0(11, 22.2, 33, 44); +} + +int main(int argc, char **argv){ + + printf("it is in main.\n"); + goto cs_goto(); + return 0; +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test_para2.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,40 @@ +#include<stdio.h> +#include<stdlib.h> + +__code cs_end(int a){ + printf("cs_exit : a=%d.\n", a); + exit(a); +} + +__code cs0(int a, int b, int c, int d); + +__code cs_goto(int a, int b, int c, int d){ + //printf("cs_goto : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d.\n", a, b, c, d, e, f, g); + printf("cs_goto : a=%d, b=%d, c=%d, d=%d.\n", a, b, c, d); + //printf("cs_goto : a-4=%d, a-8=%d, a-12=%d, a-16=%d.\n", *(&a-4), *(&a-8), *(&a-12), *(&a-16)); + //printf("cs_goto : cs0(a, b, c, d)\n"); + goto cs0(b, c, d, a); +} + +__code cs0(int a, int b, int c, int d){ + //printf("cs0 : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d.\n", a, b, c, d, e, f, g); + printf("cs_cs0 : a=%d, b=%d, c=%d, d=%d.\n", a, b, c, d); + goto cs_end( (int)(20*a + 30*b + 40*c + 50*d) ); +} + + +int function(double a, float b, int c){ + + //printf("function:\n"); + //printf("a=%lf, b=%f, c=%d\n", a, b, c); + //goto cs_goto(10, 20, 30, 40); + goto cs_goto(10, 20, 30, 40); +} + +int main(int argc, char **argv){ + + function(10.01, 20.02, 30); + return 0; +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test_para3.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,83 @@ +#include<stdio.h> +#include<stdlib.h> + +struct abc { + int a; + double b; + char c; + double *d; +}; + +struct def { + int d; + struct abc e; + struct abc *f; +}; + +void print_abc(struct abc a){ + printf("\tstruct abc:\n"); + printf("\ta=%d, b=%lf, c=%d, d=%p\n", a.a, a.b, a.c, a.d); +} +void print_def(struct def b){ + printf("\tstruct def:\n"); + printf("\td=%d, f=%p\n", b.d, b.f); + print_abc(b.e); +} + +__code cs_exit(int a){ + printf("cs_exit : a=%d.\n", a); + exit(a); +} + +__code cs0(struct abc a, struct def b, int c){ + printf("cs0 :\n"); + printf("c=%d\n", c); + print_abc(a); + print_def(b); + goto cs_exit( c*a.a+b.e.c ); +} + + +__code cs_goto(int c, struct abc a, struct def b){ + printf("cs_goto :\n"); + printf("c=%d\n", c); + print_abc(a); + print_def(b); + goto cs0(a, b, c); +} + +int function(){ + struct abc A; + struct def B; + A.a = 10, A.b = 20.02, A.c = '\0', A.d = 0xad; + B.d = 30, B.f = 0xbf; + B.e.a = 50, B.e.b = 60.06, B.e.c = '\1', B.e.d = 0xed; + + printf("function :\n"); + print_abc(A); + print_def(B); + //printf("20*%d + 30*%d + 40*%d + 50*%d =\n", a, b, c, d); + goto cs_goto(100, A, B); + return 0; +} + +int main(int argc, char **argv){ + struct abc A; + struct def B; + //int a=10, b=20, c=30, d=40, e=50, f=60, g=70; + A.a = 10, A.b = 20.02, A.c = '\0', A.d = 0xad; + B.d = 30, B.f = 0xbf; + B.e.a = 50, B.e.b = 60.06, B.e.c = '\1', B.e.d = 0xed; + + /* + printf("main :\n"); + print_abc(A); + print_def(B); + //printf("20*%d + 30*%d + 40*%d + 50*%d =\n", a, b, c, d); + goto cs_goto(100, A, B); + */ + function(); + return 0; +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test_para4.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,74 @@ +//#include<stdio.h> +//#include<stdlib.h> + +#define DPRINT 1 +#define NOINLINE __attribute__((noinline)) + +extern __code cs_goto(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, + int a2, int b2, int c2, int d2, int e2, int f2, int g2, int h2, int i2, int j2); +extern __code cs0(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, + int a2, int b2, int c2, int d2, int e2, int f2, int g2, int h2, int i2, int j2); + +__code (*csp)(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, + int a2, int b2, int c2, int d2, int e2, int f2, int g2, int h2, int i2, int j2); + +__code NOINLINE cs_exit(int a){ + int b = 20 * a + 3; + printf("cs_exit : a=%d. b=%d\n", a, b); + exit(a); +} + +__code NOINLINE cs0(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, + int a2, int b2, int c2, int d2, int e2, int f2, int g2, int h2, int i2, int j2){ +#if DPRINT + //printf("cs0 : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d.\n", a, b, c, d, e, f, g); + printf("cs0 : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", + a, b, c, d, e, f, g, h, i, j); + printf("cs0 : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", + a2, b2, c2, d2, e2, f2, g2, h2, i2, j2); +#endif + goto cs_exit( (int)(10*a + 10*b + 10*i2 + 10*j2) ); +} + +__code NOINLINE cs_goto(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, + int a2, int b2, int c2, int d2, int e2, int f2, int g2, int h2, int i2, int j2){ +#if DPRINT + printf("cs_goto : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", + a, b, c, d, e, f, g, h, i, j); + printf("cs_goto : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", + a2, b2, c2, d2, e2, f2, g2, h2, i2, j2); +#endif + goto cs0(b, c, d, e, f, g, h, i, j, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, a); +} + +int function(double l, float m, int n){ + int a=10, b=20, c=30, d=40, e=50, f=60, g=70, h=80, i=90, j=100; + int a2=110, b2=120, c2=130, d2=140, e2=150, f2=160, g2=170, h2=180, i2=190, j2=200; + +#if DPRINT + printf("function: a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", + a, b, c, d, e, f, g, h, i, j); + printf("function: a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", + a2, b2, c2, d2, e2, f2, g2, h2, i2, j2); + //printf("l=%lf, m=%f, n=%d\n", l, m, n); +#endif + //goto cs_goto(10, 20, 30, 40); + goto cs_goto(a, b, c, d, e, f, g, h, i, j, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2); +} + + +int main(int argc, char **argv){ + + //printf("main :\n"); + /* + printf("main : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", + a, b, c, d, e, f, g, h, i, j); + printf("main : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", + a2, b2, c2, d2, e2, f2, g2, h2, i2, j2); + */ + //csp = cs0; + function(10.01, 20.02, 30); + return 0; +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test_return.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,89 @@ +#include<stdio.h> + +#if 0 +typedef float testtype; +testtype good = 33.3f; +testtype bad = 0.0f; +void print_testtype(testtype t) +{ + printf("return value = %2.3f good=%2.3f,bad=%2.3f\n", t,good,bad); +} +#elif 1 +typedef char testtype; +testtype good = 33; +testtype bad = 0; +void print_testtype(testtype t) +{ + printf("return value = %d, good=%d,bad=%d\n", t,good,bad); +} +#elif 0 +typedef double testtype; +testtype good = 333.3; +testtype bad = 0.00; +void print_testtype(testtype t) +{ + printf("return value = %3.3lf, good=%3.3lf,bad=%3.3lf\n", t,good,bad); +} +#elif 0 +typedef +struct { + int a; + float b; + int c[4]; +} testtype; +testtype good = {33, 33.3, {4,4,4,4}}; +testtype bad = {0, 00.0, {0,0,0,0}}; +void print_testtype(testtype t) +{ + printf( "return value = {\n" + " a = %d\n" + " b = %2.3f\n" + " c = { %d, %d, %d, %d }" + "}\n", t.a, t.b, + t.c[0],t.c[1],t.c[2],t.c[3]); +} +#else +typedef int testtype; +testtype good = 33; +testtype bad = 0; +void print_testtype(testtype t) +{ + printf("return value = %d, good=%d,bad=%d\n", t,good,bad); +} +#endif + +typedef void (*RET_FUNC)(testtype, void *); + +void g(RET_FUNC func) +{ + func(good, NULL); +} + +testtype f_cbc() +{ + //__label__ _cbc_exit0; + //int retval; + void *ret; + + ret = _CbC_return; + + printf("f0: fp = %p\n", __builtin_frame_address(0)); + printf("__return_func = %p\n", ret); + g(ret); + + printf("not good\n"); + return bad; +//_cbc_exit0: + //printf("f1: fp = 0x%x\n", __builtin_frame_address(0)); + //return retval; +} + +int main(int argc, char **argv) +{ + testtype t; + printf("main before: fp = %p\n", __builtin_frame_address(0)); + t = f_cbc(); + print_testtype(t); + printf("main after: fp = %p\n", __builtin_frame_address(0)); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test_struct.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,31 @@ + +struct aaa{ + int a; // 4 + char b; // 1 + int c; // 4 + double d; // 8 + char e[10]; //10 +}; //27 --> 32 + +int main(int argc, char **argv){ + struct aaa A; + A.a = 10; + A.b = 'A'; + A.c = 20; + A.d = 1.11; + A.e[0] = 'A', A.e[1] = 'Z'; + + printf("sizeof aaa = %d\n", sizeof(struct aaa)); + tset01( A, 10); + return 0; +} + +void tset01( struct aaa B, int size){ + printf("B.a = %d\n", B.a); + printf("B.b = %d\n", B.b); + printf("B.c = %d\n", B.c); + printf("B.d = %lf\n", B.d); + B.e[9] = '\0'; + printf("B.e = %s\n", B.e); + printf("size = %d\n", size); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test_tailcall1.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,28 @@ +#include<stdio.h> + + +void B(int a, int b, int c){ + printf("B: a=%d, b=%d, c=%d\n", a, b, c); + return ; +} + +void* freturn(){ + return B; +} +void A(int a, int b, int c, int d){ + void (*fp)(int, int, int); + fp = freturn(); + + printf("A: a=%d, b=%d, c=%d, d=%d\n", a, b, c, d); + return fp(a, b, c+d); + //return B(a, b, c+d); +} + +int main(int argc, char **argv){ + printf("main: \n"); + //fp = B; + A(10, 20, 30, 40); + return 0; +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/test_tree.c Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,54 @@ +//#include<stdio.h> +double test(char, char, int, double); +__code cs(int , double , char ); +void testvoid(double a); +int testint(double a); + +__code cs(int a, double b, char c){ + printf("__code cs was called.\n"); + printf("a = %d, b = %lf, c = %d\n", a, b, c); + exit(0); +} +__code cs1(int a, double b, char c, int d){ + printf("__code cs1 was called.\n"); + printf("a = %d, b = %lf, c = %d, d = %d\n", a, b, c, d); + exit(0); +} + +int main(int argc, char **argv){ + double t; + //goto cs(2, 10.2, 2); + + t = test('a', 'b', 10, 2.5); + printf("t = %lf\n", t); + testvoid(2.22); + testint(2.22); + + printf("test_goto\n"); + goto test_goto1(10, 20, 30.3); + return 0; +} +void test0(){ + exit(0); +} + +void testvoid(double a){ + return ; +} +int testint(double a){ + int b; + b = (a*100-a) +2; + return 1; +} + +double test(char c, char l, int a, double d){ + return (double)a*d+c+l; +} + +void test_goto(int a, int b, double c){ + goto cs(2, 10.2, 3); +} +__code test_goto1(int a, int b, double c){ + goto cs1(2, 10.2, 3, 4); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-implemantation.ja Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,207 @@ + + + GCC への CbC コンパイル機能の実装について + + +___________________________________________________________ + Code Segmentの実装 +----------------------------------------------------------- + +Code SegmentをC言語に組み込む。 +コンパイラとしては単なるvoidの関数として扱い、parse treeにcode +segmentであることのフラグを追加する。 + + * 予約語''__code``の追加 + c-common.cで定義されているc_common_reswords配列に追加 + { "__code", RID_CbC_CODE, 0} # D_CONLYも入れるか? + + * treeの生成関数 + 関数の型を表すtreeはbuild_funciton_type関数で生成されるが、code + segmentではこれを使えない。build_function_typeはhash管理でまったく同 + じ引数型、返り値型を持つものは同じオブジェクトを使うから。 + なのでbuild_code_segment_typeでこの代わりを行う。 + # 本当はbuild_function_typeのhashにcbcフラグも含める方がいいかもし + # れない。 + この関数は主にgrokdeclaratorから呼ばれる + + * cbc_set_codesegment関数 + Undocumented. + でも今は意味なかったような… + + + +___________________________________________________________ + goto文の実装 +----------------------------------------------------------- + +CbCについて重要な構文''goto cs(a, b, c);``を実装する。 +c-parser.c内の c_parser_statement_after_labels()関数における巨大なスイ +ッチ文のcase RID_GOTOのコードを修正する。 + + * アイデア + 全てのgoto文を単なる関数呼び出しとその後のリターン文と解釈することで + tail callを可能にする。 + 次のgoto文は + goto cs(a); + このparse treeでもこの様に解釈される + cs(a); + return; + + * Parser側での修正 + + オリジナルC言語のパース方法 + 1. gotoに続くトークンがCPP_NAME + 通常のgoto文として処理 + 2. gotoに続くトークンが'*` + computed gotoとして処理 + see "GCC Manual" Sec 6.3. (not internals Manual) + これを以下の様に変更する + + CbCでのパース方法 + 1. gotoに続くトークンがCPP_NAME && CPP_NAMEに次ぐトークンが';` + 通常のgoto文として処理 + 2. gotoに続くトークンが'*` + computed gotoとして処理 + 3. それ以外 + CbCのgotoとして処理 + + 処理内容 + 1. gotoトークンに続く文を関数呼び出しとみて + c_parser_expr_no_commas()関数を使ってパース、treeを取得 + # これで(*csp)(a)などにも対応できる + 2. 取得したtreeがCALL_EXPRでなければエラー + 3. treeにCbC_GOTOのフラグを立てる + 4. treeにTAILCALLのフラグを立てる + 5. add_stmt + 6. return文のtreeを生成 + + * RTL expansion + + 通常のCALL_EXPRを解析するexpand_callを一部修正する。この関数の途中か + らでexpand_cbc_goto関数に切り替えてRTLの生成はそこで全てを請け負う。 + 本来expand_callではtreeにsibcallフラグが立っていても、生成の過程で不 + 可能と検知するとsibcallを中断して通常のcallになるが、cbc_expand_call + では無理やりsibcallにする。 + + expand_callでの修正内容 + Undocumented. + expand_cbc_gotoの処理内容 + Undocumented. + +___________________________________________________________ + goto文における並列代入の実装 Nov 26, 2009 +----------------------------------------------------------- + +c-parser.c: c_parser_statement_after_labels()における goto文のパースの +段階で全ての引数を一時変数に代入する形に変更する。 +もちろんこれだけで並列代入ができる分けではないが、おそらくGCCの最適化 +機構でできると考える。 + + 1. c_parser_expr_no_commasでCALL_EXPRを取得 + 2. 全ての引数に対して一時変数を作成 + 3. それぞれを代入 + 4. CALL_EXPRの引数を一時変数に置き換え + 2-4の処理をcbc_replace_argumentsで行う。 + + + +___________________________________________________________ + return擬似変数の実装 +----------------------------------------------------------- + +___________________________________________________________ + environmentの実装 +----------------------------------------------------------- + + + + + + + + + + + + + + + + + +___________________________________________ + * goto文における並列代入実装について考える +------------------------------------------- + +Nov 26, 2009 +c-parser.c: c_parser_statement_after_labels()における goto文のパースの +段階で全ての引数を一時変数に代入する形に変更する。 +もちろんこれだけで並列代入ができる分けではないが、おそらくGCCの最適化 +機構でできると考える。 + + 1. c_parser_expr_no_commasでCALL_EXPRを取得 + 2. 全ての引数に対して一時変数を作成 build_decl? + 名前なしでできるか? + 3. それぞれを代入 + 4. CALL_EXPRの引数を一時変数に置き換え + 5. expand_callでの実装を元に戻す? + 現状のままでも動きはするはず +引数のタイプ + 関数 + o ADDR_EXPR + o PARM_DECL, VAR_DECL, + other + o *_EXPR + o PARM_DECL, VAR_DECL, + +実装の準備 + o CALL_EXPRから引数リストを取得 + DECL_ARGUMENTS(fundecl) + tree args = DECL_ARGUMENTS (fndecl); + for (; args; args = TREE_CHAIN (args)) + { + tree type = TREE_TYPE (args); + if (INTEGRAL_TYPE_P (type) + && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) + DECL_ARG_TYPE (args) = integer_type_node; + } + o 名前なしの変数作成 + var = build_decl(VAR_DECL, NULL_TREE, TYPE); + DECL_ARTIFICIAL (val) = 1; + o 代入文 + build_modify_expr (loc, TO_EXPR, NOP_EXPR, FROM_EXPR) + o Constantなら一時変数いらない + もしくはcallerの引数と同じ場合にのみ一時変数を使うか + o CALL_EXPRは取得後に引数を変えても大丈夫なのか? + o expand_callでのstore_one_arg, check_sibcall_argument_overlapの動作 + +<del>実装に邪魔ないくつかの関数の解析</del> + o mem_overlaps_already_clobbered_arg_p(addr, size) + 指定したメモリ[addr,addr+size]範囲がすでに前の引数格納によって上書 + きされていないかをチェックする。 + 引数範囲を1byte毎にbitmapの1bitに表し、上書きされた場所は1がセット + されている。それにかぶるとNG. + また、addrが動的(esp+eaxなど)ならNG. + o sotre_one_args() +この実装ではexpand_cbc_gotoをいじらない事にした + + + + * DEBUG手法 + + gccコマンドではなくcc1コマンドに対してgdbを起動 + $ ls + GCC/ build-test/ test/ + $ cd test + $ gdb ../build-test/gcc/cc1 + + treeの表示 + (gdb) p browse_tree (exp) <== expはtree構造体 + + rtxの表示 + (gdb) p debug_rtx (exp) <== expはrtx構造体 + + browse_treeはtree, debug_rtxはrtxをconfigureの + --enable-checkingで指定している必要がある + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-memo.ja Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,888 @@ +GCC + + + + +[[configureオプションの追加]] +$ cd gcc +$ vi configure.ac + ... +$ autoheader-2.59 # versionはconfigure.acの中に書いてある奴に合わせる +$ autoconf-2.59 +$ vi Makefile.in +これでconfigureスクリプトが完成するが、このautoconfはtarボールでは成功しない +svnリポジトリからチェックアウトしないと必要な関数が定義されてないのでエラーになる +なのでチェックアウトしたものでconfigureを生成したあと、それだけコピーしてこればOK +TOPディレクトリでは +$ autogen Makefile.def +$ autoconf-2.59 +ただしこれを使うことはないと思われる? + + +[[fastcall i386]] +1: %ecx +2: %edx +3: (%esp) +4: 4(%esp) +5: 8(%esp) + +__attribute__((noreturn)): 今のところこれでは問題が出ない +__attribute__((fastcall)): こっちはいろいろ問題あり + + +fastcallで起こる問題: +せっかく計算したebpが上書きされてしまっている +ecxに退避してそこにjmpすれば動く (これを直にかける?) +expand_cbc_gotoを直す必要がある +08048714 <returner>: +8048714: 53 push %ebx +8048715: 83 ec 28 sub $0x28,%esp +8048718: 89 4c 24 0c mov %ecx,0xc(%esp) +804871c: 8b 44 24 0c mov 0xc(%esp),%eax +8048720: 89 44 24 1c mov %eax,0x1c(%esp) +8048724: 8b 44 24 1c mov 0x1c(%esp),%eax +8048728: 8b 00 mov (%eax),%eax +804872a: 01 44 24 0c add %eax,0xc(%esp) +804872e: 8b 44 24 1c mov 0x1c(%esp),%eax +8048732: 8b 58 08 mov 0x8(%eax),%ebx +8048735: 8b 44 24 1c mov 0x1c(%esp),%eax +8048739: 8b 40 04 mov 0x4(%eax),%eax +804873c: 8b 54 24 0c mov 0xc(%esp),%edx +8048740: 89 c1 mov %eax,%ecx +8048742: 83 c4 28 add $0x28,%esp +8048745: 5b pop %ebx +8048746: ff e3 jmp *%ebx +これを手動で直すと-O0でも-O2でも動くことが確認できた + + + + + +**PROJECT CVS** +firefly.cr:~one/CVS_DB/CbC_Project/GCC + +-checkout + cvs co CbC_project/GCC +-commit + cvs commit +-import from 3rdparty source + tar xzvf gcc-xxx.tgz + cd gcc-xxx + cvs import -ko -m ".." CbC/project/GCC FSF_GCC REL_4_x_y +-merge + cd /temp + cvs checkout -jREL_4_2_1 -jREL_xxx CbC_project/GCC + もしくはすでに本流をcheckoutしているディレクトリで + cvs update -jREL_4_2_1 -jREL_4_2_2 でもできる? (4_2_2に移行時はこれをしたけど...まだ分かんない ) + cvs update -jREL_4_2_2 -jREL_4_2_3 + + +コンパイル時に実行されるプログラムは主に3つ +省略すると +cc1, as, collect2 +/usr/libexec/gcc/i386/redhat-linux/4.1.1/cc1 test.c -o test.s +as -o test.o test.s +/usr/libexec/gcc/i386/redhat/linux/4.1.1/collect2 ..... test.o + +cc1とcollect2は +gcc-core-4.2.0/gcc/内でコンパイルされるもの。 +必要なのはcc1だ。 + + + +CbCの実装 + tail callを使う。 + +tail call +関数の末尾呼び出しを最適化して、callでなくjmpで関数に飛ぶようになる。 +gcc -O1 -foptimize-sibling-calls か +gcc -O2 でコンパイルすればこの最適化が行われる。 + +最適化条件? (構造体未確認) +(推測!!) + 返り値が同じ + 呼ばれる関数の引数サイズが呼び出し側関数の引数サイズより小さい + +expand_gimple_basic_blockでstatement毎にRTLに変換されているが、 +ほとんどのstmtはexpand_expr_stmtに送られるけど、 +tail call の場合は expand_gimple_tailcallに直接送られる + + +**TEST BUILD** +mkdir build-test +cd build-test +../GCC/configure --disable-nls --disable-bootstrap --enable-languages=c --prefix=$PWD/installed --enable-checking=tree,rtl,assert +デバグのため、下の(a)を実行 +make +make install # これまでしないと処理系によってはerrorがいくつか... + +(a). 全てのMakefileの-O2 を -O0 に変更 viで :%s/-O2/-O0/gってとこか? + どうやら --prefix=...って、ちゃんとしないといけない? + stdio.hをインクルードしてるとエラーが出る。 + これはオレが失敗したのか?それともconfigureが悪いのか? + +$ CFLAGS="-O0 -gdwarf-2 -g3" ../GCC/configure ... + + +stdio.hをインクルードしたらerrorが出る問題 +firefly: --prefix=$PWD/USR-LOCALあり、別ディレクトリ + preinstall: NG postinstall: OK installed: OK +firefly: --prefixなし、別ディレクトリ + preinstall: NG postinstall: ?? +firefly: --prefixあり、同ディレクトリ + preinstall: NG postinstall: OK installed: OK +firefly(nativePkg): --prefixなし、別ディレクトリ + preinstall: NG + +chani: --prefix=$PWD/installedあり、同ディレクトリ + preinstall: OK +chani(nativePkg): --prefixなし、別ディレクトリ + preinstall: OK + + + +$PWD/installed/bin/gcc -O2 .... +$PWD/installed/libexec/gcc/i686-pc-linux-gnu/4.2.1/cc1 -O2 test01.c +browse_tree (tree) +debug_rtx(rtl) + + + +**GCC DEBUG** +gdb $BUILD-TEST/installed/libexec/gcc/i686-pc-linux-gnu/4.2.1/cc1 +プログラム内で +p browse_tree (current_function_decl) + + + + + +cc1 +main.c, toplev.c, + +main() in main.c + +toplev_main() in toplev.c + general_init(argv[0]) + signal設定 + init_gcc() + decode_options(argc, argv) + randomize() + do_compile() in toplev.c + timevar_start(TV_TOTAL) + process_options() + compile_file() + +struct lang_hooks lang_hooks +この構造体にパーサ等の関数ポインタが含まれている。 +これはlanghooks-def.hでLANG_HOOKS_INITIALIZERが定義されているが、 +言語ごとの定義はcならc-objc-common.hで、各メンバの定義が入れ替えられる。 + +options +decode_options -O?などのオプションを処理 + handle_options その他のオプションを順番に走査 + コンパイル対象のファイル名を main_input_filenameに入れる + -で始まる引数があればhandle_optionを呼ぶ + handle_option オプションを処理する + + +compile_file() + lang_hooks.parse_file() == c_common_parse_file + c_parse_file() in c-parser.c Parse a single source file. + c_parser_translation_unit() in c-parser.c + c_parser_external_declaration() + + +c_parser_external_declaration() in c-parser.c +CPPのtokenはここで処理して通常のはc_parser_declaration_or_fndefに渡す + +全体を通して、c_parser *parserという変数が関数の第一引数に渡される。 +これがファイルをparseする際の状態を保持しているっぽい + +c_parser_declaration_or_fndef() +こいつがglobalな関数、変数の宣言を処理する。 + c_parser_declspecs() 基本type (int, char, strcut...) + declspecs_add_scspec(specs, tree) extern,inline,staticなどのstorageをspecsにおさめる(specsのフラグをたてる) + declspecs_add_type(specs, c_typespec t) int, char, longなど第2引数が型名、第1引数にそれを格納 + finish_declspecs() Complexやunsignedなどの後に来る型名の処理? + shadow_tag(specs) 名前無しのstructやunionを処理。 + c_parser_declarator() 名前の前の*の処理 + c_parser_direct_declarator() idを取得 + c_parser_direct_declarator_inner() idの後の[]や()をパース + c_parser_parms_declarator() 引数リストもしくはidリスト(これはoldSTYLEのため) + c_parser_parms_list_declarator() + c_parser_parameter_declaration() + 通常の変数なら + start_decl() + start_init() c_parser_initializer() finish_init() + finish_decl() + + 関数パラメータ + start_function() 関数のdeclaration treeを作成する + treeはcurrent_function_declに保存 + old-styleパラメータ(while c_parser_declaration_or_fndef(parser, f, f, t, f) + fnbody = c_parser_compound_statement(parser) 関数本体の定義 + add_stmt(fnbody) fnbodyを専用のstatement listに追加する gimplifyに使われる? + finish_function() + current_function_declからfndeclを取得 + ...(fndecl) = pop_stmt_list(....(fndecl)) statement listからbodyを取得しfndeclにつなげる + c_genericize(fndecl) convert LD-tree to LI-tree + c_gimple_diagnostics_recursively(fndecl) + cgraph_finalize_function(fndecl,false) ファイルにアセンブラを出力? + cgraph_assemble_pending_functions() in cgraphunit.c + +関数とcode segment +code segmentはパース中の型はcts_CbC_codeとしてdeclspecsに保持している +finish_declspecsにおいて、treeを構成する際に型をvoid_type_nodeで格納 +このvoid_typeになんらかのフラグをつける?それともfunction_typeにつける? + + + +IDの取得 +c_parser_declarator() 名前の前の*の処理 + c_parser_direct_declarator() id or (.id)をパース + c_parser_direct_declarator_inner() idの後の[]や()をパース fnTreeを生成 + c_parser_parms_declarator() 型なしidリスト(これはoldSTYLEのため) + c_parser_parms_list_declarator() 型付き引数リストのパース 可変長かもみる + c_parser_parameter_declaration() + build_function_declarator() パースした引数とdelcで関数の宣言をつくる + c_declarator->u.arg_infoに引数を保持 + + +**expand_* treeをパースしてRTLを出力する +tree_expand_cfg() + expand_used_vars() + expand_function_start(current_function_decl) + cfunの値を設定して行く + assign_parms() + ここでcfun->args_sizeが設定されている + expand_gimple_basic_block() in for-loop + expand_expr_stmt() in stmt.c + expand_expr() in expr.h + expand_expr_real() expr.c + expand_expr_real_1() + +expand_expr_real_1() expr.c:8210 + expand_mult() expmed.c + expand_binop() optabs.c + GEN_FCN (icode) (temp, xop0, xop1); + 下の感じのRTLが返される + (set (reg:DF 67) (mult:DF (reg:DF 66) (reg/v:DF 64 [ d ]))) + が、この関数が返すのは (reg:DF 67)だけ + emit_insn(rtx) + RTLをDL-listに追加する. rtxはinsnでなければinsnでラッピングされる + + +**PASS LIST** +関数ごとに出力する場合、 +cgraph_assemble_pending_functions() flag_unit_at_a_timeが真なら実行 + cgraph_expand_function() + tree_rest_of_compilation + execute_pass_list + +まとめて出力する場合 +compile_file + lang_hooks.decls.final_write_globals = c_write_global_declarations flag_unit_at_a_timeが偽なら実行 + cgraph_optimize + cgraph_expand_all_functions + cgraph_expand_function + +GIMPLE treeから RTL への変換 +pass.execute = tree_expand_cfg() + +RTLからアセンブラへの変換pass final.cで定義 +pass_final.execute == rest_of_handle_final in final.c + + +最終的な RTL=>"文字列" 変換する pass +execute_one_pass() + rest_of_handle_final() + assemble_start_function() + final_start_function() + final() # insnリストを出力 + final_scan_insn() # 与えられたinsnのアセンブラを出力 + recog_memoized() # insn_data[code]のcode 決定 + get_insn_template() # 出力するアセンブラのchar*文字列を返す + output_asm_insn() # 文字列の%..を修正してファイルに出力 + final_end_function() + assemble_end_function() + +RTLの仮想レジスタを物理レジスタに置き換える pass +execute_one_pass() + instantiate_virtual_regs() + instantiate_virtual_regs_in_insn() for each instruction + extract_insn() + recog_memoized() + insn_extract() +ppcではこのrecog_memoizedで-1しか返ってこないことで落ちる + +下のmdのmatch_operand 0がaddressにしか対応してないのが問題だと思う +;; sibling call patterns +(define_expand "sibcall" + [(parallel [(call (mem:SI (match_operand 0 "address_operand" "")) + (match_operand 1 "" "")) + (use (match_operand 2 "" "")) + (use (reg:SI LR_REGNO)) + (return)])] + "" + " + { + #if TARGET_MACHO + if (MACHOPIC_INDIRECT) + operands[0] = machopic_indirect_call_target (operands[0]); + #endif + + gcc_assert (GET_CODE (operands[0]) == MEM); + gcc_assert (GET_CODE (operands[1]) == CONST_INT); + + operands[0] = XEXP (operands[0], 0); + }") + + +targetm.asm_outから出力 +ターゲットマシンによってtargetm構造体の内容が変わる。 + + + +/* In all nodes that are expressions, this is the data type of the expression. + In POINTER_TYPE nodes, this is the type that the pointer points to. + In ARRAY_TYPE nodes, this is the type of the elements. + In VECTOR_TYPE nodes, this is the type of the elements. */ +#define TREE_TYPE(NODE) ((NODE)->common.type) // in tree.h +このnodeの型を表す(functionなら関数の型、pointerならそいつのさしている型.. + +/* The tree-code says what kind of node it is. + Codes are defined in tree.def. */ +#define TREE_CODE(NODE) ((enum tree_code) (NODE)->common.code) // in tree.h +このnodeがどんなtreeなのかを表す + + + +c_parser_compound_statement() + c_begin_compound_stmt() + c_parser_compund_statement_nostart() __label__, lvarの処理 + c_parser_statement_after_labels() + c_end_compound_stmt() + +c_parser_if_statement() +c_parser_do_statement() + +c_parser_paren_condition() ifやwhileの'()'の中をparseする + + +parse expressions + +c_parser_unary_expression() increment,decrement, &, *ポインタ、アドレスの処理 +c_parser_postfix_expression() 数字や変数、文字列などの処理(TCCのunary()か) +c_parser_postfix_expression_after_primary() 変数とかの後ろの'[]'や'()'の処理(関数や配列の添字) + + +c_parser_* Cのパーサ +build_* treeの生成 (Cパーサから呼ばれる) +expand_* tree(gimple)のパーサ +emit_* rtlの生成 (treeパーサから呼ばれる) + + + + +宣言時の新しい識別子 +token->type==CPP_NAME +build_id_declarator + XOBNEWを使って parser_obstackに作られる => gcc_obstack_init in default.h +変数名等を格納するc_declaratorはparser_obstack上に作られ、 + + +tree.def +tree.[ch] + +union tree_node GTY((ptr_alias (union lang_tree_node), + desc ("tree_node_structure (&%h)"))) +{ + struct tree_common GTY ((tag ("IS_COMMON"))) common; + struct tree_int_cst GTY ((tag ("IS_INT_CST"))) common; + struct tree_real_cst GTY ((tag ("IS_REAL_CST"))) common; + .. + .. +}; +c-tree.h: +struct c_expr{ + tree value; + enum tree_code original_code; +} + + +tokenizer + +c_parser_peek_token() int c-parser.c 現在参照すべきtoken を返す + c_lex_one_token() in c-parser.c + c_lex_with_flags() in c-lex.c + cpp_get_token() in libcpp(macro.c) +c_parser_next_token_is( parser, token0) tokenを取得し、それがtoken0ならtrue +c_parser_consume_token( parser) 次のtokenを取ってくる + +parser->tokens[0,1] (c_token) +この[0]に現在のtokenの情報がある。 +[1]はnext? +新たなtokenはlibcppのcpp_get_tokenによって取得する。 + +cppでは'!'や'*'などの一つ一つのtokenとなんらかの文字列を返す +予約語等の処理はgccがやる. +token +struct c_token{ + enum cpp_ttype type: 8; /* libcppで得られるtokenのtype, '<','==', name, '['などなど */ + enum c_id_kind id_kind: 8; /* type==CPP=NAMEの時のみ */ + enum rid keyword: 8; /* Cの予約語(int, if, typedef, gotoなど) */ + pragma_kind: 7; + in_systemheader: 1; + tree value; + location_t location; +} +enum cpp_ttype in libcpp/include/cpplib.h +{ + TTYPE_TABLE ==>> CPP_EQ, CPP_NOT, ... , CPP_NAME, ..., CPP_PADDING, + N_TTYPES, + + /* Positions in the table. */ + CPP_LAST_EQ = CPP_LSHIFT, + CPP_FIRST_DIGRAPH = CPP_HASH, + CPP_LAST_PUNCTUATOR= CPP_ATSIGN, + CPP_LAST_CPP_OP = CPP_LESS_EQ +}; +本来予約語もCPP_NAMEに含まれるが、無理矢理CPP_KEYWORDを作っている +CPP_KEYWORDはc-parser.cで独自に定義、N_TTYPES+1 +typedef enum c_id_kind { + C_ID_ID, /* An ordinary identifier. */ + C_ID_TYPENAME, /* An identifier declared as a typedef name. */ + C_ID_CLASSNAME, /* An identifier declared as an Objective-C class name. */ + C_ID_NONE /* Not an identifier. */ +} c_id_kind; + + +enum c_declarator_kind { /* in c-tree.h */ + cdk_id, /* An identifier. */ + cdk_function, /* A function. */ + cdk_array, /* An array. */ + cdk_pointer, /* A pointer. */ + cdk_attrs /* Parenthesized declarator with nested attributes. */ +}; +struct c_declarator { /* in c-tree.h */ + enum c_declarator_kind kind; /* The kind of declarator. */ + struct c_declarator *declarator; /* Except for cdk_id, the contained declarator. For cdk_id, NULL. */ + location_t id_loc; /* Currently only set for cdk_id. */ + union { + tree id; /* For identifiers, an IDENTIFIER_NODE or NULL_TREE if an abstract declarator. */ + struct c_arg_info *arg_info; /* For functions. */ + struct { /* For arrays. */ + tree dimen; /* The array dimension, or NULL for [] and [*]. */ + int quals; /* The qualifiers inside []. */ + tree attrs; /* The attributes (currently ignored) inside []. */ + BOOL_BITFIELD static_p : 1; /* Whether [static] was used. */ + BOOL_BITFIELD vla_unspec_p : 1; /* Whether [*] was used. */ + } array; + int pointer_quals; /* For pointers, the qualifiers on the pointer type. */ + tree attrs; /* For attributes. */ + } u; +}; + +/* A type specifier keyword "void", "_Bool", "char", "int", "float", + "double", or none of these. */ +enum c_typespec_keyword { //でも使われてるのはdeclspec + cts_none, + cts_void, + cts_CbC_code, いる? + cts_bool, + cts_char, + cts_int, + cts_float, + cts_double, + cts_dfloat32, + cts_dfloat64, + cts_dfloat128 +}; +enum c_typespec_kind { + ctsk_resword, + ctsk_tagref, + ctsk_tagfirstref, + /* A definition of a tag such as "struct foo { int a; }". */ + ctsk_tagdef, + ctsk_typedef, + ctsk_objc, + ctsk_typeof +}; +struct c_typespec { + enum c_typespec_kind kind; + tree spec; +}; +struct c_declspecs { /* c-tree.c */ + /* The type specified, if a single type specifier such as a struct, + union or enum specifier, typedef name or typeof specifies the + whole type, or NULL_TREE if none or a keyword such as "void" or + "char" is used. Does not include qualifiers. */ + tree type; + /* The attributes from a typedef decl. */ + tree decl_attr; + /* When parsing, the attributes. Outside the parser, this will be + NULL; attributes (possibly from multiple lists) will be passed + separately. */ + tree attrs; + /* Any type specifier keyword used such as "int", not reflecting + modifiers such as "short", or cts_none if none. */ + enum c_typespec_keyword typespec_word; + /* The storage class specifier, or csc_none if none. */ + enum c_storage_class storage_class; + BOOL_BITFIELD declspecs_seen_p : 1; + BOOL_BITFIELD type_seen_p : 1; + BOOL_BITFIELD typedef_p : 1; + BOOL_BITFIELD default_int_p; + BOOL_BITFIELD long_p : 1; + BOOL_BITFIELD long_long_p : 1; + BOOL_BITFIELD short_p : 1; + BOOL_BITFIELD signed_p : 1; + : +} + + + + +**TAIL CALL OPTIMIZATION** +execute_tail_calls in tree-tailcall.c + tree_optimize_tail_calls_1(true) + たいした調査もせず、簡単にフラグCALL_EXPR_TAILCALLをたててるだけ。 + +expand_call 1834-3115 in calls.c + initialize_argument_information(); + 引数処理 + 引数をレジスタやスタックのどこに保存するかを決める + tree actparmsで示された引数をargs, args_sizeに格納する + 1011行目 We can't use sibcalls if a callee-copied argument is stored in the current function's frame. + if statement 2200行目: try_tail_call=0 + targetm.function_ok?for?sibcall(fndecl, exp) + args_size.constant > (current_function_args_size - current_function_pretend_args_size) + emit_call_1(); + SIBLING_CALL_P(..) = ( (ecf_flag & ECF_SIBLING) != 0); + +expand_callでtailcall可能かどうかの判定を詳しく行っているようだ +bool try_tail_call = CALL_EXPR_TAILCALL(exp); +2252あたりのfor文が怪しいが、900行ある。 + +2252 in calls.c +for(pass = try_tail_call ? 0:1; pass<2; pass++) 2253-3087 +2回ループ。 +1回目はtailcall用。 +2回目は普通のcalling +生成後にどちらかを選ぶ? +2227 args_size.constant > (current_function_args_size - current_function_pretend_args_size) + + hard_function_value + check_sibcall_argument_overlap + prepare_call_address + load_register_parameters + + + +Language Dependent Tree + v +GENERIC + v +GIMPLE + +GENERIC trees + LD trees + v +GIMPLE + + +**RTL** +RTL expression + クラス: RTX_OBJ, RTX_CONST_OBJ, _COMPARE _COMM_COMPARE _UNARY ... in rtx.def + オペランド: e(expression), i(integer), w, s, E, ... + +RTLへのアクセス +GET_CODE (RTX) (enum rtx_code) (RTX)->code + RTXのコード(種類)を返す +GET_RTX_CLASS (code) + このrtxコードのクラスを返す +GET_RTX_LENGTH (code) + このrtxコードのオペランドの数を返す +GET_RTX_FORMAT (code) + オペランドの種類を文字列で返す + i.e. "iuuBieieee" on CALL_INSN +XEXP(RTX, N) X->u.fld[N].rt_rtx + RTX のN番目のオペランドをexpressionとして取得する +XINT(RTX, N) X->u.fld[N].rt_int + RTX のN番目のオペランドをintegerとして取得する +XVEC(RTX, N) X->u.fld[N].rt_rtvec + RTX のN番目のオペランドをrtvectorとして取得する + XVECEXP(RTX, N, M) XVEC(RTX,N)->elem[M] + RTX のN番目のオペランドをrtvectorとし、その M番目の要素を返す + XVECLEN(RTX, N) XVEC(RTX,N)->num_elem + RTX のN番目のオペランドをrtvectorとし、そのサイズを返す + +struct rtvec_def GTY(()) { + int num_elem; /* number of elements */ + rtx GTY ((length ("%h.num_elem"))) elem[1]; +}; + + +typedef struct trx_def *rtx; //gcc/coretypes.h +struct rtx_def; //gcc/rtl.h +struct rtx_def GTY((chain_next ("RTX_NEXT (&%h)"), + chain_prev ("RTX_PREV (&%h)"))) +{ + /* The kind of expression this is. */ + ENUM_BITFIELD(rtx_code) code: 16; + + /* The kind of value the expression has. */ + ENUM_BITFIELD(machine_mode) mode : 8; + + /* 1 in a MEM if we should keep the alias set for this mem unchanged + when we access a component. + 1 in a CALL_INSN if it is a sibling call. + 1 in a SET that is for a return. + In a CODE_LABEL, part of the two-bit alternate entry field. */ + unsigned int jump : 1; + /* In a CODE_LABEL, part of the two-bit alternate entry field. + 1 in a MEM if it cannot trap. */ + unsigned int call : 1; + /* 1 in a REG, MEM, or CONCAT if the value is set at most once, anywhere. + 1 in a SUBREG if it references an unsigned object whose mode has been + from a promoted to a wider mode. + 1 in a SYMBOL_REF if it addresses something in the per-function + constants pool. + 1 in a CALL_INSN, NOTE, or EXPR_LIST for a const or pure call. + 1 in a JUMP_INSN, CALL_INSN, or INSN of an annulling branch. */ + unsigned int unchanging : 1; + /* 1 in a MEM or ASM_OPERANDS expression if the memory reference is volatile. + 1 in an INSN, CALL_INSN, JUMP_INSN, CODE_LABEL, BARRIER, or NOTE + if it has been deleted. + 1 in a REG expression if corresponds to a variable declared by the user, + 0 for an internally generated temporary. + 1 in a SUBREG with a negative value. + 1 in a LABEL_REF or in a REG_LABEL note for a non-local label. + In a SYMBOL_REF, this flag is used for machine-specific purposes. */ + unsigned int volatil : 1; + /* 1 in a MEM referring to a field of an aggregate. + 0 if the MEM was a variable or the result of a * operator in C; + 1 if it was the result of a . or -> operator (on a struct) in C. + 1 in a REG if the register is used only in exit code a loop. + 1 in a SUBREG expression if was generated from a variable with a + promoted mode. + 1 in a CODE_LABEL if the label is used for nonlocal gotos + and must not be deleted even if its count is zero. + 1 in an INSN, JUMP_INSN or CALL_INSN if this insn must be scheduled + together with the preceding insn. Valid only within sched. + 1 in an INSN, JUMP_INSN, or CALL_INSN if insn is in a delay slot and + from the target of a branch. Valid from reorg until end of compilation; + cleared before used. */ + unsigned int in_struct : 1; + /* At the end of RTL generation, 1 if this rtx is used. This is used for + copying shared structure. See `unshare_all_rtl'. + In a REG, this is not needed for that purpose, and used instead + in `leaf_renumber_regs_insn'. + 1 in a SYMBOL_REF, means that emit_library_call + has used it as the function. */ + unsigned int used : 1; + /* 1 in an INSN or a SET if this rtx is related to the call frame, + either changing how we compute the frame address or saving and + restoring registers in the prologue and epilogue. + 1 in a REG or MEM if it is a pointer. + 1 in a SYMBOL_REF if it addresses something in the per-function + constant string pool. */ + unsigned frame_related : 1; + /* 1 in a REG or PARALLEL that is the current function's return value. + 1 in a MEM if it refers to a scalar. + 1 in a SYMBOL_REF for a weak symbol. */ + unsigned return_val : 1; + + /* The first element of the operands of this rtx. + The number of operands and their types are controlled + by the `code' field, according to rtl.def. */ + union u { + rtunion fld[1]; + HOST_WIDE_INT hwint[1]; + struct block_symbol block_sym; + struct real_value rv; + } GTY ((special ("rtx_def"), desc ("GET_CODE (&%0)"))) u; +}; + + +FUNCTION_TYPEの実態はtree_type +make_node_stat(FUNCTION_TYPE)で作成される + TREE_TYPE + TYPE_ARG_TYPES ->type.values + TYPE_UID ->type.uid + TYPE_ALIGN ->type.align + TYPE_USER_ALIGN ->type.user_align + TYPE_MAIN_VARIANT ->type.main_variant + TYPE_ATTRIBUTES ->type.attributes + +こいつの lang_flag_6 ビットフィールドをcode segmentかどうかのフラグとする。 +#define TYPE_LANG_FLAG_5(NODE) (TYPE_CHECK (NODE)->type.lang_flag_5) //tree.h +#define CbC_IS_CODE_SEGMENT(TYPE) TYPE_LANG_FLAG_5 (TYPE) //c-tree.h +code segmentを作ったらCbC_IS_CODE_SEGMENT(type) = 1 でセット できる? + + + + + + +**GENERIC TREE** +関数の型 +<function_type 0xb7b7d9b4 + type <real_type 0xb7b72a6c double DF + size <integer_cst 0xb7b60528 constant invariant 64> + unit size <integer_cst 0xb7b60540 constant invariant 8> + align 64 symtab 0 alias set -1 precision 64 + pointer_to_this <pointer_type 0xb7b72b80>> + QI + size <integer_cst 0xb7b601f8 type <integer_type 0xb7b7205c bit_size_type> constant invariant 8> + unit size <integer_cst 0xb7b60210 type <integer_type 0xb7b72000 unsigned int> constant invariant 1> + align 8 symtab 0 alias set -1 + arg-types <tree_list 0xb7b7c8a0 + +関数の宣言 +<function_decl + type <function_type ... >> + +関数の引数 +<tree_list + value <integer_type + size <integer_cst ...> + unit size <integer_cst ...> + align 32 .... <integer_cst ...> + chain <tree_list ...>> + +配列 +<array_type 0xb7f04170 + type <integer_type 0xb7e7f284 int public SI ... > + BLK + size <integer_cst 0xb7f02f18 type <integer_type 0xb7e7f05c bit_size_type> constant invariant 320> + unit size <integer_cst 0xb7f05030 type <integer_type 0xb7e7f000 unsigned int> constant invariant 40> + align 32 symtab 0 alias set -1 + domain <integer_type 0xb7f04114 + type <integer_type 0xb7e7f000 unsigned int public unsigned sizetype SI size <integer_cst 0xb7e6d3f0 32> unit size <integer_cst 0xb7e6d180 4> + align 32 symtab 0 alias set -1 precision 32 min <integer_cst 0xb7e6d468 0> max <integer_cst 0xb7e6d9f0 -1>> + SI size <integer_cst 0xb7e6d3f0 32> unit size <integer_cst 0xb7e6d180 4> + align 32 symtab 0 alias set -1 precision 32 min <integer_cst 0xb7e6d198 0> max <integer_cst 0xb7f02fc0 9>>> + +関数呼び出し +<call_expr 0xb7e52078 + type <real_type 0xb7e55a6c double DF ...> + side-effects arg 0 <addr_expr 0xb7ed2080 + type <pointer_type 0xb7eda170 type <function_type 0xb7ecff18> + unsigned SI + size <integer_cst 0xb7e433f0 constant invariant 32> + unit size <integer_cst 0xb7e43180 constant invariant 4> + align 32 symtab 0 alias set -1> + constant invariant + arg 0 <function_decl 0xb7ed15b0 test type <function_type 0xb7ecff18> + addressable used public external decl_5 QI defer-output file test_tree.c line 2>> + arg 1 <tree_list 0xb7edb138 + value <integer_cst 0xb7edb030 constant invariant 97> + chain <tree_list 0xb7edb168 + value <integer_cst 0xb7edb060 constant invariant 98> + chain <tree_list 0xb7edb180 + value <integer_cst 0xb7edb090 constant invariant 10> + chain <tree_list 0xb7edb198 + value <real_cst 0xb7edb0c0 type <real_type 0xb7e55a6c double> + constant invariant 2.5e+0>>>>>> + + +build_function_call(tree fndecl, tree exprlist) +FUNCTION_DECLとEXPRのリストからCALL_EXPRを作って返す + +convert_arguments(arglist, params, function, fundecl); +check_function_arguments(); + + +配列の作り方 +icst : INTEGER_CST +itype: INTEGER_TYPE + +icst = build_int_cst (NULL_TREE, size-1); +itype = build_index_type (icst); +array = build_array_type + +//build_range_type(size_type, integer_zero_node, exp) + + + +**PPC** +http://developer.apple.com/documentation/DeveloperTools/Reference/Assembler/ASMIntroduction/chapter_1_section_1.html +http://developer.apple.com/documentation/DeveloperTools/Conceptual/LowLevelABI/Articles/32bitPowerPC.html#//apple_ref/doc/uid/TP40002438-SW17 +http://developer.apple.com/documentation/DeveloperTools/Conceptual/MachORuntime/Reference/reference.html +http://www.freescale.co.jp/pdf/MPCFPE32BJ_R1a.pdf +http://www.nk.rim.or.jp/~jun/ppcasm/ppcasm01.html + + + + + +**ソースコード読み会 準備** +cd ~/public_html +mkdir gcc; cd gcc +checkout CbC_project/GCC; CbC_project/GCC +./configure --... +make +gtags +htags -Ffx -t 'GCC source tour' +cd ../../ +tar -czv CbC_project --exclude **/CVS -f GCC-source-....tar.gz + + + +normal tail call +(call_insn/j 24 23 0 (parallel [ + (call (mem:SI (symbol_ref:SI ("cs0") [flags 0x403] <function_decl 0x42e03980 cs0>) [0 S4 A8]) + (const_int 256 [0x100])) + (use (const_int 0 [0x0])) + (use (reg:SI 125)) + (return) + ]) -1 (nil) + (expr_list:REG_EH_REGION (const_int 0 [0x0]) + (nil)) + (expr_list:REG_DEP_TRUE (use (reg:SI 6 r6)) + (expr_list:REG_DEP_TRUE (use (reg:SI 5 r5)) + (expr_list:REG_DEP_TRUE (use (reg:SI 4 r4)) + (expr_list:REG_DEP_TRUE (use (reg:SI 3 r3)) + (nil)))))) + +indirect tail call +(call_insn/j 25 24 0 (parallel [ + (call (mem:SI (reg/f:SI 129) [0 S4 A8]) + (const_int 256 [0x100])) + (use (const_int 0 [0x0])) + (use (reg:SI 130)) + (return) + ]) -1 (nil) + (nil) + (expr_list:REG_DEP_TRUE (use (reg:SI 6 r6)) + (expr_list:REG_DEP_TRUE (use (reg:SI 5 r5)) + (expr_list:REG_DEP_TRUE (use (reg:SI 4 r4)) + (expr_list:REG_DEP_TRUE (use (reg:SI 3 r3)) + (nil)))))) + + + +CFLAGS='-O0 -gdwarf-2 -g3' ../GCC/configure --disable-nls --disable-bootstrap --enable-languages=c --prefix=$PWD/INSTALL-DIR --enable-checking=tree,rtl,assert --disable-shared --disable-threads --with-headers --with-system-zlib --with-newlib --enable-version-specific-runtime-libs --disable-libssp --target=spu + +../toolchain/gcc/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --disable-shared --disable-threads --disable-checking --with-headers --with-system-zlib --with-newlib --enable-languages=c,c++,fortran --disable-nls --enable-version-specific-runtime-libs --disable-libssp --program-prefix=spu- --target=spu + + + + +$ cvs checkout CbC_project/GCC +$ mkdir tmp; cd tmp +$ wget http://www.bsc.es/projects/deepcomputing/linuxoncell/cellsimulator/sdk3.0/SRPMS/spu-gcc-4.1.1-107.src.rpm +$ rpm2cpio spu-gcc--4.1.1-107.src.rpm | cpio -i -v +$ tar xjvf gcc-r886.tar.bz2 +$ cat *.diff | patch -d ../CbC_project/GCC -p2 +$ cp toolchain/gcc/config.sub ../CbC_project/GCC/ +$ cp toolchain/gcc/gcc/config.gcc ../CbC_project/GCC/gcc/ +$ cd ../CbC_project/GCC +$ + + +change bit_merge to vec_merge in gcc/config/spu/spu.md +split0_completed; in recog.c, rtl.h, final.c +SPU_FLOAT_FORMAT +:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-scripts/make_headers.py Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,124 @@ +#!/usr/bin/env python3.0 + + +import sys +import re +import getopt + +reserved_words = [ "if", "for", "switch", "return", "while", "else", ] + +PATTERN = "([a-zA-Z_][\w\s]*\**)\s([a-zA-Z_]\w*)\s*\(([^{/;]*)\)\s*\{" +# TODO: 関数パラメータ内にコメントがあると正しく動かない! +# TODO: int * const * とか大丈夫? +PROG = re.compile(PATTERN, re.S) + +omit_static=False +add_extern="" + +def truncate_comments(data): + pass + +def check_reserved_word(decl): + """ return true if decl's type and name is not reserved word. """ + + if decl["name"] in reserved_words or decl["type"] in reserved_words: + return False + return True + +def read_decls(file): + declarators = [] + + # open the file and read all lines into a string. + try: + fo = open(file, 'r') + lines = fo.readlines() + data = "".join(lines) + truncate_comments(data) + except IOError: + print("cannot read file %s" % file) + return None + + # find all matched strings. + # moiter is iterator of MatchObject. + moiter = PROG.finditer(data) + for mo in moiter: + tmp = { "type": mo.group(1), + "name": mo.group(2), + "parms": mo.group(3), + "offset": mo.start() } + if check_reserved_word(tmp): + declarators.append(tmp) + + return declarators + +def debug_print(decl): + for (key,value) in list(decl.items()): + if isinstance(value, str): + decl[key] = value.replace("\n"," ").replace("\t"," ") + + print("Type:\t{0:s}".format(decl["type"])) + print("Name:\t{0:s}".format(decl["name"])) + print("Params:\t{0:s}".format(decl["parms"])) + print("offset:\t{0:d}".format(decl["offset"])) + print("") + +def format_print(decl, file): + for (key,value) in list(decl.items()): + if isinstance(value, str): + decl[key] = value.replace("\n"," ").replace("\t"," ") + + print("/* defined in file {0:s} at offset {1:d} */".format(file,decl["offset"])) + print("{3:s}{0:s} {1:s} ({2:s});".format(decl["type"],decl["name"],decl["parms"], add_extern)) + print("") + +def getoptions(): + global omit_static, add_extern + + try: + opts, args = getopt.getopt(sys.argv[1:], 'se', [ 'omit-static', 'add-extern' ]) + except getopt.GetoptError as err: + print(err) + usage() + sys.exit(2) + + for opt,a in opts: + if opt in ("-s", "--omit-static"): + omit_static=True + elif opt in ("-e", "--add-extern"): + add_extern="extern " + else: + print("unhandled option {0}".format(opt)) + usage() + + return args + +def usage(): + print( """\ +Usage: {0:s} OPION... [FILE]... +OPTIONS: + -s, --omit-static omit static functions + -e, --add-extern add extern to all function declarations + """.format(sys.argv[0])) + +def main(): + + # option handling. + args = getoptions() + + for file in args: + # read function declaration from each file. + decls = read_decls(file) + if decls==None or len(decls)==0: + # no function found. + print("{0} have no function definition!".format(file)) + continue + + for decl in decls: + if omit_static and 0 <= decl["type"].find("static"): + # static function is ignored. + continue + #debug_print(decl) + format_print(decl, file) + +main() +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-scripts/make_headers.py2 Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,126 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import sys +import re +import getopt + +reserved_words = [ "if", "for", "switch", "return", "while", "else", ] + +PATTERN = r"([a-zA-Z_][\w\s]*\**)\s([a-zA-Z_]\w*)\s*\(([^\{/;]*)\)\s*\{" +#PATTERN = r"([a-zA-Z_]\w*)\s+([a-zA-Z_]\w*)\s*\(([^;]*)\)\s*\{" +#PATTERN = r"((?:[a-zA-Z_]\w*)\s+)+?([a-zA-Z_]\w*)\s*\(([^;]*)\)\s*\{" +# TODO: 関数パラメータ内にコメントがあると正しく動かない! +PROG = re.compile(PATTERN, re.S) + +omit_static=False +add_extern="" + +def truncate_comments(data): + pass + +def check_reserved_word(decl): + """ return true if decl's type and name is not reserved word. """ + + if decl["name"] in reserved_words or decl["type"] in reserved_words: + return False + return True + +def read_decls(file): + declarators = [] + + # open the file and read all lines into a string. + try: + fo = open(file, 'r') + lines = fo.readlines() + data = "".join(lines) + truncate_comments(data) + except IOError: + print "cannot read file %s" % file + return None + + # find all matched strings. + # moiter is iterator of MatchObject. + moiter = PROG.finditer(data) + for mo in moiter: + tmp = { "type": mo.group(1), + "name": mo.group(2), + "parms": mo.group(3), + "offset": mo.start() } + if check_reserved_word(tmp): + declarators.append(tmp) + + return declarators + +def debug_print(decl): + for (key,value) in decl.items(): + if isinstance(value, str): + decl[key] = value.replace("\n"," ").replace("\t"," ") + + print "Type:\t%s" % decl["type"] + print "Name:\t%s" % decl["name"] + print "Params:\t%s" % decl["parms"] + print "offset:\t%d" % decl["offset"] + print "" + #s = "%s %s ( %s );" % (decl["type"], decl["name"], decl["parms"]) + #print s, "/* offset: %d */" % decl["offset"] + +def format_print(decl, file): + for (key,value) in decl.items(): + if isinstance(value, str): + decl[key] = value.replace("\n"," ").replace("\t"," ") + + print "/* defined in file %s at offset %d */" % (file,decl["offset"]) + print "%s%s %s (%s);" % (add_extern, decl["type"],decl["name"],decl["parms"]) + print "" + +def getoptions(): + global omit_static, add_extern + + try: + opts, args = getopt.getopt(sys.argv[1:], 'se', [ 'omit-static', 'add-extern' ]) + except getopt.GetoptError: + print(err) + usage() + sys.exit(2) + + for opt,a in opts: + if opt in ("-s", "--omit-static"): + omit_static=True + elif opt in ("-e", "--add-extern"): + add_extern="extern " + else: + print("unhandled option {0}".format(opt)) + usage() + + return args + +def usage(): + print( """\ +Usage: {0:s} OPION... [FILE]... +OPTIONS: + -s, --omit-static omit static functions + -e, --add-extern add extern to all function declarations + """.format(sys.argv[0])) + +def main(): + # option handling. + args = getoptions() + + for file in args: + # read function declaration from each file. + decls = read_decls(file) + if decls==None or len(decls)==0: + # no function found. + print "%s have no function definition!" % file + continue + + for decl in decls: + if omit_static and 0 <= decl["type"].find("static"): + # static function is ignored. + continue + #debug_print(decl) + format_print(decl, file) + +main() +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gcc/ChangeLog.CbC Sun Aug 21 07:53:12 2011 +0900 @@ -0,0 +1,69 @@ +2009-08-20 Shinji KONO <kono@ie.u-ryukyu.ac.jp> + + どうも、goto hoge(0),env; で、env を渡すのがよろしくない。 + goto hoge(0,env); + と言う形にして、hoge 側で env を設定するのはどうか? + + __code main_return2_1(int i,stack sp) { + goto (( (struct main_continuation *)sp)->main_ret)(0), + ((struct main_continuation *)sp)->env; + } + + を、 + + __code main_return2_1(int i,stack sp) { + goto (( (struct main_continuation *)sp)->main_ret)(0, + ((struct main_continuation *)sp)->env); + } + という形にする。 + + そうすれば、goto 文は、かなり簡単になる。 + +2009-08-20 Shinji KONO <kono@ie.u-ryukyu.ac.jp> + +以下のようにすれば良いらしい... いっそ #define でも出来るが。 + + extern int printf(const char *, ...); + + void g( void (*ret)(int retval_,void *f) , void *fp) { + printf("g: fp = 0x%x\n",__builtin_frame_address(0)); + (*ret)(5,fp); + } + + int f() + { + + int retval = 1; + void (*ret)(int retval_,void *fp) ; + + ret = ({ + __label__ exit0; + volatile static flag = 0; + void __return_func(int retval_,void *fp) { + retval = retval_; + goto exit0; + } + if (flag) { + exit0: + printf("f1: fp = 0x%x\n",__builtin_frame_address(0)); + return retval; + } + __return_func; + }); + + printf("f0: fp = 0x%x\n",__builtin_frame_address(0)); + + g(ret,__builtin_frame_address(0)); + + printf("bad\n"); + + return retval; + } + + + int + main() + { + printf("%d\n",f()); + } +
--- a/gcc/c-decl.c Sun Aug 21 07:07:55 2011 +0900 +++ b/gcc/c-decl.c Sun Aug 21 07:53:12 2011 +0900 @@ -58,16 +58,23 @@ #include "hashtab.h" #include "langhooks-def.h" #include "pointer-set.h" +#include "gimple.h" +#ifndef noCbC +#include "cbc-tree.h" +tree cbc_env; +tree cbc_return_f; +location_t cbc_return; +#endif #include "plugin.h" #include "c-family/c-ada-spec.h" /* In grokdeclarator, distinguish syntactic contexts of declarators. */ enum decl_context -{ NORMAL, /* Ordinary declaration */ - FUNCDEF, /* Function definition */ - PARM, /* Declaration of parm before function body */ - FIELD, /* Declaration inside struct or union */ - TYPENAME}; /* Typename (inside cast or sizeof) */ +{ NORMAL, /* Ordinary declaration */ + FUNCDEF, /* Function definition */ + PARM, /* Declaration of parm before function body */ + FIELD, /* Declaration inside struct or union */ + TYPENAME}; /* Typename (inside cast or sizeof) */ /* States indicating how grokdeclarator() should handle declspecs marked with __attribute__((deprecated)). An object declared as @@ -189,20 +196,20 @@ invisible bit true. */ struct GTY((chain_next ("%h.prev"))) c_binding { - union GTY(()) { /* first so GTY desc can use decl */ + union GTY(()) { /* first so GTY desc can use decl */ tree GTY((tag ("0"))) type; /* the type in this scope */ struct c_label_vars * GTY((tag ("1"))) label; /* for warnings */ } GTY((desc ("TREE_CODE (%0.decl) == LABEL_DECL"))) u; - tree decl; /* the decl bound */ - tree id; /* the identifier it's bound to */ - struct c_binding *prev; /* the previous decl in this scope */ - struct c_binding *shadowed; /* the innermost decl shadowed by this one */ + tree decl; /* the decl bound */ + tree id; /* the identifier it's bound to */ + struct c_binding *prev; /* the previous decl in this scope */ + struct c_binding *shadowed; /* the innermost decl shadowed by this one */ unsigned int depth : 28; /* depth of this scope */ BOOL_BITFIELD invisible : 1; /* normal lookup should ignore this binding */ BOOL_BITFIELD nested : 1; /* do not set DECL_CONTEXT when popping */ BOOL_BITFIELD inner_comp : 1; /* incomplete array completed in inner scope */ - BOOL_BITFIELD in_struct : 1; /* currently defined as struct field */ - location_t locus; /* location for nested bindings */ + BOOL_BITFIELD in_struct : 1; /* currently defined as struct field */ + location_t locus; /* location for nested bindings */ }; #define B_IN_SCOPE(b1, b2) ((b1)->depth == (b2)->depth) #define B_IN_CURRENT_SCOPE(b) ((b)->depth == current_scope->depth) @@ -245,7 +252,7 @@ chain_next ("TREE_CODE (&%h.generic) == INTEGER_TYPE ? (union lang_tree_node *) TYPE_NEXT_VARIANT (&%h.generic) : ((union lang_tree_node *) TREE_CHAIN (&%h.generic))"))) lang_tree_node { union tree_node GTY ((tag ("0"), - desc ("tree_node_structure (&%h)"))) + desc ("tree_node_structure (&%h)"))) generic; struct lang_identifier GTY ((tag ("1"))) identifier; }; @@ -441,25 +448,25 @@ static GTY((deletable)) struct c_binding *binding_freelist; /* Append VAR to LIST in scope SCOPE. */ -#define SCOPE_LIST_APPEND(scope, list, decl) do { \ - struct c_scope *s_ = (scope); \ - tree d_ = (decl); \ - if (s_->list##_last) \ - BLOCK_CHAIN (s_->list##_last) = d_; \ - else \ - s_->list = d_; \ - s_->list##_last = d_; \ +#define SCOPE_LIST_APPEND(scope, list, decl) do { \ + struct c_scope *s_ = (scope); \ + tree d_ = (decl); \ + if (s_->list##_last) \ + BLOCK_CHAIN (s_->list##_last) = d_; \ + else \ + s_->list = d_; \ + s_->list##_last = d_; \ } while (0) /* Concatenate FROM in scope FSCOPE onto TO in scope TSCOPE. */ -#define SCOPE_LIST_CONCAT(tscope, to, fscope, from) do { \ - struct c_scope *t_ = (tscope); \ - struct c_scope *f_ = (fscope); \ - if (t_->to##_last) \ - BLOCK_CHAIN (t_->to##_last) = f_->from; \ - else \ - t_->to = f_->from; \ - t_->to##_last = f_->from##_last; \ +#define SCOPE_LIST_CONCAT(tscope, to, fscope, from) do { \ + struct c_scope *t_ = (tscope); \ + struct c_scope *f_ = (fscope); \ + if (t_->to##_last) \ + BLOCK_CHAIN (t_->to##_last) = f_->from; \ + else \ + t_->to = f_->from; \ + t_->to##_last = f_->from##_last; \ } while (0) /* A c_inline_static structure stores details of a static identifier @@ -530,9 +537,9 @@ static tree lookup_name_in_scope (tree, struct c_scope *); static tree c_make_fname_decl (location_t, tree, int); static tree grokdeclarator (const struct c_declarator *, - struct c_declspecs *, - enum decl_context, bool, tree *, tree *, tree *, - bool *, enum deprecated_states); + struct c_declspecs *, + enum decl_context, bool, tree *, tree *, tree *, + bool *, enum deprecated_states); static tree grokparms (struct c_arg_info *, bool); static void layout_array_type (tree); @@ -548,7 +555,7 @@ if (CAN_HAVE_LOCATION_P (t) && code != LABEL_EXPR) { if (!EXPR_HAS_LOCATION (t)) - SET_EXPR_LOCATION (t, input_location); + SET_EXPR_LOCATION (t, input_location); } if (code == LABEL_EXPR || code == CASE_LABEL_EXPR) @@ -598,7 +605,7 @@ tree rid = ridpointers[C_RID_CODE (node)]; indent_to (file, indent + 4); fprintf (file, "rid " HOST_PTR_PRINTF " \"%s\"", - (void *) rid, IDENTIFIER_POINTER (rid)); + (void *) rid, IDENTIFIER_POINTER (rid)); } } @@ -687,12 +694,12 @@ labels, and add the LABEL_VARS value. */ static void bind_label (tree name, tree label, struct c_scope *scope, - struct c_label_vars *label_vars) + struct c_label_vars *label_vars) { struct c_binding *b; bind (name, label, scope, /*invisible=*/false, /*nested=*/false, - UNKNOWN_LOCATION); + UNKNOWN_LOCATION); scope->has_label_bindings = true; @@ -712,17 +719,17 @@ { tree type = TREE_TYPE (decl); if (type != error_mark_node - && TREE_CODE (type) == ARRAY_TYPE - && !DECL_EXTERNAL (decl) - && TYPE_DOMAIN (type) == 0) - { - warning_at (DECL_SOURCE_LOCATION (decl), - 0, "array %q+D assumed to have one element", decl); - - complete_array_type (&TREE_TYPE (decl), NULL_TREE, true); - - layout_decl (decl, 0); - } + && TREE_CODE (type) == ARRAY_TYPE + && !DECL_EXTERNAL (decl) + && TYPE_DOMAIN (type) == 0) + { + warning_at (DECL_SOURCE_LOCATION (decl), + 0, "array %q+D assumed to have one element", decl); + + complete_array_type (&TREE_TYPE (decl), NULL_TREE, true); + + layout_decl (decl, 0); + } } } @@ -732,7 +739,7 @@ void record_inline_static (location_t loc, tree func, tree decl, - enum c_inline_static_type type) + enum c_inline_static_type type) { struct c_inline_static *csi = ggc_alloc_c_inline_static (); csi->location = loc; @@ -754,21 +761,21 @@ for (csi = c_inline_statics; csi; csi = csi->next) { if (DECL_EXTERNAL (csi->function)) - switch (csi->type) - { - case csi_internal: - pedwarn (csi->location, 0, - "%qD is static but used in inline function %qD " - "which is not static", csi->static_decl, csi->function); - break; - case csi_modifiable: - pedwarn (csi->location, 0, - "%q+D is static but declared in inline function %qD " - "which is not static", csi->static_decl, csi->function); - break; - default: - gcc_unreachable (); - } + switch (csi->type) + { + case csi_internal: + pedwarn (csi->location, 0, + "%qD is static but used in inline function %qD " + "which is not static", csi->static_decl, csi->function); + break; + case csi_modifiable: + pedwarn (csi->location, 0, + "%q+D is static but declared in inline function %qD " + "which is not static", csi->static_decl, csi->function); + break; + default: + gcc_unreachable (); + } } c_inline_statics = NULL; } @@ -802,8 +809,8 @@ if (p->scope != scope) { /* This label or goto is defined in some other scope, or it is a - label which is not yet defined. There is nothing to - update. */ + label which is not yet defined. There is nothing to + update. */ return false; } @@ -837,11 +844,11 @@ scope = scope->outer) { for (b = scope->bindings; b; b = b->prev) - objc_volatilize_decl (b->decl); + objc_volatilize_decl (b->decl); /* Do not climb up past the current function. */ if (scope->function_body) - break; + break; } } @@ -851,8 +858,8 @@ global_bindings_p (void) { return (current_scope == file_scope && !c_override_global_bindings_to_false - ? -1 - : 0); + ? -1 + : 0); } void @@ -899,15 +906,15 @@ if (next_is_function_body) { /* This is the transition from the parameters to the top level - of the function body. These are the same scope - (C99 6.2.1p4,6) so we do not push another scope structure. - next_is_function_body is set only by store_parm_decls, which - in turn is called when and only when we are about to - encounter the opening curly brace for the function body. - - The outermost block of a function always gets a BLOCK node, - because the debugging output routines expect that each - function has at least one BLOCK. */ + of the function body. These are the same scope + (C99 6.2.1p4,6) so we do not push another scope structure. + next_is_function_body is set only by store_parm_decls, which + in turn is called when and only when we are about to + encounter the opening curly brace for the function body. + + The outermost block of a function always gets a BLOCK node, + because the debugging output routines expect that each + function has at least one BLOCK. */ current_scope->parm_flag = false; current_scope->function_body = true; current_scope->keep = true; @@ -919,39 +926,39 @@ /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes. */ if (current_scope->outer) - current_scope->float_const_decimal64 - = current_scope->outer->float_const_decimal64; + current_scope->float_const_decimal64 + = current_scope->outer->float_const_decimal64; else - current_scope->float_const_decimal64 = false; + current_scope->float_const_decimal64 = false; } else { struct c_scope *scope; if (scope_freelist) - { - scope = scope_freelist; - scope_freelist = scope->outer; - } + { + scope = scope_freelist; + scope_freelist = scope->outer; + } else - scope = ggc_alloc_cleared_c_scope (); + scope = ggc_alloc_cleared_c_scope (); /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes. */ if (current_scope) - scope->float_const_decimal64 = current_scope->float_const_decimal64; + scope->float_const_decimal64 = current_scope->float_const_decimal64; else - scope->float_const_decimal64 = false; + scope->float_const_decimal64 = false; scope->keep = keep_next_level_flag; scope->outer = current_scope; - scope->depth = current_scope ? (current_scope->depth + 1) : 0; + scope->depth = current_scope ? (current_scope->depth + 1) : 0; /* Check for scope depth overflow. Unlikely (2^28 == 268,435,456) but - possible. */ + possible. */ if (current_scope && scope->depth == 0) - { - scope->depth--; - sorry ("GCC supports only %u nested scopes", scope->depth); - } + { + scope->depth--; + sorry ("GCC supports only %u nested scopes", scope->depth); + } current_scope = scope; keep_next_level_flag = false; @@ -1020,7 +1027,7 @@ /* Don't search beyond the current function. */ if (s == current_function_scope) - break; + break; s = s->outer; } @@ -1064,7 +1071,7 @@ /* In each subblock, record that this is its superior. */ for (p = scope->blocks; p; p = BLOCK_CHAIN (p)) - BLOCK_SUPERCONTEXT (p) = block; + BLOCK_SUPERCONTEXT (p) = block; BLOCK_VARS (block) = 0; } @@ -1107,7 +1114,6 @@ } else warn_for_unused_label (p); - /* Labels go in BLOCK_VARS. */ DECL_CHAIN (p) = BLOCK_VARS (block); BLOCK_VARS (block) = p; @@ -1206,6 +1212,7 @@ DECL_EXTERNAL decl for debug info generation. */ tree extp = copy_node (p); + DECL_EXTERNAL (extp) = 1; TREE_STATIC (extp) = 0; TREE_PUBLIC (extp) = 1; @@ -1234,6 +1241,7 @@ set_type_context (TREE_TYPE (p), context); } + /* Fall through. */ /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have already been put there by store_parm_decls. Unused- @@ -1268,12 +1276,12 @@ else if (scope->outer) { if (block) - SCOPE_LIST_APPEND (scope->outer, blocks, block); + SCOPE_LIST_APPEND (scope->outer, blocks, block); /* If we did not make a block for the scope just exited, any - blocks made for inner scopes must be carried forward so they - will later become subblocks of something else. */ + blocks made for inner scopes must be carried forward so they + will later become subblocks of something else. */ else if (scope->blocks) - SCOPE_LIST_CONCAT (scope->outer, blocks, scope, blocks); + SCOPE_LIST_CONCAT (scope->outer, blocks, scope, blocks); } /* Pop the current scope, and free the structure for reuse. */ @@ -1303,7 +1311,7 @@ for (decl = visible_builtins; decl; decl = DECL_CHAIN (decl)) bind (DECL_NAME (decl), decl, file_scope, - /*invisible=*/false, /*nested=*/true, DECL_SOURCE_LOCATION (decl)); + /*invisible=*/false, /*nested=*/true, DECL_SOURCE_LOCATION (decl)); } void @@ -1348,7 +1356,7 @@ struct c_binding *b; if (!scope->has_label_bindings) - continue; + continue; for (b = scope->bindings; b != NULL; b = b->prev) { @@ -1381,7 +1389,7 @@ struct c_binding *b; if (!scope->has_label_bindings) - continue; + continue; for (b = scope->bindings; b != NULL; b = b->prev) { @@ -1441,7 +1449,7 @@ tagged type. */ TYPE_STUB_DECL (type) = pushdecl (build_decl (loc, - TYPE_DECL, NULL_TREE, type)); + TYPE_DECL, NULL_TREE, type)); /* An approximation for now, so we can tell this is a function-scope tag. This will be updated in pop_scope. */ @@ -1452,20 +1460,20 @@ struct c_binding *b = I_SYMBOL_BINDING (name); if (b != NULL - && b->decl != NULL_TREE - && TREE_CODE (b->decl) == TYPE_DECL - && (B_IN_CURRENT_SCOPE (b) - || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b))) - && (TYPE_MAIN_VARIANT (TREE_TYPE (b->decl)) - != TYPE_MAIN_VARIANT (type))) - { - warning_at (loc, OPT_Wc___compat, - ("using %qD as both a typedef and a tag is " - "invalid in C++"), - b->decl); - if (b->locus != UNKNOWN_LOCATION) - inform (b->locus, "originally defined here"); - } + && b->decl != NULL_TREE + && TREE_CODE (b->decl) == TYPE_DECL + && (B_IN_CURRENT_SCOPE (b) + || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b))) + && (TYPE_MAIN_VARIANT (TREE_TYPE (b->decl)) + != TYPE_MAIN_VARIANT (type))) + { + warning_at (loc, OPT_Wc___compat, + ("using %qD as both a typedef and a tag is " + "invalid in C++"), + b->decl); + if (b->locus != UNKNOWN_LOCATION) + inform (b->locus, "originally defined here"); + } } } @@ -1494,12 +1502,12 @@ while (oldargs || newargs) { if (!oldargs - || !newargs - || !TREE_VALUE (oldargs) - || !TREE_VALUE (newargs) - || TYPE_MODE (TREE_VALUE (oldargs)) - != TYPE_MODE (TREE_VALUE (newargs))) - return 0; + || !newargs + || !TREE_VALUE (oldargs) + || !TREE_VALUE (newargs) + || TYPE_MODE (TREE_VALUE (oldargs)) + != TYPE_MODE (TREE_VALUE (newargs))) + return 0; oldargs = TREE_CHAIN (oldargs); newargs = TREE_CHAIN (newargs); @@ -1514,7 +1522,7 @@ diagnostics. */ static void diagnose_arglist_conflict (tree newdecl, tree olddecl, - tree newtype, tree oldtype) + tree newtype, tree oldtype) { tree t; @@ -1532,19 +1540,19 @@ tree type = TREE_VALUE (t); if (TREE_CHAIN (t) == 0 - && TYPE_MAIN_VARIANT (type) != void_type_node) - { - inform (input_location, "a parameter list with an ellipsis can%'t match " - "an empty parameter name list declaration"); - break; - } + && TYPE_MAIN_VARIANT (type) != void_type_node) + { + inform (input_location, "a parameter list with an ellipsis can%'t match " + "an empty parameter name list declaration"); + break; + } if (c_type_promotes_to (type) != type) - { - inform (input_location, "an argument type that has a default promotion can%'t match " - "an empty parameter name list declaration"); - break; - } + { + inform (input_location, "an argument type that has a default promotion can%'t match " + "an empty parameter name list declaration"); + break; + } } } @@ -1570,38 +1578,38 @@ tree newargtype = TREE_VALUE (newargs); if (oldargtype == error_mark_node || newargtype == error_mark_node) - return false; + return false; oldargtype = TYPE_MAIN_VARIANT (oldargtype); newargtype = TYPE_MAIN_VARIANT (newargtype); if (END_OF_ARGLIST (oldargtype) && END_OF_ARGLIST (newargtype)) - break; + break; /* Reaching the end of just one list means the two decls don't - agree on the number of arguments. */ + agree on the number of arguments. */ if (END_OF_ARGLIST (oldargtype)) - { - error ("prototype for %q+D declares more arguments " - "than previous old-style definition", newdecl); - return false; - } + { + error ("prototype for %q+D declares more arguments " + "than previous old-style definition", newdecl); + return false; + } else if (END_OF_ARGLIST (newargtype)) - { - error ("prototype for %q+D declares fewer arguments " - "than previous old-style definition", newdecl); - return false; - } + { + error ("prototype for %q+D declares fewer arguments " + "than previous old-style definition", newdecl); + return false; + } /* Type for passing arg must be consistent with that declared - for the arg. */ + for the arg. */ else if (!comptypes (oldargtype, newargtype)) - { - error ("prototype for %q+D declares argument %d" - " with incompatible type", - newdecl, i); - return false; - } + { + error ("prototype for %q+D declares argument %d" + " with incompatible type", + newdecl, i); + return false; + } oldargs = TREE_CHAIN (oldargs); newargs = TREE_CHAIN (newargs); @@ -1611,7 +1619,7 @@ /* If we get here, no errors were found, but do issue a warning for this poor-style construct. */ warning (0, "prototype for %q+D follows non-prototype definition", - newdecl); + newdecl); return true; #undef END_OF_ARGLIST } @@ -1642,7 +1650,7 @@ static bool diagnose_mismatched_decls (tree newdecl, tree olddecl, - tree *newtypep, tree *oldtypep) + tree *newtypep, tree *oldtypep) { tree newtype, oldtype; bool pedwarned = false; @@ -1650,7 +1658,7 @@ bool retval = true; #define DECL_EXTERN_INLINE(DECL) (DECL_DECLARED_INLINE_P (DECL) \ - && DECL_EXTERNAL (DECL)) + && DECL_EXTERNAL (DECL)) /* If we have error_mark_node for either decl or type, just discard the previous decl - we're in an error cascade already. */ @@ -1666,18 +1674,18 @@ if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) { if (!(TREE_CODE (olddecl) == FUNCTION_DECL - && DECL_BUILT_IN (olddecl) - && !C_DECL_DECLARED_BUILTIN (olddecl))) - { - error ("%q+D redeclared as different kind of symbol", newdecl); - locate_old_decl (olddecl); - } + && DECL_BUILT_IN (olddecl) + && !C_DECL_DECLARED_BUILTIN (olddecl))) + { + error ("%q+D redeclared as different kind of symbol", newdecl); + locate_old_decl (olddecl); + } else if (TREE_PUBLIC (newdecl)) - warning (0, "built-in function %q+D declared as non-function", - newdecl); + warning (0, "built-in function %q+D declared as non-function", + newdecl); else - warning (OPT_Wshadow, "declaration of %q+D shadows " - "a built-in function", newdecl); + warning (OPT_Wshadow, "declaration of %q+D shadows " + "a built-in function", newdecl); return false; } @@ -1693,98 +1701,98 @@ if (!comptypes (oldtype, newtype)) { if (TREE_CODE (olddecl) == FUNCTION_DECL - && DECL_BUILT_IN (olddecl) && !C_DECL_DECLARED_BUILTIN (olddecl)) - { - /* Accept harmless mismatch in function types. - This is for the ffs and fprintf builtins. */ - tree trytype = match_builtin_function_types (newtype, oldtype); - - if (trytype && comptypes (newtype, trytype)) - *oldtypep = oldtype = trytype; - else - { - /* If types don't match for a built-in, throw away the - built-in. No point in calling locate_old_decl here, it - won't print anything. */ - warning (0, "conflicting types for built-in function %q+D", - newdecl); - return false; - } - } + && DECL_BUILT_IN (olddecl) && !C_DECL_DECLARED_BUILTIN (olddecl)) + { + /* Accept harmless mismatch in function types. + This is for the ffs and fprintf builtins. */ + tree trytype = match_builtin_function_types (newtype, oldtype); + + if (trytype && comptypes (newtype, trytype)) + *oldtypep = oldtype = trytype; + else + { + /* If types don't match for a built-in, throw away the + built-in. No point in calling locate_old_decl here, it + won't print anything. */ + warning (0, "conflicting types for built-in function %q+D", + newdecl); + return false; + } + } else if (TREE_CODE (olddecl) == FUNCTION_DECL - && DECL_IS_BUILTIN (olddecl)) - { - /* A conflicting function declaration for a predeclared - function that isn't actually built in. Objective C uses - these. The new declaration silently overrides everything - but the volatility (i.e. noreturn) indication. See also - below. FIXME: Make Objective C use normal builtins. */ - TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl); - return false; - } + && DECL_IS_BUILTIN (olddecl)) + { + /* A conflicting function declaration for a predeclared + function that isn't actually built in. Objective C uses + these. The new declaration silently overrides everything + but the volatility (i.e. noreturn) indication. See also + below. FIXME: Make Objective C use normal builtins. */ + TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl); + return false; + } /* Permit void foo (...) to match int foo (...) if the latter is - the definition and implicit int was used. See - c-torture/compile/920625-2.c. */ + the definition and implicit int was used. See + c-torture/compile/920625-2.c. */ else if (TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl) - && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == void_type_node - && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == integer_type_node - && C_FUNCTION_IMPLICIT_INT (newdecl) && !DECL_INITIAL (olddecl)) - { - pedwarned = pedwarn (input_location, 0, - "conflicting types for %q+D", newdecl); - /* Make sure we keep void as the return type. */ - TREE_TYPE (newdecl) = *newtypep = newtype = oldtype; - C_FUNCTION_IMPLICIT_INT (newdecl) = 0; - } + && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == void_type_node + && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == integer_type_node + && C_FUNCTION_IMPLICIT_INT (newdecl) && !DECL_INITIAL (olddecl)) + { + pedwarned = pedwarn (input_location, 0, + "conflicting types for %q+D", newdecl); + /* Make sure we keep void as the return type. */ + TREE_TYPE (newdecl) = *newtypep = newtype = oldtype; + C_FUNCTION_IMPLICIT_INT (newdecl) = 0; + } /* Permit void foo (...) to match an earlier call to foo (...) with - no declared type (thus, implicitly int). */ + no declared type (thus, implicitly int). */ else if (TREE_CODE (newdecl) == FUNCTION_DECL - && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == void_type_node - && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == integer_type_node - && C_DECL_IMPLICIT (olddecl) && !DECL_INITIAL (olddecl)) - { - pedwarned = pedwarn (input_location, 0, - "conflicting types for %q+D", newdecl); - /* Make sure we keep void as the return type. */ - TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype; - } + && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == void_type_node + && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == integer_type_node + && C_DECL_IMPLICIT (olddecl) && !DECL_INITIAL (olddecl)) + { + pedwarned = pedwarn (input_location, 0, + "conflicting types for %q+D", newdecl); + /* Make sure we keep void as the return type. */ + TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype; + } else - { - int new_quals = TYPE_QUALS (newtype); - int old_quals = TYPE_QUALS (oldtype); - - if (new_quals != old_quals) - { - addr_space_t new_addr = DECODE_QUAL_ADDR_SPACE (new_quals); - addr_space_t old_addr = DECODE_QUAL_ADDR_SPACE (old_quals); - if (new_addr != old_addr) - { - if (ADDR_SPACE_GENERIC_P (new_addr)) - error ("conflicting named address spaces (generic vs %s) " - "for %q+D", - c_addr_space_name (old_addr), newdecl); - else if (ADDR_SPACE_GENERIC_P (old_addr)) - error ("conflicting named address spaces (%s vs generic) " - "for %q+D", - c_addr_space_name (new_addr), newdecl); - else - error ("conflicting named address spaces (%s vs %s) " - "for %q+D", - c_addr_space_name (new_addr), - c_addr_space_name (old_addr), - newdecl); - } - - if (CLEAR_QUAL_ADDR_SPACE (new_quals) - != CLEAR_QUAL_ADDR_SPACE (old_quals)) - error ("conflicting type qualifiers for %q+D", newdecl); - } - else - error ("conflicting types for %q+D", newdecl); - diagnose_arglist_conflict (newdecl, olddecl, newtype, oldtype); - locate_old_decl (olddecl); - return false; - } + { + int new_quals = TYPE_QUALS (newtype); + int old_quals = TYPE_QUALS (oldtype); + + if (new_quals != old_quals) + { + addr_space_t new_addr = DECODE_QUAL_ADDR_SPACE (new_quals); + addr_space_t old_addr = DECODE_QUAL_ADDR_SPACE (old_quals); + if (new_addr != old_addr) + { + if (ADDR_SPACE_GENERIC_P (new_addr)) + error ("conflicting named address spaces (generic vs %s) " + "for %q+D", + c_addr_space_name (old_addr), newdecl); + else if (ADDR_SPACE_GENERIC_P (old_addr)) + error ("conflicting named address spaces (%s vs generic) " + "for %q+D", + c_addr_space_name (new_addr), newdecl); + else + error ("conflicting named address spaces (%s vs %s) " + "for %q+D", + c_addr_space_name (new_addr), + c_addr_space_name (old_addr), + newdecl); + } + + if (CLEAR_QUAL_ADDR_SPACE (new_quals) + != CLEAR_QUAL_ADDR_SPACE (old_quals)) + error ("conflicting type qualifiers for %q+D", newdecl); + } + else + error ("conflicting types for %q+D", newdecl); + diagnose_arglist_conflict (newdecl, olddecl, newtype, oldtype); + locate_old_decl (olddecl); + return false; + } } /* Redeclaration of a type is a constraint violation (6.7.2.3p1), @@ -1808,10 +1816,10 @@ } if (DECL_IN_SYSTEM_HEADER (newdecl) - || DECL_IN_SYSTEM_HEADER (olddecl) - || TREE_NO_WARNING (newdecl) - || TREE_NO_WARNING (olddecl)) - return true; /* Allow OLDDECL to continue in use. */ + || DECL_IN_SYSTEM_HEADER (olddecl) + || TREE_NO_WARNING (newdecl) + || TREE_NO_WARNING (olddecl)) + return true; /* Allow OLDDECL to continue in use. */ if (pedantic && !flag_isoc1x) { @@ -1844,9 +1852,9 @@ else if (TREE_CODE (newdecl) == FUNCTION_DECL) { /* If you declare a built-in function name as static, or - define the built-in with an old-style definition (so we - can't validate the argument list) the built-in definition is - overridden, but optionally warn this was a bad choice of name. */ + define the built-in with an old-style definition (so we + can't validate the argument list) the built-in definition is + overridden, but optionally warn this was a bad choice of name. */ if (DECL_BUILT_IN (olddecl) && !C_DECL_DECLARED_BUILTIN (olddecl) && (!TREE_PUBLIC (newdecl) @@ -1860,33 +1868,33 @@ } if (DECL_INITIAL (newdecl)) - { - if (DECL_INITIAL (olddecl)) - { - /* If both decls are in the same TU and the new declaration - isn't overriding an extern inline reject the new decl. - In c99, no overriding is allowed in the same translation - unit. */ - if ((!DECL_EXTERN_INLINE (olddecl) - || DECL_EXTERN_INLINE (newdecl) - || (!flag_gnu89_inline - && (!DECL_DECLARED_INLINE_P (olddecl) - || !lookup_attribute ("gnu_inline", - DECL_ATTRIBUTES (olddecl))) - && (!DECL_DECLARED_INLINE_P (newdecl) - || !lookup_attribute ("gnu_inline", - DECL_ATTRIBUTES (newdecl)))) - ) - && same_translation_unit_p (newdecl, olddecl)) - { - error ("redefinition of %q+D", newdecl); - locate_old_decl (olddecl); - return false; - } - } - } + { + if (DECL_INITIAL (olddecl)) + { + /* If both decls are in the same TU and the new declaration + isn't overriding an extern inline reject the new decl. + In c99, no overriding is allowed in the same translation + unit. */ + if ((!DECL_EXTERN_INLINE (olddecl) + || DECL_EXTERN_INLINE (newdecl) + || (!flag_gnu89_inline + && (!DECL_DECLARED_INLINE_P (olddecl) + || !lookup_attribute ("gnu_inline", + DECL_ATTRIBUTES (olddecl))) + && (!DECL_DECLARED_INLINE_P (newdecl) + || !lookup_attribute ("gnu_inline", + DECL_ATTRIBUTES (newdecl)))) + ) + && same_translation_unit_p (newdecl, olddecl)) + { + error ("redefinition of %q+D", newdecl); + locate_old_decl (olddecl); + return false; + } + } + } /* If we have a prototype after an old-style function definition, - the argument types must be checked specially. */ + the argument types must be checked specially. */ else if (DECL_INITIAL (olddecl) && !prototype_p (oldtype) && prototype_p (newtype) && TYPE_ACTUAL_ARG_TYPES (oldtype) @@ -1896,172 +1904,172 @@ return false; } /* A non-static declaration (even an "extern") followed by a - static declaration is undefined behavior per C99 6.2.2p3-5,7. - The same is true for a static forward declaration at block - scope followed by a non-static declaration/definition at file - scope. Static followed by non-static at the same scope is - not undefined behavior, and is the most convenient way to get - some effects (see e.g. what unwind-dw2-fde-glibc.c does to - the definition of _Unwind_Find_FDE in unwind-dw2-fde.c), but - we do diagnose it if -Wtraditional. */ + static declaration is undefined behavior per C99 6.2.2p3-5,7. + The same is true for a static forward declaration at block + scope followed by a non-static declaration/definition at file + scope. Static followed by non-static at the same scope is + not undefined behavior, and is the most convenient way to get + some effects (see e.g. what unwind-dw2-fde-glibc.c does to + the definition of _Unwind_Find_FDE in unwind-dw2-fde.c), but + we do diagnose it if -Wtraditional. */ if (TREE_PUBLIC (olddecl) && !TREE_PUBLIC (newdecl)) - { - /* Two exceptions to the rule. If olddecl is an extern - inline, or a predeclared function that isn't actually - built in, newdecl silently overrides olddecl. The latter - occur only in Objective C; see also above. (FIXME: Make - Objective C use normal builtins.) */ - if (!DECL_IS_BUILTIN (olddecl) - && !DECL_EXTERN_INLINE (olddecl)) - { - error ("static declaration of %q+D follows " - "non-static declaration", newdecl); - locate_old_decl (olddecl); - } - return false; - } + { + /* Two exceptions to the rule. If olddecl is an extern + inline, or a predeclared function that isn't actually + built in, newdecl silently overrides olddecl. The latter + occur only in Objective C; see also above. (FIXME: Make + Objective C use normal builtins.) */ + if (!DECL_IS_BUILTIN (olddecl) + && !DECL_EXTERN_INLINE (olddecl)) + { + error ("static declaration of %q+D follows " + "non-static declaration", newdecl); + locate_old_decl (olddecl); + } + return false; + } else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl)) - { - if (DECL_CONTEXT (olddecl)) - { - error ("non-static declaration of %q+D follows " - "static declaration", newdecl); - locate_old_decl (olddecl); - return false; - } - else if (warn_traditional) - { - warned |= warning (OPT_Wtraditional, - "non-static declaration of %q+D " - "follows static declaration", newdecl); - } - } + { + if (DECL_CONTEXT (olddecl)) + { + error ("non-static declaration of %q+D follows " + "static declaration", newdecl); + locate_old_decl (olddecl); + return false; + } + else if (warn_traditional) + { + warned |= warning (OPT_Wtraditional, + "non-static declaration of %q+D " + "follows static declaration", newdecl); + } + } /* Make sure gnu_inline attribute is either not present, or - present on all inline decls. */ + present on all inline decls. */ if (DECL_DECLARED_INLINE_P (olddecl) - && DECL_DECLARED_INLINE_P (newdecl)) - { - bool newa = lookup_attribute ("gnu_inline", - DECL_ATTRIBUTES (newdecl)) != NULL; - bool olda = lookup_attribute ("gnu_inline", - DECL_ATTRIBUTES (olddecl)) != NULL; - if (newa != olda) - { - error_at (input_location, "%<gnu_inline%> attribute present on %q+D", - newa ? newdecl : olddecl); - error_at (DECL_SOURCE_LOCATION (newa ? olddecl : newdecl), - "but not here"); - } - } + && DECL_DECLARED_INLINE_P (newdecl)) + { + bool newa = lookup_attribute ("gnu_inline", + DECL_ATTRIBUTES (newdecl)) != NULL; + bool olda = lookup_attribute ("gnu_inline", + DECL_ATTRIBUTES (olddecl)) != NULL; + if (newa != olda) + { + error_at (input_location, "%<gnu_inline%> attribute present on %q+D", + newa ? newdecl : olddecl); + error_at (DECL_SOURCE_LOCATION (newa ? olddecl : newdecl), + "but not here"); + } + } } else if (TREE_CODE (newdecl) == VAR_DECL) { /* Only variables can be thread-local, and all declarations must - agree on this property. */ + agree on this property. */ if (C_DECL_THREADPRIVATE_P (olddecl) && !DECL_THREAD_LOCAL_P (newdecl)) - { - /* Nothing to check. Since OLDDECL is marked threadprivate - and NEWDECL does not have a thread-local attribute, we - will merge the threadprivate attribute into NEWDECL. */ - ; - } + { + /* Nothing to check. Since OLDDECL is marked threadprivate + and NEWDECL does not have a thread-local attribute, we + will merge the threadprivate attribute into NEWDECL. */ + ; + } else if (DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl)) - { - if (DECL_THREAD_LOCAL_P (newdecl)) - error ("thread-local declaration of %q+D follows " - "non-thread-local declaration", newdecl); - else - error ("non-thread-local declaration of %q+D follows " - "thread-local declaration", newdecl); - - locate_old_decl (olddecl); - return false; - } + { + if (DECL_THREAD_LOCAL_P (newdecl)) + error ("thread-local declaration of %q+D follows " + "non-thread-local declaration", newdecl); + else + error ("non-thread-local declaration of %q+D follows " + "thread-local declaration", newdecl); + + locate_old_decl (olddecl); + return false; + } /* Multiple initialized definitions are not allowed (6.9p3,5). */ if (DECL_INITIAL (newdecl) && DECL_INITIAL (olddecl)) - { - error ("redefinition of %q+D", newdecl); - locate_old_decl (olddecl); - return false; - } + { + error ("redefinition of %q+D", newdecl); + locate_old_decl (olddecl); + return false; + } /* Objects declared at file scope: if the first declaration had - external linkage (even if it was an external reference) the - second must have external linkage as well, or the behavior is - undefined. If the first declaration had internal linkage, then - the second must too, or else be an external reference (in which - case the composite declaration still has internal linkage). - As for function declarations, we warn about the static-then- - extern case only for -Wtraditional. See generally 6.2.2p3-5,7. */ + external linkage (even if it was an external reference) the + second must have external linkage as well, or the behavior is + undefined. If the first declaration had internal linkage, then + the second must too, or else be an external reference (in which + case the composite declaration still has internal linkage). + As for function declarations, we warn about the static-then- + extern case only for -Wtraditional. See generally 6.2.2p3-5,7. */ if (DECL_FILE_SCOPE_P (newdecl) - && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl)) - { - if (DECL_EXTERNAL (newdecl)) - { - if (!DECL_FILE_SCOPE_P (olddecl)) - { - error ("extern declaration of %q+D follows " - "declaration with no linkage", newdecl); - locate_old_decl (olddecl); - return false; - } - else if (warn_traditional) - { - warned |= warning (OPT_Wtraditional, - "non-static declaration of %q+D " - "follows static declaration", newdecl); - } - } - else - { - if (TREE_PUBLIC (newdecl)) - error ("non-static declaration of %q+D follows " - "static declaration", newdecl); - else - error ("static declaration of %q+D follows " - "non-static declaration", newdecl); - - locate_old_decl (olddecl); - return false; - } - } + && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl)) + { + if (DECL_EXTERNAL (newdecl)) + { + if (!DECL_FILE_SCOPE_P (olddecl)) + { + error ("extern declaration of %q+D follows " + "declaration with no linkage", newdecl); + locate_old_decl (olddecl); + return false; + } + else if (warn_traditional) + { + warned |= warning (OPT_Wtraditional, + "non-static declaration of %q+D " + "follows static declaration", newdecl); + } + } + else + { + if (TREE_PUBLIC (newdecl)) + error ("non-static declaration of %q+D follows " + "static declaration", newdecl); + else + error ("static declaration of %q+D follows " + "non-static declaration", newdecl); + + locate_old_decl (olddecl); + return false; + } + } /* Two objects with the same name declared at the same block - scope must both be external references (6.7p3). */ + scope must both be external references (6.7p3). */ else if (!DECL_FILE_SCOPE_P (newdecl)) - { - if (DECL_EXTERNAL (newdecl)) - { - /* Extern with initializer at block scope, which will - already have received an error. */ - } - else if (DECL_EXTERNAL (olddecl)) - { - error ("declaration of %q+D with no linkage follows " - "extern declaration", newdecl); - locate_old_decl (olddecl); - } - else - { - error ("redeclaration of %q+D with no linkage", newdecl); - locate_old_decl (olddecl); - } - - return false; - } + { + if (DECL_EXTERNAL (newdecl)) + { + /* Extern with initializer at block scope, which will + already have received an error. */ + } + else if (DECL_EXTERNAL (olddecl)) + { + error ("declaration of %q+D with no linkage follows " + "extern declaration", newdecl); + locate_old_decl (olddecl); + } + else + { + error ("redeclaration of %q+D with no linkage", newdecl); + locate_old_decl (olddecl); + } + + return false; + } /* C++ does not permit a decl to appear multiple times at file - scope. */ + scope. */ if (warn_cxx_compat - && DECL_FILE_SCOPE_P (newdecl) - && !DECL_EXTERNAL (newdecl) - && !DECL_EXTERNAL (olddecl)) - warned |= warning_at (DECL_SOURCE_LOCATION (newdecl), - OPT_Wc___compat, - ("duplicate declaration of %qD is " - "invalid in C++"), - newdecl); + && DECL_FILE_SCOPE_P (newdecl) + && !DECL_EXTERNAL (newdecl) + && !DECL_EXTERNAL (olddecl)) + warned |= warning_at (DECL_SOURCE_LOCATION (newdecl), + OPT_Wc___compat, + ("duplicate declaration of %qD is " + "invalid in C++"), + newdecl); } /* warnings */ @@ -2071,70 +2079,70 @@ && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl)) { warned |= warning (0, "redeclaration of %q+D with different visibility " - "(old visibility preserved)", newdecl); + "(old visibility preserved)", newdecl); } if (TREE_CODE (newdecl) == FUNCTION_DECL) { /* Diagnose inline __attribute__ ((noinline)) which is silly. */ if (DECL_DECLARED_INLINE_P (newdecl) - && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl))) - { - warned |= warning (OPT_Wattributes, - "inline declaration of %qD follows " - "declaration with attribute noinline", newdecl); - } + && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl))) + { + warned |= warning (OPT_Wattributes, + "inline declaration of %qD follows " + "declaration with attribute noinline", newdecl); + } else if (DECL_DECLARED_INLINE_P (olddecl) - && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl))) - { - warned |= warning (OPT_Wattributes, - "declaration of %q+D with attribute " - "noinline follows inline declaration ", newdecl); - } + && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl))) + { + warned |= warning (OPT_Wattributes, + "declaration of %q+D with attribute " + "noinline follows inline declaration ", newdecl); + } } else /* PARM_DECL, VAR_DECL */ { /* Redeclaration of a parameter is a constraint violation (this is - not explicitly stated, but follows from C99 6.7p3 [no more than - one declaration of the same identifier with no linkage in the - same scope, except type tags] and 6.2.2p6 [parameters have no - linkage]). We must check for a forward parameter declaration, - indicated by TREE_ASM_WRITTEN on the old declaration - this is - an extension, the mandatory diagnostic for which is handled by - mark_forward_parm_decls. */ + not explicitly stated, but follows from C99 6.7p3 [no more than + one declaration of the same identifier with no linkage in the + same scope, except type tags] and 6.2.2p6 [parameters have no + linkage]). We must check for a forward parameter declaration, + indicated by TREE_ASM_WRITTEN on the old declaration - this is + an extension, the mandatory diagnostic for which is handled by + mark_forward_parm_decls. */ if (TREE_CODE (newdecl) == PARM_DECL - && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl))) - { - error ("redefinition of parameter %q+D", newdecl); - locate_old_decl (olddecl); - return false; - } + && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl))) + { + error ("redefinition of parameter %q+D", newdecl); + locate_old_decl (olddecl); + return false; + } } /* Optional warning for completely redundant decls. */ if (!warned && !pedwarned && warn_redundant_decls /* Don't warn about a function declaration followed by a - definition. */ + definition. */ && !(TREE_CODE (newdecl) == FUNCTION_DECL - && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)) + && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)) /* Don't warn about redundant redeclarations of builtins. */ && !(TREE_CODE (newdecl) == FUNCTION_DECL - && !DECL_BUILT_IN (newdecl) - && DECL_BUILT_IN (olddecl) - && !C_DECL_DECLARED_BUILTIN (olddecl)) + && !DECL_BUILT_IN (newdecl) + && DECL_BUILT_IN (olddecl) + && !C_DECL_DECLARED_BUILTIN (olddecl)) /* Don't warn about an extern followed by a definition. */ && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl)) /* Don't warn about forward parameter decls. */ && !(TREE_CODE (newdecl) == PARM_DECL - && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl)) + && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl)) /* Don't warn about a variable definition following a declaration. */ && !(TREE_CODE (newdecl) == VAR_DECL - && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))) + && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))) { warned = warning (OPT_Wredundant_decls, "redundant redeclaration of %q+D", - newdecl); + newdecl); } /* Report location of previous decl/defn. */ @@ -2155,7 +2163,7 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype) { bool new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL - && DECL_INITIAL (newdecl) != 0); + && DECL_INITIAL (newdecl) != 0); bool new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL && prototype_p (TREE_TYPE (newdecl))); bool old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL @@ -2171,8 +2179,8 @@ struct c_binding *b, **here; for (here = ¤t_scope->bindings; *here; here = &(*here)->prev) - if ((*here)->decl == olddecl) - goto found; + if ((*here)->decl == olddecl) + goto found; gcc_unreachable (); found: @@ -2196,11 +2204,11 @@ if (!comptypes (oldtype, TREE_TYPE (newdecl))) { if (TREE_TYPE (newdecl) != error_mark_node) - layout_type (TREE_TYPE (newdecl)); + layout_type (TREE_TYPE (newdecl)); if (TREE_CODE (newdecl) != FUNCTION_DECL - && TREE_CODE (newdecl) != TYPE_DECL - && TREE_CODE (newdecl) != CONST_DECL) - layout_decl (newdecl, 0); + && TREE_CODE (newdecl) != TYPE_DECL + && TREE_CODE (newdecl) != CONST_DECL) + layout_decl (newdecl, 0); } else { @@ -2209,10 +2217,10 @@ DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl); DECL_MODE (newdecl) = DECL_MODE (olddecl); if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl)) - { - DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl); - DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl); - } + { + DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl); + DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl); + } } /* Keep the old rtl since we can safely use it. */ @@ -2239,12 +2247,12 @@ && !DECL_IN_SYSTEM_HEADER (newdecl) ) DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl); else if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS) - && DECL_IN_SYSTEM_HEADER (newdecl) - && !DECL_IN_SYSTEM_HEADER (olddecl)) + && DECL_IN_SYSTEM_HEADER (newdecl) + && !DECL_IN_SYSTEM_HEADER (olddecl)) DECL_SOURCE_LOCATION (olddecl) = DECL_SOURCE_LOCATION (newdecl); else if ((DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0) - || (old_is_prototype && !new_is_prototype - && !C_DECL_BUILTIN_PROTOTYPE (olddecl))) + || (old_is_prototype && !new_is_prototype + && !C_DECL_BUILTIN_PROTOTYPE (olddecl))) DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl); /* Merge the initialization information. */ @@ -2261,52 +2269,52 @@ if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS)) { /* Merge the section attribute. - We want to issue an error if the sections conflict but that - must be done later in decl_attributes since we are called - before attributes are assigned. */ + We want to issue an error if the sections conflict but that + must be done later in decl_attributes since we are called + before attributes are assigned. */ if (DECL_SECTION_NAME (newdecl) == NULL_TREE) - DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl); + DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl); /* Copy the assembler name. - Currently, it can only be defined in the prototype. */ + Currently, it can only be defined in the prototype. */ COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl); /* Use visibility of whichever declaration had it specified */ if (DECL_VISIBILITY_SPECIFIED (olddecl)) - { - DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl); - DECL_VISIBILITY_SPECIFIED (newdecl) = 1; - } + { + DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl); + DECL_VISIBILITY_SPECIFIED (newdecl) = 1; + } if (TREE_CODE (newdecl) == FUNCTION_DECL) - { - DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl); - DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl); - DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl); - DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl) - |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl); - TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl); - DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl); - DECL_IS_OPERATOR_NEW (newdecl) |= DECL_IS_OPERATOR_NEW (olddecl); - TREE_READONLY (newdecl) |= TREE_READONLY (olddecl); - DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl); - DECL_IS_NOVOPS (newdecl) |= DECL_IS_NOVOPS (olddecl); - } + { + DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl); + DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl); + DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl); + DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl) + |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl); + TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl); + DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl); + DECL_IS_OPERATOR_NEW (newdecl) |= DECL_IS_OPERATOR_NEW (olddecl); + TREE_READONLY (newdecl) |= TREE_READONLY (olddecl); + DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl); + DECL_IS_NOVOPS (newdecl) |= DECL_IS_NOVOPS (olddecl); + } /* Merge the storage class information. */ merge_weak (newdecl, olddecl); /* For functions, static overrides non-static. */ if (TREE_CODE (newdecl) == FUNCTION_DECL) - { - TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl); - /* This is since we don't automatically - copy the attributes of NEWDECL into OLDDECL. */ - TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); - /* If this clears `static', clear it in the identifier too. */ - if (!TREE_PUBLIC (olddecl)) - TREE_PUBLIC (DECL_NAME (olddecl)) = 0; - } + { + TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl); + /* This is since we don't automatically + copy the attributes of NEWDECL into OLDDECL. */ + TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); + /* If this clears `static', clear it in the identifier too. */ + if (!TREE_PUBLIC (olddecl)) + TREE_PUBLIC (DECL_NAME (olddecl)) = 0; + } } /* In c99, 'extern' declaration before (or after) 'inline' means this @@ -2315,10 +2323,10 @@ if (TREE_CODE (newdecl) == FUNCTION_DECL && !flag_gnu89_inline && (DECL_DECLARED_INLINE_P (newdecl) - || DECL_DECLARED_INLINE_P (olddecl)) + || DECL_DECLARED_INLINE_P (olddecl)) && (!DECL_DECLARED_INLINE_P (newdecl) - || !DECL_DECLARED_INLINE_P (olddecl) - || !DECL_EXTERNAL (olddecl)) + || !DECL_DECLARED_INLINE_P (olddecl) + || !DECL_EXTERNAL (olddecl)) && DECL_EXTERNAL (newdecl) && !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (newdecl)) && !current_function_decl) @@ -2332,10 +2340,10 @@ /* An extern decl does not override previous storage class. */ TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); if (!DECL_EXTERNAL (newdecl)) - { - DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl); - DECL_COMMON (newdecl) = DECL_COMMON (olddecl); - } + { + DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl); + DECL_COMMON (newdecl) = DECL_COMMON (olddecl); + } } else { @@ -2346,53 +2354,53 @@ if (TREE_CODE (newdecl) == FUNCTION_DECL) { /* If we're redefining a function previously defined as extern - inline, make sure we emit debug info for the inline before we - throw it away, in case it was inlined into a function that - hasn't been written out yet. */ + inline, make sure we emit debug info for the inline before we + throw it away, in case it was inlined into a function that + hasn't been written out yet. */ if (new_is_definition && DECL_INITIAL (olddecl)) - /* The new defn must not be inline. */ - DECL_UNINLINABLE (newdecl) = 1; + /* The new defn must not be inline. */ + DECL_UNINLINABLE (newdecl) = 1; else - { - /* If either decl says `inline', this fn is inline, unless - its definition was passed already. */ - if (DECL_DECLARED_INLINE_P (newdecl) - || DECL_DECLARED_INLINE_P (olddecl)) - DECL_DECLARED_INLINE_P (newdecl) = 1; - - DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl) - = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)); - - DECL_DISREGARD_INLINE_LIMITS (newdecl) - = DECL_DISREGARD_INLINE_LIMITS (olddecl) - = (DECL_DISREGARD_INLINE_LIMITS (newdecl) - || DECL_DISREGARD_INLINE_LIMITS (olddecl)); - } + { + /* If either decl says `inline', this fn is inline, unless + its definition was passed already. */ + if (DECL_DECLARED_INLINE_P (newdecl) + || DECL_DECLARED_INLINE_P (olddecl)) + DECL_DECLARED_INLINE_P (newdecl) = 1; + + DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl) + = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)); + + DECL_DISREGARD_INLINE_LIMITS (newdecl) + = DECL_DISREGARD_INLINE_LIMITS (olddecl) + = (DECL_DISREGARD_INLINE_LIMITS (newdecl) + || DECL_DISREGARD_INLINE_LIMITS (olddecl)); + } if (DECL_BUILT_IN (olddecl)) - { - /* If redeclaring a builtin function, it stays built in. - But it gets tagged as having been declared. */ - DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl); - DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl); - C_DECL_DECLARED_BUILTIN (newdecl) = 1; - if (new_is_prototype) - C_DECL_BUILTIN_PROTOTYPE (newdecl) = 0; - else - C_DECL_BUILTIN_PROTOTYPE (newdecl) - = C_DECL_BUILTIN_PROTOTYPE (olddecl); - } + { + /* If redeclaring a builtin function, it stays built in. + But it gets tagged as having been declared. */ + DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl); + DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl); + C_DECL_DECLARED_BUILTIN (newdecl) = 1; + if (new_is_prototype) + C_DECL_BUILTIN_PROTOTYPE (newdecl) = 0; + else + C_DECL_BUILTIN_PROTOTYPE (newdecl) + = C_DECL_BUILTIN_PROTOTYPE (olddecl); + } /* Preserve function specific target and optimization options */ if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl) - && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl)) - DECL_FUNCTION_SPECIFIC_TARGET (newdecl) - = DECL_FUNCTION_SPECIFIC_TARGET (olddecl); + && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl)) + DECL_FUNCTION_SPECIFIC_TARGET (newdecl) + = DECL_FUNCTION_SPECIFIC_TARGET (olddecl); if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl) - && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)) - DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl) - = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl); + && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)) + DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl) + = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl); /* Also preserve various other info from the definition. */ if (!new_is_definition) @@ -2438,8 +2446,8 @@ olddecl_arguments = DECL_ARGUMENTS (olddecl); memcpy ((char *) olddecl + sizeof (struct tree_common), - (char *) newdecl + sizeof (struct tree_common), - sizeof (struct tree_decl_common) - sizeof (struct tree_common)); + (char *) newdecl + sizeof (struct tree_common), + sizeof (struct tree_decl_common) - sizeof (struct tree_common)); switch (TREE_CODE (olddecl)) { case FUNCTION_DECL: @@ -2450,16 +2458,16 @@ case RESULT_DECL: case CONST_DECL: case TYPE_DECL: - memcpy ((char *) olddecl + sizeof (struct tree_decl_common), - (char *) newdecl + sizeof (struct tree_decl_common), - tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common)); - break; + memcpy ((char *) olddecl + sizeof (struct tree_decl_common), + (char *) newdecl + sizeof (struct tree_decl_common), + tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common)); + break; default: - memcpy ((char *) olddecl + sizeof (struct tree_decl_common), - (char *) newdecl + sizeof (struct tree_decl_common), - sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)); + memcpy ((char *) olddecl + sizeof (struct tree_decl_common), + (char *) newdecl + sizeof (struct tree_decl_common), + sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)); } DECL_UID (olddecl) = olddecl_uid; DECL_CONTEXT (olddecl) = olddecl_context; @@ -2472,8 +2480,8 @@ flags and attributes. */ if (DECL_RTL_SET_P (olddecl) && (TREE_CODE (olddecl) == FUNCTION_DECL - || (TREE_CODE (olddecl) == VAR_DECL - && TREE_STATIC (olddecl)))) + || (TREE_CODE (olddecl) == VAR_DECL + && TREE_STATIC (olddecl)))) make_decl_rtl (olddecl); /* If we changed a function from DECL_EXTERNAL to !DECL_EXTERNAL, @@ -2526,35 +2534,35 @@ for (b = I_SYMBOL_BINDING (DECL_NAME (new_decl)); b; b = b->shadowed) if (b->decl && b->decl != new_decl && !b->invisible) { - tree old_decl = b->decl; - - if (old_decl == error_mark_node) - { - warning (OPT_Wshadow, "declaration of %q+D shadows previous " - "non-variable", new_decl); - break; - } - else if (TREE_CODE (old_decl) == PARM_DECL) - warning (OPT_Wshadow, "declaration of %q+D shadows a parameter", - new_decl); - else if (DECL_FILE_SCOPE_P (old_decl)) - warning (OPT_Wshadow, "declaration of %q+D shadows a global " - "declaration", new_decl); - else if (TREE_CODE (old_decl) == FUNCTION_DECL - && DECL_BUILT_IN (old_decl)) - { - warning (OPT_Wshadow, "declaration of %q+D shadows " - "a built-in function", new_decl); - break; - } - else - warning (OPT_Wshadow, "declaration of %q+D shadows a previous local", - new_decl); - - warning_at (DECL_SOURCE_LOCATION (old_decl), OPT_Wshadow, - "shadowed declaration is here"); - - break; + tree old_decl = b->decl; + + if (old_decl == error_mark_node) + { + warning (OPT_Wshadow, "declaration of %q+D shadows previous " + "non-variable", new_decl); + break; + } + else if (TREE_CODE (old_decl) == PARM_DECL) + warning (OPT_Wshadow, "declaration of %q+D shadows a parameter", + new_decl); + else if (DECL_FILE_SCOPE_P (old_decl)) + warning (OPT_Wshadow, "declaration of %q+D shadows a global " + "declaration", new_decl); + else if (TREE_CODE (old_decl) == FUNCTION_DECL + && DECL_BUILT_IN (old_decl)) + { + warning (OPT_Wshadow, "declaration of %q+D shadows " + "a built-in function", new_decl); + break; + } + else + warning (OPT_Wshadow, "declaration of %q+D shadows a previous local", + new_decl); + + warning_at (DECL_SOURCE_LOCATION (old_decl), OPT_Wshadow, + "shadowed declaration is here"); + + break; } } @@ -2580,14 +2588,14 @@ unless they have initializers (which generate code). */ if (current_function_decl && ((TREE_CODE (x) != FUNCTION_DECL && TREE_CODE (x) != VAR_DECL) - || DECL_INITIAL (x) || !DECL_EXTERNAL (x))) + || DECL_INITIAL (x) || !DECL_EXTERNAL (x))) DECL_CONTEXT (x) = current_function_decl; /* Anonymous decls are just inserted in the scope. */ if (!name) { bind (name, x, scope, /*invisible=*/false, /*nested=*/false, - locus); + locus); return x; } @@ -2606,49 +2614,49 @@ tree visdecl = b->decl; tree vistype = TREE_TYPE (visdecl); if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE - && COMPLETE_TYPE_P (TREE_TYPE (x))) - b->inner_comp = false; + && COMPLETE_TYPE_P (TREE_TYPE (x))) + b->inner_comp = false; b_use = b; b_ext = b; /* If this is an external linkage declaration, we should check - for compatibility with the type in the external scope before - setting the type at this scope based on the visible - information only. */ + for compatibility with the type in the external scope before + setting the type at this scope based on the visible + information only. */ if (TREE_PUBLIC (x) && TREE_PUBLIC (visdecl)) - { - while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext)) - b_ext = b_ext->shadowed; - if (b_ext) - { - b_use = b_ext; - if (b_use->u.type) - TREE_TYPE (b_use->decl) = b_use->u.type; - } - } + { + while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext)) + b_ext = b_ext->shadowed; + if (b_ext) + { + b_use = b_ext; + if (b_use->u.type) + TREE_TYPE (b_use->decl) = b_use->u.type; + } + } if (duplicate_decls (x, b_use->decl)) - { - if (b_use != b) - { - /* Save the updated type in the external scope and - restore the proper type for this scope. */ - tree thistype; - if (comptypes (vistype, type)) - thistype = composite_type (vistype, type); - else - thistype = TREE_TYPE (b_use->decl); - b_use->u.type = TREE_TYPE (b_use->decl); - if (TREE_CODE (b_use->decl) == FUNCTION_DECL - && DECL_BUILT_IN (b_use->decl)) - thistype - = build_type_attribute_variant (thistype, - TYPE_ATTRIBUTES - (b_use->u.type)); - TREE_TYPE (b_use->decl) = thistype; - } - return b_use->decl; - } + { + if (b_use != b) + { + /* Save the updated type in the external scope and + restore the proper type for this scope. */ + tree thistype; + if (comptypes (vistype, type)) + thistype = composite_type (vistype, type); + else + thistype = TREE_TYPE (b_use->decl); + b_use->u.type = TREE_TYPE (b_use->decl); + if (TREE_CODE (b_use->decl) == FUNCTION_DECL + && DECL_BUILT_IN (b_use->decl)) + thistype + = build_type_attribute_variant (thistype, + TYPE_ATTRIBUTES + (b_use->u.type)); + TREE_TYPE (b_use->decl) = thistype; + } + return b_use->decl; + } else - goto skip_external_and_shadow_checks; + goto skip_external_and_shadow_checks; } /* All declarations with external linkage, and all external @@ -2670,106 +2678,106 @@ tree visdecl = 0; bool type_saved = false; if (b && !B_IN_EXTERNAL_SCOPE (b) - && (TREE_CODE (b->decl) == FUNCTION_DECL - || TREE_CODE (b->decl) == VAR_DECL) - && DECL_FILE_SCOPE_P (b->decl)) - { - visdecl = b->decl; - vistype = TREE_TYPE (visdecl); - } + && (TREE_CODE (b->decl) == FUNCTION_DECL + || TREE_CODE (b->decl) == VAR_DECL) + && DECL_FILE_SCOPE_P (b->decl)) + { + visdecl = b->decl; + vistype = TREE_TYPE (visdecl); + } if (scope != file_scope - && !DECL_IN_SYSTEM_HEADER (x)) - warning (OPT_Wnested_externs, "nested extern declaration of %qD", x); + && !DECL_IN_SYSTEM_HEADER (x)) + warning (OPT_Wnested_externs, "nested extern declaration of %qD", x); while (b && !B_IN_EXTERNAL_SCOPE (b)) - { - /* If this decl might be modified, save its type. This is - done here rather than when the decl is first bound - because the type may change after first binding, through - being completed or through attributes being added. If we - encounter multiple such decls, only the first should have - its type saved; the others will already have had their - proper types saved and the types will not have changed as - their scopes will not have been re-entered. */ - if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved) - { - b->u.type = TREE_TYPE (b->decl); - type_saved = true; - } - if (B_IN_FILE_SCOPE (b) - && TREE_CODE (b->decl) == VAR_DECL - && TREE_STATIC (b->decl) - && TREE_CODE (TREE_TYPE (b->decl)) == ARRAY_TYPE - && !TYPE_DOMAIN (TREE_TYPE (b->decl)) - && TREE_CODE (type) == ARRAY_TYPE - && TYPE_DOMAIN (type) - && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) - && !integer_zerop (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))) - { - /* Array type completed in inner scope, which should be - diagnosed if the completion does not have size 1 and - it does not get completed in the file scope. */ - b->inner_comp = true; - } - b = b->shadowed; - } + { + /* If this decl might be modified, save its type. This is + done here rather than when the decl is first bound + because the type may change after first binding, through + being completed or through attributes being added. If we + encounter multiple such decls, only the first should have + its type saved; the others will already have had their + proper types saved and the types will not have changed as + their scopes will not have been re-entered. */ + if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved) + { + b->u.type = TREE_TYPE (b->decl); + type_saved = true; + } + if (B_IN_FILE_SCOPE (b) + && TREE_CODE (b->decl) == VAR_DECL + && TREE_STATIC (b->decl) + && TREE_CODE (TREE_TYPE (b->decl)) == ARRAY_TYPE + && !TYPE_DOMAIN (TREE_TYPE (b->decl)) + && TREE_CODE (type) == ARRAY_TYPE + && TYPE_DOMAIN (type) + && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) + && !integer_zerop (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))) + { + /* Array type completed in inner scope, which should be + diagnosed if the completion does not have size 1 and + it does not get completed in the file scope. */ + b->inner_comp = true; + } + b = b->shadowed; + } /* If a matching external declaration has been found, set its - type to the composite of all the types of that declaration. - After the consistency checks, it will be reset to the - composite of the visible types only. */ + type to the composite of all the types of that declaration. + After the consistency checks, it will be reset to the + composite of the visible types only. */ if (b && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl)) - && b->u.type) - TREE_TYPE (b->decl) = b->u.type; + && b->u.type) + TREE_TYPE (b->decl) = b->u.type; /* The point of the same_translation_unit_p check here is, - we want to detect a duplicate decl for a construct like - foo() { extern bar(); } ... static bar(); but not if - they are in different translation units. In any case, - the static does not go in the externals scope. */ + we want to detect a duplicate decl for a construct like + foo() { extern bar(); } ... static bar(); but not if + they are in different translation units. In any case, + the static does not go in the externals scope. */ if (b - && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl)) - && duplicate_decls (x, b->decl)) - { - tree thistype; - if (vistype) - { - if (comptypes (vistype, type)) - thistype = composite_type (vistype, type); - else - thistype = TREE_TYPE (b->decl); - } - else - thistype = type; - b->u.type = TREE_TYPE (b->decl); - if (TREE_CODE (b->decl) == FUNCTION_DECL && DECL_BUILT_IN (b->decl)) - thistype - = build_type_attribute_variant (thistype, - TYPE_ATTRIBUTES (b->u.type)); - TREE_TYPE (b->decl) = thistype; - bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true, - locus); - return b->decl; - } + && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl)) + && duplicate_decls (x, b->decl)) + { + tree thistype; + if (vistype) + { + if (comptypes (vistype, type)) + thistype = composite_type (vistype, type); + else + thistype = TREE_TYPE (b->decl); + } + else + thistype = type; + b->u.type = TREE_TYPE (b->decl); + if (TREE_CODE (b->decl) == FUNCTION_DECL && DECL_BUILT_IN (b->decl)) + thistype + = build_type_attribute_variant (thistype, + TYPE_ATTRIBUTES (b->u.type)); + TREE_TYPE (b->decl) = thistype; + bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true, + locus); + return b->decl; + } else if (TREE_PUBLIC (x)) - { - if (visdecl && !b && duplicate_decls (x, visdecl)) - { - /* An external declaration at block scope referring to a - visible entity with internal linkage. The composite - type will already be correct for this scope, so we - just need to fall through to make the declaration in - this scope. */ - nested = true; - x = visdecl; - } - else - { - bind (name, x, external_scope, /*invisible=*/true, - /*nested=*/false, locus); - nested = true; - } - } + { + if (visdecl && !b && duplicate_decls (x, visdecl)) + { + /* An external declaration at block scope referring to a + visible entity with internal linkage. The composite + type will already be correct for this scope, so we + just need to fall through to make the declaration in + this scope. */ + nested = true; + x = visdecl; + } + else + { + bind (name, x, external_scope, /*invisible=*/true, + /*nested=*/false, locus); + nested = true; + } + } } if (TREE_CODE (x) != PARM_DECL) @@ -2796,16 +2804,16 @@ tree element = TREE_TYPE (x); while (TREE_CODE (element) == ARRAY_TYPE) - element = TREE_TYPE (element); + element = TREE_TYPE (element); element = TYPE_MAIN_VARIANT (element); if ((TREE_CODE (element) == RECORD_TYPE - || TREE_CODE (element) == UNION_TYPE) - && (TREE_CODE (x) != TYPE_DECL - || TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE) - && !COMPLETE_TYPE_P (element)) - C_TYPE_INCOMPLETE_VARS (element) - = tree_cons (NULL_TREE, x, C_TYPE_INCOMPLETE_VARS (element)); + || TREE_CODE (element) == UNION_TYPE) + && (TREE_CODE (x) != TYPE_DECL + || TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE) + && !COMPLETE_TYPE_P (element)) + C_TYPE_INCOMPLETE_VARS (element) + = tree_cons (NULL_TREE, x, C_TYPE_INCOMPLETE_VARS (element)); } return x; } @@ -2829,7 +2837,7 @@ if (TREE_PUBLIC (x)) { bind (name, x, external_scope, /*invisible=*/true, /*nested=*/false, - UNKNOWN_LOCATION); + UNKNOWN_LOCATION); nested = true; } if (file_scope) @@ -2846,21 +2854,26 @@ bool warned; if (flag_isoc99) - warned = pedwarn (input_location, OPT_Wimplicit_function_declaration, - "implicit declaration of function %qE", id); + warned = pedwarn (input_location, OPT_Wimplicit_function_declaration, + "implicit declaration of function %qE", id); else - warned = warning (OPT_Wimplicit_function_declaration, - G_("implicit declaration of function %qE"), id); + warned = warning (OPT_Wimplicit_function_declaration, + G_("implicit declaration of function %qE"), id); if (olddecl && warned) - locate_old_decl (olddecl); + locate_old_decl (olddecl); } } /* Generate an implicit declaration for identifier FUNCTIONID at LOC as a function of type int (). */ +#ifndef noCbC +tree +implicitly_declare (location_t loc, tree functionid, int fun) +#else tree implicitly_declare (location_t loc, tree functionid) +#endif { struct c_binding *b; tree decl = 0; @@ -2869,74 +2882,79 @@ for (b = I_SYMBOL_BINDING (functionid); b; b = b->shadowed) { if (B_IN_SCOPE (b, external_scope)) - { - decl = b->decl; - break; - } + { + decl = b->decl; + break; + } } if (decl) { if (decl == error_mark_node) - return decl; + return decl; /* FIXME: Objective-C has weird not-really-builtin functions - which are supposed to be visible automatically. They wind up - in the external scope because they're pushed before the file - scope gets created. Catch this here and rebind them into the - file scope. */ + which are supposed to be visible automatically. They wind up + in the external scope because they're pushed before the file + scope gets created. Catch this here and rebind them into the + file scope. */ if (!DECL_BUILT_IN (decl) && DECL_IS_BUILTIN (decl)) - { - bind (functionid, decl, file_scope, - /*invisible=*/false, /*nested=*/true, - DECL_SOURCE_LOCATION (decl)); - return decl; - } + { + bind (functionid, decl, file_scope, + /*invisible=*/false, /*nested=*/true, + DECL_SOURCE_LOCATION (decl)); + return decl; + } else - { - tree newtype = default_function_type; - if (b->u.type) - TREE_TYPE (decl) = b->u.type; - /* Implicit declaration of a function already declared - (somehow) in a different scope, or as a built-in. - If this is the first time this has happened, warn; - then recycle the old declaration but with the new type. */ - if (!C_DECL_IMPLICIT (decl)) - { - implicit_decl_warning (functionid, decl); - C_DECL_IMPLICIT (decl) = 1; - } - if (DECL_BUILT_IN (decl)) - { - newtype = build_type_attribute_variant (newtype, - TYPE_ATTRIBUTES - (TREE_TYPE (decl))); - if (!comptypes (newtype, TREE_TYPE (decl))) - { - warning_at (loc, 0, "incompatible implicit declaration of " - "built-in function %qD", decl); - newtype = TREE_TYPE (decl); - } - } - else - { - if (!comptypes (newtype, TREE_TYPE (decl))) - { - error_at (loc, "incompatible implicit declaration of function %qD", decl); - locate_old_decl (decl); - } - } - b->u.type = TREE_TYPE (decl); - TREE_TYPE (decl) = newtype; - bind (functionid, decl, current_scope, - /*invisible=*/false, /*nested=*/true, - DECL_SOURCE_LOCATION (decl)); - return decl; - } + { + tree newtype = default_function_type; + if (b->u.type) + TREE_TYPE (decl) = b->u.type; + /* Implicit declaration of a function already declared + (somehow) in a different scope, or as a built-in. + If this is the first time this has happened, warn; + then recycle the old declaration but with the new type. */ + if (!C_DECL_IMPLICIT (decl)) + { + implicit_decl_warning (functionid, decl); + C_DECL_IMPLICIT (decl) = 1; + } + if (DECL_BUILT_IN (decl)) + { + newtype = build_type_attribute_variant (newtype, + TYPE_ATTRIBUTES + (TREE_TYPE (decl))); + if (!comptypes (newtype, TREE_TYPE (decl))) + { + warning_at (loc, 0, "incompatible implicit declaration of " + "built-in function %qD", decl); + newtype = TREE_TYPE (decl); + } + } + else + { + if (!comptypes (newtype, TREE_TYPE (decl))) + { + error_at (loc, "incompatible implicit declaration of function %qD", decl); + locate_old_decl (decl); + } + } + b->u.type = TREE_TYPE (decl); + TREE_TYPE (decl) = newtype; + bind (functionid, decl, current_scope, + /*invisible=*/false, /*nested=*/true, + DECL_SOURCE_LOCATION (decl)); + return decl; + } } /* Not seen before. */ +#ifndef noCbC + decl = build_decl (loc, FUNCTION_DECL, functionid, + fun==RID_CbC_CODE?build_function_type (void_type_node, NULL_TREE):default_function_type); +#else decl = build_decl (loc, FUNCTION_DECL, functionid, default_function_type); +#endif DECL_EXTERNAL (decl) = 1; TREE_PUBLIC (decl) = 1; C_DECL_IMPLICIT (decl) = 1; @@ -2990,11 +3008,11 @@ } /* If we are parsing old-style parameter decls, current_function_decl - will be nonnull but current_function_scope will be null. */ + will be nonnull but current_function_scope will be null. */ scope = current_function_scope ? current_function_scope : current_scope; } bind (id, error_mark_node, scope, /*invisible=*/false, /*nested=*/false, - UNKNOWN_LOCATION); + UNKNOWN_LOCATION); } /* Subroutine of lookup_label, declare_label, define_label: construct a @@ -3003,7 +3021,7 @@ static tree make_label (location_t location, tree name, bool defining, - struct c_label_vars **p_label_vars) + struct c_label_vars **p_label_vars) { tree label = build_decl (location, LABEL_DECL, name, void_type_node); struct c_label_vars *label_vars; @@ -3043,13 +3061,13 @@ using __label__. */ label = I_LABEL_DECL (name); if (label && (DECL_CONTEXT (label) == current_function_decl - || C_DECLARED_LABEL_FLAG (label))) + || C_DECLARED_LABEL_FLAG (label))) { /* If the label has only been declared, update its apparent - location to point here, for better diagnostics if it - turns out not to have been defined. */ + location to point here, for better diagnostics if it + turns out not to have been defined. */ if (DECL_INITIAL (label) == NULL_TREE) - DECL_SOURCE_LOCATION (label) = input_location; + DECL_SOURCE_LOCATION (label) = input_location; return label; } @@ -3070,10 +3088,10 @@ { if (variably_modified_type_p (TREE_TYPE (decl), NULL_TREE)) error_at (goto_loc, - "jump into scope of identifier with variably modified type"); + "jump into scope of identifier with variably modified type"); else warning_at (goto_loc, OPT_Wjump_misses_init, - "jump skips variable initialization"); + "jump skips variable initialization"); inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label); inform (DECL_SOURCE_LOCATION (decl), "%qD declared here", decl); } @@ -3196,7 +3214,7 @@ } /* We also need to warn about decls defined in any scopes - between the scope of the label and the scope of the goto. */ + between the scope of the label and the scope of the goto. */ for (scope = label_vars->label_bindings.scope; scope != g->goto_bindings.scope; scope = scope->outer) @@ -3217,11 +3235,11 @@ } if (g->goto_bindings.stmt_exprs > 0) - { - error_at (g->loc, "jump into statement expression"); - inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", - label); - } + { + error_at (g->loc, "jump into statement expression"); + inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", + label); + } } /* Now that the label is defined, we will issue warnings about @@ -3245,9 +3263,9 @@ if (label && ((DECL_CONTEXT (label) == current_function_decl - && DECL_INITIAL (label) != 0) - || (DECL_CONTEXT (label) != current_function_decl - && C_DECLARED_LABEL_FLAG (label)))) + && DECL_INITIAL (label) != 0) + || (DECL_CONTEXT (label) != current_function_decl + && C_DECLARED_LABEL_FLAG (label)))) { error_at (location, "duplicate label %qD", label); locate_old_decl (label); @@ -3258,13 +3276,13 @@ struct c_label_vars *label_vars = I_LABEL_BINDING (name)->u.label; /* The label has been used or declared already in this function, - but not defined. Update its location to point to this - definition. */ + but not defined. Update its location to point to this + definition. */ DECL_SOURCE_LOCATION (label) = location; set_spot_bindings (&label_vars->label_bindings, true); /* Issue warnings as required about any goto statements from - earlier in the function. */ + earlier in the function. */ check_earlier_gotos (label, label_vars); } else @@ -3280,8 +3298,8 @@ if (!in_system_header && lookup_name (name)) warning_at (location, OPT_Wtraditional, - "traditional C lacks a separate namespace " - "for labels, identifier %qE conflicts", name); + "traditional C lacks a separate namespace " + "for labels, identifier %qE conflicts", name); /* Mark label as having been defined. */ DECL_INITIAL (label) = error_mark_node; @@ -3315,7 +3333,7 @@ bool c_check_switch_jump_warnings (struct c_spot_bindings *switch_bindings, - location_t switch_loc, location_t case_loc) + location_t switch_loc, location_t case_loc) { bool saw_error; struct c_scope *scope; @@ -3333,24 +3351,24 @@ continue; for (b = scope->bindings; b != NULL; b = b->prev) - { - if (decl_jump_unsafe (b->decl)) - { - if (variably_modified_type_p (TREE_TYPE (b->decl), NULL_TREE)) - { - saw_error = true; - error_at (case_loc, - ("switch jumps into scope of identifier with " - "variably modified type")); - } - else - warning_at (case_loc, OPT_Wjump_misses_init, - "switch jumps over variable initialization"); - inform (switch_loc, "switch starts here"); - inform (DECL_SOURCE_LOCATION (b->decl), "%qD declared here", - b->decl); - } - } + { + if (decl_jump_unsafe (b->decl)) + { + if (variably_modified_type_p (TREE_TYPE (b->decl), NULL_TREE)) + { + saw_error = true; + error_at (case_loc, + ("switch jumps into scope of identifier with " + "variably modified type")); + } + else + warning_at (case_loc, OPT_Wjump_misses_init, + "switch jumps over variable initialization"); + inform (switch_loc, "switch starts here"); + inform (DECL_SOURCE_LOCATION (b->decl), "%qD declared here", + b->decl); + } + } } if (switch_bindings->stmt_exprs > 0) @@ -3374,7 +3392,7 @@ static tree lookup_tag (enum tree_code code, tree name, int thislevel_only, - location_t *ploc) + location_t *ploc) { struct c_binding *b = I_TAG_BINDING (name); int thislevel = 0; @@ -3387,12 +3405,12 @@ if (thislevel_only || TREE_CODE (b->decl) != code) { /* For our purposes, a tag in the external scope is the same as - a tag in the file scope. (Primarily relevant to Objective-C - and its builtin structure tags, which get pushed before the - file scope is created.) */ + a tag in the file scope. (Primarily relevant to Objective-C + and its builtin structure tags, which get pushed before the + file scope is created.) */ if (B_IN_CURRENT_SCOPE (b) - || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b))) - thislevel = 1; + || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b))) + thislevel = 1; } if (thislevel_only && !thislevel) @@ -3405,11 +3423,11 @@ pending_invalid_xref_location = input_location; /* If in the same binding level as a declaration as a tag - of a different type, this must not be allowed to - shadow that tag, so give the error immediately. - (For example, "struct foo; union foo;" is invalid.) */ + of a different type, this must not be allowed to + shadow that tag, so give the error immediately. + (For example, "struct foo; union foo;" is invalid.) */ if (thislevel) - pending_xref_error (); + pending_xref_error (); } if (ploc != NULL) @@ -3428,7 +3446,7 @@ { if (pending_invalid_xref != 0) error_at (pending_invalid_xref_location, "%qE defined as wrong kind of tag", - pending_invalid_xref); + pending_invalid_xref); pending_invalid_xref = 0; } @@ -3497,7 +3515,7 @@ /* Even in C99, which has a real boolean type. */ pushdecl (build_decl (UNKNOWN_LOCATION, TYPE_DECL, get_identifier ("_Bool"), - boolean_type_node)); + boolean_type_node)); input_location = save_loc; @@ -3523,7 +3541,7 @@ size_t length = strlen (name); type = build_array_type (char_type_node, - build_index_type (size_int (length))); + build_index_type (size_int (length))); type = c_build_qualified_type (type, TYPE_QUAL_CONST); decl = build_decl (loc, VAR_DECL, id, type); @@ -3552,7 +3570,7 @@ { DECL_CONTEXT (decl) = current_function_decl; bind (id, decl, current_function_scope, - /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION); + /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION); } finish_decl (decl, loc, init, NULL_TREE, NULL_TREE); @@ -3573,7 +3591,7 @@ gcc_assert (!I_SYMBOL_BINDING (id)); bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false, - UNKNOWN_LOCATION); + UNKNOWN_LOCATION); /* Builtins in the implementation namespace are made visible without needing to be explicitly declared. See push_file_scope. */ @@ -3599,7 +3617,7 @@ gcc_assert (!I_SYMBOL_BINDING (id)); bind (id, decl, external_scope, /*invisible=*/false, /*nested=*/false, - UNKNOWN_LOCATION); + UNKNOWN_LOCATION); /* Builtins in the implementation namespace are made visible without needing to be explicitly declared. See push_file_scope. */ @@ -3701,14 +3719,26 @@ } } else - { - if (warned != 1 && !in_system_header) - { - pedwarn (input_location, 0, - "useless type name in empty declaration"); - warned = 1; - } - } + { + pending_invalid_xref = 0; + t = lookup_tag (code, name, 1, NULL); + + if (t == 0) + { + t = make_node (code); + pushtag (input_location, name, t); + } + } + } + else + { + if (warned != 1 && !in_system_header) + { + pedwarn (input_location, 0, + "useless type name in empty declaration"); + warned = 1; + } + } } else if (warned != 1 && !in_system_header && declspecs->typedef_p) { @@ -3749,9 +3779,9 @@ } if (!warned && !in_system_header && (declspecs->const_p - || declspecs->volatile_p - || declspecs->restrict_p - || declspecs->address_space)) + || declspecs->volatile_p + || declspecs->restrict_p + || declspecs->address_space)) { warning (0, "useless type qualifier in empty declaration"); warned = 2; @@ -3760,7 +3790,7 @@ if (warned != 1) { if (!found_tag) - pedwarn (input_location, 0, "empty declaration"); + pedwarn (input_location, 0, "empty declaration"); } } @@ -3773,24 +3803,24 @@ quals_from_declspecs (const struct c_declspecs *specs) { int quals = ((specs->const_p ? TYPE_QUAL_CONST : 0) - | (specs->volatile_p ? TYPE_QUAL_VOLATILE : 0) - | (specs->restrict_p ? TYPE_QUAL_RESTRICT : 0) - | (ENCODE_QUAL_ADDR_SPACE (specs->address_space))); + | (specs->volatile_p ? TYPE_QUAL_VOLATILE : 0) + | (specs->restrict_p ? TYPE_QUAL_RESTRICT : 0) + | (ENCODE_QUAL_ADDR_SPACE (specs->address_space))); gcc_assert (!specs->type - && !specs->decl_attr - && specs->typespec_word == cts_none - && specs->storage_class == csc_none - && !specs->typedef_p - && !specs->explicit_signed_p - && !specs->deprecated_p - && !specs->long_p - && !specs->long_long_p - && !specs->short_p - && !specs->signed_p - && !specs->unsigned_p - && !specs->complex_p - && !specs->inline_p - && !specs->thread_p); + && !specs->decl_attr + && specs->typespec_word == cts_none + && specs->storage_class == csc_none + && !specs->typedef_p + && !specs->explicit_signed_p + && !specs->deprecated_p + && !specs->long_p + && !specs->long_long_p + && !specs->short_p + && !specs->signed_p + && !specs->unsigned_p + && !specs->complex_p + && !specs->inline_p + && !specs->thread_p); return quals; } @@ -3806,11 +3836,11 @@ struct c_declarator * build_array_declarator (location_t loc, - tree expr, struct c_declspecs *quals, bool static_p, - bool vla_unspec_p) + tree expr, struct c_declspecs *quals, bool static_p, + bool vla_unspec_p) { struct c_declarator *declarator = XOBNEW (&parser_obstack, - struct c_declarator); + struct c_declarator); declarator->id_loc = loc; declarator->kind = cdk_array; declarator->declarator = 0; @@ -3830,23 +3860,23 @@ if (!flag_isoc99) { if (static_p || quals != NULL) - pedwarn (loc, OPT_pedantic, - "ISO C90 does not support %<static%> or type " - "qualifiers in parameter array declarators"); + pedwarn (loc, OPT_pedantic, + "ISO C90 does not support %<static%> or type " + "qualifiers in parameter array declarators"); if (vla_unspec_p) - pedwarn (loc, OPT_pedantic, - "ISO C90 does not support %<[*]%> array declarators"); + pedwarn (loc, OPT_pedantic, + "ISO C90 does not support %<[*]%> array declarators"); } if (vla_unspec_p) { if (!current_scope->parm_flag) - { - /* C99 6.7.5.2p4 */ - error_at (loc, "%<[*]%> not allowed in other than " - "function prototype scope"); - declarator->u.array.vla_unspec_p = false; - return NULL; - } + { + /* C99 6.7.5.2p4 */ + error_at (loc, "%<[*]%> not allowed in other than " + "function prototype scope"); + declarator->u.array.vla_unspec_p = false; + return NULL; + } current_scope->had_vla_unspec = true; } return declarator; @@ -3858,7 +3888,7 @@ struct c_declarator * set_array_declarator_inner (struct c_declarator *decl, - struct c_declarator *inner) + struct c_declarator *inner) { decl->declarator = inner; return decl; @@ -3885,9 +3915,9 @@ { complete_array_type (&type, elt, false); DECL_SIZE (decl) - = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type)); + = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type)); DECL_SIZE_UNIT (decl) - = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), TYPE_SIZE_UNIT (type)); + = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), TYPE_SIZE_UNIT (type)); } } @@ -3899,7 +3929,7 @@ tree groktypename (struct c_type_name *type_name, tree *expr, - bool *expr_const_operands) + bool *expr_const_operands) { tree type; tree attrs = type_name->specs->attrs; @@ -3907,8 +3937,8 @@ type_name->specs->attrs = NULL_TREE; type = grokdeclarator (type_name->declarator, type_name->specs, TYPENAME, - false, NULL, &attrs, expr, expr_const_operands, - DEPRECATED_NORMAL); + false, NULL, &attrs, expr, expr_const_operands, + DEPRECATED_NORMAL); /* Apply attributes. */ decl_attributes (&type, attrs, 0); @@ -3933,7 +3963,7 @@ tree start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs, - bool initialized, tree attributes) + bool initialized, tree attributes) { tree decl; tree tem; @@ -3946,8 +3976,8 @@ deprecated_state = DEPRECATED_SUPPRESS; decl = grokdeclarator (declarator, declspecs, - NORMAL, initialized, NULL, &attributes, &expr, NULL, - deprecated_state); + NORMAL, initialized, NULL, &attributes, &expr, NULL, + deprecated_state); if (!decl) return 0; @@ -3964,64 +3994,64 @@ switch (TREE_CODE (decl)) { case TYPE_DECL: - error ("typedef %qD is initialized (use __typeof__ instead)", decl); - initialized = 0; - break; + error ("typedef %qD is initialized (use __typeof__ instead)", decl); + initialized = 0; + break; case FUNCTION_DECL: - error ("function %qD is initialized like a variable", decl); - initialized = 0; - break; + error ("function %qD is initialized like a variable", decl); + initialized = 0; + break; case PARM_DECL: - /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */ - error ("parameter %qD is initialized", decl); - initialized = 0; - break; + /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */ + error ("parameter %qD is initialized", decl); + initialized = 0; + break; default: - /* Don't allow initializations for incomplete types except for - arrays which might be completed by the initialization. */ - - /* This can happen if the array size is an undefined macro. - We already gave a warning, so we don't need another one. */ - if (TREE_TYPE (decl) == error_mark_node) - initialized = 0; - else if (COMPLETE_TYPE_P (TREE_TYPE (decl))) - { - /* A complete type is ok if size is fixed. */ - - if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST - || C_DECL_VARIABLE_SIZE (decl)) - { - error ("variable-sized object may not be initialized"); - initialized = 0; - } - } - else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE) - { - error ("variable %qD has initializer but incomplete type", decl); - initialized = 0; - } - else if (C_DECL_VARIABLE_SIZE (decl)) - { - /* Although C99 is unclear about whether incomplete arrays - of VLAs themselves count as VLAs, it does not make - sense to permit them to be initialized given that - ordinary VLAs may not be initialized. */ - error ("variable-sized object may not be initialized"); - initialized = 0; - } + /* Don't allow initializations for incomplete types except for + arrays which might be completed by the initialization. */ + + /* This can happen if the array size is an undefined macro. + We already gave a warning, so we don't need another one. */ + if (TREE_TYPE (decl) == error_mark_node) + initialized = 0; + else if (COMPLETE_TYPE_P (TREE_TYPE (decl))) + { + /* A complete type is ok if size is fixed. */ + + if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST + || C_DECL_VARIABLE_SIZE (decl)) + { + error ("variable-sized object may not be initialized"); + initialized = 0; + } + } + else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE) + { + error ("variable %qD has initializer but incomplete type", decl); + initialized = 0; + } + else if (C_DECL_VARIABLE_SIZE (decl)) + { + /* Although C99 is unclear about whether incomplete arrays + of VLAs themselves count as VLAs, it does not make + sense to permit them to be initialized given that + ordinary VLAs may not be initialized. */ + error ("variable-sized object may not be initialized"); + initialized = 0; + } } if (initialized) { if (current_scope == file_scope) - TREE_STATIC (decl) = 1; + TREE_STATIC (decl) = 1; /* Tell 'pushdecl' this is an initialized decl - even though we don't yet have the initializer expression. - Also tell 'finish_decl' it may store the real initializer. */ + even though we don't yet have the initializer expression. + Also tell 'finish_decl' it may store the real initializer. */ DECL_INITIAL (decl) = error_mark_node; } @@ -4057,12 +4087,12 @@ && !flag_gnu89_inline && TREE_CODE (decl) == FUNCTION_DECL && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl)) - || current_function_decl)) + || current_function_decl)) { if (declspecs->storage_class == csc_auto && current_scope != file_scope) - ; + ; else if (declspecs->storage_class != csc_static) - DECL_EXTERNAL (decl) = !DECL_EXTERNAL (decl); + DECL_EXTERNAL (decl) = !DECL_EXTERNAL (decl); } if (TREE_CODE (decl) == FUNCTION_DECL @@ -4071,7 +4101,7 @@ struct c_declarator *ce = declarator; if (ce->kind == cdk_pointer) - ce = declarator->declarator; + ce = declarator->declarator; if (ce->kind == cdk_function) { tree args = ce->u.arg_info->parms; @@ -4090,7 +4120,7 @@ && DECL_UNINLINABLE (decl) && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl))) warning (OPT_Wattributes, "inline function %q+D given attribute noinline", - decl); + decl); /* C99 6.7.4p3: An inline definition of a function with external linkage shall not contain a definition of a modifiable object @@ -4102,7 +4132,7 @@ && DECL_DECLARED_INLINE_P (current_function_decl) && DECL_EXTERNAL (current_function_decl)) record_inline_static (input_location, current_function_decl, - decl, csi_modifiable); + decl, csi_modifiable); if (c_dialect_objc () && (TREE_CODE (decl) == VAR_DECL @@ -4161,7 +4191,7 @@ void finish_decl (tree decl, location_t init_loc, tree init, - tree origtype, tree asmspec_tree) + tree origtype, tree asmspec_tree) { tree type; bool was_incomplete = (DECL_SIZE (decl) == 0); @@ -4193,8 +4223,8 @@ store_init_value (init_loc, decl, init, origtype); if (c_dialect_objc () && (TREE_CODE (decl) == VAR_DECL - || TREE_CODE (decl) == FUNCTION_DECL - || TREE_CODE (decl) == FIELD_DECL)) + || TREE_CODE (decl) == FUNCTION_DECL + || TREE_CODE (decl) == FIELD_DECL)) objc_check_decl (decl); type = TREE_TYPE (decl); @@ -4205,65 +4235,65 @@ && TREE_CODE (decl) != TYPE_DECL) { bool do_default - = (TREE_STATIC (decl) - /* Even if pedantic, an external linkage array - may have incomplete type at first. */ - ? pedantic && !TREE_PUBLIC (decl) - : !DECL_EXTERNAL (decl)); + = (TREE_STATIC (decl) + /* Even if pedantic, an external linkage array + may have incomplete type at first. */ + ? pedantic && !TREE_PUBLIC (decl) + : !DECL_EXTERNAL (decl)); int failure - = complete_array_type (&TREE_TYPE (decl), DECL_INITIAL (decl), - do_default); + = complete_array_type (&TREE_TYPE (decl), DECL_INITIAL (decl), + do_default); /* Get the completed type made by complete_array_type. */ type = TREE_TYPE (decl); switch (failure) - { - case 1: - error ("initializer fails to determine size of %q+D", decl); - break; - - case 2: - if (do_default) - error ("array size missing in %q+D", decl); - /* If a `static' var's size isn't known, - make it extern as well as static, so it does not get - allocated. - If it is not `static', then do not mark extern; - finish_incomplete_decl will give it a default size - and it will get allocated. */ - else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl)) - DECL_EXTERNAL (decl) = 1; - break; - - case 3: - error ("zero or negative size array %q+D", decl); - break; - - case 0: - /* For global variables, update the copy of the type that - exists in the binding. */ - if (TREE_PUBLIC (decl)) - { - struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl)); - while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext)) - b_ext = b_ext->shadowed; - if (b_ext) - { - if (b_ext->u.type) - b_ext->u.type = composite_type (b_ext->u.type, type); - else - b_ext->u.type = type; - } - } - break; - - default: - gcc_unreachable (); - } + { + case 1: + error ("initializer fails to determine size of %q+D", decl); + break; + + case 2: + if (do_default) + error ("array size missing in %q+D", decl); + /* If a `static' var's size isn't known, + make it extern as well as static, so it does not get + allocated. + If it is not `static', then do not mark extern; + finish_incomplete_decl will give it a default size + and it will get allocated. */ + else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl)) + DECL_EXTERNAL (decl) = 1; + break; + + case 3: + error ("zero or negative size array %q+D", decl); + break; + + case 0: + /* For global variables, update the copy of the type that + exists in the binding. */ + if (TREE_PUBLIC (decl)) + { + struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl)); + while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext)) + b_ext = b_ext->shadowed; + if (b_ext) + { + if (b_ext->u.type) + b_ext->u.type = composite_type (b_ext->u.type, type); + else + b_ext->u.type = type; + } + } + break; + + default: + gcc_unreachable (); + } if (DECL_INITIAL (decl)) - TREE_TYPE (DECL_INITIAL (decl)) = type; + TREE_TYPE (DECL_INITIAL (decl)) = type; layout_decl (decl, 0); } @@ -4271,42 +4301,42 @@ if (TREE_CODE (decl) == VAR_DECL) { if (init && TREE_CODE (init) == CONSTRUCTOR) - add_flexible_array_elts_to_size (decl, init); + add_flexible_array_elts_to_size (decl, init); if (DECL_SIZE (decl) == 0 && TREE_TYPE (decl) != error_mark_node - && COMPLETE_TYPE_P (TREE_TYPE (decl))) - layout_decl (decl, 0); + && COMPLETE_TYPE_P (TREE_TYPE (decl))) + layout_decl (decl, 0); if (DECL_SIZE (decl) == 0 - /* Don't give an error if we already gave one earlier. */ - && TREE_TYPE (decl) != error_mark_node - && (TREE_STATIC (decl) - /* A static variable with an incomplete type - is an error if it is initialized. - Also if it is not file scope. - Otherwise, let it through, but if it is not `extern' - then it may cause an error message later. */ - ? (DECL_INITIAL (decl) != 0 - || !DECL_FILE_SCOPE_P (decl)) - /* An automatic variable with an incomplete type - is an error. */ - : !DECL_EXTERNAL (decl))) - { - error ("storage size of %q+D isn%'t known", decl); - TREE_TYPE (decl) = error_mark_node; - } + /* Don't give an error if we already gave one earlier. */ + && TREE_TYPE (decl) != error_mark_node + && (TREE_STATIC (decl) + /* A static variable with an incomplete type + is an error if it is initialized. + Also if it is not file scope. + Otherwise, let it through, but if it is not `extern' + then it may cause an error message later. */ + ? (DECL_INITIAL (decl) != 0 + || !DECL_FILE_SCOPE_P (decl)) + /* An automatic variable with an incomplete type + is an error. */ + : !DECL_EXTERNAL (decl))) + { + error ("storage size of %q+D isn%'t known", decl); + TREE_TYPE (decl) = error_mark_node; + } if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl)) - && DECL_SIZE (decl) != 0) - { - if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) - constant_expression_warning (DECL_SIZE (decl)); - else - { - error ("storage size of %q+D isn%'t constant", decl); - TREE_TYPE (decl) = error_mark_node; - } - } + && DECL_SIZE (decl) != 0) + { + if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) + constant_expression_warning (DECL_SIZE (decl)); + else + { + error ("storage size of %q+D isn%'t constant", decl); + TREE_TYPE (decl) = error_mark_node; + } + } if (TREE_USED (type)) { @@ -4321,7 +4351,7 @@ if (TREE_CODE (decl) == FUNCTION_DECL && asmspec) { if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL) - set_builtin_user_assembler_name (decl, asmspec); + set_builtin_user_assembler_name (decl, asmspec); set_user_assembler_name (decl, asmspec); } @@ -4336,98 +4366,98 @@ { /* Determine the ELF visibility. */ if (TREE_PUBLIC (decl)) - c_determine_visibility (decl); + c_determine_visibility (decl); /* This is a no-op in c-lang.c or something real in objc-act.c. */ if (c_dialect_objc ()) - objc_check_decl (decl); + objc_check_decl (decl); if (asmspec) - { - /* If this is not a static variable, issue a warning. - It doesn't make any sense to give an ASMSPEC for an - ordinary, non-register local variable. Historically, - GCC has accepted -- but ignored -- the ASMSPEC in - this case. */ - if (!DECL_FILE_SCOPE_P (decl) - && TREE_CODE (decl) == VAR_DECL - && !C_DECL_REGISTER (decl) - && !TREE_STATIC (decl)) - warning (0, "ignoring asm-specifier for non-static local " - "variable %q+D", decl); - else - set_user_assembler_name (decl, asmspec); - } + { + /* If this is not a static variable, issue a warning. + It doesn't make any sense to give an ASMSPEC for an + ordinary, non-register local variable. Historically, + GCC has accepted -- but ignored -- the ASMSPEC in + this case. */ + if (!DECL_FILE_SCOPE_P (decl) + && TREE_CODE (decl) == VAR_DECL + && !C_DECL_REGISTER (decl) + && !TREE_STATIC (decl)) + warning (0, "ignoring asm-specifier for non-static local " + "variable %q+D", decl); + else + set_user_assembler_name (decl, asmspec); + } if (DECL_FILE_SCOPE_P (decl)) - { - if (DECL_INITIAL (decl) == NULL_TREE - || DECL_INITIAL (decl) == error_mark_node) - /* Don't output anything - when a tentative file-scope definition is seen. - But at end of compilation, do output code for them. */ - DECL_DEFER_OUTPUT (decl) = 1; - rest_of_decl_compilation (decl, true, 0); - } + { + if (DECL_INITIAL (decl) == NULL_TREE + || DECL_INITIAL (decl) == error_mark_node) + /* Don't output anything + when a tentative file-scope definition is seen. + But at end of compilation, do output code for them. */ + DECL_DEFER_OUTPUT (decl) = 1; + rest_of_decl_compilation (decl, true, 0); + } else - { - /* In conjunction with an ASMSPEC, the `register' - keyword indicates that we should place the variable - in a particular register. */ - if (asmspec && C_DECL_REGISTER (decl)) - { - DECL_HARD_REGISTER (decl) = 1; - /* This cannot be done for a structure with volatile - fields, on which DECL_REGISTER will have been - reset. */ - if (!DECL_REGISTER (decl)) - error ("cannot put object with volatile field into register"); - } - - if (TREE_CODE (decl) != FUNCTION_DECL) - { - /* If we're building a variable sized type, and we might be - reachable other than via the top of the current binding - level, then create a new BIND_EXPR so that we deallocate - the object at the right time. */ - /* Note that DECL_SIZE can be null due to errors. */ - if (DECL_SIZE (decl) - && !TREE_CONSTANT (DECL_SIZE (decl)) - && STATEMENT_LIST_HAS_LABEL (cur_stmt_list)) - { - tree bind; - bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL); - TREE_SIDE_EFFECTS (bind) = 1; - add_stmt (bind); - BIND_EXPR_BODY (bind) = push_stmt_list (); - } - add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), - DECL_EXPR, decl)); - } - } + { + /* In conjunction with an ASMSPEC, the `register' + keyword indicates that we should place the variable + in a particular register. */ + if (asmspec && C_DECL_REGISTER (decl)) + { + DECL_HARD_REGISTER (decl) = 1; + /* This cannot be done for a structure with volatile + fields, on which DECL_REGISTER will have been + reset. */ + if (!DECL_REGISTER (decl)) + error ("cannot put object with volatile field into register"); + } + + if (TREE_CODE (decl) != FUNCTION_DECL) + { + /* If we're building a variable sized type, and we might be + reachable other than via the top of the current binding + level, then create a new BIND_EXPR so that we deallocate + the object at the right time. */ + /* Note that DECL_SIZE can be null due to errors. */ + if (DECL_SIZE (decl) + && !TREE_CONSTANT (DECL_SIZE (decl)) + && STATEMENT_LIST_HAS_LABEL (cur_stmt_list)) + { + tree bind; + bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL); + TREE_SIDE_EFFECTS (bind) = 1; + add_stmt (bind); + BIND_EXPR_BODY (bind) = push_stmt_list (); + } + add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), + DECL_EXPR, decl)); + } + } if (!DECL_FILE_SCOPE_P (decl)) - { - /* Recompute the RTL of a local array now - if it used to be an incomplete type. */ - if (was_incomplete - && !TREE_STATIC (decl) && !DECL_EXTERNAL (decl)) - { - /* If we used it already as memory, it must stay in memory. */ - TREE_ADDRESSABLE (decl) = TREE_USED (decl); - /* If it's still incomplete now, no init will save it. */ - if (DECL_SIZE (decl) == 0) - DECL_INITIAL (decl) = 0; - } - } + { + /* Recompute the RTL of a local array now + if it used to be an incomplete type. */ + if (was_incomplete + && !TREE_STATIC (decl) && !DECL_EXTERNAL (decl)) + { + /* If we used it already as memory, it must stay in memory. */ + TREE_ADDRESSABLE (decl) = TREE_USED (decl); + /* If it's still incomplete now, no init will save it. */ + if (DECL_SIZE (decl) == 0) + DECL_INITIAL (decl) = 0; + } + } } if (TREE_CODE (decl) == TYPE_DECL) { if (!DECL_FILE_SCOPE_P (decl) - && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE)) - add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl)); + && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE)) + add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl)); rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0); } @@ -4489,7 +4519,7 @@ { tree attrs = parm->attrs; tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, - NULL, &attrs, NULL, NULL, DEPRECATED_NORMAL); + NULL, &attrs, NULL, NULL, DEPRECATED_NORMAL); decl_attributes (&decl, attrs, 0); @@ -4506,7 +4536,7 @@ tree decl; decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, NULL, - &attrs, NULL, NULL, DEPRECATED_NORMAL); + &attrs, NULL, NULL, DEPRECATED_NORMAL); decl_attributes (&decl, attrs, 0); decl = pushdecl (decl); @@ -4525,7 +4555,7 @@ if (pedantic && !current_scope->warned_forward_parm_decls) { pedwarn (input_location, OPT_pedantic, - "ISO C forbids forward parameter declarations"); + "ISO C forbids forward parameter declarations"); current_scope->warned_forward_parm_decls = true; } @@ -4568,7 +4598,7 @@ if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type)) { int failure = complete_array_type (&TREE_TYPE (decl), - DECL_INITIAL (decl), true); + DECL_INITIAL (decl), true); gcc_assert (!failure); type = TREE_TYPE (decl); @@ -4615,7 +4645,7 @@ && (type_name->specs->typespec_kind == ctsk_tagdef || type_name->specs->typespec_kind == ctsk_tagfirstref)) warning_at (loc, OPT_Wc___compat, - "defining a type in a compound literal is invalid in C++"); + "defining a type in a compound literal is invalid in C++"); } /* Determine whether TYPE is a structure with a flexible array member, @@ -4634,10 +4664,10 @@ while (DECL_CHAIN (x) != NULL_TREE) x = DECL_CHAIN (x); if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE - && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE - && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE - && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE) - return true; + && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE + && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE + && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE) + return true; return false; case UNION_TYPE: for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x)) @@ -4660,8 +4690,8 @@ unsigned int max_width; unsigned HOST_WIDE_INT w; const char *name = (orig_name - ? identifier_to_locale (IDENTIFIER_POINTER (orig_name)) - : _("<anonymous>")); + ? identifier_to_locale (IDENTIFIER_POINTER (orig_name)) + : _("<anonymous>")); /* Detect and ignore out of range field width and process valid field widths. */