node/lib/metasm/metasm/preprocessor.rb
def dump_macros(list, comment = true)
		depend = {}
		# build dependency graph (we can output macros in any order, but it's more human-readable)
		walk = lambda { |mname|
			depend[mname] ||= []
			@definition[mname].body.each { |t|
				name = t.raw
				if @definition[name]
					depend[mname] << name
					if not depend[name]
						depend[name] = []
						walk[name]
					end
				end
			}
		}
		list.each { |mname| walk[mname] }

		res = []
		while not depend.empty?
			todo_now = depend.keys.find_all { |k| (depend[k] - [k]).empty? }
			if todo_now.empty?
				dep_cycle = lambda { |ary|
					deps = depend[ary.last]
					if deps.include? ary.first; ary
					elsif (deps-ary).find { |d| deps = dep_cycle[ary + [d]] }; deps
					end
				}
				if not depend.find { |k, dep| todo_now = dep_cycle[[k]] }
					todo_now = depend.keys
				end
			end
			todo_now.sort.each { |k|
				res << @definition[k].dump(comment) if @definition[k].kind_of? Macro
				depend.delete k
			}
			depend.each_key { |k| depend[k] -= todo_now }
		end
		res.join("\n")
	end
# dumps the definition of the macros whose name is in the list + their dependencies
# returns one big C-style source string
dumps the definition of the macros whose name is in the list + their dependencies
returns one big C-style source string
dumps the definition of the macros whose name is in the list + their dependencies returns one big C - style source string
def dump_macros(list, comment = true)
		depend = {}
		walk = lambda { |mname|
			depend[mname] ||= []
			@definition[mname].body.each { |t|
				name = t.raw
				if @definition[name]
					depend[mname] << name
					if not depend[name]
						depend[name] = []
						walk[name]
					end
				end
			}
		}
		list.each { |mname| walk[mname] }
		res = []
		while not depend.empty?
			todo_now = depend.keys.find_all { |k| (depend[k] - [k]).empty? }
			if todo_now.empty?
				dep_cycle = lambda { |ary|
					deps = depend[ary.last]
					if deps.include? ary.first; ary
					elsif (deps-ary).find { |d| deps = dep_cycle[ary + [d]] }; deps
					end
				}
				if not depend.find { |k, dep| todo_now = dep_cycle[[k]] }
					todo_now = depend.keys
				end
			end
			todo_now.sort.each { |k|
				res << @definition[k].dump(comment) if @definition[k].kind_of? Macro
				depend.delete k
			}
			depend.each_key { |k| depend[k] -= todo_now }
		end
		res.join("\n")
	end
def dump_macros ( list , comment = true ) depend = { } walk = lambda { | mname | depend [ mname ] ||= [ ] @definition [ mname ] . body . each { | t | name = t . raw if @definition [ name ] depend [ mname ] << name if not depend [ name ] depend [ name ] = [ ] walk [ name ] end end } } list . each { | mname | walk [ mname ] } res = [ ] while not depend . empty? todo_now = depend . keys . find_all { | k | ( depend [ k ] - [ k ] ) . empty? } if todo_now . empty? dep_cycle = lambda { | ary | deps = depend [ ary . last ] if deps . include? ary . first ; ary elsif ( deps - ary ) . find { | d | deps = dep_cycle [ ary + [ d ] ] } ; deps end } if not depend . find { | k , dep | todo_now = dep_cycle [ [ k ] ] } todo_now = depend . keys end end todo_now . sort . each { | k | res << @definition [ k ] . dump ( comment ) if @definition [ k ] . kind_of? Macro depend . delete k } depend . each_key { | k | depend [ k ] -= todo_now } end res . join ( "\n" ) end
dumps the definition of the macros whose name is in the list + their dependencies
returns one big C-style source string
dumps the definition of the macros whose name is in the list + their dependencies returns one big C - style source string
# build dependency graph (we can output macros in any order, but it's more human-readable)
list
comment