#include "ctrump/analyzer/analyze.h"
#include "ctrump/common/mempool.h"
#include "ctrump/ast/ast.h"
#include "ctrump/analyzer/cfg.h"
#include <stdlib.h>
#include "ctrump/common/abort.h"
#include "ctrump/common/varray.h"
#include "ctrump/common/intmap.h"
Go to the source code of this file.
Data Structures | |
struct | analyze_allocator |
ID, メモリアロケータ. More... | |
struct | build_loop_tree_state |
loop tree構築に必要な情報 More... | |
Functions | |
static void | init_build_loop_tree_state (struct build_loop_tree_state *st, struct ctrump_intmap *var_info_map, struct ctrump_varray *loops) |
static void | destroy_build_loop_tree_state (struct build_loop_tree_state *st) |
static int | analyze_loop_control_flow (struct build_loop_tree_state *st, struct ctrump_loop_cfg_info *attr, struct ctrump_cfg *cfg, struct ctrump_stmt *loop_body, struct ctrump_location *loc, struct analyze_allocator *alloc) |
static void | analyze_control_flow (struct build_loop_tree_state *st, struct ctrump_stmt *stmt, struct ctrump_cfg *cfg, struct analyze_allocator *alloc) |
コントロールフローの簡単な解析 ループ脱出が無いかどうかを解析する | |
static void | build_loop_tree_compound_stmt (struct build_loop_tree_state *st, struct ctrump_compound_stmt *stmt, struct ctrump_cfg *cfg, struct analyze_allocator *alloc) |
static void | complicated_loop (struct build_loop_tree_state *st, enum ctrump_complicated_loop_reason_code code, struct ctrump_stmt *stmt) |
static void | append_root (struct ctrump_varray *roots, struct ctrump_varray *new_roots) |
loop treeのルートを追加する | |
static void | build_loop_tree_func (struct ctrump_varray *loops, struct ctrump_fundef *func, struct ctrump_cfg *cfg, struct ctrump_intmap *var_info_map, const struct ctrump_abi *abi, struct analyze_allocator *alloc) |
loop treeを作る | |
int | ctrump_analyze (struct ctrump_translation_unit *unit, const struct ctrump_abi *abi, struct ctrump_mempool *pool, struct ctrump_build_cfg_error *error, int num_ast, int id_base) |
プログラムを解析する 解析結果は unit の指すツリーの中に反映される |
Definition in file analyze.c.
static void analyze_control_flow | ( | struct build_loop_tree_state * | st, | |
struct ctrump_stmt * | stmt, | |||
struct ctrump_cfg * | cfg, | |||
struct analyze_allocator * | alloc | |||
) | [static] |
コントロールフローの簡単な解析 ループ脱出が無いかどうかを解析する
Definition at line 125 of file analyze.c.
References analyze_loop_control_flow(), ctrump_do_while_stmt::body, ctrump_while_stmt::body, ctrump_for_decl_stmt::body, ctrump_for_stmt::body, ctrump_switch_stmt::body, ctrump_if_stmt::body, build_loop_tree_compound_stmt(), ctrump_stmt::case_, ctrump_stmt::code, complicated_loop(), ctrump_stmt::compound, CTRUMP_COMPLICATED_LOOP_BREAK, CTRUMP_COMPLICATED_LOOP_GOTO, CTRUMP_COMPLICATED_LOOP_HAVE_COMPLICATED_NEST, CTRUMP_COMPLICATED_LOOP_NEST, CTRUMP_COMPLICATED_LOOP_RETURN, CTRUMP_STMT_ASM, CTRUMP_STMT_BREAK, CTRUMP_STMT_CASE, CTRUMP_STMT_COMPOUND, CTRUMP_STMT_CONTINUE, CTRUMP_STMT_DECL, CTRUMP_STMT_DEFAULT, CTRUMP_STMT_DEFINE, CTRUMP_STMT_DO_WHILE, CTRUMP_STMT_EMPTY, CTRUMP_STMT_EXPR, CTRUMP_STMT_FOR, CTRUMP_STMT_FOR_DECL, CTRUMP_STMT_GOTO, CTRUMP_STMT_IF, CTRUMP_STMT_IF_ELSE, CTRUMP_STMT_IFDEF, CTRUMP_STMT_LABELED, CTRUMP_STMT_LIST, CTRUMP_STMT_NEWLINE, CTRUMP_STMT_PRAGMA, CTRUMP_STMT_RETURN, CTRUMP_STMT_RETURN_EXPR, CTRUMP_STMT_SLAAST_COMMENT, CTRUMP_STMT_SLASLA_COMMENT, CTRUMP_STMT_SWITCH, CTRUMP_STMT_UNDEF, CTRUMP_STMT_WHILE, ctrump_unreachable, ctrump_stmt::default_, ctrump_stmt::do_while, ctrump_if_else_stmt::else_body, ctrump_stmt::for_, ctrump_stmt::for_decl, ctrump_stmt::if_, ctrump_stmt::if_else, ctrump_while_stmt::kwd_loc, ctrump_for_decl_stmt::kwd_loc, ctrump_for_stmt::kwd_loc, ctrump_stmt::labeled, ctrump_while_stmt::loop_cfg, ctrump_for_decl_stmt::loop_cfg, ctrump_for_stmt::loop_cfg, ctrump_default_stmt::stmt, ctrump_case_stmt::stmt, ctrump_labeled_stmt::stmt, ctrump_stmt::switch_, ctrump_if_else_stmt::then_body, ctrump_stmt::u, and ctrump_stmt::while_.
Referenced by analyze_loop_control_flow(), and build_loop_tree_compound_stmt().
static int analyze_loop_control_flow | ( | struct build_loop_tree_state * | st, | |
struct ctrump_loop_cfg_info * | attr, | |||
struct ctrump_cfg * | cfg, | |||
struct ctrump_stmt * | loop_body, | |||
struct ctrump_location * | loc, | |||
struct analyze_allocator * | alloc | |||
) | [static] |
Definition at line 249 of file analyze.c.
References analyze_control_flow(), append_root(), ctrump_loop_info_node::cfg_info, ctrump_loop_info_node::children, build_loop_tree_state::children, ctrump_loop_cfg_info::code, ctrump_loop_cfg_info::complicated, CTRUMP_LOOP_COMPLICATED, ctrump_mempool_alloc, ctrump_varray_copy(), destroy_build_loop_tree_state(), analyze_allocator::id, ctrump_loop_info_node::id, init_build_loop_tree_state(), ctrump_loop_info_node::loc, build_loop_tree_state::loop_tree_roots, ctrump_varray::nelem, ctrump_loop_info_node::nest_level, ctrump_loop_info_node::num_child, build_loop_tree_state::num_complicated, ctrump_loop_info_node::parent, analyze_allocator::pool, build_loop_tree_state::reason, ctrump_loop_cfg_info::u, VA_PUSH, and build_loop_tree_state::var_info_map.
Referenced by analyze_control_flow().
static void append_root | ( | struct ctrump_varray * | roots, | |
struct ctrump_varray * | new_roots | |||
) | [static] |
loop treeのルートを追加する
Definition at line 232 of file analyze.c.
References ctrump_loop_info_node::children, ctrump_varray::elements, ctrump_varray::nelem, and VA_PUSH.
Referenced by analyze_loop_control_flow(), and build_loop_tree_func().
static void build_loop_tree_compound_stmt | ( | struct build_loop_tree_state * | st, | |
struct ctrump_compound_stmt * | stmt, | |||
struct ctrump_cfg * | cfg, | |||
struct analyze_allocator * | alloc | |||
) | [static] |
Definition at line 95 of file analyze.c.
References analyze_control_flow(), ctrump_compound_stmt::items, and ctrump_compound_stmt::num_item.
Referenced by analyze_control_flow(), and build_loop_tree_func().
static void build_loop_tree_func | ( | struct ctrump_varray * | loops, | |
struct ctrump_fundef * | func, | |||
struct ctrump_cfg * | cfg, | |||
struct ctrump_intmap * | var_info_map, | |||
const struct ctrump_abi * | abi, | |||
struct analyze_allocator * | alloc | |||
) | [static] |
loop treeを作る
Definition at line 303 of file analyze.c.
References append_root(), ctrump_fundef::body, build_loop_tree_compound_stmt(), build_loop_tree_state::children, ctrump_analyze_loop(), ctrump_mempool_alloc, destroy_build_loop_tree_state(), ctrump_varray::elements, analyze_allocator::id, ctrump_loop_info::id, init_build_loop_tree_state(), ctrump_varray::nelem, ctrump_loop_info::nest_level, analyze_allocator::pool, and ctrump_loop_info::root.
Referenced by ctrump_analyze().
static void complicated_loop | ( | struct build_loop_tree_state * | st, | |
enum ctrump_complicated_loop_reason_code | code, | |||
struct ctrump_stmt * | stmt | |||
) | [static] |
Definition at line 109 of file analyze.c.
References build_loop_tree_state::num_complicated, ctrump_complicated_loop::reason, build_loop_tree_state::reason, and ctrump_complicated_loop::stmt.
Referenced by analyze_control_flow().
int ctrump_analyze | ( | struct ctrump_translation_unit * | unit, | |
const struct ctrump_abi * | abi, | |||
struct ctrump_mempool * | pool, | |||
struct ctrump_build_cfg_error * | error, | |||
int | num_ast, | |||
int | id_base | |||
) |
プログラムを解析する 解析結果は unit の指すツリーの中に反映される
Definition at line 335 of file analyze.c.
References build_loop_tree_func(), ctrump_fundef::cfg, ctrump_extdecl::code, ctrump_build_cfg(), CTRUMP_EXT_FUNCTION_DEFINITION, ctrump_mempool_alloc, ctrump_mempool_destroy(), ctrump_mempool_init(), ctrump_varray_copy(), ctrump_varray_discard(), ctrump_varray_init(), ctrump_translation_unit::decls, ctrump_extdecl::func_def, analyze_allocator::id, ctrump_cfg::id, ctrump_cfg::loop_tree_roots, ctrump_varray::nelem, ctrump_translation_unit::num_decl, ctrump_cfg::num_loop, analyze_allocator::pool, and ctrump_extdecl::u.
Referenced by cfront_parse().
static void destroy_build_loop_tree_state | ( | struct build_loop_tree_state * | st | ) | [static] |
Definition at line 77 of file analyze.c.
References build_loop_tree_state::children, and ctrump_varray_discard().
Referenced by analyze_loop_control_flow(), and build_loop_tree_func().
static void init_build_loop_tree_state | ( | struct build_loop_tree_state * | st, | |
struct ctrump_intmap * | var_info_map, | |||
struct ctrump_varray * | loops | |||
) | [static] |
Definition at line 65 of file analyze.c.
References build_loop_tree_state::children, ctrump_varray_init(), build_loop_tree_state::loop_tree_roots, build_loop_tree_state::num_complicated, and build_loop_tree_state::var_info_map.
Referenced by analyze_loop_control_flow(), and build_loop_tree_func().