Deutsch English Français Italiano |
<vjrpcd$1nqeb$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: bart <bc@freeuk.com> Newsgroups: comp.lang.c Subject: Re: transpiling to low level C Date: Tue, 17 Dec 2024 12:04:29 +0000 Organization: A noiseless patient Spider Lines: 125 Message-ID: <vjrpcd$1nqeb$1@dont-email.me> References: <vjlh19$8j4k$1@dont-email.me> <vjn9g5$n0vl$1@raubtier-asyl.eternal-september.org> <vjnhsq$oh1f$1@dont-email.me> <vjnq5s$pubt$1@dont-email.me> <vjq5nr$1aari$3@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 17 Dec 2024 13:04:30 +0100 (CET) Injection-Info: dont-email.me; posting-host="5300244e42b5123d47a75c920a0bca9f"; logging-data="1829323"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/sPbdDJOdWMhZbu5cdDw97" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:d4v6q7Ql6hcF+4JYDeVpNwgnppg= Content-Language: en-GB In-Reply-To: <vjq5nr$1aari$3@dont-email.me> Bytes: 4137 On 16/12/2024 21:23, Lawrence D'Oliveiro wrote: > On Sun, 15 Dec 2024 17:53:30 -0600, BGB wrote: > >> As an IL, even C is a little overkill, unless turned into a restricted >> subset ... > > Why not use WASM as your IL? Have you tried it? I mean, directly generating WASM from a compiler front-end, not just using somebody else's tool to do so. WASM is a stack-based language, but one that supposedly doesn't even have branching, although there is a 'br' statement, with some restrictions. Information about it is quite elusive; it took me 5 minutes to even get examples of what it looks like (and I've seen it before). C can apparently compile to WASM via Clang, so I tried this program: void F(void) { int i=0; while (i<10000) ++i; } which compiled to 128 lines of WASM (technically, some form of 'WAT', as WASM is a binary format). The 60 lines correspondoing to F are shown below, and below that, is my own stack IL code. So, what do you with your WASM/WAT program once generated? I've no idea, except that WASM is inextricably typed up with with browsers and with JavaScript, in which I have no interest. With C, you run a compiler; with ASM, an assembler; these formats are well understood. You can appreciate that it can be easier to devise your own format and your own tools that you understand 100%. -------------------------------------- F: # @F .functype F () -> () .local i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 # %bb.0: global.get __stack_pointer local.set 0 i32.const 16 local.set 1 local.get 0 local.get 1 i32.sub local.set 2 i32.const 0 local.set 3 local.get 2 local.get 3 i32.store 12 ..LBB0_1: # =>This Inner Loop Header: Depth=1 block loop # label1: local.get 2 i32.load 12 local.set 4 i32.const 10000 local.set 5 local.get 4 local.set 6 local.get 5 local.set 7 local.get 6 local.get 7 i32.lt_s local.set 8 i32.const 1 local.set 9 local.get 8 local.get 9 i32.and local.set 10 local.get 10 i32.eqz br_if 1 # 1: down to label0 # %bb.2: # in Loop: Header=BB0_1 Depth=1 local.get 2 i32.load 12 local.set 11 i32.const 1 local.set 12 local.get 11 local.get 12 i32.add local.set 13 local.get 2 local.get 13 i32.store 12 br 0 # 0: up to label1 ..LBB0_3: end_loop end_block # label0: return end_function ----------------------------- proc F:: local i32 i.1 load i32 0 store i32 i.1 jump #2 #4: load u64 &i.1 incrto i32 /1 #2: load i32 i.1 load i32 10000 jumplt i32 #4 #3: #1: retproc endproc