Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ragusaa committed Jan 10, 2024
1 parent 5698a79 commit 6ce19b2
Show file tree
Hide file tree
Showing 31 changed files with 1,192 additions and 1,332 deletions.
39 changes: 34 additions & 5 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Left
AlignOperands: true
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
Expand All @@ -21,12 +23,14 @@ AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: true
AfterNamespace: true
Expand All @@ -36,11 +40,14 @@ BraceWrapping:
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Linux
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
Expand All @@ -59,30 +66,40 @@ Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: true
DisableFormat: false
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
StatementAttributeLikeMacros:
- Q_EMIT
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: true
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
Expand All @@ -92,6 +109,7 @@ MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
Expand All @@ -102,18 +120,22 @@ PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PenaltyIndentedWhitespace: 0
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
Expand All @@ -125,12 +147,19 @@ SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...

7 changes: 4 additions & 3 deletions clam-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

clang-format -style='{ Language: Cpp, UseTab: Never, IndentWidth: 4, AlignTrailingComments: true, AlignConsecutiveAssignments: true, AlignAfterOpenBracket: true, AlignEscapedNewlines: Left, AlignOperands: true, AllowShortFunctionsOnASingleLine: Empty, AllowShortIfStatementsOnASingleLine: true, AllowShortLoopsOnASingleLine: true, BreakBeforeBraces: Linux, BreakBeforeTernaryOperators: true, ColumnLimit: 0, FixNamespaceComments: true, SortIncludes: false, MaxEmptyLinesToKeep: 1, SpaceBeforeParens: ControlStatements, IndentCaseLabels: true, DerivePointerAlignment: true }' -dump-config > .clang-format
clang-format-12 -style='{ Language: Cpp, UseTab: Never, IndentWidth: 4, AlignTrailingComments: true, AlignConsecutiveAssignments: true, AlignAfterOpenBracket: true, AlignEscapedNewlines: Left, AlignOperands: true, AllowShortFunctionsOnASingleLine: Empty, AllowShortIfStatementsOnASingleLine: true, AllowShortLoopsOnASingleLine: true, BreakBeforeBraces: Linux, BreakBeforeTernaryOperators: true, ColumnLimit: 0, FixNamespaceComments: true, SortIncludes: false, MaxEmptyLinesToKeep: 1, SpaceBeforeParens: ControlStatements, IndentCaseLabels: true, DerivePointerAlignment: true }' -dump-config > .clang-format

clang-format -i -verbose libclambcc/*/*.cpp
clang-format -i -verbose libclambcc/*/*.h
clang-format-12 -i -verbose `find libclambcc -name "*.cpp"`
clang-format-12 -i -verbose `find libclambcc -name "*.h"`
clang-format-12 -i -verbose `find libclambcc -name "*.c"`
41 changes: 19 additions & 22 deletions libclambcc/ClamBCAnalyzer/ClamBCAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static bool compare_lt_functions(Function *A, Function *B)
return NA.compare(NB) < 0;
}

void ClamBCAnalysis::run(Module & m)
void ClamBCAnalysis::run(Module &m)
{
pMod = &m;

Expand Down Expand Up @@ -158,7 +158,7 @@ void ClamBCAnalysis::run(Module & m)
indices.push_back(CE->getOperand(i));
}
Type *IP8Ty = PointerType::getUnqual(Type::getInt8Ty(CE->getContext()));
Type * type = getResultType(CE);
Type *type = getResultType(CE);

uint64_t idx = dataLayout.getIndexedOffsetInType(type, indices);

Expand All @@ -184,7 +184,7 @@ void ClamBCAnalysis::run(Module & m)

// Collect types of all globals.
const Type *Ty = I->getType();
Ty = I->getValueType();
Ty = I->getValueType();
if (!typeIDs.count(Ty)) {
extraTypes.push_back(Ty);
typeIDs[Ty] = tid++;
Expand All @@ -200,7 +200,7 @@ void ClamBCAnalysis::run(Module & m)
functions.push_back(F);
}

for (size_t i = 0; i < functions.size(); i++){
for (size_t i = 0; i < functions.size(); i++) {
functions[i]->removeFromParent();
}

Expand Down Expand Up @@ -292,13 +292,13 @@ void ClamBCAnalysis::run(Module & m)
}
}

for (size_t i = 0; i < II->getNumOperands(); i++){
Value * operand = II->getOperand(i);
if (llvm::isa<BasicBlock>(operand)){
for (size_t i = 0; i < II->getNumOperands(); i++) {
Value *operand = II->getOperand(i);
if (llvm::isa<BasicBlock>(operand)) {
continue;
}
Type * pt = operand->getType();
if (0 == typeIDs.count(pt)){
Type *pt = operand->getType();
if (0 == typeIDs.count(pt)) {
types.push_back(pt);
extraTypes.push_back(pt);
typeIDs[pt] = tid++;
Expand Down Expand Up @@ -599,17 +599,14 @@ void ClamBCAnalysis::populateAPIMap()

// This part is the new way of registering your pass
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
llvmGetPassPluginInfo() {
return {
LLVM_PLUGIN_API_VERSION, "ClamBCAnalysis", "v0.1",
[](PassBuilder &PB) {
PB.registerAnalysisRegistrationCallback(
[](ModuleAnalysisManager &mam) {
mam.registerPass([] () { return ClamBCAnalyzer(); } );
}
);
}
};
llvmGetPassPluginInfo()
{
return {
LLVM_PLUGIN_API_VERSION, "ClamBCAnalysis", "v0.1",
[](PassBuilder &PB) {
PB.registerAnalysisRegistrationCallback(
[](ModuleAnalysisManager &mam) {
mam.registerPass([]() { return ClamBCAnalyzer(); });
});
}};
}


41 changes: 22 additions & 19 deletions libclambcc/ClamBCAnalyzer/ClamBCAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
//6. Evaluate the TODO in runOnModule.

//class ClamBCAnalyzer : public llvm::PassInfoMixin<ClamBCAnalyzer> //llvm::ModulePass
class ClamBCAnalysis
class ClamBCAnalysis
{
protected:
typedef llvm::DenseMap<const llvm::Type *, unsigned> TypeMapTy;
Expand Down Expand Up @@ -83,7 +83,7 @@ class ClamBCAnalysis
std::vector<llvm::Constant *> globalInits;
std::vector<const llvm::MDNode *> mds;
bool WriteDI = false;

virtual void printGlobals(uint16_t stid);

/* TODO
Expand All @@ -110,7 +110,7 @@ class ClamBCAnalysis
public:
static char ID;
explicit ClamBCAnalysis()
//: ModulePass(ID)
//: ModulePass(ID)
{

populateAPIMap();
Expand All @@ -124,23 +124,24 @@ class ClamBCAnalysis
globalsMap["__clambc_match_offsets"] = GLOBAL_MATCH_OFFSETS;
}

virtual uint32_t getHighestTID(){
virtual uint32_t getHighestTID()
{
uint32_t ret = 0;
for (auto i = typeIDs.begin(), e = typeIDs.end(); i != e; i++) {
if (i->second > ret){
if (i->second > ret) {
ret = i->second;
}
}
return ret;
}

~ClamBCAnalysis() {}
virtual void run(llvm::Module & m);
virtual void run(llvm::Module &m);

virtual uint32_t getTypeID(const llvm::Type *const t)
{
TypeMapTy::iterator I = typeIDs.find(t);
if (I == typeIDs.end()){
if (I == typeIDs.end()) {
DEBUG_NONPOINTER("BAD VALUE");
DEBUG_VALUE(t);
}
Expand Down Expand Up @@ -267,23 +268,25 @@ class ClamBCAnalysis

class ClamBCAnalyzer : public llvm::AnalysisInfoMixin<ClamBCAnalyzer>
{
protected:
ClamBCAnalysis clamBCAnalysis;
protected:
ClamBCAnalysis clamBCAnalysis;

public:
friend llvm::AnalysisInfoMixin<ClamBCAnalyzer> ;
static llvm::AnalysisKey Key;
public:
friend llvm::AnalysisInfoMixin<ClamBCAnalyzer>;
static llvm::AnalysisKey Key;

ClamBCAnalyzer() : clamBCAnalysis() {}
virtual ~ClamBCAnalyzer(){}
ClamBCAnalyzer()
: clamBCAnalysis() {}
virtual ~ClamBCAnalyzer() {}

typedef ClamBCAnalysis Result;
typedef ClamBCAnalysis Result;

ClamBCAnalysis & run(llvm::Module & mod, llvm::ModuleAnalysisManager & mam) {
clamBCAnalysis.run(mod);
ClamBCAnalysis &run(llvm::Module &mod, llvm::ModuleAnalysisManager &mam)
{
clamBCAnalysis.run(mod);

return clamBCAnalysis;
}
return clamBCAnalysis;
}
};

#endif //CLAMBC_ANALYZER_H_
Loading

0 comments on commit 6ce19b2

Please sign in to comment.