Re: question about linker

Liste des GroupesRevenir à cl c  
Sujet : Re: question about linker
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.c
Date : 03. Dec 2024, 16:47:02
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vin95m$5da6$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
User-Agent : Mozilla Thunderbird
On 03/12/2024 14:34, David Brown wrote:
On 02/12/2024 22:53, Bart wrote:

So, how would you have organised the 16-module example I posted elsewhere? (Not a C project, these are 16 source files, so no headers etc.)
>
Because two posters here have suggested my organisation is poor, but without knowing how big, small, or complex my projects are.
 No one (as far as I have noticed) have said that your organisation /is/ poor - they have said it /sounds/ poor from the way you describe it. The difference is very significant.
 For file organisation, I'd likely have all the modules in one directory unless there is a particular reason to split them up.  I would not have any non-project files in that directory.
 But the questions raised about your organisation was not a matter of where you store your files, or how they are divided in directories.  It is about how you organise the code and split functionality between files (or directories, for bigger projects).
 What you have described is modules that have far too much in one file, modules with little or no structure as to where things are in the file,
Because it doesn't really matter. (My language allows out-of-order everything. So all module-scope variables could go at the end of the file, or file-scope variables at the end of the function! However I don't do that.
But I really don't want to care about whether function F precedes G in the file, or follows it. Any more than I would care whether a file "F" is stored before or after file "G" in a directory! The ordering could be sorted in different ways for display; perhaps an editor could do the same. (I guess your IDE does that.)

little to no structure or control over which modules use facilities from which other modules, and completely random inter-module dependencies which can happily be circular.
They can be circular when it makes sense. They are after all part of the same program!
In C, if you have 100 modules, but modules 23 and 87 need to share some variable or function, it can be visible to the other 98 too, or can clash with the same name thaty 17 and 26 want to share. Or with a name that module 72 forgot to make static.
Or module 49 exports variable 'abc' as int, but 53 imports it as 'char*', then fun and games follow. C has a lot worse problems!
Being able to split a too-large module into two or more files without worrying about hierarchy is a good thing; isn't it? If the original function exported F G H, accessed as X.F, X.G, X.H, do you then have to change all the calls to X.F, Y.G, Z.G because of how the original file has been split up?
My scheme just makes this stuff very easy and effortless.

These opinions are formed from how you describe your code and your language.
Below I've given the actual set of modules from my C compiler project, partly annotated. It comprises three libraries whose sources files are compiled into one executable.
The 'PCL' one (pc_ files) will probably be split up too at some point; right now there's no need.
The average module size is 1000 lines, but some are larger. For example, pc_genmcl, which is a set of 150 handler functions for the 150 opcodes of my IL.
And pc_run, which is the interpreter for the IL, whose core is an 1100-line function containing a special kind of looping switch which is implemented as a computed-goto (different from a normal switch since there are N dispatch points rather than 1).
So a module is larger when it needs to encapsulate functions that do part of the same job. There are several modules which have to dispatch on an IL bytecode, or AST tag, or native code instruction.

 
>
BTW your project doesn't sound that big, especially if you have a penchant for having a larger number of smaller files.
>
A line-count would give a better idea.
>
 For the whole project (relevant to things like the build and the organisation):
 -----------------------------------------------------------------------
Language             files          blank        comment           code
-----------------------------------------------------------------------
C                      155          13849          34547          80139
C/C++ Header           284          13719          62329          61056
C++                     43           2447           1230          13009
-----------------------------------------------------------------------
SUM:                   482          30015          98106         154204
-----------------------------------------------------------------------
So about 600 lines per file.

 For the project-specific code, rather than libraries, SDK, etc.:
 -----------------------------------------------------------------------
Language             files          blank        comment           code
-----------------------------------------------------------------------
C++                     39           2217           1020          11820
C/C++ Header            44           1078            798           2696
C                        3            259            237           1152
-----------------------------------------------------------------------
SUM:                    86           3554           2055          15668
------------------------------------------------------------------------
And here about 250 lines per file. Total line count isn't that different from my 1990s CAD app, which was about 150Kloc, more than half consisting of scripted modules.
This doesn't include the add-on scripted modules that OEMs would write (plus alls sorts of data files, libraries of parts etc) to form the final product.
Anyway, below are my C compiler modules as promised.
Here, there is a hierarchy. None of the second two libraries can access anything from the main application. Both the first two can can access imported entities from the third library.
-----------------------------------
# Main application
project =
     module cc_cli
# Global Data and Tables
     module cc_decls
     module cc_tables
# Lexing and Parsing
     module cc_lex
     module cc_parse
# Generate PCL
     module cc_genpcl
     module cc_blockpcl
     module cc_libpcl
# General
     module cc_lib
     module cc_support
# Bundled headers
     module cc_headers
#   module cc_headersx
# Diagnostics
     module cc_show
#   module cc_showdummy
# IL Backend
     $sourcepath "c:/px/"
     import pcl
end
# Backend library
project =
     module pc_decls
# API to generate IL from a front-end compiler
     module pc_api
# IL Diagnostics
     module pc_diags
#   module pc_diags_dummy
     module pc_reduce         # experimental IL optimiser
# PCL (IL) Interpreter
     module pc_run
     module pc_runaux
# Tables (eg. types and IL opcodes)
     module pc_tables
# x64 backend (pcl -> mcl)
     module mc_GenMCL         # Main loop scanning PCL code
     module mc_AuxMCL
     module mc_LibMCL         # API for building MCL (native code) representation
     module mc_StackMCL       # Deal with converting stack-based IL to reg-based native code
# Generate SS tables (MCL -> SS; SS is binary native code)
     module mc_GenSS
     module mc_Decls as md    # (eg. x64 opcode enums)
     module mc_OBJdecls       # Describe PE-format data structures
# Write ASM (currently only one at a time is compiled in)
     module mc_WriteASM       # MCL -> ASM source
#   module mc_WriteNASM      # MCL -> NASM-format source
# Write EXE/DLL/OBJ (from SS)
     module mc_WriteEXE       # Create PE image and write EXE or DLL
     module mc_WriteOBJ
# SS diagnostic display
#   module mc_writess
#   module mc_disasm         # x64 disassembler for code segments
     module mc_writess_dummy
# SS -> MCU -> MCX/MCB (Runnable in-memory code; or MX binary file)
     module mx_decls
     module mx_run
     module mx_lib
     module mx_write          # Write MX-format binary
end
# Standard library of my language (this is imported by default)
project =
     module msys          # Language support
     module mlib          # The std library
     module mclib         # Import some C std library functions
     module mwindows      # OS-specific functions
     module mwindll       # provides LIBFFI-like capabilities
end
-----------------------------------
When I used to support Linux targets, then mwindows was replaced by 'mlinux', or 'mnos' for an OS-neutral version. This module provides a common set of wrapper functions over some OS-specfic functions
For a C target (of the compiler for this project, then a target of this project), then mwindll is replaced mwindllc, which provides some limited functionality using HLL code only (so that it can be transpiled to C)

Date Sujet#  Auteur
26 Nov 24 * question about linker382Thiago Adams
26 Nov 24 +* Re: question about linker16Thiago Adams
26 Nov 24 i`* Re: question about linker15Bart
26 Nov 24 i `* Re: question about linker14Thiago Adams
27 Nov 24 i  +* Re: question about linker2BGB
27 Nov 24 i  i`- Re: question about linker1Bart
27 Nov 24 i  +* Re: question about linker5David Brown
27 Nov 24 i  i`* Re: question about linker4Thiago Adams
27 Nov 24 i  i +* Re: question about linker2David Brown
27 Nov 24 i  i i`- Re: question about linker1Thiago Adams
2 Dec 24 i  i `- Re: question about linker1BGB
27 Nov 24 i  `* Re: question about linker6Michael S
27 Nov 24 i   `* Re: question about linker5Thiago Adams
27 Nov 24 i    `* Re: question about linker4Michael S
27 Nov 24 i     +- Re: question about linker1David Brown
28 Nov 24 i     +- Re: question about linker1Tim Rentsch
2 Dec 24 i     `- Re: question about linker1BGB
26 Nov 24 +* Re: question about linker20Bart
26 Nov 24 i`* Re: question about linker19Thiago Adams
26 Nov 24 i `* Re: question about linker18Bart
27 Nov 24 i  +* Re: question about linker3BGB
27 Nov 24 i  i`* Re: question about linker2fir
27 Nov 24 i  i `- Re: question about linker1BGB
27 Nov 24 i  `* Re: question about linker14Bart
27 Nov 24 i   +* Re: question about linker12Thiago Adams
27 Nov 24 i   i+- Re: question about linker1Thiago Adams
27 Nov 24 i   i`* Re: question about linker10Bart
27 Nov 24 i   i +* Re: question about linker6Bart
27 Nov 24 i   i i`* Re: question about linker5Thiago Adams
27 Nov 24 i   i i +* Re: question about linker3Thiago Adams
27 Nov 24 i   i i i`* Re: question about linker2Thiago Adams
27 Nov 24 i   i i i `- Re: question about linker1Bart
27 Nov 24 i   i i `- Re: question about linker1Bart
27 Nov 24 i   i `* Re: question about linker3Thiago Adams
27 Nov 24 i   i  `* Re: question about linker2Bart
27 Nov 24 i   i   `- Re: question about linker1Thiago Adams
28 Nov 24 i   `- Re: question about linker1Tim Rentsch
27 Nov 24 `* Re: question about linker345Waldek Hebisch
27 Nov 24  `* Re: question about linker344Thiago Adams
28 Nov 24   `* Re: question about linker343Keith Thompson
28 Nov 24    `* Re: question about linker342Thiago Adams
28 Nov 24     +* Re: question about linker337Bart
28 Nov 24     i`* Re: question about linker336Keith Thompson
29 Nov 24     i `* Re: question about linker335Bart
29 Nov 24     i  `* Re: question about linker334Keith Thompson
29 Nov 24     i   `* Re: question about linker333Bart
29 Nov 24     i    +* Re: question about linker3Keith Thompson
29 Nov 24     i    i`* Re: question about linker2Bart
29 Nov 24     i    i `- Re: question about linker1Keith Thompson
29 Nov 24     i    `* Re: question about linker329David Brown
29 Nov 24     i     `* Re: question about linker328Bart
29 Nov 24     i      +- Re: question about linker1Ike Naar
29 Nov 24     i      +* Re: question about linker325Michael S
29 Nov 24     i      i+* Re: question about linker322Bart
29 Nov 24     i      ii`* Re: question about linker321Michael S
29 Nov 24     i      ii +* Re: question about linker319David Brown
29 Nov 24     i      ii i`* Re: question about linker318Bart
29 Nov 24     i      ii i +* Re: question about linker164Keith Thompson
29 Nov 24     i      ii i i`* Re: question about linker163Bart
30 Nov 24     i      ii i i `* Re: question about linker162Keith Thompson
30 Nov 24     i      ii i i  +* Re: question about linker95Waldek Hebisch
30 Nov 24     i      ii i i  i+- Re: question about linker1Keith Thompson
30 Nov 24     i      ii i i  i+* Re: question about linker3James Kuyper
30 Nov 24     i      ii i i  ii`* Re: question about linker2Michael S
3 Dec 24     i      ii i i  ii `- Re: question about linker1Tim Rentsch
1 Dec 24     i      ii i i  i`* Re: question about linker90David Brown
1 Dec 24     i      ii i i  i +* Re: question about linker88Bart
1 Dec 24     i      ii i i  i i`* Re: question about linker87David Brown
1 Dec 24     i      ii i i  i i `* Re: question about linker86Bart
2 Dec 24     i      ii i i  i i  `* Re: question about linker85David Brown
2 Dec 24     i      ii i i  i i   `* Re: question about linker84Bart
2 Dec 24     i      ii i i  i i    +* Re: question about linker78David Brown
2 Dec 24     i      ii i i  i i    i+* Re: question about linker72Janis Papanagnou
2 Dec 24     i      ii i i  i i    ii+* Re: question about linker70Bart
2 Dec 24     i      ii i i  i i    iii+* Re: question about linker68David Brown
2 Dec 24     i      ii i i  i i    iiii`* Re: question about linker67Bart
3 Dec 24     i      ii i i  i i    iiii `* Re: question about linker66David Brown
3 Dec 24     i      ii i i  i i    iiii  +* Re: question about linker53Bart
3 Dec 24     i      ii i i  i i    iiii  i`* Re: question about linker52David Brown
3 Dec 24     i      ii i i  i i    iiii  i `* Re: question about linker51Bart
4 Dec 24     i      ii i i  i i    iiii  i  `* Re: question about linker50David Brown
4 Dec 24     i      ii i i  i i    iiii  i   `* Re: question about linker49Bart
4 Dec 24     i      ii i i  i i    iiii  i    `* Re: question about linker48David Brown
4 Dec 24     i      ii i i  i i    iiii  i     +* Re: question about linker24Bart
5 Dec 24     i      ii i i  i i    iiii  i     i`* Re: question about linker23David Brown
5 Dec 24     i      ii i i  i i    iiii  i     i +- Re: question about linker1Janis Papanagnou
5 Dec 24     i      ii i i  i i    iiii  i     i `* Re: question about linker21Bart
6 Dec 24     i      ii i i  i i    iiii  i     i  `* Re: question about linker20David Brown
6 Dec 24     i      ii i i  i i    iiii  i     i   `* Re: question about linker19Bart
6 Dec 24     i      ii i i  i i    iiii  i     i    +* Re: question about linker5Ike Naar
6 Dec 24     i      ii i i  i i    iiii  i     i    i+- Re: question about linker1Bart
7 Dec 24     i      ii i i  i i    iiii  i     i    i+- Re: question about linker1Keith Thompson
7 Dec 24     i      ii i i  i i    iiii  i     i    i`* Re: question about linker2Bart
7 Dec 24     i      ii i i  i i    iiii  i     i    i `- Re: question about linker1Keith Thompson
7 Dec 24     i      ii i i  i i    iiii  i     i    +* Re: question about linker10David Brown
7 Dec 24     i      ii i i  i i    iiii  i     i    i`* Re: question about linker9Bart
7 Dec 24     i      ii i i  i i    iiii  i     i    i `* Re: question about linker8David Brown
7 Dec 24     i      ii i i  i i    iiii  i     i    i  `* Re: question about linker7Bart
7 Dec 24     i      ii i i  i i    iiii  i     i    i   `* Re: question about linker6David Brown
7 Dec 24     i      ii i i  i i    iiii  i     i    i    `* Re: question about linker5Bart
8 Dec 24     i      ii i i  i i    iiii  i     i    i     +* Re: question about linker3Ben Bacarisse
8 Dec 24     i      ii i i  i i    iiii  i     i    i     `- Re: question about linker1David Brown
8 Dec 24     i      ii i i  i i    iiii  i     i    `* Re: question about linker3Waldek Hebisch
5 Dec 24     i      ii i i  i i    iiii  i     +* Re: question about linker15Waldek Hebisch
11 Dec 24     i      ii i i  i i    iiii  i     `* Re: question about linker8James Kuyper
3 Dec 24     i      ii i i  i i    iiii  `* Re: question about linker12Bart
3 Dec 24     i      ii i i  i i    iii`- Re: question about linker1Janis Papanagnou
2 Dec 24     i      ii i i  i i    ii`- Re: question about linker1Bart
2 Dec 24     i      ii i i  i i    i`* Re: question about linker5Bart
4 Dec 24     i      ii i i  i i    `* Re: question about linker5Waldek Hebisch
1 Dec 24     i      ii i i  i `- Re: question about linker1Janis Papanagnou
30 Nov 24     i      ii i i  +* Re: question about linker44Bart
30 Nov 24     i      ii i i  +- Re: question about linker1Janis Papanagnou
1 Dec 24     i      ii i i  `* Re: question about linker21David Brown
30 Nov 24     i      ii i `* Re: question about linker153David Brown
5 Dec 24     i      ii `- Re: question about linker1Tim Rentsch
30 Nov 24     i      i`* Re: question about linker2Tim Rentsch
29 Nov 24     i      `- Re: question about linker1David Brown
28 Nov 24     `* Re: question about linker4Keith Thompson

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal