├── .gitattributes ├── .gitignore ├── FSHlvm.sln ├── LICENSE.md ├── README.md ├── RELEASE_NOTES.md ├── build.cmd ├── build.sh ├── docs ├── content │ └── .gitignore ├── files │ └── .gitignore └── tools │ ├── generate.fsx │ ├── packages.config │ └── templates │ └── template.cshtml ├── lib ├── FSLLVM.LICENSE └── FSLLVM.dll ├── run.sh ├── src ├── FSHlvm.Cli │ ├── AssemblyInfo.fs │ ├── FSHlvm.Cli.fsproj │ ├── Program.fs │ ├── libfshlvmllvmwrapper.so │ └── libfshlvmruntime.so ├── FSHlvm.Core │ ├── AssemblyInfo.fs │ ├── FSHlvm.Core.fsproj │ ├── FSHlvm.fs │ └── HashMultiMap.fs └── FSHlvm.Runtime │ ├── Makefile │ ├── llvm.cpp │ └── runtime.cpp └── tests └── FSHlvm.Core.Tests ├── AssemblyInfo.fs ├── FSCheckRunner.fs ├── FSHlvm.Core.Tests.fsproj ├── FSHlvmTest.fs ├── FSUnit.fs ├── libLLVM-3.8.so ├── libfshlvmllvmwrapper.so ├── libfshlvmruntime.so ├── run.sh └── tests.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | # Autodetect text or binary. Do not leave merge conflict markers in the files. 5 | * text=auto merge=union 6 | 7 | # Use LF in the working directory by default. Override with core.autocrlf=true. 8 | *.fs eol=lf 9 | 10 | # Visual Studio can read LF sln files, but it always writes them as CRLF. 11 | *.sln eol=crlf 12 | 13 | ############################################################################### 14 | # Set default behavior for command prompt diff. 15 | # 16 | # This is need for earlier builds of msysgit that does not have it on by 17 | # default for csharp files. 18 | # Note: This is only used by command line 19 | ############################################################################### 20 | #*.cs diff=csharp 21 | 22 | ############################################################################### 23 | # Set the merge driver for project and solution files 24 | # 25 | # Merging from the command prompt will add diff markers to the files if there 26 | # are conflicts (Merging from VS is not affected by the settings below, in VS 27 | # the diff markers are never inserted). Diff markers may cause the following 28 | # file extensions to fail to load in VS. An alternative would be to treat 29 | # these files as binary and thus will always conflict and require user 30 | # intervention with every merge. To do so, just uncomment the entries below 31 | ############################################################################### 32 | #*.sln merge=binary 33 | #*.csproj merge=binary 34 | #*.vbproj merge=binary 35 | #*.vcxproj merge=binary 36 | #*.vcproj merge=binary 37 | #*.dbproj merge=binary 38 | #*.fsproj merge=binary 39 | #*.lsproj merge=binary 40 | #*.wixproj merge=binary 41 | #*.modelproj merge=binary 42 | #*.sqlproj merge=binary 43 | #*.wwaproj merge=binary 44 | 45 | ############################################################################### 46 | # behavior for image files 47 | # 48 | # image files are treated as binary by default. 49 | ############################################################################### 50 | #*.jpg binary 51 | #*.png binary 52 | #*.gif binary 53 | 54 | ############################################################################### 55 | # diff behavior for common document formats 56 | # 57 | # Convert binary document formats to text before diffing them. This feature 58 | # is only available from the command line. Turn it on by uncommenting the 59 | # entries below. 60 | ############################################################################### 61 | #*.doc diff=astextplain 62 | #*.DOC diff=astextplain 63 | #*.docx diff=astextplain 64 | #*.DOCX diff=astextplain 65 | #*.dot diff=astextplain 66 | #*.DOT diff=astextplain 67 | #*.pdf diff=astextplain 68 | #*.PDF diff=astextplain 69 | #*.rtf diff=astextplain 70 | #*.RTF diff=astextplain 71 | 72 | *.sh text eol=lf 73 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Xamarin Studio / monodevelop user-specific 10 | *.userprefs 11 | 12 | # Build results 13 | 14 | [Dd]ebug/ 15 | [Rr]elease/ 16 | x64/ 17 | build/ 18 | [Bb]in/ 19 | [Oo]bj/ 20 | 21 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets 22 | !packages/*/build/ 23 | 24 | # MSTest test Results 25 | [Tt]est[Rr]esult*/ 26 | [Bb]uild[Ll]og.* 27 | 28 | *_i.c 29 | *_p.c 30 | *.ilk 31 | *.meta 32 | *.obj 33 | *.pch 34 | *.pdb 35 | *.pgc 36 | *.pgd 37 | *.rsp 38 | *.sbr 39 | *.tlb 40 | *.tli 41 | *.tlh 42 | *.tmp 43 | *.tmp_proj 44 | *.log 45 | *.vspscc 46 | *.vssscc 47 | .builds 48 | *.pidb 49 | *.log 50 | *.scc 51 | 52 | # Visual C++ cache files 53 | ipch/ 54 | *.aps 55 | *.ncb 56 | *.opensdf 57 | *.sdf 58 | *.cachefile 59 | 60 | # Visual Studio profiler 61 | *.psess 62 | *.vsp 63 | *.vspx 64 | 65 | # Guidance Automation Toolkit 66 | *.gpState 67 | 68 | # ReSharper is a .NET coding add-in 69 | _ReSharper*/ 70 | *.[Rr]e[Ss]harper 71 | 72 | # TeamCity is a build add-in 73 | _TeamCity* 74 | 75 | # DotCover is a Code Coverage Tool 76 | *.dotCover 77 | 78 | # NCrunch 79 | *.ncrunch* 80 | .*crunch*.local.xml 81 | 82 | # Installshield output folder 83 | [Ee]xpress/ 84 | 85 | # DocProject is a documentation generator add-in 86 | DocProject/buildhelp/ 87 | DocProject/Help/*.HxT 88 | DocProject/Help/*.HxC 89 | DocProject/Help/*.hhc 90 | DocProject/Help/*.hhk 91 | DocProject/Help/*.hhp 92 | DocProject/Help/Html2 93 | DocProject/Help/html 94 | 95 | # Click-Once directory 96 | publish/ 97 | 98 | # Publish Web Output 99 | *.Publish.xml 100 | 101 | # Enable nuget.exe in the .nuget folder (though normally executables are not tracked) 102 | !.nuget/NuGet.exe 103 | 104 | # Windows Azure Build Output 105 | csx 106 | *.build.csdef 107 | 108 | # Windows Store app package directory 109 | AppPackages/ 110 | 111 | # Others 112 | sql/ 113 | *.Cache 114 | ClientBin/ 115 | [Ss]tyle[Cc]op.* 116 | ~$* 117 | *~ 118 | *.dbmdl 119 | *.[Pp]ublish.xml 120 | *.pfx 121 | *.publishsettings 122 | 123 | # RIA/Silverlight projects 124 | Generated_Code/ 125 | 126 | # Backup & report files from converting an old project file to a newer 127 | # Visual Studio version. Backup files are not needed, because we have git ;-) 128 | _UpgradeReport_Files/ 129 | Backup*/ 130 | UpgradeLog*.XML 131 | UpgradeLog*.htm 132 | 133 | # SQL Server files 134 | App_Data/*.mdf 135 | App_Data/*.ldf 136 | 137 | 138 | #LightSwitch generated files 139 | GeneratedArtifacts/ 140 | _Pvt_Extensions/ 141 | ModelManifest.xml 142 | 143 | # ========================= 144 | # Windows detritus 145 | # ========================= 146 | 147 | # Windows image file caches 148 | Thumbs.db 149 | ehthumbs.db 150 | 151 | # Folder config file 152 | Desktop.ini 153 | 154 | # Recycle Bin used on file shares 155 | $RECYCLE.BIN/ 156 | 157 | # Mac desktop service store files 158 | .DS_Store 159 | 160 | # =================================================== 161 | # Exclude F# project specific directories and files 162 | # =================================================== 163 | 164 | # NuGet Packages Directory 165 | packages/ 166 | 167 | # Generated documentation folder 168 | docs/output/ 169 | 170 | # Temp folder used for publishing docs 171 | temp/ 172 | 173 | # Test results produced by build 174 | TestResults.xml 175 | 176 | # Nuget outputs 177 | nuget/*.nupkg 178 | -------------------------------------------------------------------------------- /FSHlvm.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26124.0 5 | MinimumVisualStudioVersion = 15.0.26124.0 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3D8565B2-6605-4186-8526-C0EEF6A14C74}" 7 | EndProject 8 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSHlvm.Core", "src\FSHlvm.Core\FSHlvm.Core.fsproj", "{17A5F19C-7B19-4DCB-8037-0D5977DE09B6}" 9 | EndProject 10 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSHlvm.Cli", "src\FSHlvm.Cli\FSHlvm.Cli.fsproj", "{73654A44-A47A-4E48-8786-272C9EE00989}" 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{E3FC74BA-3D6E-4D49-BFD2-5EA10D9582ED}" 13 | EndProject 14 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSHlvm.Core.Tests", "tests\FSHlvm.Core.Tests\FSHlvm.Core.Tests.fsproj", "{907CB8D7-B9EE-447C-840E-F658A532DC0A}" 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|Any CPU = Debug|Any CPU 19 | Debug|x64 = Debug|x64 20 | Debug|x86 = Debug|x86 21 | Release|Any CPU = Release|Any CPU 22 | Release|x64 = Release|x64 23 | Release|x86 = Release|x86 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 29 | {17A5F19C-7B19-4DCB-8037-0D5977DE09B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 30 | {17A5F19C-7B19-4DCB-8037-0D5977DE09B6}.Debug|Any CPU.Build.0 = Debug|Any CPU 31 | {17A5F19C-7B19-4DCB-8037-0D5977DE09B6}.Debug|x64.ActiveCfg = Debug|x64 32 | {17A5F19C-7B19-4DCB-8037-0D5977DE09B6}.Debug|x64.Build.0 = Debug|x64 33 | {17A5F19C-7B19-4DCB-8037-0D5977DE09B6}.Debug|x86.ActiveCfg = Debug|x86 34 | {17A5F19C-7B19-4DCB-8037-0D5977DE09B6}.Debug|x86.Build.0 = Debug|x86 35 | {17A5F19C-7B19-4DCB-8037-0D5977DE09B6}.Release|Any CPU.ActiveCfg = Release|Any CPU 36 | {17A5F19C-7B19-4DCB-8037-0D5977DE09B6}.Release|Any CPU.Build.0 = Release|Any CPU 37 | {17A5F19C-7B19-4DCB-8037-0D5977DE09B6}.Release|x64.ActiveCfg = Release|x64 38 | {17A5F19C-7B19-4DCB-8037-0D5977DE09B6}.Release|x64.Build.0 = Release|x64 39 | {17A5F19C-7B19-4DCB-8037-0D5977DE09B6}.Release|x86.ActiveCfg = Release|x86 40 | {17A5F19C-7B19-4DCB-8037-0D5977DE09B6}.Release|x86.Build.0 = Release|x86 41 | {73654A44-A47A-4E48-8786-272C9EE00989}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 42 | {73654A44-A47A-4E48-8786-272C9EE00989}.Debug|Any CPU.Build.0 = Debug|Any CPU 43 | {73654A44-A47A-4E48-8786-272C9EE00989}.Debug|x64.ActiveCfg = Debug|x64 44 | {73654A44-A47A-4E48-8786-272C9EE00989}.Debug|x64.Build.0 = Debug|x64 45 | {73654A44-A47A-4E48-8786-272C9EE00989}.Debug|x86.ActiveCfg = Debug|x86 46 | {73654A44-A47A-4E48-8786-272C9EE00989}.Debug|x86.Build.0 = Debug|x86 47 | {73654A44-A47A-4E48-8786-272C9EE00989}.Release|Any CPU.ActiveCfg = Release|Any CPU 48 | {73654A44-A47A-4E48-8786-272C9EE00989}.Release|Any CPU.Build.0 = Release|Any CPU 49 | {73654A44-A47A-4E48-8786-272C9EE00989}.Release|x64.ActiveCfg = Release|x64 50 | {73654A44-A47A-4E48-8786-272C9EE00989}.Release|x64.Build.0 = Release|x64 51 | {73654A44-A47A-4E48-8786-272C9EE00989}.Release|x86.ActiveCfg = Release|x86 52 | {73654A44-A47A-4E48-8786-272C9EE00989}.Release|x86.Build.0 = Release|x86 53 | {907CB8D7-B9EE-447C-840E-F658A532DC0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 54 | {907CB8D7-B9EE-447C-840E-F658A532DC0A}.Debug|Any CPU.Build.0 = Debug|Any CPU 55 | {907CB8D7-B9EE-447C-840E-F658A532DC0A}.Debug|x64.ActiveCfg = Debug|x64 56 | {907CB8D7-B9EE-447C-840E-F658A532DC0A}.Debug|x64.Build.0 = Debug|x64 57 | {907CB8D7-B9EE-447C-840E-F658A532DC0A}.Debug|x86.ActiveCfg = Debug|x86 58 | {907CB8D7-B9EE-447C-840E-F658A532DC0A}.Debug|x86.Build.0 = Debug|x86 59 | {907CB8D7-B9EE-447C-840E-F658A532DC0A}.Release|Any CPU.ActiveCfg = Release|Any CPU 60 | {907CB8D7-B9EE-447C-840E-F658A532DC0A}.Release|Any CPU.Build.0 = Release|Any CPU 61 | {907CB8D7-B9EE-447C-840E-F658A532DC0A}.Release|x64.ActiveCfg = Release|x64 62 | {907CB8D7-B9EE-447C-840E-F658A532DC0A}.Release|x64.Build.0 = Release|x64 63 | {907CB8D7-B9EE-447C-840E-F658A532DC0A}.Release|x86.ActiveCfg = Release|x86 64 | {907CB8D7-B9EE-447C-840E-F658A532DC0A}.Release|x86.Build.0 = Release|x86 65 | EndGlobalSection 66 | GlobalSection(NestedProjects) = preSolution 67 | {17A5F19C-7B19-4DCB-8037-0D5977DE09B6} = {3D8565B2-6605-4186-8526-C0EEF6A14C74} 68 | {73654A44-A47A-4E48-8786-272C9EE00989} = {3D8565B2-6605-4186-8526-C0EEF6A14C74} 69 | {907CB8D7-B9EE-447C-840E-F658A532DC0A} = {E3FC74BA-3D6E-4D49-BFD2-5EA10D9582ED} 70 | EndGlobalSection 71 | EndGlobal 72 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2014-2020 2 | 3 | Zoltan Podlovics 4 | KP-Tech Kft. 5 | All rights reserved. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | 19 | 20 | Apache License, Version 2.0 21 | =========================== 22 | 23 | Apache License 24 | Version 2.0, January 2004 25 | http://www.apache.org/licenses/ 26 | 27 | ------------------------------------------------------------ 28 | 29 | ### TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 30 | 31 | 32 | **1. Definitions.** 33 | 34 | - "License" shall mean the terms and conditions for use, reproduction, 35 | and distribution as defined by Sections 1 through 9 of this document. 36 | 37 | - "Licensor" shall mean the copyright owner or entity authorized by 38 | the copyright owner that is granting the License. 39 | 40 | - "Legal Entity" shall mean the union of the acting entity and all 41 | other entities that control, are controlled by, or are under common 42 | control with that entity. For the purposes of this definition, 43 | "control" means (i) the power, direct or indirect, to cause the 44 | direction or management of such entity, whether by contract or 45 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 46 | outstanding shares, or (iii) beneficial ownership of such entity. 47 | 48 | - "You" (or "Your") shall mean an individual or Legal Entity 49 | exercising permissions granted by this License. 50 | 51 | - "Source" form shall mean the preferred form for making modifications, 52 | including but not limited to software source code, documentation 53 | source, and configuration files. 54 | 55 | - "Object" form shall mean any form resulting from mechanical 56 | transformation or translation of a Source form, including but 57 | not limited to compiled object code, generated documentation, 58 | and conversions to other media types. 59 | 60 | - "Work" shall mean the work of authorship, whether in Source or 61 | Object form, made available under the License, as indicated by a 62 | copyright notice that is included in or attached to the work 63 | (an example is provided in the Appendix below). 64 | 65 | - "Derivative Works" shall mean any work, whether in Source or Object 66 | form, that is based on (or derived from) the Work and for which the 67 | editorial revisions, annotations, elaborations, or other modifications 68 | represent, as a whole, an original work of authorship. For the purposes 69 | of this License, Derivative Works shall not include works that remain 70 | separable from, or merely link (or bind by name) to the interfaces of, 71 | the Work and Derivative Works thereof. 72 | 73 | - "Contribution" shall mean any work of authorship, including 74 | the original version of the Work and any modifications or additions 75 | to that Work or Derivative Works thereof, that is intentionally 76 | submitted to Licensor for inclusion in the Work by the copyright owner 77 | or by an individual or Legal Entity authorized to submit on behalf of 78 | the copyright owner. For the purposes of this definition, "submitted" 79 | means any form of electronic, verbal, or written communication sent 80 | to the Licensor or its representatives, including but not limited to 81 | communication on electronic mailing lists, source code control systems, 82 | and issue tracking systems that are managed by, or on behalf of, the 83 | Licensor for the purpose of discussing and improving the Work, but 84 | excluding communication that is conspicuously marked or otherwise 85 | designated in writing by the copyright owner as "Not a Contribution." 86 | 87 | - "Contributor" shall mean Licensor and any individual or Legal Entity 88 | on behalf of whom a Contribution has been received by Licensor and 89 | subsequently incorporated within the Work. 90 | 91 | **2. Grant of Copyright License.** 92 | Subject to the terms and conditions of 93 | this License, each Contributor hereby grants to You a perpetual, 94 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 95 | copyright license to reproduce, prepare Derivative Works of, 96 | publicly display, publicly perform, sublicense, and distribute the 97 | Work and such Derivative Works in Source or Object form. 98 | 99 | **3. Grant of Patent License.** 100 | Subject to the terms and conditions of 101 | this License, each Contributor hereby grants to You a perpetual, 102 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 103 | (except as stated in this section) patent license to make, have made, 104 | use, offer to sell, sell, import, and otherwise transfer the Work, 105 | where such license applies only to those patent claims licensable 106 | by such Contributor that are necessarily infringed by their 107 | Contribution(s) alone or by combination of their Contribution(s) 108 | with the Work to which such Contribution(s) was submitted. If You 109 | institute patent litigation against any entity (including a 110 | cross-claim or counterclaim in a lawsuit) alleging that the Work 111 | or a Contribution incorporated within the Work constitutes direct 112 | or contributory patent infringement, then any patent licenses 113 | granted to You under this License for that Work shall terminate 114 | as of the date such litigation is filed. 115 | 116 | **4. Redistribution.** 117 | You may reproduce and distribute copies of the 118 | Work or Derivative Works thereof in any medium, with or without 119 | modifications, and in Source or Object form, provided that You 120 | meet the following conditions: 121 | 122 | - You must give any other recipients of the Work or 123 | Derivative Works a copy of this License; and 124 | 125 | - You must cause any modified files to carry prominent notices 126 | stating that You changed the files; and 127 | 128 | - You must retain, in the Source form of any Derivative Works 129 | that You distribute, all copyright, patent, trademark, and 130 | attribution notices from the Source form of the Work, 131 | excluding those notices that do not pertain to any part of 132 | the Derivative Works; and 133 | 134 | - If the Work includes a "NOTICE" text file as part of its 135 | distribution, then any Derivative Works that You distribute must 136 | include a readable copy of the attribution notices contained 137 | within such NOTICE file, excluding those notices that do not 138 | pertain to any part of the Derivative Works, in at least one 139 | of the following places: within a NOTICE text file distributed 140 | as part of the Derivative Works; within the Source form or 141 | documentation, if provided along with the Derivative Works; or, 142 | within a display generated by the Derivative Works, if and 143 | wherever such third-party notices normally appear. The contents 144 | of the NOTICE file are for informational purposes only and 145 | do not modify the License. You may add Your own attribution 146 | notices within Derivative Works that You distribute, alongside 147 | or as an addendum to the NOTICE text from the Work, provided 148 | that such additional attribution notices cannot be construed 149 | as modifying the License. 150 | 151 | You may add Your own copyright statement to Your modifications and 152 | may provide additional or different license terms and conditions 153 | for use, reproduction, or distribution of Your modifications, or 154 | for any such Derivative Works as a whole, provided Your use, 155 | reproduction, and distribution of the Work otherwise complies with 156 | the conditions stated in this License. 157 | 158 | **5. Submission of Contributions.** 159 | Unless You explicitly state otherwise, 160 | any Contribution intentionally submitted for inclusion in the Work 161 | by You to the Licensor shall be under the terms and conditions of 162 | this License, without any additional terms or conditions. 163 | Notwithstanding the above, nothing herein shall supersede or modify 164 | the terms of any separate license agreement you may have executed 165 | with Licensor regarding such Contributions. 166 | 167 | **6. Trademarks.** 168 | This License does not grant permission to use the trade 169 | names, trademarks, service marks, or product names of the Licensor, 170 | except as required for reasonable and customary use in describing the 171 | origin of the Work and reproducing the content of the NOTICE file. 172 | 173 | **7. Disclaimer of Warranty.** 174 | Unless required by applicable law or 175 | agreed to in writing, Licensor provides the Work (and each 176 | Contributor provides its Contributions) on an "AS IS" BASIS, 177 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 178 | implied, including, without limitation, any warranties or conditions 179 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 180 | PARTICULAR PURPOSE. You are solely responsible for determining the 181 | appropriateness of using or redistributing the Work and assume any 182 | risks associated with Your exercise of permissions under this License. 183 | 184 | **8. Limitation of Liability.** 185 | In no event and under no legal theory, 186 | whether in tort (including negligence), contract, or otherwise, 187 | unless required by applicable law (such as deliberate and grossly 188 | negligent acts) or agreed to in writing, shall any Contributor be 189 | liable to You for damages, including any direct, indirect, special, 190 | incidental, or consequential damages of any character arising as a 191 | result of this License or out of the use or inability to use the 192 | Work (including but not limited to damages for loss of goodwill, 193 | work stoppage, computer failure or malfunction, or any and all 194 | other commercial damages or losses), even if such Contributor 195 | has been advised of the possibility of such damages. 196 | 197 | **9. Accepting Warranty or Additional Liability.** 198 | While redistributing 199 | the Work or Derivative Works thereof, You may choose to offer, 200 | and charge a fee for, acceptance of support, warranty, indemnity, 201 | or other liability obligations and/or rights consistent with this 202 | License. However, in accepting such obligations, You may act only 203 | on Your own behalf and on Your sole responsibility, not on behalf 204 | of any other Contributor, and only if You agree to indemnify, 205 | defend, and hold each Contributor harmless for any liability 206 | incurred by, or claims asserted against, such Contributor by reason 207 | of your accepting any such warranty or additional liability. 208 | 209 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## FSHlvm A High Level Virtual Machine Written In F# 2 | 3 | FSHlvm is a cross-platform open-source virtual machine with the following features: 4 | 5 | High-level DSL like language based on F# 6 | Safe 7 | Generics and type specialization 8 | Garbage collected 9 | High performance 10 | Multicore support 11 | Builtin FFI for C interoperability 12 | Commerce friendly 13 | 14 | The virtual machine is written in F# and uses the LLVM library for high-performance 15 | code generation. 16 | 17 | More information about FSHlvm are be available at: 18 | http://www.kp-tech.hu/en/products/fshlvm-opensource 19 | 20 | This work is based HLVM, written by Jon Harrop, Flying Frog Consultancy Ltd. 21 | More information about HLVM are available at: http://www.ffconsultancy.com/ocaml/hlvm/ 22 | 23 | ## Status 24 | 25 | The `master` branch is for the latest version of FSHlvm. 26 | 27 | ## Build Requirements on Linux 28 | 29 | Requires .NET Core SDK 3.1. 30 | Requires FSLLVM (precompiled netstandard2.0 version are available under lib/). 31 | 32 | ## Execution Requirements on Linux 33 | 34 | Tested on Ubuntu 20.04 (amd64) 35 | 36 | Requires LLVM-10 37 | Requires CLANG-10 38 | Requires FSHlvm fshlvmllvmwrapper shared library 39 | Requires FSHlvm fshlvmruntime shared library 40 | 41 | ### Installing LLVM-10 42 | 43 | apt install llvm-10-dev libllvm10 44 | 45 | ### Installing CLANG-10 46 | 47 | apt install clang-10 48 | 49 | ## How to Build 50 | 51 | ### Linux: 52 | 53 | #### QuickStart 54 | 55 | The following command will: 56 | * Build the F# codebase 57 | * Execute the FSHlvm.Cli executable (which will generate a list llvm bitcode example list.bc) 58 | * Optimize the list example llvm bitcode (listopt.bc) 59 | * Create a native executable for the list example called (listopt) 60 | 61 | ``` 62 | sh run.sh 63 | ``` 64 | 65 | #### Build everything 66 | 67 | The following command will: 68 | * Build the F# codebase 69 | 70 | ``` 71 | sh build.sh 72 | ``` 73 | 74 | Alternative F# codebase building method: 75 | Linux/.NET Core: open the FSHlvm.sln project file with Visual Studio Code and build the project. This will generate the FSHlvm.Core.dll assembly for you. 76 | 77 | #### Build fshlvmllvmwrapper and fshlvmruntime shared library 78 | 79 | ``` 80 | cd $FSHLVM_PATH/src/FSHlvm.Runtime 81 | make 82 | make install 83 | ``` 84 | 85 | This will copy the fshlvmllvmwrapper.so and fshlvmruntime.so to $FSHLVM_PATH/lib 86 | 87 | ### OS X 88 | 89 | Not yet tested on OS X. 90 | 91 | ### Windows (64bit), using msbuild 92 | 93 | Not yet tested on Windows. 94 | 95 | ## Development Notes 96 | 97 | ### Using FSHlvm in your project 98 | 99 | In order to use FSHlvm you will want to check the following: 100 | 101 | 1. Example F# code under FSHlvm.Cli. 102 | 2. Tests F# code under FSHlvm.Core.Tests. 103 | 104 | ### Editing the Project with Visual Studio, Visual Studio Code, Xamarin Studio or MonoDevelop 105 | 106 | Open `FSHlvm.sln`, and edit in modes Debug or Release. 107 | 108 | ## How to Test and Validate manually 109 | 110 | ### Linux 111 | 112 | Cli Test and Validation 113 | 114 | ``` 115 | cd $FSHLVM_PATH/src/FSHlvm.Cli 116 | ln -sfn ../../lib/libfshlvmllvmwrapper.so . 117 | ln -sfn ../../lib/libfshlvmruntime.so . 118 | dotnet restore 119 | dotnet run -c Release 120 | opt-10 -tailcallelim -O3 < list.bc >listopt.bc 121 | clang-10 -o listopt listopt.bc -ldl 122 | ./listopt 123 | ``` 124 | 125 | Additional Tests Test and Validation (each test must run individually, one by one!) 126 | 127 | ``` 128 | cd $FSHLVM_PATH/tests/FSHlvm.Core.Tests 129 | ln -sfn ../../lib/libfshlvmllvmwrapper.so . 130 | ln -sfn ../../lib/libfshlvmruntime.so . 131 | dotnet restore 132 | ./run.sh 133 | ./ffibopt 134 | ./fibopt 135 | ./foldopt 136 | ./listopt 137 | ./mandelbrot2opt 138 | ./mandelbrotopt 139 | ./tcoopt 140 | ./trigopt 141 | ``` 142 | -------------------------------------------------------------------------------- /RELEASE_NOTES.md: -------------------------------------------------------------------------------- 1 | #### 1.0 - Augustus 22 2014 2 | * Initial release 3 | 4 | #### 2.0 - Jul 27 2017 5 | * Move to .NET Core 2.0 preview2 6 | 7 | #### 3.0 - Nov 21 2020 8 | * Move to .NET Core 3.1 -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | cls 3 | dotnet restore 4 | dotnet build -c Release 5 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export FSHLVM_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 3 | cd $FSHLVM_HOME/src/FsHlvm.Runtime 4 | make 5 | make install 6 | cd $FSHLVM_HOME 7 | dotnet restore 8 | dotnet build -c Release 9 | -------------------------------------------------------------------------------- /docs/content/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /docs/files/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /docs/tools/generate.fsx: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------- 2 | // Builds the documentation from `.fsx` and `.md` files in the 'docs/content' directory 3 | // (the generated documentation is stored in the 'docs/output' directory) 4 | // -------------------------------------------------------------------------------------- 5 | 6 | // Binaries that have XML documentation (in a corresponding generated XML file) 7 | let referenceBinaries = [ "FSHlvm.Core.dll" ] 8 | // Web site location for the generated documentation 9 | let website = "/FSHlvm" 10 | 11 | let githubLink = "http://github.com/kp-tech/FSHlvm" 12 | 13 | // Specify more information about your project 14 | let info = 15 | [ "project-name", "FSHlvm" 16 | "project-author", "Zoltan Podlovics, KP-Tech kft." 17 | "project-summary", "FSHlvm is a cross-platform open-source virtual machine written in F# and uses the LLVM library for high-performance code generation." 18 | "project-github", githubLink 19 | "project-nuget", "http://nuget.com/packages/FSHlvm" ] 20 | 21 | // -------------------------------------------------------------------------------------- 22 | // For typical project, no changes are needed below 23 | // -------------------------------------------------------------------------------------- 24 | 25 | #I "../../packages/FSharp.Formatting.2.4.1/lib/net40" 26 | #I "../../packages/RazorEngine.3.3.0/lib/net40" 27 | #I "../../packages/FSharp.Compiler.Service.0.0.36/lib/net40" 28 | #r "../../packages/Microsoft.AspNet.Razor.2.0.30506.0/lib/net40/System.Web.Razor.dll" 29 | #r "../../packages/FAKE/tools/NuGet.Core.dll" 30 | #r "../../packages/FAKE/tools/FakeLib.dll" 31 | #r "RazorEngine.dll" 32 | #r "FSharp.Literate.dll" 33 | #r "FSharp.CodeFormat.dll" 34 | #r "FSharp.MetadataFormat.dll" 35 | #r "FSharp.Markdown.dll" 36 | open Fake 37 | open System.IO 38 | open Fake.FileHelper 39 | open FSharp.Literate 40 | open FSharp.MetadataFormat 41 | 42 | // When called from 'build.fsx', use the public project URL as 43 | // otherwise, use the current 'output' directory. 44 | #if RELEASE 45 | let root = website 46 | #else 47 | let root = "file://" + (__SOURCE_DIRECTORY__ @@ "../output") 48 | #endif 49 | 50 | // Paths with template/source/output locations 51 | let bin = __SOURCE_DIRECTORY__ @@ "../../bin/Release" //might not work in the future 52 | let content = __SOURCE_DIRECTORY__ @@ "../content" 53 | let output = __SOURCE_DIRECTORY__ @@ "../output" 54 | let files = __SOURCE_DIRECTORY__ @@ "../files" 55 | let templates = __SOURCE_DIRECTORY__ @@ "templates" 56 | let formatting = __SOURCE_DIRECTORY__ @@ "../../packages/FSharp.Formatting.2.4.1/" 57 | let docTemplate = formatting @@ "templates/docpage.cshtml" 58 | 59 | // Where to look for *.csproj templates (in this order) 60 | let layoutRoots = 61 | [ templates; formatting @@ "templates" 62 | formatting @@ "templates/reference" ] 63 | 64 | // Copy static files and CSS + JS from F# Formatting 65 | let copyFiles () = 66 | CopyRecursive files output true |> Log "Copying file: " 67 | ensureDirectory (output @@ "content") 68 | CopyRecursive (formatting @@ "styles") (output @@ "content") true 69 | |> Log "Copying styles and scripts: " 70 | 71 | // Build API reference from XML comments 72 | let buildReference () = 73 | CleanDir (output @@ "reference") 74 | for lib in referenceBinaries do 75 | MetadataFormat.Generate 76 | ( bin @@ lib, output @@ "reference", layoutRoots, 77 | parameters = ("root", root)::info, 78 | publicOnly = true ) 79 | 80 | // Build documentation from `fsx` and `md` files in `docs/content` 81 | let buildDocumentation () = 82 | let subdirs = Directory.EnumerateDirectories(content, "*", SearchOption.AllDirectories) 83 | for dir in Seq.append [content] subdirs do 84 | let sub = if dir.Length > content.Length then dir.Substring(content.Length + 1) else "." 85 | Literate.ProcessDirectory 86 | ( dir, docTemplate, output @@ sub, replacements = ("root", root)::info, 87 | layoutRoots = layoutRoots, fsiEvaluator = new FsiEvaluator(), lineNumbers=false ) 88 | 89 | // Generate 90 | copyFiles() 91 | buildDocumentation() 92 | //buildReference() 93 | -------------------------------------------------------------------------------- /docs/tools/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /docs/tools/templates/template.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | @Title 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | 23 |
24 |
25 | 29 |

@Properties["project-name"]

30 |
31 |
32 |
33 |
34 | @RenderBody() 35 |
36 |
37 | F# Project 38 | 53 |
54 |
55 |
56 | Fork me on GitHub 57 | 58 | 59 | -------------------------------------------------------------------------------- /lib/FSLLVM.LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2020, Zoltan Podlovics, KP-Tech Kft. All Rights Reserved. 2 | 3 | University of Illinois/NCSA 4 | Open Source License 5 | 6 | Developed by: 7 | 8 | Zoltan Podlovics 9 | 10 | https://github.com/kp-tech/fshlvm 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining a copy of 13 | this software and associated documentation files (the "Software"), to deal with 14 | the Software without restriction, including without limitation the rights to 15 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 16 | of the Software, and to permit persons to whom the Software is furnished to do 17 | so, subject to the following conditions: 18 | 19 | * Redistributions of source code must retain the above copyright notice, 20 | this list of conditions and the following disclaimers. 21 | 22 | * Redistributions in binary form must reproduce the above copyright notice, 23 | this list of conditions and the following disclaimers in the 24 | documentation and/or other materials provided with the distribution. 25 | 26 | * Neither the names of fshlvm, nor the names of its contributors may be used to 27 | endorse or promote products derived from this Software without specific 28 | prior written permission. 29 | 30 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 32 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE 36 | SOFTWARE. 37 | 38 | This file incorporates work covered by the following copyright and 39 | permission notice: 40 | 41 | University of Illinois/NCSA 42 | Open Source License 43 | 44 | Copyright (c) 2011 Keith Sheppard. 45 | All rights reserved. 46 | 47 | Developed by: 48 | 49 | Keith Sheppard 50 | 51 | https://github.com/keithshep/llvm-fs 52 | 53 | Permission is hereby granted, free of charge, to any person obtaining a copy of 54 | this software and associated documentation files (the "Software"), to deal with 55 | the Software without restriction, including without limitation the rights to 56 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 57 | of the Software, and to permit persons to whom the Software is furnished to do 58 | so, subject to the following conditions: 59 | 60 | * Redistributions of source code must retain the above copyright notice, 61 | this list of conditions and the following disclaimers. 62 | 63 | * Redistributions in binary form must reproduce the above copyright notice, 64 | this list of conditions and the following disclaimers in the 65 | documentation and/or other materials provided with the distribution. 66 | 67 | * Neither the names of llvm-fs, nor the names of its contributors may be used to 68 | endorse or promote products derived from this Software without specific 69 | prior written permission. 70 | 71 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 72 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 73 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 74 | CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 75 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 76 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE 77 | SOFTWARE. 78 | 79 | -------------------------------------------------------------------------------- /lib/FSLLVM.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kp-tech/fshlvm/0c129bd5a531be1cfb95fcdeb4b91dc41716b666/lib/FSLLVM.dll -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export FSHLVM_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 3 | sh $FSHLVM_HOME/build.sh 4 | cd $FSHLVM_HOME 5 | dotnet run -c Release --project $FSHLVM_HOME/src/FSHlvm.Cli/FSHlvm.Cli.fsproj 6 | mv $FSHLVM_HOME/list.bc $FSHLVM_HOME/bin/ 7 | opt-3.8 -tailcallelim -O3 < $FSHLVM_HOME/bin/list.bc > $FSHLVM_HOME/bin/listopt.bc 8 | clang-3.8 -o $FSHLVM_HOME/bin/listopt $FSHLVM_HOME/bin/listopt.bc -ldl 9 | ln -sfn $FSHLVM_HOME/lib/libfshlvmllvmwrapper.so $FSHLVM_HOME/bin/ 10 | ln -sfn $FSHLVM_HOME/lib/libfshlvmruntime.so $FSHLVM_HOME/bin/ 11 | cd $FSHLVM_HOME/bin 12 | ./listopt 13 | cd $FSHLVM_HOME 14 | -------------------------------------------------------------------------------- /src/FSHlvm.Cli/AssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // Copyright (c) 2014-2020, Zoltan Podlovics, KP-Tech Kft. All Rights Reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0. See LICENSE.md in the 5 | // project root for license information. 6 | // --------------------------------------------------------------------------- 7 | namespace System 8 | open System.Reflection 9 | 10 | [] 11 | [] 12 | [] 13 | [] 14 | [] 15 | [] 16 | [] 17 | do () 18 | 19 | module internal AssemblyVersionInformation = 20 | let [] Version = "2.0" 21 | -------------------------------------------------------------------------------- /src/FSHlvm.Cli/FSHlvm.Cli.fsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/FSHlvm.Cli/Program.fs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // Copyright (c) 2014-2020, Zoltan Podlovics, KP-Tech Kft. All Rights Reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0. See LICENSE.md in the 5 | // project root for license information. 6 | // --------------------------------------------------------------------------- 7 | // This file incorporates work covered by the following copyright and 8 | // permission notice: 9 | // --------------------------------------------------------------------------- 10 | // Portions of Copyright (c) 2009, Jon Harrop, Flying Frog Consultancy Ltd. 11 | // All rights reserved. 12 | // 13 | // Redistribution and use in source and binary forms, with or without 14 | // modification, are permitted provided that the following conditions 15 | // are met: 16 | // 17 | // 1. Redistributions of source code must retain the above copyright 18 | // notice, this list of conditions and the following disclaimer. 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 | // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // --------------------------------------------------------------------------- 34 | 35 | module KPTech.FSHlvm.Main.Program 36 | 37 | open KPTech.FSHlvm.Core 38 | 39 | open Type 40 | open Expr 41 | open RLType 42 | open System.IO 43 | 44 | /// 45 | /// sample program 46 | /// 47 | let tyList ty = 48 | [ TLType("Cons", TStruct[ty; TReference]); 49 | TLType("Nil", TUnit) ] 50 | 51 | let nil = Construct("Nil", Unit) 52 | let cons h t = Construct("Cons", Struct[h; t]) 53 | 54 | (** Pattern match over empty or non-empty list. *) 55 | let condList list h t kNil kCons = 56 | If(IsType(Var list, "Nil"), kNil, 57 | Let(h+t, Cast(Var list, "Cons"), 58 | Let(h, GetValue(Var (h+t), 0), 59 | Let(t, GetValue(Var (h+t), 1), 60 | kCons)))) 61 | 62 | (** Polymorphic List.fold_left in HLVM. *) 63 | let listFoldLeft a b = 64 | TLFunction("List.foldLeft", ["f", TFunction([a; b], a); 65 | "x", a; 66 | "list", TReference], a, 67 | condList "list" "h" "t" 68 | (Var "x") 69 | (Apply(Var "List.foldLeft", 70 | [Var "f"; 71 | Apply(Var "f", [Var "x"; Var "h"]); 72 | Var "t"]))) 73 | 74 | let list ns = 75 | tyList TInt @ 76 | [ TLFunction("add", ["n", TInt; "m", TInt], TInt, 77 | compound[ 78 | Var "n" +. Var "m"]); 79 | 80 | TLFunction("List.init", ["t", TReference; "n", TInt], TReference, 81 | Let("t", cons (Var "n") (Var "t"), 82 | If(Var "n" =. Int 0L, Var "t", 83 | Apply(Var "List.init", [Var "t"; Var "n" -. Int 1L])))) 84 | 85 | listFoldLeft TInt TInt; 86 | 87 | TLExpr(Apply(Var "List.init", [nil; Int 10L])) ] @ 88 | List.map 89 | (fun n -> 90 | TLExpr 91 | (compound 92 | [ Printf("\nList.init and fold over %d elements\n", [Int n]); 93 | Let("list", Apply(Var "List.init", [nil; Int n]), 94 | Apply(Var "List.foldLeft", 95 | [Var "add"; Int 0L; Var "list"])) ])) 96 | ns 97 | 98 | [] 99 | let main argv = 100 | printfn "Args: %A" argv 101 | let main (args:string array) = 102 | let printUsage () = 103 | printfn "About: FSHlvm example program (list)" 104 | printfn "Usage: FSHlvm.Main options" 105 | printfn "Possible options:" 106 | printfn "--enable-debug enable debugging (default: disabled)" 107 | printfn "--enable-jit enable execute the code (default: disabled)" 108 | printfn "--enable-view-functions enable view function definitions as a graph using llvm internal function viewer (default: disabled)" 109 | printfn "--disable-shadow-stack disable shadow stack (default: enabled)" 110 | printfn "--disable-gc disable garbage collector (default: enabled)" 111 | printfn "--disable-tco disable tail call elimination (default: enabled)" 112 | printfn "--set-target set target architecture (default: x86_64-pc-linux-gnu)" 113 | 114 | let rec parseCommandLineRec argList = 115 | match argList with 116 | | [] -> () 117 | | "--help"::xs -> printUsage (); exit(0); 118 | | "--enable-debug"::xs -> Options.Debug := true 119 | | "--enable-jit"::xs -> Options.CompileOnly := false 120 | | "--enable-view-functions"::xs -> Options.View := true 121 | | "--disable-shadow-stack"::xs -> 122 | printfn "Shadow stack and GC disabled"; 123 | Options.ShadowStackEnabled := false; 124 | Options.GcEnabled := false 125 | | "--disable-gc"::xs -> 126 | printfn "GC disabled."; 127 | Options.GcEnabled := false 128 | | "--disable-stack-handler"::xs -> 129 | printfn "Stack handler disabled."; 130 | Options.StackHandler := false 131 | | "--disable-tco"::xs -> 132 | printfn "Tail call elimination disabled."; 133 | Options.Tco := false 134 | | "--set-target"::t::xs -> 135 | printfn "Set target architecture to: %s" t; 136 | Options.Target := t 137 | | x::xs -> 138 | eprintfn "Option '%s' is unrecognized" x 139 | parseCommandLineRec xs in 140 | parseCommandLineRec (List.ofArray args) 141 | createEval "list.bc" (list [10L]); 142 | 143 | main argv 144 | 145 | 0 // return an integer exit code 146 | -------------------------------------------------------------------------------- /src/FSHlvm.Cli/libfshlvmllvmwrapper.so: -------------------------------------------------------------------------------- 1 | ../../lib/libfshlvmllvmwrapper.so -------------------------------------------------------------------------------- /src/FSHlvm.Cli/libfshlvmruntime.so: -------------------------------------------------------------------------------- 1 | ../../lib/libfshlvmruntime.so -------------------------------------------------------------------------------- /src/FSHlvm.Core/AssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // Copyright (c) 2014-2020, Zoltan Podlovics, KP-Tech Kft. All Rights Reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0. See LICENSE.md in the 5 | // project root for license information. 6 | // --------------------------------------------------------------------------- 7 | 8 | namespace System 9 | open System.Reflection 10 | 11 | [] 12 | [] 13 | [] 14 | [] 15 | [] 16 | [] 17 | [] 18 | do () 19 | 20 | module internal AssemblyVersionInformation = 21 | let [] Version = "2.0" 22 | -------------------------------------------------------------------------------- /src/FSHlvm.Core/FSHlvm.Core.fsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netcoreapp2.0 4 | portable 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/FSHlvm.Core/HashMultiMap.fs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // Copyright (c) 2014-2020, Zoltan Podlovics, KP-Tech Kft. All Rights Reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0. See LICENSE.md in the 5 | // project root for license information. 6 | // --------------------------------------------------------------------------- 7 | // This file incorporates work covered by the following copyright and 8 | // permission notice: 9 | // --------------------------------------------------------------------------- 10 | // Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 11 | // --------------------------------------------------------------------------- 12 | namespace KPTech.FSHlvm.Collections 13 | 14 | open System 15 | open System.Collections.Generic 16 | open Microsoft.FSharp.Collections 17 | 18 | // Each entry in the HashMultiMap dictionary has at least one entry. Under normal usage each entry has _only_ 19 | // one entry. So use two hash tables: one for the main entries and one for the overflow. 20 | [] 21 | type HashMultiMap<'Key,'Value>(n: int, hasheq: IEqualityComparer<'Key>) = 22 | let firstEntries = Dictionary<_,_>(n,hasheq) 23 | let rest = Dictionary<_,_>(3,hasheq) 24 | 25 | new (hasheq : IEqualityComparer<'Key>) = HashMultiMap<'Key,'Value>(11, hasheq) 26 | new (seq : seq<'Key * 'Value>, hasheq : IEqualityComparer<'Key>) as x = 27 | new HashMultiMap<'Key,'Value>(11, hasheq) 28 | then seq |> Seq.iter (fun (k,v) -> x.Add(k,v)) 29 | 30 | member x.GetRest(k) = 31 | let mutable res = [] 32 | let ok = rest.TryGetValue(k,&res) 33 | if ok then res else [] 34 | 35 | member x.Add(y,z) = 36 | let mutable res = Unchecked.defaultof<'Value> 37 | let ok = firstEntries.TryGetValue(y,&res) 38 | if ok then 39 | rest.[y] <- res :: x.GetRest(y) 40 | firstEntries.[y] <- z 41 | 42 | member x.Clear() = 43 | firstEntries.Clear() 44 | rest.Clear() 45 | 46 | member x.FirstEntries = firstEntries 47 | member x.Rest = rest 48 | member x.Copy() = 49 | let res = HashMultiMap<'Key,'Value>(firstEntries.Count,firstEntries.Comparer) 50 | for kvp in firstEntries do 51 | res.FirstEntries.Add(kvp.Key,kvp.Value) 52 | 53 | for kvp in rest do 54 | res.Rest.Add(kvp.Key,kvp.Value) 55 | res 56 | 57 | member x.Item 58 | with get(y : 'Key) = 59 | let mutable res = Unchecked.defaultof<'Value> 60 | let ok = firstEntries.TryGetValue(y,&res) 61 | if ok then res else raise (KeyNotFoundException("The item was not found in collection")) 62 | and set (y:'Key) (z:'Value) = 63 | x.Replace(y,z) 64 | 65 | member x.FindAll(y) = 66 | let mutable res = Unchecked.defaultof<'Value> 67 | let ok = firstEntries.TryGetValue(y,&res) 68 | if ok then res :: x.GetRest(y) else [] 69 | 70 | member x.Fold f acc = 71 | let mutable res = acc 72 | for kvp in firstEntries do 73 | res <- f kvp.Key kvp.Value res 74 | match x.GetRest(kvp.Key) with 75 | | [] -> () 76 | | rest -> 77 | for z in rest do 78 | res <- f kvp.Key z res 79 | res 80 | 81 | member x.Iterate(f) = 82 | for kvp in firstEntries do 83 | f kvp.Key kvp.Value 84 | match x.GetRest(kvp.Key) with 85 | | [] -> () 86 | | rest -> 87 | for z in rest do 88 | f kvp.Key z 89 | 90 | member x.Contains(y) = firstEntries.ContainsKey(y) 91 | 92 | member x.ContainsKey(y) = firstEntries.ContainsKey(y) 93 | 94 | member x.Remove(y) = 95 | let mutable res = Unchecked.defaultof<'Value> 96 | let ok = firstEntries.TryGetValue(y,&res) 97 | // NOTE: If not ok then nothing to remove - nop 98 | if ok then 99 | // We drop the FirstEntry. Here we compute the new FirstEntry and residue MoreEntries 100 | let mutable res = [] 101 | let ok = rest.TryGetValue(y,&res) 102 | if ok then 103 | match res with 104 | | [h] -> 105 | firstEntries.[y] <- h; 106 | rest.Remove(y) |> ignore 107 | | (h::t) -> 108 | firstEntries.[y] <- h 109 | rest.[y] <- t 110 | | _ -> 111 | () 112 | else 113 | firstEntries.Remove(y) |> ignore 114 | 115 | member x.Replace(y,z) = 116 | firstEntries.[y] <- z 117 | 118 | member x.TryFind(y) = 119 | let mutable res = Unchecked.defaultof<'Value> 120 | let ok = firstEntries.TryGetValue(y,&res) 121 | if ok then Some(res) else None 122 | 123 | member x.Count = firstEntries.Count 124 | 125 | interface IEnumerable> with 126 | member s.GetEnumerator() = 127 | let elems = List<_>(firstEntries.Count + rest.Count) 128 | for kvp in firstEntries do 129 | elems.Add(kvp) 130 | for z in s.GetRest(kvp.Key) do 131 | elems.Add(KeyValuePair(kvp.Key, z)) 132 | (elems.GetEnumerator() :> IEnumerator<_>) 133 | 134 | interface System.Collections.IEnumerable with 135 | member s.GetEnumerator() = ((s :> seq<_>).GetEnumerator() :> System.Collections.IEnumerator) 136 | 137 | interface IDictionary<'Key, 'Value> with 138 | member s.Item 139 | with get x = s.[x] 140 | and set x v = s.[x] <- v 141 | 142 | member s.Keys = ([| for kvp in s -> kvp.Key |] :> ICollection<'Key>) 143 | member s.Values = ([| for kvp in s -> kvp.Value |] :> ICollection<'Value>) 144 | member s.Add(k,v) = s.[k] <- v 145 | member s.ContainsKey(k) = s.ContainsKey(k) 146 | member s.TryGetValue(k,r) = if s.ContainsKey(k) then (r <- s.[k]; true) else false 147 | member s.Remove(k:'Key) = 148 | let res = s.ContainsKey(k) in 149 | s.Remove(k); res 150 | 151 | interface ICollection> with 152 | member s.Add(x) = s.[x.Key] <- x.Value 153 | member s.Clear() = s.Clear() 154 | member s.Remove(x) = 155 | let res = s.ContainsKey(x.Key) 156 | if res && Unchecked.equals s.[x.Key] x.Value then 157 | s.Remove(x.Key); 158 | res 159 | member s.Contains(x) = 160 | s.ContainsKey(x.Key) && 161 | Unchecked.equals s.[x.Key] x.Value 162 | member s.CopyTo(arr,arrIndex) = s |> Seq.iteri (fun j x -> arr.[arrIndex+j] <- x) 163 | member s.IsReadOnly = false 164 | member s.Count = s.Count 165 | 166 | 167 | -------------------------------------------------------------------------------- /src/FSHlvm.Runtime/Makefile: -------------------------------------------------------------------------------- 1 | all: libfshlvmruntime.so libfshlvmllvmwrapper.so 2 | 3 | clean: 4 | rm -f libfshlvmruntime.so libfshlvmllvmwrapper.so 5 | 6 | libfshlvmruntime.so: runtime.cpp 7 | g++ -pg -pthread -Wall -O3 -fPIC -shared -std=c++11 runtime.cpp -o libfshlvmruntime.so 8 | 9 | libfshlvmllvmwrapper.so: llvm.cpp 10 | g++ -I /usr/lib/llvm-10/include -L /usr/lib/llvm-10/lib -lLLVM-10 -pg -pthread -Wall -O3 -fPIC -shared -std=c++11 llvm.cpp -o libfshlvmllvmwrapper.so 11 | 12 | DESTDIR = ../../lib 13 | install: libfshlvmruntime.so libfshlvmllvmwrapper.so 14 | install libfshlvmruntime.so $(DESTDIR) 15 | install libfshlvmllvmwrapper.so $(DESTDIR) 16 | 17 | .PHONY: clean all 18 | -------------------------------------------------------------------------------- /src/FSHlvm.Runtime/llvm.cpp: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // Copyright (c) 2014-2017, Zoltan Podlovics, KP-Tech Kft. All Rights Reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0. See LICENSE.md in the 5 | // project root for license information. 6 | // --------------------------------------------------------------------------- 7 | // This file incorporates work covered by the following copyright and 8 | // permission notice: 9 | // --------------------------------------------------------------------------- 10 | // Portions of Copyright (c) 2009, Jon Harrop, Flying Frog Consultancy Ltd. 11 | // All rights reserved. 12 | // 13 | // Redistribution and use in source and binary forms, with or without 14 | // modification, are permitted provided that the following conditions 15 | // are met: 16 | // 17 | // 1. Redistributions of source code must retain the above copyright 18 | // notice, this list of conditions and the following disclaimer. 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 | // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // --------------------------------------------------------------------------- 34 | 35 | //#include "llvm/Target/TargetOptions.h" 36 | #include "llvm/Support/PrettyStackTrace.h" 37 | #include 38 | 39 | extern "C" { 40 | using namespace std; 41 | 42 | void hlvmEnableTailCallOpt() { 43 | cout << "Enabling LLVM.TCO" << endl; 44 | } 45 | } 46 | 47 | extern "C" void 48 | fshlvm_llvm_enable_tailcall_optimization(void) 49 | { 50 | cout << "Enabling LLVM.TCO2" << endl; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/FSHlvm.Runtime/runtime.cpp: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // Copyright (c) 2014-2017, Zoltan Podlovics, KP-Tech Kft. All Rights Reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0. See LICENSE.md in the 5 | // project root for license information. 6 | // --------------------------------------------------------------------------- 7 | // This file incorporates work covered by the following copyright and 8 | // permission notice: 9 | // --------------------------------------------------------------------------- 10 | // Portions of Copyright (c) 2009, Jon Harrop, Flying Frog Consultancy Ltd. 11 | // All rights reserved. 12 | // 13 | // Redistribution and use in source and binary forms, with or without 14 | // modification, are permitted provided that the following conditions 15 | // are met: 16 | // 17 | // 1. Redistributions of source code must retain the above copyright 18 | // notice, this list of conditions and the following disclaimer. 19 | // 2. Redistributions in binary form must reproduce the above copyright 20 | // notice, this list of conditions and the following disclaimer in the 21 | // documentation and/or other materials provided with the distribution. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 | // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // --------------------------------------------------------------------------- 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | using namespace std; 43 | 44 | pthread_mutex_t mutex; 45 | map sizes; 46 | 47 | void add_size(void *key, int val) { 48 | pthread_mutex_lock(&mutex); 49 | sizes[long(key)] = val; 50 | pthread_mutex_unlock(&mutex); 51 | } 52 | 53 | int get_size(void *key) { 54 | pthread_mutex_lock(&mutex); 55 | int size = sizes[long(key)]; 56 | pthread_mutex_unlock(&mutex); 57 | return size; 58 | } 59 | 60 | extern "C" { 61 | const bool debug = false; 62 | 63 | void *fshlvm_alloc(int n, int m) { 64 | if (debug) 65 | printf("fshlvm_alloc(%d, %d)\n", n, m); 66 | if (n*m == 0) { 67 | if (debug) 68 | printf("fshlvm_alloc(%d, %d) -> %p\n", n, m, (void *)NULL); 69 | return 0; 70 | } 71 | //void *data = calloc(n, m); 72 | void *data = malloc(n*m); 73 | if (data == 0) { 74 | printf("Out of memory\n"); 75 | exit(1); 76 | } 77 | if (debug) 78 | printf("fshlvm_alloc(%d, %d) -> %p\n", n, m, data); 79 | if (debug) 80 | add_size(data, n*m); 81 | return data; 82 | } 83 | 84 | void fshlvm_free(void *data) { 85 | if (data != 0) { 86 | int size = 0; 87 | if (debug) 88 | size = get_size(data); 89 | if (debug) 90 | sizes.erase(long(data)); 91 | free(data); 92 | } 93 | } 94 | 95 | pthread_attr_t attr; 96 | pthread_key_t key; 97 | __thread void *local; 98 | 99 | void fshlvm_init() { 100 | if (debug) { 101 | printf("fshlvm_init()\n"); 102 | printf("Initializing pthread attribute...\n"); 103 | } 104 | pthread_attr_init(&attr); 105 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); 106 | if (debug) 107 | printf("Creating pthread key...\n"); 108 | key = pthread_key_create(&key, NULL); 109 | pthread_mutex_init(&mutex, NULL); 110 | if (debug) 111 | printf("fshlvm_init() ends\n"); 112 | } 113 | 114 | void *fshlvm_create_thread(void *(*f)(void *), void *x) { 115 | if (debug) 116 | printf("fshlvm_create_thread(%p, %p)\n", f, x); 117 | pthread_t *thread = (pthread_t *)fshlvm_alloc(1, sizeof(pthread_t)); 118 | pthread_create(thread, &attr, f, x); 119 | if (debug) 120 | printf("fshlvm_create_thread(%p, %p) -> %p\n", f, x, thread); 121 | return (void *)thread; 122 | } 123 | 124 | void fshlvm_join_thread(pthread_t *thread) { 125 | if (debug) 126 | printf("fshlvm_join_thread(%p)\n", thread); 127 | pthread_join(*thread, NULL); 128 | fshlvm_free(thread); 129 | if (debug) 130 | printf("fshlvm_join_thread(%p) done\n", thread); 131 | } 132 | 133 | void *fshlvm_create_mutex() { 134 | if (debug) 135 | printf("fshlvm_create_mutex()\n"); 136 | pthread_mutex_t *mutex = 137 | (pthread_mutex_t *)fshlvm_alloc(1, sizeof(pthread_mutex_t)); 138 | pthread_mutex_init(mutex, NULL); 139 | if (debug) 140 | printf("fshlvm_create_mutex() -> %p\n", mutex); 141 | return (void *)mutex; 142 | } 143 | 144 | void fshlvm_lock_mutex(pthread_mutex_t *mutex) { 145 | if(debug) 146 | printf("fshlvm_lock_mutex()\n"); 147 | pthread_mutex_lock(mutex); 148 | } 149 | 150 | void fshlvm_unlock_mutex(pthread_mutex_t *mutex) { 151 | if(debug) 152 | printf("fshlvm_unlock_mutex()\n"); 153 | pthread_mutex_unlock(mutex); 154 | } 155 | 156 | void *fshlvm_get_thread_local() { 157 | void *tl = pthread_getspecific(key); 158 | if(debug) 159 | printf("fshlvm_get_thread_local() -> %p\n", tl); 160 | return tl; 161 | } 162 | 163 | void fshlvm_set_thread_local(void *ptr) { 164 | if (debug) 165 | printf("fshlvm_set_thread_local(%p)\n", ptr); 166 | pthread_setspecific(key, ptr); 167 | if (debug) 168 | printf("fshlvm_set_thread_local(%p) done\n", ptr); 169 | } 170 | 171 | // If *ptr is oldval then replace with newval, returning the old *ptr 172 | int fshlvm_cas(int *ptr, int oldval, int newval) { 173 | return __sync_val_compare_and_swap(ptr, oldval, newval); 174 | } 175 | 176 | double fshlvm_time() { 177 | struct timeval t; 178 | gettimeofday(&t, NULL); 179 | return (double)t.tv_sec + 1e-6 * (double)t.tv_usec; 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /tests/FSHlvm.Core.Tests/AssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // Copyright (c) 2014-2017, Zoltan Podlovics, KP-Tech Kft. All Rights Reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0. See LICENSE.md in the 5 | // project root for license information. 6 | // --------------------------------------------------------------------------- 7 | 8 | 9 | module KPTech.FSHlvm.Tests.AssemblyInfo 10 | open System.Reflection 11 | open System.Runtime.CompilerServices 12 | 13 | [] 14 | [] 15 | [] 16 | [] 17 | [] 18 | [] 19 | [] 20 | 21 | // The assembly version has the format {Major}.{Minor}.{Build}.{Revision} 22 | 23 | [] 24 | 25 | //[] 26 | //[] 27 | 28 | () 29 | 30 | -------------------------------------------------------------------------------- /tests/FSHlvm.Core.Tests/FSCheckRunner.fs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // Copyright (c) 2014-2017, Zoltan Podlovics, KP-Tech Kft. All Rights Reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0. See LICENSE.md in the 5 | // project root for license information. 6 | // --------------------------------------------------------------------------- 7 | // This module is based on FSharpx unit tests which is also licensed under 8 | // Apache License 2.0. 9 | // --------------------------------------------------------------------------- 10 | 11 | module KPTech.FSHlvm.Tests.FsCheck 12 | 13 | open FsCheck 14 | open NUnit.Framework 15 | 16 | let private nUnitRunner = 17 | { new IRunner with 18 | member x.OnStartFixture t = () 19 | member x.OnArguments(ntest, args, every) = () 20 | member x.OnShrink(args, everyShrink) = () 21 | member x.OnFinished(name, result) = 22 | match result with 23 | | TestResult.True data -> 24 | printfn "%s" (Runner.onFinishedToString name result) 25 | | _ -> Assert.Fail(Runner.onFinishedToString name result) } 26 | 27 | let private nUnitConfig = { Config.Default with Runner = nUnitRunner } 28 | 29 | let fsCheck name testable = 30 | FsCheck.Check.One (name, nUnitConfig, testable) 31 | 32 | module Gen = 33 | let ap x = Gen.apply x 34 | -------------------------------------------------------------------------------- /tests/FSHlvm.Core.Tests/FSHlvm.Core.Tests.fsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netcoreapp3.1 4 | false 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | all 23 | runtime; build; native; contentfiles; analyzers 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /tests/FSHlvm.Core.Tests/FSHlvmTest.fs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // Copyright (c) 2014-2017, Zoltan Podlovics, KP-Tech Kft. All Rights Reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0. See LICENSE.md in the 5 | // project root for license information. 6 | // --------------------------------------------------------------------------- 7 | // This work is based HLVM, written by Jon Harrop, Flying Frog Consultancy Ltd. 8 | // --------------------------------------------------------------------------- 9 | // Portions of Copyright (c) 2009, Jon Harrop, Flying Frog Consultancy Ltd. 10 | // All rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions 14 | // are met: 15 | // 16 | // 1. Redistributions of source code must retain the above copyright 17 | // notice, this list of conditions and the following disclaimer. 18 | // 2. Redistributions in binary form must reproduce the above copyright 19 | // notice, this list of conditions and the following disclaimer in the 20 | // documentation and/or other materials provided with the distribution. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 | // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 | // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 | // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | // --------------------------------------------------------------------------- 33 | 34 | module KPTech.FSHlvm.Core.Tests.FSHlvmTest 35 | 36 | open System 37 | open Xunit 38 | open FsUnit 39 | 40 | open Printf 41 | open KPTech.FSHlvm.Core 42 | 43 | open Type 44 | open Expr 45 | open RLType 46 | 47 | let testEval name defs = createEval name defs 48 | 49 | let ( |> ) x f = f x 50 | let floatOfInt x = FloatOfInt(EFloat.Float64, x) 51 | 52 | let nil = Construct("Nil", Unit) 53 | 54 | let fill ty = 55 | [TLFunction 56 | ("fill", [ "a", TArray ty; 57 | "x", ty; 58 | "i", TInt ], TUnit, 59 | If(Var "i" <. Length(Var "a"), 60 | compound 61 | [ Set(Var "a", Var "i", Var "x"); 62 | Apply(Var "fill", [Var "a"; Var "x"; Var "i" +. Int 1L]) ], 63 | Unit))] 64 | 65 | // Note: Run only one test case at a time (!), because FSHlvm require proper inicialization, and the compiler also has internal mutable state 66 | //opt-3.8 -tailcallelim -O3 aoutopt.bc 67 | //llc-3.8 -tailcallopt aoutopt.bc -o aoutopt.s 68 | //g++ -g aoutopt.s -lsigsegv -ldl -lm -o aoutopt 69 | // 70 | //OR 71 | // 72 | //opt-3.8 -tailcallelim -O3 aoutopt.bc 73 | //clang -o aoutopt aoutopt.bc -ldl 74 | 75 | type public exprTests() = 76 | 77 | [] 78 | [] 79 | member x.``exprPrintfIntN`` n = 80 | let exprPrintfIntN n = 81 | [TLExpr 82 | (compound 83 | [ Printf("\exprPrintfIntN: (%d)\n", [Int n]) ] )] in 84 | 85 | testEval "exprPrintfIntN.bc" (exprPrintfIntN n); 86 | shouldEqual true true; 87 | 88 | [] 89 | [] 90 | member x.``exprPrintfIntNM`` n m = 91 | let exprPrintfIntNM n m = 92 | [TLExpr 93 | (compound 94 | [ Printf("\exprPrintfIntNM: (%d) (%d)\n", [Int n; Int m]) ] )] in 95 | 96 | testEval "exprPrintfIntNM.bc" (exprPrintfIntNM n m); 97 | shouldEqual true true; 98 | 99 | 100 | [] 101 | [] 102 | member x.``exprPrintfFloatN`` n = 103 | let exprPrintfFloatN n = 104 | [TLExpr 105 | (compound 106 | [ Printf("\exprPrintfFloatN: (%f)\n", [Float64 n]) ] )] in 107 | 108 | testEval "exprPrintfFloatN.bc" (exprPrintfFloatN n); 109 | shouldEqual true true; 110 | 111 | [] 112 | [] 113 | member x.``exprLetVarPrintfIntN`` n = 114 | let exprLetVarPrintfIntN n = 115 | [TLExpr 116 | (compound 117 | [Let("n", Int n, 118 | Printf("\exprLetVarPrintfIntN: (%d)\n", [Var "n"]))] )] in 119 | 120 | testEval "exprLetVarPrintfIntN.bc" (exprLetVarPrintfIntN n); 121 | shouldEqual true true; 122 | 123 | 124 | [] 125 | [] 126 | member x.``exprSumNM`` n m = 127 | let exprSumNM n m = 128 | [TLExpr 129 | (compound 130 | [Let("n", Int n, 131 | Let("m", Int m, 132 | Let("r", Var "n" +. Var "m", 133 | Printf("\exprSumNM: (%d)\n", [Var("r")])))) ] )] in 134 | 135 | testEval "exprSumNM.bc" (exprSumNM n m); 136 | shouldEqual true true; 137 | 138 | [] 139 | [] 140 | member x.``exprArrayAllocNM`` n m = 141 | let exprArrayAllocNM n m = 142 | [TLExpr 143 | (compound 144 | [Let("n", Alloc(Int n, Int m), 145 | Printf("\exprArrayAllocNM: (%d) (%d)\n", [Int n; Int m])) ] )] in 146 | 147 | testEval "exprArrayAllocNM.bc" (exprArrayAllocNM n m); 148 | shouldEqual true true; 149 | 150 | [] 151 | member x.``funIntAddNM`` () = 152 | let funIntAddNM n m = 153 | let nVar = Var "n" in 154 | let mVar = Var "m" in 155 | [TLFunction 156 | ("funIntAddNM", ["n", TInt; "m", TInt], TInt, 157 | nVar +. mVar) ] @ 158 | [TLExpr 159 | (compound 160 | [ Let("r", 161 | Apply(Var "funIntAddNM", [Int n; Int m]), 162 | Printf("\nInteger add function: funIntAddNM (%d) (%d): %d\n", [Int n; Int m; Var "r"])) 163 | ] )] 164 | 165 | testEval "funIntAddNM.bc" (funIntAddNM 1L 2L); 166 | shouldEqual true true; 167 | 168 | [] 169 | member x.``funFloatAddNM`` () = 170 | let funFloatAddNM n m = 171 | let nVar = Var "n" in 172 | let mVar = Var "m" in 173 | [TLFunction 174 | ("funFloatAddNM", ["n", TFloat64; "m", TFloat64], TFloat64, 175 | nVar +. mVar) ] @ 176 | [TLExpr 177 | (compound 178 | [ Let("r", 179 | Apply(Var "funFloatAddNM", [Float64 n; Float64 m]), 180 | Printf("\nInteger add function: funIntAddNM (%f) (%f): %f\n", [Float64 n; Float64 m; Var "r"])) 181 | ] )] 182 | 183 | testEval "funFloatAddNM.bc" (funFloatAddNM 1.0 2.0); 184 | shouldEqual true true; 185 | 186 | 187 | type public applicationTests() = 188 | [] 189 | member x.``boehm`` () = 190 | let boehm = 191 | let n = 1048576L in 192 | [ TLFunction 193 | ("fill", [ "a", TArray TInt; 194 | "rand", TInt; 195 | "i", TInt ], TUnit, 196 | If(Var "i" <. Int n, 197 | compound 198 | [ Set(Var "a", Var "i", Var "rand"); 199 | Apply(Var "fill", 200 | [Var "a"; 201 | Var "rand" *. Int 1664525L +. Int 1013904223L; 202 | Var "i" +. Int 1L]) ], 203 | Unit)); 204 | 205 | TLFunction("loop", [ "i", TInt ], TUnit, 206 | If(Var "i" <. Int 1L, Unit, 207 | Let("", Alloc(Var "i", UInt8 0uy), 208 | Apply(Var "loop", [ Var "i" -. Int 1L ])))); 209 | 210 | TLExpr 211 | (compound 212 | [ Let("p", Alloc(Int n, Int 0L), 213 | compound 214 | [ Apply(Var "fill", [Var "p"; Int 1L; Int 0L]); 215 | Apply(Var "loop", [Int 32768L]) ]) ]) ] in 216 | 217 | testEval "boehm.bc" (boehm); 218 | shouldEqual true true; 219 | 220 | [] 221 | member x.``sieve`` () = 222 | 223 | (** Sieve of Eratosthenes. *) 224 | let sieve is = 225 | fill TBool @ 226 | [ TLFunction 227 | ("last", ["a", TArray TBool; "i", TInt], TInt, 228 | If(Get(Var "a", Var "i"), Var "i", 229 | Apply(Var "last", [Var "a"; Var "i" -. Int 1L]))); 230 | 231 | TLFunction 232 | ("loop2", ["a", TArray TBool; "i", TInt; "di", TInt], TUnit, 233 | If(Var "i" >=. Length(Var "a"), Unit, 234 | compound 235 | [ Set(Var "a", Var "i", Bool false); 236 | Apply(Var "loop2", 237 | [Var "a"; Var "i" +. Var "di"; Var "di"]) ])); 238 | 239 | TLFunction 240 | ("loop1", ["a", TArray TBool; "i", TInt], TUnit, 241 | If(Var "i" =. Length(Var "a"), Unit, 242 | compound 243 | [ If(Get(Var "a", Var "i"), 244 | Apply(Var "loop2", [Var "a"; Int 2L *. Var "i"; Var "i"]), 245 | Unit); 246 | Apply(Var "loop1", [Var "a"; Var "i" +. Int 1L]) ])) ] @ 247 | List.map 248 | (fun i -> 249 | TLExpr(Let("a", Alloc(Int i, Bool false), 250 | compound 251 | [ Printf("\nSieve of Eratosthenes\n", []); 252 | Apply(Var "fill", [Var "a"; Bool true; Int 0L]); 253 | Apply(Var "loop1", [Var "a"; Int 2L]); 254 | Apply(Var "last", 255 | [Var "a"; Length(Var "a") -. Int 1L]) ]))) 256 | is in 257 | testEval "sieve.bc" (sieve [1000L]); 258 | shouldEqual true true; 259 | 260 | 261 | [] 262 | member x.``fib`` () = 263 | let fib ns = 264 | let n = Var "n" in 265 | [TLFunction 266 | ("fib", ["n", TInt], TInt, 267 | If(n >. Int 1L, 268 | Apply(Var "fib", [n -. Int 2L]) +. Apply(Var "fib", [n -. Int 1L]), 269 | n)) ] @ 270 | List.map 271 | (fun n -> 272 | TLExpr 273 | (compound 274 | [ Printf("\nInteger Fibonacci function: fib(%d)\n", [Int n]); 275 | Apply(Var "fib", [Int n]) ])) 276 | ns in 277 | testEval "fib.bc" (fib [10L]); 278 | shouldEqual true true; 279 | 280 | [] 281 | member x.``ffib`` () = 282 | let ffib ns = 283 | let n = Var "n" in 284 | [TLFunction 285 | ("ffib", ["n", TFloat64], TFloat64, 286 | If(n >. Float64 1.0, 287 | Apply(Var "ffib", [n -. Float64 2.0]) +. 288 | Apply(Var "ffib", [n -. Float64 1.0]), 289 | n)) ] @ 290 | List.map 291 | (fun n -> 292 | let n = Float64 n in 293 | TLExpr 294 | (compound 295 | [ Printf("\nFloating-point Fibonacci function: fib(%f)\n", [n]); 296 | Apply(Var "ffib", [n]) ])) 297 | ns in 298 | testEval "ffib.bc" (ffib [10.0]); 299 | shouldEqual true true; 300 | 301 | [] 302 | member x.``mandelbrot`` () = 303 | let mandelbrot ns = 304 | [ TLFunction 305 | ("pixel", ["n", TInt; 306 | "zr", TFloat64; "zi", TFloat64; 307 | "cr", TFloat64; "ci", TFloat64], TUnit, 308 | If(Var "n" =. Int 65536L, Printf(" ", []), 309 | If(Var "zr" *. Var "zr" +. Var "zi" *. Var "zi" >=. Float64 4.0, 310 | Printf(".", []), 311 | Apply(Var "pixel", 312 | [Var "n" +. Int 1L; 313 | Var "zr" *. Var "zr" -. 314 | Var "zi" *. Var "zi" +. Var "cr"; 315 | Float64 2.0 *. Var "zr" *. Var "zi" +. Var "ci"; 316 | Var "cr"; Var "ci"])))); 317 | 318 | TLFunction 319 | ("row", ["i", TInt; "j", TInt; "n", TInt], TUnit, 320 | If(Var "i" >. Var "n", Unit, 321 | compound 322 | [ Apply(Var "pixel", 323 | [Int 0L; 324 | Float64 0.0; Float64 0.0; 325 | Float64 2.0 *. floatOfInt(Var "i") /. floatOfInt(Var "n") -. 326 | Float64 1.5; 327 | Float64 2.0 *. floatOfInt(Var "j") /. floatOfInt(Var "n") -. 328 | Float64 1.0]); 329 | Apply(Var "row", [Var "i" +. Int 1L; Var "j"; Var "n"])])); 330 | 331 | TLFunction 332 | ("col", ["j", TInt; "n", TInt], TUnit, 333 | If(Var "j" >. Var "n", Unit, 334 | compound 335 | [ Apply(Var "row", [Int 0L; Var "j"; Var "n"]); 336 | Printf("\n", []); 337 | Apply(Var "col", [Var "j" +. Int 1L; Var "n"])])) ] @ 338 | List.map 339 | (fun n -> 340 | TLExpr 341 | (compound 342 | [ Printf("\nMandelbrot with inline complex arithmetic\n", []); 343 | Apply(Var "col", [Int 0L; Int n]) ])) 344 | ns 345 | testEval "mandelbrot.bc" (mandelbrot [80L]); 346 | shouldEqual true true; 347 | 348 | [] 349 | member x.``mandelbrot2`` () = 350 | let mandelbrot2 ns = 351 | let complex = TStruct[TFloat64; TFloat64] in 352 | let re z = GetValue(Var z, 0) in 353 | let im z = GetValue(Var z, 1) in 354 | [ TLFunction("znorm2", ["z", complex], TFloat64, 355 | re "z" *. re "z" +. im "z" *. im "z"); 356 | 357 | TLFunction("zsqr", ["z", complex], complex, 358 | Struct[re "z" *. re "z" -. im "z" *. im "z"; 359 | Float64 2.0 *. re "z" *. im "z"]); 360 | 361 | TLFunction("zadd", ["z1", complex; "z2", complex], complex, 362 | Struct[re "z1" +. re "z2"; im "z1" +. im "z2"]); 363 | 364 | TLFunction 365 | ("pixel", ["n", TInt; "z", complex; "c", complex], TUnit, 366 | If(Var "n" =. Int 65536L, Printf(" ", []), 367 | If(Apply(Var "znorm2", [Var "z"]) >=. Float64 4.0, 368 | Printf(".", []), 369 | Apply(Var "pixel", 370 | [Var "n" +. Int 1L; 371 | Apply(Var "zadd", [Apply(Var "zsqr", [Var "z"]); Var "c"]); 372 | Var "c"])))); 373 | 374 | TLFunction 375 | ("row", ["i", TInt; "j", TInt; "n", TInt], TUnit, 376 | If(Var "i" >. Var "n", Unit, 377 | compound 378 | [ Apply(Var "pixel", 379 | [Int 0L; 380 | Struct[Float64 0.0; Float64 0.0]; 381 | Struct[Float64 2.0 *. floatOfInt(Var "i") /. 382 | floatOfInt(Var "n") -. Float64 1.5; 383 | Float64 2.0 *. floatOfInt(Var "j") /. 384 | floatOfInt(Var "n") -. Float64 1.0]]); 385 | Apply(Var "row", [Var "i" +. Int 1L; Var "j"; Var "n"])])); 386 | 387 | TLFunction 388 | ("col", ["j", TInt; "n", TInt], TUnit, 389 | If(Var "j" >. Var "n", Unit, 390 | compound 391 | [ Apply(Var "row", [Int 0L; Var "j"; Var "n"]); 392 | Printf("\n", []); 393 | Apply(Var "col", [Var "j" +. Int 1L; Var "n"])])) ] @ 394 | List.map 395 | (fun n -> 396 | TLExpr 397 | (compound 398 | [ Printf("\nMandelbrot with complex arithmetic functions\n", []); 399 | Apply(Var "col", [Int 0L; Int n]) ])) 400 | ns 401 | 402 | testEval "mandelbrot2.bc" (mandelbrot2 [80L]); 403 | shouldEqual true true; 404 | 405 | [] 406 | member x.``tco`` () = 407 | let tco n = 408 | [ TLFunction("even", ["odd", TFunction([TInt], TInt); "n", TInt], TInt, 409 | Apply(Var "odd", [Var "n" +. Int 1L])); 410 | 411 | TLFunction("odd", ["n", TInt], TInt, 412 | If(Var "n" <. Int n, 413 | Apply(Var "even", [Var "odd"; Var "n" +. Int 1L]), 414 | Var "n")); 415 | 416 | TLExpr 417 | (compound 418 | [ Printf("\nTesting TCO across a higher-order function\n", []); 419 | Apply(Var "even", [Var "odd"; Int 0L]) ])] in 420 | 421 | testEval "tco.bc" (tco 1000000000L); 422 | shouldEqual true true; 423 | 424 | [] 425 | member x.``trig`` () = 426 | let trig = 427 | let triple = TStruct[TFloat64; TFloat64; TFloat64] in 428 | [ TLExtern("sin", [TFloat64], TFloat64); 429 | 430 | TLExtern("cos", [TFloat64], TFloat64); 431 | 432 | TLFunction("test", ["f", TFunction([TFloat64], TFloat64)], triple, 433 | Struct[Apply(Var "f", [Float64 0.1]); 434 | Apply(Var "f", [Float64 0.2]); 435 | Apply(Var "f", [Float64 0.3])]); 436 | 437 | TLExpr 438 | (compound 439 | [ Printf("\nTesting FFI\n", []); 440 | Print(Apply(Var "test", [Var "sin"])); 441 | Print(Apply(Var "test", [Var "cos"])) ]) ] 442 | 443 | testEval "trig.bc" (trig); 444 | shouldEqual true true; 445 | 446 | [] 447 | member x.``fold`` () = 448 | let fold ns = 449 | let fold ty1 ty2 = 450 | [ TLFunction("Array.fold_aux", ["n", TInt; 451 | "f", TFunction([ty1; ty2], ty1); 452 | "y", ty1; 453 | "xs", TArray ty2], ty1, 454 | If(Var "n" <. Length(Var "xs"), 455 | Apply(Var "Array.fold_aux", 456 | [Var "n" +. Int 1L; 457 | Var "f"; 458 | Apply(Var "f", [Var "y"; Get(Var "xs", Var "n")]); 459 | Var "xs"]), 460 | Var "y")); 461 | 462 | TLFunction("Array.fold", ["f", TFunction([ty1; ty2], ty1); 463 | "y", ty1; 464 | "xs", TArray ty2], ty1, 465 | Apply(Var "Array.fold_aux", 466 | [Int 0L; Var "f"; Var "y"; Var "xs"])) ] 467 | in 468 | 469 | fold (TStruct[TFloat64; TFloat64]) TFloat64 @ 470 | fill TFloat64 @ 471 | [ TLFunction("f", ["x", TStruct[TFloat64; TFloat64]; 472 | "y", TFloat64], TStruct[TFloat64; TFloat64], 473 | Struct[GetValue(Var "x", 0) +. 474 | Var "y" /. (Float64 1.0 +. GetValue(Var "x", 1)); 475 | GetValue(Var "x", 1) +. Float64 1.]) ] @ 476 | List.map 477 | (fun n -> 478 | TLExpr 479 | (Let("xs", Alloc(Int n, Float64 1.0), 480 | compound 481 | [ Printf("\nArray.fold over %d elements\n", [Int n]); 482 | Apply(Var "Array.fold", 483 | [Var "f"; Struct[Float64 0.; Float64 0.]; Var "xs"]) ]))) 484 | ns 485 | 486 | testEval "fold.bc" (fold [1000L]); 487 | shouldEqual true true; 488 | 489 | 490 | 491 | [] 492 | member x.``list`` () = 493 | let tyList ty = 494 | [ TLType("Cons", TStruct[ty; TReference]); 495 | TLType("Nil", TUnit) ] 496 | 497 | let nil = Construct("Nil", Unit) 498 | let cons h t = Construct("Cons", Struct[h; t]) 499 | 500 | (** Pattern match over empty or non-empty list. *) 501 | let condList list h t kNil kCons = 502 | If(IsType(Var list, "Nil"), kNil, 503 | Let(h+t, Cast(Var list, "Cons"), 504 | Let(h, GetValue(Var (h+t), 0), 505 | Let(t, GetValue(Var (h+t), 1), 506 | kCons)))) 507 | 508 | (** Polymorphic List.fold_left in HLVM. *) 509 | let listFoldLeft a b = 510 | TLFunction("List.foldLeft", ["f", TFunction([a; b], a); 511 | "x", a; 512 | "list", TReference], a, 513 | condList "list" "h" "t" 514 | (Var "x") 515 | (Apply(Var "List.foldLeft", 516 | [Var "f"; 517 | Apply(Var "f", [Var "x"; Var "h"]); 518 | Var "t"]))) 519 | 520 | let list ns = 521 | tyList TInt @ 522 | [ TLFunction("add", ["n", TInt; "m", TInt], TInt, Var "n" +. Var "m"); 523 | 524 | TLFunction("List.init", ["t", TReference; "n", TInt], TReference, 525 | Let("t", cons (Var "n") (Var "t"), 526 | If(Var "n" =. Int 0L, Var "t", 527 | Apply(Var "List.init", [Var "t"; Var "n" -. Int 1L])))); 528 | 529 | listFoldLeft TInt TInt; 530 | 531 | TLExpr(Apply(Var "List.init", [nil; Int 10L])) ] @ 532 | List.map 533 | (fun n -> 534 | TLExpr 535 | (compound 536 | [ Printf("\nList.init and fold over %d elements\n", [Int n]); 537 | Let("list", Apply(Var "List.init", [nil; Int n]), 538 | Apply(Var "List.foldLeft", 539 | [Var "add"; Int 0L; Var "list"])) ])) 540 | ns 541 | testEval "list.bc" (list [1000L]); 542 | shouldEqual true true; 543 | -------------------------------------------------------------------------------- /tests/FSHlvm.Core.Tests/FSUnit.fs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // Copyright (c) 2014, Zoltan Podlovics, KP-Tech Kft. All Rights Reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0. See LICENSE.md in the 5 | // project root for license information. 6 | // --------------------------------------------------------------------------- 7 | // This module is based on FSharpx unit tests which is also licensed under 8 | // Apache License 2.0. 9 | // --------------------------------------------------------------------------- 10 | 11 | module KPTech.FSHlvm.Core.Tests.FsUnit 12 | 13 | open Xunit 14 | 15 | // like "should equal", but validates same-type 16 | let shouldEqual (x: 'a) (y: 'a) = 17 | let msg = System.String.Format("Expected: {0}\nActual: {1}", x, y) 18 | Assert.Equal<'a>(x, y) 19 | 20 | let shouldLess (x: 'a) (y: 'a) = 21 | let msg = System.String.Format("Expected: {0}\nActual: {1}", x, y) 22 | Assert.True(x < y, msg) 23 | 24 | let shouldLessOrEqual (x: 'a) (y: 'a) = 25 | let msg = System.String.Format("Expected: {0}\nActual: {1}", x, y) 26 | Assert.True(x <= y, msg) 27 | 28 | let shouldGreater (x: 'a) (y: 'a) = 29 | let msg = System.String.Format("Expected: {0}\nActual: {1}", x, y) 30 | Assert.True(x > y, msg) 31 | 32 | let shouldGreaterOrEqual (x: 'a) (y: 'a) = 33 | let msg = System.String.Format("Expected: {0}\nActual: {1}", x, y) 34 | Assert.True(x >= y, msg) 35 | 36 | let shouldEqualPos (i: int) (x: 'a) (y: 'a) = 37 | let msg = System.String.Format("Position: {0}\n Expected: {0}\nActual: {1}", i, x, y) in 38 | Assert.Equal<'a>(x, y) 39 | 40 | -------------------------------------------------------------------------------- /tests/FSHlvm.Core.Tests/libLLVM-3.8.so: -------------------------------------------------------------------------------- 1 | /usr/lib/llvm-3.8/lib/libLLVM-3.8.so -------------------------------------------------------------------------------- /tests/FSHlvm.Core.Tests/libfshlvmllvmwrapper.so: -------------------------------------------------------------------------------- 1 | ../../lib/libfshlvmllvmwrapper.so -------------------------------------------------------------------------------- /tests/FSHlvm.Core.Tests/libfshlvmruntime.so: -------------------------------------------------------------------------------- 1 | ../../lib/libfshlvmruntime.so -------------------------------------------------------------------------------- /tests/FSHlvm.Core.Tests/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for i in `cat tests.txt`; do 3 | dotnet test -c Release --filter \"KPTech.FSHlvm.Core.Tests.FSHlvmTest+applicationTests.$i\"; 4 | done 5 | 6 | for i in `cat tests.txt`; do 7 | opt-10 -tailcallelim -O3 < bin/Release/netcoreapp3.1/"$i".bc >"$i"opt.bc 8 | done 9 | 10 | for i in `cat tests.txt`; do 11 | clang-10 -o "$i"opt "$i"opt.bc -ldl -lm 12 | done 13 | 14 | -------------------------------------------------------------------------------- /tests/FSHlvm.Core.Tests/tests.txt: -------------------------------------------------------------------------------- 1 | fib 2 | ffib 3 | mandelbrot 4 | mandelbrot2 5 | tco 6 | trig 7 | fold 8 | list 9 | --------------------------------------------------------------------------------