This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Help with creating a simple switch stmt in Gimple
- From: Ian Lance Taylor <iant at google dot com>
- To: Jeff Saremi <jeffsaremi at yahoo dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 26 Jul 2010 23:02:44 -0700
- Subject: Re: Help with creating a simple switch stmt in Gimple
- References: <561684.8462.qm@web88105.mail.re2.yahoo.com>
Jeff Saremi <jeffsaremi@yahoo.com> writes:
> Does anyone have an example of how to create a simple switch statement in Gimple? I'm really confused by the CASE_LABEL.
> I know that to create a switch one can call gimple_build_switch() but then it requires one or more case labels (so far so good). But there seem to be no function that can create a case label. We have gimple_build_label() which may be the one however again i'm confused by the fact that this function takes an existing? label. Why would someone want to create a label for an existing label.
A CASE_LABEL_EXPR contains a reference to an existing LABEL_DECL. A
CASE_LABEL is part of a GENERIC SWITCH_EXPR or a GIMPLE GIMPLE_SWITCH.
Either construct has a list of CASE_LABEL_EXPRs. Each CASE_LABEL_EXPR
refers to a LABEL_DECL. The LABEL_DECL should be defined elsewhere in
the function in front of whatever code should be executed for that case.
In other words, a GIMPLE_SWITCH is a multi-way goto.
To build a CASE_LABEL_EXPR, use build3.
gimple_build_label takes a GENERIC LABEL_DECL and constructs a
GIMPLE_LABEL.
Ian