|
|
@ -3,14 +3,10 @@ |
|
|
|
#include <iostream> |
|
|
|
#include <vector> |
|
|
|
#include <map> |
|
|
|
#include <string> |
|
|
|
#include <libserpent/funcs.h> |
|
|
|
#include <libdevcore/Exceptions.h> |
|
|
|
|
|
|
|
int main(int argv, char** argc) |
|
|
|
{ |
|
|
|
if (argv == 1) |
|
|
|
{ |
|
|
|
int main(int argv, char** argc) { |
|
|
|
if (argv == 1) { |
|
|
|
std::cerr << "Must provide a command and arguments! Try parse, rewrite, compile, assemble\n"; |
|
|
|
return 0; |
|
|
|
} |
|
|
@ -18,77 +14,98 @@ int main(int argv, char** argc) |
|
|
|
std::string command = argc[1]; |
|
|
|
std::string input; |
|
|
|
std::string secondInput; |
|
|
|
if (std::string(argc[1]) == "-s") |
|
|
|
{ |
|
|
|
if (std::string(argc[1]) == "-s") { |
|
|
|
flag = command.substr(1); |
|
|
|
command = argc[2]; |
|
|
|
input = ""; |
|
|
|
std::string line; |
|
|
|
while (std::getline(std::cin, line)) |
|
|
|
{ |
|
|
|
while (std::getline(std::cin, line)) { |
|
|
|
input += line + "\n"; |
|
|
|
} |
|
|
|
secondInput = argv == 3 ? "" : argc[3]; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (argv == 2) |
|
|
|
{ |
|
|
|
else { |
|
|
|
if (argv == 2) { |
|
|
|
std::cerr << "Not enough arguments for serpent cmdline\n"; |
|
|
|
BOOST_THROW_EXCEPTION(dev::Exception() << dev::errinfo_comment("Not enough arguments for serpent cmdline")); |
|
|
|
throw(0); |
|
|
|
} |
|
|
|
input = argc[2]; |
|
|
|
secondInput = argv == 3 ? "" : argc[3]; |
|
|
|
} |
|
|
|
bool haveSec = secondInput.length() > 0; |
|
|
|
if (command == "parse" || command == "parse_serpent") |
|
|
|
if (command == "parse" || command == "parse_serpent") { |
|
|
|
std::cout << printAST(parseSerpent(input), haveSec) << "\n"; |
|
|
|
else if (command == "rewrite") |
|
|
|
} |
|
|
|
else if (command == "rewrite") { |
|
|
|
std::cout << printAST(rewrite(parseLLL(input, true)), haveSec) << "\n"; |
|
|
|
else if (command == "compile_to_lll") |
|
|
|
} |
|
|
|
else if (command == "compile_to_lll") { |
|
|
|
std::cout << printAST(compileToLLL(input), haveSec) << "\n"; |
|
|
|
else if (command == "build_fragtree") |
|
|
|
} |
|
|
|
else if (command == "rewrite_chunk") { |
|
|
|
std::cout << printAST(rewriteChunk(parseLLL(input, true)), haveSec) << "\n"; |
|
|
|
} |
|
|
|
else if (command == "compile_chunk_to_lll") { |
|
|
|
std::cout << printAST(compileChunkToLLL(input), haveSec) << "\n"; |
|
|
|
} |
|
|
|
else if (command == "build_fragtree") { |
|
|
|
std::cout << printAST(buildFragmentTree(parseLLL(input, true))) << "\n"; |
|
|
|
else if (command == "compile_lll") |
|
|
|
} |
|
|
|
else if (command == "compile_lll") { |
|
|
|
std::cout << binToHex(compileLLL(parseLLL(input, true))) << "\n"; |
|
|
|
else if (command == "dereference") |
|
|
|
} |
|
|
|
else if (command == "dereference") { |
|
|
|
std::cout << printAST(dereference(parseLLL(input, true)), haveSec) <<"\n"; |
|
|
|
else if (command == "pretty_assemble") |
|
|
|
} |
|
|
|
else if (command == "pretty_assemble") { |
|
|
|
std::cout << printTokens(prettyAssemble(parseLLL(input, true))) <<"\n"; |
|
|
|
else if (command == "pretty_compile_lll") |
|
|
|
} |
|
|
|
else if (command == "pretty_compile_lll") { |
|
|
|
std::cout << printTokens(prettyCompileLLL(parseLLL(input, true))) << "\n"; |
|
|
|
else if (command == "pretty_compile") |
|
|
|
} |
|
|
|
else if (command == "pretty_compile") { |
|
|
|
std::cout << printTokens(prettyCompile(input)) << "\n"; |
|
|
|
else if (command == "assemble") |
|
|
|
} |
|
|
|
else if (command == "pretty_compile_chunk") { |
|
|
|
std::cout << printTokens(prettyCompileChunk(input)) << "\n"; |
|
|
|
} |
|
|
|
else if (command == "assemble") { |
|
|
|
std::cout << assemble(parseLLL(input, true)) << "\n"; |
|
|
|
else if (command == "serialize") |
|
|
|
} |
|
|
|
else if (command == "serialize") { |
|
|
|
std::cout << binToHex(serialize(tokenize(input, Metadata(), false))) << "\n"; |
|
|
|
else if (command == "flatten") |
|
|
|
} |
|
|
|
else if (command == "flatten") { |
|
|
|
std::cout << printTokens(flatten(parseLLL(input, true))) << "\n"; |
|
|
|
else if (command == "deserialize") |
|
|
|
} |
|
|
|
else if (command == "deserialize") { |
|
|
|
std::cout << printTokens(deserialize(hexToBin(input))) << "\n"; |
|
|
|
else if (command == "compile") |
|
|
|
} |
|
|
|
else if (command == "compile") { |
|
|
|
std::cout << binToHex(compile(input)) << "\n"; |
|
|
|
else if (command == "encode_datalist") |
|
|
|
{ |
|
|
|
} |
|
|
|
else if (command == "compile_chunk") { |
|
|
|
std::cout << binToHex(compileChunk(input)) << "\n"; |
|
|
|
} |
|
|
|
else if (command == "encode_datalist") { |
|
|
|
std::vector<Node> tokens = tokenize(input); |
|
|
|
std::vector<std::string> o; |
|
|
|
for (int i = 0; i < (int)tokens.size(); i++) |
|
|
|
for (int i = 0; i < (int)tokens.size(); i++) { |
|
|
|
o.push_back(tokens[i].val); |
|
|
|
} |
|
|
|
std::cout << binToHex(encodeDatalist(o)) << "\n"; |
|
|
|
} |
|
|
|
else if (command == "decode_datalist") |
|
|
|
{ |
|
|
|
else if (command == "decode_datalist") { |
|
|
|
std::vector<std::string> o = decodeDatalist(hexToBin(input)); |
|
|
|
std::vector<Node> tokens; |
|
|
|
for (int i = 0; i < (int)o.size(); i++) |
|
|
|
tokens.push_back(token(o[i])); |
|
|
|
std::cout << printTokens(tokens) << "\n"; |
|
|
|
} |
|
|
|
else if (command == "tokenize") |
|
|
|
else if (command == "tokenize") { |
|
|
|
std::cout << printTokens(tokenize(input)); |
|
|
|
else if (command == "biject") |
|
|
|
{ |
|
|
|
} |
|
|
|
else if (command == "biject") { |
|
|
|
if (argv == 3) |
|
|
|
std::cerr << "Not enough arguments for biject\n"; |
|
|
|
int pos = decimalToUnsigned(secondInput); |
|
|
|