Aria

A low-level systems programming language
git clone git://git.m21c.me/Aria.git
Log | Files | Refs | LICENSE

commit 73f33d1132a091c80184a4a75181cf1255b9e932
parent 3ea40cb3df5e88073884252d125b3a161a232d28
Author: m21c  <ho*******@gmail.com>
Date:   Thu,  2 Feb 2023 05:17:37 +0100

worked on data-flow analysis: alternative version

Diffstat:
Mcompiler.c | 113+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 113 insertions(+), 0 deletions(-)

diff --git a/compiler.c b/compiler.c @@ -430,6 +430,16 @@ enum BlockKind { BELSE = 8 } BlockKind; +typedef +enum ConductKind { + CUNREACH = 0, /* alway after a break, continue, goto or return */ + CSCOPE = 1, /* only the first conduct of a block and conducts after + * cunducts containing blocks are of this kind */ + CBLOCK = 2, /* always containing one or more blocks and nothing + else */ + CLABEL = 3 /* always after a label */ +} ConductKind; + /* SECTION: - type definitions - */ @@ -635,6 +645,82 @@ struct Conduct { Conduct *next, *prev; }; +typedef struct Section Section; +typedef struct Edge Edge; +typedef struct EdgeEntry EdgeEntry; +typedef struct Analysis Analysis; + +typedef enum EdgeKind { + JBRANCH = 0, /* unconditional branch */ + JIFBRANCH = 1, /* conditional branch */ + JNEXT = 2, /* unconditional next section (without branch) */ + JIFNEXT = 3 /* conditional next section (without branch) */ +} EdgeKind; + +struct Edge { + EdgeKind kind; + Section *section; + + Conduct *gistlist; /* NOTE(m21c): maybe remove this, since the gistlist + * is always the last of a section */ + + /* TODO(m21c): add information about the branch/edge condition */ + + /* for memory-management, since an edge is used in mult. edge-entries */ + int refcount; +}; + +typedef enum EdgeEntryKind { + JINGOING = 0, /* added as reachedfrom to section */ + JOUTGOING = 1, /* added as branchto to section */ + JSTART = 2, /* added as reachedfrom edge entry to first section */ + JEND = 3 /* added as branchto edge entry to last section */ +} EdgeEntryKind; + +/* NOTE(m21c): since an edge is used in multiple lists, edge-entry is used + * as linked-list entry */ +struct EdgeEntry { + EdgeEntryKind kind; + Section *belongsto; + + Edge *edge; /* is NULL on JSTART or JEND */ + EdgeEntry *prev, *next; +}; + +/* a section is single level. there is no hierarchy, like in the case of + * scopes/environments. a function has simply a list of section from top to + * bottom. */ +struct Section { + uint id; /* incremental number */ + + /* a section begins after baranch/label/start and ends + * containing a terminating branch/label/end. this way it contains at + * least one instructin/statement (terminating branch/label), if the + * (terminating branch/label/end) is not augment at the end of the + * function-scope/clause. */ + Node *first, *last; + + struct { + Conduct *head, *tail; + } gistlists; + + struct { + EdgeEntry *head, *tail; + } reachedfrom; + + struct { + EdgeEntry *head, *tail; + } branchto; + + /* prev/next section in code (no branch-info) from top to bottom + * in function */ + Section *prev, *next; +}; + +struct Analysis { + Section *head, *tail; +}; + @@ -4667,6 +4753,33 @@ dataflow(Block *block, Node *expr) } + +/* SECTION: - data-flow analysis version 2 */ + +static void +fetchsections(Analysis *analysis, Node *expr) +{ + Node *lhs, *rhs; + +nextnode: + switch (expr->kind) { + } +} + +static void +dataflow2(Analysis *analysis, Node *expr) +{ + assert(expr); + + fetchsections(analysis, expr); +} + + + +/* SECTION: - intermediate code generation - */ + + + /* SECTION: - print ast - */ static void