Class: RedShift::Library

Inherits:
CShadow::Library
  • Object
show all
Defined in:
lib/redshift/target/c/library.rb,
lib/redshift/target/c/flow/buffer.rb

Defined Under Namespace

Classes: BufferAttribute

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Library

Returns a new instance of Library.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/redshift/target/c/library.rb', line 11

def initialize(*args)
  super
  
  self.purge_source_dir = :delete
  
  self.show_times_flag =
    case $REDSHIFT_BUILD_TIMES
    when nil, false, /\A(false|0*)\z/i
      false
    else
      true
    end

  if $REDSHIFT_DEBUG
    include_file.include "<assert.h>"
    ## better to use something that raises a ruby exception
  else
    include_file.declare :assert => %{#define assert(cond) 0}
  end

  include_file.include '<math.h>'
end

Instance Method Details

#commitObject



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/redshift/target/c/library.rb', line 63

def commit
  return if committed?
  precommit

  ## this makes it a little trickier to use gdb
  use_work_dir $REDSHIFT_WORK_DIR do
    # $REDSHIFT_SKIP_BUILD is normally handled in redshift/target/c.rb.
    # useful for: turnkey; fast start if no changes; manual lib edits
    super(!$REDSHIFT_SKIP_BUILD)
  end
  ## freeze metadata in comp classes?
  ## can cgen/cshadow freeze some stuff?
end

#component_classesObject

Return list of all subclasses of Component (including Component).



78
79
80
81
82
83
84
85
# File 'lib/redshift/target/c/library.rb', line 78

def component_classes
  return @component_classes if @component_classes

  cc = Library.sort_class_tree(Component.subclasses)
  @component_classes = cc if committed?
    
  return cc
end

#declare_external_constant(*vars) ⇒ Object



39
40
41
42
43
44
# File 'lib/redshift/target/c/library.rb', line 39

def declare_external_constant *vars
  @external_constants ||= {}
  vars.each do |var|
    @external_constants[var.to_s] = true
  end
end

#define_bufferObject



5
6
7
8
9
10
11
12
13
# File 'lib/redshift/target/c/flow/buffer.rb', line 5

def define_buffer
  unless @buffer_defined
    @buffer_defined = true
    text = File.read(File.join(REDSHIFT_BUFFER_DIR, "buffer.h"))
    buffer_h = CGenerator::CFile.new("buffer.h", self, nil, true)
    buffer_h.declare :buffer_header_text => text
    add [buffer_h]
  end
end

#extconfObject



50
51
52
53
54
55
56
57
# File 'lib/redshift/target/c/library.rb', line 50

def extconf
  super do |lines|
    if @link_libs
      libstr = " " + @link_libs.flatten.join(" ")
      lines << %{$LOCAL_LIBS << "#{libstr}"}
    end
  end
end

#external_constant?(var) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/redshift/target/c/library.rb', line 46

def external_constant? var
  @external_constants and @external_constants.key?(var.to_s)
end

Call this to link with external libraries. See examples/external-lib.rb.



35
36
37
# File 'lib/redshift/target/c/library.rb', line 35

def link_with *libs
  (@link_libs ||= []) << libs
end

#make(arg = nil) ⇒ Object



59
60
61
# File 'lib/redshift/target/c/library.rb', line 59

def make arg=nil
  super [$REDSHIFT_MAKE_ARGS, arg].join(" ")
end

#precommitObject

Operate on Component class specifications gathered by meta.rb, and stored in the component classes.



89
90
91
92
93
94
# File 'lib/redshift/target/c/library.rb', line 89

def precommit
  ## no need to precommit Component? Other abstract classes?
  component_classes.each {|cl| cl.precommit}
  ## optimization?
  ## check if changed
end