0
+require 'rdoc/generator'
0
+require 'rdoc/markup/to_html_hyperlink'
0
+require 'kernel/core/iseq'
0
+OP_CODE_TEMPLATE = <<-EOF
0
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
0
+<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
0
+<title>Rubinius Virtual Machine OpCode: %s</title>
0
+<link rel="stylesheet" href="../styles.css" type="text/css" />
0
+<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
0
+<title>Rubinius Virtual Machine OpCodes</title>
0
+<link rel="stylesheet" href="styles.css" type="text/css" />
0
- def create_index_html(op_codes, template)
0
- File.open("toc.html", 'w') do |f|
0
- html = template.result(binding)
0
+<li><a href="intro.html" target="op_code">Intro</a></li>
0
+<li><a href="shotgun.html" target="op_code">Shotgun</a></li>
0
+<li><a href="rubinius_vs_mri.html" target="op_code">Rubinius vs MRI</a></li>
0
+<li><a href="concurrency.html" target="op_code">Concurrency</a></li>
0
+<li><a href="vm_interfaces.html" target="op_code">Interfacing to Rubinius</a></li>
0
+<li><a href="rbc_files.html" target="op_code">Rubinius Compiled Files</a></li>
0
+<ul id="op_codes" class="toc_subsection">
0
+class ToRubiniusOpCode < RDoc::Markup::ToHtmlHyperlink
0
+ @markup.add_special(/<\/?code>/, :CODE)
0
+ def accept_list_end(am, fragment)
0
+ if @level and fragment.level > @level
0
+ elsif fragment.level == @level then
0
+ make_stack am, @name, @stack
0
- def create_opcode_html(op_code, template)
0
- # Create documentation page for this op code
0
- file_name = "op_codes/#{op_code.mnemonic.to_s}.html"
0
- File.open(file_name, 'w') do |f|
0
- html = template.result(binding)
0
+ def accept_list_item(am, fragment)
0
+ if @level and fragment.level >= @level then
0
+ elsif fragment.param =~ /^Stack/ then
0
+ @name = fragment.param
0
+ @level = fragment.level + 1
0
- # Supports VERY simple formatting instructions in a description. At present,
0
- # _italics_ is converted to italics, and *bold text* is converted to bold.
0
- # Links are supported via "link":url, and line breaks are converted to <p>.
0
- html = str.gsub(/(^|\W)_(\S([^_]|(_\w))*)_/){|m| "#{$1}<i>#{$2}</i>" }.gsub(/\*((\w|\s)+?)\*/) {|m| "<b>#{$1}</b>"}
0
- html = html.gsub(/@((\w|\s)+?)@/) {|m| "<code>#{$1}</code>"}
0
- html = html.gsub(/"(.+?)":((\w|\/)+(\.\w+)?)/){|m| "<a href=\"#{$2}\">#{$1}</a>"}
0
- %Q{<p>#{html.gsub("\n","</p><p>")}</p>}
0
+ def accept_list_start(am, fragment)
0
+ if @level and fragment.level >= @level
0
- # Outputs a representation of the stack
0
- html << "[#{html_escape i.join(', ')}]"
0
- html << (i.map do |key,val|
0
- html_escape "#{key}=>#{val}"
0
- html << html_escape(i)
0
+ def make_stack(am, name, stack)
0
+ level = stack.first.level
0
+ stack.each do |fragment|
0
+ when RDoc::Markup::ListStart then
0
+ @res << "<table class=\"stack\">\n"
0
+ #@res << "<caption>#{name}</caption>"
0
+ when RDoc::Markup::ListEnd then
0
+ when RDoc::Markup::ListItem then
0
+ @res << "<tr><td>#{fragment.txt}</td></tr>\n"
0
+ raise "Unknown fragment #{fragment.inspect}"
0
- html << "</td></tr></table>"
0
+ # This is a hack around a misfeature in RDoc for labeled list handling.
0
+ def handle_special_CODE(special)
0
-op_code_template = ERB.new(File.read('op_codes/op_code_template.html.erb'),nil,'<>')
0
-index_template = ERB.new(File.read('toc.html.erb'), nil, '<>')
0
-emitter = OpCode::HTMLEmitter.new
0
-OpCode::Info.op_codes.each do |op|
0
- op_code = OpCode::Info.new(op)
0
- emitter.create_opcode_html(op_code, op_code_template) if ARGV.empty? or ARGV.include? op.to_s
0
- rescue Exception => ex
0
- puts "An exception occurred while processing op code '#{op_code}'"
0
+options = RDoc::Options.new({})
0
+options.generator = nil
0
+options.files = ['shotgun/lib/instructions.rb']
0
+options.inline_source = true
0
+toplevels = rdoc.parse_files options
0
+files, classes = RDoc::Generator::Context.build_indicies toplevels, options
0
+formatter = ToRubiniusOpCode.new '', nil, true
0
+classes.each do |klass|
0
+ formatter.context = klass
0
+ klass.methods.each do |method|
0
+ str = method.context.comment
0
+ source = method.context.token_stream.find do |ts|
0
+ RubyToken::TkSTRING === ts
0
+ source = source.text[1..-2]
0
+ source = source.split("\\n").map do |line|
0
+ if str =~ /^(?>\s*)[^\#]/ then
0
+ content = str.gsub(/^\s*(#+)/) { $1.tr '#', ' ' }
0
+ bytecode = InstructionSet[method.name.intern].bytecode rescue nil
0
+ [Byte code] 0x#{bytecode.to_s 16}
0
+ html = OP_CODE_TEMPLATE % [
0
+ formatter.convert(content)
0
+ file = File.join 'doc', 'vm', 'op_codes', "#{method.name}.html"
0
+ File.open file, 'w' do |fp|
0
+toc = toc.sort.map do |name|
0
+ "<li><a href=\"op_codes/#{name}.html\">#{name}</a></li>"
0
+toc_path = File.join 'doc', 'vm', 'toc.html'
0
+toc_html = TOC_TEMPLATE % [toc]
0
+File.open toc_path, 'w' do |fp|
0
-emitter.create_index_html(op_codes, index_template)
Comments
No one has commented yet.