00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef INCL_UCFUN
00026 #define INCL_UCFUN
00027
00028 #include "ucsym.h"
00029 #include "uclabel.h"
00030
00031 class Uc_location;
00032 class Uc_statement;
00033 #ifndef ALPHA_LINUX_CXX
00034 # include <iosfwd>
00035 #endif
00036
00037
00038
00039
00040 class Uc_function
00041 {
00042 static Uc_scope globals;
00043
00044 static vector<Uc_intrinsic_symbol *> intrinsics;
00045
00046 static int add_answer, remove_answer, push_answers, pop_answers,
00047 show_face, remove_face;
00048 static int num_global_statics;
00049 Uc_scope top;
00050 Uc_function_symbol *proto;
00051 Uc_scope *cur_scope;
00052 int num_parms;
00053 int num_locals;
00054 int num_statics;
00055
00056
00057 vector<Uc_statement *> breakables;
00058 vector<int> breaks;
00059
00060
00061
00062 std::vector<Uc_function_symbol *> links;
00063 std::map<std::string, Uc_label *> labels;
00064 char *text_data;
00065 int text_data_size;
00066
00067 std::map<std::string, int> text_map;
00068 Uc_statement *statement;
00069
00070 int reloffset;
00071 public:
00072 Uc_function(Uc_function_symbol *p);
00073 ~Uc_function();
00074 enum Intrinsic_type
00075 {
00076 bg,
00077 si
00078 };
00079 static void set_intrinsics(Intrinsic_type ty);
00080 void set_statement(Uc_statement *s)
00081 { statement = s; }
00082 void adjust_reloffset(int diff) { reloffset += diff; }
00083 int get_reloffset() const { return reloffset; }
00084 void push_scope()
00085 { cur_scope = cur_scope->add_scope(); }
00086 void pop_scope()
00087 {
00088 cur_scope = cur_scope->get_parent();
00089 }
00090 Uc_symbol *search(char *nm)
00091 { return cur_scope->search(nm); }
00092 Uc_symbol *search_up(char *nm)
00093 {
00094 Uc_symbol *sym = cur_scope->search_up(nm);
00095 return (sym ? sym : globals.search(nm));
00096 }
00097 static Uc_intrinsic_symbol *get_intrinsic(int i)
00098 { return (i >= 0 && i < intrinsics.size())? intrinsics[i] : 0;}
00099 static Uc_intrinsic_symbol *get_add_answer()
00100 { return get_intrinsic(add_answer); }
00101 static Uc_intrinsic_symbol *get_remove_answer()
00102 { return get_intrinsic(remove_answer); }
00103 static Uc_intrinsic_symbol *get_push_answers()
00104 { return get_intrinsic(push_answers); }
00105 static Uc_intrinsic_symbol *get_pop_answers()
00106 { return get_intrinsic(pop_answers); }
00107 static Uc_intrinsic_symbol *get_show_face()
00108 { return get_intrinsic(show_face); }
00109 static Uc_intrinsic_symbol *get_remove_face()
00110 { return get_intrinsic(remove_face); }
00111
00112 static bool is_dup(Uc_scope *scope, char *nm);
00113 Uc_var_symbol *add_symbol(char *nm);
00114 void add_static(char *nm);
00115 int add_function_symbol(Uc_function_symbol *fun)
00116 { return cur_scope->add_function_symbol(fun); }
00117 static int add_global_function_symbol(Uc_function_symbol *fun)
00118 { return globals.add_function_symbol(fun); }
00119
00120 Uc_symbol *add_string_symbol(char *nm, char *text);
00121
00122 Uc_symbol *add_int_const_symbol(char *nm, int value);
00123 static Uc_symbol *add_global_int_const_symbol(char *nm, int val);
00124 static void add_global_static(char *nm);
00125 int add_string(char *text);
00126 int find_string_prefix(Uc_location& loc, const char *text);
00127
00128 void add_label(Uc_label* l) { labels[l->get_name()] = l; }
00129 Uc_label *search_label(char *nm);
00130
00131 void start_breakable(Uc_statement *s);
00132 void end_breakable(Uc_statement *s, vector<char>& stmt_code);
00133
00134 void add_break(int op_offset);
00135
00136
00137
00138
00139 int link(Uc_function_symbol *fun);
00140 void link_labels(std::vector<char>& code);
00141 void gen(std::ostream& out);
00142 };
00143
00144 #endif