Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions toolchain/autoupdate_testdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def main() -> None:
args = parser.parse_args()

if args.non_fatal_checks:
if build_mode == "opt":
if build_mode == "optimize":
exit(
"`--non-fatal-checks` is incompatible with inferred "
"`-c opt` build mode"
"`-c optimize` build mode"
)
configs.append("--config=non-fatal-checks")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ auto foo(short a) -> void;
// CHECK:STDOUT: | |-ParmVarDecl {{0x[a-f0-9]+}} <<invalid sloc>> <invalid sloc> implicit 'std::align_val_t'
// CHECK:STDOUT: | `-VisibilityAttr {{0x[a-f0-9]+}} <<invalid sloc>> Implicit Default
// CHECK:STDOUT: |-FunctionDecl {{0x[a-f0-9]+}} <<carbon-internal>:8:1, line:14:1> line:8:7 operator new 'void *(unsigned long, void *) noexcept'
// CHECK:STDOUT: | |-ParmVarDecl {{0x[a-f0-9]+}} <<built-in>:173:23, col:37> <carbon-internal>:8:33 'unsigned long'
// CHECK:STDOUT: | |-ParmVarDecl {{0x[a-f0-9]+}} <<built-in>:174:23, col:37> <carbon-internal>:8:33 'unsigned long'
// CHECK:STDOUT: | `-ParmVarDecl {{0x[a-f0-9]+}} <col:35, col:39> col:40 'void *'
// CHECK:STDOUT: `-FunctionDecl {{0x[a-f0-9]+}} <./thunk_required.h:[[@LINE-51]]:6> col:6 foo__carbon_thunk 'void (short * _Nonnull)' extern
// CHECK:STDOUT: |-ParmVarDecl {{0x[a-f0-9]+}} <col:6> col:6 used a 'short * _Nonnull':'short *'
Expand Down
21 changes: 0 additions & 21 deletions toolchain/codegen/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,6 @@

namespace Carbon {

auto CodeGen::Make(llvm::Module* module, llvm::StringRef target_triple_str,
Diagnostics::Consumer* consumer) -> std::optional<CodeGen> {
llvm::Triple target_triple(target_triple_str);
std::string error;
const llvm::Target* target =
llvm::TargetRegistry::lookupTarget(target_triple, error);
CARBON_CHECK(target, "Target should be validated before codegen: {0}", error);

module->setTargetTriple(target_triple);

constexpr llvm::StringLiteral CPU = "generic";
constexpr llvm::StringLiteral Features = "";

llvm::TargetOptions target_opts;
CodeGen codegen(module,
consumer ? consumer : &Diagnostics::ConsoleConsumer());
codegen.target_machine_.reset(target->createTargetMachine(
target_triple, CPU, Features, target_opts, llvm::Reloc::PIC_));
return codegen;
}

auto CodeGen::EmitAssembly(llvm::raw_pwrite_stream& out) -> bool {
return EmitCode(out, llvm::CodeGenFileType::AssemblyFile);
}
Expand Down
17 changes: 6 additions & 11 deletions toolchain/codegen/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ namespace Carbon {

class CodeGen {
public:
// `module` and `errors` must not be null. `consumer` may be null, in which
// case diagnostics go to stderr.
static auto Make(llvm::Module* module, llvm::StringRef target_triple_str,
Diagnostics::Consumer* consumer = nullptr)
-> std::optional<CodeGen>;
// `module`, `target_machine`, and `consumer` must not be null.
explicit CodeGen(llvm::Module* module, llvm::TargetMachine* target_machine,
Diagnostics::Consumer* consumer)
: module_(module), target_machine_(target_machine), emitter_(consumer) {}

// Generates the object code file.
// Returns false in case of failure, and any information about the failure is
Expand All @@ -35,10 +34,6 @@ class CodeGen {
auto EmitAssembly(llvm::raw_pwrite_stream& out) -> bool;

private:
// `module` and `consumer` must not be null.
explicit CodeGen(llvm::Module* module, Diagnostics::Consumer* consumer)
: module_(module), emitter_(consumer) {}

// Using the llvm pass emits either assembly or object code to dest.
// Returns false in case of failure, and any information about the failure is
// printed to the error stream.
Expand All @@ -47,10 +42,10 @@ class CodeGen {

llvm::Module* module_;

llvm::TargetMachine* target_machine_;

// The emitter for diagnostics.
Diagnostics::FileEmitter emitter_;

std::unique_ptr<llvm::TargetMachine> target_machine_;
};

} // namespace Carbon
Expand Down
2 changes: 2 additions & 0 deletions toolchain/driver/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,15 @@ cc_library(
"//toolchain/language_server",
"//toolchain/lex",
"//toolchain/lower",
"//toolchain/lower:options",
"//toolchain/parse",
"//toolchain/parse:tree",
"//toolchain/sem_ir:file",
"//toolchain/sem_ir:typed_insts",
"//toolchain/source:source_buffer",
"@llvm-project//llvm:Core",
"@llvm-project//llvm:MC",
"@llvm-project//llvm:Passes",
"@llvm-project//llvm:Support",
"@llvm-project//llvm:TargetParser",
],
Expand Down
Loading
Loading