Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #101024

Re: 'Amalgamated' source code

From BartC <bc@freeuk.com>
Newsgroups comp.lang.c
Subject Re: 'Amalgamated' source code
Date 2017-01-03 19:47 +0000
Organization A noiseless patient Spider
Message-ID <o4gv18$8sc$1@dont-email.me> (permalink)
References <o4gf2a$bl9$1@dont-email.me> <dbf92bb2-ae2d-4133-83f6-f0f9a5c5d198@googlegroups.com>

Show all headers | View raw


On 03/01/2017 16:47, Thiago Adams wrote:
> On Tuesday, January 3, 2017 at 1:14:53 PM UTC-2, Bart wrote:
>> Interesting article here on converting large projects into just a few
>> source files:
>>
>> https://blog.forrestthewoods.com/improving-open-source-with-amalgamation-cf293592c5f4#.jzgq6ppvn

> Hi, I like the concept of one-unit of compilation.
> (I also have implemented an C preprocessor.)

(I'm the middle of one at the minute. Most online refs on writing 
compilers tend to ignore this piffling little obstacle that you have to 
overcome first!)

> I think there are two options to generate this amalgamation.

> 2) " Transpilation" - generate C code
> Read many C files and generates one file doing what is necessary to avoid internal linkage conflicts.
>
> The generated code also could transform functions into static
> to make internal linkage if they are not "exported".
>
> I was playing with this idea because I wanted to use my parser to extend the C language but generating one ANSI C file.
>
> Let's say I want to implement the default initialization in a extended C language.
>
> --file1.h--
> #include <stdio.h>
...
> #include "file1.h"
...

>Then the generated C file would be:
>
> #include <stdio.h>
>
> struct X {
>  int i;
> };
>
> void f() {
>   struct X x = {1};
> }
>
>
> Note that because I changed the declaration I cannot include file1.h but I still including system files <stdio.h>
> For static function inside many files I would have to rename each function when generating one file

> --file1.c--
>
> static void F() { }
>
> void F2() {   F(); }
...
> merged file
>
> static void _FILE1_F() { }
> void F2() {   _FILE1_F(); }

This is like the approach I use at the minute, but part of a project 
where non-C source is converted to C, still a module at a time. A 
special compile option is used to change how declarations are generated 
and how global names are treated (by adding prefixing, but I'm also 
experimenting with no prefix, and manually avoiding clashes, as 
otherwise the output looks horrific. Or more horrifix!).

In this form, it can't be processed a C compiler as normal. A separate 
step is needed that scans all the modules, and collates the blocks of 
code, so that all type declarations, all variables etc are grouped 
together at the top of the file. (Example 
https://github.com/bartg/langs/blob/master/pcc.c)

It's a bit of a pain (and there are complications to do with the target 
OS where the right modules have to be picked). I'll be glad when my new 
C to C translator works then it'll be automatic.

 > https://www.sqlite.org/amalgamation.html

I wonder why other open source products don't take the same approach? 
Sometimes people just aren't interested in the details of how a project 
is structured, they just want to compile whatever source code is needed 
and end up with an executable, without any fuss, or having to install 
half of Unix.

-- 
Bartc

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-03 15:14 +0000
  Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-03 08:47 -0800
    Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-03 19:47 +0000
      Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-03 12:48 -0800
        Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-03 21:36 +0000
          Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-03 16:01 -0800
            Re: 'Amalgamated' source code Keith Thompson <kst-u@mib.org> - 2017-01-03 16:26 -0800
              Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-03 18:00 -0800
                Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-04 03:34 +0000
                Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-04 03:31 -0800
                Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 12:03 +0000
                Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-04 05:00 -0800
                Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-05 02:38 -0800
                Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-05 14:28 +0000
                Re: 'Amalgamated' source code supercat@casperkitty.com - 2017-01-05 08:20 -0800
                Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-05 17:05 +0000
                Re: 'Amalgamated' source code supercat@casperkitty.com - 2017-01-05 10:11 -0800
                Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-05 19:46 +0000
                Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-05 12:15 -0800
                Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-05 21:54 +0000
                Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-05 17:40 +0000
                Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-05 19:33 +0000
            Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 10:53 +0000
          Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-04 01:51 +0000
        Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 11:54 +0000
          Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-04 05:57 -0800
            Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 14:20 +0000
            Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 15:07 +0000
              Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-04 15:34 +0000
                Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-04 08:03 -0800
                Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-04 17:09 +0000
                Re: 'Amalgamated' source code bart4858@gmail.com - 2017-01-04 08:54 -0800
                Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-04 17:22 +0000
              Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-04 07:55 -0800
                Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-05 18:04 +0000
                Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-05 11:50 -0800
  Re: 'Amalgamated' source code Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-01-04 16:29 +0000
    Re: 'Amalgamated' source code bart4858@gmail.com - 2017-01-04 09:15 -0800
      Re: 'Amalgamated' source code Ian Collins <ian-news@hotmail.com> - 2017-01-05 08:33 +1300
        Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 20:26 +0000
          Re: 'Amalgamated' source code supercat@casperkitty.com - 2017-01-04 13:09 -0800
          Re: 'Amalgamated' source code Ian Collins <ian-news@hotmail.com> - 2017-01-05 10:21 +1300
            Re: 'Amalgamated' source code supercat@casperkitty.com - 2017-01-04 13:51 -0800
            Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 22:02 +0000
              Re: 'Amalgamated' source code Ian Collins <ian-news@hotmail.com> - 2017-01-05 11:15 +1300
      Re: 'Amalgamated' source code Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-01-07 06:38 +0000
        Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-07 11:35 +0000
    Re: 'Amalgamated' source code supercat@casperkitty.com - 2017-01-04 09:53 -0800
    Re: 'Amalgamated' source code Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-04 11:50 -0800
    Re: 'Amalgamated' source code raltbos@xs4all.nl (Richard Bos) - 2017-01-10 01:34 +0000
      Re: 'Amalgamated' source code Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-10 01:59 -0800
      Re: 'Amalgamated' source code Les Cargill <lcargill99@comcast.com> - 2017-01-10 06:55 -0600
      Re: 'Amalgamated' source code Richard Heathfield <rjh@cpax.org.uk> - 2017-01-10 14:48 +0000
  Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-04-26 07:17 -0700

csiph-web