summaryrefslogtreecommitdiff
path: root/miniany/README
blob: 6367011d9e2d8d11b36bd6081ec48c26f7bde1d4 (plain)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Running on host:

```
./build.sh cc tcc hosted d
./build.sh cc tcc freestanding d
./cc < test1.c > test1.asm
fasm test1.asm test1.bin
ndisasm -b32 -o1000000h -a test1.bin
```

# Running on c4:

```
echo -n -e "\034" > EOF
cat cc.c EOF hello.c | ./c4
cat c4.c EOF cc.c EOF hello.c | ./c4
cat c4.c4 EOF c4.c EOF cc.c EOF hello.c | ./c4
```

# Local version of c4

This local version of c4 is used to guarantee that our own bootstrapped
cc.c can also run on c4. This makes sure we are not integrating too
complex things into our own compiler.

* currently integrated:
  - switch statement from switch-and-structs, adapted c4 to use switch
    statements instead of ifs (as in switch-and-structs)
  - structures from switch-and-structs
* my own changes:
  - constants like EOF, EXIT_SUCCESS, NULL
  - standard C block comments along to c++ end of line ones
  - negative enum initializers
  - do/while loops
  - more C functions like isspace, getc, strcmp
  - some simplified functions for printing like putstring, putint, putnl
  - strict C89 conformance, mainly use standard comment blocks, also
    removed some warnings
  - some casts around malloc and memset to fit to non-void freestanding-libc
  - converted printf to putstring/putint/putnl and some helper functions
    for error reporting like error()
  - removed memory leaks
  - de-POSIX-ified, no open/read/close, use getchar from stdin only
    (don't assume the existence of a file system), this also means
    we have to create sort of an old style tape-file with FS markers
    to separate the files piped to c4.

# Acknoledgments and references

* c4
  * https://github.com/rswier/c4.git
    c4 - C in four functions
    minimalistic C compiler running on an emulator on the IR, inspiration
    for this project
  * https://github.com/rswier/c4/blob/switch-and-structs/c4.c:
    c4 adaptions to provide switch and structs
  * https://github.com/EarlGray/c4: a X86 JIT version of c4
  * https://github.com/jserv/amacc: based on C4, JIT or native code, for
    ARM, quite well documented, also very nice list of compiler
    resources on Github page

* selfie
  * http://selfie.cs.uni-salzburg.at/:
    C* self-hosting C compiler (also emulator, hypervisor) for RISCV,
    inspiration for what makes up a minimal C language

* tiny.c
  * http://www.iro.umontreal.ca/~felipe/IFT2030-Automne2002/Complements/tinyc.c,
    Marc Feeley, really easy and much more readable, meant as educational compiler

* c.c in swieros: https://github.com/rswier/swieros.git

* https://github.com/lotabout/write-a-C-interpreter/blob/master/tutorial/en/: tutorial
  based on C4 how to build a C interpreter, explains nicely details in C4.

* https://github.com/felipensp/assembly/blob/master/x86/itoa.s,
  https://baptiste-wicht.com/posts/2011/11/print-strings-integers-intel-assembly.html,
  putint for early debugging

* documentation
  * "Compiler Construction", Niklaus Wirth
  * https://github.com/DoctorWkt/acwj: a nice series on building a C compiler,
    step by step with lots of good explanations
  * https://www.engr.mun.ca/~theo/Misc/exp_parsing.htm#climbing,
    https://en.wikipedia.org/wiki/Operator-precedence_parser#Precedence_climbing_method