ZCC
ZJU standard C Compiler
Code Organization
- Lex and Yas related codes are in the folder yyparse.
- Symbol table and Type check related codes are in the folder symbol.
- Generating machine code related codes are in the folder generation.
- Treating Special variables related codes are in the folder public.
- Optimization codes are stored separately in each folder.
Parsing Tree Sample:
declaration
declaration_specifiers
storage_class_specifier
typedef
declaration_specifiers
type_specifier
struct_or_union_specifier
struct_or_union
struct
{
struct_declaration_list
struct_declaration_list
struct_declaration
specifier_qualifier_list
type_specifier
int
struct_declarator_list
struct_declarator
declarator
direct_declarator
a
;
struct_declaration
specifier_qualifier_list
type_specifier
double
struct_declarator_list
struct_declarator
declarator
direct_declarator
c
;
}
init_declarator_list
init_declarator
declarator
direct_declarator
mytype
;
Code Generation
Miscellaneous
Call functions in self.tools to translate.
Detailed comments and examples can be found in generation.generate.
Basic X86 supports
- Calculation: add, sub, mul, div.
- Logic: and, or, not.
- Jump: jmp, je, jg, jl.
- Shift: sal, sar.
- Function: call, ret.
- Stack: push, pop.
- Float number operation: fld, fstp, fadd, fsub, fmul, fdiv.
- Global/Static variables, Constant float number, String
Code Optimization
The optimization types supported
http://www.compileroptimizations.com/index.html
Constant propagation
http://people.eecs.berkeley.edu/~bodik/cs264/lectures/4-chaotic-notes.pdf