Skip to content

Commit a689a25

Browse files
committed
Update the IR
1 parent c6ab724 commit a689a25

3 files changed

Lines changed: 32 additions & 293 deletions

File tree

rules/stdio/ir_refcount.json

Lines changed: 19 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -420,217 +420,56 @@
420420
"f5": {
421421
"body": [
422422
{
423-
"text": "let total = "
424-
},
425-
{
426-
"method_call": {
427-
"receiver": [
428-
{
429-
"placeholder": {
430-
"arg": "a1",
431-
"access": "read"
432-
}
433-
}
434-
],
435-
"body": [
436-
{
437-
"text": ".saturating_mul("
438-
},
439-
{
440-
"placeholder": {
441-
"arg": "a2",
442-
"access": "read"
443-
}
444-
},
445-
{
446-
"text": ")"
447-
}
448-
]
449-
}
450-
},
451-
{
452-
"text": " as usize;\n let mut dst = "
423+
"text": "libcc2rs::fread_refcount("
453424
},
454425
{
455-
"method_call": {
456-
"receiver": [
457-
{
458-
"method_call": {
459-
"receiver": [
460-
{
461-
"method_call": {
462-
"receiver": [
463-
{
464-
"placeholder": {
465-
"arg": "a0",
466-
"access": "read"
467-
}
468-
}
469-
],
470-
"body": [
471-
{
472-
"text": ".cast::<u8>()"
473-
}
474-
]
475-
}
476-
}
477-
],
478-
"body": [
479-
{
480-
"text": ".expect(\"fread: only supporting u8 pointers\")"
481-
}
482-
]
483-
}
484-
}
485-
],
486-
"body": [
487-
{
488-
"text": ".clone()"
489-
}
490-
]
491-
}
492-
},
493-
{
494-
"text": ";\n\n let mut f = "
495-
},
496-
{
497-
"method_call": {
498-
"receiver": [
499-
{
500-
"method_call": {
501-
"receiver": [
502-
{
503-
"text": "(*"
504-
},
505-
{
506-
"method_call": {
507-
"receiver": [
508-
{
509-
"method_call": {
510-
"receiver": [
511-
{
512-
"placeholder": {
513-
"arg": "a3",
514-
"access": "read"
515-
}
516-
}
517-
],
518-
"body": [
519-
{
520-
"text": ".upgrade()"
521-
}
522-
]
523-
}
524-
}
525-
],
526-
"body": [
527-
{
528-
"text": ".deref()"
529-
}
530-
]
531-
}
532-
},
533-
{
534-
"text": ")"
535-
}
536-
],
537-
"body": [
538-
{
539-
"text": ".try_clone()"
540-
}
541-
]
542-
}
543-
}
544-
],
545-
"body": [
546-
{
547-
"text": ".expect(\"try_clone failed\")"
548-
}
549-
]
550-
}
551-
},
552-
{
553-
"text": ";\n let mut reader = std::io::BufReader::with_capacity(64 * 1024, f);\n\n let mut read_bytes: usize = 0;\n let mut buffer: [u8; 8192] = [0; 8192];\n\n while read_bytes < total {\n let remaining = total - read_bytes;\n let to_read = std::cmp::min("
554-
},
555-
{
556-
"method_call": {
557-
"receiver": [
558-
{
559-
"text": "buffer"
560-
}
561-
],
562-
"body": [
563-
{
564-
"text": ".len()"
565-
}
566-
]
426+
"placeholder": {
427+
"arg": "a0",
428+
"access": "read"
567429
}
568430
},
569431
{
570-
"text": ", remaining);\n\n let n = match std::io::Read::read(&mut reader, &mut buffer[..to_read]) {\n Ok(0) => break,\n Ok(n) => n,\n Err(ref e) if "
432+
"text": ", "
571433
},
572434
{
573-
"method_call": {
574-
"receiver": [
575-
{
576-
"text": "e"
577-
}
578-
],
579-
"body": [
580-
{
581-
"text": ".kind()"
582-
}
583-
]
435+
"placeholder": {
436+
"arg": "a1",
437+
"access": "read"
584438
}
585439
},
586440
{
587-
"text": " == std::io::ErrorKind::Interrupted => continue,\n Err(e) => panic!(\"Unhandled error in fread: {e}\"),\n };\n\n for i in 0..n {\n "
441+
"text": ", "
588442
},
589443
{
590-
"method_call": {
591-
"receiver": [
592-
{
593-
"text": "dst"
594-
}
595-
],
596-
"body": [
597-
{
598-
"text": ".write(buffer[i])"
599-
}
600-
]
444+
"placeholder": {
445+
"arg": "a2",
446+
"access": "read"
601447
}
602448
},
603449
{
604-
"text": ";\n dst = "
450+
"text": ", "
605451
},
606452
{
607453
"method_call": {
608454
"receiver": [
609455
{
610-
"text": "dst"
456+
"placeholder": {
457+
"arg": "a3",
458+
"access": "read"
459+
}
611460
}
612461
],
613462
"body": [
614463
{
615-
"text": ".offset(1)"
464+
"text": ".clone()"
616465
}
617466
]
618467
}
619468
},
620469
{
621-
"text": ";\n }\n\n read_bytes += n;\n }\n\n (read_bytes / "
622-
},
623-
{
624-
"placeholder": {
625-
"arg": "a1",
626-
"access": "read"
627-
}
628-
},
629-
{
630-
"text": " as usize) as u64"
470+
"text": ")"
631471
}
632472
],
633-
"multi_statement": true,
634473
"params": {
635474
"a0": {
636475
"type": "AnyPtr"

rules/stdio/ir_unsafe.json

Lines changed: 12 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -477,36 +477,7 @@
477477
"f5": {
478478
"body": [
479479
{
480-
"text": "let total = "
481-
},
482-
{
483-
"method_call": {
484-
"receiver": [
485-
{
486-
"placeholder": {
487-
"arg": "a1",
488-
"access": "read"
489-
}
490-
}
491-
],
492-
"body": [
493-
{
494-
"text": ".saturating_mul("
495-
},
496-
{
497-
"placeholder": {
498-
"arg": "a2",
499-
"access": "read"
500-
}
501-
},
502-
{
503-
"text": ")"
504-
}
505-
]
506-
}
507-
},
508-
{
509-
"text": " as usize;\n let mut dst = "
480+
"text": "unsafe { libcc2rs::fread_unsafe("
510481
},
511482
{
512483
"placeholder": {
@@ -515,107 +486,36 @@
515486
}
516487
},
517488
{
518-
"text": " as *mut u8;\n\n let mut f = "
489+
"text": " as *mut ::std::ffi::c_void, "
519490
},
520491
{
521-
"method_call": {
522-
"receiver": [
523-
{
524-
"method_call": {
525-
"receiver": [
526-
{
527-
"text": "(*"
528-
},
529-
{
530-
"placeholder": {
531-
"arg": "a3",
532-
"access": "read"
533-
}
534-
},
535-
{
536-
"text": ")"
537-
}
538-
],
539-
"body": [
540-
{
541-
"text": ".try_clone()"
542-
}
543-
]
544-
}
545-
}
546-
],
547-
"body": [
548-
{
549-
"text": ".expect(\"try_clone failed\")"
550-
}
551-
]
552-
}
553-
},
554-
{
555-
"text": ";\n let mut reader = std::io::BufReader::with_capacity(64 * 1024, f);\n\n let mut read_bytes: usize = 0;\n let mut buffer: [u8; 8192] = [0; 8192];\n\n while read_bytes < total {\n let remaining = total - read_bytes;\n let to_read = std::cmp::min("
556-
},
557-
{
558-
"method_call": {
559-
"receiver": [
560-
{
561-
"text": "buffer"
562-
}
563-
],
564-
"body": [
565-
{
566-
"text": ".len()"
567-
}
568-
]
569-
}
570-
},
571-
{
572-
"text": ", remaining);\n\n let n = match std::io::Read::read(&mut reader, &mut buffer[..to_read]) {\n Ok(0) => break,\n Ok(n) => n,\n Err(ref e) if "
573-
},
574-
{
575-
"method_call": {
576-
"receiver": [
577-
{
578-
"text": "e"
579-
}
580-
],
581-
"body": [
582-
{
583-
"text": ".kind()"
584-
}
585-
]
492+
"placeholder": {
493+
"arg": "a1",
494+
"access": "read"
586495
}
587496
},
588497
{
589-
"text": " == std::io::ErrorKind::Interrupted => continue,\n Err(e) => panic!(\"Unhandled error in fread: {e}\"),\n };\n\n for i in 0..n {\n *dst = buffer[i];\n dst = "
498+
"text": ", "
590499
},
591500
{
592-
"method_call": {
593-
"receiver": [
594-
{
595-
"text": "dst"
596-
}
597-
],
598-
"body": [
599-
{
600-
"text": ".offset(1)"
601-
}
602-
]
501+
"placeholder": {
502+
"arg": "a2",
503+
"access": "read"
603504
}
604505
},
605506
{
606-
"text": ";\n }\n\n read_bytes += n;\n }\n\n (read_bytes / "
507+
"text": ", "
607508
},
608509
{
609510
"placeholder": {
610-
"arg": "a1",
511+
"arg": "a3",
611512
"access": "read"
612513
}
613514
},
614515
{
615-
"text": " as usize) as u64"
516+
"text": ") }"
616517
}
617518
],
618-
"multi_statement": true,
619519
"params": {
620520
"a0": {
621521
"type": "*mut ::libc::c_void",

0 commit comments

Comments
 (0)