Class: Benchcc::Compiler
- Inherits:
-
Object
- Object
- Benchcc::Compiler
- Defined in:
- lib/benchcc/compiler.rb,
lib/benchcc/compiler.rb
Overview
Basic interface to compiler frontends.
Class Method Summary collapse
Instance Method Summary collapse
-
#compile_code(code, *args) ⇒ Object
compile_code: String -> CompilationResult.
-
#compile_file(file, *args) ⇒ Object
compile_file: Path -> CompilationResult.
-
#constexpr_depth ⇒ Object
Maximum constexpr recursion depth supported by the compiler.
-
#template_depth ⇒ Object
Maximum template recursion depth supported by the compiler.
-
#to_s ⇒ Object
Show the name and the version of the compiler.
Class Method Details
.guess_from_binary(binary) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/benchcc/compiler.rb', line 149 def self.guess_from_binary(binary) stdout, stderr, status = Open3.capture3("#{binary} --version") case stdout when /\(GCC\)/ return GCC.new(binary) when /clang/ return Clang.new(binary) else raise ArgumentError("unknown compiler #{binary}") end end |
Instance Method Details
#compile_code(code, *args) ⇒ Object
compile_code: String -> CompilationResult
Compile the given string and return compilation statistics.
This method has the same behavior as compile_file, except the code is given as-is instead of being in a file. Either this method or compile_file must be implemented in subclasses.
84 85 86 87 88 89 90 91 |
# File 'lib/benchcc/compiler.rb', line 84 def compile_code(code, *args) tmp = Tempfile.new(["", '.cpp']) tmp.write(code) tmp.close compile_file(tmp.path, *args) ensure tmp.unlink end |
#compile_file(file, *args) ⇒ Object
compile_file: Path -> CompilationResult
Compile the given file and return compilation statistics.
Additional compiler-specific arguments may be specified.
A CompilationError is be raised if the compilation fails for whatever reason. Either this method or compile_code must be implemented in subclasses.
71 72 73 74 75 |
# File 'lib/benchcc/compiler.rb', line 71 def compile_file(file, *args) raise ArgumentError, "invalid filename #{file}" unless File.file? file code = File.read(file) compile_code(code, *args) end |
#constexpr_depth ⇒ Object
Maximum constexpr recursion depth supported by the compiler.
53 54 55 |
# File 'lib/benchcc/compiler.rb', line 53 def constexpr_depth raise NotImplementedError end |
#template_depth ⇒ Object
Maximum template recursion depth supported by the compiler.
48 49 50 |
# File 'lib/benchcc/compiler.rb', line 48 def template_depth raise NotImplementedError end |
#to_s ⇒ Object
Show the name and the version of the compiler.
58 59 60 |
# File 'lib/benchcc/compiler.rb', line 58 def to_s raise NotImplementedError end |