@@ -21,8 +21,6 @@ const AliasList = common.AliasList;
2121const ResultUsed = common .ResultUsed ;
2222const Scope = common .ScopeExtra (Context , Type );
2323
24- pub const Compilation = aro .Compilation ;
25-
2624const Context = struct {
2725 gpa : mem.Allocator ,
2826 arena : mem.Allocator ,
@@ -54,7 +52,7 @@ const Context = struct {
5452
5553 pattern_list : translate_c.PatternList ,
5654 tree : Tree ,
57- comp : * Compilation ,
55+ comp : * aro. Compilation ,
5856 mapper : aro.TypeMapper ,
5957
6058 fn getMangle (c : * Context ) u32 {
@@ -108,7 +106,7 @@ fn warn(c: *Context, scope: *Scope, loc: TokenIndex, comptime format: []const u8
108106
109107pub fn translate (
110108 gpa : mem.Allocator ,
111- comp : * Compilation ,
109+ comp : * aro. Compilation ,
112110 args : []const []const u8 ,
113111) ! std.zig.Ast {
114112 try comp .addDefaultPragmaHandlers ();
@@ -124,23 +122,18 @@ pub fn translate(
124122 assert (driver .inputs .items .len == 1 );
125123 const source = driver .inputs .items [0 ];
126124
127- const builtin = try comp .generateBuiltinMacros ();
125+ const builtin_macros = try comp .generateBuiltinMacros (.include_system_defines );
128126 const user_macros = try comp .addSourceFromBuffer ("<command line>" , macro_buf .items );
129127
130- var pp = aro .Preprocessor .init (comp );
128+ var pp = try aro .Preprocessor .initDefault (comp );
131129 defer pp .deinit ();
132130
133- try pp .addBuiltinMacros ();
134-
135- _ = try pp .preprocess (builtin );
136- _ = try pp .preprocess (user_macros );
137- const eof = try pp .preprocess (source );
138- try pp .tokens .append (pp .comp .gpa , eof );
131+ try pp .preprocessSources (&.{ source , builtin_macros , user_macros });
139132
140- var tree = try aro . Parser . parse (& pp );
133+ var tree = try pp . parse ();
141134 defer tree .deinit ();
142135
143- if (driver .comp .diag .errors != 0 ) {
136+ if (driver .comp .diagnostics .errors != 0 ) {
144137 return error .SemanticAnalyzeFail ;
145138 }
146139
@@ -441,14 +434,11 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: NodeIndex, field_nodes:
441434 };
442435
443436 const val = c .tree .value_map .get (field_node ).? ;
444- const str = try std .fmt .allocPrint (c .arena , "{d}" , .{val .data .int });
445- const int = try ZigTag .integer_literal .create (c .arena , str );
446-
447437 const enum_const_def = try ZigTag .enum_constant .create (c .arena , .{
448438 .name = enum_val_name ,
449439 .is_public = toplevel ,
450440 .type = enum_const_type_node ,
451- .value = int ,
441+ .value = try transCreateNodeAPInt ( c , val ) ,
452442 });
453443 if (toplevel )
454444 try addTopLevelDecl (c , enum_val_name , enum_const_def )
@@ -565,7 +555,7 @@ fn transFnType(
565555
566556 const linksection_string = blk : {
567557 if (raw_ty .getAttribute (.section )) | section | {
568- break :blk section . name . slice ( c . tree . strings ) ;
558+ break :blk c . comp . interner . get ( section . name . ref ()). bytes ;
569559 }
570560 break :blk null ;
571561 };
@@ -659,8 +649,7 @@ fn transExpr(c: *Context, node: NodeIndex, result_used: ResultUsed) TransError!Z
659649 const ty = c .tree .nodes .items (.ty )[@intFromEnum (node )];
660650 if (c .tree .value_map .get (node )) | val | {
661651 // TODO handle other values
662- const str = try std .fmt .allocPrint (c .arena , "{d}" , .{val .data .int });
663- const int = try ZigTag .integer_literal .create (c .arena , str );
652+ const int = try transCreateNodeAPInt (c , val );
664653 const as_node = try ZigTag .as .create (c .arena , .{
665654 .lhs = try transType (c , undefined , ty , undefined ),
666655 .rhs = int ,
@@ -673,3 +662,17 @@ fn transExpr(c: *Context, node: NodeIndex, result_used: ResultUsed) TransError!Z
673662 }
674663 return .none ;
675664}
665+
666+ fn transCreateNodeAPInt (c : * Context , int : aro.Value ) ! ZigNode {
667+ var space : aro.Interner.Tag.Int.BigIntSpace = undefined ;
668+ var big = int .toBigInt (& space , c .comp );
669+ const is_negative = ! big .positive ;
670+ big .positive = true ;
671+
672+ const str = big .toStringAlloc (c .arena , 10 , .lower ) catch | err | switch (err ) {
673+ error .OutOfMemory = > return error .OutOfMemory ,
674+ };
675+ const res = try ZigTag .integer_literal .create (c .arena , str );
676+ if (is_negative ) return ZigTag .negate .create (c .arena , res );
677+ return res ;
678+ }
0 commit comments