treecc help required

Gomi Kapoor <gomikapoor-/[email protected]> Wed, 29 Dec 2004 02:36:56 +0000 (GMT)
Newsgroups gmane.comp.gnu.dotgnu.developer
Message-ID <[email protected]>
Oops! forgot to attach the files...
Please find them attached now (hopefully)
 
Hi Rhys and all,
 I have read the treecc manual and trying to
 implement  a small compiler using it (for learning 
 purposes). The IR which I want to implement is 
 discussed in the first few pages in this report
 (especially page 10 and page 12):
 From Quads to Graphs: An Intermediate
Representation's Journey
 http://citeseer.ist.psu.edu/click93from.html
 
 I have just started implementing a bit of it and you
 can find the attached *.tc files and the main files.
 For running the files:
 bash$ treecc Inst.tc
 bash$ gcc -g Inst.c main.c
 bash$ ./a.out
 
 One major issue which I faced coming with this
 simple  implementation is casting between 
 Instruction* and other derived nodes. 
 I found that casting  between them to be very
tedious.
 I feel that I am  doing a basic mistake in using 
 treecc. Would you  mind commenting on the way I have 
 (mis)used in the attached  simple implementation.
 
 Thanks in advance.
 
 Regards,
 Gomi

________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony

_______________________________________________
Developers mailing list
[email protected]
http://dotgnu.org/mailman/listinfo/developers
Inst.tc (application/octet-stream, 3.3 KB) - not displayed
Type.tc (application/octet-stream, 189 B) - not displayed
main.c (application/octet-stream, 631 B)
#include "Inst.h"
int main()
{
	Instruction *inst,*x,*y,*next;
	BlockBegin* bbegin;
	Block* b;
	BlockList* blist;

	bbegin = (BlockBegin*)BlockBegin_create(NULL,0);
	b = (Block*)Block_create(NULL,bbegin);
	next = (Instruction*)bbegin;	

	inst = BlockEnd_create(NULL);
	b->_end = (BlockEnd*)inst;
	next = SetNext(next,inst);

	blist = (BlockList*)BlockList_create(NULL,b);

	next = (Instruction*)bbegin;	
	x = (Instruction*)IntConstant_create(NULL,10);
	y = (Instruction*)IntConstant_create(NULL,20);
	inst = Optimize(ArithOp_create(NULL,Add,x,y));
	next = SetNext(next,inst);

	PrintInstruction((Instruction*)blist);

	return 0;
}