summaryrefslogtreecommitdiff
path: root/module/language/assembly/decompile-bytecode.scm
AgeCommit message (Collapse)AuthorFilesLines
2013-11-08Remove assembly language.Andy Wingo1-144/+0
* 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-01-14case-lambda* clauses fail to match if too many positionalsAndy Wingo1-2/+12
* doc/ref/api-procedures.texi (Case-lambda): Expand case-lambda* documentation. * module/ice-9/eval.scm (primitive-eval): * libguile/eval.c (prepare_boot_closure_env_for_apply): Dispatch to the next case-lambda clause if there are too many positionals. * doc/ref/vm.texi (Function Prologue Instructions): * libguile/vm-i-system.c (bind-optionals/shuffle-or-br): New instruction, like bind-optionals/shuffle but can dispatch to the next clause if there are too many positionals. * module/language/assembly/disassemble.scm (code-annotation): * module/language/assembly/decompile-bytecode.scm (decode-load-program): * module/language/assembly/compile-bytecode.scm (compile-bytecode): Add case for bind-optionals/shuffle-or-br. * module/language/glil/compile-assembly.scm (glil->assembly): If there is an alternate, use bind-optionals/shuffle-or-br instead of bind-optionals/shuffle. * test-suite/tests/optargs.test ("case-lambda*"): Add tests.
2010-06-01rename (rnrs bytevector) to (rnrs bytevectors)Andy Wingo1-1/+1
* module/rnrs/bytevectors.scm: Rename to (rnrs bytevectors), from (rnrs bytevector), to match the name from the R6RS. * benchmark-suite/benchmarks/bytevectors.bm: * doc/ref/api-data.texi: * doc/ref/api-foreign.texi: * libguile/bytevectors.c: * module/6/rnrs.scm: * module/language/assembly.scm: * module/language/assembly/compile-bytecode.scm: * module/language/assembly/decompile-bytecode.scm: * module/language/glil/compile-assembly.scm: * module/language/tree-il/primitives.scm: * module/srfi/srfi-4.scm: * module/srfi/srfi-4/gnu.scm: * module/system/foreign.scm: * test-suite/standalone/test-ffi: * test-suite/tests/asm-to-bytecode.test: * test-suite/tests/bytevectors.test: * test-suite/tests/foreign.test: * test-suite/tests/r6rs-ports.test: Update all referrers.
2010-02-19prompt handlers are always inlineAndy Wingo1-2/+2
* libguile/control.h (SCM_F_PROMPT_INLINE, SCM_PROMPT_INLINE_P): Remove; prompts always have "inline" handlers now. * libguile/control.c (scm_c_make_prompt): Remove inline_handler_p arg. * libguile/vm-i-system.c (prompt): * module/language/assembly/decompile-bytecode.scm (decode-load-program): * module/language/assembly/compile-bytecode.scm (write-bytecode): Adapt to prompt changes. * module/language/glil.scm (make-glil-prompt, glil-prompt-inline?): Remove inline? flag. (parse-glil, unparse-glil): * module/language/glil/compile-assembly.scm (glil->assembly): Adapt to <glil-prompt> change. * module/language/tree-il/compile-glil.scm (flatten): Require the handler of a <prompt> to be a lambda-case. * module/language/tree-il/primitives.scm (*primitive-expand-table*): Ensure that the handler of a <prompt> is a lambda-case. * module/language/tree-il/inline.scm (inline!): Simplify a degenerate case: (lambda args (apply (lambda ...) args)) => (lambda ...).
2010-01-31GLIL and assembly support for prompt compilationAndy Wingo1-1/+3
* module/language/glil/compile-assembly.scm (glil->assembly): Compile <glil-prompt> appropriately. * module/language/assembly/disassemble.scm (code-annotation): * module/language/assembly/decompile-bytecode.scm (decode-load-program): * module/language/assembly/compile-bytecode.scm (write-bytecode): Assemble and disassemble `prompt' appropriately.
2009-10-28Fix incorrect display of wide strings in decompilationMichael Gran1-1/+1
A byte ordering error caused incorrect display of wide strings when using the ",c" decompilation from the REPL. * module/language/assembly/decompile-bytecode.scm (decode-bytecode): wide strings are encoded in native endianness
2009-10-25assembly/disassembly support for br-if-nargs-*Andy Wingo1-0/+4
* module/language/assembly/compile-bytecode.scm (write-bytecode): Handle br-if-nargs compilation. * module/language/assembly/decompile-bytecode.scm (decode-load-program): And decompile them nicely as well. * module/language/assembly/disassemble.scm (code-annotation): And, present the disassembly if br-if-nargs-* nicely.
2009-10-23de-nargs struct scm_objcode; procedure-property refactorAndy Wingo1-6/+2
* libguile/objcodes.h (struct scm_objcode): Remove nargs, nrest, and nlocs, as they are no longer needed. Also obviates the need for a padding word. * libguile/procs.c (scm_thunk_p): Use scm_i_program_arity for programs. * libguile/procprop.c (scm_i_procedure_arity): Use scm_i_program_arity for programs. (scm_procedure_properties, scm_set_procedure_properties_x) (scm_procedure_property, scm_set_procedure_property_x): Rework so that non-closure properties are stored directly in a weak hash, instead of needing a weak hash of "stand-in" closures to hold the properties. Fix docstrings also. * libguile/root.h (scm_stand_in_procs): Remove from the scm_sys_protects set. Actually with libGC, we should be able to store the elements of scm_sys_protects directly as global variables. * libguile/gc.c (scm_init_storage): Remove scm_stand_in_procs initialization. * libguile/programs.c (scm_i_program_arity): New private accessor, tries to determine the "minimum arity" of a program. * libguile/vm.c (really_make_boot_program): Adapt to changes in struct scm_objcode. * module/language/assembly.scm (*program-header-len*, byte-length): * module/language/assembly/compile-bytecode.scm (write-bytecode): * module/language/assembly/decompile-bytecode.scm (decode-load-program): * module/language/assembly/disassemble.scm (disassemble-load-program): Adapt to changes in objcode. * module/system/xref.scm (program-callee-rev-vars): Adapt to changes in assembly. * module/language/glil.scm: Remove nargs, nrest, and nlocs from glil-program. * module/language/glil/compile-assembly.scm (make-meta, glil->assembly): * module/language/glil/decompile-assembly.scm (decompile-toplevel): (decompile-load-program): Adapt to changes in GLIL and assembly. * module/language/tree-il/compile-glil.scm (flatten-lambda): Adapt to changes in GLIL. * test-suite/tests/asm-to-bytecode.test: Adapt to assembly and bytecode changes. * test-suite/tests/tree-il.test: Adapt to GLIL changes.
2009-10-22Fix bytecode disassembler.Ludovic Courtès1-1/+1
* module/language/assembly/decompile-bytecode.scm (decode-load-program): Add missing argument to `ensure-label'.
2009-10-16jumps encoded using 24 bits, not 19; blocks no longer alignedAndy Wingo1-10/+9
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump. * libguile/vm-i-system.c (FETCH_OFFSET, BR): Labels are no longer 8-byte aligned; instead, jumps are encoded into 3 bytes instead of 2. (br, br-if, br-if-not, br-if-eq, br-if-not-eq, br-if-null) (br-if-not-null, mv-call): Adapt for new length of br instructions (3 bytes instead of 2). * libguile/vm.c (really_make_boot_program): Adapt hand-coded bytecode for new offset regime. * module/language/assembly.scm (align-block): No alignment necessary. * module/language/assembly/compile-bytecode.scm (write-bytecode): Write out breaks as 24-bit relative jumps. * module/language/assembly/decompile-bytecode.scm (decode-load-program): Decompile break instructions.
2009-09-21Remove unused variables in system/language.Ludovic Courtès1-2/+1
* module/language/assembly.scm (byte-length): Don't match unused record slots. * module/language/tree-il.scm (tree-il->scheme, post-order!, pre-order!): Likewise. * module/language/tree-il/analyze.scm (analyze-lexicals): Likewise. * module/language/tree-il/compile-glil.scm (flatten): Likewise. * module/language/assembly/disassemble.scm (disassemble-load-program): Don't match unused list elements. * module/language/glil/decompile-assembly.scm (decompile-toplevel, decompile-load-program): Likewise. * module/system/xref.scm (program-callee-rev-vars): Likewise. * module/language/assembly/compile-bytecode.scm (write-bytecode)[write-sized-loader]: Remove. * module/language/assembly/decompile-bytecode.scm (decode-load-program): Factorize `pad' variables. * module/language/ecmascript/base.scm (object->value/string, object->value/number)[v]: Remove. * module/language/ecmascript/tokenize.scm (read-slash)[c0]: Remove. * module/language/objcode/spec.scm (decompile-value)[nargs]: Remove. * module/system/repl/command.scm (time)[vms-start, vms-end]: Remove. * module/system/repl/repl.scm (prompting-meta-read): Use `prompt'.
2009-08-12rework the vm support for wide stringsAndy Wingo1-21/+6
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump. * libguile/vm-engine.c (vm_error_bad_wide_string_length): New error case. * libguile/vm-i-loader.c (load-unsigned-integer, load-integer) (load-keyword): Remove these instructions. The former two are obsoleted by make-int64/make-uint64, the latter via make-keyword. (load-string): Only handle narrow strings. (load-symbol): Only handle narrow symbols. The wide case is handled via make-symbol. (load-wide-string): New instruction, for wide strings. * libguile/vm-i-system.c (define): Move here from loaders.c, as now it just takes a sym on the stack. (make-keyword, make-symbol): New instructions. * module/language/assembly.scm: Remove removed instructions. No more width byte in load-string etc. * module/language/assembly/compile-bytecode.scm (write-bytecode): Adapt to change in instruction set. * module/language/glil/compile-assembly.scm (glil->assembly): Compile define by pushing the sym then emitting (define). (dump-object): Dump narrow and wide strings differently. Use make-keyword and make-symbol as appropriate. * module/language/tree-il/compile-glil.scm (flatten): When compiling a ref to a primitive (not a call), first see if the primitive is actually bound in the root module. (That's not the case with e.g. bytevector-u8-ref). * module/system/xref.scm (program-callee-rev-vars): Don't parse out "nexts". * test-suite/tests/asm-to-bytecode.test ("compiler"): Adapt to bytecode format change.
2009-08-12Fix disassembly of strings and symbolsMichael Gran1-2/+22
* module/language/assembly/decompile-bytecode.scm (decode-bytecode): fix disassembly of strings, symbols, keywords, and defines
2009-07-26increase range of relative jumps by aligning blocks to 8-byte boundariesAndy Wingo1-1/+2
* libguile/objcodes.c (OBJCODE_COOKIE): Bump again, as our jump offsets are now multiplied by 8. * libguile/vm-i-system.c (BR): Interpret the 16-bit offset as a relative jump to the nearest 8-byte-aligned block -- increasing relative jump range from +/-32K to +/-240K. (mvra): Do the same for the mvra jump. * libguile/vm.c (really_make_boot_program): Align the mvra. * module/language/assembly.scm (align-block): New export, for aligning blocks. * module/language/assembly/compile-bytecode.scm (write-bytecode): Emit jumps to the nearest 8-byte-aligned block. Effectively our range is 18 bits in either direction. I would like to do this differently -- have long-br and long-br-if, and all the other br instructions go to 8 bits only. But the assembler doesn't have an appropriate representation to allow me to do this yet, so for now this is what we have. * module/language/assembly/decompile-bytecode.scm (decode-load-program): Decode the 19-bit jumps.
2009-07-26make sure all programs are 8-byte alignedAndy Wingo1-0/+1
* libguile/objcodes.c (OBJCODE_COOKIE): Bump objcode cookie, as we added to struct scm_objcode. * libguile/objcodes.h (struct scm_objcode): Add a uint32 after metalen and before base, so that if the structure has 8-byte alignment, base will have 8-byte alignment too. (Before, base was 12 bytes from the start of the structure, now it's 16 bytes.) * libguile/vm-engine.h (ASSERT_ALIGNED_PROCEDURE): Add a check that can be turned on with VM_ENABLE_PARANOID_ASSERTIONS. (CACHE_PROGRAM): Call ASSERT_ALIGNED_PROCEDURE. * libguile/vm-i-system.c (long-local-ref): Add a missing semicolon. * libguile/vm.c (really_make_boot_program): Rework to operate directly on a malloc'd buffer, so that the program will be 8-byte aligned. * module/language/assembly.scm (*program-header-len*): Add another 4 for the padding. (object->assembly): Fix case in which we would return (make-int8 0) instead of (make-int8:0). This would throw off compile-assembly.scm's use of addr+. * module/language/assembly/compile-bytecode.scm (write-bytecode): Write out the padding int. * module/language/assembly/decompile-bytecode.scm (decode-load-program): And pop off the padding int too. * module/language/glil/compile-assembly.scm (glil->assembly): Don't pack the assembly, assume that assembly.scm has done it for us. If a program has a meta, pad out the program so that meta will be aligned. * test-suite/tests/asm-to-bytecode.test: Adapt to expect programs to have the extra 4-byte padding int.
2009-07-24nlocs is now 16 bits wideAndy Wingo1-1/+3
* libguile/objcodes.h (struct scm_objcode): Remove the "unused" field -- the old "nexts" -- and expand nlocs to 16 bits. * module/language/assembly/compile-bytecode.scm (write-bytecode): Write the nlocs as a uint16. * module/language/assembly/decompile-bytecode.scm (decode-load-program): Decompile 16-bit nlocs. It seems this decompilation is little-endian :-/ * test-suite/tests/asm-to-bytecode.test: Fix up to understand nlocs as a little-endian value. The test does the right thing regarding endianness.
2009-07-23remove all mentions of "external" from the compiler and related codeAndy Wingo1-3/+3
With this, GHIL is effectively bitrotten. I need to port the ECMAScript compiler to tree-il, then I'll remove it. * module/language/assembly.scm (byte-length): * module/language/assembly/compile-bytecode.scm (write-bytecode): * module/language/assembly/decompile-bytecode.scm (decode-load-program): * module/language/assembly/disassemble.scm (disassemble-load-program): (disassemble-free-vars, code-annotation): * module/language/glil.scm (<glil-program>, <glil-local>) (<glil-exteral>, parse-glil, unparse-glil): * module/language/glil/compile-assembly.scm (make-meta): (compile-assembly, glil->assembly): * module/language/glil/decompile-assembly.scm (decompile-toplevel): (decompile-load-program): * module/language/objcode/spec.scm (decompile-value): * module/language/tree-il/compile-glil.scm (flatten-lambda): * module/system/vm/frame.scm (frame-binding-ref): (frame-binding-set!): * module/system/vm/program.scm (binding:boxed?): * module/system/vm/trace.scm (trace-next): * test-suite/tests/asm-to-bytecode.test ("compiler"): * test-suite/tests/tree-il.test: Remove all mentions of "external", and of <glil-local>. Docs updates will come soon.
2009-06-19Fix decompilation of the `load-array' instruction.Ludovic Courtès1-4/+15
This allows, e.g., ",c #u8(1 2 3)" at the REPL to actually work instead of failing to decode `load-array'. * module/language/assembly/decompile-bytecode.scm (decode-bytecode): Account for the `load-array' instruction, which is followed by a bytevector instead of a string. We should find a more elegant way to do that.
2009-06-17Change Guile license to LGPLv3+Neil Jerram1-14/+13
(Not quite finished, the following will be done tomorrow. module/srfi/*.scm module/rnrs/*.scm module/scripts/*.scm testsuite/*.scm guile-readline/* )
2009-03-17parse jumps as labels when decompiling bytecode->assemblyAndy Wingo1-3/+28
* module/language/assembly/decompile-bytecode.scm (decode-load-program): Parse out jumps as labels.
2009-02-01fix the disassembler for load-string, load-symbol et alAndy Wingo1-1/+2
* module/language/assembly/decompile-bytecode.scm (decode-bytecode): Fix decoding of lengths in loader instructions.
2009-02-01add code for writing out metadata to the end of a programAndy Wingo1-5/+6
* libguile/objcodes.c (make_objcode_by_mmap, scm_c_make_objcode_slice): Verify the lengths with the meta-length. (scm_objcode_meta): New procedure, for getting at the meta-info of an objcode. (scm_objcode_to_bytecode): (scm_write_objcode): Write bytecode with the metadata too. * module/system/vm/objcode.scm: Export object-meta. * module/language/assembly.scm (byte-length): * module/language/assembly/compile-bytecode.scm (write-bytecode): * module/language/assembly/decompile-bytecode.scm (decode-load-program): * module/language/assembly/disassemble.scm (disassemble-load-program): * module/language/glil/compile-assembly.scm (glil->assembly): * test-suite/tests/asm-to-bytecode.test ("compiler"): Change to load-program format to have meta-or-#f instead of meta-length, so that we can serialize the meta as objcode without a load-program byte. Add a test for writing out the meta.
2009-02-01add metalen field to bytecode serializationAndy Wingo1-5/+8
* libguile/objcodes.h (struct scm_objcode): Add a new field, metalen, in preparation for embedding metadata within a program. (SCM_OBJCODE_META_LEN, SCM_OBJCODE_TOTAL_LEN): New defines. * libguile/vm.c (really_make_boot_program): * module/language/assembly.scm (*program-header-len*, byte-length): * module/language/assembly/compile-bytecode.scm (write-bytecode): * module/language/assembly/decompile-bytecode.scm (decode-load-program): * module/language/assembly/disassemble.scm (disassemble-load-program): * module/language/glil/compile-assembly.scm (glil->assembly): * test-suite/tests/asm-to-bytecode.test ("compiler"): Update for metalen addition.
2009-01-30add decompilers that can take us back to assemblyAndy Wingo1-0/+85
* module/language/assembly/Makefile.am: * module/language/assembly/spec.scm: * module/language/assembly/decompile-bytecode.scm: Add a bytecode decompiler. Neat! * module/language/bytecode/spec.scm (decompile-objcode): * module/language/objcode/spec.scm (decompile-value): Add some "decompilers" here too. * module/system/base/compile.scm (current-language): Since we can refer to languages by name, do so here -- removes the previous anti-circularity hack. (compile-file, compile): Refer to target languages by name. (decompile): New public function. Neat! * module/system/base/language.scm (lookup-decompilation-order): Fix so we look for decompilers with the high-level language definition.