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
157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/benchcc/compiler.rb', line 157 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.
76 77 78 79 80 81 82 83 |
# File 'lib/benchcc/compiler.rb', line 76 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.
63 64 65 66 67 |
# File 'lib/benchcc/compiler.rb', line 63 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.
45 46 47 |
# File 'lib/benchcc/compiler.rb', line 45 def constexpr_depth raise NotImplementedError end |
#template_depth ⇒ Object
Maximum template recursion depth supported by the compiler.
40 41 42 |
# File 'lib/benchcc/compiler.rb', line 40 def template_depth raise NotImplementedError end |
#to_s ⇒ Object
Show the name and the version of the compiler.
50 51 52 |
# File 'lib/benchcc/compiler.rb', line 50 def to_s raise NotImplementedError end |