From 61a1343f3771491ca074207c7cd41649bc4f40df Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Tue, 13 May 2014 09:14:22 +0430 Subject: [PATCH] ncc: describe what each file does in its header --- arm.c | 1 + arm.h | 1 + cpp.c | 2 ++ gen.c | 1 + gen.h | 9 +++++---- mem.h | 2 +- ncc.c | 22 ++++++++++++++++++++-- out.c | 3 ++- out.h | 1 + reg.c | 1 + reg.h | 1 + tok.c | 1 + tok.h | 1 + x64.c | 1 + x64.h | 1 + x86.c | 1 + x86.h | 1 + 17 files changed, 42 insertions(+), 8 deletions(-) diff --git a/arm.c b/arm.c index 63ac741..2720a14 100644 --- a/arm.c +++ b/arm.c @@ -1,3 +1,4 @@ +/* architecture-dependent code generation for ARM */ #include #include "tok.h" #include "gen.h" diff --git a/arm.h b/arm.h index ae54ed4..00888de 100644 --- a/arm.h +++ b/arm.h @@ -1,3 +1,4 @@ +/* architecture-dependent header for ARM */ #define LONGSZ 4 /* word size */ #define I_ARCH "__arm__" diff --git a/cpp.c b/cpp.c index 9419a9e..19d4923 100644 --- a/cpp.c +++ b/cpp.c @@ -1,3 +1,4 @@ +/* neatcc preprocessor */ #include #include #include @@ -34,6 +35,7 @@ static int mnext[NDEFS]; /* macro hash table next entries */ #define BUF_EVAL 3 #define BUF_TEMP 4 +/* preprocessing input buffers for files, macros and macro arguments */ static struct buf { char *buf; int len; diff --git a/gen.c b/gen.c index 518048a..c394c12 100644 --- a/gen.c +++ b/gen.c @@ -1,3 +1,4 @@ +/* neatcc code generation */ #include #include #include diff --git a/gen.h b/gen.h index 07009ad..9ae99bc 100644 --- a/gen.h +++ b/gen.h @@ -1,3 +1,4 @@ +/* neatcc code generation interface */ /* basic types */ #define BT_SZMASK 0x00ff #define BT_SIGNED 0x0100 @@ -26,9 +27,9 @@ #define O_NOT 0x41 #define O_LNOT 0x42 -/* operations */ -void o_bop(int op); -void o_uop(int op); +/* operations on the stack */ +void o_bop(int op); /* binary operation */ +void o_uop(int op); /* unary operation */ void o_cast(unsigned bt); void o_memcpy(void); void o_memset(void); @@ -38,7 +39,7 @@ void o_assign(unsigned bt); void o_deref(unsigned bt); void o_load(void); int o_popnum(long *c); -/* pushing values */ +/* pushing values to the stack */ void o_num(long n); void o_local(long addr); void o_sym(char *sym); diff --git a/mem.h b/mem.h index 74e092f..7e30c5b 100644 --- a/mem.h +++ b/mem.h @@ -1,4 +1,4 @@ -/* variable length memory buffer */ +/* variable length buffer */ struct mem { char *s; /* allocated buffer */ int sz; /* buffer size */ diff --git a/ncc.c b/ncc.c index 66d958e..3658130 100644 --- a/ncc.c +++ b/ncc.c @@ -1,10 +1,25 @@ /* * neatcc - the neatcc compiler * - * Copyright (C) 2010-2013 Ali Gholami Rudi + * Copyright (C) 2010-2014 Ali Gholami Rudi * * This program is released under the Modified BSD license. */ +/* + * neatcc parser + * + * The parser reads tokens from the tokenizer (tok_*) and calls the + * appropriate code generation functions (o_*). The generator + * maintains a stack of values pushed via, for instance, o_num() + * and generates the necessary code for the accesses to the items + * in this stack, like o_bop() for performing a binary operations + * on the top two items of the stack. The parser maintains the + * types of values pushed to the generator stack in its type stack + * (ts_*). For instance, for binary operations two types are + * popped first and the resulting type is pushed to the type stack + * (ts_binop()). + * + */ #include #include #include @@ -328,6 +343,7 @@ static void tok_expect(int tok) err("syntax error\n"); } +/* the result of a binary operation on variables of type bt1 and bt2 */ static unsigned bt_op(unsigned bt1, unsigned bt2) { unsigned s1 = BT_SZ(bt1); @@ -335,6 +351,7 @@ static unsigned bt_op(unsigned bt1, unsigned bt2) return ((bt1 | bt2) & BT_SIGNED) | (s1 > s2 ? s1 : s2); } +/* push the result of a binary operation on the type stack */ static void ts_binop(int op) { struct type t1, t2; @@ -348,6 +365,7 @@ static void ts_binop(int op) ts_push_bt(bt); } +/* push the result of an additive binary operation on the type stack */ static void ts_addop(int op) { struct type t1, t2; @@ -453,7 +471,7 @@ static void enum_create(void) } } -/* used to differenciate labels from case and cond exprs */ +/* used to differentiate labels from case and cond exprs */ static int ncexpr; static int caseexpr; diff --git a/out.c b/out.c index d1dbd3e..885386e 100644 --- a/out.c +++ b/out.c @@ -1,3 +1,4 @@ +/* neatcc ELF object generation */ #include #include #include @@ -16,7 +17,7 @@ #define SEC_BSS 7 #define NSECS 8 -/* simplifed elf struct and macro names */ +/* simplified elf struct and macro names */ #if LONGSZ == 8 # define USERELA 1 # define Elf_Ehdr Elf64_Ehdr diff --git a/out.h b/out.h index 3eba142..b91bc58 100644 --- a/out.h +++ b/out.h @@ -1,3 +1,4 @@ +/* neatcc output object generation interface */ #define OUT_CS 0x0001 /* code segment symbol */ #define OUT_DS 0x0002 /* data segment symbol */ #define OUT_BSS 0x0004 /* bss segment symbol */ diff --git a/reg.c b/reg.c index 95e19cb..33137d5 100644 --- a/reg.c +++ b/reg.c @@ -1,3 +1,4 @@ +/* neatcc register allocation */ #include #include #include "gen.h" diff --git a/reg.h b/reg.h index e696381..1241a58 100644 --- a/reg.h +++ b/reg.h @@ -1,3 +1,4 @@ +/* register allocation interface */ void r_func(int nargs, int vargs); /* reset variables for functions */ int r_alloc(int leaf, int used); /* register allocation */ diff --git a/tok.c b/tok.c index f3c1455..ebae9e6 100644 --- a/tok.c +++ b/tok.c @@ -1,3 +1,4 @@ +/* neatcc tokenizer */ #include #include #include diff --git a/tok.h b/tok.h index 37cb414..16c3353 100644 --- a/tok.h +++ b/tok.h @@ -1,3 +1,4 @@ +/* neatcc tokenizer interface */ #define TOK2(a) ((a)[0] << 16 | (a)[1] << 8) #define TOK3(a) ((a)[0] << 16 | (a)[1] << 8 | (a)[2]) diff --git a/x64.c b/x64.c index f0e7141..4a7272c 100644 --- a/x64.c +++ b/x64.c @@ -1,3 +1,4 @@ +/* architecture-dependent code generation for x86_64 */ #include "tok.h" #include "gen.h" #include "out.h" diff --git a/x64.h b/x64.h index 0157312..3d913d3 100644 --- a/x64.h +++ b/x64.h @@ -1,3 +1,4 @@ +/* architecture-dependent header for x86_64 */ #define LONGSZ 8 /* word size */ #define I_ARCH "__x86_64__" diff --git a/x86.c b/x86.c index 4fd0b22..7eb1cf1 100644 --- a/x86.c +++ b/x86.c @@ -1,3 +1,4 @@ +/* architecture-dependent code generation for x86 */ #include "tok.h" #include "gen.h" #include "out.h" diff --git a/x86.h b/x86.h index fa059c9..ae93412 100644 --- a/x86.h +++ b/x86.h @@ -1,3 +1,4 @@ +/* architecture-dependent header for x86 */ #define LONGSZ 4 /* word size */ #define I_ARCH "__i386__" -- 2.11.4.GIT