public inbox for cgen@sourceware.org
 help / color / mirror / Atom feed
* Couple of newbie questions
@ 2000-12-20  5:34 Richard Sandiford
  2000-12-20  8:15 ` Doug Evans
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Sandiford @ 2000-12-20  5:34 UTC (permalink / raw)
  To: cgen

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"))


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Couple of newbie questions
  2000-12-20  5:34 Couple of newbie questions Richard Sandiford
@ 2000-12-20  8:15 ` Doug Evans
  0 siblings, 0 replies; 2+ messages in thread
From: Doug Evans @ 2000-12-20  8:15 UTC (permalink / raw)
  To: Richard Sandiford; +Cc: cgen

Richard Sandiford writes:
 > I'm trying to learn CGEN by doing a mini 6502 port (yes, really).

Cool.  After that could you do an 1802 port?  That was my first.

 > 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!

I originally had the macro expander re-evaluate the symbol
in the car position to see if it was another macro name.
cgen worked this way for a long time but in the end the implementation
got too complicated for my tastes and I'd rather not go back.

.expand may be a reasonable way to do this.
Maybe the name .eval is a better one, though it is already
taken (arguably for something dubious).

 > 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?

In and of itself, changing the get/put value routines to support
24 bits is ok by me.

 > 
 > 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"))
 > 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-12-20  8:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-20  5:34 Couple of newbie questions Richard Sandiford
2000-12-20  8:15 ` Doug Evans

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).