1 //===-- jitcs_instructionstream.h - blockwise instructions ------*- C++ -*-===//
5 //===----------------------------------------------------------------------===//
7 #ifndef _JITCS_INSTRUCTIONSTREAM_H_
8 #define _JITCS_INSTRUCTIONSTREAM_H_
10 #include "jitcs_adt_ref.h"
11 #include "jitcs_base.h"
12 #include "jitcs_ids.h"
13 #include "jitcs_instruction.h"
14 #include "jitcs_bblock.h"
18 struct MemoryReference
;
19 struct VirtualRegister
;
21 struct InstructionStream
{
22 Ref
<Instruction
> alloc(u32 d
) {
23 if (d
> space
) _flush();
26 return reinterpret_cast<Instruction
*>(t
);
30 void init(iptr
* dp
, u32 spc
) { cur
= dp
; space
= spc
; }
31 virtual void _flush() = 0;
39 struct InstructionStreamBuffer
: InstructionStream
{
40 enum { INSSZ2
= (INSSZ
+ 31) & (~31) };
41 RefOrNull
<BasicBlock
> bb
;
42 iptr originalBuffer
[INSSZ2
];
44 InstructionStreamBuffer() = default;
45 void start(RefOrNull
<BasicBlock
> block
) { bb
= block
; init(&originalBuffer
[0], INSSZ2
); }
46 void start(Ref
<BasicBlock
> block
) { bb
._ptr
= block
._ptr
; init(&originalBuffer
[0], INSSZ2
); }
47 void end() { _flush(); bb
= nullptr; }
50 virtual void _flush() {
52 bb
.removeNullType()->append_copy(&originalBuffer
[0], INSSZ2
- space
);
53 init(&originalBuffer
[0], INSSZ2
);
57 } // end of namespace jitcs
60 // _JITCS_INSTRUCTIONSTREAM_H_