From 8fd3ad10c0628e6156c4a6c360b140912a404349 Mon Sep 17 00:00:00 2001 From: dhower-qc <134728312+dhower-qc@users.noreply.github.com> Date: Wed, 16 Oct 2024 21:49:26 -0400 Subject: [PATCH] Add exception analysis back in generators (#93) * Add exception analysis back in generators * Fix typo in instruction.rb Signed-off-by: dhower-qc <134728312+dhower-qc@users.noreply.github.com> --------- Signed-off-by: dhower-qc <134728312+dhower-qc@users.noreply.github.com> --- backends/crd_doc/templates/crd.adoc.erb | 18 ++++++------- .../manual/templates/instruction.adoc.erb | 3 +-- .../templates/profile_pdf.adoc.erb | 17 +++++------- lib/arch_obj_models/instruction.rb | 27 +++++++------------ 4 files changed, 25 insertions(+), 40 deletions(-) diff --git a/backends/crd_doc/templates/crd.adoc.erb b/backends/crd_doc/templates/crd.adoc.erb index cb74d37f5..78768ad09 100644 --- a/backends/crd_doc/templates/crd.adoc.erb +++ b/backends/crd_doc/templates/crd.adoc.erb @@ -455,20 +455,18 @@ RV64:: ==== Exceptions -// TODO: add back after sym table update for generic arch def is merged in profiles branch -<%# -<% exception_list = inst.reachable_exceptions_str(crd.arch_def.symtab) -% > -<% if exception_list.empty? -% > +<%- exception_list = inst.reachable_exceptions_str(crd.arch_def.symtab) -%> +<%- if exception_list.empty? -%> This instruction does not generate synchronous exceptions. -<% else -% > +<%- else -%> This instruction may result in the following synchronous exceptions: - <% exception_list.sort.each do |etype| -% > - * <%= etype % > - <% end -% > + <%- exception_list.sort.each do |etype| -%> + * <%= etype %> + <%- end -%> + +<%- end -%> -<% end -% > -%> <% end -%> diff --git a/backends/manual/templates/instruction.adoc.erb b/backends/manual/templates/instruction.adoc.erb index 030b1a600..9a5335403 100644 --- a/backends/manual/templates/instruction.adoc.erb +++ b/backends/manual/templates/instruction.adoc.erb @@ -108,8 +108,7 @@ RV64:: ---- <%- end -%> -<%# exception_list = inst.reachable_exceptions_str(inst.arch_def.sym_table_64, 64) -%> -<%- exception_list = [] -%> +<% exception_list = inst.reachable_exceptions_str(inst.arch_def.symtab, 64) -%> <%- unless exception_list.empty? -%> == Exceptions diff --git a/backends/profile_doc/templates/profile_pdf.adoc.erb b/backends/profile_doc/templates/profile_pdf.adoc.erb index ffe1f3136..4d03f12ba 100644 --- a/backends/profile_doc/templates/profile_pdf.adoc.erb +++ b/backends/profile_doc/templates/profile_pdf.adoc.erb @@ -618,20 +618,17 @@ RV64:: ==== Exceptions -// TODO: add back after sym table update for generic arch def is merged in profiles branch -<%# -<%- exception_list = inst.reachable_exceptions_str(arch_def.symtab) -% > -<%- if exception_list.empty? -% > +<%- exception_list = inst.reachable_exceptions_str(arch_def.symtab) -%> +<%- if exception_list.empty? -%> This instruction does not generate synchronous exceptions. -<%- else -% > +<%- else -%> This instruction may result in the following synchronous exceptions: - <%- exception_list.sort.each do |etype| -% > - * <%= etype % > - <%- end -% > + <%- exception_list.sort.each do |etype| -%> + * <%= etype %> + <%- end -%> -<%- end -% > -%> +<%- end -%> <%- end -%> diff --git a/lib/arch_obj_models/instruction.rb b/lib/arch_obj_models/instruction.rb index 9b9fa0070..1779b9590 100644 --- a/lib/arch_obj_models/instruction.rb +++ b/lib/arch_obj_models/instruction.rb @@ -160,7 +160,6 @@ def reachable_exceptions_str(symtab, effective_xlen=nil) if @data["operation()"].nil? [] else - # RubyProf.start etype = symtab.get("ExceptionCode") if effective_xlen.nil? if symtab.archdef.multi_xlen? @@ -174,21 +173,18 @@ def reachable_exceptions_str(symtab, effective_xlen=nil) puts "done" pruned_ast = pruned_operation_ast(symtab, 64) print "Determining reachable exceptions from #{name}#RV64..." - e64 = mask_to_array(prunted_ast.reachable_exceptions(fill_symtab(symtab, 64, pruned_ast))).map { |code| + e64 = mask_to_array(pruned_ast.reachable_exceptions(fill_symtab(symtab, 64, pruned_ast))).map { |code| etype.element_name(code) } - puts done + puts "done" e32 + e64 ).uniq else pruned_ast = pruned_operation_ast(symtab, base) print "Determining reachable exceptions from #{name}..." - result = RubyProf.profile do - e = mask_to_array(pruned_ast.reachable_exceptions(fill_symtab(symtab, base, pruned_ast))).map { |code| - etype.element_name(code) - } - end - RubyProf::CallStackPrinter.new(result).print(File.open("#{name}-profile.html", "w+"), {}) + e = mask_to_array(pruned_ast.reachable_exceptions(fill_symtab(symtab, base, pruned_ast))).map { |code| + etype.element_name(code) + } puts "done" e end @@ -196,12 +192,9 @@ def reachable_exceptions_str(symtab, effective_xlen=nil) effective_xlen = symtab.archdef.mxlen pruned_ast = pruned_operation_ast(symtab, effective_xlen) print "Determining reachable exceptions from #{name}..." - # result = RubyProf.profile do - e = mask_to_array(pruned_ast.reachable_exceptions(fill_symtab(symtab, effective_xlen, pruned_ast))).map { |code| - etype.element_name(code) - } - # end - # RubyProf::FlameGraphPrinter.new(result).print(File.open("#{name}-profile.html", "w+"), {}) + e = mask_to_array(pruned_ast.reachable_exceptions(fill_symtab(symtab, effective_xlen, pruned_ast))).map { |code| + etype.element_name(code) + } puts "done" e end @@ -209,14 +202,12 @@ def reachable_exceptions_str(symtab, effective_xlen=nil) pruned_ast = pruned_operation_ast(symtab, effective_xlen) print "Determining reachable exceptions from #{name}..." - e = mask_to_array(prunted_ast.reachable_exceptions(fill_symtab(symtab, effective_xlen, pruned_ast))).map { |code| + e = mask_to_array(pruned_ast.reachable_exceptions(fill_symtab(symtab, effective_xlen, pruned_ast))).map { |code| etype.element_name(code) } puts "done" e end - # result = RubyProf.stop - # RubyProf::FlatPrinter.new(result).print(STDOUT) end end