From 8b3ce501d6cac286f3fbaf246d48596b001fda26 Mon Sep 17 00:00:00 2001 From: shubhamnarlawar77 Date: Wed, 12 Jun 2019 15:54:51 +0530 Subject: [PATCH] Added support for Section Function Attribute --- src/Attribute.cpp | 17 +++++++++++++++++ src/Attribute.h | 8 ++++++++ src/Function.cpp | 1 + 3 files changed, 26 insertions(+) diff --git a/src/Attribute.cpp b/src/Attribute.cpp index 342108b7b..0628b9e8d 100644 --- a/src/Attribute.cpp +++ b/src/Attribute.cpp @@ -80,3 +80,20 @@ AlignedAttribute::make_random() else return ""; } + +SectionAttribute::SectionAttribute(string name, int prob) + : Attribute(name, prob) +{ +} + +string +SectionAttribute::make_random() +{ + if(rnd_flipcoin(prob)){ + ostringstream oss; + oss << rnd_upto(10); + return name + "(\"usersection" + oss.str() + "\")"; + } + else + return ""; +} diff --git a/src/Attribute.h b/src/Attribute.h index 804c9a4bb..0b24c6049 100644 --- a/src/Attribute.h +++ b/src/Attribute.h @@ -49,6 +49,14 @@ class AlignedAttribute : public Attribute string make_random(); }; +//Generates usersections to put functions in different sections +class SectionAttribute : public Attribute +{ +public: + SectionAttribute(string, int); + string make_random(); +}; + //Generates function and types attributes class AttributeGenerator { diff --git a/src/Function.cpp b/src/Function.cpp index cb150f33f..d5a10423e 100644 --- a/src/Function.cpp +++ b/src/Function.cpp @@ -136,6 +136,7 @@ Function::InitializeAttributes() func_attr_generator.attributes.push_back(new MultiChoiceAttribute("visibility", FuncAttrProb, visibility_choices)); func_attr_generator.attributes.push_back(new MultiChoiceAttribute("no_sanitize", FuncAttrProb, sanitize_choices)); func_attr_generator.attributes.push_back(new AlignedAttribute("aligned", FuncAttrProb, 16)); + func_attr_generator.attributes.push_back(new SectionAttribute("section", FuncAttrProb)); } }