Related articles |
---|
Basic blocks and CFG licaner@gmail.com (lican) (2009-03-16) |
Re: Basic blocks and CFG dnovillo@acm.org (Diego Novillo) (2009-03-17) |
Re: Basic blocks and CFG kamalpr@hp.com (kamal) (2009-03-17) |
From: | Diego Novillo <dnovillo@acm.org> |
Newsgroups: | comp.compilers |
Date: | Tue, 17 Mar 2009 09:45:22 -0400 |
Organization: | Compilers Central |
References: | 09-03-078 |
Keywords: | analysis, AST |
Posted-Date: | 17 Mar 2009 17:05:33 EDT |
On Mon, Mar 16, 2009 at 22:22, lican <licaner@gmail.com> wrote:
> Does anyone know if it is possible to build basic blocks without
> generating IR, directly from an AST? I find it rather difficult.
In general, it is not possible because you will have basic blocks with
multiple control flow paths inside. At the very least, you should
factor the ASTs so that each node contains no control side effects.
This means decomposing all the statements in your language that affect
control flow so that they are isolated in a single AST node. For
instance, using C's ?: operator
x = f ? u : v
decompose into
if (f)
t.1 = u
else
t.1 = v
x = t.1
Your next problem will be additional side-effects in expressions. If
you are going to do analysis and optimizations on your AST, having
expressions with side-effects will complicate matters (e.g., x = b++ *
--c).
Once you start down this road, you will very quickly converge into
some variant of 3-address representations. You can still keep using
your AST, you just apply stricter and stricter syntax requirements on
it.
Diego.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.