Type.py (7055:4e24742201d7) | Type.py (7453:1a5db3dd0f62) |
---|---|
1# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 2# Copyright (c) 2009 The Hewlett-Packard Development Company 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer; --- 191 unchanged lines hidden (view full) --- 200 */ 201 202#ifndef __${{self.c_ident}}_HH__ 203#define __${{self.c_ident}}_HH__ 204 205#include <iostream> 206 207#include "mem/ruby/common/Global.hh" | 1# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 2# Copyright (c) 2009 The Hewlett-Packard Development Company 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer; --- 191 unchanged lines hidden (view full) --- 200 */ 201 202#ifndef __${{self.c_ident}}_HH__ 203#define __${{self.c_ident}}_HH__ 204 205#include <iostream> 206 207#include "mem/ruby/common/Global.hh" |
208#include "mem/gems_common/Allocator.hh" | |
209''') 210 211 for dm in self.data_members.values(): 212 if not dm.type.isPrimitive: 213 code('#include "mem/protocol/$0.hh"', dm.type.c_ident) 214 215 parent = "" 216 if "interface" in self: --- 20 unchanged lines hidden (view full) --- 237 # Look for the type default 238 tid = dm.type.c_ident 239 code('m_$ident = ${{dm.type["default"]}}; // default value of $tid') 240 else: 241 code('// m_$ident has no default') 242 code.dedent() 243 code('}') 244 | 208''') 209 210 for dm in self.data_members.values(): 211 if not dm.type.isPrimitive: 212 code('#include "mem/protocol/$0.hh"', dm.type.c_ident) 213 214 parent = "" 215 if "interface" in self: --- 20 unchanged lines hidden (view full) --- 236 # Look for the type default 237 tid = dm.type.c_ident 238 code('m_$ident = ${{dm.type["default"]}}; // default value of $tid') 239 else: 240 code('// m_$ident has no default') 241 code.dedent() 242 code('}') 243 |
244 # ******** Copy constructor ******** 245 if not self.isGlobal: 246 code('${{self.c_ident}}(const ${{self.c_ident}}&other)') 247 248 # Call superclass constructor 249 if "interface" in self: 250 code(' : ${{self["interface"]}}(other)') 251 252 code('{') 253 code.indent() 254 255 for dm in self.data_members.values(): 256 code('m_${{dm.ident}} = other.m_${{dm.ident}};') 257 258 if self.isMessage: 259 code('proc_id = other.proc_id;') 260 261 code.dedent() 262 code('}') 263 |
|
245 # ******** Full init constructor ******** 246 if not self.isGlobal: 247 params = [ 'const %s& local_%s' % (dm.type.c_ident, dm.ident) \ 248 for dm in self.data_members.itervalues() ] 249 250 if self.isMessage: 251 params.append('const unsigned local_proc_id') 252 --- 12 unchanged lines hidden (view full) --- 265 code('m_${{dm.ident}}${{dm["nextLineCallHack"]}};') 266 267 if self.isMessage: 268 code('proc_id = local_proc_id;') 269 270 code.dedent() 271 code('}') 272 | 264 # ******** Full init constructor ******** 265 if not self.isGlobal: 266 params = [ 'const %s& local_%s' % (dm.type.c_ident, dm.ident) \ 267 for dm in self.data_members.itervalues() ] 268 269 if self.isMessage: 270 params.append('const unsigned local_proc_id') 271 --- 12 unchanged lines hidden (view full) --- 284 code('m_${{dm.ident}}${{dm["nextLineCallHack"]}};') 285 286 if self.isMessage: 287 code('proc_id = local_proc_id;') 288 289 code.dedent() 290 code('}') 291 |
273 # create a static factory method 274 if "interface" in self: 275 code(''' 276static ${{self["interface"]}}* | 292 # create a static factory method and a clone member 293 code(''' 294static ${{self.c_ident}}* |
277create() 278{ 279 return new ${{self.c_ident}}(); 280} | 295create() 296{ 297 return new ${{self.c_ident}}(); 298} |
281''') | |
282 | 299 |
283 # ******** Message member functions ******** 284 # FIXME: those should be moved into slicc file, slicc should 285 # support more of the c++ class inheritance 286 287 if self.isMessage: 288 code(''' 289Message * | 300${{self.c_ident}}* |
290clone() const 291{ | 301clone() const 302{ |
292 checkAllocator(); 293 return s_allocator_ptr->allocate(*this); | 303 return new ${{self.c_ident}}(*this); |
294} | 304} |
295 296void 297destroy() 298{ 299 checkAllocator(); 300 s_allocator_ptr->deallocate(this); 301} 302 303static Allocator<${{self.c_ident}}>* s_allocator_ptr; 304 305static void 306checkAllocator() 307{ 308 if (s_allocator_ptr == NULL) { 309 s_allocator_ptr = new Allocator<${{self.c_ident}}>; 310 } 311} | |
312''') 313 314 if not self.isGlobal: 315 # const Get methods for each field 316 code('// Const accessors methods for each field') 317 for dm in self.data_members.values(): 318 code(''' 319/** \\brief Const accessor method for ${{dm.ident}} field. --- 89 unchanged lines hidden (view full) --- 409 410#include <iostream> 411 412#include "mem/protocol/${{self.c_ident}}.hh" 413 414using namespace std; 415''') 416 | 305''') 306 307 if not self.isGlobal: 308 # const Get methods for each field 309 code('// Const accessors methods for each field') 310 for dm in self.data_members.values(): 311 code(''' 312/** \\brief Const accessor method for ${{dm.ident}} field. --- 89 unchanged lines hidden (view full) --- 402 403#include <iostream> 404 405#include "mem/protocol/${{self.c_ident}}.hh" 406 407using namespace std; 408''') 409 |
417 if self.isMessage: 418 code('Allocator<${{self.c_ident}}>* ${{self.c_ident}}::s_allocator_ptr = NULL;') | |
419 code(''' 420/** \\brief Print the state of this object */ 421void 422${{self.c_ident}}::print(ostream& out) const 423{ 424 out << "[${{self.c_ident}}: "; 425''') 426 --- 288 unchanged lines hidden --- | 410 code(''' 411/** \\brief Print the state of this object */ 412void 413${{self.c_ident}}::print(ostream& out) const 414{ 415 out << "[${{self.c_ident}}: "; 416''') 417 --- 288 unchanged lines hidden --- |