00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef CBZ_C_BREEZE_H
00039 #define CBZ_C_BREEZE_H
00040
00041
00042
00043 #ifdef _WIN32
00044
00045 #pragma warning(disable:4786)
00046 #pragma warning(disable:4503)
00047
00048 #pragma warning(disable:4800)
00049
00050 #pragma warning(disable:4267)
00051 #endif //
00052
00053
00054
00055
00056 #include <iostream>
00057 #include <fstream>
00058 #include <sstream>
00059 #include <string>
00060 #include <list>
00061 #include <vector>
00062 #include <map>
00063 #include <algorithm>
00064 #include <functional>
00065
00066 #include <assert.h>
00067 #include <stdio.h>
00068 #include "cbz_util.h"
00069 #include "hash_set_ex.h"
00070
00071
00072
00073 class Node;
00074 class unitNode;
00075 class defNode;
00076 class declNode;
00077 class typeNode;
00078 class primNode;
00079 class tdefNode;
00080 class ptrNode;
00081 class arrayNode;
00082 class funcNode;
00083 class sueNode;
00084 class structNode;
00085 class unionNode;
00086 class enumNode;
00087 class suespecNode;
00088 class exprNode;
00089 class indexNode;
00090 class constNode;
00091 class idNode;
00092 class binaryNode;
00093 class unaryNode;
00094 class castNode;
00095 class commaNode;
00096 class ternaryNode;
00097 class callNode;
00098 class initializerNode;
00099 class stmtNode;
00100 class blockNode;
00101 class basicblockNode;
00102 class exprstmtNode;
00103 class targetNode;
00104 class labelNode;
00105 class caseNode;
00106 class selectionNode;
00107 class ifNode;
00108 class switchNode;
00109 class loopNode;
00110 class whileNode;
00111 class doNode;
00112 class forNode;
00113 class jumpNode;
00114 class gotoNode;
00115 class continueNode;
00116 class breakNode;
00117 class returnNode;
00118 class attribNode;
00119 class procNode;
00120 class operandNode;
00121 class conditiongotoNode;
00122 class threeAddrNode;
00123 class textNode;
00124 class CBZ;
00125 class Containers;
00126 class Coord;
00127 class Datatype;
00128 class LirInst;
00129 class LirBlock;
00130
00131 class Symbols;
00132 class Identifiers_table;
00133 class Tags_table;
00134 class Externals_table;
00135
00136 class FlowVal;
00137 class FlowProblem;
00138 class Annote;
00139
00140
00141 using namespace std;
00142
00143 typedef list< Node * > node_list;
00144 typedef node_list::iterator node_list_p;
00145
00146 typedef list< exprNode * > expr_list;
00147 typedef expr_list::iterator expr_list_p;
00148
00149 typedef list< declNode * > decl_list;
00150 typedef decl_list::iterator decl_list_p;
00151
00152 typedef list< targetNode * > target_list;
00153 typedef target_list::iterator target_list_p;
00154
00155 typedef list< attribNode * > attrib_list;
00156 typedef attrib_list::iterator attrib_list_p;
00157
00158 typedef list< indexNode *> index_list;
00159 typedef index_list::iterator index_list_p;
00160
00161 typedef list< idNode * > id_list;
00162 typedef id_list::iterator id_list_p;
00163
00164 typedef list< stmtNode * > stmt_list;
00165 typedef stmt_list::iterator stmt_list_p;
00166
00167 typedef list< gotoNode * > goto_list;
00168 typedef goto_list::iterator goto_list_p;
00169
00170 typedef list< defNode * > def_list;
00171 typedef def_list::iterator def_list_p;
00172
00173 typedef list< Annote * > annote_list;
00174 typedef annote_list::iterator annote_list_p;
00175
00176 typedef list< unitNode * > unit_list;
00177 typedef unit_list::iterator unit_list_p;
00178
00179 typedef vector< string > str_vec;
00180 typedef str_vec::iterator str_vec_p;
00181
00182 typedef list< string > str_list;
00183 typedef str_list::iterator str_list_p;
00184
00185 typedef list< textNode * > text_list;
00186 typedef text_list::iterator text_list_p;
00187
00188 typedef list< suespecNode * > suespec_list;
00189 typedef suespec_list::iterator suespec_list_p;
00190
00191 typedef list< blockNode * > block_list;
00192 typedef block_list::iterator block_list_p;
00193
00194 typedef list< basicblockNode * > basicblock_list;
00195 typedef basicblock_list::iterator basicblock_list_p;
00196
00197 typedef list< operandNode * > operand_list;
00198 typedef operand_list::iterator operand_list_p;
00199
00200 class Visitor;
00201 class Walker;
00202 class Changer;
00203
00204 class output_context;
00205
00206
00207
00208
00209
00210 typedef list<LirInst*> instruction_list;
00211 typedef instruction_list::iterator instruction_list_p;
00212
00213
00214 typedef hash_set_ex<LirInst*> instruction_set;
00215 typedef instruction_set::iterator instruction_set_p;
00216
00217
00218 typedef list<LirBlock*> LirBlockList;
00219 typedef LirBlockList::iterator LirBlockList_p;
00220 typedef hash_set_ex<LirBlock*> LirBlockSet;
00221 typedef LirBlockSet::iterator LirBlockSet_p;
00222
00223
00224
00225
00226
00227
00228 typedef enum {
00229
00230 Const, Id, Binary, Unary, Cast, Comma, Ternary, Call, Initializer,
00231
00232
00233 Label, Switch, Case, If, While, Do, For, Goto, Continue,
00234 Break, Return, Block,
00235
00236
00237 Prim, Tdef, Ptr, Array, Func, Struct, Union, Enum, sueSpec,
00238
00239
00240
00241 Decl,
00242
00243
00244 Attrib,
00245
00246
00247 Proc,
00248
00249
00250 Text,
00251
00252
00253 Expr,
00254
00255
00256 Undeclared,
00257
00258
00259 Unit,
00260
00261
00262 Meta,
00263
00264
00265 Operand,
00266
00267
00268 Condition,
00269
00270
00271 ThreeAddr,
00272
00273 } NodeType;
00274
00275
00276
00277 typedef enum {
00278 Redecl,
00279 NoRedecl,
00280 SU,
00281 Formal
00282
00283 } ScopeState;
00284
00285
00286
00287
00288 typedef enum { Right, Left } Assoc;
00289
00290
00291
00292 #include "coord.h"
00293 #include "operators.h"
00294 #include "basic_type.h"
00295 #include "constant.h"
00296 #include "annote.h"
00297 #include "ast.h"
00298 #include "visitor.h"
00299 #include "walker.h"
00300 #include "changer.h"
00301 #include "dataflow.h"
00302 #include "symbol.h"
00303 #include "phase.h"
00304 #include "output_context.h"
00305 #include "arch_info.h"
00306 #include "instruction.h"
00307
00308
00309
00310 typedef map<Node *,
00311 unsigned int,
00312 less< Node * > > numbering_map;
00313
00314
00315
00316
00317 class CBZ {
00318
00319 public:
00320
00321
00322 static unit_list Program;
00323
00324
00325 static str_vec Files;
00326
00327
00328 static string input_suffix ;
00329 static string output_suffix ;
00330
00331
00332 static string preproc;
00333 static string default_preproc ;
00334 static string gcc_preproc ;
00335 static string ansi_preproc ;
00336
00337
00338
00339 static float VersionNumber ;
00340 static string VersionDate ;
00341 static string Executable;
00342 static arch_info ArchInfo;
00343
00344
00345 static int WarningLevel ;
00346
00347
00348 static str_list * cpp_flags;
00349
00350
00351
00352 static unitNode * current_unit;
00353 static int current_file;
00354 static int current_line;
00355 static int current_offset;
00356
00357 static text_list pragmas;
00358
00359 static void set_file(const char *name, int line, bool is_new_file);
00360
00361 static bool is_file_included();
00362
00363 static void char_to_text(char * array, unsigned char value);
00364
00365
00366
00367 static string PhaseName;
00368
00369
00370
00371 static bool QuietlyIgnore;
00372 static bool DebugLex;
00373 static bool PrintSymTables;
00374 static bool TrackInsertSymbol;
00375 static bool PrintLineOffset;
00376 static bool IgnoreLineDirectives;
00377 static bool ANSIOnly;
00378 static bool FormatReadably;
00379 static bool Preprocess;
00380 static bool ShowPreprocess;
00381 static bool GCCisms;
00382 static bool NoRegAlloc;
00383
00384
00385
00386 static bool OldStyleFunctionDefinition;
00387
00388
00389
00390 static void Fail(const string file, int line, const string msg);
00391 static void SyntaxError(string s);
00392 static void Warning(int level, string s);
00393 static void SyntaxError(Coord c, string s);
00394 static void Warning(int level, Coord c, string s);
00395 static void WarnAboutPrecedence(unsigned int op_id, exprNode * the_expr);
00396 static void Error(Coord c, string s);
00397
00398
00399
00400
00401
00402
00403
00404 #define CBZFAIL( errfmt ) \
00405 CBZ::Fail( __FILE__, __LINE__, cbz_util::string_format errfmt );
00406
00407
00408
00409
00410 static string get_temp_id_str();
00411
00412
00413 static idNode * get_temp_id();
00414
00415
00416 static idNode * get_temp_var( blockNode * containing_block, typeNode * type );
00417
00418 private:
00419
00420
00421 static unsigned int next_temp_id_seed;
00422
00423 };
00424
00425
00426
00427 struct _TQ {
00428 typeNode::Type_qualifiers tq;
00429 declNode::Storage_class sc;
00430 simpleCoord coord;
00431 };
00432
00433 struct _TYPE {
00434 typeNode * ty;
00435 declNode::Storage_class sc;
00436 };
00437
00438
00439 #endif // CBZ_C_BREEZE_H