If your language is quite different from C, and you wish to make a fast
compiler, I would suggest building  the compiler yourself. If you can make
EBNF of the langage syntax, your frontend is almost done. Take some fast
parser generator. I strongly recommend Coco/R because it generates easy to
understand and fast parser code and suipports different programming
languages.
The Compiler Generator Coco/R (jku.at)
<https://ssw.jku.at/Research/Projects/Coco/>

What is here interesting, you can add code in your favorite language to be
executed after any syntax element is recognized inside (.    .)  brackets.
It may be storing new variables during the declaration into the table ,
recognizing the variable already in the table or machine code generating.
It is relatively easy to generate assembly code, but it is not the fastest
way to execute. In a case of machine code, you need to know also about
executable format (headers and sections), instruction encoding and code
patching in case of jumps.

On Wed, Jan 26, 2022 at 10:09 PM Niklas Rosencrantz <[email protected]>
wrote:

> I'm not an expert C programmer. I could find my way, read and learn from
> the TCC source code. It reminded me of reading the source of SASH (the
> stand-alone shell) which is readable compared to DASH for example.
>
> 2. What I would do to learn more but it's not guaranteed to work
>
> a) I would try and learn how statements (in C) translate to assembly for a
> target platform. Maybe start with ARM or MIPS that is supposed to be easier
> than x86 asm.
>
> b) I would try and write a disassembler because I heard it's a good
> exercise.
>
> My experience is that compilers or how to write an interpreter is not a
> learn-by-doing ability. I would need to read and practice a lot before
> trying to do it.
>
> /Niklas
>
> Den ons 26 jan. 2022 20:28rempas via Tinycc-devel <[email protected]>
> skrev:
>
>> **Huge post incoming!!!**
>>
>> Hi! I'm a beginner with low level programming and assembly. I'm
>> interested in learning
>> assembly so I can create my own (non-toy) compiler. Now, I'm a huge
>> fanatic for
>> TCC!!! I LOVE IT!!! I love it so much that it inspired my to create my
>> own compiler that
>> will output C code and then use TCC (or any C compiler to compile) it.
>> However, I thought about some things.
>>
>> 1. Compile times. TCC is the fastest non-toy compiler but my compiler
>>     will add up to the compilation time because it will need to create
>>     these C files. On top on that, the C programming language doesn't
>>     use the best practices when it comes to header files as you have to
>>     re-write the files end up on becoming slower not because of the
>> compiler
>>     or the backend because because of the design of the language itself.
>>
>> 2. Having to deal with C. A lot of things of my language will not
>> translate to C
>>     with the best possible way so it will be harder and I will need to
>> sacrifice the
>>     compilation times and maybe runtime performance.
>>
>> 3. Optimizations. As we know, TCC doesn't make optimizations (or does
>> it?) so
>>     the resulting code can run slower that GCC or Clang some times. This
>> means
>>     that we will need to use 2 compilers in some projects to get the best
>> possible
>>     performance while keeping the amazing fast compilation times of TCC.
>>
>> So what I thought was... "You know what? We don't I make a compiler that
>> will
>> create binaries itself? I will have the best possible compilation times
>> and I will
>> be able to apply the optimizations that I want!". Well that's a great
>> idea but there
>> are some problems.
>>
>> 1. This is HARD!!! Not only I must first learn assembly but I must also
>> read
>>     the manufacturer manual for each CPU that I want to support. Also,
>> even
>>     across the same instruction set, Each operating system needs different
>>     work to be done (I don't know, I suppose even OSes that use something
>>     common like ELF will not work out of the box without any small change
>> right?).
>>     So even for people that know assembly NOW and are very experienced
>> with it,
>>     this will be very hard to do and maintain unless you are a genius and
>> I am NOT
>>     one for sure (the exact opposite probably).
>>
>> 2. Where do I learn? I mean, resources about creating binary files in ELF
>> format
>>     (or whatever each OS is using) and learning the CPU instructions
>> don't exist here
>>     and there and even in the places where they exist, it is most of the
>> times, references
>>     or things like manufacturer manuals which are not the best things to
>> study if you
>>     don't have years of experience and you are already confident enough
>> with this topic.
>>
>> Ok this is getting too big, I will be sort. So after all that, I either
>> do my original idea
>> and output C code or I'm writing this email and hope for a reply. So what
>> I wanted
>> to ask from people that have work with TCC's code and know how assembly
>> works,
>> is TCC's backed tied with TCC's frontend? Will it be strain-forward If I
>> was trying to learn
>> some assembly and then trying to read TCC backend and then try to
>> understand how
>> it works and add my own frontend to it? What are your thoughts?
>>
>> _______________________________________________
>> Tinycc-devel mailing list
>> [email protected]
>> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>>
> _______________________________________________
> Tinycc-devel mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to