1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

x64 machine code generation (ELF)

This commit is contained in:
Alexander Medvednikov
2019-11-19 09:53:52 +03:00
parent ab91733a28
commit 9712213f50
13 changed files with 564 additions and 15 deletions

View File

@@ -87,6 +87,27 @@ pub fn (f File) read_bytes_at(size, pos int) []byte {
return arr
}
pub fn read_bytes(path string) ?[]byte {
mut fp := vfopen(path, 'rb')
if isnil(fp) {
return error('failed to open file "$path"')
}
C.fseek(fp, 0, C.SEEK_END)
fsize := C.ftell(fp)
C.rewind(fp)
println('fsize=$fsize')
mut data := malloc(fsize)
C.fread(data, fsize, 1, fp)
mut res := [`0`].repeat(fsize)
for i in 0..fsize {
res[i] = data[i]
}
C.fclose(fp)
//res := []byte(data, 10) // TODO can't `return []byte(data)`
//println('res0 = ' + res[0].str())
return res
}
// read_file reads the file in `path` and returns the contents.
pub fn read_file(path string) ?string {
mode := 'rb'