Browse Source

style fix

cl-refactor
Christoph Jentzsch 10 years ago
parent
commit
34c8cf9fd2
  1. 7
      libserpent/util.cpp
  2. 189
      sc/cmdline.cpp

7
libserpent/util.cpp

@ -6,7 +6,6 @@
#include "bignum.h" #include "bignum.h"
#include <fstream> #include <fstream>
#include <cerrno> #include <cerrno>
#include <libdevcore/Exceptions.h>
//Token or value node constructor //Token or value node constructor
Node token(std::string val, Metadata met) { Node token(std::string val, Metadata met) {
@ -212,7 +211,7 @@ std::string get_file_contents(std::string filename)
in.close(); in.close();
return(contents); return(contents);
} }
BOOST_THROW_EXCEPTION(dev::FileError() << boost::errinfo_file_name(filename) << boost::errinfo_errno(errno)); throw(errno);
} }
//Report error //Report error
@ -220,8 +219,8 @@ void err(std::string errtext, Metadata met) {
std::string err = "Error (file \"" + met.file + "\", line " + std::string err = "Error (file \"" + met.file + "\", line " +
unsignedToDecimal(met.ln + 1) + ", char " + unsignedToDecimal(met.ch) + unsignedToDecimal(met.ln + 1) + ", char " + unsignedToDecimal(met.ch) +
"): " + errtext; "): " + errtext;
std::cerr << err << "\n"; std::cerr << err << "\n";
BOOST_THROW_EXCEPTION(dev::Exception() << dev::errinfo_comment(err)); throw(err);
} }
//Bin to hex //Bin to hex

189
sc/cmdline.cpp

@ -7,103 +7,96 @@
#include <libserpent/funcs.h> #include <libserpent/funcs.h>
#include <libdevcore/Exceptions.h> #include <libdevcore/Exceptions.h>
int main(int argv, char** argc) { int main(int argv, char** argc)
if (argv == 1) { {
std::cerr << "Must provide a command and arguments! Try parse, rewrite, compile, assemble\n"; if (argv == 1)
return 0; {
} std::cerr << "Must provide a command and arguments! Try parse, rewrite, compile, assemble\n";
std::string flag = ""; return 0;
std::string command = argc[1]; }
std::string input; std::string flag = "";
std::string secondInput; std::string command = argc[1];
if (std::string(argc[1]) == "-s") { std::string input;
flag = command.substr(1); std::string secondInput;
command = argc[2]; if (std::string(argc[1]) == "-s")
input = ""; {
std::string line; flag = command.substr(1);
while (std::getline(std::cin, line)) { command = argc[2];
input += line + "\n"; input = "";
} std::string line;
secondInput = argv == 3 ? "" : argc[3]; while (std::getline(std::cin, line))
} {
else { input += line + "\n";
if (argv == 2) { }
std::cerr << "Not enough arguments for serpent cmdline\n"; secondInput = argv == 3 ? "" : argc[3];
}
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")); BOOST_THROW_EXCEPTION(dev::Exception() << dev::errinfo_comment("Not enough arguments for serpent cmdline"));
} }
input = argc[2]; input = argc[2];
secondInput = argv == 3 ? "" : argc[3]; secondInput = argv == 3 ? "" : argc[3];
} }
bool haveSec = secondInput.length() > 0; bool haveSec = secondInput.length() > 0;
if (command == "parse" || command == "parse_serpent") { if (command == "parse" || command == "parse_serpent")
std::cout << printAST(parseSerpent(input), haveSec) << "\n"; std::cout << printAST(parseSerpent(input), haveSec) << "\n";
} else if (command == "rewrite")
else if (command == "rewrite") { std::cout << printAST(rewrite(parseLLL(input, true)), haveSec) << "\n";
std::cout << printAST(rewrite(parseLLL(input, true)), haveSec) << "\n"; else if (command == "compile_to_lll")
} std::cout << printAST(compileToLLL(input), haveSec) << "\n";
else if (command == "compile_to_lll") { else if (command == "build_fragtree")
std::cout << printAST(compileToLLL(input), haveSec) << "\n"; std::cout << printAST(buildFragmentTree(parseLLL(input, true))) << "\n";
} else if (command == "compile_lll")
else if (command == "build_fragtree") { std::cout << binToHex(compileLLL(parseLLL(input, true))) << "\n";
std::cout << printAST(buildFragmentTree(parseLLL(input, true))) << "\n"; else if (command == "dereference")
} std::cout << printAST(dereference(parseLLL(input, true)), haveSec) <<"\n";
else if (command == "compile_lll") { else if (command == "pretty_assemble")
std::cout << binToHex(compileLLL(parseLLL(input, true))) << "\n"; std::cout << printTokens(prettyAssemble(parseLLL(input, true))) <<"\n";
} else if (command == "pretty_compile_lll")
else if (command == "dereference") { std::cout << printTokens(prettyCompileLLL(parseLLL(input, true))) << "\n";
std::cout << printAST(dereference(parseLLL(input, true)), haveSec) <<"\n"; else if (command == "pretty_compile")
} std::cout << printTokens(prettyCompile(input)) << "\n";
else if (command == "pretty_assemble") { else if (command == "assemble")
std::cout << printTokens(prettyAssemble(parseLLL(input, true))) <<"\n"; std::cout << assemble(parseLLL(input, true)) << "\n";
} else if (command == "serialize")
else if (command == "pretty_compile_lll") { std::cout << binToHex(serialize(tokenize(input, Metadata(), false))) << "\n";
std::cout << printTokens(prettyCompileLLL(parseLLL(input, true))) << "\n"; else if (command == "flatten")
} std::cout << printTokens(flatten(parseLLL(input, true))) << "\n";
else if (command == "pretty_compile") { else if (command == "deserialize")
std::cout << printTokens(prettyCompile(input)) << "\n"; std::cout << printTokens(deserialize(hexToBin(input))) << "\n";
} else if (command == "compile")
else if (command == "assemble") { std::cout << binToHex(compile(input)) << "\n";
std::cout << assemble(parseLLL(input, true)) << "\n"; else if (command == "encode_datalist")
} {
else if (command == "serialize") { std::vector<Node> tokens = tokenize(input);
std::cout << binToHex(serialize(tokenize(input, Metadata(), false))) << "\n"; std::vector<std::string> o;
} for (int i = 0; i < (int)tokens.size(); i++)
else if (command == "flatten") { o.push_back(tokens[i].val);
std::cout << printTokens(flatten(parseLLL(input, true))) << "\n"; std::cout << binToHex(encodeDatalist(o)) << "\n";
} }
else if (command == "deserialize") { else if (command == "decode_datalist")
std::cout << printTokens(deserialize(hexToBin(input))) << "\n"; {
} std::vector<std::string> o = decodeDatalist(hexToBin(input));
else if (command == "compile") { std::vector<Node> tokens;
std::cout << binToHex(compile(input)) << "\n"; for (int i = 0; i < (int)o.size(); i++)
} tokens.push_back(token(o[i]));
else if (command == "encode_datalist") { std::cout << printTokens(tokens) << "\n";
std::vector<Node> tokens = tokenize(input); }
std::vector<std::string> o; else if (command == "tokenize")
for (int i = 0; i < (int)tokens.size(); i++) { std::cout << printTokens(tokenize(input));
o.push_back(tokens[i].val); else if (command == "biject")
} {
std::cout << binToHex(encodeDatalist(o)) << "\n"; if (argv == 3)
} std::cerr << "Not enough arguments for biject\n";
else if (command == "decode_datalist") { int pos = decimalToUnsigned(secondInput);
std::vector<std::string> o = decodeDatalist(hexToBin(input)); std::vector<Node> n = prettyCompile(input);
std::vector<Node> tokens; if (pos >= (int)n.size())
for (int i = 0; i < (int)o.size(); i++) std::cerr << "Code position too high\n";
tokens.push_back(token(o[i])); Metadata m = n[pos].metadata;
std::cout << printTokens(tokens) << "\n"; std::cout << "Opcode: " << n[pos].val << ", file: " << m.file <<
} ", line: " << m.ln << ", char: " << m.ch << "\n";
else if (command == "tokenize") { }
std::cout << printTokens(tokenize(input));
}
else if (command == "biject") {
if (argv == 3)
std::cerr << "Not enough arguments for biject\n";
int pos = decimalToUnsigned(secondInput);
std::vector<Node> n = prettyCompile(input);
if (pos >= (int)n.size())
std::cerr << "Code position too high\n";
Metadata m = n[pos].metadata;
std::cout << "Opcode: " << n[pos].val << ", file: " << m.file <<
", line: " << m.ln << ", char: " << m.ch << "\n";
}
} }

Loading…
Cancel
Save