require '_h2ph_pre.ph';

no warnings qw(redefine misc);

unless(defined(&_ASM_H_)) {
    eval 'sub _ASM_H_ () {1;}' unless defined(&_ASM_H_);
    unless(defined(&_LOCORE)) {
	eval 'sub _LOCORE () {1;}' unless defined(&_LOCORE);
    }
    require 'machine/frame.ph';
    unless(defined(&_LOCORE)) {
	eval 'sub _LOCORE () {1;}' unless defined(&_LOCORE);
    }
    require 'machine/frame.ph';
    if(defined(&__ELF__)) {
	eval 'sub _C_LABEL {
	    my($name) = @_;
    	    eval q($name);
	}' unless defined(&_C_LABEL);
    } else {
	if(defined(&__STDC__)) {
	    eval 'sub _C_LABEL {
	        my($name) = @_;
    		eval q( &_  $name);
	    }' unless defined(&_C_LABEL);
	} else {
	    eval 'sub _C_LABEL {
	        my($name) = @_;
    		eval q( &_ $name);
	    }' unless defined(&_C_LABEL);
	}
    }
    eval 'sub _ASM_LABEL {
        my($name) = @_;
	    eval q($name);
    }' unless defined(&_ASM_LABEL);
    if(defined(&PIC)) {
	eval 'sub PIC_PROLOGUE {
	    my($dest,$tmp) = @_;
    	    eval q( &sethi % &hi( &_GLOBAL_OFFSET_TABLE_-4),$dest;  &rd % &pc, $tmp;  &or $dest,% &lo( &_GLOBAL_OFFSET_TABLE_+4),$dest;  &add $dest,$tmp,$dest);
	}' unless defined(&PIC_PROLOGUE);
	eval 'sub PICCY_SET {
	    my($var,$dest,$tmp) = @_;
    	    eval q(3:  &rd % &pc, $tmp;  &add $tmp,($var-3 &b),$dest);
	}' unless defined(&PICCY_SET);
    } else {
	eval 'sub PIC_PROLOGUE {
	    my($dest,$tmp) = @_;
    	    eval q();
	}' unless defined(&PIC_PROLOGUE);
	eval 'sub PICCY_OFFSET {
	    my($var,$dest,$tmp) = @_;
    	    eval q();
	}' unless defined(&PICCY_OFFSET);
    }
    eval 'sub FTYPE {
        my($x) = @_;
	    eval q(. &type $x,@ &function);
    }' unless defined(&FTYPE);
    eval 'sub OTYPE {
        my($x) = @_;
	    eval q(. &type $x,@ &object);
    }' unless defined(&OTYPE);
    eval 'sub _ENTRY {
        my($name) = @_;
	    eval q(. &align 4; . &globl $name; . &proc 1;  &FTYPE($name); $name:);
    }' unless defined(&_ENTRY);
    if(defined(&GPROF)) {
	eval 'sub _PROF_PROLOGUE () {. &data; . &align 8; 1: . &uaword 0; . &uaword 0; . &text;  &save % &sp,- &CC64FSZ,% &sp;  &sethi % &hi(1 &b),% &o0;  &call  &_mcount;  &or % &o0,% &lo(1 &b),% &o0;  &restore;}' unless defined(&_PROF_PROLOGUE);
    } else {
	eval 'sub _PROF_PROLOGUE () {1;}' unless defined(&_PROF_PROLOGUE);
    }
    eval 'sub ENTRY {
        my($name) = @_;
	    eval q( &_ENTRY( &_C_LABEL($name));  &_PROF_PROLOGUE);
    }' unless defined(&ENTRY);
    eval 'sub ASENTRY {
        my($name) = @_;
	    eval q( &_ENTRY( &_ASM_LABEL($name));  &_PROF_PROLOGUE);
    }' unless defined(&ASENTRY);
    eval 'sub FUNC {
        my($name) = @_;
	    eval q( &ASENTRY($name));
    }' unless defined(&FUNC);
    eval 'sub RODATA {
        my($name) = @_;
	    eval q(. &align 4; . &text; . &globl  &_C_LABEL($name);  &OTYPE( &_C_LABEL($name));  &_C_LABEL($name):);
    }' unless defined(&RODATA);
    eval 'sub ASMSTR () {. &asciz;}' unless defined(&ASMSTR);
    eval 'sub RCSID {
        my($name) = @_;
	    eval q(. &asciz $name);
    }' unless defined(&RCSID);
    if(defined(&__ELF__)) {
	eval 'sub WEAK_ALIAS {
	    my($alias,$sym) = @_;
    	    eval q(. &weak $alias; $alias = $sym);
	}' unless defined(&WEAK_ALIAS);
    }
    if(defined(&__ELF__)) {
	if(defined(&__STDC__)) {
	    eval 'sub WARN_REFERENCES {
	        my($_sym,$_msg) = @_;
    		eval q(. &section . ($gnu->{warning}).  $_sym ; . &ascii $_msg ; . &text);
	    }' unless defined(&WARN_REFERENCES);
	} else {
	    eval 'sub WARN_REFERENCES {
	        my($_sym,$_msg) = @_;
    		eval q(. &section . ($gnu->{warning}). $_sym ; . &ascii $_msg ; . &text);
	    }' unless defined(&WARN_REFERENCES);
	}
    } else {
	if(defined(&__STDC__)) {
	    eval 'sub __STRING {
	        my($x) = @_;
    		eval q($x);
	    }' unless defined(&__STRING);
	    eval 'sub WARN_REFERENCES {
	        my($sym,$msg) = @_;
    		eval q(. &stabs $msg  ,30,0,0,0; . &stabs  &__STRING( &_  $sym)  ,1,0,0,0);
	    }' unless defined(&WARN_REFERENCES);
	} else {
	    eval 'sub __STRING {
	        my($x) = @_;
    		eval q(\\"x\\");
	    }' unless defined(&__STRING);
	    eval 'sub WARN_REFERENCES {
	        my($sym,$msg) = @_;
    		eval q(. &stabs $msg,30,0,0,0; . &stabs  &__STRING( &_ $sym),1,0,0,0);
	    }' unless defined(&WARN_REFERENCES);
	}
    }
}
1;
