Files
carbon-lang/executable_semantics/main.cpp
T
pk19604014andJon Meow 22462a0d7f Carbon fuzzing 3/3: added actual fuzzer implementation and a fuzzverter utility for investigating crashing protos (#1156)
* finished fuzzer and added fuzzverter util

* fixed typo

* renamed cmd line params

* fixed libproto_mutator download path

* small fixes

* small fixes

* small fixes

* renamed sample corpus proto

* small fixes

* try building on github with LIBCPP_DEBUG enabled

* temporarily marked proto fuzzer as a manual test

* code review

* use a dedicated proto-fuzzer feature to work around LIBCPP_DEBUG=1 crash in proto code

* code review comments, added README.md

* minor fixes to the text

* Update bazel/cc_toolchains/clang_cc_toolchain_config.bzl

Co-authored-by: Jon Meow <jperkins@google.com>

* use Carbon source representation for "empty Main()" instead of text format proto representation

* fixed typo

* made FuzzerUtil produce the full carbon source (proto converted + Main if needed) to decrease code duplication a bit

* typo

* switched to text proto format per code review

* Update executable_semantics/prelude.h

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/fuzzing/README.md

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/fuzzing/README.md

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/fuzzing/README.md

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/fuzzing/README.md

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/fuzzing/README.md

Co-authored-by: Jon Meow <jperkins@google.com>

* review comments

* removed unnecessary file mode variables

* Update executable_semantics/fuzzing/fuzzverter.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/fuzzing/README.md

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/fuzzing/README.md

Co-authored-by: Jon Meow <jperkins@google.com>

* code review comments

* Update executable_semantics/syntax/BUILD

Co-authored-by: Jon Meow <jperkins@google.com>

* buildifier

Co-authored-by: Jon Meow <jperkins@google.com>
2022-04-11 16:47:03 -04:00

64 lines
2.1 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include <unistd.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include "common/error.h"
#include "executable_semantics/common/arena.h"
#include "executable_semantics/common/nonnull.h"
#include "executable_semantics/interpreter/exec_program.h"
#include "executable_semantics/syntax/parse.h"
#include "executable_semantics/syntax/prelude.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
// Prints an error message and returns error code value.
auto PrintError(const Carbon::Error& error) -> int {
llvm::errs() << error.message() << "\n";
return EXIT_FAILURE;
}
auto main(int argc, char* argv[]) -> int {
llvm::setBugReportMsg(
"Please report issues to "
"https://github.com/carbon-language/carbon-lang/issues and include the "
"crash backtrace.\n");
llvm::InitLLVM init_llvm(argc, argv);
// Printing to stderr should flush stdout. This is most noticeable when stderr
// is piped to stdout.
llvm::errs().tie(&llvm::outs());
using llvm::cl::desc;
using llvm::cl::opt;
opt<bool> trace_option("trace", desc("Enable tracing"));
opt<std::string> input_file_name(llvm::cl::Positional, desc("<input file>"),
llvm::cl::Required);
opt<std::string> prelude_file_name(
"prelude", desc("<prelude file>"),
llvm::cl::init("executable_semantics/data/prelude.carbon"));
llvm::cl::ParseCommandLineOptions(argc, argv);
Carbon::Arena arena;
Carbon::ErrorOr<Carbon::AST> ast =
Carbon::Parse(&arena, input_file_name, trace_option);
if (!ast.ok()) {
return PrintError(ast.error());
}
AddPrelude(prelude_file_name, &arena, &ast->declarations);
// Typecheck and run the parsed program.
Carbon::ErrorOr<int> result = Carbon::ExecProgram(&arena, *ast, trace_option);
if (!result.ok()) {
return PrintError(result.error());
}
}