[llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/Makefile boolean.h constants.h convert.c convert.h load.c load.h memory.c memory.h pass1.c pass1.h pass2.c pass2.h print.c print.h stringI.c stringI.h sym_tab.c sym_tab.h

Chris Lattner lattner at cs.uiuc.edu
Tue Oct 5 14:12:03 PDT 2004



Changes in directory llvm-test/MultiSource/Benchmarks/Prolangs-C/loader:

Makefile added (r1.1)
boolean.h added (r1.1)
constants.h added (r1.1)
convert.c added (r1.1)
convert.h added (r1.1)
load.c added (r1.1)
load.h added (r1.1)
memory.c added (r1.1)
memory.h added (r1.1)
pass1.c added (r1.1)
pass1.h added (r1.1)
pass2.c added (r1.1)
pass2.h added (r1.1)
print.c added (r1.1)
print.h added (r1.1)
stringI.c added (r1.1)
stringI.h added (r1.1)
sym_tab.c added (r1.1)
sym_tab.h added (r1.1)
---
Log message:

New program, guess what?  No input


---
Diffs of the changes:  (+1457 -0)

Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/Makefile
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/Makefile:1.1
*** /dev/null	Tue Oct  5 16:11:59 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/Makefile	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,6 ----
+ LEVEL = ../../../..
+ 
+ LDFLAGS = -lm
+ PROG = loader
+ include $(LEVEL)/MultiSource/Makefile.multisrc
+ 


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/boolean.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/boolean.h:1.1
*** /dev/null	Tue Oct  5 16:12:02 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/boolean.h	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,6 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ============================= boolean.h ================================= */
+ /* Just makes BOOLEAN another name for int.                                  */
+ typedef int BOOLEAN;


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/constants.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/constants.h:1.1
*** /dev/null	Tue Oct  5 16:12:02 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/constants.h	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,61 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ============================= constants.h =============================== */
+ /* A collection of commonly used constants for the assembler.                */
+ 
+ 
+ /* DEBUG_FLAG_1            Controls whether certain lines of the program.    */
+ /*                         Execution or non-execution of these lines aids in */
+ /*                         Debugging the program.                            */
+ #define DEBUG_FLAG_1            0
+ 
+ /* LABEL_SIZE_1            Size of the largest valid LABEL in characters     */
+ #define LABEL_SIZE_1            8
+ 
+ /* MEM_SIZE_1              Size of SIC/XE main memory in bytes               */
+ /*                         NOTE: 2^20 = 1048576                              */
+ #define MEM_SIZE_1        1048576
+ 
+ /* MEM_ADDR_SIZE_1         Number of BITS in an address {log2(MEM_SIZE_1)}   */
+ #define MEM_ADDR_SIZE_1        20
+ 
+ /* BITS_PER_WORD_1         Number of BITS in a WORD                          */
+ #define BITS_PER_WORD_1        24
+ 
+ /* MAX_INT_1               Biggest integer+1: 2^BITS_PER_WORD_1              */
+ #define MAX_INT_1        16777216
+ 
+ /* BITS_PER_HALFBYTE_1     Number of BITS in a Half BYTE                     */
+ #define BITS_PER_HALFBYTE_1         4
+ 
+ /* BITS_PER_BYTE_2         Number of BITS in a BYTE                          */
+ #define BITS_PER_BYTE_2         8
+ 
+ /* HEX_CHAR_PER_BYTE_1     Number of hexidecimal characters (ASCII) must be  */
+ /*                         used to produce a 1 BYTE value.                   */
+ #define HEX_CHAR_PER_BYTE_1     2
+ 
+ /* LARGEST_INSTRUCT_SIZE_1 Size in BITS of the the largest instruction in    */
+ /*                         SIC/XE. Format 4 is 32 bits                       */
+ #define LARGEST_INSTRUCT_SIZE_1   32
+ 
+ /* MAX_PC_RELATIVE_1       Smallest number that will NOT fit in a PC relative*/
+ /*                         address. {4096 = 2^12}                            */
+ #define MAX_PC_RELATIVE_1    4096
+ 
+ /* GLOBAL_1                Module name for Global labels -- used by LOADER.  */
+ #define GLOBAL_1         "_GLOBAL "
+ 
+ /* -------------------------- Boolean Constants ---------------------------- */
+ #define FALSE_1                 0
+ #define TRUE_1                  1
+ 
+ 
+ /* ------------------- Expression types (LABELS,CONSTANTS,etc) ------------- */
+ #define ABSOLUTE_OR_RELATIVE_1  0    /* Don't know type                      */
+ #define ABSOLUTE_VALUE_1        1    /* Absolute expressions                 */
+ #define RELATIVE_VALUE_1        2    /* Relative expressions                 */
+ #define EXTERN_VALUE_1          3    /* An external reference                */
+ 
+ 


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/convert.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/convert.c:1.1
*** /dev/null	Tue Oct  5 16:12:02 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/convert.c	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,104 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ============================= convert.c ================================= */
+ /* Contains routines that convert one thing to another. Most of the routines */
+ /* deal with converting a number to a string of that number in some base, or */
+ /* converting a string (assuming some base) into an integer. Basically       */
+ /* just a file of miscellaneous 'useful' routines.                           */
+ #include <stdio.h>
+ #include <string.h>
+ #include <math.h>
+ #include "boolean.h"
+ #include "constants.h"
+ 
+ /* ----------------------------- eoln -------------------------------------- */
+ /* true if CH is the End Of LiNe character, otherwise false.                 */
+ BOOLEAN eoln(char CH)
+ {
+   return (CH == '\0');
+ }
+ 
+ /* ------------------------ CHAR_TO_DIGIT ---------------------------------- */
+ /* Convert a character (CH) into its integer value give base NUM_BASE. Return*/
+ /* -1 if it is not a valid digit in that base.                               */
+ int CHAR_TO_DIGIT(char CH,int NUM_BASE)
+ {
+   int DIGIT = -1;
+   if ( (CH >= '0') && (CH <= '9') ) DIGIT = (int) (CH - '0');
+   if ( (CH >= 'A') && (CH <= 'Z') ) DIGIT = ((int) (CH - 'A'))+10;
+   if (DIGIT >= NUM_BASE) DIGIT = -1;
+   return DIGIT;
+ }
+ 
+ 
+ /* ------------------------- NUM_TO_STR ------------------------------------ */
+ /* Put into STR the string with LEN digits that represents the number NUM    */
+ /* in base BASE (eg. NUM_TO_STR(10,16,3,STR) puts "00A" in STR).             */
+ void  NUM_TO_STR(int NUM,int BASE,int LEN,char *STR)
+ {
+   int I;                        /* loop counter                              */
+   int DIGIT;                    /* one digit in base specified of NUM        */
+ 
+   STR[LEN] = '\0';
+   for (I=(LEN-1); I>=0; I--) {
+     DIGIT = NUM - (NUM/BASE) * BASE;
+     NUM /= BASE;
+     if ((DIGIT >= 0) && (DIGIT <= 9))
+       STR[I] = (char) DIGIT + '0';
+     else STR[I] = (char) (DIGIT-10) + 'A';
+   }
+   if (NUM != 0)
+     (void) printf("NUM_TO_STR called illegally.\n");
+ }
+ 
+ /* ------------------------------ GET_NUM ---------------------------------- */
+ /* CURRENT_CHAR points to a string. Starting with the character              */
+ /* **CURRENT_CHAR and get the biggest possible integer in BASE NUM_BASE. If  */
+ /* that number is too large/small to fit in BITS bits (2's complement),      */
+ /* Put an error message into ERROR_REC_BUF. Returns 0 if this or any error is*/
+ /* detected, otherwise it returns the integer representation of the number.  */
+ /* NOTE: If number is to large/small this routine stops as soon as it        */
+ /*   realizes this w/o (with out) looking at the rest of the input.          */
+ int GET_NUM(char **CURRENT_CHAR,int BITS,int NUM_BASE,BOOLEAN *ERROR)
+ {
+   int CONVERT = 0;                /* CONVERT is the converted integer of the */
+                                   /*    string */
+   int MAX_UNSIGNED_INT;           /* MAX_UNSIGNED_INT = 2^BITS               */
+                                   /*    - Biggest biggest number + 1         */
+ 				  /*      (w/o sign) that fits               */
+   int DIGIT;                      /* One digit of the number.                */
+ 
+   MAX_UNSIGNED_INT = (int) pow(2.0,BITS*1.0);
+ 
+ /* ----------------------------- Get the biggest [legal] number you can      */
+   while ( ( (DIGIT = CHAR_TO_DIGIT(**CURRENT_CHAR,NUM_BASE)) != -1) &&
+ 	 !eoln(**CURRENT_CHAR) ) {
+     if (CONVERT <= MAX_UNSIGNED_INT)
+       CONVERT = CONVERT*NUM_BASE + DIGIT;
+     (*CURRENT_CHAR) ++;
+   }
+ 
+   if ( (CONVERT > (MAX_UNSIGNED_INT - 1)) ||
+       (!eoln(**CURRENT_CHAR)) ) (*ERROR) = TRUE_1;
+   
+   return CONVERT;
+ }
+ 
+ /* -------------------------------- STR_TO_NUM ----------------------------- */
+ /* Convert the first DIGITS characters of STR to an integer of base BASE.    */
+ void STR_TO_NUM(char *STR,int DIGITS,int BASE,int *NUM,BOOLEAN *ERROR)
+ {
+   int I;
+   int ONE_DIGIT;
+   BOOLEAN LOCAL_ERROR = FALSE_1;
+ 
+   (*NUM) = 0;
+   for (I = 0; ((I < DIGITS) && !LOCAL_ERROR); I ++)
+     if ( (ONE_DIGIT = CHAR_TO_DIGIT(STR[I],BASE)) == -1)
+       LOCAL_ERROR = TRUE_1;               /* Not a valid number.             */
+     else
+       (*NUM) = (*NUM)*BASE + ONE_DIGIT;
+ 
+   if (LOCAL_ERROR) (*ERROR) = TRUE_1;
+ }


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/convert.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/convert.h:1.1
*** /dev/null	Tue Oct  5 16:12:02 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/convert.h	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,60 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* =============================== convert.h =============================== */
+ /* Contains routines that convert one thing to another. Most of the routines */
+ /* deal with converting a number to a string of that number in some base, or */
+ /* converting a string (assuming some base) into an integer. Basically       */
+ /* just a file of miscellaneous 'useful' routines.                           */
+ 
+ /* ----------------------------- eoln -------------------------------------- */
+ /* true if CH is the End Of LiNe character, otherwise false.                 */
+ /* 1 parameter:                                                              */
+ /*    1) char CH;            Character in question.                          */
+ extern int eoln();
+ 
+ /* ------------------------ CHAR_TO_DIGIT ---------------------------------- */
+ /* 2 parameters:                                                             */
+ /*    1) char CH;                       character to convert                 */
+ /*    2) int NUM_BASE;                  base of number                       */
+ /* Convert a character (CH) into its integer value give base NUM_BASE. Return*/
+ /* -1 if it is not a valid digit in that base.                               */
+ extern int CHAR_TO_DIGIT();
+ 
+ /* ------------------------- NUM_TO_STR ------------------------------------ */
+ /* 4 parameters:                                                             */
+ /*    1) int NUM;                  Number to convert                         */
+ /*    2) int BASE;                 Base to convert into                      */
+ /*    3) int LEN;                  Number of digits in final string          */
+ /*    4) char *STR;                where to put it.                          */
+ /* Put into STR the string with LEN digits that represents the number NUM    */
+ /* in base BASE (eg. NUM_TO_STR(10,16,3,STR) puts "00A" in STR).             */
+ extern void NUM_TO_STR();
+ 
+ /* ------------------------------ GET_NUM ---------------------------------- */
+ /* 4 parameters:                                                             */
+ /*   1) char **CURRENT_CHAR;         pointer to start of string to interpret */
+ /*                                   as an integer (in NUM_BASE)             */
+ /*   2) int BITS;                    Number must fit in this may bits 2's    */
+ /*                                   complement.                             */
+ /*   3) int NUM_BASE;                Base the number is in.                  */
+ /*   4) BOOLEAN *ERROR;              Was an error detected.                  */
+ /* CURRENT_CHAR points to a string. Starting with the character              */
+ /* **CURRENT_CHAR and get the biggest possible integer in BASE NUM_BASE. If  */
+ /* that number is too large/small to fit in BITS bits (2's complement),      */
+ /* Put an error message into ERROR_REC_BUF. Returns 0 if this or any error is*/
+ /* detected, otherwise it returns the integer representation of the number.  */
+ /* NOTE: If number is to large/small this routine stops as soon as it        */
+ /*   realizes this w/o (with out) looking at the rest of the input.          */
+ extern int GET_NUM();
+ 
+ /* -------------------------------- STR_TO_NUM ----------------------------- */
+ /* Convert the first DIGITS characters of STR to an integer of base BASE.    */
+ /* 5 paramaters:                                                             */
+ /*      1) char *STR;             STRing to convert.                         */
+ /*      2) int DIGITS;            number of DIGITS of string to convert.     */
+ /*      3) int BASE;              BASE of the number.                        */
+ /*      4) int *NUM;              Place to return the result                 */
+ /*      5) BOOLEAN *ERROR;        Has an error been detected.                */
+ extern void STR_TO_NUM();
+ 


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/load.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/load.c:1.1
*** /dev/null	Tue Oct  5 16:12:02 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/load.c	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,158 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ============================= load.c ==================================== */
+ /* Main (driving) routine of the loader.                                     */
+ 
+ /* to compile (the loader) use:                                              */
+ /*     cc -o load load.o pass1.o pass2.o convert.o sym_tab.o memory.o        */
+ /*                stringI.o print.o -g -lm                                   */
+        
+ #include <stdio.h>
+ #include <malloc.h>
+ #include <string.h>
+ #include "constants.h"
+ #include "sym_tab.h"
+ #include "boolean.h"
+ #include "convert.h"
+ #include "memory.h"
+ #include "pass1.h"
+ #include "pass2.h"
+ #include "print.h"
+ 
+ /* --------------------------------- Globals ------------------------------ */
+ /* START_ADDRESS                     Start Address for program execution.   */
+ int START_ADDRESS = -1;
+ 
+ /* MAIN_ROUTINE                      Name of (program) module declared with */
+ /*                                      a START (main routine).             */
+ char MAIN_ROUTINE[LABEL_SIZE_1+1];
+ 
+ /* -------------------------------- main ---------------------------------- */
+ void main(int argc,char **argv)
+ {
+   FILE *INPUT_STREAM;             /* Input file stream                      */
+   SYMBOL_TABLE SYM_TAB;           /* The symbol table                       */
+   BOOLEAN ERROR = FALSE_1;        /* FALSE no errors seen. TRUE seen errors */
+   int LOCATION = 0;               /* LOCATION in memory to load the next    */
+                                   /*    module into.                        */
+   int START_LOCATION;             /* LOCATION in memory to load the FIRST   */
+                                   /*    module.                             */
+   char *EXECUTABLE_FILE;          /* Name of file to put the executable into*/
+   FILE *EXECUTABLE_STREAM;        /* Stream for executable file             */
+   char *MEM_DUMP_FILE;            /* Name of file to put memory dump into   */
+   FILE *MEM_DUMP_STREAM;          /* Stream for memory dump file            */
+   char *SYM_TAB_DUMP_FILE;        /* Name of file to put sym. table into    */
+   FILE *SYM_TAB_DUMP_STREAM;      /* Stream for symbol table dump file      */
+   int LOOP_COUNTER;               /* a loop counter                         */
+   MEM_SPACE MEMORY = NULL;        /* The Main Memory.                       */
+   int FILES_START;                /* Where in the list of arguments do the  */
+                                   /*    files start.                        */
+ 
+   if (argc == 1) (void) printf("usage:  load [-l location] file ...\n");
+   else {
+     int ARGUMENT = 1;             /* Which argument of the command line     */
+                                   /* currently processing.                  */
+     BOOLEAN FLAG;                 /* Just a temporary boolean.              */
+ 
+ /* --------------------------------- Process command directives             */
+     if (ARGUMENT < argc) FLAG = (argv[ARGUMENT][0] == '-');
+     while ( (ARGUMENT < argc) && FLAG) {
+       if (!strcmp(argv[ARGUMENT],"-l")) {
+ 	BOOLEAN NOT_LEGAL_NUM = FALSE_1;
+ 
+ 	ARGUMENT ++; 
+ 	if (ARGUMENT < argc) {
+ 	  char *NEXT;
+ 
+ 	  NEXT = argv[ARGUMENT];
+ 	  LOCATION = GET_NUM(&NEXT,MEM_ADDR_SIZE_1,10,
+ 			     &NOT_LEGAL_NUM);
+ 	  if (NOT_LEGAL_NUM) 
+     (void) printf("load: %s is not a legal starting address. Starting at %d\n",
+ 		  argv[ARGUMENT], LOCATION);
+ 	} else 
+    (void) printf("load: -l must be followed by a location. Starting at %d\n",
+ 		 LOCATION);
+ 
+       } else
+ 	  (void) printf("Illegal command directive, '%s'. Ignoring.\n",
+ 			argv[ARGUMENT]);
+       if (ARGUMENT < argc) ARGUMENT ++;
+       if (ARGUMENT < argc) FLAG = (argv[ARGUMENT][0] == '-');
+     }
+ 
+     if (ARGUMENT < argc) {
+ /* --------------------------------- Get name for output files               */
+       EXECUTABLE_FILE = malloc((unsigned int) (strlen(argv[ARGUMENT])+5));
+       MEM_DUMP_FILE = malloc((unsigned int) (strlen(argv[ARGUMENT])+5));
+       SYM_TAB_DUMP_FILE = malloc((unsigned int) (strlen(argv[ARGUMENT])+5));
+       (void) strcpy(EXECUTABLE_FILE,argv[ARGUMENT]);
+       (void) strcpy(MEM_DUMP_FILE,argv[ARGUMENT]);
+       (void) strcpy(SYM_TAB_DUMP_FILE,argv[ARGUMENT]);
+       for ((LOOP_COUNTER = strlen(argv[ARGUMENT]));
+ 	   ( (LOOP_COUNTER >= 0) && (EXECUTABLE_FILE[LOOP_COUNTER] != '.'));
+ 	   LOOP_COUNTER --);
+       if (LOOP_COUNTER <= 0) LOOP_COUNTER = strlen(argv[ARGUMENT]);
+       (void) strcpy(&(EXECUTABLE_FILE[LOOP_COUNTER]),".exe");
+       (void) strcpy(&(MEM_DUMP_FILE[LOOP_COUNTER]),".mem");
+       (void) strcpy(&(SYM_TAB_DUMP_FILE[LOOP_COUNTER]),".sym");
+ 
+     } else
+       (void) printf("load: requires at least one file name.\n");
+ 
+ 
+     INIT_SYM_TAB(&SYM_TAB);         /* Initialize the symbol table           */
+     CREATE_MEMORY(&MEMORY);         /* Create/initialize the main memory.    */
+ /* ============================== PASS1 ==================================== */
+     FILES_START = ARGUMENT;
+     START_LOCATION = LOCATION;
+     while ( (ARGUMENT < argc) && (LOCATION <= MEM_SIZE_1)) {
+       if ( (INPUT_STREAM = fopen(argv[ARGUMENT],"r")) == NULL) {
+ 	(void) printf("%s: No such file or directory\n",argv[ARGUMENT]);
+       } else {
+ /* --------------------------------- Have a valid file: load it              */
+ 	PASS1(&SYM_TAB,&LOCATION,&ERROR,INPUT_STREAM);
+ 	(void) fclose(INPUT_STREAM);
+       }
+       ARGUMENT ++;
+     }
+ 
+ /* ============================== PASS2 ==================================== */
+     ARGUMENT = FILES_START;
+     LOCATION = START_LOCATION;
+ 
+     while ( (ARGUMENT < argc) && (LOCATION <= MEM_SIZE_1)) {
+       if ( (INPUT_STREAM = fopen(argv[ARGUMENT],"r")) != NULL) 
+ 	{
+ /* --------------------------------- Have a valid file: load it              */
+ 	  PASS2(MEMORY,&SYM_TAB,&LOCATION,&ERROR,INPUT_STREAM);
+ 	  (void) fclose(INPUT_STREAM);
+ 	}
+       ARGUMENT ++;
+     }
+ 
+ 
+     if (START_ADDRESS == -1) {
+       (void) printf(
+           "ERROR: Expected a main routine. None found. Program not loaded.\n");
+       ERROR = TRUE_1;
+     }
+ 
+ /* ================== Output the memory and symbol table to files ========== */
+     SYM_TAB_DUMP_STREAM = fopen(SYM_TAB_DUMP_FILE,"w");
+     PRT_SYM_TAB(SYM_TAB,SYM_TAB_DUMP_STREAM);
+     (void) fclose(SYM_TAB_DUMP_STREAM);
+ 
+     if (!ERROR || DEBUG_FLAG_1) {
+       EXECUTABLE_STREAM = fopen(EXECUTABLE_FILE,"w");
+       MEM_DUMP_STREAM = fopen(MEM_DUMP_FILE,"w");
+       PRINT_MEM(MEMORY,MEM_DUMP_STREAM);
+       PRINT_EXEC(MEMORY,SYM_TAB,EXECUTABLE_STREAM);
+       (void) fclose(EXECUTABLE_STREAM);
+       (void) fclose(MEM_DUMP_STREAM);
+     } else
+       (void) printf("Errors detected. No executable created.\n");
+ 
+   }
+ }


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/load.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/load.h:1.1
*** /dev/null	Tue Oct  5 16:12:03 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/load.h	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,12 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ================================= load.h =============================== */
+ 
+ /* --------------------------------- Globals ------------------------------ */
+ /* START_ADDRESS                     Start Address for program execution.   */
+ int START_ADDRESS;
+ 
+ /* MAIN_ROUTINE                      Name of (program) module declared with */
+ /*                                      a START (main routine).             */
+ char MAIN_ROUTINE[LABEL_SIZE_1+1];


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/memory.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/memory.c:1.1
*** /dev/null	Tue Oct  5 16:12:03 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/memory.c	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,351 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* =============================== memory.c ================================ */
+ /* Contains all the routines that manage the main memory of the SIC/XE       */
+ /* machine.                                                                  */
+ 
+ #include "boolean.h"
+ #include <malloc.h>
+ #include <stdio.h>
+ #include <string.h>
+ #include "constants.h"
+ #include "convert.h"
+ #include "load.h"
+ 
+ /* MEM_SPACE                       The type of a main memory in this program.*/
+ typedef char *MEM_SPACE;
+ 
+ /* ========================== Printing memory constants ==================== */
+ /* BYTES_PER_GROUP                 How many bytes to print out at a time.    */
+ #define BYTES_PER_GROUP                      4
+ /* GROUPS_PER_LINE                 How many groups of bytes to put on one    */
+ /*                                    line*/
+ #define GROUPS_PER_LINE                      4
+ /* LINES_OF_GAP_TO_ELIPSE          How many consequative lines of unchanged  */
+ /*                                    bytes must present to elipse out the   */
+ /*                                    lines from the output.                 */
+ #define LINES_OF_GAP_TO_ELIPSE               3
+ 
+ /* ========== Keeping Track of which locations have been modified ========== */
+ /* Keep a linked list of blocks of memory that have been modified. ONLY      */
+ /* locations that where actually loaded into are included in any block and   */
+ /* locations that where loaded are in some block.                            */
+ 
+ /* BUFFER_ELEMENT                 Type of one block. START of block and it's */
+ /*                                   length. Plus a pointer because a linked */
+ /*                                   list.                                   */
+ struct BUFFER_ELEMENT {
+   int START;                   /* Start of the block.                        */
+   int LENGTH;                  /* Length of the block.                       */
+   struct BUFFER_ELEMENT *NEXT; /* Next block in the linked list.             */
+ };
+ 
+ /* BUFFER                        A record with the first and last element of */
+ /*                                  a lined list.                            */
+ /* LOCATIONS_USED                A BUFFER that contains the modifed locations*/
+ struct BUFFER {
+   struct BUFFER_ELEMENT *HEAD;/* First block of the linked list.             */
+   struct BUFFER_ELEMENT *END; /* Last block of the linked list.              */
+ } LOCATIONS_USED = {NULL,NULL};
+ 
+ /* ---------------------------- ADD_TO_BUFFER (local) ---------------------- */
+ /* Adds a block to the END of the linked list of blocks.                     */
+ void ADD_TO_BUFFER(int LOCATION,int LEN)
+ {
+   if (LOCATIONS_USED.HEAD == NULL) {
+ /* ------------ Add to an empty list.                                        */
+     LOCATIONS_USED.HEAD = (struct BUFFER_ELEMENT *) malloc(sizeof(struct BUFFER_ELEMENT));
+     LOCATIONS_USED.END = LOCATIONS_USED.HEAD;
+   } else {
+ /* ------------ Add to a non-empty list.                                     */
+     (*LOCATIONS_USED.END).NEXT = 
+ 	(struct BUFFER_ELEMENT *) malloc(sizeof(struct BUFFER_ELEMENT));
+     LOCATIONS_USED.END = (*LOCATIONS_USED.END).NEXT;
+   }
+   (*LOCATIONS_USED.END).START = LOCATION;
+   (*LOCATIONS_USED.END).LENGTH = LEN;
+   (*LOCATIONS_USED.END).NEXT = NULL;
+ }
+ 
+ /* ============================= Memory Routines =========================== */
+ 
+ /* --------------------------------- INT  ---------------------------------- */
+ /* Return the integer representation for a character. Had to be written      */
+ /* Because the character 255 (for example) who be treated as the integer -1, */
+ /* but I needed it to be 255.                                                */
+ int INT(char CH)
+ {
+   int I;
+   I = CH;
+ 
+   if (I<0) return (256+I);
+   return (I);
+ }
+ 
+ /* ----------------------------- Create Memory ----------------------------- */
+ /* Create a megabyte of memory and point MEMORY to it. It does not initialize*/
+ /* the memory as this took about 5 minuites. Since the memory was            */
+ /* uninitized I needed another way to know when locations where modified,    */
+ /* thus the above lined list of blocks.                                      */
+ void CREATE_MEMORY(MEM_SPACE *MEMORY)
+ {
+   if ((*MEMORY) != NULL)
+     (void) printf("CREATE_MEMORY called illegally.\n");
+   else (*MEMORY) = malloc((unsigned int) MEM_SIZE_1);
+ }
+ 
+ /* -------------------------- DO_STORE (local) ----------------------------- */
+ /* Place BYTES consequative bytes into MEMORY, starting at ADDRESS.          */
+ void DO_STORE(char *VALUE,int BYTES,int ADDRESS,MEM_SPACE MEMORY,
+               BOOLEAN *ERROR,BOOLEAN BUFFER_Q)
+ {
+   BOOLEAN LOCAL_ERROR = FALSE_1; /* Was an error detected during the store.  */
+   int TEMP;                 /* A loop counter variable.                      */
+   int INT_VAL;              /* Integer representation of one byte of the     */
+                             /*    block.                                     */
+ 
+ /* ---------------------- Check if fits into memory                          */
+   if ( (ADDRESS + BYTES <= MEM_SIZE_1) && (ADDRESS + BYTES >= 0) ) {
+ 
+ /* ---------------------- Remember loaded into this block (if necessary)     */
+     if (BUFFER_Q) ADD_TO_BUFFER(ADDRESS,BYTES);
+ 
+ /* ---------------------- Load each byte into memory                         */
+     for (TEMP = 0; ((TEMP < BYTES) && !eoln(VALUE[TEMP]) && !LOCAL_ERROR);
+ 	 TEMP++) {
+       STR_TO_NUM(&(VALUE[TEMP*HEX_CHAR_PER_BYTE_1]),HEX_CHAR_PER_BYTE_1,
+ 		 16,&INT_VAL,&LOCAL_ERROR); 
+       MEMORY[ADDRESS+TEMP] = (char) INT_VAL;
+     }
+ 
+     if (LOCAL_ERROR) {
+       (void) printf("ERROR: Illegal store VALUE = %s.\n", VALUE);
+       (*ERROR) = TRUE_1;
+     }
+   } else {
+     (void) printf("ERROR: Illegal store[1] ADDRESS = %d, BYTES = %d.\n",
+ 		  ADDRESS,BYTES);
+     (*ERROR) = TRUE_1;
+   }
+ }
+ 
+ /* ------------------------------ STORE_AT --------------------------------- */
+ /* Place BYTES consequative bytes into MEMORY, starting at ADDRESS.          */
+ void STORE_AT(char *VALUE,int BYTES,int ADDRESS,MEM_SPACE MEMORY,
+               BOOLEAN *ERROR)
+ {
+ /*                                          vvvvvv Remember loaded this block*/
+   DO_STORE(VALUE,BYTES,ADDRESS,MEMORY,ERROR,TRUE_1);
+ }
+ 
+ /* ---------------------------- ADD_INT_TO_LOC ----------------------------- */
+ /* Add the integer NUM to what is store at LOCATION in MEMORY.               */
+ void ADD_INT_TO_LOC(int NUM,int LOCATION,int HALF_BYTES,MEM_SPACE MEMORY,
+                     BOOLEAN *ERROR)
+ {
+   int INT_MEM_VAL = 0;      /* Integer stored at the relavant location.      */
+   char CHAR_MEM_VAL[BITS_PER_WORD_1/BITS_PER_HALFBYTE_1+2]; 
+                             /* CHAR_MEM_VAL is the string representation of  */
+                             /*   the number stored at a location of size     */
+                             /*   HALF_BYTES.                                 */
+ 
+   if ( ((int) HALF_BYTES/2)*2 != HALF_BYTES)
+     HALF_BYTES ++;          /* If odd number of half_bytes include an extra  */
+                             /*   one so that have an even number always.     */
+ 
+ /* ----------------- Check if store is legal (fits in memory)                */
+   if ( (LOCATION + HALF_BYTES/HEX_CHAR_PER_BYTE_1 <= MEM_SIZE_1) 
+       && (LOCATION + HALF_BYTES/HEX_CHAR_PER_BYTE_1 >= 0)) {
+     int I;
+ 
+ /* ------ Get what is stored there                                           */
+     for (I = 0; I < HALF_BYTES/HEX_CHAR_PER_BYTE_1; I ++)
+       INT_MEM_VAL = INT_MEM_VAL*256 + INT(MEMORY[LOCATION+I]);
+ 
+ /* ------ Add the NUMber to what was there                                   */
+     INT_MEM_VAL += NUM;
+ 
+ /* ------ Put the result back                                                */
+     NUM_TO_STR(INT_MEM_VAL,16,HALF_BYTES,CHAR_MEM_VAL);
+     DO_STORE(CHAR_MEM_VAL,HALF_BYTES/HEX_CHAR_PER_BYTE_1, LOCATION,
+ 	     MEMORY, ERROR,FALSE_1);
+   } else {
+     (void) printf("ERROR: Illegal store[2] ADDRESS = %d, BYTES = %d.\n",
+ 		  LOCATION,HALF_BYTES/HEX_CHAR_PER_BYTE_1);
+     (*ERROR) = TRUE_1;
+   }
+ }
+ 
+ /* ============================ Outputting routines ======================== */
+ 
+ /* ------------------------ START_OF_LINE_ADDR (local) --------------------- */
+ /* Returns smallest address that is output on the same line as ADDRESS.      */
+ int START_OF_LINE_ADDR(int ADDRESS)
+ {
+   return ( ((int) ADDRESS / (BYTES_PER_GROUP * GROUPS_PER_LINE)) *
+ 	  BYTES_PER_GROUP * GROUPS_PER_LINE);
+ }
+ 
+ /* ------------------------- END_OF_LINE_ADDR (local) ---------------------- */
+ /* Returns largest address that is output on the same line as ADDRESS.       */
+ int END_OF_LINE_ADDR(int ADDRESS)
+ {
+   return (START_OF_LINE_ADDR(ADDRESS) + BYTES_PER_GROUP * GROUPS_PER_LINE - 1);
+ }
+ 
+ /* --------------------------- LINES_OF_GAP (local) ------------------------ */
+ /* Number of lines (of output) of bytes that seperate the two blocks.        */
+ int LINES_OF_GAP(struct BUFFER_ELEMENT *REC1,struct BUFFER_ELEMENT *REC2)
+ {
+   int REC1_END;                 /* Smallest address displayed on an output   */
+                                 /* line that contains last byte of REC1.     */
+   int REC2_START;               /* Smallest address displayed on an output   */
+                                 /* line that contains first byte of REC2.    */
+ 
+   if (REC1 == NULL) REC1_END = 0;
+   else REC1_END = START_OF_LINE_ADDR( (*REC1).START + (*REC1).LENGTH - 1);
+ 
+   if (REC2 == NULL) REC2_START = START_OF_LINE_ADDR(MEM_SIZE_1 - 1);
+   else REC2_START = START_OF_LINE_ADDR( (*REC2).START);
+ 
+   return ( (REC2_START - REC1_END) / (BYTES_PER_GROUP * GROUPS_PER_LINE) );
+ }
+ 
+ /* -------------------------- PRINT_ELIPSE (local) ------------------------- */
+ /* Elipse out portion of the output, if the gap between this block of memory */
+ /* and previous block is large enough.                                       */
+ void PRINT_ELIPSE(struct BUFFER_ELEMENT *PREV,struct BUFFER_ELEMENT *CURR,
+                   int PREV_ADDR,FILE *OUTPUT)
+ {
+   int LOOP_COUNTER;
+ /* ---------- STR_ADDR               String rep of addr.                     */
+   char STR_ADDR[MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1 + 1];
+   
+ 
+ /* -------------- Check if gap is large enough                               */
+   if ( LINES_OF_GAP(PREV,CURR) >= LINES_OF_GAP_TO_ELIPSE ) {
+ 
+     NUM_TO_STR(PREV_ADDR,16,MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1, STR_ADDR);
+     (void) fprintf(OUTPUT,
+ 		   " %s    xxxxxxxx  xxxxxxxx  xxxxxxxx  xxxxxxxx\n",
+ 		   STR_ADDR);
+ 
+     for (LOOP_COUNTER = 1;LOOP_COUNTER <= 3; LOOP_COUNTER++)
+       (void) fprintf(OUTPUT,
+ 		     "   .          .         .         .         .\n");
+     
+     if (CURR != NULL) 
+       NUM_TO_STR(START_OF_LINE_ADDR( (*CURR).START)-
+ 		 BYTES_PER_GROUP*GROUPS_PER_LINE, 
+ 		 16,MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1, STR_ADDR);
+     else 
+       NUM_TO_STR(START_OF_LINE_ADDR( MEM_SIZE_1) -
+ 		 BYTES_PER_GROUP*GROUPS_PER_LINE, 
+ 		 16,MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1, STR_ADDR);
+ 
+     (void) fprintf(OUTPUT,
+ 		   " %s    xxxxxxxx  xxxxxxxx  xxxxxxxx  xxxxxxxx\n",
+ 		   STR_ADDR);
+   }
+ }
+ 
+ /* ----------------------------- PRINT_MEM --------------------------------- */
+ /* Output the loaded areas of memory in a nice user readable way.            */
+ void PRINT_MEM(MEM_SPACE MEMORY,FILE *OUTPUT)
+ {
+   struct BUFFER_ELEMENT *STEP;     /* Current block of memory outputing.     */
+   struct BUFFER_ELEMENT *PREVIOUS = NULL; /* Last block output               */
+   int PREVIOUS_ADDR = 0;           /* Start address of the last output block */
+   int ADDRESS;                     /* Next address of memory to output.      */
+   char STR_ADDR[MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1 + 1];/* String version of*/
+                                    /*                     address            */
+ 
+   (void) fprintf(OUTPUT,"MEMORY\n");
+   (void) fprintf(OUTPUT,"ADDRESS                  Contents\n");
+   (void) fprintf(OUTPUT,"-------   --------------------------------------\n");
+ /*                        12345    12345678  12345678  12345678  12345678 */
+ /*                       123456789012345678901234567890123456789012345678 */
+ 
+   if (LOCATIONS_USED.HEAD == NULL) 
+     (void) fprintf(OUTPUT,
+ 		   "=========> NOTHING LOADED INTO MEMORY <=========\n");
+   else {
+ 
+ /* --------------- STEP through the list of loaded blocks                    */
+     for (STEP = LOCATIONS_USED.HEAD; STEP != NULL; STEP = (*STEP).NEXT) {
+ 
+       PRINT_ELIPSE(PREVIOUS,STEP,PREVIOUS_ADDR,OUTPUT);
+       ADDRESS = START_OF_LINE_ADDR((*STEP).START);
+ 
+ /* ------ repeat until consequtive blocks are output on seperate lines.      */
+       do {
+ 	BOOLEAN REST_EMPTY = FALSE_1;
+ 	int I,J;
+ 	char STR_BYTE[HEX_CHAR_PER_BYTE_1 + 1];
+ 
+ 	NUM_TO_STR(ADDRESS,16,MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1,STR_ADDR);
+ 	(void) fprintf(OUTPUT," %s    ",STR_ADDR);
+ 	
+ /* --------- OUTPUT 1 line                                                   */
+ 	for (I=0;I<GROUPS_PER_LINE;I++) {
+ 	  for (J=0;J<BYTES_PER_GROUP;J++) {
+ 	    int LOC;
+ 
+ 	    LOC = ADDRESS+I*BYTES_PER_GROUP+J;
+ 	    if (!REST_EMPTY && (LOC >= ((*STEP).START + (*STEP).LENGTH)))
+ 	      {
+ 		if ( ((*STEP).NEXT == NULL) ||
+ 		    (LINES_OF_GAP(STEP,(*STEP).NEXT) > 0)) REST_EMPTY = TRUE_1;
+ 		else STEP = (*STEP).NEXT;
+ 	      }
+ 
+ 	    if ( REST_EMPTY || (LOC < (*STEP).START))
+ 	      (void) fprintf(OUTPUT,"xx");
+ 	    else {
+ 	      NUM_TO_STR(INT(MEMORY[LOC]),16,HEX_CHAR_PER_BYTE_1,STR_BYTE);
+ 	      (void) fprintf(OUTPUT,"%s",STR_BYTE);
+ 	    }
+ 	  }
+ 	  (void) fprintf(OUTPUT,"  ");
+ 	}
+ 	(void) fprintf(OUTPUT,"\n");
+ 
+ 	ADDRESS = END_OF_LINE_ADDR(ADDRESS) + 1;
+       } while (ADDRESS <= 
+ 	       END_OF_LINE_ADDR( (*STEP).START + (*STEP).LENGTH - 1) );
+       PREVIOUS_ADDR = ADDRESS;
+       PREVIOUS = STEP;
+     }
+     PRINT_ELIPSE(PREVIOUS,STEP,PREVIOUS_ADDR,OUTPUT);
+   }
+ }
+ 
+ /* ---------------------------- OUTPUT_MEM --------------------------------- */
+ /* Prints out the loaded areas of memory in a machine friendly format. Very  */
+ /* to the text records of the object stream except relocated and modified.   */
+ void OUTPUT_MEM(MEM_SPACE MEMORY,FILE *OUTPUT)
+ { 
+   struct BUFFER_ELEMENT *CURRENT; /* Current block outputing                 */
+   int COUNT;                   /* Simple loop counter                        */
+   char ADDRESS[MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1 + 2];/* String version of */
+                                /*                        address             */
+   char STR_BYTE[HEX_CHAR_PER_BYTE_1 + 1]; /* String version of byte          */
+ 
+   CURRENT = LOCATIONS_USED.HEAD;
+   while (CURRENT != NULL) {
+     NUM_TO_STR((*CURRENT).START,16,MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1+1,
+ 	       ADDRESS);
+     NUM_TO_STR((*CURRENT).LENGTH,16,HEX_CHAR_PER_BYTE_1,STR_BYTE);
+     (void) fprintf(OUTPUT,"T%s%s",ADDRESS,STR_BYTE);
+ 
+     for (COUNT = (*CURRENT).START; 
+ 	 COUNT < ((*CURRENT).START + (*CURRENT).LENGTH);
+ 	 COUNT ++) {
+       NUM_TO_STR(INT(MEMORY[COUNT]),16,HEX_CHAR_PER_BYTE_1,STR_BYTE);
+       (void) fprintf(OUTPUT,"%s",STR_BYTE);
+     }
+     (void) fprintf(OUTPUT,"\n");
+     CURRENT = (*CURRENT).NEXT;
+   }
+ }


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/memory.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/memory.h:1.1
*** /dev/null	Tue Oct  5 16:12:03 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/memory.h	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,62 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ============================== memory.h ================================= */
+ /* Contains all the routines that manage the main memory of the SIC/XE       */
+ /* machine.                                                                  */
+ 
+ /* MEM_SPACE                     The type of a main memory in this program.  */
+ typedef char *MEM_SPACE;
+ 
+ /* --------------------------------- INT  ---------------------------------- */
+ /* 1 parameter:                                                              */
+ /*   1)  char CH;               Character to convert.                        */
+ /* Return the integer representation for a character. Had to be written      */
+ /* Because the character 255 (for example) who be treated as the integer -1, */
+ /* but I needed it to be 255.                                                */
+ extern int INT();
+ 
+ /* ----------------------------- Create Memory ----------------------------- */
+ /* 1 parameter:                                                              */
+ /*    1) MEM_SPACE *MEMORY;          name of the main memory to create.      */
+ /* Create a megabyte of memory and point MEMORY to it. It does not initialize*/
+ /* the memory as this took about 5 minuites. Since the memory was            */
+ /* uninitized I needed another way to know when locations where modified,    */
+ /* thus the above lined list of blocks.                                      */
+ extern void CREATE_MEMORY();
+ 
+ /* ------------------------------ STORE_AT --------------------------------- */
+ /* 5 parameters:                                                             */
+ /*    1) char *VALUE;            Character representation (2 chars/byte) of  */
+ /*                                 what the block of memory should contain.  */
+ /*    2) int BYTES;              bytes in the block to load into memory.     */
+ /*    3) int ADDRESS;            Where the block begins in memory.           */
+ /*    4) MEM_SPACE MEMORY;       The main memory.                            */
+ /*    5) BOOLEAN *ERROR;         Was an error detected during the store.     */
+ /* Place BYTES consequative bytes into MEMORY, starting at ADDRESS.          */
+ extern void STORE_AT();
+ 
+ /* ---------------------------- ADD_INT_TO_LOC ----------------------------- */
+ /* 5 parameters:                                                             */
+ /*    1) int NUM;                NUMber to add to the value already in memory*/
+ /*    2) int LOCATION;           Address of the integer in memory            */
+ /*    3) int HALF_BYTES;         How many HALF_BYTES does the number occupy  */
+ /*    4) MEM_SPACE MEMORY;       The memory.                                 */
+ /*    5) BOOLEAN *ERROR;         Has an error been detected.                 */
+ /* Add the integer NUM to what is store at LOCATION in MEMORY.               */
+ extern void ADD_INT_TO_LOC();
+ 
+ /* ----------------------------- PRINT_MEM --------------------------------- */
+ /* 2 parameters:                                                             */
+ /*    1) MEM_SPACE MEMORY;              Memory to output.                    */
+ /*    2) FILE *OUTPUT;                  Output stream.                       */
+ /* Output the loaded areas of memory in a nice user readable way.            */
+ extern void PRINT_MEM();
+ 
+ /* ---------------------------- OUTPUT_MEM --------------------------------- */
+ /* 2 parameters:                                                             */
+ /*    1) MEM_SPACE MEMORY;              Memory to output.                    */
+ /*    2) FILE *OUTPUT;                  Output stream.                       */
+ /* Prints out the loaded areas of memory in a machine friendly format. Very  */
+ /* to the text records of the object stream except relocated and modified.   */
+ extern void OUTPUT_MEM();


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/pass1.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/pass1.c:1.1
*** /dev/null	Tue Oct  5 16:12:03 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/pass1.c	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,140 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* =============================== pass1.c ================================= */
+ /* Process Header, define, and end records of oen object file.               */
+ #include <string.h>
+ #include <stdio.h>
+ #include "boolean.h"
+ #include "constants.h"
+ #include "sym_tab.h"
+ #include "stringI.h"
+ #include "memory.h"
+ #include "convert.h"
+ #include "load.h"
+ 
+ /* ------------------------------- PASS1 ----------------------------------- */
+ /* Process Header, define, and end records of oen object file.               */
+ void PASS1(SYMBOL_TABLE *SYM_TAB,int *LOCATION,int *ERROR,FILE *INPUT)
+ {
+   char MODULE_NAME[LABEL_SIZE_1+1];  /* Name of (program) module currently   */
+                                      /* assembling.                          */
+ 
+   char *RECORD;                   /* One record from the input stream        */
+   int UNREL_TO_REL_SHIFT = 0;     /* signed number of bytes to shift the     */
+                                   /*    object code due to relocation        */
+ 
+ 
+   MODULE_NAME[LABEL_SIZE_1] = '\0';
+ 
+   while (!feof(INPUT) && ((*LOCATION) <= MEM_SIZE_1)) {
+     BOOLEAN LOCAL_ERROR;
+ 
+     LOCAL_ERROR = FALSE_1;
+ 
+     GET_LINE(&RECORD,INPUT);
+     switch (RECORD[0]) {
+ 
+     case 'H':
+ /* ---------------------- HEADER RECORD ------------------------------------ */
+       if (strlen(RECORD) != (13 + LABEL_SIZE_1)) 
+ 	LOCAL_ERROR = TRUE_1;
+        else {
+ 	int TEMP_LOC;
+ 
+ 	(void) strncpy(MODULE_NAME,&(RECORD[1]),LABEL_SIZE_1);
+ 	if (!INSERT_IN_SYM_TAB(GLOBAL_1,MODULE_NAME,*LOCATION,MODULE,
+ 			       SYM_TAB)) {
+ 	  int I;
+ 
+ 	  for (I=LABEL_SIZE_1-1; ( (I<1) || (MODULE_NAME[I] == ' ')); I--);
+ 	  MODULE_NAME[I+1] = '\0';
+ 	  (void) printf(
+ 		"ERROR: Multiply defined global %s. Program not loaded.\n",
+ 			MODULE_NAME);
+ 	  (*ERROR) = TRUE_1;
+ 	} else {
+ 
+ 	  STR_TO_NUM(&(RECORD[9]),6,16,&TEMP_LOC,&LOCAL_ERROR);
+ 	  UNREL_TO_REL_SHIFT = (*LOCATION) - TEMP_LOC;
+ 	  STR_TO_NUM(&(RECORD[15]),6,16,&TEMP_LOC,&LOCAL_ERROR);
+ 	  (*LOCATION) += TEMP_LOC;
+ 	  (*LOOK_UP_SYMBOL(GLOBAL_1,MODULE_NAME,SYM_TAB)).LENGTH =
+ 	    TEMP_LOC;
+ 	}
+       }
+ 
+       if (LOCAL_ERROR)
+ 	(void) printf("ERROR: Illegal header record = %s\n",RECORD);
+ 
+       break;
+ 	    
+     case 'D':
+ /* ------------------------ DEFINE RECORD ---------------------------------- */
+       if (strlen(RECORD) > 71) LOCAL_ERROR = TRUE_1;
+ 	else {
+ 	  int NEXT = 1;
+ 	  char TEMP_NAME[LABEL_SIZE_1+1];
+ 	  int TEMP_LOC;
+ 
+ 	  TEMP_NAME[LABEL_SIZE_1] = '\0';
+ 	  while (NEXT + 14 <= strlen(RECORD)) {
+ 	    (void) strncpy(TEMP_NAME,&(RECORD[NEXT]),LABEL_SIZE_1);
+ 	    STR_TO_NUM(&(RECORD[NEXT+LABEL_SIZE_1]),6,16,&TEMP_LOC,
+ 		       &LOCAL_ERROR);
+ 	    if (!INSERT_IN_SYM_TAB(GLOBAL_1,TEMP_NAME
+ 				   ,TEMP_LOC + UNREL_TO_REL_SHIFT,GLOBAL,
+ 				   SYM_TAB)) {
+ 	      int I;
+ 
+ 	      for (I=LABEL_SIZE_1-1; ( (I<1) || (TEMP_NAME[I] == ' ')); I--);
+ 	      TEMP_NAME[I+1] = '\0';
+ 	      (void) printf(
+ 		   "ERROR: Multiply defined global %s. Program not loaded.\n",
+ 			    TEMP_NAME);
+ 	      (*ERROR) = TRUE_1;
+ 	    }
+ 	    NEXT += 14;
+ 	  }
+ 	  if (NEXT != strlen(RECORD)) LOCAL_ERROR = TRUE_1;
+ 	}
+ 
+       if (LOCAL_ERROR)
+ 	(void) printf("ERROR: Illegal define record = %s\n",RECORD);
+ 
+       break;
+ 
+ /* ------------------------- END RECORD ------------------------------------ */
+     case 'E':
+       if (strlen(RECORD) != 1)
+ 	if (strlen(RECORD) != 7)
+ 	  LOCAL_ERROR = TRUE_1;
+ 	else {
+ 	  if (START_ADDRESS != -1) 
+ 	    (void) printf("%s%s\n",
+ 			  "WARNING: Found multiple start addresses.",
+ 			  " Expected only one. Using the first.");
+ 	  else {
+ 	    STR_TO_NUM(&(RECORD[1]),6,16,&START_ADDRESS, &LOCAL_ERROR);
+ 	    START_ADDRESS += UNREL_TO_REL_SHIFT;
+ 	    (void) strcpy(MAIN_ROUTINE,MODULE_NAME);
+ 	  }
+ 	}
+ 
+       if (LOCAL_ERROR)
+ 	(void) printf("ERROR: Illegal end record = %s\n",RECORD);
+ 
+       break;
+     case 'M':
+     case 'R':
+     case 'T':
+     case '\0':
+       break;
+ 
+     default:
+       (void) printf("ERROR: Illegal RECORD = %s\n",RECORD);
+       LOCAL_ERROR = TRUE_1;
+     }
+     (*ERROR) = (*ERROR) || LOCAL_ERROR;
+   }
+ }


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/pass1.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/pass1.h:1.1
*** /dev/null	Tue Oct  5 16:12:03 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/pass1.h	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,13 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* =============================== pass1.h ================================= */
+ 
+ /* ------------------------------- PASS1 ----------------------------------- */
+ /* 4 parameters:                                                             */
+ /*    1) SYMBOL_TABLE *SYM_TAB;      loaders [global] symbol table           */
+ /*    2) int *LOCATION;              Location to load next csect             */
+ /*    3) int *ERROR;                 any errors in the object code?          */
+ /*    4) FILE *INPUT;                stream with the object code             */
+ /* Process Header, define, and end records of oen object file.               */
+ extern void PASS1();


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/pass2.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/pass2.c:1.1
*** /dev/null	Tue Oct  5 16:12:03 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/pass2.c	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,167 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* =============================== pass2.h ================================= */
+ /* Process Text, Modify, and Reference records of one object file. Also      */
+ /* does minimal recomputation of the number of bytes needs to be shifted to  */
+ /* accomidate the relocation.                                                */
+ #include <string.h>
+ #include <stdio.h>
+ #include "boolean.h"
+ #include "constants.h"
+ #include "sym_tab.h"
+ #include "stringI.h"
+ #include "memory.h"
+ #include "convert.h"
+ #include "load.h"
+ 
+ /* --------------------------------- pass2 --------------------------------- */
+ /* Process Text, Modify, and Reference records of one object file. Also      */
+ /* does minimal recomputation of the number of bytes needs to be shifted to  */
+ /* accomidate the relocation.                                                */
+ void PASS2(MEM_SPACE MEMORY,SYMBOL_TABLE *SYM_TAB,int *LOCATION,int *ERROR,
+            FILE *INPUT)
+ {
+   char MODULE_NAME[LABEL_SIZE_1+1];  /* Name of (program) module currently   */
+                                      /* assembling.                          */
+ 
+   char *RECORD;                   /* One record from the input stream        */
+   int UNREL_LOCATION;             /* Where in the unrelocated memory is it   */
+                                   /* located.                                */
+   int UNREL_TO_REL_SHIFT = 0;     /* signed number of bytes to shift the     */
+                                   /*    object code due to relocation        */
+   int LENGTH;                     /* Used to store length of blocks of       */
+                                   /* memory affected by text and modification*/
+                                   /* records                                 */
+ 
+   MODULE_NAME[LABEL_SIZE_1] = '\0';
+ 
+   while (!feof(INPUT)  && ((*LOCATION) <= MEM_SIZE_1)) {
+     BOOLEAN LOCAL_ERROR;
+ 
+     LOCAL_ERROR = FALSE_1;
+ 
+     GET_LINE(&RECORD,INPUT);
+     switch (RECORD[0]) {
+ 
+     case 'T':
+ /* ---------------------------- TEXT RECORD -------------------------------- */
+       if (strlen(RECORD) < 9)
+ 	LOCAL_ERROR = TRUE_1;
+       else {
+ 
+ 	STR_TO_NUM(&(RECORD[1]),6,16,&UNREL_LOCATION,&LOCAL_ERROR);
+ 	STR_TO_NUM(&(RECORD[7]),2,16,&LENGTH,&LOCAL_ERROR);
+ 	if (strlen(RECORD) != 9+LENGTH*2) LOCAL_ERROR = TRUE_1;
+ 	else STORE_AT(&(RECORD[9]), LENGTH, UNREL_LOCATION+UNREL_TO_REL_SHIFT,
+ 		      MEMORY,&LOCAL_ERROR);
+       }
+       if (LOCAL_ERROR)
+ 	(void) printf("ERROR: Illegal text record = %s\n",RECORD);
+ 
+       break;
+ 
+     case 'H':
+ /* ---------------------------- HEADER RECORD ------------------------------ */
+ /* ----- Just calcution of UNREL_TO_REL_SHIFT                                */
+       if (strlen(RECORD) != (13 + LABEL_SIZE_1))
+ 	LOCAL_ERROR = TRUE_1;
+       else {
+ 	int TEMP_LOC;
+ 	
+ 	(void) strncpy(MODULE_NAME,&(RECORD[1]),LABEL_SIZE_1);
+ 	STR_TO_NUM(&(RECORD[9]),6,16,&TEMP_LOC,&LOCAL_ERROR);
+ 	UNREL_TO_REL_SHIFT = (*LOCATION) - TEMP_LOC;
+ 	STR_TO_NUM(&(RECORD[15]),6,16,&TEMP_LOC,&LOCAL_ERROR);
+ 	(*LOCATION) += TEMP_LOC;
+ 	if ((*LOCATION) > MEM_SIZE_1)
+ 	  (void) printf("ERROR: Program does not fit in memory. Aborting.\n");
+       }
+ 
+       break;
+ 
+ /* ---------------------------- MODIFICATION RECORD ------------------------ */
+     case 'M':
+       if (strlen(RECORD) < 9) LOCAL_ERROR = TRUE_1;
+       else if (strlen(RECORD) == 9) {	
+ /* -------------------------- Type 1 Modification record. ------------------ */
+ 	STR_TO_NUM(&(RECORD[1]),6,16,&UNREL_LOCATION,&LOCAL_ERROR);
+ 	STR_TO_NUM(&(RECORD[7]),2,16,&LENGTH,&LOCAL_ERROR);
+ 	ADD_INT_TO_LOC(UNREL_TO_REL_SHIFT, UNREL_LOCATION + UNREL_TO_REL_SHIFT,
+  		       LENGTH, MEMORY, &LOCAL_ERROR);
+       } else 
+ /* -------------------------- Type 2 Modification record. ------------------ */
+ 	if (strlen(RECORD) != 18) LOCAL_ERROR = TRUE_1;
+ 	  else {
+ 	    struct SYMBOL_TABLE_ENTRY *SYMBOL;
+ 	    int SIGN;
+ 
+ 	    STR_TO_NUM(&(RECORD[1]),6,16,&UNREL_LOCATION,&LOCAL_ERROR);
+ 	    STR_TO_NUM(&(RECORD[7]),2,16,&LENGTH,&LOCAL_ERROR);
+ 
+ 	    switch (RECORD[9]) {
+ 	    case '-':
+ 	      SIGN = -1;
+ 	      break;
+ 	    case '+':
+ 	      SIGN = 1;
+ 	      break;
+ 	    default:
+ 	      SIGN = 0;
+ 	      LOCAL_ERROR = TRUE_1;
+ 	      break;
+ 	    }
+ 
+ 	    SYMBOL = LOOK_UP_SYMBOL(GLOBAL_1,&(RECORD[10]),SYM_TAB);
+ 	    if (SYMBOL == NULL) LOCAL_ERROR = TRUE_1;
+ 	    else ADD_INT_TO_LOC((*SYMBOL).LOCATION * SIGN,
+ 				UNREL_LOCATION + UNREL_TO_REL_SHIFT,
+ 				LENGTH, MEMORY, &LOCAL_ERROR);
+ 	  }
+ 
+       if (LOCAL_ERROR)
+ 	(void) printf("ERROR: Illegal text record = %s\n",RECORD);
+       break;
+ 
+     case 'R':
+ /* ------------------------------- REFERENCE RECORD ------------------------ */
+       if (strlen(RECORD) > 73) LOCAL_ERROR = TRUE_1;
+ 	else {
+ 	  int NEXT = 1;
+ 	  char TEMP_NAME[LABEL_SIZE_1+1];
+ 
+ 	  TEMP_NAME[LABEL_SIZE_1] = '\0';
+ 	  while (NEXT + LABEL_SIZE_1 <= strlen(RECORD)) {
+ 	    (void) strncpy(TEMP_NAME,&(RECORD[NEXT]),LABEL_SIZE_1);
+ 	    if (LOOK_UP_SYMBOL(GLOBAL_1,TEMP_NAME, SYM_TAB) == NULL) {
+ 	      int I;
+ 
+ 	      (void) INSERT_IN_SYM_TAB(GLOBAL_1,TEMP_NAME,0,UNDEFINED,SYM_TAB);
+ 	      for (I=LABEL_SIZE_1-1; ( (I<1) || (TEMP_NAME[I] == ' ')); I--);
+ 	      TEMP_NAME[I+1] = '\0';
+ 	      (void) printf(
+ 			    "ERROR: Undefined global %s. Program not loaded.\n"
+ 			    ,TEMP_NAME);
+ 
+ 	      (*ERROR) = TRUE_1;
+ 	    }
+ 	    NEXT += LABEL_SIZE_1;
+ 	  }
+ 	  if (NEXT != strlen(RECORD)) LOCAL_ERROR = TRUE_1;
+ 	}
+ 
+       if (LOCAL_ERROR)
+ 	(void) printf("ERROR: Illegal define record = %s\n",RECORD);
+ 
+       break;
+ 
+ 
+     case 'E':
+     case 'D':
+     case '\0':
+     default:
+       break;
+     }
+     (*ERROR) = (*ERROR) || LOCAL_ERROR;
+   }
+ }


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/pass2.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/pass2.h:1.1
*** /dev/null	Tue Oct  5 16:12:03 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/pass2.h	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,16 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ============================== pass2.h ================================== */
+ 
+ /* --------------------------------- pass2 --------------------------------- */
+ /* 5 parameters:                                                             */
+ /*    1) MEM_SPACE MEMORY;           The SIC/XE's main memory                */
+ /*    2) SYMBOL_TABLE *SYM_TAB;      loaders [global] symbol table           */
+ /*    3) int *LOCATION;              Location to load next csect             */
+ /*    4) int *ERROR;                 any errors in the object code?          */
+ /*    5) FILE *INPUT;                stream with the object code             */
+ /* Process Text, Modify, and Reference records of one object file. Also      */
+ /* does minimal recomputation of the number of bytes needs to be shifted to  */
+ /* accomidate the relocation.                                                */
+ extern void PASS2();


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/print.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/print.c:1.1
*** /dev/null	Tue Oct  5 16:12:03 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/print.c	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,96 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ============================== print.c ================================== */
+ /* Contains routines for output the symbol table and executable files.       */
+ #include <string.h>
+ #include <stdio.h>
+ #include "boolean.h"
+ #include "constants.h"
+ #include "sym_tab.h"
+ #include "convert.h"
+ #include "memory.h"
+ #include "load.h"
+ 
+ /* ============================== Symbol Table ============================= */
+ /* -------------------------- PRINT_TABLE (local) -------------------------- */
+ /* Outputs the Symbol Table. Recursive                                       */
+ void PRINT_TABLE(SYMBOL_TABLE SYM_TAB,FILE *OUTPUT)
+ {
+   char TEMP[(int) MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1 + 1];
+ 
+ /* ------------------- Print out the linked list backwards                   */
+   if (SYM_TAB != NULL) {
+ 
+     PRINT_TABLE((*SYM_TAB).NEXT,OUTPUT);
+ 
+     if ((*SYM_TAB).TYPE == MODULE) 
+       (void) fprintf(OUTPUT,   "%s            ",(*SYM_TAB).LABEL);
+     else (void) fprintf(OUTPUT,"          %s  ",(*SYM_TAB).LABEL);
+ 
+     NUM_TO_STR((*SYM_TAB).LOCATION, 16, 
+ 	       (int) MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1,TEMP);
+ 
+     if ((*SYM_TAB).TYPE == UNDEFINED)
+       (void) fprintf(OUTPUT,"Undefined ");
+     else (void) fprintf(OUTPUT,"%s    ",TEMP);
+ 
+     if ((*SYM_TAB).TYPE == MODULE) {
+       NUM_TO_STR((*SYM_TAB).LENGTH, 16, 
+ 		 (int)MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1+1,TEMP);
+       (void) fprintf(OUTPUT,"%s\n",TEMP);
+     } else (void) fprintf(OUTPUT,"\n");
+   }
+ }
+ 
+ /* --------------------------------- PRT_SYM_TAB --------------------------- */
+ /* Prints header for the symbol table file and lets PRINT_TABLE print it.    */
+ void PRT_SYM_TAB(SYMBOL_TABLE SYM_TAB,FILE *OUTPUT)
+ {
+   (void) fprintf(OUTPUT,"CONTROL   SYMBOL\n");
+   (void) fprintf(OUTPUT,"SECTION   NAME     ADDRESS   LENGTH\n");  
+   (void) fprintf(OUTPUT,"-----------------------------------\n");
+   PRINT_TABLE(SYM_TAB,OUTPUT);
+ }
+ /* ============================= Executable ================================ */
+ /* ----------------------------- OUTPUT_TABLE ------------------------------ */
+ /* Prints out the symbol table into the executable file. Again is recursive  */
+ void OUTPUT_TABLE(SYMBOL_TABLE SYM_TAB,FILE *OUTPUT)
+ {
+   char TEMP[(int) MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1 + 2];
+ 
+ /* ---------------- Prints linked list out backwards                         */
+   if (SYM_TAB != NULL) {
+     OUTPUT_TABLE((*SYM_TAB).NEXT,OUTPUT);
+ 
+     if ((*SYM_TAB).TYPE == MODULE) 
+       (void) fprintf(OUTPUT,"M%s",(*SYM_TAB).LABEL);
+     else if (!strcmp((*SYM_TAB).MODULE,GLOBAL_1)) 
+       (void) fprintf(OUTPUT,"G%s",(*SYM_TAB).LABEL);
+     else (void) fprintf(OUTPUT,"L%s%s",(*SYM_TAB).MODULE,(*SYM_TAB).LABEL);
+ 
+     NUM_TO_STR((*SYM_TAB).LOCATION, 16, 
+ 	       (int) MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1+1,TEMP);
+     (void) fprintf(OUTPUT,"%s",TEMP);
+ 
+     if ((*SYM_TAB).TYPE == MODULE) {
+       NUM_TO_STR((*SYM_TAB).LENGTH, 16,
+ 		 (int) MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1+1, TEMP);
+       (void) fprintf(OUTPUT,"%s",TEMP);
+     }
+     (void) fprintf(OUTPUT,"\n");
+   }
+ }
+ 
+ /* ------------------------------ PRINT_EXEC ------------------------------- */
+ /* Drives the outputing of the executable file                               */
+ void PRINT_EXEC(MEM_SPACE MEMORY,SYMBOL_TABLE SYM_TAB,FILE *OUTPUT)
+ {
+   char ADDRESS[MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1 + 1];
+   
+   NUM_TO_STR(START_ADDRESS,16,MEM_ADDR_SIZE_1/BITS_PER_HALFBYTE_1,ADDRESS);
+   (void) fprintf(OUTPUT,"S%s%s\n",MAIN_ROUTINE,ADDRESS);
+ 
+   OUTPUT_TABLE(SYM_TAB,OUTPUT);
+   OUTPUT_MEM(MEMORY,OUTPUT);
+ }


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/print.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/print.h:1.1
*** /dev/null	Tue Oct  5 16:12:03 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/print.h	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,20 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ============================== print.h ================================== */
+ /* Contains routines for output the symbol table and executable files.       */
+ 
+ /* --------------------------------- PRT_SYM_TAB --------------------------- */
+ /* 2 parameters:                                                             */
+ /*    1) SYMBOL_TABLE SYM_TAB;          The symbol table.                    */
+ /*    2) FILE *OUTPUT;                  The output steam                     */
+ /* Prints header for the symbol table file and lets PRINT_TABLE print it.    */
+ extern void PRT_SYM_TAB();
+ 
+ /* ------------------------------ PRINT_EXEC ------------------------------- */
+ /* 3 parameters:                                                             */
+ /*    1) MEM_SPACE MEMORY;               The memory                          */
+ /*    2) SYMBOL_TABLE SYM_TAB;           The symbol table                    */
+ /*    3) FILE *OUTPUT;                   The output stream                   */
+ /* Drives the outputing of the executable file                               */
+ extern void PRINT_EXEC();


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/stringI.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/stringI.c:1.1
*** /dev/null	Tue Oct  5 16:12:03 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/stringI.c	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,57 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ================================ stringI.c ============================== */
+ /* Reads in one line of input gauranteeing that it will return a pointer to  */
+ /* the whole line, no matter how long it is (it uses CALLOC a version of     */
+ /* MALLOC).                                                                  */
+ #include <stdio.h>
+ 
+ /* CARRAGIAGE_RETURN            <cr> is ascii 10                             */
+ #define CARRIAGE_RETURN         10
+ 
+ /* LEX_LEN_INCREMENT            For long strings, number of characters to    */
+ /*                              increase the string buffer by on overflow.   */
+ #define LEX_LEN_INCR            128
+ 
+ char CH = ' ';                 /* Current input Character                    */
+ char LEXEME[LEX_LEN_INCR+1];   /* Input String                               */
+ 
+ char *FRONT,*BACK;             /* FRONT and BACK characters of Input String  */
+ unsigned LEX_LEN = LEX_LEN_INCR;/* Size of the Input String Buffer           */
+ 
+ 
+ /* ------------------------------- GETCHR ---------------------------------- */
+ /* gets the next character form input file and expands buffer if needed      */
+ void GETCHR(FILE *STREAM)
+ {
+ /*  int TEMP; */
+ 
+ /* --------- get next character                                              */
+   CH = getc(STREAM);
+ 
+ /*  TEMP = (int) (FRONT-BACK); */
+   if ((FRONT-BACK) < ((int)LEX_LEN-3)) {
+ /* --------- update input string appropriately                               */
+       FRONT ++;
+       *FRONT = CH;
+       *(FRONT+1) = '\0';
+     }
+ }
+ 
+ /* --------------------------------- GET_LINE ------------------------------ */
+ /* Read in a line from the input stream.                                     */
+ void GET_LINE(char **LINE,FILE *STREAM)
+ {
+ /* -------- Clear input string                                               */
+   LEXEME[0] = '\0';
+ /* -------- reset pointers                                                   */
+   BACK = LEXEME;
+   FRONT = BACK - 1;
+ 
+   GETCHR(STREAM);
+   while ((CH != CARRIAGE_RETURN) && !feof(STREAM))
+     GETCHR(STREAM);
+   *FRONT = '\0';
+   *LINE = LEXEME;
+ }


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/stringI.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/stringI.h:1.1
*** /dev/null	Tue Oct  5 16:12:03 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/stringI.h	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,15 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* =============================== stringI.h =============================== */
+ /* Reads in one line of input gauranteeing that it will return a pointer to  */
+ /* the whole line, no matter how long it is (it uses CALLOC a version of     */
+ /* MALLOC).                                                                  */
+ 
+ /* --------------------------------- GET_LINE ------------------------------ */
+ /* 2 parameters:                                                             */
+ /*  1) char **LINE;               Points to the input line (string) when done*/
+ /*  2) FILE *STREAM;              Where to get the line from.                */
+ /* Read in a line from the input stream.                                     */
+ extern void GET_LINE();
+ 


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/sym_tab.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/sym_tab.c:1.1
*** /dev/null	Tue Oct  5 16:12:03 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/sym_tab.c	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,59 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ================================ sym_tab.c ============================== */
+ /* intialize, retrieve from, and store to the symbol table. Currently        */
+ /* implemented with a linked list and linear search.                         */
+ #include "sym_tab.h"
+ #include <string.h>
+ #include <stdio.h>
+ #include <malloc.h>
+ 
+ /* -------------------------------- INIT_SYM_TAB --------------------------- */
+ /* Initialize the symbol table TABLE.                                        */
+ void INIT_SYM_TAB(SYMBOL_TABLE *TABLE)
+ {
+   *TABLE = NULL;
+ }
+ 
+ /* ------------------------- LOOK_UP_SYMBOL -------------------------------- */
+ /* find a symbol in the table. Return a pointer to its entry in the table, if*/
+ /* found, otherwise return NULL.                                             */
+ struct SYMBOL_TABLE_ENTRY *LOOK_UP_SYMBOL(char MODULE[],char LABEL[],
+                                           SYMBOL_TABLE *TABLE)
+ {
+   struct SYMBOL_TABLE_ENTRY *TABLE_ENTRY;
+   TABLE_ENTRY = *TABLE;
+    while (TABLE_ENTRY != NULL)
+      { 
+        if ( !strcmp((*TABLE_ENTRY).MODULE,MODULE) &&
+ 	    !strcmp((*TABLE_ENTRY).LABEL,LABEL)) return TABLE_ENTRY;
+        TABLE_ENTRY = (*TABLE_ENTRY).NEXT;
+      } 
+    return NULL;
+ }
+ 
+ /* -------------------------- INSERT_IN_SYM_TAB ---------------------------- */
+ /* If <MODULE,LABEL> pair is not in the symbol table, put it there and       */
+ /* TRUE (integer 1). Otherwise return FALSE (integer 0).                     */
+ /* Puts onto front of the linked list.                                       */
+ int INSERT_IN_SYM_TAB(char *MODULE,char *LABEL,int LOCATION,enum kind TYPE,
+                       SYMBOL_TABLE *TABLE)
+ {
+   struct SYMBOL_TABLE_ENTRY *TABLE_ENTRY;
+ 
+   TABLE_ENTRY = LOOK_UP_SYMBOL(MODULE,LABEL,TABLE);
+   if (TABLE_ENTRY == NULL)
+     {
+       TABLE_ENTRY = (struct SYMBOL_TABLE_ENTRY *) malloc(sizeof(struct SYMBOL_TABLE_ENTRY));
+       (*TABLE_ENTRY).NEXT = *TABLE;
+       (void) strcpy((*TABLE_ENTRY).MODULE, MODULE);
+       (void) strcpy((*TABLE_ENTRY).LABEL, LABEL);
+       (*TABLE_ENTRY).LOCATION = LOCATION;
+       (*TABLE_ENTRY).LENGTH = 0;
+       (*TABLE_ENTRY).TYPE = TYPE;
+       *TABLE = TABLE_ENTRY;
+       return 1;
+     }
+   else return 0;
+ }


Index: llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/sym_tab.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/sym_tab.h:1.1
*** /dev/null	Tue Oct  5 16:12:03 2004
--- llvm-test/MultiSource/Benchmarks/Prolangs-C/loader/sym_tab.h	Tue Oct  5 16:11:49 2004
***************
*** 0 ****
--- 1,54 ----
+ /* %%%%%%%%%%%%%%%%%%%% (c) William Landi 1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%% */
+ /* Permission to use this code is granted as long as the copyright */
+ /* notice remains in place. */
+ /* ========================= sym_tab.h ===================================== */
+ #include "constants.h"
+ 
+ /* kind                   What kind/type of symbol is it.                    */
+ enum kind {RELATIVE,ABSOLUTE,EXTERN_REF,MODULE,GLOBAL,UNDEFINED};
+ 
+ /* SYMBOL_TABLE_ENTRY     type of a symbol table entry. Part of a linked list*/
+ typedef struct SYMBOL_TABLE_ENTRY {
+   char LABEL[LABEL_SIZE_1+1];       /* Name of the symbol.                   */
+   char MODULE[LABEL_SIZE_1+1];      /* [Program] Module the symbol was found */
+                                     /*   int.                                */
+   int  LOCATION;                    /* Location in SICs memory this label    */
+                                     /*    represents. For module names it    */
+                                     /*    is the starting address. For       */
+                                     /*    constants it is the value.         */
+   int LENGTH;                       /* Only for module names, the length of  */
+                                     /*    the module.                        */
+   enum kind TYPE;                   /* kind/type of label (relative, ...)    */
+   struct SYMBOL_TABLE_ENTRY *NEXT;  /* Pointer to next entry in the list     */
+ } *SYMBOL_TABLE;
+ 
+ /* -------------------------------- INIT_SYM_TAB --------------------------- */
+ /* 1 parameter:                                                              */
+ /*   1) SYMBOL_TABLE *TABLE;                                                 */
+ /* Initialize the symbol table TABLE.                                        */
+ extern void INIT_SYM_TAB();
+ 
+ /* ------------------------- LOOK_UP_SYMBOL -------------------------------- */
+ /* 3 parameters:                                                             */
+ /*   1) char MODULE[];                   /* Name of module label found it.   */
+ /*   2) char LABEL[];                    /* Label to look for.               */
+ /*   3) SYMBOL_TABLE *TABLE;             /* Table to look in.                */
+ /* find a symbol in the table. Return a pointer to its entry in the table, if*/
+ /* found, otherwise return NULL.                                             */
+ extern struct SYMBOL_TABLE_ENTRY *LOOK_UP_SYMBOL();
+ 
+ /* -------------------------- INSERT_IN_SYM_TAB ---------------------------- */
+ /* 5 parameters:                                                             */
+ /*  1) char *LABEL;                    Label to add.                         */
+ /*  2) char *MODULE;                   Module that this label was found in.  */
+ /*  3) int  LOCATION;                  What the entries LOCATION field       */
+ /*                                        should be set to.                  */
+ /*  4)  enum kind TYPE;                What the entries TYPE field should be */
+ /*                                        set to.                            */
+ /*  5) SYMBOL_TABLE *TABLE;            Table to add <MODULE,LABEL> to.       */
+ /* If <MODULE,LABEL> pair is not in the symbol table, put it there and       */
+ /* TRUE (integer 1). Otherwise return FALSE (integer 0).                     */
+ /* Puts onto front of the linked list.                                       */
+ extern int INSERT_IN_SYM_TAB();
+ 
+ 






More information about the llvm-commits mailing list