Skip to content

Commit

Permalink
Merge pull request #52 from philippegorley/master
Browse files Browse the repository at this point in the history
Header ordering and warnings
  • Loading branch information
philippegorley authored Mar 3, 2018
2 parents f2e2a7c + db7ce8e commit 9335dde
Show file tree
Hide file tree
Showing 30 changed files with 71 additions and 86 deletions.
1 change: 0 additions & 1 deletion fcd/ast/ast_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,6 @@ const ExpressionType& AstContext::getType(Type &type)
structType = &createStructure(move(name));
for (unsigned i = 0; i < structure->getNumElements(); ++i)
{
string name;
if (module != nullptr)
{
name = md::getRecoveredReturnFieldName(*module, *structure, i).str();
Expand Down
5 changes: 2 additions & 3 deletions fcd/ast/expression_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#ifndef expression_type_hpp
#define expression_type_hpp


#include <llvm/ADT/StringRef.h>
#include <llvm/Support/raw_ostream.h>

Expand Down Expand Up @@ -162,9 +161,9 @@ class StructExpressionType : public ExpressionType
const ExpressionTypeField& operator[](size_t index) const { return fields[index]; }
size_t size() const { return fields.size(); }

void append(const ExpressionType& type, std::string name)
void append(const ExpressionType& type, std::string fieldName)
{
fields.emplace_back(type, std::move(name));
fields.emplace_back(type, std::move(fieldName));
}

virtual void print(llvm::raw_ostream& os) const override;
Expand Down
1 change: 0 additions & 1 deletion fcd/ast/expression_use.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#ifndef use_list_hpp
#define use_list_hpp


#include <llvm/ADT/iterator_range.h>
#include <llvm/ADT/PointerIntPair.h>
#include <llvm/Support/raw_ostream.h>
Expand Down
6 changes: 3 additions & 3 deletions fcd/ast/expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include "ast_context.h"
#include "expressions.h"
#include "function.h"
#include "statements.h"
#include "print.h"
#include "statements.h"

#include <llvm/Support/raw_os_ostream.h>

Expand Down Expand Up @@ -284,9 +284,9 @@ TokenExpression::TokenExpression(AstContext& ctx, unsigned uses, const Expressio

bool TokenExpression::operator==(const Expression& that) const
{
if (auto token = llvm::dyn_cast<TokenExpression>(&that))
if (auto tokenExpr = llvm::dyn_cast<TokenExpression>(&that))
{
return strcmp(this->token, token->token) == 0;
return strcmp(this->token, tokenExpr->token) == 0;
}
return false;
}
Expand Down
10 changes: 5 additions & 5 deletions fcd/ast/pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ void AstModulePass::run(deque<unique_ptr<FunctionNode>>& fn)

void AstFunctionPass::doRun(deque<unique_ptr<FunctionNode>>& list)
{
for (unique_ptr<FunctionNode>& fn : list)
for (unique_ptr<FunctionNode>& funcNode : list)
{
if (runOnDeclarations || fn->hasBody())
if (runOnDeclarations || funcNode->hasBody())
{
PrettyStackTraceFormat runPass("Running AST pass \"%s\" on function \"%s\"", getName(), string(fn->getFunction().getName()).c_str());
PrettyStackTraceFormat runPass("Running AST pass \"%s\" on function \"%s\"", getName(), string(funcNode->getFunction().getName()).c_str());

this->fn = fn.get();
doRun(*fn);
this->fn = funcNode.get();
doRun(*funcNode);
}
}
}
2 changes: 1 addition & 1 deletion fcd/ast/pass_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
//

#include "metadata.h"
#include "passes.h"
#include "pass_backend.h"
#include "passes.h"
#include "pre_ast_cfg.h"

#include <llvm/ADT/PostOrderIterator.h>
Expand Down
6 changes: 3 additions & 3 deletions fcd/ast/pre_ast_cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ PreAstBasicBlock& PreAstBasicBlock::operator=(PreAstBasicBlock&& that)
return *this;
}

void PreAstBasicBlock::swap(PreAstBasicBlock& block)
void PreAstBasicBlock::swap(PreAstBasicBlock& other)
{
auto temporary = move(*this);
*this = move(block);
block = move(temporary);
*this = move(other);
other = move(temporary);
}

void PreAstBasicBlock::printAsOperand(llvm::raw_ostream& os, bool printType)
Expand Down
2 changes: 1 addition & 1 deletion fcd/ast/pre_ast_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

#include <llvm/ADT/ArrayRef.h>
#include <llvm/ADT/SmallVector.h>
#include <llvm/IR/Function.h>
#include <llvm/Analysis/DominanceFrontier.h>
#include <llvm/Analysis/LoopInfo.h>
#include <llvm/IR/BasicBlock.h>
#include <llvm/IR/Dominators.h>
#include <llvm/IR/Function.h>
#include <llvm/Support/GenericDomTree.h>
#include <llvm/Support/GenericDomTreeConstruction.h>

Expand Down
18 changes: 4 additions & 14 deletions fcd/ast/print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,29 +490,19 @@ void StatementPrintVisitor::visitCall(const CallExpression& call)
outSS << '(';
auto iter = call.params_begin();
auto end = call.params_end();
if (iter != end)
string separator = "";
for (; iter != end; ++iter)
{
outSS << separator;
const string& paramName = funcType[paramIndex].name;
if (paramName != "")
{
outSS << paramName << '=';
paramIndex++;
}

visit(*iter->getUse());
outSS << take(os);
for (++iter; iter != end; ++iter)
{
outSS << ", ";
const string& paramName = funcType[paramIndex].name;
if (paramName != "")
{
outSS << paramName << '=';
paramIndex++;
}
visit(*iter->getUse());
outSS << take(os);
}
separator = ", ";
}
outSS << ')';
swap(outSS.str(), os.str());
Expand Down
4 changes: 2 additions & 2 deletions fcd/ast/statements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
// license. See LICENSE.md for details.
//

#include "statements.h"
#include "function.h"
#include "visitor.h"
#include "print.h"
#include "statements.h"
#include "visitor.h"

#include <llvm/Support/raw_os_ostream.h>

Expand Down
3 changes: 2 additions & 1 deletion fcd/ast/statements.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
#ifndef fcd__ast_statements_h
#define fcd__ast_statements_h

#include <iterator>
#include "expression_use.h"
#include "expressions.h"
#include "not_null.h"

#include <iterator>

class Statement;

class StatementList
Expand Down
2 changes: 1 addition & 1 deletion fcd/callconv/cc_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#ifndef fcd__callconv_cc_common_h
#define fcd__callconv_cc_common_h

#include "targetinfo.h"
#include "params_registry.h"
#include "targetinfo.h"

#include <llvm/IR/Function.h>

Expand Down
15 changes: 9 additions & 6 deletions fcd/callconv/params_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ namespace
bool old;
bool& value;

TemporaryTrue(bool& value)
: value(value)
TemporaryTrue(bool& val)
: value(val)
{
old = value;
old = val;
value = true;
}

Expand Down Expand Up @@ -194,7 +194,8 @@ CallInformation* ParameterRegistry::analyzeFunction(Function& fn)
{
for (CallingConvention* cc : ccChain)
{
PrettyStackTraceFormat analyzing("Analyzing function \"%s\" with calling convention \"%s\"", string(fn.getName()).c_str(), cc->getName());
PrettyStackTraceFormat analyzingFunction("Analyzing function \"%s\" with calling convention \"%s\"",
string(fn.getName()).c_str(), cc->getName());

info.setStage(CallInformation::Analyzing);
if (cc->analyzeFunction(*this, info, fn))
Expand Down Expand Up @@ -280,7 +281,8 @@ const CallInformation* ParameterRegistry::getDefinitionCallInfo(Function& functi
raw_string_ostream functionTypeStream(functionType);
function.getFunctionType()->print(functionTypeStream);
functionTypeStream.flush();
PrettyStackTraceFormat analyzing("Analyzing function type \"%s\" with calling convention \"%s\"", functionType.c_str(), cc->getName());
PrettyStackTraceFormat analyzingFunction("Analyzing function type \"%s\" with calling convention \"%s\"",
functionType.c_str(), cc->getName());

if (cc->analyzeFunctionType(*this, info, *function.getFunctionType()))
{
Expand Down Expand Up @@ -312,7 +314,8 @@ unique_ptr<CallInformation> ParameterRegistry::analyzeCallSite(CallSite callSite
calleeName = "(not a function)";
}
string callerName = callSite->getFunction()->getName();
PrettyStackTraceFormat analyzing("Analyzing call site for \"%s\" in \"%s\" with calling convention \"%s\"", calleeName.c_str(), callerName.c_str(), cc->getName());
PrettyStackTraceFormat analyzingFunction("Analyzing call site for \"%s\" in \"%s\" with calling convention \"%s\"",
calleeName.c_str(), callerName.c_str(), cc->getName());

info->setStage(CallInformation::Analyzing);
if (cc->analyzeCallSite(*this, *info, callSite))
Expand Down
12 changes: 6 additions & 6 deletions fcd/callconv/x86_64_systemv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ bool CallingConvention_x86_64_systemv::analyzeFunction(ParameterRegistry &regist

// Look at temporary registers that are read before they are written
MemorySSA& mssa = *registry.getMemorySSA(function);
for (const char* name : parameterRegisters)
for (const char* regName : parameterRegisters)
{
const TargetRegisterInfo* smallReg = targetInfo.registerNamed(name);
const TargetRegisterInfo* smallReg = targetInfo.registerNamed(regName);
const TargetRegisterInfo& regInfo = targetInfo.largestOverlappingRegister(*smallReg);
auto range = geps.equal_range(&regInfo);

Expand Down Expand Up @@ -336,10 +336,10 @@ bool CallingConvention_x86_64_systemv::analyzeFunction(ParameterRegistry &regist
if (auto load = dyn_cast<LoadInst>(use.getUser()))
{
// Find uses above +8 (since +0 is the return address)
for (auto& use : load->uses())
for (auto& loadUse : load->uses())
{
ConstantInt* offset = nullptr;
if (match(use.get(), m_Add(m_Value(), m_ConstantInt(offset))))
if (match(loadUse.get(), m_Add(m_Value(), m_ConstantInt(offset))))
{
auto intOffset = static_cast<int64_t>(offset->getLimitedValue());
if (intOffset > 8)
Expand All @@ -357,9 +357,9 @@ bool CallingConvention_x86_64_systemv::analyzeFunction(ParameterRegistry &regist
vector<const TargetRegisterInfo*> usedReturns;
usedReturns.reserve(2);

for (const char* name : returnRegisters)
for (const char* regName : returnRegisters)
{
const TargetRegisterInfo* regInfo = targetInfo.registerNamed(name);
const TargetRegisterInfo* regInfo = targetInfo.registerNamed(regName);
auto range = geps.equal_range(regInfo);
for (auto iter = range.first; iter != range.second; ++iter)
{
Expand Down
3 changes: 2 additions & 1 deletion fcd/capstone_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
// license. See LICENSE.md for details.
//

#include "capstone_wrapper.h"

#include <string>
#include <system_error>
#include "capstone_wrapper.h"

using namespace llvm;
using namespace std;
Expand Down
1 change: 0 additions & 1 deletion fcd/capstone_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#ifndef fcd__capstone_wrapper_h
#define fcd__capstone_wrapper_h


#include <llvm/Support/ErrorOr.h>

#include <capstone/capstone.h>
Expand Down
6 changes: 3 additions & 3 deletions fcd/codegen/code_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ namespace
ConstantInt::get(int32Ty, cs.operands[i].mem.base),
ConstantInt::get(int32Ty, cs.operands[i].mem.index),
ConstantInt::get(int32Ty, static_cast<unsigned>(cs.operands[i].mem.scale)),
ConstantInt::get(int64Ty, cs.operands[i].mem.disp),
ConstantInt::get(int64Ty, static_cast<uint64_t>(cs.operands[i].mem.disp)),
};
Constant* opMem = ConstantStruct::get(x86OpMem, structFields);
Constant* wrapper = ConstantStruct::get(x86OpMemWrapper, opMem, nullptr);
Expand All @@ -267,9 +267,9 @@ namespace
ConstantInt::get(int8Ty, cs.addr_size),
ConstantInt::get(int8Ty, cs.modrm),
ConstantInt::get(int8Ty, cs.sib),
ConstantInt::get(int32Ty, cs.disp),
ConstantInt::get(int32Ty, static_cast<uint32_t>(cs.disp)),
ConstantInt::get(int32Ty, cs.sib_index),
ConstantInt::get(int8Ty, cs.sib_scale),
ConstantInt::get(int8Ty, static_cast<uint8_t>(cs.sib_scale)),
ConstantInt::get(int32Ty, cs.sib_base),
ConstantInt::get(int32Ty, cs.sse_cc),
ConstantInt::get(int32Ty, cs.avx_cc),
Expand Down
1 change: 0 additions & 1 deletion fcd/codegen/translation_maps.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#ifndef translation_maps_h
#define translation_maps_h


#include <llvm/IR/BasicBlock.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/Module.h>
Expand Down
1 change: 0 additions & 1 deletion fcd/command_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#ifndef fcd__command_line_h
#define fcd__command_line_h


#include <llvm/Support/CommandLine.h>

struct whitelist
Expand Down
4 changes: 2 additions & 2 deletions fcd/cpu/x86_register_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ namespace
}
}

inline void regInfo(size_t size, size_t offset, const string& name, x86_reg registerId)
inline void regInfo(size_t size, size_t off, const string& name, x86_reg registerId)
{
if (registerId != X86_REG_INVALID)
{
TargetRegisterInfo result = { offset, offset - this->offset, size, {fieldOffset, 0}, name, registerId };
TargetRegisterInfo result = { off, off - this->offset, size, {fieldOffset, 0}, name, registerId };
info.push_back(result);
}
}
Expand Down
3 changes: 1 addition & 2 deletions fcd/dumb_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
#ifndef fcd__dumb_allocator_h
#define fcd__dumb_allocator_h


#include <llvm/ADT/StringRef.h>

#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstring>
#include <iterator>
#include <list>
#include <memory>
#include <cstring>
#include <type_traits>

#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion fcd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "main.h"
#include "metadata.h"
#include "passes.h"
#include "python_context.h"
#include "params_registry.h"
#include "python_context.h"
#include "translation_context.h"

#include <llvm/Analysis/AliasAnalysis.h>
Expand Down
4 changes: 2 additions & 2 deletions fcd/metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ bool md::isPrototype(const Function &fn)
const BasicBlock& entry = fn.getEntryBlock();
if (entry.getInstList().size() == 2)
if (const CallInst* call = dyn_cast<CallInst>(entry.begin()))
if (Function* fn = call->getCalledFunction())
if (Function* func = call->getCalledFunction())
{
return fn->getName().startswith("fcd.placeholder");
return func->getName().startswith("fcd.placeholder");
}
}

Expand Down
2 changes: 1 addition & 1 deletion fcd/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include "params_registry.h"

#include <llvm/IR/Constants.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/Metadata.h>

#include <string>
Expand Down
1 change: 0 additions & 1 deletion fcd/not_null.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#ifndef fcd__not_null_h
#define fcd__not_null_h


#include <llvm/Support/Casting.h>

#ifdef FCD_DEBUG
Expand Down
Loading

0 comments on commit 9335dde

Please sign in to comment.