Пример #1
0
Файл: ebc.cpp Проект: Ekleog/EBC
int main(int argc, char** argv) {
    if (argc < 2) return 1;
    std::string input_fn(argv[1]); std::ifstream input(input_fn.c_str());
    std::string base_fn(input_fn.substr(0, input_fn.size() - 3));
    std::string err; int ret;

    if (input_fn.rfind(".bf") != input_fn.size() - 3) return 2;

    llvm::Module * module = compile_ir(input);
    if (!module) return 3;
    llvm::raw_fd_ostream out_ll((base_fn + ".ll").c_str(), err);
    if (!err.empty()) return 4;
    module->print(out_ll, nullptr);

    std::printf(("Outputting to " + base_fn + ".s ...\n").c_str());
    ret = std::system(("llc -O3 " + base_fn + ".ll").c_str());
    if (ret) return 5;

    std::printf(("Outputting to " + base_fn + ".o ...\n").c_str());
    ret = std::system(("as " + base_fn + ".s -o " + base_fn + ".o").c_str());
    if (ret) return 6;

    std::printf(("Outputting to " + base_fn + ".exe ...\n").c_str());
    ret = std::system(("gcc -O3 " + base_fn + ".o -o " + base_fn + ".exe").c_str());
    if (ret) return 7;
}
Пример #2
0
/*
* Iterate the TLS state machine
*/
void TLS_Server::state_machine()
   {
   byte rec_type = CONNECTION_CLOSED;
   SecureVector<byte> record(1024);

   size_t bytes_needed = reader.get_record(rec_type, record);

   while(bytes_needed)
      {
      size_t to_get = std::min<size_t>(record.size(), bytes_needed);
      size_t got = input_fn(&record[0], to_get);

      if(got == 0)
         {
         rec_type = CONNECTION_CLOSED;
         break;
         }

      reader.add_input(&record[0], got);

      bytes_needed = reader.get_record(rec_type, record);
      }

   if(rec_type == CONNECTION_CLOSED)
      {
      active = false;
      reader.reset();
      writer.reset();
      }
   else if(rec_type == APPLICATION_DATA)
      {
      if(active)
         read_buf.write(&record[0], record.size());
      else
         throw Unexpected_Message("Application data before handshake done");
      }
   else if(rec_type == HANDSHAKE || rec_type == CHANGE_CIPHER_SPEC)
      read_handshake(rec_type, record);
   else if(rec_type == ALERT)
      {
      Alert alert(record);

      if(alert.is_fatal() || alert.type() == CLOSE_NOTIFY)
         {
         if(alert.type() == CLOSE_NOTIFY)
            writer.alert(WARNING, CLOSE_NOTIFY);

         reader.reset();
         writer.reset();
         active = false;
         }
      }
   else
      throw Unexpected_Message("Unknown message type received");
   }