Skip to content

Commit 97efe64

Browse files
committed
Compiles helloWorld from CLI
1 parent 6fe46b4 commit 97efe64

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

chapter25/src/main/java/com/seaofnodes/simple/codegen/Encoding.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,10 @@ else if( bb instanceof FunNode ) {
390390
opLen(bb, (byte) (_bits.size() - opStart(bb)));
391391
}
392392
for( Node n : bb._outputs ) {
393-
if( n instanceof MachNode mach && !(n instanceof FunNode) ) {
393+
if( n instanceof MachNode mach && !(n instanceof FunNode) &&
394+
// FunPtrs are encoding in the block of their control, not
395+
// the block of the ReturnNode input - which is also a CFG.
396+
!(n instanceof FunPtrNode && bb instanceof ReturnNode) ) {
394397
opStart(n, _bits.size());
395398
mach.encoding( this );
396399
opLen(n, (byte) (_bits.size() - opStart(n)));
@@ -490,7 +493,7 @@ void patchLocalRelocations() {
490493
// and, it can only be used to test against zero or equals to
491494
// another function pointer... i.e., there Is No Code Here.
492495
int target = dst == null ? start : opStart(dst);
493-
((RIPRelSize)src).patch(this, start, opLen(src), target - start);
496+
((RIPRelSize)src).patch(this, start, opLen(src), target - start);
494497
}
495498
}
496499

chapter25/src/main/java/com/seaofnodes/simple/codegen/Serialize.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ public static Ary<Node> nodeOrder( CodeGen code ) {
422422
// All the CompUnits
423423
for( CompUnit cu : code._compunits.values() ) {
424424
// Whole CompUnits have no users, went dead
425-
if( !cu._start.isDead() ) {
425+
if( cu._start != null && !cu._start.isDead() ) {
426426
nodes.add(cu._start);
427427
// Memory proj
428428
nodes.add(cu._start.proj(1));

chapter25/src/test/java/com/seaofnodes/simple/Chapter25Test.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,18 @@ public void testHelloWorldNoInlineImportsSys() throws Exception {
224224
CodeGen code = new CodeGen(null,"build/objs",new Ary<>(new String[]{RELEASE_SYS_BLDDIR}),
225225
base,prog,123L,TypeInteger.BOT);
226226
code.driver(TestC.CPU_PORT,TestC.CALL_CONVENTION,false,true);
227+
String str = code.toString();
228+
String asm = code.asm();
227229

228230
String obj = "build/objs/"+base+".o";
229231
String exe = "build/objs/"+base+(TestC.OS.startsWith("Windows") ? ".exe" : "");
230232
String syms = run(new String[]{"nm",obj});
231233
assertTrue(syms, syms.contains(" U sys.io.p_noInline"));
232234

233-
run(new String[]{"gcc",obj,RELEASE_SYS_BLDDIR+"/sys.o","-lm","-g","-o",exe});
234-
assertEquals(expected, run(new String[]{exe}));
235+
String out = run(new String[]{"gcc",obj,RELEASE_SYS_BLDDIR+"/sys.o","-lm","-g","-o",exe});
236+
assertEquals("",out);
237+
String rez = run(new String[]{exe});
238+
assertEquals(expected,rez);
235239
}
236240

237241
private static String run(String[] cmd) throws Exception {

0 commit comments

Comments
 (0)