Skip to content

Commit

Permalink
Added more integral constructors for builder and dyn_var
Browse files Browse the repository at this point in the history
  • Loading branch information
AjayBrahmakshatriya committed Aug 18, 2023
1 parent 73e3041 commit 79c0fcc
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/blocks/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ class int_const : public const_expr {
}

long long value;
bool is_64bit;

virtual bool is_same(block::Ptr other) override {
if (!isa<int_const>(other))
Expand Down
20 changes: 20 additions & 0 deletions include/builder/builder_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class builder : builder_root {
builder_context *ctx = builder_context::current_builder_context;
ctx->expr_sequence.push_back(a);
}
builder(const unsigned int &a): builder((int)a) {}

builder(const int &a) {
if (builder_precheck()) {
builder_from_sequence();
Expand All @@ -82,11 +84,29 @@ class builder : builder_root {
tracer::tag offset = get_offset_in_function();
int_const->static_offset = offset;
int_const->value = a;
int_const->is_64bit = false;
builder_context::current_builder_context->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<block::int_const>();
tracer::tag offset = get_offset_in_function();
int_const->static_offset = offset;
int_const->value = a;
int_const->is_64bit = true;
builder_context::current_builder_context->add_node_to_sequence(int_const);
block_expr = int_const;

push_to_sequence(block_expr);
}

builder(const double &a) {
if (builder_precheck()) {
Expand Down
12 changes: 12 additions & 0 deletions include/builder/dyn_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,18 @@ class dyn_var_impl : public var {
return (BT) * this = a;
}

BT operator=(const unsigned int &a) {
return operator=((BT)a);
}
BT operator=(const int &a) {
return operator=((BT)a);
}
BT operator=(const long long &a) {
return operator=((BT)a);
}
BT operator=(const unsigned long long &a) {
return operator=((BT)a);
}

BT operator=(const double &a) {
return operator=((BT)a);
Expand Down Expand Up @@ -279,6 +288,9 @@ class dyn_var_impl : public var {
}

dyn_var_impl(const int &a) : my_type((BT)a) {}
dyn_var_impl(const unsigned int &a) : my_type((BT)a) {}
dyn_var_impl(const long long &a) : my_type((BT)a) {}
dyn_var_impl(const unsigned long long &a) : my_type((BT)a) {}
dyn_var_impl(const bool &a) : my_type((BT)a) {}
dyn_var_impl(const double &a) : my_type((BT)a) {}
dyn_var_impl(const float &a) : my_type((BT)a) {}
Expand Down
4 changes: 2 additions & 2 deletions samples/outputs.var_names/sample30
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ STMT_BLOCK
DECL_STMT
SCALAR_TYPE (UNSIGNED_LONG_LONG_INT)
VAR (h_7)
NO_INITIALIZATION
INT_CONST (4)
DECL_STMT
SCALAR_TYPE (CHAR)
VAR (i_8)
Expand Down Expand Up @@ -75,7 +75,7 @@ STMT_BLOCK
long int e_4;
unsigned long int f_5;
long long int g_6;
unsigned long long int h_7;
unsigned long long int h_7 = 4ll;
char i_8;
unsigned char j_9;
float k_10;
Expand Down
4 changes: 2 additions & 2 deletions samples/outputs/sample30
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ STMT_BLOCK
DECL_STMT
SCALAR_TYPE (UNSIGNED_LONG_LONG_INT)
VAR (var7)
NO_INITIALIZATION
INT_CONST (4)
DECL_STMT
SCALAR_TYPE (CHAR)
VAR (var8)
Expand Down Expand Up @@ -75,7 +75,7 @@ STMT_BLOCK
long int var4;
unsigned long int var5;
long long int var6;
unsigned long long int var7;
unsigned long long int var7 = 4ll;
char var8;
unsigned char var9;
float var10;
Expand Down
2 changes: 1 addition & 1 deletion samples/sample30.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static void foo(void) {
dyn_var<long> e;
dyn_var<unsigned long> f;
dyn_var<long long> g;
dyn_var<unsigned long long> h;
dyn_var<unsigned long long> h = (unsigned long long) 4;
dyn_var<char> i;
dyn_var<unsigned char> j;
dyn_var<float> k;
Expand Down
1 change: 1 addition & 0 deletions src/blocks/c_code_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ void c_code_generator::visit(var_expr::Ptr a) {
}
void c_code_generator::visit(int_const::Ptr a) {
oss << a->value;
if (a->is_64bit) oss << "ll";
}
void c_code_generator::visit(double_const::Ptr a) {
oss << std::setprecision(15);
Expand Down

0 comments on commit 79c0fcc

Please sign in to comment.