Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/unixasm/aix-power.rb
Views: 11766
#!/usr/bin/env ruby12require 'erb'34class Template5attr_accessor :template, :result67def initialize(filename)8begin9f = File.new(filename)10@template = f.read11rescue Errno::ENOENT12end13end1415def parse16@result = ERB.new(@template).result(binding)17end1819def get_result20result21end22end2324class Source < Template25attr_accessor :__CAL26attr_accessor :__NR_execve27attr_accessor :__NR_getpeername28attr_accessor :__NR_accept29attr_accessor :__NR_listen30attr_accessor :__NR_bind31attr_accessor :__NR_socket32attr_accessor :__NR_connect33attr_accessor :__NR_close34attr_accessor :__NR_kfcntl35attr_accessor :__cal36attr_accessor :_cal37attr_accessor :cal38attr_accessor :ver3940def initialize(filename)41@__CAL = 204742@__cal = "\x38\x5d"43@_cal = Hash.new44@cal = Hash.new45@ver = String.new4647@execve = ''48@getpeername = ''49@accept = ''50@listen = ''51@bind = ''52@socket = ''53@connect = ''54@close = ''55@kfcntl = ''5657super(filename)58end5960def parse61__NC_execve = -(__CAL - __NR_execve)62__NC_getpeername = -(__CAL - __NR_getpeername)63__NC_accept = -(__CAL - __NR_accept)64__NC_listen = -(__CAL - __NR_listen)65__NC_bind = -(__CAL - __NR_bind)66__NC_socket = -(__CAL - __NR_socket)67__NC_connect = -(__CAL - __NR_connect)68__NC_close = -(__CAL - __NR_close)69__NC_kfcntl = -(__CAL - __NR_kfcntl)7071_cal[ver] = {72:execve => __cal + [__NC_execve].pack('n'),73:getpeername => __cal + [__NC_getpeername].pack('n'),74:accept => __cal + [__NC_accept].pack('n'),75:listen => __cal + [__NC_listen].pack('n'),76:bind => __cal + [__NC_bind].pack('n'),77:socket => __cal + [__NC_socket].pack('n'),78:connect => __cal + [__NC_connect].pack('n'),79:close => __cal + [__NC_close].pack('n'),80:kfcntl => __cal + [__NC_kfcntl].pack('n'),81}8283cal = Hash.new84cal[ver] = Hash.new8586_cal[ver].each_pair do |key, value|87cal[ver][key] = Array.new88cal[ver][key] << String.new89cal[ver][key][-1] << '#ifdef AIX%s' % ver.delete('.')90cal[ver][key][-1] << "\n"91cal[ver][key][-1] << '"'.rjust(5)92value.each_byte do |c|93cal[ver][key][-1] << '\x%02x' % c94end95cal[ver][key][-1] << '"'.ljust(7)96cal[ver][key][-1] << '/* cal r2,-%d(r29)' %97(65536 - value.unpack('nn')[1])98cal[ver][key][-1] << '*/'.rjust(15)99cal[ver][key][-1] << "\n"100cal[ver][key][-1] << "#endif"101cal[ver][key][-1] << "\n"102end103104cal.each_pair do |key, ver|105ver.each_pair do |key, value|106instance_variable_get("@#{key}").concat(value[-1])107end108end109110super111end112end113114class Parser115def initialize(filename)116@src = Source.new(filename)117end118119def parse120vers = [121'6.1.4',122'6.1.3',123'6.1.2',124'6.1.1',125'6.1.0',126'5.3.10',127'5.3.9',128'5.3.8',129'5.3.7',130]131132vers.each do |ver|133case ver134when '6.1.4'135__NR_execve = 7136__NR_getpeername = 211137__NR_accept = 237138__NR_listen = 240139__NR_bind = 242140__NR_socket = 243141__NR_connect = 244142__NR_close = 278143__NR_kfcntl = 658144145when '6.1.3'146__NR_execve = 7147__NR_getpeername = 205148__NR_accept = 232149__NR_listen = 235150__NR_bind = 237151__NR_socket = 238152__NR_connect = 239153__NR_close = 272154__NR_kfcntl = 644155156when '6.1.2'157__NR_execve = 7158__NR_getpeername = 205159__NR_accept = 232160__NR_listen = 235161__NR_bind = 237162__NR_socket = 238163__NR_connect = 239164__NR_close = 272165__NR_kfcntl = 635166167when '6.1.1'168__NR_execve = 7169__NR_getpeername = 202170__NR_accept = 229171__NR_listen = 232172__NR_bind = 234173__NR_socket = 235174__NR_connect = 236175__NR_close = 269176__NR_kfcntl = 614177178when '6.1.0'179__NR_execve = 6180__NR_getpeername = 203181__NR_accept = 229182__NR_listen = 232183__NR_bind = 234184__NR_socket = 235185__NR_connect = 236186__NR_close = 269187__NR_kfcntl = 617188189when '5.3.10', '5.3.9', '5.3.8', '5.3.7'190__NR_execve = 6191__NR_getpeername = 198192__NR_accept = 214193__NR_listen = 215194__NR_bind = 216195__NR_socket = 217196__NR_connect = 218197__NR_close = 245198__NR_kfcntl = 493199200end201202@src.__NR_execve = __NR_execve203@src.__NR_getpeername = __NR_getpeername204@src.__NR_accept = __NR_accept205@src.__NR_listen = __NR_listen206@src.__NR_bind = __NR_bind207@src.__NR_socket = __NR_socket208@src.__NR_connect = __NR_connect209@src.__NR_close = __NR_close210@src.__NR_kfcntl = __NR_kfcntl211212@src.ver = ver213@src.parse214end215end216217def get_result218@src.get_result219end220end221222filename = ARGV.shift || exit223224parser = Parser.new(filename)225parser.parse226print parser.get_result227228229230