Commit 20121c82 authored by Julian Kranz's avatar Julian Kranz

cppgdsl: fixes

parent ca48ef9c
......@@ -11,6 +11,7 @@
extern "C" {
#include <gdsl_generic.h>
}
#include <vector>
namespace gdsl {
namespace rreil {
......@@ -18,23 +19,23 @@ namespace rreil {
class ite : public statement {
private:
sexpr *cond;
statement *then_branch;
statement *else_branch;
std::vector<statement*> *then_branch;
std::vector<statement*> *else_branch;
void put(std::ostream &out);
public:
ite(sexpr *cond, statement *then_branch, statement *else_branch);
ite(sexpr *cond, std::vector<statement*> *then_branch, std::vector<statement*> *else_branch);
~ite();
sexpr *get_cond() {
return cond;
}
statement *get_then_branch() {
std::vector<statement*> *get_then_branch() {
return then_branch;
}
statement *get_else_branch() {
std::vector<statement*> *get_else_branch() {
return else_branch;
}
......
......@@ -12,24 +12,26 @@ extern "C" {
#include <gdsl_generic.h>
}
#include <vector>
namespace gdsl {
namespace rreil {
class _while : public statement {
private:
sexpr *cond;
statement *body;
std::vector<statement*> *body;
void put(std::ostream &out);
public:
_while(sexpr *cond, statement *body);
_while(sexpr *cond, std::vector<statement*> *body);
~_while();
sexpr *get_cond() {
return cond;
}
statement *get_body() {
std::vector<statement*> *get_body() {
return body;
}
......
......@@ -10,7 +10,7 @@
using namespace std;
gdsl::rreil::ite::ite(sexpr *cond, statement *then_branch, statement *else_branch) {
gdsl::rreil::ite::ite(sexpr *cond, std::vector<statement*> *then_branch, std::vector<statement*> *else_branch) {
this->cond = cond;
this->then_branch = then_branch;
this->else_branch = else_branch;
......@@ -18,8 +18,12 @@ gdsl::rreil::ite::ite(sexpr *cond, statement *then_branch, statement *else_branc
gdsl::rreil::ite::~ite() {
delete this->cond;
delete this->then_branch;
delete this->else_branch;
for(auto stmt : *then_branch)
delete stmt;
delete then_branch;
for(auto stmt : *else_branch)
delete stmt;
delete else_branch;
}
void gdsl::rreil::ite::accept(statement_visitor &v) {
......@@ -28,7 +32,10 @@ void gdsl::rreil::ite::accept(statement_visitor &v) {
void gdsl::rreil::ite::put(std::ostream &out) {
out << "if(" << *cond << ") {\n";
out << *then_branch << "\n}{\n";
out << *else_branch;
out << "\n}";
for(auto stmt : *then_branch)
out << *stmt << "\n";
out << "}{\n";
for(auto stmt : *else_branch)
out << *stmt << "\n";
out << "}";
}
......@@ -11,13 +11,15 @@
using namespace std;
gdsl::rreil::_while::_while(sexpr *cond, statement *body) {
gdsl::rreil::_while::_while(sexpr *cond, vector<statement*> *body) {
this->cond = cond;
this->body = body;
}
gdsl::rreil::_while::~_while() {
delete this->cond;
for(auto stmt : *body)
delete stmt;
delete this->body;
}
......@@ -27,5 +29,7 @@ void gdsl::rreil::_while::accept(statement_visitor &v) {
void gdsl::rreil::_while::put(ostream &out) {
out << "while(" << *cond << ") {\n";
out << *body << "\n}";
for(auto stmt: *body)
out << stmt;
out << "\n}";
}
......@@ -82,14 +82,17 @@ void gdsl::rreil::visitor::visit(store *a) {
void gdsl::rreil::visitor::visit(ite *a) {
statement_visitor::visit(a);
a->get_cond()->accept(*this);
a->get_then_branch()->accept(*this);
a->get_else_branch()->accept(*this);
for(auto stmt : *a->get_then_branch())
stmt->accept(*this);
for(auto stmt : *a->get_else_branch())
stmt->accept(*this);
}
void gdsl::rreil::visitor::visit(_while *a) {
statement_visitor::visit(a);
a->get_cond()->accept(*this);
a->get_body()->accept(*this);
for(auto stmt : *a->get_body())
stmt->accept(*this);
}
void gdsl::rreil::visitor::visit(cbranch *a) {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment