From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM,PLING_QUERY autolearn=no autolearn_force=no version=3.4.5-pre1 X-Received: by 2002:ac8:5e89:: with SMTP id r9mr28053759qtx.10.1617119354025; Tue, 30 Mar 2021 08:49:14 -0700 (PDT) X-Received: by 2002:a5b:8cd:: with SMTP id w13mr21243018ybq.92.1617119353867; Tue, 30 Mar 2021 08:49:13 -0700 (PDT) Path: eternal-september.org!reader02.eternal-september.org!news.uzoreto.com!news.muarf.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 30 Mar 2021 08:49:13 -0700 (PDT) In-Reply-To: <41bc7a62-9c70-466d-b316-5fc74a3ee845n@googlegroups.com> Injection-Info: google-groups.googlegroups.com; posting-host=146.5.2.231; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 146.5.2.231 References: <41bc7a62-9c70-466d-b316-5fc74a3ee845n@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <03c4c697-56ed-4640-a668-cef44e939eb9n@googlegroups.com> Subject: Re: Adapting an Ada compiler to generate 8051 code (Again?! ;-) From: Shark8 Injection-Date: Tue, 30 Mar 2021 15:49:14 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:61688 List-Id: On Tuesday, March 30, 2021 at 3:04:43 AM UTC-6, mockturtle wrote: > Dear.all,=20 > for a project related to a possible start-up, we need to program a Flash = controller that has a 8051 core (as many other controllers). I would like u= sing Ada for that, but I discovered (also by browsing c.l.a.) that there is= no Ada compiler producing 8051 code.=20 >=20 > I am considering involving some university colleagues of mine to start a = project aimed to having an Ada compiler for 8051, possibly leveraging some = existing compiler. According to some post read here, I understand that it i= s not totally impossible, if we are willing to accept some limitations.=20 >=20 > I did not study (yet) in detail the 8051, but as I understand it is a sma= ll 8-bit processor, with flash memory for code and data and a small amount = of RAM onboard (but maybe this depends on the specific controller). My know= ledge about compilers is superficial, but I guess we should give up to some= Ada features like=20 >=20 > * Multitasking (maybe only non preemptive policy, single priority, no dyn= amic task allocation? Kind of coroutines...) This depends. Dynamic multitasking would likely never work, but a staticall= y-set multitasking should be doable. While I wouldn't recommend using GNAT for targeting the 8051, this thesis l= ays out a lot of stuff on proving schedulability and WCET-proofs. https://openresearch-repository.anu.edu.au/bitstream/1885/112723/1/Bernardi= %20P%20Thesis%202017.pdf > * Dynamic memory allocation Maybe. Take a look at Ada's storage-pools here and you might be able to use some d= ynamic-memory, provided it goes through a custom allocator. (This is actual= ly a really good exercise: make an pool implemented as an array [indexed 0.= .14] w/ an access type that is a 4-bit integer, using 15 as the null-value.= Doing this will help you to understand access types a lot better.) > * Exception raising, but not handling, an exception would stop the execut= ion (I guess having an exception inside a microcontroller is not a nice ide= a... This sounds like a job for Spark to be sure that no exception will hap= pen) Are you going to implement a SPARK prover, or prove the source separately a= nd then feed it into the compiler? > * OOP? Some of that can be retained? There's an excellent couple of paper on optimizing OOP: https://scholarworks.umass.edu/cgi/viewcontent.cgi?article=3D1008&context= =3Dcs_faculty_pubs & ftp://trout.cs.washington.edu/tr/1996/06/UW-CSE-96-06-= 02.pdf The end-result is that a LOT of the dynamic-dispatch can be optimized to st= atically-known calls, especially in the presence of whole-program optimizat= ion. > * Run-time check of contracts (maybe can be kept active during developmen= t and debugging) I would recommend that they be kept on at all times, unless (a) actual benc= hmarking shows them to be a problem, and (b) they can be proven unnecessary= . > Considering the kind of software usually run inside a micro-controller, t= hese limitations do not sound too severe. We would retain all the "syntacti= c features" of Ada like strong typing, packages, named parameters and so on= ... that are a strong help in writing correct software. Also, with the limi= tations above a 8051 Ada code most probably would be also a Spark code. Or, alternatively, you could have the back-end signal what it can and canno= t support, erroring out with a good error-message if an unsupported constru= ct is submitted. (Just like the Ada-compiler can do if something is requested beyond its cap= abilities, like a custom integer-range suprsetting the system's own word-ra= nge.) > I have some knowledge about compilers, but not so deep to understand the = difficulties of this project and I would like to ask you=20 >=20 > 1. The most challenging points that you see in such a project, also if I = forgot something in the list of "feature to be given up" Ada isn't a small language, but it's also not a large language compared to = linguistics. The most challenging part I think, would be getting buy-in and effort in th= e project. > 2. Some compiler we can start from Byron is freely available, and MIT-licensed... but I only have up to the pa= rser done, IIRC. One thing that I am shooting for with Byron is having an easily interchange= able backend (code-generation), though with FORTH being the sort of default= output. [To aid in bootstrapping the compiler, since FORTH is easy to port= . The idea being compile to FORTH, run the FORTH on your new machine, then = (if needed) write your native backend and recompile with that: Bam! a new n= ative-code compiler.] > 3. An estimate of the effort in person-month (you wish...), considering a= skilled but inexperienced programmer (like a skilled university student)= =20 I don't know. It's sometimes easier when you have collaborators, and it's sometimes that = collaborators 'get in the way'.