ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
jimple_ast.h
Go to the documentation of this file.
1#ifndef ESBMC_JIMPLE_AST_H
2#define ESBMC_JIMPLE_AST_H
3
4#include <irep2/irep2_type.h>
5#include <util/irep/expr.h>
8#include <util/lang/c_types.h>
10#include <nlohmann/json.hpp>
11
12// For json parsing
13using json = nlohmann::json;
14
19{
20public:
25 void dump() const
26 {
27 log_debug("jimple", "{}", this->to_string());
28 }
29
36 virtual void from_json(const json &) = 0;
37
43 virtual std::string to_string() const = 0;
44
45protected:
59 const type2tc &t,
60 const std::string &module,
61 const std::string &name,
62 const std::string &id,
63 const std::string function_name = "")
64 {
65 symbolt symbol;
66 symbol.mode = "C";
67 symbol.module = module;
68 symbol.location = std::move(get_location(module, function_name));
69 symbol.set_type(t);
70 symbol.name = name;
71 symbol.id = id;
72 return symbol;
73 }
74
84 const type2tc &t,
85 const std::string &class_name,
86 const std::string &function_name)
87 {
88 static unsigned int counter = 0;
89
90 std::string id, name;
91 id = get_symbol_name(
92 class_name,
93 function_name,
94 "return_value$tmp$" + std::to_string(counter++));
95 name = "return_value$tmp$";
96 name += counter;
97 auto tmp_symbol =
98 create_jimple_symbolt(t, class_name, name, id, function_name);
99
100 tmp_symbol.lvalue = true;
101 tmp_symbol.static_lifetime = false;
102 tmp_symbol.is_extern = false;
103 tmp_symbol.file_local = true;
104 return tmp_symbol;
105 }
106
116 {
117 std::string allocation_function = "malloc";
118 symbolt symbol;
119 symbol.mode = "C";
120 symbol.set_type(code_type2tc(
121 std::vector<type2tc>{uint_type2()},
122 pointer_type2tc(get_empty_type()),
123 std::vector<irep_idt>{irep_idt()},
124 /*ellipsis=*/false));
125 symbol.name = allocation_function;
126 symbol.id = allocation_function;
127 symbol.is_extern = false;
128 symbol.file_local = false;
129 return symbol;
130 }
131
141 {
142 std::string func = "__ESBMC_get_object_size";
143 symbolt symbol;
144 symbol.mode = "C";
145 symbol.set_type(code_type2tc(
146 std::vector<type2tc>{pointer_type2tc(get_empty_type())},
147 uint_type2(),
148 std::vector<irep_idt>{irep_idt()},
149 /*ellipsis=*/false));
150 symbol.name = func;
151 symbol.id = func;
152 symbol.is_extern = false;
153 symbol.file_local = false;
154 return symbol;
155 }
156
168 static std::string
169 get_method_name(std::string class_name, std::string function_name)
170 {
171 std::ostringstream oss;
172 oss << class_name << ":" << function_name;
173 return oss.str();
174 }
175
186 static std::string get_symbol_name(
187 std::string class_name,
188 std::string function_name,
189 std::string symbol)
190 {
191 std::ostringstream oss;
192 oss << get_method_name(class_name, function_name) << "@" << symbol;
193 return oss.str();
194 }
195
201 static locationt
202 get_location(const std::string &module, const std::string function_name = "")
203 {
204 locationt l;
205 l.set_file(module + ".jimple");
206 if (!function_name.empty())
207 l.set_function(function_name);
208 return l;
209 }
210
211public:
214};
215
216// These functions are used by nlohmann::json. Making it easier to
217// parse the JSON file. Avoid using them directly.
218void from_json(const json &j, jimple_ast &p);
219void to_json(json &, const jimple_ast &);
220#endif // ESBMC_JIMPLE_AST_H
type2tc get_empty_type()
Definition c_types.cpp:424
type2tc uint_type2()
Definition c_types.cpp:80
Definition irep_idt.h:12
Base interface for Jimple AST.
Definition jimple_ast.h:19
static std::string get_method_name(std::string class_name, std::string function_name)
Get the unique method name.
Definition jimple_ast.h:169
int line_location
instruction location
Definition jimple_ast.h:213
virtual void from_json(const json &)=0
Initializes the current instance by parsing a JSON.
static symbolt get_allocation_function()
Get the allocation function symbol.
Definition jimple_ast.h:115
static std::string get_symbol_name(std::string class_name, std::string function_name, std::string symbol)
Get the symbol name id.
Definition jimple_ast.h:186
static symbolt create_jimple_symbolt(const type2tc &t, const std::string &module, const std::string &name, const std::string &id, const std::string function_name="")
creates a symbol with the default characteristics
Definition jimple_ast.h:58
void dump() const
Prints the contents into the the stdout.
Definition jimple_ast.h:25
static locationt get_location(const std::string &module, const std::string function_name="")
initialize a location for the symbol
Definition jimple_ast.h:202
static symbolt get_lengthof_function()
Get the esbmc_get_object_size symbol.
Definition jimple_ast.h:140
static symbolt get_temp_symbol(const type2tc &t, const std::string &class_name, const std::string &function_name)
Create a temporary variable to be used.
Definition jimple_ast.h:83
virtual std::string to_string() const =0
Converts the object into a string.
Definition location.h:7
void set_file(const irep_idt &file)
Definition location.h:31
void set_function(const irep_idt &function)
Definition location.h:56
Definition module.h:60
Definition symbol.h:12
bool is_extern
Definition symbol.h:24
bool file_local
Definition symbol.h:24
irep_idt module
Definition symbol.h:16
locationt location
Definition symbol.h:14
irep_idt id
Definition symbol.h:15
irep_idt name
Definition symbol.h:17
void set_type(const typet &t)
Definition symbol.cpp:60
irep_idt mode
Definition symbol.h:18
irep_container< type2t > type2tc
Definition irep2.h:430
void from_json(const json &j, jimple_ast &p)
Definition jimple_file.cpp:14
void to_json(json &, const jimple_ast &)
Definition jimple_file.cpp:9
nlohmann::json json
Definition json.cpp:12
#define log_debug(mod, fmt,...)
Definition message.h:104