ruby: libruby_init now takes parsed Ruby-lang config text
libruby_init now expects to get a file that contains the output of running a ruby-lang configuration, opposed to the ruby-lang configuration itself.
This commit is contained in:
parent
225de2eaff
commit
80544cda8a
2 changed files with 12 additions and 56 deletions
|
@ -100,9 +100,11 @@ class LibRubyObject
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.printConstructors()
|
def self.printConstructors()
|
||||||
|
str = ""
|
||||||
@@all_objs.each { |obj|
|
@@all_objs.each { |obj|
|
||||||
print obj.cppClassName, " ", obj.obj_name, " ",obj.argv,"\n"
|
str += obj.cppClassName + " " + obj.obj_name + " " + obj.argv + "\n"
|
||||||
}
|
}
|
||||||
|
return str
|
||||||
end
|
end
|
||||||
def self.all()
|
def self.all()
|
||||||
@@all_objs
|
@@all_objs
|
||||||
|
@ -215,7 +217,7 @@ class RubySystem
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.generateConfig()
|
def self.getConfig()
|
||||||
# get current time for random seed if set to "rand"
|
# get current time for random seed if set to "rand"
|
||||||
if @@params[:random_seed] == "rand"
|
if @@params[:random_seed] == "rand"
|
||||||
t = Time.now
|
t = Time.now
|
||||||
|
@ -224,13 +226,18 @@ class RubySystem
|
||||||
if ! @@params[:random_seed].is_a?(Integer)
|
if ! @@params[:random_seed].is_a?(Integer)
|
||||||
raise TypeException
|
raise TypeException
|
||||||
end
|
end
|
||||||
print "System sys0 ",argv,"\n"
|
str = "System sys0 "+argv+"\n"
|
||||||
LibRubyObject.all.each { |obj|
|
LibRubyObject.all.each { |obj|
|
||||||
if obj.is_a?(SetAssociativeCache)
|
if obj.is_a?(SetAssociativeCache)
|
||||||
obj.calculateLatency
|
obj.calculateLatency
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
LibRubyObject.printConstructors
|
str += LibRubyObject.printConstructors
|
||||||
|
return str
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.generateConfig()
|
||||||
|
puts getConfig
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.printIfacePorts()
|
def self.printIfacePorts()
|
||||||
|
|
|
@ -88,58 +88,7 @@ vector<string> tokenizeString(string str, string delims)
|
||||||
|
|
||||||
void libruby_init(const char* cfg_filename)
|
void libruby_init(const char* cfg_filename)
|
||||||
{
|
{
|
||||||
stringstream cfg_output;
|
ifstream cfg_output(cfg_filename);
|
||||||
|
|
||||||
// first we execute the Ruby-lang configuration script
|
|
||||||
int fd[2];
|
|
||||||
int pid;
|
|
||||||
if (pipe(fd) == -1) {
|
|
||||||
perror("Error Creating Pipe");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
pid = fork();
|
|
||||||
if (pid == -1){
|
|
||||||
perror("Error forking");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pid) {
|
|
||||||
// child
|
|
||||||
close(fd[0]); // close the read end of the pipe
|
|
||||||
// replace stdout with the write pipe
|
|
||||||
if (dup2(fd[1], STDOUT_FILENO) == -1) {
|
|
||||||
perror("Error redirecting stdout");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
if (execlp("ruby", "ruby", "-I", GEMS_ROOT "/ruby/config",
|
|
||||||
GEMS_ROOT "/ruby/config/print_cfg.rb", "-r", cfg_filename, NULL)) {
|
|
||||||
perror("execlp");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
close(fd[1]);
|
|
||||||
|
|
||||||
int child_status;
|
|
||||||
if (wait(&child_status) == -1) {
|
|
||||||
perror("wait");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
if (child_status != EXIT_SUCCESS) {
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
char buf[100];
|
|
||||||
int bytes_read;
|
|
||||||
while( (bytes_read = read(fd[0], buf, 100)) > 0 ) {
|
|
||||||
for (int i=0;i<bytes_read;i++) {
|
|
||||||
// cout << buf[i];
|
|
||||||
cfg_output << buf[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert(bytes_read == 0);
|
|
||||||
close(fd[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<RubyObjConf> * sys_conf = new vector<RubyObjConf>;
|
vector<RubyObjConf> * sys_conf = new vector<RubyObjConf>;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue