From mboxrd@z Thu Jan 1 00:00:00 1970 From: Doug Evans To: Richard Sandiford Cc: cgen@sources.redhat.com Subject: Couple of newbie questions Date: Wed, 20 Dec 2000 08:15:00 -0000 Message-id: <14912.56094.34354.944235@casey.transmeta.com> References: X-SW-Source: 2000-q4/msg00285.html 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")) >