00001 #include <string.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <ctype.h>
00005 #include <stdarg.h>
00006 #include "globals.h"
00007 #include "types.h"
00008 #include "errors.h"
00009 #include "ast_util.h"
00010 #include "odin_util.h"
00011 #include "util.h"
00012 #include "high_level_data.h"
00013
00014
00015 void update_tree(ast_node_t *node);
00016 void update_tag(ast_node_t *node, int tag, int line);
00017 int generate_tag();
00018 int last_tag;
00019 int get_linenumber(ast_node_t *node);
00020
00021
00022
00023
00024
00025 void add_tag_data()
00026 {
00027 int i;
00028
00029 for (i = 0; i < num_modules; i++)
00030 {
00031 update_tree (ast_modules[i]);
00032 }
00033 }
00034
00035
00036
00037
00038 void update_tree(ast_node_t *node)
00039 {
00040 int i;
00041 int tag;
00042 int line;
00043
00044 if (node == NULL)
00045 return;
00046
00047 if (strcmp(global_args.high_level_block,"if")==0)
00048 {
00049 switch(node->type)
00050 {
00051 case IF:
00052 tag = generate_tag();
00053 line = get_linenumber(node);
00054 update_tag(node, tag, line);
00055 break;
00056
00057 default:
00058 for (i=0; i < node->num_children; i++)
00059 {
00060 update_tree(node->children[i]);
00061 }
00062 }
00063 }
00064 else if (strcmp(global_args.high_level_block,"always")==0)
00065 {
00066 switch(node->type)
00067 {
00068 case ALWAYS:
00069 tag = generate_tag();
00070 line = get_linenumber(node);
00071 update_tag(node, tag, line);
00072 break;
00073
00074 default:
00075 for (i=0; i < node->num_children; i++)
00076 {
00077 update_tree(node->children[i]);
00078 }
00079 }
00080 }
00081 else if (strcmp(global_args.high_level_block,"module")==0)
00082 {
00083 switch(node->type)
00084 {
00085 case MODULE:
00086 tag = generate_tag();
00087 line = get_linenumber(node);
00088 update_tag(node, tag, line);
00089 break;
00090
00091 default:
00092 for (i=0; i < node->num_children; i++)
00093 {
00094 update_tree(node->children[i]);
00095 }
00096 }
00097 }
00098 }
00099
00100
00101
00102
00103 void update_tag(ast_node_t *node, int tag, int line)
00104 {
00105 int i;
00106 if (node == NULL)
00107 return;
00108
00109 node->far_tag = tag;
00110 node->high_number = line;
00111
00112 for (i=0; i < node->num_children; i++)
00113 {
00114 update_tag(node->children[i],tag, line);
00115 }
00116
00117 }
00118
00119
00120
00121
00122 int generate_tag()
00123 {
00124 static int high_level_id = 0;
00125 high_level_id ++;
00126 last_tag = high_level_id;
00127
00128 return high_level_id;
00129 }
00130
00131
00132
00133
00134 int get_linenumber(ast_node_t *node)
00135 {
00136 return node->line_number;
00137 }