Skip to content

Commit

Permalink
Switching to codelib.{cc,h} generated by codelib-gen
Browse files Browse the repository at this point in the history
  • Loading branch information
schrnz committed Jun 22, 2018
1 parent 436230b commit 3adec5c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 45 deletions.
47 changes: 32 additions & 15 deletions src/codelib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,49 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author "Parthipan Ramesh <[email protected]>"
* @author "Oliver Schranz <[email protected]>"
*
*/

#include "codelib.h"

const std::string TemplateCodeLib::INJECTION_ARTIST_TARGET("Lsaarland/cispa/artist/codelib/CodeLib;injectionArtistTarget(I)V");
const std::string TemplateCodeLib::BASIC_ARTIST_TARGET("Lsaarland/cispa/artist/codelib/CodeLib;basicArtistTarget(ILjava/lang/Object;)V");

// CODE_GENERATOR //////////////////////////////////////////////////////////////////////////////////////////////////////
// METHODS //////////////////////////////////
const string TemplateCodeLib::_M_SAARLAND_CISPA_ARTIST_CODELIB_CODELIB__BASICARTISTTARGET__IL__V =
"Lsaarland/cispa/artist/codelib/CodeLib;basicArtistTarget(ILjava/lang/Object;)V";
const string TemplateCodeLib::_M_SAARLAND_CISPA_ARTIST_CODELIB_CODELIB__INJECTIONARTISTTARGET__I__V =
"Lsaarland/cispa/artist/codelib/CodeLib;injectionArtistTarget(I)V";

// FIELDS ///////////////////////////////////
const string TemplateCodeLib::_F_CODECLASS_INSTANCE =
"Lsaarland/cispa/artist/codelib/CodeLib;INSTANCE";

// CLASSES //////////////////////////////////
const string TemplateCodeLib::_C_JAVA_LANG_STRING =
"Ljava/lang/String;";
const string TemplateCodeLib::_C_JAVA_LANG_OBJECT =
"Ljava/lang/Object;";
const string TemplateCodeLib::_C_CODECLASS =
"Lsaarland/cispa/artist/codelib/CodeLib;";

unordered_set<string> &TemplateCodeLib::getMethods() const {
// here we expose the signatures of codelib methods that are meant to be used from ARTist
static unordered_set<string> methods({INJECTION_ARTIST_TARGET, BASIC_ARTIST_TARGET});
return methods;
static unordered_set<string> methods({
TemplateCodeLib::_M_SAARLAND_CISPA_ARTIST_CODELIB_CODELIB__BASICARTISTTARGET__IL__V,
TemplateCodeLib::_M_SAARLAND_CISPA_ARTIST_CODELIB_CODELIB__INJECTIONARTISTTARGET__I__V,
});
return methods;
}

string &TemplateCodeLib::getInstanceField() const {
// here we expose the static field with our singleton instance. This will be used by ARTist to obtain an instance
// of the codelib to call methods on it.
static string instanceField = "Lsaarland/cispa/artist/codelib/CodeLib;INSTANCE";
return instanceField;
static string instanceField = TemplateCodeLib::_F_CODECLASS_INSTANCE;
return instanceField;
}

string &TemplateCodeLib::getCodeClass() const {
// here we expose the codelib's java class to be able to load it in ARTist
static string codeClass = "Lsaarland/cispa/artist/codelib/CodeLib;";
return codeClass;
static string codeClass = TemplateCodeLib::_C_CODECLASS;
return codeClass;
}


// CODE_GENERATOR END //////////////////////////////////////////////////////////////////////////////////////////////////


57 changes: 29 additions & 28 deletions src/codelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author "Parthipan Ramesh <[email protected]>"
* @author "Oliver Schranz <[email protected]>"
*
*/

#ifndef ART_MODULES_CODELIB_H_
#define ART_MODULES_CODELIB_H_
#ifndef ART_MODULES_TEMPLATE_TEMPLATE_CODELIB_H_
#define ART_MODULES_TEMPLATE_TEMPLATE_CODELIB_H_


#include <string>
#include <unordered_set>
Expand All @@ -33,28 +31,31 @@ using std::unordered_set;
using art::CodeLib;

class TemplateCodeLib : public CodeLib {
public:
static const string INJECTION_ARTIST_TARGET;
static const string BASIC_ARTIST_TARGET;


TemplateCodeLib() = default;

TemplateCodeLib(const TemplateCodeLib &other) = default;

TemplateCodeLib(TemplateCodeLib &&other) = default;

~TemplateCodeLib() override = default;

TemplateCodeLib &operator=(const TemplateCodeLib &) = default;

TemplateCodeLib &operator=(TemplateCodeLib &&) = default;

unordered_set<string> &getMethods() const override;

string &getInstanceField() const override;

string &getCodeClass() const override;
public:
// METHODS //////////////////////////////////
static const string _M_SAARLAND_CISPA_ARTIST_CODELIB_CODELIB__BASICARTISTTARGET__IL__V;
static const string _M_SAARLAND_CISPA_ARTIST_CODELIB_CODELIB__INJECTIONARTISTTARGET__I__V;
// FIELDS ///////////////////////////////////
static const string _F_CODECLASS_INSTANCE;
// CLASSES //////////////////////////////////
static const string _C_JAVA_LANG_STRING;
static const string _C_JAVA_LANG_OBJECT;
static const string _C_CODECLASS;

public:
TemplateCodeLib() = default;
TemplateCodeLib(const TemplateCodeLib& other) = default;
TemplateCodeLib(TemplateCodeLib&& other) = default;

~TemplateCodeLib() override = default;

TemplateCodeLib& operator=(const TemplateCodeLib&) = default;
TemplateCodeLib& operator=(TemplateCodeLib&&) = default;

unordered_set<string>& getMethods() const override;
string& getInstanceField() const override;
string& getCodeClass() const override;
}; // class TemplateCodeLib

#endif // ART_MODULES_CODELIB_H_

#endif // ART_MODULES_TEMPLATE_TEMPLATE_CODELIB_H_
2 changes: 1 addition & 1 deletion src/template_basic_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void HTemplateBasicArtist::RunPass() {
art::HInstruction* cursor = graph_->GetEntryBlock()->GetLastInstruction();

// we will add a call to this method
auto codelib_method = TemplateCodeLib::BASIC_ARTIST_TARGET;
auto codelib_method = TemplateCodeLib::_M_SAARLAND_CISPA_ARTIST_CODELIB_CODELIB__BASICARTISTTARGET__IL__V;

// we will collect all parameters as HInstructions. Instructions also represent their return value, hence if you
// want to use the return value of a method invocation, use the invocation instruction as a parameter.
Expand Down
2 changes: 1 addition & 1 deletion src/template_injection_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ vector<shared_ptr<const Injection>> HTemplateInjectionArtist::ProvideInjections(

// The injection combines the signature of the method we want to inject a call to, its parameters, and the targets
// we defined earlier.
auto injection = make_shared<const Injection>(TemplateCodeLib::INJECTION_ARTIST_TARGET, params, targets);
auto injection = make_shared<const Injection>(TemplateCodeLib::_M_SAARLAND_CISPA_ARTIST_CODELIB_CODELIB__INJECTIONARTISTTARGET__I__V, params, targets);

// In theory, you can have as many injections as you want, but due to the so called *clone bug*
// (https://github.com/Project-ARTist/ARTist/issues/10), this is currently not possible.
Expand Down

0 comments on commit 3adec5c

Please sign in to comment.