Fix archive issues in cli
This commit is contained in:
@@ -1,8 +1,19 @@
|
|||||||
// c
|
// c
|
||||||
extern func puts(text: cstring)
|
extern func puts(text: cstring)
|
||||||
|
|
||||||
|
struct Human {
|
||||||
|
name: cstring
|
||||||
|
age: u32
|
||||||
|
}
|
||||||
|
|
||||||
func main(args: []cstring): i64
|
func main(args: []cstring): i64
|
||||||
{
|
{
|
||||||
puts("Hello, World")
|
let x: Human = struct {
|
||||||
|
name = "Oliver"
|
||||||
|
age = 23
|
||||||
|
}
|
||||||
|
|
||||||
|
puts(x.name)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,10 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Remove="assets\libruntime_x64.a" />
|
<None Remove="assets\runtime.o" />
|
||||||
<EmbeddedResource Include="assets\libruntime_x64.a" />
|
<EmbeddedResource Include="assets\runtime.o" />
|
||||||
|
<None Remove="assets\x64.o" />
|
||||||
|
<EmbeddedResource Include="assets\x64.o" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -124,32 +124,38 @@ for (var i = 0; i < typedSyntaxTrees.Count; i++)
|
|||||||
objectFiles.Add(objFilePath);
|
objectFiles.Add(objFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
const string runtimeName = "libruntime_x64.a";
|
|
||||||
|
|
||||||
var resources = Assembly.GetExecutingAssembly().GetManifestResourceNames();
|
var resources = Assembly.GetExecutingAssembly().GetManifestResourceNames();
|
||||||
var runtime = resources.First(r => r.EndsWith(runtimeName));
|
|
||||||
|
|
||||||
await using var reader = Assembly.GetExecutingAssembly().GetManifestResourceStream(runtime);
|
string[] runtimeObjects = ["runtime.o", "x64.o"];
|
||||||
|
|
||||||
if (reader == null)
|
foreach (var runtimeObject in runtimeObjects)
|
||||||
{
|
{
|
||||||
Console.Error.WriteLine($"Cannot open stream to '{runtimeName}'");
|
var runtime = resources.First(r => r.EndsWith(runtimeObject));
|
||||||
return 1;
|
|
||||||
|
await using var reader = Assembly
|
||||||
|
.GetExecutingAssembly()
|
||||||
|
.GetManifestResourceStream(runtime);
|
||||||
|
|
||||||
|
if (reader == null)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"Cannot open read stream to '{runtimeObject}'");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var runtimePath = Path.Combine("build", "runtime", runtimeObject);
|
||||||
|
var runtimeDir = Path.GetDirectoryName(runtimePath);
|
||||||
|
if (!string.IsNullOrEmpty(runtimeDir))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(runtimeDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
await using var writer = new FileStream(runtimePath, FileMode.Create);
|
||||||
|
|
||||||
|
reader.CopyTo(writer);
|
||||||
|
|
||||||
|
objectFiles.Add(runtimePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
var runtimePath = Path.Combine("build", "runtime", runtimeName);
|
|
||||||
var runtimeDir = Path.GetDirectoryName(runtimePath);
|
|
||||||
if (!string.IsNullOrEmpty(runtimeDir))
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(runtimeDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
await using var writer = new FileStream(runtimePath, FileMode.Create);
|
|
||||||
|
|
||||||
reader.CopyTo(writer);
|
|
||||||
|
|
||||||
objectFiles.Add(runtimePath);
|
|
||||||
|
|
||||||
var outPath = options.OutputPath ?? Path.Combine("build", "out.a");
|
var outPath = options.OutputPath ?? Path.Combine("build", "out.a");
|
||||||
var outDir = Path.GetDirectoryName(outPath);
|
var outDir = Path.GetDirectoryName(outPath);
|
||||||
if (!string.IsNullOrEmpty(outDir))
|
if (!string.IsNullOrEmpty(outDir))
|
||||||
@@ -163,4 +169,5 @@ if (!archiveResult)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
Binary file not shown.
BIN
src/compiler/NubLang.CLI/assets/x64.o
Normal file
BIN
src/compiler/NubLang.CLI/assets/x64.o
Normal file
Binary file not shown.
@@ -939,7 +939,7 @@ public class QBEGenerator
|
|||||||
{
|
{
|
||||||
destination = TmpName();
|
destination = TmpName();
|
||||||
var size = SizeOf(structInitializer.StructType);
|
var size = SizeOf(structInitializer.StructType);
|
||||||
_writer.Indented($"{destination} =l alloc8 {size}");
|
_writer.Indented($"{destination} =l call $malloc(l {size})");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var field in structDef.Fields)
|
foreach (var field in structDef.Fields)
|
||||||
|
|||||||
3
src/runtime/.gitignore
vendored
3
src/runtime/.gitignore
vendored
@@ -1,2 +1 @@
|
|||||||
bin
|
build
|
||||||
bin-int
|
|
||||||
|
|||||||
@@ -3,14 +3,12 @@ TARGET ?= x64
|
|||||||
|
|
||||||
CFLAGS = -Wall -Werror -Wextra -g
|
CFLAGS = -Wall -Werror -Wextra -g
|
||||||
|
|
||||||
libruntime: bin-int/runtime.o
|
libruntime: build/runtime.o
|
||||||
$(CC) $(CFLAGS) -c targets/$(TARGET).s -o bin-int/$(TARGET).o
|
$(CC) $(CFLAGS) -c targets/$(TARGET).s -o build/$(TARGET).o
|
||||||
mkdir -p bin
|
|
||||||
ar rcs bin/libruntime_$(TARGET).a bin-int/runtime.o bin-int/$(TARGET).o
|
|
||||||
|
|
||||||
bin-int/runtime.o: runtime/runtime.c
|
build/runtime.o: runtime/runtime.c
|
||||||
mkdir -p bin-int
|
mkdir -p build
|
||||||
$(CC) $(CFLAGS) -c runtime/runtime.c -o bin-int/runtime.o
|
$(CC) $(CFLAGS) -c runtime/runtime.c -o build/runtime.o
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -r bin bin-int
|
rm -r build
|
||||||
|
|||||||
Reference in New Issue
Block a user