mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 13:41:06 +01:00
Creates object file from the module. (#2955)
This pr creates the object file for the carbon code that returns either 0 or 1. The command to convert the object code to binary is `clang <object_file_name> -o <binary_name>` --------- Co-authored-by: Farzana Ahmed Siddique <fasiddique@google.com> Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Farzana Ahmed Siddique
Richard Smith
parent
123662f5b1
commit
037196f69f
@@ -8,15 +8,49 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
|
||||
namespace Carbon {
|
||||
// Prints the assembly to stdout for the given llvm module.
|
||||
// If print fails, this returns false and any information about the failure is
|
||||
// printed to the error stream.
|
||||
auto PrintAssemblyFromModule(llvm::Module& module,
|
||||
llvm::StringRef target_triple,
|
||||
llvm::raw_pwrite_stream& error_stream,
|
||||
llvm::raw_pwrite_stream& output_stream) -> bool;
|
||||
|
||||
class CodeGen {
|
||||
public:
|
||||
CodeGen(llvm::Module& module, llvm::StringRef triple,
|
||||
llvm::raw_pwrite_stream& error_stream,
|
||||
llvm::raw_pwrite_stream& output_stream)
|
||||
: Module(module),
|
||||
output_stream_(output_stream),
|
||||
error_stream_(error_stream),
|
||||
target_triple(triple){};
|
||||
|
||||
// Generates the object code file.
|
||||
// Returns false in case of failure, and any information about the failure is
|
||||
// printed to the error stream.
|
||||
auto GenerateObjectCode() -> bool;
|
||||
|
||||
// Prints the assembly to stdout.
|
||||
// Returns false in case of failure, and any information about the failure is
|
||||
// printed to the error stream.
|
||||
auto PrintAssembly() -> bool;
|
||||
|
||||
private:
|
||||
llvm::Module& Module;
|
||||
llvm::raw_pwrite_stream& output_stream_;
|
||||
llvm::raw_pwrite_stream& error_stream_;
|
||||
llvm::StringRef target_triple;
|
||||
|
||||
// Creates the target machine for triple.
|
||||
// Returns nullptr in case of failure, and any information about the failure
|
||||
// is printed to the error stream.
|
||||
auto CreateTargetMachine() -> std::unique_ptr<llvm::TargetMachine>;
|
||||
|
||||
// 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.
|
||||
auto EmitCode(llvm::raw_pwrite_stream& dest,
|
||||
llvm::TargetMachine* target_machine,
|
||||
llvm::CodeGenFileType file_type) -> bool;
|
||||
};
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
#endif // CARBON_TOOLCHAIN_CODEGEN_CODEGEN_H_
|
||||
|
||||
Reference in New Issue
Block a user