summaryrefslogtreecommitdiff
path: root/chapter21/src/main/java/com
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2025-03-19 09:54:38 -0700
committerCliff Click <cliffc@acm.org>2025-03-19 09:54:38 -0700
commit352c6927252137a252ab942c83695890fb332004 (patch)
treecf36c8a487fc7d05d487531f565ce3015a8f9493 /chapter21/src/main/java/com
parent0328057dc9e5a7b4bcee4b9fe9260c91a59d5b5e (diff)
downloadSimple-352c6927252137a252ab942c83695890fb332004.tar.gz
Simple-352c6927252137a252ab942c83695890fb332004.zip
ELF exporting takes a target file
Diffstat (limited to 'chapter21/src/main/java/com')
-rw-r--r--chapter21/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java7
-rw-r--r--chapter21/src/main/java/com/seaofnodes/simple/codegen/ElfFile.java12
2 files changed, 7 insertions, 12 deletions
diff --git a/chapter21/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java b/chapter21/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java
index 88144a1d..8788d109 100644
--- a/chapter21/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java
+++ b/chapter21/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java
@@ -2,11 +2,10 @@ package com.seaofnodes.simple.codegen;
import com.seaofnodes.simple.*;
import com.seaofnodes.simple.node.*;
-
import com.seaofnodes.simple.print.*;
import com.seaofnodes.simple.type.*;
-
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.util.BitSet;
import java.util.HashMap;
import java.util.IdentityHashMap;
@@ -323,11 +322,11 @@ public class CodeGen {
// ---------------------------
// Exporting to external formats
- public CodeGen exportELF() {
+ public CodeGen exportELF(String fname) throws IOException {
assert _phase == Phase.Encoding;
_phase = Phase.Export;
ElfFile obj = new ElfFile(this);
- obj.export();
+ obj.export(fname);
return this;
}
diff --git a/chapter21/src/main/java/com/seaofnodes/simple/codegen/ElfFile.java b/chapter21/src/main/java/com/seaofnodes/simple/codegen/ElfFile.java
index c39c5dc2..019cdf90 100644
--- a/chapter21/src/main/java/com/seaofnodes/simple/codegen/ElfFile.java
+++ b/chapter21/src/main/java/com/seaofnodes/simple/codegen/ElfFile.java
@@ -258,7 +258,7 @@ public class ElfFile {
}
}
- public void export() {
+ public void export(String fname) throws IOException {
DataSection strtab = new DataSection(".strtab", 3 /* SHT_SYMTAB */);
// first byte is reserved for an empty string
strtab._contents.write(0);
@@ -375,13 +375,9 @@ public class ElfFile {
}
assert out.position() == size;
- try {
- BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("a.o"));
- bos.write(out.array());
- bos.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fname));
+ bos.write(out.array());
+ bos.close();
}
}