├── .gitattributes ├── .github └── workflows │ ├── build.yml │ ├── latest.yml │ └── oldest.yml ├── .gitignore ├── .gitmodules ├── Changelog.md ├── LICENSE ├── Makefile ├── Makefile.extr ├── Makefile.menhir ├── MenhirLib ├── Alphabet.v ├── Automaton.v ├── Grammar.v ├── Interpreter.v ├── Interpreter_complete.v ├── Interpreter_correct.v ├── Main.v ├── Validator_classes.v ├── Validator_complete.v └── Validator_safe.v ├── README.md ├── VERSION ├── aarch64 ├── Archi.v ├── Asm.v ├── AsmToJSON.ml ├── Asmexpand.ml ├── Asmgen.v ├── Asmgenproof.v ├── Asmgenproof1.v ├── Builtins1.v ├── CBuiltins.ml ├── CombineOp.v ├── CombineOpproof.v ├── ConstpropOp.vp ├── ConstpropOpproof.v ├── Conventions1.v ├── Machregs.v ├── Machregsaux.ml ├── NeedOp.v ├── Op.v ├── PrintOp.ml ├── SelectLong.vp ├── SelectLongproof.v ├── SelectOp.vp ├── SelectOpproof.v ├── Stacklayout.v ├── TargetPrinter.ml ├── ValueAOp.v └── extractionMachdep.v ├── arm ├── Archi.v ├── Asm.v ├── AsmToJSON.ml ├── AsmToJSON.mli ├── Asmexpand.ml ├── Asmgen.v ├── Asmgenproof.v ├── Asmgenproof1.v ├── Builtins1.v ├── CBuiltins.ml ├── CombineOp.v ├── CombineOpproof.v ├── Constantexpand.ml ├── ConstpropOp.vp ├── ConstpropOpproof.v ├── Conventions1.v ├── Machregs.v ├── Machregsaux.ml ├── Machregsaux.mli ├── NeedOp.v ├── Op.v ├── PrintOp.ml ├── SelectLong.vp ├── SelectLongproof.v ├── SelectOp.vp ├── SelectOpproof.v ├── Stacklayout.v ├── TargetPrinter.ml ├── ValueAOp.v └── extractionMachdep.v ├── backend ├── AisAnnot.ml ├── AisAnnot.mli ├── Allocation.v ├── Allocproof.v ├── Asmexpandaux.ml ├── Asmexpandaux.mli ├── Asmgenproof0.v ├── Bounds.v ├── CSE.v ├── CSEdomain.v ├── CSEproof.v ├── CleanupLabels.v ├── CleanupLabelsproof.v ├── Cminor.v ├── CminorSel.v ├── Cminortyping.v ├── Constprop.v ├── Constpropproof.v ├── Conventions.v ├── Deadcode.v ├── Deadcodeproof.v ├── Debugvar.v ├── Debugvarproof.v ├── Fileinfo.ml ├── IRC.ml ├── IRC.mli ├── Inlining.v ├── Inliningaux.ml ├── Inliningaux.mli ├── Inliningproof.v ├── Inliningspec.v ├── Json.ml ├── JsonAST.ml ├── JsonAST.mli ├── Kildall.v ├── LTL.v ├── Linear.v ├── Linearize.v ├── Linearizeaux.ml ├── Linearizeproof.v ├── Lineartyping.v ├── Liveness.v ├── Locations.v ├── Mach.v ├── Machregsnames.ml ├── Machregsnames.mli ├── NeedDomain.v ├── PrintAsm.ml ├── PrintAsm.mli ├── PrintAsmaux.ml ├── PrintCminor.ml ├── PrintLTL.ml ├── PrintMach.ml ├── PrintRTL.ml ├── PrintXTL.ml ├── RTL.v ├── RTLgen.v ├── RTLgenaux.ml ├── RTLgenproof.v ├── RTLgenspec.v ├── RTLtyping.v ├── Regalloc.ml ├── Registers.v ├── Renumber.v ├── Renumberproof.v ├── SelectDiv.vp ├── SelectDivproof.v ├── Selection.v ├── Selectionaux.ml ├── Selectionproof.v ├── SplitLong.vp ├── SplitLongproof.v ├── Splitting.ml ├── Stacking.v ├── Stackingproof.v ├── Tailcall.v ├── Tailcallproof.v ├── Tunneling.v ├── Tunnelingproof.v ├── Unusedglob.v ├── Unusedglobproof.v ├── ValueAnalysis.v ├── ValueDomain.v ├── XTL.ml └── XTL.mli ├── cfrontend ├── C2C.ml ├── CPragmas.ml ├── Cexec.v ├── Clight.v ├── ClightBigstep.v ├── Cminorgen.v ├── Cminorgenproof.v ├── Cop.v ├── Csem.v ├── Csharpminor.v ├── Cshmgen.v ├── Cshmgenproof.v ├── Cstrategy.v ├── Csyntax.v ├── Ctypes.v ├── Ctyping.v ├── Initializers.v ├── Initializersproof.v ├── PrintClight.ml ├── PrintCsyntax.ml ├── SimplExpr.v ├── SimplExprproof.v ├── SimplExprspec.v ├── SimplLocals.v └── SimplLocalsproof.v ├── common ├── AST.v ├── Behaviors.v ├── Builtins.v ├── Builtins0.v ├── Determinism.v ├── Errors.v ├── Events.v ├── Globalenvs.v ├── Linking.v ├── Memdata.v ├── Memory.v ├── Memtype.v ├── PrintAST.ml ├── Sections.ml ├── Sections.mli ├── Separation.v ├── Smallstep.v ├── Subtyping.v ├── Switch.v ├── Switchaux.ml ├── Unityping.v └── Values.v ├── configure ├── coq ├── cparser ├── C.mli ├── Cabs.v ├── Cabshelper.ml ├── Ceval.ml ├── Ceval.mli ├── Cflow.ml ├── Cflow.mli ├── Checks.ml ├── Checks.mli ├── Cleanup.ml ├── Cleanup.mli ├── Cprint.ml ├── Cprint.mli ├── Cutil.ml ├── Cutil.mli ├── Diagnostics.ml ├── Diagnostics.mli ├── Elab.ml ├── Elab.mli ├── Env.ml ├── Env.mli ├── ErrorReports.ml ├── ErrorReports.mli ├── ExtendedAsm.ml ├── GCC.ml ├── GCC.mli ├── GNUmakefile ├── Lexer.mll ├── Machine.ml ├── Machine.mli ├── PackedStructs.ml ├── Parse.ml ├── Parse.mli ├── Parser.vy ├── Rename.ml ├── Rename.mli ├── StructPassing.ml ├── StructPassing.mli ├── SwitchNorm.ml ├── SwitchNorm.mli ├── Transform.ml ├── Transform.mli ├── Unblock.ml ├── Unblock.mli ├── deLexer.ml ├── handcrafted.messages ├── pre_parser.mly ├── pre_parser_aux.ml ├── pre_parser_aux.mli └── tests │ ├── generated │ └── Makefile │ └── handwritten │ ├── conditional-0.c │ ├── conditional-1.c │ ├── dubious-enum.c │ ├── missing-assignment.c │ ├── missing-closing-brace-at-end-of-function.c │ ├── missing-loop-body.c │ ├── missing-operator.c │ ├── missing-semicolon.c │ ├── too-many-closing-parens.c │ ├── unclosed-paren.c │ └── variable-type-confusion.c ├── debug ├── Debug.ml ├── Debug.mli ├── DebugInformation.ml ├── DebugInformation.mli ├── DebugInit.ml ├── DebugTypes.mli ├── DwarfPrinter.ml ├── DwarfPrinter.mli ├── DwarfTypes.mli ├── DwarfUtil.ml └── Dwarfgen.ml ├── doc ├── ccomp.1 ├── index.html └── style.css ├── driver ├── Assembler.ml ├── Assembler.mli ├── Clflags.ml ├── CommonOptions.ml ├── Compiler.v ├── Complements.v ├── Compopts.v ├── Configuration.ml ├── Configuration.mli ├── Driver.ml ├── Driveraux.ml ├── Driveraux.mli ├── Frontend.ml ├── Frontend.mli ├── Interp.ml ├── Linker.ml ├── Linker.mli └── Timing.ml ├── export ├── Clightdefs.v ├── Clightnorm.ml ├── Csyntaxdefs.v ├── Ctypesdefs.v ├── ExportBase.ml ├── ExportClight.ml ├── ExportCsyntax.ml ├── ExportCtypes.ml ├── ExportDriver.ml └── README.md ├── extraction ├── .gitignore └── extraction.v ├── flocq ├── Calc │ ├── Bracket.v │ ├── Div.v │ ├── Operations.v │ ├── Plus.v │ ├── Round.v │ └── Sqrt.v ├── Core │ ├── Core.v │ ├── Defs.v │ ├── Digits.v │ ├── FIX.v │ ├── FLT.v │ ├── FLX.v │ ├── FTZ.v │ ├── Float_prop.v │ ├── Generic_fmt.v │ ├── Raux.v │ ├── Round_NE.v │ ├── Round_pred.v │ ├── Ulp.v │ └── Zaux.v ├── IEEE754 │ ├── Binary.v │ ├── BinarySingleNaN.v │ └── Bits.v ├── Prop │ ├── Div_sqrt_error.v │ ├── Double_rounding.v │ ├── Mult_error.v │ ├── Plus_error.v │ ├── Relative.v │ ├── Round_odd.v │ └── Sterbenz.v └── Version.v ├── lib ├── Axioms.v ├── BoolEqual.v ├── Camlcoq.ml ├── Commandline.ml ├── Commandline.mli ├── Coqlib.v ├── Decidableplus.v ├── FSetAVLplus.v ├── Floats.v ├── Heaps.v ├── IEEE754_extra.v ├── Integers.v ├── Intv.v ├── IntvSets.v ├── Iteration.v ├── Lattice.v ├── Maps.v ├── Ordered.v ├── Parmov.v ├── Postorder.v ├── Printlines.ml ├── Printlines.mli ├── Readconfig.mli ├── Readconfig.mll ├── Responsefile.mli ├── Responsefile.mll ├── Tokenize.mli ├── Tokenize.mll ├── UnionFind.v ├── Wfsimpl.v └── Zbits.v ├── pg ├── powerpc ├── Archi.v ├── Asm.v ├── AsmToJSON.ml ├── AsmToJSON.mli ├── Asmexpand.ml ├── Asmgen.v ├── Asmgenproof.v ├── Asmgenproof1.v ├── Builtins1.v ├── CBuiltins.ml ├── CombineOp.v ├── CombineOpproof.v ├── ConstpropOp.vp ├── ConstpropOpproof.v ├── Conventions1.v ├── Machregs.v ├── Machregsaux.ml ├── Machregsaux.mli ├── NeedOp.v ├── Op.v ├── PrintOp.ml ├── SelectLong.vp ├── SelectLongproof.v ├── SelectOp.vp ├── SelectOpproof.v ├── Stacklayout.v ├── TargetPrinter.ml ├── ValueAOp.v └── extractionMachdep.v ├── riscV ├── Archi.v ├── Asm.v ├── AsmToJSON.ml ├── Asmexpand.ml ├── Asmgen.v ├── Asmgenproof.v ├── Asmgenproof1.v ├── Builtins1.v ├── CBuiltins.ml ├── CombineOp.v ├── CombineOpproof.v ├── ConstpropOp.vp ├── ConstpropOpproof.v ├── Conventions1.v ├── Machregs.v ├── Machregsaux.ml ├── Machregsaux.mli ├── NeedOp.v ├── Op.v ├── PrintOp.ml ├── SelectLong.vp ├── SelectLongproof.v ├── SelectOp.vp ├── SelectOpproof.v ├── Stacklayout.v ├── TargetPrinter.ml ├── ValueAOp.v └── extractionMachdep.v ├── runtime ├── Makefile ├── README ├── aarch64 │ ├── sysdeps.h │ └── vararg.S ├── arm │ ├── i64_dtos.S │ ├── i64_dtou.S │ ├── i64_sar.S │ ├── i64_sdiv.S │ ├── i64_shl.S │ ├── i64_shr.S │ ├── i64_smod.S │ ├── i64_smulh.S │ ├── i64_stod.S │ ├── i64_stof.S │ ├── i64_udiv.S │ ├── i64_udivmod.S │ ├── i64_umod.S │ ├── i64_umulh.S │ ├── i64_utod.S │ ├── i64_utof.S │ ├── sysdeps.h │ └── vararg.S ├── c │ ├── i64.h │ ├── i64_dtos.c │ ├── i64_dtou.c │ ├── i64_sar.c │ ├── i64_sdiv.c │ ├── i64_shl.c │ ├── i64_shr.c │ ├── i64_smod.c │ ├── i64_smulh.c │ ├── i64_stod.c │ ├── i64_stof.c │ ├── i64_udiv.c │ ├── i64_udivmod.c │ ├── i64_umod.c │ ├── i64_umulh.c │ ├── i64_utod.c │ └── i64_utof.c ├── include │ ├── float.h │ ├── iso646.h │ ├── stdalign.h │ ├── stdarg.h │ ├── stdbool.h │ ├── stddef.h │ ├── stdnoreturn.h │ └── varargs.h ├── powerpc │ ├── i64_dtos.S │ ├── i64_dtou.S │ ├── i64_sar.S │ ├── i64_sdiv.S │ ├── i64_shl.S │ ├── i64_shr.S │ ├── i64_smod.S │ ├── i64_smulh.S │ ├── i64_stod.S │ ├── i64_stof.S │ ├── i64_udiv.S │ ├── i64_udivmod.S │ ├── i64_umod.S │ ├── i64_umulh.S │ ├── i64_utod.S │ ├── i64_utof.S │ ├── sysdeps.h │ └── vararg.S ├── powerpc64 │ ├── i64_dtou.S │ ├── i64_stof.S │ ├── i64_utod.S │ ├── i64_utof.S │ ├── sysdeps.h │ └── vararg.S ├── riscV │ ├── sysdeps.h │ └── vararg.S ├── test │ └── test_int64.c ├── x86_32 │ ├── i64_dtos.S │ ├── i64_dtou.S │ ├── i64_sar.S │ ├── i64_sdiv.S │ ├── i64_shl.S │ ├── i64_shr.S │ ├── i64_smod.S │ ├── i64_smulh.S │ ├── i64_stod.S │ ├── i64_stof.S │ ├── i64_udiv.S │ ├── i64_udivmod.S │ ├── i64_umod.S │ ├── i64_umulh.S │ ├── i64_utod.S │ ├── i64_utof.S │ ├── sysdeps.h │ └── vararg.S └── x86_64 │ ├── i64_dtou.S │ ├── i64_utod.S │ ├── i64_utof.S │ ├── sysdeps.h │ └── vararg.S ├── tools ├── modorder.ml ├── ndfun.ml └── runner.sh ├── x86 ├── Asm.v ├── AsmToJSON.ml ├── AsmToJSON.mli ├── Asmexpand.ml ├── Asmgen.v ├── Asmgenproof.v ├── Asmgenproof1.v ├── Builtins1.v ├── CBuiltins.ml ├── CombineOp.v ├── CombineOpproof.v ├── ConstpropOp.vp ├── ConstpropOpproof.v ├── Conventions1.v ├── Machregs.v ├── Machregsaux.ml ├── Machregsaux.mli ├── NeedOp.v ├── Op.v ├── PrintOp.ml ├── SelectLong.vp ├── SelectLongproof.v ├── SelectOp.vp ├── SelectOpproof.v ├── Stacklayout.v ├── TargetPrinter.ml ├── ValueAOp.v └── extractionMachdep.v ├── x86_32 └── Archi.v └── x86_64 └── Archi.v /.gitattributes: -------------------------------------------------------------------------------- 1 | # Files that should be ignored by Github linguist 2 | /test/** linguist-vendored 3 | /doc/** linguist-documentation 4 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'master' 7 | pull_request: 8 | workflow_dispatch: 9 | 10 | jobs: 11 | linux: 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | target: [aarch64, arm, ppc, riscv, x86_32, x86_64] 16 | env: 17 | target: ${{ matrix.target }} 18 | os: linux 19 | jobs: 4 20 | opamroot: /home/coq/.opam 21 | container: 22 | image: coqorg/coq:8.17.1 23 | options: --user root 24 | steps: 25 | - name: Checkout 26 | uses: actions/checkout@v4 27 | with: 28 | submodules: true 29 | - name: OS dependencies 30 | run: tools/runner.sh system_install 31 | - name: OPAM dependencies 32 | run: tools/runner.sh opam_install menhir 33 | - name: Configure 34 | run: tools/runner.sh configure 35 | - name: Build 36 | run: tools/runner.sh build 37 | - name: Hygiene 38 | run: tools/runner.sh hygiene 39 | - name: Test default configuration 40 | run: tools/runner.sh test1 41 | - name: Test alternate configuration 42 | run: tools/runner.sh test2 43 | - name: Test alternate configuration 2 44 | run: tools/runner.sh test3 45 | macos: 46 | runs-on: macos-latest 47 | env: 48 | target: aarch64 49 | os: macos 50 | jobs: 3 51 | configopts: -ignore-coq-version -ignore-ocaml-version 52 | steps: 53 | - name: Checkout 54 | uses: actions/checkout@v4 55 | with: 56 | submodules: true 57 | - name: OS dependencies 58 | run: | 59 | brew install coq ocaml 60 | brew install --build-from-source menhir # temporary workaround 61 | - name: Configure 62 | run: tools/runner.sh configure 63 | - name: Build 64 | run: tools/runner.sh build 65 | - name: Test default configuration 66 | run: tools/runner.sh test1 67 | - name: Test alternate configuration 68 | run: tools/runner.sh test2 69 | -------------------------------------------------------------------------------- /.github/workflows/latest.yml: -------------------------------------------------------------------------------- 1 | name: Latest 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'master' 7 | workflow_dispatch: 8 | 9 | jobs: 10 | latest: 11 | runs-on: ubuntu-latest 12 | strategy: 13 | matrix: 14 | target: [aarch64, arm, ppc, riscv, x86_32, x86_64] 15 | env: 16 | target: ${{ matrix.target }} 17 | os: linux 18 | jobs: 4 19 | opamroot: /home/rocq/.opam 20 | configopts: -ignore-coq-version 21 | container: 22 | image: rocq/rocq-prover:latest 23 | options: --user root 24 | steps: 25 | - name: Checkout 26 | uses: actions/checkout@v4 27 | with: 28 | submodules: true 29 | - name: OPAM dependencies 30 | run: tools/runner.sh opam_install coq menhir 31 | - name: Configure 32 | run: tools/runner.sh configure 33 | - name: Build 34 | run: tools/runner.sh build_ccomp 35 | - name: Check proof 36 | run: tools/runner.sh check_proof 37 | -------------------------------------------------------------------------------- /.github/workflows/oldest.yml: -------------------------------------------------------------------------------- 1 | name: Oldest 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'master' 7 | workflow_dispatch: 8 | 9 | jobs: 10 | oldest: 11 | runs-on: ubuntu-latest 12 | strategy: 13 | matrix: 14 | target: [aarch64, arm, ppc, riscv, x86_32, x86_64] 15 | env: 16 | target: ${{ matrix.target }} 17 | os: linux 18 | jobs: 4 19 | opamroot: /home/coq/.opam 20 | configopts: -ignore-coq-version 21 | container: 22 | image: coqorg/coq:8.15 23 | options: --user root 24 | steps: 25 | - name: Checkout 26 | uses: actions/checkout@v4 27 | with: 28 | submodules: true 29 | - name: OPAM dependencies 30 | run: tools/runner.sh opam_install menhir=20200624 31 | - name: Configure 32 | run: tools/runner.sh configure 33 | - name: Build 34 | run: tools/runner.sh build_ccomp 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files, in general 2 | *.vo 3 | *.vok 4 | *.vos 5 | *.glob 6 | *.timing 7 | *.prof.json 8 | *.prof.json.gz 9 | *.o 10 | *.a 11 | *.cmi 12 | *.cmo 13 | *.cmx 14 | *.cma 15 | *.cmxa 16 | .*.aux 17 | *.cmti 18 | *.cmt 19 | .coq-native 20 | # Emacs saves 21 | *~ 22 | # Executables and configuration 23 | /ccomp 24 | /ccomp.byte 25 | /ccomp.prof 26 | /clightgen 27 | /clightgen.byte 28 | /tools/ndfun 29 | /tools/modorder 30 | /Makefile.config 31 | /.merlin 32 | /_CoqProject 33 | /compile.pl 34 | # Generated files 35 | /.depend 36 | /.depend.extr 37 | /compcert.ini 38 | /compcert.config 39 | /x86/ConstpropOp.v 40 | /x86/SelectOp.v 41 | /x86/SelectLong.v 42 | /powerpc/ConstpropOp.v 43 | /powerpc/SelectOp.v 44 | /powerpc/SelectLong.v 45 | /arm/ConstpropOp.v 46 | /arm/SelectOp.v 47 | /arm/SelectLong.v 48 | /riscV/ConstpropOp.v 49 | /riscV/SelectOp.v 50 | /riscV/SelectLong.v 51 | /aarch64/ConstpropOp.v 52 | /aarch64/SelectOp.v 53 | /aarch64/SelectLong.v 54 | /backend/SelectDiv.v 55 | /backend/SplitLong.v 56 | /cparser/Parser.v 57 | /cparser/Lexer.ml 58 | /cparser/pre_parser.ml 59 | /cparser/pre_parser.mli 60 | /cparser/pre_parser_messages.ml 61 | /cparser/pre_parser.automaton 62 | /cparser/pre_parser.messages 63 | /cparser/pre_parser.conflicts 64 | /cparser/handcrafted.messages.bak 65 | /cparser/handcrafted.messages.raw 66 | /cparser/deLexer 67 | /cparser/tests/generated/*.c 68 | /cparser/tests/generated/*.err 69 | /lib/Readconfig.ml 70 | /lib/Tokenize.ml 71 | /lib/Responsefile.ml 72 | /driver/Version.ml 73 | # Documentation 74 | /doc/coq2html 75 | /doc/coq2html.ml 76 | /doc/html 77 | /doc/html/ 78 | # MacOS metadata 79 | .DS_Store 80 | # Test generated data 81 | /test/export/clight/*.v 82 | /test/export/csyntax/*.v 83 | # Coq caches 84 | .lia.cache 85 | .nia.cache 86 | .nra.cache 87 | .csdp.cache 88 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "test"] 2 | path = test 3 | url = https://github.com/AbsInt/CompCert-small-tests 4 | -------------------------------------------------------------------------------- /Makefile.menhir: -------------------------------------------------------------------------------- 1 | ####################################################################### 2 | # # 3 | # The Compcert verified compiler # 4 | # # 5 | # François Pottier, INRIA Paris-Rocquencourt # 6 | # # 7 | # Copyright Institut National de Recherche en Informatique et en # 8 | # Automatique. All rights reserved. This file is distributed # 9 | # under the terms of the GNU Lesser General Public License as # 10 | # published by the Free Software Foundation, either version 2.1 of # 11 | # the License, or (at your option) any later version. # 12 | # This file is also distributed under the terms of the # 13 | # INRIA Non-Commercial License Agreement. # 14 | # # 15 | ####################################################################### 16 | 17 | # This is a Makefile fragment for Menhir-specific aspects. 18 | 19 | # Executable. 20 | 21 | MENHIR = menhir 22 | 23 | # This flag can be set to true or false. It controls whether we use 24 | # Menhir's table back-end or code back-end. The table back-end is a 25 | # bit slower, but supports more features, including advanced error 26 | # reporting. 27 | 28 | MENHIR_TABLE = true 29 | 30 | # To pass or not to pass --table. 31 | 32 | ifeq ($(MENHIR_TABLE),true) 33 | MENHIR_MODE = --table 34 | else 35 | MENHIR_MODE = 36 | endif 37 | 38 | # Options. 39 | 40 | MENHIR_FLAGS = -v --no-stdlib -la 1 41 | 42 | # Using Menhir in --table mode requires MenhirLib. 43 | 44 | ifeq ($(MENHIR_TABLE),true) 45 | MENHIR_LIBS = menhirLib.cmxa 46 | else 47 | MENHIR_LIBS = 48 | endif 49 | 50 | # The compilation rule. 51 | 52 | %.ml %.mli: %.mly 53 | $(MENHIR) $(MENHIR_MODE) $(MENHIR_FLAGS) $< 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CompCert 2 | The formally-verified C compiler. 3 | 4 | ## Overview 5 | The CompCert C verified compiler is a compiler for a large subset of the 6 | C programming language that generates code for the PowerPC, ARM, x86 and 7 | RISC-V processors. 8 | 9 | The distinguishing feature of CompCert is that it has been formally 10 | verified using the Coq proof assistant: the generated assembly code is 11 | formally guaranteed to behave as prescribed by the semantics of the 12 | source C code. 13 | 14 | For more information on CompCert (supported platforms, supported C 15 | features, installation instructions, using the compiler, etc), please 16 | refer to the [Web site](https://compcert.org/) and especially 17 | the [user's manual](https://compcert.org/man/). 18 | 19 | ## License 20 | CompCert is not free software. This non-commercial release can only 21 | be used for evaluation, research, educational and personal purposes. 22 | A commercial version of CompCert, without this restriction and with 23 | professional support and extra features, can be purchased from 24 | [AbsInt](https://www.absint.com). See the file `LICENSE` for more 25 | information. 26 | 27 | ## Copyright 28 | The CompCert verified compiler is Copyright Institut National de 29 | Recherche en Informatique et en Automatique (INRIA) and 30 | AbsInt Angewandte Informatik GmbH. 31 | 32 | 33 | ## Contact 34 | General discussions on CompCert take place on the 35 | [compcert-users@inria.fr](https://sympa.inria.fr/sympa/info/compcert-users) 36 | mailing list. 37 | 38 | For inquiries on the commercial version of CompCert, please contact 39 | info@absint.com 40 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | version=3.16 2 | buildnr= 3 | tag= 4 | branch= 5 | -------------------------------------------------------------------------------- /aarch64/AsmToJSON.ml: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, Collège de France and INRIA Paris *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | (* Functions to serialize AArch64 Asm to JSON *) 14 | 15 | (* Dummy function *) 16 | 17 | let destination: string option ref = ref None 18 | 19 | let sdump_folder = ref "" 20 | 21 | let print_if prog sourcename = 22 | () 23 | 24 | let pp_mnemonics pp = () 25 | -------------------------------------------------------------------------------- /aarch64/Builtins1.v: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, Collège de France and Inria Paris *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (** Platform-specific built-in functions *) 18 | 19 | From Coq Require Import String. 20 | Require Import Coqlib AST Integers Floats Values. 21 | Require Import Builtins0. 22 | 23 | Inductive platform_builtin : Type := . 24 | 25 | Local Open Scope string_scope. 26 | 27 | Definition platform_builtin_table : list (string * platform_builtin) := 28 | nil. 29 | 30 | Definition platform_builtin_sig (b: platform_builtin) : signature := 31 | match b with end. 32 | 33 | Definition platform_builtin_sem (b: platform_builtin) : builtin_sem (sig_res (platform_builtin_sig b)) := 34 | match b with end. 35 | 36 | Definition eq_platform_builtin: forall (x y: platform_builtin), {x=y} + {x<>y}. 37 | Proof. 38 | intros. destruct x. 39 | Defined. 40 | -------------------------------------------------------------------------------- /aarch64/Machregsaux.ml: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, Collège de France and INRIA Paris *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | (** Auxiliary functions on machine registers *) 14 | 15 | let is_scratch_register s = 16 | s = "X16" || s = "x16" || s = "X30" || s = "x30" 17 | -------------------------------------------------------------------------------- /aarch64/extractionMachdep.v: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, Collège de France and INRIA Paris *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (* Additional extraction directives specific to the AArch64 port *) 18 | 19 | Require Archi Asm Asmgen SelectOp. 20 | 21 | (* Archi *) 22 | 23 | Extract Constant Archi.abi => 24 | "match Configuration.abi with 25 | | ""apple"" -> Apple 26 | | _ -> AAPCS64". 27 | 28 | (* SelectOp *) 29 | 30 | Extract Constant SelectOp.symbol_is_relocatable => 31 | "match Configuration.system with 32 | | ""macos"" -> C2C.atom_is_external 33 | | _ -> (fun _ -> false)". 34 | 35 | (* Asm *) 36 | 37 | Extract Constant Asm.symbol_low => "fun _ _ _ -> assert false". 38 | Extract Constant Asm.symbol_high => "fun _ _ _ -> assert false". 39 | 40 | (* Asmgen *) 41 | 42 | Extract Constant Asmgen.symbol_is_aligned => "C2C.atom_is_aligned". 43 | -------------------------------------------------------------------------------- /arm/AsmToJSON.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 6 | (* *) 7 | (* AbsInt Angewandte Informatik GmbH. All rights reserved. This file *) 8 | (* is distributed under the terms of the INRIA Non-Commercial *) 9 | (* License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | val pp_mnemonics: Format.formatter -> unit 14 | 15 | val print_if: (Asm.coq_function AST.fundef, 'a) AST.program -> string -> unit 16 | 17 | val destination: string option ref 18 | 19 | val sdump_folder : string ref 20 | -------------------------------------------------------------------------------- /arm/Builtins1.v: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, Collège de France and Inria Paris *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (** Platform-specific built-in functions *) 18 | 19 | From Coq Require Import String. 20 | Require Import Coqlib AST Integers Floats Values. 21 | Require Import Builtins0. 22 | 23 | Inductive platform_builtin : Type := . 24 | 25 | Local Open Scope string_scope. 26 | 27 | Definition platform_builtin_table : list (string * platform_builtin) := 28 | nil. 29 | 30 | Definition platform_builtin_sig (b: platform_builtin) : signature := 31 | match b with end. 32 | 33 | Definition platform_builtin_sem (b: platform_builtin) : builtin_sem (sig_res (platform_builtin_sig b)) := 34 | match b with end. 35 | 36 | Definition eq_platform_builtin: forall (x y: platform_builtin), {x=y} + {x<>y}. 37 | Proof. 38 | intros. destruct x. 39 | Defined. 40 | -------------------------------------------------------------------------------- /arm/CBuiltins.ml: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (* Processor-dependent builtin C functions *) 18 | 19 | open C 20 | 21 | let builtins = { 22 | builtin_typedefs = [ 23 | "__builtin_va_list", TPtr(TVoid [], []) 24 | ]; 25 | builtin_functions = [ 26 | (* Memory accesses *) 27 | "__builtin_read16_reversed", 28 | (TInt(IUShort, []), [TPtr(TInt(IUShort, [AConst]), [])], false); 29 | "__builtin_read32_reversed", 30 | (TInt(IUInt, []), [TPtr(TInt(IUInt, [AConst]), [])], false); 31 | "__builtin_write16_reversed", 32 | (TVoid [], [TPtr(TInt(IUShort, []), []); TInt(IUShort, [])], false); 33 | "__builtin_write32_reversed", 34 | (TVoid [], [TPtr(TInt(IUInt, []), []); TInt(IUInt, [])], false); 35 | (* Synchronization *) 36 | "__builtin_dmb", 37 | (TVoid [], [], false); 38 | "__builtin_dsb", 39 | (TVoid [], [], false); 40 | "__builtin_isb", 41 | (TVoid [], [], false) 42 | ] 43 | } 44 | 45 | let size_va_list = 4 46 | let va_list_scalar = true 47 | 48 | (* Expand memory references inside extended asm statements. Used in C2C. *) 49 | 50 | let asm_mem_argument arg = Printf.sprintf "[%s, #0]" arg 51 | -------------------------------------------------------------------------------- /arm/Machregsaux.ml: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | (** Auxiliary functions on machine registers *) 14 | 15 | let is_scratch_register s = s = "R14" || s = "r14" 16 | -------------------------------------------------------------------------------- /arm/Machregsaux.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | (** Auxiliary functions on machine registers *) 14 | 15 | val is_scratch_register: string -> bool 16 | -------------------------------------------------------------------------------- /arm/SelectLong.vp: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | (** Instruction selection for 64-bit integer operations *) 14 | 15 | Require Import Coqlib. 16 | Require Import Compopts. 17 | Require Import AST Integers Floats. 18 | Require Import Op CminorSel. 19 | Require Import SelectOp SplitLong. 20 | 21 | (** This file is empty because we use the default implementation provided in [SplitLong]. *) 22 | -------------------------------------------------------------------------------- /arm/SelectLongproof.v: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | (** Instruction selection for 64-bit integer operations *) 14 | 15 | From Coq Require Import String. 16 | Require Import Coqlib Maps Integers Floats Errors. 17 | Require Archi. 18 | Require Import AST Values Memory Globalenvs Events. 19 | Require Import Cminor Op CminorSel. 20 | Require Import SelectOp SelectOpproof SplitLong SplitLongproof. 21 | Require Import SelectLong. 22 | 23 | (** This file is empty because we use the default implementation provided in [SplitLong]. *) 24 | -------------------------------------------------------------------------------- /arm/extractionMachdep.v: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (* Additional extraction directives specific to the ARM port *) 18 | 19 | (* Suppression of stupidly big equality functions *) 20 | Extract Constant Asm.ireg_eq => "fun (x: ireg) (y: ireg) -> x = y". 21 | Extract Constant Asm.freg_eq => "fun (x: freg) (y: freg) -> x = y". 22 | Extract Constant Asm.preg_eq => "fun (x: preg) (y: preg) -> x = y". 23 | 24 | (* Choice of calling conventions *) 25 | Extract Constant Archi.abi => 26 | "begin match Configuration.abi with 27 | | ""eabi"" -> Softfloat 28 | | ""hardfloat"" -> Hardfloat 29 | | _ -> assert false 30 | end". 31 | 32 | (* Choice of endianness *) 33 | Extract Constant Archi.big_endian => 34 | "Configuration.is_big_endian". 35 | 36 | (* Whether the model is ARMv6T2 or above and hence supports Thumb2. *) 37 | Extract Constant Archi.thumb2_support => 38 | "(Configuration.model = ""armv6t2"" || Configuration.model >= ""armv7"")". 39 | 40 | (* Whether the model has hardware supports sdiv and udiv *) 41 | Extract Constant Archi.hardware_idiv => 42 | "fun () -> begin match Configuration.model with 43 | | ""armv7r"" | ""armv7m"" -> !Clflags.option_mthumb 44 | | _ -> false 45 | end". 46 | -------------------------------------------------------------------------------- /backend/AisAnnot.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | type t = 14 | | Label of int (** label argument, used for current location*) 15 | | String of string (** text part of the ais annotation *) 16 | | Symbol of AST.ident (** symbol argument, used in variable and function addresses *) 17 | 18 | val add_ais_annot : int -> ('a -> string) -> string -> string -> 'a AST.builtin_arg list -> unit 19 | (** [add_ais_annot lbl preg spreg txt args] adds the ais annotation [txt] were the format 20 | specifiers are replace according to their type: 21 | -e: general expressions 22 | -l: l-value expressions 23 | -here: the address of the ais annotation [lbl] 24 | and [preg] is used to get the names of the registers, as well as [spreg] the name of the 25 | stack pointer and [args] the arguments reference in the replacements 26 | *) 27 | 28 | val get_ais_annots: unit -> (t list) list 29 | (** [get_ais_annots ()] return the list of all ais annotations and reset it *) 30 | 31 | val validate_ais_annot: Env.t -> string * int -> string -> C.exp list -> unit 32 | (** [validate_ais env loc txt args] validates the ais annotation text and arguments, checking 33 | that no volatile variables or float expressions are used as well as that no illegal format 34 | specifier is used in the [txt] 35 | *) 36 | 37 | val json_ais_annot: ('a -> string) -> string -> string -> 'a AST.builtin_arg list -> t list 38 | (** [json_ais_annot lbl preg spreg txt args] prints the ais annotation [txt] were the format 39 | specifiers are replace according to their type: 40 | -e: general expressions 41 | -l: l-value expressions 42 | -here: the address of the ais annotation [lbl] 43 | for json export. 44 | *) 45 | -------------------------------------------------------------------------------- /backend/Asmexpandaux.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 7 | (* *) 8 | (* Copyright Institut National de Recherche en Informatique et en *) 9 | (* Automatique. All rights reserved. This file is distributed *) 10 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 11 | (* *) 12 | (* *********************************************************************) 13 | 14 | open Asm 15 | open AST 16 | open BinNums 17 | 18 | (** Auxiliary functions for builtin expansion *) 19 | 20 | val emit: instruction -> unit 21 | (* Emit an instruction *) 22 | val new_label: unit -> label 23 | (* Compute a fresh label *) 24 | val is_current_function_variadic: unit -> bool 25 | (* Test whether the current function is a variadic function *) 26 | val get_current_function_args: unit -> typ list 27 | (* Get the types of the current function arguments *) 28 | val get_current_function_sig: unit -> signature 29 | (* Get the signature of the current function *) 30 | val set_current_function: coq_function -> unit 31 | (* Set the current function *) 32 | val get_current_function: unit -> coq_function 33 | (* Get the current function *) 34 | val expand: positive -> int -> (preg -> int) -> (instruction -> unit) -> instruction list -> unit 35 | (* Expand the instruction sequence of a function. Takes the function id, the register number of the stackpointer, a 36 | function to get the dwarf mapping of variable names and for the expansion of simple instructions *) 37 | -------------------------------------------------------------------------------- /backend/IRC.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | (* Iterated Register Coalescing: George and Appel's graph coloring algorithm *) 14 | 15 | open Registers 16 | open Locations 17 | open XTL 18 | 19 | (* The abstract type of interference and preference graphs. *) 20 | type graph 21 | 22 | (* Information associated to every variable. *) 23 | type var_stats = { 24 | mutable cost: int; (* estimated cost of a spill *) 25 | mutable usedefs: int (* number of uses and defs *) 26 | } 27 | 28 | (* Create an empty graph. The given function associates statistics to 29 | every variable. *) 30 | val init: (reg -> var_stats) -> graph 31 | 32 | (* Add an interference between two variables. *) 33 | val add_interf: graph -> var -> var -> unit 34 | 35 | (* Add a preference between two variables. *) 36 | val add_pref: graph -> var -> var -> unit 37 | 38 | (* Color the graph. Return an assignment of locations to variables. *) 39 | val coloring: graph -> (var -> loc) 40 | 41 | (* Auxiliaries to deal with register classes *) 42 | val class_of_type: AST.typ -> int 43 | val class_of_loc: loc -> int 44 | -------------------------------------------------------------------------------- /backend/Inliningaux.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | (* Inlining heuristics *) 14 | 15 | type inlining_info 16 | 17 | val inlining_analysis: RTL.program -> inlining_info 18 | 19 | val should_inline: inlining_info -> AST.ident -> RTL.coq_function -> bool 20 | -------------------------------------------------------------------------------- /backend/JsonAST.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 6 | (* *) 7 | (* AbsInt Angewandte Informatik GmbH. All rights reserved. This file *) 8 | (* is distributed under the terms of the INRIA Non-Commercial *) 9 | (* License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | 14 | 15 | val pp_mnemonics : Format.formatter -> string list -> unit 16 | val pp_ast : out_channel -> (out_channel -> Asm.code -> unit) -> (Asm.coq_function AST.fundef, 'a) AST.program -> string -> unit 17 | -------------------------------------------------------------------------------- /backend/Machregsnames.ml: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | let register_names : (Machregs.mreg, string) Hashtbl.t = Hashtbl.create 31 14 | 15 | let _ = 16 | List.iter 17 | (fun (s, r) -> Hashtbl.add register_names r (Camlcoq.camlstring_of_coqstring s)) 18 | Machregs.register_names 19 | 20 | let name_of_register r = 21 | Hashtbl.find_opt register_names r 22 | 23 | let register_by_name s = 24 | Machregs.register_by_name (Camlcoq.coqstring_uppercase_ascii_of_camlstring s) 25 | -------------------------------------------------------------------------------- /backend/Machregsnames.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | (** Auxiliary functions on machine registers *) 14 | 15 | val name_of_register: Machregs.mreg -> string option 16 | val register_by_name: string -> Machregs.mreg option 17 | -------------------------------------------------------------------------------- /backend/PrintAsm.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 7 | (* *) 8 | (* Copyright Institut National de Recherche en Informatique et en *) 9 | (* Automatique. All rights reserved. This file is distributed *) 10 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 11 | (* *) 12 | (* *********************************************************************) 13 | 14 | val print_program: out_channel -> Asm.program -> unit 15 | -------------------------------------------------------------------------------- /coq: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Start rocqide/coqide with the right options 3 | # Use the Makefile to rebuild dependencies if needed 4 | # Recompile the modified file after coqide editing 5 | 6 | make -q ${1}o || { 7 | make -n ${1}o | grep -v "\\b${1}\\b" | \ 8 | (while read cmd; do 9 | sh -c "$cmd" || exit 2 10 | done) 11 | } 12 | 13 | if command -v "${COQBIN}rocqide" >/dev/null 2>&1; then 14 | cmd="${COQBIN}rocqide" 15 | elif command -v "${COQBIN}coqide" >/dev/null 2>&1; then 16 | cmd="${COQBIN}coqide" 17 | else 18 | echo "Cannot find rocqide / coqide" >&2 19 | exit 2 20 | fi 21 | 22 | "$cmd" -async-proofs off $1 && make ${1}o 23 | -------------------------------------------------------------------------------- /cparser/Ceval.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | val integer_expr : Env.t -> C.exp -> int64 option 18 | val constant_expr : Env.t -> C.typ -> C.exp -> C.constant option 19 | val normalize_int : int64 -> C.ikind -> int64 20 | val is_constant_init: Env.t -> C.init -> bool 21 | val is_constant_expr: Env.t -> C.exp -> bool 22 | -------------------------------------------------------------------------------- /cparser/Cflow.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (* A simple control flow analysis for C statements. 18 | Main purpose: emit warnings for _Noreturn functions. *) 19 | 20 | val function_returns: Env.t -> C.stmt -> bool * bool 21 | (** Given a function body, returns two Booleans: 22 | - the first says whether the function can return 23 | - the second says whether the function can return by falling through 24 | the end of its body. 25 | Both are over-approximations. *) 26 | -------------------------------------------------------------------------------- /cparser/Checks.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | val unknown_attrs_program: C.program -> unit 18 | 19 | val unused_variables: C.program -> unit 20 | 21 | val non_linear_conditional : C.program -> unit 22 | -------------------------------------------------------------------------------- /cparser/Cleanup.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | val program : C.program -> C.program 18 | -------------------------------------------------------------------------------- /cparser/Cprint.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | val print_idents_in_full : bool ref 18 | val print_line_numbers : bool ref 19 | val print_debug_idents : bool ref 20 | 21 | val location : Format.formatter -> C.location -> unit 22 | val attributes : Format.formatter -> C.attributes -> unit 23 | val typ : Format.formatter -> C.typ -> unit 24 | val typ_raw : Format.formatter -> C.typ -> unit 25 | val simple_decl : Format.formatter -> C.ident * C.typ -> unit 26 | val full_decl: Format.formatter -> C.decl -> unit 27 | val const : Format.formatter -> C.constant -> unit 28 | val exp : Format.formatter -> int * C.exp -> unit 29 | val opt_exp : Format.formatter -> C.stmt -> unit 30 | val stmt : Format.formatter -> C.stmt -> unit 31 | val fundef : Format.formatter -> C.fundef -> unit 32 | val init : Format.formatter -> C.init -> unit 33 | val storage : Format.formatter -> C.storage -> unit 34 | val field : Format.formatter -> C.field -> unit 35 | val globdecl : Format.formatter -> C.globdecl -> unit 36 | val program : Format.formatter -> C.program -> unit 37 | 38 | val destination : string option ref 39 | val print_if : C.program -> unit 40 | 41 | val name_of_ikind: C.ikind -> string 42 | val name_of_fkind: C.fkind -> string 43 | -------------------------------------------------------------------------------- /cparser/Elab.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | val elab_file : Cabs.definition list -> C.program 18 | (* This is the main entry point. It transforms a list of toplevel 19 | definitions as produced by the parser into a program in C abstract 20 | syntax. *) 21 | 22 | val elab_int_constant : Cabs.loc -> string -> int64 * C.ikind 23 | val elab_float_constant : Cabs.floatInfo -> C.float_cst * C.fkind 24 | val elab_char_constant : Cabs.loc -> Cabs.encoding -> int64 list -> int64 * C.ikind 25 | (* These auxiliary functions are exported so that they can be reused 26 | in other projects that deal with C-style source languages. *) 27 | -------------------------------------------------------------------------------- /cparser/ErrorReports.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* François Pottier, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (* This module is in charge of reporting a syntax error after the pre_parser 18 | has failed. *) 19 | 20 | open Pre_parser.MenhirInterpreter 21 | 22 | (* The parser keeps track of the last two tokens in a two-place buffer. *) 23 | 24 | type 'a buffer = 25 | | Zero 26 | | One of 'a 27 | | Two of 'a * (* most recent: *) 'a 28 | 29 | (* [update buffer x] pushes [x] into [buffer], causing the buffer to slide. *) 30 | 31 | val update: 'a buffer -> 'a -> 'a buffer 32 | 33 | (* [report text buffer checkpoint] constructs an error message. The C source 34 | code must be stored in the string [text]. The start and end positions of the 35 | last two tokens that were read must be stored in [buffer]. The parser state 36 | (i.e., the automaton's state and stack) must be recorded in the checkpoint 37 | [checkpoint]. *) 38 | 39 | val report: 40 | string -> 41 | (Lexing.position * Lexing.position) buffer -> 42 | _ checkpoint -> 43 | string 44 | -------------------------------------------------------------------------------- /cparser/GCC.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (* GCC built-ins and attributes *) 18 | 19 | val builtins: Builtins.t 20 | val attributes: (string * Cutil.attribute_class) list 21 | -------------------------------------------------------------------------------- /cparser/Parse.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (* Entry point for the library: parse, elaborate, and transform *) 18 | 19 | val preprocessed_file: 20 | ?unblock: bool -> 21 | ?switch_norm: [`Off | `Partial | `Full] -> 22 | ?struct_passing: bool -> 23 | ?packed_structs: bool -> 24 | string -> string -> C.program 25 | (** [preprocessed_file filename sourcetext] performs parsing, 26 | elaboration, and optional source-to-source transformations. 27 | [filename] is the name of the source file, for error messages. 28 | [sourcetext] is the text of the source file after preprocessing. 29 | The optional arguments indicate which source-to-source 30 | transformations to perform. They default to [false] or [`Off] 31 | (do not perform). *) 32 | -------------------------------------------------------------------------------- /cparser/Rename.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | val program : C.program -> C.program 18 | -------------------------------------------------------------------------------- /cparser/StructPassing.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | val program: C.program -> C.program 18 | -------------------------------------------------------------------------------- /cparser/SwitchNorm.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, Collège de France and Inria *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (* Normalization of structured "switch" statements 18 | and emulation of unstructured "switch" statements (e.g. Duff's device) *) 19 | 20 | (* Assumes: nothing 21 | Produces: code with normalized "switch" statements *) 22 | 23 | (* A normalized switch has the following form: 24 | Sswitch(e, Sblock [ Slabeled(lbl1, case1); ... 25 | Slabeled(lblN,caseN) ]) 26 | *) 27 | 28 | val program: bool -> C.program -> C.program 29 | -------------------------------------------------------------------------------- /cparser/Unblock.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (* Simplification of blocks and initializers within functions *) 18 | 19 | val program: C.program -> C.program 20 | -------------------------------------------------------------------------------- /cparser/pre_parser_aux.ml: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Jacques-Henri Jourdan, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | type identifier_type = 18 | | VarId 19 | | TypedefId 20 | | OtherId 21 | 22 | let save_context:(unit -> (unit -> unit)) ref = ref (fun _ -> assert false) 23 | let declare_varname:(string -> unit) ref = ref (fun _ -> assert false) 24 | let declare_typename:(string -> unit) ref = ref (fun _ -> assert false) 25 | -------------------------------------------------------------------------------- /cparser/pre_parser_aux.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Jacques-Henri Jourdan, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | type identifier_type = 18 | | VarId 19 | | TypedefId 20 | | OtherId 21 | 22 | (* Applying once this functions saves the current context, and 23 | applying it the second time restores it. *) 24 | val save_context : (unit -> (unit -> unit)) ref 25 | 26 | (* Change the context by changing an identifier to be a varname or a 27 | typename *) 28 | val declare_varname : (string -> unit) ref 29 | val declare_typename : (string -> unit) ref 30 | -------------------------------------------------------------------------------- /cparser/tests/generated/Makefile: -------------------------------------------------------------------------------- 1 | ####################################################################### 2 | # # 3 | # The Compcert verified compiler # 4 | # # 5 | # François Pottier, INRIA Paris-Rocquencourt # 6 | # # 7 | # Copyright Institut National de Recherche en Informatique et en # 8 | # Automatique. All rights reserved. This file is distributed # 9 | # under the terms of the INRIA Non-Commercial License Agreement. # 10 | # # 11 | ####################################################################### 12 | 13 | .PHONY: all clean 14 | 15 | SOURCES := $(wildcard *.c) 16 | TARGETS := \ 17 | $(patsubst %.c,%.ccomp.err,$(SOURCES)) \ 18 | $(patsubst %.c,%.gcc.err,$(SOURCES)) \ 19 | $(patsubst %.c,%.clang.err,$(SOURCES)) 20 | 21 | CCOMP := ../../../ccomp 22 | GCC := gcc 23 | CLANG := clang 24 | 25 | all: $(TARGETS) 26 | 27 | clean: 28 | @ rm -f *.err *~ 29 | 30 | %.ccomp.err: %.c $(CCOMP) 31 | @ echo $(CCOMP) -c $< 32 | @ if $(CCOMP) -c $< 2>$@ ; then \ 33 | echo "UNEXPECTED SUCCESS: $(CCOMP) -c $< SUCCEEDED!" ; \ 34 | fi 35 | @ if grep "unknown syntax error" $@ ; then \ 36 | echo "UNKNOWN SYNTAX ERROR!" ; \ 37 | fi 38 | 39 | %.gcc.err: %.c 40 | @ echo $(GCC) -c $< 41 | @ if $(GCC) -c $< 2>$@ ; then \ 42 | echo "UNEXPECTED SUCCESS: $(GCC) -c $< SUCCEEDED!" ; \ 43 | fi 44 | 45 | %.clang.err: %.c 46 | @ echo $(CLANG) -c $< 47 | @ if $(CLANG) -c $< 2>$@ ; then \ 48 | echo "UNEXPECTED SUCCESS: $(CLANG) -c $< SUCCEEDED!" ; \ 49 | fi 50 | 51 | -------------------------------------------------------------------------------- /cparser/tests/handwritten/conditional-0.c: -------------------------------------------------------------------------------- 1 | int main (int x, int y) 2 | { 3 | return x == 0 ? x : y == 0 : y; 4 | } 5 | -------------------------------------------------------------------------------- /cparser/tests/handwritten/conditional-1.c: -------------------------------------------------------------------------------- 1 | int main (int x, int y) 2 | { 3 | return x == 0 ? x : y == 0 ? y; 4 | } 5 | -------------------------------------------------------------------------------- /cparser/tests/handwritten/dubious-enum.c: -------------------------------------------------------------------------------- 1 | int f (void) 2 | { 3 | int x = sizeof(enum e; 4 | /* Maybe a closing parenthesis is missing, 5 | maybe also "enum e" could be continued with an opening brace. 6 | Our message ignores the latter possibility. */ 7 | } 8 | -------------------------------------------------------------------------------- /cparser/tests/handwritten/missing-assignment.c: -------------------------------------------------------------------------------- 1 | int main (void) 2 | { 3 | int x = 10, y 8; 4 | } 5 | -------------------------------------------------------------------------------- /cparser/tests/handwritten/missing-closing-brace-at-end-of-function.c: -------------------------------------------------------------------------------- 1 | int main (void) 2 | { 3 | int x = 0; 4 | x++; 5 | /* missing closing brace, here */ 6 | /* unfortunately, the error is detected only after the declaration of f */ 7 | 8 | void f (void) 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /cparser/tests/handwritten/missing-loop-body.c: -------------------------------------------------------------------------------- 1 | int main (void) 2 | { 3 | int x = 10; 4 | while (x--) /* missing loop body */ 5 | } 6 | -------------------------------------------------------------------------------- /cparser/tests/handwritten/missing-operator.c: -------------------------------------------------------------------------------- 1 | int main (void) 2 | { 3 | int y = 7, z = 8; 4 | int x = (3 * (2 x) - y * y); 5 | } 6 | -------------------------------------------------------------------------------- /cparser/tests/handwritten/missing-semicolon.c: -------------------------------------------------------------------------------- 1 | int main (void) 2 | { 3 | int y = 7, z = 8 4 | int x = (3 * (2 + x) - y * y); 5 | } 6 | -------------------------------------------------------------------------------- /cparser/tests/handwritten/too-many-closing-parens.c: -------------------------------------------------------------------------------- 1 | int main (void) 2 | { 3 | int x = main()); 4 | } 5 | -------------------------------------------------------------------------------- /cparser/tests/handwritten/unclosed-paren.c: -------------------------------------------------------------------------------- 1 | int main (void) 2 | { 3 | int y = 7; 4 | int x = (3 * (2 + x) - y * y; 5 | } 6 | -------------------------------------------------------------------------------- /cparser/tests/handwritten/variable-type-confusion.c: -------------------------------------------------------------------------------- 1 | typedef int t; 2 | typedef int u; 3 | int f (void) { 4 | t = 3; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /debug/DebugInformation.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 6 | (* *) 7 | (* AbsInt Angewandte Informatik GmbH. All rights reserved. This file *) 8 | (* is distributed under the terms of the INRIA Non-Commercial *) 9 | (* License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | open BinNums 14 | open Camlcoq 15 | open DebugTypes 16 | open Sections 17 | 18 | val typ_to_string: C.typ -> string 19 | 20 | val next_id: unit -> int 21 | 22 | val get_type: int -> debug_types 23 | 24 | val fold_types: (int -> debug_types -> 'a -> 'a) -> 'a -> 'a 25 | 26 | val is_symbol_printed: string -> bool 27 | 28 | val variable_location: atom -> atom -> var_location 29 | 30 | val translate_label: atom -> positive -> int 31 | 32 | val get_scope_ranges: int -> scope_range list 33 | 34 | val get_local_variable: int -> local_information 35 | 36 | val diab_file_loc: string -> string -> int 37 | 38 | val section_start: string -> int 39 | 40 | val fold_section_start: (string -> int -> 'a -> 'a) -> 'a -> 'a 41 | 42 | val section_end: string -> int 43 | 44 | val diab_additional_section: string -> int * int 45 | 46 | val file_name: string ref 47 | 48 | val fold_definitions: (int -> definition_type -> 'a -> 'a) -> 'a -> 'a 49 | 50 | val diab_add_fun_addr: atom -> section_name -> (int * int) -> unit 51 | 52 | val gnu_add_fun_addr: atom -> section_name -> (int * int) -> unit 53 | 54 | val add_diab_info: section_name -> int -> int -> int -> unit 55 | 56 | val default_debug: Debug.implem 57 | -------------------------------------------------------------------------------- /debug/DwarfPrinter.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 6 | (* *) 7 | (* AbsInt Angewandte Informatik GmbH. All rights reserved. This file *) 8 | (* is distributed under the terms of the INRIA Non-Commercial *) 9 | (* License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | open DwarfTypes 14 | 15 | module DwarfPrinter: DWARF_TARGET -> 16 | sig 17 | val print_debug: out_channel -> debug_entries -> unit 18 | end 19 | -------------------------------------------------------------------------------- /doc/style.css: -------------------------------------------------------------------------------- 1 | a:visited {color : #416DFF; text-decoration : none; } 2 | a:link {color : #416DFF; text-decoration : none; font-weight : bold} 3 | a:hover {color : Red; text-decoration : underline; } 4 | a:active {color : Red; text-decoration : underline; } 5 | .keyword { font-weight : bold ; color : Red } 6 | .keywordsign { color : #C04600 } 7 | .superscript { font-size : 4 } 8 | .subscript { font-size : 4 } 9 | .comment { color : Green } 10 | .constructor { color : Blue } 11 | .string { color : Maroon } 12 | .warning { color : Red ; font-weight : bold } 13 | .info { margin-left : 3em; margin-right : 3em } 14 | #.title1 { font-size : 20pt ; background-color : #416DFF } 15 | #.title2 { font-size : 20pt ; background-color : #418DFF } 16 | #.title3 { font-size : 20pt ; background-color : #41ADFF } 17 | #.title4 { font-size : 20pt ; background-color : #41CDFF } 18 | #.title5 { font-size : 20pt ; background-color : #41EDFF } 19 | #.title6 { font-size : 20pt ; background-color : #41FFFF } 20 | body { 21 | color: black; background: white; 22 | margin-left: 10%; margin-right: 5%; 23 | } 24 | tr { background-color : White } 25 | # .doc { background-color :#aaeeff } 26 | # .doc { background-color :#66ff66 } 27 | .doc { margin-left: -5%; } 28 | .docright { margin-left: 40%; } 29 | div.doc code { color : #008000; font-weight: bold } 30 | h1.libtitle { text-align: center; } 31 | h1 { margin-left: -5%; } 32 | h2 { margin-left: -5%; } 33 | h3,h4,h5,h6 { margin-left: -3%; } 34 | hr { margin-left: -10%; margin-right:-10%; } 35 | -------------------------------------------------------------------------------- /driver/Assembler.ml: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 7 | (* *) 8 | (* Copyright Institut National de Recherche en Informatique et en *) 9 | (* Automatique. All rights reserved. This file is distributed *) 10 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 11 | (* *) 12 | (* *********************************************************************) 13 | 14 | open Clflags 15 | open Commandline 16 | open Driveraux 17 | 18 | (* From asm to object file *) 19 | 20 | let assemble ifile ofile = 21 | Diagnostics.raise_on_errors (); 22 | let cmd = List.concat [ 23 | Configuration.asm; 24 | ["-o"; ofile]; 25 | List.rev !assembler_options; 26 | [ifile] 27 | ] in 28 | let exc = command cmd in 29 | if exc <> 0 then begin 30 | safe_remove ofile; 31 | command_error "assembler" exc 32 | end 33 | 34 | let assembler_actions = 35 | [ Prefix "-Wa,", Self (fun s -> if Configuration.gnu_toolchain then 36 | assembler_options := s :: !assembler_options 37 | else 38 | assembler_options := List.rev_append (explode_comma_option s) !assembler_options); 39 | Exact "-Xassembler", String (fun s -> if Configuration.gnu_toolchain then 40 | assembler_options := s::"-Xassembler":: !assembler_options 41 | else 42 | assembler_options := s::!assembler_options );] 43 | 44 | let assembler_help = 45 | {|Assembling options: 46 | -Wa, Pass option to the assembler 47 | -Xassembler Pass as an option to the assembler 48 | |} 49 | -------------------------------------------------------------------------------- /driver/Assembler.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 7 | (* *) 8 | (* Copyright Institut National de Recherche en Informatique et en *) 9 | (* Automatique. All rights reserved. This file is distributed *) 10 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 11 | (* *) 12 | (* *********************************************************************) 13 | 14 | val assemble: string -> string -> unit 15 | (** From asm to object file *) 16 | 17 | val assembler_actions: (Commandline.pattern * Commandline.action) list 18 | (** Commandline options affecting the assembler *) 19 | 20 | val assembler_help: string 21 | (** Commandline help description *) 22 | -------------------------------------------------------------------------------- /driver/Compopts.v: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | (** Compilation options *) 14 | 15 | (** This file collects Coq functions to query the command-line 16 | options that influence the code generated by the verified 17 | part of CompCert. These functions are mapped by extraction 18 | to accessors for the flags in [Clflags.ml]. *) 19 | 20 | (** Flag [-Os]. For instruction selection (mainly). *) 21 | Parameter optim_for_size: unit -> bool. 22 | 23 | (** Flag [-ffloat-const-prop]. For value analysis and constant propagation. *) 24 | Parameter propagate_float_constants: unit -> bool. 25 | Parameter generate_float_constants: unit -> bool. 26 | 27 | (** For value analysis. Currently always false. *) 28 | Parameter va_strict: unit -> bool. 29 | 30 | (** Flag -ftailcalls. For tail call optimization. *) 31 | Parameter optim_tailcalls: unit -> bool. 32 | 33 | (** Flag -fconstprop. For constant propagation. *) 34 | Parameter optim_constprop: unit -> bool. 35 | 36 | (** Flag -fcse. For common subexpression elimination. *) 37 | Parameter optim_CSE: unit -> bool. 38 | 39 | (** Flag -fredundancy. For dead code elimination. *) 40 | Parameter optim_redundancy: unit -> bool. 41 | 42 | (** Flag -fthumb. For the ARM back-end. *) 43 | Parameter thumb: unit -> bool. 44 | 45 | (** Flag -g. For insertion of debugging information. *) 46 | Parameter debug: unit -> bool. 47 | -------------------------------------------------------------------------------- /driver/Configuration.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 6 | (* *) 7 | (* AbsInt Angewandte Informatik GmbH. All rights reserved. This file *) 8 | (* is distributed under the terms of the INRIA Non-Commercial *) 9 | (* License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | val arch: string 14 | (** Target architecture *) 15 | 16 | val model: string 17 | (** Sub-model for this architecture *) 18 | 19 | val abi: string 20 | (** ABI to use *) 21 | 22 | val is_big_endian: bool 23 | (** Endianness to use *) 24 | 25 | val system: string 26 | (** Flavor of operating system that runs CompCert *) 27 | 28 | val prepro: string list 29 | (** How to invoke the external preprocessor *) 30 | 31 | val asm: string list 32 | (** How to invoke the external assembler *) 33 | 34 | val linker: string list 35 | (** How to invoke the external linker *) 36 | 37 | val asm_supports_cfi: bool 38 | (** True if the assembler supports Call Frame Information *) 39 | 40 | val stdlib_path: string 41 | (** Path to CompCert's library *) 42 | 43 | val has_runtime_lib: bool 44 | (** True if CompCert's library is available. *) 45 | 46 | val has_standard_headers: bool 47 | (** True if CompCert's standard header files is available. *) 48 | 49 | type response_file_style = 50 | | Gnu (* responsefiles in gnu compatible syntax *) 51 | | Diab (* responsefiles in diab compatible syntax *) 52 | | Unsupported (* responsefiles are not supported *) 53 | 54 | val response_file_style: response_file_style 55 | (** Style of supported responsefiles *) 56 | 57 | val gnu_toolchain: bool 58 | (** Does the targeted system use the gnu toolchain *) 59 | 60 | val elf_target: bool 61 | (** Is the target binary format ELF? *) 62 | -------------------------------------------------------------------------------- /driver/Driveraux.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 7 | (* *) 8 | (* Copyright Institut National de Recherche en Informatique et en *) 9 | (* Automatique. All rights reserved. This file is distributed *) 10 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 11 | (* *) 12 | (* *********************************************************************) 13 | 14 | 15 | val command: ?stdout:string -> string list -> int 16 | (** Execute the command with the given arguments and an optional file for 17 | the stdout. Returns the exit code. *) 18 | 19 | val command_error: string -> int -> 'a 20 | (** Generate an error message for the given command and exit code *) 21 | 22 | val safe_remove: string -> unit 23 | (** Remove the given file if it exists *) 24 | 25 | val tmp_file: string -> string 26 | (** Create a temporary file with the given suffix. 27 | The file will be removed when the program exits. 28 | Return the absolute path to the file. *) 29 | 30 | val output_filename: ?final:bool -> string -> suffix:string -> string 31 | (** Determine names for output files. We use -o option if specified 32 | and if this is the final destination file (not a dump file). 33 | Otherwise, we generate a file in the current directory. *) 34 | 35 | val output_filename_default: string -> string 36 | (** Return either the file specified by -o or the given file name *) 37 | 38 | val ensure_inputfile_exists: string -> unit 39 | (** Test whether the given input file exists *) 40 | 41 | val print_error:Format.formatter -> Errors.errcode list -> unit 42 | (** Printing of error messages *) 43 | 44 | val explode_comma_option: string -> string list 45 | (** Split option at commas *) 46 | 47 | val push_action: (string -> string) -> string -> unit 48 | (** Add an action to be performed after parsing the command line *) 49 | 50 | val push_linker_arg: string -> unit 51 | (** Add a linker arguments *) 52 | 53 | val perform_actions: unit -> string list 54 | (** Perform actions *) 55 | -------------------------------------------------------------------------------- /driver/Frontend.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 7 | (* *) 8 | (* Copyright Institut National de Recherche en Informatique et en *) 9 | (* Automatique. All rights reserved. This file is distributed *) 10 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 11 | (* *) 12 | (* *********************************************************************) 13 | 14 | val preprocess: string -> string -> unit 15 | (** From C to preprocessed C *) 16 | 17 | val parse_c_file: string -> string -> Csyntax.coq_function Ctypes.program 18 | (** From preprocessed C to Csyntax *) 19 | 20 | val prepro_actions: (Commandline.pattern * Commandline.action) list 21 | (** Commandline options affecting the frontend *) 22 | 23 | val prepro_help: string 24 | (** Commandline help description *) 25 | 26 | val init: unit -> unit 27 | (** Initialize the Frontend *) 28 | -------------------------------------------------------------------------------- /driver/Linker.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 7 | (* *) 8 | (* Copyright Institut National de Recherche en Informatique et en *) 9 | (* Automatique. All rights reserved. This file is distributed *) 10 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 11 | (* *) 12 | (* *********************************************************************) 13 | 14 | val linker: string -> string list -> unit 15 | (** Link files into executable *) 16 | 17 | val linker_actions: (Commandline.pattern * Commandline.action) list 18 | (** Commandline options affecting the assembler *) 19 | 20 | val linker_help: string 21 | (** Commandline help description *) 22 | -------------------------------------------------------------------------------- /driver/Timing.ml: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | open Clflags 14 | 15 | (** Timing facility *) 16 | 17 | let timers : (string * float) list ref = ref [] 18 | 19 | let add_to_timer name time = 20 | let rec add = function 21 | | [] -> [name, time] 22 | | (name1, time1 as nt1) :: rem -> 23 | if name1 = name then (name1, time1 +. time) :: rem else nt1 :: add rem 24 | in timers := add !timers 25 | 26 | let time name fn arg = 27 | if not !option_timings then 28 | fn arg 29 | else begin 30 | let start = Sys.time() in 31 | try 32 | let res = fn arg in 33 | add_to_timer name (Sys.time() -. start); 34 | res 35 | with x -> 36 | add_to_timer name (Sys.time() -. start); 37 | raise x 38 | end 39 | 40 | let time2 name fn arg1 arg2 = time name (fun () -> fn arg1 arg2) () 41 | let time3 name fn arg1 arg2 arg3 = time name (fun () -> fn arg1 arg2 arg3) () 42 | 43 | let time_coq name fn arg = 44 | if not !option_timings then 45 | fn arg 46 | else begin 47 | let start = Sys.time() in 48 | try 49 | let res = fn arg in 50 | add_to_timer (Camlcoq.camlstring_of_coqstring name) (Sys.time() -. start); 51 | res 52 | with x -> 53 | add_to_timer (Camlcoq.camlstring_of_coqstring name) (Sys.time() -. start); 54 | raise x 55 | end 56 | 57 | let print_timers () = 58 | if !option_timings then 59 | List.iter 60 | (fun (name, time) -> Printf.printf "%7.2fs %s\n" time name) 61 | !timers 62 | 63 | let _ = at_exit print_timers 64 | -------------------------------------------------------------------------------- /export/README.md: -------------------------------------------------------------------------------- 1 | # The clightgen tool 2 | 3 | ## Overview 4 | 5 | `clightgen` is an experimental tool that transforms C source files 6 | into Clight abstract syntax or Csyntax abstract syntax, pretty-printed 7 | in Coq format inside `.v` files. 8 | 9 | These generated `.v` files can be loaded in a Coq session for 10 | interactive verification, for example using the 11 | [VST](https://vst.cs.princeton.edu/) toolchain. 12 | 13 | ## How to build 14 | 15 | Configure CompCert with `./configure -clightgen`. 16 | 17 | Build CompCert as usual. 18 | 19 | The `clightgen` tool will be installed in the same directory as the 20 | `ccomp` compiler. 21 | 22 | ## Usage 23 | ``` 24 | clightgen [options] 25 | ``` 26 | For each source file `src.c`, its Clight abstract syntax is generated 27 | in `src.v`. 28 | 29 | Run `clightgen -help` for a list of options. 30 | 31 | Several options are shared with the `ccomp` compiler; 32 | see [user's manual](http://compcert.inria.fr/man/manual003.html) 33 | for full documentation). 34 | -------------------------------------------------------------------------------- /extraction/.gitignore: -------------------------------------------------------------------------------- 1 | # Caml files generated by extraction 2 | *.mli 3 | *.ml 4 | # Extraction timestamp 5 | STAMP 6 | -------------------------------------------------------------------------------- /flocq/Core/Core.v: -------------------------------------------------------------------------------- 1 | (** 2 | This file is part of the Flocq formalization of floating-point 3 | arithmetic in Coq: https://flocq.gitlabpages.inria.fr/ 4 | 5 | Copyright (C) 2010-2018 Sylvie Boldo 6 | #
# 7 | Copyright (C) 2010-2018 Guillaume Melquiond 8 | 9 | This library is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 3 of the License, or (at your option) any later version. 13 | 14 | This library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | COPYING file for more details. 18 | *) 19 | 20 | (** To ease the import *) 21 | Require Export Zaux Raux Defs Digits Float_prop Round_pred Generic_fmt Round_NE FIX FLX FLT Ulp. 22 | -------------------------------------------------------------------------------- /flocq/Version.v: -------------------------------------------------------------------------------- 1 | (** 2 | This file is part of the Flocq formalization of floating-point 3 | arithmetic in Coq: https://flocq.gitlabpages.inria.fr/ 4 | 5 | Copyright (C) 2011-2018 Sylvie Boldo 6 | #
# 7 | Copyright (C) 2011-2018 Guillaume Melquiond 8 | 9 | This library is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 3 of the License, or (at your option) any later version. 13 | 14 | This library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | COPYING file for more details. 18 | *) 19 | 20 | (** Helper for detecting the version of Flocq *) 21 | Require Import BinNat. 22 | Require Import Ascii String. 23 | 24 | Definition Flocq_version := Eval vm_compute in 25 | let fix parse s major minor := 26 | match s with 27 | | String "."%char t => parse t (major * 100 + minor)%N N0 28 | | String h t => 29 | parse t major (minor * 10 + N_of_ascii h - N_of_ascii "0"%char)%N 30 | | EmptyString => (major * 100 + minor)%N 31 | end in 32 | parse "4.2.1"%string N0 N0. 33 | -------------------------------------------------------------------------------- /lib/Axioms.v: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (** This file collects some axioms used throughout the CompCert development. *) 18 | 19 | From Coq Require ClassicalFacts FunctionalExtensionality. 20 | 21 | (** * Extensionality axioms *) 22 | 23 | (** The [Require FunctionalExtensionality] gives us functional 24 | extensionality for dependent function types: *) 25 | 26 | Lemma functional_extensionality_dep: 27 | forall {A: Type} {B : A -> Type} (f g : forall x : A, B x), 28 | (forall x, f x = g x) -> f = g. 29 | Proof @FunctionalExtensionality.functional_extensionality_dep. 30 | 31 | (** and, as a corollary, functional extensionality for non-dependent functions: 32 | *) 33 | 34 | Lemma functional_extensionality: 35 | forall {A B: Type} (f g : A -> B), (forall x, f x = g x) -> f = g. 36 | Proof @FunctionalExtensionality.functional_extensionality. 37 | 38 | (** For compatibility with earlier developments, [extensionality] 39 | is an alias for [functional_extensionality]. *) 40 | 41 | Lemma extensionality: 42 | forall {A B: Type} (f g : A -> B), (forall x, f x = g x) -> f = g. 43 | Proof @functional_extensionality. 44 | 45 | (** * Proof irrelevance *) 46 | 47 | (** We also use proof irrelevance. *) 48 | 49 | Axiom proof_irr: ClassicalFacts.proof_irrelevance. 50 | 51 | Arguments proof_irr [A]. 52 | -------------------------------------------------------------------------------- /lib/Printlines.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (** Print lines from a file *) 18 | 19 | type filebuf 20 | (** The type of buffers on opened files *) 21 | 22 | val openfile: string -> filebuf 23 | (** Open the file with the given name. *) 24 | 25 | val close: filebuf -> unit 26 | (** Close the file underlying the given buffer. *) 27 | 28 | val copy: out_channel -> string -> filebuf -> int -> int -> unit 29 | (** [copy oc pref buf first last] copies lines number [first] 30 | to [last], included, to the channel [oc]. Each line is 31 | prefixed by [pref]. *) 32 | -------------------------------------------------------------------------------- /lib/Readconfig.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (* Reading configuration files *) 18 | 19 | (* The format of a configuration file is a list of lines 20 | variable=value 21 | The "value" on the right hand side is a list of whitespace-separated 22 | words. Quoting is honored with the same rules as POSIX shell: 23 | \ for multi-line values 24 | single quotes no escapes within 25 | double quotes \$ \` \ \\ \ as escapes 26 | Finally, lines starting with '#' are comments. 27 | *) 28 | 29 | val read_config_file: string -> unit 30 | (** Read (key, value) pairs from the given file name. Raise [Error] 31 | if file is ill-formed. *) 32 | 33 | val key_val: string -> string list option 34 | (** [key_val k] returns the value associated with key [k], if any. 35 | Otherwise, [None] is returned. *) 36 | 37 | exception Error of string * int * string 38 | (** Raised in case of error. 39 | First argument is file name, second argument is line number, 40 | third argument is an explanation of the error. *) 41 | -------------------------------------------------------------------------------- /lib/Responsefile.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 7 | (* *) 8 | (* Copyright Institut National de Recherche en Informatique et en *) 9 | (* Automatique. All rights reserved. This file is distributed *) 10 | (* under the terms of the GNU Lesser General Public License as *) 11 | (* published by the Free Software Foundation, either version 2.1 of *) 12 | (* the License, or (at your option) any later version. *) 13 | (* This file is also distributed under the terms of the *) 14 | (* INRIA Non-Commercial License Agreement. *) 15 | (* *) 16 | (* *********************************************************************) 17 | 18 | 19 | val expandargv: string array -> string array 20 | (** Expand responsefile arguments contained in the array and return the full 21 | set of arguments. *) 22 | 23 | exception Error of string 24 | (** Raised by [expandargv] in case of an error *) 25 | 26 | val gnu_quote : string -> string 27 | (** [gnu_quote arg] returns [arg] quoted compatible with the gnu tool chain 28 | quoting conventions. *) 29 | 30 | val diab_quote : string -> string 31 | (** [diab_quote arg] returns [arg] quoted compatible with the diab tool chain 32 | quoting conventions. *) 33 | -------------------------------------------------------------------------------- /lib/Tokenize.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (* Parse a string as a list of tokens *) 18 | 19 | val string: string -> string list 20 | (** [Tokenize.string s] decomposes [s] into a list of tokens. 21 | Whitespace separates tokens. The following substrings 22 | constitute tokens: 23 | - A string enclosed in double quotes. Within the string, 24 | the escape sequences '\t' '\n' '\"' and '\\' are recognized. 25 | The token value is the contents of the string without the 26 | enclosing double quotes. 27 | - A string enclosed in single quotes. No escape sequences are 28 | recognized. The token value is the contents of the string without the 29 | enclosing single quotes. 30 | - A sequence of letters, digits, or the [_], [$], [-] and [.] 31 | characters. [-] and [.] cannot appear as the first character. 32 | - Any other non-whitespace character is treated as a separate token 33 | of length 1. 34 | *) 35 | -------------------------------------------------------------------------------- /lib/Tokenize.mll: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (* Parse a string as a list of tokens *) 18 | 19 | let identstart = [ '0'-'9' 'A'-'Z' 'a'-'z' '$' '_' ] 20 | let identcont = [ '0'-'9' 'A'-'Z' 'a'-'z' '$' '_' '-' '.' ] 21 | 22 | rule tokenize acc = parse 23 | | eof { List.rev acc } 24 | | [' ' '\t' '\n' '\r'] + { tokenize acc lexbuf } 25 | | "\"" { tok_dquote acc (Buffer.create 16) lexbuf } 26 | | "'" { tok_squote acc (Buffer.create 16) lexbuf } 27 | | (identstart identcont*) as s 28 | { tokenize (s :: acc) lexbuf } 29 | | _ as c { tokenize (String.make 1 c :: acc) lexbuf } 30 | 31 | and tok_dquote acc buf = parse 32 | | "\"" | eof { tokenize (Buffer.contents buf :: acc) lexbuf } 33 | | "\\t" { Buffer.add_char buf '\t'; tok_dquote acc buf lexbuf } 34 | | "\\n" { Buffer.add_char buf '\n'; tok_dquote acc buf lexbuf } 35 | | "\\r" { Buffer.add_char buf '\r'; tok_dquote acc buf lexbuf } 36 | | "\\" ([ '\\' '\"' ] as c) 37 | { Buffer.add_char buf c; tok_dquote acc buf lexbuf } 38 | | _ as c { Buffer.add_char buf c; tok_dquote acc buf lexbuf } 39 | 40 | and tok_squote acc buf = parse 41 | | "\'" | eof { tokenize (Buffer.contents buf :: acc) lexbuf } 42 | | _ as c { Buffer.add_char buf c; tok_squote acc buf lexbuf } 43 | 44 | { 45 | let string s = 46 | tokenize [] (Lexing.from_string s) 47 | } 48 | -------------------------------------------------------------------------------- /pg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Start Proof General with the right Coq version 3 | # Use the Makefile to rebuild dependencies if needed 4 | # Recompile the modified file after editing 5 | 6 | make -q ${1}o || { 7 | make -n ${1}o | grep -v "\\b${1}\\b" | \ 8 | (while read cmd; do 9 | sh -c "$cmd" || exit 2 10 | done) 11 | } 12 | 13 | COQPROGNAME="${COQBIN}coqtop" 14 | 15 | emacs --eval "(setq coq-prog-name \"$COQPROGNAME\")" $1 \ 16 | && make ${1}o 17 | -------------------------------------------------------------------------------- /powerpc/AsmToJSON.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 6 | (* *) 7 | (* AbsInt Angewandte Informatik GmbH. All rights reserved. This file *) 8 | (* is distributed under the terms of the INRIA Non-Commercial *) 9 | (* License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | val pp_mnemonics: Format.formatter -> unit 14 | 15 | val print_if: (Asm.coq_function AST.fundef, 'a) AST.program -> string -> unit 16 | 17 | val destination: string option ref 18 | 19 | val sdump_folder : string ref 20 | -------------------------------------------------------------------------------- /powerpc/Machregsaux.ml: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | (** Auxiliary functions on machine registers *) 14 | 15 | let is_scratch_register s = s = "R0" || s = "r0" 16 | -------------------------------------------------------------------------------- /powerpc/Machregsaux.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | (** Auxiliary functions on machine registers *) 14 | 15 | val is_scratch_register: string -> bool 16 | -------------------------------------------------------------------------------- /powerpc/extractionMachdep.v: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (* Additional extraction directives specific to the PowerPC port *) 18 | 19 | (* Asm *) 20 | Extract Constant Asm.low_half => "fun _ _ _ -> assert false". 21 | Extract Constant Asm.high_half => "fun _ _ _ -> assert false". 22 | Extract Constant Asm.symbol_is_small_data => "C2C.atom_is_small_data". 23 | Extract Constant Asm.small_data_area_offset => "fun _ _ _ -> assert false". 24 | Extract Constant Asm.symbol_is_rel_data => "C2C.atom_is_rel_data". 25 | Extract Constant Asm.symbol_is_aligned => "C2C.atom_is_aligned". 26 | 27 | (* Suppression of stupidly big equality functions *) 28 | Extract Constant Asm.ireg_eq => "fun (x: ireg) (y: ireg) -> x = y". 29 | Extract Constant Asm.freg_eq => "fun (x: freg) (y: freg) -> x = y". 30 | Extract Constant Asm.preg_eq => "fun (x: preg) (y: preg) -> x = y". 31 | 32 | (* Choice of PPC splitlong *) 33 | Extract Constant Archi.ppc64 => 34 | "begin match Configuration.model with 35 | | ""ppc64"" -> true 36 | | ""e5500"" -> true 37 | | _ -> false 38 | end". 39 | 40 | (* Choice of passing of single *) 41 | Extract Constant Archi.single_passed_as_single => "Configuration.gnu_toolchain". 42 | -------------------------------------------------------------------------------- /riscV/AsmToJSON.ml: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 6 | (* *) 7 | (* AbsInt Angewandte Informatik GmbH. All rights reserved. This file *) 8 | (* is distributed under the terms of the INRIA Non-Commercial *) 9 | (* License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | (* Simple functions to serialize RISC-V Asm to JSON *) 14 | 15 | (* Dummy function *) 16 | let destination: string option ref = ref None 17 | 18 | let sdump_folder = ref "" 19 | 20 | let print_if prog sourcename = 21 | () 22 | 23 | let pp_mnemonics pp = () 24 | -------------------------------------------------------------------------------- /riscV/Builtins1.v: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, Collège de France and Inria Paris *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (** Platform-specific built-in functions *) 18 | 19 | From Coq Require Import String. 20 | Require Import Coqlib AST Integers Floats Values. 21 | Require Import Builtins0. 22 | 23 | Inductive platform_builtin : Type := . 24 | 25 | Local Open Scope string_scope. 26 | 27 | Definition platform_builtin_table : list (string * platform_builtin) := 28 | nil. 29 | 30 | Definition platform_builtin_sig (b: platform_builtin) : signature := 31 | match b with end. 32 | 33 | Definition platform_builtin_sem (b: platform_builtin) : builtin_sem (sig_res (platform_builtin_sig b)) := 34 | match b with end. 35 | 36 | Definition eq_platform_builtin: forall (x y: platform_builtin), {x=y} + {x<>y}. 37 | Proof. 38 | intros. destruct x. 39 | Defined. 40 | -------------------------------------------------------------------------------- /riscV/CBuiltins.ml: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (* Processor-dependent builtin C functions *) 18 | 19 | open C 20 | 21 | let builtins = { 22 | builtin_typedefs = [ 23 | "__builtin_va_list", TPtr(TVoid [], []) 24 | ]; 25 | builtin_functions = [ 26 | (* Synchronization *) 27 | "__builtin_fence", 28 | (TVoid [], [], false); 29 | (* Float arithmetic *) 30 | "__builtin_fmadd", 31 | (TFloat(FDouble, []), 32 | [TFloat(FDouble, []); TFloat(FDouble, []); TFloat(FDouble, [])], 33 | false); 34 | "__builtin_fmsub", 35 | (TFloat(FDouble, []), 36 | [TFloat(FDouble, []); TFloat(FDouble, []); TFloat(FDouble, [])], 37 | false); 38 | "__builtin_fnmadd", 39 | (TFloat(FDouble, []), 40 | [TFloat(FDouble, []); TFloat(FDouble, []); TFloat(FDouble, [])], 41 | false); 42 | "__builtin_fnmsub", 43 | (TFloat(FDouble, []), 44 | [TFloat(FDouble, []); TFloat(FDouble, []); TFloat(FDouble, [])], 45 | false); 46 | "__builtin_fmax", 47 | (TFloat(FDouble, []), [TFloat(FDouble, []); TFloat(FDouble, [])], false); 48 | "__builtin_fmin", 49 | (TFloat(FDouble, []), [TFloat(FDouble, []); TFloat(FDouble, [])], false); 50 | ] 51 | } 52 | 53 | let va_list_type = TPtr(TVoid [], []) (* to check! *) 54 | let size_va_list = if Archi.ptr64 then 8 else 4 55 | let va_list_scalar = true 56 | 57 | (* Expand memory references inside extended asm statements. Used in C2C. *) 58 | 59 | let asm_mem_argument arg = Printf.sprintf "0(%s)" arg 60 | -------------------------------------------------------------------------------- /riscV/Machregsaux.ml: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | (** Auxiliary functions on machine registers *) 14 | 15 | let is_scratch_register r = false 16 | -------------------------------------------------------------------------------- /riscV/Machregsaux.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | (** Auxiliary functions on machine registers *) 14 | 15 | val is_scratch_register: string -> bool 16 | -------------------------------------------------------------------------------- /riscV/extractionMachdep.v: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (* Additional extraction directives specific to the RISC-V port *) 18 | 19 | Require Archi Asm. 20 | 21 | (* Archi *) 22 | 23 | Extract Constant Archi.ptr64 => " Configuration.model = ""64"" ". 24 | Extract Constant Archi.pic_code => "fun () -> false". (* for the time being *) 25 | 26 | (* Asm *) 27 | Extract Constant Asm.low_half => "fun _ _ _ -> assert false". 28 | Extract Constant Asm.high_half => "fun _ _ _ -> assert false". 29 | -------------------------------------------------------------------------------- /runtime/README: -------------------------------------------------------------------------------- 1 | This is the support library for CompCert-generated code. 2 | 3 | It provides helper functions for: 4 | - 64-bit integer arithmetic 5 | - implementing the va_arg macro from 6 | 7 | The implementation is written in assembly language in the 8 | arm/ powerpc/ powerpc64/ riscV/ x86_32/ x86_64/ directories. 9 | 10 | The c/ directory contains a C implementation of the 64-bit integer functions. 11 | It is provided for reference and as a guide for the asm implementations. 12 | -------------------------------------------------------------------------------- /runtime/aarch64/sysdeps.h: -------------------------------------------------------------------------------- 1 | // ***************************************************************** 2 | // 3 | // The Compcert verified compiler 4 | // 5 | // Xavier Leroy, Collège de France and INRIA Paris 6 | // 7 | // Copyright (c) Institut National de Recherche en Informatique et 8 | // en Automatique. 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // * Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // * Neither the name of the nor the 18 | // names of its contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | // 33 | // ********************************************************************* 34 | 35 | // System dependencies 36 | 37 | #if defined(SYS_macos) 38 | 39 | #define GLOB(x) _##x 40 | 41 | #define FUNCTION(f) FUNCTION f 42 | 43 | .macro FUNCTION name 44 | .text 45 | .globl _\name 46 | .align 4 47 | _\name: 48 | .endm 49 | 50 | #define ENDFUNCTION(f) 51 | 52 | #else 53 | 54 | #define GLOB(x) x 55 | 56 | #define FUNCTION(f) \ 57 | .text; \ 58 | .balign 16; \ 59 | .globl f; \ 60 | f: 61 | 62 | #define ENDFUNCTION(f) \ 63 | .type f, @function; .size f, . - f 64 | 65 | #endif 66 | 67 | #if defined(SYS_linux) || defined(SYS_bsd) 68 | .section .note.GNU-stack,"",%progbits 69 | #endif 70 | -------------------------------------------------------------------------------- /runtime/arm/i64_sar.S: -------------------------------------------------------------------------------- 1 | @ ***************************************************************** 2 | @ 3 | @ The Compcert verified compiler 4 | @ 5 | @ Xavier Leroy, INRIA Paris-Rocquencourt 6 | @ 7 | @ Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | @ en Automatique. 9 | @ 10 | @ Redistribution and use in source and binary forms, with or without 11 | @ modification, are permitted provided that the following conditions are met: 12 | @ * Redistributions of source code must retain the above copyright 13 | @ notice, this list of conditions and the following disclaimer. 14 | @ * Redistributions in binary form must reproduce the above copyright 15 | @ notice, this list of conditions and the following disclaimer in the 16 | @ documentation and/or other materials provided with the distribution. 17 | @ * Neither the name of the nor the 18 | @ names of its contributors may be used to endorse or promote products 19 | @ derived from this software without specific prior written permission. 20 | @ 21 | @ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | @ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | @ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | @ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | @ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | @ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | @ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | @ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | @ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | @ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | @ 33 | @ ********************************************************************* 34 | 35 | @ Helper functions for 64-bit integer arithmetic. ARM version. 36 | 37 | #include "sysdeps.h" 38 | 39 | @@@ Shift right signed 40 | 41 | FUNCTION(__compcert_i64_sar) 42 | AND r2, r2, #63 @ normalize amount to 0...63 43 | rsbs r3, r2, #32 @ r3 = 32 - amount 44 | ble 1f @ branch if <= 0, namely if amount >= 32 45 | LSR Reg0LO, Reg0LO, r2 46 | LSL r3, Reg0HI, r3 47 | ORR Reg0LO, Reg0LO, r3 48 | ASR Reg0HI, Reg0HI, r2 49 | bx lr 50 | 1: 51 | SUB r2, r2, #32 52 | ASR Reg0LO, Reg0HI, r2 53 | ASR Reg0HI, Reg0HI, #31 54 | bx lr 55 | ENDFUNCTION(__compcert_i64_sar) 56 | 57 | 58 | -------------------------------------------------------------------------------- /runtime/arm/i64_sdiv.S: -------------------------------------------------------------------------------- 1 | @ ***************************************************************** 2 | @ 3 | @ The Compcert verified compiler 4 | @ 5 | @ Xavier Leroy, INRIA Paris-Rocquencourt 6 | @ 7 | @ Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | @ en Automatique. 9 | @ 10 | @ Redistribution and use in source and binary forms, with or without 11 | @ modification, are permitted provided that the following conditions are met: 12 | @ * Redistributions of source code must retain the above copyright 13 | @ notice, this list of conditions and the following disclaimer. 14 | @ * Redistributions in binary form must reproduce the above copyright 15 | @ notice, this list of conditions and the following disclaimer in the 16 | @ documentation and/or other materials provided with the distribution. 17 | @ * Neither the name of the nor the 18 | @ names of its contributors may be used to endorse or promote products 19 | @ derived from this software without specific prior written permission. 20 | @ 21 | @ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | @ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | @ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | @ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | @ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | @ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | @ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | @ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | @ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | @ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | @ 33 | @ ********************************************************************* 34 | 35 | @ Helper functions for 64-bit integer arithmetic. ARM version. 36 | 37 | #include "sysdeps.h" 38 | 39 | @@@ Signed division 40 | 41 | FUNCTION(__compcert_i64_sdiv) 42 | push {r4, r5, r6, r7, r8, r10, lr} 43 | ASR r4, Reg0HI, #31 @ r4 = sign of N 44 | ASR r5, Reg1HI, #31 @ r5 = sign of D 45 | EOR r10, r4, r5 @ r10 = sign of result 46 | LCONDOPP(Reg0, Reg0, r4) @ take absolute value of N 47 | LCONDOPP(Reg1, Reg1, r5) @ take absolute value of D 48 | bl __compcert_i64_udivmod @ do unsigned division 49 | LCONDOPP(Reg0, Reg2, r10) @ apply expected sign 50 | pop {r4, r5, r6, r7, r8, r10, lr} 51 | bx lr 52 | ENDFUNCTION(__compcert_i64_sdiv) 53 | -------------------------------------------------------------------------------- /runtime/arm/i64_shl.S: -------------------------------------------------------------------------------- 1 | @ ***************************************************************** 2 | @ 3 | @ The Compcert verified compiler 4 | @ 5 | @ Xavier Leroy, INRIA Paris-Rocquencourt 6 | @ 7 | @ Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | @ en Automatique. 9 | @ 10 | @ Redistribution and use in source and binary forms, with or without 11 | @ modification, are permitted provided that the following conditions are met: 12 | @ * Redistributions of source code must retain the above copyright 13 | @ notice, this list of conditions and the following disclaimer. 14 | @ * Redistributions in binary form must reproduce the above copyright 15 | @ notice, this list of conditions and the following disclaimer in the 16 | @ documentation and/or other materials provided with the distribution. 17 | @ * Neither the name of the nor the 18 | @ names of its contributors may be used to endorse or promote products 19 | @ derived from this software without specific prior written permission. 20 | @ 21 | @ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | @ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | @ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | @ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | @ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | @ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | @ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | @ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | @ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | @ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | @ 33 | @ ********************************************************************* 34 | 35 | @ Helper functions for 64-bit integer arithmetic. ARM version. 36 | 37 | #include "sysdeps.h" 38 | 39 | @@@ Shift left 40 | 41 | FUNCTION(__compcert_i64_shl) 42 | AND r2, r2, #63 @ normalize amount to 0...63 43 | LSHL(Reg0, Reg0, r2, r3) 44 | bx lr 45 | ENDFUNCTION(__compcert_i64_shl) 46 | -------------------------------------------------------------------------------- /runtime/arm/i64_shr.S: -------------------------------------------------------------------------------- 1 | @ ***************************************************************** 2 | @ 3 | @ The Compcert verified compiler 4 | @ 5 | @ Xavier Leroy, INRIA Paris-Rocquencourt 6 | @ 7 | @ Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | @ en Automatique. 9 | @ 10 | @ Redistribution and use in source and binary forms, with or without 11 | @ modification, are permitted provided that the following conditions are met: 12 | @ * Redistributions of source code must retain the above copyright 13 | @ notice, this list of conditions and the following disclaimer. 14 | @ * Redistributions in binary form must reproduce the above copyright 15 | @ notice, this list of conditions and the following disclaimer in the 16 | @ documentation and/or other materials provided with the distribution. 17 | @ * Neither the name of the nor the 18 | @ names of its contributors may be used to endorse or promote products 19 | @ derived from this software without specific prior written permission. 20 | @ 21 | @ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | @ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | @ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | @ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | @ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | @ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | @ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | @ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | @ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | @ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | @ 33 | @ ********************************************************************* 34 | 35 | @ Helper functions for 64-bit integer arithmetic. ARM version. 36 | 37 | #include "sysdeps.h" 38 | 39 | @@@ Shift right unsigned 40 | 41 | FUNCTION(__compcert_i64_shr) 42 | AND r2, r2, #63 @ normalize amount to 0...63 43 | LSHR(Reg0, Reg0, r2, r3) 44 | bx lr 45 | ENDFUNCTION(__compcert_i64_shr) 46 | -------------------------------------------------------------------------------- /runtime/arm/i64_smod.S: -------------------------------------------------------------------------------- 1 | @ ***************************************************************** 2 | @ 3 | @ The Compcert verified compiler 4 | @ 5 | @ Xavier Leroy, INRIA Paris-Rocquencourt 6 | @ 7 | @ Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | @ en Automatique. 9 | @ 10 | @ Redistribution and use in source and binary forms, with or without 11 | @ modification, are permitted provided that the following conditions are met: 12 | @ * Redistributions of source code must retain the above copyright 13 | @ notice, this list of conditions and the following disclaimer. 14 | @ * Redistributions in binary form must reproduce the above copyright 15 | @ notice, this list of conditions and the following disclaimer in the 16 | @ documentation and/or other materials provided with the distribution. 17 | @ * Neither the name of the nor the 18 | @ names of its contributors may be used to endorse or promote products 19 | @ derived from this software without specific prior written permission. 20 | @ 21 | @ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | @ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | @ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | @ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | @ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | @ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | @ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | @ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | @ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | @ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | @ 33 | @ ********************************************************************* 34 | 35 | @ Helper functions for 64-bit integer arithmetic. ARM version. 36 | 37 | #include "sysdeps.h" 38 | 39 | @@@ Signed modulus 40 | 41 | FUNCTION(__compcert_i64_smod) 42 | push {r4, r5, r6, r7, r8, r10, lr} 43 | ASR r10, Reg0HI, #31 @ r10 = sign of N = sign of result 44 | ASR r5, Reg1HI, #31 @ r5 = sign of D 45 | LCONDOPP(Reg0, Reg0, r10) @ take absolute value of N 46 | LCONDOPP(Reg1, Reg1, r5) @ take absolute value of D 47 | bl __compcert_i64_udivmod @ do unsigned division 48 | LCONDOPP(Reg0, Reg0, r10) @ apply expected sign 49 | pop {r4, r5, r6, r7, r8, r10, lr} 50 | bx lr 51 | ENDFUNCTION(__compcert_i64_smod) 52 | -------------------------------------------------------------------------------- /runtime/arm/i64_udiv.S: -------------------------------------------------------------------------------- 1 | @ ***************************************************************** 2 | @ 3 | @ The Compcert verified compiler 4 | @ 5 | @ Xavier Leroy, INRIA Paris-Rocquencourt 6 | @ 7 | @ Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | @ en Automatique. 9 | @ 10 | @ Redistribution and use in source and binary forms, with or without 11 | @ modification, are permitted provided that the following conditions are met: 12 | @ * Redistributions of source code must retain the above copyright 13 | @ notice, this list of conditions and the following disclaimer. 14 | @ * Redistributions in binary form must reproduce the above copyright 15 | @ notice, this list of conditions and the following disclaimer in the 16 | @ documentation and/or other materials provided with the distribution. 17 | @ * Neither the name of the nor the 18 | @ names of its contributors may be used to endorse or promote products 19 | @ derived from this software without specific prior written permission. 20 | @ 21 | @ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | @ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | @ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | @ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | @ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | @ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | @ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | @ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | @ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | @ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | @ 33 | @ ********************************************************************* 34 | 35 | @ Helper functions for 64-bit integer arithmetic. ARM version. 36 | 37 | #include "sysdeps.h" 38 | 39 | @@@ Unsigned division 40 | 41 | FUNCTION(__compcert_i64_udiv) 42 | push {r4, r5, r6, r7, r8, lr} 43 | bl __compcert_i64_udivmod 44 | LMOV(Reg0, Reg2) 45 | pop {r4, r5, r6, r7, r8, lr} 46 | bx lr 47 | ENDFUNCTION(__compcert_i64_udiv) 48 | -------------------------------------------------------------------------------- /runtime/arm/i64_umod.S: -------------------------------------------------------------------------------- 1 | @ ***************************************************************** 2 | @ 3 | @ The Compcert verified compiler 4 | @ 5 | @ Xavier Leroy, INRIA Paris-Rocquencourt 6 | @ 7 | @ Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | @ en Automatique. 9 | @ 10 | @ Redistribution and use in source and binary forms, with or without 11 | @ modification, are permitted provided that the following conditions are met: 12 | @ * Redistributions of source code must retain the above copyright 13 | @ notice, this list of conditions and the following disclaimer. 14 | @ * Redistributions in binary form must reproduce the above copyright 15 | @ notice, this list of conditions and the following disclaimer in the 16 | @ documentation and/or other materials provided with the distribution. 17 | @ * Neither the name of the nor the 18 | @ names of its contributors may be used to endorse or promote products 19 | @ derived from this software without specific prior written permission. 20 | @ 21 | @ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | @ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | @ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | @ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | @ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | @ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | @ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | @ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | @ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | @ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | @ 33 | @ ********************************************************************* 34 | 35 | @ Helper functions for 64-bit integer arithmetic. ARM version. 36 | 37 | #include "sysdeps.h" 38 | 39 | @@@ Unsigned remainder 40 | 41 | FUNCTION(__compcert_i64_umod) 42 | push {r4, r5, r6, r7, r8, lr} 43 | bl __compcert_i64_udivmod @ remainder is already in r0,r1 44 | pop {r4, r5, r6, r7, r8, lr} 45 | bx lr 46 | ENDFUNCTION(__compcert_i64_umod) 47 | -------------------------------------------------------------------------------- /runtime/c/i64.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * The Compcert verified compiler 4 | * 5 | * Xavier Leroy, INRIA Paris-Rocquencourt 6 | * 7 | * Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | * en Automatique. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | **********************************************************************/ 34 | 35 | /* Helper functions for 64-bit integer arithmetic. Reference C implementation */ 36 | 37 | extern unsigned long long i64_shl(unsigned long long x, int amount); 38 | extern unsigned long long i64_shr(unsigned long long x, int amount); 39 | extern signed long long i64_sar(signed long long x, int amount); 40 | 41 | extern unsigned long long i64_udivmod(unsigned long long n, 42 | unsigned long long d, 43 | unsigned long long * rp); 44 | extern unsigned long long i64_umulh(unsigned long long u, 45 | unsigned long long v); 46 | -------------------------------------------------------------------------------- /runtime/c/i64_sar.c: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * The Compcert verified compiler 4 | * 5 | * Xavier Leroy, INRIA Paris-Rocquencourt 6 | * 7 | * Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | * en Automatique. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | **********************************************************************/ 34 | 35 | /* Helper functions for 64-bit integer arithmetic. Reference C implementation */ 36 | 37 | #include "i64.h" 38 | 39 | /* Shift right signed */ 40 | 41 | signed long long i64_sar(signed long long x, int amount) 42 | { 43 | unsigned xl = x; 44 | int xh = x >> 32; 45 | amount = amount & 63; 46 | if (amount == 0) { 47 | return x; 48 | } 49 | else if (amount < 32) { 50 | unsigned rl = (xl >> amount) | (xh << (32 - amount)); 51 | int rh = xh >> amount; 52 | return rl | ((signed long long) rh << 32); 53 | } else { 54 | return (signed long long) (xh >> (amount - 32)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /runtime/c/i64_sdiv.c: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * The Compcert verified compiler 4 | * 5 | * Xavier Leroy, INRIA Paris-Rocquencourt 6 | * 7 | * Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | * en Automatique. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | **********************************************************************/ 34 | 35 | /* Helper functions for 64-bit integer arithmetic. Reference C implementation */ 36 | 37 | #include "i64.h" 38 | 39 | /* Signed division */ 40 | 41 | signed long long i64_sdiv(signed long long n, signed long long d) 42 | { 43 | unsigned long long un, ud, uq, ur; 44 | int nh = n >> 32, dh = d >> 32; 45 | /* Take absolute values of n and d */ 46 | un = nh < 0 ? -n : n; 47 | ud = dh < 0 ? -d : d; 48 | uq = i64_udivmod(un, ud, &ur); 49 | /* Apply sign to quotient */ 50 | return (nh ^ dh) < 0 ? -uq : uq; 51 | } 52 | -------------------------------------------------------------------------------- /runtime/c/i64_shl.c: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * The Compcert verified compiler 4 | * 5 | * Xavier Leroy, INRIA Paris-Rocquencourt 6 | * 7 | * Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | * en Automatique. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | **********************************************************************/ 34 | 35 | /* Helper functions for 64-bit integer arithmetic. Reference C implementation */ 36 | 37 | #include "i64.h" 38 | 39 | /* Shift left */ 40 | 41 | unsigned long long i64_shl(unsigned long long x, int amount) 42 | { 43 | unsigned xl = x, xh = x >> 32; 44 | amount = amount & 63; 45 | if (amount == 0) { 46 | return x; 47 | } 48 | else if (amount < 32) { 49 | unsigned rl = xl << amount; 50 | unsigned rh = (xh << amount) | (xl >> (32 - amount)); 51 | return rl | ((unsigned long long) rh << 32); 52 | } else { 53 | return ((unsigned long long) (xl << (amount - 32))) << 32; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /runtime/c/i64_shr.c: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * The Compcert verified compiler 4 | * 5 | * Xavier Leroy, INRIA Paris-Rocquencourt 6 | * 7 | * Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | * en Automatique. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | **********************************************************************/ 34 | 35 | /* Helper functions for 64-bit integer arithmetic. Reference C implementation */ 36 | 37 | #include "i64.h" 38 | 39 | /* Shift right unsigned */ 40 | 41 | unsigned long long i64_shr(unsigned long long x, int amount) 42 | { 43 | unsigned xl = x, xh = x >> 32; 44 | amount = amount & 63; 45 | if (amount == 0) { 46 | return x; 47 | } 48 | else if (amount < 32) { 49 | unsigned rl = (xl >> amount) | (xh << (32 - amount)); 50 | unsigned rh = xh >> amount; 51 | return rl | ((unsigned long long) rh << 32); 52 | } else { 53 | return (unsigned long long) (xh >> (amount - 32)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /runtime/c/i64_smod.c: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * The Compcert verified compiler 4 | * 5 | * Xavier Leroy, INRIA Paris-Rocquencourt 6 | * 7 | * Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | * en Automatique. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | **********************************************************************/ 34 | 35 | /* Helper functions for 64-bit integer arithmetic. Reference C implementation */ 36 | 37 | #include "i64.h" 38 | 39 | /* Signed remainder */ 40 | 41 | signed long long i64_smod(signed long long n, signed long long d) 42 | { 43 | unsigned long long un, ud, ur; 44 | int nh = n >> 32, dh = d >> 32; 45 | /* Take absolute values of n and d */ 46 | un = nh < 0 ? -n : n; 47 | ud = dh < 0 ? -d : d; 48 | (void) i64_udivmod(un, ud, &ur); 49 | /* Apply sign to remainder */ 50 | return nh < 0 ? -ur : ur; 51 | } 52 | -------------------------------------------------------------------------------- /runtime/c/i64_smulh.c: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * The Compcert verified compiler 4 | * 5 | * Xavier Leroy, INRIA Paris-Rocquencourt 6 | * 7 | * Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | * en Automatique. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | **********************************************************************/ 34 | 35 | /* Helper functions for 64-bit integer arithmetic. Reference C implementation */ 36 | 37 | #include "i64.h" 38 | 39 | typedef signed long long s64; 40 | typedef unsigned long long u64; 41 | 42 | /* Signed multiply high */ 43 | 44 | /* Hacker's Delight section 8.3: 45 | * - compute high 64 bits of the unsigned product X * Y 46 | * - subtract X if Y < 0 47 | * - subtract Y if X < 0 48 | */ 49 | 50 | s64 i64_smulh(s64 x, s64 y) 51 | { 52 | s64 t = (s64) i64_umulh(x, y); 53 | if (y < 0) t = t - x; 54 | if (x < 0) t = t - y; 55 | return t; 56 | } 57 | -------------------------------------------------------------------------------- /runtime/c/i64_stod.c: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * The Compcert verified compiler 4 | * 5 | * Xavier Leroy, INRIA Paris-Rocquencourt 6 | * 7 | * Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | * en Automatique. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | **********************************************************************/ 34 | 35 | /* Helper functions for 64-bit integer arithmetic. Reference C implementation */ 36 | 37 | #include "i64.h" 38 | 39 | /* Conversion from signed int64 to float64 */ 40 | 41 | double i64_stod(signed long long x) 42 | { 43 | unsigned xl = x; 44 | signed xh = x >> 32; 45 | return (double) xl + 0x1p+32 * (double) xh; 46 | } 47 | -------------------------------------------------------------------------------- /runtime/c/i64_udiv.c: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * The Compcert verified compiler 4 | * 5 | * Xavier Leroy, INRIA Paris-Rocquencourt 6 | * 7 | * Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | * en Automatique. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | **********************************************************************/ 34 | 35 | /* Helper functions for 64-bit integer arithmetic. Reference C implementation */ 36 | 37 | #include "i64.h" 38 | 39 | /* Unsigned division */ 40 | 41 | unsigned long long i64_udiv(unsigned long long n, unsigned long long d) 42 | { 43 | unsigned long long r; 44 | return i64_udivmod(n, d, &r); 45 | } 46 | -------------------------------------------------------------------------------- /runtime/c/i64_umod.c: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * The Compcert verified compiler 4 | * 5 | * Xavier Leroy, INRIA Paris-Rocquencourt 6 | * 7 | * Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | * en Automatique. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | **********************************************************************/ 34 | 35 | /* Helper functions for 64-bit integer arithmetic. Reference C implementation */ 36 | 37 | #include "i64.h" 38 | 39 | /* Unsigned remainder */ 40 | 41 | unsigned long long i64_umod(unsigned long long n, unsigned long long d) 42 | { 43 | unsigned long long r; 44 | (void) i64_udivmod(n, d, &r); 45 | return r; 46 | } 47 | -------------------------------------------------------------------------------- /runtime/c/i64_umulh.c: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * The Compcert verified compiler 4 | * 5 | * Xavier Leroy, INRIA Paris 6 | * 7 | * Copyright (c) 2016 Institut National de Recherche en Informatique et 8 | * en Automatique. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | **********************************************************************/ 34 | 35 | /* Helper functions for 64-bit integer arithmetic. Reference C implementation */ 36 | 37 | #include "i64.h" 38 | 39 | typedef unsigned long long u64; 40 | typedef unsigned int u32; 41 | 42 | /* Unsigned multiply high */ 43 | 44 | /* Hacker's Delight, algorithm 8.1, specialized to two 32-bit words */ 45 | 46 | u64 i64_umulh(u64 u, u64 v) 47 | { 48 | u32 u0 = u, u1 = u >> 32; 49 | u32 v0 = v, v1 = v >> 32; 50 | u32 w1, w2, w3, k; 51 | u64 t; 52 | 53 | t = (u64) u0 * (u64) v0; 54 | k = t >> 32; 55 | 56 | t = (u64) u1 * (u64) v0 + k; 57 | w1 = t; 58 | w2 = t >> 32; 59 | 60 | t = (u64) u0 * (u64) v1 + w1; 61 | k = t >> 32; 62 | 63 | t = (u64) u1 * (u64) v1 + w2 + k; 64 | 65 | return t; 66 | } 67 | -------------------------------------------------------------------------------- /runtime/c/i64_utod.c: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * The Compcert verified compiler 4 | * 5 | * Xavier Leroy, INRIA Paris-Rocquencourt 6 | * 7 | * Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | * en Automatique. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | **********************************************************************/ 34 | 35 | /* Helper functions for 64-bit integer arithmetic. Reference C implementation */ 36 | 37 | #include "i64.h" 38 | 39 | /* Conversion from unsigned int64 to float64 */ 40 | 41 | double i64_utod(unsigned long long x) 42 | { 43 | unsigned xl = x, xh = x >> 32; 44 | return (double) xl + 0x1.0p32 * (double) xh; 45 | } 46 | -------------------------------------------------------------------------------- /runtime/c/i64_utof.c: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * The Compcert verified compiler 4 | * 5 | * Xavier Leroy, INRIA Paris-Rocquencourt 6 | * 7 | * Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | * en Automatique. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the name of the nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | **********************************************************************/ 34 | 35 | /* Helper functions for 64-bit integer arithmetic. Reference C implementation */ 36 | 37 | #include "i64.h" 38 | 39 | /* Conversion from unsigned int64 to float32 */ 40 | 41 | float i64_utof(unsigned long long x) 42 | { 43 | if (x >= 1ULL << 53) { 44 | /* x is large enough that double rounding can occur. 45 | Nudge x away from the points where double rounding occurs 46 | (the "round to odd" technique) */ 47 | unsigned delta = ((unsigned) x & 0x7FF) + 0x7FF; 48 | x = (x | delta) & ~0x7FFULL; 49 | } 50 | /* Convert to double */ 51 | unsigned xl = x, xh = x >> 32; 52 | double r = (double) xl + 0x1.0p32 * (double) xh; 53 | /* Round to single */ 54 | return (float) r; 55 | } 56 | -------------------------------------------------------------------------------- /runtime/include/iso646.h: -------------------------------------------------------------------------------- 1 | /* This file is part of the Compcert verified compiler. 2 | * 3 | * Copyright (c) 2015 Institut National de Recherche en Informatique et 4 | * en Automatique. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of the nor the 14 | * names of its contributors may be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | /* 31 | * ISO C Standard: 7.9 Alternative spellings 32 | */ 33 | 34 | #ifndef _ISO646_H 35 | #define _ISO646_H 36 | 37 | #define and && 38 | #define and_eq &= 39 | #define bitand & 40 | #define bitor | 41 | #define compl ~ 42 | #define not ! 43 | #define not_eq != 44 | #define or || 45 | #define or_eq |= 46 | #define xor ^ 47 | #define xor_eq ^= 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /runtime/include/stdalign.h: -------------------------------------------------------------------------------- 1 | /* This file is part of the Compcert verified compiler. 2 | * 3 | * Copyright (c) 2015 Institut National de Recherche en Informatique et 4 | * en Automatique. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of the nor the 14 | * names of its contributors may be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | 31 | /* ISO C11: 7.15 Alignment . */ 32 | 33 | #ifndef _STDALIGN_H 34 | #define _STDALIGN_H 35 | 36 | #define alignas _Alignas 37 | #define alignof _Alignof 38 | 39 | #define __alignas_is_defined 1 40 | #define __alignof_is_defined 1 41 | 42 | #endif /* stdalign.h */ 43 | -------------------------------------------------------------------------------- /runtime/include/stdbool.h: -------------------------------------------------------------------------------- 1 | /* This file is part of the Compcert verified compiler. 2 | * 3 | * Copyright (c) 2015 Institut National de Recherche en Informatique et 4 | * en Automatique. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of the nor the 14 | * names of its contributors may be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | /* -- Boolean type and values (ISO C99 7.16) */ 31 | 32 | #ifndef _STDBOOL_H 33 | #define _STDBOOL_H 34 | 35 | #define bool _Bool 36 | #define true 1 37 | #define false 0 38 | #define __bool_true_false_are_defined 1 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /runtime/include/stdnoreturn.h: -------------------------------------------------------------------------------- 1 | /* This file is part of the Compcert verified compiler. 2 | * 3 | * Copyright (c) 2015 Institut National de Recherche en Informatique et 4 | * en Automatique. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of the nor the 14 | * names of its contributors may be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | 31 | /* ISO C11: 7.23 _Noreturn . */ 32 | 33 | #ifndef _STDNORETURN_H 34 | #define _STDNORETURN_H 35 | 36 | #define noreturn _Noreturn 37 | 38 | #endif /* stdnoreturn.h */ 39 | -------------------------------------------------------------------------------- /runtime/include/varargs.h: -------------------------------------------------------------------------------- 1 | /* This file is part of the Compcert verified compiler. 2 | * 3 | * Copyright (c) 2015 Institut National de Recherche en Informatique et 4 | * en Automatique. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of the nor the 14 | * names of its contributors may be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | /* -- old-style variable argument handling */ 31 | 32 | #ifndef _VARARGS_H 33 | #define _VARARGS_H 34 | 35 | #error "CompCert does not implement ." 36 | #error "Please use instead." 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /runtime/powerpc/i64_udiv.S: -------------------------------------------------------------------------------- 1 | // ***************************************************************** 2 | // 3 | // The Compcert verified compiler 4 | // 5 | // Xavier Leroy, INRIA Paris-Rocquencourt 6 | // 7 | // Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | // en Automatique. 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // * Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // * Neither the name of the nor the 18 | // names of its contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | // 33 | // ********************************************************************* 34 | 35 | // Helper functions for 64-bit integer arithmetic. PowerPC version. 36 | 37 | #include "sysdeps.h" 38 | 39 | .text 40 | 41 | // Unsigned division 42 | 43 | .balign 16 44 | .globl __compcert_i64_udiv 45 | __compcert_i64_udiv: 46 | mflr r0 47 | stw r0, 4(r1) // save return address in caller's frame 48 | bl __compcert_i64_udivmod // unsigned divide 49 | lwz r0, 4(r1) 50 | mtlr r0 // restore return address 51 | mr r3, r5 // result = quotient 52 | mr r4, r6 53 | blr 54 | .type __compcert_i64_udiv, @function 55 | .size __compcert_i64_udiv, .-__compcert_i64_udiv 56 | 57 | -------------------------------------------------------------------------------- /runtime/powerpc/i64_umod.S: -------------------------------------------------------------------------------- 1 | // ***************************************************************** 2 | // 3 | // The Compcert verified compiler 4 | // 5 | // Xavier Leroy, INRIA Paris-Rocquencourt 6 | // 7 | // Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | // en Automatique. 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // * Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // * Neither the name of the nor the 18 | // names of its contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | // 33 | // ********************************************************************* 34 | 35 | // Helper functions for 64-bit integer arithmetic. PowerPC version. 36 | 37 | #include "sysdeps.h" 38 | 39 | .text 40 | 41 | // Unsigned modulus 42 | 43 | .balign 16 44 | .globl __compcert_i64_umod 45 | __compcert_i64_umod: 46 | b __compcert_i64_udivmod 47 | .type __compcert_i64_umod, @function 48 | .size __compcert_i64_umod, .-__compcert_i64_umod 49 | 50 | -------------------------------------------------------------------------------- /runtime/powerpc/sysdeps.h: -------------------------------------------------------------------------------- 1 | // ***************************************************************** 2 | // 3 | // The Compcert verified compiler 4 | // 5 | // Xavier Leroy, Collège de France and INRIA Paris 6 | // 7 | // Copyright (c) Institut National de Recherche en Informatique et 8 | // en Automatique. 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // * Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // * Neither the name of the nor the 18 | // names of its contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | // 33 | // ********************************************************************* 34 | 35 | // System dependencies 36 | 37 | #if defined(SYS_linux) || defined(SYS_bsd) 38 | .section .note.GNU-stack,"",%progbits 39 | #endif 40 | -------------------------------------------------------------------------------- /runtime/powerpc64/sysdeps.h: -------------------------------------------------------------------------------- 1 | // ***************************************************************** 2 | // 3 | // The Compcert verified compiler 4 | // 5 | // Xavier Leroy, Collège de France and INRIA Paris 6 | // 7 | // Copyright (c) Institut National de Recherche en Informatique et 8 | // en Automatique. 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // * Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // * Neither the name of the nor the 18 | // names of its contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | // 33 | // ********************************************************************* 34 | 35 | // System dependencies 36 | 37 | #if defined(SYS_linux) || defined(SYS_bsd) 38 | .section .note.GNU-stack,"",%progbits 39 | #endif 40 | -------------------------------------------------------------------------------- /runtime/riscV/sysdeps.h: -------------------------------------------------------------------------------- 1 | // ***************************************************************** 2 | // 3 | // The Compcert verified compiler 4 | // 5 | // Xavier Leroy, INRIA Paris-Rocquencourt 6 | // 7 | // Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | // en Automatique. 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // * Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // * Neither the name of the nor the 18 | // names of its contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | // 33 | // ********************************************************************* 34 | 35 | // System dependencies 36 | 37 | #define FUNCTION(f) \ 38 | .text; \ 39 | .balign 16; \ 40 | .globl f; \ 41 | f: 42 | 43 | #define ENDFUNCTION(f) \ 44 | .type f, @function; .size f, . - f 45 | 46 | #if defined(MODEL_64) 47 | 48 | #define WORDSIZE 8 49 | #define lptr ld 50 | #define sptr sd 51 | 52 | #elif defined(MODEL_32) 53 | 54 | #define WORDSIZE 4 55 | #define lptr lw 56 | #define sptr sw 57 | 58 | #else 59 | 60 | #error "Wrong MODEL" 61 | 62 | #endif 63 | 64 | #if defined(SYS_linux) || defined(SYS_bsd) 65 | .section .note.GNU-stack,"",%progbits 66 | #endif 67 | -------------------------------------------------------------------------------- /runtime/x86_32/i64_dtos.S: -------------------------------------------------------------------------------- 1 | // ***************************************************************** 2 | // 3 | // The Compcert verified compiler 4 | // 5 | // Xavier Leroy, INRIA Paris-Rocquencourt 6 | // 7 | // Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | // en Automatique. 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // * Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // * Neither the name of the nor the 18 | // names of its contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | // 33 | // ********************************************************************* 34 | 35 | // Helper functions for 64-bit integer arithmetic. IA32 version. 36 | 37 | #include "sysdeps.h" 38 | 39 | // Conversion float -> signed long 40 | 41 | FUNCTION(__compcert_i64_dtos) 42 | subl $4, %esp 43 | // Change rounding mode to "round towards zero" 44 | fnstcw 0(%esp) 45 | movw 0(%esp), %ax 46 | movb $12, %ah 47 | movw %ax, 2(%esp) 48 | fldcw 2(%esp) 49 | // Convert 50 | fldl 8(%esp) 51 | fistpll 8(%esp) 52 | // Restore rounding mode 53 | fldcw 0(%esp) 54 | // Load result in edx:eax 55 | movl 8(%esp), %eax 56 | movl 12(%esp), %edx 57 | addl $4, %esp 58 | ret 59 | ENDFUNCTION(__compcert_i64_dtos) 60 | 61 | -------------------------------------------------------------------------------- /runtime/x86_32/i64_stod.S: -------------------------------------------------------------------------------- 1 | // ***************************************************************** 2 | // 3 | // The Compcert verified compiler 4 | // 5 | // Xavier Leroy, INRIA Paris-Rocquencourt 6 | // 7 | // Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | // en Automatique. 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // * Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // * Neither the name of the nor the 18 | // names of its contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | // 33 | // ********************************************************************* 34 | 35 | // Helper functions for 64-bit integer arithmetic. IA32 version. 36 | 37 | #include "sysdeps.h" 38 | 39 | // Conversion signed long -> double-precision float 40 | 41 | FUNCTION(__compcert_i64_stod) 42 | fildll 4(%esp) 43 | ret 44 | // The result is in extended precision (80 bits) and therefore 45 | // exact (64 bits of mantissa). It will be rounded to double 46 | // precision by the caller, when transferring the result 47 | // to an XMM register or a 64-bit stack slot. 48 | ENDFUNCTION(__compcert_i64_stod) 49 | 50 | -------------------------------------------------------------------------------- /runtime/x86_32/i64_stof.S: -------------------------------------------------------------------------------- 1 | // ***************************************************************** 2 | // 3 | // The Compcert verified compiler 4 | // 5 | // Xavier Leroy, INRIA Paris-Rocquencourt 6 | // 7 | // Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | // en Automatique. 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // * Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // * Neither the name of the nor the 18 | // names of its contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | // 33 | // ********************************************************************* 34 | 35 | // Helper functions for 64-bit integer arithmetic. IA32 version. 36 | 37 | #include "sysdeps.h" 38 | 39 | // Conversion signed long -> single-precision float 40 | 41 | FUNCTION(__compcert_i64_stof) 42 | fildll 4(%esp) 43 | // The TOS is in extended precision and therefore exact. 44 | // Force rounding to single precision 45 | fstps 4(%esp) 46 | flds 4(%esp) 47 | ret 48 | ENDFUNCTION(__compcert_i64_stof) 49 | 50 | -------------------------------------------------------------------------------- /runtime/x86_32/i64_udiv.S: -------------------------------------------------------------------------------- 1 | // ***************************************************************** 2 | // 3 | // The Compcert verified compiler 4 | // 5 | // Xavier Leroy, INRIA Paris-Rocquencourt 6 | // 7 | // Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | // en Automatique. 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // * Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // * Neither the name of the nor the 18 | // names of its contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | // 33 | // ********************************************************************* 34 | 35 | // Helper functions for 64-bit integer arithmetic. IA32 version. 36 | 37 | #include "sysdeps.h" 38 | 39 | // Unsigned division 40 | 41 | FUNCTION(__compcert_i64_udiv) 42 | pushl %ebp 43 | pushl %esi 44 | pushl %edi 45 | call GLOB(__compcert_i64_udivmod) 46 | movl %esi, %eax 47 | movl %edi, %edx 48 | popl %edi 49 | popl %esi 50 | popl %ebp 51 | ret 52 | ENDFUNCTION(__compcert_i64_udiv) 53 | -------------------------------------------------------------------------------- /runtime/x86_32/i64_umod.S: -------------------------------------------------------------------------------- 1 | // ***************************************************************** 2 | // 3 | // The Compcert verified compiler 4 | // 5 | // Xavier Leroy, INRIA Paris-Rocquencourt 6 | // 7 | // Copyright (c) 2013 Institut National de Recherche en Informatique et 8 | // en Automatique. 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // * Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // * Neither the name of the nor the 18 | // names of its contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | // 33 | // ********************************************************************* 34 | 35 | // Helper functions for 64-bit integer arithmetic. IA32 version. 36 | 37 | #include "sysdeps.h" 38 | 39 | // Unsigned remainder 40 | 41 | FUNCTION(__compcert_i64_umod) 42 | pushl %ebp 43 | pushl %esi 44 | pushl %edi 45 | call GLOB(__compcert_i64_udivmod) 46 | popl %edi 47 | popl %esi 48 | popl %ebp 49 | ret 50 | ENDFUNCTION(__compcert_i64_umod) 51 | 52 | -------------------------------------------------------------------------------- /runtime/x86_64/i64_dtou.S: -------------------------------------------------------------------------------- 1 | // ***************************************************************** 2 | // 3 | // The Compcert verified compiler 4 | // 5 | // Xavier Leroy, INRIA Paris 6 | // 7 | // Copyright (c) 2016 Institut National de Recherche en Informatique et 8 | // en Automatique. 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // * Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // * Neither the name of the nor the 18 | // names of its contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | // 33 | // ********************************************************************* 34 | 35 | // Helper functions for 64-bit integer arithmetic. x86_64 version. 36 | 37 | #include "sysdeps.h" 38 | 39 | // Conversion float -> unsigned long 40 | 41 | FUNCTION(__compcert_i64_dtou) 42 | ucomisd .LC1(%rip), FP_ARG_1 43 | jnb 1f 44 | cvttsd2siq FP_ARG_1, INT_RES 45 | ret 46 | 1: subsd .LC1(%rip), FP_ARG_1 47 | cvttsd2siq FP_ARG_1, INT_RES 48 | addq .LC2(%rip), INT_RES 49 | ret 50 | 51 | .p2align 3 52 | .LC1: .quad 0x43e0000000000000 // 2^63 in double precision 53 | .LC2: .quad 0x8000000000000000 // 2^63 as an integer 54 | 55 | ENDFUNCTION(__compcert_i64_dtou) 56 | 57 | -------------------------------------------------------------------------------- /x86/AsmToJSON.ml: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 6 | (* *) 7 | (* AbsInt Angewandte Informatik GmbH. All rights reserved. This file *) 8 | (* is distributed under the terms of the INRIA Non-Commercial *) 9 | (* License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | (* Simple functions to serialize ia32 Asm to JSON *) 14 | 15 | (* Dummy function *) 16 | let destination: string option ref = ref None 17 | 18 | let sdump_folder = ref "" 19 | 20 | let print_if prog sourcename = 21 | () 22 | 23 | let pp_mnemonics pp = () 24 | -------------------------------------------------------------------------------- /x86/AsmToJSON.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) 6 | (* *) 7 | (* AbsInt Angewandte Informatik GmbH. All rights reserved. This file *) 8 | (* is distributed under the terms of the INRIA Non-Commercial *) 9 | (* License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | val pp_mnemonics: Format.formatter -> unit 14 | 15 | val print_if: (Asm.coq_function AST.fundef, 'a) AST.program -> string -> unit 16 | 17 | val destination: string option ref 18 | 19 | val sdump_folder : string ref 20 | -------------------------------------------------------------------------------- /x86/Builtins1.v: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, Collège de France and Inria Paris *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (** Platform-specific built-in functions *) 18 | 19 | From Coq Require Import String. 20 | Require Import Coqlib AST Integers Floats Values. 21 | Require Import Builtins0. 22 | Local Open Scope asttyp_scope. 23 | 24 | Inductive platform_builtin : Type := 25 | | BI_fmin 26 | | BI_fmax. 27 | 28 | Local Open Scope string_scope. 29 | 30 | Definition platform_builtin_table : list (string * platform_builtin) := 31 | ("__builtin_fmin", BI_fmin) 32 | :: ("__builtin_fmax", BI_fmax) 33 | :: nil. 34 | 35 | Definition platform_builtin_sig (b: platform_builtin) : signature := 36 | match b with 37 | | BI_fmin | BI_fmax => [Xfloat; Xfloat ---> Xfloat] 38 | end. 39 | 40 | Definition platform_builtin_sem (b: platform_builtin) : builtin_sem (sig_res (platform_builtin_sig b)) := 41 | match b with 42 | | BI_fmin => 43 | mkbuiltin_n2t Tfloat Tfloat Xfloat 44 | (fun f1 f2 => match Float.compare f1 f2 with 45 | | Some Lt => f1 46 | | Some Eq | Some Gt | None => f2 47 | end) 48 | | BI_fmax => 49 | mkbuiltin_n2t Tfloat Tfloat Xfloat 50 | (fun f1 f2 => match Float.compare f1 f2 with 51 | | Some Gt => f1 52 | | Some Eq | Some Lt | None => f2 53 | end) 54 | end. 55 | 56 | Definition eq_platform_builtin: forall (x y: platform_builtin), {x=y} + {x<>y}. 57 | Proof. 58 | decide equality. 59 | Defined. 60 | -------------------------------------------------------------------------------- /x86/Machregsaux.ml: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | (** Auxiliary functions on machine registers *) 14 | 15 | let is_scratch_register r = false 16 | -------------------------------------------------------------------------------- /x86/Machregsaux.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 10 | (* *) 11 | (* *********************************************************************) 12 | 13 | (** Auxiliary functions on machine registers *) 14 | 15 | val is_scratch_register: string -> bool 16 | -------------------------------------------------------------------------------- /x86/extractionMachdep.v: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU Lesser General Public License as *) 10 | (* published by the Free Software Foundation, either version 2.1 of *) 11 | (* the License, or (at your option) any later version. *) 12 | (* This file is also distributed under the terms of the *) 13 | (* INRIA Non-Commercial License Agreement. *) 14 | (* *) 15 | (* *********************************************************************) 16 | 17 | (* Additional extraction directives specific to the x86-64 port *) 18 | 19 | Require Archi SelectOp. 20 | 21 | (* Archi *) 22 | 23 | Extract Constant Archi.win64 => 24 | "match Configuration.system with 25 | | ""cygwin"" when ptr64 -> true 26 | | _ -> false". 27 | 28 | (* SelectOp *) 29 | 30 | Extract Constant SelectOp.symbol_is_external => 31 | "match Configuration.system with 32 | | ""macos"" -> C2C.atom_is_external 33 | | ""cygwin"" when Archi.ptr64 -> C2C.atom_is_external 34 | | _ -> (fun _ -> false)". 35 | --------------------------------------------------------------------------------