Posts

Showing posts with the label A Register Allocation algorithm that translates the given code into one with a fixed number of registers.

A Register Allocation algorithm that translates the given code into one with a fixed number of registers.

//C code for  A Register Allocation algorithm that translates the given code into one with a fixed number of registers. #include<stdlib.h> #include<stdio.h> /* We will implement DAG as Strictly Binary Tree where each node has zero or two children */ struct bin_tree { char data; int label; struct bin_tree *right, *left; }; typedef struct bin_tree node; /* R is stack for storing registers */ int R[10]; int top; /* op will be used for opcode name w.r.t. arithmetic operator e.g. ADD for + */ char *op; /* insertnode() and insert() functions are for adding nodes to tree(DAG) */void insertnode(node **tree,char val) { node *temp = NULL; if(!(*tree)) { temp = (node *)malloc(sizeof(node)); temp->left = temp->right = NULL; temp->data = val; temp->label=-1; *tree = temp; } } void insert(node **tree,char val) { char l,r; int numofchildren; insertnode(tree, val); printf("\nEnter number of children of %c:",val); scanf("%d...