Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.

[WIP] Add .clang-format #292

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
Language: Cpp
# BasedOnStyle: Chromium
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
BreakBeforeTernaryOperators: false
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^".*'
Priority: 1
- Regex: '^<boost.*'
Priority: 98
- Regex: '^<.*\.h>'
Priority: 2
- Regex: '^<.*'
Priority: 99
- Regex: '.*'
Priority: 4
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 50
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 4
UseTab: Never
...
6 changes: 3 additions & 3 deletions include/evm2wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#include <string>

namespace evm2wasm {

namespace evm2wasm
{
std::string wast2wasm(const std::string& input, bool debug = false);
std::string evm2wast(const std::string& input, bool tracing = false);
std::string evm2wasm(const std::string& input, bool tracing = false);

}
} // namespace evm2wasm
98 changes: 56 additions & 42 deletions libs/evm2wasm/evm2wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,71 @@

using namespace std;

namespace evm2wasm {

string wast2wasm(const string& input, bool debug) {
wasm::Module module;

try {
if (debug) std::cerr << "s-parsing..." << std::endl;
// FIXME: binaryen 1.37.28 actually modifies the input...
// as a workaround make a copy here
string tmp = input;
wasm::SExpressionParser parser(const_cast<char*>(tmp.c_str()));
wasm::Element& root = *parser.root;
if (debug) std::cerr << "w-parsing..." << std::endl;
wasm::SExpressionWasmBuilder builder(module, *root[0]);
} catch (wasm::ParseException& p) {
if (debug) {
std::cerr << "error in parsing input" << std::endl;
p.dump(std::cerr);
namespace evm2wasm
{
string wast2wasm(const string& input, bool debug)
{
wasm::Module module;

try
{
if (debug)
std::cerr << "s-parsing..." << std::endl;
// FIXME: binaryen 1.37.28 actually modifies the input...
// as a workaround make a copy here
string tmp = input;
wasm::SExpressionParser parser(const_cast<char*>(tmp.c_str()));
wasm::Element& root = *parser.root;
if (debug)
std::cerr << "w-parsing..." << std::endl;
wasm::SExpressionWasmBuilder builder(module, *root[0]);
}
catch (wasm::ParseException& p)
{
if (debug)
{
std::cerr << "error in parsing input" << std::endl;
p.dump(std::cerr);
}
return string();
}
return string();
}

if (!wasm::WasmValidator().validate(module)) {
if (debug) std::cerr << "module is invalid" << std::endl;
return string();
}
if (!wasm::WasmValidator().validate(module))
{
if (debug)
std::cerr << "module is invalid" << std::endl;
return string();
}

if (debug) std::cerr << "binarification..." << std::endl;
wasm::BufferWithRandomAccess buffer(debug);
wasm::WasmBinaryWriter writer(&module, buffer, debug);
writer.write();
if (debug)
std::cerr << "binarification..." << std::endl;
wasm::BufferWithRandomAccess buffer(debug);
wasm::WasmBinaryWriter writer(&module, buffer, debug);
writer.write();

if (debug) std::cerr << "writing to output..." << std::endl;
if (debug)
std::cerr << "writing to output..." << std::endl;

ostringstream output;
buffer.writeTo(output);
ostringstream output;
buffer.writeTo(output);

if (debug) std::cerr << "Done." << std::endl;

return output.str();
}
if (debug)
std::cerr << "Done." << std::endl;

string evm2wast(const string& input, bool tracing) {
(void)input;
(void)tracing;
// FIXME: do evm magic here
return "(module (export \"main\" (func $main)) (func $main))";
return output.str();
}

string evm2wasm(const string& input, bool tracing) {
return wast2wasm(evm2wast(input, tracing));
string evm2wast(const string& input, bool tracing)
{
(void)input;
(void)tracing;
// FIXME: do evm magic here
return "(module (export \"main\" (func $main)) (func $main))";
}

string evm2wasm(const string& input, bool tracing)
{
return wast2wasm(evm2wast(input, tracing));
}

} // namespace evm2wasm
31 changes: 18 additions & 13 deletions tools/evm2wasm/main.cpp
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
#include <string>
#include <iostream>
#include <fstream>
#include <iostream>
#include <streambuf>
#include <string>

#include <evm2wasm.h>

using namespace std;

int main(int argc, char **argv) {
if (argc < 2) {
int main(int argc, char** argv)
{
if (argc < 2)
{
cerr << "Usage: " << argv[0] << " <EVM file> [--wast]" << endl;
return 1;
}

bool wast = false;
if (argc == 3) {
if (argc == 3)
{
wast = (string(argv[2]) == "--wast");
if (!wast) {
if (!wast)
{
cerr << "Usage: " << argv[0] << " <EVM file> [--wast]" << endl;
return 1;
}
}

ifstream input(argv[1]);
if (!input.is_open()) {
if (!input.is_open())
{
cerr << "File not found: " << argv[1] << endl;
return 1;
}

string str(
(std::istreambuf_iterator<char>(input)),
std::istreambuf_iterator<char>()
);
string str((std::istreambuf_iterator<char>(input)), std::istreambuf_iterator<char>());

if (wast) {
if (wast)
{
cout << evm2wasm::evm2wast(str) << endl;
} else {
}
else
{
cout << evm2wasm::evm2wasm(str) << endl;
}

Expand Down
7 changes: 4 additions & 3 deletions tools/wast2wasm/main.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include <string>
#include <iostream>
#include <fstream>
#include <iostream>
#include <streambuf>
#include <string>

#include <evm2wasm.h>

using namespace std;

int main(int argc, char **argv) {
int main(int argc, char** argv)
{
(void)argc;
(void)argv;

Expand Down