Skip to content

Instantly share code, notes, and snippets.

@tingwei628
Last active October 24, 2021 14:04
Show Gist options
  • Save tingwei628/ff433ba40f4eec77b82fa2af292d4f64 to your computer and use it in GitHub Desktop.
Save tingwei628/ff433ba40f4eec77b82fa2af292d4f64 to your computer and use it in GitHub Desktop.
COOL compiler note

Backend

IR -> IR Optimization -> Code Generation(Register allocation/Instruction selection) Assembly

Code generation

1.top-of-stack caching (1-TOSCA)
2.init garbage collector

Object layout

1.similar to C++ inheritance
2.gc in COOL runtime
3.Class Tag, Object Size, Dispatch table pointer (similar to C++ vptr), Dispatch table (similar to C++ vtable)
4.register allocation is Graph coloring
(Linear-Scan Register Allocation is another way to allocate registers)

IR

1.Three-address code (it doesn't be implemented in this course)

Runtime

1.it contains a concurrent garbage collector
2.the management of application memory
3.how the program accesses variables, mechanisms for passing parameters between procedures
4.interfacing with the operating system
5.The compiler makes assumptions depending on the specific runtime system to generate correct code.

GC (cgen.cc)

gc is also part of the program

Questions

1.gc in runtime
2.how gc works
3.stack-based virtual machine -> register-based virtual machine (?
4.code generation
4-1. stack based machine
4-2. register based machine
-> register allocation and assignment
-> instruction selection/instruction scheduling
5. how to verify and test compiler?

@tingwei628
Copy link
Author

@tingwei628
Copy link
Author

tingwei628 commented Oct 9, 2021

known issues

  1. How to work under ASLR ? (fPIC?)
  2. stdin/stdout is hardcoded. (Type: R_AARCH64_COPY)
  3. fflush(stdin) before fgets (problem)
  4. Under GC mode, Program received signal SIGSEGV, Segmentation fault. _GenGC_MajorC_stackloop () at trap_handler_aarch64.s

@tingwei628
Copy link
Author

tingwei628 commented Oct 15, 2021

(gdb)x/xg is equivalent to x/2xw (g: 8-byte, w: 4-byte)

0xfffffffffad0: 0x0040128c
(gdb) x/4xw 0xfffffad0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment