GithubHelp home page GithubHelp logo

Comments (9)

Vexu avatar Vexu commented on July 19, 2024

With 7222741 the compiler no longer crashes but you need to add your own minimal stddef.h and stdarg.h (at least with glibc).

// minimal stddef.h
typedef long ptrdiff_t;
typedef unsigned long size_t;
typedef int wchar_t;
#define NULL ((void*)0)

With all that there are still a bunch of compiler errors due to bugs and unimplemented features.

from arocc.

Vexu avatar Vexu commented on July 19, 2024

With 8af9873 and 634c286 I'm now able to successfully parse that simple hello world on my machine using arocc test.c -Wno-macro-redefined. Note that since there is no backend yet the command will just dump the resulting AST.

from arocc.

VarLad avatar VarLad commented on July 19, 2024

Now I get

fatal error: could not find Aro builtin headers

I guess I'll have to define stddef.h and stdargs.h

Any help with that?

from arocc.

Vexu avatar Vexu commented on July 19, 2024

You don't need to but it isn't able to find the correct headers. Can you give which arocc? Using zig-out/bin/arocc works for me.

from arocc.

VarLad avatar VarLad commented on July 19, 2024

Okay, I cut pasted it from zig-out/bin/arocc to .local/bin/arocc

I pasted it back and made a symlink in .local/bin
Now it works but now I get this

viav0.9.0-dev.861+311797f68 
❯ arocc test.c -o test
/usr/include/bits/wordsize.h:4:10: warning: '__WORDSIZE' macro redefined
# define __WORDSIZE	64
         ^
/usr/include/bits/wordsize.h:12:10: warning: '__WORDSIZE_TIME64_COMPAT32' macro redefined
# define __WORDSIZE_TIME64_COMPAT32	1
         ^
/usr/include/bits/wordsize.h:14:10: warning: '__SYSCALL_WORDSIZE' macro redefined
# define __SYSCALL_WORDSIZE		64
         ^
/usr/include/bits/long-double.h:21:9: warning: '__LDOUBLE_REDIRECTS_TO_FLOAT128_ABI' macro redefined
#define __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI 0
        ^
4 warnings generated.
typedef: 'long'
 name: ptrdiff_t

typedef: 'unsigned long'
 name: size_t

typedef: 'int'
 name: wchar_t

struct_decl_two: 'struct (anonymous struct at /home/varlad/arocc/include/stddef.h:10:9)'
  record_field_decl: 'long long'
   name: __aro_max_align_ll
  record_field_decl: 'long double'
   name: __aro_max_align_ld

typedef: 'struct (anonymous struct at /home/varlad/arocc/include/stddef.h:10:9)'
 name: max_align_t

typedef: 'int'
 name: va_list

typedef: 'int'
 name: __gnuc_va_list

typedef: 'unsigned char'
 name: __u_char

typedef: 'unsigned short'
 name: __u_short

typedef: 'unsigned int'
 name: __u_int

typedef: 'unsigned long'
 name: __u_long

typedef: 'signed char'
 name: __int8_t

typedef: 'unsigned char'
 name: __uint8_t

typedef: 'short'
 name: __int16_t

typedef: 'unsigned short'
 name: __uint16_t

typedef: 'int'
 name: __int32_t

typedef: 'unsigned int'
 name: __uint32_t

typedef: 'long'
 name: __int64_t

typedef: 'unsigned long'
 name: __uint64_t

typedef: 'signed char'
 name: __int_least8_t

typedef: 'unsigned char'
 name: __uint_least8_t

typedef: 'short'
 name: __int_least16_t

typedef: 'unsigned short'
 name: __uint_least16_t

typedef: 'int'
 name: __int_least32_t

typedef: 'unsigned int'
 name: __uint_least32_t

typedef: 'long'
 name: __int_least64_t

typedef: 'unsigned long'
 name: __uint_least64_t

typedef: 'long'
 name: __quad_t

typedef: 'unsigned long'
 name: __u_quad_t

typedef: 'long'
 name: __intmax_t

typedef: 'unsigned long'
 name: __uintmax_t

typedef: 'unsigned long'
 name: __dev_t

typedef: 'unsigned int'
 name: __uid_t

typedef: 'unsigned int'
 name: __gid_t

typedef: 'unsigned long'
 name: __ino_t

typedef: 'unsigned long'
 name: __ino64_t

typedef: 'unsigned int'
 name: __mode_t

typedef: 'unsigned long'
 name: __nlink_t

typedef: 'long'
 name: __off_t

typedef: 'long'
 name: __off64_t

typedef: 'int'
 name: __pid_t

struct_decl_two: 'struct (anonymous struct at /usr/include/bits/typesizes.h:73:24)'
  record_field_decl: '[2]int'
   name: __val

typedef: 'struct (anonymous struct at /usr/include/bits/typesizes.h:73:24)'
 name: __fsid_t

typedef: 'long'
 name: __clock_t

typedef: 'unsigned long'
 name: __rlim_t

typedef: 'unsigned long'
 name: __rlim64_t

typedef: 'unsigned int'
 name: __id_t

typedef: 'long'
 name: __time_t

typedef: 'unsigned int'
 name: __useconds_t

typedef: 'long'
 name: __suseconds_t

typedef: 'long'
 name: __suseconds64_t

typedef: 'int'
 name: __daddr_t

typedef: 'int'
 name: __key_t

typedef: 'int'
 name: __clockid_t

typedef: '*void'
 name: __timer_t

typedef: 'long'
 name: __blksize_t

typedef: 'long'
 name: __blkcnt_t

typedef: 'long'
 name: __blkcnt64_t

typedef: 'unsigned long'
 name: __fsblkcnt_t

typedef: 'unsigned long'
 name: __fsblkcnt64_t

typedef: 'unsigned long'
 name: __fsfilcnt_t

typedef: 'unsigned long'
 name: __fsfilcnt64_t

typedef: 'long'
 name: __fsword_t

typedef: 'long'
 name: __ssize_t

typedef: 'long'
 name: __syscall_slong_t

typedef: 'unsigned long'
 name: __syscall_ulong_t

typedef: 'long'
 name: __loff_t

typedef: '*char'
 name: __caddr_t

typedef: 'long'
 name: __intptr_t

typedef: 'unsigned int'
 name: __socklen_t

typedef: 'int'
 name: __sig_atomic_t

struct_decl: 'struct (anonymous struct at /usr/include/bits/types/__mbstate_t.h:13:9)'
  record_field_decl: 'int'
   name: __count

  union_decl_two: 'union (anonymous union at /usr/include/bits/types/__mbstate_t.h:16:3)'
    record_field_decl: 'unsigned int'
     name: __wch
    record_field_decl: '[4]char'
     name: __wchb

  record_field_decl: 'union (anonymous union at /usr/include/bits/types/__mbstate_t.h:16:3)'
   name: __value

typedef: 'struct (anonymous struct at /usr/include/bits/types/__mbstate_t.h:13:9)'
 name: __mbstate_t

struct_decl_two: 'struct _G_fpos_t'
  record_field_decl: 'long'
   name: __pos
  record_field_decl: 'struct (anonymous struct at /usr/include/bits/types/__mbstate_t.h:13:9)'
   name: __state

typedef: 'struct _G_fpos_t'
 name: __fpos_t

struct_decl_two: 'struct _G_fpos64_t'
  record_field_decl: 'long'
   name: __pos
  record_field_decl: 'struct (anonymous struct at /usr/include/bits/types/__mbstate_t.h:13:9)'
   name: __state

typedef: 'struct _G_fpos64_t'
 name: __fpos64_t

typedef: 'struct _IO_FILE'
 name: __FILE

typedef: 'struct _IO_FILE'
 name: FILE

typedef: 'void'
 name: _IO_lock_t

struct_decl: 'struct _IO_FILE'
  record_field_decl: 'int'
   name: _flags

  record_field_decl: '*char'
   name: _IO_read_ptr

  record_field_decl: '*char'
   name: _IO_read_end

  record_field_decl: '*char'
   name: _IO_read_base

  record_field_decl: '*char'
   name: _IO_write_base

  record_field_decl: '*char'
   name: _IO_write_ptr

  record_field_decl: '*char'
   name: _IO_write_end

  record_field_decl: '*char'
   name: _IO_buf_base

  record_field_decl: '*char'
   name: _IO_buf_end

  record_field_decl: '*char'
   name: _IO_save_base

  record_field_decl: '*char'
   name: _IO_backup_base

  record_field_decl: '*char'
   name: _IO_save_end

  record_field_decl: '*struct _IO_marker'
   name: _markers

  record_field_decl: '*struct _IO_FILE'
   name: _chain

  record_field_decl: 'int'
   name: _fileno

  record_field_decl: 'int'
   name: _flags2

  record_field_decl: 'long'
   name: _old_offset

  record_field_decl: 'unsigned short'
   name: _cur_column

  record_field_decl: 'signed char'
   name: _vtable_offset

  record_field_decl: '[1]char'
   name: _shortbuf

  record_field_decl: '*void'
   name: _lock

  record_field_decl: 'long'
   name: _offset

  record_field_decl: '*struct _IO_codecvt'
   name: _codecvt

  record_field_decl: '*struct _IO_wide_data'
   name: _wide_data

  record_field_decl: '*struct _IO_FILE'
   name: _freeres_list

  record_field_decl: '*void'
   name: _freeres_buf

  record_field_decl: 'unsigned long'
   name: __pad5

  record_field_decl: 'int'
   name: _mode

  record_field_decl: '[20]char'
   name: _unused2

typedef: 'long'
 name: off_t

typedef: 'long'
 name: ssize_t

typedef: 'struct _G_fpos_t'
 name: fpos_t

extern_var: '*struct _IO_FILE'
 name: stdin

extern_var: '*struct _IO_FILE'
 name: stdout

extern_var: '*struct _IO_FILE'
 name: stderr

fn_proto: 'fn (__filename: *const char) int'
 name: remove

fn_proto: 'fn (__old: *const char, __new: *const char) int'
 name: rename

fn_proto: 'fn (__oldfd: int, __old: *const char, __newfd: int, __new: *const char) int'
 name: renameat

fn_proto: 'fn () *struct _IO_FILE'
 name: tmpfile

fn_proto: 'fn (__s: *char) *char'
 name: tmpnam

fn_proto: 'fn (__s: *char) *char'
 name: tmpnam_r

fn_proto: 'fn (__dir: *const char, __pfx: *const char) *char'
 name: tempnam

fn_proto: 'fn (__stream: *struct _IO_FILE) int'
 name: fclose

fn_proto: 'fn (__stream: *struct _IO_FILE) int'
 name: fflush

fn_proto: 'fn (__stream: *struct _IO_FILE) int'
 name: fflush_unlocked

fn_proto: 'fn (__filename: restrict *const char, __modes: restrict *const char) *struct _IO_FILE'
 name: fopen

fn_proto: 'fn (__filename: restrict *const char, __modes: restrict *const char, __stream: restrict *struct _IO_FILE) *struct _IO_FILE'
 name: freopen

fn_proto: 'fn (__fd: int, __modes: *const char) *struct _IO_FILE'
 name: fdopen

fn_proto: 'fn (__s: *void, __len: unsigned long, __modes: *const char) *struct _IO_FILE'
 name: fmemopen

fn_proto: 'fn (__bufloc: **char, __sizeloc: *unsigned long) *struct _IO_FILE'
 name: open_memstream

fn_proto: 'fn (__stream: restrict *struct _IO_FILE, __buf: restrict *char) void'
 name: setbuf

fn_proto: 'fn (__stream: restrict *struct _IO_FILE, __buf: restrict *char, __modes: int, __n: unsigned long) int'
 name: setvbuf

fn_proto: 'fn (__stream: restrict *struct _IO_FILE, __buf: restrict *char, __size: unsigned long) void'
 name: setbuffer

fn_proto: 'fn (__stream: *struct _IO_FILE) void'
 name: setlinebuf

fn_proto: 'fn (__stream: restrict *struct _IO_FILE, __format: restrict *const char, ...) int'
 name: fprintf

fn_proto: 'fn (__format: restrict *const char, ...) int'
 name: printf

fn_proto: 'fn (__s: restrict *char, __format: restrict *const char, ...) int'
 name: sprintf

fn_proto: 'fn (__s: restrict *struct _IO_FILE, __format: restrict *const char, __arg: int) int'
 name: vfprintf

fn_proto: 'fn (__format: restrict *const char, __arg: int) int'
 name: vprintf

fn_proto: 'fn (__s: restrict *char, __format: restrict *const char, __arg: int) int'
 name: vsprintf

fn_proto: 'fn (__s: restrict *char, __maxlen: unsigned long, __format: restrict *const char, ...) int'
 name: snprintf

fn_proto: 'fn (__s: restrict *char, __maxlen: unsigned long, __format: restrict *const char, __arg: int) int'
 name: vsnprintf

fn_proto: 'fn (__fd: int, __fmt: restrict *const char, __arg: int) int'
 name: vdprintf

fn_proto: 'fn (__fd: int, __fmt: restrict *const char, ...) int'
 name: dprintf

fn_proto: 'fn (__stream: restrict *struct _IO_FILE, __format: restrict *const char, ...) int'
 name: fscanf

fn_proto: 'fn (__format: restrict *const char, ...) int'
 name: scanf

fn_proto: 'fn (__s: restrict *const char, __format: restrict *const char, ...) int'
 name: sscanf

typedef: 'float'
 name: _Float32

typedef: 'double'
 name: _Float64

typedef: 'double'
 name: _Float32x

typedef: 'long double'
 name: _Float64x

fn_proto: 'fn (__stream: restrict *struct _IO_FILE, __format: restrict *const char, ...) int'
 name: __isoc99_fscanf

fn_proto: 'fn (__format: restrict *const char, ...) int'
 name: __isoc99_scanf

fn_proto: 'fn (__s: restrict *const char, __format: restrict *const char, ...) int'
 name: __isoc99_sscanf

fn_proto: 'fn (__s: restrict *struct _IO_FILE, __format: restrict *const char, __arg: int) int'
 name: vfscanf

fn_proto: 'fn (__format: restrict *const char, __arg: int) int'
 name: vscanf

fn_proto: 'fn (__s: restrict *const char, __format: restrict *const char, __arg: int) int'
 name: vsscanf

fn_proto: 'fn (__s: restrict *struct _IO_FILE, __format: restrict *const char, __arg: int) int'
 name: __isoc99_vfscanf

fn_proto: 'fn (__format: restrict *const char, __arg: int) int'
 name: __isoc99_vscanf

fn_proto: 'fn (__s: restrict *const char, __format: restrict *const char, __arg: int) int'
 name: __isoc99_vsscanf

fn_proto: 'fn (__stream: *struct _IO_FILE) int'
 name: fgetc

fn_proto: 'fn (__stream: *struct _IO_FILE) int'
 name: getc

fn_proto: 'fn () int'
 name: getchar

fn_proto: 'fn (__stream: *struct _IO_FILE) int'
 name: getc_unlocked

fn_proto: 'fn () int'
 name: getchar_unlocked

fn_proto: 'fn (__stream: *struct _IO_FILE) int'
 name: fgetc_unlocked

fn_proto: 'fn (__c: int, __stream: *struct _IO_FILE) int'
 name: fputc

fn_proto: 'fn (__c: int, __stream: *struct _IO_FILE) int'
 name: putc

fn_proto: 'fn (__c: int) int'
 name: putchar

fn_proto: 'fn (__c: int, __stream: *struct _IO_FILE) int'
 name: fputc_unlocked

fn_proto: 'fn (__c: int, __stream: *struct _IO_FILE) int'
 name: putc_unlocked

fn_proto: 'fn (__c: int) int'
 name: putchar_unlocked

fn_proto: 'fn (__stream: *struct _IO_FILE) int'
 name: getw

fn_proto: 'fn (__w: int, __stream: *struct _IO_FILE) int'
 name: putw

fn_proto: 'fn (__s: restrict *char, __n: int, __stream: restrict *struct _IO_FILE) *char'
 name: fgets

fn_proto: 'fn (__lineptr: restrict **char, __n: restrict *unsigned long, __delimiter: int, __stream: restrict *struct _IO_FILE) long'
 name: __getdelim

fn_proto: 'fn (__lineptr: restrict **char, __n: restrict *unsigned long, __delimiter: int, __stream: restrict *struct _IO_FILE) long'
 name: getdelim

fn_proto: 'fn (__lineptr: restrict **char, __n: restrict *unsigned long, __stream: restrict *struct _IO_FILE) long'
 name: getline

fn_proto: 'fn (__s: restrict *const char, __stream: restrict *struct _IO_FILE) int'
 name: fputs

fn_proto: 'fn (__s: *const char) int'
 name: puts

fn_proto: 'fn (__c: int, __stream: *struct _IO_FILE) int'
 name: ungetc

fn_proto: 'fn (__ptr: restrict *void, __size: unsigned long, __n: unsigned long, __stream: restrict *struct _IO_FILE) unsigned long'
 name: fread

fn_proto: 'fn (__ptr: restrict *const void, __size: unsigned long, __n: unsigned long, __s: restrict *struct _IO_FILE) unsigned long'
 name: fwrite

fn_proto: 'fn (__ptr: restrict *void, __size: unsigned long, __n: unsigned long, __stream: restrict *struct _IO_FILE) unsigned long'
 name: fread_unlocked

fn_proto: 'fn (__ptr: restrict *const void, __size: unsigned long, __n: unsigned long, __stream: restrict *struct _IO_FILE) unsigned long'
 name: fwrite_unlocked

fn_proto: 'fn (__stream: *struct _IO_FILE, __off: long, __whence: int) int'
 name: fseek

fn_proto: 'fn (__stream: *struct _IO_FILE) long'
 name: ftell

fn_proto: 'fn (__stream: *struct _IO_FILE) void'
 name: rewind

fn_proto: 'fn (__stream: *struct _IO_FILE, __off: long, __whence: int) int'
 name: fseeko

fn_proto: 'fn (__stream: *struct _IO_FILE) long'
 name: ftello

fn_proto: 'fn (__stream: restrict *struct _IO_FILE, __pos: restrict *struct _G_fpos_t) int'
 name: fgetpos

fn_proto: 'fn (__stream: *struct _IO_FILE, __pos: *const struct _G_fpos_t) int'
 name: fsetpos

fn_proto: 'fn (__stream: *struct _IO_FILE) void'
 name: clearerr

fn_proto: 'fn (__stream: *struct _IO_FILE) int'
 name: feof

fn_proto: 'fn (__stream: *struct _IO_FILE) int'
 name: ferror

fn_proto: 'fn (__stream: *struct _IO_FILE) void'
 name: clearerr_unlocked

fn_proto: 'fn (__stream: *struct _IO_FILE) int'
 name: feof_unlocked

fn_proto: 'fn (__stream: *struct _IO_FILE) int'
 name: ferror_unlocked

fn_proto: 'fn (__s: *const char) void'
 name: perror

fn_proto: 'fn (__stream: *struct _IO_FILE) int'
 name: fileno

fn_proto: 'fn (__stream: *struct _IO_FILE) int'
 name: fileno_unlocked

fn_proto: 'fn (__command: *const char, __modes: *const char) *struct _IO_FILE'
 name: popen

fn_proto: 'fn (__stream: *struct _IO_FILE) int'
 name: pclose

fn_proto: 'fn (__s: *char) *char'
 name: ctermid

fn_proto: 'fn (__stream: *struct _IO_FILE) void'
 name: flockfile

fn_proto: 'fn (__stream: *struct _IO_FILE) int'
 name: ftrylockfile

fn_proto: 'fn (__stream: *struct _IO_FILE) void'
 name: funlockfile

fn_proto: 'fn (*struct _IO_FILE) int'
 name: __uflow

fn_proto: 'fn (*struct _IO_FILE, int) int'
 name: __overflow

fn_def: 'fn (...) int'
 name: main
 body:
  compound_stmt_two: 'void'
    call_expr_one: 'int'
     lhs:
      function_to_pointer: '*fn (__format: restrict *const char, ...) int'
        decl_ref_expr: 'fn (__format: restrict *const char, ...) int' lvalue
         name: printf
     arg:
      array_to_pointer: 'd[11]char'
        string_literal_expr: '[11]char' lvalue
         data: "Well, heck"
    return_stmt: 'void'
     expr:
      int_literal: 'int' (value: 0)
       value: 0

I guess you're right, it just throws the AST at me

Any way to get the output binary though?

from arocc.

ehaas avatar ehaas commented on July 19, 2024

Any way to get the output binary though?

This is just a frontend - no code generation currently. I can't speak for Vexu but the stated goal from the README is that it becomes good enough that Zig's translate-c can use it and thus be entirely self-hosted instead of relying on clang for parsing the C. The Zig compiler could also use the AST from this project for the stage2 C codegen, instead of emitting strings.

from arocc.

VarLad avatar VarLad commented on July 19, 2024

Thanks! Hope its usable enough to replace the use of clang in Zig soon enough 🙂

from arocc.

VarLad avatar VarLad commented on July 19, 2024

@Vexu This looks interesting!
Is it something I can try?

If so, any instructions?

from arocc.

VarLad avatar VarLad commented on July 19, 2024

Ahh, right, in the README.md!
Sorry to ping! Thanks again!

This was pretty fast!

from arocc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.