Class: ISE::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/ise/project.rb

Constant Summary collapse

GoalProperty =
'Last Applied Goal'
ShortNameProperty =
'PROP_DesignName'
OutputNameProperty =
'Output File Name'
TopLevelFileProperty =
'Implementation Top File'
WorkingDirectoryProperty =
'Working Directory'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml, filename) ⇒ Project

Creates a new ISE Project from an XML string or file object.



23
24
25
26
27
# File 'lib/ise/project.rb', line 23

def initialize(xml, filename)
  @xml = Nokogiri.XML(xml)
  @filename = filename
  @base_path = File.dirname(filename)
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



17
18
19
# File 'lib/ise/project.rb', line 17

def filename
  @filename
end

Class Method Details

.load(file_path) ⇒ Object

Factory method which creates a new Project from a project file.



33
34
35
# File 'lib/ise/project.rb', line 33

def self.load(file_path)
  new(File::read(file_path), file_path)
end

Instance Method Details

#bit_fileObject

Returns the best-guess path to the most recently generated bit file, or nil if we weren’t able to find one.



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/ise/project.rb', line 119

def bit_file

  #Determine ISE's working directory.
  working_directory = get_property(WorkingDirectoryProperty)

  #Find an absolute path at which the most recently generated bit file should reside.
  name = get_property(OutputNameProperty)
  name = File.expand_path("#{working_directory}/#{name}.bit", @base_path)

  #If it exists, return it.
  File::exists?(name) ? name : nil

end

#get_property(name) ⇒ Object

Returns the value of a project property.



47
48
49
50
51
52
53
# File 'lib/ise/project.rb', line 47

def get_property(name)

  #Retreive the value of the node with the given property.
  node = get_property_node(name)
  node.attribute("value").value

end

#minimize_runtime!Object

Attempts to minimize synthesis runtime of a _single run_.

This will place all intermediary files in RAM- which means that synthesis results won’t be preserved between reboots!



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ise/project.rb', line 75

def minimize_runtime!

  #Compute the path in which temporary synthesis files should be created.
  shortname = CGI::escape(get_property(ShortNameProperty))
  temp_path = Dir::mktmpdir([shortname, ''])
  
  #Synthesize from RAM.
  set_property(WorkingDirectoryProperty, temp_path)

  #Ask the project to focus on runtime over performance.
  set_property(GoalProperty, 'Minimum Runtime')

end

#save(file_path = @filename) ⇒ Object

Writes the project to disk, saving any changes.



40
41
42
# File 'lib/ise/project.rb', line 40

def save(file_path=@filename)
  File::write(file_path, @xml)
end

#set_property(name, value, mark_non_default = true) ⇒ Object

Sets the value of an ISE project property.



58
59
60
61
62
63
64
65
66
67
# File 'lib/ise/project.rb', line 58

def set_property(name, value, mark_non_default=true)
 
  #Set the node's property, as specified.
  node = get_property_node(name)
  node.attribute("value").value = value

  #If the mark non-default option is set, mark the state is not a default value.
  node.attribute("valueState").value = 'non-default' if mark_non_default

end

#top_level_file(absolute_path = true) ⇒ Object

Returns a path to the top-level file in the given project.

absoulute_path: If set when the project file’s path is known, an absolute path will be returned.



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/ise/project.rb', line 94

def top_level_file(absolute_path=true)
 
  path = get_property(TopLevelFileProperty)

  #If the absolute_path flag is set, and we know how, expand the file path.
  if absolute_path
    path = File.expand_path(path, @base_path) 
  end

  #Return the relevant path.
  path

end

#working_directoryObject

Returns the project’s working directory.



111
112
113
# File 'lib/ise/project.rb', line 111

def working_directory
  File.expand_path(get_property(WorkingDirectoryProperty), @base_path)
end