Couple of newbie questions
Richard Sandiford
rsandifo@cambridge.redhat.com
Wed Dec 20 05:34:00 GMT 2000
Hi,
I'm trying to learn CGEN by doing a mini 6502 port (yes, really).
I have a couple of questions...
1)
In a define-pmacro, is there a way of using .sym to create a symbol
name and then look it up as another pmacro? I want to do something
like:
(define-pmacro (create-insn MODE)
(... (.expand foo- MODE) ... (.expand bar- MODE) ...))
where (create-insn immediate) would cause the definitions of
"foo-immediate" and "bar-immediate" to be substituted. I ended up adding
a new command to do this (patch attached in case anyone's interested).
But please tell me if it's already supported in some other way!
2)
What are the requirements for CGEN_INT_INSN_P? All the 6502
instructions fit into 24 bits, so the macro is defined to be "1".
But cgen_get_insn_value() and cgen_put_insn_value() seem to expect
instructions to be 8, 16 or 32 bits wide. Is this a common
assumption, or would it be safe to just change those two to
support 24 bits? Or would it better to change the condition
for setting CGEN_INT_INSN_P?
Thanks,
Richard
-------------
Index: pmacros.scm
===================================================================
RCS file: /cvs/cvsfiles/devo/cgen/pmacros.scm,v
retrieving revision 1.28
diff -c -r1.28 pmacros.scm
*** pmacros.scm 2000/07/27 04:53:32 1.28
--- pmacros.scm 2000/12/20 11:47:04
***************
*** 494,499 ****
--- 494,513 ----
(apply map (cons transformer (cons arg1 arg-rest))))
)
+ ; .expand
+
+ (define -pmacro-expand-command
+ (lambda args
+ (let* ((name (apply -pmacro-sym args))
+ (pmacro (-pmacro-lookup name)))
+ (if (not (-pmacro? pmacro))
+ (-pmacro-error "not a pmacro" name))
+ (let ((transformer (-pmacro-transformer pmacro)))
+ (cond ((procedure? transformer)
+ pmacro)
+ (else transformer)))))
+ )
+
; .apply
(define (-pmacro-apply pmacro arg-list)
***************
*** 546,551 ****
--- 560,568 ----
(-pmacro-make '.map '(macro-name arg1 . arg-rest) #f
-pmacro-map
"map a macro over a list of arguments"))
+ (-pmacro-set! '.expand
+ (-pmacro-make '.expand 'symbols #f -pmacro-expand-command
+ "the macro corresponding to a synthetic name"))
(-pmacro-set! '.apply
(-pmacro-make '.apply '(macro-name arg-list) #f -pmacro-apply
"apply a macro, taking arguments from a list"))
More information about the Cgen
mailing list