Browse Source

Integrated sc and lllc

cl-refactor
Vitalik Buterin 11 years ago
parent
commit
db987c526a
  1. 1
      libserpent/CMakeLists.txt
  2. 11
      libserpent/example.cpp
  3. 19
      libserpent/funcs.cpp
  4. 6
      libserpent/funcs.h
  5. 11
      sc/cmdline.cpp

1
libserpent/CMakeLists.txt

@ -43,4 +43,5 @@ message("Installation path: ${CMAKE_INSTALL_PREFIX}")
install( TARGETS ${EXECUTABLE} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib )
install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} )
#install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libserpent.so DESTINATION lib )

11
libserpent/example.cpp

@ -1,11 +0,0 @@
#include <libserpent/funcs.h>
#include <libserpent/bignum.h>
#include <iostream>
using namespace std;
int main() {
cout << printAST(compileToLLL(get_file_contents("examples/namecoin.se"))) << "\n";
cout << decimalSub("10234", "10234") << "\n";
cout << decimalSub("10234", "10233") << "\n";
}

19
libserpent/funcs.cpp

@ -9,15 +9,28 @@
#include "compiler.h"
#include "rewriter.h"
#include "tokenize.h"
#include <liblll/Compiler.h>
#include <libethential/Common.h>
Node compileToLLL(std::string input) {
return rewrite(parseSerpent(input));
}
std::string compile(std::string input) {
return compileLLL(compileToLLL(input));
std::vector<uint8_t> compile(std::string input) {
return eth::compileLLL(printSimple(compileToLLL(input)));
}
std::vector<Node> prettyCompile(std::string input) {
return prettyCompileLLL(compileToLLL(input));
return deserialize(bytesToString(
eth::compileLLL(printSimple(compileToLLL(input)))));
}
std::string bytesToString(std::vector<uint8_t> input) {
std::string o;
for (unsigned i = 0; i < input.size(); i++) o += (char)input[i];
return o;
}
std::string bytesToHex(std::vector<uint8_t> input) {
return binToHex(bytesToString(input));
}

6
libserpent/funcs.h

@ -24,6 +24,10 @@
Node compileToLLL(std::string input);
std::string compile(std::string input);
std::vector<uint8_t> compile(std::string input);
std::vector<Node> prettyCompile(std::string input);
std::string bytesToString(std::vector<uint8_t> input);
std::string bytesToHex(std::vector<uint8_t> input);

11
sc/cmdline.cpp

@ -3,6 +3,8 @@
#include <vector>
#include <map>
#include <libserpent/funcs.h>
#include <liblll/Compiler.h>
#include <libethential/Common.h>
int main(int argv, char** argc) {
if (argv == 1) {
@ -45,7 +47,7 @@ int main(int argv, char** argc) {
std::cout << printAST(buildFragmentTree(parseLLL(input, true))) << "\n";
}
else if (command == "compile_lll") {
std::cout << binToHex(compileLLL(parseLLL(input, true))) << "\n";
std::cout << bytesToHex(eth::compileLLL(input)) << "\n";
}
else if (command == "dereference") {
std::cout << printAST(dereference(parseLLL(input, true)), haveSec) <<"\n";
@ -54,10 +56,11 @@ int main(int argv, char** argc) {
std::cout << printTokens(prettyAssemble(parseLLL(input, true))) <<"\n";
}
else if (command == "pretty_compile_lll") {
std::cout << printTokens(prettyCompileLLL(parseLLL(input, true))) << "\n";
std::cout << printTokens(deserialize(bytesToString(
eth::compileLLL(input)))) << "\n";
}
else if (command == "pretty_compile") {
std::cout << printTokens(prettyCompile(input)) << "\n";
std::cout << printTokens(deserialize(bytesToString(compile(input)))) << "\n";
}
else if (command == "assemble") {
std::cout << assemble(parseLLL(input, true)) << "\n";
@ -72,7 +75,7 @@ int main(int argv, char** argc) {
std::cout << printTokens(deserialize(hexToBin(input))) << "\n";
}
else if (command == "compile") {
std::cout << binToHex(compile(input)) << "\n";
std::cout << bytesToHex(compile(input)) << "\n";
}
else if (command == "encode_datalist") {
std::vector<Node> tokens = tokenize(input);

Loading…
Cancel
Save