diff --git a/.github/workflows/ci-all-samples.yml b/.github/workflows/ci-all-samples.yml index db49e33..432c8a6 100644 --- a/.github/workflows/ci-all-samples.yml +++ b/.github/workflows/ci-all-samples.yml @@ -33,3 +33,4 @@ jobs: uses: actions/checkout@v2 - run: make -C ${{ github.workspace }} -j$(sysctl -n hw.physicalcpu) run - run: echo "Tests completed" + diff --git a/include/blocks/c_code_generator.h b/include/blocks/c_code_generator.h index cc215a1..056452e 100644 --- a/include/blocks/c_code_generator.h +++ b/include/blocks/c_code_generator.h @@ -8,10 +8,11 @@ #include "blocks/block_visitor.h" #include "blocks/stmt.h" -#include "builder/dyn_var.h" #include "util/printer.h" #include #include +#include "builder/forward_declarations.h" +#include "builder/providers_dyn_var.h" namespace block { class c_code_generator : public block_visitor { @@ -116,11 +117,11 @@ class c_code_generator : public block_visitor { } template static void generate_struct_decl(std::ostream &oss, int indent = 0) { - static_assert(std::is_base_of::value, "Template argument should be a dyn_var"); - auto save = builder::options::track_members; - builder::options::track_members = true; + static_assert(builder::is_dyn_var_type::value, "Template argument should be a dyn_var"); + auto save = builder::user_defined_provider_track_members; + builder::user_defined_provider_track_members = true; T v = builder::with_name("_"); - builder::options::track_members = save; + builder::user_defined_provider_track_members = save; // Construct a struct decl auto sd = std::make_shared(); @@ -130,9 +131,9 @@ class c_code_generator : public block_visitor { "Cannot yet, generate decls for types with template args"); sd->struct_name = to(var_type)->type_name; - for (auto member: v.members) { + for (auto member: v.user_defined_members) { auto decl = std::make_shared(); - decl->decl_var = member->block_var; + decl->decl_var = member; decl->init_expr = nullptr; sd->members.push_back(decl); } diff --git a/include/builder/arena_dyn_var.h b/include/builder/arena_dyn_var.h new file mode 100644 index 0000000..9c26713 --- /dev/null +++ b/include/builder/arena_dyn_var.h @@ -0,0 +1,129 @@ +#ifndef ARENA_DYN_VAR_H +#define ARENA_DYN_VAR_H +#include + +namespace builder { + +using byte_t = unsigned char; +struct arena_list { + std::vector chunks; + size_t used_objects = 0; +}; + +constexpr const int arena_objects_per_chunk = 64; + +// Registry type for types that are allocatable +// Each global construct call assigns a unique id to each type +struct allocatable_type_registry { + // Declaration for unique counter, definition is in cpp + static int type_counter; + + // A function that can destroy a list of objects of a type + using deleter_t = void(*)(arena_list*); + + // This has to be a pointer because we cannot guarantee order of invocation of constructors + static std::vector *type_deleters; + + int type_id; + + // Grab an ID and increment + allocatable_type_registry(deleter_t deleter) { + if (type_deleters == nullptr) { + type_deleters = new std::vector(); + } + type_deleters->push_back(deleter); + type_id = type_counter; + type_counter++; + } + + // Post global constructor, this returns the maximum + // type id. Make sure this is ONLY called from main + static int get_max_type_id(void) { + return type_counter; + } +}; + +// This type is instantiated for each +// type that is allocated in the whole binary +template +struct allocatable_type_manager { + static allocatable_type_registry register_type; + static void delete_objects(arena_list *list) { + for (size_t i = 0; i < list->used_objects; i++) { + int chunk_id = i / arena_objects_per_chunk; + int chunk_offset = i % arena_objects_per_chunk; + + auto ptr_b = list->chunks[chunk_id] + sizeof(T) * chunk_offset; + auto ptr = (T*)ptr_b; + ptr->~T(); + } + list->used_objects = 0; + } +}; + +template +allocatable_type_registry allocatable_type_manager::register_type(allocatable_type_manager::delete_objects); + +class dyn_var_arena { + // Arena contains a separate list for each type + // indexed by a generated type id + std::vector arena_lists; + + template + byte_t* grab_buffer() { + // Get arena list index for this type + int index = allocatable_type_manager::register_type.type_id; + arena_list& list = arena_lists[index]; + // If list is full add another chunk + if (list.used_objects == list.chunks.size() * arena_objects_per_chunk) { + // Alignment and pointer and the end + static_assert(alignof(T) <= alignof(std::max_align_t), + "Allocated type has higher alignment requirement that std::max_align_t" + "needs manual alignment"); + byte_t* new_chunk = new byte_t[sizeof(T) * arena_objects_per_chunk]; + list.chunks.push_back(new_chunk); + } + int chunk_id = list.used_objects / arena_objects_per_chunk; + int chunk_offset = list.used_objects % arena_objects_per_chunk; + + auto ptr = list.chunks[chunk_id] + sizeof(T) * chunk_offset; + list.used_objects++; + return ptr; + } + +public: + + dyn_var_arena() { + arena_lists.resize(allocatable_type_registry::get_max_type_id()); + } + + template + T* allocate(Args&&...args) { + auto ptr_b = grab_buffer(); + auto ptr = new (ptr_b) T(std::forward(args)...); + return ptr; + } + + + void reset_arena(void) { + // For each type call the respective deleters on the type + for (unsigned int i = 0; i < arena_lists.size(); i++) { + if (arena_lists[i].used_objects > 0) { + (*allocatable_type_registry::type_deleters)[i](&(arena_lists[i])); + } + } + } + + ~dyn_var_arena() { + reset_arena(); + for (auto& a: arena_lists) { + for (auto c: a.chunks) { + delete[] c; + } + } + } +}; + +} + +#endif diff --git a/include/builder/array.h b/include/builder/array.h index fc00ddf..7e52b5b 100644 --- a/include/builder/array.h +++ b/include/builder/array.h @@ -5,10 +5,8 @@ namespace builder { - -// If the array is of dyn_vars, we initialize with a -// builder, anything else and we directly initialize with T -// This avoids unnecessary copies unless entirely necessary +// This helper avoids unnecessary copies for +// dyn_var objects template struct initializer_selector { typedef const T type; @@ -16,11 +14,9 @@ struct initializer_selector { template struct initializer_selector> { - typedef builder type; + typedef expr_wrapper type; }; - - template class array { private: diff --git a/include/builder/block_type_extractor.h b/include/builder/block_type_extractor.h index c1c2543..a1d5b6f 100644 --- a/include/builder/block_type_extractor.h +++ b/include/builder/block_type_extractor.h @@ -1,15 +1,12 @@ #ifndef TYPE_EXTRACTOR_H #define TYPE_EXTRACTOR_H - #include "builder/forward_declarations.h" #include "util/mtp_utils.h" -#include "builder/generics.h" #include namespace builder { -struct custom_type_base; template struct external_type_namer; @@ -83,10 +80,8 @@ template class type_extractor { public: // This implementation is currenty only used - // by custom types which are derived from custom_type_base + // by custom types which are derived from custom_type static block::type::Ptr extract_type(void) { - //static_assert(std::is_base_of::value, - //"Custom types should inherit from builder::custom_type_base"); block::named_type::Ptr type = std::make_shared(); type->type_name = type_namer::get_type_name(); type->template_args = type_template::get_templates(); @@ -345,34 +340,13 @@ class type_extractor { }; - -// Extracting function types -template -std::vector extract_type_vector_dyn(void); - -template -std::vector extract_type_vector_helper_dyn(void) { - std::vector rest = extract_type_vector_dyn(); - rest.push_back(type_extractor::extract_type()); - return rest; -} - -template -std::vector extract_type_vector_dyn(void) { - return extract_type_vector_helper_dyn(); -} - -template <> -std::vector extract_type_vector_dyn<>(void); - template class type_extractor { public: static block::type::Ptr extract_type(void) { block::function_type::Ptr type = std::make_shared(); type->return_type = type_extractor::extract_type(); - type->arg_types = extract_type_vector_dyn(); - std::reverse(type->arg_types.begin(), type->arg_types.end()); + type->arg_types = std::vector({type_extractor::extract_type()...}); return type; } }; @@ -380,32 +354,13 @@ class type_extractor { template struct name {}; -template -struct extract_type_from_args; - -template -struct extract_type_from_args { - static std::vector get_types() { - auto a = extract_type_from_args::get_types(); - a.insert(a.begin(), type_extractor::extract_type()); - return a; - } -}; - -template <> -struct extract_type_from_args<> { - static std::vector get_types() { - return std::vector(); - } -}; - template class type_extractor> { public: static block::type::Ptr extract_type(void) { block::named_type::Ptr type = std::make_shared(); type->type_name = N; - type->template_args = extract_type_from_args::get_types(); + type->template_args = {type_extractor::extract_type()...}; return type; } }; diff --git a/include/builder/builder.h b/include/builder/builder.h deleted file mode 100644 index 73ede01..0000000 --- a/include/builder/builder.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef BUILDER_H -#define BUILDER_H -#include "builder/builder_base.h" -#include "builder/operator_overload.h" - -namespace builder { - - -} // namespace builder - -#endif diff --git a/include/builder/builder_base.h b/include/builder/builder_base.h deleted file mode 100644 index 8e13026..0000000 --- a/include/builder/builder_base.h +++ /dev/null @@ -1,315 +0,0 @@ -#ifndef BUILDER_BASE_H -#define BUILDER_BASE_H - -#include "builder/forward_declarations.h" - -#include "blocks/var.h" -#include "builder/block_type_extractor.h" -#include "builder/builder_context.h" -#include "builder/signature_extract.h" -#include -#include -#include -#include -#include - -namespace builder { - -// Builder objects are always alive only for duration of the RUN/SEQUENCE. -// Never store pointers to these objects (across runs) or heap allocate them. - -template -std::vector extract_call_arguments(const arg_types &...args); - -template -std::vector extract_call_arguments_helper(const arg_types &...args); - -class builder { - -public: - // All members here - block::expr::Ptr block_expr; - - // All the costructors and copy constructors to the top - // Simple constrcutor, should only be used inside the operator - // and set the block_expr immediately - builder() = default; - // Copy constructor from another builder - builder(const builder &other) { - block_expr = other.block_expr; - } - - static bool builder_precheck(void) { - return get_run_state()->is_catching_up(); - } - void builder_from_sequence(void) { - block_expr = get_run_state()->get_next_cached_expr(); - } - static builder create_builder_from_sequence(void) { - builder ret_builder; - ret_builder.builder_from_sequence(); - return ret_builder; - } - static void push_to_sequence(block::expr::Ptr a) { - get_run_state()->add_to_cached_expr(a); - } - builder(const unsigned int &a) : builder((int)a) {} - - builder(const int &a) { - if (builder_precheck()) { - builder_from_sequence(); - return; - } - - block::int_const::Ptr int_const = std::make_shared(); - tracer::tag offset = tracer::get_offset_in_function(); - int_const->static_offset = offset; - int_const->value = a; - int_const->is_64bit = false; - get_run_state()->add_node_to_sequence(int_const); - block_expr = int_const; - - push_to_sequence(block_expr); - } - builder(const unsigned long long &a) : builder((long long)a) {} - builder(const long long &a) { - if (builder_precheck()) { - builder_from_sequence(); - return; - } - - block::int_const::Ptr int_const = std::make_shared(); - tracer::tag offset = tracer::get_offset_in_function(); - int_const->static_offset = offset; - int_const->value = a; - int_const->is_64bit = true; - get_run_state()->add_node_to_sequence(int_const); - block_expr = int_const; - - push_to_sequence(block_expr); - } - - builder(const unsigned long &a): builder((unsigned long long)a){} - builder(const long &a): builder((long long)a){} - - builder(const double &a) { - if (builder_precheck()) { - builder_from_sequence(); - return; - } - - block::double_const::Ptr double_const = std::make_shared(); - tracer::tag offset = tracer::get_offset_in_function(); - double_const->static_offset = offset; - double_const->value = a; - get_run_state()->add_node_to_sequence(double_const); - block_expr = double_const; - - push_to_sequence(block_expr); - } - builder(const float &a) { - if (builder_precheck()) { - builder_from_sequence(); - return; - } - - block::float_const::Ptr float_const = std::make_shared(); - tracer::tag offset = tracer::get_offset_in_function(); - float_const->static_offset = offset; - float_const->value = a; - get_run_state()->add_node_to_sequence(float_const); - block_expr = float_const; - - push_to_sequence(block_expr); - } - builder(const bool &b) : builder((int)b) {} - builder(const char &c) : builder((int)c) {} - builder(unsigned char &c) : builder((int)c) {} - builder(const std::string &s) { - if (builder_precheck()) { - builder_from_sequence(); - return; - } - - block::string_const::Ptr string_const = std::make_shared(); - tracer::tag offset = tracer::get_offset_in_function(); - string_const->static_offset = offset; - string_const->value = s; - get_run_state()->add_node_to_sequence(string_const); - block_expr = string_const; - - push_to_sequence(block_expr); - } - builder(const char *s) : builder((std::string)s) {} - builder(char *s) : builder((std::string)s) {} - - // This is a template class declaration but requires access to var - // So this is defined after the var class definition - builder(const var &a); - - template - builder(const static_var &a) : builder((const T)a) {} - - // Other basic functions - template - builder builder_unary_op() const { - if (builder_precheck()) { - return create_builder_from_sequence(); - } - get_run_state()->remove_node_from_sequence(block_expr); - tracer::tag offset = tracer::get_offset_in_function(); - - typename T::Ptr expr = std::make_shared(); - expr->static_offset = offset; - expr->expr1 = block_expr; - get_run_state()->add_node_to_sequence(expr); - - builder ret_builder; - ret_builder.block_expr = expr; - push_to_sequence(expr); - return ret_builder; - } - - template - builder builder_binary_op(const builder &a) const { - if (builder_precheck()) { - return create_builder_from_sequence(); - } - get_run_state()->remove_node_from_sequence(block_expr); - get_run_state()->remove_node_from_sequence(a.block_expr); - - tracer::tag offset = tracer::get_offset_in_function(); - - typename T::Ptr expr = std::make_shared(); - expr->static_offset = offset; - - expr->expr1 = block_expr; - expr->expr2 = a.block_expr; - - get_run_state()->add_node_to_sequence(expr); - - builder ret_builder; - ret_builder.block_expr = expr; - push_to_sequence(expr); - return ret_builder; - } - - builder operator[](const builder &a) { - if (builder_precheck()) { - return create_builder_from_sequence(); - } - get_run_state()->remove_node_from_sequence(block_expr); - get_run_state()->remove_node_from_sequence(a.block_expr); - - tracer::tag offset = tracer::get_offset_in_function(); - // assert(offset != -1); - - block::sq_bkt_expr::Ptr expr = std::make_shared(); - expr->static_offset = offset; - - expr->var_expr = block_expr; - expr->index = a.block_expr; - - get_run_state()->add_node_to_sequence(expr); - - builder ret_builder; - ret_builder.block_expr = expr; - push_to_sequence(expr); - return ret_builder; - } - builder operator*(void) { - auto b = (*this)[0]; - b.block_expr->template setMetadata("deref_is_star", true); - return b; - } - - builder assign(const builder &a) { - if (builder_precheck()) { - return create_builder_from_sequence(); - } - - get_run_state()->remove_node_from_sequence(block_expr); - get_run_state()->remove_node_from_sequence(a.block_expr); - tracer::tag offset = tracer::get_offset_in_function(); - - block::assign_expr::Ptr expr = std::make_shared(); - expr->static_offset = offset; - - expr->var1 = block_expr; - expr->expr1 = a.block_expr; - - get_run_state()->add_node_to_sequence(expr); - - builder ret_builder; - ret_builder.block_expr = expr; - push_to_sequence(expr); - return ret_builder; - } - builder operator=(const builder &a) { - return assign(a); - } - - explicit operator bool() { - get_run_state()->commit_uncommitted(); - return get_run_state()->get_next_bool(block_expr); - } - - template - builder operator()(const arg_types &...args) { - if (builder_precheck()) { - return create_builder_from_sequence(); - } - - get_run_state()->remove_node_from_sequence(block_expr); - tracer::tag offset = tracer::get_offset_in_function(); - - block::function_call_expr::Ptr expr = std::make_shared(); - expr->static_offset = offset; - - expr->expr1 = block_expr; - expr->args = extract_call_arguments(args...); - std::reverse(expr->args.begin(), expr->args.end()); - get_run_state()->add_node_to_sequence(expr); - - builder ret_builder; - ret_builder.block_expr = expr; - push_to_sequence(expr); - return ret_builder; - } - -}; - -void annotate(std::string); - -void create_return_stmt(const builder &a); - -// Helper function for the implementation of () operator on builder -template -std::vector extract_call_arguments_helper(void) { - std::vector empty_vector; - return empty_vector; -} - -template -typename std::enable_if::value && !std::is_same::value, - std::vector>::type -extract_call_arguments_helper(const T &first_arg, const arg_types &...rest_args) { - return extract_call_arguments_helper((BT)first_arg, rest_args...); -} - -template -std::vector extract_call_arguments_helper(const BT &first_arg, const arg_types &...rest_args) { - get_run_state()->remove_node_from_sequence(first_arg.block_expr); - - std::vector rest = extract_call_arguments_helper(rest_args...); - rest.push_back(first_arg.block_expr); - return rest; -} - -template -std::vector extract_call_arguments(const arg_types &...args) { - return extract_call_arguments_helper(args...); -} - -} // namespace builder -#endif diff --git a/include/builder/builder_context.h b/include/builder/builder_context.h index aa13dff..84bd66e 100644 --- a/include/builder/builder_context.h +++ b/include/builder/builder_context.h @@ -57,6 +57,7 @@ class builder_context { }; + } // namespace builder diff --git a/include/builder/builder_union.h b/include/builder/builder_union.h index 91fd10d..f19053e 100644 --- a/include/builder/builder_union.h +++ b/include/builder/builder_union.h @@ -6,49 +6,6 @@ namespace builder { template class builder_union { public: - enum class type_t { - STATIC_VAR, - DYN_VAR, - BUILDER, - - UNDECIDED, - }; - - type_t current_type; - - static_var *wrapped_static_var = nullptr; - dyn_var *wrapped_dyn_var = nullptr; - - builder *wrapped_builder = nullptr; - - ~builder_union() { - if (current_type == type_t::STATIC_VAR) { - delete wrapped_static_var; - } else if (current_type == type_t::DYN_VAR) { - delete wrapped_dyn_var; - } - } - - builder_union(const T &val) { - current_type = type_t::STATIC_VAR; - wrapped_static_var = new static_var(); - *wrapped_static_var = val; - } - builder_union(const builder &val) { - current_type = type_t::DYN_VAR; - wrapped_dyn_var = new dyn_var(val); - } - builder_union(const builder_union &val) { - current_type = val.current_type; - if (current_type == type_t::STATIC_VAR) { - wrapped_static_var = new static_var(); - *wrapped_static_var = *(val.wrapped_static_var); - } - } - builder_union() { - // Determine type on first assignment - current_type = type_t::UNDECIDED; - } }; } // namespace builder diff --git a/include/builder/dyn_var.h b/include/builder/dyn_var.h index 10fc4c6..fdbe45d 100644 --- a/include/builder/dyn_var.h +++ b/include/builder/dyn_var.h @@ -1,360 +1,331 @@ #ifndef BUILDER_DYN_VAR_H #define BUILDER_DYN_VAR_H -#include "builder/builder.h" +#include "builder/block_type_extractor.h" +#include "builder/run_states.h" +#include "builder/to_expr.h" +#include "builder/providers_dyn_var.h" +#include "builder/operator_overload.h" #include "util/var_finder.h" -#include "util/mtp_utils.h" -namespace builder { -namespace options { -extern bool track_members; +namespace block { +// Forward declaring this class for friend +class c_code_generator; } -class var { -public: - enum var_state { +namespace builder { + + +// Top level class forward declaration +template +class dyn_var; + +// Non-typed base class for all dyn_vars +class dyn_var_base { +protected: + // All members are part of the base class + // so operations can be done without knowing the + // derived type + enum dyn_var_mode { standalone_var, member_var, compound_expr, - }; + } var_mode; - var_state current_state = standalone_var; - - // Optional var name - std::string var_name; block::var::Ptr block_var; block::decl_stmt::Ptr block_decl_stmt; - - // Feature to implement members - var *parent_var; - - // Feature to implement vars as complex expressions - // This is require when casting a compound_expr to a - // type derived from dyn_var, mainly for using members - // Avoid using this unless really required - block::expr::Ptr encompassing_expr; - - // Feature to gather members of this type - std::vector members; - // Counter for naming unnamed members + dyn_var_base* parent_var; + std::string member_name; + block::expr::Ptr block_expr; + // Required for custom types + std::vector user_defined_members; int member_counter = 0; - static block::type::Ptr create_block_type(void) { - // Cannot create block type for abstract class - assert(false); - } - - var() = default; - - explicit operator bool(); +public: + // Member functions user can call + void set_type(type t); - // This is for enabling dynamic inheritance - virtual ~var() = default; -}; +public: + ~dyn_var_base() = default; + friend block::expr::Ptr to_expr(const dyn_var_base& d); + + // These friend declarations + // are added to different T can access each others + // members + template + friend class dyn_var_impl; + + template + friend class dyn_var; -struct custom_type_base { - static std::vector get_template_arg_types() { - return extract_type_from_args<>::get_types(); - } -}; + template + friend void resize_arr(const dyn_var &x, int size); -template -struct custom_type : custom_type_base { - static std::vector get_template_arg_types() { - return extract_type_from_args::get_types(); - } -}; + friend type type_of(const dyn_var_base& v); -extern std::vector *parents_stack; + template + friend typename std::enable_if::value>::type + copy_types_provider(dyn_var_impl&, const TO&); -// Struct to initialize a dyn_var as member; -struct as_member { - var *parent_var; - std::string member_name; - // This constructor is to be used if the user prefers to define a specialization for - // dyn_var. In this case they do not inherit from custom_type_base - as_member(var *p, std::string n) : parent_var(p), member_name(n){}; - as_member(std::string n) : parent_var(parents_stack->back()), member_name(n) {} -}; -// Struct to initialize a dyn_var as a compound expr -struct as_compound_expr { - block::expr::Ptr encompassing_expr; - as_compound_expr(const builder &b) : encompassing_expr(b.block_expr) {} + friend class block::c_code_generator; }; -using cast = as_compound_expr; +// The dyn_var_impl class has all the implementation +// But still uses dyn_var internally, this way dyn_var doesn't +// have to implement stuff differently template -class dyn_var_impl : public var { -public: - typedef dyn_var_impl self_type; - typedef T stored_type; - - - template - builder operator()(const types &...args) const { - return ((builder) * this)(args...); - } - - // These three need to be defined inside the class, cannot be defined globally - builder operator[](const builder &a) const { - return ((builder) * this)[a]; - } - builder operator*(void) const { - return *((builder) * this); - } - builder operator!() const { - return !(builder) * this; - } - operator bool() const { - return (bool)(builder) * this; - } - - // Unified operator= that offloads implementation to builder - template - builder operator=(const X& a) { - return ((builder)*this) = ((builder)a); - } - - - static block::type::Ptr create_block_type(void) { - return type_extractor::extract_type(); - } - - void create_dyn_var(bool create_without_context = false) { - if (create_without_context) { - block::var::Ptr dyn_var = std::make_shared(); - dyn_var->var_type = create_block_type(); - block_var = dyn_var; - // Don't try to obtain preferred names for objects created without context - // dyn_var->preferred_name = utils::find_variable_name(this); - return; +class dyn_var_impl: public dyn_var_base { + +private: + // Helper functions that depend on the type + tracer::tag create_block_var(std::string vname = "", dyn_var_base* supplied_parent = nullptr) { + block_var = std::make_shared(); + block_var->var_type = type_extractor::extract_type(); + if (parents_stack && parents_stack->size() != 0 && supplied_parent == nullptr) { + supplied_parent = parents_stack->back(); } - get_run_state()->commit_uncommitted(); - block::var::Ptr dyn_var = std::make_shared(); - dyn_var->var_type = create_block_type(); - tracer::tag offset = tracer::get_offset_in_function(); - // push this tag into the live_dyn_vars set - get_run_state()->insert_live_dyn_var(offset); - dyn_var->preferred_name = utils::find_variable_name_cached(this, offset); - block_var = dyn_var; - dyn_var->static_offset = offset; - block_decl_stmt = nullptr; - if (get_run_state()->is_catching_up()) - return; - block::decl_stmt::Ptr decl_stmt = std::make_shared(); - decl_stmt->static_offset = offset; - decl_stmt->decl_var = dyn_var; - decl_stmt->init_expr = nullptr; - block_decl_stmt = decl_stmt; - get_run_state()->add_stmt_to_current_block(decl_stmt, true); - } - dyn_var_impl() { - // implementation for auto member detection - if (parents_stack && parents_stack->size() != 0) { - current_state = member_var; - parent_var = parents_stack->back(); - var_name = "mem" + std::to_string(parent_var->member_counter++); + // First check if this variable is being created as a member + if (supplied_parent) { + var_mode = member_var; + parent_var = supplied_parent; + if (vname == "") { + member_name = "mem" + std::to_string(parent_var->member_counter++); + } else { + member_name = vname; + } + if (user_defined_provider_track_members) { + // Record the block var, record it + // and then discard + block_var->var_name = member_name; + parent_var->user_defined_members.push_back(block_var); + } + // Discard the created block_var block_var = nullptr; - block_decl_stmt = nullptr; - - if (options::track_members) { - parent_var->members.push_back(this); - block_var = std::make_shared(); - block_var->var_type = create_block_type(); - block_var->var_name = var_name; - } - return; - } - create_dyn_var(false); - } - // Basic and other constructors - dyn_var_impl(const as_global &v) { - if (!is_under_run()) { - create_dyn_var(true); - block_var->var_name = v.name; - var_name = v.name; } else { - create_dyn_var(false); - block_var->var_name = v.name; - var_name = v.name; + block_var->var_name = vname; + var_mode = standalone_var; } - // Now that we have created the block_var, we need to leak a reference - // So that the destructor for the block_var is never called - auto ptr_to_leak = new std::shared_ptr(); - *ptr_to_leak = block_var; - } - dyn_var_impl(const with_name &v) { - if (parents_stack && parents_stack->size() != 0) { - current_state = member_var; - parent_var = parents_stack->back(); - var_name = v.name; - block_var = nullptr; - block_decl_stmt = nullptr; - - if (options::track_members) { - parent_var->members.push_back(this); - block_var = std::make_shared(); - block_var->var_type = create_block_type(); - block_var->var_name = var_name; - } - return; + + if (is_under_run() && block_var) { + // If a variable is created outside of a run, + // it doesn't need a static tag + tracer::tag offset = tracer::get_offset_in_function(); + get_run_state()->insert_live_dyn_var(offset); + block_var->static_offset = offset; + block_var->preferred_name = utils::find_variable_name_cached(this, offset); + return offset; + } else { + // Else return an empty tag + return tracer::tag(); } - // with_name constructors don't usually get declarations - create_dyn_var(!v.with_decl); - block_var->var_name = v.name; - block_var->preferred_name = ""; - var_name = v.name; } - dyn_var_impl(const with_block_var& v) { - create_dyn_var(!v.with_decl); - // Swap out the variable - block_var = v.var; - var_name = v.var->var_name; - // If a declaration was created, swap out the var too - if (v.with_decl) { - block_decl_stmt->decl_var = v.var; + void create_var_decl_stmt(block::expr::Ptr init_expr, tracer::tag t) { + // Create a decl only if under run + // Sometimes standalone variables can be created at a global scope + if (!is_under_run()) { + return; + } + // If variable isn't a standalone var, don't create a decl + if (var_mode != standalone_var) + return; + // Remove the init_expr from the sequence before committing + // so the annotations aren't added to the sub expr + if (init_expr != nullptr) { + get_run_state()->remove_node_from_sequence(init_expr); } + get_run_state()->commit_uncommitted(); + // decl statements are only valid for standalone vars + auto ds = std::make_shared(); + // Use the tag supplied, not the one from the block var, they could be different + ds->static_offset = t; + ds->decl_var = block_var; + ds->init_expr = init_expr; + block_decl_stmt = ds; + get_run_state()->add_stmt_to_current_block(ds, true); + } + + void create_standalone(block::expr::Ptr init_expr = nullptr) { + auto t = create_block_var(); + create_var_decl_stmt(init_expr, t); + } + void move_from (const dyn_var_impl& other) { + var_mode = other.var_mode; + block_var = other.block_var; + block_decl_stmt = other.block_decl_stmt; + parent_var = other.parent_var; + block_expr = other.block_expr; + user_defined_members = other.user_defined_members; + member_counter = other.member_counter; } - - dyn_var_impl(const defer_init &) { - // Do nothing here - // Defer init "automatically" supports custom types - // because well, we don't create declarations anyway +public: + // An alias to help signature identifer + using stored_type = T; +public: + // General constructors and copy/move constructors + dyn_var_impl() { + create_standalone(); } - // The function to actually initialize a dyn_var, if it - // has been deferred. It is OKAY to call this even if defer_init - // is not used, but is not adviced. This can definitely be called multiple - // times and will produce the same dyn_var based on the static tag at the - // time of this call - // Currently we don't support init val, but can be added if needed - void deferred_init(void) { - create_dyn_var(false); + dyn_var_impl(const dyn_var_impl& other) { + create_standalone(to_expr(other)); + copy_types_provider(*this, other); } - // This version allows deferred init to accept other constructor helpers - void deferred_init(const with_name &v) { - create_dyn_var(!v.with_decl); - block_var->var_name = v.name; - block_var->preferred_name = ""; - var_name = v.name; + dyn_var_impl(dyn_var_impl&& other) { // Move constructor to simply steal resources + move_from(other); } - // Constructor to initialize a dyn_var as member - // This declaration does not produce a declaration - dyn_var_impl(const as_member &a) { - current_state = member_var; - parent_var = a.parent_var; - var_name = a.member_name; - block_var = nullptr; - block_decl_stmt = nullptr; - - if (options::track_members) { - parent_var->members.push_back(this); - block_var = std::make_shared(); - block_var->var_type = create_block_type(); - block_var->var_name = var_name; - } + // This constructor uses dyn_var on the RHS + // because it will never ever be dyn_var_impl + template + dyn_var_impl(const dyn_var& other) { + create_standalone(to_expr(other)); + copy_types_provider(*this, other); } - // Constructor and operator = to initialize a dyn_var as a compound expr - // This declaration also does not produce a declaration or assign stmt - dyn_var_impl(const as_compound_expr &a) { - current_state = compound_expr; - parent_var = nullptr; - block_var = nullptr; - block_decl_stmt = nullptr; - encompassing_expr = a.encompassing_expr; + template + dyn_var_impl(dyn_var_impl&& other) = delete; + + // A general constructor to initialize from any other type + // TODO: Add check to make sure to_expr exists for the type + template + dyn_var_impl(const TO& other) { + create_standalone(to_expr(other)); } - void operator=(const as_compound_expr &a) { - current_state = compound_expr; - parent_var = nullptr; - block_var = nullptr; - block_decl_stmt = nullptr; - encompassing_expr = a.encompassing_expr; + // An std initializer list type can never be deduced, so we + // need a special constructor for it + dyn_var_impl(const std::initializer_list& other) { + create_standalone(to_expr(other)); } - dyn_var_impl(const builder &a) { - get_run_state()->remove_node_from_sequence(a.block_expr); - create_dyn_var(); - if (get_run_state()->is_catching_up()) - return; - block_decl_stmt->init_expr = a.block_expr; + // Constructor for creating compound expressions + template ::value>::type> + dyn_var_impl(std::shared_ptr e) { + var_mode = compound_expr; + block_expr = e; } - template - struct is_builder_constructible { - // TODO: Add more checks to is_base_of to - // make sure it is wrapping a type that is builder_constructible - // We could just check if a conversion to (builder) exists - static const bool value = std::is_arithmetic::value - || std::is_base_of::value || std::is_base_of::value; - }; - - template - dyn_var_impl(const TO& a, typename std::enable_if::value>::type* _ = NULL) - : self_type((builder)a) {} - - dyn_var_impl(const std::string &a) : self_type((builder)a) {} - dyn_var_impl(const char *s) : self_type((builder)(std::string)s) {} - dyn_var_impl(char *s) : self_type((builder)(std::string)s) {} + // Special constructors with tags + dyn_var_impl(const defer_init& ) { + // Defer, everything + } - void from_builder_vector(std::vector a) { - auto r_state = get_run_state(); - for (unsigned int i = 0; i < a.size(); i++) { - r_state->remove_node_from_sequence(a[i].block_expr); - } - create_dyn_var(); - if (builder::builder_precheck()) { - builder bt = builder::create_builder_from_sequence(); - if (block_decl_stmt) - block_decl_stmt->init_expr = bt.block_expr; - return; + dyn_var_impl(const with_name& wn) { + auto t = create_block_var(wn.name); + if (wn.with_decl) { + create_var_decl_stmt(nullptr, t); + block_var->preferred_name = ""; } - tracer::tag offset = tracer::get_offset_in_function(); - block::initializer_list_expr::Ptr list_expr = std::make_shared(); - list_expr->static_offset = offset; - for (unsigned int i = 0; i < a.size(); i++) { - list_expr->elems.push_back(a[i].block_expr); + } + dyn_var_impl(const with_block_var& bv) { + block_var = bv.var; + var_mode = standalone_var; + if (bv.with_decl) { + // If a decl is created, it will use the above block var + create_var_decl_stmt(nullptr, block_var->static_offset); } - block_decl_stmt->init_expr = list_expr; - builder::push_to_sequence(list_expr); } - - dyn_var_impl(const std::initializer_list &_a) { - std::vector a(_a); - from_builder_vector(a); + // Explicit as_member initialization + dyn_var_impl(const as_member& am) { + // No special logic since create_block_var + // handles this automatically + create_block_var(am.member_name, am.parent_var); } + // The with_type constructor is defined is generics + dyn_var_impl(const with_type&); + + // Operators that need to be defined inside the class + // Notice that the return type is still dyn_var, not impl + dyn_var& operator= (const dyn_var_impl& other) { + auto e1 = to_expr(*this); + auto e2 = to_expr(other); + auto e = create_expr({e1, e2}); + e->var1 = e1; + e->expr1 = e2; + return *get_invocation_state()->get_arena()->allocate>(e); + } template - dyn_var_impl(const std::vector &_a, - typename std::enable_if::value>::type*_ = NULL ) { - - std::vector a; - // Create builder nodes for each elements, they would be pushed to sequence - // AND to the uncommitted list - for (auto i: _a) { - a.emplace_back(i); - } - from_builder_vector(a); + dyn_var& operator= (const TO& other) { + auto e1 = to_expr(*this); + auto e2 = to_expr(other); + auto e = create_expr({e1, e2}); + e->var1 = e1; + e->expr1 = e2; + return *get_invocation_state()->get_arena()->allocate>(e); + } + + // Use a dummy copy of T to defer the SFINAE check + // till the operator is actually instantiated + template + dyn_var>& operator[] (const TO& other) { + using RetType = dyn_var>; + auto e1 = to_expr(*this); + auto e2 = to_expr(other); + auto e = create_expr({e1, e2}); + e->var_expr = e1; + e->index = e2; + return *get_invocation_state()->get_arena()->allocate(e); + } + + // Unary * operator also uses the same provider + template + dyn_var>& operator* (void) { + auto& ret = operator[](0); + block::expr::Ptr be = ret.block_expr; + be->setMetadata("deref_is_star", true); + return ret; + } + + + // Operator -> also uses the same type, except the return type is a ptr + // not an lvalue reference + template + dyn_var>* operator -> (void) { + auto &ret = operator*(); + return ret.addr(); + } + + template + dyn_var>& operator() (const Args&...args) { + using RetType = dyn_var>; + auto e1 = to_expr(*this); + std::vector argv = {to_expr(args)...}; + auto args_copy = argv; + args_copy.push_back(e1); + auto e = create_expr(args_copy); + e->expr1 = e1; + e->args = std::move(argv); + return *get_invocation_state()->get_arena()->allocate(e); } - virtual ~dyn_var_impl() { + + // Bool conversion operator for branching + explicit operator bool (void) const { + get_run_state()->commit_uncommitted(); + return get_run_state()->get_next_bool(to_expr(*this)); + } +public: + // Destructor for removing variable from live vars + ~dyn_var_impl() { if (block_var && is_under_run()) { get_run_state()->remove_live_dyn_var(block_var->static_offset); } } +public: + // Public functions for users to call + // addr function to get the real address + dyn_var* addr(void) { + return static_cast*>(this); + } - // Assume that _impl objects will never be created - // Thus addr can always cast the address to dyn_var - dyn_var *addr(void) { - // TODO: Consider using dynamic_cast here - return (dyn_var *)this; + void deferred_init(void) { + create_standalone(); } - const dyn_var *addr(void) const { - // TODO: Consider using dynamic_cast here - return (const dyn_var *)this; + // A second deferred init to handle any existing constructors + template + void deferred_init(const TO& other) { + move_from(dyn_var_impl(other)); } - void add_attribute(std::string s) { std::vector attrs; if (block_var->hasMetadata>("attributes")) { @@ -365,224 +336,35 @@ class dyn_var_impl : public var { } block_var->setMetadata>("attributes", attrs); } -}; - -template -struct dyn_var_parent_selector { - // This base class is just empty -}; - -template -struct member_initializer_begin { - member_initializer_begin() { - if (parents_stack == nullptr) { - parents_stack = new std::vector(); - } - parents_stack->push_back(static_cast(static_cast *>(this))); - } -}; - -struct member_initializer_end { - member_initializer_end() { - parents_stack->pop_back(); - } -}; - -template -struct dyn_var_parent_selector::type>::value && !std::is_base_of::type>::value - && !std::is_base_of::type>::value - >::type> - : public member_initializer_begin, public std::remove_reference::type, public member_initializer_end {}; - - -template -class dyn_var_mimic; - - -// These helper classes provide implementation of the operator[] -// The return type is selected based on whether the T has a member called dereference_type defined -// if it is defined, the return is builder::cast'd to a dyn_var (mimic) of that type (just like *) -// otherwise a regular builder return implementation is provided -// This allows implementation of vector<> types with appropriate return types -template -struct dyn_var_deref_provider { - builder operator[] (const builder& b) { - return static_cast*>(this)->dyn_var_impl::operator[](b); - } -}; - -template -struct dyn_var_deref_provider::type> { - dyn_var_mimic operator[] (const builder& b) { - return (cast)(static_cast*>(this)->dyn_var_impl::operator[](b)); - } -}; - - - -// Actual dyn_var implementation -// Split design to allow for easily extending types with specialization -template -class dyn_var : public dyn_var_impl, public dyn_var_parent_selector, public dyn_var_deref_provider { public: - typedef dyn_var_impl super; - - using super::super; - using super::operator=; - - dyn_var() : dyn_var_impl() {} - - // Some implementations don't like implicitly declared - // constructors so define them here - dyn_var(const dyn_var &t) : dyn_var_impl((builder)t) {} - - // Since we are also defining a destructor, we should define a move constructor - dyn_var(dyn_var &&t): dyn_var_impl((builder)t) {} - - // Unfortunately because we are changing the return type, - // the implicitly defined copy assignment will always - // shadow the version the parent defines - builder operator=(const dyn_var &t) { - return *this = (builder)t; - } - - using dyn_var_deref_provider::operator[]; -}; - - -// dyn var specialization for pointer types to return the appropriate types on [], * and -> -template -class dyn_var_mimic: public dyn_var { - // Behaves exactly like a dyn_var for most purposes - // including accessign members - // But allows us to disable copy elision when required - // Currently only used when returning dyn_vars from [] and * operators -public: - typedef dyn_var super; - - using super::super; - using super::operator=; - builder operator=(const dyn_var_mimic &t) { - return *this = (builder)t; - } -}; - - -template -class dyn_var - : public dyn_var_impl { // No need for parent selector, pointers types aren't custom types by themselves -public: - typedef dyn_var_impl super; - using super::super; - using super::operator=; - - dyn_var() : dyn_var_impl() {} - - dyn_var(const dyn_var &t) : dyn_var_impl((builder)t) {} - - builder operator=(const dyn_var &t) { - return *this = (builder)t; - } - - // Specialization for the [] operator to return the right type - dyn_var_mimic operator[](const builder &bt) { - return (dyn_var_mimic)(cast)this->dyn_var_impl::operator[](bt); - } - dyn_var_mimic operator*() { - return (cast)(this->dyn_var_impl::operator*()); + // static helper functions associated with this dyn_var type + static block::type::Ptr create_block_type(void) { + return type_extractor::extract_type(); } - // Hack for creating a member that's live across return site - std::shared_ptr> _p = nullptr; - - dyn_var *operator->() { - auto b = this->operator[](0); - b.encompassing_expr->template setMetadata("deref_is_star", true); - if (_p == nullptr) { - _p = std::make_shared>(as_member(this, "_p")); - } - *_p = (cast)b; - return _p->addr(); - } -}; - - -struct with_type { - type t; - block::expr::Ptr init_expr; - with_type(const type& t): t(t), init_expr(nullptr) {} - with_type(const type& t, const builder &a): t(t), init_expr(a.block_expr) {} - with_type(const var& v): t(type_of(v)), init_expr(nullptr) { - builder a = v; - init_expr = a.block_expr; - } }; -// Specialization for dyn_var -template <> -class dyn_var: public dyn_var_impl { +// The actual dyn_var type is a simple struct with no new operations +// The user defined member provider is included here and not with the +// impl so the user can choose to not add them for their custom +// specializations +template +class dyn_var: public dyn_var_impl, public user_defined_member_provider { public: - typedef dyn_var_impl super; - using super::super; - using super::operator=; - - // default constructor and copy constructor - dyn_var() : dyn_var_impl() {} - - // Copy type if the initialization is just another variable - dyn_var(const dyn_var& t): dyn_var_impl((builder)t) { - block_var->var_type = t.block_var->var_type; - } - template - dyn_var(const dyn_var& t): dyn_var_impl((builder)t) { - block_var->var_type = t.block_var->var_type; - } - + using dyn_var_impl::dyn_var_impl; + using dyn_var_impl::operator=; + using dyn_var_impl::operator[]; + using dyn_var_impl::operator(); + using dyn_var_impl::operator bool; - // default copy assignment operator - builder operator=(const dyn_var& t) { - return *this = (builder) t; - } - - - void set_type(type t) { - block_var->var_type = t.enclosed_type; - } - dyn_var(const with_type& wt): dyn_var_impl(defer_init()) { - // We invoked the empty constructor from impl - // so we can manually construct here. This allows to properly - // handle init_expr - if (wt.init_expr) - get_run_state()->remove_node_from_sequence(wt.init_expr); - create_dyn_var(); - block_var->var_type = wt.t.enclosed_type; - if (block_decl_stmt) - block_decl_stmt->init_expr = wt.init_expr; + // Some constructors and operators that need to be defined + dyn_var(): dyn_var_impl() {} + dyn_var(const dyn_var& other): dyn_var_impl(other) {} + dyn_var& operator=(const dyn_var& other) { + return dyn_var_impl::operator=(other); } }; -template -typename std::enable_if::value>::type create_return_stmt(const T &a) { - create_return_stmt((builder)a); -} -template -dyn_var_mimic cast_to(const builder& x) { - if (builder::builder_precheck()) { - return builder::create_builder_from_sequence(); - } - get_run_state()->remove_node_from_sequence(x.block_expr); - tracer::tag offset = tracer::get_offset_in_function(); - auto ce = std::make_shared(); - ce->static_offset = offset; - ce->expr1 = x.block_expr; - ce->type1 = dyn_var::create_block_type(); - builder b; - b.block_expr = ce; - builder::push_to_sequence(ce); - return (cast)b; } -} // namespace builder #endif diff --git a/include/builder/forward_declarations.h b/include/builder/forward_declarations.h index 4690820..75b386b 100644 --- a/include/builder/forward_declarations.h +++ b/include/builder/forward_declarations.h @@ -2,36 +2,27 @@ #define BUILDER_FORWARD_DECLARATIONS_H #include "blocks/var.h" +#include "blocks/expr.h" #include namespace builder { -class builder_root; - -// The builder base class -class builder; +class static_var_base; template -using is_builder_type = typename std::is_same; +class static_var; template -using if_builder = typename std::enable_if::value, T>::type; +using is_static_var_type = std::is_base_of; -class static_var_base; - -template -class static_var; // The var classes declaration -class var; - -template -class dyn_var_impl; +class dyn_var_base; template class dyn_var; template -using is_dyn_var_type = std::is_base_of; +using is_dyn_var_type = std::is_base_of; template class type_extractor; @@ -42,28 +33,41 @@ class type_extractor; struct defer_init { // No members }; - - -// Constructor helpers for dyn_var -struct as_global { - std::string name; - as_global(const std::string &n) : name(n) {} -}; // With name is just like as_global but can be used locally struct with_name { std::string name; bool with_decl; with_name(const std::string &n, bool wd = false) : name(n), with_decl(wd) {} }; - +// With block var constructor helper to create a dyn_var with an existing block var +// currently used by signature extract struct with_block_var { block::var::Ptr var; bool with_decl; with_block_var(block::var::Ptr v, bool wd = false): var(v), with_decl(wd) {} }; +extern std::vector *parents_stack; +// Struct to initialize a dyn_var as member; +struct as_member { + dyn_var_base *parent_var; + std::string member_name; + // This constructor is to be used if the user prefers to define a specialization for + // dyn_var. In this case they do not inherit from custom_type + as_member(dyn_var_base *p, std::string n) : parent_var(p), member_name(n){}; + as_member(std::string n) : parent_var(parents_stack->back()), member_name(n) {} +}; + +class type; +class generic; +// with type is defined in generics +struct with_type; + // Generator states for non-deterministic values struct nd_var_gen_base; +// Helper functions called by users or otherwise +void annotate(std::string label); + } // namespace builder #endif diff --git a/include/builder/generics.h b/include/builder/generics.h index 68d64ea..f0fb02a 100644 --- a/include/builder/generics.h +++ b/include/builder/generics.h @@ -1,14 +1,67 @@ #ifndef BUILDER_GENERICS_H #define BUILDER_GENERICS_H + #include "blocks/var.h" +#include "builder/dyn_var.h" namespace builder { // TODO: Figure out if this needs to be wrapped into a generics sub namespace // Generic placeholder class to be passed inside dyn_var -class generic {}; +class generic { +public: + // Define the dereference_type to help the provider + using dereference_type = generic; +}; + +// For the generic type, declare all the operators so the types can be inferred for the wrapper +// We just have to declare but not define since the operators are only invoked in unevalauted contexts + +#define BINARY_OPERATOR(op) \ +template \ +generic operator op (const generic&, const T&); \ +template \ +generic operator op (const T&, generic&); \ +generic operator op (const generic&, const generic&); + +#define UNARY_OPERATOR(op) generic operator op (const generic&); +// Binary operators +// Arithmetic Operators +BINARY_OPERATOR(+) +BINARY_OPERATOR(-) +BINARY_OPERATOR(*) +BINARY_OPERATOR(/) +BINARY_OPERATOR(%) +// Relational Operators +BINARY_OPERATOR(==) +BINARY_OPERATOR(!=) +BINARY_OPERATOR(<) +BINARY_OPERATOR(>) +BINARY_OPERATOR(<=) +BINARY_OPERATOR(>=) +// Bitwise Operators +BINARY_OPERATOR(&) +BINARY_OPERATOR(|) +BINARY_OPERATOR(^) +BINARY_OPERATOR(<<) +BINARY_OPERATOR(>>) +// Logical Operators +BINARY_OPERATOR(&&) +BINARY_OPERATOR(||) +// Unary Operators +// Arithmetic Operators +UNARY_OPERATOR(-) +// Bitwise Operators +UNARY_OPERATOR(~) +// Logical Operators +UNARY_OPERATOR(!) +// Other Operators +UNARY_OPERATOR(&) + +#undef BINARY_OPERATOR +#undef UNARY_OPERATOR // An opaque handle over block::type // this also allows us to overload operators and helper functions @@ -26,13 +79,32 @@ class type { } }; +type type_of(const dyn_var_base& v); + +// With type constructor helper for dyn_var +struct with_type { + type t; + block::expr::Ptr init_expr; + with_type(const type& t): t(t), init_expr(nullptr) {} + template + with_type(const type& t, const T &a): t(t), init_expr(to_expr(a)) {} + with_type(const dyn_var_base& v): t(type_of(v)), init_expr(to_expr(v)) {} +}; + +template +dyn_var_impl::dyn_var_impl(const with_type& wt) { + create_standalone(wt.init_expr); + // Currently we are supporting generic only + // for standalone vars + assert(var_mode == standalone_var); + block_var->var_type = wt.t.enclosed_type; +} template type create_type(void) { - return type(dyn_var::create_block_type()); + return type(type_extractor::extract_type()); } -type type_of(const var& v); type array_of(const type &t, int size = -1); type remove_array(const type &t); diff --git a/include/builder/nd_var.h b/include/builder/nd_var.h index 5fa1f77..b194e77 100644 --- a/include/builder/nd_var.h +++ b/include/builder/nd_var.h @@ -1,7 +1,6 @@ #ifndef ND_VAR_H #define ND_VAR_H -#include "builder/builder.h" #include "builder/static_var.h" #include "util/tracer.h" #include "builder/exceptions.h" diff --git a/include/builder/operator_overload.h b/include/builder/operator_overload.h index 7c2d09c..d4e0ee8 100644 --- a/include/builder/operator_overload.h +++ b/include/builder/operator_overload.h @@ -1,226 +1,166 @@ #ifndef BUILDER_OPERATOR_OVERLOAD_H #define BUILDER_OPERATOR_OVERLOAD_H - -#include "builder/builder_base.h" - +#include "builder/to_expr.h" +#include namespace builder { -template -struct is_possible_builder { - constexpr static bool value = is_builder_type::value || is_dyn_var_type::value; +// We use T& and not T in declval so that operators +// that expect a lvalue like & also work +template +struct stripped { + static auto val(void) -> decltype(std::declval()); }; -template -struct return_type_helper {}; - -template -struct return_type_helper::value>::type> { - typedef T type; +template +struct stripped> { + static auto val(void) -> decltype(std::declval()); }; -template -struct return_type_helper::value && is_dyn_var_type::value>::type> { - typedef builder type; -}; - -template -struct allowed_builder_return {}; - -template -struct allowed_builder_return< - T1, T2, - typename std::enable_if::value && - std::is_convertible::type>::value>::type> - : return_type_helper {}; - -template -struct allowed_builder_return< - T1, T2, - typename std::enable_if::value && is_possible_builder::value && - std::is_convertible::type>::value>::type> - : return_type_helper {}; - -template -typename allowed_builder_return::type operator&&(const t1 &a, const t2 &b) { - typedef typename allowed_builder_return::type ret_type; - return ret_type(a).template builder_binary_op((ret_type)b); -} -template -typename allowed_builder_return::type operator&(const t1 &a, const t2 &b) { - typedef typename allowed_builder_return::type ret_type; - return ret_type(a).template builder_binary_op((ret_type)b); -} - -template -typename allowed_builder_return::type operator||(const T1 &a, const T2 &b) { - typedef typename allowed_builder_return::type ret_type; - return ret_type(a).template builder_binary_op((ret_type)b); -} -template -typename allowed_builder_return::type operator|(const T1 &a, const T2 &b) { - typedef typename allowed_builder_return::type ret_type; - return ret_type(a).template builder_binary_op((ret_type)b); -} -template -typename allowed_builder_return::type operator^(const T1 &a, const T2 &b) { - typedef typename allowed_builder_return::type ret_type; - return ret_type(a).template builder_binary_op((ret_type)b); -} - -template -typename allowed_builder_return::type operator+(const T1 &a, const T2 &b) { - typedef typename allowed_builder_return::type ret_type; - return ret_type(a).template builder_binary_op((ret_type)b); -} - -template -typename allowed_builder_return::type operator-(const T1 &a, const T2 &b) { - typedef typename allowed_builder_return::type ret_type; - return ret_type(a).template builder_binary_op((ret_type)b); -} - -template -typename allowed_builder_return::type operator*(const T1 &a, const T2 &b) { - typedef typename allowed_builder_return::type ret_type; - return ret_type(a).template builder_binary_op((ret_type)b); -} - -template -typename allowed_builder_return::type operator/(const T1 &a, const T2 &b) { - typedef typename allowed_builder_return::type ret_type; - return ret_type(a).template builder_binary_op((ret_type)b); -} - -template -typename allowed_builder_return::type operator<(const T1 &a, const T2 &b) { - typedef typename allowed_builder_return::type ret_type; - return ret_type(a).template builder_binary_op((ret_type)b); -} - -template -typename allowed_builder_return::type operator>(const T1 &a, const T2 &b) { - typedef typename allowed_builder_return::type ret_type; - return ret_type(a).template builder_binary_op((ret_type)b); -} - -template -typename allowed_builder_return::type operator<=(const T1 &a, const T2 &b) { - typedef typename allowed_builder_return::type ret_type; - return ret_type(a).template builder_binary_op((ret_type)b); -} - -template -typename allowed_builder_return::type operator>=(const T1 &a, const T2 &b) { - typedef typename allowed_builder_return::type ret_type; - return ret_type(a).template builder_binary_op((ret_type)b); -} template -typename allowed_builder_return::type operator<<(const T1 &a, const T2 &b) { - typedef typename allowed_builder_return::type ret_type; - return ret_type(a).template builder_binary_op((ret_type)b); -} - -template -typename allowed_builder_return::type operator>>(const T1 &a, const T2 &b) { - typedef typename allowed_builder_return::type ret_type; - return ret_type(a).template builder_binary_op((ret_type)b); -} +struct allowed_types{}; template -typename allowed_builder_return::type operator==(const T1 &a, const T2 &b) { - typedef typename allowed_builder_return::type ret_type; - return ret_type(a).template builder_binary_op((ret_type)b); -} - +struct allowed_types, dyn_var> { + using type = void; +}; template -typename allowed_builder_return::type operator!=(const T1 &a, const T2 &b) { - typedef typename allowed_builder_return::type ret_type; - return ret_type(a).template builder_binary_op((ret_type)b); -} - +struct allowed_types, T2> { + using type = void; +}; template -typename allowed_builder_return::type operator%(const T1 &a, const T2 &b) { - typedef typename allowed_builder_return::type ret_type; - return ret_type(a).template builder_binary_op((ret_type)b); -} - -// Unary operators -template -typename return_type_helper::type operator!(const T &a) { - typedef typename return_type_helper::type ret_type; - return ret_type(a).template builder_unary_op(); -} - -template -typename return_type_helper::type operator-(const T &a) { - typedef typename return_type_helper::type ret_type; - return ret_type(a).template builder_unary_op(); -} - -template -typename return_type_helper::type operator~(const T &a) { - typedef typename return_type_helper::type ret_type; - return ret_type(a).template builder_unary_op(); -} - -template -typename return_type_helper::type operator&(const T &a) { - typedef typename return_type_helper::type ret_type; - return ret_type(a).template builder_unary_op(); -} +struct allowed_types> { + using type = void; +}; -// Helper operators only! These do no produce any special block operators. +template +block::expr::Ptr binary_expr_helper(const T1& d1, const T2& d2) { + auto e1 = to_expr(d1); + auto e2 = to_expr(d2); + auto e = create_expr({e1, e2}); + e->expr1 = e1; + e->expr2 = e2; + return e; +} +template +block::expr::Ptr unary_expr_helper(const T1& d1) { + auto e1 = to_expr(d1); + auto e = create_expr({e1}); + e->expr1 = e1; + return e; +} + +#define BINARY_OPERATOR(op, op_class) \ +template ::type, \ + typename RetType = dyn_var::val() op stripped::val())>> \ +auto operator op (const T1& d1, const T2& d2) -> RetType& { \ + return *get_invocation_state()->get_arena()->allocate(binary_expr_helper(d1, d2)); \ +} + +// This uses declval and not stripped, because we don't want to strip too +// many layers if nested +#define UNARY_OPERATOR(op, op_class) \ +template ())>> \ +auto operator op (const dyn_var& d1) -> RetType& { \ + return *get_invocation_state()->get_arena()->allocate(unary_expr_helper(d1)); \ +} + +// Binary operators +// Arithmetic Operators +BINARY_OPERATOR(+, plus_expr) +BINARY_OPERATOR(-, minus_expr) +BINARY_OPERATOR(*, mul_expr) +BINARY_OPERATOR(/, div_expr) +BINARY_OPERATOR(%, mod_expr) +// Relational Operators +BINARY_OPERATOR(==, equals_expr) +BINARY_OPERATOR(!=, ne_expr) +BINARY_OPERATOR(<, lt_expr) +BINARY_OPERATOR(>, gt_expr) +BINARY_OPERATOR(<=, lte_expr) +BINARY_OPERATOR(>=, gte_expr) +// Bitwise Operators +BINARY_OPERATOR(&, bitwise_and_expr) +BINARY_OPERATOR(|, bitwise_or_expr) +BINARY_OPERATOR(^, bitwise_xor_expr) +BINARY_OPERATOR(<<, lshift_expr) +BINARY_OPERATOR(>>, rshift_expr) +// Logical Operators +BINARY_OPERATOR(&&, and_expr) +BINARY_OPERATOR(||, or_expr) + +// Unary Operators +// Arithmetic Operators +UNARY_OPERATOR(-, unary_minus_expr) +// Bitwise Operators +UNARY_OPERATOR(~, bitwise_not_expr) +// Logical Operators +UNARY_OPERATOR(!, not_expr) +// Other Operators +UNARY_OPERATOR(&, addr_of_expr) + +#undef BINARY_OPERATOR +#undef UNARY_OPERATOR +// Helpers // Prefix increment template -typename return_type_helper::type>::type operator++(T &&a) { - return (a = a + 1); +dyn_var& operator ++ (dyn_var& d1) { + return (d1 = d1 + 1); } // Postfix increment template -typename return_type_helper::type>::type operator++(T &&a, int) { - return ((a = a + 1) - 1); +dyn_var& operator ++ (dyn_var& d1, int) { + return ((d1 = d1 + 1) - 1); } // Prefix decrement template -typename return_type_helper::type>::type operator--(T &&a) { - return (a = a - 1); +dyn_var& operator -- (dyn_var& d1) { + return (d1 = d1 - 1); } // Postfix increment template -typename return_type_helper::type>::type operator--(T &&a, int) { - return ((a = a - 1) + 1); +dyn_var& operator -- (dyn_var& d1, int) { + return ((d1 = d1 - 1) + 1); } +// Hybrid Assignment template -typename allowed_builder_return::type, T2>::type operator+=(T1 &&a, const T2 &b) { - return (a = a + b); +dyn_var& operator += (dyn_var& d1, const T2& d2) { + return (d1 = d1 + d2); } template -typename allowed_builder_return::type, T2>::type operator-=(T1 &&a, const T2 &b) { - return (a = a - b); +dyn_var& operator -= (dyn_var& d1, const T2& d2) { + return (d1 = d1 - d2); } template -typename allowed_builder_return::type, T2>::type operator*=(T1 &&a, const T2 &b) { - return (a = a * b); +dyn_var& operator *= (dyn_var& d1, const T2& d2) { + return (d1 = d1 * d2); } template -typename allowed_builder_return::type, T2>::type operator/=(T1 &&a, const T2 &b) { - return (a = a / b); +dyn_var& operator /= (dyn_var& d1, const T2& d2) { + return (d1 = d1 / d2); } template -typename allowed_builder_return::type, T2>::type operator&=(T1 &&a, const T2 &b) { - return (a = a & b); +dyn_var& operator &= (dyn_var& d1, const T2& d2) { + return (d1 = d1 & d2); } template -typename allowed_builder_return::type, T2>::type operator|=(T1 &&a, const T2 &b) { - return (a = a | b); +dyn_var& operator |= (dyn_var& d1, const T2& d2) { + return (d1 = d1 | d2); } template -typename allowed_builder_return::type, T2>::type operator^=(T1 &&a, const T2 &b) { - return (a = a ^ b); +dyn_var& operator ^= (dyn_var& d1, const T2& d2) { + return (d1 = d1 ^ d2); } -} // namespace builder +// An explicit cast expression, this can however be automatically inserted +// by comparing types while assignment, but for now, we will keep this simple +template +dyn_var& cast_to(const T2& d1) { + auto ce = block::to(unary_expr_helper(d1)); + ce->type1 = type_extractor::extract_type(); + return *get_invocation_state()->get_arena()->allocate>(ce); +} +} #endif diff --git a/include/builder/providers_dyn_var.h b/include/builder/providers_dyn_var.h new file mode 100644 index 0000000..e494de9 --- /dev/null +++ b/include/builder/providers_dyn_var.h @@ -0,0 +1,116 @@ +#ifndef BUILDER_PROVIDERS_DYN_VAR_H +#define BUILDER_PROVIDERS_DYN_VAR_H +#include "util/mtp_utils.h" +#include "builder/block_type_extractor.h" +namespace builder { + +template +class dyn_var_impl; + +template +class dyn_var; + + +// A provider to compute return types for operator [] +// Implicitly also disables the operator using SFINAE if the type +// isn't a pointer or if it doesn't have dereference type defined +template +struct op_sq_bkt_ret_provider {}; + +template +struct op_sq_bkt_ret_provider { + using type = T; +}; + +template +struct op_sq_bkt_ret_provider: public op_sq_bkt_ret_provider { +}; +template +struct op_sq_bkt_ret_provider: public op_sq_bkt_ret_provider { +}; + +template +struct op_sq_bkt_ret_provider::type> { + using type = typename T::dereference_type; +}; + +template +using op_sq_bkt_ret_provider_t = typename op_sq_bkt_ret_provider::type; + +// A provider to compute return types for operator () +// Implicitly also disables the operator using SFINAE if the +// type isn't a function or function pointer type +// Argument types aren't enforced, to allow var args etc + +template +struct op_fcall_ret_provider {}; + +template +struct op_fcall_ret_provider: public op_fcall_ret_provider {}; + +template +struct op_fcall_ret_provider { + // Remove reference type from the return type in case the user uses auto + using type = typename std::remove_reference::type; +}; + +template +using op_fcall_ret_provider_t = typename op_fcall_ret_provider::type; + +// A provider to inherit members from user defined types +// The dyn_var class will directly inherit from this type + +extern bool user_defined_provider_track_members; + +template +struct user_defined_member_provider_begin { + user_defined_member_provider_begin() { + if (parents_stack == nullptr) { + parents_stack = new std::vector(); + } + parents_stack->push_back(static_cast(static_cast*>(this))); + } +}; + +struct user_defined_member_provider_end { + user_defined_member_provider_end() { + parents_stack->pop_back(); + } +}; + +template ::type, typename V=void> +struct user_defined_member_provider { +}; // Default implementation is empty + +template +struct user_defined_member_provider::value && !is_dyn_var_type::value && + !is_static_var_type::value>::type>: + public user_defined_member_provider_begin, public TR, public user_defined_member_provider_end { +}; + + +// A function that is implemented just for dyn_var that copies over RHS arguments +template +typename std::enable_if::value>::type copy_types_provider(dyn_var_impl& to, const TO& from) { +} + +template +typename std::enable_if::value>::type copy_types_provider(dyn_var_impl& to, const TO& from) { + assert(to.var_mode == dyn_var_impl::standalone_var); + to.block_var->var_type = from.block_var->var_type; +} + +// Not exaclty a helper but a base type user from inherit that provides +// template types to a type, required for stuff like user defined std::vector +template +struct custom_type { + static std::vector get_template_arg_types() { + return {type_extractor::extract_type()...}; + } +}; + + +} + +#endif diff --git a/include/builder/run_states.h b/include/builder/run_states.h index 69254eb..a665ea8 100644 --- a/include/builder/run_states.h +++ b/include/builder/run_states.h @@ -5,6 +5,7 @@ #include #include "util/tracer.h" #include "builder/forward_declarations.h" +#include "builder/arena_dyn_var.h" #include #include #include @@ -78,7 +79,11 @@ class run_state { /* Memoization related fields */ // Tags visited before for loopback edges - std::unordered_set visited_offsets; + std::unordered_map visited_offsets; + + // Tag deduplication set, this keeps track of tags + // for statements that are the same but the statements are different + std::unordered_map tag_deduplication_map; /* Parent dynamic states */ execution_state* e_state; @@ -160,6 +165,10 @@ class invocation_state { block::func_decl::Ptr generated_func_decl; builder_context* b_ctx = nullptr; + + // Arena is part of the invocation state + // so the buffers persist + dyn_var_arena var_arena; public: @@ -177,6 +186,11 @@ class invocation_state { template friend std::shared_ptr get_or_create_generator(tracer::tag req_tag, Args&&...args); + +public: + dyn_var_arena* get_arena(void) { + return &var_arena; + } }; static inline run_state* get_run_state(void) { diff --git a/include/builder/signature_extract.h b/include/builder/signature_extract.h index fb5bedd..be3d1b8 100644 --- a/include/builder/signature_extract.h +++ b/include/builder/signature_extract.h @@ -23,9 +23,22 @@ OtherParams... - all the remaining params the other ProcessedArgTypes is borrowed from above and hence is not really a pack */ +// Helper function to create a return statement template -constexpr bool is_dyn_var(void) { - return std::is_base_of::value; +void create_return_stmt(const dyn_var& a) { + auto e = to_expr(a); + get_run_state()->remove_node_from_sequence(e); + get_run_state()->commit_uncommitted(); + if (get_run_state()->is_catching_up()) + return; + block::return_stmt::Ptr ret_stmt = std::make_shared(); + // ret_stmt->static_offset = a.block_expr->static_offset; + // Finding conflicts between return statements is somehow really hard. + // So treat each return statement as different. This is okay, because a + // jump is as bad a return. Also no performance issues + ret_stmt->static_offset = tracer::get_unique_tag(); + ret_stmt->return_val = e; + get_run_state()->add_stmt_to_current_block(ret_stmt, true); } template @@ -41,7 +54,7 @@ struct extract_signature_impl { // For partial specializations, the template parameter is a pack but is used inside a tuple // 1. When the next argument to process is dyn_var - It has to be dyn_var not any derived types template -struct extract_signature_impl, std::tuple, ReturnType, typename std::enable_if()>::type> { +struct extract_signature_impl, std::tuple, ReturnType, typename std::enable_if::value>::type> { using NextArg = typename NextArgWrap::stored_type; // The dyn_var version doesn't need any NextParam to exist or be used template @@ -61,7 +74,7 @@ struct extract_signature_impl, std::tuple -struct extract_signature_impl, std::tuple, ReturnType, typename std::enable_if()>::type> { +struct extract_signature_impl, std::tuple, ReturnType, typename std::enable_if::value>::type> { // This version needs a NextParam template static void fill_invocation(invocation_state* i_state, F func, int arg_index, ProcessedArgTypes...processed_args, NextParam&& next_param, OtherParams&&...other_params) { diff --git a/include/builder/static_var.h b/include/builder/static_var.h index cb714b0..0cd75a9 100644 --- a/include/builder/static_var.h +++ b/include/builder/static_var.h @@ -1,7 +1,6 @@ #ifndef STATIC_VAR_H #define STATIC_VAR_H -#include "builder/builder.h" #include "builder/builder_context.h" #include "util/var_finder.h" @@ -141,10 +140,6 @@ class static_var : static_var_base { } } - operator builder() { - try_get_name(); - return (builder)val; - } std::string serialize() override { return utils::can_to_string::get_string(val); } diff --git a/include/builder/to_expr.h b/include/builder/to_expr.h new file mode 100644 index 0000000..85942a4 --- /dev/null +++ b/include/builder/to_expr.h @@ -0,0 +1,86 @@ +#ifndef BUILDER_TO_EXPR_H +#define BUILDER_TO_EXPR_H +#include +#include "builder/forward_declarations.h" +namespace builder { + +// A single templated constructor to create expr blocks of any type +// This handles removing childred from UC, adding new expresisons to UC +// and caching for runs, the children, aren't set but are removed from UC +template +typename T::Ptr create_expr(const std::vector &children) { + // Caching happens here + if (get_run_state()->is_catching_up()) { + return block::to(get_run_state()->get_next_cached_expr()); + } + for (auto c: children) { + get_run_state()->remove_node_from_sequence(c); + } + tracer::tag offset = tracer::get_offset_in_function(); + typename T::Ptr expr = std::make_shared(); + expr->static_offset = offset; + // The other members will be set by the caller + get_run_state()->add_node_to_sequence(expr); + // For caching + get_run_state()->add_to_cached_expr(expr); + return expr; +} + + +// Single conversion function to convert anything into +// an expression, overloads for different types +block::expr::Ptr to_expr(const dyn_var_base& d); + +template +typename std::enable_if::value, block::expr::Ptr>::type to_expr(const T& v) { + auto e = create_expr({}); + e->value = v; + e->is_64bit = sizeof(T) > 4; + return e; +} + +template +block::expr::Ptr to_expr(const static_var& s) { + return to_expr((T)s); +} + +template +block::expr::Ptr to_expr(const std::vector& v) { + std::vector argv; + for (auto x: v) { + argv.push_back(to_expr(x)); + } + auto e = create_expr(argv); + e->elems = argv; + return e; + +} + +block::expr::Ptr to_expr(const float& v); +block::expr::Ptr to_expr(const double& v); +block::expr::Ptr to_expr(const std::string& s); +block::expr::Ptr to_expr(const char* s); +block::expr::Ptr to_expr(char* s); + +// An untyped expression wrapper +// to be specifically used for initializer_lists since they need +// to be homogenous. This can be constructed from anything that is +// to_expr convertible + +struct expr_wrapper_base { + block::expr::Ptr e; + expr_wrapper_base(block::expr::Ptr e): e(e) {} +}; + +struct expr_wrapper: public expr_wrapper_base { + template + expr_wrapper(const T& t): expr_wrapper_base(to_expr(t)) {} +}; + +block::expr::Ptr to_expr(const std::initializer_list& i); +block::expr::Ptr to_expr(const expr_wrapper_base&); + + +} + +#endif diff --git a/include/util/tracer.h b/include/util/tracer.h index ca84e81..752d515 100644 --- a/include/util/tracer.h +++ b/include/util/tracer.h @@ -22,7 +22,7 @@ class tag { std::vector> static_var_snapshots; std::vector> static_var_key_values; std::vector live_dyn_vars; - + size_t dedup_id = 0; std::string cached_string; mutable size_t cached_hash = 0; @@ -38,6 +38,7 @@ class tag { pointers.clear(); static_var_snapshots.clear(); live_dyn_vars.clear(); + dedup_id = 0; } // A function to create another tag @@ -95,6 +96,9 @@ class tag { h = hash_combine(h, (size_t) live_dyn_vars[i]); } + // Finally add the dedup id in + h = hash_combine(h, dedup_id); + cached_hash = h; return cached_hash; } diff --git a/make/tests.mk b/make/tests.mk index 8f8cd80..10aacc1 100644 --- a/make/tests.mk +++ b/make/tests.mk @@ -23,12 +23,12 @@ run: $(SAMPLES) if [[ $$(head -n1 $(SAMPLES_DIR)/$$sample_name".cpp") != "/*NO_TEST*/" ]]; then \ ((total=total+1)); \ if cmp -s $(SAMPLES_DIR)/$(OUTPUT_DIR)/$$sample_name <($$sample); then \ - echo -e "\e[32m"$$sample_name: "OK\e[39m"; \ + echo -e "\033[32m"$$sample_name: "OK\033[39m"; \ ((success=success+1)); \ - progress=$$progress"\e[32m#\e[39m"; \ + progress=$$progress"\033[32m#\033[39m"; \ else \ - echo -e "\e[31m"$$sample_name: "FAIL\e[39m"; \ - fail=$$fail"\e[31mX\e[39m"; \ + echo -e "\033[31m"$$sample_name: "FAIL\033[39m"; \ + fail=$$fail"\033[31mX\033[39m"; \ fi; \ fi; \ done; \ diff --git a/samples/outputs.var_names/sample1 b/samples/outputs.var_names/sample1 index b813f34..8b4513f 100644 --- a/samples/outputs.var_names/sample1 +++ b/samples/outputs.var_names/sample1 @@ -105,6 +105,10 @@ STMT_BLOCK BITWISE_NOT_EXPR VAR_EXPR VAR (b_1) + EXPR_STMT + ADDR_OF_EXPR + VAR_EXPR + VAR (b_1) { int a_0 = 0; int b_1 = a_0; @@ -123,4 +127,5 @@ STMT_BLOCK a_0 = a_0 | b_1; a_0 = a_0 ^ b_1; ~b_1; + &b_1; } diff --git a/samples/outputs.var_names/sample21 b/samples/outputs.var_names/sample21 index 16bcc05..6163e2b 100644 --- a/samples/outputs.var_names/sample21 +++ b/samples/outputs.var_names/sample21 @@ -2,11 +2,21 @@ STMT_BLOCK DECL_STMT SCALAR_TYPE (INT) VAR (x_0) - INT_CONST (2) + INT_CONST (18) DECL_STMT SCALAR_TYPE (INT) - VAR (bar_1) - PLUS_EXPR - STRING_CONST ("foo") + VAR (y_1) + INT_CONST (17) + EXPR_STMT + ASSIGN_EXPR VAR_EXPR VAR (x_0) + PLUS_EXPR + VAR_EXPR + VAR (y_1) + INT_CONST (9) +{ + int x_0 = 18; + int y_1 = 17; + x_0 = y_1 + 9; +} diff --git a/samples/outputs.var_names/sample22 b/samples/outputs.var_names/sample22 index 6163e2b..83493aa 100644 --- a/samples/outputs.var_names/sample22 +++ b/samples/outputs.var_names/sample22 @@ -1,22 +1,77 @@ STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (t_2) + NO_INITIALIZATION DECL_STMT SCALAR_TYPE (INT) VAR (x_0) - INT_CONST (18) + NO_INITIALIZATION DECL_STMT SCALAR_TYPE (INT) - VAR (y_1) - INT_CONST (17) - EXPR_STMT - ASSIGN_EXPR + VAR (var1) + VAR_EXPR + VAR (x_0) + IF_STMT + GT_EXPR VAR_EXPR - VAR (x_0) - PLUS_EXPR - VAR_EXPR - VAR (y_1) - INT_CONST (9) + VAR (var1) + INT_CONST (10) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (t_2) + INT_CONST (9) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (t_2) + INT_CONST (0) + IF_STMT + VAR_EXPR + VAR (t_2) + STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (k_3) + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (k_3) + INT_CONST (0) + STMT_BLOCK + IF_STMT + VAR_EXPR + VAR (x_0) + STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (k_4) + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (k_4) + INT_CONST (0) + STMT_BLOCK { - int x_0 = 18; - int y_1 = 17; - x_0 = y_1 + 9; + int t_2; + int x_0; + int var1 = x_0; + if (var1 > 10) { + t_2 = 9; + } else { + t_2 = 0; + } + if (t_2) { + int k_3 = 0; + k_3 = 0; + } + if (x_0) { + int k_4 = 0; + k_4 = 0; + } } diff --git a/samples/outputs.var_names/sample23 b/samples/outputs.var_names/sample23 index 83493aa..46afdfb 100644 --- a/samples/outputs.var_names/sample23 +++ b/samples/outputs.var_names/sample23 @@ -1,77 +1,353 @@ STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (t_2) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (INT) - VAR (x_0) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (INT) - VAR (var1) - VAR_EXPR - VAR (x_0) - IF_STMT - GT_EXPR - VAR_EXPR - VAR (var1) - INT_CONST (10) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) + SCALAR_TYPE (INT) + VAR (g_0) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (g_0) + INT_CONST (0) + ASSIGN_EXPR + VAR_EXPR + VAR (g_0) + PLUS_EXPR + VAR_EXPR + VAR (g_0) + INT_CONST (1) STMT_BLOCK + DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (x_1) + INT_CONST (0) EXPR_STMT ASSIGN_EXPR VAR_EXPR - VAR (t_2) - INT_CONST (9) + VAR (x_1) + PLUS_EXPR + VAR_EXPR + VAR (x_1) + INT_CONST (1) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) + SCALAR_TYPE (INT) + VAR (g_2) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (g_2) + INT_CONST (1) + ASSIGN_EXPR + VAR_EXPR + VAR (g_2) + PLUS_EXPR + VAR_EXPR + VAR (g_2) + INT_CONST (1) STMT_BLOCK + DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (x_3) + INT_CONST (1) EXPR_STMT ASSIGN_EXPR VAR_EXPR - VAR (t_2) - INT_CONST (0) - IF_STMT - VAR_EXPR - VAR (t_2) + VAR (x_3) + PLUS_EXPR + VAR_EXPR + VAR (x_3) + INT_CONST (1) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) + SCALAR_TYPE (INT) + VAR (g_4) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (g_4) + INT_CONST (2) + ASSIGN_EXPR + VAR_EXPR + VAR (g_4) + PLUS_EXPR + VAR_EXPR + VAR (g_4) + INT_CONST (1) STMT_BLOCK DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (x_5) + INT_CONST (2) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (x_5) + PLUS_EXPR + VAR_EXPR + VAR (x_5) + INT_CONST (1) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) SCALAR_TYPE (INT) - VAR (k_3) - INT_CONST (0) + VAR (g_6) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (g_6) + INT_CONST (3) + ASSIGN_EXPR + VAR_EXPR + VAR (g_6) + PLUS_EXPR + VAR_EXPR + VAR (g_6) + INT_CONST (1) + STMT_BLOCK + DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (x_7) + INT_CONST (3) EXPR_STMT ASSIGN_EXPR VAR_EXPR - VAR (k_3) - INT_CONST (0) + VAR (x_7) + PLUS_EXPR + VAR_EXPR + VAR (x_7) + INT_CONST (1) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) + SCALAR_TYPE (INT) + VAR (g_8) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (g_8) + INT_CONST (4) + ASSIGN_EXPR + VAR_EXPR + VAR (g_8) + PLUS_EXPR + VAR_EXPR + VAR (g_8) + INT_CONST (1) STMT_BLOCK - IF_STMT - VAR_EXPR - VAR (x_0) + DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (x_9) + INT_CONST (4) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (x_9) + PLUS_EXPR + VAR_EXPR + VAR (x_9) + INT_CONST (1) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) + SCALAR_TYPE (INT) + VAR (g_10) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (g_10) + INT_CONST (5) + ASSIGN_EXPR + VAR_EXPR + VAR (g_10) + PLUS_EXPR + VAR_EXPR + VAR (g_10) + INT_CONST (1) STMT_BLOCK DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (x_11) + INT_CONST (5) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (x_11) + PLUS_EXPR + VAR_EXPR + VAR (x_11) + INT_CONST (1) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) SCALAR_TYPE (INT) - VAR (k_4) - INT_CONST (0) + VAR (g_12) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (g_12) + INT_CONST (6) + ASSIGN_EXPR + VAR_EXPR + VAR (g_12) + PLUS_EXPR + VAR_EXPR + VAR (g_12) + INT_CONST (1) + STMT_BLOCK + DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (x_13) + INT_CONST (6) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (x_13) + PLUS_EXPR + VAR_EXPR + VAR (x_13) + INT_CONST (1) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) + SCALAR_TYPE (INT) + VAR (g_14) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (g_14) + INT_CONST (7) + ASSIGN_EXPR + VAR_EXPR + VAR (g_14) + PLUS_EXPR + VAR_EXPR + VAR (g_14) + INT_CONST (1) + STMT_BLOCK + DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (x_15) + INT_CONST (7) EXPR_STMT ASSIGN_EXPR VAR_EXPR - VAR (k_4) - INT_CONST (0) + VAR (x_15) + PLUS_EXPR + VAR_EXPR + VAR (x_15) + INT_CONST (1) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) + SCALAR_TYPE (INT) + VAR (g_16) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (g_16) + INT_CONST (8) + ASSIGN_EXPR + VAR_EXPR + VAR (g_16) + PLUS_EXPR + VAR_EXPR + VAR (g_16) + INT_CONST (1) STMT_BLOCK + DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (x_17) + INT_CONST (8) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (x_17) + PLUS_EXPR + VAR_EXPR + VAR (x_17) + INT_CONST (1) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) + SCALAR_TYPE (INT) + VAR (g_18) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (g_18) + INT_CONST (9) + ASSIGN_EXPR + VAR_EXPR + VAR (g_18) + PLUS_EXPR + VAR_EXPR + VAR (g_18) + INT_CONST (1) + STMT_BLOCK + DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (x_19) + INT_CONST (9) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (x_19) + PLUS_EXPR + VAR_EXPR + VAR (x_19) + INT_CONST (1) { - int t_2; - int x_0; - int var1 = x_0; - if (var1 > 10) { - t_2 = 9; - } else { - t_2 = 0; + for (builder::static_var g_0 = 0; g_0 < 0; g_0 = g_0 + 1) { + builder::dyn_var x_1 = 0; + x_1 = x_1 + 1; + } + for (builder::static_var g_2 = 0; g_2 < 1; g_2 = g_2 + 1) { + builder::dyn_var x_3 = 1; + x_3 = x_3 + 1; + } + for (builder::static_var g_4 = 0; g_4 < 2; g_4 = g_4 + 1) { + builder::dyn_var x_5 = 2; + x_5 = x_5 + 1; + } + for (builder::static_var g_6 = 0; g_6 < 3; g_6 = g_6 + 1) { + builder::dyn_var x_7 = 3; + x_7 = x_7 + 1; + } + for (builder::static_var g_8 = 0; g_8 < 4; g_8 = g_8 + 1) { + builder::dyn_var x_9 = 4; + x_9 = x_9 + 1; + } + for (builder::static_var g_10 = 0; g_10 < 5; g_10 = g_10 + 1) { + builder::dyn_var x_11 = 5; + x_11 = x_11 + 1; + } + for (builder::static_var g_12 = 0; g_12 < 6; g_12 = g_12 + 1) { + builder::dyn_var x_13 = 6; + x_13 = x_13 + 1; + } + for (builder::static_var g_14 = 0; g_14 < 7; g_14 = g_14 + 1) { + builder::dyn_var x_15 = 7; + x_15 = x_15 + 1; + } + for (builder::static_var g_16 = 0; g_16 < 8; g_16 = g_16 + 1) { + builder::dyn_var x_17 = 8; + x_17 = x_17 + 1; + } + for (builder::static_var g_18 = 0; g_18 < 9; g_18 = g_18 + 1) { + builder::dyn_var x_19 = 9; + x_19 = x_19 + 1; } - if (t_2) { - int k_3 = 0; - k_3 = 0; - } - if (x_0) { - int k_4 = 0; - k_4 = 0; - } } diff --git a/samples/outputs.var_names/sample24 b/samples/outputs.var_names/sample24 index 46afdfb..1ad92bd 100644 --- a/samples/outputs.var_names/sample24 +++ b/samples/outputs.var_names/sample24 @@ -1,353 +1,118 @@ -STMT_BLOCK - FOR_STMT +FUNC_DECL (func1) + SCALAR_TYPE (INT) + VAR (arg0) + VAR (arg1) + VAR (arg2) + STMT_BLOCK DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (g_0) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (g_0) - INT_CONST (0) - ASSIGN_EXPR - VAR_EXPR - VAR (g_0) - PLUS_EXPR - VAR_EXPR - VAR (g_0) - INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (x_1) - INT_CONST (0) - EXPR_STMT - ASSIGN_EXPR + SCALAR_TYPE (INT) + VAR (z_0) + MINUS_EXPR + MINUS_EXPR VAR_EXPR - VAR (x_1) - PLUS_EXPR - VAR_EXPR - VAR (x_1) - INT_CONST (1) - FOR_STMT - DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (g_2) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (g_2) - INT_CONST (1) - ASSIGN_EXPR - VAR_EXPR - VAR (g_2) - PLUS_EXPR - VAR_EXPR - VAR (g_2) - INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (x_3) - INT_CONST (1) - EXPR_STMT - ASSIGN_EXPR + VAR (arg0) VAR_EXPR - VAR (x_3) - PLUS_EXPR - VAR_EXPR - VAR (x_3) - INT_CONST (1) - FOR_STMT - DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (g_4) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (g_4) - INT_CONST (2) - ASSIGN_EXPR - VAR_EXPR - VAR (g_4) - PLUS_EXPR + VAR (arg1) VAR_EXPR - VAR (g_4) - INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (x_5) - INT_CONST (2) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (x_5) - PLUS_EXPR - VAR_EXPR - VAR (x_5) - INT_CONST (1) - FOR_STMT + VAR (arg2) DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (g_6) + SCALAR_TYPE (INT) + VAR (var1) INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (g_6) - INT_CONST (3) - ASSIGN_EXPR + RETURN_STMT VAR_EXPR - VAR (g_6) - PLUS_EXPR - VAR_EXPR - VAR (g_6) - INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (x_7) - INT_CONST (3) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (x_7) - PLUS_EXPR - VAR_EXPR - VAR (x_7) - INT_CONST (1) - FOR_STMT + VAR (var1) +int func1 (int arg0, int arg1, int arg2) { + int z_0 = arg0 - arg1 - arg2; + int var1 = 0; + return var1; +} + +FUNC_DECL (func2) + SCALAR_TYPE (INT) + VAR (arg0) + STMT_BLOCK DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (g_8) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (g_8) - INT_CONST (4) - ASSIGN_EXPR - VAR_EXPR - VAR (g_8) + SCALAR_TYPE (INT) + VAR (var0) PLUS_EXPR VAR_EXPR - VAR (g_8) + VAR (arg0) INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (x_9) - INT_CONST (4) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (x_9) - PLUS_EXPR - VAR_EXPR - VAR (x_9) - INT_CONST (1) - FOR_STMT - DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (g_10) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (g_10) - INT_CONST (5) - ASSIGN_EXPR + RETURN_STMT VAR_EXPR - VAR (g_10) - PLUS_EXPR - VAR_EXPR - VAR (g_10) - INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (x_11) - INT_CONST (5) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (x_11) - PLUS_EXPR - VAR_EXPR - VAR (x_11) - INT_CONST (1) - FOR_STMT + VAR (var0) +int func2 (int arg0) { + int var0 = arg0 + 1; + return var0; +} + +FUNC_DECL (func3) + SCALAR_TYPE (VOID) + VAR (arg0) + STMT_BLOCK DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (g_12) - INT_CONST (0) - LT_EXPR + SCALAR_TYPE (INT) + VAR (b_0) VAR_EXPR - VAR (g_12) - INT_CONST (6) - ASSIGN_EXPR - VAR_EXPR - VAR (g_12) - PLUS_EXPR + VAR (arg0) + EXPR_STMT + ASSIGN_EXPR VAR_EXPR - VAR (g_12) - INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (x_13) - INT_CONST (6) - EXPR_STMT - ASSIGN_EXPR + VAR (arg0) + PLUS_EXPR VAR_EXPR - VAR (x_13) - PLUS_EXPR - VAR_EXPR - VAR (x_13) - INT_CONST (1) - FOR_STMT + VAR (b_0) + INT_CONST (1) +void func3 (int arg0) { + int b_0 = arg0; + arg0 = b_0 + 1; +} + +FUNC_DECL (func4) + SCALAR_TYPE (INT) + VAR (arg0) + STMT_BLOCK DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (g_14) + SCALAR_TYPE (INT) + VAR (t_0) INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (g_14) - INT_CONST (7) - ASSIGN_EXPR - VAR_EXPR - VAR (g_14) - PLUS_EXPR + EXPR_STMT + ASSIGN_EXPR VAR_EXPR - VAR (g_14) - INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (x_15) - INT_CONST (7) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (x_15) + VAR (t_0) + PLUS_EXPR PLUS_EXPR VAR_EXPR - VAR (x_15) - INT_CONST (1) - FOR_STMT - DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (g_16) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (g_16) - INT_CONST (8) - ASSIGN_EXPR - VAR_EXPR - VAR (g_16) - PLUS_EXPR - VAR_EXPR - VAR (g_16) - INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (x_17) - INT_CONST (8) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (x_17) - PLUS_EXPR + VAR (t_0) VAR_EXPR - VAR (x_17) - INT_CONST (1) - FOR_STMT - DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (g_18) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (g_18) - INT_CONST (9) - ASSIGN_EXPR - VAR_EXPR - VAR (g_18) - PLUS_EXPR + VAR (arg0) + INT_CONST (1) + EXPR_STMT + ASSIGN_EXPR VAR_EXPR - VAR (g_18) - INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (x_19) - INT_CONST (9) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (x_19) + VAR (t_0) + PLUS_EXPR PLUS_EXPR VAR_EXPR - VAR (x_19) - INT_CONST (1) -{ - for (builder::static_var g_0 = 0; g_0 < 0; g_0 = g_0 + 1) { - builder::dyn_var x_1 = 0; - x_1 = x_1 + 1; - } - for (builder::static_var g_2 = 0; g_2 < 1; g_2 = g_2 + 1) { - builder::dyn_var x_3 = 1; - x_3 = x_3 + 1; - } - for (builder::static_var g_4 = 0; g_4 < 2; g_4 = g_4 + 1) { - builder::dyn_var x_5 = 2; - x_5 = x_5 + 1; - } - for (builder::static_var g_6 = 0; g_6 < 3; g_6 = g_6 + 1) { - builder::dyn_var x_7 = 3; - x_7 = x_7 + 1; - } - for (builder::static_var g_8 = 0; g_8 < 4; g_8 = g_8 + 1) { - builder::dyn_var x_9 = 4; - x_9 = x_9 + 1; - } - for (builder::static_var g_10 = 0; g_10 < 5; g_10 = g_10 + 1) { - builder::dyn_var x_11 = 5; - x_11 = x_11 + 1; - } - for (builder::static_var g_12 = 0; g_12 < 6; g_12 = g_12 + 1) { - builder::dyn_var x_13 = 6; - x_13 = x_13 + 1; - } - for (builder::static_var g_14 = 0; g_14 < 7; g_14 = g_14 + 1) { - builder::dyn_var x_15 = 7; - x_15 = x_15 + 1; - } - for (builder::static_var g_16 = 0; g_16 < 8; g_16 = g_16 + 1) { - builder::dyn_var x_17 = 8; - x_17 = x_17 + 1; - } - for (builder::static_var g_18 = 0; g_18 < 9; g_18 = g_18 + 1) { - builder::dyn_var x_19 = 9; - x_19 = x_19 + 1; - } + VAR (t_0) + VAR_EXPR + VAR (arg0) + INT_CONST (1) + EXPR_STMT + FUNCTION_CALL_EXPR + VAR_EXPR + VAR (print_val) + VAR_EXPR + VAR (t_0) + RETURN_STMT + VAR_EXPR + VAR (t_0) +int func4 (int arg0) { + int t_0 = 0; + t_0 = t_0 + arg0 + 1; + t_0 = t_0 + arg0 + 1; + print_val(t_0); + return t_0; } + diff --git a/samples/outputs.var_names/sample25 b/samples/outputs.var_names/sample25 index 9382694..303da7f 100644 --- a/samples/outputs.var_names/sample25 +++ b/samples/outputs.var_names/sample25 @@ -1,154 +1,112 @@ -FUNC_DECL - SCALAR_TYPE (INT) - VAR (arg0) - VAR (arg1) - VAR (arg2) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (var0) - VAR_EXPR - VAR (arg2) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var1) - VAR_EXPR - VAR (arg1) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var2) - VAR_EXPR - VAR (arg0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (z_3) - MINUS_EXPR - MINUS_EXPR - VAR_EXPR - VAR (var2) - VAR_EXPR - VAR (var1) +STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (k_0) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (t_1) + INT_CONST (0) + WHILE_STMT + NOT_EXPR + EQUALS_EXPR VAR_EXPR - VAR (var0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var4) - INT_CONST (0) - RETURN_STMT - VAR_EXPR - VAR (var4) -int func1 (int arg0, int arg1, int arg2) { - int var0 = arg2; - int var1 = arg1; - int var2 = arg0; - int z_3 = (var2 - var1) - var0; - int var4 = 0; - return var4; -} - -FUNC_DECL - SCALAR_TYPE (INT) - VAR (arg0) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (var0) - VAR_EXPR - VAR (arg0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var1) - PLUS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (1) - RETURN_STMT - VAR_EXPR - VAR (var1) -int func2 (int arg0) { - int var0 = arg0; - int var1 = var0 + 1; - return var1; -} - -FUNC_DECL - SCALAR_TYPE (VOID) - VAR (arg0) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (var0) - VAR_EXPR - VAR (arg0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (b_1) - VAR_EXPR - VAR (var0) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var0) - PLUS_EXPR + VAR (k_0) + INT_CONST (0) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR VAR_EXPR - VAR (b_1) - INT_CONST (1) -void func3 (int arg0) { - int var0 = arg0; - int b_1 = var0; - var0 = b_1 + 1; -} - -FUNC_DECL - SCALAR_TYPE (INT) - VAR (arg0) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (var0) - VAR_EXPR - VAR (arg0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (t_1) - INT_CONST (0) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (t_1) - PLUS_EXPR + VAR (t_1) PLUS_EXPR VAR_EXPR VAR (t_1) + INT_CONST (1) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (t_1) + PLUS_EXPR VAR_EXPR - VAR (var0) - INT_CONST (1) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (t_1) - PLUS_EXPR + VAR (t_1) + INT_CONST (1) + WHILE_STMT + NOT_EXPR + EQUALS_EXPR + VAR_EXPR + VAR (k_0) + INT_CONST (0) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (t_1) PLUS_EXPR VAR_EXPR VAR (t_1) + INT_CONST (1) + WHILE_STMT + NOT_EXPR + EQUALS_EXPR VAR_EXPR - VAR (var0) - INT_CONST (1) - EXPR_STMT - FUNCTION_CALL_EXPR - VAR_EXPR - VAR (print_val) - VAR_EXPR - VAR (t_1) - RETURN_STMT + VAR (k_0) + INT_CONST (0) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (t_1) + PLUS_EXPR + VAR_EXPR + VAR (t_1) + INT_CONST (1) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (t_1) + PLUS_EXPR + VAR_EXPR + VAR (t_1) + INT_CONST (1) + EXPR_STMT + ASSIGN_EXPR VAR_EXPR VAR (t_1) -int func4 (int arg0) { - int var0 = arg0; + PLUS_EXPR + VAR_EXPR + VAR (t_1) + INT_CONST (2) + WHILE_STMT + NOT_EXPR + EQUALS_EXPR + VAR_EXPR + VAR (k_0) + INT_CONST (0) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (t_1) + PLUS_EXPR + VAR_EXPR + VAR (t_1) + INT_CONST (1) +{ + int k_0 = 0; int t_1 = 0; - t_1 = (t_1 + var0) + 1; - t_1 = (t_1 + var0) + 1; - print_val(t_1); - return t_1; + while (!(k_0 == 0)) { + t_1 = t_1 + 1; + t_1 = t_1 + 1; + while (!(k_0 == 0)) { + } + t_1 = t_1 + 1; + while (!(k_0 == 0)) { + t_1 = t_1 + 1; + } + t_1 = t_1 + 1; + } + t_1 = t_1 + 2; + while (!(k_0 == 0)) { + t_1 = t_1 + 1; + } } - diff --git a/samples/outputs.var_names/sample26 b/samples/outputs.var_names/sample26 index 00fda52..1bdd654 100644 --- a/samples/outputs.var_names/sample26 +++ b/samples/outputs.var_names/sample26 @@ -1,112 +1,27 @@ -STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (k_0) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (t_1) - INT_CONST (0) - WHILE_STMT - NOT_EXPR - EQUALS_EXPR - VAR_EXPR - VAR (k_0) - INT_CONST (0) - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (t_1) - PLUS_EXPR - VAR_EXPR - VAR (t_1) - INT_CONST (1) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (t_1) - PLUS_EXPR - VAR_EXPR - VAR (t_1) - INT_CONST (1) - WHILE_STMT - NOT_EXPR - EQUALS_EXPR - VAR_EXPR - VAR (k_0) - INT_CONST (0) - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (t_1) - PLUS_EXPR - VAR_EXPR - VAR (t_1) - INT_CONST (1) - WHILE_STMT - NOT_EXPR - EQUALS_EXPR - VAR_EXPR - VAR (k_0) - INT_CONST (0) - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (t_1) - PLUS_EXPR - VAR_EXPR - VAR (t_1) - INT_CONST (1) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (t_1) - PLUS_EXPR - VAR_EXPR - VAR (t_1) - INT_CONST (1) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (t_1) - PLUS_EXPR - VAR_EXPR - VAR (t_1) - INT_CONST (1) - WHILE_STMT - NOT_EXPR - EQUALS_EXPR - VAR_EXPR - VAR (k_0) - INT_CONST (0) - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (t_1) - PLUS_EXPR - VAR_EXPR - VAR (t_1) - INT_CONST (1) -{ - int k_0 = 0; - int t_1 = 0; - while (!(k_0 == 0)) { - t_1 = t_1 + 1; - t_1 = t_1 + 1; - while (!(k_0 == 0)) { - } - t_1 = t_1 + 1; - while (!(k_0 == 0)) { - t_1 = t_1 + 1; - } - t_1 = t_1 + 1; - } - t_1 = t_1 + 1; - while (!(k_0 == 0)) { - t_1 = t_1 + 1; +int power_15 (int arg0) { + int res_0 = 1; + int x_1 = arg0; + res_0 = res_0 * x_1; + x_1 = x_1 * x_1; + res_0 = res_0 * x_1; + x_1 = x_1 * x_1; + res_0 = res_0 * x_1; + x_1 = x_1 * x_1; + res_0 = res_0 * x_1; + x_1 = x_1 * x_1; + return res_0; +} + +int power_5 (int arg0) { + int res_0 = 1; + int x_1 = 5; + while (arg0 > 0) { + if (arg0 % 2 == 1) { + res_0 = res_0 * x_1; + } + x_1 = x_1 * x_1; + arg0 = arg0 / 2; } + return res_0; } + diff --git a/samples/outputs.var_names/sample27 b/samples/outputs.var_names/sample27 index 4d881e5..ab98c7f 100644 --- a/samples/outputs.var_names/sample27 +++ b/samples/outputs.var_names/sample27 @@ -1,29 +1,183 @@ -int power_15 (int arg0) { - int var0 = arg0; - int res_1 = 1; - int x_2 = var0; - res_1 = res_1 * x_2; - x_2 = x_2 * x_2; - res_1 = res_1 * x_2; - x_2 = x_2 * x_2; - res_1 = res_1 * x_2; - x_2 = x_2 * x_2; - res_1 = res_1 * x_2; - x_2 = x_2 * x_2; - return res_1; -} - -int power_5 (int arg1) { - int var0 = arg1; - int res_1 = 1; - int x_2 = 5; - while (var0 > 0) { - if ((var0 % 2) == 1) { - res_1 = res_1 * x_2; - } - x_2 = x_2 * x_2; - var0 = var0 / 2; +STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (sum_0) + INT_CONST (0) + DECL_STMT + ARRAY_TYPE + SCALAR_TYPE (INT) + 9 + VAR (roll_var_5) + INITIALIZER_LIST_EXPR + INT_CONST (1) + INT_CONST (3) + INT_CONST (4) + INT_CONST (2) + INT_CONST (6) + INT_CONST (8) + INT_CONST (1) + INT_CONST (-2) + INT_CONST (3) + FOR_STMT + DECL_STMT + SCALAR_TYPE (INT) + VAR (index_var_6) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (index_var_6) + INT_CONST (9) + ASSIGN_EXPR + VAR_EXPR + VAR (index_var_6) + PLUS_EXPR + VAR_EXPR + VAR (index_var_6) + INT_CONST (1) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (sum_0) + PLUS_EXPR + VAR_EXPR + VAR (sum_0) + SQ_BKT_EXPR + VAR_EXPR + VAR (roll_var_5) + VAR_EXPR + VAR (index_var_6) + DECL_STMT + ARRAY_TYPE + SCALAR_TYPE (INT) + 5 + VAR (old_ranks_1) + NO_INITIALIZATION + DECL_STMT + ARRAY_TYPE + SCALAR_TYPE (INT) + 5 + VAR (new_ranks_2) + NO_INITIALIZATION + DECL_STMT + ARRAY_TYPE + SCALAR_TYPE (INT) + 8 + VAR (roll_var_0) + INITIALIZER_LIST_EXPR + INT_CONST (0) + INT_CONST (0) + INT_CONST (1) + INT_CONST (1) + INT_CONST (2) + INT_CONST (3) + INT_CONST (3) + INT_CONST (3) + DECL_STMT + ARRAY_TYPE + SCALAR_TYPE (INT) + 8 + VAR (roll_var_1) + INITIALIZER_LIST_EXPR + INT_CONST (0) + INT_CONST (0) + INT_CONST (1) + INT_CONST (1) + INT_CONST (2) + INT_CONST (3) + INT_CONST (3) + INT_CONST (3) + DECL_STMT + ARRAY_TYPE + SCALAR_TYPE (INT) + 8 + VAR (roll_var_2) + INITIALIZER_LIST_EXPR + INT_CONST (4) + INT_CONST (1) + INT_CONST (5) + INT_CONST (1) + INT_CONST (1) + INT_CONST (1) + INT_CONST (2) + INT_CONST (1) + DECL_STMT + ARRAY_TYPE + SCALAR_TYPE (INT) + 8 + VAR (roll_var_3) + INITIALIZER_LIST_EXPR + INT_CONST (0) + INT_CONST (2) + INT_CONST (0) + INT_CONST (4) + INT_CONST (2) + INT_CONST (0) + INT_CONST (1) + INT_CONST (2) + FOR_STMT + DECL_STMT + SCALAR_TYPE (INT) + VAR (index_var_4) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (index_var_4) + INT_CONST (8) + ASSIGN_EXPR + VAR_EXPR + VAR (index_var_4) + PLUS_EXPR + VAR_EXPR + VAR (index_var_4) + INT_CONST (1) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + SQ_BKT_EXPR + VAR_EXPR + VAR (new_ranks_2) + SQ_BKT_EXPR + VAR_EXPR + VAR (roll_var_0) + VAR_EXPR + VAR (index_var_4) + PLUS_EXPR + SQ_BKT_EXPR + VAR_EXPR + VAR (new_ranks_2) + SQ_BKT_EXPR + VAR_EXPR + VAR (roll_var_1) + VAR_EXPR + VAR (index_var_4) + MUL_EXPR + SQ_BKT_EXPR + VAR_EXPR + VAR (roll_var_2) + VAR_EXPR + VAR (index_var_4) + SQ_BKT_EXPR + VAR_EXPR + VAR (old_ranks_1) + SQ_BKT_EXPR + VAR_EXPR + VAR (roll_var_3) + VAR_EXPR + VAR (index_var_4) +{ + int sum_0 = 0; + int roll_var_5[9] = {1, 3, 4, 2, 6, 8, 1, -2, 3}; + for (int index_var_6 = 0; index_var_6 < 9; index_var_6 = index_var_6 + 1) { + sum_0 = sum_0 + roll_var_5[index_var_6]; //from.roll.0 + } + int old_ranks_1[5]; + int new_ranks_2[5]; + int roll_var_0[8] = {0, 0, 1, 1, 2, 3, 3, 3}; + int roll_var_1[8] = {0, 0, 1, 1, 2, 3, 3, 3}; + int roll_var_2[8] = {4, 1, 5, 1, 1, 1, 2, 1}; + int roll_var_3[8] = {0, 2, 0, 4, 2, 0, 1, 2}; + for (int index_var_4 = 0; index_var_4 < 8; index_var_4 = index_var_4 + 1) { + new_ranks_2[roll_var_0[index_var_4]] = new_ranks_2[roll_var_1[index_var_4]] + (roll_var_2[index_var_4] * old_ranks_1[roll_var_3[index_var_4]]); //from.roll.1 } - return res_1; } - diff --git a/samples/outputs.var_names/sample28 b/samples/outputs.var_names/sample28 index 448a329..45ac78a 100644 --- a/samples/outputs.var_names/sample28 +++ b/samples/outputs.var_names/sample28 @@ -1,22 +1,98 @@ STMT_BLOCK DECL_STMT - SCALAR_TYPE (INT) - VAR (x_0) + SCALAR_TYPE (SHORT_INT) + VAR (a_0) NO_INITIALIZATION DECL_STMT - SCALAR_TYPE (INT) - VAR (y_1) + SCALAR_TYPE (UNSIGNED_SHORT_INT) + VAR (b_1) NO_INITIALIZATION DECL_STMT SCALAR_TYPE (INT) - VAR (var2) - PLUS_EXPR - VAR_EXPR - VAR (x_0) + VAR (c_2) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (UNSIGNED_INT) + VAR (d_3) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (LONG_INT) + VAR (e_4) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (UNSIGNED_LONG_INT) + VAR (f_5) + INT_CONST (5) + DECL_STMT + SCALAR_TYPE (LONG_LONG_INT) + VAR (g_6) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (UNSIGNED_LONG_LONG_INT) + VAR (h_7) + INT_CONST (4) + DECL_STMT + SCALAR_TYPE (CHAR) + VAR (i_8) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (UNSIGNED_CHAR) + VAR (j_9) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (FLOAT) + VAR (k_10) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (DOUBLE) + VAR (l_11) + NO_INITIALIZATION + DECL_STMT + POINTER_TYPE + SCALAR_TYPE (VOID) + VAR (m_12) + NO_INITIALIZATION + DECL_STMT + ARRAY_TYPE + SCALAR_TYPE (CHAR) + -1 + VAR (n_13) + STRING_CONST ("Hello world") + EXPR_STMT + ASSIGN_EXPR VAR_EXPR - VAR (y_1) + VAR (n_13) + STRING_CONST ("new string") + DECL_STMT + POINTER_TYPE + SCALAR_TYPE (CHAR) + VAR (o_14) + STRING_CONST ("Hello world") + DECL_STMT + SCALAR_TYPE (BOOL) + VAR (p_15) + INT_CONST (1) + DECL_STMT + SCALAR_TYPE (INT) + VAR (x_16) + INT_CONST (0) { - int x_0; - int y_1; - int var2 = x_0 + y_1; + short int a_0; + unsigned short int b_1; + int c_2; + unsigned int d_3; + long int e_4; + unsigned long int f_5 = 5ll; + long long int g_6; + unsigned long long int h_7 = 4ll; + char i_8; + unsigned char j_9; + float k_10; + double l_11; + void* m_12; + char n_13[] = "Hello world"; + n_13 = "new string"; + const char* const volatile o_14 = "Hello world"; + bool p_15 = 1; + int x_16 = 0; } diff --git a/samples/outputs.var_names/sample29 b/samples/outputs.var_names/sample29 index ab98c7f..e812ece 100644 --- a/samples/outputs.var_names/sample29 +++ b/samples/outputs.var_names/sample29 @@ -1,183 +1,32 @@ STMT_BLOCK DECL_STMT - SCALAR_TYPE (INT) - VAR (sum_0) - INT_CONST (0) - DECL_STMT - ARRAY_TYPE - SCALAR_TYPE (INT) - 9 - VAR (roll_var_5) - INITIALIZER_LIST_EXPR - INT_CONST (1) - INT_CONST (3) - INT_CONST (4) - INT_CONST (2) - INT_CONST (6) - INT_CONST (8) - INT_CONST (1) - INT_CONST (-2) - INT_CONST (3) - FOR_STMT - DECL_STMT - SCALAR_TYPE (INT) - VAR (index_var_6) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (index_var_6) - INT_CONST (9) + NAMED_TYPE (GraphT) + VAR (g_0) + NO_INITIALIZATION + EXPR_STMT ASSIGN_EXPR VAR_EXPR - VAR (index_var_6) + VAR (g_0) PLUS_EXPR VAR_EXPR - VAR (index_var_6) + VAR (g_0) INT_CONST (1) - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (sum_0) - PLUS_EXPR - VAR_EXPR - VAR (sum_0) - SQ_BKT_EXPR - VAR_EXPR - VAR (roll_var_5) - VAR_EXPR - VAR (index_var_6) DECL_STMT - ARRAY_TYPE + NAMED_TYPE (FooT) SCALAR_TYPE (INT) - 5 - VAR (old_ranks_1) + VAR (f_1) NO_INITIALIZATION - DECL_STMT - ARRAY_TYPE - SCALAR_TYPE (INT) - 5 - VAR (new_ranks_2) - NO_INITIALIZATION - DECL_STMT - ARRAY_TYPE - SCALAR_TYPE (INT) - 8 - VAR (roll_var_0) - INITIALIZER_LIST_EXPR - INT_CONST (0) - INT_CONST (0) - INT_CONST (1) - INT_CONST (1) - INT_CONST (2) - INT_CONST (3) - INT_CONST (3) - INT_CONST (3) - DECL_STMT - ARRAY_TYPE - SCALAR_TYPE (INT) - 8 - VAR (roll_var_1) - INITIALIZER_LIST_EXPR - INT_CONST (0) - INT_CONST (0) - INT_CONST (1) - INT_CONST (1) - INT_CONST (2) - INT_CONST (3) - INT_CONST (3) - INT_CONST (3) - DECL_STMT - ARRAY_TYPE - SCALAR_TYPE (INT) - 8 - VAR (roll_var_2) - INITIALIZER_LIST_EXPR - INT_CONST (4) - INT_CONST (1) - INT_CONST (5) - INT_CONST (1) - INT_CONST (1) - INT_CONST (1) - INT_CONST (2) - INT_CONST (1) - DECL_STMT - ARRAY_TYPE - SCALAR_TYPE (INT) - 8 - VAR (roll_var_3) - INITIALIZER_LIST_EXPR - INT_CONST (0) - INT_CONST (2) - INT_CONST (0) - INT_CONST (4) - INT_CONST (2) - INT_CONST (0) - INT_CONST (1) - INT_CONST (2) - FOR_STMT - DECL_STMT - SCALAR_TYPE (INT) - VAR (index_var_4) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (index_var_4) - INT_CONST (8) + EXPR_STMT ASSIGN_EXPR VAR_EXPR - VAR (index_var_4) + VAR (f_1) PLUS_EXPR VAR_EXPR - VAR (index_var_4) + VAR (f_1) INT_CONST (1) - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - SQ_BKT_EXPR - VAR_EXPR - VAR (new_ranks_2) - SQ_BKT_EXPR - VAR_EXPR - VAR (roll_var_0) - VAR_EXPR - VAR (index_var_4) - PLUS_EXPR - SQ_BKT_EXPR - VAR_EXPR - VAR (new_ranks_2) - SQ_BKT_EXPR - VAR_EXPR - VAR (roll_var_1) - VAR_EXPR - VAR (index_var_4) - MUL_EXPR - SQ_BKT_EXPR - VAR_EXPR - VAR (roll_var_2) - VAR_EXPR - VAR (index_var_4) - SQ_BKT_EXPR - VAR_EXPR - VAR (old_ranks_1) - SQ_BKT_EXPR - VAR_EXPR - VAR (roll_var_3) - VAR_EXPR - VAR (index_var_4) { - int sum_0 = 0; - int roll_var_5[9] = {1, 3, 4, 2, 6, 8, 1, -2, 3}; - for (int index_var_6 = 0; index_var_6 < 9; index_var_6 = index_var_6 + 1) { - sum_0 = sum_0 + roll_var_5[index_var_6]; //from.roll.0 - } - int old_ranks_1[5]; - int new_ranks_2[5]; - int roll_var_0[8] = {0, 0, 1, 1, 2, 3, 3, 3}; - int roll_var_1[8] = {0, 0, 1, 1, 2, 3, 3, 3}; - int roll_var_2[8] = {4, 1, 5, 1, 1, 1, 2, 1}; - int roll_var_3[8] = {0, 2, 0, 4, 2, 0, 1, 2}; - for (int index_var_4 = 0; index_var_4 < 8; index_var_4 = index_var_4 + 1) { - new_ranks_2[roll_var_0[index_var_4]] = new_ranks_2[roll_var_1[index_var_4]] + (roll_var_2[index_var_4] * old_ranks_1[roll_var_3[index_var_4]]); //from.roll.1 - } + GraphT g_0; + g_0 = g_0 + 1; + FooT f_1; + f_1 = f_1 + 1; } diff --git a/samples/outputs.var_names/sample30 b/samples/outputs.var_names/sample30 index 45ac78a..55d3241 100644 --- a/samples/outputs.var_names/sample30 +++ b/samples/outputs.var_names/sample30 @@ -1,98 +1,52 @@ -STMT_BLOCK - DECL_STMT - SCALAR_TYPE (SHORT_INT) - VAR (a_0) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (UNSIGNED_SHORT_INT) - VAR (b_1) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (INT) - VAR (c_2) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (UNSIGNED_INT) - VAR (d_3) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (LONG_INT) - VAR (e_4) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (UNSIGNED_LONG_INT) - VAR (f_5) - INT_CONST (5) - DECL_STMT - SCALAR_TYPE (LONG_LONG_INT) - VAR (g_6) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (UNSIGNED_LONG_LONG_INT) - VAR (h_7) - INT_CONST (4) - DECL_STMT - SCALAR_TYPE (CHAR) - VAR (i_8) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (UNSIGNED_CHAR) - VAR (j_9) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (FLOAT) - VAR (k_10) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (DOUBLE) - VAR (l_11) - NO_INITIALIZATION - DECL_STMT - POINTER_TYPE - SCALAR_TYPE (VOID) - VAR (m_12) - NO_INITIALIZATION - DECL_STMT - ARRAY_TYPE - SCALAR_TYPE (CHAR) - -1 - VAR (n_13) - STRING_CONST ("Hello world") - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (n_13) - STRING_CONST ("new string") - DECL_STMT - POINTER_TYPE - SCALAR_TYPE (CHAR) - VAR (o_14) - STRING_CONST ("Hello world") - DECL_STMT - SCALAR_TYPE (BOOL) - VAR (p_15) - INT_CONST (1) - DECL_STMT - SCALAR_TYPE (INT) - VAR (x_16) - INT_CONST (0) -{ - short int a_0; - unsigned short int b_1; - int c_2; - unsigned int d_3; - long int e_4; - unsigned long int f_5 = 5ll; - long long int g_6; - unsigned long long int h_7 = 4ll; - char i_8; - unsigned char j_9; - float k_10; - double l_11; - void* m_12; - char n_13[] = "Hello world"; - n_13 = "new string"; - const char* const volatile o_14 = "Hello world"; - bool p_15 = 1; - int x_16 = 0; +FUNC_DECL (bar) + SCALAR_TYPE (VOID) + STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (x_0) + INT_CONST (5) + FOR_STMT + DECL_STMT + SCALAR_TYPE (INT) + VAR (i_1) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (i_1) + INT_CONST (100) + ASSIGN_EXPR + VAR_EXPR + VAR (i_1) + PLUS_EXPR + VAR_EXPR + VAR (i_1) + INT_CONST (1) + STMT_BLOCK + IF_STMT + NOT_EXPR + EQUALS_EXPR + VAR_EXPR + VAR (i_1) + VAR_EXPR + VAR (x_0) + STMT_BLOCK + CONTINUE_STMT + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (x_0) + VAR_EXPR + VAR (i_1) + BREAK_STMT +void bar (void) { + int x_0 = 5; + for (int i_1 = 0; i_1 < 100; i_1 = i_1 + 1) { + if (!(i_1 == x_0)) { + continue; + } + x_0 = i_1; + break; + } } + diff --git a/samples/outputs.var_names/sample31 b/samples/outputs.var_names/sample31 index 1d6d6aa..dda3d27 100644 --- a/samples/outputs.var_names/sample31 +++ b/samples/outputs.var_names/sample31 @@ -1,35 +1,48 @@ -FUNC_DECL (func1) - SCALAR_TYPE (INT) - VAR (arg0) +FUNC_DECL (bar) + SCALAR_TYPE (VOID) STMT_BLOCK - DECL_STMT - NAMED_TYPE (foo) - VAR (z_0) - PLUS_EXPR - PLUS_EXPR - INT_CONST (3) - MEMBER_ACCESS_EXPR (var1) - VAR_EXPR - VAR (arg0) - MUL_EXPR - INT_CONST (5) - MEMBER_ACCESS_EXPR (var1) - VAR_EXPR - VAR (arg0) DECL_STMT SCALAR_TYPE (INT) - VAR (var1) - PLUS_EXPR - MEMBER_ACCESS_EXPR (neighbor) + VAR (i_0) + INT_CONST (0) + FOR_STMT + EXPR_STMT + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (i_0) + INT_CONST (100) + ASSIGN_EXPR + VAR_EXPR + VAR (i_0) + PLUS_EXPR + VAR_EXPR + VAR (i_0) + INT_CONST (1) + STMT_BLOCK + FOR_STMT + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (i_0) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (i_0) + INT_CONST (100) + ASSIGN_EXPR + VAR_EXPR + VAR (i_0) + PLUS_EXPR VAR_EXPR - VAR (z_0) - INT_CONST (2) - RETURN_STMT - VAR_EXPR - VAR (var1) -int func1 (foo arg0) { - foo z_0 = 3 + arg0.var1 + 5 * arg0.var1; - int var1 = z_0.neighbor + 2; - return var1; + VAR (i_0) + INT_CONST (1) + STMT_BLOCK +void bar (void) { + int i_0 = 0; + for (0; i_0 < 100; i_0 = i_0 + 1) { + } + for (i_0 = 0; i_0 < 100; i_0 = i_0 + 1) { + } } diff --git a/samples/outputs.var_names/sample32 b/samples/outputs.var_names/sample32 index e812ece..dce60d4 100644 --- a/samples/outputs.var_names/sample32 +++ b/samples/outputs.var_names/sample32 @@ -1,32 +1 @@ -STMT_BLOCK - DECL_STMT - NAMED_TYPE (GraphT) - VAR (g_0) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (g_0) - PLUS_EXPR - VAR_EXPR - VAR (g_0) - INT_CONST (1) - DECL_STMT - NAMED_TYPE (FooT) - SCALAR_TYPE (INT) - VAR (f_1) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (f_1) - PLUS_EXPR - VAR_EXPR - VAR (f_1) - INT_CONST (1) -{ - GraphT g_0; - g_0 = g_0 + 1; - FooT f_1; - f_1 = f_1 + 1; -} +32768 diff --git a/samples/outputs.var_names/sample33 b/samples/outputs.var_names/sample33 index 1570ed9..afcf303 100644 --- a/samples/outputs.var_names/sample33 +++ b/samples/outputs.var_names/sample33 @@ -1,54 +1,29 @@ -STMT_BLOCK - DECL_STMT - NAMED_TYPE (FooT) - VAR (g_0) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (g_0) - PLUS_EXPR - VAR_EXPR - VAR (g_0) - INT_CONST (1) - DECL_STMT - SCALAR_TYPE (INT) - VAR (x_1) - MEMBER_ACCESS_EXPR (member) - VAR_EXPR - VAR (g_0) - DECL_STMT - NAMED_TYPE (FooT) - VAR (h_2) - VAR_EXPR - VAR (g_0) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (h_2) - VAR_EXPR - VAR (g_0) - DECL_STMT - POINTER_TYPE - NAMED_TYPE (FooT) - VAR (ptr_3) - ADDR_OF_EXPR - VAR_EXPR - VAR (g_0) - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (member) - SQ_BKT_EXPR - VAR_EXPR - VAR (ptr_3) - INT_CONST (0) - INT_CONST (0) -{ - FooT g_0; - g_0 = g_0 + 1; - int x_1 = g_0.member; - FooT h_2 = g_0; - h_2 = g_0; - FooT* ptr_3 = &g_0; - ptr_3[0].member = 0; +void __global__ cuda_kernel_0 (int* arg0) { + int thread_id_2 = blockIdx.x * 512 + threadIdx.x; + arg0[thread_id_2] = 0; } + +void __global__ cuda_kernel_1 (int* arg0) { + int thread_id_5 = blockIdx.x * 512 + threadIdx.x; + arg0[thread_id_5] = 0; +} + +char ret_2_0[sizeof(int*)] __device__; +void __global__ cuda_kernel_2 (int* arg0) { + int thread_id_8 = blockIdx.x * 512 + threadIdx.x; + arg0[thread_id_8] = 0; + if (!(blockIdx.x * blockDim.x + threadIdx.x)) { + runtime::cudaMemcpyToSymbolMagic(ret_2_0, arg0); + } +} + +void bar (int* arg0) { + cuda_kernel_0<<<128, 512>>>(arg0); + cudaDeviceSynchronize(); + runtime::LaunchCooperativeKernel((void*)cuda_kernel_1, 128, 512, arg0); + cudaDeviceSynchronize(); + runtime::LaunchCooperativeKernel((void*)cuda_kernel_2, 128, 512, arg0); + cudaDeviceSynchronize(); + runtime::cudaMemcpyFromSymbolMagic(&arg0, ret_2_0); +} + diff --git a/samples/outputs.var_names/sample34 b/samples/outputs.var_names/sample34 index 55d3241..7bd7771 100644 --- a/samples/outputs.var_names/sample34 +++ b/samples/outputs.var_names/sample34 @@ -1,52 +1,69 @@ -FUNC_DECL (bar) - SCALAR_TYPE (VOID) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (x_0) - INT_CONST (5) - FOR_STMT - DECL_STMT - SCALAR_TYPE (INT) - VAR (i_1) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (i_1) - INT_CONST (100) - ASSIGN_EXPR - VAR_EXPR - VAR (i_1) - PLUS_EXPR +STMT_BLOCK + DECL_STMT + NAMED_TYPE (FooT) + VAR (g_0) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (INT) + VAR (x_1) + MEMBER_ACCESS_EXPR (member) + VAR_EXPR + VAR (g_0) + DECL_STMT + NAMED_TYPE (FooT) + VAR (h_2) + VAR_EXPR + VAR (g_0) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (h_2) + VAR_EXPR + VAR (g_0) + DECL_STMT + POINTER_TYPE + NAMED_TYPE (FooT) + VAR (ptr_3) + ADDR_OF_EXPR + VAR_EXPR + VAR (g_0) + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (member) + SQ_BKT_EXPR VAR_EXPR - VAR (i_1) - INT_CONST (1) - STMT_BLOCK - IF_STMT - NOT_EXPR - EQUALS_EXPR - VAR_EXPR - VAR (i_1) - VAR_EXPR - VAR (x_0) - STMT_BLOCK - CONTINUE_STMT - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (x_0) - VAR_EXPR - VAR (i_1) - BREAK_STMT -void bar (void) { - int x_0 = 5; - for (int i_1 = 0; i_1 < 100; i_1 = i_1 + 1) { - if (!(i_1 == x_0)) { - continue; - } - x_0 = i_1; - break; - } + VAR (ptr_3) + INT_CONST (0) + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (member) + SQ_BKT_EXPR + VAR_EXPR + VAR (ptr_3) + INT_CONST (0) + INT_CONST (1) + DECL_STMT + NAMED_TYPE (FooT) + VAR (i_4) + SQ_BKT_EXPR + VAR_EXPR + VAR (ptr_3) + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (member) + VAR_EXPR + VAR (i_4) + INT_CONST (3) +{ + FooT g_0; + int x_1 = g_0.member; + FooT h_2 = g_0; + h_2 = g_0; + FooT* ptr_3 = &g_0; + ptr_3->member = 0; + ptr_3->member = 1; + FooT i_4 = *ptr_3; + i_4.member = 3; } - diff --git a/samples/outputs.var_names/sample35 b/samples/outputs.var_names/sample35 deleted file mode 100644 index dda3d27..0000000 --- a/samples/outputs.var_names/sample35 +++ /dev/null @@ -1,48 +0,0 @@ -FUNC_DECL (bar) - SCALAR_TYPE (VOID) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (i_0) - INT_CONST (0) - FOR_STMT - EXPR_STMT - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (i_0) - INT_CONST (100) - ASSIGN_EXPR - VAR_EXPR - VAR (i_0) - PLUS_EXPR - VAR_EXPR - VAR (i_0) - INT_CONST (1) - STMT_BLOCK - FOR_STMT - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (i_0) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (i_0) - INT_CONST (100) - ASSIGN_EXPR - VAR_EXPR - VAR (i_0) - PLUS_EXPR - VAR_EXPR - VAR (i_0) - INT_CONST (1) - STMT_BLOCK -void bar (void) { - int i_0 = 0; - for (0; i_0 < 100; i_0 = i_0 + 1) { - } - for (i_0 = 0; i_0 < 100; i_0 = i_0 + 1) { - } -} - diff --git a/samples/outputs.var_names/sample36 b/samples/outputs.var_names/sample36 index dce60d4..389c44c 100644 --- a/samples/outputs.var_names/sample36 +++ b/samples/outputs.var_names/sample36 @@ -1 +1,41 @@ -32768 +#include +int match_re (char* arg0) { + int str_len_0 = strlen(arg0); + int to_match_1 = 0; + if (to_match_1 < str_len_0) { + if (arg0[to_match_1] == 97) { + to_match_1 = to_match_1 + 1; + label0: + if (to_match_1 < str_len_0) { + if (arg0[to_match_1] == 98) { + to_match_1 = to_match_1 + 1; + goto label0; + } + if (arg0[to_match_1] == 99) { + label1: + to_match_1 = to_match_1 + 1; + if (to_match_1 < str_len_0) { + if (arg0[to_match_1] == 99) { + goto label1; + } + if (arg0[to_match_1] == 100) { + label2: + to_match_1 = to_match_1 + 1; + if (to_match_1 < str_len_0) { + label3: + return 0; + } + return 1; + } + } + } else { + if (arg0[to_match_1] == 100) { + goto label2; + } + } + } + } + } + goto label3; +} + diff --git a/samples/outputs.var_names/sample37 b/samples/outputs.var_names/sample37 index afcf303..7ed6ff8 100644 --- a/samples/outputs.var_names/sample37 +++ b/samples/outputs.var_names/sample37 @@ -1,29 +1 @@ -void __global__ cuda_kernel_0 (int* arg0) { - int thread_id_2 = blockIdx.x * 512 + threadIdx.x; - arg0[thread_id_2] = 0; -} - -void __global__ cuda_kernel_1 (int* arg0) { - int thread_id_5 = blockIdx.x * 512 + threadIdx.x; - arg0[thread_id_5] = 0; -} - -char ret_2_0[sizeof(int*)] __device__; -void __global__ cuda_kernel_2 (int* arg0) { - int thread_id_8 = blockIdx.x * 512 + threadIdx.x; - arg0[thread_id_8] = 0; - if (!(blockIdx.x * blockDim.x + threadIdx.x)) { - runtime::cudaMemcpyToSymbolMagic(ret_2_0, arg0); - } -} - -void bar (int* arg0) { - cuda_kernel_0<<<128, 512>>>(arg0); - cudaDeviceSynchronize(); - runtime::LaunchCooperativeKernel((void*)cuda_kernel_1, 128, 512, arg0); - cudaDeviceSynchronize(); - runtime::LaunchCooperativeKernel((void*)cuda_kernel_2, 128, 512, arg0); - cudaDeviceSynchronize(); - runtime::cudaMemcpyFromSymbolMagic(&arg0, ret_2_0); -} - +5 diff --git a/samples/outputs.var_names/sample38 b/samples/outputs.var_names/sample38 index 04e0bbc..b1787a7 100644 --- a/samples/outputs.var_names/sample38 +++ b/samples/outputs.var_names/sample38 @@ -1,78 +1,13 @@ -STMT_BLOCK - DECL_STMT - NAMED_TYPE (FooT) - VAR (g_0) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (g_0) - PLUS_EXPR - VAR_EXPR - VAR (g_0) - INT_CONST (1) - DECL_STMT - SCALAR_TYPE (INT) - VAR (x_1) - MEMBER_ACCESS_EXPR (member) - VAR_EXPR - VAR (g_0) - DECL_STMT - NAMED_TYPE (FooT) - VAR (h_2) - VAR_EXPR - VAR (g_0) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (h_2) - VAR_EXPR - VAR (g_0) - DECL_STMT - POINTER_TYPE - NAMED_TYPE (FooT) - VAR (ptr_3) - ADDR_OF_EXPR - VAR_EXPR - VAR (g_0) - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (member) - SQ_BKT_EXPR - VAR_EXPR - VAR (ptr_3) - INT_CONST (0) - INT_CONST (0) - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (member) - SQ_BKT_EXPR - VAR_EXPR - VAR (ptr_3) - INT_CONST (0) - INT_CONST (1) - DECL_STMT - NAMED_TYPE (FooT) - VAR (i_4) - SQ_BKT_EXPR - VAR_EXPR - VAR (ptr_3) - INT_CONST (0) - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (member) - VAR_EXPR - VAR (i_4) - INT_CONST (3) -{ - FooT g_0; - g_0 = g_0 + 1; - int x_1 = g_0.member; - FooT h_2 = g_0; - h_2 = g_0; - FooT* ptr_3 = &g_0; - ptr_3->member = 0; - ptr_3->member = 1; - FooT i_4 = *ptr_3; - i_4.member = 3; +void bar (void) { + int y_0[10] = 0; + for (int x_1 = 0; x_1 < 10; x_1 = x_1 + 1) { + *y_0 = *y_0 + x_1; + y_0[x_1] = y_0[x_1] * 2; + } + for (int x_2 = 0; x_2 < 10; (x_2 = x_2 + 1) - 1) { + *y_0 = *y_0 - x_2; + y_0[x_2] = y_0[x_2] / 2; + } + (*y_0 = *y_0 + 1) - 1; } + diff --git a/samples/outputs.var_names/sample39 b/samples/outputs.var_names/sample39 new file mode 100644 index 0000000..91de929 --- /dev/null +++ b/samples/outputs.var_names/sample39 @@ -0,0 +1,50 @@ +void foo (void) { + int var0; + int var1; + int var2; + var0 = 1; + var1 = var0 + 2; + var2 = var1 + var0; + int var3 = 0; + int var4 = var0 + 4; + int var5 = 0; + int var6 = 0; + int var7 = 1; + int var8 = 2; + int var9; + int var10; + int var11 = var3; + int var12 = var4; + int var13 = var5; + int var14 = var6; + int var15 = var9; + int var16 = var10; + int var17; + int var18; + int var19; + int var20; + int* var21; + var20 = 0; + int var22; + int* var23; + var22 = 0; + int var24; + int* var25; + var24 = 0; + int var26; + int* var27; + var26 = 0; + int var28; + int* var29; + var28 = 0; + var21 = &var22; + int var30 = var20; + int* var31 = var21; + int var32 = var22; + int* var33 = var23; + int var34 = var30; + int* var35 = var31; + int var36 = var32; + int* var37 = var33; +} + diff --git a/samples/outputs.var_names/sample40 b/samples/outputs.var_names/sample40 index 49d4436..4ee9458 100644 --- a/samples/outputs.var_names/sample40 +++ b/samples/outputs.var_names/sample40 @@ -1,53 +1,35 @@ -#include -int match_re (char* arg0) { - int var2; - int var4; - int str_len_0 = strlen(arg0); - int to_match_1 = 0; - if (to_match_1 < str_len_0) { - if (arg0[to_match_1] == 97) { - to_match_1 = to_match_1 + 1; - label0: - if (to_match_1 < str_len_0) { - if (arg0[to_match_1] == 98) { - to_match_1 = to_match_1 + 1; - goto label0; - } - if (arg0[to_match_1] == 99) { - label1: - to_match_1 = to_match_1 + 1; - if (to_match_1 < str_len_0) { - if (arg0[to_match_1] == 99) { - goto label1; - } - if (arg0[to_match_1] == 100) { - label2: - to_match_1 = to_match_1 + 1; - if (to_match_1 < str_len_0) { - var2 = 0; - return var2; - } - return 1; - } - var2 = 0; - return var2; - } - var4 = 0; - return var4; - } - if (arg0[to_match_1] == 100) { - goto label2; - } - var2 = 0; - return var2; - } - var4 = 0; - return var4; - } - var2 = 0; - return var2; +void staged (void) { + int var0 = 24; + if (var0) { } - var4 = 0; - return var4; + int var1 = 0; + var1 != 1; + int var2 = 32; + if (var2) { + } + int var3 = 0; + var1 != 1 && var3 != 1; +} + +void staged2 (void) { + int a_0 = 0; + for (int i_1 = 0; i_1 < 5; i_1 = i_1 + 1) { + a_0 = a_0 + 1; + } + int b_2 = a_0; + for (int i_3 = 0; i_3 < a_0; i_3 = i_3 + 1) { + b_2 = b_2 + 1; + } +} + +void staged2 (void) { + int a_0 = 0; + for (int i_1 = 0; i_1 < 5; i_1 = i_1 + 1) { + a_0 = a_0 + 1; + } + int b_2 = a_0; + for (int i_3 = 0; i_3 < a_0; i_3 = i_3 + 1) { + b_2 = b_2 + 1; + } } diff --git a/samples/outputs.var_names/sample41 b/samples/outputs.var_names/sample41 index 7ed6ff8..ac31407 100644 --- a/samples/outputs.var_names/sample41 +++ b/samples/outputs.var_names/sample41 @@ -1 +1,26 @@ -5 +a +bb +ccc +dddd +eeeee +ffffff +ggggggg +hhhhhhhh +iiiiiiiii +jjjjjjjjjj +kkkkkkkkkkk +llllllllllll +mmmmmmmmmmmmm +nnnnnnnnnnnnnn +ooooooooooooooo +pppppppppppppppp +qqqqqqqqqqqqqqqqq +rrrrrrrrrrrrrrrrrr +sssssssssssssssssss +tttttttttttttttttttt +uuuuuuuuuuuuuuuuuuuuu +vvvvvvvvvvvvvvvvvvvvvv +wwwwwwwwwwwwwwwwwwwwwww +xxxxxxxxxxxxxxxxxxxxxxxx +yyyyyyyyyyyyyyyyyyyyyyyyy +zzzzzzzzzzzzzzzzzzzzzzzzzz diff --git a/samples/outputs.var_names/sample42 b/samples/outputs.var_names/sample42 index b1787a7..9f64e87 100644 --- a/samples/outputs.var_names/sample42 +++ b/samples/outputs.var_names/sample42 @@ -1,13 +1,113 @@ -void bar (void) { - int y_0[10] = 0; - for (int x_1 = 0; x_1 < 10; x_1 = x_1 + 1) { - *y_0 = *y_0 + x_1; - y_0[x_1] = y_0[x_1] * 2; - } - for (int x_2 = 0; x_2 < 10; (x_2 = x_2 + 1) - 1) { - *y_0 = *y_0 - x_2; - y_0[x_2] = y_0[x_2] / 2; - } - (*y_0 = *y_0 + 1) - 1; +FUNC_DECL (my_bar) + SCALAR_TYPE (VOID) + STMT_BLOCK + DECL_STMT + NAMED_TYPE (FooT) + VAR (g_0) + NO_INITIALIZATION + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (g_0) + PLUS_EXPR + VAR_EXPR + VAR (g_0) + INT_CONST (1) + DECL_STMT + SCALAR_TYPE (INT) + VAR (x_1) + MEMBER_ACCESS_EXPR (member) + VAR_EXPR + VAR (g_0) + DECL_STMT + NAMED_TYPE (FooT) + VAR (h_2) + VAR_EXPR + VAR (g_0) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (h_2) + VAR_EXPR + VAR (g_0) + DECL_STMT + NAMED_TYPE (BarT) + VAR (f_3) + NO_INITIALIZATION + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (second_member) + VAR_EXPR + VAR (f_3) + PLUS_EXPR + VAR_EXPR + VAR (g_0) + INT_CONST (1) + DECL_STMT + NAMED_TYPE (CarT) + SCALAR_TYPE (INT) + NAMED_TYPE (BarT) + VAR (l_4) + NO_INITIALIZATION + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (my_member) + VAR_EXPR + VAR (l_4) + MEMBER_ACCESS_EXPR (member) + VAR_EXPR + VAR (g_0) + DECL_STMT + POINTER_TYPE + NAMED_TYPE (FooT) + VAR (i_5) + NO_INITIALIZATION + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (member) + SQ_BKT_EXPR + VAR_EXPR + VAR (i_5) + INT_CONST (0) + MEMBER_ACCESS_EXPR (my_member) + VAR_EXPR + VAR (l_4) + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (member) + SQ_BKT_EXPR + VAR_EXPR + VAR (i_5) + INT_CONST (0) + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (member) + SQ_BKT_EXPR + VAR_EXPR + VAR (i_5) + INT_CONST (3) + INT_CONST (0) +struct FooT { + int member; +}; +struct BarT { + int my_member; + int second_member; +}; +void my_bar (void) { + FooT g_0; + g_0 = g_0 + 1; + int x_1 = g_0.member; + FooT h_2 = g_0; + h_2 = g_0; + BarT f_3; + f_3.second_member = g_0 + 1; + CarT l_4; + l_4.my_member = g_0.member; + FooT* i_5; + i_5->member = l_4.my_member; + i_5->member = 0; + i_5[3].member = 0; } diff --git a/samples/outputs.var_names/sample43 b/samples/outputs.var_names/sample43 index 91de929..6a9b7a5 100644 --- a/samples/outputs.var_names/sample43 +++ b/samples/outputs.var_names/sample43 @@ -1,50 +1,86 @@ -void foo (void) { - int var0; - int var1; - int var2; - var0 = 1; - var1 = var0 + 2; - var2 = var1 + var0; - int var3 = 0; - int var4 = var0 + 4; - int var5 = 0; - int var6 = 0; - int var7 = 1; - int var8 = 2; - int var9; - int var10; - int var11 = var3; - int var12 = var4; - int var13 = var5; - int var14 = var6; - int var15 = var9; - int var16 = var10; - int var17; - int var18; - int var19; - int var20; - int* var21; - var20 = 0; - int var22; - int* var23; - var22 = 0; - int var24; - int* var25; - var24 = 0; - int var26; - int* var27; - var26 = 0; - int var28; - int* var29; - var28 = 0; - var21 = &var22; - int var30 = var20; - int* var31 = var21; - int var32 = var22; - int* var33 = var23; - int var34 = var30; - int* var35 = var31; - int var36 = var32; - int* var37 = var33; +FUNC_DECL (my_bar) + SCALAR_TYPE (VOID) + STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (c_0) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (c_1) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (c_2) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (c_3) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (c_4) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (c_5) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (c_6) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (c_7) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (c_8) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (c_9) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (c_10) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (c_11) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (c_12) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (c_13) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (c_14) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (c_15) + INT_CONST (0) +void my_bar (void) { + int c_0 = 0; + int c_1 = 0; + int c_2 = 0; + int c_3 = 0; + int c_4 = 0; + int c_5 = 0; + int c_6 = 0; + int c_7 = 0; + int c_8 = 0; + int c_9 = 0; + int c_10 = 0; + int c_11 = 0; + int c_12 = 0; + int c_13 = 0; + int c_14 = 0; + int c_15 = 0; } diff --git a/samples/outputs.var_names/sample44 b/samples/outputs.var_names/sample44 index 4ee9458..b11f060 100644 --- a/samples/outputs.var_names/sample44 +++ b/samples/outputs.var_names/sample44 @@ -1,35 +1,42 @@ -void staged (void) { - int var0 = 24; - if (var0) { - } +FUNC_DECL (my_bar) + SCALAR_TYPE (VOID) + STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (x_0) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (INT) + VAR (var1) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var2) + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var1) + INT_CONST (1) + WHILE_STMT + INT_CONST (1) + STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (var3) + INT_CONST (1) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var4) + INT_CONST (2) +void my_bar (void) { + int x_0; int var1 = 0; - var1 != 1; - int var2 = 32; - if (var2) { - } - int var3 = 0; - var1 != 1 && var3 != 1; -} - -void staged2 (void) { - int a_0 = 0; - for (int i_1 = 0; i_1 < 5; i_1 = i_1 + 1) { - a_0 = a_0 + 1; - } - int b_2 = a_0; - for (int i_3 = 0; i_3 < a_0; i_3 = i_3 + 1) { - b_2 = b_2 + 1; - } -} - -void staged2 (void) { - int a_0 = 0; - for (int i_1 = 0; i_1 < 5; i_1 = i_1 + 1) { - a_0 = a_0 + 1; - } - int b_2 = a_0; - for (int i_3 = 0; i_3 < a_0; i_3 = i_3 + 1) { - b_2 = b_2 + 1; + int var2 = 0; + var1 = 1; + while (1) { + int var3 = 1; + int var4 = 2; } } diff --git a/samples/outputs.var_names/sample45 b/samples/outputs.var_names/sample45 index ac31407..5065023 100644 --- a/samples/outputs.var_names/sample45 +++ b/samples/outputs.var_names/sample45 @@ -1,26 +1,23 @@ -a -bb -ccc -dddd -eeeee -ffffff -ggggggg -hhhhhhhh -iiiiiiiii -jjjjjjjjjj -kkkkkkkkkkk -llllllllllll -mmmmmmmmmmmmm -nnnnnnnnnnnnnn -ooooooooooooooo -pppppppppppppppp -qqqqqqqqqqqqqqqqq -rrrrrrrrrrrrrrrrrr -sssssssssssssssssss -tttttttttttttttttttt -uuuuuuuuuuuuuuuuuuuuu -vvvvvvvvvvvvvvvvvvvvvv -wwwwwwwwwwwwwwwwwwwwwww -xxxxxxxxxxxxxxxxxxxxxxxx -yyyyyyyyyyyyyyyyyyyyyyyyy -zzzzzzzzzzzzzzzzzzzzzzzzzz +FUNC_DECL (foo) + SCALAR_TYPE (VOID) + STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (my_var) + NO_INITIALIZATION + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (my_var) + INT_CONST (1) + DECL_STMT + SCALAR_TYPE (INT) + VAR (y_0) + VAR_EXPR + VAR (my_var) +void foo (void) { + int my_var; + my_var = 1; + int y_0 = my_var; +} + diff --git a/samples/outputs.var_names/sample46 b/samples/outputs.var_names/sample46 index 9f64e87..0553108 100644 --- a/samples/outputs.var_names/sample46 +++ b/samples/outputs.var_names/sample46 @@ -1,113 +1,56 @@ -FUNC_DECL (my_bar) +FUNC_DECL (bar) SCALAR_TYPE (VOID) STMT_BLOCK - DECL_STMT - NAMED_TYPE (FooT) - VAR (g_0) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (g_0) - PLUS_EXPR - VAR_EXPR - VAR (g_0) - INT_CONST (1) DECL_STMT SCALAR_TYPE (INT) - VAR (x_1) - MEMBER_ACCESS_EXPR (member) - VAR_EXPR - VAR (g_0) - DECL_STMT - NAMED_TYPE (FooT) - VAR (h_2) - VAR_EXPR - VAR (g_0) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (h_2) - VAR_EXPR - VAR (g_0) - DECL_STMT - NAMED_TYPE (BarT) - VAR (f_3) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (second_member) - VAR_EXPR - VAR (f_3) - PLUS_EXPR - VAR_EXPR - VAR (g_0) - INT_CONST (1) - DECL_STMT - NAMED_TYPE (CarT) - SCALAR_TYPE (INT) - NAMED_TYPE (BarT) - VAR (l_4) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (my_member) - VAR_EXPR - VAR (l_4) - MEMBER_ACCESS_EXPR (member) - VAR_EXPR - VAR (g_0) + VAR (k_0) + INT_CONST (0) DECL_STMT - POINTER_TYPE - NAMED_TYPE (FooT) - VAR (i_5) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (member) - SQ_BKT_EXPR - VAR_EXPR - VAR (i_5) - INT_CONST (0) - MEMBER_ACCESS_EXPR (my_member) - VAR_EXPR - VAR (l_4) - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (member) - SQ_BKT_EXPR - VAR_EXPR - VAR (i_5) - INT_CONST (0) - INT_CONST (0) - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (member) - SQ_BKT_EXPR + SCALAR_TYPE (INT) + VAR (t_1) + INT_CONST (0) + WHILE_STMT + INT_CONST (1) + STMT_BLOCK + IF_STMT + NE_EXPR VAR_EXPR - VAR (i_5) - INT_CONST (3) - INT_CONST (0) -struct FooT { - int member; -}; -struct BarT { - int my_member; - int second_member; -}; -void my_bar (void) { - FooT g_0; - g_0 = g_0 + 1; - int x_1 = g_0.member; - FooT h_2 = g_0; - h_2 = g_0; - BarT f_3; - f_3.second_member = g_0 + 1; - CarT l_4; - l_4.my_member = g_0.member; - FooT* i_5; - i_5->member = l_4.my_member; - i_5->member = 0; - i_5[3].member = 0; + VAR (k_0) + INT_CONST (1) + STMT_BLOCK + IF_STMT + EQUALS_EXPR + VAR_EXPR + VAR (k_0) + INT_CONST (2) + STMT_BLOCK + WHILE_STMT + NE_EXPR + VAR_EXPR + VAR (k_0) + INT_CONST (3) + STMT_BLOCK + STMT_BLOCK + STMT_BLOCK + WHILE_STMT + NE_EXPR + VAR_EXPR + VAR (k_0) + INT_CONST (3) + STMT_BLOCK +void bar (void) { + int k_0 = 0; + int t_1 = 0; + while (1) { + if (k_0 != 1) { + if (k_0 == 2) { + while (k_0 != 3) { + } + } + } else { + while (k_0 != 3) { + } + } + } } diff --git a/samples/outputs.var_names/sample47 b/samples/outputs.var_names/sample47 index 6a9b7a5..37f0593 100644 --- a/samples/outputs.var_names/sample47 +++ b/samples/outputs.var_names/sample47 @@ -1,86 +1,125 @@ -FUNC_DECL (my_bar) +FUNC_DECL (bar) SCALAR_TYPE (VOID) STMT_BLOCK DECL_STMT SCALAR_TYPE (INT) - VAR (c_0) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (c_1) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (c_2) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (c_3) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (c_4) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (c_5) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (c_6) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (c_7) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (c_8) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (c_9) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (c_10) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (c_11) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (c_12) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (c_13) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (c_14) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (c_15) - INT_CONST (0) -void my_bar (void) { - int c_0 = 0; - int c_1 = 0; - int c_2 = 0; - int c_3 = 0; - int c_4 = 0; - int c_5 = 0; - int c_6 = 0; - int c_7 = 0; - int c_8 = 0; - int c_9 = 0; - int c_10 = 0; - int c_11 = 0; - int c_12 = 0; - int c_13 = 0; - int c_14 = 0; - int c_15 = 0; + VAR (x_0) + INT_CONST (5) + WHILE_STMT + LT_EXPR + VAR_EXPR + VAR (x_0) + INT_CONST (10) + STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (control_guard0) + INT_CONST (0) + WHILE_STMT + GT_EXPR + VAR_EXPR + VAR (x_0) + INT_CONST (100) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (control_guard0) + INT_CONST (0) + IF_STMT + EQUALS_EXPR + VAR_EXPR + VAR (x_0) + INT_CONST (0) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (x_0) + PLUS_EXPR + VAR_EXPR + VAR (x_0) + INT_CONST (5) + WHILE_STMT + NE_EXPR + VAR_EXPR + VAR (x_0) + INT_CONST (-1) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (x_0) + PLUS_EXPR + VAR_EXPR + VAR (x_0) + INT_CONST (6) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (control_guard0) + INT_CONST (1) + BREAK_STMT + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (x_0) + PLUS_EXPR + VAR_EXPR + VAR (x_0) + INT_CONST (4) + IF_STMT + VAR_EXPR + VAR (control_guard0) + STMT_BLOCK + CONTINUE_STMT + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (x_0) + PLUS_EXPR + VAR_EXPR + VAR (x_0) + INT_CONST (5) + WHILE_STMT + NE_EXPR + VAR_EXPR + VAR (x_0) + INT_CONST (-1) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (x_0) + PLUS_EXPR + VAR_EXPR + VAR (x_0) + INT_CONST (6) +void bar (void) { + int x_0 = 5; + while (x_0 < 10) { + int control_guard0 = 0; + while (x_0 > 100) { + control_guard0 = 0; + if (x_0 == 0) { + x_0 = x_0 + 5; + while (x_0 != -1) { + x_0 = x_0 + 6; + } + control_guard0 = 1; + break; + } + x_0 = x_0 + 4; + } + if (control_guard0) { + continue; + } + x_0 = x_0 + 5; + while (x_0 != -1) { + x_0 = x_0 + 6; + } + } } diff --git a/samples/outputs.var_names/sample48 b/samples/outputs.var_names/sample48 index b11f060..009efe3 100644 --- a/samples/outputs.var_names/sample48 +++ b/samples/outputs.var_names/sample48 @@ -1,42 +1,49 @@ -FUNC_DECL (my_bar) - SCALAR_TYPE (VOID) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (x_0) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (INT) - VAR (var1) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var2) - INT_CONST (0) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var1) - INT_CONST (1) - WHILE_STMT - INT_CONST (1) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (var3) - INT_CONST (1) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var4) - INT_CONST (2) -void my_bar (void) { - int x_0; - int var1 = 0; - int var2 = 0; - var1 = 1; - while (1) { - int var3 = 1; - int var4 = 2; - } +int isEven (int arg0) { + if (arg0 == 0) { + return 1; + } + if (arg0 == 1) { + return 0; + } + if (arg0 == 2) { + return 1; + } + if (arg0 == 3) { + return 0; + } + if (arg0 == 4) { + return 1; + } + if (arg0 == 5) { + return 0; + } + if (arg0 == 6) { + return 1; + } + if (arg0 == 7) { + return 0; + } + if (arg0 == 8) { + return 1; + } + if (arg0 == 9) { + return 0; + } + if (arg0 == 10) { + return 1; + } + if (arg0 == 11) { + return 0; + } + if (arg0 == 12) { + return 1; + } + if (arg0 == 13) { + return 0; + } + if (arg0 == 14) { + return 1; + } + return 0; } diff --git a/samples/outputs.var_names/sample49 b/samples/outputs.var_names/sample49 index 5065023..17addcd 100644 --- a/samples/outputs.var_names/sample49 +++ b/samples/outputs.var_names/sample49 @@ -1,23 +1,40 @@ -FUNC_DECL (foo) - SCALAR_TYPE (VOID) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (my_var) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (my_var) - INT_CONST (1) - DECL_STMT - SCALAR_TYPE (INT) - VAR (y_0) - VAR_EXPR - VAR (my_var) void foo (void) { - int my_var; - my_var = 1; - int y_0 = my_var; + int member_var; + int x_0 = 0; + if (x_0) { + member_var = 1; + } else { + member_var = 2; + } + if (member_var % 2 == 0) { + member_var = member_var + 0; + } + if (member_var % 2 == 0) { + member_var = member_var + 1; + } + if (member_var % 2 == 0) { + member_var = member_var + 2; + } + if (member_var % 2 == 0) { + member_var = member_var + 3; + } + if (member_var % 2 == 0) { + member_var = member_var + 4; + } + if (member_var % 2 == 0) { + member_var = member_var + 5; + } + if (member_var % 2 == 0) { + member_var = member_var + 6; + } + if (member_var % 2 == 0) { + member_var = member_var + 7; + } + if (member_var % 2 == 0) { + member_var = member_var + 8; + } + if (member_var % 2 == 0) { + member_var = member_var + 9; + } } diff --git a/samples/outputs.var_names/sample50 b/samples/outputs.var_names/sample50 index 0553108..4619aa8 100644 --- a/samples/outputs.var_names/sample50 +++ b/samples/outputs.var_names/sample50 @@ -1,56 +1,20 @@ -FUNC_DECL (bar) - SCALAR_TYPE (VOID) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (k_0) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (t_1) - INT_CONST (0) - WHILE_STMT - INT_CONST (1) - STMT_BLOCK - IF_STMT - NE_EXPR - VAR_EXPR - VAR (k_0) - INT_CONST (1) - STMT_BLOCK - IF_STMT - EQUALS_EXPR - VAR_EXPR - VAR (k_0) - INT_CONST (2) - STMT_BLOCK - WHILE_STMT - NE_EXPR - VAR_EXPR - VAR (k_0) - INT_CONST (3) - STMT_BLOCK - STMT_BLOCK - STMT_BLOCK - WHILE_STMT - NE_EXPR - VAR_EXPR - VAR (k_0) - INT_CONST (3) - STMT_BLOCK void bar (void) { - int k_0 = 0; - int t_1 = 0; - while (1) { - if (k_0 != 1) { - if (k_0 == 2) { - while (k_0 != 3) { - } - } - } else { - while (k_0 != 3) { - } - } + int y_0 = 0; + int m_1; + int n_2; + if (y_0) { + int z_3 = 1; + int& k_4 = m_1; + int b_5; + int a_6 = z_3; + z_3 = z_3 + k_4; + } else { + int z_7 = 2; + int& k_8 = m_1; + int b_9; + int a_10 = z_7; + z_7 = z_7 + k_8; } + m_1 = m_1 + 3; } diff --git a/samples/outputs.var_names/sample51 b/samples/outputs.var_names/sample51 index 37f0593..2a9664d 100644 --- a/samples/outputs.var_names/sample51 +++ b/samples/outputs.var_names/sample51 @@ -1,125 +1,9 @@ -FUNC_DECL (bar) - SCALAR_TYPE (VOID) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (x_0) - INT_CONST (5) - WHILE_STMT - LT_EXPR - VAR_EXPR - VAR (x_0) - INT_CONST (10) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (control_guard0) - INT_CONST (0) - WHILE_STMT - GT_EXPR - VAR_EXPR - VAR (x_0) - INT_CONST (100) - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (control_guard0) - INT_CONST (0) - IF_STMT - EQUALS_EXPR - VAR_EXPR - VAR (x_0) - INT_CONST (0) - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (x_0) - PLUS_EXPR - VAR_EXPR - VAR (x_0) - INT_CONST (5) - WHILE_STMT - NE_EXPR - VAR_EXPR - VAR (x_0) - INT_CONST (-1) - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (x_0) - PLUS_EXPR - VAR_EXPR - VAR (x_0) - INT_CONST (6) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (control_guard0) - INT_CONST (1) - BREAK_STMT - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (x_0) - PLUS_EXPR - VAR_EXPR - VAR (x_0) - INT_CONST (4) - IF_STMT - VAR_EXPR - VAR (control_guard0) - STMT_BLOCK - CONTINUE_STMT - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (x_0) - PLUS_EXPR - VAR_EXPR - VAR (x_0) - INT_CONST (5) - WHILE_STMT - NE_EXPR - VAR_EXPR - VAR (x_0) - INT_CONST (-1) - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (x_0) - PLUS_EXPR - VAR_EXPR - VAR (x_0) - INT_CONST (6) void bar (void) { - int x_0 = 5; - while (x_0 < 10) { - int control_guard0 = 0; - while (x_0 > 100) { - control_guard0 = 0; - if (x_0 == 0) { - x_0 = x_0 + 5; - while (x_0 != -1) { - x_0 = x_0 + 6; - } - control_guard0 = 1; - break; - } - x_0 = x_0 + 4; - } - if (control_guard0) { - continue; - } - x_0 = x_0 + 5; - while (x_0 != -1) { - x_0 = x_0 + 6; - } - } + int x_0; + char x_mem2_1; + int y_mem1_2; + char y_mem2_3; + x_0 = x_mem2_1; + y_mem2_3 = y_mem1_2; } diff --git a/samples/outputs.var_names/sample52 b/samples/outputs.var_names/sample52 index 009efe3..80566d6 100644 --- a/samples/outputs.var_names/sample52 +++ b/samples/outputs.var_names/sample52 @@ -1,49 +1,64 @@ -int isEven (int arg0) { - if (arg0 == 0) { - return 1; - } - if (arg0 == 1) { - return 0; - } - if (arg0 == 2) { - return 1; - } - if (arg0 == 3) { - return 0; - } - if (arg0 == 4) { - return 1; - } - if (arg0 == 5) { - return 0; - } - if (arg0 == 6) { - return 1; - } - if (arg0 == 7) { - return 0; - } - if (arg0 == 8) { - return 1; - } - if (arg0 == 9) { - return 0; - } - if (arg0 == 10) { - return 1; - } - if (arg0 == 11) { - return 0; - } - if (arg0 == 12) { - return 1; - } - if (arg0 == 13) { - return 0; - } - if (arg0 == 14) { - return 1; - } - return 0; +FUNC_DECL (bar) + SCALAR_TYPE (VOID) + STMT_BLOCK + DECL_STMT + NAMED_TYPE (my_type) + VAR (a_0) + NO_INITIALIZATION + DECL_STMT + NAMED_TYPE (custom_struct0) + VAR (b_1) + NO_INITIALIZATION + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (nested) + VAR_EXPR + VAR (a_0) + VAR_EXPR + VAR (b_1) + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (mem0) + MEMBER_ACCESS_EXPR (nested) + VAR_EXPR + VAR (a_0) + MEMBER_ACCESS_EXPR (mem0) + VAR_EXPR + VAR (a_0) + EXPR_STMT + MINUS_EXPR + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (mem1) + MEMBER_ACCESS_EXPR (nested) + VAR_EXPR + VAR (a_0) + PLUS_EXPR + MEMBER_ACCESS_EXPR (mem1) + MEMBER_ACCESS_EXPR (nested) + VAR_EXPR + VAR (a_0) + INT_CONST (1) + INT_CONST (1) + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (mem0) + VAR_EXPR + VAR (p) + INT_CONST (0) +struct custom_struct0 { + int mem0; + float mem1; +}; +struct my_type { + custom_struct0 nested; + int mem0; +}; +void bar (void) { + my_type a_0; + custom_struct0 b_1; + a_0.nested = b_1; + a_0.nested.mem0 = a_0.mem0; + (a_0.nested.mem1 = a_0.nested.mem1 + 1) - 1; + p.mem0 = 0; } diff --git a/samples/outputs.var_names/sample53 b/samples/outputs.var_names/sample53 index 17addcd..dda1c8c 100644 --- a/samples/outputs.var_names/sample53 +++ b/samples/outputs.var_names/sample53 @@ -1,40 +1,12 @@ -void foo (void) { - int member_var; +void bar (void) { int x_0 = 0; - if (x_0) { - member_var = 1; - } else { - member_var = 2; - } - if (member_var % 2 == 0) { - member_var = member_var + 0; - } - if (member_var % 2 == 0) { - member_var = member_var + 1; - } - if (member_var % 2 == 0) { - member_var = member_var + 2; - } - if (member_var % 2 == 0) { - member_var = member_var + 3; - } - if (member_var % 2 == 0) { - member_var = member_var + 4; - } - if (member_var % 2 == 0) { - member_var = member_var + 5; - } - if (member_var % 2 == 0) { - member_var = member_var + 6; - } - if (member_var % 2 == 0) { - member_var = member_var + 7; - } - if (member_var % 2 == 0) { - member_var = member_var + 8; - } - if (member_var % 2 == 0) { - member_var = member_var + 9; - } + int* y_1 = &x_0; + (*y_1 = *y_1 + 1) - 1; + int z_2 = 0; + (z_2 = z_2 + 1) - 1; + int a_3 = z_2; + (z_2 = z_2 + 1) - 1; + int b_4 = a_3; + (b_4 = b_4 + 1) - 1; } diff --git a/samples/outputs.var_names/sample54 b/samples/outputs.var_names/sample54 index 4619aa8..e3dc1d4 100644 --- a/samples/outputs.var_names/sample54 +++ b/samples/outputs.var_names/sample54 @@ -1,20 +1,12 @@ -void bar (void) { - int y_0 = 0; - int m_1; - int n_2; - if (y_0) { - int z_3 = 1; - int& k_4 = m_1; - int b_5; - int a_6 = z_3; - z_3 = z_3 + k_4; - } else { - int z_7 = 2; - int& k_8 = m_1; - int b_9; - int a_10 = z_7; - z_7 = z_7 + k_8; - } - m_1 = m_1 + 3; +FUNC_DECL (bar) + SCALAR_TYPE (VOID) + VAR (arg0) + STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (y_0) + NO_INITIALIZATION +void bar (int arg0) { + int y_0; } diff --git a/samples/outputs.var_names/sample55 b/samples/outputs.var_names/sample55 index 2a9664d..824b379 100644 --- a/samples/outputs.var_names/sample55 +++ b/samples/outputs.var_names/sample55 @@ -1,9 +1,29 @@ +FUNC_DECL (bar) + SCALAR_TYPE (VOID) + STMT_BLOCK + DECL_STMT + NAMED_TYPE (std::vector) + NAMED_TYPE (std::vector) + SCALAR_TYPE (INT) + VAR (x_0) + NO_INITIALIZATION + EXPR_STMT + FUNCTION_CALL_EXPR + MEMBER_ACCESS_EXPR (resize) + VAR_EXPR + VAR (x_0) + INT_CONST (2) + EXPR_STMT + FUNCTION_CALL_EXPR + MEMBER_ACCESS_EXPR (resize) + SQ_BKT_EXPR + VAR_EXPR + VAR (x_0) + INT_CONST (0) + INT_CONST (1) void bar (void) { - int x_0; - char x_mem2_1; - int y_mem1_2; - char y_mem2_3; - x_0 = x_mem2_1; - y_mem2_3 = y_mem1_2; + std::vector> x_0; + x_0.resize(2); + x_0[0].resize(1); } diff --git a/samples/outputs.var_names/sample56 b/samples/outputs.var_names/sample56 index 80566d6..0e0e65d 100644 --- a/samples/outputs.var_names/sample56 +++ b/samples/outputs.var_names/sample56 @@ -1,64 +1,22 @@ -FUNC_DECL (bar) - SCALAR_TYPE (VOID) - STMT_BLOCK - DECL_STMT - NAMED_TYPE (my_type) - VAR (a_0) - NO_INITIALIZATION - DECL_STMT - NAMED_TYPE (custom_struct0) - VAR (b_1) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (nested) - VAR_EXPR - VAR (a_0) - VAR_EXPR - VAR (b_1) - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (mem0) - MEMBER_ACCESS_EXPR (nested) - VAR_EXPR - VAR (a_0) - MEMBER_ACCESS_EXPR (mem0) - VAR_EXPR - VAR (a_0) - EXPR_STMT - MINUS_EXPR - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (mem1) - MEMBER_ACCESS_EXPR (nested) - VAR_EXPR - VAR (a_0) - PLUS_EXPR - MEMBER_ACCESS_EXPR (mem1) - MEMBER_ACCESS_EXPR (nested) - VAR_EXPR - VAR (a_0) - INT_CONST (1) - INT_CONST (1) - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (mem0) - VAR_EXPR - VAR (p) - INT_CONST (0) -struct custom_struct0 { - int mem0; - float mem1; -}; -struct my_type { - custom_struct0 nested; - int mem0; -}; void bar (void) { - my_type a_0; - custom_struct0 b_1; - a_0.nested = b_1; - a_0.nested.mem0 = a_0.mem0; - (a_0.nested.mem1 = a_0.nested.mem1 + 1) - 1; - p.mem0 = 0; + int x_0; + int a_2; + int b_3; + float m_4; + float n_5; + int res_8; + if (a_2 < b_3) { + res_8 = b_3; + } else { + res_8 = a_2; + } + float res_12; + if (m_4 < n_5) { + res_12 = n_5; + } else { + res_12 = m_4; + } + int* var14 = &x_0; + *var14 = 0; } diff --git a/samples/outputs.var_names/sample57 b/samples/outputs.var_names/sample57 index dda1c8c..1131b63 100644 --- a/samples/outputs.var_names/sample57 +++ b/samples/outputs.var_names/sample57 @@ -1,12 +1,5 @@ void bar (void) { - int x_0 = 0; - int* y_1 = &x_0; - (*y_1 = *y_1 + 1) - 1; - int z_2 = 0; - (z_2 = z_2 + 1) - 1; - int a_3 = z_2; - (z_2 = z_2 + 1) - 1; - int b_4 = a_3; - (b_4 = b_4 + 1) - 1; + int x_0 = 1; + int y_1 = 0; } diff --git a/samples/outputs.var_names/sample58 b/samples/outputs.var_names/sample58 index e3dc1d4..df4f84e 100644 --- a/samples/outputs.var_names/sample58 +++ b/samples/outputs.var_names/sample58 @@ -1,12 +1,73 @@ -FUNC_DECL (bar) +Found 1 matches +----- +ASSIGN_EXPR + VAR_EXPR + VAR (x_0) + PLUS_EXPR + VAR_EXPR + VAR (x_0) + INT_CONST (1) +----- +Found 1 matches +----- +PLUS_EXPR + VAR_EXPR + VAR (x_0) + INT_CONST (0) +----- +After all replacements +FUNC_DECL (foo) SCALAR_TYPE (VOID) - VAR (arg0) STMT_BLOCK DECL_STMT SCALAR_TYPE (INT) - VAR (y_0) - NO_INITIALIZATION -void bar (int arg0) { - int y_0; + VAR (x_0) + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (x_0) + PLUS_EXPR + VAR_EXPR + VAR (x_0) + INT_CONST (1) + DECL_STMT + SCALAR_TYPE (INT) + VAR (y_1) + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (y_1) + PLUS_EXPR + VAR_EXPR + VAR (x_0) + INT_CONST (1) + DECL_STMT + SCALAR_TYPE (INT) + VAR (z_2) + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (z_2) + PLUS_EXPR + VAR_EXPR + VAR (z_2) + INT_CONST (2) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (z_2) + VAR_EXPR + VAR (x_0) +void foo (void) { + int x_0 = 0; + x_0 = x_0 + 1; + int y_1 = 0; + y_1 = x_0 + 1; + int z_2 = 0; + z_2 = z_2 + 2; + z_2 = x_0; } diff --git a/samples/outputs.var_names/sample59 b/samples/outputs.var_names/sample59 index 824b379..1642289 100644 --- a/samples/outputs.var_names/sample59 +++ b/samples/outputs.var_names/sample59 @@ -1,29 +1,10 @@ -FUNC_DECL (bar) - SCALAR_TYPE (VOID) - STMT_BLOCK - DECL_STMT - NAMED_TYPE (std::vector) - NAMED_TYPE (std::vector) - SCALAR_TYPE (INT) - VAR (x_0) - NO_INITIALIZATION - EXPR_STMT - FUNCTION_CALL_EXPR - MEMBER_ACCESS_EXPR (resize) - VAR_EXPR - VAR (x_0) - INT_CONST (2) - EXPR_STMT - FUNCTION_CALL_EXPR - MEMBER_ACCESS_EXPR (resize) - SQ_BKT_EXPR - VAR_EXPR - VAR (x_0) - INT_CONST (0) - INT_CONST (1) +struct linked_list { + linked_list* next; + struct foo* other; +}; void bar (void) { - std::vector> x_0; - x_0.resize(2); - x_0[0].resize(1); + linked_list* x_0; + x_0->next->next->next = 0; + x_0->other = 0; } diff --git a/samples/outputs.var_names/sample60 b/samples/outputs.var_names/sample60 index 0e0e65d..c979100 100644 --- a/samples/outputs.var_names/sample60 +++ b/samples/outputs.var_names/sample60 @@ -1,22 +1,22 @@ -void bar (void) { - int x_0; - int a_2; - int b_3; - float m_4; - float n_5; - int res_8; - if (a_2 < b_3) { - res_8 = b_3; - } else { - res_8 = a_2; +int power (int arg0, int arg1) { + int exponent_0 = arg1; + int res_1 = 1; + int x_2 = arg0; + while (exponent_0 > 1) { + if (exponent_0 % 2 == 1) { + res_1 = res_1 * x_2; + } + x_2 = x_2 * x_2; + exponent_0 = exponent_0 / 2; } - float res_12; - if (m_4 < n_5) { - res_12 = n_5; - } else { - res_12 = m_4; + return res_1 * x_2; +} + +void bar (void) { + int a_0; + int x_1 = a_0 + 1; + while (x_1) { + a_0 = a_0 + 1; } - int* var14 = &x_0; - *var14 = 0; } diff --git a/samples/outputs.var_names/sample61 b/samples/outputs.var_names/sample61 index 1131b63..2b27ba9 100644 --- a/samples/outputs.var_names/sample61 +++ b/samples/outputs.var_names/sample61 @@ -1,5 +1,21 @@ void bar (void) { - int x_0 = 1; - int y_1 = 0; + int y_0 = 0ll; + if (y_0 < 0ll) { + (y_0 = y_0 + 1) - 1; + } else { + (y_0 = y_0 - 1) + 1; + } + int y_1 = 1ll; + if (y_1 < 1ll) { + (y_1 = y_1 + 1) - 1; + } else { + (y_1 = y_1 - 1) + 1; + } + int y_2 = 2ll; + if (y_2 < 2ll) { + (y_2 = y_2 + 1) - 1; + } else { + (y_2 = y_2 - 1) + 1; + } } diff --git a/samples/outputs.var_names/sample62 b/samples/outputs.var_names/sample62 index df4f84e..fb434fb 100644 --- a/samples/outputs.var_names/sample62 +++ b/samples/outputs.var_names/sample62 @@ -1,73 +1,7 @@ -Found 1 matches ------ -ASSIGN_EXPR - VAR_EXPR - VAR (x_0) - PLUS_EXPR - VAR_EXPR - VAR (x_0) - INT_CONST (1) ------ -Found 1 matches ------ -PLUS_EXPR - VAR_EXPR - VAR (x_0) - INT_CONST (0) ------ -After all replacements -FUNC_DECL (foo) - SCALAR_TYPE (VOID) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (x_0) - INT_CONST (0) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (x_0) - PLUS_EXPR - VAR_EXPR - VAR (x_0) - INT_CONST (1) - DECL_STMT - SCALAR_TYPE (INT) - VAR (y_1) - INT_CONST (0) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (y_1) - PLUS_EXPR - VAR_EXPR - VAR (x_0) - INT_CONST (1) - DECL_STMT - SCALAR_TYPE (INT) - VAR (z_2) - INT_CONST (0) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (z_2) - PLUS_EXPR - VAR_EXPR - VAR (z_2) - INT_CONST (2) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (z_2) - VAR_EXPR - VAR (x_0) -void foo (void) { - int x_0 = 0; - x_0 = x_0 + 1; - int y_1 = 0; - y_1 = x_0 + 1; - int z_2 = 0; - z_2 = z_2 + 2; - z_2 = x_0; +void bar (void) { + int y_0[] = {1, 2, 3}; + for (int i_1 = 0; i_1 < 3ll; i_1 = i_1 + 1) { + y_0[i_1] = y_0[i_1] + y_0[i_1 - 1]; + } } diff --git a/samples/outputs.var_names/sample63 b/samples/outputs.var_names/sample63 index 1642289..b37a8af 100644 --- a/samples/outputs.var_names/sample63 +++ b/samples/outputs.var_names/sample63 @@ -1,10 +1,11 @@ -struct linked_list { - linked_list* next; - struct foo* other; -}; void bar (void) { - linked_list* x_0; - x_0->next->next->next = 0; - x_0->other = 0; + _Pragma("omp parallel for") + for (int outer_0 = 0; outer_0 < 10; outer_0 = outer_0 + 1) { + int sum_1 = 0; + _Pragma("unroll") + for (int inner_2 = 0; inner_2 < 15; inner_2 = inner_2 + 1) { + sum_1 = sum_1 + inner_2; + } + } } diff --git a/samples/outputs.var_names/sample64 b/samples/outputs.var_names/sample64 index c979100..ba8daa6 100644 --- a/samples/outputs.var_names/sample64 +++ b/samples/outputs.var_names/sample64 @@ -1,22 +1,6 @@ -int power (int arg0, int arg1) { - int exponent_0 = arg1; - int res_1 = 1; - int x_2 = arg0; - while (exponent_0 > 1) { - if (exponent_0 % 2 == 1) { - res_1 = res_1 * x_2; - } - x_2 = x_2 * x_2; - exponent_0 = exponent_0 / 2; - } - return res_1 * x_2; -} - void bar (void) { - int a_0; - int x_1 = a_0 + 1; - while (x_1) { - a_0 = a_0 + 1; - } + int* x_0 = (int*)malloc(4ll); + x_0[0] = 123; + free(x_0); } diff --git a/samples/outputs.var_names/sample65 b/samples/outputs.var_names/sample65 index 2b27ba9..2d85b68 100644 --- a/samples/outputs.var_names/sample65 +++ b/samples/outputs.var_names/sample65 @@ -1,21 +1,6 @@ -void bar (void) { - int y_0 = 0ll; - if (y_0 < 0ll) { - (y_0 = y_0 + 1) - 1; - } else { - (y_0 = y_0 - 1) + 1; - } - int y_1 = 1ll; - if (y_1 < 1ll) { - (y_1 = y_1 + 1) - 1; - } else { - (y_1 = y_1 - 1) + 1; - } - int y_2 = 2ll; - if (y_2 < 2ll) { - (y_2 = y_2 + 1) - 1; - } else { - (y_2 = y_2 - 1) + 1; +void bar (int* restrict arg0, int* restrict arg1, int arg2) { + for (int i_0 = 0; i_0 < arg2; (i_0 = i_0 + 1) - 1) { + arg0[i_0] = arg1[i_0]; } } diff --git a/samples/outputs.var_names/sample66 b/samples/outputs.var_names/sample66 deleted file mode 100644 index fb434fb..0000000 --- a/samples/outputs.var_names/sample66 +++ /dev/null @@ -1,7 +0,0 @@ -void bar (void) { - int y_0[] = {1, 2, 3}; - for (int i_1 = 0; i_1 < 3ll; i_1 = i_1 + 1) { - y_0[i_1] = y_0[i_1] + y_0[i_1 - 1]; - } -} - diff --git a/samples/outputs.var_names/sample67 b/samples/outputs.var_names/sample67 deleted file mode 100644 index b37a8af..0000000 --- a/samples/outputs.var_names/sample67 +++ /dev/null @@ -1,11 +0,0 @@ -void bar (void) { - _Pragma("omp parallel for") - for (int outer_0 = 0; outer_0 < 10; outer_0 = outer_0 + 1) { - int sum_1 = 0; - _Pragma("unroll") - for (int inner_2 = 0; inner_2 < 15; inner_2 = inner_2 + 1) { - sum_1 = sum_1 + inner_2; - } - } -} - diff --git a/samples/outputs.var_names/sample68 b/samples/outputs.var_names/sample68 deleted file mode 100644 index ba8daa6..0000000 --- a/samples/outputs.var_names/sample68 +++ /dev/null @@ -1,6 +0,0 @@ -void bar (void) { - int* x_0 = (int*)malloc(4ll); - x_0[0] = 123; - free(x_0); -} - diff --git a/samples/outputs.var_names/sample69 b/samples/outputs.var_names/sample69 deleted file mode 100644 index 2d85b68..0000000 --- a/samples/outputs.var_names/sample69 +++ /dev/null @@ -1,6 +0,0 @@ -void bar (int* restrict arg0, int* restrict arg1, int arg2) { - for (int i_0 = 0; i_0 < arg2; (i_0 = i_0 + 1) - 1) { - arg0[i_0] = arg1[i_0]; - } -} - diff --git a/samples/outputs/sample1 b/samples/outputs/sample1 index b83aaab..909c489 100644 --- a/samples/outputs/sample1 +++ b/samples/outputs/sample1 @@ -105,6 +105,10 @@ STMT_BLOCK BITWISE_NOT_EXPR VAR_EXPR VAR (var1) + EXPR_STMT + ADDR_OF_EXPR + VAR_EXPR + VAR (var1) { int var0 = 0; int var1 = var0; @@ -123,4 +127,5 @@ STMT_BLOCK var0 = var0 | var1; var0 = var0 ^ var1; ~var1; + &var1; } diff --git a/samples/outputs/sample21 b/samples/outputs/sample21 index d56e7fa..a8e1ab7 100644 --- a/samples/outputs/sample21 +++ b/samples/outputs/sample21 @@ -2,11 +2,21 @@ STMT_BLOCK DECL_STMT SCALAR_TYPE (INT) VAR (var0) - INT_CONST (2) + INT_CONST (18) DECL_STMT SCALAR_TYPE (INT) VAR (var1) - PLUS_EXPR - STRING_CONST ("foo") + INT_CONST (17) + EXPR_STMT + ASSIGN_EXPR VAR_EXPR VAR (var0) + PLUS_EXPR + VAR_EXPR + VAR (var1) + INT_CONST (9) +{ + int var0 = 18; + int var1 = 17; + var0 = var1 + 9; +} diff --git a/samples/outputs/sample22 b/samples/outputs/sample22 index a8e1ab7..5afdacf 100644 --- a/samples/outputs/sample22 +++ b/samples/outputs/sample22 @@ -1,22 +1,77 @@ STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (var2) + NO_INITIALIZATION DECL_STMT SCALAR_TYPE (INT) VAR (var0) - INT_CONST (18) + NO_INITIALIZATION DECL_STMT SCALAR_TYPE (INT) VAR (var1) - INT_CONST (17) - EXPR_STMT - ASSIGN_EXPR + VAR_EXPR + VAR (var0) + IF_STMT + GT_EXPR VAR_EXPR - VAR (var0) - PLUS_EXPR - VAR_EXPR - VAR (var1) - INT_CONST (9) + VAR (var1) + INT_CONST (10) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var2) + INT_CONST (9) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var2) + INT_CONST (0) + IF_STMT + VAR_EXPR + VAR (var2) + STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (var3) + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var3) + INT_CONST (0) + STMT_BLOCK + IF_STMT + VAR_EXPR + VAR (var0) + STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (var4) + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var4) + INT_CONST (0) + STMT_BLOCK { - int var0 = 18; - int var1 = 17; - var0 = var1 + 9; + int var2; + int var0; + int var1 = var0; + if (var1 > 10) { + var2 = 9; + } else { + var2 = 0; + } + if (var2) { + int var3 = 0; + var3 = 0; + } + if (var0) { + int var4 = 0; + var4 = 0; + } } diff --git a/samples/outputs/sample23 b/samples/outputs/sample23 index 5afdacf..6ef2b70 100644 --- a/samples/outputs/sample23 +++ b/samples/outputs/sample23 @@ -1,77 +1,353 @@ STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (var2) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (INT) - VAR (var0) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (INT) - VAR (var1) - VAR_EXPR + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) + SCALAR_TYPE (INT) VAR (var0) - IF_STMT - GT_EXPR + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (0) + ASSIGN_EXPR VAR_EXPR + VAR (var0) + PLUS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (1) + STMT_BLOCK + DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) VAR (var1) - INT_CONST (10) + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var1) + PLUS_EXPR + VAR_EXPR + VAR (var1) + INT_CONST (1) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) + SCALAR_TYPE (INT) + VAR (var2) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (var2) + INT_CONST (1) + ASSIGN_EXPR + VAR_EXPR + VAR (var2) + PLUS_EXPR + VAR_EXPR + VAR (var2) + INT_CONST (1) STMT_BLOCK + DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (var3) + INT_CONST (1) EXPR_STMT ASSIGN_EXPR VAR_EXPR - VAR (var2) - INT_CONST (9) + VAR (var3) + PLUS_EXPR + VAR_EXPR + VAR (var3) + INT_CONST (1) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) + SCALAR_TYPE (INT) + VAR (var4) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (var4) + INT_CONST (2) + ASSIGN_EXPR + VAR_EXPR + VAR (var4) + PLUS_EXPR + VAR_EXPR + VAR (var4) + INT_CONST (1) STMT_BLOCK + DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (var5) + INT_CONST (2) EXPR_STMT ASSIGN_EXPR VAR_EXPR - VAR (var2) - INT_CONST (0) - IF_STMT - VAR_EXPR - VAR (var2) + VAR (var5) + PLUS_EXPR + VAR_EXPR + VAR (var5) + INT_CONST (1) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) + SCALAR_TYPE (INT) + VAR (var6) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (var6) + INT_CONST (3) + ASSIGN_EXPR + VAR_EXPR + VAR (var6) + PLUS_EXPR + VAR_EXPR + VAR (var6) + INT_CONST (1) STMT_BLOCK DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (var7) + INT_CONST (3) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var7) + PLUS_EXPR + VAR_EXPR + VAR (var7) + INT_CONST (1) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) SCALAR_TYPE (INT) - VAR (var3) - INT_CONST (0) + VAR (var8) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (var8) + INT_CONST (4) + ASSIGN_EXPR + VAR_EXPR + VAR (var8) + PLUS_EXPR + VAR_EXPR + VAR (var8) + INT_CONST (1) + STMT_BLOCK + DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (var9) + INT_CONST (4) EXPR_STMT ASSIGN_EXPR VAR_EXPR - VAR (var3) - INT_CONST (0) + VAR (var9) + PLUS_EXPR + VAR_EXPR + VAR (var9) + INT_CONST (1) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) + SCALAR_TYPE (INT) + VAR (var10) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (var10) + INT_CONST (5) + ASSIGN_EXPR + VAR_EXPR + VAR (var10) + PLUS_EXPR + VAR_EXPR + VAR (var10) + INT_CONST (1) STMT_BLOCK - IF_STMT - VAR_EXPR - VAR (var0) + DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (var11) + INT_CONST (5) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var11) + PLUS_EXPR + VAR_EXPR + VAR (var11) + INT_CONST (1) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) + SCALAR_TYPE (INT) + VAR (var12) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (var12) + INT_CONST (6) + ASSIGN_EXPR + VAR_EXPR + VAR (var12) + PLUS_EXPR + VAR_EXPR + VAR (var12) + INT_CONST (1) STMT_BLOCK DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (var13) + INT_CONST (6) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var13) + PLUS_EXPR + VAR_EXPR + VAR (var13) + INT_CONST (1) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) SCALAR_TYPE (INT) - VAR (var4) - INT_CONST (0) + VAR (var14) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (var14) + INT_CONST (7) + ASSIGN_EXPR + VAR_EXPR + VAR (var14) + PLUS_EXPR + VAR_EXPR + VAR (var14) + INT_CONST (1) + STMT_BLOCK + DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (var15) + INT_CONST (7) EXPR_STMT ASSIGN_EXPR VAR_EXPR - VAR (var4) - INT_CONST (0) + VAR (var15) + PLUS_EXPR + VAR_EXPR + VAR (var15) + INT_CONST (1) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) + SCALAR_TYPE (INT) + VAR (var16) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (var16) + INT_CONST (8) + ASSIGN_EXPR + VAR_EXPR + VAR (var16) + PLUS_EXPR + VAR_EXPR + VAR (var16) + INT_CONST (1) STMT_BLOCK + DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (var17) + INT_CONST (8) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var17) + PLUS_EXPR + VAR_EXPR + VAR (var17) + INT_CONST (1) + FOR_STMT + DECL_STMT + BUILDER_VAR_TYPE (STATIC_VAR) + SCALAR_TYPE (INT) + VAR (var18) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (var18) + INT_CONST (9) + ASSIGN_EXPR + VAR_EXPR + VAR (var18) + PLUS_EXPR + VAR_EXPR + VAR (var18) + INT_CONST (1) + STMT_BLOCK + DECL_STMT + BUILDER_VAR_TYPE (DYN_VAR) + SCALAR_TYPE (INT) + VAR (var19) + INT_CONST (9) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var19) + PLUS_EXPR + VAR_EXPR + VAR (var19) + INT_CONST (1) { - int var2; - int var0; - int var1 = var0; - if (var1 > 10) { - var2 = 9; - } else { - var2 = 0; + for (builder::static_var var0 = 0; var0 < 0; var0 = var0 + 1) { + builder::dyn_var var1 = 0; + var1 = var1 + 1; + } + for (builder::static_var var2 = 0; var2 < 1; var2 = var2 + 1) { + builder::dyn_var var3 = 1; + var3 = var3 + 1; + } + for (builder::static_var var4 = 0; var4 < 2; var4 = var4 + 1) { + builder::dyn_var var5 = 2; + var5 = var5 + 1; + } + for (builder::static_var var6 = 0; var6 < 3; var6 = var6 + 1) { + builder::dyn_var var7 = 3; + var7 = var7 + 1; + } + for (builder::static_var var8 = 0; var8 < 4; var8 = var8 + 1) { + builder::dyn_var var9 = 4; + var9 = var9 + 1; + } + for (builder::static_var var10 = 0; var10 < 5; var10 = var10 + 1) { + builder::dyn_var var11 = 5; + var11 = var11 + 1; + } + for (builder::static_var var12 = 0; var12 < 6; var12 = var12 + 1) { + builder::dyn_var var13 = 6; + var13 = var13 + 1; + } + for (builder::static_var var14 = 0; var14 < 7; var14 = var14 + 1) { + builder::dyn_var var15 = 7; + var15 = var15 + 1; + } + for (builder::static_var var16 = 0; var16 < 8; var16 = var16 + 1) { + builder::dyn_var var17 = 8; + var17 = var17 + 1; + } + for (builder::static_var var18 = 0; var18 < 9; var18 = var18 + 1) { + builder::dyn_var var19 = 9; + var19 = var19 + 1; } - if (var2) { - int var3 = 0; - var3 = 0; - } - if (var0) { - int var4 = 0; - var4 = 0; - } } diff --git a/samples/outputs/sample24 b/samples/outputs/sample24 index 6ef2b70..afe4ff4 100644 --- a/samples/outputs/sample24 +++ b/samples/outputs/sample24 @@ -1,353 +1,118 @@ -STMT_BLOCK - FOR_STMT +FUNC_DECL (func1) + SCALAR_TYPE (INT) + VAR (arg0) + VAR (arg1) + VAR (arg2) + STMT_BLOCK DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) + SCALAR_TYPE (INT) VAR (var0) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (0) - ASSIGN_EXPR - VAR_EXPR - VAR (var0) - PLUS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (var1) - INT_CONST (0) - EXPR_STMT - ASSIGN_EXPR + MINUS_EXPR + MINUS_EXPR VAR_EXPR - VAR (var1) - PLUS_EXPR - VAR_EXPR - VAR (var1) - INT_CONST (1) - FOR_STMT - DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (var2) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (var2) - INT_CONST (1) - ASSIGN_EXPR - VAR_EXPR - VAR (var2) - PLUS_EXPR - VAR_EXPR - VAR (var2) - INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (var3) - INT_CONST (1) - EXPR_STMT - ASSIGN_EXPR + VAR (arg0) VAR_EXPR - VAR (var3) - PLUS_EXPR - VAR_EXPR - VAR (var3) - INT_CONST (1) - FOR_STMT - DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (var4) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (var4) - INT_CONST (2) - ASSIGN_EXPR - VAR_EXPR - VAR (var4) - PLUS_EXPR + VAR (arg1) VAR_EXPR - VAR (var4) - INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (var5) - INT_CONST (2) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var5) - PLUS_EXPR - VAR_EXPR - VAR (var5) - INT_CONST (1) - FOR_STMT + VAR (arg2) DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (var6) + SCALAR_TYPE (INT) + VAR (var1) INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (var6) - INT_CONST (3) - ASSIGN_EXPR + RETURN_STMT VAR_EXPR - VAR (var6) - PLUS_EXPR - VAR_EXPR - VAR (var6) - INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (var7) - INT_CONST (3) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var7) - PLUS_EXPR - VAR_EXPR - VAR (var7) - INT_CONST (1) - FOR_STMT + VAR (var1) +int func1 (int arg0, int arg1, int arg2) { + int var0 = arg0 - arg1 - arg2; + int var1 = 0; + return var1; +} + +FUNC_DECL (func2) + SCALAR_TYPE (INT) + VAR (arg0) + STMT_BLOCK DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (var8) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (var8) - INT_CONST (4) - ASSIGN_EXPR - VAR_EXPR - VAR (var8) + SCALAR_TYPE (INT) + VAR (var0) PLUS_EXPR VAR_EXPR - VAR (var8) + VAR (arg0) INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (var9) - INT_CONST (4) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var9) - PLUS_EXPR - VAR_EXPR - VAR (var9) - INT_CONST (1) - FOR_STMT - DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (var10) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (var10) - INT_CONST (5) - ASSIGN_EXPR + RETURN_STMT VAR_EXPR - VAR (var10) - PLUS_EXPR - VAR_EXPR - VAR (var10) - INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (var11) - INT_CONST (5) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var11) - PLUS_EXPR - VAR_EXPR - VAR (var11) - INT_CONST (1) - FOR_STMT + VAR (var0) +int func2 (int arg0) { + int var0 = arg0 + 1; + return var0; +} + +FUNC_DECL (func3) + SCALAR_TYPE (VOID) + VAR (arg0) + STMT_BLOCK DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (var12) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (var12) - INT_CONST (6) - ASSIGN_EXPR + SCALAR_TYPE (INT) + VAR (var0) VAR_EXPR - VAR (var12) - PLUS_EXPR + VAR (arg0) + EXPR_STMT + ASSIGN_EXPR VAR_EXPR - VAR (var12) - INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (var13) - INT_CONST (6) - EXPR_STMT - ASSIGN_EXPR + VAR (arg0) + PLUS_EXPR VAR_EXPR - VAR (var13) - PLUS_EXPR - VAR_EXPR - VAR (var13) - INT_CONST (1) - FOR_STMT + VAR (var0) + INT_CONST (1) +void func3 (int arg0) { + int var0 = arg0; + arg0 = var0 + 1; +} + +FUNC_DECL (func4) + SCALAR_TYPE (INT) + VAR (arg0) + STMT_BLOCK DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (var14) + SCALAR_TYPE (INT) + VAR (var0) INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (var14) - INT_CONST (7) - ASSIGN_EXPR - VAR_EXPR - VAR (var14) - PLUS_EXPR + EXPR_STMT + ASSIGN_EXPR VAR_EXPR - VAR (var14) - INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (var15) - INT_CONST (7) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var15) + VAR (var0) + PLUS_EXPR PLUS_EXPR VAR_EXPR - VAR (var15) - INT_CONST (1) - FOR_STMT - DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (var16) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (var16) - INT_CONST (8) - ASSIGN_EXPR - VAR_EXPR - VAR (var16) - PLUS_EXPR - VAR_EXPR - VAR (var16) - INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (var17) - INT_CONST (8) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var17) - PLUS_EXPR + VAR (var0) VAR_EXPR - VAR (var17) - INT_CONST (1) - FOR_STMT - DECL_STMT - BUILDER_VAR_TYPE (STATIC_VAR) - SCALAR_TYPE (INT) - VAR (var18) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (var18) - INT_CONST (9) - ASSIGN_EXPR - VAR_EXPR - VAR (var18) - PLUS_EXPR + VAR (arg0) + INT_CONST (1) + EXPR_STMT + ASSIGN_EXPR VAR_EXPR - VAR (var18) - INT_CONST (1) - STMT_BLOCK - DECL_STMT - BUILDER_VAR_TYPE (DYN_VAR) - SCALAR_TYPE (INT) - VAR (var19) - INT_CONST (9) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var19) + VAR (var0) + PLUS_EXPR PLUS_EXPR VAR_EXPR - VAR (var19) - INT_CONST (1) -{ - for (builder::static_var var0 = 0; var0 < 0; var0 = var0 + 1) { - builder::dyn_var var1 = 0; - var1 = var1 + 1; - } - for (builder::static_var var2 = 0; var2 < 1; var2 = var2 + 1) { - builder::dyn_var var3 = 1; - var3 = var3 + 1; - } - for (builder::static_var var4 = 0; var4 < 2; var4 = var4 + 1) { - builder::dyn_var var5 = 2; - var5 = var5 + 1; - } - for (builder::static_var var6 = 0; var6 < 3; var6 = var6 + 1) { - builder::dyn_var var7 = 3; - var7 = var7 + 1; - } - for (builder::static_var var8 = 0; var8 < 4; var8 = var8 + 1) { - builder::dyn_var var9 = 4; - var9 = var9 + 1; - } - for (builder::static_var var10 = 0; var10 < 5; var10 = var10 + 1) { - builder::dyn_var var11 = 5; - var11 = var11 + 1; - } - for (builder::static_var var12 = 0; var12 < 6; var12 = var12 + 1) { - builder::dyn_var var13 = 6; - var13 = var13 + 1; - } - for (builder::static_var var14 = 0; var14 < 7; var14 = var14 + 1) { - builder::dyn_var var15 = 7; - var15 = var15 + 1; - } - for (builder::static_var var16 = 0; var16 < 8; var16 = var16 + 1) { - builder::dyn_var var17 = 8; - var17 = var17 + 1; - } - for (builder::static_var var18 = 0; var18 < 9; var18 = var18 + 1) { - builder::dyn_var var19 = 9; - var19 = var19 + 1; - } + VAR (var0) + VAR_EXPR + VAR (arg0) + INT_CONST (1) + EXPR_STMT + FUNCTION_CALL_EXPR + VAR_EXPR + VAR (print_val) + VAR_EXPR + VAR (var0) + RETURN_STMT + VAR_EXPR + VAR (var0) +int func4 (int arg0) { + int var0 = 0; + var0 = var0 + arg0 + 1; + var0 = var0 + arg0 + 1; + print_val(var0); + return var0; } + diff --git a/samples/outputs/sample25 b/samples/outputs/sample25 new file mode 100644 index 0000000..934a49e --- /dev/null +++ b/samples/outputs/sample25 @@ -0,0 +1,112 @@ +STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (var0) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var1) + INT_CONST (0) + WHILE_STMT + NOT_EXPR + EQUALS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (0) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var1) + PLUS_EXPR + VAR_EXPR + VAR (var1) + INT_CONST (1) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var1) + PLUS_EXPR + VAR_EXPR + VAR (var1) + INT_CONST (1) + WHILE_STMT + NOT_EXPR + EQUALS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (0) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var1) + PLUS_EXPR + VAR_EXPR + VAR (var1) + INT_CONST (1) + WHILE_STMT + NOT_EXPR + EQUALS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (0) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var1) + PLUS_EXPR + VAR_EXPR + VAR (var1) + INT_CONST (1) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var1) + PLUS_EXPR + VAR_EXPR + VAR (var1) + INT_CONST (1) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var1) + PLUS_EXPR + VAR_EXPR + VAR (var1) + INT_CONST (2) + WHILE_STMT + NOT_EXPR + EQUALS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (0) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var1) + PLUS_EXPR + VAR_EXPR + VAR (var1) + INT_CONST (1) +{ + int var0 = 0; + int var1 = 0; + while (!(var0 == 0)) { + var1 = var1 + 1; + var1 = var1 + 1; + while (!(var0 == 0)) { + } + var1 = var1 + 1; + while (!(var0 == 0)) { + var1 = var1 + 1; + } + var1 = var1 + 1; + } + var1 = var1 + 2; + while (!(var0 == 0)) { + var1 = var1 + 1; + } +} diff --git a/samples/outputs/sample26 b/samples/outputs/sample26 index 302bf8d..cdb166d 100644 --- a/samples/outputs/sample26 +++ b/samples/outputs/sample26 @@ -1,112 +1,27 @@ -STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (var0) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var1) - INT_CONST (0) - WHILE_STMT - NOT_EXPR - EQUALS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (0) - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var1) - PLUS_EXPR - VAR_EXPR - VAR (var1) - INT_CONST (1) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var1) - PLUS_EXPR - VAR_EXPR - VAR (var1) - INT_CONST (1) - WHILE_STMT - NOT_EXPR - EQUALS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (0) - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var1) - PLUS_EXPR - VAR_EXPR - VAR (var1) - INT_CONST (1) - WHILE_STMT - NOT_EXPR - EQUALS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (0) - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var1) - PLUS_EXPR - VAR_EXPR - VAR (var1) - INT_CONST (1) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var1) - PLUS_EXPR - VAR_EXPR - VAR (var1) - INT_CONST (1) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var1) - PLUS_EXPR - VAR_EXPR - VAR (var1) - INT_CONST (1) - WHILE_STMT - NOT_EXPR - EQUALS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (0) - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var1) - PLUS_EXPR - VAR_EXPR - VAR (var1) - INT_CONST (1) -{ - int var0 = 0; - int var1 = 0; - while (!(var0 == 0)) { - var1 = var1 + 1; - var1 = var1 + 1; - while (!(var0 == 0)) { - } - var1 = var1 + 1; - while (!(var0 == 0)) { - var1 = var1 + 1; - } - var1 = var1 + 1; - } - var1 = var1 + 1; - while (!(var0 == 0)) { - var1 = var1 + 1; +int power_15 (int arg0) { + int var0 = 1; + int var1 = arg0; + var0 = var0 * var1; + var1 = var1 * var1; + var0 = var0 * var1; + var1 = var1 * var1; + var0 = var0 * var1; + var1 = var1 * var1; + var0 = var0 * var1; + var1 = var1 * var1; + return var0; +} + +int power_5 (int arg0) { + int var0 = 1; + int var1 = 5; + while (arg0 > 0) { + if (arg0 % 2 == 1) { + var0 = var0 * var1; + } + var1 = var1 * var1; + arg0 = arg0 / 2; } + return var0; } + diff --git a/samples/outputs/sample28 b/samples/outputs/sample28 new file mode 100644 index 0000000..4ada156 --- /dev/null +++ b/samples/outputs/sample28 @@ -0,0 +1,98 @@ +STMT_BLOCK + DECL_STMT + SCALAR_TYPE (SHORT_INT) + VAR (var0) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (UNSIGNED_SHORT_INT) + VAR (var1) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (INT) + VAR (var2) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (UNSIGNED_INT) + VAR (var3) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (LONG_INT) + VAR (var4) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (UNSIGNED_LONG_INT) + VAR (var5) + INT_CONST (5) + DECL_STMT + SCALAR_TYPE (LONG_LONG_INT) + VAR (var6) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (UNSIGNED_LONG_LONG_INT) + VAR (var7) + INT_CONST (4) + DECL_STMT + SCALAR_TYPE (CHAR) + VAR (var8) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (UNSIGNED_CHAR) + VAR (var9) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (FLOAT) + VAR (var10) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (DOUBLE) + VAR (var11) + NO_INITIALIZATION + DECL_STMT + POINTER_TYPE + SCALAR_TYPE (VOID) + VAR (var12) + NO_INITIALIZATION + DECL_STMT + ARRAY_TYPE + SCALAR_TYPE (CHAR) + -1 + VAR (var13) + STRING_CONST ("Hello world") + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var13) + STRING_CONST ("new string") + DECL_STMT + POINTER_TYPE + SCALAR_TYPE (CHAR) + VAR (var14) + STRING_CONST ("Hello world") + DECL_STMT + SCALAR_TYPE (BOOL) + VAR (var15) + INT_CONST (1) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var16) + INT_CONST (0) +{ + short int var0; + unsigned short int var1; + int var2; + unsigned int var3; + long int var4; + unsigned long int var5 = 5ll; + long long int var6; + unsigned long long int var7 = 4ll; + char var8; + unsigned char var9; + float var10; + double var11; + void* var12; + char var13[] = "Hello world"; + var13 = "new string"; + const char* const volatile var14 = "Hello world"; + bool var15 = 1; + int var16 = 0; +} diff --git a/samples/outputs/sample29 b/samples/outputs/sample29 new file mode 100644 index 0000000..12f4ffc --- /dev/null +++ b/samples/outputs/sample29 @@ -0,0 +1,32 @@ +STMT_BLOCK + DECL_STMT + NAMED_TYPE (GraphT) + VAR (var0) + NO_INITIALIZATION + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var0) + PLUS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (1) + DECL_STMT + NAMED_TYPE (FooT) + SCALAR_TYPE (INT) + VAR (var1) + NO_INITIALIZATION + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var1) + PLUS_EXPR + VAR_EXPR + VAR (var1) + INT_CONST (1) +{ + GraphT var0; + var0 = var0 + 1; + FooT var1; + var1 = var1 + 1; +} diff --git a/samples/outputs/sample30 b/samples/outputs/sample30 index 4ada156..40e9a6e 100644 --- a/samples/outputs/sample30 +++ b/samples/outputs/sample30 @@ -1,98 +1,52 @@ -STMT_BLOCK - DECL_STMT - SCALAR_TYPE (SHORT_INT) - VAR (var0) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (UNSIGNED_SHORT_INT) - VAR (var1) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (INT) - VAR (var2) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (UNSIGNED_INT) - VAR (var3) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (LONG_INT) - VAR (var4) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (UNSIGNED_LONG_INT) - VAR (var5) - INT_CONST (5) - DECL_STMT - SCALAR_TYPE (LONG_LONG_INT) - VAR (var6) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (UNSIGNED_LONG_LONG_INT) - VAR (var7) - INT_CONST (4) - DECL_STMT - SCALAR_TYPE (CHAR) - VAR (var8) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (UNSIGNED_CHAR) - VAR (var9) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (FLOAT) - VAR (var10) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (DOUBLE) - VAR (var11) - NO_INITIALIZATION - DECL_STMT - POINTER_TYPE - SCALAR_TYPE (VOID) - VAR (var12) - NO_INITIALIZATION - DECL_STMT - ARRAY_TYPE - SCALAR_TYPE (CHAR) - -1 - VAR (var13) - STRING_CONST ("Hello world") - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var13) - STRING_CONST ("new string") - DECL_STMT - POINTER_TYPE - SCALAR_TYPE (CHAR) - VAR (var14) - STRING_CONST ("Hello world") - DECL_STMT - SCALAR_TYPE (BOOL) - VAR (var15) - INT_CONST (1) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var16) - INT_CONST (0) -{ - short int var0; - unsigned short int var1; - int var2; - unsigned int var3; - long int var4; - unsigned long int var5 = 5ll; - long long int var6; - unsigned long long int var7 = 4ll; - char var8; - unsigned char var9; - float var10; - double var11; - void* var12; - char var13[] = "Hello world"; - var13 = "new string"; - const char* const volatile var14 = "Hello world"; - bool var15 = 1; - int var16 = 0; +FUNC_DECL (bar) + SCALAR_TYPE (VOID) + STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (var0) + INT_CONST (5) + FOR_STMT + DECL_STMT + SCALAR_TYPE (INT) + VAR (var1) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (var1) + INT_CONST (100) + ASSIGN_EXPR + VAR_EXPR + VAR (var1) + PLUS_EXPR + VAR_EXPR + VAR (var1) + INT_CONST (1) + STMT_BLOCK + IF_STMT + NOT_EXPR + EQUALS_EXPR + VAR_EXPR + VAR (var1) + VAR_EXPR + VAR (var0) + STMT_BLOCK + CONTINUE_STMT + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var0) + VAR_EXPR + VAR (var1) + BREAK_STMT +void bar (void) { + int var0 = 5; + for (int var1 = 0; var1 < 100; var1 = var1 + 1) { + if (!(var1 == var0)) { + continue; + } + var0 = var1; + break; + } } + diff --git a/samples/outputs/sample31 b/samples/outputs/sample31 index c24b6ae..da4d763 100644 --- a/samples/outputs/sample31 +++ b/samples/outputs/sample31 @@ -1,35 +1,48 @@ -FUNC_DECL (func1) - SCALAR_TYPE (INT) - VAR (arg0) +FUNC_DECL (bar) + SCALAR_TYPE (VOID) STMT_BLOCK DECL_STMT - NAMED_TYPE (foo) + SCALAR_TYPE (INT) VAR (var0) - PLUS_EXPR + INT_CONST (0) + FOR_STMT + EXPR_STMT + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (100) + ASSIGN_EXPR + VAR_EXPR + VAR (var0) + PLUS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (1) + STMT_BLOCK + FOR_STMT + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (0) + LT_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (100) + ASSIGN_EXPR + VAR_EXPR + VAR (var0) PLUS_EXPR - INT_CONST (3) - MEMBER_ACCESS_EXPR (var1) - VAR_EXPR - VAR (arg0) - MUL_EXPR - INT_CONST (5) - MEMBER_ACCESS_EXPR (var1) - VAR_EXPR - VAR (arg0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var1) - PLUS_EXPR - MEMBER_ACCESS_EXPR (neighbor) VAR_EXPR VAR (var0) - INT_CONST (2) - RETURN_STMT - VAR_EXPR - VAR (var1) -int func1 (foo arg0) { - foo var0 = 3 + arg0.var1 + 5 * arg0.var1; - int var1 = var0.neighbor + 2; - return var1; + INT_CONST (1) + STMT_BLOCK +void bar (void) { + int var0 = 0; + for (0; var0 < 100; var0 = var0 + 1) { + } + for (var0 = 0; var0 < 100; var0 = var0 + 1) { + } } diff --git a/samples/outputs/sample32 b/samples/outputs/sample32 index 12f4ffc..dce60d4 100644 --- a/samples/outputs/sample32 +++ b/samples/outputs/sample32 @@ -1,32 +1 @@ -STMT_BLOCK - DECL_STMT - NAMED_TYPE (GraphT) - VAR (var0) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var0) - PLUS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (1) - DECL_STMT - NAMED_TYPE (FooT) - SCALAR_TYPE (INT) - VAR (var1) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var1) - PLUS_EXPR - VAR_EXPR - VAR (var1) - INT_CONST (1) -{ - GraphT var0; - var0 = var0 + 1; - FooT var1; - var1 = var1 + 1; -} +32768 diff --git a/samples/outputs/sample33 b/samples/outputs/sample33 index 76b70f0..333bc74 100644 --- a/samples/outputs/sample33 +++ b/samples/outputs/sample33 @@ -1,54 +1,29 @@ -STMT_BLOCK - DECL_STMT - NAMED_TYPE (FooT) - VAR (var0) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var0) - PLUS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (1) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var1) - MEMBER_ACCESS_EXPR (member) - VAR_EXPR - VAR (var0) - DECL_STMT - NAMED_TYPE (FooT) - VAR (var2) - VAR_EXPR - VAR (var0) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var2) - VAR_EXPR - VAR (var0) - DECL_STMT - POINTER_TYPE - NAMED_TYPE (FooT) - VAR (var3) - ADDR_OF_EXPR - VAR_EXPR - VAR (var0) - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (member) - SQ_BKT_EXPR - VAR_EXPR - VAR (var3) - INT_CONST (0) - INT_CONST (0) -{ - FooT var0; - var0 = var0 + 1; - int var1 = var0.member; - FooT var2 = var0; - var2 = var0; - FooT* var3 = &var0; - var3[0].member = 0; +void __global__ cuda_kernel_0 (int* arg0) { + int var2 = blockIdx.x * 512 + threadIdx.x; + arg0[var2] = 0; } + +void __global__ cuda_kernel_1 (int* arg0) { + int var5 = blockIdx.x * 512 + threadIdx.x; + arg0[var5] = 0; +} + +char ret_2_0[sizeof(int*)] __device__; +void __global__ cuda_kernel_2 (int* arg0) { + int var8 = blockIdx.x * 512 + threadIdx.x; + arg0[var8] = 0; + if (!(blockIdx.x * blockDim.x + threadIdx.x)) { + runtime::cudaMemcpyToSymbolMagic(ret_2_0, arg0); + } +} + +void bar (int* arg0) { + cuda_kernel_0<<<128, 512>>>(arg0); + cudaDeviceSynchronize(); + runtime::LaunchCooperativeKernel((void*)cuda_kernel_1, 128, 512, arg0); + cudaDeviceSynchronize(); + runtime::LaunchCooperativeKernel((void*)cuda_kernel_2, 128, 512, arg0); + cudaDeviceSynchronize(); + runtime::cudaMemcpyFromSymbolMagic(&arg0, ret_2_0); +} + diff --git a/samples/outputs/sample34 b/samples/outputs/sample34 index 40e9a6e..7e5e566 100644 --- a/samples/outputs/sample34 +++ b/samples/outputs/sample34 @@ -1,52 +1,69 @@ -FUNC_DECL (bar) - SCALAR_TYPE (VOID) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) +STMT_BLOCK + DECL_STMT + NAMED_TYPE (FooT) + VAR (var0) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (INT) + VAR (var1) + MEMBER_ACCESS_EXPR (member) + VAR_EXPR + VAR (var0) + DECL_STMT + NAMED_TYPE (FooT) + VAR (var2) + VAR_EXPR VAR (var0) - INT_CONST (5) - FOR_STMT - DECL_STMT - SCALAR_TYPE (INT) - VAR (var1) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (var1) - INT_CONST (100) - ASSIGN_EXPR - VAR_EXPR - VAR (var1) - PLUS_EXPR + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var2) + VAR_EXPR + VAR (var0) + DECL_STMT + POINTER_TYPE + NAMED_TYPE (FooT) + VAR (var3) + ADDR_OF_EXPR + VAR_EXPR + VAR (var0) + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (member) + SQ_BKT_EXPR VAR_EXPR - VAR (var1) - INT_CONST (1) - STMT_BLOCK - IF_STMT - NOT_EXPR - EQUALS_EXPR - VAR_EXPR - VAR (var1) - VAR_EXPR - VAR (var0) - STMT_BLOCK - CONTINUE_STMT - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var0) - VAR_EXPR - VAR (var1) - BREAK_STMT -void bar (void) { - int var0 = 5; - for (int var1 = 0; var1 < 100; var1 = var1 + 1) { - if (!(var1 == var0)) { - continue; - } - var0 = var1; - break; - } + VAR (var3) + INT_CONST (0) + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (member) + SQ_BKT_EXPR + VAR_EXPR + VAR (var3) + INT_CONST (0) + INT_CONST (1) + DECL_STMT + NAMED_TYPE (FooT) + VAR (var4) + SQ_BKT_EXPR + VAR_EXPR + VAR (var3) + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (member) + VAR_EXPR + VAR (var4) + INT_CONST (3) +{ + FooT var0; + int var1 = var0.member; + FooT var2 = var0; + var2 = var0; + FooT* var3 = &var0; + var3->member = 0; + var3->member = 1; + FooT var4 = *var3; + var4.member = 3; } - diff --git a/samples/outputs/sample35 b/samples/outputs/sample35 deleted file mode 100644 index da4d763..0000000 --- a/samples/outputs/sample35 +++ /dev/null @@ -1,48 +0,0 @@ -FUNC_DECL (bar) - SCALAR_TYPE (VOID) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (var0) - INT_CONST (0) - FOR_STMT - EXPR_STMT - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (100) - ASSIGN_EXPR - VAR_EXPR - VAR (var0) - PLUS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (1) - STMT_BLOCK - FOR_STMT - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (0) - LT_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (100) - ASSIGN_EXPR - VAR_EXPR - VAR (var0) - PLUS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (1) - STMT_BLOCK -void bar (void) { - int var0 = 0; - for (0; var0 < 100; var0 = var0 + 1) { - } - for (var0 = 0; var0 < 100; var0 = var0 + 1) { - } -} - diff --git a/samples/outputs/sample36 b/samples/outputs/sample36 index dce60d4..71dd3e1 100644 --- a/samples/outputs/sample36 +++ b/samples/outputs/sample36 @@ -1 +1,41 @@ -32768 +#include +int match_re (char* arg0) { + int var0 = strlen(arg0); + int var1 = 0; + if (var1 < var0) { + if (arg0[var1] == 97) { + var1 = var1 + 1; + label0: + if (var1 < var0) { + if (arg0[var1] == 98) { + var1 = var1 + 1; + goto label0; + } + if (arg0[var1] == 99) { + label1: + var1 = var1 + 1; + if (var1 < var0) { + if (arg0[var1] == 99) { + goto label1; + } + if (arg0[var1] == 100) { + label2: + var1 = var1 + 1; + if (var1 < var0) { + label3: + return 0; + } + return 1; + } + } + } else { + if (arg0[var1] == 100) { + goto label2; + } + } + } + } + } + goto label3; +} + diff --git a/samples/outputs/sample37 b/samples/outputs/sample37 index 333bc74..7ed6ff8 100644 --- a/samples/outputs/sample37 +++ b/samples/outputs/sample37 @@ -1,29 +1 @@ -void __global__ cuda_kernel_0 (int* arg0) { - int var2 = blockIdx.x * 512 + threadIdx.x; - arg0[var2] = 0; -} - -void __global__ cuda_kernel_1 (int* arg0) { - int var5 = blockIdx.x * 512 + threadIdx.x; - arg0[var5] = 0; -} - -char ret_2_0[sizeof(int*)] __device__; -void __global__ cuda_kernel_2 (int* arg0) { - int var8 = blockIdx.x * 512 + threadIdx.x; - arg0[var8] = 0; - if (!(blockIdx.x * blockDim.x + threadIdx.x)) { - runtime::cudaMemcpyToSymbolMagic(ret_2_0, arg0); - } -} - -void bar (int* arg0) { - cuda_kernel_0<<<128, 512>>>(arg0); - cudaDeviceSynchronize(); - runtime::LaunchCooperativeKernel((void*)cuda_kernel_1, 128, 512, arg0); - cudaDeviceSynchronize(); - runtime::LaunchCooperativeKernel((void*)cuda_kernel_2, 128, 512, arg0); - cudaDeviceSynchronize(); - runtime::cudaMemcpyFromSymbolMagic(&arg0, ret_2_0); -} - +5 diff --git a/samples/outputs/sample38 b/samples/outputs/sample38 index ef56c07..96e6831 100644 --- a/samples/outputs/sample38 +++ b/samples/outputs/sample38 @@ -1,78 +1,13 @@ -STMT_BLOCK - DECL_STMT - NAMED_TYPE (FooT) - VAR (var0) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var0) - PLUS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (1) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var1) - MEMBER_ACCESS_EXPR (member) - VAR_EXPR - VAR (var0) - DECL_STMT - NAMED_TYPE (FooT) - VAR (var2) - VAR_EXPR - VAR (var0) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var2) - VAR_EXPR - VAR (var0) - DECL_STMT - POINTER_TYPE - NAMED_TYPE (FooT) - VAR (var3) - ADDR_OF_EXPR - VAR_EXPR - VAR (var0) - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (member) - SQ_BKT_EXPR - VAR_EXPR - VAR (var3) - INT_CONST (0) - INT_CONST (0) - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (member) - SQ_BKT_EXPR - VAR_EXPR - VAR (var3) - INT_CONST (0) - INT_CONST (1) - DECL_STMT - NAMED_TYPE (FooT) - VAR (var4) - SQ_BKT_EXPR - VAR_EXPR - VAR (var3) - INT_CONST (0) - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (member) - VAR_EXPR - VAR (var4) - INT_CONST (3) -{ - FooT var0; - var0 = var0 + 1; - int var1 = var0.member; - FooT var2 = var0; - var2 = var0; - FooT* var3 = &var0; - var3->member = 0; - var3->member = 1; - FooT var4 = *var3; - var4.member = 3; +void bar (void) { + int var0[10] = 0; + for (int var1 = 0; var1 < 10; var1 = var1 + 1) { + *var0 = *var0 + var1; + var0[var1] = var0[var1] * 2; + } + for (int var2 = 0; var2 < 10; (var2 = var2 + 1) - 1) { + *var0 = *var0 - var2; + var0[var2] = var0[var2] / 2; + } + (*var0 = *var0 + 1) - 1; } + diff --git a/samples/outputs/sample39 b/samples/outputs/sample39 new file mode 100644 index 0000000..91de929 --- /dev/null +++ b/samples/outputs/sample39 @@ -0,0 +1,50 @@ +void foo (void) { + int var0; + int var1; + int var2; + var0 = 1; + var1 = var0 + 2; + var2 = var1 + var0; + int var3 = 0; + int var4 = var0 + 4; + int var5 = 0; + int var6 = 0; + int var7 = 1; + int var8 = 2; + int var9; + int var10; + int var11 = var3; + int var12 = var4; + int var13 = var5; + int var14 = var6; + int var15 = var9; + int var16 = var10; + int var17; + int var18; + int var19; + int var20; + int* var21; + var20 = 0; + int var22; + int* var23; + var22 = 0; + int var24; + int* var25; + var24 = 0; + int var26; + int* var27; + var26 = 0; + int var28; + int* var29; + var28 = 0; + var21 = &var22; + int var30 = var20; + int* var31 = var21; + int var32 = var22; + int* var33 = var23; + int var34 = var30; + int* var35 = var31; + int var36 = var32; + int* var37 = var33; +} + diff --git a/samples/outputs/sample40 b/samples/outputs/sample40 index e7ea5a8..5899e67 100644 --- a/samples/outputs/sample40 +++ b/samples/outputs/sample40 @@ -1,53 +1,35 @@ -#include -int match_re (char* arg0) { - int var2; - int var4; - int var0 = strlen(arg0); +void staged (void) { + int var0 = 24; + if (var0) { + } int var1 = 0; - if (var1 < var0) { - if (arg0[var1] == 97) { - var1 = var1 + 1; - label0: - if (var1 < var0) { - if (arg0[var1] == 98) { - var1 = var1 + 1; - goto label0; - } - if (arg0[var1] == 99) { - label1: - var1 = var1 + 1; - if (var1 < var0) { - if (arg0[var1] == 99) { - goto label1; - } - if (arg0[var1] == 100) { - label2: - var1 = var1 + 1; - if (var1 < var0) { - var2 = 0; - return var2; - } - return 1; - } - var2 = 0; - return var2; - } - var4 = 0; - return var4; - } - if (arg0[var1] == 100) { - goto label2; - } - var2 = 0; - return var2; - } - var4 = 0; - return var4; - } - var2 = 0; - return var2; + var1 != 1; + int var2 = 32; + if (var2) { } - var4 = 0; - return var4; + int var3 = 0; + var1 != 1 && var3 != 1; +} + +void staged2 (void) { + int var0 = 0; + for (int var1 = 0; var1 < 5; var1 = var1 + 1) { + var0 = var0 + 1; + } + int var2 = var0; + for (int var3 = 0; var3 < var0; var3 = var3 + 1) { + var2 = var2 + 1; + } +} + +void staged2 (void) { + int var0 = 0; + for (int var1 = 0; var1 < 5; var1 = var1 + 1) { + var0 = var0 + 1; + } + int var2 = var0; + for (int var3 = 0; var3 < var0; var3 = var3 + 1) { + var2 = var2 + 1; + } } diff --git a/samples/outputs/sample41 b/samples/outputs/sample41 index 7ed6ff8..ac31407 100644 --- a/samples/outputs/sample41 +++ b/samples/outputs/sample41 @@ -1 +1,26 @@ -5 +a +bb +ccc +dddd +eeeee +ffffff +ggggggg +hhhhhhhh +iiiiiiiii +jjjjjjjjjj +kkkkkkkkkkk +llllllllllll +mmmmmmmmmmmmm +nnnnnnnnnnnnnn +ooooooooooooooo +pppppppppppppppp +qqqqqqqqqqqqqqqqq +rrrrrrrrrrrrrrrrrr +sssssssssssssssssss +tttttttttttttttttttt +uuuuuuuuuuuuuuuuuuuuu +vvvvvvvvvvvvvvvvvvvvvv +wwwwwwwwwwwwwwwwwwwwwww +xxxxxxxxxxxxxxxxxxxxxxxx +yyyyyyyyyyyyyyyyyyyyyyyyy +zzzzzzzzzzzzzzzzzzzzzzzzzz diff --git a/samples/outputs/sample42 b/samples/outputs/sample42 index 96e6831..66a738b 100644 --- a/samples/outputs/sample42 +++ b/samples/outputs/sample42 @@ -1,13 +1,113 @@ -void bar (void) { - int var0[10] = 0; - for (int var1 = 0; var1 < 10; var1 = var1 + 1) { - *var0 = *var0 + var1; - var0[var1] = var0[var1] * 2; - } - for (int var2 = 0; var2 < 10; (var2 = var2 + 1) - 1) { - *var0 = *var0 - var2; - var0[var2] = var0[var2] / 2; - } - (*var0 = *var0 + 1) - 1; +FUNC_DECL (my_bar) + SCALAR_TYPE (VOID) + STMT_BLOCK + DECL_STMT + NAMED_TYPE (FooT) + VAR (var0) + NO_INITIALIZATION + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var0) + PLUS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (1) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var1) + MEMBER_ACCESS_EXPR (member) + VAR_EXPR + VAR (var0) + DECL_STMT + NAMED_TYPE (FooT) + VAR (var2) + VAR_EXPR + VAR (var0) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var2) + VAR_EXPR + VAR (var0) + DECL_STMT + NAMED_TYPE (BarT) + VAR (var3) + NO_INITIALIZATION + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (second_member) + VAR_EXPR + VAR (var3) + PLUS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (1) + DECL_STMT + NAMED_TYPE (CarT) + SCALAR_TYPE (INT) + NAMED_TYPE (BarT) + VAR (var4) + NO_INITIALIZATION + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (my_member) + VAR_EXPR + VAR (var4) + MEMBER_ACCESS_EXPR (member) + VAR_EXPR + VAR (var0) + DECL_STMT + POINTER_TYPE + NAMED_TYPE (FooT) + VAR (var5) + NO_INITIALIZATION + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (member) + SQ_BKT_EXPR + VAR_EXPR + VAR (var5) + INT_CONST (0) + MEMBER_ACCESS_EXPR (my_member) + VAR_EXPR + VAR (var4) + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (member) + SQ_BKT_EXPR + VAR_EXPR + VAR (var5) + INT_CONST (0) + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (member) + SQ_BKT_EXPR + VAR_EXPR + VAR (var5) + INT_CONST (3) + INT_CONST (0) +struct FooT { + int member; +}; +struct BarT { + int my_member; + int second_member; +}; +void my_bar (void) { + FooT var0; + var0 = var0 + 1; + int var1 = var0.member; + FooT var2 = var0; + var2 = var0; + BarT var3; + var3.second_member = var0 + 1; + CarT var4; + var4.my_member = var0.member; + FooT* var5; + var5->member = var4.my_member; + var5->member = 0; + var5[3].member = 0; } diff --git a/samples/outputs/sample43 b/samples/outputs/sample43 index 91de929..7117443 100644 --- a/samples/outputs/sample43 +++ b/samples/outputs/sample43 @@ -1,50 +1,86 @@ -void foo (void) { - int var0; - int var1; - int var2; - var0 = 1; - var1 = var0 + 2; - var2 = var1 + var0; +FUNC_DECL (my_bar) + SCALAR_TYPE (VOID) + STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (var0) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var1) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var2) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var3) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var4) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var5) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var6) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var7) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var8) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var9) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var10) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var11) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var12) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var13) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var14) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var15) + INT_CONST (0) +void my_bar (void) { + int var0 = 0; + int var1 = 0; + int var2 = 0; int var3 = 0; - int var4 = var0 + 4; + int var4 = 0; int var5 = 0; int var6 = 0; - int var7 = 1; - int var8 = 2; - int var9; - int var10; - int var11 = var3; - int var12 = var4; - int var13 = var5; - int var14 = var6; - int var15 = var9; - int var16 = var10; - int var17; - int var18; - int var19; - int var20; - int* var21; - var20 = 0; - int var22; - int* var23; - var22 = 0; - int var24; - int* var25; - var24 = 0; - int var26; - int* var27; - var26 = 0; - int var28; - int* var29; - var28 = 0; - var21 = &var22; - int var30 = var20; - int* var31 = var21; - int var32 = var22; - int* var33 = var23; - int var34 = var30; - int* var35 = var31; - int var36 = var32; - int* var37 = var33; + int var7 = 0; + int var8 = 0; + int var9 = 0; + int var10 = 0; + int var11 = 0; + int var12 = 0; + int var13 = 0; + int var14 = 0; + int var15 = 0; } diff --git a/samples/outputs/sample44 b/samples/outputs/sample44 index 5899e67..b027aea 100644 --- a/samples/outputs/sample44 +++ b/samples/outputs/sample44 @@ -1,35 +1,42 @@ -void staged (void) { - int var0 = 24; - if (var0) { - } +FUNC_DECL (my_bar) + SCALAR_TYPE (VOID) + STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (var0) + NO_INITIALIZATION + DECL_STMT + SCALAR_TYPE (INT) + VAR (var1) + INT_CONST (0) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var2) + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var1) + INT_CONST (1) + WHILE_STMT + INT_CONST (1) + STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (var3) + INT_CONST (1) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var4) + INT_CONST (2) +void my_bar (void) { + int var0; int var1 = 0; - var1 != 1; - int var2 = 32; - if (var2) { - } - int var3 = 0; - var1 != 1 && var3 != 1; -} - -void staged2 (void) { - int var0 = 0; - for (int var1 = 0; var1 < 5; var1 = var1 + 1) { - var0 = var0 + 1; - } - int var2 = var0; - for (int var3 = 0; var3 < var0; var3 = var3 + 1) { - var2 = var2 + 1; - } -} - -void staged2 (void) { - int var0 = 0; - for (int var1 = 0; var1 < 5; var1 = var1 + 1) { - var0 = var0 + 1; - } - int var2 = var0; - for (int var3 = 0; var3 < var0; var3 = var3 + 1) { - var2 = var2 + 1; + int var2 = 0; + var1 = 1; + while (1) { + int var3 = 1; + int var4 = 2; } } diff --git a/samples/outputs/sample45 b/samples/outputs/sample45 index ac31407..6f8610c 100644 --- a/samples/outputs/sample45 +++ b/samples/outputs/sample45 @@ -1,26 +1,23 @@ -a -bb -ccc -dddd -eeeee -ffffff -ggggggg -hhhhhhhh -iiiiiiiii -jjjjjjjjjj -kkkkkkkkkkk -llllllllllll -mmmmmmmmmmmmm -nnnnnnnnnnnnnn -ooooooooooooooo -pppppppppppppppp -qqqqqqqqqqqqqqqqq -rrrrrrrrrrrrrrrrrr -sssssssssssssssssss -tttttttttttttttttttt -uuuuuuuuuuuuuuuuuuuuu -vvvvvvvvvvvvvvvvvvvvvv -wwwwwwwwwwwwwwwwwwwwwww -xxxxxxxxxxxxxxxxxxxxxxxx -yyyyyyyyyyyyyyyyyyyyyyyyy -zzzzzzzzzzzzzzzzzzzzzzzzzz +FUNC_DECL (foo) + SCALAR_TYPE (VOID) + STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (my_var) + NO_INITIALIZATION + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (my_var) + INT_CONST (1) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var0) + VAR_EXPR + VAR (my_var) +void foo (void) { + int my_var; + my_var = 1; + int var0 = my_var; +} + diff --git a/samples/outputs/sample46 b/samples/outputs/sample46 index 66a738b..5466000 100644 --- a/samples/outputs/sample46 +++ b/samples/outputs/sample46 @@ -1,113 +1,56 @@ -FUNC_DECL (my_bar) +FUNC_DECL (bar) SCALAR_TYPE (VOID) STMT_BLOCK DECL_STMT - NAMED_TYPE (FooT) + SCALAR_TYPE (INT) VAR (var0) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var0) - PLUS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (1) + INT_CONST (0) DECL_STMT SCALAR_TYPE (INT) VAR (var1) - MEMBER_ACCESS_EXPR (member) - VAR_EXPR - VAR (var0) - DECL_STMT - NAMED_TYPE (FooT) - VAR (var2) - VAR_EXPR - VAR (var0) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var2) - VAR_EXPR - VAR (var0) - DECL_STMT - NAMED_TYPE (BarT) - VAR (var3) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (second_member) - VAR_EXPR - VAR (var3) - PLUS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (1) - DECL_STMT - NAMED_TYPE (CarT) - SCALAR_TYPE (INT) - NAMED_TYPE (BarT) - VAR (var4) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (my_member) - VAR_EXPR - VAR (var4) - MEMBER_ACCESS_EXPR (member) - VAR_EXPR - VAR (var0) - DECL_STMT - POINTER_TYPE - NAMED_TYPE (FooT) - VAR (var5) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (member) - SQ_BKT_EXPR - VAR_EXPR - VAR (var5) - INT_CONST (0) - MEMBER_ACCESS_EXPR (my_member) - VAR_EXPR - VAR (var4) - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (member) - SQ_BKT_EXPR - VAR_EXPR - VAR (var5) - INT_CONST (0) - INT_CONST (0) - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (member) - SQ_BKT_EXPR + INT_CONST (0) + WHILE_STMT + INT_CONST (1) + STMT_BLOCK + IF_STMT + NE_EXPR VAR_EXPR - VAR (var5) - INT_CONST (3) - INT_CONST (0) -struct FooT { - int member; -}; -struct BarT { - int my_member; - int second_member; -}; -void my_bar (void) { - FooT var0; - var0 = var0 + 1; - int var1 = var0.member; - FooT var2 = var0; - var2 = var0; - BarT var3; - var3.second_member = var0 + 1; - CarT var4; - var4.my_member = var0.member; - FooT* var5; - var5->member = var4.my_member; - var5->member = 0; - var5[3].member = 0; + VAR (var0) + INT_CONST (1) + STMT_BLOCK + IF_STMT + EQUALS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (2) + STMT_BLOCK + WHILE_STMT + NE_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (3) + STMT_BLOCK + STMT_BLOCK + STMT_BLOCK + WHILE_STMT + NE_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (3) + STMT_BLOCK +void bar (void) { + int var0 = 0; + int var1 = 0; + while (1) { + if (var0 != 1) { + if (var0 == 2) { + while (var0 != 3) { + } + } + } else { + while (var0 != 3) { + } + } + } } diff --git a/samples/outputs/sample47 b/samples/outputs/sample47 index 7117443..8ae537e 100644 --- a/samples/outputs/sample47 +++ b/samples/outputs/sample47 @@ -1,86 +1,125 @@ -FUNC_DECL (my_bar) +FUNC_DECL (bar) SCALAR_TYPE (VOID) STMT_BLOCK DECL_STMT SCALAR_TYPE (INT) VAR (var0) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var1) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var2) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var3) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var4) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var5) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var6) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var7) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var8) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var9) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var10) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var11) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var12) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var13) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var14) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var15) - INT_CONST (0) -void my_bar (void) { - int var0 = 0; - int var1 = 0; - int var2 = 0; - int var3 = 0; - int var4 = 0; - int var5 = 0; - int var6 = 0; - int var7 = 0; - int var8 = 0; - int var9 = 0; - int var10 = 0; - int var11 = 0; - int var12 = 0; - int var13 = 0; - int var14 = 0; - int var15 = 0; + INT_CONST (5) + WHILE_STMT + LT_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (10) + STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (control_guard0) + INT_CONST (0) + WHILE_STMT + GT_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (100) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (control_guard0) + INT_CONST (0) + IF_STMT + EQUALS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (0) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var0) + PLUS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (5) + WHILE_STMT + NE_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (-1) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var0) + PLUS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (6) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (control_guard0) + INT_CONST (1) + BREAK_STMT + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var0) + PLUS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (4) + IF_STMT + VAR_EXPR + VAR (control_guard0) + STMT_BLOCK + CONTINUE_STMT + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var0) + PLUS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (5) + WHILE_STMT + NE_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (-1) + STMT_BLOCK + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var0) + PLUS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (6) +void bar (void) { + int var0 = 5; + while (var0 < 10) { + int control_guard0 = 0; + while (var0 > 100) { + control_guard0 = 0; + if (var0 == 0) { + var0 = var0 + 5; + while (var0 != -1) { + var0 = var0 + 6; + } + control_guard0 = 1; + break; + } + var0 = var0 + 4; + } + if (control_guard0) { + continue; + } + var0 = var0 + 5; + while (var0 != -1) { + var0 = var0 + 6; + } + } } diff --git a/samples/outputs/sample48 b/samples/outputs/sample48 index b027aea..009efe3 100644 --- a/samples/outputs/sample48 +++ b/samples/outputs/sample48 @@ -1,42 +1,49 @@ -FUNC_DECL (my_bar) - SCALAR_TYPE (VOID) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (var0) - NO_INITIALIZATION - DECL_STMT - SCALAR_TYPE (INT) - VAR (var1) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var2) - INT_CONST (0) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var1) - INT_CONST (1) - WHILE_STMT - INT_CONST (1) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (var3) - INT_CONST (1) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var4) - INT_CONST (2) -void my_bar (void) { - int var0; - int var1 = 0; - int var2 = 0; - var1 = 1; - while (1) { - int var3 = 1; - int var4 = 2; - } +int isEven (int arg0) { + if (arg0 == 0) { + return 1; + } + if (arg0 == 1) { + return 0; + } + if (arg0 == 2) { + return 1; + } + if (arg0 == 3) { + return 0; + } + if (arg0 == 4) { + return 1; + } + if (arg0 == 5) { + return 0; + } + if (arg0 == 6) { + return 1; + } + if (arg0 == 7) { + return 0; + } + if (arg0 == 8) { + return 1; + } + if (arg0 == 9) { + return 0; + } + if (arg0 == 10) { + return 1; + } + if (arg0 == 11) { + return 0; + } + if (arg0 == 12) { + return 1; + } + if (arg0 == 13) { + return 0; + } + if (arg0 == 14) { + return 1; + } + return 0; } diff --git a/samples/outputs/sample49 b/samples/outputs/sample49 index 6f8610c..1cda47f 100644 --- a/samples/outputs/sample49 +++ b/samples/outputs/sample49 @@ -1,23 +1,40 @@ -FUNC_DECL (foo) - SCALAR_TYPE (VOID) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (my_var) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (my_var) - INT_CONST (1) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var0) - VAR_EXPR - VAR (my_var) void foo (void) { - int my_var; - my_var = 1; - int var0 = my_var; + int member_var; + int var0 = 0; + if (var0) { + member_var = 1; + } else { + member_var = 2; + } + if (member_var % 2 == 0) { + member_var = member_var + 0; + } + if (member_var % 2 == 0) { + member_var = member_var + 1; + } + if (member_var % 2 == 0) { + member_var = member_var + 2; + } + if (member_var % 2 == 0) { + member_var = member_var + 3; + } + if (member_var % 2 == 0) { + member_var = member_var + 4; + } + if (member_var % 2 == 0) { + member_var = member_var + 5; + } + if (member_var % 2 == 0) { + member_var = member_var + 6; + } + if (member_var % 2 == 0) { + member_var = member_var + 7; + } + if (member_var % 2 == 0) { + member_var = member_var + 8; + } + if (member_var % 2 == 0) { + member_var = member_var + 9; + } } diff --git a/samples/outputs/sample50 b/samples/outputs/sample50 index 5466000..395c25c 100644 --- a/samples/outputs/sample50 +++ b/samples/outputs/sample50 @@ -1,56 +1,20 @@ -FUNC_DECL (bar) - SCALAR_TYPE (VOID) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (var0) - INT_CONST (0) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var1) - INT_CONST (0) - WHILE_STMT - INT_CONST (1) - STMT_BLOCK - IF_STMT - NE_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (1) - STMT_BLOCK - IF_STMT - EQUALS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (2) - STMT_BLOCK - WHILE_STMT - NE_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (3) - STMT_BLOCK - STMT_BLOCK - STMT_BLOCK - WHILE_STMT - NE_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (3) - STMT_BLOCK void bar (void) { int var0 = 0; - int var1 = 0; - while (1) { - if (var0 != 1) { - if (var0 == 2) { - while (var0 != 3) { - } - } - } else { - while (var0 != 3) { - } - } + int var1; + int var2; + if (var0) { + int var3 = 1; + int& var4 = var1; + int var5; + int var6 = var3; + var3 = var3 + var4; + } else { + int var7 = 2; + int& var8 = var1; + int var9; + int var10 = var7; + var7 = var7 + var8; } + var1 = var1 + 3; } diff --git a/samples/outputs/sample51 b/samples/outputs/sample51 index 8ae537e..43bf0b2 100644 --- a/samples/outputs/sample51 +++ b/samples/outputs/sample51 @@ -1,125 +1,9 @@ -FUNC_DECL (bar) - SCALAR_TYPE (VOID) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (var0) - INT_CONST (5) - WHILE_STMT - LT_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (10) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (control_guard0) - INT_CONST (0) - WHILE_STMT - GT_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (100) - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (control_guard0) - INT_CONST (0) - IF_STMT - EQUALS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (0) - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var0) - PLUS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (5) - WHILE_STMT - NE_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (-1) - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var0) - PLUS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (6) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (control_guard0) - INT_CONST (1) - BREAK_STMT - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var0) - PLUS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (4) - IF_STMT - VAR_EXPR - VAR (control_guard0) - STMT_BLOCK - CONTINUE_STMT - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var0) - PLUS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (5) - WHILE_STMT - NE_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (-1) - STMT_BLOCK - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var0) - PLUS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (6) void bar (void) { - int var0 = 5; - while (var0 < 10) { - int control_guard0 = 0; - while (var0 > 100) { - control_guard0 = 0; - if (var0 == 0) { - var0 = var0 + 5; - while (var0 != -1) { - var0 = var0 + 6; - } - control_guard0 = 1; - break; - } - var0 = var0 + 4; - } - if (control_guard0) { - continue; - } - var0 = var0 + 5; - while (var0 != -1) { - var0 = var0 + 6; - } - } + int var0; + char var1; + int var2; + char var3; + var0 = var1; + var3 = var2; } diff --git a/samples/outputs/sample52 b/samples/outputs/sample52 index 009efe3..443e6d8 100644 --- a/samples/outputs/sample52 +++ b/samples/outputs/sample52 @@ -1,49 +1,64 @@ -int isEven (int arg0) { - if (arg0 == 0) { - return 1; - } - if (arg0 == 1) { - return 0; - } - if (arg0 == 2) { - return 1; - } - if (arg0 == 3) { - return 0; - } - if (arg0 == 4) { - return 1; - } - if (arg0 == 5) { - return 0; - } - if (arg0 == 6) { - return 1; - } - if (arg0 == 7) { - return 0; - } - if (arg0 == 8) { - return 1; - } - if (arg0 == 9) { - return 0; - } - if (arg0 == 10) { - return 1; - } - if (arg0 == 11) { - return 0; - } - if (arg0 == 12) { - return 1; - } - if (arg0 == 13) { - return 0; - } - if (arg0 == 14) { - return 1; - } - return 0; +FUNC_DECL (bar) + SCALAR_TYPE (VOID) + STMT_BLOCK + DECL_STMT + NAMED_TYPE (my_type) + VAR (var0) + NO_INITIALIZATION + DECL_STMT + NAMED_TYPE (custom_struct0) + VAR (var1) + NO_INITIALIZATION + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (nested) + VAR_EXPR + VAR (var0) + VAR_EXPR + VAR (var1) + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (mem0) + MEMBER_ACCESS_EXPR (nested) + VAR_EXPR + VAR (var0) + MEMBER_ACCESS_EXPR (mem0) + VAR_EXPR + VAR (var0) + EXPR_STMT + MINUS_EXPR + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (mem1) + MEMBER_ACCESS_EXPR (nested) + VAR_EXPR + VAR (var0) + PLUS_EXPR + MEMBER_ACCESS_EXPR (mem1) + MEMBER_ACCESS_EXPR (nested) + VAR_EXPR + VAR (var0) + INT_CONST (1) + INT_CONST (1) + EXPR_STMT + ASSIGN_EXPR + MEMBER_ACCESS_EXPR (mem0) + VAR_EXPR + VAR (p) + INT_CONST (0) +struct custom_struct0 { + int mem0; + float mem1; +}; +struct my_type { + custom_struct0 nested; + int mem0; +}; +void bar (void) { + my_type var0; + custom_struct0 var1; + var0.nested = var1; + var0.nested.mem0 = var0.mem0; + (var0.nested.mem1 = var0.nested.mem1 + 1) - 1; + p.mem0 = 0; } diff --git a/samples/outputs/sample53 b/samples/outputs/sample53 index 1cda47f..99a6710 100644 --- a/samples/outputs/sample53 +++ b/samples/outputs/sample53 @@ -1,40 +1,12 @@ -void foo (void) { - int member_var; +void bar (void) { int var0 = 0; - if (var0) { - member_var = 1; - } else { - member_var = 2; - } - if (member_var % 2 == 0) { - member_var = member_var + 0; - } - if (member_var % 2 == 0) { - member_var = member_var + 1; - } - if (member_var % 2 == 0) { - member_var = member_var + 2; - } - if (member_var % 2 == 0) { - member_var = member_var + 3; - } - if (member_var % 2 == 0) { - member_var = member_var + 4; - } - if (member_var % 2 == 0) { - member_var = member_var + 5; - } - if (member_var % 2 == 0) { - member_var = member_var + 6; - } - if (member_var % 2 == 0) { - member_var = member_var + 7; - } - if (member_var % 2 == 0) { - member_var = member_var + 8; - } - if (member_var % 2 == 0) { - member_var = member_var + 9; - } + int* var1 = &var0; + (*var1 = *var1 + 1) - 1; + int var2 = 0; + (var2 = var2 + 1) - 1; + int var3 = var2; + (var2 = var2 + 1) - 1; + int var4 = var3; + (var4 = var4 + 1) - 1; } diff --git a/samples/outputs/sample54 b/samples/outputs/sample54 index 395c25c..687f924 100644 --- a/samples/outputs/sample54 +++ b/samples/outputs/sample54 @@ -1,20 +1,12 @@ -void bar (void) { - int var0 = 0; - int var1; - int var2; - if (var0) { - int var3 = 1; - int& var4 = var1; - int var5; - int var6 = var3; - var3 = var3 + var4; - } else { - int var7 = 2; - int& var8 = var1; - int var9; - int var10 = var7; - var7 = var7 + var8; - } - var1 = var1 + 3; +FUNC_DECL (bar) + SCALAR_TYPE (VOID) + VAR (arg0) + STMT_BLOCK + DECL_STMT + SCALAR_TYPE (INT) + VAR (var0) + NO_INITIALIZATION +void bar (int arg0) { + int var0; } diff --git a/samples/outputs/sample55 b/samples/outputs/sample55 index 43bf0b2..64b6497 100644 --- a/samples/outputs/sample55 +++ b/samples/outputs/sample55 @@ -1,9 +1,29 @@ +FUNC_DECL (bar) + SCALAR_TYPE (VOID) + STMT_BLOCK + DECL_STMT + NAMED_TYPE (std::vector) + NAMED_TYPE (std::vector) + SCALAR_TYPE (INT) + VAR (var0) + NO_INITIALIZATION + EXPR_STMT + FUNCTION_CALL_EXPR + MEMBER_ACCESS_EXPR (resize) + VAR_EXPR + VAR (var0) + INT_CONST (2) + EXPR_STMT + FUNCTION_CALL_EXPR + MEMBER_ACCESS_EXPR (resize) + SQ_BKT_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (0) + INT_CONST (1) void bar (void) { - int var0; - char var1; - int var2; - char var3; - var0 = var1; - var3 = var2; + std::vector> var0; + var0.resize(2); + var0[0].resize(1); } diff --git a/samples/outputs/sample56 b/samples/outputs/sample56 index 443e6d8..d893b64 100644 --- a/samples/outputs/sample56 +++ b/samples/outputs/sample56 @@ -1,64 +1,22 @@ -FUNC_DECL (bar) - SCALAR_TYPE (VOID) - STMT_BLOCK - DECL_STMT - NAMED_TYPE (my_type) - VAR (var0) - NO_INITIALIZATION - DECL_STMT - NAMED_TYPE (custom_struct0) - VAR (var1) - NO_INITIALIZATION - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (nested) - VAR_EXPR - VAR (var0) - VAR_EXPR - VAR (var1) - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (mem0) - MEMBER_ACCESS_EXPR (nested) - VAR_EXPR - VAR (var0) - MEMBER_ACCESS_EXPR (mem0) - VAR_EXPR - VAR (var0) - EXPR_STMT - MINUS_EXPR - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (mem1) - MEMBER_ACCESS_EXPR (nested) - VAR_EXPR - VAR (var0) - PLUS_EXPR - MEMBER_ACCESS_EXPR (mem1) - MEMBER_ACCESS_EXPR (nested) - VAR_EXPR - VAR (var0) - INT_CONST (1) - INT_CONST (1) - EXPR_STMT - ASSIGN_EXPR - MEMBER_ACCESS_EXPR (mem0) - VAR_EXPR - VAR (p) - INT_CONST (0) -struct custom_struct0 { - int mem0; - float mem1; -}; -struct my_type { - custom_struct0 nested; - int mem0; -}; void bar (void) { - my_type var0; - custom_struct0 var1; - var0.nested = var1; - var0.nested.mem0 = var0.mem0; - (var0.nested.mem1 = var0.nested.mem1 + 1) - 1; - p.mem0 = 0; + int var0; + int var2; + int var3; + float var4; + float var5; + int var8; + if (var2 < var3) { + var8 = var3; + } else { + var8 = var2; + } + float var12; + if (var4 < var5) { + var12 = var5; + } else { + var12 = var4; + } + int* var14 = &var0; + *var14 = 0; } diff --git a/samples/outputs/sample57 b/samples/outputs/sample57 index 99a6710..75090ec 100644 --- a/samples/outputs/sample57 +++ b/samples/outputs/sample57 @@ -1,12 +1,5 @@ void bar (void) { - int var0 = 0; - int* var1 = &var0; - (*var1 = *var1 + 1) - 1; - int var2 = 0; - (var2 = var2 + 1) - 1; - int var3 = var2; - (var2 = var2 + 1) - 1; - int var4 = var3; - (var4 = var4 + 1) - 1; + int var0 = 1; + int var1 = 0; } diff --git a/samples/outputs/sample58 b/samples/outputs/sample58 index 687f924..d815fe6 100644 --- a/samples/outputs/sample58 +++ b/samples/outputs/sample58 @@ -1,12 +1,73 @@ -FUNC_DECL (bar) +Found 1 matches +----- +ASSIGN_EXPR + VAR_EXPR + VAR (var0) + PLUS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (1) +----- +Found 1 matches +----- +PLUS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (0) +----- +After all replacements +FUNC_DECL (foo) SCALAR_TYPE (VOID) - VAR (arg0) STMT_BLOCK DECL_STMT SCALAR_TYPE (INT) VAR (var0) - NO_INITIALIZATION -void bar (int arg0) { - int var0; + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var0) + PLUS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (1) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var1) + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var1) + PLUS_EXPR + VAR_EXPR + VAR (var0) + INT_CONST (1) + DECL_STMT + SCALAR_TYPE (INT) + VAR (var2) + INT_CONST (0) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var2) + PLUS_EXPR + VAR_EXPR + VAR (var2) + INT_CONST (2) + EXPR_STMT + ASSIGN_EXPR + VAR_EXPR + VAR (var2) + VAR_EXPR + VAR (var0) +void foo (void) { + int var0 = 0; + var0 = var0 + 1; + int var1 = 0; + var1 = var0 + 1; + int var2 = 0; + var2 = var2 + 2; + var2 = var0; } diff --git a/samples/outputs/sample59 b/samples/outputs/sample59 index 64b6497..dada18e 100644 --- a/samples/outputs/sample59 +++ b/samples/outputs/sample59 @@ -1,29 +1,10 @@ -FUNC_DECL (bar) - SCALAR_TYPE (VOID) - STMT_BLOCK - DECL_STMT - NAMED_TYPE (std::vector) - NAMED_TYPE (std::vector) - SCALAR_TYPE (INT) - VAR (var0) - NO_INITIALIZATION - EXPR_STMT - FUNCTION_CALL_EXPR - MEMBER_ACCESS_EXPR (resize) - VAR_EXPR - VAR (var0) - INT_CONST (2) - EXPR_STMT - FUNCTION_CALL_EXPR - MEMBER_ACCESS_EXPR (resize) - SQ_BKT_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (0) - INT_CONST (1) +struct linked_list { + linked_list* next; + struct foo* other; +}; void bar (void) { - std::vector> var0; - var0.resize(2); - var0[0].resize(1); + linked_list* var0; + var0->next->next->next = 0; + var0->other = 0; } diff --git a/samples/outputs/sample60 b/samples/outputs/sample60 index d893b64..a278b1e 100644 --- a/samples/outputs/sample60 +++ b/samples/outputs/sample60 @@ -1,22 +1,22 @@ +int power (int arg0, int arg1) { + int var0 = arg1; + int var1 = 1; + int var2 = arg0; + while (var0 > 1) { + if (var0 % 2 == 1) { + var1 = var1 * var2; + } + var2 = var2 * var2; + var0 = var0 / 2; + } + return var1 * var2; +} + void bar (void) { int var0; - int var2; - int var3; - float var4; - float var5; - int var8; - if (var2 < var3) { - var8 = var3; - } else { - var8 = var2; - } - float var12; - if (var4 < var5) { - var12 = var5; - } else { - var12 = var4; + int var1 = var0 + 1; + while (var1) { + var0 = var0 + 1; } - int* var14 = &var0; - *var14 = 0; } diff --git a/samples/outputs/sample61 b/samples/outputs/sample61 index 75090ec..7b9043a 100644 --- a/samples/outputs/sample61 +++ b/samples/outputs/sample61 @@ -1,5 +1,21 @@ void bar (void) { - int var0 = 1; - int var1 = 0; + int var0 = 0ll; + if (var0 < 0ll) { + (var0 = var0 + 1) - 1; + } else { + (var0 = var0 - 1) + 1; + } + int var1 = 1ll; + if (var1 < 1ll) { + (var1 = var1 + 1) - 1; + } else { + (var1 = var1 - 1) + 1; + } + int var2 = 2ll; + if (var2 < 2ll) { + (var2 = var2 + 1) - 1; + } else { + (var2 = var2 - 1) + 1; + } } diff --git a/samples/outputs/sample62 b/samples/outputs/sample62 index d815fe6..d589fd5 100644 --- a/samples/outputs/sample62 +++ b/samples/outputs/sample62 @@ -1,73 +1,7 @@ -Found 1 matches ------ -ASSIGN_EXPR - VAR_EXPR - VAR (var0) - PLUS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (1) ------ -Found 1 matches ------ -PLUS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (0) ------ -After all replacements -FUNC_DECL (foo) - SCALAR_TYPE (VOID) - STMT_BLOCK - DECL_STMT - SCALAR_TYPE (INT) - VAR (var0) - INT_CONST (0) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var0) - PLUS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (1) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var1) - INT_CONST (0) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var1) - PLUS_EXPR - VAR_EXPR - VAR (var0) - INT_CONST (1) - DECL_STMT - SCALAR_TYPE (INT) - VAR (var2) - INT_CONST (0) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var2) - PLUS_EXPR - VAR_EXPR - VAR (var2) - INT_CONST (2) - EXPR_STMT - ASSIGN_EXPR - VAR_EXPR - VAR (var2) - VAR_EXPR - VAR (var0) -void foo (void) { - int var0 = 0; - var0 = var0 + 1; - int var1 = 0; - var1 = var0 + 1; - int var2 = 0; - var2 = var2 + 2; - var2 = var0; +void bar (void) { + int var0[] = {1, 2, 3}; + for (int var1 = 0; var1 < 3ll; var1 = var1 + 1) { + var0[var1] = var0[var1] + var0[var1 - 1]; + } } diff --git a/samples/outputs/sample63 b/samples/outputs/sample63 index dada18e..7505c4f 100644 --- a/samples/outputs/sample63 +++ b/samples/outputs/sample63 @@ -1,10 +1,11 @@ -struct linked_list { - linked_list* next; - struct foo* other; -}; void bar (void) { - linked_list* var0; - var0->next->next->next = 0; - var0->other = 0; + _Pragma("omp parallel for") + for (int var0 = 0; var0 < 10; var0 = var0 + 1) { + int var1 = 0; + _Pragma("unroll") + for (int var2 = 0; var2 < 15; var2 = var2 + 1) { + var1 = var1 + var2; + } + } } diff --git a/samples/outputs/sample64 b/samples/outputs/sample64 index a278b1e..1cc508f 100644 --- a/samples/outputs/sample64 +++ b/samples/outputs/sample64 @@ -1,22 +1,6 @@ -int power (int arg0, int arg1) { - int var0 = arg1; - int var1 = 1; - int var2 = arg0; - while (var0 > 1) { - if (var0 % 2 == 1) { - var1 = var1 * var2; - } - var2 = var2 * var2; - var0 = var0 / 2; - } - return var1 * var2; -} - void bar (void) { - int var0; - int var1 = var0 + 1; - while (var1) { - var0 = var0 + 1; - } + int* var0 = (int*)malloc(4ll); + var0[0] = 123; + free(var0); } diff --git a/samples/outputs/sample65 b/samples/outputs/sample65 index 7b9043a..d955777 100644 --- a/samples/outputs/sample65 +++ b/samples/outputs/sample65 @@ -1,21 +1,6 @@ -void bar (void) { - int var0 = 0ll; - if (var0 < 0ll) { - (var0 = var0 + 1) - 1; - } else { - (var0 = var0 - 1) + 1; - } - int var1 = 1ll; - if (var1 < 1ll) { - (var1 = var1 + 1) - 1; - } else { - (var1 = var1 - 1) + 1; - } - int var2 = 2ll; - if (var2 < 2ll) { - (var2 = var2 + 1) - 1; - } else { - (var2 = var2 - 1) + 1; +void bar (int* restrict arg0, int* restrict arg1, int arg2) { + for (int var0 = 0; var0 < arg2; (var0 = var0 + 1) - 1) { + arg0[var0] = arg1[var0]; } } diff --git a/samples/outputs/sample66 b/samples/outputs/sample66 deleted file mode 100644 index d589fd5..0000000 --- a/samples/outputs/sample66 +++ /dev/null @@ -1,7 +0,0 @@ -void bar (void) { - int var0[] = {1, 2, 3}; - for (int var1 = 0; var1 < 3ll; var1 = var1 + 1) { - var0[var1] = var0[var1] + var0[var1 - 1]; - } -} - diff --git a/samples/outputs/sample67 b/samples/outputs/sample67 deleted file mode 100644 index 7505c4f..0000000 --- a/samples/outputs/sample67 +++ /dev/null @@ -1,11 +0,0 @@ -void bar (void) { - _Pragma("omp parallel for") - for (int var0 = 0; var0 < 10; var0 = var0 + 1) { - int var1 = 0; - _Pragma("unroll") - for (int var2 = 0; var2 < 15; var2 = var2 + 1) { - var1 = var1 + var2; - } - } -} - diff --git a/samples/outputs/sample68 b/samples/outputs/sample68 deleted file mode 100644 index 1cc508f..0000000 --- a/samples/outputs/sample68 +++ /dev/null @@ -1,6 +0,0 @@ -void bar (void) { - int* var0 = (int*)malloc(4ll); - var0[0] = 123; - free(var0); -} - diff --git a/samples/outputs/sample69 b/samples/outputs/sample69 deleted file mode 100644 index d955777..0000000 --- a/samples/outputs/sample69 +++ /dev/null @@ -1,6 +0,0 @@ -void bar (int* restrict arg0, int* restrict arg1, int arg2) { - for (int var0 = 0; var0 < arg2; (var0 = var0 + 1) - 1) { - arg0[var0] = arg1[var0]; - } -} - diff --git a/samples/sample1.cpp b/samples/sample1.cpp index 6704c99..b5ab6e9 100644 --- a/samples/sample1.cpp +++ b/samples/sample1.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include @@ -24,6 +23,7 @@ static void foo(void) { a|=b; a^=b; ~b; + &b; } int main(int argc, char *argv[]) { builder::builder_context context; diff --git a/samples/sample10.cpp b/samples/sample10.cpp index 929834e..fea1caa 100644 --- a/samples/sample10.cpp +++ b/samples/sample10.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include diff --git a/samples/sample11.cpp b/samples/sample11.cpp index 5d6aea6..4934e8b 100644 --- a/samples/sample11.cpp +++ b/samples/sample11.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include diff --git a/samples/sample12.cpp b/samples/sample12.cpp index c75eea0..8b9c3df 100644 --- a/samples/sample12.cpp +++ b/samples/sample12.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" diff --git a/samples/sample13.cpp b/samples/sample13.cpp index 283f3de..47e7861 100644 --- a/samples/sample13.cpp +++ b/samples/sample13.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" diff --git a/samples/sample14.cpp b/samples/sample14.cpp index 2b81c18..b51cce7 100644 --- a/samples/sample14.cpp +++ b/samples/sample14.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include diff --git a/samples/sample15.cpp b/samples/sample15.cpp index a794121..af63390 100644 --- a/samples/sample15.cpp +++ b/samples/sample15.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include diff --git a/samples/sample16.cpp b/samples/sample16.cpp index 8ab0f37..7869554 100644 --- a/samples/sample16.cpp +++ b/samples/sample16.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include diff --git a/samples/sample17.cpp b/samples/sample17.cpp index fa45df0..a486e09 100644 --- a/samples/sample17.cpp +++ b/samples/sample17.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" diff --git a/samples/sample18.cpp b/samples/sample18.cpp index a28cd4b..29a5758 100644 --- a/samples/sample18.cpp +++ b/samples/sample18.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" diff --git a/samples/sample19.cpp b/samples/sample19.cpp index 1185dff..9e8b35f 100644 --- a/samples/sample19.cpp +++ b/samples/sample19.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include diff --git a/samples/sample2.cpp b/samples/sample2.cpp index 62ad668..a04e1a2 100644 --- a/samples/sample2.cpp +++ b/samples/sample2.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include diff --git a/samples/sample20.cpp b/samples/sample20.cpp index b1f673e..18c1e41 100644 --- a/samples/sample20.cpp +++ b/samples/sample20.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include diff --git a/samples/sample21.cpp b/samples/sample21.cpp index 4c7d7fc..35b4e44 100644 --- a/samples/sample21.cpp +++ b/samples/sample21.cpp @@ -1,43 +1,22 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" #include - using builder::dyn_var; using builder::static_var; - -// We are now deprecating foreign_exprs -class dummy { -public: - std::string value; - - // We have to define this so that the foreign_expr can check for - // equality - bool operator==(dummy &other) { - if (value == other.value) - return true; - return false; - } - - // Operator builder::builder is not defined anymore -}; - -// A simple straight line code with 2 variable declarations and one operator int main(int argc, char *argv[]) { builder::builder_context context; + // Code to test assignments between static var and normal vars + auto ast = context.extract_ast_from_function([=](void) { + static_var foo = 4 + 5; + dyn_var x = foo + 9; + dyn_var y = 8 + foo; - dummy foo; - foo.value = "foo"; - - auto ast = context.extract_ast_from_function([=] { - dyn_var x = 2; - // Since foreign functions are deprecated, use the value from foo - dyn_var bar = foo.value + x; + x = y + foo; }); - ast->dump(std::cout, 0); + block::c_code_generator::generate_code(ast, std::cout, 0); return 0; } diff --git a/samples/sample22.cpp b/samples/sample22.cpp index 2da2d8f..85069cf 100644 --- a/samples/sample22.cpp +++ b/samples/sample22.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" @@ -7,16 +6,36 @@ using builder::dyn_var; using builder::static_var; +static dyn_var foo(dyn_var x) { + int t; + if (x > 10) + t = 9; + else + t = 0; + return t; +} + +static void bar(void) { + dyn_var x; + + dyn_var t = foo(x); + if (t) { + dyn_var k = 0; + k = 0; + } + + // x = x + 1; + + if (x) { + dyn_var k = 0; + k = 0; + } +} + int main(int argc, char *argv[]) { builder::builder_context context; // Code to test assignments between static var and normal vars - auto ast = context.extract_ast_from_function([=](void) { - static_var foo = 4 + 5; - dyn_var x = foo + 9; - dyn_var y = 8 + foo; - - x = y + foo; - }); + auto ast = context.extract_ast_from_function(bar); ast->dump(std::cout, 0); block::c_code_generator::generate_code(ast, std::cout, 0); return 0; diff --git a/samples/sample23.cpp b/samples/sample23.cpp index 0349106..ab7b5b6 100644 --- a/samples/sample23.cpp +++ b/samples/sample23.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" @@ -7,35 +6,18 @@ using builder::dyn_var; using builder::static_var; -static dyn_var foo(dyn_var x) { - int t; - if (x > 10) - t = 9; - else - t = 0; - return t; -} - static void bar(void) { - dyn_var x; - - dyn_var t = foo(x); - if (t) { - dyn_var k = 0; - k = 0; - } - - // x = x + 1; - - if (x) { - dyn_var k = 0; - k = 0; + for (static_var i = 0; i < 10; i++) { + for (dyn_var> g = 0; g < i; g = g + 1) { + dyn_var> x = i; + x = x + 1; + } } } int main(int argc, char *argv[]) { builder::builder_context context; - // Code to test assignments between static var and normal vars + // Code to generate full type closure with builder_var_type auto ast = context.extract_ast_from_function(bar); ast->dump(std::cout, 0); block::c_code_generator::generate_code(ast, std::cout, 0); diff --git a/samples/sample24.cpp b/samples/sample24.cpp index 9550e7a..35c07a1 100644 --- a/samples/sample24.cpp +++ b/samples/sample24.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" @@ -7,20 +6,45 @@ using builder::dyn_var; using builder::static_var; -static void bar(void) { - for (static_var i = 0; i < 10; i++) { - for (dyn_var> g = 0; g < i; g = g + 1) { - dyn_var> x = i; - x = x + 1; - } - } +static dyn_var foo(dyn_var x) { + return x + 1; } +static void bar(dyn_var x) { + dyn_var b = x; + x = b + 1; +} + +static dyn_var foobar(dyn_var x, const int &iter, dyn_var &print_val) { + dyn_var t = 0; + for (static_var i = 0; i < iter; i++) + t = t + x + 1; + print_val(t); + return t; +} int main(int argc, char *argv[]) { builder::builder_context context; - // Code to generate full type closure with builder_var_type - auto ast = context.extract_ast_from_function(bar); + + auto ast = context.extract_function_ast( + [=](dyn_var x, dyn_var y, dyn_var w) -> dyn_var { + dyn_var z = x - y - w; + return 0; + }, + "func1"); ast->dump(std::cout, 0); block::c_code_generator::generate_code(ast, std::cout, 0); + + auto ast2 = context.extract_function_ast(foo, "func2"); + ast2->dump(std::cout, 0); + block::c_code_generator::generate_code(ast2, std::cout, 0); + + auto ast3 = context.extract_function_ast(bar, "func3"); + ast3->dump(std::cout, 0); + block::c_code_generator::generate_code(ast3, std::cout, 0); + + dyn_var print_val = builder::with_name("print_val"); + auto ast4 = context.extract_function_ast(foobar, "func4", 2, print_val); + ast4->dump(std::cout, 0); + block::c_code_generator::generate_code(ast4, std::cout, 0); return 0; } diff --git a/samples/sample25.cpp b/samples/sample25.cpp index 7656877..0502f29 100644 --- a/samples/sample25.cpp +++ b/samples/sample25.cpp @@ -1,6 +1,4 @@ -/*NO_TEST*/ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" @@ -8,45 +6,48 @@ using builder::dyn_var; using builder::static_var; -static dyn_var foo(dyn_var x) { - return x + 1; -} +static void bar(void) { + dyn_var k = 0; + dyn_var t = 0; + /* + for (static_var i = 0; i < 2; i++) { + if (k == i) { + for (dyn_var s = 0; s < i; s = s + 1) { + t = t + 1; + } + } + } + */ + while (1) { + if (k == 0) + break; + t = t + 1; + t = t + 1; + while (1) { + if (k == 0) + break; + } -static void bar(dyn_var x) { - dyn_var b = x; - x = b + 1; + t = t + 1; + while (1) { + if (k == 0) + break; + t = t + 1; + } + t = t + 1; + } + t = t + 2; + while (1) { + if (k == 0) + break; + t = t + 1; + } } -static dyn_var foobar(dyn_var x, const int &iter, dyn_var &print_val) { - dyn_var t = 0; - for (static_var i = 0; i < iter; i++) - t = t + x + 1; - print_val(t); - return t; -} int main(int argc, char *argv[]) { builder::builder_context context; - - auto ast = context.extract_function_ast( - [=](dyn_var x, dyn_var y, dyn_var w) -> dyn_var { - dyn_var z = x - y - w; - return 0; - }, - "func1"); + auto ast = context.extract_ast_from_function(bar); ast->dump(std::cout, 0); block::c_code_generator::generate_code(ast, std::cout, 0); - - auto ast2 = context.extract_function_ast(foo, "func2"); - ast2->dump(std::cout, 0); - block::c_code_generator::generate_code(ast2, std::cout, 0); - - auto ast3 = context.extract_function_ast(bar, "func3"); - ast3->dump(std::cout, 0); - block::c_code_generator::generate_code(ast3, std::cout, 0); - - dyn_var print_val = builder::with_name("print_val"); - auto ast4 = context.extract_function_ast(foobar, "func4", 2, print_val); - ast4->dump(std::cout, 0); - block::c_code_generator::generate_code(ast4, std::cout, 0); return 0; } diff --git a/samples/sample26.cpp b/samples/sample26.cpp index e243aaa..b67c33a 100644 --- a/samples/sample26.cpp +++ b/samples/sample26.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" @@ -7,48 +6,24 @@ using builder::dyn_var; using builder::static_var; -static void bar(void) { - dyn_var k = 0; - dyn_var t = 0; - /* - for (static_var i = 0; i < 2; i++) { - if (k == i) { - for (dyn_var s = 0; s < i; s = s + 1) { - t = t + 1; - } - } - } - */ - while (1) { - if (k == 0) - break; - t = t + 1; - t = t + 1; - while (1) { - if (k == 0) - break; - } - - t = t + 1; - while (1) { - if (k == 0) - break; - t = t + 1; - } - t = t + 1; - } - t = t + 1; - while (1) { - if (k == 0) - break; - t = t + 1; +template +dyn_var power_f(BT base, ET exponent) { + dyn_var res = 1, x = base; + while (exponent > 0) { + if (exponent % 2 == 1) + res = res * x; + x = x * x; + exponent = exponent / 2; } + return res; } - int main(int argc, char *argv[]) { - builder::builder_context context; - auto ast = context.extract_ast_from_function(bar); - ast->dump(std::cout, 0); - block::c_code_generator::generate_code(ast, std::cout, 0); + auto ast1 = + builder::builder_context().extract_function_ast(power_f, static_var>, "power_15", 15); + block::c_code_generator::generate_code(ast1, std::cout, 0); + auto ast2 = + builder::builder_context().extract_function_ast(power_f, dyn_var>, "power_5", 5); + block::c_code_generator::generate_code(ast2, std::cout, 0); + return 0; } diff --git a/samples/sample27.cpp b/samples/sample27.cpp index 8d32fcc..00cbb19 100644 --- a/samples/sample27.cpp +++ b/samples/sample27.cpp @@ -1,31 +1,46 @@ /*NO_TEST*/ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" +#include "builder/builder_union.h" #include "builder/dyn_var.h" #include "builder/static_var.h" #include using builder::dyn_var; using builder::static_var; -template -dyn_var power_f(BT base, ET exponent) { - dyn_var res = 1, x = base; - while (exponent > 0) { - if (exponent % 2 == 1) - res = res * x; - x = x * x; - exponent = exponent / 2; +static void foo(void) { + dyn_var sum = 0; + const int arr[] = {1, 3, 4, 0, 2, 6, 0, 8, 0, 0, 1, -2, 0, 0, 3}; + + for (static_var x = 0; x < sizeof(arr) / sizeof(*arr); x++) { + if (arr[x] != 0) { + builder::annotate("roll.0"); + sum = sum + arr[x]; + } + } + + const int adj[5][5] = {{4, 0, 1, 0, 0}, {5, 0, 0, 0, 1}, {0, 0, 1, 0, 0}, {1, 2, 1, 0, 0}, {0, 0, 0, 0, 0}}; + + dyn_var old_ranks; + dyn_var new_ranks; + + for (static_var src = 0; src < 5; src++) { + // dyn_var sum = 0; + for (static_var dst = 0; dst < 5; dst++) { + if (adj[src][dst] != 0) { + builder::annotate("roll.1"); + // builder::annotate("roll.1." + + // std::to_string(src)); + new_ranks[src] = new_ranks[src] + adj[src][dst] * old_ranks[dst]; + } + } } - return res; } -int main(int argc, char *argv[]) { - auto ast1 = - builder::builder_context().extract_function_ast(power_f, static_var>, "power_15", 15); - block::c_code_generator::generate_code(ast1, std::cout, 0); - auto ast2 = - builder::builder_context().extract_function_ast(power_f, dyn_var>, "power_5", 5); - block::c_code_generator::generate_code(ast2, std::cout, 0); +int main(int argc, char *argv[]) { + builder::builder_context context; + auto ast = context.extract_ast_from_function(foo); + ast->dump(std::cout, 0); + block::c_code_generator::generate_code(ast, std::cout, 0); return 0; } diff --git a/samples/sample28.cpp b/samples/sample28.cpp index f99eba1..d43d1b1 100644 --- a/samples/sample28.cpp +++ b/samples/sample28.cpp @@ -1,6 +1,4 @@ -/*NO_TEST*/ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/builder_union.h" #include "builder/dyn_var.h" @@ -11,10 +9,30 @@ using builder::dyn_var; using builder::static_var; static void foo(void) { - dyn_var x; - dyn_var y; - builder_union z = x + y; - builder_union res = 1; + dyn_var a; + dyn_var b; + dyn_var c; + dyn_var d; + dyn_var e; + dyn_var f = (unsigned long)5; + dyn_var g; + dyn_var h = (unsigned long long)4; + dyn_var i; + dyn_var j; + dyn_var k; + dyn_var l; + dyn_var m; + dyn_var n = "Hello world"; + n = "new string"; + + dyn_var o = "Hello world"; + + dyn_var p = true; + + // bool test, fixes a bug + // that causes false as an init value creates a variable + // without context + dyn_var x = false; } int main(int argc, char *argv[]) { diff --git a/samples/sample29.cpp b/samples/sample29.cpp index 1f73473..43dc3c0 100644 --- a/samples/sample29.cpp +++ b/samples/sample29.cpp @@ -1,47 +1,42 @@ -/*NO_TEST*/ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" -#include "builder/builder_union.h" #include "builder/dyn_var.h" #include "builder/static_var.h" #include -using builder::builder_union; using builder::dyn_var; using builder::static_var; -static void foo(void) { - dyn_var sum = 0; - const int arr[] = {1, 3, 4, 0, 2, 6, 0, 8, 0, 0, 1, -2, 0, 0, 3}; +// Don't declare this as constexpr, so that graph_t +// has external linkage and operator can left undefined +char graph_t_name[] = "GraphT"; +using graph_t = typename builder::name; - for (static_var x = 0; x < sizeof(arr) / sizeof(*arr); x++) { - if (arr[x] != 0) { - builder::annotate("roll.0"); - sum = sum + arr[x]; - } - } +extern char foo_t_name[]; +char foo_t_name[] = "FooT"; - const int adj[5][5] = {{4, 0, 1, 0, 0}, {5, 0, 0, 0, 1}, {0, 0, 1, 0, 0}, {1, 2, 1, 0, 0}, {0, 0, 0, 0, 0}}; +template +using foo_t = typename builder::name; - dyn_var old_ranks; - dyn_var new_ranks; +// Declare the operators inside the builder namespace +// this allows ADL to find the operators. Otherwise atleast clang +// doesn't see this +namespace builder { +graph_t operator + (const graph_t& a, const int&); +template +foo_t operator + (const foo_t& a, const int&); +} + +static void bar(void) { + dyn_var g; + g = g + 1; - for (static_var src = 0; src < 5; src++) { - // dyn_var sum = 0; - for (static_var dst = 0; dst < 5; dst++) { - if (adj[src][dst] != 0) { - builder::annotate("roll.1"); - // builder::annotate("roll.1." + - // std::to_string(src)); - new_ranks[src] = new_ranks[src] + adj[src][dst] * old_ranks[dst]; - } - } - } + dyn_var> f; + f = f + 1; } int main(int argc, char *argv[]) { builder::builder_context context; - auto ast = context.extract_ast_from_function(foo); + auto ast = context.extract_ast_from_function(bar); ast->dump(std::cout, 0); block::c_code_generator::generate_code(ast, std::cout, 0); return 0; diff --git a/samples/sample3.cpp b/samples/sample3.cpp index 6468307..54da2b7 100644 --- a/samples/sample3.cpp +++ b/samples/sample3.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include diff --git a/samples/sample30.cpp b/samples/sample30.cpp index 4c7efd5..1fe6e64 100644 --- a/samples/sample30.cpp +++ b/samples/sample30.cpp @@ -1,45 +1,26 @@ +// Include the headers #include "blocks/c_code_generator.h" -#include "builder/builder.h" -#include "builder/builder_context.h" -#include "builder/builder_union.h" #include "builder/dyn_var.h" #include "builder/static_var.h" #include -using builder::builder_union; + +// Include the BuildIt types using builder::dyn_var; using builder::static_var; - -static void foo(void) { - dyn_var a; - dyn_var b; - dyn_var c; - dyn_var d; - dyn_var e; - dyn_var f = (unsigned long)5; - dyn_var g; - dyn_var h = (unsigned long long)4; - dyn_var i; - dyn_var j; - dyn_var k; - dyn_var l; - dyn_var m; - dyn_var n = "Hello world"; - n = "new string"; - - dyn_var o = "Hello world"; - - dyn_var p = true; - - // bool test, fixes a bug - // that causes false as an init value creates a variable - // without context - dyn_var x = false; +static void bar(void) { + // Insert code to stage here + dyn_var x = 5; + for (dyn_var i = 0; i < 100; i = i + 1) { + if (i == x) { + x = i; + break; + } + } } int main(int argc, char *argv[]) { builder::builder_context context; - auto ast = context.extract_ast_from_function(foo); + auto ast = context.extract_function_ast(bar, "bar"); ast->dump(std::cout, 0); block::c_code_generator::generate_code(ast, std::cout, 0); - return 0; } diff --git a/samples/sample31.cpp b/samples/sample31.cpp index b46dd01..14b67c6 100644 --- a/samples/sample31.cpp +++ b/samples/sample31.cpp @@ -1,43 +1,23 @@ +// Include the headers #include "blocks/c_code_generator.h" -#include "builder/builder.h" -#include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" #include -using builder::as_member; +// Include the BuildIt types using builder::dyn_var; -// We will now create our own dyn_var type with members -// We are deprecating extending dyn_var with members -// instead one can write a specialization for a particular type - -struct foo { - static constexpr const char* type_name = "foo"; -}; - -template -struct my_dyn_var: public builder::dyn_var { - using builder::dyn_var::dyn_var; - using builder::dyn_var::operator=; - - my_dyn_var(const my_dyn_var &t) : builder::dyn_var((builder::builder)t) {} - - builder::builder operator=(const my_dyn_var &t) { - return (*this) = (builder::builder)t; +using builder::static_var; +static void bar(void) { + dyn_var i = 0; + for (; i < 100; i = i + 1) { + } + for (i = 0; i < 100; i = i + 1) { } - dyn_var var1 = as_member(this, "var1"); - dyn_var neighbor = as_member(this, "neighbor"); -}; +} int main(int argc, char *argv[]) { builder::builder_context context; - auto ast = context.extract_function_ast( - [=](my_dyn_var x) -> dyn_var { - my_dyn_var z = 3 + x.var1 + 5 * x.var1; - return z.neighbor + 2; - }, - "func1"); + auto ast = context.extract_function_ast(bar, "bar"); ast->dump(std::cout, 0); block::c_code_generator::generate_code(ast, std::cout, 0); - return 0; } diff --git a/samples/sample32.cpp b/samples/sample32.cpp index 2a6cfaf..c2d7010 100644 --- a/samples/sample32.cpp +++ b/samples/sample32.cpp @@ -1,31 +1,27 @@ +// Include the headers #include "blocks/c_code_generator.h" -#include "builder/builder.h" -#include "builder/builder_context.h" +#include "builder/builder_dynamic.h" #include "builder/dyn_var.h" #include "builder/static_var.h" #include + +// Include the BuildIt types using builder::dyn_var; using builder::static_var; -constexpr char graph_t_name[] = "GraphT"; -using graph_t = typename builder::name; - -constexpr char foo_t_name[] = "FooT"; -template -using foo_t = typename builder::name; - -static void bar(void) { - dyn_var g; - g = g + 1; - - dyn_var> f; - f = f + 1; +static dyn_var power_f(dyn_var base, static_var exponent) { + dyn_var res = 1, x = base; + while (exponent > 1) { + if (exponent % 2 == 1) + res = res * x; + x = x * x; + exponent = exponent / 2; + } + return res * x; } int main(int argc, char *argv[]) { - builder::builder_context context; - auto ast = context.extract_ast_from_function(bar); - ast->dump(std::cout, 0); - block::c_code_generator::generate_code(ast, std::cout, 0); + auto fptr = (int (*)(int))builder::compile_function(power_f, 5); + std::cout << fptr(8) << std::endl; return 0; } diff --git a/samples/sample33.cpp b/samples/sample33.cpp index bcad996..001afeb 100644 --- a/samples/sample33.cpp +++ b/samples/sample33.cpp @@ -1,44 +1,42 @@ +// Include the headers #include "blocks/c_code_generator.h" -#include "builder/builder.h" -#include "builder/builder_context.h" +#include "blocks/extract_cuda.h" #include "builder/dyn_var.h" #include "builder/static_var.h" #include -using builder::as_member; + +// Include the BuildIt types using builder::dyn_var; using builder::static_var; - -constexpr char foo_t_name[] = "FooT"; -using foo_t = typename builder::name; - -class FooT : public dyn_var { -public: - typedef dyn_var super; - using super::super; - using dyn_var::operator=; - FooT(const FooT &t) : dyn_var((builder::builder)t) {} - FooT() : dyn_var() {} - builder::builder operator=(const FooT &t) { - return (*this) = (builder::builder)t; +static void bar(dyn_var buffer) { + builder::annotate(CUDA_KERNEL); + for (dyn_var cta = 0; cta < 128; cta = cta + 1) { + for (dyn_var tid = 0; tid < 512; tid = tid + 1) { + dyn_var thread_id = cta * 512 + tid; + buffer[thread_id] = 0; + } + } + builder::annotate(CUDA_KERNEL_COOP); + for (dyn_var cta = 0; cta < 128; cta = cta + 1) { + for (dyn_var tid = 0; tid < 512; tid = tid + 1) { + dyn_var thread_id = cta * 512 + tid; + buffer[thread_id] = 0; + } + } + builder::annotate(CUDA_KERNEL_COOP_COPY_OUT); + for (dyn_var cta = 0; cta < 128; cta = cta + 1) { + for (dyn_var tid = 0; tid < 512; tid = tid + 1) { + dyn_var thread_id = cta * 512 + tid; + buffer[thread_id] = 0; + } } - - dyn_var member = as_member(this, "member"); -}; - -static void bar(void) { - FooT g; - g = g + 1; - dyn_var x = g.member; - FooT h = g; - h = g; - dyn_var ptr = &g; - ((FooT)(builder::cast)ptr[0]).member = 0; } int main(int argc, char *argv[]) { builder::builder_context context; - auto ast = context.extract_ast_from_function(bar); - ast->dump(std::cout, 0); + auto ast = context.extract_function_ast(bar, "bar"); + auto new_decls = block::extract_cuda_from(block::to(ast)->body); + for (auto a : new_decls) + block::c_code_generator::generate_code(a, std::cout, 0); block::c_code_generator::generate_code(ast, std::cout, 0); - return 0; } diff --git a/samples/sample34.cpp b/samples/sample34.cpp index 1fe6e64..372ef69 100644 --- a/samples/sample34.cpp +++ b/samples/sample34.cpp @@ -1,26 +1,58 @@ -// Include the headers #include "blocks/c_code_generator.h" +#include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" #include - -// Include the BuildIt types +#include +using builder::as_member; using builder::dyn_var; using builder::static_var; -static void bar(void) { - // Insert code to stage here - dyn_var x = 5; - for (dyn_var i = 0; i < 100; i = i + 1) { - if (i == x) { - x = i; - break; - } + +constexpr char foo_t_name[] = "FooT"; +using foo_t = typename builder::name; + +namespace builder { + +// Use specialization instead of inheritance +// We still support specialization in case different +// operator implementations need to be added +template <> +class dyn_var : public dyn_var_impl { +public: + typedef dyn_var_impl super; + using super::super; + using super::operator=; + dyn_var& operator=(const dyn_var &t) { + return dyn_var_impl::operator=(t); } + dyn_var() : dyn_var_impl() {} + dyn_var(const dyn_var &t) : dyn_var_impl(t) {} + + dyn_var member = as_member(this, "member"); +}; + +/* Specialization for foo_t* is not required because it comes built in with dyn_var now */ + +} // namespace builder + +static void bar(void) { + dyn_var g; + dyn_var x = g.member; + dyn_var h = g; + h = g; + dyn_var ptr = &g; + (*ptr).member = 0; + ptr->member = 1; + + // This SHOULD produce a copy + dyn_var i = *ptr; + i.member = 3; } int main(int argc, char *argv[]) { builder::builder_context context; - auto ast = context.extract_function_ast(bar, "bar"); + auto ast = context.extract_ast_from_function(bar); ast->dump(std::cout, 0); block::c_code_generator::generate_code(ast, std::cout, 0); + return 0; } diff --git a/samples/sample35.cpp b/samples/sample35.cpp index 14b67c6..4ecc744 100644 --- a/samples/sample35.cpp +++ b/samples/sample35.cpp @@ -1,23 +1,44 @@ +/*NO_TEST*/ // Include the headers #include "blocks/c_code_generator.h" +#include "blocks/extract_cuda.h" #include "builder/dyn_var.h" #include "builder/static_var.h" +#include "builder/lib/utils.h" #include // Include the BuildIt types using builder::dyn_var; using builder::static_var; -static void bar(void) { - dyn_var i = 0; - for (; i < 100; i = i + 1) { + +static dyn_var choose(dyn_var n, dyn_var k, const int MAX_N) { + int comp[MAX_N][MAX_N]; + for (int i = 0; i < MAX_N; i++) { + comp[i][0] = 1; + comp[i][i] = 1; + } + for (int i = 1; i < MAX_N; ++i) { + comp[0][i] = 0; + for (int j = 1; j < i; ++j) { + comp[i][j] = comp[i - 1][j - 1] + comp[i - 1][j]; + comp[j][i] = 0; + } } - for (i = 0; i < 100; i = i + 1) { + dyn_var comp_r; + resize_arr(comp_r, MAX_N * MAX_N); + + for (static_var i = 0; i < MAX_N * MAX_N; i++) { + builder::annotate("roll.0"); + comp_r[i] = comp[i / MAX_N][i % MAX_N]; } + return comp_r[n * MAX_N + k]; } int main(int argc, char *argv[]) { builder::builder_context context; - auto ast = context.extract_function_ast(bar, "bar"); - ast->dump(std::cout, 0); + auto ast = context.extract_function_ast(choose, "choose", 10); + + std::cout << "#include " << std::endl; block::c_code_generator::generate_code(ast, std::cout, 0); + std::cout << "int main(int argc, char* argv[]) {\n\tstd::cout << choose(8, 3) << std::endl;\n}" << std::endl; } diff --git a/samples/sample36.cpp b/samples/sample36.cpp index c2d7010..03bafc4 100644 --- a/samples/sample36.cpp +++ b/samples/sample36.cpp @@ -1,27 +1,104 @@ -// Include the headers #include "blocks/c_code_generator.h" -#include "builder/builder_dynamic.h" #include "builder/dyn_var.h" #include "builder/static_var.h" +#include #include -// Include the BuildIt types -using builder::dyn_var; +template +using dyn = builder::dyn_var; using builder::static_var; -static dyn_var power_f(dyn_var base, static_var exponent) { - dyn_var res = 1, x = base; - while (exponent > 1) { - if (exponent % 2 == 1) - res = res * x; - x = x * x; - exponent = exponent / 2; +static dyn d_strlen(builder::with_name("strlen")); + +static bool is_normal(char m) { + return (m >= 'a' && m <= 'z') || (m >= 'A' && m <= 'Z') || (m >= '0' && m <= '9'); +} +static void progress(const char *re, static_var *next, int p) { + int ns = p + 1; + if ((int)strlen(re) == ns) { + next[ns] = true; + } else if (is_normal(re[ns]) || '.' == re[ns]) { + next[ns] = true; + if ('*' == re[ns + 1]) { + // We are allowed to skip this + // so just progress again + progress(re, next, ns + 1); + } + } else if ('*' == re[ns]) { + next[p] = true; + progress(re, next, ns); + } +} + +static dyn match_regex(const char *re, dyn str) { + // allocate two state vectors + const int re_len = strlen(re); + static_var *current = new static_var[re_len + 1]; + static_var *next = new static_var[re_len + 1]; + for (static_var i = 0; i < re_len + 1; i++) + current[i] = next[i] = 0; + progress(re, current, -1); + dyn str_len = d_strlen(str); + dyn to_match = 0; + while (to_match < str_len) { + // Don’t do anything for $. + static_var early_break = -1; + for (static_var state = 0; state < re_len; ++state) + if (current[state]) { + static_var m = re[state]; + if (is_normal(m)) { + if (-1 == early_break) { + // Normal character + if (str[to_match] == m) { + progress(re, next, state); + // If a match happens, it + // cannot match anything else + // Setting early break + // avoids unnecessary checks + early_break = m; + } + } else if (early_break == m) { + // The comparison has been done + // already, let us not repeat + progress(re, next, state); + } + } else if ('.' == m) { + progress(re, next, state); + } else { + printf("Invalid Character(%c)\n", (char)m); + return false; + } + } + + // All the states have been checked + // Now swap the states and clear next + static_var count = 0; + for (static_var i = 0; i < re_len + 1; i++) { + current[i] = next[i]; + next[i] = false; + if (current[i]) + count++; + } + if (count == 0) + break; + to_match = to_match + 1; + } + // Now that the string is done, + // we should have $ in the state + static_var is_match = (char)current[re_len]; + for (static_var i = 0; i < re_len + 1; i++) { + next[i] = 0; + current[i] = 0; } - return res * x; + return is_match; } int main(int argc, char *argv[]) { - auto fptr = (int (*)(int))builder::compile_function(power_f, 5); - std::cout << fptr(8) << std::endl; + builder::builder_context context; + context.feature_unstructured = true; + context.run_rce = true; + auto ast = context.extract_function_ast(match_regex, "match_re", "ab*c*d"); + std::cout << "#include " << std::endl; + block::c_code_generator::generate_code(ast, std::cout); return 0; } diff --git a/samples/sample37.cpp b/samples/sample37.cpp index 001afeb..db6f919 100644 --- a/samples/sample37.cpp +++ b/samples/sample37.cpp @@ -1,6 +1,6 @@ // Include the headers #include "blocks/c_code_generator.h" -#include "blocks/extract_cuda.h" +#include "builder/builder_dynamic.h" #include "builder/dyn_var.h" #include "builder/static_var.h" #include @@ -8,35 +8,27 @@ // Include the BuildIt types using builder::dyn_var; using builder::static_var; -static void bar(dyn_var buffer) { - builder::annotate(CUDA_KERNEL); - for (dyn_var cta = 0; cta < 128; cta = cta + 1) { - for (dyn_var tid = 0; tid < 512; tid = tid + 1) { - dyn_var thread_id = cta * 512 + tid; - buffer[thread_id] = 0; - } - } - builder::annotate(CUDA_KERNEL_COOP); - for (dyn_var cta = 0; cta < 128; cta = cta + 1) { - for (dyn_var tid = 0; tid < 512; tid = tid + 1) { - dyn_var thread_id = cta * 512 + tid; - buffer[thread_id] = 0; - } - } - builder::annotate(CUDA_KERNEL_COOP_COPY_OUT); - for (dyn_var cta = 0; cta < 128; cta = cta + 1) { - for (dyn_var tid = 0; tid < 512; tid = tid + 1) { - dyn_var thread_id = cta * 512 + tid; - buffer[thread_id] = 0; - } - } + +template +struct vector_t: public builder::custom_type { + static constexpr const char* type_name = "std::vector"; + using dereference_type = T; +}; + +static dyn_var power_f(void) { + dyn_var> x = {0, 1, 2}; + dyn_var> y = x; + for (dyn_var i = 0; i < 5; i = i + 1) + y[0] = y[1] + y[0]; + return y[0]; } int main(int argc, char *argv[]) { builder::builder_context context; - auto ast = context.extract_function_ast(bar, "bar"); - auto new_decls = block::extract_cuda_from(block::to(ast)->body); - for (auto a : new_decls) - block::c_code_generator::generate_code(a, std::cout, 0); - block::c_code_generator::generate_code(ast, std::cout, 0); + context.dynamic_use_cxx = true; + context.dynamic_header_includes = "#include "; + context.feature_unstructured = true; + auto fptr = (int (*)(void))builder::compile_function_with_context(context, power_f); + std::cout << fptr() << std::endl; + return 0; } diff --git a/samples/sample38.cpp b/samples/sample38.cpp index ea0a750..6e85991 100644 --- a/samples/sample38.cpp +++ b/samples/sample38.cpp @@ -1,58 +1,31 @@ +// Include the headers #include "blocks/c_code_generator.h" -#include "builder/builder.h" -#include "builder/builder_context.h" #include "builder/dyn_var.h" +#include "builder/lib/utils.h" #include "builder/static_var.h" #include -#include -using builder::as_member; +// Include the BuildIt types using builder::dyn_var; using builder::static_var; -constexpr char foo_t_name[] = "FooT"; -using foo_t = typename builder::name; - -namespace builder { - -// Use specialization instead of inheritance -template <> -class dyn_var : public dyn_var_impl { -public: - typedef dyn_var_impl super; - using super::super; - using super::operator=; - builder operator=(const dyn_var &t) { - return (*this) = (builder)t; - } - dyn_var(const dyn_var &t) : dyn_var_impl((builder)t) {} - dyn_var() : dyn_var_impl() {} - - dyn_var member = as_member(this, "member"); -}; - -/* Specialization for foo_t* is not required because it comes built in with dyn_var now */ - -} // namespace builder - static void bar(void) { - dyn_var g; - g = g + 1; - dyn_var x = g.member; - dyn_var h = g; - h = g; - dyn_var ptr = &g; - (*ptr).member = 0; - ptr->member = 1; + // Insert code to stage here + dyn_var y = 0; + resize_arr(y, 10); + for (dyn_var x = 0; x < 10; ++x) { + *y += x; + y[x] *= 2; + } + for (dyn_var x = 0; x < 10; x++) { + *y -= x; + y[x] /= 2; + } - // This SHOULD produce a copy - dyn_var i = *ptr; - i.member = 3; + (*y)++; } int main(int argc, char *argv[]) { - builder::builder_context context; - auto ast = context.extract_ast_from_function(bar); - ast->dump(std::cout, 0); - block::c_code_generator::generate_code(ast, std::cout, 0); + block::c_code_generator::generate_code(builder::builder_context().extract_function_ast(bar, "bar"), std::cout, + 0); return 0; } diff --git a/samples/sample39.cpp b/samples/sample39.cpp index 5558dfc..a946384 100644 --- a/samples/sample39.cpp +++ b/samples/sample39.cpp @@ -1,47 +1,51 @@ -/*NO_TEST*/ -// Include the headers #include "blocks/c_code_generator.h" -#include "blocks/extract_cuda.h" +#include "builder/array.h" #include "builder/dyn_var.h" -#include "builder/static_var.h" -#include -template -void resize(T &t, int size) { - block::to(t.block_var->var_type)->size = size; -} -// Include the BuildIt types +using builder::dyn_arr; using builder::dyn_var; -using builder::static_var; +using builder::arr; + +using namespace std; + -static dyn_var choose(dyn_var n, dyn_var k, const int MAX_N) { - int comp[MAX_N][MAX_N]; - for (int i = 0; i < MAX_N; i++) { - comp[i][0] = 1; - comp[i][i] = 1; - } - for (int i = 1; i < MAX_N; ++i) { - comp[0][i] = 0; - for (int j = 1; j < i; ++j) { - comp[i][j] = comp[i - 1][j - 1] + comp[i - 1][j]; - comp[j][i] = 0; - } - } - dyn_var comp_r; - resize(comp_r, MAX_N * MAX_N); - for (static_var i = 0; i < MAX_N * MAX_N; i++) { - builder::annotate("roll.0"); - comp_r[i] = comp[i / MAX_N][i % MAX_N]; +struct container { + dyn_var idx; + dyn_var next; + + container() { + idx = 0; } - return comp_r[n * MAX_N + k]; -} +}; -int main(int argc, char *argv[]) { - builder::builder_context context; - auto ast = context.extract_function_ast(choose, "choose", 10); - std::cout << "#include " << std::endl; - block::c_code_generator::generate_code(ast, std::cout, 0); - std::cout << "int main(int argc, char* argv[]) {\n\tstd::cout << choose(8, 3) << std::endl;\n}" << std::endl; +static void foo() { + dyn_arr x; + x[0] = 1; + x[1] = x[0] + 2; + x[2] = x[1] + x[0]; + + dyn_arr y = {0, x[0] + 4, 0, 0}; + + dyn_arr z = {1, 2}; + + dyn_arr a; + a.set_size(2); + + dyn_arr b = y; + dyn_arr c = a; + + + arr containers; + containers[0].next = &(containers[1].idx); + + + arr conts = {containers[0], containers[1]}; + +} +int main(int argc, char *argv[]) { + auto ast = builder::builder_context().extract_function_ast(foo, "foo"); + block::c_code_generator::generate_code(ast, cout, 0); + return 0; } diff --git a/samples/sample4.cpp b/samples/sample4.cpp index fded327..606f6b0 100644 --- a/samples/sample4.cpp +++ b/samples/sample4.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include diff --git a/samples/sample40.cpp b/samples/sample40.cpp index 7ab383e..f9f1797 100644 --- a/samples/sample40.cpp +++ b/samples/sample40.cpp @@ -1,104 +1,45 @@ #include "blocks/c_code_generator.h" +#include "blocks/rce.h" #include "builder/dyn_var.h" -#include "builder/static_var.h" -#include -#include +#include "builder/builder_context.h" -template -using dyn = builder::dyn_var; -using builder::static_var; +using builder::dyn_var; +using namespace std; -static dyn d_strlen(builder::as_global("strlen")); - -static bool is_normal(char m) { - return (m >= 'a' && m <= 'z') || (m >= 'A' && m <= 'Z') || (m >= '0' && m <= '9'); -} -static void progress(const char *re, static_var *next, int p) { - int ns = p + 1; - if ((int)strlen(re) == ns) { - next[ns] = true; - } else if (is_normal(re[ns]) || '.' == re[ns]) { - next[ns] = true; - if ('*' == re[ns + 1]) { - // We are allowed to skip this - // so just progress again - progress(re, next, ns + 1); - } - } else if ('*' == re[ns]) { - next[p] = true; - progress(re, next, ns); +static dyn_var bar(dyn_var n) { + if (n) { } + return 0; } -static dyn match_regex(const char *re, dyn str) { - // allocate two state vectors - const int re_len = strlen(re); - static_var *current = new static_var[re_len + 1]; - static_var *next = new static_var[re_len + 1]; - for (static_var i = 0; i < re_len + 1; i++) - current[i] = next[i] = 0; - progress(re, current, -1); - dyn str_len = d_strlen(str); - dyn to_match = 0; - while (to_match < str_len) { - // Don’t do anything for $. - static_var early_break = -1; - for (static_var state = 0; state < re_len; ++state) - if (current[state]) { - static_var m = re[state]; - if (is_normal(m)) { - if (-1 == early_break) { - // Normal character - if (str[to_match] == m) { - progress(re, next, state); - // If a match happens, it - // cannot match anything else - // Setting early break - // avoids unnecessary checks - early_break = m; - } - } else if (early_break == m) { - // The comparison has been done - // already, let us not repeat - progress(re, next, state); - } - } else if ('.' == m) { - progress(re, next, state); - } else { - printf("Invalid Character(%c)\n", (char)m); - return false; - } - } +static void staged() { + bar(24) != 1 && bar(32) != 1; +} - // All the states have been checked - // Now swap the states and clear next - static_var count = 0; - for (static_var i = 0; i < re_len + 1; i++) { - current[i] = next[i]; - next[i] = false; - if (current[i]) - count++; - } - if (count == 0) - return false; - to_match = to_match + 1; +static void staged2() { + dyn_var a = 0; + for (dyn_var i = 0; i < 5; i = i + 1) { + a = a + 1; } - // Now that the string is done, - // we should have $ in the state - static_var is_match = (char)current[re_len]; - for (static_var i = 0; i < re_len + 1; i++) { - next[i] = 0; - current[i] = 0; + dyn_var b = a; + for (dyn_var i = 0; i < a; i = i + 1) { + b = b + 1; } - return is_match; } -int main(int argc, char *argv[]) { - builder::builder_context context; - context.feature_unstructured = true; - context.run_rce = true; - auto ast = context.extract_function_ast(match_regex, "match_re", "ab*c*d"); - std::cout << "#include " << std::endl; - block::c_code_generator::generate_code(ast, std::cout); - return 0; +int main() { + // This example causes a segfault on block::binary_is_same. + // If you only use a single condition within the while loop, it's fine. + if (true) { + auto ast = builder::builder_context().extract_function_ast(staged, "staged"); + block::c_code_generator::generate_code(ast, cout, 0); + } + + // This shows different semantics before and after running rce. + if (true) { + auto ast = builder::builder_context().extract_function_ast(staged2, "staged2"); + block::c_code_generator::generate_code(ast, cout, 0); + block::eliminate_redundant_vars(ast); + block::c_code_generator::generate_code(ast, cout, 0); + } } diff --git a/samples/sample41.cpp b/samples/sample41.cpp index eb3ac24..5ea5d72 100644 --- a/samples/sample41.cpp +++ b/samples/sample41.cpp @@ -1,33 +1,46 @@ -// Include the headers #include "blocks/c_code_generator.h" +#include "builder/builder_context.h" #include "builder/builder_dynamic.h" #include "builder/dyn_var.h" -#include "builder/static_var.h" -#include - -// Include the BuildIt types +#include using builder::dyn_var; -using builder::static_var; - -static const char vector_t_name[] = "std::vector"; -template -using vector_t = builder::name; +dyn_var myprintf = builder::with_name("printf"); -static dyn_var power_f(void) { - dyn_var> x = {0, 1, 2}; - dyn_var> y = x; - for (dyn_var i = 0; i < 5; i = i + 1) - y[0] = y[1] + y[0]; - return y[0]; +static void foo(dyn_var count, char to_print, std::set &working_set, std::set &done_set) { + for (dyn_var i = 0; i < count; ++i) { + myprintf("%c", to_print); + } + myprintf("\n"); + if (to_print < 'z') { + if (done_set.find(to_print + 1) == done_set.end()) + working_set.insert(to_print + 1); + std::string name = "print_" + std::to_string(to_print + 1); + dyn_var bar = builder::with_name(name); + bar(count + 1); + } } int main(int argc, char *argv[]) { - builder::builder_context context; - context.dynamic_use_cxx = true; - context.dynamic_header_includes = "#include "; - context.feature_unstructured = true; - auto fptr = (int (*)(void))builder::compile_function_with_context(context, power_f); - std::cout << fptr() << std::endl; + std::set working_set, done_set; + std::vector functions; + + working_set.insert('a'); + + while (!working_set.empty()) { + char c = *working_set.begin(); + working_set.erase(c); + std::string name = "print_" + std::to_string(c); + auto ast = builder::builder_context().extract_function_ast(foo, name, c, working_set, done_set); + functions.push_back(ast); + done_set.insert(c); + } + + builder::builder_context ctx; + ctx.dynamic_header_includes = "#include "; + void (*fptr)(int) = (void (*)(int))builder::compile_asts(ctx, functions, "print_" + std::to_string('a')); + + fptr(1); + return 0; } diff --git a/samples/sample42.cpp b/samples/sample42.cpp index 6e85991..77bb7c0 100644 --- a/samples/sample42.cpp +++ b/samples/sample42.cpp @@ -1,31 +1,62 @@ -// Include the headers #include "blocks/c_code_generator.h" +#include "builder/builder_context.h" #include "builder/dyn_var.h" -#include "builder/lib/utils.h" #include "builder/static_var.h" #include -// Include the BuildIt types +using builder::as_member; using builder::dyn_var; using builder::static_var; +struct FooT : public builder::custom_type<> { + static constexpr const char *type_name = "FooT"; + dyn_var member = as_member("member"); +}; +// Let's say we want to support + on FooT +FooT operator + (const FooT&, int); + +template +struct BarT : public builder::custom_type<> { + static constexpr const char *type_name = "BarT"; + dyn_var my_member = as_member("my_member"); + dyn_var second_member = as_member("second_member"); +}; + +template +struct CarT : public builder::custom_type { + static constexpr const char *type_name = "CarT"; + dyn_var my_member = as_member("my_member"); +}; + static void bar(void) { - // Insert code to stage here - dyn_var y = 0; - resize_arr(y, 10); - for (dyn_var x = 0; x < 10; ++x) { - *y += x; - y[x] *= 2; - } - for (dyn_var x = 0; x < 10; x++) { - *y -= x; - y[x] /= 2; - } - - (*y)++; + dyn_var g; + g = g + 1; + dyn_var x = g.member; + dyn_var h = g; + h = g; + + dyn_var> f; + f.second_member = g + 1; + + dyn_var>> l; + l.my_member = g.member; + + dyn_var i; + i->member = l.my_member; + (*i).member = 0; + i[3].member = 0; } int main(int argc, char *argv[]) { - block::c_code_generator::generate_code(builder::builder_context().extract_function_ast(bar, "bar"), std::cout, - 0); + builder::builder_context context; + auto ast = context.extract_function_ast(bar, "my_bar"); + ast->dump(std::cout, 0); + + block::c_code_generator::generate_struct_decl>(std::cout); + block::c_code_generator::generate_struct_decl>>(std::cout); + + // Don't do this because this has a template in the generated type + // block::c_code_generator::generate_struct_decl>>>(std::cout); + + block::c_code_generator::generate_code(ast, std::cout, 0); return 0; } diff --git a/samples/sample43.cpp b/samples/sample43.cpp index a946384..d35504c 100644 --- a/samples/sample43.cpp +++ b/samples/sample43.cpp @@ -1,51 +1,28 @@ #include "blocks/c_code_generator.h" -#include "builder/array.h" #include "builder/dyn_var.h" +#include "builder/static_var.h" -using builder::dyn_arr; using builder::dyn_var; -using builder::arr; - -using namespace std; - - - -struct container { - dyn_var idx; - dyn_var next; - - container() { - idx = 0; +using builder::static_var; + +static void foo(void) { + static_var states; + states.resize(4); + for (states[0] = 0; states[0] < 2; states[0]++) { + for (states[1] = 0; states[1] < 2; states[1]++) { + for (states[2] = 0; states[2] < 2; states[2]++) { + for (states[3] = 0; states[3] < 2; states[3]++) { + dyn_var c = 0; + } + } + } } -}; - - -static void foo() { - dyn_arr x; - x[0] = 1; - x[1] = x[0] + 2; - x[2] = x[1] + x[0]; - - dyn_arr y = {0, x[0] + 4, 0, 0}; - - dyn_arr z = {1, 2}; - - dyn_arr a; - a.set_size(2); - - dyn_arr b = y; - dyn_arr c = a; - - - arr containers; - containers[0].next = &(containers[1].idx); - - - arr conts = {containers[0], containers[1]}; - } int main(int argc, char *argv[]) { - auto ast = builder::builder_context().extract_function_ast(foo, "foo"); - block::c_code_generator::generate_code(ast, cout, 0); + builder::builder_context context; + auto ast = context.extract_function_ast(foo, "my_bar"); + ast->dump(std::cout, 0); + + block::c_code_generator::generate_code(ast, std::cout, 0); return 0; } diff --git a/samples/sample44.cpp b/samples/sample44.cpp index fdd94b8..7a3bdf0 100644 --- a/samples/sample44.cpp +++ b/samples/sample44.cpp @@ -1,44 +1,24 @@ #include "blocks/c_code_generator.h" -#include "blocks/rce.h" +#include "builder/array.h" #include "builder/dyn_var.h" +#include "builder/static_var.h" +using builder::dyn_arr; using builder::dyn_var; -using namespace std; +using builder::static_var; -static dyn_var bar(dyn_var n) { - if (n) { - } - return 0; -} - -static void staged() { - bar(24) != 1 && bar(32) != 1; +static void foo(void) { + dyn_var x; + dyn_arr y = {0, 0}; + y[0] = 1; + while (1) + dyn_arr z = {1, 2}; } +int main(int argc, char *argv[]) { + builder::builder_context context; + auto ast = context.extract_function_ast(foo, "my_bar"); + ast->dump(std::cout, 0); -static void staged2() { - dyn_var a = 0; - for (dyn_var i = 0; i < 5; i = i + 1) { - a = a + 1; - } - dyn_var b = a; - for (dyn_var i = 0; i < a; i = i + 1) { - b = b + 1; - } -} - -int main() { - // This example causes a segfault on block::binary_is_same. - // If you only use a single condition within the while loop, it's fine. - if (true) { - auto ast = builder::builder_context().extract_function_ast(staged, "staged"); - block::c_code_generator::generate_code(ast, cout, 0); - } - - // This shows different semantics before and after running rce. - if (true) { - auto ast = builder::builder_context().extract_function_ast(staged2, "staged2"); - block::c_code_generator::generate_code(ast, cout, 0); - block::eliminate_redundant_vars(ast); - block::c_code_generator::generate_code(ast, cout, 0); - } + block::c_code_generator::generate_code(ast, std::cout, 0); + return 0; } diff --git a/samples/sample45.cpp b/samples/sample45.cpp index 4a06414..ee90163 100644 --- a/samples/sample45.cpp +++ b/samples/sample45.cpp @@ -1,46 +1,21 @@ #include "blocks/c_code_generator.h" -#include "builder/builder_context.h" -#include "builder/builder_dynamic.h" #include "builder/dyn_var.h" -#include -using builder::dyn_var; +#include "builder/builder_context.h" -dyn_var myprintf = builder::as_global("printf"); +using builder::dyn_var; -static void foo(dyn_var count, char to_print, std::set &working_set, std::set &done_set) { - for (dyn_var i = 0; i < count; i++) { - myprintf("%c", to_print); - } - myprintf("\n"); - if (to_print < 'z') { - if (done_set.find(to_print + 1) == done_set.end()) - working_set.insert(to_print + 1); - std::string name = "print_" + std::to_string(to_print + 1); - dyn_var bar = builder::with_name(name); - bar(count + 1); - } +static void foo(void) { + std::string name = "my_var"; + dyn_var v = builder::with_name(name, true); + v = 1; + dyn_var v1 = builder::with_name(name); + dyn_var y = v1; } - int main(int argc, char *argv[]) { - std::set working_set, done_set; - std::vector functions; - - working_set.insert('a'); - - while (!working_set.empty()) { - char c = *working_set.begin(); - working_set.erase(c); - std::string name = "print_" + std::to_string(c); - auto ast = builder::builder_context().extract_function_ast(foo, name, c, working_set, done_set); - functions.push_back(ast); - done_set.insert(c); - } - - builder::builder_context ctx; - ctx.dynamic_header_includes = "#include "; - void (*fptr)(int) = (void (*)(int))builder::compile_asts(ctx, functions, "print_" + std::to_string('a')); - - fptr(1); + builder::builder_context context; + auto ast = context.extract_function_ast(foo, "foo"); + ast->dump(std::cout, 0); + block::c_code_generator::generate_code(ast, std::cout, 0); return 0; } diff --git a/samples/sample46.cpp b/samples/sample46.cpp index dca4656..7699aa4 100644 --- a/samples/sample46.cpp +++ b/samples/sample46.cpp @@ -1,61 +1,29 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" #include -using builder::as_member; using builder::dyn_var; using builder::static_var; -struct FooT : public builder::custom_type<> { - static constexpr const char *type_name = "FooT"; - dyn_var member = as_member("member"); -}; - -template -struct BarT : public builder::custom_type<> { - static constexpr const char *type_name = "BarT"; - dyn_var my_member = as_member("my_member"); - dyn_var second_member = as_member("second_member"); -}; - -template -struct CarT : public builder::custom_type { - static constexpr const char *type_name = "CarT"; - dyn_var my_member = as_member("my_member"); -}; - static void bar(void) { - dyn_var g; - g = g + 1; - dyn_var x = g.member; - dyn_var h = g; - h = g; - - dyn_var> f; - f.second_member = g + 1; - - dyn_var>> l; - l.my_member = g.member; - - dyn_var i; - i->member = l.my_member; - (*i).member = 0; - i[3].member = 0; + dyn_var k = 0; + dyn_var t = 0; + while (1) { + while (k != 1) { + + if (k == 2) + break; + } + while (k != 3) { + } + } } int main(int argc, char *argv[]) { builder::builder_context context; - auto ast = context.extract_function_ast(bar, "my_bar"); + auto ast = context.extract_function_ast(bar, "bar"); ast->dump(std::cout, 0); - - block::c_code_generator::generate_struct_decl>(std::cout); - block::c_code_generator::generate_struct_decl>>(std::cout); - - // Don't do this because this has a template in the generated type - // block::c_code_generator::generate_struct_decl>>>(std::cout); - block::c_code_generator::generate_code(ast, std::cout, 0); return 0; } diff --git a/samples/sample47.cpp b/samples/sample47.cpp index d35504c..aa3d3cd 100644 --- a/samples/sample47.cpp +++ b/samples/sample47.cpp @@ -1,28 +1,32 @@ #include "blocks/c_code_generator.h" +#include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" - +#include using builder::dyn_var; using builder::static_var; -static void foo(void) { - static_var states; - states.resize(4); - for (states[0] = 0; states[0] < 2; states[0]++) { - for (states[1] = 0; states[1] < 2; states[1]++) { - for (states[2] = 0; states[2] < 2; states[2]++) { - for (states[3] = 0; states[3] < 2; states[3]++) { - dyn_var c = 0; - } - } +void bar(void); +void bar(void) { + // This example tests the case where a jump cuts + // through the parent loop + dyn_var x = 5; + while (x < 10) { + while (x > 100) { + if (x == 0) + break; + x = x + 4; } + x = x + 5; + while (x != -1) + x = x + 6; } } + int main(int argc, char *argv[]) { builder::builder_context context; - auto ast = context.extract_function_ast(foo, "my_bar"); + auto ast = context.extract_function_ast(bar, "bar"); ast->dump(std::cout, 0); - block::c_code_generator::generate_code(ast, std::cout, 0); return 0; } diff --git a/samples/sample48.cpp b/samples/sample48.cpp index 7a3bdf0..9cd638c 100644 --- a/samples/sample48.cpp +++ b/samples/sample48.cpp @@ -1,24 +1,22 @@ +// Include the headers #include "blocks/c_code_generator.h" -#include "builder/array.h" #include "builder/dyn_var.h" +#include "builder/lib/utils.h" #include "builder/static_var.h" +#include -using builder::dyn_arr; +// Include the BuildIt types using builder::dyn_var; using builder::static_var; -static void foo(void) { - dyn_var x; - dyn_arr y = {0, 0}; - y[0] = 1; - while (1) - dyn_arr z = {1, 2}; +static dyn_var isEven(dyn_var x) { + static_var xs = builder::up_cast_range(x, 16); + return (xs % 2) == 0; } + int main(int argc, char *argv[]) { builder::builder_context context; - auto ast = context.extract_function_ast(foo, "my_bar"); - ast->dump(std::cout, 0); - - block::c_code_generator::generate_code(ast, std::cout, 0); + context.run_rce = true; + block::c_code_generator::generate_code(context.extract_function_ast(isEven, "isEven"), std::cout, 0); return 0; } diff --git a/samples/sample49.cpp b/samples/sample49.cpp index c55481c..8890e7a 100644 --- a/samples/sample49.cpp +++ b/samples/sample49.cpp @@ -1,20 +1,42 @@ +// Include the headers #include "blocks/c_code_generator.h" #include "builder/dyn_var.h" +#include "builder/lib/utils.h" +#include "builder/static_var.h" +#include +// Include the BuildIt types using builder::dyn_var; +using builder::static_var; -static void foo(void) { - std::string name = "my_var"; - dyn_var v = builder::with_name(name, true); - v = 1; - dyn_var v1 = builder::with_name(name); - dyn_var y = v1; +struct external_object_t { + dyn_var member = builder::defer_init(); + static_var counter = builder::defer_init(); +}; + +static void foo(external_object_t &obj) { + // Init not + obj.member.deferred_init(builder::with_name("member_var", true)); + obj.counter.deferred_init(); + obj.counter = 0; + + dyn_var x = 0; + if (x) { + obj.member = 1; + } else { + obj.member = 2; + } + + for (obj.counter = 0; obj.counter < 10; obj.counter++) + if (obj.member % 2 == 0) + obj.member += obj.counter; } + int main(int argc, char *argv[]) { - builder::builder_context context; - auto ast = context.extract_function_ast(foo, "foo"); - ast->dump(std::cout, 0); - block::c_code_generator::generate_code(ast, std::cout, 0); + external_object_t obj; + + builder::builder_context context; + block::c_code_generator::generate_code(context.extract_function_ast(foo, "foo", obj), std::cout, 0); return 0; } diff --git a/samples/sample5.cpp b/samples/sample5.cpp index 9c263fa..80953bf 100644 --- a/samples/sample5.cpp +++ b/samples/sample5.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include diff --git a/samples/sample50.cpp b/samples/sample50.cpp index 41ef02a..52c63cd 100644 --- a/samples/sample50.cpp +++ b/samples/sample50.cpp @@ -1,30 +1,49 @@ +// Include the headers #include "blocks/c_code_generator.h" -#include "builder/builder.h" -#include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" #include + +// Include the BuildIt types using builder::dyn_var; using builder::static_var; static void bar(void) { - dyn_var k = 0; - dyn_var t = 0; - while (1) { - while (k != 1) { - - if (k == 2) - break; - } - while (k != 3) { - } + static_var x = 0; + + dyn_var y = 0; + dyn_var m, n; + + if (y) { + x = 1; + } else { + x = 2; + } + + { + // When z is declared, x is in different states + dyn_var z = x; + dyn_var k = m; + + // Executions can now merge, but z is still in different states + x = 0; + + // this declaration forces executions to merge because static tags are the same + // merge is triggered by memoization + dyn_var b; + + // this statement now has issues because z has forked + dyn_var a = z; + + z = z + k; } + + // This statement should be merged since z's lifetime has ended + m = m + 3; } int main(int argc, char *argv[]) { - builder::builder_context context; - auto ast = context.extract_function_ast(bar, "bar"); - ast->dump(std::cout, 0); - block::c_code_generator::generate_code(ast, std::cout, 0); + block::c_code_generator::generate_code(builder::builder_context().extract_function_ast(bar, "bar"), std::cout, + 0); return 0; } diff --git a/samples/sample51.cpp b/samples/sample51.cpp index 4861025..4421152 100644 --- a/samples/sample51.cpp +++ b/samples/sample51.cpp @@ -1,31 +1,38 @@ +// Include the headers #include "blocks/c_code_generator.h" -#include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" #include + +// Include the BuildIt types using builder::dyn_var; using builder::static_var; + +// Members of this struct will have names except for the first one +// since we currently don't match sizes +struct wrapper1 { + dyn_var mem1; + dyn_var mem2; +}; + +// Members of this struct will have names since the first member is a non dynamic one +struct wrapper2 { + int spacer; + dyn_var mem1; + dyn_var mem2; +}; + + static void bar(void) { - // This example tests the case where a jump cuts - // through the parent loop - dyn_var x = 5; - while (x < 10) { - while (x > 100) { - if (x == 0) - break; - x = x + 4; - } - x = x + 5; - while (x != -1) - x = x + 6; - } + struct wrapper1 x; + struct wrapper2 y; + x.mem1 = x.mem2; + y.mem2 = y.mem1; } int main(int argc, char *argv[]) { - builder::builder_context context; - auto ast = context.extract_function_ast(bar, "bar"); - ast->dump(std::cout, 0); - block::c_code_generator::generate_code(ast, std::cout, 0); + block::c_code_generator::generate_code( + builder::builder_context().extract_function_ast(bar, "bar"), std::cout, 0); return 0; } diff --git a/samples/sample52.cpp b/samples/sample52.cpp index 9cd638c..91232f4 100644 --- a/samples/sample52.cpp +++ b/samples/sample52.cpp @@ -1,22 +1,46 @@ -// Include the headers #include "blocks/c_code_generator.h" +#include "builder/builder_context.h" #include "builder/dyn_var.h" -#include "builder/lib/utils.h" #include "builder/static_var.h" #include -// Include the BuildIt types using builder::dyn_var; using builder::static_var; -static dyn_var isEven(dyn_var x) { - static_var xs = builder::up_cast_range(x, 16); - return (xs % 2) == 0; + +struct struct_type { + dyn_var x; + dyn_var y; +}; + +struct my_type { + static constexpr const char* type_name = "my_type"; + dyn_var nested = builder::with_name("nested"); + dyn_var another; +}; + + +dyn_var p = builder::with_name("p"); + +static void bar(void) { + dyn_var a; + dyn_var b; + + a.nested = b; + a.nested.x = a.another; + + a.nested.y++; + p.x = 0; } int main(int argc, char *argv[]) { + builder::builder_context context; - context.run_rce = true; - block::c_code_generator::generate_code(context.extract_function_ast(isEven, "isEven"), std::cout, 0); + auto ast = context.extract_function_ast(bar, "bar"); + ast->dump(std::cout, 0); + + block::c_code_generator::generate_struct_decl>(std::cout); + block::c_code_generator::generate_struct_decl>(std::cout); + block::c_code_generator::generate_code(ast, std::cout, 0); return 0; } diff --git a/samples/sample53.cpp b/samples/sample53.cpp index 8890e7a..6ee5732 100644 --- a/samples/sample53.cpp +++ b/samples/sample53.cpp @@ -1,42 +1,40 @@ // Include the headers #include "blocks/c_code_generator.h" -#include "builder/dyn_var.h" -#include "builder/lib/utils.h" #include "builder/static_var.h" +#include "builder/dyn_var.h" +#include "blocks/rce.h" #include // Include the BuildIt types using builder::dyn_var; using builder::static_var; -struct external_object_t { - dyn_var member = builder::defer_init(); - static_var counter = builder::defer_init(); -}; - -static void foo(external_object_t &obj) { - // Init not - obj.member.deferred_init(builder::with_name("member_var", true)); - obj.counter.deferred_init(); - obj.counter = 0; - - dyn_var x = 0; - if (x) { - obj.member = 1; - } else { - obj.member = 2; - } - - for (obj.counter = 0; obj.counter < 10; obj.counter++) - if (obj.member % 2 == 0) - obj.member += obj.counter; -} +static void bar(void) { + // Insert code to stage here + + dyn_var x = 0; + dyn_var y = &x; + + (*y)++; -int main(int argc, char *argv[]) { + dyn_var z = 0; + z++; - external_object_t obj; + dyn_var a = z; + z++; + dyn_var b = a; + b++; + + +} + +int main(int argc, char* argv[]) { builder::builder_context context; - block::c_code_generator::generate_code(context.extract_function_ast(foo, "foo", obj), std::cout, 0); + auto ast = context.extract_function_ast(bar, "bar"); + block::eliminate_redundant_vars(ast); + block::c_code_generator::generate_code(ast, std::cout, 0); return 0; } + + diff --git a/samples/sample54.cpp b/samples/sample54.cpp index 52c63cd..8f346b3 100644 --- a/samples/sample54.cpp +++ b/samples/sample54.cpp @@ -1,49 +1,41 @@ -// Include the headers #include "blocks/c_code_generator.h" +#include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" +#include "builder/lib/utils.h" #include - -// Include the BuildIt types using builder::dyn_var; using builder::static_var; -static void bar(void) { - static_var x = 0; - - dyn_var y = 0; - dyn_var m, n; - - if (y) { - x = 1; - } else { - x = 2; - } - { - // When z is declared, x is in different states - dyn_var z = x; - dyn_var k = m; +static void bar(dyn_var x) { + /* Test out of order deinitialization of static variables and arrays */ + + auto sv1 = new static_var(); + auto sv2 = new static_var(); - // Executions can now merge, but z is still in different states - x = 0; + auto sva1 = new static_var(); + sva1->resize(5); + auto sva2 = new static_var(); + sva2->resize(5); - // this declaration forces executions to merge because static tags are the same - // merge is triggered by memoization - dyn_var b; - // this statement now has issues because z has forked - dyn_var a = z; + dyn_var y; - z = z + k; - } + delete sv1; + delete sv2; + delete sva1; + delete sva2; + + // A realistic test is hard to get right (depends on rv-optimizations) + // so we will just stick with this simple one above - // This statement should be merged since z's lifetime has ended - m = m + 3; } int main(int argc, char *argv[]) { - block::c_code_generator::generate_code(builder::builder_context().extract_function_ast(bar, "bar"), std::cout, - 0); + builder::builder_context context; + auto ast = context.extract_function_ast(bar, "bar"); + ast->dump(std::cout, 0); + block::c_code_generator::generate_code(ast, std::cout, 0); return 0; } diff --git a/samples/sample55.cpp b/samples/sample55.cpp index 4421152..3929f4e 100644 --- a/samples/sample55.cpp +++ b/samples/sample55.cpp @@ -1,38 +1,30 @@ -// Include the headers #include "blocks/c_code_generator.h" +#include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" +#include "builder/lib/utils.h" #include - -// Include the BuildIt types using builder::dyn_var; using builder::static_var; -// Members of this struct will have names except for the first one -// since we currently don't match sizes -struct wrapper1 { - dyn_var mem1; - dyn_var mem2; -}; - -// Members of this struct will have names since the first member is a non dynamic one -struct wrapper2 { - int spacer; - dyn_var mem1; - dyn_var mem2; +template +struct vector: public builder::custom_type { + static constexpr const char* type_name = "std::vector"; + typedef T dereference_type; + dyn_var resize = builder::with_name("resize"); }; - static void bar(void) { - struct wrapper1 x; - struct wrapper2 y; - x.mem1 = x.mem2; - y.mem2 = y.mem1; + dyn_var>> x; + x.resize(2); + x[0].resize(1); } int main(int argc, char *argv[]) { - block::c_code_generator::generate_code( - builder::builder_context().extract_function_ast(bar, "bar"), std::cout, 0); + builder::builder_context context; + auto ast = context.extract_function_ast(bar, "bar"); + ast->dump(std::cout, 0); + block::c_code_generator::generate_code(ast, std::cout, 0); return 0; } diff --git a/samples/sample56.cpp b/samples/sample56.cpp index 6dda718..5b58b71 100644 --- a/samples/sample56.cpp +++ b/samples/sample56.cpp @@ -1,48 +1,57 @@ +// Include the headers #include "blocks/c_code_generator.h" -#include "builder/builder.h" -#include "builder/builder_context.h" -#include "builder/dyn_var.h" #include "builder/static_var.h" +#include "builder/dyn_var.h" +#include "builder/generics.h" +#include "blocks/rce.h" #include -using builder::as_member; +// Include the BuildIt types using builder::dyn_var; using builder::static_var; +using builder::generic; +using builder::type_of; +using builder::with_type; -struct struct_type { - dyn_var x; - dyn_var y; -}; +static dyn_var get_max(dyn_var x, dyn_var y) { -struct my_type { - static constexpr const char* type_name = "my_type"; - dyn_var nested = builder::with_name("nested"); - dyn_var another; -}; + if (type_of(x) != type_of(y)) { + assert(false && "get_max can only compare similar types"); + } + dyn_var res = with_type(type_of(x)); + if (x < y) res = y; + else res = x; + return res; +} -dyn_var p = builder::as_global("p"); +static void set_zero(dyn_var ptr) { + *ptr = 0; +} static void bar(void) { - dyn_var a; - dyn_var b; - - a.nested = b; - a.nested.x = a.another; - - a.nested.y++; - p.x = 0; -} + dyn_var x; + x.set_type(builder::create_type()); + + dyn_var y = with_type(builder::create_type()); + + dyn_var a, b; + dyn_var m,n; -int main(int argc, char *argv[]) { + dyn_var m1 = get_max(with_type(a), with_type(b)); + dyn_var m2 = get_max(m, n); + + set_zero(with_type(pointer_of(type_of(x)), &x)); +} + +int main(int argc, char* argv[]) { builder::builder_context context; + context.run_rce = true; auto ast = context.extract_function_ast(bar, "bar"); - ast->dump(std::cout, 0); - - block::c_code_generator::generate_struct_decl>(std::cout); - block::c_code_generator::generate_struct_decl>(std::cout); block::c_code_generator::generate_code(ast, std::cout, 0); return 0; } + + diff --git a/samples/sample57.cpp b/samples/sample57.cpp index 6ee5732..0220e73 100644 --- a/samples/sample57.cpp +++ b/samples/sample57.cpp @@ -3,36 +3,29 @@ #include "builder/static_var.h" #include "builder/dyn_var.h" #include "blocks/rce.h" +#include "builder/nd_var.h" #include // Include the BuildIt types using builder::dyn_var; using builder::static_var; +using builder::nd_var; static void bar(void) { - // Insert code to stage here - - dyn_var x = 0; - dyn_var y = &x; - - (*y)++; + nd_var t; + dyn_var x = (int)((builder::true_top)t).value; - dyn_var z = 0; - z++; + t.require_val(builder::true_top::T); - dyn_var a = z; - z++; - - dyn_var b = a; - b++; - - + nd_var r(builder::true_top::F); + dyn_var y = (int)(r.get()->value); + r.require_val(builder::true_top::F); + t.require_val(builder::true_top::T); } int main(int argc, char* argv[]) { builder::builder_context context; auto ast = context.extract_function_ast(bar, "bar"); - block::eliminate_redundant_vars(ast); block::c_code_generator::generate_code(ast, std::cout, 0); return 0; } diff --git a/samples/sample58.cpp b/samples/sample58.cpp index 901b579..3c6b14a 100644 --- a/samples/sample58.cpp +++ b/samples/sample58.cpp @@ -1,42 +1,58 @@ -#include "blocks/c_code_generator.h" -#include "builder/builder.h" +#include "blocks/matchers/patterns.h" +#include "blocks/matchers/matchers.h" +#include "blocks/matchers/replacers.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include "builder/static_var.h" -#include "builder/lib/utils.h" -#include +#include "blocks/c_code_generator.h" + +using namespace block::matcher; using builder::dyn_var; using builder::static_var; - -static void bar(dyn_var x) { - /* Test out of order deinitialization of static variables and arrays */ - - auto sv1 = new static_var(); - auto sv2 = new static_var(); - - auto sva1 = new static_var(); - sva1->resize(5); - auto sva2 = new static_var(); - sva2->resize(5); +static void foo(void) { + dyn_var x = 0; + x = x + 1; + // this should not be matched + dyn_var y = 0; + y = x + 1; + dyn_var z = 0; + z = z + 2; - dyn_var y; - - delete sv1; - delete sv2; - delete sva1; - delete sva2; - - // A realistic test is hard to get right (depends on rv-optimizations) - // so we will just stick with this simple one above - + z = x + 0; } -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) { builder::builder_context context; - auto ast = context.extract_function_ast(bar, "bar"); + auto ast = context.extract_function_ast(foo, "foo"); + + auto p = assign_expr(var("a"), binary_expr(var("a"), int_const(1))); + auto matches = find_all_matches(p, ast); + std::cout << "Found " << matches.size() << " matches" << std::endl; + std::cout << "-----" << std::endl; + for (auto x: matches) { + x.node->dump(std::cout, 0); + std::cout << "-----" << std::endl; + } + + + auto p2 = expr("a") + int_const(0); + auto matches2 = find_all_matches(p2, ast); + std::cout << "Found " << matches2.size() << " matches" << std::endl; + std::cout << "-----" << std::endl; + for (auto x: matches2) { + x.node->dump(std::cout, 0); + std::cout << "-----" << std::endl; + } + + auto p3 = expr("a"); + + for (auto x: matches2) { + replace_match(ast, x, p3); + } + std::cout << "After all replacements" << std::endl; ast->dump(std::cout, 0); block::c_code_generator::generate_code(ast, std::cout, 0); return 0; -} +} diff --git a/samples/sample59.cpp b/samples/sample59.cpp index 254ed66..d368523 100644 --- a/samples/sample59.cpp +++ b/samples/sample59.cpp @@ -1,31 +1,42 @@ +// Include the headers #include "blocks/c_code_generator.h" -#include "builder/builder.h" -#include "builder/builder_context.h" -#include "builder/dyn_var.h" #include "builder/static_var.h" -#include "builder/lib/utils.h" +#include "builder/dyn_var.h" +#include "blocks/rce.h" #include + +// Include the BuildIt types using builder::dyn_var; using builder::static_var; +struct foo; + +// Mechanism for assigning names to incomplete types +namespace builder { +template <> +struct external_type_namer { + static constexpr const char* type_name = "struct foo"; +}; +} -template -struct vector: public builder::custom_type { - static constexpr const char* type_name = "std::vector"; - typedef T dereference_type; - dyn_var resize = builder::with_name("resize"); +struct linked_list { + static constexpr const char* type_name = "linked_list"; + dyn_var next = builder::with_name("next"); + dyn_var other = builder::with_name("other"); }; static void bar(void) { - dyn_var>> x; - x.resize(2); - x[0].resize(1); + dyn_var x; + x->next->next->next = 0; + x->other = 0; } -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) { + block::c_code_generator::generate_struct_decl>(std::cout); builder::builder_context context; auto ast = context.extract_function_ast(bar, "bar"); - ast->dump(std::cout, 0); block::c_code_generator::generate_code(ast, std::cout, 0); return 0; } + + diff --git a/samples/sample6.cpp b/samples/sample6.cpp index 7db87da..e37b62a 100644 --- a/samples/sample6.cpp +++ b/samples/sample6.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include diff --git a/samples/sample60.cpp b/samples/sample60.cpp index 6f43b36..39a4dd5 100644 --- a/samples/sample60.cpp +++ b/samples/sample60.cpp @@ -8,48 +8,47 @@ // Include the BuildIt types using builder::dyn_var; using builder::static_var; -using builder::generic; -using builder::type_of; -using builder::with_type; +static dyn_var power(dyn_var base, dyn_var exp) { + + // Make a copy of exponent because we want to make sure it isn't + // copy eliminated partially -static dyn_var get_max(dyn_var x, dyn_var y) { + dyn_var exponent = exp; - if (type_of(x) != type_of(y)) { - assert(false && "get_max can only compare similar types"); + dyn_var res = 1, x = base; + while (exponent > 1) { + if (exponent % 2 == 1) + res = res * x; + x = x * x; + exponent = exponent / 2; } - - dyn_var res = with_type(type_of(x)); - if (x < y) res = y; - else res = x; - return res; -} - -static void set_zero(dyn_var ptr) { - *ptr = 0; + return res * x; } static void bar(void) { - dyn_var x; - x.set_type(builder::create_type()); - - dyn_var y = with_type(builder::create_type()); - - dyn_var a, b; - dyn_var m,n; - dyn_var m1 = get_max(with_type(a), with_type(b)); - dyn_var m2 = get_max(m, n); + dyn_var a; + dyn_var x = a + 1; + while (x) { + a = a + 1; + } - - set_zero(with_type(pointer_of(type_of(x)), &x)); -} +} int main(int argc, char* argv[]) { + builder::builder_context context; context.run_rce = true; - auto ast = context.extract_function_ast(bar, "bar"); + auto ast = context.extract_function_ast(power, "power"); block::c_code_generator::generate_code(ast, std::cout, 0); + + + builder::builder_context context2; + context2.run_rce = true; + auto ast2 = context2.extract_function_ast(bar, "bar"); + block::c_code_generator::generate_code(ast2, std::cout, 0); + return 0; } diff --git a/samples/sample61.cpp b/samples/sample61.cpp index 0220e73..9613572 100644 --- a/samples/sample61.cpp +++ b/samples/sample61.cpp @@ -3,25 +3,24 @@ #include "builder/static_var.h" #include "builder/dyn_var.h" #include "blocks/rce.h" -#include "builder/nd_var.h" #include // Include the BuildIt types using builder::dyn_var; using builder::static_var; -using builder::nd_var; static void bar(void) { - nd_var t; - dyn_var x = (int)((builder::true_top)t).value; - - t.require_val(builder::true_top::T); - - nd_var r(builder::true_top::F); - dyn_var y = (int)(r.get()->value); - r.require_val(builder::true_top::F); - t.require_val(builder::true_top::T); -} + static_var> x; + while (x.val.size() < 3) { + dyn_var y = x.val.size(); + if (y < x.val.size()) { + y++; + } else { + y--; + } + x.val.push_back(2); + } +} int main(int argc, char* argv[]) { builder::builder_context context; diff --git a/samples/sample62.cpp b/samples/sample62.cpp index 3c6b14a..12cf7f3 100644 --- a/samples/sample62.cpp +++ b/samples/sample62.cpp @@ -1,58 +1,27 @@ -#include "blocks/matchers/patterns.h" -#include "blocks/matchers/matchers.h" -#include "blocks/matchers/replacers.h" -#include "builder/builder_context.h" -#include "builder/dyn_var.h" -#include "builder/static_var.h" +// Include the headers #include "blocks/c_code_generator.h" +#include "builder/static_var.h" +#include "builder/dyn_var.h" +#include "blocks/rce.h" +#include -using namespace block::matcher; +// Include the BuildIt types using builder::dyn_var; using builder::static_var; -static void foo(void) { - dyn_var x = 0; - x = x + 1; - // this should not be matched - dyn_var y = 0; - y = x + 1; - dyn_var z = 0; - z = z + 2; - - - z = x + 0; -} +static void bar(std::vector x) { + dyn_var y = x; + for (dyn_var i = 0; i < x.size(); ++i) { + y[i] = y[i] + y[i-1]; + } +} int main(int argc, char* argv[]) { builder::builder_context context; - auto ast = context.extract_function_ast(foo, "foo"); - - auto p = assign_expr(var("a"), binary_expr(var("a"), int_const(1))); - auto matches = find_all_matches(p, ast); - std::cout << "Found " << matches.size() << " matches" << std::endl; - std::cout << "-----" << std::endl; - for (auto x: matches) { - x.node->dump(std::cout, 0); - std::cout << "-----" << std::endl; - } - - - auto p2 = expr("a") + int_const(0); - auto matches2 = find_all_matches(p2, ast); - std::cout << "Found " << matches2.size() << " matches" << std::endl; - std::cout << "-----" << std::endl; - for (auto x: matches2) { - x.node->dump(std::cout, 0); - std::cout << "-----" << std::endl; - } - - auto p3 = expr("a"); - - for (auto x: matches2) { - replace_match(ast, x, p3); - } - std::cout << "After all replacements" << std::endl; - ast->dump(std::cout, 0); + std::vector x = {1, 2, 3}; + auto ast = context.extract_function_ast(bar, "bar", x); block::c_code_generator::generate_code(ast, std::cout, 0); return 0; -} +} + + diff --git a/samples/sample63.cpp b/samples/sample63.cpp index d368523..59be62b 100644 --- a/samples/sample63.cpp +++ b/samples/sample63.cpp @@ -9,30 +9,18 @@ using builder::dyn_var; using builder::static_var; -struct foo; - -// Mechanism for assigning names to incomplete types -namespace builder { -template <> -struct external_type_namer { - static constexpr const char* type_name = "struct foo"; -}; -} - -struct linked_list { - static constexpr const char* type_name = "linked_list"; - dyn_var next = builder::with_name("next"); - dyn_var other = builder::with_name("other"); -}; - static void bar(void) { - dyn_var x; - x->next->next->next = 0; - x->other = 0; -} + builder::annotate("pragma: omp parallel for"); + for (dyn_var outer = 0; outer < 10; ++outer) { + dyn_var sum = 0; + builder::annotate("pragma: unroll"); + for (dyn_var inner = 0; inner < 15; ++inner) { + sum += inner; + } + } +} int main(int argc, char* argv[]) { - block::c_code_generator::generate_struct_decl>(std::cout); builder::builder_context context; auto ast = context.extract_function_ast(bar, "bar"); block::c_code_generator::generate_code(ast, std::cout, 0); diff --git a/samples/sample64.cpp b/samples/sample64.cpp index 39a4dd5..70b5b12 100644 --- a/samples/sample64.cpp +++ b/samples/sample64.cpp @@ -2,54 +2,27 @@ #include "blocks/c_code_generator.h" #include "builder/static_var.h" #include "builder/dyn_var.h" -#include "blocks/rce.h" #include // Include the BuildIt types using builder::dyn_var; using builder::static_var; -static dyn_var power(dyn_var base, dyn_var exp) { - - // Make a copy of exponent because we want to make sure it isn't - // copy eliminated partially - - dyn_var exponent = exp; - - dyn_var res = 1, x = base; - while (exponent > 1) { - if (exponent % 2 == 1) - res = res * x; - x = x * x; - exponent = exponent / 2; - } - return res * x; +namespace runtime { +static dyn_var malloc = builder::with_name("malloc"); +static dyn_var free = builder::with_name("free"); } static void bar(void) { - - dyn_var a; - dyn_var x = a + 1; - while (x) { - a = a + 1; - } - -} + dyn_var x = builder::cast_to(runtime::malloc(sizeof(int))); + x[0] = 123; + runtime::free(x); +} int main(int argc, char* argv[]) { - builder::builder_context context; - context.run_rce = true; - auto ast = context.extract_function_ast(power, "power"); + auto ast = context.extract_function_ast(bar, "bar"); block::c_code_generator::generate_code(ast, std::cout, 0); - - - builder::builder_context context2; - context2.run_rce = true; - auto ast2 = context2.extract_function_ast(bar, "bar"); - block::c_code_generator::generate_code(ast2, std::cout, 0); - return 0; } - diff --git a/samples/sample65.cpp b/samples/sample65.cpp index 9613572..d2a172d 100644 --- a/samples/sample65.cpp +++ b/samples/sample65.cpp @@ -2,31 +2,26 @@ #include "blocks/c_code_generator.h" #include "builder/static_var.h" #include "builder/dyn_var.h" -#include "blocks/rce.h" #include // Include the BuildIt types using builder::dyn_var; using builder::static_var; -static void bar(void) { - static_var> x; - while (x.val.size() < 3) { - dyn_var y = x.val.size(); - if (y < x.val.size()) { - y++; - } else { - y--; - } - x.val.push_back(2); + +static void bar(dyn_var x, dyn_var y, dyn_var size) { + x.add_attribute("restrict"); + y.add_attribute("restrict"); + for (builder::dyn_var i = 0; i < size; i++) { + x[i] = y[i]; } -} +} int main(int argc, char* argv[]) { builder::builder_context context; auto ast = context.extract_function_ast(bar, "bar"); + auto fd = block::to(ast); block::c_code_generator::generate_code(ast, std::cout, 0); return 0; } - diff --git a/samples/sample66.cpp b/samples/sample66.cpp deleted file mode 100644 index 12cf7f3..0000000 --- a/samples/sample66.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// Include the headers -#include "blocks/c_code_generator.h" -#include "builder/static_var.h" -#include "builder/dyn_var.h" -#include "blocks/rce.h" -#include - -// Include the BuildIt types -using builder::dyn_var; -using builder::static_var; - -static void bar(std::vector x) { - dyn_var y = x; - for (dyn_var i = 0; i < x.size(); ++i) { - y[i] = y[i] + y[i-1]; - } -} - -int main(int argc, char* argv[]) { - builder::builder_context context; - std::vector x = {1, 2, 3}; - auto ast = context.extract_function_ast(bar, "bar", x); - block::c_code_generator::generate_code(ast, std::cout, 0); - return 0; -} - - diff --git a/samples/sample67.cpp b/samples/sample67.cpp deleted file mode 100644 index 59be62b..0000000 --- a/samples/sample67.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// Include the headers -#include "blocks/c_code_generator.h" -#include "builder/static_var.h" -#include "builder/dyn_var.h" -#include "blocks/rce.h" -#include - -// Include the BuildIt types -using builder::dyn_var; -using builder::static_var; - -static void bar(void) { - builder::annotate("pragma: omp parallel for"); - for (dyn_var outer = 0; outer < 10; ++outer) { - dyn_var sum = 0; - builder::annotate("pragma: unroll"); - for (dyn_var inner = 0; inner < 15; ++inner) { - sum += inner; - } - } -} - -int main(int argc, char* argv[]) { - builder::builder_context context; - auto ast = context.extract_function_ast(bar, "bar"); - block::c_code_generator::generate_code(ast, std::cout, 0); - return 0; -} - - diff --git a/samples/sample68.cpp b/samples/sample68.cpp deleted file mode 100644 index 70b5b12..0000000 --- a/samples/sample68.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Include the headers -#include "blocks/c_code_generator.h" -#include "builder/static_var.h" -#include "builder/dyn_var.h" -#include - -// Include the BuildIt types -using builder::dyn_var; -using builder::static_var; - -namespace runtime { -static dyn_var malloc = builder::with_name("malloc"); -static dyn_var free = builder::with_name("free"); -} - -static void bar(void) { - dyn_var x = builder::cast_to(runtime::malloc(sizeof(int))); - x[0] = 123; - runtime::free(x); -} - -int main(int argc, char* argv[]) { - builder::builder_context context; - auto ast = context.extract_function_ast(bar, "bar"); - block::c_code_generator::generate_code(ast, std::cout, 0); - return 0; -} - diff --git a/samples/sample69.cpp b/samples/sample69.cpp deleted file mode 100644 index d2a172d..0000000 --- a/samples/sample69.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// Include the headers -#include "blocks/c_code_generator.h" -#include "builder/static_var.h" -#include "builder/dyn_var.h" -#include - -// Include the BuildIt types -using builder::dyn_var; -using builder::static_var; - - -static void bar(dyn_var x, dyn_var y, dyn_var size) { - x.add_attribute("restrict"); - y.add_attribute("restrict"); - for (builder::dyn_var i = 0; i < size; i++) { - x[i] = y[i]; - } -} - -int main(int argc, char* argv[]) { - builder::builder_context context; - auto ast = context.extract_function_ast(bar, "bar"); - auto fd = block::to(ast); - block::c_code_generator::generate_code(ast, std::cout, 0); - return 0; -} - diff --git a/samples/sample7.cpp b/samples/sample7.cpp index 720c880..bad5a84 100644 --- a/samples/sample7.cpp +++ b/samples/sample7.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include diff --git a/samples/sample8.cpp b/samples/sample8.cpp index 7db87da..e37b62a 100644 --- a/samples/sample8.cpp +++ b/samples/sample8.cpp @@ -1,5 +1,4 @@ #include "blocks/c_code_generator.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include diff --git a/samples/sample9.cpp b/samples/sample9.cpp index 5c14f2a..0a2a589 100644 --- a/samples/sample9.cpp +++ b/samples/sample9.cpp @@ -1,5 +1,4 @@ #include "blocks/annotation_finder.h" -#include "builder/builder.h" #include "builder/builder_context.h" #include "builder/dyn_var.h" #include @@ -24,7 +23,7 @@ static void foo(void) { int main(int argc, char *argv[]) { builder::builder_context context; auto ast = context.extract_ast_from_function(foo); - + block::stmt::Ptr s1_stmt = block::annotation_finder::find_annotation(ast, "s1"); if (s1_stmt != nullptr) { s1_stmt->dump(std::cout, 0); diff --git a/src/blocks/loop_roll.cpp b/src/blocks/loop_roll.cpp index 7b06e9f..8c7c263 100644 --- a/src/blocks/loop_roll.cpp +++ b/src/blocks/loop_roll.cpp @@ -1,5 +1,4 @@ #include "blocks/loop_roll.h" -#include "builder/builder.h" #include "builder/dyn_var.h" namespace block { static bool is_roll(std::set ss, std::string &match) { diff --git a/src/builder/annotate.cpp b/src/builder/annotate.cpp index 64fa878..f096d2f 100644 --- a/src/builder/annotate.cpp +++ b/src/builder/annotate.cpp @@ -1,4 +1,4 @@ -#include "builder/builder.h" +#include "builder/run_states.h" namespace builder { void annotate(std::string label) { diff --git a/src/builder/builder.cpp b/src/builder/builder.cpp deleted file mode 100644 index 9712f56..0000000 --- a/src/builder/builder.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include "builder/builder.h" -#include "builder/builder_context.h" -#include "builder/dyn_var.h" -#include "util/tracer.h" -#include "builder/static_var.h" -namespace builder { -namespace options { -bool track_members = false; -} - -std::vector *parents_stack = nullptr; - -template <> -std::vector extract_type_vector_dyn<>(void) { - std::vector empty_vector; - return empty_vector; -} - -void create_return_stmt(const builder &a) { - - get_run_state()->remove_node_from_sequence(a.block_expr); - get_run_state()->commit_uncommitted(); - - if (get_run_state()->is_catching_up()) - return; - block::return_stmt::Ptr ret_stmt = std::make_shared(); - // ret_stmt->static_offset = a.block_expr->static_offset; - // Finding conflicts between return statements is somehow really hard. - // So treat each return statement as different. This is okay, because a - // jump is as bad a return. Also no performance issues - ret_stmt->static_offset = tracer::get_unique_tag(); - ret_stmt->return_val = a.block_expr; - get_run_state()->add_stmt_to_current_block(ret_stmt, true); -} -builder::builder(const var &a) { - if (builder_precheck()) { - builder_from_sequence(); - return; - } - block_expr = nullptr; - - tracer::tag offset = tracer::get_offset_in_function(); - if (a.current_state == var::member_var) { - assert(a.parent_var != nullptr); - builder parent_expr_builder = (builder)(*a.parent_var); - - block::member_access_expr::Ptr member = std::make_shared(); - member->parent_expr = parent_expr_builder.block_expr; - get_run_state()->remove_node_from_sequence(member->parent_expr); - member->member_name = a.var_name; - get_run_state()->add_node_to_sequence(member); - - block_expr = member; - } else if (a.current_state == var::compound_expr) { - assert(a.encompassing_expr != nullptr); - block_expr = a.encompassing_expr; - // For now don't remove this expr from the uncommitted list - // It should be removed when it is used - } else if (a.current_state == var::standalone_var) { - assert(a.block_var != nullptr); - if (a.block_var->static_offset.stringify_stat() != offset.stringify_stat()) { - a.block_var->setMetadata("escapes_static_scope", 1); - } - block::var_expr::Ptr var_expr = std::make_shared(); - var_expr->static_offset = offset; - - var_expr->var1 = a.block_var; - get_run_state()->add_node_to_sequence(var_expr); - - block_expr = var_expr; - } - push_to_sequence(block_expr); -} - -static_var_base::~static_var_base() {} -static_var_snapshot_base::~static_var_snapshot_base() {} - -} // namespace builder diff --git a/src/builder/builder_context.cpp b/src/builder/builder_context.cpp index fc54566..43d0fec 100644 --- a/src/builder/builder_context.cpp +++ b/src/builder/builder_context.cpp @@ -8,7 +8,6 @@ #include "blocks/sub_expr_cleanup.h" #include "blocks/generic_checker.h" #include "blocks/var_namer.h" -#include "builder/builder.h" #include "builder/dyn_var.h" #include "builder/exceptions.h" #include "util/tracer.h" @@ -226,7 +225,6 @@ void builder_context::extract_function_ast_impl(invocation_state* i_state) { block::sub_expr_cleanup cleaner; ast->accept(&cleaner); - if (!feature_unstructured) { block::basic_block::cfg_block BBs = generate_basic_blocks(block::to(ast)); @@ -278,10 +276,14 @@ block::stmt::Ptr builder_context::extract_ast_from_run(run_state* r_state) { lambda_wrapper(r_state->i_state->invocation_function); r_state->commit_uncommitted(); ret_ast = ast; + get_invocation_state()->get_arena()->reset_arena(); run_state::current_run_state = nullptr; } catch (OutOfBoolsException &e) { + // Reset dyn_var arena before starting new runs + get_invocation_state()->get_arena()->reset_arena(); + run_state::current_run_state = nullptr; block::expr_stmt::Ptr last_stmt = block::to(r_state->current_stmt_block->stmts.back()); @@ -296,11 +298,13 @@ block::stmt::Ptr builder_context::extract_ast_from_run(run_state* r_state) { true_r_state.cached_expr_sequence = r_state->cached_expr_sequence; true_r_state.bool_vector.push_back(true); true_r_state.visited_offsets = r_state->visited_offsets; + true_r_state.tag_deduplication_map = r_state->tag_deduplication_map; std::copy(bool_vector_copy.begin(), bool_vector_copy.end(), std::back_inserter(true_r_state.bool_vector)); // Establish two run_states run_state false_r_state(r_state->e_state, r_state->i_state); false_r_state.visited_offsets = r_state->visited_offsets; + false_r_state.tag_deduplication_map = r_state->tag_deduplication_map; // Only copy over the expr_sequence since it is part of the r_state that // just terminated false_r_state.cached_expr_sequence = r_state->cached_expr_sequence; @@ -337,6 +341,7 @@ block::stmt::Ptr builder_context::extract_ast_from_run(run_state* r_state) { ret_ast = ast; } catch (LoopBackException &e) { + get_invocation_state()->get_arena()->reset_arena(); run_state::current_run_state = nullptr; block::goto_stmt::Ptr goto_stmt = std::make_shared(); goto_stmt->static_offset.clear(); @@ -345,6 +350,7 @@ block::stmt::Ptr builder_context::extract_ast_from_run(run_state* r_state) { r_state->add_stmt_to_current_block(goto_stmt, false); ret_ast = ast; } catch (MemoizationException &e) { + get_invocation_state()->get_arena()->reset_arena(); run_state::current_run_state = nullptr; if (feature_unstructured) { // Instead of copying statements to the current block, we will just insert a goto @@ -366,7 +372,9 @@ block::stmt::Ptr builder_context::extract_ast_from_run(run_state* r_state) { } } ret_ast = ast; - } + } + + run_state::current_run_state = nullptr; // Update the memoized table with the stmt block we just created diff --git a/src/builder/dyn_var.cpp b/src/builder/dyn_var.cpp new file mode 100644 index 0000000..d9d1b86 --- /dev/null +++ b/src/builder/dyn_var.cpp @@ -0,0 +1,70 @@ +#include "builder/dyn_var.h" +#include "builder/generics.h" +namespace builder { + +std::vector *parents_stack = nullptr; +bool user_defined_provider_track_members = false; + +int allocatable_type_registry::type_counter = 0; +std::vector* allocatable_type_registry::type_deleters = nullptr; + +void dyn_var_base::set_type(type t) { + assert(var_mode == standalone_var); + block_var->var_type = t.enclosed_type; +} + +block::expr::Ptr to_expr(const dyn_var_base& d) { + if (d.var_mode == dyn_var_base::standalone_var) { + auto e = create_expr({}); + e->var1 = d.block_var; + return e; + } else if (d.var_mode == dyn_var_base::member_var) { + auto parent_expr = to_expr(*(d.parent_var)); + auto e = create_expr({parent_expr}); + e->parent_expr = parent_expr; + e->member_name = d.member_name; + return e; + } else if (d.var_mode == dyn_var_base::compound_expr) { + return d.block_expr; + } else { + assert(false && "Bad mode for variable"); + } + return nullptr; +} +block::expr::Ptr to_expr(const float& v) { + auto e = create_expr({}); + e->value = v; + return e; +} + +block::expr::Ptr to_expr(const double& v) { + auto e = create_expr({}); + e->value = v; + return e; +} +block::expr::Ptr to_expr(const std::string& s) { + auto e = create_expr({}); + e->value = s; + return e; +} +block::expr::Ptr to_expr(const char* s) { + return to_expr((std::string)s); +} +block::expr::Ptr to_expr(char* s) { + return to_expr((std::string)s); +} +block::expr::Ptr to_expr(const std::initializer_list& i) { + std::vector args(i); + std::vector argv; + for (auto x: args) { + argv.push_back(x.e); + } + auto e = create_expr(argv); + e->elems = argv; + return e; +} +block::expr::Ptr to_expr(const expr_wrapper_base& e) { + return e.e; +} + +} diff --git a/src/builder/generics.cpp b/src/builder/generics.cpp index 9ae498d..a492278 100644 --- a/src/builder/generics.cpp +++ b/src/builder/generics.cpp @@ -1,9 +1,9 @@ #include "builder/dyn_var.h" #include "blocks/var.h" - +#include "builder/generics.h" namespace builder { -type type_of(const var& v) { +type type_of(const dyn_var_base& v) { assert(v.block_var); // We want to avoid cloning variables that themselves don't have a type yet assert(v.block_var->var_type && "Cloning type from variable that doesn't have a type"); diff --git a/src/builder/run_states.cpp b/src/builder/run_states.cpp index 73c7d41..4c826a9 100644 --- a/src/builder/run_states.cpp +++ b/src/builder/run_states.cpp @@ -5,6 +5,9 @@ namespace builder { run_state* run_state::current_run_state = nullptr; + + + void run_state::add_stmt_to_current_block(block::stmt::Ptr s, bool check_for_conflicts) { if (bool_vector.size() > 0) { return; @@ -13,7 +16,38 @@ void run_state::add_stmt_to_current_block(block::stmt::Ptr s, bool check_for_con s->annotation = get_and_clear_annotations(); } if (!s->static_offset.is_empty() && is_visited_tag(s->static_offset) > 0) { - throw LoopBackException(s->static_offset); + // Let's go and find that statement + auto lt = visited_offsets[s->static_offset]; + // This is only a loopback if it is an exact match + if (lt->is_same(s)) + throw LoopBackException(s->static_offset); + + // We have found a tag is the same, but statemetns aren't the same + // The tag we have has dedup_id as 0 + tracer::tag tag0 = s->static_offset; + + if (tag_deduplication_map.find(tag0) == tag_deduplication_map.end()) { + // If duplicates aren't seen before, insert this tag in the deduplication_map + // 1 is HOW many such tags exist, default is 1 for all tags + tag_deduplication_map[tag0] = 1; + } + // We have already checked 0 + size_t d_id = 1, max_d_id = tag_deduplication_map[tag0]; + for (d_id = 1; d_id < max_d_id; d_id++) { + tag0.dedup_id = d_id; + // Find the statement + auto lt = visited_offsets[tag0]; + if (lt->is_same(s)) { + s->static_offset = tag0; + s->static_offset.cached_string = ""; + throw LoopBackException(s->static_offset); + } + } + // If we reached here, there is no match, this must be a new copy, update the tag and dedup map + s->static_offset.dedup_id = d_id; + s->static_offset.cached_string = ""; + tag0.dedup_id = 0; + tag_deduplication_map[tag0] = d_id + 1; } tracer::tag stag = s->static_offset; @@ -37,10 +71,12 @@ void run_state::add_stmt_to_current_block(block::stmt::Ptr s, bool check_for_con throw MemoizationException(s->static_offset, parent, i); } + if (parent->stmts[i]->is_same(s)) throw MemoizationException(s->static_offset, parent, i); } - visited_offsets.insert(s->static_offset); + // If dedup happens, this has already been updated + visited_offsets[s->static_offset] = s; current_stmt_block->stmts.push_back(s); } diff --git a/src/builder/static_var.cpp b/src/builder/static_var.cpp new file mode 100644 index 0000000..0b7569a --- /dev/null +++ b/src/builder/static_var.cpp @@ -0,0 +1,6 @@ +#include "builder/static_var.h" + +namespace builder { +static_var_base::~static_var_base() {} +static_var_snapshot_base::~static_var_snapshot_base() {} +} diff --git a/src/util/tracer.cpp b/src/util/tracer.cpp index df850e5..10b3fae 100644 --- a/src/util/tracer.cpp +++ b/src/util/tracer.cpp @@ -26,6 +26,8 @@ tag get_offset_in_function(void) { unw_init_local(&cursor, &context); tag new_tag; + new_tag.dedup_id = 0; + while (unw_step(&cursor)) { unw_word_t ip; unw_get_reg(&cursor, UNW_REG_IP, &ip); @@ -69,6 +71,8 @@ tag get_offset_in_function(void) { void *buffer[50]; tag new_tag; + new_tag.dedup_id = 0; + // First add the RIP pointers int backtrace_size = backtrace(buffer, 50); for (int i = 0; i < backtrace_size; i++) { @@ -118,6 +122,11 @@ tag get_unique_tag(void) { bool tag::operator==(const tag &other) const { + + // Check the dedup id first since it is cheap + if (dedup_id != other.dedup_id) + return false; + if (other.pointers.size() != pointers.size()) return false; for (unsigned int i = 0; i < pointers.size(); i++) @@ -146,6 +155,7 @@ bool tag::operator==(const tag &other) const { for (unsigned int i = 0; i < live_dyn_vars.size(); i++) if (!(live_dyn_vars[i] == other.live_dyn_vars[i])) return false; + return true; } @@ -180,6 +190,9 @@ std::string tag::stringify(void) { } output_string += "]"; + // Finally add the dedup id + output_string += "<" + std::to_string(dedup_id) + ">"; + cached_string = output_string; return output_string; }