diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..bd8c816a --- /dev/null +++ b/.clang-format @@ -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: '^' + 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 +... diff --git a/include/evm2wasm.h b/include/evm2wasm.h index f8a9cd28..84f33bf3 100644 --- a/include/evm2wasm.h +++ b/include/evm2wasm.h @@ -2,10 +2,10 @@ #include -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 diff --git a/libs/evm2wasm/evm2wasm.cpp b/libs/evm2wasm/evm2wasm.cpp index 1631dcb5..24fd8cde 100644 --- a/libs/evm2wasm/evm2wasm.cpp +++ b/libs/evm2wasm/evm2wasm.cpp @@ -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(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(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 diff --git a/tools/evm2wasm/main.cpp b/tools/evm2wasm/main.cpp index a5be4d5d..25b6065c 100644 --- a/tools/evm2wasm/main.cpp +++ b/tools/evm2wasm/main.cpp @@ -1,41 +1,46 @@ -#include -#include #include +#include #include +#include #include 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] << " [--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] << " [--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(input)), - std::istreambuf_iterator() - ); + string str((std::istreambuf_iterator(input)), std::istreambuf_iterator()); - if (wast) { + if (wast) + { cout << evm2wasm::evm2wast(str) << endl; - } else { + } + else + { cout << evm2wasm::evm2wasm(str) << endl; } diff --git a/tools/wast2wasm/main.cpp b/tools/wast2wasm/main.cpp index ef8bbb55..5d26c6d9 100644 --- a/tools/wast2wasm/main.cpp +++ b/tools/wast2wasm/main.cpp @@ -1,13 +1,14 @@ -#include -#include #include +#include #include +#include #include using namespace std; -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ (void)argc; (void)argv;