Class: Benchcc::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/benchcc/compiler.rb,
lib/benchcc/compiler.rb

Overview

Basic interface to compiler frontends.

Direct Known Subclasses

Clang, GCC

Class Method Summary collapse

Instance Method Summary collapse

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.

Raises:

  • (ArgumentError)


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_depthObject

Maximum constexpr recursion depth supported by the compiler.

Raises:

  • (NotImplementedError)


45
46
47
# File 'lib/benchcc/compiler.rb', line 45

def constexpr_depth
  raise NotImplementedError
end

#template_depthObject

Maximum template recursion depth supported by the compiler.

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/benchcc/compiler.rb', line 40

def template_depth
  raise NotImplementedError
end

#to_sObject

Show the name and the version of the compiler.

Raises:

  • (NotImplementedError)


50
51
52
# File 'lib/benchcc/compiler.rb', line 50

def to_s
  raise NotImplementedError
end