Commit db7743f6 authored by Benoit Perrot's avatar Benoit Perrot
Browse files

VM: Use variable input and output streams.

parent 9aacb73f
2003-07-17 Benot Perrot <benoit@lrde.epita.fr> 2003-07-17 Benot Perrot <benoit@lrde.epita.fr>
* src/inst/section.hh: Export types.
* src/vm/virtual_machine.cc, src/vm/virtual_machine.hh:
Use variable input and output streams.
2003-07-17 Benot Perrot <benoit@lrde.epita.fr>
* src/inst/section.hh: Add a const accessor to Section's labels. * src/inst/section.hh: Add a const accessor to Section's labels.
2003-07-12 Benot Perrot <benoit@lrde.epita.fr> 2003-07-12 Benot Perrot <benoit@lrde.epita.fr>
......
...@@ -33,6 +33,8 @@ namespace inst ...@@ -33,6 +33,8 @@ namespace inst
{ {
protected: protected:
typedef std::list<const Label*> label_list_t; typedef std::list<const Label*> label_list_t;
public:
typedef std::map<int, label_list_t> offset_label_t; typedef std::map<int, label_list_t> offset_label_t;
typedef std::map<const Label, int> label_offset_t; typedef std::map<const Label, int> label_offset_t;
......
...@@ -507,7 +507,7 @@ namespace vm ...@@ -507,7 +507,7 @@ namespace vm
{ {
// print_int (integer: $a0) // print_int (integer: $a0)
case 1: case 1:
std::cout << cpu.get_a0(); ostr << cpu.get_a0();
break; break;
// print_string (buffer: $a0) // print_string (buffer: $a0)
...@@ -517,7 +517,7 @@ namespace vm ...@@ -517,7 +517,7 @@ namespace vm
char b = memory.load_byte(i); char b = memory.load_byte(i);
if (b == 0) if (b == 0)
break; break;
std::cout << b; ostr << b;
} }
break; break;
...@@ -528,8 +528,8 @@ namespace vm ...@@ -528,8 +528,8 @@ namespace vm
int c = 0; int c = 0;
for (; (i < cpu.get_a1() - 1) && (c != '\n') && (c != '\r') ; ++i) for (; (i < cpu.get_a1() - 1) && (c != '\n') && (c != '\r') ; ++i)
{ {
c = std::cin.get(); c = istr.get();
if (std::cin.eof()) if (istr.eof())
break; break;
memory.store_byte(cpu.get_a0() + i, c); memory.store_byte(cpu.get_a0() + i, c);
} }
...@@ -550,7 +550,7 @@ namespace vm ...@@ -550,7 +550,7 @@ namespace vm
default: default:
assertion(!"syscall: Not implemented yet"); assertion(!"syscall: Not implemented yet");
}; };
std::cout.flush(); ostr.flush();
} }
} // namespace vm } // namespace vm
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#ifndef VM_VIRTUAL_MACHINE_HH #ifndef VM_VIRTUAL_MACHINE_HH
# define VM_VIRTUAL_MACHINE_HH # define VM_VIRTUAL_MACHINE_HH
# include <iostream>
# include "misc/contract.hh" # include "misc/contract.hh"
# include "common.hh" # include "common.hh"
...@@ -35,7 +37,9 @@ namespace vm ...@@ -35,7 +37,9 @@ namespace vm
protected inst::ConstVisitor protected inst::ConstVisitor
{ {
public: public:
VirtualMachine(): VirtualMachine(std::istream& istr = std::cin,
std::ostream& ostr = std::cout):
istr(istr), ostr(ostr),
program(0), text_section(0) program(0), text_section(0)
{ {
} }
...@@ -149,6 +153,9 @@ namespace vm ...@@ -149,6 +153,9 @@ namespace vm
protected: protected:
bool halt; bool halt;
std::istream& istr;
std::ostream& ostr;
protected: protected:
Cpu cpu; Cpu cpu;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment