Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
82 lines (67 loc) · 3.74 KB

File metadata and controls

82 lines (67 loc) · 3.74 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// This example program shows how to write out a binary file representing the AST.
#include "rose.h"
// This is OK if not declared in a header file
using namespace std;
// Example of user defined attribute
class UserDefinedAttribute : public AstAttribute
{
public:
// Function interface for supporting File IO.
// Required if user-defined attributes are to be reconstructed in File input.
// But not defined as pure virtual functions in the AstAttribute base class.
virtual string attribute_class_name() { return "UserDefinedAttribute"; }
virtual UserDefinedAttribute* constructor() { return new UserDefinedAttribute(); }
virtual char* packed() { return (char*) this; }
virtual int packed_size() { return 0; }
virtual void unpacked( char* ptr ) { }
};
int
main ( int argc, char * argv[] )
{
// Initialize and check compatibility. See Rose::initialize
ROSE_INITIALIZE;
SgProject* project = frontend(argc,argv);
ROSE_ASSERT (project != NULL);
// Get the file name of the source file input on the command line (a.out is default if none is specified)
string fileName = project->get_outputFileName();
// This macro registers any user-defined classes derived from AstAttribute so that
// they can be rebuilt by mechanism to read the file. This must be called at any
// point before the AST_FILE_IO::readASTFromFile() is called. It is a macro because
// we need to build the type and the name of the type.
REGISTER_ATTRIBUTE_FOR_FILE_IO(UserDefinedAttribute);
// This phase:
// 1) builds the lists of numbers of IR nodes for each type
// 2) sets the free pointer in each IR node to a global id number (so that the pointers can be reconstructed)
// 3) builds list of static data held in the IR nodes (builtin types, global function type symbol table, root of AST)
// 4) registers all astAttribute objects (base classes of user defined objects attached to the AST)
AST_FILE_IO::startUp( project ) ;
// This phase:
// 1) write out lists of static data
// 2) for each memory pool (each IR node type)
// a) loop over each IR node for selected type (SgStatement, etc.)
// *) copy data from each IR node to an entry in a contiguous array
// of associated StorageClass nodes (classes generated by ROSETTA)
// *) write out all astArrtibute information (calls user-defined function to pack data)
// b) write out single the storage class array (fastest possible binary file I/O)
AST_FILE_IO::writeASTToFile ( fileName + ".binaryAST" );
// Delete the memory pools, removing the entire AST from memory (and resetting all static data pointers).
AST_FILE_IO::clearAllMemoryPools();
// Rebuild the AST from the save binary file
// 1) Rebuild the memory pools sizes for the IR nodes from the information saved
// in the file (only applies to AST read in from empty memory pools)
// 2) Extends the memory pools to hold correct number of allocated IR nodes from AST in file
// 3) for each memory pool (each IR node type)
// a) Read the stored storage classes.
// b) Read the static data for each IR node type
// c) Loop over array of storage classes
// *) rebuild each IR node
// *) convert global id values to pointer addresses in memory pools
// d) delete the StorageClass array
// e) Save the static data for the IR node type (save in the
// AST_FILE_IO::staticDataMemberManagementClass (or some name like that))
project = (SgProject*) (AST_FILE_IO::readASTFromFile ( fileName + ".binaryAST" ) );
// Run all the AST consistancy tests
AstTests::runAllTests(project);
// Generate the source code from the AST and compile it
return backend(project);
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.