diff options
Diffstat (limited to 'subx/037heap.cc')
-rw-r--r-- | subx/037heap.cc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/subx/037heap.cc b/subx/037heap.cc new file mode 100644 index 00000000..315fd0d5 --- /dev/null +++ b/subx/037heap.cc @@ -0,0 +1,29 @@ +//: Support for dynamic allocation. +//: +//: Just provide a special label marking the first unused address in the data +//: segment. Then we'll write SubX helpers to make use of it. + +:(before "Begin rewrite_global_variables") +insert_heap_global_variable(p); +:(code) +void insert_heap_global_variable(program& p) { + if (SIZE(p.segments) < 2) + return; // no data segment defined + // Start-of-heap: + p.segments.at(1).lines.push_back(label("Start-of-heap")); +} + +line label(string s) { + line result; + result.words.push_back(word()); + result.words.back().data = (s+":"); + return result; +} + +line imm32(const string& s) { + line result; + result.words.push_back(word()); + result.words.back().data = s; + result.words.back().metadata.push_back("imm32"); + return result; +} |