├── .gitignore ├── AUTHORS ├── LICENSE ├── Makefile.in ├── NOTICE ├── README.md ├── api_gen ├── Makefile.in ├── doxygen.conf.in ├── llevm.c.in ├── llevm.erl.in ├── llevm.hrl.in ├── llvm_api.erl ├── llvm_api.hrl ├── llvm_api_erlang.erl ├── llvm_api_nif.erl └── llvm_api_parser.erl ├── autoconf ├── config.guess ├── config.sub └── install-sh ├── configure ├── configure.in ├── csrc └── llevm.c ├── include └── llevm.hrl ├── mac_env ├── os_lathund ├── rebar ├── src ├── llevm.app.src ├── llevm.erl └── llvm_nif.erl └── tests ├── basic_SUITE.erl ├── erlang_SUITE.erl ├── erlang_SUITE_data └── erlang_gen.erl ├── kaleidoscope_SUITE.erl └── kaleidoscope_SUITE_data ├── kal_gen.erl ├── kal_parse.yrl └── kal_scan.erl /.gitignore: -------------------------------------------------------------------------------- 1 | ## Temp files 2 | *~ 3 | \#* 4 | 5 | ## Auto-generated files 6 | Makefile 7 | config.log 8 | config.status 9 | 10 | api_gen/Makefile 11 | api_gen/doxygen.conf 12 | api_gen/llvm_xml/ 13 | 14 | ## Binary files 15 | *.beam 16 | ebin/ 17 | priv/ 18 | obj.*/ 19 | 20 | ## Misc 21 | autom4te.cache/ 22 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Lukas Larsson 2 | Yiannis Tsiouris 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | -------------------------------------------------------------------------------- /Makefile.in: -------------------------------------------------------------------------------- 1 | 2 | # Global 3 | ARCH=x86_64 4 | CSRC=csrc 5 | ESRC=src 6 | EBIN=ebin 7 | INCLUDE_DIR=include 8 | OBJ_DIR=obj.$(ARCH) 9 | 10 | # llvm Variables 11 | 12 | LLVM_CONFIG=@llvm_config_var@ 13 | LLVM_CFLAGS=-g3 -Wall -fPIC -I`$(LLVM_CONFIG) --includedir` -DNDEBUG -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D SIZEOF_LONG_LONG=8 -fno-common 14 | LLVM_LDFLAGS=`$(LLVM_CONFIG) --ldflags` `$(LLVM_CONFIG) --libdir`/libLTO.a `$(LLVM_CONFIG) --libs` 15 | 16 | # Erlang Variables 17 | ERL_TOP=@ERLANG_ROOT_DIR@ 18 | ERL=$(ERL_TOP)/bin/erl 19 | ERLC=$(ERL_TOP)/bin/erlc 20 | BEAM_FILES=$(patsubst $(ESRC)/%.erl,$(EBIN)/%.beam,$(wildcard $(ESRC)/*.erl)) 21 | HRL_FILES=$(wildcard $(ESRC)/*.hrl) $(wildcard $(INCLUDE_DIR)/*.hrl) 22 | 23 | # CPP Variables 24 | CC=@CC@ 25 | LINKER=@LINKER@ 26 | CFLAGS=@CFLAGS@ 27 | CFLAGS+=$(LLVM_CFLAGS) 28 | CFLAGS+=-I @ERTS_DIR@/include/ 29 | LDFLAGS=@LDFLAGS@ 30 | LDFLAGS+=$(LLVM_LDFLAGS) 31 | LIBS=@LIBS@ 32 | OBJ_FILES=$(patsubst $(CSRC)/%.c, $(OBJ_DIR)/%.o, $(wildcard $(CSRC)/*.c)) 33 | H_FILES=$(wildcard $(CSRC)/*.h) 34 | 35 | all: compile 36 | 37 | compile: compile_erl priv/$(ARCH)/llevm.so 38 | @erl -noshell -pa ../llevm/ebin -eval "code:load_file(llevm)." -s init stop 39 | 40 | compile_erl: $(EBIN) $(BEAM_FILES) 41 | cp $(ESRC)/llevm.app.src $(EBIN)/llevm.app 42 | 43 | $(EBIN)/%.beam: $(ESRC)/%.erl $(HRL_FILES) 44 | $(ERLC) -I$(INCLUDE_DIR) -o $(EBIN) $< 45 | 46 | $(OBJ_DIR)/%.o: $(CSRC)/%.c $(H_FILES) $(OBJ_DIR) 47 | $(CC) -c $(CFLAGS) -o $@ $< 48 | 49 | priv/$(ARCH)/llevm.so: $(OBJ_FILES) priv/$(ARCH) 50 | $(LINKER) $(OBJ_FILES) $(LIBS) $(LDFLAGS) -o $@ 51 | 52 | priv/$(ARCH) $(OBJ_DIR) $(EBIN) $(INCLUDE_DIR) logs: 53 | @mkdir -p $@ 54 | 55 | clean: 56 | rm -rf $(OBJ_DIR) priv $(EBIN) 57 | 58 | very_clean: clean 59 | rm -rf config.status autom4te.cache Makefile config.log api_gen/llvm_xml/ 60 | 61 | shell: 62 | erl -pa ebin 63 | 64 | test: compile logs 65 | ct_run -noshell -pa ../llevm/ebin -logdir logs -suite tests/kaleidoscope_SUITE.erl -suite tests/erlang_SUITE.erl 66 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2011-2012 Lukas Larsson 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | LLEVM 2 | ==================== 3 | llevm is an erlang wrapper to the C API functions of llvm. 4 | The documentation of the functions can be found at the official 5 | [llvm website]( http://llvm.org/doxygen/dir_ba5bdc16f452288d1429bb9e178a5965.html ). 6 | Unfortunately the documentation of the C functions seem to be very 7 | sparse, so when looking for what functions do one should try to find 8 | the corresponding C++ class function and read the documentation for it 9 | instead. 10 | 11 | For examples on how to use llevm see the testcases, especially 12 | `tests/kaleidoscope_SUITE.erl` and `tests/kaleidoscope_SUITE_data/kal_gen.erl` 13 | contain lots of basics in how to generate llvm code and use the JIT 14 | execution engine from Erlang. 15 | 16 | Most functions are converted to erlang and hopefully work as well :) 17 | There is a list of which functions are not as yet converted in 18 | `api_gen/llvm_api.hrl`. The functions are listed in the LIMIT macro. 19 | 20 | Compiling 21 | -------------------- 22 | You should only have to run 23 | 24 | ./configure && make 25 | 26 | to compile llevm. Make sure that the correct llvm version is in the 27 | path. 28 | 29 | Some possible issues when compiling are: 30 | 31 | * The erlang vm and llvm has to have the same arch (i.e. 64 vs 32 bit) 32 | * You have to have the correct version of llvm. 33 | As of this writing that is 2.9. If you need another version you have 34 | to regenerate all the erlang and nif files. 35 | 36 | Generating a new llevm 37 | -------------------- 38 | If you are not happy with the generated API you can regenerate it 39 | to suite your needs. To do this you have to have doxygen in your path then run: 40 | 41 | ./configure && (cd api_gen && make) 42 | 43 | then new `src/llevm.erl`, `csrc/llevm.c` and `include/llevm.hrl` should be 44 | regerated. The code which generated the llevm interface is in the api_gen 45 | folder and divided into the different files that they generate. 46 | 47 | 48 | Running test 49 | --------------------- 50 | llevm comes with a set of test which tests that everything works as it should. 51 | To run the tests type: 52 | 53 | make test 54 | 55 | The tests are very basic and are more there to provide examples than to test 56 | the actual interface. So just because they pass don't trust that llevm does 57 | what it should :) 58 | 59 | Debugging 60 | --------------------- 61 | It is possible to enable lots of debug printouts in `api_gen/llvm_api_nif.erl`. 62 | Just search for printf and uncomment those lines and then regenerate llevm. 63 | It is also helpful to use gdb to step through execution, there are some 64 | example commands in `os_lathund` to show how I do it on my mac. 65 | -------------------------------------------------------------------------------- /api_gen/Makefile.in: -------------------------------------------------------------------------------- 1 | 2 | # Global 3 | ESRC=./ 4 | EBIN=./ 5 | 6 | # Erlang Variables 7 | ERL_TOP=@ERLANG_ROOT_DIR@ 8 | ERL=$(ERL_TOP)/bin/erl 9 | ERLC=$(ERL_TOP)/bin/erlc 10 | BEAM_FILES=$(patsubst $(ESRC)/%.erl,$(EBIN)/%.beam,$(wildcard $(ESRC)/*.erl)) 11 | HRL_FILES=$(wildcard $(ESRC)/*.hrl) 12 | 13 | # Other 14 | DOXYGEN=@DOXYGEN_PATH@ 15 | 16 | all: generate 17 | 18 | compile: $(BEAM_FILES) 19 | 20 | $(EBIN)/%.beam: $(ESRC)/%.erl $(HRL_FILES) 21 | $(ERLC) -o $(EBIN) $< 22 | 23 | generate_doxygen: doxygen.conf 24 | $(DOXYGEN) doxygen.conf 25 | 26 | generate: compile generate_doxygen 27 | $(ERL) -noshell -eval 'llvm_api:generate("llvm_xml/*_8h.xml","../")' -s init stop -------------------------------------------------------------------------------- /api_gen/llevm.c.in: -------------------------------------------------------------------------------- 1 | /* 2 | Nif generated by llevm created by Lukas Larsson, 3 | Visit https://github.com/garazdawi/llevm for details. 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "llvm-c/Core.h" 11 | #include "llvm-c/ExecutionEngine.h" 12 | #include "llvm-c/Transforms/Scalar.h" 13 | #include "llvm-c/Transforms/IPO.h" 14 | #include "llvm-c/Target.h" 15 | #include "llvm-c/Initialization.h" 16 | #include "llvm-c/lto.h" 17 | #include "llvm-c/LinkTimeOptimizer.h" 18 | #include "llvm-c/BitWriter.h" 19 | #include "llvm-c/BitReader.h" 20 | #include "llvm-c/EnhancedDisassembly.h" 21 | #include "llvm-c/Analysis.h" 22 | #include "llvm-c/Transforms/PassManagerBuilder.h" 23 | #include "llvm-c/Object.h" 24 | #include "llvm-c/Disassembler.h" 25 | 26 | #include "erl_nif.h" 27 | 28 | typedef enum { 29 | // @@TYPES@@ 30 | RTVoidPtr 31 | } llvm_type_t; 32 | 33 | typedef struct llvm_ptr { 34 | llvm_type_t type; 35 | void *value; 36 | } llvm_ptr_t; 37 | 38 | // @@RESOURCE_TYPES@@ 39 | static ErlNifResourceType* module; 40 | 41 | static int load_nif(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info) { 42 | module = enif_open_resource_type(env, "llvm_nif", "module", NULL, 43 | ERL_NIF_RT_CREATE, NULL); 44 | return 0; 45 | } 46 | 47 | static int llvm_ptr_deref(ErlNifEnv* env, ERL_NIF_TERM term, void** objp) { 48 | llvm_ptr_t *ptr; 49 | enif_get_resource(env, term, module, (void **) &ptr); 50 | // printf("fetching %ld\n",(long)ptr->value); 51 | *objp = ptr->value; 52 | return 0; 53 | } 54 | 55 | static ERL_NIF_TERM llvm_ptr_create(ErlNifEnv* env, llvm_type_t type, 56 | void *data) { 57 | ERL_NIF_TERM term; 58 | llvm_ptr_t *ptr = (llvm_ptr_t*) enif_alloc_resource(module, 59 | sizeof(llvm_ptr_t)); 60 | 61 | // printf("storing %ld\n",(long)data); 62 | /* initialize struct ... */ 63 | ptr->type = type; 64 | ptr->value = data; 65 | 66 | term = enif_make_resource(env, ptr); 67 | 68 | // enif_release_resource(ptr); 69 | enif_keep_resource(ptr); 70 | return term; 71 | } 72 | 73 | 74 | // @@FUNCTIONS@@ 75 | 76 | static ErlNifFunc nif_funcs[] = 77 | { 78 | // @@NIF_MAPPINGS@@ 79 | }; 80 | 81 | ERL_NIF_INIT(llevm,nif_funcs,load_nif,NULL,NULL,NULL) 82 | -------------------------------------------------------------------------------- /api_gen/llevm.erl.in: -------------------------------------------------------------------------------- 1 | -module(llevm). 2 | 3 | %% 4 | %% Module generated by llevm created by Lukas Larsson, 5 | %% Visit https://github.com/garazdawi/llevm for details. 6 | %% 7 | %% 8 | 9 | -include("llevm.hrl"). 10 | 11 | -on_load(load_my_nifs/0). 12 | 13 | %% @@EXPORTS@@ 14 | 15 | -type llvm_ptr(Base) :: {llvm_ptr, Base}. 16 | 17 | %% @@TYPES@@ 18 | 19 | load_my_nifs() -> 20 | erlang:load_nif(filename:join([code:priv_dir(llevm),"x86_64/llevm"]),0). 21 | 22 | %% @@FUNCTIONS@@ 23 | -------------------------------------------------------------------------------- /api_gen/llevm.hrl.in: -------------------------------------------------------------------------------- 1 | %% 2 | %% Header file generated by llevm created by Lukas Larsson, 3 | %% Visit https://github.com/garazdawi/llevm for details. 4 | %% 5 | 6 | %% @@CONST@@ 7 | -------------------------------------------------------------------------------- /api_gen/llvm_api.erl: -------------------------------------------------------------------------------- 1 | -module(llvm_api). 2 | 3 | -export([generate/2, generate_params/2]). 4 | 5 | -include("llvm_api.hrl"). 6 | 7 | generate(From, To) -> 8 | Files = filelib:wildcard(From), 9 | init(To), 10 | [generate_int(filename:basename(File),llvm_api_parser:parse(File)) || 11 | File <- Files]. 12 | 13 | replace(Where, What, With) when is_atom(Where) -> 14 | {ok, Bin} = file:read_file(get(Where)), 15 | NewStr = replace(binary_to_list(Bin), What, With), 16 | {ok,D} = file:open(get(Where),[write]), 17 | split_format(lists:flatten(NewStr),0,[], 18 | fun(SubStr) -> io:format(D,add_escape(SubStr),[]) end), 19 | file:close(D); 20 | replace("@@"++Rest, What, With) -> 21 | case lists:prefix(What,Rest) of 22 | true -> 23 | ["@@",What,"@@\n",With,Rest -- (What++"@@")]; 24 | _Else -> 25 | ["@@"|replace(Rest, What, With)] 26 | end; 27 | replace([C|R],What,With) -> 28 | [C|replace(R,What,With)]. 29 | 30 | 31 | init(Path) -> 32 | Inc = filename:join([Path,"include","llevm.hrl"]), 33 | file:copy("llevm.hrl.in",Inc), 34 | put(include, Inc), 35 | 36 | Module = filename:join([Path,"src","llevm.erl"]), 37 | file:copy("llevm.erl.in",Module), 38 | put(module, Module), 39 | 40 | Nif = filename:join([Path,"csrc","llevm.c"]), 41 | file:copy("llevm.c.in",Nif), 42 | put(nif, Nif), 43 | 44 | ok. 45 | 46 | header(From, Str, Cmt) -> 47 | Pre = io_lib:format(Cmt++" -- Start generating from ~s " 48 | "on ~w--~n~n",[From,calendar:local_time()]), 49 | List = split_format(lists:flatten(Str),0,[], 50 | fun(SubStr) -> io_lib:format(SubStr,[]) end), 51 | Post = io_lib:format(Cmt++" --- Stop generating from ~s~n",[From]), 52 | [Pre,List,Post]. 53 | 54 | split_format(Rest,Len,Acc,F) when Len == 128, hd(Acc) /= $~ -> 55 | [split_format([],0,Acc,F)|split_format(Rest,0,[],F)]; 56 | split_format([C|R],Len,Acc,F) -> 57 | split_format(R,Len+1,[C|Acc],F); 58 | split_format([],_,[],_) -> 59 | []; 60 | split_format([],_,Acc,F) -> 61 | F(lists:reverse(Acc)). 62 | 63 | generate_int(From, Entities) -> 64 | replace(include, "CONST", 65 | header(From,llvm_api_erlang:generate_enums(Entities),"%%")), 66 | replace(module, "TYPES", 67 | header(From, llvm_api_erlang:generate_erlang_types(Entities),"%%")), 68 | replace(module, "EXPORTS", 69 | header(From, llvm_api_erlang:generate_exports(Entities),"%%")), 70 | replace(module, "FUNCTIONS", 71 | header(From, llvm_api_erlang:generate_erlang_functions(Entities),"%%")), 72 | replace(nif, "TYPES", 73 | header(From,llvm_api_nif:generate_types(Entities),"//")), 74 | replace(nif, "RESOURCE_TYPES", 75 | header(From,llvm_api_nif:generate_resource_types(Entities),"//")), 76 | replace(nif, "FUNCTIONS", 77 | header(From,llvm_api_nif:generate_functions(Entities),"//")), 78 | replace(nif, "NIF_MAPPINGS", 79 | header(From,llvm_api_nif:generate_mappings(Entities),"//")). 80 | 81 | generate_params([], _Fun) -> 82 | []; 83 | generate_params([P | Rest], Fun) -> 84 | case Fun(P) of 85 | [] -> generate_params(Rest, Fun); 86 | Res -> 87 | [Res | generate_rest(Rest, Fun)] 88 | end. 89 | generate_rest([], _Fun) -> 90 | []; 91 | generate_rest([#param{} = P|Rest], Fun) -> 92 | case Fun(P) of 93 | [] -> generate_rest(Rest,Fun); 94 | Res -> 95 | [",",Res|generate_rest(Rest,Fun)] 96 | end. 97 | 98 | add_escape([$~|R]) -> 99 | [$~,$~|add_escape(R)]; 100 | add_escape([C|R]) -> 101 | [C|add_escape(R)]; 102 | add_escape([]) -> 103 | []. 104 | -------------------------------------------------------------------------------- /api_gen/llvm_api.hrl: -------------------------------------------------------------------------------- 1 | -record(typedef, {name, type, is_ptr, docs }). 2 | 3 | -record(enum_member, {name, value, docs }). 4 | -record(enum, {name, members = [], docs }). 5 | 6 | -record(param, {name, type, erlang_type, erlang_tag, array = false, 7 | out_param = false}). 8 | -record(function, {name, return_type, params = [], docs }). 9 | 10 | -define(ARRAYS, [{"LLVMFunctionType", "ParamTypes"}, 11 | {"LLVMStructTypeInContext","ElementTypes"}, 12 | {"LLVMStructType","ElementTypes"}, 13 | {"LLVMMDNode","Vals"}, 14 | {"LLVMConstStructInContext","ConstantVals"}, 15 | {"LLVMConstArray","ConstantVals"}, 16 | {"LLVMConstStruct","ConstantVals"}, 17 | {"LLVMConstVector","ScalarConstantVals"}, 18 | {"LLVMConstGEP","ConstantIndices"}, 19 | {"LLVMConstInBoundsGEP","ConstantIndices"}, 20 | {"LLVMAddIncoming","IncomingValues"}, 21 | {"LLVMAddIncoming","IncomingBlocks"}, 22 | {"LLVMBuildAggregateRet","RetVals"}, 23 | {"LLVMBuildInvoke","Args"}, 24 | {"LLVMBuildGEP","Indices"}, 25 | {"LLVMBuildInBoundsGEP","Indices"}, 26 | {"LLVMBuildCall","Args"}, 27 | {"LLVMRunFunction","Args"}, 28 | {"LLVMRunFunctionAsMain","ArgV"}, 29 | {"LLVMRunFunctionAsMain","EnvP"}, 30 | {"lto_codegen_set_assembler_args","args"} 31 | ]). 32 | 33 | -define(OUT_PARAM, [{"LLVMCreateExecutionEngineForModule","OutEE"}, 34 | {"LLVMCreateExecutionEngineForModule","OutError"}, 35 | {"LLVMCreateInterpreterForModule","OutInterp"}, 36 | {"LLVMCreateInterpreterForModule","OutError"}, 37 | {"LLVMCreateJITCompilerForModule","OutJIT"}, 38 | {"LLVMCreateJITCompilerForModule","OutError"}, 39 | {"LLVMCreateExecutionEngine","OutEE"}, 40 | {"LLVMCreateExecutionEngine","OutError"}, 41 | {"LLVMCreateInterpreter","OutInterp"}, 42 | {"LLVMCreateInterpreter","OutError"}, 43 | {"LLVMCreateJITCompiler","OutJIT"}, 44 | {"LLVMCreateJITCompiler","OutError"}, 45 | {"LLVMCreateMemoryBufferWithContentsOfFile","OutMemBuf"}, 46 | {"LLVMCreateMemoryBufferWithContentsOfFile","OutMessage"}, 47 | {"LLVMRemoveModule","OutMod"}, 48 | {"LLVMRemoveModule","OutError"}, 49 | {"LLVMRemoveModulePrivider","OutMod"}, 50 | {"LLVMRemoveModulePrivider","OutError"}, 51 | {"LLVMFindFunction","OutFn"}, 52 | {"LLVMParseBitcode","OutModule"} 53 | ]). 54 | 55 | -define(IS_ENUM(Value), 56 | Value == "LLVMAttribute"; 57 | Value == "LLVMOpcode"; 58 | Value == "LLVMTypeKind"; 59 | Value == "LLVMLinkage"; 60 | Value == "LLVMVisibility"; 61 | Value == "LLVMCallConv"; 62 | Value == "LLVMIntPredicate"; 63 | Value == "LLVMRealPredicate"; 64 | Value == "lto_symbol_attributes"; 65 | Value == "lto_debug_model"; 66 | Value == "lto_codegen_model"; 67 | Value == "llvm_lto_status_t"). 68 | 69 | -define(LIMIT, when 70 | Name /= "LLVMCreateMemoryBufferWithSTDIN" 71 | ,Name /= "lto_module_create_from_fd" 72 | %% These symbols do not resolve for some reason 73 | ,Name /= "LLVMInitializeCore" 74 | ,Name /= "LLVMInitializeIPO" 75 | ,Name /= "LLVMInitializeAnalysis" 76 | ,Name /= "EDInstID" 77 | ,Name /= "LLVMDisasmInstruction" 78 | ,Name /= "LLVMConstIntOfArbitraryPrecision" 79 | %% I think the LinkTimeOptimizer is supposed to be used from C++ code to 80 | %% interface with existing LTO C code. 81 | ,Name /= "llvm_create_optimizer" 82 | ,Name /= "llvm_destroy_optimizer" 83 | ,Name /= "llvm_read_object_file" 84 | ,Name /= "llvm_optimize_modules" 85 | ). 86 | 87 | 88 | -define(LIMIT_OLD, when 89 | Name == "LLVMModuleCreateWithName"; 90 | Name == "LLVMDumpModule"; 91 | Name == "LLVMDumpValue"; 92 | Name == "LLVMConstReal"; 93 | Name == "LLVMCreateBuilderInContext"; 94 | Name == "LLVMGetGlobalContext"; 95 | Name == "LLVMConstReal"; 96 | Name == "LLVMAppendBasicBlock"; 97 | Name == "LLVMPositionBuilderAtEnd"; 98 | Name == "LLVMBuildRet"; 99 | Name == "LLVMFunctionType"; 100 | Name == "LLVMBuildFAdd"; 101 | Name == "LLVMBuildFMul"; 102 | Name == "LLVMBuildFSub"; 103 | Name == "LLVMGetParam"; 104 | Name == "LLVMBuildFCmp"; 105 | Name == "LLVMGetNamedFunction"; 106 | Name == "LLVMSetLinkage"; 107 | Name == "LLVMGetLinkage"; 108 | Name == "LLVMBuildCall"; 109 | Name == "LLVMBuildUIToFP"; 110 | Name == "LLVMConstNull"; 111 | Name == "LLVMGetBasicBlockParent"; 112 | Name == "LLVMGetInsertBlock"; 113 | Name == "LLVMBuildCondBr"; 114 | Name == "LLVMBuildBr"; 115 | Name == "LLVMBuildPhi"; 116 | Name == "LLVMAddIncoming"; 117 | Name == "LLVMAddFunction"; 118 | %% Types 119 | Name == "LLVMInt1Type"; 120 | Name == "LLVMInt8Type"; 121 | Name == "LLVMInt16Type"; 122 | Name == "LLVMInt32Type"; 123 | Name == "LLVMInt64Type"; 124 | Name == "LLVMIntType"; 125 | Name == "LLVMInt1TypeInContext"; 126 | Name == "LLVMInt8TypeInContext"; 127 | Name == "LLVMInt16TypeInContext"; 128 | Name == "LLVMInt32TypeInContext"; 129 | Name == "LLVMInt64TypeInContext"; 130 | Name == "LLVMIntTypeInContext"; 131 | Name == "LLVMFloatType"; 132 | Name == "LLVMDoubleType"; 133 | Name == "LLVMX86FP80TypeType"; 134 | Name == "LLVMFP128Type"; 135 | Name == "LLVMPPCFP128Type"; 136 | Name == "LLVMFloatTypeInContext"; 137 | Name == "LLVMDoubleTypeInContext"; 138 | Name == "LLVMX86FP80TypeTypeInContext"; 139 | Name == "LLVMFP128TypeInContext"; 140 | Name == "LLVMPPCFP128TypeInContext"; 141 | Name == "LLVMCreateFunctionPassManagerForModule"; 142 | Name == "LLVMInitializeFunctionPassManager"; 143 | Name == "LLVMFinalizeFunctionPassManager"; 144 | Name == "LLVMRunFunctionPassManager"; 145 | Name == "LLVMRunPassManager"; 146 | %% Transforms 147 | Name == "LLVMAddGVNPass"; 148 | Name == "LLVMAddInstructionCombiningPass"; 149 | Name == "LLVMAddReassociatePass"; 150 | Name == "LLVMAddCFGSimplificationPass"; 151 | Name == "LLVMGetGlobalPassRegistry"; 152 | %% Execution Engine 153 | Name == "LLVMLinkInInterpreter"; 154 | Name == "LLVMCreateExecutionEngineForModule"; 155 | Name == "LLVMCreateInterpreterForModule"; 156 | Name == "LLVMCreateJITCompilerForModule"; 157 | Name == "LLVMRunFunction"; 158 | Name == "LLVMCreateGenericValueOfFloat"; 159 | Name == "LLVMGenericValueToFloat"; 160 | %% Target 161 | Name == "LLVMInitializeNativeTarget"; 162 | %% Bitwriter 163 | Name == "LLVMWriteBitcodeToFile"; 164 | %% Inits 165 | % Name == "LLVMInitializeCore"; 166 | Name == "LLVMInitializeScalarOpts"; 167 | Name == "LLVMInitializeInstCombine"; 168 | % Name == "LLVMInitializeIPO"; 169 | Name == "LLVMInitializeInstrumentation"; 170 | % Name == "LLVMInitializeAnalysis"; 171 | Name == "LLVMInitializeIPA"; 172 | Name == "LLVMInitializeCodeGen"; 173 | Name == "LLVMInitializeTarget"; 174 | % Name == "LLVMGetNamedFunction"; 175 | % Name == "LLVMCountParams"; 176 | % Name == "LLVMBuildCall"; 177 | % Name == "LLVMSetLinkage"; 178 | % Name == "LLVMDeleteFunction"; 179 | % Name == "LLVMCountBasicBlocks" 180 | false 181 | ). 182 | %-define(LIMIT, when length(Params) == 0). 183 | %-define(LIMIT, ). 184 | -------------------------------------------------------------------------------- /api_gen/llvm_api_erlang.erl: -------------------------------------------------------------------------------- 1 | -module(llvm_api_erlang). 2 | 3 | -include("llvm_api.hrl"). 4 | 5 | -export([generate_enums/1,generate_exports/1,generate_erlang_types/1, 6 | generate_erlang_functions/1]). 7 | 8 | generate_enums([#enum{ name = Name, members = Members, docs = _Docs }|Rest]) -> 9 | ["%% enum ",Name,"~n", 10 | generate_enum_member(Name, Members), 11 | "~n", 12 | generate_enums(Rest)]; 13 | generate_enums([_|Rest]) -> 14 | generate_enums(Rest); 15 | generate_enums([]) -> 16 | []. 17 | 18 | generate_enum_member(EnumName, [#enum_member{ name = Name, 19 | value = Value, 20 | docs = Docs }|Rest]) -> 21 | ["-define(",Name,",{'",EnumName,"',",integer_to_list(Value),"}).~n", 22 | if Docs /= [] -> 23 | ["%% ",add_escape(Docs),"~n"]; 24 | true -> 25 | [] 26 | end, 27 | generate_enum_member(EnumName, Rest)]; 28 | generate_enum_member(_EnumName, []) -> 29 | []. 30 | 31 | 32 | generate_erlang_types([#typedef{ name = Name, is_ptr = true, docs = Docs }|Rest]) -> 33 | ["-opaque '",Name,"'() :: {'",Name,"',binary()}.~n" 34 | "%% ",add_escape(Docs),"~n"| 35 | generate_erlang_types(Rest)]; 36 | generate_erlang_types([#typedef{ name = Name, type = Type, 37 | is_ptr = false, docs = Docs }|Rest]) -> 38 | ErlangType = case Type of 39 | "int" -> "integer"; 40 | "unsigned" -> "integer"; 41 | _ -> Type 42 | end, 43 | ["-type '",Name,"'() :: ",ErlangType,"().~n" 44 | "%% ",add_escape(Docs),"~n~n"| 45 | generate_erlang_types(Rest)]; 46 | generate_erlang_types([#enum{ name = Name }|Rest]) -> 47 | ["-opaque '",Name,"'() :: {'",Name,"',integer()}.~n"| 48 | generate_erlang_types(Rest)]; 49 | generate_erlang_types([_|R]) -> 50 | generate_erlang_types(R); 51 | generate_erlang_types([]) -> 52 | []. 53 | 54 | generate_erlang_functions([#function{ name = Name, 55 | return_type = Return, 56 | params = Params, 57 | docs = Docs }|Rest]) -> 58 | DocStr = ["%% @doc ",add_escape(Docs),"~n"], 59 | SpecStr = ["-spec '",Name,"'(", 60 | llvm_api:generate_params(Params, 61 | fun(#param{ out_param = true }) -> 62 | []; 63 | (#param{name = PName, erlang_type=T}) -> 64 | [to_var(PName)," :: ",T] end), 65 | ") -> ",llvm_api_parser:to_erlang_type(Return),".~n"], 66 | 67 | BodyStr = ["'",Name,"'(", 68 | llvm_api:generate_params( 69 | Params, 70 | fun(#param{ out_param = true} ) -> 71 | []; 72 | (#param{ name = PName, array = false, erlang_type = T, 73 | erlang_tag = Tag}) -> 74 | case is_erlang_type(T) of 75 | false -> 76 | ["{",Tag,",",to_var(PName),"}"]; 77 | ptr -> 78 | PtrTag = case Tag of 79 | "'char * *'" -> 80 | "'string"; 81 | Else -> 82 | hd(string:tokens(Else," ")) 83 | end, 84 | ["{ptr,{",PtrTag, 85 | "',",to_var(PName),"}}"]; 86 | true -> 87 | to_var(PName) 88 | end; 89 | (#param{ name = PName, array = true }) -> 90 | to_var(PName) 91 | end), 92 | ") ->~n" 93 | "\t",generate_return_value(Name, Return, Params), 94 | "'",Name,"_internal'(", 95 | llvm_api:generate_params(Params, 96 | fun(#param{ name = PName, 97 | out_param = false}) -> 98 | ["_",to_var(PName)]; 99 | (#param{ }) -> 100 | [] 101 | end), 102 | ") ->~n" 103 | "\tnif_not_loaded.~n~n"], 104 | [DocStr,SpecStr,BodyStr|generate_erlang_functions(Rest)]; 105 | 106 | generate_erlang_functions([_|R]) -> 107 | generate_erlang_functions(R); 108 | generate_erlang_functions([]) -> 109 | []. 110 | 111 | generate_return_value(Name, Return, Params) -> 112 | case [P || P <- Params, P#param.out_param == true] of 113 | [] -> ["{",llvm_api_parser:to_erlang_tag(Return),",'",Name,"_internal'(", 114 | llvm_api:generate_params(Params,fun(#param{ name = PName }) -> 115 | to_var(PName) 116 | end), 117 | ")}.~n"]; 118 | OutParams -> 119 | ["{Return, ",llvm_api:generate_params(OutParams, 120 | fun(#param{ name = PName }) -> 121 | PName 122 | end),"} = '",Name,"_internal'(", 123 | llvm_api:generate_params(Params--OutParams, 124 | fun(#param{ name = PName, 125 | out_param = false }) -> 126 | to_var(PName) 127 | end),"),~n", 128 | "\t{{",llvm_api_parser:to_erlang_tag(Return),",Return},", 129 | llvm_api:generate_params(OutParams, fun(#param{ name = PName, 130 | erlang_tag = Tag }) -> 131 | ["{",strip_ptr(Tag),",",PName,"}"] 132 | end),"}.~n"] 133 | end. 134 | 135 | generate_exports([#function{ name = Name, params = Params}|Rest]) -> 136 | InParams = [P || P <- Params, P#param.out_param == false], 137 | ["-export(['",Name,"'/",integer_to_list(length(InParams)),"]).~n"| 138 | generate_exports(Rest)]; 139 | generate_exports([_|R]) -> 140 | generate_exports(R); 141 | generate_exports([]) -> 142 | []. 143 | 144 | add_escape([$&|R]) -> 145 | "&"++add_escape(R); 146 | add_escape([$~|R]) -> 147 | [$~,$~|add_escape(R)]; 148 | add_escape([C|R]) -> 149 | [C|add_escape(R)]; 150 | add_escape([]) -> 151 | []. 152 | 153 | strip_ptr(Atom) when is_atom(Atom) -> 154 | list_to_atom(strip_ptr(atom_to_list(Atom))); 155 | strip_ptr(List) when is_list(List) -> 156 | [_,_,_|Rest] = lists:reverse(List), 157 | lists:reverse([$'|Rest]). 158 | 159 | 160 | to_var([C|Rest]) when $a =< C, C =< $z -> 161 | [C - $a + $A|Rest]; 162 | to_var(Else) -> 163 | Else. 164 | 165 | is_erlang_type(ErlangType) -> 166 | case hd(ErlangType) of 167 | $' -> 168 | false; 169 | $l -> 170 | ptr; 171 | _Else -> 172 | true 173 | end. 174 | -------------------------------------------------------------------------------- /api_gen/llvm_api_nif.erl: -------------------------------------------------------------------------------- 1 | -module(llvm_api_nif). 2 | 3 | -include("llvm_api.hrl"). 4 | 5 | -export([generate_types/1, 6 | generate_resource_types/1, 7 | generate_functions/1, 8 | generate_mappings/1]). 9 | 10 | generate_types([#typedef{ name = Name }|Rest]) -> 11 | ["RT",Name,",~n",generate_types(Rest)]; 12 | generate_types([#enum{ name = "@0" }|Rest]) -> 13 | generate_types(Rest); 14 | generate_types([#enum{ name = Name }|Rest]) -> 15 | ["RT",Name,",~n",generate_types(Rest)]; 16 | generate_types([_|R]) -> 17 | generate_types(R); 18 | generate_types([]) -> 19 | []. 20 | 21 | generate_resource_types(_Entities) -> 22 | "". 23 | 24 | generate_functions([#function{name = Name, 25 | params = Params, 26 | return_type = Return}|Rest]) ?LIMIT -> 27 | put({param_count,Name},0), 28 | ["static ERL_NIF_TERM ",Name,"_nif(ErlNifEnv* env, int argc, " 29 | "const ERL_NIF_TERM argv[]) {~n", 30 | % " printf(\"\\rCalling ",Name,"\\r\\n\");~n", 31 | [generate_param_extract(Name,Param) || Param <- Params], 32 | if Return /= "void" -> 33 | [" ",Return," retVal = ",Name,"(", 34 | llvm_api:generate_params(Params,fun(#param{ name = PName, type = T}) -> 35 | ["(",T,")",PName] 36 | end), 37 | ");~n~n return ", 38 | generate_return(Params, Return),";"]; 39 | true -> 40 | [Name,"(", 41 | llvm_api:generate_params(Params,fun(#param{ name = PName, type = T}) -> 42 | ["(",T,")",PName] 43 | end), 44 | ");~n~n", 45 | " return enif_make_atom(env,\"ok\");"] 46 | end, 47 | "~n}~n~n" 48 | ,generate_functions(Rest)]; 49 | generate_functions([_|R]) -> 50 | generate_functions(R); 51 | generate_functions([]) -> 52 | []. 53 | 54 | generate_param_extract(Func,#param{ out_param = true} = Param) -> 55 | generate_param_extract(Func,Param,undefined); 56 | generate_param_extract(Func,Param) -> 57 | Num = get({param_count,Func}), 58 | put({param_count,Func},Num+1), 59 | generate_param_extract(Func,Param,integer_to_list(Num)). 60 | 61 | generate_param_extract(_Fun, #param{ name = Name, out_param = true, type = Type}, 62 | _Num) -> 63 | [" ",Type," ",Name," = (",Type,")calloc(1,sizeof(",Type,"));~n~n"]; 64 | generate_param_extract(Func, #param{ type = "const "++Type} = Param, Num ) -> 65 | generate_param_extract(Func, Param#param{ type = Type }, Num); 66 | generate_param_extract(_Func,#param{ name = Name, array = true, type = Type}, Num) -> 67 | [" int ",Name,"size = 0;~n" 68 | " ERL_NIF_TERM *",Name,"array;~n" 69 | " enif_get_tuple(env, argv[",Num,"], &",Name,"size, (const ERL_NIF_TERM **)&",Name,"array);~n" 70 | " ",Type," ",Name,";~n" 71 | " if (",Name,"size == 0)~n" 72 | " ",Name," = NULL;~n" 73 | " else {~n" 74 | " ",Name," = (",Type,")malloc(sizeof(",Type,")*",Name,"size);~n" 75 | " int i,local_size=0;~n" 76 | " ERL_NIF_TERM *local_array;~n" 77 | " for(i = 0;i < ",Name,"size; i++) {~n" 78 | " enif_get_tuple(env,*(",Name,"array+i), &local_size, (const ERL_NIF_TERM **)&local_array);~n" 79 | " llvm_ptr_deref(env,*(local_array+1),(void **)",Name,"+i);~n" 80 | " }~n" 81 | " }~n~n"]; 82 | generate_param_extract(_Func,#param{ name = Name, type = "double" = Type}, Num) -> 83 | [" ",Type," ",Name,";~n" 84 | " enif_get_double(env, argv[",Num,"], (double*)&",Name,");~n~n"]; 85 | generate_param_extract(_Func,#param{ name = Name, type = Type}, Num) 86 | when ?IS_ENUM(Type); Type == "unsigned" -> 87 | [" ",Type," ",Name,";~n" 88 | " enif_get_uint(env, argv[",Num,"], (",Type,"*)&",Name,");~n~n"]; 89 | generate_param_extract(_Func,#param{ name = Name, type = Type}, Num) 90 | when Type == "unsigned long long"-> 91 | [" ",Type," ",Name,";~n" 92 | " enif_get_uint64(env, argv[",Num,"], (ErlNifUInt64 *)&",Name,");~n~n"]; 93 | generate_param_extract(_Func,#param{ name = Name, type = Type}, Num) 94 | when Type == "int"-> 95 | [" ",Type," ",Name,";~n" 96 | " enif_get_int(env, argv[",Num,"], (",Type,"*)&",Name,");~n~n"]; 97 | generate_param_extract(_Func,#param{ name = Name, type = "LLVMBool" = Type}, Num) -> 98 | [" char *",Name,"_tmp = (char *) malloc(sizeof(char) * 255);~n" 99 | " enif_get_atom(env, argv[",Num,"], (char*)",Name,"_tmp, 255, ERL_NIF_LATIN1);~n" 100 | " ",Type," ",Name," = (strcmp(",Name,"_tmp,\"true\") == 0);~n~n"]; 101 | generate_param_extract(_Func,#param{ name = Name, type = CharType}, Num) 102 | when CharType == "char *"; CharType == "const char *" -> 103 | [" ",CharType,Name," = (char *) malloc(sizeof(char) * 255);~n" 104 | " enif_get_string(env, argv[",Num,"], (char*)",Name,", 255, ERL_NIF_LATIN1);~n~n"]; 105 | generate_param_extract(_Func,#param{ name = Name, type = Type }, Num) -> 106 | [" ",Type," ",Name,";~n" 107 | " llvm_ptr_deref(env, argv[",Num,"], (void **) &",Name,");~n~n"]. 108 | 109 | generate_return(Params, Return) -> 110 | case [P || P <- Params, P#param.out_param == true] of 111 | [] -> 112 | generate_return(Return); 113 | OutParams -> 114 | generate_return_with_out_params(OutParams, Return) 115 | end. 116 | 117 | generate_return("unsigned"++_) -> 118 | [" enif_make_uint(env, retVal)"]; 119 | generate_return("uint64_t") -> 120 | [" enif_make_uint(env, retVal)"]; 121 | generate_return("int") -> 122 | [" enif_make_int(env, retVal)"]; 123 | generate_return("long long") -> 124 | [" enif_make_int(env, retVal)"]; 125 | generate_return(Return) when ?IS_ENUM(Return) -> 126 | [" enif_make_int(env, (int)retVal)"]; 127 | generate_return(Bool) when Bool == "LLVMBool";Bool == "bool" -> 128 | [" retVal ? enif_make_atom(env,\"true\") : enif_make_atom(env,\"false\")"]; 129 | generate_return("double") -> 130 | [" enif_make_double(env,retVal)"]; 131 | generate_return(String) when String == "const char *"; String == "char *" -> 132 | [" enif_make_string(env,retVal,ERL_NIF_LATIN1)"]; 133 | generate_return("const void *") -> 134 | [" llvm_ptr_create(env, RTVoidPtr, (void *)retVal)"]; 135 | generate_return("void *") -> 136 | generate_return("VoidPtr"); 137 | generate_return("enum "++_Rest) -> 138 | [" enif_make_int(env, (int)retVal)"]; 139 | generate_return(Return) -> 140 | [" llvm_ptr_create(env, RT",Return,", retVal)"]. 141 | 142 | generate_return_with_out_params(OutParams, Return) -> 143 | [" enif_make_tuple",integer_to_list(length(OutParams)+1), 144 | "(env, ", generate_return(Return),",", 145 | llvm_api:generate_params( 146 | OutParams, 147 | fun(#param{ type = "char **", name = PName }) -> 148 | ["*",PName," != NULL?enif_make_string(env, *",PName,",ERL_NIF_LATIN1):enif_make_list(env,0)"]; 149 | (#param{ type = Type, name = PName }) -> 150 | ["llvm_ptr_create(env, RT",strip_ptr(Type),",*",PName,")"] 151 | end),");~n~n"]. 152 | 153 | 154 | generate_mappings([#function{ name = Name, params = Params}|Rest]) ?LIMIT -> 155 | InParams = [P || P <- Params, P#param.out_param == false], 156 | [" {\"",Name,"_internal\",",integer_to_list(length(InParams)), 157 | ",",Name,"_nif},~n",generate_mappings(Rest)]; 158 | generate_mappings([_|R]) -> 159 | generate_mappings(R); 160 | generate_mappings([]) -> 161 | []. 162 | 163 | strip_ptr(Atom) when is_atom(Atom) -> 164 | list_to_atom(strip_ptr(atom_to_list(Atom))); 165 | strip_ptr(List) when is_list(List) -> 166 | [_,_|Rest] = lists:reverse(List), 167 | lists:reverse(Rest). 168 | -------------------------------------------------------------------------------- /api_gen/llvm_api_parser.erl: -------------------------------------------------------------------------------- 1 | -module(llvm_api_parser). 2 | 3 | -export([parse/1,to_erlang_tag/1,to_erlang_type/1]). 4 | 5 | -include("llvm_api.hrl"). 6 | -include_lib("xmerl/include/xmerl.hrl"). 7 | 8 | parse(Path) -> 9 | Acc = fun(#xmlText{value = " ", pos = P}, Acc, S) -> 10 | {Acc, P, S}; % new return format 11 | (X, Acc, S) -> 12 | {[X|Acc], S} 13 | end, 14 | {XML, []} = xmerl_scan:file(Path,[{space,normalize}, {acc_fun, Acc}]), 15 | lists:reverse(parse_xml(XML,[])). 16 | 17 | 18 | parse_xml(#xmlElement{ name = memberdef, 19 | attributes = [#xmlAttribute{ name = kind, value = "enum"}|_], 20 | content = Content},Acc) -> 21 | [parse_enum(Content,#enum{})|Acc]; 22 | parse_xml(#xmlElement{ name = memberdef, 23 | attributes = [#xmlAttribute{ name = kind, value = "typedef"}|_], 24 | content = Content},Acc) -> 25 | [parse_typedef(Content,#typedef{})|Acc]; 26 | parse_xml(#xmlElement{ name = memberdef, 27 | attributes = [#xmlAttribute{ name = kind, value = "function"}|_], 28 | content = [_,_,_,#xmlElement{ content = 29 | [#xmlText{ value = Name }]}|_] 30 | = Content},Acc) ?LIMIT -> 31 | [parse_function(Content,#function{})|Acc]; 32 | parse_xml(#xmlText{}, Acc) -> 33 | Acc; 34 | parse_xml(#xmlElement{ content = Content }, Acc) -> 35 | lists:foldl(fun(XML, NewAcc) -> 36 | parse_xml(XML,NewAcc) 37 | end, Acc, Content). 38 | 39 | % 40 | % Parse Enum things 41 | % 42 | parse_enum(#xmlElement{ name = name, content = [#xmlText{ value = Name }]}, 43 | Enum) -> 44 | Enum#enum{ name = Name }; 45 | parse_enum(#xmlElement{ name = enumvalue, content = Content},Enum) -> 46 | Member = parse_enum_member(Content, #enum_member{}), 47 | Enum#enum{ members = [Member|Enum#enum.members]}; 48 | parse_enum(#xmlElement{ name = detaileddescription, content = Descr}, 49 | Enum) -> 50 | Enum#enum{ docs = parse_text(Descr) }; 51 | parse_enum(#xmlElement{},Enum) -> 52 | Enum; 53 | parse_enum(XML, Enum) when is_list(XML) -> 54 | FinEnum = lists:foldl(fun(XMLElement, Acc) -> 55 | parse_enum(XMLElement, Acc) 56 | end,Enum,XML), 57 | Members = lists:reverse(FinEnum#enum.members), 58 | {NewMembers,_} = lists:mapfoldl( 59 | fun(#enum_member{ value = undefined } = Member, Num) -> 60 | {Member#enum_member{ value = Num}, Num + 1}; 61 | (Member, Num) -> 62 | {Member, Num + Member#enum_member.value + 1} % Use initializer's value 63 | end,0, Members), 64 | FinEnum#enum{ members = NewMembers }. 65 | 66 | 67 | parse_enum_member(#xmlElement{ name = name, 68 | content = [#xmlText{ value = Name }]}, 69 | Member) -> 70 | Member#enum_member{ name = Name }; 71 | parse_enum_member(#xmlElement{ name = initializer, content = Text}, 72 | Member) -> 73 | Member#enum_member{ value = parse_value(Text) }; 74 | parse_enum_member(#xmlElement{ name = detaileddescription, content = Descr}, 75 | Member) -> 76 | Member#enum_member{ docs = parse_text(Descr) }; 77 | parse_enum_member(#xmlElement{ }, Member) -> 78 | Member; 79 | parse_enum_member(XML, EnumMember) when is_list(XML) -> 80 | lists:foldl(fun(XMLElement, Acc) -> 81 | parse_enum_member(XMLElement, Acc) 82 | end,EnumMember,XML). 83 | 84 | parse_value(XML) -> 85 | Str = parse_text(XML, ""), 86 | case {string:tokens(Str, " <"),string:tokens(Str, "x")} of 87 | {[Left,Right],_} -> 88 | list_to_integer(Left) bsl list_to_integer(Right); 89 | {_,[_Left,Right]} -> 90 | list_to_integer(Right,16); 91 | {[Integer],_} -> 92 | list_to_integer(Integer) 93 | end. 94 | 95 | % 96 | % Parse typedef 97 | % 98 | parse_typedef(#xmlElement{ name = type, content = TypeXML }, Typedef) -> 99 | [TypeStr|_] = lists:reverse(string:tokens(parse_text(TypeXML)," ")), 100 | 101 | IsPtr = case lists:reverse(TypeStr) of 102 | [$*|_] -> 103 | true; 104 | _Else -> 105 | false 106 | end, 107 | Typedef#typedef{ is_ptr = IsPtr, type = TypeStr }; 108 | parse_typedef(#xmlElement{ name = name, content = [#xmlText{ value = Name }]}, 109 | Typedef) -> 110 | Typedef#typedef{ name = Name }; 111 | parse_typedef(#xmlElement{ name = detaileddescription, 112 | content = Descr}, 113 | Typedef) -> 114 | Typedef#typedef{ docs = parse_text(Descr) }; 115 | parse_typedef(#xmlElement{}, Typedef) -> 116 | Typedef; 117 | parse_typedef(XML, Typedef) when is_list(XML) -> 118 | lists:foldl(fun(XMLElement, Acc) -> 119 | parse_typedef(XMLElement, Acc) 120 | end,Typedef,XML). 121 | 122 | % 123 | % Generic 124 | % 125 | parse_function(#xmlElement{ name = name, content = [#xmlText{ value = Name }]}, 126 | Func) -> 127 | Func#function{ name = Name }; 128 | parse_function(#xmlElement{ name = type, content = Type }, Func) -> 129 | Func#function{ return_type = parse_type(Type) }; 130 | parse_function(#xmlElement{ name = detaileddescription, content = Descr}, 131 | Func) -> 132 | Func#function{ docs = parse_text(Descr) }; 133 | parse_function(#xmlElement{ name = param, content = ParamXML },Func) -> 134 | put(func_name, Func#function.name), 135 | Param = parse_param(ParamXML, #param{}), 136 | Func#function{ params = [Param|Func#function.params]}; 137 | parse_function(#xmlElement{ }, Func) -> 138 | Func; 139 | parse_function(XML, Func) when is_list(XML) -> 140 | FinFunc = lists:foldl(fun(XMLElement, Acc) -> 141 | parse_function(XMLElement, Acc) 142 | end,Func,XML), 143 | NewParam = lists:flatmap(fun(#param{ type = "LLVMBuilderRef", 144 | name = undefined } = Param) -> 145 | [Param#param{ name = "B" }]; 146 | (#param{ type = "LLVMAttribute", 147 | name = undefined } = Param) -> 148 | [Param#param{ name = "PA" }]; 149 | (#param{ type = "LLVMPassManagerRef", 150 | name = undefined } = Param) -> 151 | [Param#param{ name = "PM" }]; 152 | (#param{ type = "LLVMTargetDataRef", 153 | name = undefined } = Param) -> 154 | [Param#param{ name = "TD" }]; 155 | (#param{ type = "LLVMTypeRef", 156 | name = undefined } = Param) -> 157 | [Param#param{ name = "TypeRef" }]; 158 | (#param{ type = "lto_code_gen_t", 159 | name = undefined } = Param) -> 160 | [Param#param{ name = "code_gen" }]; 161 | (#param{ type = "lto_debug_model", 162 | name = undefined } = Param) -> 163 | [Param#param{ name = "dbg" }]; 164 | (#param{ type = "lto_codegen_model", 165 | name = undefined } = Param) -> 166 | [Param#param{ name = "code_gen" }]; 167 | (#param{ type = "const char *", 168 | name = undefined } = Param) -> 169 | [Param#param{ name = "string" }]; 170 | (#param{ type = "void" }) -> 171 | []; 172 | (#param{ type = Type, 173 | name = undefined } = Param) -> 174 | [Param#param{ name = Type++"_var" }]; 175 | (P) -> 176 | [P] 177 | end,lists:reverse(FinFunc#function.params)), 178 | OutParam = [Param#param{ out_param = is_out_param(get(func_name),PName) } || 179 | Param = #param{ name = PName} <- NewParam], 180 | FinFunc#function{ params = OutParam}. 181 | 182 | parse_param(#xmlElement{ name = type, content = TypeXML }, Param) -> 183 | Type = parse_type(TypeXML), 184 | case is_array(get(func_name),Param#param.name) of 185 | true -> 186 | StrippedType = lists:flatten(string:tokens(Type," *")), 187 | Param#param{ type = Type, array = true, 188 | erlang_type = ["tuple(",to_erlang_type(StrippedType),")"], 189 | erlang_tag = to_erlang_tag(StrippedType) }; 190 | false -> 191 | Param#param{ type = Type, erlang_type = to_erlang_type(Type), 192 | erlang_tag = to_erlang_tag(Type) } 193 | end; 194 | parse_param(#xmlElement{ name = declname, content = [#xmlText{ value = Name }]}, 195 | Param) -> 196 | Param#param{ name = Name }; 197 | parse_param(#xmlElement{ name = array }, Param) -> 198 | Param#param{ array = true }; 199 | parse_param(XML, Param) when is_list(XML) -> 200 | lists:foldl(fun(XMLElement, Acc) -> 201 | parse_param(XMLElement, Acc) 202 | end,Param,lists:reverse(XML)). 203 | 204 | parse_type([#xmlElement{ 205 | name = ref, 206 | content = [#xmlText{ value = Type }]}]) -> 207 | Type; 208 | parse_type(Type) -> 209 | parse_text(Type). 210 | 211 | 212 | % 213 | % Generic 214 | % 215 | parse_text(XML) -> 216 | parse_text(XML,""). 217 | parse_text([#xmlElement{ content = Content}|Rest], Acc) -> 218 | parse_text(Rest, [parse_text(Content)|Acc]); 219 | parse_text([#xmlText{ value = Val }|Rest],Acc) -> 220 | parse_text(Rest,[Val|Acc]); 221 | parse_text([],Acc) -> 222 | lists:flatten(lists:reverse(Acc)). 223 | 224 | to_erlang_type(Val) -> 225 | Tag = to_erlang_tag(Val), 226 | case lists:reverse(Tag) of 227 | [$',$*,$ |Rest] -> 228 | "llvm_ptr("++to_erlang_type(tl(lists:reverse(Rest)))++")"; 229 | _ -> 230 | Tag++"()" 231 | end. 232 | 233 | 234 | to_erlang_tag("unsigned") -> 235 | "integer"; 236 | to_erlang_tag("int") -> 237 | "integer"; 238 | to_erlang_tag("unsigned int") -> 239 | "integer"; 240 | to_erlang_tag("uint64_t") -> 241 | "integer"; 242 | to_erlang_tag("integer") -> 243 | "integer"; 244 | to_erlang_tag("char *") -> 245 | "string"; 246 | to_erlang_tag("char **") -> 247 | "'char * *'"; 248 | to_erlang_tag("const char *") -> 249 | "string"; 250 | to_erlang_tag("const uint64_t") -> 251 | "integer"; 252 | to_erlang_tag("uint8_t") -> 253 | "integer"; 254 | to_erlang_tag("unsigned long long") -> 255 | "integer"; 256 | to_erlang_tag("long long") -> 257 | "integer"; 258 | to_erlang_tag("size_t") -> 259 | "integer"; 260 | to_erlang_tag("off_t") -> 261 | "integer"; 262 | to_erlang_tag("double") -> 263 | "float"; 264 | to_erlang_tag("void") -> 265 | "atom"; 266 | to_erlang_tag("bool") -> 267 | "boolean"; 268 | to_erlang_tag("LLVMBool") -> 269 | "boolean"; 270 | to_erlang_tag("constcharconst") -> 271 | "string"; 272 | to_erlang_tag("constchar") -> 273 | "string"; 274 | to_erlang_tag("const "++Rest) -> 275 | to_erlang_tag(Rest); 276 | to_erlang_tag("enum "++Rest) -> 277 | to_erlang_tag(Rest); 278 | to_erlang_tag(Else) -> 279 | "'"++Else++"'". 280 | 281 | %% Check hardcoded arrays 282 | is_array(FName,PName) -> 283 | lists:member({FName,PName},?ARRAYS). 284 | is_out_param(_FName,"Out"++_) -> 285 | true; 286 | is_out_param(_,_) -> 287 | false. 288 | 289 | -------------------------------------------------------------------------------- /autoconf/config.guess: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Attempt to guess a canonical system name. 3 | # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 4 | # 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, 5 | # Inc. 6 | 7 | timestamp='2006-02-27' 8 | 9 | # This file is free software; you can redistribute it and/or modify it 10 | # under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation; either version 2 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # This program is distributed in the hope that it will be useful, but 15 | # WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | # General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program; if not, write to the Free Software 21 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 22 | # 02110-1301, USA. 23 | # 24 | # As a special exception to the GNU General Public License, if you 25 | # distribute this file as part of a program that contains a 26 | # configuration script generated by Autoconf, you may include it under 27 | # the same distribution terms that you use for the rest of that program. 28 | 29 | 30 | # Originally written by Per Bothner . 31 | # Please send patches to . Submit a context 32 | # diff and a properly formatted ChangeLog entry. 33 | # 34 | # This script attempts to guess a canonical system name similar to 35 | # config.sub. If it succeeds, it prints the system name on stdout, and 36 | # exits with 0. Otherwise, it exits with 1. 37 | # 38 | # The plan is that this can be called by configure scripts if you 39 | # don't specify an explicit build system type. 40 | 41 | me=`echo "$0" | sed -e 's,.*/,,'` 42 | 43 | usage="\ 44 | Usage: $0 [OPTION] 45 | 46 | Output the configuration name of the system \`$me' is run on. 47 | 48 | Operation modes: 49 | -h, --help print this help, then exit 50 | -t, --time-stamp print date of last modification, then exit 51 | -v, --version print version number, then exit 52 | 53 | Report bugs and patches to ." 54 | 55 | version="\ 56 | GNU config.guess ($timestamp) 57 | 58 | Originally written by Per Bothner. 59 | Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 60 | Free Software Foundation, Inc. 61 | 62 | This is free software; see the source for copying conditions. There is NO 63 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." 64 | 65 | help=" 66 | Try \`$me --help' for more information." 67 | 68 | # Parse command line 69 | while test $# -gt 0 ; do 70 | case $1 in 71 | --time-stamp | --time* | -t ) 72 | echo "$timestamp" ; exit ;; 73 | --version | -v ) 74 | echo "$version" ; exit ;; 75 | --help | --h* | -h ) 76 | echo "$usage"; exit ;; 77 | -- ) # Stop option processing 78 | shift; break ;; 79 | - ) # Use stdin as input. 80 | break ;; 81 | -* ) 82 | echo "$me: invalid option $1$help" >&2 83 | exit 1 ;; 84 | * ) 85 | break ;; 86 | esac 87 | done 88 | 89 | if test $# != 0; then 90 | echo "$me: too many arguments$help" >&2 91 | exit 1 92 | fi 93 | 94 | trap 'exit 1' 1 2 15 95 | 96 | # CC_FOR_BUILD -- compiler used by this script. Note that the use of a 97 | # compiler to aid in system detection is discouraged as it requires 98 | # temporary files to be created and, as you can see below, it is a 99 | # headache to deal with in a portable fashion. 100 | 101 | # Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still 102 | # use `HOST_CC' if defined, but it is deprecated. 103 | 104 | # Portable tmp directory creation inspired by the Autoconf team. 105 | 106 | set_cc_for_build=' 107 | trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; 108 | trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; 109 | : ${TMPDIR=/tmp} ; 110 | { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || 111 | { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || 112 | { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || 113 | { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; 114 | dummy=$tmp/dummy ; 115 | tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; 116 | case $CC_FOR_BUILD,$HOST_CC,$CC in 117 | ,,) echo "int x;" > $dummy.c ; 118 | for c in cc gcc c89 c99 ; do 119 | if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then 120 | CC_FOR_BUILD="$c"; break ; 121 | fi ; 122 | done ; 123 | if test x"$CC_FOR_BUILD" = x ; then 124 | CC_FOR_BUILD=no_compiler_found ; 125 | fi 126 | ;; 127 | ,,*) CC_FOR_BUILD=$CC ;; 128 | ,*,*) CC_FOR_BUILD=$HOST_CC ;; 129 | esac ; set_cc_for_build= ;' 130 | 131 | # This is needed to find uname on a Pyramid OSx when run in the BSD universe. 132 | # (ghazi@noc.rutgers.edu 1994-08-24) 133 | if (test -f /.attbin/uname) >/dev/null 2>&1 ; then 134 | PATH=$PATH:/.attbin ; export PATH 135 | fi 136 | 137 | UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown 138 | UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown 139 | UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown 140 | UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown 141 | 142 | # Note: order is significant - the case branches are not exclusive. 143 | 144 | case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in 145 | *:NetBSD:*:*) 146 | # NetBSD (nbsd) targets should (where applicable) match one or 147 | # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, 148 | # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently 149 | # switched to ELF, *-*-netbsd* would select the old 150 | # object file format. This provides both forward 151 | # compatibility and a consistent mechanism for selecting the 152 | # object file format. 153 | # 154 | # Note: NetBSD doesn't particularly care about the vendor 155 | # portion of the name. We always set it to "unknown". 156 | sysctl="sysctl -n hw.machine_arch" 157 | UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ 158 | /usr/sbin/$sysctl 2>/dev/null || echo unknown)` 159 | case "${UNAME_MACHINE_ARCH}" in 160 | armeb) machine=armeb-unknown ;; 161 | arm*) machine=arm-unknown ;; 162 | sh3el) machine=shl-unknown ;; 163 | sh3eb) machine=sh-unknown ;; 164 | *) machine=${UNAME_MACHINE_ARCH}-unknown ;; 165 | esac 166 | # The Operating System including object format, if it has switched 167 | # to ELF recently, or will in the future. 168 | case "${UNAME_MACHINE_ARCH}" in 169 | arm*|i386|m68k|ns32k|sh3*|sparc|vax) 170 | eval $set_cc_for_build 171 | if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ 172 | | grep __ELF__ >/dev/null 173 | then 174 | # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). 175 | # Return netbsd for either. FIX? 176 | os=netbsd 177 | else 178 | os=netbsdelf 179 | fi 180 | ;; 181 | *) 182 | os=netbsd 183 | ;; 184 | esac 185 | # The OS release 186 | # Debian GNU/NetBSD machines have a different userland, and 187 | # thus, need a distinct triplet. However, they do not need 188 | # kernel version information, so it can be replaced with a 189 | # suitable tag, in the style of linux-gnu. 190 | case "${UNAME_VERSION}" in 191 | Debian*) 192 | release='-gnu' 193 | ;; 194 | *) 195 | release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` 196 | ;; 197 | esac 198 | # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: 199 | # contains redundant information, the shorter form: 200 | # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. 201 | echo "${machine}-${os}${release}" 202 | exit ;; 203 | *:OpenBSD:*:*) 204 | UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` 205 | echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} 206 | exit ;; 207 | *:ekkoBSD:*:*) 208 | echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} 209 | exit ;; 210 | *:SolidBSD:*:*) 211 | echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} 212 | exit ;; 213 | macppc:MirBSD:*:*) 214 | echo powerppc-unknown-mirbsd${UNAME_RELEASE} 215 | exit ;; 216 | *:MirBSD:*:*) 217 | echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} 218 | exit ;; 219 | alpha:OSF1:*:*) 220 | case $UNAME_RELEASE in 221 | *4.0) 222 | UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` 223 | ;; 224 | *5.*) 225 | UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` 226 | ;; 227 | esac 228 | # According to Compaq, /usr/sbin/psrinfo has been available on 229 | # OSF/1 and Tru64 systems produced since 1995. I hope that 230 | # covers most systems running today. This code pipes the CPU 231 | # types through head -n 1, so we only detect the type of CPU 0. 232 | ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` 233 | case "$ALPHA_CPU_TYPE" in 234 | "EV4 (21064)") 235 | UNAME_MACHINE="alpha" ;; 236 | "EV4.5 (21064)") 237 | UNAME_MACHINE="alpha" ;; 238 | "LCA4 (21066/21068)") 239 | UNAME_MACHINE="alpha" ;; 240 | "EV5 (21164)") 241 | UNAME_MACHINE="alphaev5" ;; 242 | "EV5.6 (21164A)") 243 | UNAME_MACHINE="alphaev56" ;; 244 | "EV5.6 (21164PC)") 245 | UNAME_MACHINE="alphapca56" ;; 246 | "EV5.7 (21164PC)") 247 | UNAME_MACHINE="alphapca57" ;; 248 | "EV6 (21264)") 249 | UNAME_MACHINE="alphaev6" ;; 250 | "EV6.7 (21264A)") 251 | UNAME_MACHINE="alphaev67" ;; 252 | "EV6.8CB (21264C)") 253 | UNAME_MACHINE="alphaev68" ;; 254 | "EV6.8AL (21264B)") 255 | UNAME_MACHINE="alphaev68" ;; 256 | "EV6.8CX (21264D)") 257 | UNAME_MACHINE="alphaev68" ;; 258 | "EV6.9A (21264/EV69A)") 259 | UNAME_MACHINE="alphaev69" ;; 260 | "EV7 (21364)") 261 | UNAME_MACHINE="alphaev7" ;; 262 | "EV7.9 (21364A)") 263 | UNAME_MACHINE="alphaev79" ;; 264 | esac 265 | # A Pn.n version is a patched version. 266 | # A Vn.n version is a released version. 267 | # A Tn.n version is a released field test version. 268 | # A Xn.n version is an unreleased experimental baselevel. 269 | # 1.2 uses "1.2" for uname -r. 270 | echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` 271 | exit ;; 272 | Alpha\ *:Windows_NT*:*) 273 | # How do we know it's Interix rather than the generic POSIX subsystem? 274 | # Should we change UNAME_MACHINE based on the output of uname instead 275 | # of the specific Alpha model? 276 | echo alpha-pc-interix 277 | exit ;; 278 | 21064:Windows_NT:50:3) 279 | echo alpha-dec-winnt3.5 280 | exit ;; 281 | Amiga*:UNIX_System_V:4.0:*) 282 | echo m68k-unknown-sysv4 283 | exit ;; 284 | *:[Aa]miga[Oo][Ss]:*:*) 285 | echo ${UNAME_MACHINE}-unknown-amigaos 286 | exit ;; 287 | *:[Mm]orph[Oo][Ss]:*:*) 288 | echo ${UNAME_MACHINE}-unknown-morphos 289 | exit ;; 290 | *:OS/390:*:*) 291 | echo i370-ibm-openedition 292 | exit ;; 293 | *:z/VM:*:*) 294 | echo s390-ibm-zvmoe 295 | exit ;; 296 | *:OS400:*:*) 297 | echo powerpc-ibm-os400 298 | exit ;; 299 | arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) 300 | echo arm-acorn-riscix${UNAME_RELEASE} 301 | exit ;; 302 | arm:riscos:*:*|arm:RISCOS:*:*) 303 | echo arm-unknown-riscos 304 | exit ;; 305 | SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) 306 | echo hppa1.1-hitachi-hiuxmpp 307 | exit ;; 308 | Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) 309 | # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. 310 | if test "`(/bin/universe) 2>/dev/null`" = att ; then 311 | echo pyramid-pyramid-sysv3 312 | else 313 | echo pyramid-pyramid-bsd 314 | fi 315 | exit ;; 316 | NILE*:*:*:dcosx) 317 | echo pyramid-pyramid-svr4 318 | exit ;; 319 | DRS?6000:unix:4.0:6*) 320 | echo sparc-icl-nx6 321 | exit ;; 322 | DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) 323 | case `/usr/bin/uname -p` in 324 | sparc) echo sparc-icl-nx7; exit ;; 325 | esac ;; 326 | sun4H:SunOS:5.*:*) 327 | echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` 328 | exit ;; 329 | sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) 330 | echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` 331 | exit ;; 332 | i86pc:SunOS:5.*:*) 333 | echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` 334 | exit ;; 335 | sun4*:SunOS:6*:*) 336 | # According to config.sub, this is the proper way to canonicalize 337 | # SunOS6. Hard to guess exactly what SunOS6 will be like, but 338 | # it's likely to be more like Solaris than SunOS4. 339 | echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` 340 | exit ;; 341 | sun4*:SunOS:*:*) 342 | case "`/usr/bin/arch -k`" in 343 | Series*|S4*) 344 | UNAME_RELEASE=`uname -v` 345 | ;; 346 | esac 347 | # Japanese Language versions have a version number like `4.1.3-JL'. 348 | echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` 349 | exit ;; 350 | sun3*:SunOS:*:*) 351 | echo m68k-sun-sunos${UNAME_RELEASE} 352 | exit ;; 353 | sun*:*:4.2BSD:*) 354 | UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` 355 | test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 356 | case "`/bin/arch`" in 357 | sun3) 358 | echo m68k-sun-sunos${UNAME_RELEASE} 359 | ;; 360 | sun4) 361 | echo sparc-sun-sunos${UNAME_RELEASE} 362 | ;; 363 | esac 364 | exit ;; 365 | aushp:SunOS:*:*) 366 | echo sparc-auspex-sunos${UNAME_RELEASE} 367 | exit ;; 368 | # The situation for MiNT is a little confusing. The machine name 369 | # can be virtually everything (everything which is not 370 | # "atarist" or "atariste" at least should have a processor 371 | # > m68000). The system name ranges from "MiNT" over "FreeMiNT" 372 | # to the lowercase version "mint" (or "freemint"). Finally 373 | # the system name "TOS" denotes a system which is actually not 374 | # MiNT. But MiNT is downward compatible to TOS, so this should 375 | # be no problem. 376 | atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) 377 | echo m68k-atari-mint${UNAME_RELEASE} 378 | exit ;; 379 | atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) 380 | echo m68k-atari-mint${UNAME_RELEASE} 381 | exit ;; 382 | *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) 383 | echo m68k-atari-mint${UNAME_RELEASE} 384 | exit ;; 385 | milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) 386 | echo m68k-milan-mint${UNAME_RELEASE} 387 | exit ;; 388 | hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) 389 | echo m68k-hades-mint${UNAME_RELEASE} 390 | exit ;; 391 | *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) 392 | echo m68k-unknown-mint${UNAME_RELEASE} 393 | exit ;; 394 | m68k:machten:*:*) 395 | echo m68k-apple-machten${UNAME_RELEASE} 396 | exit ;; 397 | powerpc:machten:*:*) 398 | echo powerpc-apple-machten${UNAME_RELEASE} 399 | exit ;; 400 | RISC*:Mach:*:*) 401 | echo mips-dec-mach_bsd4.3 402 | exit ;; 403 | RISC*:ULTRIX:*:*) 404 | echo mips-dec-ultrix${UNAME_RELEASE} 405 | exit ;; 406 | VAX*:ULTRIX*:*:*) 407 | echo vax-dec-ultrix${UNAME_RELEASE} 408 | exit ;; 409 | 2020:CLIX:*:* | 2430:CLIX:*:*) 410 | echo clipper-intergraph-clix${UNAME_RELEASE} 411 | exit ;; 412 | mips:*:*:UMIPS | mips:*:*:RISCos) 413 | eval $set_cc_for_build 414 | sed 's/^ //' << EOF >$dummy.c 415 | #ifdef __cplusplus 416 | #include /* for printf() prototype */ 417 | int main (int argc, char *argv[]) { 418 | #else 419 | int main (argc, argv) int argc; char *argv[]; { 420 | #endif 421 | #if defined (host_mips) && defined (MIPSEB) 422 | #if defined (SYSTYPE_SYSV) 423 | printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); 424 | #endif 425 | #if defined (SYSTYPE_SVR4) 426 | printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); 427 | #endif 428 | #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) 429 | printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); 430 | #endif 431 | #endif 432 | exit (-1); 433 | } 434 | EOF 435 | $CC_FOR_BUILD -o $dummy $dummy.c && 436 | dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && 437 | SYSTEM_NAME=`$dummy $dummyarg` && 438 | { echo "$SYSTEM_NAME"; exit; } 439 | echo mips-mips-riscos${UNAME_RELEASE} 440 | exit ;; 441 | Motorola:PowerMAX_OS:*:*) 442 | echo powerpc-motorola-powermax 443 | exit ;; 444 | Motorola:*:4.3:PL8-*) 445 | echo powerpc-harris-powermax 446 | exit ;; 447 | Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) 448 | echo powerpc-harris-powermax 449 | exit ;; 450 | Night_Hawk:Power_UNIX:*:*) 451 | echo powerpc-harris-powerunix 452 | exit ;; 453 | m88k:CX/UX:7*:*) 454 | echo m88k-harris-cxux7 455 | exit ;; 456 | m88k:*:4*:R4*) 457 | echo m88k-motorola-sysv4 458 | exit ;; 459 | m88k:*:3*:R3*) 460 | echo m88k-motorola-sysv3 461 | exit ;; 462 | AViiON:dgux:*:*) 463 | # DG/UX returns AViiON for all architectures 464 | UNAME_PROCESSOR=`/usr/bin/uname -p` 465 | if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] 466 | then 467 | if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ 468 | [ ${TARGET_BINARY_INTERFACE}x = x ] 469 | then 470 | echo m88k-dg-dgux${UNAME_RELEASE} 471 | else 472 | echo m88k-dg-dguxbcs${UNAME_RELEASE} 473 | fi 474 | else 475 | echo i586-dg-dgux${UNAME_RELEASE} 476 | fi 477 | exit ;; 478 | M88*:DolphinOS:*:*) # DolphinOS (SVR3) 479 | echo m88k-dolphin-sysv3 480 | exit ;; 481 | M88*:*:R3*:*) 482 | # Delta 88k system running SVR3 483 | echo m88k-motorola-sysv3 484 | exit ;; 485 | XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) 486 | echo m88k-tektronix-sysv3 487 | exit ;; 488 | Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) 489 | echo m68k-tektronix-bsd 490 | exit ;; 491 | *:IRIX*:*:*) 492 | echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` 493 | exit ;; 494 | ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. 495 | echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id 496 | exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' 497 | i*86:AIX:*:*) 498 | echo i386-ibm-aix 499 | exit ;; 500 | ia64:AIX:*:*) 501 | if [ -x /usr/bin/oslevel ] ; then 502 | IBM_REV=`/usr/bin/oslevel` 503 | else 504 | IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} 505 | fi 506 | echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} 507 | exit ;; 508 | *:AIX:2:3) 509 | if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then 510 | eval $set_cc_for_build 511 | sed 's/^ //' << EOF >$dummy.c 512 | #include 513 | 514 | main() 515 | { 516 | if (!__power_pc()) 517 | exit(1); 518 | puts("powerpc-ibm-aix3.2.5"); 519 | exit(0); 520 | } 521 | EOF 522 | if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` 523 | then 524 | echo "$SYSTEM_NAME" 525 | else 526 | echo rs6000-ibm-aix3.2.5 527 | fi 528 | elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then 529 | echo rs6000-ibm-aix3.2.4 530 | else 531 | echo rs6000-ibm-aix3.2 532 | fi 533 | exit ;; 534 | *:AIX:*:[45]) 535 | IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` 536 | if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then 537 | IBM_ARCH=rs6000 538 | else 539 | IBM_ARCH=powerpc 540 | fi 541 | if [ -x /usr/bin/oslevel ] ; then 542 | IBM_REV=`/usr/bin/oslevel` 543 | else 544 | IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} 545 | fi 546 | echo ${IBM_ARCH}-ibm-aix${IBM_REV} 547 | exit ;; 548 | *:AIX:*:*) 549 | echo rs6000-ibm-aix 550 | exit ;; 551 | ibmrt:4.4BSD:*|romp-ibm:BSD:*) 552 | echo romp-ibm-bsd4.4 553 | exit ;; 554 | ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and 555 | echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to 556 | exit ;; # report: romp-ibm BSD 4.3 557 | *:BOSX:*:*) 558 | echo rs6000-bull-bosx 559 | exit ;; 560 | DPX/2?00:B.O.S.:*:*) 561 | echo m68k-bull-sysv3 562 | exit ;; 563 | 9000/[34]??:4.3bsd:1.*:*) 564 | echo m68k-hp-bsd 565 | exit ;; 566 | hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) 567 | echo m68k-hp-bsd4.4 568 | exit ;; 569 | 9000/[34678]??:HP-UX:*:*) 570 | HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` 571 | case "${UNAME_MACHINE}" in 572 | 9000/31? ) HP_ARCH=m68000 ;; 573 | 9000/[34]?? ) HP_ARCH=m68k ;; 574 | 9000/[678][0-9][0-9]) 575 | if [ -x /usr/bin/getconf ]; then 576 | sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` 577 | sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` 578 | case "${sc_cpu_version}" in 579 | 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 580 | 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 581 | 532) # CPU_PA_RISC2_0 582 | case "${sc_kernel_bits}" in 583 | 32) HP_ARCH="hppa2.0n" ;; 584 | 64) HP_ARCH="hppa2.0w" ;; 585 | '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 586 | esac ;; 587 | esac 588 | fi 589 | if [ "${HP_ARCH}" = "" ]; then 590 | eval $set_cc_for_build 591 | sed 's/^ //' << EOF >$dummy.c 592 | 593 | #define _HPUX_SOURCE 594 | #include 595 | #include 596 | 597 | int main () 598 | { 599 | #if defined(_SC_KERNEL_BITS) 600 | long bits = sysconf(_SC_KERNEL_BITS); 601 | #endif 602 | long cpu = sysconf (_SC_CPU_VERSION); 603 | 604 | switch (cpu) 605 | { 606 | case CPU_PA_RISC1_0: puts ("hppa1.0"); break; 607 | case CPU_PA_RISC1_1: puts ("hppa1.1"); break; 608 | case CPU_PA_RISC2_0: 609 | #if defined(_SC_KERNEL_BITS) 610 | switch (bits) 611 | { 612 | case 64: puts ("hppa2.0w"); break; 613 | case 32: puts ("hppa2.0n"); break; 614 | default: puts ("hppa2.0"); break; 615 | } break; 616 | #else /* !defined(_SC_KERNEL_BITS) */ 617 | puts ("hppa2.0"); break; 618 | #endif 619 | default: puts ("hppa1.0"); break; 620 | } 621 | exit (0); 622 | } 623 | EOF 624 | (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` 625 | test -z "$HP_ARCH" && HP_ARCH=hppa 626 | fi ;; 627 | esac 628 | if [ ${HP_ARCH} = "hppa2.0w" ] 629 | then 630 | eval $set_cc_for_build 631 | 632 | # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating 633 | # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler 634 | # generating 64-bit code. GNU and HP use different nomenclature: 635 | # 636 | # $ CC_FOR_BUILD=cc ./config.guess 637 | # => hppa2.0w-hp-hpux11.23 638 | # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess 639 | # => hppa64-hp-hpux11.23 640 | 641 | if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | 642 | grep __LP64__ >/dev/null 643 | then 644 | HP_ARCH="hppa2.0w" 645 | else 646 | HP_ARCH="hppa64" 647 | fi 648 | fi 649 | echo ${HP_ARCH}-hp-hpux${HPUX_REV} 650 | exit ;; 651 | ia64:HP-UX:*:*) 652 | HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` 653 | echo ia64-hp-hpux${HPUX_REV} 654 | exit ;; 655 | 3050*:HI-UX:*:*) 656 | eval $set_cc_for_build 657 | sed 's/^ //' << EOF >$dummy.c 658 | #include 659 | int 660 | main () 661 | { 662 | long cpu = sysconf (_SC_CPU_VERSION); 663 | /* The order matters, because CPU_IS_HP_MC68K erroneously returns 664 | true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct 665 | results, however. */ 666 | if (CPU_IS_PA_RISC (cpu)) 667 | { 668 | switch (cpu) 669 | { 670 | case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; 671 | case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; 672 | case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; 673 | default: puts ("hppa-hitachi-hiuxwe2"); break; 674 | } 675 | } 676 | else if (CPU_IS_HP_MC68K (cpu)) 677 | puts ("m68k-hitachi-hiuxwe2"); 678 | else puts ("unknown-hitachi-hiuxwe2"); 679 | exit (0); 680 | } 681 | EOF 682 | $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && 683 | { echo "$SYSTEM_NAME"; exit; } 684 | echo unknown-hitachi-hiuxwe2 685 | exit ;; 686 | 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) 687 | echo hppa1.1-hp-bsd 688 | exit ;; 689 | 9000/8??:4.3bsd:*:*) 690 | echo hppa1.0-hp-bsd 691 | exit ;; 692 | *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) 693 | echo hppa1.0-hp-mpeix 694 | exit ;; 695 | hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) 696 | echo hppa1.1-hp-osf 697 | exit ;; 698 | hp8??:OSF1:*:*) 699 | echo hppa1.0-hp-osf 700 | exit ;; 701 | i*86:OSF1:*:*) 702 | if [ -x /usr/sbin/sysversion ] ; then 703 | echo ${UNAME_MACHINE}-unknown-osf1mk 704 | else 705 | echo ${UNAME_MACHINE}-unknown-osf1 706 | fi 707 | exit ;; 708 | parisc*:Lites*:*:*) 709 | echo hppa1.1-hp-lites 710 | exit ;; 711 | C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) 712 | echo c1-convex-bsd 713 | exit ;; 714 | C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) 715 | if getsysinfo -f scalar_acc 716 | then echo c32-convex-bsd 717 | else echo c2-convex-bsd 718 | fi 719 | exit ;; 720 | C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) 721 | echo c34-convex-bsd 722 | exit ;; 723 | C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) 724 | echo c38-convex-bsd 725 | exit ;; 726 | C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) 727 | echo c4-convex-bsd 728 | exit ;; 729 | CRAY*Y-MP:*:*:*) 730 | echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' 731 | exit ;; 732 | CRAY*[A-Z]90:*:*:*) 733 | echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ 734 | | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ 735 | -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ 736 | -e 's/\.[^.]*$/.X/' 737 | exit ;; 738 | CRAY*TS:*:*:*) 739 | echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' 740 | exit ;; 741 | CRAY*T3E:*:*:*) 742 | echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' 743 | exit ;; 744 | CRAY*SV1:*:*:*) 745 | echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' 746 | exit ;; 747 | *:UNICOS/mp:*:*) 748 | echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' 749 | exit ;; 750 | F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) 751 | FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` 752 | FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` 753 | FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` 754 | echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" 755 | exit ;; 756 | 5000:UNIX_System_V:4.*:*) 757 | FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` 758 | FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` 759 | echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" 760 | exit ;; 761 | i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) 762 | echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} 763 | exit ;; 764 | sparc*:BSD/OS:*:*) 765 | echo sparc-unknown-bsdi${UNAME_RELEASE} 766 | exit ;; 767 | *:BSD/OS:*:*) 768 | echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} 769 | exit ;; 770 | *:FreeBSD:*:*) 771 | case ${UNAME_MACHINE} in 772 | pc98) 773 | echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; 774 | *) 775 | echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; 776 | esac 777 | exit ;; 778 | i*:CYGWIN*:*) 779 | echo ${UNAME_MACHINE}-pc-cygwin 780 | exit ;; 781 | i*:MINGW*:*) 782 | echo ${UNAME_MACHINE}-pc-mingw32 783 | exit ;; 784 | i*:MSYS_NT-*:*:*) 785 | echo ${UNAME_MACHINE}-pc-mingw32 786 | exit ;; 787 | i*:windows32*:*) 788 | # uname -m includes "-pc" on this system. 789 | echo ${UNAME_MACHINE}-mingw32 790 | exit ;; 791 | i*:PW*:*) 792 | echo ${UNAME_MACHINE}-pc-pw32 793 | exit ;; 794 | x86:Interix*:[345]*) 795 | echo i586-pc-interix${UNAME_RELEASE} 796 | exit ;; 797 | EM64T:Interix*:[345]*) 798 | echo x86_64-unknown-interix${UNAME_RELEASE} 799 | exit ;; 800 | [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) 801 | echo i${UNAME_MACHINE}-pc-mks 802 | exit ;; 803 | i*:Windows_NT*:* | Pentium*:Windows_NT*:*) 804 | # How do we know it's Interix rather than the generic POSIX subsystem? 805 | # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we 806 | # UNAME_MACHINE based on the output of uname instead of i386? 807 | echo i586-pc-interix 808 | exit ;; 809 | i*:UWIN*:*) 810 | echo ${UNAME_MACHINE}-pc-uwin 811 | exit ;; 812 | amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) 813 | echo x86_64-unknown-cygwin 814 | exit ;; 815 | p*:CYGWIN*:*) 816 | echo powerpcle-unknown-cygwin 817 | exit ;; 818 | prep*:SunOS:5.*:*) 819 | echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` 820 | exit ;; 821 | *:GNU:*:*) 822 | # the GNU system 823 | echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` 824 | exit ;; 825 | *:GNU/*:*:*) 826 | # other systems with GNU libc and userland 827 | echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu 828 | exit ;; 829 | i*86:Minix:*:*) 830 | echo ${UNAME_MACHINE}-pc-minix 831 | exit ;; 832 | arm*:Linux:*:*) 833 | echo ${UNAME_MACHINE}-unknown-linux-gnu 834 | exit ;; 835 | cris:Linux:*:*) 836 | echo cris-axis-linux-gnu 837 | exit ;; 838 | crisv32:Linux:*:*) 839 | echo crisv32-axis-linux-gnu 840 | exit ;; 841 | frv:Linux:*:*) 842 | echo frv-unknown-linux-gnu 843 | exit ;; 844 | ia64:Linux:*:*) 845 | echo ${UNAME_MACHINE}-unknown-linux-gnu 846 | exit ;; 847 | m32r*:Linux:*:*) 848 | echo ${UNAME_MACHINE}-unknown-linux-gnu 849 | exit ;; 850 | m68*:Linux:*:*) 851 | echo ${UNAME_MACHINE}-unknown-linux-gnu 852 | exit ;; 853 | mips:Linux:*:*) 854 | eval $set_cc_for_build 855 | sed 's/^ //' << EOF >$dummy.c 856 | #undef CPU 857 | #undef mips 858 | #undef mipsel 859 | #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) 860 | CPU=mipsel 861 | #else 862 | #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) 863 | CPU=mips 864 | #else 865 | CPU= 866 | #endif 867 | #endif 868 | EOF 869 | eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' 870 | /^CPU/{ 871 | s: ::g 872 | p 873 | }'`" 874 | test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } 875 | ;; 876 | mips64:Linux:*:*) 877 | eval $set_cc_for_build 878 | sed 's/^ //' << EOF >$dummy.c 879 | #undef CPU 880 | #undef mips64 881 | #undef mips64el 882 | #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) 883 | CPU=mips64el 884 | #else 885 | #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) 886 | CPU=mips64 887 | #else 888 | CPU= 889 | #endif 890 | #endif 891 | EOF 892 | eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' 893 | /^CPU/{ 894 | s: ::g 895 | p 896 | }'`" 897 | test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } 898 | ;; 899 | or32:Linux:*:*) 900 | echo or32-unknown-linux-gnu 901 | exit ;; 902 | ppc:Linux:*:*) 903 | echo powerpc-unknown-linux-gnu 904 | exit ;; 905 | ppc64:Linux:*:*) 906 | echo powerpc64-unknown-linux-gnu 907 | exit ;; 908 | alpha:Linux:*:*) 909 | case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in 910 | EV5) UNAME_MACHINE=alphaev5 ;; 911 | EV56) UNAME_MACHINE=alphaev56 ;; 912 | PCA56) UNAME_MACHINE=alphapca56 ;; 913 | PCA57) UNAME_MACHINE=alphapca56 ;; 914 | EV6) UNAME_MACHINE=alphaev6 ;; 915 | EV67) UNAME_MACHINE=alphaev67 ;; 916 | EV68*) UNAME_MACHINE=alphaev68 ;; 917 | esac 918 | objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null 919 | if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi 920 | echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} 921 | exit ;; 922 | parisc:Linux:*:* | hppa:Linux:*:*) 923 | # Look for CPU level 924 | case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in 925 | PA7*) echo hppa1.1-unknown-linux-gnu ;; 926 | PA8*) echo hppa2.0-unknown-linux-gnu ;; 927 | *) echo hppa-unknown-linux-gnu ;; 928 | esac 929 | exit ;; 930 | parisc64:Linux:*:* | hppa64:Linux:*:*) 931 | echo hppa64-unknown-linux-gnu 932 | exit ;; 933 | s390:Linux:*:* | s390x:Linux:*:*) 934 | echo ${UNAME_MACHINE}-ibm-linux 935 | exit ;; 936 | sh64*:Linux:*:*) 937 | echo ${UNAME_MACHINE}-unknown-linux-gnu 938 | exit ;; 939 | sh*:Linux:*:*) 940 | echo ${UNAME_MACHINE}-unknown-linux-gnu 941 | exit ;; 942 | sparc:Linux:*:* | sparc64:Linux:*:*) 943 | echo ${UNAME_MACHINE}-unknown-linux-gnu 944 | exit ;; 945 | vax:Linux:*:*) 946 | echo ${UNAME_MACHINE}-dec-linux-gnu 947 | exit ;; 948 | x86_64:Linux:*:*) 949 | echo x86_64-unknown-linux-gnu 950 | exit ;; 951 | i*86:Linux:*:*) 952 | # The BFD linker knows what the default object file format is, so 953 | # first see if it will tell us. cd to the root directory to prevent 954 | # problems with other programs or directories called `ld' in the path. 955 | # Set LC_ALL=C to ensure ld outputs messages in English. 956 | ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \ 957 | | sed -ne '/supported targets:/!d 958 | s/[ ][ ]*/ /g 959 | s/.*supported targets: *// 960 | s/ .*// 961 | p'` 962 | case "$ld_supported_targets" in 963 | elf32-i386) 964 | TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" 965 | ;; 966 | a.out-i386-linux) 967 | echo "${UNAME_MACHINE}-pc-linux-gnuaout" 968 | exit ;; 969 | coff-i386) 970 | echo "${UNAME_MACHINE}-pc-linux-gnucoff" 971 | exit ;; 972 | "") 973 | # Either a pre-BFD a.out linker (linux-gnuoldld) or 974 | # one that does not give us useful --help. 975 | echo "${UNAME_MACHINE}-pc-linux-gnuoldld" 976 | exit ;; 977 | esac 978 | # Determine whether the default compiler is a.out or elf 979 | eval $set_cc_for_build 980 | sed 's/^ //' << EOF >$dummy.c 981 | #include 982 | #ifdef __ELF__ 983 | # ifdef __GLIBC__ 984 | # if __GLIBC__ >= 2 985 | LIBC=gnu 986 | # else 987 | LIBC=gnulibc1 988 | # endif 989 | # else 990 | LIBC=gnulibc1 991 | # endif 992 | #else 993 | #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__sun) 994 | LIBC=gnu 995 | #else 996 | LIBC=gnuaout 997 | #endif 998 | #endif 999 | #ifdef __dietlibc__ 1000 | LIBC=dietlibc 1001 | #endif 1002 | EOF 1003 | eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' 1004 | /^LIBC/{ 1005 | s: ::g 1006 | p 1007 | }'`" 1008 | test x"${LIBC}" != x && { 1009 | echo "${UNAME_MACHINE}-pc-linux-${LIBC}" 1010 | exit 1011 | } 1012 | test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } 1013 | ;; 1014 | i*86:DYNIX/ptx:4*:*) 1015 | # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. 1016 | # earlier versions are messed up and put the nodename in both 1017 | # sysname and nodename. 1018 | echo i386-sequent-sysv4 1019 | exit ;; 1020 | i*86:UNIX_SV:4.2MP:2.*) 1021 | # Unixware is an offshoot of SVR4, but it has its own version 1022 | # number series starting with 2... 1023 | # I am not positive that other SVR4 systems won't match this, 1024 | # I just have to hope. -- rms. 1025 | # Use sysv4.2uw... so that sysv4* matches it. 1026 | echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} 1027 | exit ;; 1028 | i*86:OS/2:*:*) 1029 | # If we were able to find `uname', then EMX Unix compatibility 1030 | # is probably installed. 1031 | echo ${UNAME_MACHINE}-pc-os2-emx 1032 | exit ;; 1033 | i*86:XTS-300:*:STOP) 1034 | echo ${UNAME_MACHINE}-unknown-stop 1035 | exit ;; 1036 | i*86:atheos:*:*) 1037 | echo ${UNAME_MACHINE}-unknown-atheos 1038 | exit ;; 1039 | i*86:syllable:*:*) 1040 | echo ${UNAME_MACHINE}-pc-syllable 1041 | exit ;; 1042 | i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) 1043 | echo i386-unknown-lynxos${UNAME_RELEASE} 1044 | exit ;; 1045 | i*86:*DOS:*:*) 1046 | echo ${UNAME_MACHINE}-pc-msdosdjgpp 1047 | exit ;; 1048 | i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) 1049 | UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` 1050 | if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then 1051 | echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} 1052 | else 1053 | echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} 1054 | fi 1055 | exit ;; 1056 | i*86:*:5:[678]*) 1057 | # UnixWare 7.x, OpenUNIX and OpenServer 6. 1058 | case `/bin/uname -X | grep "^Machine"` in 1059 | *486*) UNAME_MACHINE=i486 ;; 1060 | *Pentium) UNAME_MACHINE=i586 ;; 1061 | *Pent*|*Celeron) UNAME_MACHINE=i686 ;; 1062 | esac 1063 | echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} 1064 | exit ;; 1065 | i*86:*:3.2:*) 1066 | if test -f /usr/options/cb.name; then 1067 | UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then 1070 | UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` 1071 | (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 1072 | (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ 1073 | && UNAME_MACHINE=i586 1074 | (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ 1075 | && UNAME_MACHINE=i686 1076 | (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ 1077 | && UNAME_MACHINE=i686 1078 | echo ${UNAME_MACHINE}-pc-sco$UNAME_REL 1079 | else 1080 | echo ${UNAME_MACHINE}-pc-sysv32 1081 | fi 1082 | exit ;; 1083 | pc:*:*:*) 1084 | # Left here for compatibility: 1085 | # uname -m prints for DJGPP always 'pc', but it prints nothing about 1086 | # the processor, so we play safe by assuming i386. 1087 | echo i386-pc-msdosdjgpp 1088 | exit ;; 1089 | Intel:Mach:3*:*) 1090 | echo i386-pc-mach3 1091 | exit ;; 1092 | paragon:*:*:*) 1093 | echo i860-intel-osf1 1094 | exit ;; 1095 | i860:*:4.*:*) # i860-SVR4 1096 | if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then 1097 | echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 1098 | else # Add other i860-SVR4 vendors below as they are discovered. 1099 | echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 1100 | fi 1101 | exit ;; 1102 | mini*:CTIX:SYS*5:*) 1103 | # "miniframe" 1104 | echo m68010-convergent-sysv 1105 | exit ;; 1106 | mc68k:UNIX:SYSTEM5:3.51m) 1107 | echo m68k-convergent-sysv 1108 | exit ;; 1109 | M680?0:D-NIX:5.3:*) 1110 | echo m68k-diab-dnix 1111 | exit ;; 1112 | M68*:*:R3V[5678]*:*) 1113 | test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; 1114 | 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) 1115 | OS_REL='' 1116 | test -r /etc/.relid \ 1117 | && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` 1118 | /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ 1119 | && { echo i486-ncr-sysv4.3${OS_REL}; exit; } 1120 | /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ 1121 | && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; 1122 | 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) 1123 | /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ 1124 | && { echo i486-ncr-sysv4; exit; } ;; 1125 | m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) 1126 | echo m68k-unknown-lynxos${UNAME_RELEASE} 1127 | exit ;; 1128 | mc68030:UNIX_System_V:4.*:*) 1129 | echo m68k-atari-sysv4 1130 | exit ;; 1131 | TSUNAMI:LynxOS:2.*:*) 1132 | echo sparc-unknown-lynxos${UNAME_RELEASE} 1133 | exit ;; 1134 | rs6000:LynxOS:2.*:*) 1135 | echo rs6000-unknown-lynxos${UNAME_RELEASE} 1136 | exit ;; 1137 | PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) 1138 | echo powerpc-unknown-lynxos${UNAME_RELEASE} 1139 | exit ;; 1140 | SM[BE]S:UNIX_SV:*:*) 1141 | echo mips-dde-sysv${UNAME_RELEASE} 1142 | exit ;; 1143 | RM*:ReliantUNIX-*:*:*) 1144 | echo mips-sni-sysv4 1145 | exit ;; 1146 | RM*:SINIX-*:*:*) 1147 | echo mips-sni-sysv4 1148 | exit ;; 1149 | *:SINIX-*:*:*) 1150 | if uname -p 2>/dev/null >/dev/null ; then 1151 | UNAME_MACHINE=`(uname -p) 2>/dev/null` 1152 | echo ${UNAME_MACHINE}-sni-sysv4 1153 | else 1154 | echo ns32k-sni-sysv 1155 | fi 1156 | exit ;; 1157 | PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort 1158 | # says 1159 | echo i586-unisys-sysv4 1160 | exit ;; 1161 | *:UNIX_System_V:4*:FTX*) 1162 | # From Gerald Hewes . 1163 | # How about differentiating between stratus architectures? -djm 1164 | echo hppa1.1-stratus-sysv4 1165 | exit ;; 1166 | *:*:*:FTX*) 1167 | # From seanf@swdc.stratus.com. 1168 | echo i860-stratus-sysv4 1169 | exit ;; 1170 | i*86:VOS:*:*) 1171 | # From Paul.Green@stratus.com. 1172 | echo ${UNAME_MACHINE}-stratus-vos 1173 | exit ;; 1174 | *:VOS:*:*) 1175 | # From Paul.Green@stratus.com. 1176 | echo hppa1.1-stratus-vos 1177 | exit ;; 1178 | mc68*:A/UX:*:*) 1179 | echo m68k-apple-aux${UNAME_RELEASE} 1180 | exit ;; 1181 | news*:NEWS-OS:6*:*) 1182 | echo mips-sony-newsos6 1183 | exit ;; 1184 | R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) 1185 | if [ -d /usr/nec ]; then 1186 | echo mips-nec-sysv${UNAME_RELEASE} 1187 | else 1188 | echo mips-unknown-sysv${UNAME_RELEASE} 1189 | fi 1190 | exit ;; 1191 | BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. 1192 | echo powerpc-be-beos 1193 | exit ;; 1194 | BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. 1195 | echo powerpc-apple-beos 1196 | exit ;; 1197 | BePC:BeOS:*:*) # BeOS running on Intel PC compatible. 1198 | echo i586-pc-beos 1199 | exit ;; 1200 | SX-4:SUPER-UX:*:*) 1201 | echo sx4-nec-superux${UNAME_RELEASE} 1202 | exit ;; 1203 | SX-5:SUPER-UX:*:*) 1204 | echo sx5-nec-superux${UNAME_RELEASE} 1205 | exit ;; 1206 | SX-6:SUPER-UX:*:*) 1207 | echo sx6-nec-superux${UNAME_RELEASE} 1208 | exit ;; 1209 | Power*:Rhapsody:*:*) 1210 | echo powerpc-apple-rhapsody${UNAME_RELEASE} 1211 | exit ;; 1212 | *:Rhapsody:*:*) 1213 | echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} 1214 | exit ;; 1215 | *:Darwin:*:*) 1216 | UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown 1217 | case $UNAME_PROCESSOR in 1218 | unknown) UNAME_PROCESSOR=powerpc ;; 1219 | esac 1220 | echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} 1221 | exit ;; 1222 | *:procnto*:*:* | *:QNX:[0123456789]*:*) 1223 | UNAME_PROCESSOR=`uname -p` 1224 | if test "$UNAME_PROCESSOR" = "x86"; then 1225 | UNAME_PROCESSOR=i386 1226 | UNAME_MACHINE=pc 1227 | fi 1228 | echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} 1229 | exit ;; 1230 | *:QNX:*:4*) 1231 | echo i386-pc-qnx 1232 | exit ;; 1233 | NSE-?:NONSTOP_KERNEL:*:*) 1234 | echo nse-tandem-nsk${UNAME_RELEASE} 1235 | exit ;; 1236 | NSR-?:NONSTOP_KERNEL:*:*) 1237 | echo nsr-tandem-nsk${UNAME_RELEASE} 1238 | exit ;; 1239 | *:NonStop-UX:*:*) 1240 | echo mips-compaq-nonstopux 1241 | exit ;; 1242 | BS2000:POSIX*:*:*) 1243 | echo bs2000-siemens-sysv 1244 | exit ;; 1245 | DS/*:UNIX_System_V:*:*) 1246 | echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} 1247 | exit ;; 1248 | *:Plan9:*:*) 1249 | # "uname -m" is not consistent, so use $cputype instead. 386 1250 | # is converted to i386 for consistency with other x86 1251 | # operating systems. 1252 | if test "$cputype" = "386"; then 1253 | UNAME_MACHINE=i386 1254 | else 1255 | UNAME_MACHINE="$cputype" 1256 | fi 1257 | echo ${UNAME_MACHINE}-unknown-plan9 1258 | exit ;; 1259 | *:TOPS-10:*:*) 1260 | echo pdp10-unknown-tops10 1261 | exit ;; 1262 | *:TENEX:*:*) 1263 | echo pdp10-unknown-tenex 1264 | exit ;; 1265 | KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) 1266 | echo pdp10-dec-tops20 1267 | exit ;; 1268 | XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) 1269 | echo pdp10-xkl-tops20 1270 | exit ;; 1271 | *:TOPS-20:*:*) 1272 | echo pdp10-unknown-tops20 1273 | exit ;; 1274 | *:ITS:*:*) 1275 | echo pdp10-unknown-its 1276 | exit ;; 1277 | SEI:*:*:SEIUX) 1278 | echo mips-sei-seiux${UNAME_RELEASE} 1279 | exit ;; 1280 | *:DragonFly:*:*) 1281 | echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` 1282 | exit ;; 1283 | *:*VMS:*:*) 1284 | UNAME_MACHINE=`(uname -p) 2>/dev/null` 1285 | case "${UNAME_MACHINE}" in 1286 | A*) echo alpha-dec-vms ; exit ;; 1287 | I*) echo ia64-dec-vms ; exit ;; 1288 | V*) echo vax-dec-vms ; exit ;; 1289 | esac ;; 1290 | *:XENIX:*:SysV) 1291 | echo i386-pc-xenix 1292 | exit ;; 1293 | i*86:skyos:*:*) 1294 | echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' 1295 | exit ;; 1296 | i*86:rdos:*:*) 1297 | echo ${UNAME_MACHINE}-pc-rdos 1298 | exit ;; 1299 | esac 1300 | 1301 | #echo '(No uname command or uname output not recognized.)' 1>&2 1302 | #echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 1303 | 1304 | eval $set_cc_for_build 1305 | cat >$dummy.c < 1308 | # include 1309 | #endif 1310 | main () 1311 | { 1312 | #if defined (sony) 1313 | #if defined (MIPSEB) 1314 | /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, 1315 | I don't know.... */ 1316 | printf ("mips-sony-bsd\n"); exit (0); 1317 | #else 1318 | #include 1319 | printf ("m68k-sony-newsos%s\n", 1320 | #ifdef NEWSOS4 1321 | "4" 1322 | #else 1323 | "" 1324 | #endif 1325 | ); exit (0); 1326 | #endif 1327 | #endif 1328 | 1329 | #if defined (__arm) && defined (__acorn) && defined (__unix) 1330 | printf ("arm-acorn-riscix\n"); exit (0); 1331 | #endif 1332 | 1333 | #if defined (hp300) && !defined (hpux) 1334 | printf ("m68k-hp-bsd\n"); exit (0); 1335 | #endif 1336 | 1337 | #if defined (NeXT) 1338 | #if !defined (__ARCHITECTURE__) 1339 | #define __ARCHITECTURE__ "m68k" 1340 | #endif 1341 | int version; 1342 | version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; 1343 | if (version < 4) 1344 | printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); 1345 | else 1346 | printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); 1347 | exit (0); 1348 | #endif 1349 | 1350 | #if defined (MULTIMAX) || defined (n16) 1351 | #if defined (UMAXV) 1352 | printf ("ns32k-encore-sysv\n"); exit (0); 1353 | #else 1354 | #if defined (CMU) 1355 | printf ("ns32k-encore-mach\n"); exit (0); 1356 | #else 1357 | printf ("ns32k-encore-bsd\n"); exit (0); 1358 | #endif 1359 | #endif 1360 | #endif 1361 | 1362 | #if defined (__386BSD__) 1363 | printf ("i386-pc-bsd\n"); exit (0); 1364 | #endif 1365 | 1366 | #if defined (sequent) 1367 | #if defined (i386) 1368 | printf ("i386-sequent-dynix\n"); exit (0); 1369 | #endif 1370 | #if defined (ns32000) 1371 | printf ("ns32k-sequent-dynix\n"); exit (0); 1372 | #endif 1373 | #endif 1374 | 1375 | #if defined (_SEQUENT_) 1376 | struct utsname un; 1377 | 1378 | uname(&un); 1379 | 1380 | if (strncmp(un.version, "V2", 2) == 0) { 1381 | printf ("i386-sequent-ptx2\n"); exit (0); 1382 | } 1383 | if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ 1384 | printf ("i386-sequent-ptx1\n"); exit (0); 1385 | } 1386 | printf ("i386-sequent-ptx\n"); exit (0); 1387 | 1388 | #endif 1389 | 1390 | #if defined (vax) 1391 | # if !defined (ultrix) 1392 | # include 1393 | # if defined (BSD) 1394 | # if BSD == 43 1395 | printf ("vax-dec-bsd4.3\n"); exit (0); 1396 | # else 1397 | # if BSD == 199006 1398 | printf ("vax-dec-bsd4.3reno\n"); exit (0); 1399 | # else 1400 | printf ("vax-dec-bsd\n"); exit (0); 1401 | # endif 1402 | # endif 1403 | # else 1404 | printf ("vax-dec-bsd\n"); exit (0); 1405 | # endif 1406 | # else 1407 | printf ("vax-dec-ultrix\n"); exit (0); 1408 | # endif 1409 | #endif 1410 | 1411 | #if defined (alliant) && defined (i860) 1412 | printf ("i860-alliant-bsd\n"); exit (0); 1413 | #endif 1414 | 1415 | exit (1); 1416 | } 1417 | EOF 1418 | 1419 | $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && 1420 | { echo "$SYSTEM_NAME"; exit; } 1421 | 1422 | # Apollos put the system type in the environment. 1423 | 1424 | test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } 1425 | 1426 | # Convex versions that predate uname can use getsysinfo(1) 1427 | 1428 | if [ -x /usr/convex/getsysinfo ] 1429 | then 1430 | case `getsysinfo -f cpu_type` in 1431 | c1*) 1432 | echo c1-convex-bsd 1433 | exit ;; 1434 | c2*) 1435 | if getsysinfo -f scalar_acc 1436 | then echo c32-convex-bsd 1437 | else echo c2-convex-bsd 1438 | fi 1439 | exit ;; 1440 | c34*) 1441 | echo c34-convex-bsd 1442 | exit ;; 1443 | c38*) 1444 | echo c38-convex-bsd 1445 | exit ;; 1446 | c4*) 1447 | echo c4-convex-bsd 1448 | exit ;; 1449 | esac 1450 | fi 1451 | 1452 | cat >&2 < in order to provide the needed 1466 | information to handle your system. 1467 | 1468 | config.guess timestamp = $timestamp 1469 | 1470 | uname -m = `(uname -m) 2>/dev/null || echo unknown` 1471 | uname -r = `(uname -r) 2>/dev/null || echo unknown` 1472 | uname -s = `(uname -s) 2>/dev/null || echo unknown` 1473 | uname -v = `(uname -v) 2>/dev/null || echo unknown` 1474 | 1475 | /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` 1476 | /bin/uname -X = `(/bin/uname -X) 2>/dev/null` 1477 | 1478 | hostinfo = `(hostinfo) 2>/dev/null` 1479 | /bin/universe = `(/bin/universe) 2>/dev/null` 1480 | /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` 1481 | /bin/arch = `(/bin/arch) 2>/dev/null` 1482 | /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` 1483 | /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` 1484 | 1485 | UNAME_MACHINE = ${UNAME_MACHINE} 1486 | UNAME_RELEASE = ${UNAME_RELEASE} 1487 | UNAME_SYSTEM = ${UNAME_SYSTEM} 1488 | UNAME_VERSION = ${UNAME_VERSION} 1489 | EOF 1490 | 1491 | exit 1 1492 | 1493 | # Local variables: 1494 | # eval: (add-hook 'write-file-hooks 'time-stamp) 1495 | # time-stamp-start: "timestamp='" 1496 | # time-stamp-format: "%:y-%02m-%02d" 1497 | # time-stamp-end: "'" 1498 | # End: 1499 | -------------------------------------------------------------------------------- /autoconf/config.sub: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Configuration validation subroutine script. 3 | # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 4 | # 2000, 2001, 2002, 2003 Free Software Foundation, Inc. 5 | 6 | timestamp='2003-02-22' 7 | 8 | # This file is (in principle) common to ALL GNU software. 9 | # The presence of a machine in this file suggests that SOME GNU software 10 | # can handle that machine. It does not imply ALL GNU software can. 11 | # 12 | # This file is free software; you can redistribute it and/or modify 13 | # it under the terms of the GNU General Public License as published by 14 | # the Free Software Foundation; either version 2 of the License, or 15 | # (at your option) any later version. 16 | # 17 | # This program is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | # GNU General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU General Public License 23 | # along with this program; if not, write to the Free Software 24 | # Foundation, Inc., 59 Temple Place - Suite 330, 25 | # Boston, MA 02111-1307, USA. 26 | 27 | # As a special exception to the GNU General Public License, if you 28 | # distribute this file as part of a program that contains a 29 | # configuration script generated by Autoconf, you may include it under 30 | # the same distribution terms that you use for the rest of that program. 31 | 32 | # Please send patches to . Submit a context 33 | # diff and a properly formatted ChangeLog entry. 34 | # 35 | # Configuration subroutine to validate and canonicalize a configuration type. 36 | # Supply the specified configuration type as an argument. 37 | # If it is invalid, we print an error message on stderr and exit with code 1. 38 | # Otherwise, we print the canonical config type on stdout and succeed. 39 | 40 | # This file is supposed to be the same for all GNU packages 41 | # and recognize all the CPU types, system types and aliases 42 | # that are meaningful with *any* GNU software. 43 | # Each package is responsible for reporting which valid configurations 44 | # it does not support. The user should be able to distinguish 45 | # a failure to support a valid configuration from a meaningless 46 | # configuration. 47 | 48 | # The goal of this file is to map all the various variations of a given 49 | # machine specification into a single specification in the form: 50 | # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM 51 | # or in some cases, the newer four-part form: 52 | # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM 53 | # It is wrong to echo any other type of specification. 54 | 55 | me=`echo "$0" | sed -e 's,.*/,,'` 56 | 57 | usage="\ 58 | Usage: $0 [OPTION] CPU-MFR-OPSYS 59 | $0 [OPTION] ALIAS 60 | 61 | Canonicalize a configuration name. 62 | 63 | Operation modes: 64 | -h, --help print this help, then exit 65 | -t, --time-stamp print date of last modification, then exit 66 | -v, --version print version number, then exit 67 | 68 | Report bugs and patches to ." 69 | 70 | version="\ 71 | GNU config.sub ($timestamp) 72 | 73 | Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 74 | Free Software Foundation, Inc. 75 | 76 | This is free software; see the source for copying conditions. There is NO 77 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." 78 | 79 | help=" 80 | Try \`$me --help' for more information." 81 | 82 | # Parse command line 83 | while test $# -gt 0 ; do 84 | case $1 in 85 | --time-stamp | --time* | -t ) 86 | echo "$timestamp" ; exit 0 ;; 87 | --version | -v ) 88 | echo "$version" ; exit 0 ;; 89 | --help | --h* | -h ) 90 | echo "$usage"; exit 0 ;; 91 | -- ) # Stop option processing 92 | shift; break ;; 93 | - ) # Use stdin as input. 94 | break ;; 95 | -* ) 96 | echo "$me: invalid option $1$help" 97 | exit 1 ;; 98 | 99 | *local*) 100 | # First pass through any local machine types. 101 | echo $1 102 | exit 0;; 103 | 104 | * ) 105 | break ;; 106 | esac 107 | done 108 | 109 | case $# in 110 | 0) echo "$me: missing argument$help" >&2 111 | exit 1;; 112 | 1) ;; 113 | *) echo "$me: too many arguments$help" >&2 114 | exit 1;; 115 | esac 116 | 117 | # Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). 118 | # Here we must recognize all the valid KERNEL-OS combinations. 119 | maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` 120 | case $maybe_os in 121 | nto-qnx* | linux-gnu* | freebsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*) 122 | os=-$maybe_os 123 | basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` 124 | ;; 125 | *) 126 | basic_machine=`echo $1 | sed 's/-[^-]*$//'` 127 | if [ $basic_machine != $1 ] 128 | then os=`echo $1 | sed 's/.*-/-/'` 129 | else os=; fi 130 | ;; 131 | esac 132 | 133 | ### Let's recognize common machines as not being operating systems so 134 | ### that things like config.sub decstation-3100 work. We also 135 | ### recognize some manufacturers as not being operating systems, so we 136 | ### can provide default operating systems below. 137 | case $os in 138 | -sun*os*) 139 | # Prevent following clause from handling this invalid input. 140 | ;; 141 | -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ 142 | -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ 143 | -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ 144 | -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ 145 | -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ 146 | -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ 147 | -apple | -axis) 148 | os= 149 | basic_machine=$1 150 | ;; 151 | -sim | -cisco | -oki | -wec | -winbond) 152 | os= 153 | basic_machine=$1 154 | ;; 155 | -scout) 156 | ;; 157 | -wrs) 158 | os=-vxworks 159 | basic_machine=$1 160 | ;; 161 | -chorusos*) 162 | os=-chorusos 163 | basic_machine=$1 164 | ;; 165 | -chorusrdb) 166 | os=-chorusrdb 167 | basic_machine=$1 168 | ;; 169 | -hiux*) 170 | os=-hiuxwe2 171 | ;; 172 | -sco5) 173 | os=-sco3.2v5 174 | basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` 175 | ;; 176 | -sco4) 177 | os=-sco3.2v4 178 | basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` 179 | ;; 180 | -sco3.2.[4-9]*) 181 | os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` 182 | basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` 183 | ;; 184 | -sco3.2v[4-9]*) 185 | # Don't forget version if it is 3.2v4 or newer. 186 | basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` 187 | ;; 188 | -sco*) 189 | os=-sco3.2v2 190 | basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` 191 | ;; 192 | -udk*) 193 | basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` 194 | ;; 195 | -isc) 196 | os=-isc2.2 197 | basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` 198 | ;; 199 | -clix*) 200 | basic_machine=clipper-intergraph 201 | ;; 202 | -isc*) 203 | basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` 204 | ;; 205 | -lynx*) 206 | os=-lynxos 207 | ;; 208 | -ptx*) 209 | basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` 210 | ;; 211 | -windowsnt*) 212 | os=`echo $os | sed -e 's/windowsnt/winnt/'` 213 | ;; 214 | -psos*) 215 | os=-psos 216 | ;; 217 | -mint | -mint[0-9]*) 218 | basic_machine=m68k-atari 219 | os=-mint 220 | ;; 221 | esac 222 | 223 | # Decode aliases for certain CPU-COMPANY combinations. 224 | case $basic_machine in 225 | # Recognize the basic CPU types without company name. 226 | # Some are omitted here because they have special meanings below. 227 | 1750a | 580 \ 228 | | a29k \ 229 | | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ 230 | | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ 231 | | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \ 232 | | clipper \ 233 | | d10v | d30v | dlx | dsp16xx \ 234 | | fr30 | frv \ 235 | | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ 236 | | i370 | i860 | i960 | ia64 \ 237 | | ip2k \ 238 | | m32r | m68000 | m68k | m88k | mcore \ 239 | | mips | mipsbe | mipseb | mipsel | mipsle \ 240 | | mips16 \ 241 | | mips64 | mips64el \ 242 | | mips64vr | mips64vrel \ 243 | | mips64orion | mips64orionel \ 244 | | mips64vr4100 | mips64vr4100el \ 245 | | mips64vr4300 | mips64vr4300el \ 246 | | mips64vr5000 | mips64vr5000el \ 247 | | mipsisa32 | mipsisa32el \ 248 | | mipsisa32r2 | mipsisa32r2el \ 249 | | mipsisa64 | mipsisa64el \ 250 | | mipsisa64sb1 | mipsisa64sb1el \ 251 | | mipsisa64sr71k | mipsisa64sr71kel \ 252 | | mipstx39 | mipstx39el \ 253 | | mn10200 | mn10300 \ 254 | | msp430 \ 255 | | ns16k | ns32k \ 256 | | openrisc | or32 \ 257 | | pdp10 | pdp11 | pj | pjl \ 258 | | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ 259 | | pyramid \ 260 | | sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \ 261 | | sh64 | sh64le \ 262 | | sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \ 263 | | strongarm \ 264 | | tahoe | thumb | tic80 | tron \ 265 | | v850 | v850e \ 266 | | we32k \ 267 | | x86 | xscale | xstormy16 | xtensa \ 268 | | z8k) 269 | basic_machine=$basic_machine-unknown 270 | ;; 271 | m6811 | m68hc11 | m6812 | m68hc12) 272 | # Motorola 68HC11/12. 273 | basic_machine=$basic_machine-unknown 274 | os=-none 275 | ;; 276 | m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) 277 | ;; 278 | 279 | # We use `pc' rather than `unknown' 280 | # because (1) that's what they normally are, and 281 | # (2) the word "unknown" tends to confuse beginning users. 282 | i*86 | x86_64) 283 | basic_machine=$basic_machine-pc 284 | ;; 285 | # Object if more than one company name word. 286 | *-*-*) 287 | echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 288 | exit 1 289 | ;; 290 | # Recognize the basic CPU types with company name. 291 | 580-* \ 292 | | a29k-* \ 293 | | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ 294 | | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ 295 | | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ 296 | | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ 297 | | avr-* \ 298 | | bs2000-* \ 299 | | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ 300 | | clipper-* | cydra-* \ 301 | | d10v-* | d30v-* | dlx-* \ 302 | | elxsi-* \ 303 | | f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \ 304 | | h8300-* | h8500-* \ 305 | | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ 306 | | i*86-* | i860-* | i960-* | ia64-* \ 307 | | ip2k-* \ 308 | | m32r-* \ 309 | | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ 310 | | m88110-* | m88k-* | mcore-* \ 311 | | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ 312 | | mips16-* \ 313 | | mips64-* | mips64el-* \ 314 | | mips64vr-* | mips64vrel-* \ 315 | | mips64orion-* | mips64orionel-* \ 316 | | mips64vr4100-* | mips64vr4100el-* \ 317 | | mips64vr4300-* | mips64vr4300el-* \ 318 | | mips64vr5000-* | mips64vr5000el-* \ 319 | | mipsisa32-* | mipsisa32el-* \ 320 | | mipsisa32r2-* | mipsisa32r2el-* \ 321 | | mipsisa64-* | mipsisa64el-* \ 322 | | mipsisa64sb1-* | mipsisa64sb1el-* \ 323 | | mipsisa64sr71k-* | mipsisa64sr71kel-* \ 324 | | mipstx39-* | mipstx39el-* \ 325 | | msp430-* \ 326 | | none-* | np1-* | nv1-* | ns16k-* | ns32k-* \ 327 | | orion-* \ 328 | | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ 329 | | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ 330 | | pyramid-* \ 331 | | romp-* | rs6000-* \ 332 | | sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \ 333 | | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ 334 | | sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \ 335 | | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \ 336 | | tahoe-* | thumb-* \ 337 | | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ 338 | | tron-* \ 339 | | v850-* | v850e-* | vax-* \ 340 | | we32k-* \ 341 | | x86-* | x86_64-* | xps100-* | xscale-* | xstormy16-* \ 342 | | xtensa-* \ 343 | | ymp-* \ 344 | | z8k-*) 345 | ;; 346 | # Recognize the various machine names and aliases which stand 347 | # for a CPU type and a company and sometimes even an OS. 348 | 386bsd) 349 | basic_machine=i386-unknown 350 | os=-bsd 351 | ;; 352 | 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) 353 | basic_machine=m68000-att 354 | ;; 355 | 3b*) 356 | basic_machine=we32k-att 357 | ;; 358 | a29khif) 359 | basic_machine=a29k-amd 360 | os=-udi 361 | ;; 362 | adobe68k) 363 | basic_machine=m68010-adobe 364 | os=-scout 365 | ;; 366 | alliant | fx80) 367 | basic_machine=fx80-alliant 368 | ;; 369 | altos | altos3068) 370 | basic_machine=m68k-altos 371 | ;; 372 | am29k) 373 | basic_machine=a29k-none 374 | os=-bsd 375 | ;; 376 | amdahl) 377 | basic_machine=580-amdahl 378 | os=-sysv 379 | ;; 380 | amiga | amiga-*) 381 | basic_machine=m68k-unknown 382 | ;; 383 | amigaos | amigados) 384 | basic_machine=m68k-unknown 385 | os=-amigaos 386 | ;; 387 | amigaunix | amix) 388 | basic_machine=m68k-unknown 389 | os=-sysv4 390 | ;; 391 | apollo68) 392 | basic_machine=m68k-apollo 393 | os=-sysv 394 | ;; 395 | apollo68bsd) 396 | basic_machine=m68k-apollo 397 | os=-bsd 398 | ;; 399 | aux) 400 | basic_machine=m68k-apple 401 | os=-aux 402 | ;; 403 | balance) 404 | basic_machine=ns32k-sequent 405 | os=-dynix 406 | ;; 407 | c90) 408 | basic_machine=c90-cray 409 | os=-unicos 410 | ;; 411 | convex-c1) 412 | basic_machine=c1-convex 413 | os=-bsd 414 | ;; 415 | convex-c2) 416 | basic_machine=c2-convex 417 | os=-bsd 418 | ;; 419 | convex-c32) 420 | basic_machine=c32-convex 421 | os=-bsd 422 | ;; 423 | convex-c34) 424 | basic_machine=c34-convex 425 | os=-bsd 426 | ;; 427 | convex-c38) 428 | basic_machine=c38-convex 429 | os=-bsd 430 | ;; 431 | cray | j90) 432 | basic_machine=j90-cray 433 | os=-unicos 434 | ;; 435 | crds | unos) 436 | basic_machine=m68k-crds 437 | ;; 438 | cris | cris-* | etrax*) 439 | basic_machine=cris-axis 440 | ;; 441 | da30 | da30-*) 442 | basic_machine=m68k-da30 443 | ;; 444 | decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) 445 | basic_machine=mips-dec 446 | ;; 447 | decsystem10* | dec10*) 448 | basic_machine=pdp10-dec 449 | os=-tops10 450 | ;; 451 | decsystem20* | dec20*) 452 | basic_machine=pdp10-dec 453 | os=-tops20 454 | ;; 455 | delta | 3300 | motorola-3300 | motorola-delta \ 456 | | 3300-motorola | delta-motorola) 457 | basic_machine=m68k-motorola 458 | ;; 459 | delta88) 460 | basic_machine=m88k-motorola 461 | os=-sysv3 462 | ;; 463 | dpx20 | dpx20-*) 464 | basic_machine=rs6000-bull 465 | os=-bosx 466 | ;; 467 | dpx2* | dpx2*-bull) 468 | basic_machine=m68k-bull 469 | os=-sysv3 470 | ;; 471 | ebmon29k) 472 | basic_machine=a29k-amd 473 | os=-ebmon 474 | ;; 475 | elxsi) 476 | basic_machine=elxsi-elxsi 477 | os=-bsd 478 | ;; 479 | encore | umax | mmax) 480 | basic_machine=ns32k-encore 481 | ;; 482 | es1800 | OSE68k | ose68k | ose | OSE) 483 | basic_machine=m68k-ericsson 484 | os=-ose 485 | ;; 486 | fx2800) 487 | basic_machine=i860-alliant 488 | ;; 489 | genix) 490 | basic_machine=ns32k-ns 491 | ;; 492 | gmicro) 493 | basic_machine=tron-gmicro 494 | os=-sysv 495 | ;; 496 | go32) 497 | basic_machine=i386-pc 498 | os=-go32 499 | ;; 500 | h3050r* | hiux*) 501 | basic_machine=hppa1.1-hitachi 502 | os=-hiuxwe2 503 | ;; 504 | h8300hms) 505 | basic_machine=h8300-hitachi 506 | os=-hms 507 | ;; 508 | h8300xray) 509 | basic_machine=h8300-hitachi 510 | os=-xray 511 | ;; 512 | h8500hms) 513 | basic_machine=h8500-hitachi 514 | os=-hms 515 | ;; 516 | harris) 517 | basic_machine=m88k-harris 518 | os=-sysv3 519 | ;; 520 | hp300-*) 521 | basic_machine=m68k-hp 522 | ;; 523 | hp300bsd) 524 | basic_machine=m68k-hp 525 | os=-bsd 526 | ;; 527 | hp300hpux) 528 | basic_machine=m68k-hp 529 | os=-hpux 530 | ;; 531 | hp3k9[0-9][0-9] | hp9[0-9][0-9]) 532 | basic_machine=hppa1.0-hp 533 | ;; 534 | hp9k2[0-9][0-9] | hp9k31[0-9]) 535 | basic_machine=m68000-hp 536 | ;; 537 | hp9k3[2-9][0-9]) 538 | basic_machine=m68k-hp 539 | ;; 540 | hp9k6[0-9][0-9] | hp6[0-9][0-9]) 541 | basic_machine=hppa1.0-hp 542 | ;; 543 | hp9k7[0-79][0-9] | hp7[0-79][0-9]) 544 | basic_machine=hppa1.1-hp 545 | ;; 546 | hp9k78[0-9] | hp78[0-9]) 547 | # FIXME: really hppa2.0-hp 548 | basic_machine=hppa1.1-hp 549 | ;; 550 | hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) 551 | # FIXME: really hppa2.0-hp 552 | basic_machine=hppa1.1-hp 553 | ;; 554 | hp9k8[0-9][13679] | hp8[0-9][13679]) 555 | basic_machine=hppa1.1-hp 556 | ;; 557 | hp9k8[0-9][0-9] | hp8[0-9][0-9]) 558 | basic_machine=hppa1.0-hp 559 | ;; 560 | hppa-next) 561 | os=-nextstep3 562 | ;; 563 | hppaosf) 564 | basic_machine=hppa1.1-hp 565 | os=-osf 566 | ;; 567 | hppro) 568 | basic_machine=hppa1.1-hp 569 | os=-proelf 570 | ;; 571 | i370-ibm* | ibm*) 572 | basic_machine=i370-ibm 573 | ;; 574 | # I'm not sure what "Sysv32" means. Should this be sysv3.2? 575 | i*86v32) 576 | basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` 577 | os=-sysv32 578 | ;; 579 | i*86v4*) 580 | basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` 581 | os=-sysv4 582 | ;; 583 | i*86v) 584 | basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` 585 | os=-sysv 586 | ;; 587 | i*86sol2) 588 | basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` 589 | os=-solaris2 590 | ;; 591 | i386mach) 592 | basic_machine=i386-mach 593 | os=-mach 594 | ;; 595 | i386-vsta | vsta) 596 | basic_machine=i386-unknown 597 | os=-vsta 598 | ;; 599 | iris | iris4d) 600 | basic_machine=mips-sgi 601 | case $os in 602 | -irix*) 603 | ;; 604 | *) 605 | os=-irix4 606 | ;; 607 | esac 608 | ;; 609 | isi68 | isi) 610 | basic_machine=m68k-isi 611 | os=-sysv 612 | ;; 613 | m88k-omron*) 614 | basic_machine=m88k-omron 615 | ;; 616 | magnum | m3230) 617 | basic_machine=mips-mips 618 | os=-sysv 619 | ;; 620 | merlin) 621 | basic_machine=ns32k-utek 622 | os=-sysv 623 | ;; 624 | mingw32) 625 | basic_machine=i386-pc 626 | os=-mingw32 627 | ;; 628 | miniframe) 629 | basic_machine=m68000-convergent 630 | ;; 631 | *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) 632 | basic_machine=m68k-atari 633 | os=-mint 634 | ;; 635 | mips3*-*) 636 | basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` 637 | ;; 638 | mips3*) 639 | basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown 640 | ;; 641 | mmix*) 642 | basic_machine=mmix-knuth 643 | os=-mmixware 644 | ;; 645 | monitor) 646 | basic_machine=m68k-rom68k 647 | os=-coff 648 | ;; 649 | morphos) 650 | basic_machine=powerpc-unknown 651 | os=-morphos 652 | ;; 653 | msdos) 654 | basic_machine=i386-pc 655 | os=-msdos 656 | ;; 657 | mvs) 658 | basic_machine=i370-ibm 659 | os=-mvs 660 | ;; 661 | ncr3000) 662 | basic_machine=i486-ncr 663 | os=-sysv4 664 | ;; 665 | netbsd386) 666 | basic_machine=i386-unknown 667 | os=-netbsd 668 | ;; 669 | netwinder) 670 | basic_machine=armv4l-rebel 671 | os=-linux 672 | ;; 673 | news | news700 | news800 | news900) 674 | basic_machine=m68k-sony 675 | os=-newsos 676 | ;; 677 | news1000) 678 | basic_machine=m68030-sony 679 | os=-newsos 680 | ;; 681 | news-3600 | risc-news) 682 | basic_machine=mips-sony 683 | os=-newsos 684 | ;; 685 | necv70) 686 | basic_machine=v70-nec 687 | os=-sysv 688 | ;; 689 | next | m*-next ) 690 | basic_machine=m68k-next 691 | case $os in 692 | -nextstep* ) 693 | ;; 694 | -ns2*) 695 | os=-nextstep2 696 | ;; 697 | *) 698 | os=-nextstep3 699 | ;; 700 | esac 701 | ;; 702 | nh3000) 703 | basic_machine=m68k-harris 704 | os=-cxux 705 | ;; 706 | nh[45]000) 707 | basic_machine=m88k-harris 708 | os=-cxux 709 | ;; 710 | nindy960) 711 | basic_machine=i960-intel 712 | os=-nindy 713 | ;; 714 | mon960) 715 | basic_machine=i960-intel 716 | os=-mon960 717 | ;; 718 | nonstopux) 719 | basic_machine=mips-compaq 720 | os=-nonstopux 721 | ;; 722 | np1) 723 | basic_machine=np1-gould 724 | ;; 725 | nv1) 726 | basic_machine=nv1-cray 727 | os=-unicosmp 728 | ;; 729 | nsr-tandem) 730 | basic_machine=nsr-tandem 731 | ;; 732 | op50n-* | op60c-*) 733 | basic_machine=hppa1.1-oki 734 | os=-proelf 735 | ;; 736 | or32 | or32-*) 737 | basic_machine=or32-unknown 738 | os=-coff 739 | ;; 740 | OSE68000 | ose68000) 741 | basic_machine=m68000-ericsson 742 | os=-ose 743 | ;; 744 | os68k) 745 | basic_machine=m68k-none 746 | os=-os68k 747 | ;; 748 | pa-hitachi) 749 | basic_machine=hppa1.1-hitachi 750 | os=-hiuxwe2 751 | ;; 752 | paragon) 753 | basic_machine=i860-intel 754 | os=-osf 755 | ;; 756 | pbd) 757 | basic_machine=sparc-tti 758 | ;; 759 | pbb) 760 | basic_machine=m68k-tti 761 | ;; 762 | pc532 | pc532-*) 763 | basic_machine=ns32k-pc532 764 | ;; 765 | pentium | p5 | k5 | k6 | nexgen | viac3) 766 | basic_machine=i586-pc 767 | ;; 768 | pentiumpro | p6 | 6x86 | athlon | athlon_*) 769 | basic_machine=i686-pc 770 | ;; 771 | pentiumii | pentium2) 772 | basic_machine=i686-pc 773 | ;; 774 | pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) 775 | basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` 776 | ;; 777 | pentiumpro-* | p6-* | 6x86-* | athlon-*) 778 | basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` 779 | ;; 780 | pentiumii-* | pentium2-*) 781 | basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` 782 | ;; 783 | pn) 784 | basic_machine=pn-gould 785 | ;; 786 | power) basic_machine=power-ibm 787 | ;; 788 | ppc) basic_machine=powerpc-unknown 789 | ;; 790 | ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` 791 | ;; 792 | ppcle | powerpclittle | ppc-le | powerpc-little) 793 | basic_machine=powerpcle-unknown 794 | ;; 795 | ppcle-* | powerpclittle-*) 796 | basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` 797 | ;; 798 | ppc64) basic_machine=powerpc64-unknown 799 | ;; 800 | ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` 801 | ;; 802 | ppc64le | powerpc64little | ppc64-le | powerpc64-little) 803 | basic_machine=powerpc64le-unknown 804 | ;; 805 | ppc64le-* | powerpc64little-*) 806 | basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` 807 | ;; 808 | ps2) 809 | basic_machine=i386-ibm 810 | ;; 811 | pw32) 812 | basic_machine=i586-unknown 813 | os=-pw32 814 | ;; 815 | rom68k) 816 | basic_machine=m68k-rom68k 817 | os=-coff 818 | ;; 819 | rm[46]00) 820 | basic_machine=mips-siemens 821 | ;; 822 | rtpc | rtpc-*) 823 | basic_machine=romp-ibm 824 | ;; 825 | s390 | s390-*) 826 | basic_machine=s390-ibm 827 | ;; 828 | s390x | s390x-*) 829 | basic_machine=s390x-ibm 830 | ;; 831 | sa29200) 832 | basic_machine=a29k-amd 833 | os=-udi 834 | ;; 835 | sb1) 836 | basic_machine=mipsisa64sb1-unknown 837 | ;; 838 | sb1el) 839 | basic_machine=mipsisa64sb1el-unknown 840 | ;; 841 | sequent) 842 | basic_machine=i386-sequent 843 | ;; 844 | sh) 845 | basic_machine=sh-hitachi 846 | os=-hms 847 | ;; 848 | sparclite-wrs | simso-wrs) 849 | basic_machine=sparclite-wrs 850 | os=-vxworks 851 | ;; 852 | sps7) 853 | basic_machine=m68k-bull 854 | os=-sysv2 855 | ;; 856 | spur) 857 | basic_machine=spur-unknown 858 | ;; 859 | st2000) 860 | basic_machine=m68k-tandem 861 | ;; 862 | stratus) 863 | basic_machine=i860-stratus 864 | os=-sysv4 865 | ;; 866 | sun2) 867 | basic_machine=m68000-sun 868 | ;; 869 | sun2os3) 870 | basic_machine=m68000-sun 871 | os=-sunos3 872 | ;; 873 | sun2os4) 874 | basic_machine=m68000-sun 875 | os=-sunos4 876 | ;; 877 | sun3os3) 878 | basic_machine=m68k-sun 879 | os=-sunos3 880 | ;; 881 | sun3os4) 882 | basic_machine=m68k-sun 883 | os=-sunos4 884 | ;; 885 | sun4os3) 886 | basic_machine=sparc-sun 887 | os=-sunos3 888 | ;; 889 | sun4os4) 890 | basic_machine=sparc-sun 891 | os=-sunos4 892 | ;; 893 | sun4sol2) 894 | basic_machine=sparc-sun 895 | os=-solaris2 896 | ;; 897 | sun3 | sun3-*) 898 | basic_machine=m68k-sun 899 | ;; 900 | sun4) 901 | basic_machine=sparc-sun 902 | ;; 903 | sun386 | sun386i | roadrunner) 904 | basic_machine=i386-sun 905 | ;; 906 | sv1) 907 | basic_machine=sv1-cray 908 | os=-unicos 909 | ;; 910 | symmetry) 911 | basic_machine=i386-sequent 912 | os=-dynix 913 | ;; 914 | t3e) 915 | basic_machine=alphaev5-cray 916 | os=-unicos 917 | ;; 918 | t90) 919 | basic_machine=t90-cray 920 | os=-unicos 921 | ;; 922 | tic4x | c4x*) 923 | basic_machine=tic4x-unknown 924 | os=-coff 925 | ;; 926 | tic54x | c54x*) 927 | basic_machine=tic54x-unknown 928 | os=-coff 929 | ;; 930 | tic55x | c55x*) 931 | basic_machine=tic55x-unknown 932 | os=-coff 933 | ;; 934 | tic6x | c6x*) 935 | basic_machine=tic6x-unknown 936 | os=-coff 937 | ;; 938 | tx39) 939 | basic_machine=mipstx39-unknown 940 | ;; 941 | tx39el) 942 | basic_machine=mipstx39el-unknown 943 | ;; 944 | toad1) 945 | basic_machine=pdp10-xkl 946 | os=-tops20 947 | ;; 948 | tower | tower-32) 949 | basic_machine=m68k-ncr 950 | ;; 951 | udi29k) 952 | basic_machine=a29k-amd 953 | os=-udi 954 | ;; 955 | ultra3) 956 | basic_machine=a29k-nyu 957 | os=-sym1 958 | ;; 959 | v810 | necv810) 960 | basic_machine=v810-nec 961 | os=-none 962 | ;; 963 | vaxv) 964 | basic_machine=vax-dec 965 | os=-sysv 966 | ;; 967 | vms) 968 | basic_machine=vax-dec 969 | os=-vms 970 | ;; 971 | vpp*|vx|vx-*) 972 | basic_machine=f301-fujitsu 973 | ;; 974 | vxworks960) 975 | basic_machine=i960-wrs 976 | os=-vxworks 977 | ;; 978 | vxworks68) 979 | basic_machine=m68k-wrs 980 | os=-vxworks 981 | ;; 982 | vxworks29k) 983 | basic_machine=a29k-wrs 984 | os=-vxworks 985 | ;; 986 | w65*) 987 | basic_machine=w65-wdc 988 | os=-none 989 | ;; 990 | w89k-*) 991 | basic_machine=hppa1.1-winbond 992 | os=-proelf 993 | ;; 994 | xps | xps100) 995 | basic_machine=xps100-honeywell 996 | ;; 997 | ymp) 998 | basic_machine=ymp-cray 999 | os=-unicos 1000 | ;; 1001 | z8k-*-coff) 1002 | basic_machine=z8k-unknown 1003 | os=-sim 1004 | ;; 1005 | none) 1006 | basic_machine=none-none 1007 | os=-none 1008 | ;; 1009 | 1010 | # Here we handle the default manufacturer of certain CPU types. It is in 1011 | # some cases the only manufacturer, in others, it is the most popular. 1012 | w89k) 1013 | basic_machine=hppa1.1-winbond 1014 | ;; 1015 | op50n) 1016 | basic_machine=hppa1.1-oki 1017 | ;; 1018 | op60c) 1019 | basic_machine=hppa1.1-oki 1020 | ;; 1021 | romp) 1022 | basic_machine=romp-ibm 1023 | ;; 1024 | rs6000) 1025 | basic_machine=rs6000-ibm 1026 | ;; 1027 | vax) 1028 | basic_machine=vax-dec 1029 | ;; 1030 | pdp10) 1031 | # there are many clones, so DEC is not a safe bet 1032 | basic_machine=pdp10-unknown 1033 | ;; 1034 | pdp11) 1035 | basic_machine=pdp11-dec 1036 | ;; 1037 | we32k) 1038 | basic_machine=we32k-att 1039 | ;; 1040 | sh3 | sh4 | sh[34]eb | sh[1234]le | sh[23]ele) 1041 | basic_machine=sh-unknown 1042 | ;; 1043 | sh64) 1044 | basic_machine=sh64-unknown 1045 | ;; 1046 | sparc | sparcv9 | sparcv9b) 1047 | basic_machine=sparc-sun 1048 | ;; 1049 | cydra) 1050 | basic_machine=cydra-cydrome 1051 | ;; 1052 | orion) 1053 | basic_machine=orion-highlevel 1054 | ;; 1055 | orion105) 1056 | basic_machine=clipper-highlevel 1057 | ;; 1058 | mac | mpw | mac-mpw) 1059 | basic_machine=m68k-apple 1060 | ;; 1061 | pmac | pmac-mpw) 1062 | basic_machine=powerpc-apple 1063 | ;; 1064 | *-unknown) 1065 | # Make sure to match an already-canonicalized machine name. 1066 | ;; 1067 | *) 1068 | echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 1069 | exit 1 1070 | ;; 1071 | esac 1072 | 1073 | # Here we canonicalize certain aliases for manufacturers. 1074 | case $basic_machine in 1075 | *-digital*) 1076 | basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` 1077 | ;; 1078 | *-commodore*) 1079 | basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` 1080 | ;; 1081 | *) 1082 | ;; 1083 | esac 1084 | 1085 | # Decode manufacturer-specific aliases for certain operating systems. 1086 | 1087 | if [ x"$os" != x"" ] 1088 | then 1089 | case $os in 1090 | # First match some system type aliases 1091 | # that might get confused with valid system types. 1092 | # -solaris* is a basic system type, with this one exception. 1093 | -solaris1 | -solaris1.*) 1094 | os=`echo $os | sed -e 's|solaris1|sunos4|'` 1095 | ;; 1096 | -solaris) 1097 | os=-solaris2 1098 | ;; 1099 | -svr4*) 1100 | os=-sysv4 1101 | ;; 1102 | -unixware*) 1103 | os=-sysv4.2uw 1104 | ;; 1105 | -gnu/linux*) 1106 | os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` 1107 | ;; 1108 | # First accept the basic system types. 1109 | # The portable systems comes first. 1110 | # Each alternative MUST END IN A *, to match a version number. 1111 | # -sysv* is not here because it comes later, after sysvr4. 1112 | -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ 1113 | | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ 1114 | | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ 1115 | | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ 1116 | | -aos* \ 1117 | | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ 1118 | | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ 1119 | | -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \ 1120 | | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ 1121 | | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ 1122 | | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ 1123 | | -chorusos* | -chorusrdb* \ 1124 | | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ 1125 | | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \ 1126 | | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ 1127 | | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ 1128 | | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ 1129 | | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ 1130 | | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ 1131 | | -powermax* | -dnix*) 1132 | # Remember, each alternative MUST END IN *, to match a version number. 1133 | ;; 1134 | -qnx*) 1135 | case $basic_machine in 1136 | x86-* | i*86-*) 1137 | ;; 1138 | *) 1139 | os=-nto$os 1140 | ;; 1141 | esac 1142 | ;; 1143 | -nto-qnx*) 1144 | ;; 1145 | -nto*) 1146 | os=`echo $os | sed -e 's|nto|nto-qnx|'` 1147 | ;; 1148 | -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ 1149 | | -windows* | -osx | -abug | -netware* | -os9* | -beos* \ 1150 | | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) 1151 | ;; 1152 | -mac*) 1153 | os=`echo $os | sed -e 's|mac|macos|'` 1154 | ;; 1155 | -linux*) 1156 | os=`echo $os | sed -e 's|linux|linux-gnu|'` 1157 | ;; 1158 | -sunos5*) 1159 | os=`echo $os | sed -e 's|sunos5|solaris2|'` 1160 | ;; 1161 | -sunos6*) 1162 | os=`echo $os | sed -e 's|sunos6|solaris3|'` 1163 | ;; 1164 | -opened*) 1165 | os=-openedition 1166 | ;; 1167 | -wince*) 1168 | os=-wince 1169 | ;; 1170 | -osfrose*) 1171 | os=-osfrose 1172 | ;; 1173 | -osf*) 1174 | os=-osf 1175 | ;; 1176 | -utek*) 1177 | os=-bsd 1178 | ;; 1179 | -dynix*) 1180 | os=-bsd 1181 | ;; 1182 | -acis*) 1183 | os=-aos 1184 | ;; 1185 | -atheos*) 1186 | os=-atheos 1187 | ;; 1188 | -386bsd) 1189 | os=-bsd 1190 | ;; 1191 | -ctix* | -uts*) 1192 | os=-sysv 1193 | ;; 1194 | -nova*) 1195 | os=-rtmk-nova 1196 | ;; 1197 | -ns2 ) 1198 | os=-nextstep2 1199 | ;; 1200 | -nsk*) 1201 | os=-nsk 1202 | ;; 1203 | # Preserve the version number of sinix5. 1204 | -sinix5.*) 1205 | os=`echo $os | sed -e 's|sinix|sysv|'` 1206 | ;; 1207 | -sinix*) 1208 | os=-sysv4 1209 | ;; 1210 | -triton*) 1211 | os=-sysv3 1212 | ;; 1213 | -oss*) 1214 | os=-sysv3 1215 | ;; 1216 | -svr4) 1217 | os=-sysv4 1218 | ;; 1219 | -svr3) 1220 | os=-sysv3 1221 | ;; 1222 | -sysvr4) 1223 | os=-sysv4 1224 | ;; 1225 | # This must come after -sysvr4. 1226 | -sysv*) 1227 | ;; 1228 | -ose*) 1229 | os=-ose 1230 | ;; 1231 | -es1800*) 1232 | os=-ose 1233 | ;; 1234 | -xenix) 1235 | os=-xenix 1236 | ;; 1237 | -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) 1238 | os=-mint 1239 | ;; 1240 | -aros*) 1241 | os=-aros 1242 | ;; 1243 | -kaos*) 1244 | os=-kaos 1245 | ;; 1246 | -none) 1247 | ;; 1248 | *) 1249 | # Get rid of the `-' at the beginning of $os. 1250 | os=`echo $os | sed 's/[^-]*-//'` 1251 | echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 1252 | exit 1 1253 | ;; 1254 | esac 1255 | else 1256 | 1257 | # Here we handle the default operating systems that come with various machines. 1258 | # The value should be what the vendor currently ships out the door with their 1259 | # machine or put another way, the most popular os provided with the machine. 1260 | 1261 | # Note that if you're going to try to match "-MANUFACTURER" here (say, 1262 | # "-sun"), then you have to tell the case statement up towards the top 1263 | # that MANUFACTURER isn't an operating system. Otherwise, code above 1264 | # will signal an error saying that MANUFACTURER isn't an operating 1265 | # system, and we'll never get to this point. 1266 | 1267 | case $basic_machine in 1268 | *-acorn) 1269 | os=-riscix1.2 1270 | ;; 1271 | arm*-rebel) 1272 | os=-linux 1273 | ;; 1274 | arm*-semi) 1275 | os=-aout 1276 | ;; 1277 | # This must come before the *-dec entry. 1278 | pdp10-*) 1279 | os=-tops20 1280 | ;; 1281 | pdp11-*) 1282 | os=-none 1283 | ;; 1284 | *-dec | vax-*) 1285 | os=-ultrix4.2 1286 | ;; 1287 | m68*-apollo) 1288 | os=-domain 1289 | ;; 1290 | i386-sun) 1291 | os=-sunos4.0.2 1292 | ;; 1293 | m68000-sun) 1294 | os=-sunos3 1295 | # This also exists in the configure program, but was not the 1296 | # default. 1297 | # os=-sunos4 1298 | ;; 1299 | m68*-cisco) 1300 | os=-aout 1301 | ;; 1302 | mips*-cisco) 1303 | os=-elf 1304 | ;; 1305 | mips*-*) 1306 | os=-elf 1307 | ;; 1308 | or32-*) 1309 | os=-coff 1310 | ;; 1311 | *-tti) # must be before sparc entry or we get the wrong os. 1312 | os=-sysv3 1313 | ;; 1314 | sparc-* | *-sun) 1315 | os=-sunos4.1.1 1316 | ;; 1317 | *-be) 1318 | os=-beos 1319 | ;; 1320 | *-ibm) 1321 | os=-aix 1322 | ;; 1323 | *-wec) 1324 | os=-proelf 1325 | ;; 1326 | *-winbond) 1327 | os=-proelf 1328 | ;; 1329 | *-oki) 1330 | os=-proelf 1331 | ;; 1332 | *-hp) 1333 | os=-hpux 1334 | ;; 1335 | *-hitachi) 1336 | os=-hiux 1337 | ;; 1338 | i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) 1339 | os=-sysv 1340 | ;; 1341 | *-cbm) 1342 | os=-amigaos 1343 | ;; 1344 | *-dg) 1345 | os=-dgux 1346 | ;; 1347 | *-dolphin) 1348 | os=-sysv3 1349 | ;; 1350 | m68k-ccur) 1351 | os=-rtu 1352 | ;; 1353 | m88k-omron*) 1354 | os=-luna 1355 | ;; 1356 | *-next ) 1357 | os=-nextstep 1358 | ;; 1359 | *-sequent) 1360 | os=-ptx 1361 | ;; 1362 | *-crds) 1363 | os=-unos 1364 | ;; 1365 | *-ns) 1366 | os=-genix 1367 | ;; 1368 | i370-*) 1369 | os=-mvs 1370 | ;; 1371 | *-next) 1372 | os=-nextstep3 1373 | ;; 1374 | *-gould) 1375 | os=-sysv 1376 | ;; 1377 | *-highlevel) 1378 | os=-bsd 1379 | ;; 1380 | *-encore) 1381 | os=-bsd 1382 | ;; 1383 | *-sgi) 1384 | os=-irix 1385 | ;; 1386 | *-siemens) 1387 | os=-sysv4 1388 | ;; 1389 | *-masscomp) 1390 | os=-rtu 1391 | ;; 1392 | f30[01]-fujitsu | f700-fujitsu) 1393 | os=-uxpv 1394 | ;; 1395 | *-rom68k) 1396 | os=-coff 1397 | ;; 1398 | *-*bug) 1399 | os=-coff 1400 | ;; 1401 | *-apple) 1402 | os=-macos 1403 | ;; 1404 | *-atari*) 1405 | os=-mint 1406 | ;; 1407 | *) 1408 | os=-none 1409 | ;; 1410 | esac 1411 | fi 1412 | 1413 | # Here we handle the case where we know the os, and the CPU type, but not the 1414 | # manufacturer. We pick the logical manufacturer. 1415 | vendor=unknown 1416 | case $basic_machine in 1417 | *-unknown) 1418 | case $os in 1419 | -riscix*) 1420 | vendor=acorn 1421 | ;; 1422 | -sunos*) 1423 | vendor=sun 1424 | ;; 1425 | -aix*) 1426 | vendor=ibm 1427 | ;; 1428 | -beos*) 1429 | vendor=be 1430 | ;; 1431 | -hpux*) 1432 | vendor=hp 1433 | ;; 1434 | -mpeix*) 1435 | vendor=hp 1436 | ;; 1437 | -hiux*) 1438 | vendor=hitachi 1439 | ;; 1440 | -unos*) 1441 | vendor=crds 1442 | ;; 1443 | -dgux*) 1444 | vendor=dg 1445 | ;; 1446 | -luna*) 1447 | vendor=omron 1448 | ;; 1449 | -genix*) 1450 | vendor=ns 1451 | ;; 1452 | -mvs* | -opened*) 1453 | vendor=ibm 1454 | ;; 1455 | -ptx*) 1456 | vendor=sequent 1457 | ;; 1458 | -vxsim* | -vxworks* | -windiss*) 1459 | vendor=wrs 1460 | ;; 1461 | -aux*) 1462 | vendor=apple 1463 | ;; 1464 | -hms*) 1465 | vendor=hitachi 1466 | ;; 1467 | -mpw* | -macos*) 1468 | vendor=apple 1469 | ;; 1470 | -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) 1471 | vendor=atari 1472 | ;; 1473 | -vos*) 1474 | vendor=stratus 1475 | ;; 1476 | esac 1477 | basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` 1478 | ;; 1479 | esac 1480 | 1481 | echo $basic_machine$os 1482 | exit 0 1483 | 1484 | # Local variables: 1485 | # eval: (add-hook 'write-file-hooks 'time-stamp) 1486 | # time-stamp-start: "timestamp='" 1487 | # time-stamp-format: "%:y-%02m-%02d" 1488 | # time-stamp-end: "'" 1489 | # End: 1490 | -------------------------------------------------------------------------------- /autoconf/install-sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # install - install a program, script, or datafile 4 | # This comes from X11R5. 5 | # 6 | # Calling this script install-sh is preferred over install.sh, to prevent 7 | # `make' implicit rules from creating a file called install from it 8 | # when there is no Makefile. 9 | # 10 | # This script is compatible with the BSD install script, but was written 11 | # from scratch. 12 | # 13 | 14 | 15 | # set DOITPROG to echo to test this script 16 | 17 | # Don't use :- since 4.3BSD and earlier shells don't like it. 18 | doit="${DOITPROG-}" 19 | 20 | 21 | # put in absolute paths if you don't have them in your path; or use env. vars. 22 | 23 | mvprog="${MVPROG-mv}" 24 | cpprog="${CPPROG-cp}" 25 | chmodprog="${CHMODPROG-chmod}" 26 | chownprog="${CHOWNPROG-chown}" 27 | chgrpprog="${CHGRPPROG-chgrp}" 28 | stripprog="${STRIPPROG-strip}" 29 | rmprog="${RMPROG-rm}" 30 | mkdirprog="${MKDIRPROG-mkdir}" 31 | 32 | transformbasename="" 33 | transform_arg="" 34 | instcmd="$mvprog" 35 | chmodcmd="$chmodprog 0755" 36 | chowncmd="" 37 | chgrpcmd="" 38 | stripcmd="" 39 | rmcmd="$rmprog -f" 40 | mvcmd="$mvprog" 41 | src="" 42 | srcxtra="" 43 | dst="" 44 | dir_arg="" 45 | 46 | while [ x"$1" != x ]; do 47 | case $1 in 48 | -c) instcmd="$cpprog" 49 | shift 50 | continue;; 51 | 52 | -d) dir_arg=true 53 | shift 54 | continue;; 55 | 56 | -m) chmodcmd="$chmodprog $2" 57 | shift 58 | shift 59 | continue;; 60 | 61 | -o) chowncmd="$chownprog $2" 62 | shift 63 | shift 64 | continue;; 65 | 66 | -g) chgrpcmd="$chgrpprog $2" 67 | shift 68 | shift 69 | continue;; 70 | 71 | -s) stripcmd="$stripprog" 72 | shift 73 | continue;; 74 | 75 | -t=*) transformarg=`echo $1 | sed 's/-t=//'` 76 | shift 77 | continue;; 78 | 79 | -b=*) transformbasename=`echo $1 | sed 's/-b=//'` 80 | shift 81 | continue;; 82 | 83 | *) if [ x"$src" = x ] 84 | then 85 | src=$1 86 | else 87 | # this colon is to work around a 386BSD /bin/sh bug 88 | : 89 | dst=$1 90 | if [ $# -ne 1 ]; then 91 | srcxtra="$srcxtra $1" 92 | fi 93 | fi 94 | shift 95 | continue;; 96 | esac 97 | done 98 | 99 | if [ x"$src" = x ] 100 | then 101 | echo "install: no input file specified" 102 | exit 1 103 | else 104 | true 105 | fi 106 | 107 | srcxtra="$src $srcxtra" 108 | src="" 109 | dstsave=$dst 110 | 111 | if [ x"$dir_arg" != x ]; then 112 | srcxtra="$srcxtra $dst" 113 | fi 114 | 115 | # Now loop over $srcxtra 116 | 117 | for src in $srcxtra ; do 118 | 119 | dst=$dstsave 120 | 121 | if [ x"$dir_arg" != x ]; then 122 | dst=$src 123 | src="" 124 | 125 | if [ -d $dst ]; then 126 | instcmd=: 127 | else 128 | instcmd=mkdir 129 | fi 130 | else 131 | 132 | # Waiting for this to be detected by the "$instcmd $src $dsttmp" command 133 | # might cause directories to be created, which would be especially bad 134 | # if $src (and thus $dsttmp) contains '*'. 135 | 136 | if [ -f $src -o -d $src ] 137 | then 138 | true 139 | else 140 | echo "install: $src does not exist" 141 | exit 1 142 | fi 143 | 144 | if [ x"$dst" = x ] 145 | then 146 | echo "install: no destination specified" 147 | exit 1 148 | else 149 | true 150 | fi 151 | 152 | # If destination is a directory, append the input filename; if your system 153 | # does not like double slashes in filenames, you may need to add some logic 154 | 155 | if [ -d $dst ] 156 | then 157 | dst="$dst"/`basename $src` 158 | else 159 | true 160 | fi 161 | fi 162 | 163 | ## this sed command emulates the dirname command 164 | dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` 165 | 166 | # Make sure that the destination directory exists. 167 | # this part is taken from Noah Friedman's mkinstalldirs script 168 | 169 | # Skip lots of stat calls in the usual case. 170 | if [ ! -d "$dstdir" ]; then 171 | defaultIFS=' 172 | ' 173 | IFS="${IFS-${defaultIFS}}" 174 | 175 | oIFS="${IFS}" 176 | # Some sh's can't handle IFS=/ for some reason. 177 | IFS='%' 178 | set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` 179 | IFS="${oIFS}" 180 | 181 | pathcomp='' 182 | 183 | while [ $# -ne 0 ] ; do 184 | pathcomp="${pathcomp}${1}" 185 | shift 186 | 187 | if [ ! -d "${pathcomp}" ] ; 188 | then 189 | $mkdirprog "${pathcomp}" 190 | else 191 | true 192 | fi 193 | 194 | pathcomp="${pathcomp}/" 195 | done 196 | fi 197 | 198 | if [ x"$dir_arg" != x ] 199 | then 200 | $doit $instcmd $dst && 201 | 202 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && 203 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && 204 | if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && 205 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi 206 | else 207 | 208 | # If we're going to rename the final executable, determine the name now. 209 | 210 | if [ x"$transformarg" = x ] 211 | then 212 | dstfile=`basename $dst` 213 | else 214 | dstfile=`basename $dst $transformbasename | 215 | sed $transformarg`$transformbasename 216 | fi 217 | 218 | # don't allow the sed command to completely eliminate the filename 219 | 220 | if [ x"$dstfile" = x ] 221 | then 222 | dstfile=`basename $dst` 223 | else 224 | true 225 | fi 226 | 227 | # Make a temp file name in the proper directory. 228 | 229 | dsttmp=$dstdir/#inst.$$# 230 | 231 | # Move or copy the file name to the temp name 232 | 233 | $doit $instcmd $src $dsttmp && 234 | 235 | trap "rm -f ${dsttmp}" 0 && 236 | 237 | # and set any options; do chmod last to preserve setuid bits 238 | 239 | # If any of these fail, we abort the whole thing. If we want to 240 | # ignore errors from any of these, just make sure not to ignore 241 | # errors from the above "$doit $instcmd $src $dsttmp" command. 242 | 243 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && 244 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && 245 | if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && 246 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && 247 | 248 | # Now rename the file to the real destination. 249 | 250 | $doit $rmcmd -f $dstdir/$dstfile && 251 | $doit $mvcmd $dsttmp $dstdir/$dstfile 252 | 253 | fi 254 | 255 | done && 256 | 257 | 258 | exit 0 259 | -------------------------------------------------------------------------------- /configure.in: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_INIT([llevm], [0.0.1], [lukas@erlang-solutions.com]) 5 | AC_CONFIG_AUX_DIRS($srcdir/autoconf) 6 | AC_PREREQ([2.67]) 7 | AC_CONFIG_SRCDIR([src/llevm.app.src]) 8 | 9 | AC_CANONICAL_HOST 10 | TARGET=$host 11 | AC_SUBST(TARGET) 12 | 13 | # Checks for programs. 14 | AC_PROG_CC 15 | AC_LANG([C]) 16 | AC_PATH_PROGS([llvm_config_var], [llvm-config llvm-config-2.8], [no]) 17 | if test ${llvm_config_var} = no; then 18 | AC_MSG_ERROR([llvm-config not found in path]) 19 | fi 20 | AC_PATH_PROG([DOXYGEN_PATH], [doxygen], [no]) 21 | if test ${DOXYGEN_PATH} = no; then 22 | AC_MSG_WARN([doxygen not found in path, cannot re-generate llvm nif]) 23 | fi 24 | ERLANG_ROOT_DIR=`erl -noshell -eval 'io:format("~s~n",[[code:root_dir()]])' -s erlang halt` 25 | AC_SUBST(ERLANG_ROOT_DIR) 26 | ERTS_DIR=$ERLANG_ROOT_DIR`erl -noshell -eval 'io:format("~s~n",[[lists:concat([["/erts-", erlang:system_info(version)]])]])' -s erlang halt` 27 | AC_SUBST(ERTS_DIR) 28 | AC_MSG_NOTICE(ERL ROOT DIR: [$ERLANG_ROOT_DIR]) 29 | 30 | 31 | case $host_os in 32 | darwin*) 33 | CC=gcc 34 | CXX=gcc 35 | LINKER=gcc 36 | ;; 37 | *) 38 | CC=gcc 39 | CXX=g++ 40 | LINKER=g++ 41 | ;; 42 | esac 43 | 44 | AC_CHECK_SIZEOF(void *) 45 | case $ac_cv_sizeof_void_p in 46 | 8) 47 | CFLAGS="-m64" 48 | ;; 49 | *) 50 | CFLAGS="-m32" 51 | ;; 52 | esac 53 | 54 | CFLAGS="-g3 -Wall -fPIC" 55 | 56 | case $host_os in 57 | darwin*) 58 | LDFLAGS="-fPIC -bundle -flat_namespace -undefined suppress" 59 | ;; 60 | *) 61 | LDFLAGS="-shared -fPIC" 62 | ;; 63 | esac 64 | AC_SUBST(LINKER) 65 | 66 | # Checks for libraries. 67 | 68 | # Checks for header files. 69 | LLVM_INCLUDES=`$llvm_config_var --includedir`/llvm-c 70 | AC_SUBST(LLVM_INCLUDES) 71 | 72 | # Checks for typedefs, structures, and compiler characteristics. 73 | 74 | # Checks for library functions. 75 | AC_FUNC_MALLOC 76 | if test ${DOXYGEN_PATH} != no; then 77 | AC_CONFIG_FILES([api_gen/Makefile api_gen/doxygen.conf]) 78 | fi 79 | 80 | AC_CONFIG_FILES([Makefile]) 81 | 82 | AC_OUTPUT 83 | -------------------------------------------------------------------------------- /include/llevm.hrl: -------------------------------------------------------------------------------- 1 | %% 2 | %% Header file generated by llevm created by Lukas Larsson, 3 | %% Visit https://github.com/garazdawi/llevm for details. 4 | %% 5 | 6 | %% @@CONST@@ 7 | %% -- Start generating from lto_8h.xml on {{2012,3,12},{19,42,11}}-- 8 | 9 | %% enum lto_symbol_attributes 10 | -define(LTO_SYMBOL_ALIGNMENT_MASK,{'lto_symbol_attributes',31}). 11 | -define(LTO_SYMBOL_PERMISSIONS_MASK,{'lto_symbol_attributes',224}). 12 | -define(LTO_SYMBOL_PERMISSIONS_CODE,{'lto_symbol_attributes',160}). 13 | -define(LTO_SYMBOL_PERMISSIONS_DATA,{'lto_symbol_attributes',192}). 14 | -define(LTO_SYMBOL_PERMISSIONS_RODATA,{'lto_symbol_attributes',128}). 15 | -define(LTO_SYMBOL_DEFINITION_MASK,{'lto_symbol_attributes',1792}). 16 | -define(LTO_SYMBOL_DEFINITION_REGULAR,{'lto_symbol_attributes',256}). 17 | -define(LTO_SYMBOL_DEFINITION_TENTATIVE,{'lto_symbol_attributes',512}). 18 | -define(LTO_SYMBOL_DEFINITION_WEAK,{'lto_symbol_attributes',768}). 19 | -define(LTO_SYMBOL_DEFINITION_UNDEFINED,{'lto_symbol_attributes',1024}). 20 | -define(LTO_SYMBOL_DEFINITION_WEAKUNDEF,{'lto_symbol_attributes',1280}). 21 | -define(LTO_SYMBOL_SCOPE_MASK,{'lto_symbol_attributes',14336}). 22 | -define(LTO_SYMBOL_SCOPE_INTERNAL,{'lto_symbol_attributes',2048}). 23 | -define(LTO_SYMBOL_SCOPE_HIDDEN,{'lto_symbol_attributes',4096}). 24 | -define(LTO_SYMBOL_SCOPE_PROTECTED,{'lto_symbol_attributes',8192}). 25 | -define(LTO_SYMBOL_SCOPE_DEFAULT,{'lto_symbol_attributes',6144}). 26 | -define(LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN,{'lto_symbol_attributes',10240}). 27 | 28 | %% enum lto_debug_model 29 | -define(LTO_DEBUG_MODEL_NONE,{'lto_debug_model',0}). 30 | -define(LTO_DEBUG_MODEL_DWARF,{'lto_debug_model',1}). 31 | 32 | %% enum lto_codegen_model 33 | -define(LTO_CODEGEN_PIC_MODEL_STATIC,{'lto_codegen_model',0}). 34 | -define(LTO_CODEGEN_PIC_MODEL_DYNAMIC,{'lto_codegen_model',1}). 35 | -define(LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC,{'lto_codegen_model',2}). 36 | 37 | %% --- Stop generating from lto_8h.xml 38 | 39 | %% -- Start generating from Vectorize_8h.xml on {{2012,3,12},{19,42,10}}-- 40 | 41 | %% --- Stop generating from Vectorize_8h.xml 42 | 43 | %% -- Start generating from Target_8h.xml on {{2012,3,12},{19,42,9}}-- 44 | 45 | %% enum LLVMByteOrdering 46 | -define(LLVMBigEndian,{'LLVMByteOrdering',0}). 47 | -define(LLVMLittleEndian,{'LLVMByteOrdering',1}). 48 | 49 | %% --- Stop generating from Target_8h.xml 50 | 51 | %% -- Start generating from Scalar_8h.xml on {{2012,3,12},{19,42,8}}-- 52 | 53 | %% --- Stop generating from Scalar_8h.xml 54 | 55 | %% -- Start generating from PassManagerBuilder_8h.xml on {{2012,3,12},{19,42,7}}-- 56 | 57 | %% --- Stop generating from PassManagerBuilder_8h.xml 58 | 59 | %% -- Start generating from Object_8h.xml on {{2012,3,12},{19,42,6}}-- 60 | 61 | %% --- Stop generating from Object_8h.xml 62 | 63 | %% -- Start generating from LinkTimeOptimizer_8h.xml on {{2012,3,12},{19,42,6}}-- 64 | 65 | %% enum llvm_lto_status 66 | -define(LLVM_LTO_UNKNOWN,{'llvm_lto_status',0}). 67 | -define(LLVM_LTO_OPT_SUCCESS,{'llvm_lto_status',1}). 68 | -define(LLVM_LTO_READ_SUCCESS,{'llvm_lto_status',2}). 69 | -define(LLVM_LTO_READ_FAILURE,{'llvm_lto_status',3}). 70 | -define(LLVM_LTO_WRITE_FAILURE,{'llvm_lto_status',4}). 71 | -define(LLVM_LTO_NO_TARGET,{'llvm_lto_status',5}). 72 | -define(LLVM_LTO_NO_WORK,{'llvm_lto_status',6}). 73 | -define(LLVM_LTO_MODULE_MERGE_FAILURE,{'llvm_lto_status',7}). 74 | -define(LLVM_LTO_ASM_FAILURE,{'llvm_lto_status',8}). 75 | -define(LLVM_LTO_NULL_OBJECT,{'llvm_lto_status',9}). 76 | 77 | %% --- Stop generating from LinkTimeOptimizer_8h.xml 78 | 79 | %% -- Start generating from Initialization_8h.xml on {{2012,3,12},{19,42,5}}-- 80 | 81 | %% --- Stop generating from Initialization_8h.xml 82 | 83 | %% -- Start generating from IPO_8h.xml on {{2012,3,12},{19,42,4}}-- 84 | 85 | %% --- Stop generating from IPO_8h.xml 86 | 87 | %% -- Start generating from ExecutionEngine_8h.xml on {{2012,3,12},{19,42,4}}-- 88 | 89 | %% --- Stop generating from ExecutionEngine_8h.xml 90 | 91 | %% -- Start generating from EnhancedDisassembly_8h.xml on {{2012,3,12},{19,42,3}}-- 92 | 93 | %% enum @0 94 | -define(kEDAssemblySyntaxX86Intel,{'@0',0}). 95 | %% kEDAssemblySyntaxX86Intel Intel syntax for i386 and x86_64. 96 | -define(kEDAssemblySyntaxX86ATT,{'@0',1}). 97 | %% kEDAssemblySyntaxX86ATT AT&T syntax for i386 and x86_64. 98 | -define(kEDAssemblySyntaxARMUAL,{'@0',2}). 99 | 100 | %% --- Stop generating from EnhancedDisassembly_8h.xml 101 | 102 | %% -- Start generating from Disassembler_8h.xml on {{2012,3,12},{19,42,2}}-- 103 | 104 | %% --- Stop generating from Disassembler_8h.xml 105 | 106 | %% -- Start generating from Core_8h.xml on {{2012,3,12},{19,42,2}}-- 107 | 108 | %% enum LLVMAttribute 109 | -define(LLVMZExtAttribute,{'LLVMAttribute',1}). 110 | -define(LLVMSExtAttribute,{'LLVMAttribute',2}). 111 | -define(LLVMNoReturnAttribute,{'LLVMAttribute',4}). 112 | -define(LLVMInRegAttribute,{'LLVMAttribute',8}). 113 | -define(LLVMStructRetAttribute,{'LLVMAttribute',16}). 114 | -define(LLVMNoUnwindAttribute,{'LLVMAttribute',32}). 115 | -define(LLVMNoAliasAttribute,{'LLVMAttribute',64}). 116 | -define(LLVMByValAttribute,{'LLVMAttribute',128}). 117 | -define(LLVMNestAttribute,{'LLVMAttribute',256}). 118 | -define(LLVMReadNoneAttribute,{'LLVMAttribute',512}). 119 | -define(LLVMReadOnlyAttribute,{'LLVMAttribute',1024}). 120 | -define(LLVMNoInlineAttribute,{'LLVMAttribute',2048}). 121 | -define(LLVMAlwaysInlineAttribute,{'LLVMAttribute',4096}). 122 | -define(LLVMOptimizeForSizeAttribute,{'LLVMAttribute',8192}). 123 | -define(LLVMStackProtectAttribute,{'LLVMAttribute',16384}). 124 | -define(LLVMStackProtectReqAttribute,{'LLVMAttribute',32768}). 125 | -define(LLVMAlignment,{'LLVMAttribute',2031616}). 126 | -define(LLVMNoCaptureAttribute,{'LLVMAttribute',2097152}). 127 | -define(LLVMNoRedZoneAttribute,{'LLVMAttribute',4194304}). 128 | -define(LLVMNoImplicitFloatAttribute,{'LLVMAttribute',8388608}). 129 | -define(LLVMNakedAttribute,{'LLVMAttribute',16777216}). 130 | -define(LLVMInlineHintAttribute,{'LLVMAttribute',33554432}). 131 | -define(LLVMStackAlignment,{'LLVMAttribute',469762048}). 132 | -define(LLVMReturnsTwice,{'LLVMAttribute',536870912}). 133 | -define(LLVMUWTable,{'LLVMAttribute',1073741824}). 134 | -define(LLVMNonLazyBind,{'LLVMAttribute',2147483648}). 135 | 136 | %% enum LLVMOpcode 137 | -define(LLVMRet,{'LLVMOpcode',1}). 138 | -define(LLVMBr,{'LLVMOpcode',2}). 139 | -define(LLVMSwitch,{'LLVMOpcode',3}). 140 | -define(LLVMIndirectBr,{'LLVMOpcode',4}). 141 | -define(LLVMInvoke,{'LLVMOpcode',5}). 142 | -define(LLVMUnreachable,{'LLVMOpcode',7}). 143 | -define(LLVMAdd,{'LLVMOpcode',8}). 144 | -define(LLVMFAdd,{'LLVMOpcode',9}). 145 | -define(LLVMSub,{'LLVMOpcode',10}). 146 | -define(LLVMFSub,{'LLVMOpcode',11}). 147 | -define(LLVMMul,{'LLVMOpcode',12}). 148 | -define(LLVMFMul,{'LLVMOpcode',13}). 149 | -define(LLVMUDiv,{'LLVMOpcode',14}). 150 | -define(LLVMSDiv,{'LLVMOpcode',15}). 151 | -define(LLVMFDiv,{'LLVMOpcode',16}). 152 | -define(LLVMURem,{'LLVMOpcode',17}). 153 | -define(LLVMSRem,{'LLVMOpcode',18}). 154 | -define(LLVMFRem,{'LLVMOpcode',19}). 155 | -define(LLVMShl,{'LLVMOpcode',20}). 156 | -define(LLVMLShr,{'LLVMOpcode',21}). 157 | -define(LLVMAShr,{'LLVMOpcode',22}). 158 | -define(LLVMAnd,{'LLVMOpcode',23}). 159 | -define(LLVMOr,{'LLVMOpcode',24}). 160 | -define(LLVMXor,{'LLVMOpcode',25}). 161 | -define(LLVMAlloca,{'LLVMOpcode',26}). 162 | -define(LLVMLoad,{'LLVMOpcode',27}). 163 | -define(LLVMStore,{'LLVMOpcode',28}). 164 | -define(LLVMGetElementPtr,{'LLVMOpcode',29}). 165 | -define(LLVMTrunc,{'LLVMOpcode',30}). 166 | -define(LLVMZExt,{'LLVMOpcode',31}). 167 | -define(LLVMSExt,{'LLVMOpcode',32}). 168 | -define(LLVMFPToUI,{'LLVMOpcode',33}). 169 | -define(LLVMFPToSI,{'LLVMOpcode',34}). 170 | -define(LLVMUIToFP,{'LLVMOpcode',35}). 171 | -define(LLVMSIToFP,{'LLVMOpcode',36}). 172 | -define(LLVMFPTrunc,{'LLVMOpcode',37}). 173 | -define(LLVMFPExt,{'LLVMOpcode',38}). 174 | -define(LLVMPtrToInt,{'LLVMOpcode',39}). 175 | -define(LLVMIntToPtr,{'LLVMOpcode',40}). 176 | -define(LLVMBitCast,{'LLVMOpcode',41}). 177 | -define(LLVMICmp,{'LLVMOpcode',42}). 178 | -define(LLVMFCmp,{'LLVMOpcode',43}). 179 | -define(LLVMPHI,{'LLVMOpcode',44}). 180 | -define(LLVMCall,{'LLVMOpcode',45}). 181 | -define(LLVMSelect,{'LLVMOpcode',46}). 182 | -define(LLVMUserOp1,{'LLVMOpcode',47}). 183 | -define(LLVMUserOp2,{'LLVMOpcode',48}). 184 | -define(LLVMVAArg,{'LLVMOpcode',49}). 185 | -define(LLVMExtractElement,{'LLVMOpcode',50}). 186 | -define(LLVMInsertElement,{'LLVMOpcode',51}). 187 | -define(LLVMShuffleVector,{'LLVMOpcode',52}). 188 | -define(LLVMExtractValue,{'LLVMOpcode',53}). 189 | -define(LLVMInsertValue,{'LLVMOpcode',54}). 190 | -define(LLVMFence,{'LLVMOpcode',55}). 191 | -define(LLVMAtomicCmpXchg,{'LLVMOpcode',56}). 192 | -define(LLVMAtomicRMW,{'LLVMOpcode',57}). 193 | -define(LLVMResume,{'LLVMOpcode',58}). 194 | -define(LLVMLandingPad,{'LLVMOpcode',59}). 195 | -define(LLVMUnwind,{'LLVMOpcode',60}). 196 | 197 | %% enum LLVMTypeKind 198 | -define(LLVMVoidTypeKind,{'LLVMTypeKind',0}). 199 | %% type with no size 200 | -define(LLVMHalfTypeKind,{'LLVMTypeKind',1}). 201 | %% 16 bit floating point type 202 | -define(LLVMFloatTypeKind,{'LLVMTypeKind',2}). 203 | %% 32 bit floating point type 204 | -define(LLVMDoubleTypeKind,{'LLVMTypeKind',3}). 205 | %% 64 bit floating point type 206 | -define(LLVMX86_FP80TypeKind,{'LLVMTypeKind',4}). 207 | %% 80 bit floating point type (X87) 208 | -define(LLVMFP128TypeKind,{'LLVMTypeKind',5}). 209 | %% 128 bit floating point type (112-bit mantissa) 210 | -define(LLVMPPC_FP128TypeKind,{'LLVMTypeKind',6}). 211 | %% 128 bit floating point type (two 64-bits) 212 | -define(LLVMLabelTypeKind,{'LLVMTypeKind',7}). 213 | %% Labels 214 | -define(LLVMIntegerTypeKind,{'LLVMTypeKind',8}). 215 | %% Arbitrary bit width integers 216 | -define(LLVMFunctionTypeKind,{'LLVMTypeKind',9}). 217 | %% Functions 218 | -define(LLVMStructTypeKind,{'LLVMTypeKind',10}). 219 | %% Structures 220 | -define(LLVMArrayTypeKind,{'LLVMTypeKind',11}). 221 | %% Arrays 222 | -define(LLVMPointerTypeKind,{'LLVMTypeKind',12}). 223 | %% Pointers 224 | -define(LLVMVectorTypeKind,{'LLVMTypeKind',13}). 225 | %% SIMD 'packed' format, or other vector type 226 | -define(LLVMMetadataTypeKind,{'LLVMTypeKind',14}). 227 | %% Metadata 228 | -define(LLVMX86_MMXTypeKind,{'LLVMTypeKind',15}). 229 | %% X86 MMX 230 | 231 | %% enum LLVMLinkage 232 | -define(LLVMExternalLinkage,{'LLVMLinkage',0}). 233 | %% Externally visible function 234 | -define(LLVMAvailableExternallyLinkage,{'LLVMLinkage',1}). 235 | -define(LLVMLinkOnceAnyLinkage,{'LLVMLinkage',2}). 236 | %% Keep one copy of function when linking (inline) 237 | -define(LLVMLinkOnceODRLinkage,{'LLVMLinkage',3}). 238 | %% Same, but only replaced by something equivalent. 239 | -define(LLVMWeakAnyLinkage,{'LLVMLinkage',4}). 240 | %% Keep one copy of function when linking (weak) 241 | -define(LLVMWeakODRLinkage,{'LLVMLinkage',5}). 242 | %% Same, but only replaced by something equivalent. 243 | -define(LLVMAppendingLinkage,{'LLVMLinkage',6}). 244 | %% Special purpose, only applies to global arrays 245 | -define(LLVMInternalLinkage,{'LLVMLinkage',7}). 246 | %% Rename collisions when linking (static functions) 247 | -define(LLVMPrivateLinkage,{'LLVMLinkage',8}). 248 | %% Like Internal, but omit from symbol table 249 | -define(LLVMDLLImportLinkage,{'LLVMLinkage',9}). 250 | %% Function to be imported from DLL 251 | -define(LLVMDLLExportLinkage,{'LLVMLinkage',10}). 252 | %% Function to be accessible from DLL 253 | -define(LLVMExternalWeakLinkage,{'LLVMLinkage',11}). 254 | %% ExternalWeak linkage description 255 | -define(LLVMGhostLinkage,{'LLVMLinkage',12}). 256 | %% Obsolete 257 | -define(LLVMCommonLinkage,{'LLVMLinkage',13}). 258 | %% Tentative definitions 259 | -define(LLVMLinkerPrivateLinkage,{'LLVMLinkage',14}). 260 | %% Like Private, but linker removes. 261 | -define(LLVMLinkerPrivateWeakLinkage,{'LLVMLinkage',15}). 262 | %% Like LinkerPrivate, but is weak. 263 | -define(LLVMLinkerPrivateWeakDefAutoLinkage,{'LLVMLinkage',16}). 264 | %% Like LinkerPrivateWeak, but possibly hidden. 265 | 266 | %% enum LLVMVisibility 267 | -define(LLVMDefaultVisibility,{'LLVMVisibility',0}). 268 | %% The GV is visible 269 | -define(LLVMHiddenVisibility,{'LLVMVisibility',1}). 270 | %% The GV is hidden 271 | -define(LLVMProtectedVisibility,{'LLVMVisibility',2}). 272 | %% The GV is protected 273 | 274 | %% enum LLVMCallConv 275 | -define(LLVMCCallConv,{'LLVMCallConv',0}). 276 | -define(LLVMFastCallConv,{'LLVMCallConv',8}). 277 | -define(LLVMColdCallConv,{'LLVMCallConv',9}). 278 | -define(LLVMX86StdcallCallConv,{'LLVMCallConv',64}). 279 | -define(LLVMX86FastcallCallConv,{'LLVMCallConv',65}). 280 | 281 | %% enum LLVMIntPredicate 282 | -define(LLVMIntEQ,{'LLVMIntPredicate',32}). 283 | %% equal 284 | -define(LLVMIntNE,{'LLVMIntPredicate',33}). 285 | %% not equal 286 | -define(LLVMIntUGT,{'LLVMIntPredicate',34}). 287 | %% unsigned greater than 288 | -define(LLVMIntUGE,{'LLVMIntPredicate',35}). 289 | %% unsigned greater or equal 290 | -define(LLVMIntULT,{'LLVMIntPredicate',36}). 291 | %% unsigned less than 292 | -define(LLVMIntULE,{'LLVMIntPredicate',37}). 293 | %% unsigned less or equal 294 | -define(LLVMIntSGT,{'LLVMIntPredicate',38}). 295 | %% signed greater than 296 | -define(LLVMIntSGE,{'LLVMIntPredicate',39}). 297 | %% signed greater or equal 298 | -define(LLVMIntSLT,{'LLVMIntPredicate',40}). 299 | %% signed less than 300 | -define(LLVMIntSLE,{'LLVMIntPredicate',41}). 301 | %% signed less or equal 302 | 303 | %% enum LLVMRealPredicate 304 | -define(LLVMRealPredicateFalse,{'LLVMRealPredicate',0}). 305 | %% Always false (always folded) 306 | -define(LLVMRealOEQ,{'LLVMRealPredicate',1}). 307 | %% True if ordered and equal 308 | -define(LLVMRealOGT,{'LLVMRealPredicate',2}). 309 | %% True if ordered and greater than 310 | -define(LLVMRealOGE,{'LLVMRealPredicate',3}). 311 | %% True if ordered and greater than or equal 312 | -define(LLVMRealOLT,{'LLVMRealPredicate',4}). 313 | %% True if ordered and less than 314 | -define(LLVMRealOLE,{'LLVMRealPredicate',5}). 315 | %% True if ordered and less than or equal 316 | -define(LLVMRealONE,{'LLVMRealPredicate',6}). 317 | %% True if ordered and operands are unequal 318 | -define(LLVMRealORD,{'LLVMRealPredicate',7}). 319 | %% True if ordered (no nans) 320 | -define(LLVMRealUNO,{'LLVMRealPredicate',8}). 321 | %% True if unordered: isnan(X) | isnan(Y) 322 | -define(LLVMRealUEQ,{'LLVMRealPredicate',9}). 323 | %% True if unordered or equal 324 | -define(LLVMRealUGT,{'LLVMRealPredicate',10}). 325 | %% True if unordered or greater than 326 | -define(LLVMRealUGE,{'LLVMRealPredicate',11}). 327 | %% True if unordered, greater than, or equal 328 | -define(LLVMRealULT,{'LLVMRealPredicate',12}). 329 | %% True if unordered or less than 330 | -define(LLVMRealULE,{'LLVMRealPredicate',13}). 331 | %% True if unordered, less than, or equal 332 | -define(LLVMRealUNE,{'LLVMRealPredicate',14}). 333 | %% True if unordered or not equal 334 | -define(LLVMRealPredicateTrue,{'LLVMRealPredicate',15}). 335 | %% Always true (always folded) 336 | 337 | %% enum LLVMLandingPadClauseTy 338 | -define(LLVMLandingPadCatch,{'LLVMLandingPadClauseTy',0}). 339 | %% A catch clause 340 | -define(LLVMLandingPadFilter,{'LLVMLandingPadClauseTy',1}). 341 | %% A filter clause 342 | 343 | %% --- Stop generating from Core_8h.xml 344 | 345 | %% -- Start generating from BitWriter_8h.xml on {{2012,3,12},{19,42,1}}-- 346 | 347 | %% --- Stop generating from BitWriter_8h.xml 348 | 349 | %% -- Start generating from BitReader_8h.xml on {{2012,3,12},{19,42,1}}-- 350 | 351 | %% --- Stop generating from BitReader_8h.xml 352 | 353 | %% -- Start generating from Analysis_8h.xml on {{2012,3,12},{19,42,1}}-- 354 | 355 | %% enum LLVMVerifierFailureAction 356 | -define(LLVMAbortProcessAction,{'LLVMVerifierFailureAction',0}). 357 | -define(LLVMPrintMessageAction,{'LLVMVerifierFailureAction',1}). 358 | -define(LLVMReturnStatusAction,{'LLVMVerifierFailureAction',2}). 359 | 360 | %% --- Stop generating from Analysis_8h.xml 361 | 362 | -------------------------------------------------------------------------------- /mac_env: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | export PATH=/Applications/Doxygen.app/Contents/Resources/:/Users/lukas/Documents/etc/otp/release/i386-apple-darwin10.7.0/bin/:$PATH 3 | -------------------------------------------------------------------------------- /os_lathund: -------------------------------------------------------------------------------- 1 | ## Generara och kör testerna 2 | cd ~/Documents/etc/llevm/ && source mac_env && (cd api_gen && make) && make test 3 | 4 | ## Generara och starta gdb 5 | cd ~/Documents/etc/llevm/ && source mac_env && (cd api_gen && make) && make && erlc -o tests tests/*.erl && export BINDIR=/Users/lukas/Documents/etc/otp/release/i386-apple-darwin10.7.0/bin/ && gdb /Users/lukas/Documents/etc/otp/release/i386-apple-darwin10.7.0//erts-5.8.4/bin/beam.smp 6 | 7 | ## Start erl i gdb 8 | run -- -root /Users/lukas/Documents/etc/otp/release/i386-apple-darwin10.7.0/ -- -pa ../llevm/ebin tests 9 | -------------------------------------------------------------------------------- /rebar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/garazdawi/llevm/66f2d9fd122d4bdcaa2ce31afbec64152c746132/rebar -------------------------------------------------------------------------------- /src/llevm.app.src: -------------------------------------------------------------------------------- 1 | {application, llevm, 2 | [ 3 | {description, ""}, 4 | {vsn, "1"}, 5 | {registered, []}, 6 | {applications, [ 7 | kernel, 8 | stdlib 9 | ]}, 10 | {env, []} 11 | ]}. 12 | -------------------------------------------------------------------------------- /src/llvm_nif.erl: -------------------------------------------------------------------------------- 1 | -module(llvm_nif). 2 | 3 | -on_load(load_my_nifs/0). 4 | 5 | -export([module_new/1, module_getFunction/2, module_dump/1]). 6 | 7 | load_my_nifs() -> 8 | erlang:load_nif("./priv/x86_64/llevm",0). 9 | 10 | module_new(_Name) -> 11 | not_loaded. 12 | 13 | module_getFunction(_Mod, _Callee) -> 14 | not_loaded. 15 | 16 | module_dump(_Mod) -> 17 | not_loaded. 18 | -------------------------------------------------------------------------------- /tests/basic_SUITE.erl: -------------------------------------------------------------------------------- 1 | -module(basic_SUITE). 2 | 3 | -compile(export_all). 4 | 5 | init_per_suite(Config) -> 6 | Config. 7 | 8 | end_per_suite(_Config) -> 9 | ok. 10 | 11 | init_per_testcase(_Tc, Config) -> 12 | Config. 13 | 14 | end_per_testcase(_Tc, _Config) -> 15 | ok. 16 | 17 | all() -> 18 | [basic]. 19 | 20 | basic(_Config) -> 21 | Ctx = llevm:'LLVMGetGlobalContext'(), 22 | ModRef = llevm:'LLVMModuleCreateWithName'("test"), 23 | FunTypeRef = llevm:'LLVMFunctionType'(llevm:'LLVMDoubleType'(), 24 | {llevm:'LLVMDoubleType'(), 25 | llevm:'LLVMDoubleType'() }, 2, false), 26 | FunRef = llevm:'LLVMAddFunction'(ModRef, "foo", FunTypeRef), 27 | llevm:'LLVMDumpModule'(ModRef), 28 | BuildRef = llevm:'LLVMCreateBuilderInContext'(Ctx), 29 | BB = llevm:'LLVMAppendBasicBlock'(FunRef,"entry"), 30 | llevm:'LLVMPositionBuilderAtEnd'(BuildRef, BB), 31 | Value10 = llevm:'LLVMConstReal'(llevm:'LLVMDoubleType'(), 32 | 1.0), 33 | ValueArg1 = llevm:'LLVMGetParam'(FunRef, 0), 34 | ValueArg2 = llevm:'LLVMGetParam'(FunRef, 1), 35 | 36 | ValueAdd = llevm:'LLVMBuildFAdd'(BuildRef, Value10, ValueArg1, "addtmp"), 37 | ValueMul = llevm:'LLVMBuildFMul'(BuildRef, ValueAdd, ValueArg2, "multmp"), 38 | llevm:'LLVMBuildRet'(BuildRef, ValueMul), 39 | 40 | llevm:'LLVMDumpModule'(ModRef). 41 | -------------------------------------------------------------------------------- /tests/erlang_SUITE.erl: -------------------------------------------------------------------------------- 1 | -module(erlang_SUITE). 2 | 3 | -compile(export_all). 4 | 5 | %-include_lib("common_test/include/ct.hrl"). 6 | 7 | -define(PRINT(Str,Args), ct:pal(Str,Args)). 8 | 9 | init_per_suite(Config) -> 10 | code:add_patha(proplists:get_value(data_dir,Config)), 11 | Yrls = filelib:wildcard(filename:join(proplists:get_value(data_dir, Config), 12 | "*.yrl")), 13 | [{ok,_} = yecc:file(Yrl,[{parserfile,filename:rootname(Yrl)++".erl"}]) || Yrl <- Yrls], 14 | Erls = filelib:wildcard(filename:join(proplists:get_value(data_dir, Config), 15 | "*.erl")), 16 | [{ok,_} = compile:file(Erl,[{outdir,proplists:get_value(data_dir, Config)}]) || Erl <- Erls], 17 | Config. 18 | 19 | 20 | end_per_suite(_Config) -> 21 | ok. 22 | 23 | init_per_testcase(_Tc, Config) -> 24 | Config. 25 | 26 | end_per_testcase(_Tc, _Config) -> 27 | ok. 28 | 29 | all() -> 30 | [factorial, nfactorial, nfactorial_perf]. 31 | 32 | factorial(_Config) -> 33 | {ModRef, [Fact]} = build([fact]), 34 | run(ModRef, Fact, [10]). 35 | 36 | nfactorial(_Config) -> 37 | {ModRef, [_Fact,NFact]} = build([fact,nfact]), 38 | run(ModRef, NFact, [10]). 39 | 40 | 41 | nfactorial_perf(_Config) -> 42 | {ModRef, [_Fact,NFact]} = build([fact,nfact]), 43 | 44 | {_, EERef, _} = llevm:'LLVMCreateExecutionEngineForModule'(ModRef), 45 | LLVMFact = fun(I) -> 46 | Args = {llevm:'LLVMCreateGenericValueOfInt'( 47 | llevm:'LLVMInt32Type'(),I, true)}, 48 | Res = llevm:'LLVMRunFunction'( 49 | EERef, NFact, 1, 50 | Args), 51 | element(2,llevm:'LLVMGenericValueToInt'(Res, false)) 52 | end, 53 | LLVMFact(1), 54 | ErlangFact = fun nfact/1, 55 | {N,_R} = timer:tc(fun() -> LLVMFact(1000000) end), 56 | {E,_} = timer:tc(fun() -> ErlangFact(1000000) end), 57 | ct:pal("N = ~p~nE = ~p~n",[N,E]). 58 | 59 | get_erlang_ast(Name) -> 60 | {beam_file,_Mod,_Export,_Vsn,_Opts,Function} = beam_disasm:file(code:which(?MODULE)), 61 | lists:keyfind(Name, 2, Function). 62 | 63 | 64 | run(ModRef, FunRef, Args) -> 65 | IntArgs = list_to_tuple([llevm:'LLVMCreateGenericValueOfInt'( 66 | llevm:'LLVMInt32Type'(),Int32, false) || Int32 <- Args]), 67 | {_, EERef, _} = llevm:'LLVMCreateExecutionEngineForModule'(ModRef), 68 | Res = llevm:'LLVMRunFunction'( 69 | EERef, FunRef, length(Args), 70 | IntArgs), 71 | llevm:'LLVMGenericValueToInt'(Res, false). 72 | 73 | build(Funcs) -> 74 | llevm:'LLVMLinkInInterpreter'(), 75 | 76 | Ctx = llevm:'LLVMGetGlobalContext'(), 77 | ModRef = llevm:'LLVMModuleCreateWithName'("test"), 78 | BuildRef = llevm:'LLVMCreateBuilderInContext'(Ctx), 79 | FPMRef = llevm:'LLVMCreateFunctionPassManagerForModule'(ModRef), 80 | 81 | llevm:'LLVMAddInstructionCombiningPass'(FPMRef), 82 | llevm:'LLVMAddReassociatePass'(FPMRef), 83 | llevm:'LLVMAddGVNPass'(FPMRef), 84 | llevm:'LLVMAddCFGSimplificationPass'(FPMRef), 85 | 86 | llevm:'LLVMInitializeFunctionPassManager'(FPMRef), 87 | FunRefs = lists:map(fun(Func) -> 88 | EAST = get_erlang_ast(Func), 89 | ct:print("EAST: ~p",[EAST]), 90 | FunRef = erlang_gen:gen_function(ModRef,BuildRef,EAST), 91 | llevm:'LLVMRunFunctionPassManager'(FPMRef, FunRef), 92 | FunRef 93 | end,Funcs), 94 | llevm:'LLVMFinalizeFunctionPassManager'(FPMRef), 95 | llevm:'LLVMDumpModule'(ModRef), 96 | {ModRef,FunRefs}. 97 | 98 | 99 | fact(0) -> 1;fact(N) -> N * fact(N-1). 100 | nfact(1) -> 0; nfact(N) -> (fact((N rem 10)+1)+nfact(N-1)) rem (1 bsl 30). 101 | -------------------------------------------------------------------------------- /tests/erlang_SUITE_data/erlang_gen.erl: -------------------------------------------------------------------------------- 1 | -module(erlang_gen). 2 | 3 | %-include_lib("llevm/include/llevm.hrl"). 4 | 5 | %{function,fib,1,2, 6 | % [{label,1}, 7 | % {func_info,{atom,tmp},{atom,fib},1}, 8 | % {label,2}, 9 | % {test,is_eq_exact,{f,3},[{x,0},{integer,1}]}, 10 | % return, 11 | % {label,3}, 12 | % {allocate_zero,1,1}, 13 | % {gc_bif,'-',{f,0},1,[{x,0},{integer,1}],{x,1}}, 14 | % {move,{x,0},{y,0}}, 15 | % {move,{x,1},{x,0}}, 16 | % {call,1,{tmp,fib,1}}, 17 | % {gc_bif,'*',{f,0},1,[{y,0},{x,0}],{x,0}}, 18 | % {deallocate,1}, 19 | % return]} 20 | 21 | -export([gen_function/3]). 22 | 23 | gen_function(M, B, {function,Name,ArgNum,_StartLabel,Body}) -> 24 | 25 | FunRef = gen_prototype(M, Name, ArgNum), 26 | 27 | Params = get_params(FunRef, ArgNum, 0), 28 | 29 | AllBBs = gen_bb(FunRef, Name, Body), 30 | 31 | gen_body(M, B, Params, AllBBs, Body), 32 | 33 | FunRef; 34 | gen_function(M, _B, {extern, Name, Args}) -> 35 | gen_prototype(M, Name, Args). 36 | 37 | 38 | gen_prototype(M, Name, NumArgs) -> 39 | 40 | FunctionTypeRef = llevm:'LLVMFunctionType'( 41 | llevm:'LLVMInt32Type'(), 42 | list_to_tuple([llevm:'LLVMInt32Type'() || _ <- lists:seq(1,NumArgs)]), 43 | NumArgs, false), 44 | 45 | llevm:'LLVMAddFunction'( 46 | M, atom_to_list(Name)++"_"++integer_to_list(NumArgs), FunctionTypeRef). 47 | 48 | get_params(_FunRef, 0, _I) -> 49 | []; 50 | get_params(FunRef, Cnt, I) -> 51 | [{{x,I}, llevm:'LLVMGetParam'(FunRef, I)} | get_params(FunRef, Cnt-1, I + 1)]. 52 | 53 | gen_bb(FunRef, Name, [{label, _},{func_info, _,_,_}|Rest]) -> 54 | gen_bb(FunRef, Name, Rest); 55 | gen_bb(FunRef, Name, [{label, No}|Rest]) -> 56 | [{No, llevm:'LLVMAppendBasicBlock'(FunRef, atom_to_list(Name)++"_"++integer_to_list(No))}| 57 | gen_bb(FunRef, Name, Rest)]; 58 | gen_bb(FunRef, Name, [_|Body]) -> 59 | gen_bb(FunRef, Name, Body); 60 | gen_bb(_FunRef, _Name, []) -> 61 | []. 62 | 63 | gen_body(M, B, V, BBs, [{label, _},{func_info, _, _, _}|Body]) -> 64 | gen_body(M, B, V, BBs, Body); 65 | gen_body(M, B, _V, BBs, [{label, No}|Body]) -> 66 | llevm:'LLVMPositionBuilderAtEnd'(B, proplists:get_value(No, BBs)), 67 | FunRef = llevm:'LLVMGetBasicBlockParent'( 68 | llevm:'LLVMGetInsertBlock'(B)), 69 | gen_body(M, B, get_params(FunRef, 1, 0), BBs, Body); 70 | gen_body(M, B, V, BBs, [{test, is_eq_exact, {f, FBB}, [A1,A2]}|Body]) -> 71 | A1Ref = get_ref(V, A1), 72 | A2Ref = get_ref(V, A2), 73 | CmpRef = llevm:'LLVMBuildICmp'(B, {'LLVMIntPredicate',32}, 74 | A1Ref, A2Ref, "cmptmp"), 75 | FunRef = llevm:'LLVMGetBasicBlockParent'( 76 | llevm:'LLVMGetInsertBlock'(B)), 77 | ThenBB = llevm:'LLVMAppendBasicBlock'(FunRef, "then"), 78 | 79 | llevm:'LLVMBuildCondBr'(B, CmpRef, ThenBB, proplists:get_value(FBB, BBs)), 80 | llevm:'LLVMPositionBuilderAtEnd'(B, ThenBB), 81 | gen_body(M, B, V, BBs, Body); 82 | gen_body(M, B, V, BBs, [return|Body]) -> 83 | llevm:'LLVMBuildRet'(B, proplists:get_value({x,0},V)), 84 | gen_body(M, B, V, BBs, Body); 85 | gen_body(M, B, V, BBs, [{gc_bif, Op, _Fail, _Needed, [A1,A2], Result}|Body]) -> 86 | A1Ref = get_ref(V, A1), 87 | A2Ref = get_ref(V, A2), 88 | NewRegRef = case Op of 89 | '-' -> llevm:'LLVMBuildSub'(B, A1Ref, A2Ref, 90 | reg_to_string(Result)); 91 | '+' -> llevm:'LLVMBuildAdd'(B, A1Ref, A2Ref, 92 | reg_to_string(Result)); 93 | '*' -> llevm:'LLVMBuildMul'(B, A1Ref, A2Ref, 94 | reg_to_string(Result)); 95 | 'rem' -> llevm:'LLVMBuildURem'(B,A1Ref, A2Ref, 96 | reg_to_string(Result)) 97 | end, 98 | gen_body(M, B, [{Result, NewRegRef}|V], BBs, Body); 99 | gen_body(M, B, V, BBs, [{move, From, To}|Body]) -> 100 | FromRef = get_ref(V, From), 101 | gen_body(M, B, [{To, FromRef}|V], BBs, Body); 102 | gen_body(M, B, V, BBs, [{call, _Needed, {Mo,F,A}}|Body]) -> 103 | CalleeRef = llevm:'LLVMGetNamedFunction'( 104 | M, atom_to_list(F)++"_"++integer_to_list(A)), 105 | CParamsRefs = list_to_tuple([get_ref(V, {x,I}) || I <- lists:seq(0,A-1)]), 106 | NewRegRef = llevm:'LLVMBuildCall'(B, CalleeRef, CParamsRefs, A, "calltmp"), 107 | gen_body(M, B, [{{x,0},NewRegRef}|V], BBs, Body); 108 | gen_body(M, B, V, BBs, [_|Body]) -> 109 | gen_body(M, B, V, BBs, Body); 110 | gen_body(M, B, V, BBs, []) -> 111 | ok. 112 | 113 | get_ref(_V, {integer, Num}) -> 114 | llevm:'LLVMConstInt'(llevm:'LLVMInt32Type'(), Num, true); 115 | get_ref(V, {XY, _Num} = Reg) when XY == x; XY == y -> 116 | proplists:get_value(Reg, V). 117 | 118 | 119 | 120 | reg_to_string({XY,No}) -> 121 | atom_to_list(XY)++integer_to_list(No)++"_". 122 | -------------------------------------------------------------------------------- /tests/kaleidoscope_SUITE.erl: -------------------------------------------------------------------------------- 1 | -module(kaleidoscope_SUITE). 2 | 3 | -compile(export_all). 4 | 5 | -define(PRINT(Str,Args), ct:pal(Str,Args)). 6 | 7 | init_per_suite(Config) -> 8 | code:add_patha(proplists:get_value(data_dir,Config)), 9 | Yrls = filelib:wildcard(filename:join(proplists:get_value(data_dir, Config), 10 | "*.yrl")), 11 | [{ok,_} = yecc:file(Yrl,[{parserfile,filename:rootname(Yrl)++".erl"}]) || Yrl <- Yrls], 12 | Erls = filelib:wildcard(filename:join(proplists:get_value(data_dir, Config), 13 | "*.erl")), 14 | [{ok,_} = compile:file(Erl,[{outdir,proplists:get_value(data_dir, Config)}]) || Erl <- Erls], 15 | Config. 16 | 17 | 18 | end_per_suite(_Config) -> 19 | ok. 20 | 21 | init_per_testcase(_Tc, Config) -> 22 | Config. 23 | 24 | end_per_testcase(_Tc, _Config) -> 25 | ok. 26 | 27 | all() -> 28 | [adder, complex, extern, condition, for]. 29 | 30 | adder(_Config) -> 31 | {ModRef, [FunRef]} = build(["def adding(test1,test2) test1+test2;"]), 32 | {float, 2.0} = run(ModRef, FunRef, [1.0,1.0]), 33 | {float, 3.0} = run(ModRef, FunRef, [1.0,2.0]), 34 | {float, 4.0} = run(ModRef, FunRef, [3.0,1.0]), 35 | {float, 5.0} = run(ModRef, FunRef, [1.0,4.0]), 36 | {float, 6.0} = run(ModRef, FunRef, [5.0,1.0]), 37 | {float, 7.0} = run(ModRef, FunRef, [1.0,6.0]). 38 | 39 | 40 | complex(_Config) -> 41 | {ModRef, [_Foo, Bar]} = build(["def foo(a,b) a*a + 2.0*a*b + b*b;", 42 | "def bar(a) if 1337.0 < a then 1337.0 else " 43 | " foo(a, 4.0) + bar(a*5.0);"]), 44 | {float,151629.0} = run(ModRef, Bar, [3.0]). 45 | 46 | extern(_Config) -> 47 | {ModRef, [_, FunRef]} = build(["extern cos(x);", 48 | "cos(1.234);"]), 49 | {float,0.33046510807172985} = run(ModRef, FunRef, []). 50 | 51 | condition(_Config) -> 52 | {ModRef, [FunRef]} = 53 | build(["def fib(x) if x < 3.0 then 1.0 else fib(x-1.0)+fib(x-2.0);"]), 54 | {float, 8.0} = run(ModRef, FunRef, [6.0]). 55 | 56 | 57 | for(_Config) -> 58 | {ModRef,_} = build(["extern putchard(char);", 59 | "def printstar(n) for i = 1.0, i < n, 1.0 in putchard(42.0);", 60 | "def printstar2(n) for i = 1.0, i < n in putchard(42.0);"]), 61 | {integer, 0} = llevm:'LLVMWriteBitcodeToFile'( 62 | ModRef, filename:join(proplists:get_value(priv_dir, _Config),"for.ll")). 63 | 64 | run(ModRef, FunRef, Args) -> 65 | FloatArgs = list_to_tuple([llevm:'LLVMCreateGenericValueOfFloat'( 66 | llevm:'LLVMDoubleType'(),Float) || Float <- Args]), 67 | {_, EERef, _} = llevm:'LLVMCreateExecutionEngineForModule'(ModRef), 68 | Res = llevm:'LLVMRunFunction'( 69 | EERef, FunRef, length(Args), 70 | FloatArgs), 71 | llevm:'LLVMGenericValueToFloat'(llevm:'LLVMDoubleType'(),Res). 72 | 73 | 74 | 75 | build(Strs) -> 76 | % llevm:'LLVMInitializeCore'(llevm:'LLVMGetGlobalPassRegistry'()), 77 | llevm:'LLVMLinkInInterpreter'(), 78 | 79 | Ctx = llevm:'LLVMGetGlobalContext'(), 80 | ModRef = llevm:'LLVMModuleCreateWithName'("test"), 81 | BuildRef = llevm:'LLVMCreateBuilderInContext'(Ctx), 82 | FPMRef = llevm:'LLVMCreateFunctionPassManagerForModule'(ModRef), 83 | 84 | llevm:'LLVMAddInstructionCombiningPass'(FPMRef), 85 | llevm:'LLVMAddReassociatePass'(FPMRef), 86 | llevm:'LLVMAddGVNPass'(FPMRef), 87 | llevm:'LLVMAddCFGSimplificationPass'(FPMRef), 88 | 89 | llevm:'LLVMInitializeFunctionPassManager'(FPMRef), 90 | FunRefs = lists:map(fun(Str) -> 91 | AST = scan_and_parse(Str), 92 | FunRef = kal_gen:gen_function(ModRef,BuildRef,AST), 93 | llevm:'LLVMRunFunctionPassManager'(FPMRef, FunRef), 94 | FunRef 95 | end,Strs), 96 | llevm:'LLVMFinalizeFunctionPassManager'(FPMRef), 97 | llevm:'LLVMDumpModule'(ModRef), 98 | {ModRef,FunRefs}. 99 | 100 | 101 | 102 | 103 | scan_and_parse(Str) -> 104 | Toks = kal_scan:string(Str), 105 | ?PRINT("Toks: ~p~n",[Toks]), 106 | {ok,[AST]} = kal_parse:parse(Toks), 107 | ?PRINT("AST: ~p~n",[AST]), 108 | AST. 109 | -------------------------------------------------------------------------------- /tests/kaleidoscope_SUITE_data/kal_gen.erl: -------------------------------------------------------------------------------- 1 | -module(kal_gen). 2 | 3 | %-include_lib("llevm/include/llevm.hrl"). 4 | 5 | -export([gen_function/3]). 6 | 7 | gen_function(M, B, {function,Name,Args,Body}) -> 8 | 9 | FunRef = gen_prototype(M, Name, Args), 10 | 11 | Params = get_params(FunRef, Args, 0), 12 | 13 | BB = llevm:'LLVMAppendBasicBlock'(FunRef,"entry"), 14 | llevm:'LLVMPositionBuilderAtEnd'(B, BB), 15 | 16 | BodyRef = gen_body(M, B, Params, Body), 17 | 18 | llevm:'LLVMBuildRet'(B, BodyRef), 19 | FunRef; 20 | gen_function(M, _B, {extern, Name, Args}) -> 21 | gen_prototype(M, Name, Args). 22 | 23 | 24 | gen_prototype(M, Name, Args) -> 25 | 26 | FunctionTypeRef = llevm:'LLVMFunctionType'( 27 | llevm:'LLVMDoubleType'(), 28 | list_to_tuple([llevm:'LLVMDoubleType'() || _ <- Args]), 29 | length(Args), false), 30 | 31 | llevm:'LLVMAddFunction'(M, Name, FunctionTypeRef). 32 | 33 | 34 | gen_body(M, B, Params, {Op,LHS,RHS}) 35 | when Op == '+'; Op == '-'; Op == '*'; Op == '<' -> 36 | LHSRef = gen_body(M,B,Params,LHS), 37 | RHSRef = gen_body(M,B,Params,RHS), 38 | case Op of 39 | '+' -> llevm:'LLVMBuildFAdd'(B, LHSRef, RHSRef, "addtmp"); 40 | '-' -> llevm:'LLVMBuildFSub'(B, LHSRef, RHSRef, "subtmp"); 41 | '*' -> llevm:'LLVMBuildFMul'(B, LHSRef, RHSRef, "multmp"); 42 | '<' -> 43 | L = llevm:'LLVMBuildFCmp'(B, {'LLVMRealPredicate',12},LHSRef, RHSRef, "cmptmp"), 44 | %% Convert bool 0/1 to double 0.0 or 1.0 45 | llevm:'LLVMBuildUIToFP'(B, L, llevm:'LLVMDoubleType'(), "booltmp") 46 | end; 47 | gen_body(_M, _B, _Params, {const, Val}) -> 48 | llevm:'LLVMConstReal'(llevm:'LLVMDoubleType'(),list_to_float(Val)); 49 | gen_body(_M, _B, Params, {variable, Name}) -> 50 | proplists:get_value(Name, Params); 51 | gen_body(M, B, Params, {call, Name, CParams}) -> 52 | CalleeRef = llevm:'LLVMGetNamedFunction'(M,Name), 53 | CParamsRefs = list_to_tuple([gen_body(M, B, Params, CParam) || CParam <- CParams]), 54 | llevm:'LLVMBuildCall'(B, CalleeRef, CParamsRefs, length(CParams), "calltmp"); 55 | gen_body(M, B, Params, {'if', Cond, Then, Else}) -> 56 | CondRef = gen_body(M, B, Params, Cond), 57 | CmpRef = llevm:'LLVMBuildFCmp'(B, {'LLVMRealPredicate',6}, CondRef, 58 | gen_body(M, B, Params, {const,"0.0"}), 59 | "ifcond"), 60 | FunRef = llevm:'LLVMGetBasicBlockParent'( 61 | llevm:'LLVMGetInsertBlock'(B)), 62 | ThenBB = llevm:'LLVMAppendBasicBlock'(FunRef, "then"), 63 | ElseBB = llevm:'LLVMAppendBasicBlock'(FunRef, "else"), 64 | ContBB = llevm:'LLVMAppendBasicBlock'(FunRef, "if_cont"), 65 | 66 | llevm:'LLVMBuildCondBr'(B, CmpRef, ThenBB, ElseBB), 67 | 68 | llevm:'LLVMPositionBuilderAtEnd'(B, ThenBB), 69 | ThenV = gen_body(M, B, Params, Then), 70 | llevm:'LLVMBuildBr'(B, ContBB), 71 | 72 | llevm:'LLVMPositionBuilderAtEnd'(B, ElseBB), 73 | ElseV = gen_body(M, B, Params, Else), 74 | llevm:'LLVMBuildBr'(B, ContBB), 75 | 76 | llevm:'LLVMPositionBuilderAtEnd'(B, ContBB), 77 | PhiNode = llevm:'LLVMBuildPhi'(B, llevm:'LLVMDoubleType'(), "iftmp"), 78 | llevm:'LLVMAddIncoming'(PhiNode, {ThenV,ElseV},{ThenBB,ElseBB},2), 79 | PhiNode; 80 | gen_body(M, B, Params, {'for', {variable,VarName}, Value, Cond, Incr, Body}) -> 81 | StartValRef = gen_body(M, B, Params, Value), 82 | 83 | PreBB = llevm:'LLVMGetInsertBlock'(B), 84 | FunRef = llevm:'LLVMGetBasicBlockParent'(PreBB), 85 | LoopBB = llevm:'LLVMAppendBasicBlock'(FunRef, "loop"), 86 | AfterBB = llevm:'LLVMAppendBasicBlock'(FunRef, "after_loop"), 87 | 88 | llevm:'LLVMBuildBr'(B, LoopBB), 89 | 90 | llevm:'LLVMPositionBuilderAtEnd'(B, LoopBB), 91 | PhiVal = llevm:'LLVMBuildPhi'(B, llevm:'LLVMDoubleType'(), VarName), 92 | NewParams = [{VarName,PhiVal}|Params], 93 | gen_body(M, B, NewParams, Body), 94 | 95 | StepVal = case Incr of 96 | undefined -> 97 | gen_body(M, B, NewParams, {const, "1.0"}); 98 | _Else -> 99 | gen_body(M, B, NewParams, Incr) 100 | end, 101 | NextVal = llevm:'LLVMBuildFAdd'(B, StepVal, PhiVal, "nextvar"), 102 | 103 | llevm:'LLVMAddIncoming'(PhiVal, {StartValRef,NextVal},{PreBB,LoopBB},2), 104 | 105 | CondRef = gen_body(M, B, NewParams, Cond), 106 | CmpRef = llevm:'LLVMBuildFCmp'(B, {'LLVMRealPredicate',6}, CondRef, 107 | gen_body(M, B, NewParams, {const,"0.0"}), 108 | "ifcond"), 109 | 110 | llevm:'LLVMBuildCondBr'(B, CmpRef, LoopBB, AfterBB), 111 | 112 | llevm:'LLVMPositionBuilderAtEnd'(B, AfterBB), 113 | llevm:'LLVMConstNull'(llevm:'LLVMDoubleType'()). 114 | 115 | 116 | get_params(FunRef, [{variable, Name}|Rest], I) -> 117 | [{Name, llevm:'LLVMGetParam'(FunRef, I)} | get_params(FunRef, Rest, I + 1)]; 118 | get_params(_FunRef, [], _I) -> 119 | []. 120 | 121 | 122 | -------------------------------------------------------------------------------- /tests/kaleidoscope_SUITE_data/kal_parse.yrl: -------------------------------------------------------------------------------- 1 | Nonterminals module variable expressions toplevelexpr expression variables params external function prototype. 2 | Terminals def extern num ident '(' ')' ';' ',' '+' '-' '<' '*' '=' 'if' 'then' 'else' 'for' 'in'. 3 | 4 | Rootsymbol module. 5 | Left 100 '+'. 6 | Left 150 '-'. 7 | Left 200 '*'. 8 | Left 50 '<'. 9 | 10 | module -> prototype module : ['$1'|'$2']. 11 | module -> prototype : ['$1']. 12 | module -> function module : ['$1'|'$2']. 13 | module -> function : ['$1']. 14 | module -> external module : ['$1'|'$2']. 15 | module -> external : ['$1']. 16 | module -> toplevelexpr module : ['$1'|'$2']. 17 | module -> toplevelexpr : ['$1']. 18 | 19 | toplevelexpr -> expressions ';' : {function, "", [], '$1'}. 20 | prototype -> def ident '(' variables ')' ';' : {prototype, value_of('$2'), '$4'}. 21 | function -> def ident '(' variables ')' expressions ';' : {function, value_of('$2'), '$4', '$6'}. 22 | external -> extern ident '(' variables ')' ';' : {extern, value_of('$2'), '$4'}. 23 | 24 | expressions -> expression : '$1'. 25 | 26 | expression -> num : {const, value_of('$1')}. 27 | expression -> variable : '$1'. 28 | expression -> '(' expression ')' : '$2'. 29 | expression -> expression '+' expression : {'+', '$1', '$3'}. 30 | expression -> expression '-' expression : {'-', '$1', '$3'}. 31 | expression -> expression '*' expression : {'*', '$1', '$3'}. 32 | expression -> expression '<' expression : {'<', '$1', '$3'}. 33 | expression -> 'if' expression 'then' expression 'else' expression : {'if', '$2','$4','$6'}. 34 | expression -> 'for' variable '=' expression ',' expression 'in' expression : {for, '$2', '$4', '$6', undefined, '$8'}. 35 | expression -> 'for' variable '=' expression ',' expression ',' expression 'in' expression : {for, '$2', '$4', '$6', '$8', '$10'}. 36 | expression -> ident '(' params ')' : {call, value_of('$1'),'$3'}. 37 | 38 | params -> expression : ['$1']. 39 | params -> expression ',' params : ['$1'|'$3']. 40 | 41 | variables -> variable : ['$1']. 42 | variables -> variable ',' variables : ['$1'|'$3']. 43 | 44 | variable -> ident : {variable, value_of('$1')}. 45 | 46 | Erlang code. 47 | value_of(Token) -> 48 | element(3, Token). 49 | -------------------------------------------------------------------------------- /tests/kaleidoscope_SUITE_data/kal_scan.erl: -------------------------------------------------------------------------------- 1 | -module(kal_scan). 2 | 3 | 4 | -export([string/1]). 5 | 6 | string(Str) -> 7 | put(scan_tok, 0), 8 | scan(Str,none,[]). 9 | 10 | scan([], none, Acc) -> 11 | lists:reverse(Acc); 12 | 13 | %% Keyword scan 14 | scan("def"++Rest, none, Acc) -> 15 | scan(Rest, none, [{def,num()}|Acc]); 16 | scan("extern"++Rest, none, Acc) -> 17 | scan(Rest, none, [{extern,num()}|Acc]); 18 | scan("if"++Rest, none, Acc) -> 19 | scan(Rest, none, [{'if',num()}|Acc]); 20 | scan("then"++Rest, none, Acc) -> 21 | scan(Rest, none, [{then,num()}|Acc]); 22 | scan("else"++Rest, none, Acc) -> 23 | scan(Rest, none, [{else,num()}|Acc]); 24 | scan("for"++Rest, none, Acc) -> 25 | scan(Rest, none, [{for,num()}|Acc]); 26 | scan("in"++Rest, none, Acc) -> 27 | scan(Rest, none, [{in,num()}|Acc]); 28 | scan(" "++Rest, none, Acc) -> 29 | scan(Rest, none, Acc); 30 | scan("\n"++Rest, none, Acc) -> 31 | scan(Rest, none, Acc); 32 | 33 | %% special tokens 34 | scan([Tok|Rest], none, Acc) 35 | when Tok == $(; Tok == $); Tok == $;; Tok == $,; 36 | Tok == $+; Tok == $-; Tok == $/; Tok == $*; 37 | Tok == $<; Tok == $= -> 38 | scan(Rest, none, [{list_to_atom([Tok]),num()}|Acc]); 39 | 40 | %% Number scan 41 | scan([Num|Rest], none, Acc) 42 | when ($0 =< Num andalso Num =< $9); Num == $. -> 43 | scan(Rest, {num, [Num]}, Acc); 44 | scan([Num|Rest],{num,NumAcc},Acc) 45 | when ($0 =< Num andalso Num =< $9); Num == $. -> 46 | scan(Rest, {num, [Num|NumAcc]}, Acc); 47 | scan(String,{num,Num},Acc) -> 48 | scan(String, none, [{num, num(), lists:reverse(Num)}|Acc]); 49 | 50 | %% Identifier scan 51 | scan([Ident|Rest], none, Acc) 52 | when ($a =< Ident andalso Ident =< $z); 53 | ($A =< Ident andalso Ident =< $Z) -> 54 | scan(Rest, {ident, [Ident]}, Acc); 55 | scan([Ident|Rest],{ident,IdentAcc},Acc) 56 | when ($a =< Ident andalso Ident =< $z); 57 | ($A =< Ident andalso Ident =< $Z); 58 | ($0 =< Ident andalso Ident =< $9) -> 59 | scan(Rest, {ident, [Ident|IdentAcc]}, Acc); 60 | scan(String,{ident,Ident},Acc) -> 61 | scan(String, none, [{ident, num(), lists:reverse(Ident)}|Acc]). 62 | 63 | 64 | num() -> 65 | Num = get(scan_tok), 66 | put(scan_tok, Num+1), 67 | Num. 68 | --------------------------------------------------------------------------------