Commit 52deef21 authored by Jason Hiser's avatar Jason Hiser 🚜

changed var names away from camelcase

parent 02f2ff55
......@@ -32,23 +32,23 @@ using namespace InitStack;
//
// constructor
//
InitStack_t::InitStack_t(FileIR_t *p_variantIR, const string& p_functionsFilename, int p_initValue, bool p_verbose)
InitStack_t::InitStack_t(FileIR_t *p_variantIR, const string& p_functions_filename, int p_init_value, bool p_verbose)
:
Transform_t(p_variantIR), // initialize the Transform class so things like insertAssembly and getFileIR() can be used
m_initValue(p_initValue), // member variable inits, these will vary depending on your transform's objectives
m_init_value(p_init_value), // member variable inits, these will vary depending on your transform's objectives
m_verbose(p_verbose),
m_numTransformed(0)
m_num_transformed(0)
{
// check whether to read in a list of functions to transform
if (p_functionsFilename=="")
if (p_functions_filename=="")
{
cout << "Auto-initialize all functions" << endl;
m_funcsToInit = getFileIR()->getFunctions(); // use all functions from the IR
m_funcs_to_init = getFileIR()->getFunctions(); // use all functions from the IR
}
else
{
cout << "Auto-initialize functions specified in: " << p_functionsFilename << endl;
readFunctionsFromFile(p_functionsFilename); // read functions from file
cout << "Auto-initialize functions specified in: " << p_functions_filename << endl;
readFunctionsFromFile(p_functions_filename); // read functions from file
}
}
......@@ -74,7 +74,7 @@ void InitStack_t::readFunctionsFromFile(const string &p_filename)
{
auto f=*func_it;
cout <<"Adding " << f->getName() << " to function list" << endl;
m_funcsToInit.insert(f);
m_funcs_to_init.insert(f);
}
}
}
......@@ -89,7 +89,7 @@ void InitStack_t::readFunctionsFromFile(const string &p_filename)
bool InitStack_t::execute()
{
// transform all functions
for(auto f : m_funcsToInit)
for(auto f : m_funcs_to_init)
{
// todo: remove this
if (f->getName().substr(0, 1) == ".") continue; /* anh: ??? */
......@@ -98,9 +98,9 @@ bool InitStack_t::execute()
}
// #ATTRIBUTE is a convention used to help find useful information in log files
cout << "#ATTRIBUTE InitStack::numTransformed=" << m_numTransformed << endl;
cout << "#ATTRIBUTE InitStack::num_transformed=" << m_num_transformed << endl;
return m_numTransformed>0; // true means success
return m_num_transformed>0; // true means success
}
//
......@@ -127,7 +127,7 @@ void InitStack_t::initStack(Function_t* f)
if (!entry) return;
// log what we are doing
cout << "Function: " << f->getName() << " auto-initialize " << dec << num_locs << " stack memory locations (4 bytes at a time) with value = " << hex << m_initValue << endl;
cout << "Function: " << f->getName() << " auto-initialize " << dec << num_locs << " stack memory locations (4 bytes at a time) with value = " << hex << m_init_value << endl;
// determine the registers to use on x86-32 or x86-64
const auto sp_reg = getFileIR()->getArchitectureBitWidth()==64 ? "rsp" : "esp";
......@@ -140,11 +140,11 @@ void InitStack_t::initStack(Function_t* f)
//todo: anh to comment assembly and explain -100 constant.
insertAssemblyBefore (tmp, string()+"mov ["+sp_reg+"+"+to_string(-f->getStackFrameSize()-100)+"], "+scratch_reg);
tmp = insertAssemblyAfter (tmp, string()+"mov "+scratch_reg+", -" + to_string(num_locs));
const auto L1 = tmp = insertAssemblyAfter (tmp, string()+"mov dword ["+sp_reg+"+"+scratch_reg+"*4-4], " + to_string(m_initValue));
const auto L1 = tmp = insertAssemblyAfter (tmp, string()+"mov dword ["+sp_reg+"+"+scratch_reg+"*4-4], " + to_string(m_init_value));
tmp = insertAssemblyAfter (tmp, string()+"inc "+scratch_reg);
tmp = insertAssemblyAfter (tmp, string()+"jnz 0", L1); // jnz to L1
tmp = insertAssemblyAfter (tmp, string()+"mov "+scratch_reg+", ["+sp_reg+"+"+to_string(-f->getStackFrameSize()-100)+"] ");
// bump stats
m_numTransformed++;
m_num_transformed++;
}
......@@ -42,13 +42,13 @@ namespace InitStack
// construct an object
InitStack_t(
FileIR_t *p_variantIR, // the FileIR object to transform
const string& p_functionFilename, // the name of a file with functions to transform. "" -> no file and transform all functions
int initValue = 0, // the value to write when initializing the stack
const string& p_function_filename, // the name of a file with functions to transform. "" -> no file and transform all functions
int init_value = 0, // the value to write when initializing the stack
bool p_verbose = false // use verbose logging?
);
// execute the transform
// input: m_funcsToInit the set of functions to transform, the fileIR to transform
// input: m_funcs_to_init the set of functions to transform, the fileIR to transform
// output: the transformed fileIR, with extra instructions to init stack frames
// return value: true -> success, false -> fail
bool execute();
......@@ -58,7 +58,7 @@ namespace InitStack
// read in the given file full of function names to transform (called from constructor)
// input: the filename and FileIR to transform
// output: m_funcsToInit with the functions listed in the file
// output: m_funcs_to_init with the functions listed in the file
void readFunctionsFromFile(const string &p_filename);
// initialize the stack for a given function
......@@ -67,10 +67,10 @@ namespace InitStack
void initStack(Function_t* f);
// data
set<Function_t*> m_funcsToInit; // the functions whose stacks this object should initialize
int m_initValue; // the value with which to init the stack.
bool m_verbose; // do verbose logging
int m_numTransformed; // stats about how many functions that this object has transformed
set<Function_t*> m_funcs_to_init; // the functions whose stacks this object should initialize
int m_init_value; // the value with which to init the stack.
bool m_verbose; // do verbose logging
int m_num_transformed; // stats about how many functions that this object has transformed
};
}
......
......@@ -75,8 +75,7 @@ int main(int argc, char **argv)
// parse the options in a standard getopts_long loop
while(true)
{
int index = 0;
int c = getopt_long(argc, argv, short_opts, long_options, &index);
int c = getopt_long(argc, argv, short_opts, long_options, nullptr);
if(c == -1)
break;
switch(c)
......
......@@ -384,8 +384,8 @@ void StackStamp_t::stamp(Function_t* f)
if(!can_stamp(f))
{
// No, record stats.
cout<<"Skipping "<<dec<<functionsTransformed<<": "<<f->getName()<<endl;
functionsNotTransformed++;
cout<<"Skipping "<<dec<<functions_transformed<<": "<<f->getName()<<endl;
functions_not_transformed++;
// and exit.
return;
......@@ -395,8 +395,8 @@ void StackStamp_t::stamp(Function_t* f)
assert(f->getEntryPoint());
// Yes, we can stamp. Do log/stats.
cout<<"Doing "<<dec<<functionsTransformed<<": "<<f->getName()<<endl;
functionsTransformed++;
cout<<"Doing "<<dec<<functions_transformed<<": "<<f->getName()<<endl;
functions_transformed++;
const auto fix_call_fallthrough_string=string("fix_call_fallthrough");
......@@ -538,7 +538,7 @@ int StackStamp_t::execute()
for(auto func : sorted_funcs)
{
// check to see if we've transformed everything we want already.
if (ss_max_do_transform && functionsTransformed > atoi(ss_max_do_transform))
if (ss_max_do_transform && functions_transformed > atoi(ss_max_do_transform))
{
continue;
}
......@@ -551,21 +551,21 @@ int StackStamp_t::execute()
cleanup_eh_pgms();
// calculate and output stats
const auto pct_transformed=((double)functionsTransformed/(double)((functionsTransformed+functionsNotTransformed)))*100.00;
const auto pct_not_transformed=((double)functionsNotTransformed/(double)(functionsTransformed+functionsNotTransformed))*100.00;
const auto pct_transformed=((double)functions_transformed/(double)((functions_transformed+functions_not_transformed)))*100.00;
const auto pct_not_transformed=((double)functions_not_transformed/(double)(functions_transformed+functions_not_transformed))*100.00;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Instructions_added=" << dec << instructions_added << endl;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Total_number_of_functions=" << dec << functionsTransformed+functionsNotTransformed << endl;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Functions_Transformed=" << dec << functionsTransformed << endl;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Functions_Not_Transformed=" << dec << functionsNotTransformed << endl;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Instructions_added=" << dec << instructions_added << endl;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Total_number_of_functions=" << dec << functions_transformed+functions_not_transformed << endl;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Functions_Transformed=" << dec << functions_transformed << endl;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Functions_Not_Transformed=" << dec << functions_not_transformed << endl;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Percent_Functions_Transformed=" << fixed << setprecision(1) << pct_transformed << "%" << endl;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Percent_Functions_Not_Transformed=" << fixed << setprecision(1) << pct_not_transformed << "%" << endl;
// used in testing harness to verify that the stats are correct.
assert(getenv("SELF_VALIDATE")==nullptr || instructions_added > 10);
assert(getenv("SELF_VALIDATE")==nullptr || pct_transformed > 20); // can be kind of low for small files
assert(getenv("SELF_VALIDATE")==nullptr || functionsTransformed > 5 );
assert(getenv("SELF_VALIDATE")==nullptr || instructions_added > 10);
assert(getenv("SELF_VALIDATE")==nullptr || pct_transformed > 20); // can be kind of low for small files
assert(getenv("SELF_VALIDATE")==nullptr || functions_transformed > 5 );
return 1; // true means success
}
......
......@@ -131,9 +131,9 @@ namespace Stamper
map<EhProgramPlaceHolder_t, EhProgram_t*> all_eh_pgms;
// stats
int instructions_added = 0; // how many instructions were added
int functionsTransformed = 0; // how many functions were transformed
int functionsNotTransformed = 0; // how many functions were skipped
int instructions_added = 0; // how many instructions were added
int functions_transformed = 0; // how many functions were transformed
int functions_not_transformed = 0; // how many functions were skipped
// friends
friend bool operator<(const EhProgramPlaceHolder_t &a, const EhProgramPlaceHolder_t& b) ;
......
......@@ -25,6 +25,7 @@
using namespace std;
using namespace IRDB_SDK;
using namespace Stamper;
#define ALLOF(a) begin(a), end(a)
......@@ -112,7 +113,7 @@ class StackStampDriver_t : public IRDB_SDK::TransformStep_t
auto firp=getMainFileIR();
// execute a transform.
const auto success= Stamper::StackStamp_t(firp, stamp_value, verbose).execute();
const auto success= StackStamp_t(firp, stamp_value, verbose).execute();
// return success status
return success ? 0 : 2; // bash-style, 0=success, 1=warnings, 2=errors
......@@ -144,7 +145,7 @@ class StackStampDriver_t : public IRDB_SDK::TransformStep_t
// data
const string program_name = string("stack_stamp"); // this programs nam
bool verbose = false; // use verbose mode?
Stamper::StampValue_t stamp_value=-1; // how should we stamp?
StampValue_t stamp_value=-1; // how should we stamp?
// methods
......
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