1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 20:00:19 +02:00
Commit graph

1052 commits

Author SHA1 Message Date
Andy Wingo
b77a5215c7 Per-instruction tracing doesn't try to disassemble stack VM code
* module/system/vm/trace.scm (trace-instructions-in-procedure): Don't
  try to disassemble the procedure, for now.
2013-11-08 17:32:41 +01:00
Andy Wingo
e391f179e4 (system vm traps) support for rtl programs
* module/system/vm/debug.scm: Export program-debug-info-size.

* module/system/vm/traps.scm (frame-matcher): Remove stack program
  case.  Use absolute frame-instruction-procedure to match if
  match-code?.
  (program-last-ip): Use (system vm debug) interfaces.
  (program-sources-by-line): Use program-sources, as
  program-sources-pre-retire will go away soon.  Return absolute
  addresses.
2013-11-08 17:31:51 +01:00
Andy Wingo
f3c0b53346 Remove assembly language.
* module/system/repl/command.scm: Remove disassembly cases for stack
  procedures.

* module/system/vm/inspect.scm: Adapt to disassemble RTL programs.

* module/language/assembly.scm:
* module/language/assembly/compile-bytecode.scm:
* module/language/assembly/decompile-bytecode.scm:
* module/language/assembly/disassemble.scm:
* module/language/assembly/spec.scm: Remove assembly language.

* module/Makefile.am: Adapt.
2013-11-08 16:45:10 +01:00
Andy Wingo
f7f5f49a6b Decompile goes from tree-il to scheme by default.
* module/system/base/compile.scm (decompile): By default, go from
  tree-il to Scheme, now that the assembly language is going away.
2013-11-08 16:40:27 +01:00
Andy Wingo
147f9978ba Rewrite (system xref) to work with RTL programs
* module/system/xref.scm (nested-procedures): New helper.
  (program-callee-rev-vars): Rewrite using fold-program-code and
  nested-procedures.
  (add-sources, forget-sources): Use match instead of pmatch.  Use
  nested-procedures.
2013-11-08 16:31:29 +01:00
Andy Wingo
850e80dacc Add fold-program-code to (system vm disassembler)
* module/system/vm/disassembler.scm (fold-code-range): New helper.
  (fold-program-code): New interface.
2013-11-08 15:58:27 +01:00
Andy Wingo
8734229528 Fix program-minimum-arity to work better with case-lambda.
* module/system/vm/debug.scm (program-minimum-arity): Be more precise
  with case-lambdas.
2013-11-08 14:19:41 +01:00
Andy Wingo
f41accb9c2 Fix procedure-arguments on RTL programs, and tweak session.test
* module/ice-9/session.scm (procedure-arguments): Add an rtl-program?
  case.

* module/system/vm/debug.scm (arity-arguments-alist): Use the order that
  session.test expects.

* test-suite/tests/session.test ("procedure-arguments"): Adapt tests
  with keywords for the new starting-with-the-procedure numbering of
  locals.
2013-11-08 13:29:03 +01:00
Andy Wingo
b0ed216b6f Fix case-lambda* dispatching to agree with manual.
* module/system/vm/assembler.scm (kw-prelude): Emit br-if-npos-gt as
  appropriate.
2013-11-08 11:41:28 +01:00
Andy Wingo
0e3a59f750 Fix reading and writing arities into DWARF.
* libguile/gsubr.h:
* libguile/gsubr.c (scm_i_primitive_call_ip):
* libguile/programs.c (scm_primitive_call_ip): Adapt to return an
  absolute address.

* module/system/vm/assembler.scm (write-arity-headers): Adapt to write
  byte addresses (relative to the text base).

* module/system/vm/debug.scm (arity-low-pc, arity-high-pc): Return
  absolute addresses, instead of word offsets relative to the text
  base.
  (find-first-arity): Adapt for absolute addresses.

* module/system/vm/program.scm (program-arguments-alist): Adapt for
  arity-low-pc / arity-high-pc absolute addresses.
2013-11-08 10:11:48 +01:00
Andy Wingo
581a4eb82b frame-instruction-pointer is absolute; rewrite (system vm coverage)
* libguile/frames.c (scm_frame_source): Instead of assuming that
  scm_frame_procedure is correct, use the IP to get the source.
  (scm_frame_instruction_pointer): Return an absolute value instead of
  assuming that slot 0 is correct.  (It isn't, when preparing for a tail
  call.)

* libguile/programs.h:
* libguile/programs.c (scm_find_source_for_addr): New internal helper.

* module/system/repl/debug.scm (print-registers): Readably print
  absolute instruction pointers.

* module/system/vm/coverage.scm: Complete rewrite to use absolute IP's.
  We can't assume that frame-procedure is cheap if it is correct, or
  correct if it is cheap.  Anyway using the address is better anyway.
  (coverage-data->lcov): Disable per-function info temporarily.
  (loaded-modules, module-procedures, closest-source-line)
  (closed-over-procedures): Remove these.  Instead of going from
  procedures to source info, now we go from ELF image to source info.

* module/system/vm/debug.scm (debug-context-length): New interface.

* module/system/vm/program.scm (source-for-addr): New internal helper.
2013-11-07 23:03:45 +01:00
Andy Wingo
e15aa02284 Program sources are always pre-retire now
* module/system/repl/debug.scm (<debug>): Remove for-trap?.  Backtraces
  with RTL will always happen pre-retire on the top frame, source info
  is pre-retire, and continuations will always have a source-marked
  receive or receive-values or whatever with the right source marking,
  so we can remove this complication.
  (print-frame): Use frame-source.
  (print-frames): Remove for-trap? kw.

* module/system/repl/command.scm (define-stack-command, backtrace)
  (up, down, frame): Remove for-trap? introduced local, and its uses.
  (repl-pop-continuation-resumer): Adapt to make-debug change.

* module/system/repl/error-handling.scm (call-with-error-handling):
  Adapt to make-debug change.

* module/system/vm/frame.scm (frame-next-source): Remove.  RTL sources
  are pre-retire.

* module/system/vm/trap-state.scm (add-ephemeral-stepping-trap!): Adapt
  to use frame-source.  Still some work to do here.
2013-11-07 18:00:40 +01:00
Andy Wingo
0128bb9c38 add fold-all-debug-contexts, fold-source-locations
* module/system/vm/objcode.scm:
* libguile/objcodes.c (scm_all_mapped_elf_images): New proc.

* module/system/vm/debug.scm (fold-all-debug-contexts):
  (fold-source-locations): New public interfaces.
2013-11-07 17:53:04 +01:00
Andy Wingo
31602aa04a Fix line advance DWARF opcodes when line advance is exactly 128
* module/system/vm/assembler.scm (link-debug): Fix off-by-one error in
  which forward jumps of 128 were mis-rendered.
2013-11-07 11:10:36 +01:00
Andy Wingo
32ca15d7d7 Write DWARF files list in correct order.
* module/system/vm/assembler.scm (link-debug): Fix order of writing the
  source files list; it was being written backwards.
2013-11-07 10:52:47 +01:00
Andy Wingo
963d95f1d9 Fix first find-program-sources result
* module/system/vm/debug.scm (find-program-sources): Manually set the pc
  of the first result in a function.
2013-11-06 17:33:43 +01:00
Andy Wingo
0a1d52ac77 fix docstring assembly and fetching
* module/system/vm/assembler.scm (link-docstrs): Write pc offsets as
  byte addresses.  Works better with native code.
* module/system/vm/debug.scm (find-program-docstring): Fix the linear
  search.  How embarassing!
2013-11-05 21:29:46 +01:00
Andy Wingo
3659ef543e asm-labels is a hash table
* module/system/vm/assembler.scm (make-assembler, label):
  (link-data, process-relocs, process-labels): Change labels to be a
  hash table.
2013-11-05 20:18:23 +01:00
Andy Wingo
d65514a2de RTL compiler supports static bitvectors
* libguile/arrays.c (scm_from_contiguous_typed_array):
* libguile/bytevectors.c (scm_uniform_array_to_bytevector): For
  bitvectors, round up the length to 32-bit units, as they are stored
  internally.  Otherwise I think this probably does the wrong thing for
  the last word on big-endian systems.
* libguile/bitvectors.c (BITVECTOR_LENGTH, BITVECTOR_BITS):
  (scm_c_make_bitvector): Reorder the length and pointer words to match
  the layout of bytevectors.

* module/language/cps/primitives.scm (*branching-primcall-arities*):
* module/system/vm/assembler.scm (br-if-bitvector):
* module/system/vm/disassembler.scm (code-annotation): Add bitvector
  test support.

* module/system/vm/assembler.scm (<uniform-vector-backing-store>): Add
  an element-size field.
  (intern-constant): Adapt make-uniform-vector-backing-store call.  Use
  uniform-array->bytevector, as the old compiler did.
  (link-data): Add bitvector cases.
2013-11-03 21:48:48 +01:00
Andy Wingo
cb8054c7ac Better range checks in the assembler
* module/system/vm/assembler.scm (pack-u8-u24, pack-u8-s24):
  (pack-u1-u7-u24, pack-u8-u12-u12, pack-u8-u8-u16, pack-u8-u8-u8-u8):
  Prevent adjacent fields from stompling each other.
2013-10-31 22:57:06 +01:00
Andy Wingo
c7cb2bc200 static-patch! for pair and vector fields
* module/system/vm/assembler.scm (intern-constant): Use static-patch!
  for fields.
2013-10-31 19:21:31 +01:00
Andy Wingo
57a5cc9760 Better REPL support for disassembling RTL images
* module/system/repl/command.scm (load-image): New helper.
  (compile, disassemble): Handle bytevectors.
2013-10-31 14:18:25 +01:00
Andy Wingo
b73a2ee017 Default to compiling to RTL
* module/ice-9/eval-string.scm (eval-string)
* module/language/tree-il/spec.scm (tree-il)
* module/scripts/compile.scm (compile)
* module/system/base/compile.scm (compile-file, read-and-compile)
* module/system/repl/common.scm (repl-compile, repl-prepare-eval-thunk):
  Default to compiling to RTL.

* module/language/rtl/spec.scm (rtl->value): Add value compiler.
2013-10-31 14:17:30 +01:00
Andy Wingo
becce37b58 Better compiler support for bytevector ops
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add emitters
  for bytevector ops.  Add br-if-bytevector emitter.
* module/language/cps/primitives.scm (*branching-primcall-arities*):
  Mark bytevector? as a branching primitive.
* module/system/vm/assembler.scm (br-if-bytevector): New instruction
* module/system/vm/disassembler.scm (code-annotation): Add support for
  bytevector?.
2013-10-31 12:55:24 +01:00
Andy Wingo
7bfbc7b1c5 Support serialization of uniform vector literals
* libguile/uniform.h:
* libguile/uniform.c (scm_uniform_vector_element_type_code): New
  interface, returns a type code as an integer.

* module/system/vm/assembler.scm (<uniform-vector-backing-store>)
  (simple-vector?, uniform-array?, statically-allocatable?)
  (intern-constant, link-data, link-constants): Support uniform arrays,
  and punt on vectors aren't contiguous from 0.  Support for general
  arrays will come later.

* test-suite/tests/rtl.test ("load-constant"): Add tests.
2013-10-31 12:55:23 +01:00
Andy Wingo
2ab2a10d50 static-patch! replaces link-procedure!
* libguile/vm-engine.c (static-patch!): Replace link-procedure! with
  this more versatile primitive.
* module/system/vm/assembler.scm (intern-constant): Emit static-patch!
  for static procedures and for strings.
* module/system/vm/disassembler.scm (code-annotation): Remove annotation
  for link-procedure!.  There can be no annotation for static-patch!, as
  neither operand is guaranteed to be a SCM value.
2013-10-31 09:47:48 +01:00
Andy Wingo
2700f19833 DWARF return arity fixen
* module/system/vm/dwarf.scm (read-die-abbrev): Fix return arity.
  (read-compilation-unit): Fix return arity of read-die.
2013-10-29 22:53:46 +01:00
Andy Wingo
486013d67c VM has "builtins": primitives addressable by emitted RTL code
* libguile/Makefile.am:
* libguile/vm-builtins.h: New header, declaring stubs needed by the
  compiler like values, apply, and abort-to-prompt.

* libguile/vm.c: Adapt the apply and values stubs to conform to a
  standard interface.  Add an abort-to-prompt stub.  Add call/cc and
  call-with-values stubs.
  (scm_vm_builtin_ref): New helper, for the builtin-ref opcode.
  (scm_vm_builtin_name_to_index)
  (scm_vm_builtin_index_to_name): New helpers, for the compiler and
  disassembler, respectively.
  (scm_init_vm_builtins, scm_bootstrap_vm): Allow the compiler helpers
  to be loaded later into a module.
* module/language/rtl.scm: Export builtin-index->name and
  builtin-name->index.

* libguile/vm-engine.c (RETURN_VALUE_LIST): Update to use new names of
  "apply" and "values".
  (tail-call/shuffle): New opcode.
  (abort): Update to be a tail VM op, and reorder and renumber other
  ops.
  (builtin-ref): New opcode.

* libguile/continuations.h:
* libguile/continuations.c (scm_i_call_with_current_continuation):
  Move this to vm.[ch], implemented as a builtin.

* module/language/tree-il/compile-cps.scm (convert): Convert to
  'abort-to-prompt calls, possibly with 'apply, effectively undoing the
  tree-il transformation.

* module/language/cps/reify-primitives.scm (builtin-ref): New helper.
  (reify-primitives): Convert builtin primitives to builtin-ref.

* module/language/cps/dfg.scm (constant-needs-allocation?):
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add support
  for compiling builtin-ref.

* module/system/vm/disassembler.scm (code-annotation): Add annotation
  for builtin-ref.
2013-10-27 20:09:01 +01:00
Andy Wingo
be8b62ca7f RTL compiler: Compile TC7 branches.
* module/system/vm/assembler.scm:
* module/system/vm/disassembler.scm (code-annotation):
* module/language/cps/primitives.scm (*branching-primcall-arities*):
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add support
  for compiling symbol?, variable?, vector?, and string? branches.
2013-10-26 15:16:09 +02:00
Andy Wingo
8695854a7d Fix assembler for keyword args
* module/system/vm/assembler.scm (begin-kw-arity, kw-prelude): Fix
  functions with keywords.
2013-10-22 22:31:26 +02:00
Andy Wingo
8bd261baaa (language tree-il analyze) works better with RTL programs
* module/system/vm/program.scm (program-arguments-alists): Export this
  interface.  Fall back to grovelling through procedure-minimum-arity if
  the program has no arities, as might be the case for continuations.

* module/language/tree-il/analyze.scm (validate-arity): Use
  program-arguments-alists instead of the program-arities interface, to
  cover both stack VM and RTL programs.
2013-10-18 18:41:59 +02:00
Andy Wingo
27337b6373 Subrs are RTL programs
* libguile/gsubr.c: Define RTL stubs instead of stack VM stubs.
  (SUBR_STUB_CODE, get_subr_stub_code): Adapt to return a uint32_t*
  pointer instead of a SCM value.
  (create_subr): Create RTL procedures instead of stack VM procedures.
  For RTL procedures, the function pointer, name, and generic address
  pointer go inline to the procedure, as free variables.
  (scm_i_primitive_arity, scm_i_primitive_call_ip): New helpers.
  (scm_c_make_gsubr, scm_c_define_gsubr, scm_c_make_gsubr_with_generic)
  (scm_c_define_gsubr_with_generic): Adapt to create_gsubr being renamed
  to create_subr.

  Remove gsubr test code.

* libguile/gsubr.h (SCM_PRIMITIVE_P, SCM_PRIMITIVE_GENERIC_P): Only RTL
  programs can be primitives now.
  (SCM_SUBRF, SCM_SUBR_NAME, SCM_SUBR_GENERIC): These fields are now in
  the RTL free variables, not the object table.

* libguile/programs.c (scm_i_rtl_program_name):
  (scm_i_rtl_program_documentation):
  (scm_i_rtl_program_properties):
  (scm_i_rtl_program_minimum_arity): Implement these appropriately for
  primitives, which lack debugging information.
  (scm_primitive_p, scm_primitive_call_ip): New helpers.

* libguile/snarf.h: Remove static allocation for subrs.  Since there is
  nothing to allocate besides the program itself, which needs runtime
  relocation, static allocation is not a win.

* system/vm/program.scm: Fix up various arity-related things for
  primitives, which don't use ELF arity info.

* test-suite/tests/eval.test ("stack involving a primitive"): Add an
  XFAIL until we get just one VM.
2013-10-18 11:39:35 +02:00
Andy Wingo
9dff1df97f (system vm debug): implement arity-low-pc, arity-high-pc
* module/system/vm/debug.scm (arity-low-pc, arity-high-pc): Implement
  these exports.
2013-10-18 11:39:35 +02:00
Andy Wingo
ac37196321 Procedure traps work with RTL programs.
* module/system/vm/traps.scm (frame-matcher): Work with RTL programs.
2013-10-17 23:20:32 +02:00
Andy Wingo
342370bd56 minimal RTL program support in (system xref)
* module/system/xref.scm (procedure-sources*): Work with RTL programs.
2013-10-17 23:20:32 +02:00
Andy Wingo
1d94a35d69 (system vm coverage) works with RTL programs
* module/system/vm/coverage.scm (hashq-proc, assq-proc)
  (program-sources*, closed-over-procedures, coverage-data->lcov): Work
  with RTl procedures.
2013-10-17 23:20:32 +02:00
Andy Wingo
8d59d55e86 RTL: Compile prompts
* libguile/vm-engine.c (prompt): Adapt to explicitly set the saved SP so
  we know how many incoming values the handler will receive, and to make
  escape-only? a flag.

* module/language/cps/compile-rtl.scm (emit-rtl-sequence): $prompt
  should only be found in a "seq" context, as it just pushes on a prompt
  and doesn't bind any values.  On the other hand it should emit
  appropriate code for the handler to bind its values, so do that.

* module/language/cps/slot-allocation.scm ($cont-allocation): Add a note
  that proc-slot is used by prompts as well.
  (allocate-slots): Compute the allocation of a prompt handler's args.

* module/language/tree-il/compile-cps.scm (convert): Use "unwind"
  instead of the nonexistent "pop-prompt".

* module/system/vm/disassembler.scm (code-annotation): Adapt to change
  in prompt VM op.
2013-10-14 16:13:57 +02:00
Andy Wingo
6b71a76713 A couple of fixes when no source info is available
* module/system/vm/assembler.scm (link-debug): If there was no debugging
  info, reset the file register to 0 from its default value of 1 before
  adding the final row.

* module/system/vm/dwarf.scm (line-prog-scan-to-pc): If we rescanned
  from the beginning and still found no source info for this pc, return
  #f instead of the default value of the file register (1).
2013-10-10 12:22:20 +02:00
Andy Wingo
f8fb13ef8c better RTL debugging
* libguile/frames.c (scm_frame_source, scm_frame_instruction_pointer):
  Fix to work with RTL programs.

* module/system/vm/debug.scm (find-debug-context): Allow for the
  possibility of there being no ELF image.
  (find-program-debug-info, find-program-arities)
  (program-minimum-arity, find-program-docstring)
  (find-program-properties, find-source-for-addr)
  (find-program-die, find-program-sources): Don't bail if we couldn't
  get the debug context.

* module/system/vm/frame.scm (frame-next-source)
  (frame-call-representation): Allow RTL programs.

* module/system/vm/program.scm (program-arguments-alist): Placeholder
  implementation for RTL programs.
  (program-arguments-alists): Don't bail if we couldn't get the
  arities.
2013-10-04 19:55:12 +02:00
Andy Wingo
e9588e7032 Disassembling RTL prints source information.
* module/system/vm/disassembler.scm (disassemble-buffer): Print source
  information.
2013-10-04 15:28:40 +02:00
Andy Wingo
b43e81dc60 anonymous RTl functions print with source info
* module/system/vm/debug.scm (find-program-sources): If there is no
  source location before the low-pc of the procedure we're grovelling
  for, we were skipping the source loc info.  Fix that.

* module/system/vm/program.scm (write-program): Get source info for
  anonymous RTL functions.
  (program-sources, program-sources-pre-retire): Provide program
  counters relative to the beginning of the procedure.
2013-10-03 22:48:17 +02:00
Andy Wingo
7c54029740 program-source / program-sources works with RTL programs
* libguile/programs.c (scm_program_sources): Define as %program-sources,
  and let Scheme export the program-sources proper.
  (scm_program_source): Call out to Scheme.

* module/system/vm/program.scm: Convert to use match instead of pmatch.
  Adapt existing callers.
  (program-sources, program-source): New Scheme implementations of these
  functions.
  (program-sources-pre-retire): Add RTL program case.
2013-10-03 22:31:37 +02:00
Andy Wingo
c0ada5a766 Add (system vm debug) interface to source location information
* module/system/vm/debug.scm (<source>, source-pre-pc)
  (source-post-pc, source-file, source-line, source-column)
  (source-line-for-user): New data type for source location
  information.
  (find-source-for-addr, find-program-sources): New procedures to get
  source location information for a particular address.
2013-10-03 16:14:29 +02:00
Andy Wingo
1ed81e0229 Add interface to read .debug_line data
* module/system/vm/dwarf.scm (die-line-prog):
  (line-prog-advance, line-prog-scan-to-pc): New public interfaces,
  allowing clients to interpret the "statement programs" from
  .debug_line DWARF sections.
  (<meta>, elf->dwarf-context): Record the bounds of the .debug_line
  section.
2013-10-03 16:14:25 +02:00
Andy Wingo
d56ab5a913 Serialize source positions into .debug_line
* module/system/vm/assembler.scm (link-debug): Generate a correct DWARF2
  line program.  Tests come next.
2013-10-03 16:14:20 +02:00
Andy Wingo
0a7340ac98 Emit a placeholder .debug_line section.
* module/system/vm/assembler.scm (link-debug): Emit a .debug_line
  section also.
  (link-objects): Expect .debug_line.
2013-09-30 21:49:12 +02:00
Andy Wingo
e675e9bd39 Add new "source" macro instruction; compile-rtl emits it.
* module/system/vm/assembler.scm (<asm>): Add "sources" field.
  (make-assembler): Adapt to make-asm change.
  (source): New macro assembler.

* module/language/cps/compile-rtl.scm (emit-rtl-sequence):
  (compile-fun): Emit source instructions as appropriate.
2013-09-30 21:48:07 +02:00
Andy Wingo
6371e368e6 DWARF linker: encode strings using the correct form
* module/system/vm/assembler.scm (link-debug): Encode strings using the
  strp form.
2013-09-28 18:15:50 +02:00
Andy Wingo
a862d8c138 Emit minimal DWARF information
* module/system/vm/assembler.scm (link-debug): New function, creates the
  necessary DWARF debugging sections.
  (link-objects): Emit debugging sections.
2013-09-28 14:50:48 +02:00
Andy Wingo
35558f75f8 add DWARF parser
* module/Makefile.am:
* module/system/vm/dwarf.scm: New module, a DWARF parser.
2013-09-28 14:41:08 +02:00