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>
* 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.
2003-07-12 Benot Perrot <benoit@lrde.epita.fr>
......
......@@ -33,6 +33,8 @@ namespace inst
{
protected:
typedef std::list<const Label*> label_list_t;
public:
typedef std::map<int, label_list_t> offset_label_t;
typedef std::map<const Label, int> label_offset_t;
......
......@@ -507,7 +507,7 @@ namespace vm
{
// print_int (integer: $a0)
case 1:
std::cout << cpu.get_a0();
ostr << cpu.get_a0();
break;
// print_string (buffer: $a0)
......@@ -517,7 +517,7 @@ namespace vm
char b = memory.load_byte(i);
if (b == 0)
break;
std::cout << b;
ostr << b;
}
break;
......@@ -528,8 +528,8 @@ namespace vm
int c = 0;
for (; (i < cpu.get_a1() - 1) && (c != '\n') && (c != '\r') ; ++i)
{
c = std::cin.get();
if (std::cin.eof())
c = istr.get();
if (istr.eof())
break;
memory.store_byte(cpu.get_a0() + i, c);
}
......@@ -550,7 +550,7 @@ namespace vm
default:
assertion(!"syscall: Not implemented yet");
};
std::cout.flush();
ostr.flush();
}
} // namespace vm
......@@ -19,6 +19,8 @@
#ifndef VM_VIRTUAL_MACHINE_HH
# define VM_VIRTUAL_MACHINE_HH
# include <iostream>
# include "misc/contract.hh"
# include "common.hh"
......@@ -35,7 +37,9 @@ namespace vm
protected inst::ConstVisitor
{
public:
VirtualMachine():
VirtualMachine(std::istream& istr = std::cin,
std::ostream& ostr = std::cout):
istr(istr), ostr(ostr),
program(0), text_section(0)
{
}
......@@ -149,6 +153,9 @@ namespace vm
protected:
bool halt;
std::istream& istr;
std::ostream& ostr;
protected:
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