diff options
author | Christian <c@ethdev.com> | 2014-10-10 22:37:54 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2014-10-10 22:47:21 +0800 |
commit | 7ece4e4ed1b81f2c0410a7195efcde77842dcd31 (patch) | |
tree | ac63b82554866752e9f131ecff983182ca7c92f2 | |
download | dexon-solidity-7ece4e4ed1b81f2c0410a7195efcde77842dcd31.tar dexon-solidity-7ece4e4ed1b81f2c0410a7195efcde77842dcd31.tar.gz dexon-solidity-7ece4e4ed1b81f2c0410a7195efcde77842dcd31.tar.bz2 dexon-solidity-7ece4e4ed1b81f2c0410a7195efcde77842dcd31.tar.lz dexon-solidity-7ece4e4ed1b81f2c0410a7195efcde77842dcd31.tar.xz dexon-solidity-7ece4e4ed1b81f2c0410a7195efcde77842dcd31.tar.zst dexon-solidity-7ece4e4ed1b81f2c0410a7195efcde77842dcd31.zip |
AST printer and command line tool, some fixes.
-rw-r--r-- | CMakeLists.txt | 31 | ||||
-rw-r--r-- | main.cpp | 78 |
2 files changed, 109 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..9224c109 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_policy(SET CMP0015 NEW) + +aux_source_directory(. SRC_LIST) + +include_directories(..) + +set(EXECUTABLE solc) + +add_executable(${EXECUTABLE} ${SRC_LIST}) + +target_link_libraries(${EXECUTABLE} solidity) +target_link_libraries(${EXECUTABLE} devcore) + +if ("${TARGET_PLATFORM}" STREQUAL "w64") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") + target_link_libraries(${EXECUTABLE} gcc) + target_link_libraries(${EXECUTABLE} gdi32) + target_link_libraries(${EXECUTABLE} ws2_32) + target_link_libraries(${EXECUTABLE} mswsock) + target_link_libraries(${EXECUTABLE} shlwapi) + target_link_libraries(${EXECUTABLE} iphlpapi) + target_link_libraries(${EXECUTABLE} boost_thread_win32-mt-s) + set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS) +elseif (UNIX) +else () + find_package(Threads REQUIRED) + target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) +endif () + +install( TARGETS ${EXECUTABLE} DESTINATION bin ) + diff --git a/main.cpp b/main.cpp new file mode 100644 index 00000000..6fca11a6 --- /dev/null +++ b/main.cpp @@ -0,0 +1,78 @@ + +#include <string> +#include <iostream> + +#include <libdevcore/Common.h> +#include <libdevcore/CommonData.h> +#include <libdevcore/CommonIO.h> +#include <libsolidity/Scanner.h> +#include <libsolidity/Parser.h> +#include <libsolidity/ASTPrinter.h> + +namespace dev { +namespace solidity { + +ptr<ASTNode> parseAST(std::string const& _source) +{ + ptr<Scanner> scanner = std::make_shared<Scanner>(CharStream(_source)); + Parser parser; + return parser.parse(scanner); +} + +} } // end namespaces + +void help() +{ + std::cout + << "Usage solc [OPTIONS] <file>" << std::endl + << "Options:" << std::endl + << " -h,--help Show this help message and exit." << std::endl + << " -V,--version Show the version and exit." << std::endl; + exit(0); +} + +void version() +{ + std::cout + << "solc, the solidity complier commandline interface " << dev::Version << std::endl + << " by Christian <c@ethdev.com>, (c) 2014." << std::endl + << "Build: " << DEV_QUOTED(ETH_BUILD_PLATFORM) << "/" << DEV_QUOTED(ETH_BUILD_TYPE) << std::endl; + exit(0); +} + +int main(int argc, char** argv) +{ + std::string infile; + + for (int i = 1; i < argc; ++i) + { + std::string arg = argv[i]; + if (arg == "-h" || arg == "--help") + help(); + else if (arg == "-V" || arg == "--version") + version(); + else + infile = argv[i]; + } + + std::string src; + if (infile.empty()) + { + std::string s; + while (!std::cin.eof()) + { + getline(std::cin, s); + src.append(s); + } + } else { + src = dev::asString(dev::contents(infile)); + } + + std::cout << "Parsing..." << std::endl; + // @todo catch exception + dev::solidity::ptr<dev::solidity::ASTNode> ast = dev::solidity::parseAST(src); + std::cout << "Syntax tree for the contract:" << std::endl; + dev::solidity::ASTPrinter printer(ast, src); + printer.print(std::cout); + return 0; +} |